2 * linux/fs/9p/vfs_inode.c
4 * This file contains vfs inode ops for the 9P2000 protocol.
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2
11 * as published by the Free Software Foundation.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to:
20 * Free Software Foundation
21 * 51 Franklin Street, Fifth Floor
22 * Boston, MA 02111-1301 USA
26 #include <linux/module.h>
27 #include <linux/errno.h>
29 #include <linux/file.h>
30 #include <linux/pagemap.h>
31 #include <linux/stat.h>
32 #include <linux/string.h>
33 #include <linux/inet.h>
34 #include <linux/namei.h>
35 #include <linux/idr.h>
36 #include <linux/sched.h>
37 #include <linux/slab.h>
38 #include <linux/xattr.h>
39 #include <linux/posix_acl.h>
40 #include <net/9p/9p.h>
41 #include <net/9p/client.h>
50 static const struct inode_operations v9fs_dir_inode_operations;
51 static const struct inode_operations v9fs_dir_inode_operations_dotu;
52 static const struct inode_operations v9fs_dir_inode_operations_dotl;
53 static const struct inode_operations v9fs_file_inode_operations;
54 static const struct inode_operations v9fs_file_inode_operations_dotl;
55 static const struct inode_operations v9fs_symlink_inode_operations;
56 static const struct inode_operations v9fs_symlink_inode_operations_dotl;
59 v9fs_vfs_mknod_dotl(struct inode *dir, struct dentry *dentry, int omode,
63 * unixmode2p9mode - convert unix mode bits to plan 9
64 * @v9ses: v9fs session information
65 * @mode: mode to convert
69 static int unixmode2p9mode(struct v9fs_session_info *v9ses, int mode)
75 if (v9fs_proto_dotu(v9ses)) {
78 if (v9ses->nodev == 0) {
82 res |= P9_DMNAMEDPIPE;
89 if ((mode & S_ISUID) == S_ISUID)
91 if ((mode & S_ISGID) == S_ISGID)
93 if ((mode & S_ISVTX) == S_ISVTX)
95 if ((mode & P9_DMLINK))
103 * p9mode2unixmode- convert plan9 mode bits to unix mode bits
104 * @v9ses: v9fs session information
105 * @mode: mode to convert
109 static int p9mode2unixmode(struct v9fs_session_info *v9ses, int mode)
115 if ((mode & P9_DMDIR) == P9_DMDIR)
117 else if ((mode & P9_DMSYMLINK) && (v9fs_proto_dotu(v9ses)))
119 else if ((mode & P9_DMSOCKET) && (v9fs_proto_dotu(v9ses))
120 && (v9ses->nodev == 0))
122 else if ((mode & P9_DMNAMEDPIPE) && (v9fs_proto_dotu(v9ses))
123 && (v9ses->nodev == 0))
125 else if ((mode & P9_DMDEVICE) && (v9fs_proto_dotu(v9ses))
126 && (v9ses->nodev == 0))
131 if (v9fs_proto_dotu(v9ses)) {
132 if ((mode & P9_DMSETUID) == P9_DMSETUID)
135 if ((mode & P9_DMSETGID) == P9_DMSETGID)
138 if ((mode & P9_DMSETVTX) == P9_DMSETVTX)
146 * v9fs_uflags2omode- convert posix open flags to plan 9 mode bits
147 * @uflags: flags to convert
148 * @extended: if .u extensions are active
151 int v9fs_uflags2omode(int uflags, int extended)
171 if (uflags & O_TRUNC)
178 if (uflags & O_APPEND)
186 * v9fs_blank_wstat - helper function to setup a 9P stat structure
187 * @wstat: structure to initialize
192 v9fs_blank_wstat(struct p9_wstat *wstat)
196 wstat->qid.type = ~0;
197 wstat->qid.version = ~0;
198 *((long long *)&wstat->qid.path) = ~0;
210 wstat->extension = NULL;
213 #ifdef CONFIG_9P_FSCACHE
215 * v9fs_alloc_inode - helper function to allocate an inode
216 * This callback is executed before setting up the inode so that we
217 * can associate a vcookie with each inode.
221 struct inode *v9fs_alloc_inode(struct super_block *sb)
223 struct v9fs_cookie *vcookie;
224 vcookie = (struct v9fs_cookie *)kmem_cache_alloc(vcookie_cache,
229 vcookie->fscache = NULL;
231 spin_lock_init(&vcookie->lock);
232 return &vcookie->inode;
236 * v9fs_destroy_inode - destroy an inode
240 void v9fs_destroy_inode(struct inode *inode)
242 kmem_cache_free(vcookie_cache, v9fs_inode2cookie(inode));
247 * v9fs_get_fsgid_for_create - Helper function to get the gid for creating a
248 * new file system object. This checks the S_ISGID to determine the owning
249 * group of the new file system object.
252 static gid_t v9fs_get_fsgid_for_create(struct inode *dir_inode)
254 BUG_ON(dir_inode == NULL);
256 if (dir_inode->i_mode & S_ISGID) {
257 /* set_gid bit is set.*/
258 return dir_inode->i_gid;
260 return current_fsgid();
264 * v9fs_dentry_from_dir_inode - helper function to get the dentry from
269 static struct dentry *v9fs_dentry_from_dir_inode(struct inode *inode)
271 struct dentry *dentry;
273 spin_lock(&dcache_lock);
274 /* Directory should have only one entry. */
275 BUG_ON(S_ISDIR(inode->i_mode) && !list_is_singular(&inode->i_dentry));
276 dentry = list_entry(inode->i_dentry.next, struct dentry, d_alias);
277 spin_unlock(&dcache_lock);
282 * v9fs_get_inode - helper function to setup an inode
284 * @mode: mode to setup inode with
288 struct inode *v9fs_get_inode(struct super_block *sb, int mode)
292 struct v9fs_session_info *v9ses = sb->s_fs_info;
294 P9_DPRINTK(P9_DEBUG_VFS, "super block: %p mode: %o\n", sb, mode);
296 inode = new_inode(sb);
298 P9_EPRINTK(KERN_WARNING, "Problem allocating inode\n");
299 return ERR_PTR(-ENOMEM);
302 inode_init_owner(inode, NULL, mode);
305 inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
306 inode->i_mapping->a_ops = &v9fs_addr_operations;
308 switch (mode & S_IFMT) {
313 if (v9fs_proto_dotl(v9ses)) {
314 inode->i_op = &v9fs_file_inode_operations_dotl;
315 inode->i_fop = &v9fs_file_operations_dotl;
316 } else if (v9fs_proto_dotu(v9ses)) {
317 inode->i_op = &v9fs_file_inode_operations;
318 inode->i_fop = &v9fs_file_operations;
320 P9_DPRINTK(P9_DEBUG_ERROR,
321 "special files without extended mode\n");
325 init_special_inode(inode, inode->i_mode, inode->i_rdev);
328 if (v9fs_proto_dotl(v9ses)) {
329 inode->i_op = &v9fs_file_inode_operations_dotl;
330 inode->i_fop = &v9fs_file_operations_dotl;
332 inode->i_op = &v9fs_file_inode_operations;
333 inode->i_fop = &v9fs_file_operations;
339 if (!v9fs_proto_dotu(v9ses) && !v9fs_proto_dotl(v9ses)) {
340 P9_DPRINTK(P9_DEBUG_ERROR, "extended modes used with "
341 "legacy protocol.\n");
346 if (v9fs_proto_dotl(v9ses))
347 inode->i_op = &v9fs_symlink_inode_operations_dotl;
349 inode->i_op = &v9fs_symlink_inode_operations;
354 if (v9fs_proto_dotl(v9ses))
355 inode->i_op = &v9fs_dir_inode_operations_dotl;
356 else if (v9fs_proto_dotu(v9ses))
357 inode->i_op = &v9fs_dir_inode_operations_dotu;
359 inode->i_op = &v9fs_dir_inode_operations;
361 if (v9fs_proto_dotl(v9ses))
362 inode->i_fop = &v9fs_dir_operations_dotl;
364 inode->i_fop = &v9fs_dir_operations;
368 P9_DPRINTK(P9_DEBUG_ERROR, "BAD mode 0x%x S_IFMT 0x%x\n",
369 mode, mode & S_IFMT);
382 static struct v9fs_fid*
383 v9fs_clone_walk(struct v9fs_session_info *v9ses, u32 fid, struct dentry *dentry)
387 struct v9fs_fid *ret;
388 struct v9fs_fcall *fcall;
390 nfid = v9fs_get_idpool(&v9ses->fidpool);
392 eprintk(KERN_WARNING, "no free fids available\n");
393 return ERR_PTR(-ENOSPC);
396 err = v9fs_t_walk(v9ses, fid, nfid, (char *) dentry->d_name.name,
400 if (fcall && fcall->id == RWALK)
403 PRINT_FCALL_ERROR("walk error", fcall);
404 v9fs_put_idpool(nfid, &v9ses->fidpool);
410 ret = v9fs_fid_create(v9ses, nfid);
416 err = v9fs_fid_insert(ret, dentry);
418 v9fs_fid_destroy(ret);
425 v9fs_t_clunk(v9ses, nfid);
435 * v9fs_clear_inode - release an inode
436 * @inode: inode to release
439 void v9fs_evict_inode(struct inode *inode)
441 truncate_inode_pages(inode->i_mapping, 0);
442 end_writeback(inode);
443 filemap_fdatawrite(inode->i_mapping);
445 #ifdef CONFIG_9P_FSCACHE
446 v9fs_cache_inode_put_cookie(inode);
450 static struct inode *
451 v9fs_inode(struct v9fs_session_info *v9ses, struct p9_fid *fid,
452 struct super_block *sb)
455 struct inode *ret = NULL;
458 st = p9_client_stat(fid);
462 umode = p9mode2unixmode(v9ses, st->mode);
463 ret = v9fs_get_inode(sb, umode);
469 v9fs_stat2inode(st, ret, sb);
470 ret->i_ino = v9fs_qid2ino(&st->qid);
472 #ifdef CONFIG_9P_FSCACHE
473 v9fs_vcookie_set_qid(ret, &st->qid);
474 v9fs_cache_inode_get_cookie(ret);
485 static struct inode *
486 v9fs_inode_dotl(struct v9fs_session_info *v9ses, struct p9_fid *fid,
487 struct super_block *sb)
489 struct inode *ret = NULL;
491 struct p9_stat_dotl *st;
493 st = p9_client_getattr_dotl(fid, P9_STATS_BASIC);
497 ret = v9fs_get_inode(sb, st->st_mode);
503 v9fs_stat2inode_dotl(st, ret);
504 ret->i_ino = v9fs_qid2ino(&st->qid);
505 #ifdef CONFIG_9P_FSCACHE
506 v9fs_vcookie_set_qid(ret, &st->qid);
507 v9fs_cache_inode_get_cookie(ret);
509 err = v9fs_get_acl(ret, fid);
522 * v9fs_inode_from_fid - Helper routine to populate an inode by
523 * issuing a attribute request
524 * @v9ses: session information
525 * @fid: fid to issue attribute request for
526 * @sb: superblock on which to create inode
529 static inline struct inode *
530 v9fs_inode_from_fid(struct v9fs_session_info *v9ses, struct p9_fid *fid,
531 struct super_block *sb)
533 if (v9fs_proto_dotl(v9ses))
534 return v9fs_inode_dotl(v9ses, fid, sb);
536 return v9fs_inode(v9ses, fid, sb);
540 * v9fs_remove - helper function to remove files and directories
541 * @dir: directory inode that is being deleted
542 * @file: dentry that is being deleted
543 * @rmdir: removing a directory
547 static int v9fs_remove(struct inode *dir, struct dentry *file, int rmdir)
550 struct inode *file_inode;
551 struct p9_fid *v9fid;
553 P9_DPRINTK(P9_DEBUG_VFS, "inode: %p dentry: %p rmdir: %d\n", dir, file,
556 file_inode = file->d_inode;
557 v9fid = v9fs_fid_clone(file);
559 return PTR_ERR(v9fid);
561 retval = p9_client_remove(v9fid);
563 drop_nlink(file_inode);
568 * v9fs_create - Create a file
569 * @v9ses: session information
570 * @dir: directory that dentry is being created in
571 * @dentry: dentry that is being created
572 * @extension: 9p2000.u extension string to support devices, etc.
573 * @perm: create permissions
577 static struct p9_fid *
578 v9fs_create(struct v9fs_session_info *v9ses, struct inode *dir,
579 struct dentry *dentry, char *extension, u32 perm, u8 mode)
583 struct p9_fid *dfid, *ofid, *fid;
586 P9_DPRINTK(P9_DEBUG_VFS, "name %s\n", dentry->d_name.name);
591 name = (char *) dentry->d_name.name;
592 dfid = v9fs_fid_lookup(dentry->d_parent);
595 P9_DPRINTK(P9_DEBUG_VFS, "fid lookup failed %d\n", err);
599 /* clone a fid to use for creation */
600 ofid = p9_client_walk(dfid, 0, NULL, 1);
603 P9_DPRINTK(P9_DEBUG_VFS, "p9_client_walk failed %d\n", err);
607 err = p9_client_fcreate(ofid, name, perm, mode, extension);
609 P9_DPRINTK(P9_DEBUG_VFS, "p9_client_fcreate failed %d\n", err);
613 /* now walk from the parent so we can get unopened fid */
614 fid = p9_client_walk(dfid, 1, &name, 1);
617 P9_DPRINTK(P9_DEBUG_VFS, "p9_client_walk failed %d\n", err);
622 /* instantiate inode and assign the unopened fid to the dentry */
623 inode = v9fs_inode_from_fid(v9ses, fid, dir->i_sb);
625 err = PTR_ERR(inode);
626 P9_DPRINTK(P9_DEBUG_VFS, "inode creation failed %d\n", err);
631 dentry->d_op = &v9fs_cached_dentry_operations;
633 dentry->d_op = &v9fs_dentry_operations;
635 d_instantiate(dentry, inode);
636 err = v9fs_fid_add(dentry, fid);
644 p9_client_clunk(ofid);
647 p9_client_clunk(fid);
653 * v9fs_vfs_create_dotl - VFS hook to create files for 9P2000.L protocol.
654 * @dir: directory inode that is being created
655 * @dentry: dentry that is being deleted
656 * @mode: create permissions
657 * @nd: path information
662 v9fs_vfs_create_dotl(struct inode *dir, struct dentry *dentry, int omode,
663 struct nameidata *nd)
670 struct v9fs_session_info *v9ses;
671 struct p9_fid *fid = NULL;
672 struct p9_fid *dfid, *ofid;
676 struct posix_acl *pacl = NULL, *dacl = NULL;
678 v9ses = v9fs_inode2v9ses(dir);
679 if (nd && nd->flags & LOOKUP_OPEN)
680 flags = nd->intent.open.flags - 1;
683 * create call without LOOKUP_OPEN is due
684 * to mknod of regular files. So use mknod
687 return v9fs_vfs_mknod_dotl(dir, dentry, omode, 0);
690 name = (char *) dentry->d_name.name;
691 P9_DPRINTK(P9_DEBUG_VFS, "v9fs_vfs_create_dotl: name:%s flags:0x%x "
692 "mode:0x%x\n", name, flags, omode);
694 dfid = v9fs_fid_lookup(dentry->d_parent);
697 P9_DPRINTK(P9_DEBUG_VFS, "fid lookup failed %d\n", err);
701 /* clone a fid to use for creation */
702 ofid = p9_client_walk(dfid, 0, NULL, 1);
705 P9_DPRINTK(P9_DEBUG_VFS, "p9_client_walk failed %d\n", err);
709 gid = v9fs_get_fsgid_for_create(dir);
712 /* Update mode based on ACL value */
713 err = v9fs_acl_mode(dir, &mode, &dacl, &pacl);
715 P9_DPRINTK(P9_DEBUG_VFS,
716 "Failed to get acl values in creat %d\n", err);
719 err = p9_client_create_dotl(ofid, name, flags, mode, gid, &qid);
721 P9_DPRINTK(P9_DEBUG_VFS,
722 "p9_client_open_dotl failed in creat %d\n",
726 /* instantiate inode and assign the unopened fid to the dentry */
727 if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE ||
728 (nd && nd->flags & LOOKUP_OPEN)) {
729 fid = p9_client_walk(dfid, 1, &name, 1);
732 P9_DPRINTK(P9_DEBUG_VFS, "p9_client_walk failed %d\n",
738 inode = v9fs_inode_from_fid(v9ses, fid, dir->i_sb);
740 err = PTR_ERR(inode);
741 P9_DPRINTK(P9_DEBUG_VFS, "inode creation failed %d\n",
745 dentry->d_op = &v9fs_cached_dentry_operations;
746 d_instantiate(dentry, inode);
747 err = v9fs_fid_add(dentry, fid);
750 /* The fid would get clunked via a dput */
754 * Not in cached mode. No need to populate
755 * inode with stat. We need to get an inode
756 * so that we can set the acl with dentry
758 inode = v9fs_get_inode(dir->i_sb, mode);
760 err = PTR_ERR(inode);
763 dentry->d_op = &v9fs_dentry_operations;
764 d_instantiate(dentry, inode);
766 /* Now set the ACL based on the default value */
767 v9fs_set_create_acl(dentry, dacl, pacl);
769 /* if we are opening a file, assign the open fid to the file */
770 if (nd && nd->flags & LOOKUP_OPEN) {
771 filp = lookup_instantiate_filp(nd, dentry, generic_file_open);
773 p9_client_clunk(ofid);
774 return PTR_ERR(filp);
776 filp->private_data = ofid;
778 p9_client_clunk(ofid);
784 p9_client_clunk(ofid);
786 p9_client_clunk(fid);
791 * v9fs_vfs_create - VFS hook to create files
792 * @dir: directory inode that is being created
793 * @dentry: dentry that is being deleted
794 * @mode: create permissions
795 * @nd: path information
800 v9fs_vfs_create(struct inode *dir, struct dentry *dentry, int mode,
801 struct nameidata *nd)
806 struct v9fs_session_info *v9ses;
812 v9ses = v9fs_inode2v9ses(dir);
813 perm = unixmode2p9mode(v9ses, mode);
814 if (nd && nd->flags & LOOKUP_OPEN)
815 flags = nd->intent.open.flags - 1;
819 fid = v9fs_create(v9ses, dir, dentry, NULL, perm,
820 v9fs_uflags2omode(flags,
821 v9fs_proto_dotu(v9ses)));
828 /* if we are opening a file, assign the open fid to the file */
829 if (nd && nd->flags & LOOKUP_OPEN) {
830 filp = lookup_instantiate_filp(nd, dentry, generic_file_open);
836 filp->private_data = fid;
838 p9_client_clunk(fid);
844 p9_client_clunk(fid);
850 * v9fs_vfs_mkdir - VFS mkdir hook to create a directory
851 * @dir: inode that is being unlinked
852 * @dentry: dentry that is being unlinked
853 * @mode: mode for new directory
857 static int v9fs_vfs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
861 struct v9fs_session_info *v9ses;
864 P9_DPRINTK(P9_DEBUG_VFS, "name %s\n", dentry->d_name.name);
866 v9ses = v9fs_inode2v9ses(dir);
867 perm = unixmode2p9mode(v9ses, mode | S_IFDIR);
868 fid = v9fs_create(v9ses, dir, dentry, NULL, perm, P9_OREAD);
875 p9_client_clunk(fid);
882 * v9fs_vfs_mkdir_dotl - VFS mkdir hook to create a directory
883 * @dir: inode that is being unlinked
884 * @dentry: dentry that is being unlinked
885 * @mode: mode for new directory
889 static int v9fs_vfs_mkdir_dotl(struct inode *dir,
890 struct dentry *dentry, int omode)
893 struct v9fs_session_info *v9ses;
894 struct p9_fid *fid = NULL, *dfid = NULL;
900 struct dentry *dir_dentry;
901 struct posix_acl *dacl = NULL, *pacl = NULL;
903 P9_DPRINTK(P9_DEBUG_VFS, "name %s\n", dentry->d_name.name);
905 v9ses = v9fs_inode2v9ses(dir);
908 if (dir->i_mode & S_ISGID)
911 dir_dentry = v9fs_dentry_from_dir_inode(dir);
912 dfid = v9fs_fid_lookup(dir_dentry);
915 P9_DPRINTK(P9_DEBUG_VFS, "fid lookup failed %d\n", err);
920 gid = v9fs_get_fsgid_for_create(dir);
922 /* Update mode based on ACL value */
923 err = v9fs_acl_mode(dir, &mode, &dacl, &pacl);
925 P9_DPRINTK(P9_DEBUG_VFS,
926 "Failed to get acl values in mkdir %d\n", err);
929 name = (char *) dentry->d_name.name;
930 err = p9_client_mkdir_dotl(dfid, name, mode, gid, &qid);
934 /* instantiate inode and assign the unopened fid to the dentry */
935 if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) {
936 fid = p9_client_walk(dfid, 1, &name, 1);
939 P9_DPRINTK(P9_DEBUG_VFS, "p9_client_walk failed %d\n",
945 inode = v9fs_inode_from_fid(v9ses, fid, dir->i_sb);
947 err = PTR_ERR(inode);
948 P9_DPRINTK(P9_DEBUG_VFS, "inode creation failed %d\n",
952 dentry->d_op = &v9fs_cached_dentry_operations;
953 d_instantiate(dentry, inode);
954 err = v9fs_fid_add(dentry, fid);
960 * Not in cached mode. No need to populate
961 * inode with stat. We need to get an inode
962 * so that we can set the acl with dentry
964 inode = v9fs_get_inode(dir->i_sb, mode);
966 err = PTR_ERR(inode);
969 dentry->d_op = &v9fs_dentry_operations;
970 d_instantiate(dentry, inode);
972 /* Now set the ACL based on the default value */
973 v9fs_set_create_acl(dentry, dacl, pacl);
977 p9_client_clunk(fid);
982 * v9fs_vfs_lookup - VFS lookup hook to "walk" to a new inode
983 * @dir: inode that is being walked from
984 * @dentry: dentry that is being walked to?
985 * @nameidata: path data
989 static struct dentry *v9fs_vfs_lookup(struct inode *dir, struct dentry *dentry,
990 struct nameidata *nameidata)
992 struct super_block *sb;
993 struct v9fs_session_info *v9ses;
994 struct p9_fid *dfid, *fid;
999 P9_DPRINTK(P9_DEBUG_VFS, "dir: %p dentry: (%s) %p nameidata: %p\n",
1000 dir, dentry->d_name.name, dentry, nameidata);
1002 if (dentry->d_name.len > NAME_MAX)
1003 return ERR_PTR(-ENAMETOOLONG);
1006 v9ses = v9fs_inode2v9ses(dir);
1007 /* We can walk d_parent because we hold the dir->i_mutex */
1008 dfid = v9fs_fid_lookup(dentry->d_parent);
1010 return ERR_CAST(dfid);
1012 name = (char *) dentry->d_name.name;
1013 fid = p9_client_walk(dfid, 1, &name, 1);
1015 result = PTR_ERR(fid);
1016 if (result == -ENOENT) {
1021 return ERR_PTR(result);
1024 inode = v9fs_inode_from_fid(v9ses, fid, dir->i_sb);
1025 if (IS_ERR(inode)) {
1026 result = PTR_ERR(inode);
1031 result = v9fs_fid_add(dentry, fid);
1037 dentry->d_op = &v9fs_cached_dentry_operations;
1039 dentry->d_op = &v9fs_dentry_operations;
1041 d_add(dentry, inode);
1047 p9_client_clunk(fid);
1049 return ERR_PTR(result);
1053 * v9fs_vfs_unlink - VFS unlink hook to delete an inode
1054 * @i: inode that is being unlinked
1055 * @d: dentry that is being unlinked
1059 static int v9fs_vfs_unlink(struct inode *i, struct dentry *d)
1061 return v9fs_remove(i, d, 0);
1065 * v9fs_vfs_rmdir - VFS unlink hook to delete a directory
1066 * @i: inode that is being unlinked
1067 * @d: dentry that is being unlinked
1071 static int v9fs_vfs_rmdir(struct inode *i, struct dentry *d)
1073 return v9fs_remove(i, d, 1);
1077 * v9fs_vfs_rename - VFS hook to rename an inode
1078 * @old_dir: old dir inode
1079 * @old_dentry: old dentry
1080 * @new_dir: new dir inode
1081 * @new_dentry: new dentry
1086 v9fs_vfs_rename(struct inode *old_dir, struct dentry *old_dentry,
1087 struct inode *new_dir, struct dentry *new_dentry)
1089 struct inode *old_inode;
1090 struct v9fs_session_info *v9ses;
1091 struct p9_fid *oldfid;
1092 struct p9_fid *olddirfid;
1093 struct p9_fid *newdirfid;
1094 struct p9_wstat wstat;
1097 P9_DPRINTK(P9_DEBUG_VFS, "\n");
1099 old_inode = old_dentry->d_inode;
1100 v9ses = v9fs_inode2v9ses(old_inode);
1101 oldfid = v9fs_fid_lookup(old_dentry);
1103 return PTR_ERR(oldfid);
1105 olddirfid = v9fs_fid_clone(old_dentry->d_parent);
1106 if (IS_ERR(olddirfid)) {
1107 retval = PTR_ERR(olddirfid);
1111 newdirfid = v9fs_fid_clone(new_dentry->d_parent);
1112 if (IS_ERR(newdirfid)) {
1113 retval = PTR_ERR(newdirfid);
1117 down_write(&v9ses->rename_sem);
1118 if (v9fs_proto_dotl(v9ses)) {
1119 retval = p9_client_rename(oldfid, newdirfid,
1120 (char *) new_dentry->d_name.name);
1121 if (retval != -ENOSYS)
1124 if (old_dentry->d_parent != new_dentry->d_parent) {
1126 * 9P .u can only handle file rename in the same directory
1129 P9_DPRINTK(P9_DEBUG_ERROR,
1130 "old dir and new dir are different\n");
1134 v9fs_blank_wstat(&wstat);
1135 wstat.muid = v9ses->uname;
1136 wstat.name = (char *) new_dentry->d_name.name;
1137 retval = p9_client_wstat(oldfid, &wstat);
1141 /* successful rename */
1142 d_move(old_dentry, new_dentry);
1143 up_write(&v9ses->rename_sem);
1144 p9_client_clunk(newdirfid);
1147 p9_client_clunk(olddirfid);
1154 * v9fs_vfs_getattr - retrieve file metadata
1155 * @mnt: mount information
1156 * @dentry: file to get attributes on
1157 * @stat: metadata structure to populate
1162 v9fs_vfs_getattr(struct vfsmount *mnt, struct dentry *dentry,
1166 struct v9fs_session_info *v9ses;
1168 struct p9_wstat *st;
1170 P9_DPRINTK(P9_DEBUG_VFS, "dentry: %p\n", dentry);
1172 v9ses = v9fs_inode2v9ses(dentry->d_inode);
1173 if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE)
1174 return simple_getattr(mnt, dentry, stat);
1176 fid = v9fs_fid_lookup(dentry);
1178 return PTR_ERR(fid);
1180 st = p9_client_stat(fid);
1184 v9fs_stat2inode(st, dentry->d_inode, dentry->d_inode->i_sb);
1185 generic_fillattr(dentry->d_inode, stat);
1193 v9fs_vfs_getattr_dotl(struct vfsmount *mnt, struct dentry *dentry,
1197 struct v9fs_session_info *v9ses;
1199 struct p9_stat_dotl *st;
1201 P9_DPRINTK(P9_DEBUG_VFS, "dentry: %p\n", dentry);
1203 v9ses = v9fs_inode2v9ses(dentry->d_inode);
1204 if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE)
1205 return simple_getattr(mnt, dentry, stat);
1207 fid = v9fs_fid_lookup(dentry);
1209 return PTR_ERR(fid);
1211 /* Ask for all the fields in stat structure. Server will return
1212 * whatever it supports
1215 st = p9_client_getattr_dotl(fid, P9_STATS_ALL);
1219 v9fs_stat2inode_dotl(st, dentry->d_inode);
1220 generic_fillattr(dentry->d_inode, stat);
1221 /* Change block size to what the server returned */
1222 stat->blksize = st->st_blksize;
1229 * v9fs_vfs_setattr - set file metadata
1230 * @dentry: file whose metadata to set
1231 * @iattr: metadata assignment structure
1235 static int v9fs_vfs_setattr(struct dentry *dentry, struct iattr *iattr)
1238 struct v9fs_session_info *v9ses;
1240 struct p9_wstat wstat;
1242 P9_DPRINTK(P9_DEBUG_VFS, "\n");
1244 v9ses = v9fs_inode2v9ses(dentry->d_inode);
1245 fid = v9fs_fid_lookup(dentry);
1247 return PTR_ERR(fid);
1249 v9fs_blank_wstat(&wstat);
1250 if (iattr->ia_valid & ATTR_MODE)
1251 wstat.mode = unixmode2p9mode(v9ses, iattr->ia_mode);
1253 if (iattr->ia_valid & ATTR_MTIME)
1254 wstat.mtime = iattr->ia_mtime.tv_sec;
1256 if (iattr->ia_valid & ATTR_ATIME)
1257 wstat.atime = iattr->ia_atime.tv_sec;
1259 if (iattr->ia_valid & ATTR_SIZE)
1260 wstat.length = iattr->ia_size;
1262 if (v9fs_proto_dotu(v9ses)) {
1263 if (iattr->ia_valid & ATTR_UID)
1264 wstat.n_uid = iattr->ia_uid;
1266 if (iattr->ia_valid & ATTR_GID)
1267 wstat.n_gid = iattr->ia_gid;
1270 retval = p9_client_wstat(fid, &wstat);
1274 if ((iattr->ia_valid & ATTR_SIZE) &&
1275 iattr->ia_size != i_size_read(dentry->d_inode)) {
1276 retval = vmtruncate(dentry->d_inode, iattr->ia_size);
1281 setattr_copy(dentry->d_inode, iattr);
1282 mark_inode_dirty(dentry->d_inode);
1287 * v9fs_vfs_setattr_dotl - set file metadata
1288 * @dentry: file whose metadata to set
1289 * @iattr: metadata assignment structure
1293 int v9fs_vfs_setattr_dotl(struct dentry *dentry, struct iattr *iattr)
1296 struct v9fs_session_info *v9ses;
1298 struct p9_iattr_dotl p9attr;
1300 P9_DPRINTK(P9_DEBUG_VFS, "\n");
1302 retval = inode_change_ok(dentry->d_inode, iattr);
1306 p9attr.valid = iattr->ia_valid;
1307 p9attr.mode = iattr->ia_mode;
1308 p9attr.uid = iattr->ia_uid;
1309 p9attr.gid = iattr->ia_gid;
1310 p9attr.size = iattr->ia_size;
1311 p9attr.atime_sec = iattr->ia_atime.tv_sec;
1312 p9attr.atime_nsec = iattr->ia_atime.tv_nsec;
1313 p9attr.mtime_sec = iattr->ia_mtime.tv_sec;
1314 p9attr.mtime_nsec = iattr->ia_mtime.tv_nsec;
1317 v9ses = v9fs_inode2v9ses(dentry->d_inode);
1318 fid = v9fs_fid_lookup(dentry);
1320 return PTR_ERR(fid);
1322 retval = p9_client_setattr(fid, &p9attr);
1326 if ((iattr->ia_valid & ATTR_SIZE) &&
1327 iattr->ia_size != i_size_read(dentry->d_inode)) {
1328 retval = vmtruncate(dentry->d_inode, iattr->ia_size);
1333 setattr_copy(dentry->d_inode, iattr);
1334 mark_inode_dirty(dentry->d_inode);
1335 if (iattr->ia_valid & ATTR_MODE) {
1336 /* We also want to update ACL when we update mode bits */
1337 retval = v9fs_acl_chmod(dentry);
1345 * v9fs_stat2inode - populate an inode structure with mistat info
1346 * @stat: Plan 9 metadata (mistat) structure
1347 * @inode: inode to populate
1348 * @sb: superblock of filesystem
1353 v9fs_stat2inode(struct p9_wstat *stat, struct inode *inode,
1354 struct super_block *sb)
1358 unsigned int i_nlink;
1359 struct v9fs_session_info *v9ses = sb->s_fs_info;
1363 inode->i_atime.tv_sec = stat->atime;
1364 inode->i_mtime.tv_sec = stat->mtime;
1365 inode->i_ctime.tv_sec = stat->mtime;
1367 inode->i_uid = v9ses->dfltuid;
1368 inode->i_gid = v9ses->dfltgid;
1370 if (v9fs_proto_dotu(v9ses)) {
1371 inode->i_uid = stat->n_uid;
1372 inode->i_gid = stat->n_gid;
1374 if ((S_ISREG(inode->i_mode)) || (S_ISDIR(inode->i_mode))) {
1375 if (v9fs_proto_dotu(v9ses) && (stat->extension[0] != '\0')) {
1377 * Hadlink support got added later to
1378 * to the .u extension. So there can be
1379 * server out there that doesn't support
1380 * this even with .u extension. So check
1381 * for non NULL stat->extension
1383 strncpy(ext, stat->extension, sizeof(ext));
1384 /* HARDLINKCOUNT %u */
1385 sscanf(ext, "%13s %u", tag_name, &i_nlink);
1386 if (!strncmp(tag_name, "HARDLINKCOUNT", 13))
1387 inode->i_nlink = i_nlink;
1390 inode->i_mode = p9mode2unixmode(v9ses, stat->mode);
1391 if ((S_ISBLK(inode->i_mode)) || (S_ISCHR(inode->i_mode))) {
1396 strncpy(ext, stat->extension, sizeof(ext));
1397 sscanf(ext, "%c %u %u", &type, &major, &minor);
1400 inode->i_mode &= ~S_IFBLK;
1401 inode->i_mode |= S_IFCHR;
1406 P9_DPRINTK(P9_DEBUG_ERROR,
1407 "Unknown special type %c %s\n", type,
1410 inode->i_rdev = MKDEV(major, minor);
1411 init_special_inode(inode, inode->i_mode, inode->i_rdev);
1415 i_size_write(inode, stat->length);
1417 /* not real number of blocks, but 512 byte ones ... */
1418 inode->i_blocks = (i_size_read(inode) + 512 - 1) >> 9;
1422 * v9fs_stat2inode_dotl - populate an inode structure with stat info
1423 * @stat: stat structure
1424 * @inode: inode to populate
1425 * @sb: superblock of filesystem
1430 v9fs_stat2inode_dotl(struct p9_stat_dotl *stat, struct inode *inode)
1433 if ((stat->st_result_mask & P9_STATS_BASIC) == P9_STATS_BASIC) {
1434 inode->i_atime.tv_sec = stat->st_atime_sec;
1435 inode->i_atime.tv_nsec = stat->st_atime_nsec;
1436 inode->i_mtime.tv_sec = stat->st_mtime_sec;
1437 inode->i_mtime.tv_nsec = stat->st_mtime_nsec;
1438 inode->i_ctime.tv_sec = stat->st_ctime_sec;
1439 inode->i_ctime.tv_nsec = stat->st_ctime_nsec;
1440 inode->i_uid = stat->st_uid;
1441 inode->i_gid = stat->st_gid;
1442 inode->i_nlink = stat->st_nlink;
1443 inode->i_mode = stat->st_mode;
1444 inode->i_rdev = new_decode_dev(stat->st_rdev);
1446 if ((S_ISBLK(inode->i_mode)) || (S_ISCHR(inode->i_mode)))
1447 init_special_inode(inode, inode->i_mode, inode->i_rdev);
1449 i_size_write(inode, stat->st_size);
1450 inode->i_blocks = stat->st_blocks;
1452 if (stat->st_result_mask & P9_STATS_ATIME) {
1453 inode->i_atime.tv_sec = stat->st_atime_sec;
1454 inode->i_atime.tv_nsec = stat->st_atime_nsec;
1456 if (stat->st_result_mask & P9_STATS_MTIME) {
1457 inode->i_mtime.tv_sec = stat->st_mtime_sec;
1458 inode->i_mtime.tv_nsec = stat->st_mtime_nsec;
1460 if (stat->st_result_mask & P9_STATS_CTIME) {
1461 inode->i_ctime.tv_sec = stat->st_ctime_sec;
1462 inode->i_ctime.tv_nsec = stat->st_ctime_nsec;
1464 if (stat->st_result_mask & P9_STATS_UID)
1465 inode->i_uid = stat->st_uid;
1466 if (stat->st_result_mask & P9_STATS_GID)
1467 inode->i_gid = stat->st_gid;
1468 if (stat->st_result_mask & P9_STATS_NLINK)
1469 inode->i_nlink = stat->st_nlink;
1470 if (stat->st_result_mask & P9_STATS_MODE) {
1471 inode->i_mode = stat->st_mode;
1472 if ((S_ISBLK(inode->i_mode)) ||
1473 (S_ISCHR(inode->i_mode)))
1474 init_special_inode(inode, inode->i_mode,
1477 if (stat->st_result_mask & P9_STATS_RDEV)
1478 inode->i_rdev = new_decode_dev(stat->st_rdev);
1479 if (stat->st_result_mask & P9_STATS_SIZE)
1480 i_size_write(inode, stat->st_size);
1481 if (stat->st_result_mask & P9_STATS_BLOCKS)
1482 inode->i_blocks = stat->st_blocks;
1484 if (stat->st_result_mask & P9_STATS_GEN)
1485 inode->i_generation = stat->st_gen;
1487 /* Currently we don't support P9_STATS_BTIME and P9_STATS_DATA_VERSION
1488 * because the inode structure does not have fields for them.
1493 * v9fs_qid2ino - convert qid into inode number
1496 * BUG: potential for inode number collisions?
1499 ino_t v9fs_qid2ino(struct p9_qid *qid)
1501 u64 path = qid->path + 2;
1504 if (sizeof(ino_t) == sizeof(path))
1505 memcpy(&i, &path, sizeof(ino_t));
1507 i = (ino_t) (path ^ (path >> 32));
1513 * v9fs_readlink - read a symlink's location (internal version)
1514 * @dentry: dentry for symlink
1515 * @buffer: buffer to load symlink location into
1516 * @buflen: length of buffer
1520 static int v9fs_readlink(struct dentry *dentry, char *buffer, int buflen)
1524 struct v9fs_session_info *v9ses;
1526 struct p9_wstat *st;
1528 P9_DPRINTK(P9_DEBUG_VFS, " %s\n", dentry->d_name.name);
1530 v9ses = v9fs_inode2v9ses(dentry->d_inode);
1531 fid = v9fs_fid_lookup(dentry);
1533 return PTR_ERR(fid);
1535 if (!v9fs_proto_dotu(v9ses))
1538 st = p9_client_stat(fid);
1542 if (!(st->mode & P9_DMSYMLINK)) {
1547 /* copy extension buffer into buffer */
1548 strncpy(buffer, st->extension, buflen);
1550 P9_DPRINTK(P9_DEBUG_VFS,
1551 "%s -> %s (%s)\n", dentry->d_name.name, st->extension, buffer);
1553 retval = strnlen(buffer, buflen);
1561 * v9fs_vfs_follow_link - follow a symlink path
1562 * @dentry: dentry for symlink
1567 static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
1570 char *link = __getname();
1572 P9_DPRINTK(P9_DEBUG_VFS, "%s n", dentry->d_name.name);
1575 link = ERR_PTR(-ENOMEM);
1577 len = v9fs_readlink(dentry, link, PATH_MAX);
1581 link = ERR_PTR(len);
1583 link[min(len, PATH_MAX-1)] = 0;
1585 nd_set_link(nd, link);
1591 * v9fs_vfs_put_link - release a symlink path
1592 * @dentry: dentry for symlink
1599 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
1601 char *s = nd_get_link(nd);
1603 P9_DPRINTK(P9_DEBUG_VFS, " %s %s\n", dentry->d_name.name,
1604 IS_ERR(s) ? "<error>" : s);
1610 * v9fs_vfs_mkspecial - create a special file
1611 * @dir: inode to create special file in
1612 * @dentry: dentry to create
1613 * @mode: mode to create special file
1614 * @extension: 9p2000.u format extension string representing special file
1618 static int v9fs_vfs_mkspecial(struct inode *dir, struct dentry *dentry,
1619 int mode, const char *extension)
1622 struct v9fs_session_info *v9ses;
1625 v9ses = v9fs_inode2v9ses(dir);
1626 if (!v9fs_proto_dotu(v9ses)) {
1627 P9_DPRINTK(P9_DEBUG_ERROR, "not extended\n");
1631 perm = unixmode2p9mode(v9ses, mode);
1632 fid = v9fs_create(v9ses, dir, dentry, (char *) extension, perm,
1635 return PTR_ERR(fid);
1637 p9_client_clunk(fid);
1642 * v9fs_vfs_symlink_dotl - helper function to create symlinks
1643 * @dir: directory inode containing symlink
1644 * @dentry: dentry for symlink
1645 * @symname: symlink data
1647 * See Also: 9P2000.L RFC for more information
1652 v9fs_vfs_symlink_dotl(struct inode *dir, struct dentry *dentry,
1653 const char *symname)
1655 struct v9fs_session_info *v9ses;
1656 struct p9_fid *dfid;
1657 struct p9_fid *fid = NULL;
1658 struct inode *inode;
1664 name = (char *) dentry->d_name.name;
1665 P9_DPRINTK(P9_DEBUG_VFS, "v9fs_vfs_symlink_dotl : %lu,%s,%s\n",
1666 dir->i_ino, name, symname);
1667 v9ses = v9fs_inode2v9ses(dir);
1669 dfid = v9fs_fid_lookup(dentry->d_parent);
1671 err = PTR_ERR(dfid);
1672 P9_DPRINTK(P9_DEBUG_VFS, "fid lookup failed %d\n", err);
1676 gid = v9fs_get_fsgid_for_create(dir);
1678 /* Server doesn't alter fid on TSYMLINK. Hence no need to clone it. */
1679 err = p9_client_symlink(dfid, name, (char *)symname, gid, &qid);
1682 P9_DPRINTK(P9_DEBUG_VFS, "p9_client_symlink failed %d\n", err);
1687 /* Now walk from the parent so we can get an unopened fid. */
1688 fid = p9_client_walk(dfid, 1, &name, 1);
1691 P9_DPRINTK(P9_DEBUG_VFS, "p9_client_walk failed %d\n",
1697 /* instantiate inode and assign the unopened fid to dentry */
1698 inode = v9fs_inode_from_fid(v9ses, fid, dir->i_sb);
1699 if (IS_ERR(inode)) {
1700 err = PTR_ERR(inode);
1701 P9_DPRINTK(P9_DEBUG_VFS, "inode creation failed %d\n",
1705 dentry->d_op = &v9fs_cached_dentry_operations;
1706 d_instantiate(dentry, inode);
1707 err = v9fs_fid_add(dentry, fid);
1712 /* Not in cached mode. No need to populate inode with stat */
1713 inode = v9fs_get_inode(dir->i_sb, S_IFLNK);
1714 if (IS_ERR(inode)) {
1715 err = PTR_ERR(inode);
1718 dentry->d_op = &v9fs_dentry_operations;
1719 d_instantiate(dentry, inode);
1724 p9_client_clunk(fid);
1730 * v9fs_vfs_symlink - helper function to create symlinks
1731 * @dir: directory inode containing symlink
1732 * @dentry: dentry for symlink
1733 * @symname: symlink data
1735 * See Also: 9P2000.u RFC for more information
1740 v9fs_vfs_symlink(struct inode *dir, struct dentry *dentry, const char *symname)
1742 P9_DPRINTK(P9_DEBUG_VFS, " %lu,%s,%s\n", dir->i_ino,
1743 dentry->d_name.name, symname);
1745 return v9fs_vfs_mkspecial(dir, dentry, S_IFLNK, symname);
1749 * v9fs_vfs_link - create a hardlink
1750 * @old_dentry: dentry for file to link to
1751 * @dir: inode destination for new link
1752 * @dentry: dentry for link
1757 v9fs_vfs_link(struct dentry *old_dentry, struct inode *dir,
1758 struct dentry *dentry)
1761 struct p9_fid *oldfid;
1764 P9_DPRINTK(P9_DEBUG_VFS,
1765 " %lu,%s,%s\n", dir->i_ino, dentry->d_name.name,
1766 old_dentry->d_name.name);
1768 oldfid = v9fs_fid_clone(old_dentry);
1770 return PTR_ERR(oldfid);
1773 if (unlikely(!name)) {
1778 sprintf(name, "%d\n", oldfid->fid);
1779 retval = v9fs_vfs_mkspecial(dir, dentry, P9_DMLINK, name);
1783 p9_client_clunk(oldfid);
1788 * v9fs_vfs_link_dotl - create a hardlink for dotl
1789 * @old_dentry: dentry for file to link to
1790 * @dir: inode destination for new link
1791 * @dentry: dentry for link
1796 v9fs_vfs_link_dotl(struct dentry *old_dentry, struct inode *dir,
1797 struct dentry *dentry)
1800 struct p9_fid *dfid, *oldfid;
1802 struct v9fs_session_info *v9ses;
1803 struct dentry *dir_dentry;
1805 P9_DPRINTK(P9_DEBUG_VFS, "dir ino: %lu, old_name: %s, new_name: %s\n",
1806 dir->i_ino, old_dentry->d_name.name,
1807 dentry->d_name.name);
1809 v9ses = v9fs_inode2v9ses(dir);
1810 dir_dentry = v9fs_dentry_from_dir_inode(dir);
1811 dfid = v9fs_fid_lookup(dir_dentry);
1813 return PTR_ERR(dfid);
1815 oldfid = v9fs_fid_lookup(old_dentry);
1817 return PTR_ERR(oldfid);
1819 name = (char *) dentry->d_name.name;
1821 err = p9_client_link(dfid, oldfid, (char *)dentry->d_name.name);
1824 P9_DPRINTK(P9_DEBUG_VFS, "p9_client_link failed %d\n", err);
1828 if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) {
1829 /* Get the latest stat info from server. */
1831 struct p9_stat_dotl *st;
1833 fid = v9fs_fid_lookup(old_dentry);
1835 return PTR_ERR(fid);
1837 st = p9_client_getattr_dotl(fid, P9_STATS_BASIC);
1841 v9fs_stat2inode_dotl(st, old_dentry->d_inode);
1845 /* Caching disabled. No need to get upto date stat info.
1846 * This dentry will be released immediately. So, just hold the
1849 ihold(old_dentry->d_inode);
1852 dentry->d_op = old_dentry->d_op;
1853 d_instantiate(dentry, old_dentry->d_inode);
1859 * v9fs_vfs_mknod - create a special file
1860 * @dir: inode destination for new link
1861 * @dentry: dentry for file
1862 * @mode: mode for creation
1863 * @rdev: device associated with special file
1868 v9fs_vfs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t rdev)
1873 P9_DPRINTK(P9_DEBUG_VFS,
1874 " %lu,%s mode: %x MAJOR: %u MINOR: %u\n", dir->i_ino,
1875 dentry->d_name.name, mode, MAJOR(rdev), MINOR(rdev));
1877 if (!new_valid_dev(rdev))
1883 /* build extension */
1885 sprintf(name, "b %u %u", MAJOR(rdev), MINOR(rdev));
1886 else if (S_ISCHR(mode))
1887 sprintf(name, "c %u %u", MAJOR(rdev), MINOR(rdev));
1888 else if (S_ISFIFO(mode))
1890 else if (S_ISSOCK(mode))
1897 retval = v9fs_vfs_mkspecial(dir, dentry, mode, name);
1904 * v9fs_vfs_mknod_dotl - create a special file
1905 * @dir: inode destination for new link
1906 * @dentry: dentry for file
1907 * @mode: mode for creation
1908 * @rdev: device associated with special file
1912 v9fs_vfs_mknod_dotl(struct inode *dir, struct dentry *dentry, int omode,
1918 struct v9fs_session_info *v9ses;
1919 struct p9_fid *fid = NULL, *dfid = NULL;
1920 struct inode *inode;
1923 struct dentry *dir_dentry;
1924 struct posix_acl *dacl = NULL, *pacl = NULL;
1926 P9_DPRINTK(P9_DEBUG_VFS,
1927 " %lu,%s mode: %x MAJOR: %u MINOR: %u\n", dir->i_ino,
1928 dentry->d_name.name, omode, MAJOR(rdev), MINOR(rdev));
1930 if (!new_valid_dev(rdev))
1933 v9ses = v9fs_inode2v9ses(dir);
1934 dir_dentry = v9fs_dentry_from_dir_inode(dir);
1935 dfid = v9fs_fid_lookup(dir_dentry);
1937 err = PTR_ERR(dfid);
1938 P9_DPRINTK(P9_DEBUG_VFS, "fid lookup failed %d\n", err);
1943 gid = v9fs_get_fsgid_for_create(dir);
1945 /* Update mode based on ACL value */
1946 err = v9fs_acl_mode(dir, &mode, &dacl, &pacl);
1948 P9_DPRINTK(P9_DEBUG_VFS,
1949 "Failed to get acl values in mknod %d\n", err);
1952 name = (char *) dentry->d_name.name;
1954 err = p9_client_mknod_dotl(dfid, name, mode, rdev, gid, &qid);
1958 /* instantiate inode and assign the unopened fid to the dentry */
1959 if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) {
1960 fid = p9_client_walk(dfid, 1, &name, 1);
1963 P9_DPRINTK(P9_DEBUG_VFS, "p9_client_walk failed %d\n",
1969 inode = v9fs_inode_from_fid(v9ses, fid, dir->i_sb);
1970 if (IS_ERR(inode)) {
1971 err = PTR_ERR(inode);
1972 P9_DPRINTK(P9_DEBUG_VFS, "inode creation failed %d\n",
1976 dentry->d_op = &v9fs_cached_dentry_operations;
1977 d_instantiate(dentry, inode);
1978 err = v9fs_fid_add(dentry, fid);
1984 * Not in cached mode. No need to populate inode with stat.
1985 * socket syscall returns a fd, so we need instantiate
1987 inode = v9fs_get_inode(dir->i_sb, mode);
1988 if (IS_ERR(inode)) {
1989 err = PTR_ERR(inode);
1992 dentry->d_op = &v9fs_dentry_operations;
1993 d_instantiate(dentry, inode);
1995 /* Now set the ACL based on the default value */
1996 v9fs_set_create_acl(dentry, dacl, pacl);
1999 p9_client_clunk(fid);
2004 v9fs_vfs_readlink_dotl(struct dentry *dentry, char *buffer, int buflen)
2008 char *target = NULL;
2010 P9_DPRINTK(P9_DEBUG_VFS, " %s\n", dentry->d_name.name);
2012 fid = v9fs_fid_lookup(dentry);
2014 return PTR_ERR(fid);
2016 retval = p9_client_readlink(fid, &target);
2020 strncpy(buffer, target, buflen);
2021 P9_DPRINTK(P9_DEBUG_VFS, "%s -> %s\n", dentry->d_name.name, buffer);
2023 retval = strnlen(buffer, buflen);
2028 * v9fs_vfs_follow_link_dotl - follow a symlink path
2029 * @dentry: dentry for symlink
2035 v9fs_vfs_follow_link_dotl(struct dentry *dentry, struct nameidata *nd)
2038 char *link = __getname();
2040 P9_DPRINTK(P9_DEBUG_VFS, "%s n", dentry->d_name.name);
2043 link = ERR_PTR(-ENOMEM);
2045 len = v9fs_vfs_readlink_dotl(dentry, link, PATH_MAX);
2048 link = ERR_PTR(len);
2050 link[min(len, PATH_MAX-1)] = 0;
2052 nd_set_link(nd, link);
2057 static const struct inode_operations v9fs_dir_inode_operations_dotu = {
2058 .create = v9fs_vfs_create,
2059 .lookup = v9fs_vfs_lookup,
2060 .symlink = v9fs_vfs_symlink,
2061 .link = v9fs_vfs_link,
2062 .unlink = v9fs_vfs_unlink,
2063 .mkdir = v9fs_vfs_mkdir,
2064 .rmdir = v9fs_vfs_rmdir,
2065 .mknod = v9fs_vfs_mknod,
2066 .rename = v9fs_vfs_rename,
2067 .getattr = v9fs_vfs_getattr,
2068 .setattr = v9fs_vfs_setattr,
2071 static const struct inode_operations v9fs_dir_inode_operations_dotl = {
2072 .create = v9fs_vfs_create_dotl,
2073 .lookup = v9fs_vfs_lookup,
2074 .link = v9fs_vfs_link_dotl,
2075 .symlink = v9fs_vfs_symlink_dotl,
2076 .unlink = v9fs_vfs_unlink,
2077 .mkdir = v9fs_vfs_mkdir_dotl,
2078 .rmdir = v9fs_vfs_rmdir,
2079 .mknod = v9fs_vfs_mknod_dotl,
2080 .rename = v9fs_vfs_rename,
2081 .getattr = v9fs_vfs_getattr_dotl,
2082 .setattr = v9fs_vfs_setattr_dotl,
2083 .setxattr = generic_setxattr,
2084 .getxattr = generic_getxattr,
2085 .removexattr = generic_removexattr,
2086 .listxattr = v9fs_listxattr,
2087 .check_acl = v9fs_check_acl,
2090 static const struct inode_operations v9fs_dir_inode_operations = {
2091 .create = v9fs_vfs_create,
2092 .lookup = v9fs_vfs_lookup,
2093 .unlink = v9fs_vfs_unlink,
2094 .mkdir = v9fs_vfs_mkdir,
2095 .rmdir = v9fs_vfs_rmdir,
2096 .mknod = v9fs_vfs_mknod,
2097 .rename = v9fs_vfs_rename,
2098 .getattr = v9fs_vfs_getattr,
2099 .setattr = v9fs_vfs_setattr,
2102 static const struct inode_operations v9fs_file_inode_operations = {
2103 .getattr = v9fs_vfs_getattr,
2104 .setattr = v9fs_vfs_setattr,
2107 static const struct inode_operations v9fs_file_inode_operations_dotl = {
2108 .getattr = v9fs_vfs_getattr_dotl,
2109 .setattr = v9fs_vfs_setattr_dotl,
2110 .setxattr = generic_setxattr,
2111 .getxattr = generic_getxattr,
2112 .removexattr = generic_removexattr,
2113 .listxattr = v9fs_listxattr,
2114 .check_acl = v9fs_check_acl,
2117 static const struct inode_operations v9fs_symlink_inode_operations = {
2118 .readlink = generic_readlink,
2119 .follow_link = v9fs_vfs_follow_link,
2120 .put_link = v9fs_vfs_put_link,
2121 .getattr = v9fs_vfs_getattr,
2122 .setattr = v9fs_vfs_setattr,
2125 static const struct inode_operations v9fs_symlink_inode_operations_dotl = {
2126 .readlink = v9fs_vfs_readlink_dotl,
2127 .follow_link = v9fs_vfs_follow_link_dotl,
2128 .put_link = v9fs_vfs_put_link,
2129 .getattr = v9fs_vfs_getattr_dotl,
2130 .setattr = v9fs_vfs_setattr_dotl,
2131 .setxattr = generic_setxattr,
2132 .getxattr = generic_getxattr,
2133 .removexattr = generic_removexattr,
2134 .listxattr = v9fs_listxattr,