aboutsummaryrefslogtreecommitdiffstats
path: root/fs/9p
diff options
context:
space:
mode:
Diffstat (limited to 'fs/9p')
-rw-r--r--fs/9p/Kconfig5
-rw-r--r--fs/9p/Makefile1
-rw-r--r--fs/9p/acl.c4
-rw-r--r--fs/9p/v9fs.h42
-rw-r--r--fs/9p/vfs_inode.c871
-rw-r--r--fs/9p/vfs_inode_dotl.c824
-rw-r--r--fs/9p/xattr.c2
7 files changed, 877 insertions, 872 deletions
diff --git a/fs/9p/Kconfig b/fs/9p/Kconfig
index 7e0511476797..814ac4e213a8 100644
--- a/fs/9p/Kconfig
+++ b/fs/9p/Kconfig
@@ -9,6 +9,8 @@ config 9P_FS
9 9
10 If unsure, say N. 10 If unsure, say N.
11 11
12if 9P_FS
13
12config 9P_FSCACHE 14config 9P_FSCACHE
13 bool "Enable 9P client caching support (EXPERIMENTAL)" 15 bool "Enable 9P client caching support (EXPERIMENTAL)"
14 depends on EXPERIMENTAL 16 depends on EXPERIMENTAL
@@ -20,7 +22,6 @@ config 9P_FSCACHE
20 22
21config 9P_FS_POSIX_ACL 23config 9P_FS_POSIX_ACL
22 bool "9P POSIX Access Control Lists" 24 bool "9P POSIX Access Control Lists"
23 depends on 9P_FS
24 select FS_POSIX_ACL 25 select FS_POSIX_ACL
25 help 26 help
26 POSIX Access Control Lists (ACLs) support permissions for users and 27 POSIX Access Control Lists (ACLs) support permissions for users and
@@ -30,3 +31,5 @@ config 9P_FS_POSIX_ACL
30 Linux website <http://acl.bestbits.at/>. 31 Linux website <http://acl.bestbits.at/>.
31 32
32 If you don't know what Access Control Lists are, say N 33 If you don't know what Access Control Lists are, say N
34
35endif
diff --git a/fs/9p/Makefile b/fs/9p/Makefile
index f8ba37effd1b..ab8c12780634 100644
--- a/fs/9p/Makefile
+++ b/fs/9p/Makefile
@@ -3,6 +3,7 @@ obj-$(CONFIG_9P_FS) := 9p.o
39p-objs := \ 39p-objs := \
4 vfs_super.o \ 4 vfs_super.o \
5 vfs_inode.o \ 5 vfs_inode.o \
6 vfs_inode_dotl.o \
6 vfs_addr.o \ 7 vfs_addr.o \
7 vfs_file.o \ 8 vfs_file.o \
8 vfs_dir.o \ 9 vfs_dir.o \
diff --git a/fs/9p/acl.c b/fs/9p/acl.c
index 6e58c4ca1e6e..02a2cf616318 100644
--- a/fs/9p/acl.c
+++ b/fs/9p/acl.c
@@ -28,7 +28,7 @@ static struct posix_acl *__v9fs_get_acl(struct p9_fid *fid, char *name)
28{ 28{
29 ssize_t size; 29 ssize_t size;
30 void *value = NULL; 30 void *value = NULL;
31 struct posix_acl *acl = NULL;; 31 struct posix_acl *acl = NULL;
32 32
33 size = v9fs_fid_xattr_get(fid, name, NULL, 0); 33 size = v9fs_fid_xattr_get(fid, name, NULL, 0);
34 if (size > 0) { 34 if (size > 0) {
@@ -365,7 +365,7 @@ static int v9fs_xattr_set_acl(struct dentry *dentry, const char *name,
365 case ACL_TYPE_DEFAULT: 365 case ACL_TYPE_DEFAULT:
366 name = POSIX_ACL_XATTR_DEFAULT; 366 name = POSIX_ACL_XATTR_DEFAULT;
367 if (!S_ISDIR(inode->i_mode)) { 367 if (!S_ISDIR(inode->i_mode)) {
368 retval = -EINVAL; 368 retval = acl ? -EINVAL : 0;
369 goto err_out; 369 goto err_out;
370 } 370 }
371 break; 371 break;
diff --git a/fs/9p/v9fs.h b/fs/9p/v9fs.h
index cb6396855e2d..c4b5d8864f0d 100644
--- a/fs/9p/v9fs.h
+++ b/fs/9p/v9fs.h
@@ -113,9 +113,27 @@ struct v9fs_session_info {
113 113
114struct p9_fid *v9fs_session_init(struct v9fs_session_info *, const char *, 114struct p9_fid *v9fs_session_init(struct v9fs_session_info *, const char *,
115 char *); 115 char *);
116void v9fs_session_close(struct v9fs_session_info *v9ses); 116extern void v9fs_session_close(struct v9fs_session_info *v9ses);
117void v9fs_session_cancel(struct v9fs_session_info *v9ses); 117extern void v9fs_session_cancel(struct v9fs_session_info *v9ses);
118void v9fs_session_begin_cancel(struct v9fs_session_info *v9ses); 118extern void v9fs_session_begin_cancel(struct v9fs_session_info *v9ses);
119extern struct dentry *v9fs_vfs_lookup(struct inode *dir, struct dentry *dentry,
120 struct nameidata *nameidata);
121extern int v9fs_vfs_unlink(struct inode *i, struct dentry *d);
122extern int v9fs_vfs_rmdir(struct inode *i, struct dentry *d);
123extern int v9fs_vfs_rename(struct inode *old_dir, struct dentry *old_dentry,
124 struct inode *new_dir, struct dentry *new_dentry);
125extern void v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd,
126 void *p);
127extern struct inode *v9fs_inode(struct v9fs_session_info *v9ses,
128 struct p9_fid *fid,
129 struct super_block *sb);
130
131extern const struct inode_operations v9fs_dir_inode_operations_dotl;
132extern const struct inode_operations v9fs_file_inode_operations_dotl;
133extern const struct inode_operations v9fs_symlink_inode_operations_dotl;
134extern struct inode *v9fs_inode_dotl(struct v9fs_session_info *v9ses,
135 struct p9_fid *fid,
136 struct super_block *sb);
119 137
120/* other default globals */ 138/* other default globals */
121#define V9FS_PORT 564 139#define V9FS_PORT 564
@@ -138,3 +156,21 @@ static inline int v9fs_proto_dotl(struct v9fs_session_info *v9ses)
138{ 156{
139 return v9ses->flags & V9FS_PROTO_2000L; 157 return v9ses->flags & V9FS_PROTO_2000L;
140} 158}
159
160/**
161 * v9fs_inode_from_fid - Helper routine to populate an inode by
162 * issuing a attribute request
163 * @v9ses: session information
164 * @fid: fid to issue attribute request for
165 * @sb: superblock on which to create inode
166 *
167 */
168static inline struct inode *
169v9fs_inode_from_fid(struct v9fs_session_info *v9ses, struct p9_fid *fid,
170 struct super_block *sb)
171{
172 if (v9fs_proto_dotl(v9ses))
173 return v9fs_inode_dotl(v9ses, fid, sb);
174 else
175 return v9fs_inode(v9ses, fid, sb);
176}
diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
index 59782981b225..5076eeb95502 100644
--- a/fs/9p/vfs_inode.c
+++ b/fs/9p/vfs_inode.c
@@ -49,15 +49,8 @@
49 49
50static const struct inode_operations v9fs_dir_inode_operations; 50static const struct inode_operations v9fs_dir_inode_operations;
51static const struct inode_operations v9fs_dir_inode_operations_dotu; 51static const struct inode_operations v9fs_dir_inode_operations_dotu;
52static const struct inode_operations v9fs_dir_inode_operations_dotl;
53static const struct inode_operations v9fs_file_inode_operations; 52static const struct inode_operations v9fs_file_inode_operations;
54static const struct inode_operations v9fs_file_inode_operations_dotl;
55static const struct inode_operations v9fs_symlink_inode_operations; 53static const struct inode_operations v9fs_symlink_inode_operations;
56static const struct inode_operations v9fs_symlink_inode_operations_dotl;
57
58static int
59v9fs_vfs_mknod_dotl(struct inode *dir, struct dentry *dentry, int omode,
60 dev_t rdev);
61 54
62/** 55/**
63 * unixmode2p9mode - convert unix mode bits to plan 9 56 * unixmode2p9mode - convert unix mode bits to plan 9
@@ -251,41 +244,6 @@ void v9fs_destroy_inode(struct inode *inode)
251#endif 244#endif
252 245
253/** 246/**
254 * v9fs_get_fsgid_for_create - Helper function to get the gid for creating a
255 * new file system object. This checks the S_ISGID to determine the owning
256 * group of the new file system object.
257 */
258
259static gid_t v9fs_get_fsgid_for_create(struct inode *dir_inode)
260{
261 BUG_ON(dir_inode == NULL);
262
263 if (dir_inode->i_mode & S_ISGID) {
264 /* set_gid bit is set.*/
265 return dir_inode->i_gid;
266 }
267 return current_fsgid();
268}
269
270/**
271 * v9fs_dentry_from_dir_inode - helper function to get the dentry from
272 * dir inode.
273 *
274 */
275
276static struct dentry *v9fs_dentry_from_dir_inode(struct inode *inode)
277{
278 struct dentry *dentry;
279
280 spin_lock(&inode->i_lock);
281 /* Directory should have only one entry. */
282 BUG_ON(S_ISDIR(inode->i_mode) && !list_is_singular(&inode->i_dentry));
283 dentry = list_entry(inode->i_dentry.next, struct dentry, d_alias);
284 spin_unlock(&inode->i_lock);
285 return dentry;
286}
287
288/**
289 * v9fs_get_inode - helper function to setup an inode 247 * v9fs_get_inode - helper function to setup an inode
290 * @sb: superblock 248 * @sb: superblock
291 * @mode: mode to setup inode with 249 * @mode: mode to setup inode with
@@ -454,7 +412,7 @@ void v9fs_evict_inode(struct inode *inode)
454#endif 412#endif
455} 413}
456 414
457static struct inode * 415struct inode *
458v9fs_inode(struct v9fs_session_info *v9ses, struct p9_fid *fid, 416v9fs_inode(struct v9fs_session_info *v9ses, struct p9_fid *fid,
459 struct super_block *sb) 417 struct super_block *sb)
460{ 418{
@@ -489,60 +447,6 @@ error:
489 return ERR_PTR(err); 447 return ERR_PTR(err);
490} 448}
491 449
492static struct inode *
493v9fs_inode_dotl(struct v9fs_session_info *v9ses, struct p9_fid *fid,
494 struct super_block *sb)
495{
496 struct inode *ret = NULL;
497 int err;
498 struct p9_stat_dotl *st;
499
500 st = p9_client_getattr_dotl(fid, P9_STATS_BASIC);
501 if (IS_ERR(st))
502 return ERR_CAST(st);
503
504 ret = v9fs_get_inode(sb, st->st_mode);
505 if (IS_ERR(ret)) {
506 err = PTR_ERR(ret);
507 goto error;
508 }
509
510 v9fs_stat2inode_dotl(st, ret);
511 ret->i_ino = v9fs_qid2ino(&st->qid);
512#ifdef CONFIG_9P_FSCACHE
513 v9fs_vcookie_set_qid(ret, &st->qid);
514 v9fs_cache_inode_get_cookie(ret);
515#endif
516 err = v9fs_get_acl(ret, fid);
517 if (err) {
518 iput(ret);
519 goto error;
520 }
521 kfree(st);
522 return ret;
523error:
524 kfree(st);
525 return ERR_PTR(err);
526}
527
528/**
529 * v9fs_inode_from_fid - Helper routine to populate an inode by
530 * issuing a attribute request
531 * @v9ses: session information
532 * @fid: fid to issue attribute request for
533 * @sb: superblock on which to create inode
534 *
535 */
536static inline struct inode *
537v9fs_inode_from_fid(struct v9fs_session_info *v9ses, struct p9_fid *fid,
538 struct super_block *sb)
539{
540 if (v9fs_proto_dotl(v9ses))
541 return v9fs_inode_dotl(v9ses, fid, sb);
542 else
543 return v9fs_inode(v9ses, fid, sb);
544}
545
546/** 450/**
547 * v9fs_remove - helper function to remove files and directories 451 * v9fs_remove - helper function to remove files and directories
548 * @dir: directory inode that is being deleted 452 * @dir: directory inode that is being deleted
@@ -633,12 +537,6 @@ v9fs_create(struct v9fs_session_info *v9ses, struct inode *dir,
633 P9_DPRINTK(P9_DEBUG_VFS, "inode creation failed %d\n", err); 537 P9_DPRINTK(P9_DEBUG_VFS, "inode creation failed %d\n", err);
634 goto error; 538 goto error;
635 } 539 }
636
637 if (v9ses->cache)
638 d_set_d_op(dentry, &v9fs_cached_dentry_operations);
639 else
640 d_set_d_op(dentry, &v9fs_dentry_operations);
641
642 d_instantiate(dentry, inode); 540 d_instantiate(dentry, inode);
643 err = v9fs_fid_add(dentry, fid); 541 err = v9fs_fid_add(dentry, fid);
644 if (err < 0) 542 if (err < 0)
@@ -657,144 +555,6 @@ error:
657} 555}
658 556
659/** 557/**
660 * v9fs_vfs_create_dotl - VFS hook to create files for 9P2000.L protocol.
661 * @dir: directory inode that is being created
662 * @dentry: dentry that is being deleted
663 * @mode: create permissions
664 * @nd: path information
665 *
666 */
667
668static int
669v9fs_vfs_create_dotl(struct inode *dir, struct dentry *dentry, int omode,
670 struct nameidata *nd)
671{
672 int err = 0;
673 char *name = NULL;
674 gid_t gid;
675 int flags;
676 mode_t mode;
677 struct v9fs_session_info *v9ses;
678 struct p9_fid *fid = NULL;
679 struct p9_fid *dfid, *ofid;
680 struct file *filp;
681 struct p9_qid qid;
682 struct inode *inode;
683 struct posix_acl *pacl = NULL, *dacl = NULL;
684
685 v9ses = v9fs_inode2v9ses(dir);
686 if (nd && nd->flags & LOOKUP_OPEN)
687 flags = nd->intent.open.flags - 1;
688 else {
689 /*
690 * create call without LOOKUP_OPEN is due
691 * to mknod of regular files. So use mknod
692 * operation.
693 */
694 return v9fs_vfs_mknod_dotl(dir, dentry, omode, 0);
695 }
696
697 name = (char *) dentry->d_name.name;
698 P9_DPRINTK(P9_DEBUG_VFS, "v9fs_vfs_create_dotl: name:%s flags:0x%x "
699 "mode:0x%x\n", name, flags, omode);
700
701 dfid = v9fs_fid_lookup(dentry->d_parent);
702 if (IS_ERR(dfid)) {
703 err = PTR_ERR(dfid);
704 P9_DPRINTK(P9_DEBUG_VFS, "fid lookup failed %d\n", err);
705 return err;
706 }
707
708 /* clone a fid to use for creation */
709 ofid = p9_client_walk(dfid, 0, NULL, 1);
710 if (IS_ERR(ofid)) {
711 err = PTR_ERR(ofid);
712 P9_DPRINTK(P9_DEBUG_VFS, "p9_client_walk failed %d\n", err);
713 return err;
714 }
715
716 gid = v9fs_get_fsgid_for_create(dir);
717
718 mode = omode;
719 /* Update mode based on ACL value */
720 err = v9fs_acl_mode(dir, &mode, &dacl, &pacl);
721 if (err) {
722 P9_DPRINTK(P9_DEBUG_VFS,
723 "Failed to get acl values in creat %d\n", err);
724 goto error;
725 }
726 err = p9_client_create_dotl(ofid, name, flags, mode, gid, &qid);
727 if (err < 0) {
728 P9_DPRINTK(P9_DEBUG_VFS,
729 "p9_client_open_dotl failed in creat %d\n",
730 err);
731 goto error;
732 }
733 /* instantiate inode and assign the unopened fid to the dentry */
734 if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE ||
735 (nd && nd->flags & LOOKUP_OPEN)) {
736 fid = p9_client_walk(dfid, 1, &name, 1);
737 if (IS_ERR(fid)) {
738 err = PTR_ERR(fid);
739 P9_DPRINTK(P9_DEBUG_VFS, "p9_client_walk failed %d\n",
740 err);
741 fid = NULL;
742 goto error;
743 }
744
745 inode = v9fs_inode_from_fid(v9ses, fid, dir->i_sb);
746 if (IS_ERR(inode)) {
747 err = PTR_ERR(inode);
748 P9_DPRINTK(P9_DEBUG_VFS, "inode creation failed %d\n",
749 err);
750 goto error;
751 }
752 d_set_d_op(dentry, &v9fs_cached_dentry_operations);
753 d_instantiate(dentry, inode);
754 err = v9fs_fid_add(dentry, fid);
755 if (err < 0)
756 goto error;
757 /* The fid would get clunked via a dput */
758 fid = NULL;
759 } else {
760 /*
761 * Not in cached mode. No need to populate
762 * inode with stat. We need to get an inode
763 * so that we can set the acl with dentry
764 */
765 inode = v9fs_get_inode(dir->i_sb, mode);
766 if (IS_ERR(inode)) {
767 err = PTR_ERR(inode);
768 goto error;
769 }
770 d_set_d_op(dentry, &v9fs_dentry_operations);
771 d_instantiate(dentry, inode);
772 }
773 /* Now set the ACL based on the default value */
774 v9fs_set_create_acl(dentry, dacl, pacl);
775
776 /* if we are opening a file, assign the open fid to the file */
777 if (nd && nd->flags & LOOKUP_OPEN) {
778 filp = lookup_instantiate_filp(nd, dentry, generic_file_open);
779 if (IS_ERR(filp)) {
780 p9_client_clunk(ofid);
781 return PTR_ERR(filp);
782 }
783 filp->private_data = ofid;
784 } else
785 p9_client_clunk(ofid);
786
787 return 0;
788
789error:
790 if (ofid)
791 p9_client_clunk(ofid);
792 if (fid)
793 p9_client_clunk(fid);
794 return err;
795}
796
797/**
798 * v9fs_vfs_create - VFS hook to create files 558 * v9fs_vfs_create - VFS hook to create files
799 * @dir: directory inode that is being created 559 * @dir: directory inode that is being created
800 * @dentry: dentry that is being deleted 560 * @dentry: dentry that is being deleted
@@ -884,107 +644,6 @@ static int v9fs_vfs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
884 return err; 644 return err;
885} 645}
886 646
887
888/**
889 * v9fs_vfs_mkdir_dotl - VFS mkdir hook to create a directory
890 * @dir: inode that is being unlinked
891 * @dentry: dentry that is being unlinked
892 * @mode: mode for new directory
893 *
894 */
895
896static int v9fs_vfs_mkdir_dotl(struct inode *dir,
897 struct dentry *dentry, int omode)
898{
899 int err;
900 struct v9fs_session_info *v9ses;
901 struct p9_fid *fid = NULL, *dfid = NULL;
902 gid_t gid;
903 char *name;
904 mode_t mode;
905 struct inode *inode;
906 struct p9_qid qid;
907 struct dentry *dir_dentry;
908 struct posix_acl *dacl = NULL, *pacl = NULL;
909
910 P9_DPRINTK(P9_DEBUG_VFS, "name %s\n", dentry->d_name.name);
911 err = 0;
912 v9ses = v9fs_inode2v9ses(dir);
913
914 omode |= S_IFDIR;
915 if (dir->i_mode & S_ISGID)
916 omode |= S_ISGID;
917
918 dir_dentry = v9fs_dentry_from_dir_inode(dir);
919 dfid = v9fs_fid_lookup(dir_dentry);
920 if (IS_ERR(dfid)) {
921 err = PTR_ERR(dfid);
922 P9_DPRINTK(P9_DEBUG_VFS, "fid lookup failed %d\n", err);
923 dfid = NULL;
924 goto error;
925 }
926
927 gid = v9fs_get_fsgid_for_create(dir);
928 mode = omode;
929 /* Update mode based on ACL value */
930 err = v9fs_acl_mode(dir, &mode, &dacl, &pacl);
931 if (err) {
932 P9_DPRINTK(P9_DEBUG_VFS,
933 "Failed to get acl values in mkdir %d\n", err);
934 goto error;
935 }
936 name = (char *) dentry->d_name.name;
937 err = p9_client_mkdir_dotl(dfid, name, mode, gid, &qid);
938 if (err < 0)
939 goto error;
940
941 /* instantiate inode and assign the unopened fid to the dentry */
942 if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) {
943 fid = p9_client_walk(dfid, 1, &name, 1);
944 if (IS_ERR(fid)) {
945 err = PTR_ERR(fid);
946 P9_DPRINTK(P9_DEBUG_VFS, "p9_client_walk failed %d\n",
947 err);
948 fid = NULL;
949 goto error;
950 }
951
952 inode = v9fs_inode_from_fid(v9ses, fid, dir->i_sb);
953 if (IS_ERR(inode)) {
954 err = PTR_ERR(inode);
955 P9_DPRINTK(P9_DEBUG_VFS, "inode creation failed %d\n",
956 err);
957 goto error;
958 }
959 d_set_d_op(dentry, &v9fs_cached_dentry_operations);
960 d_instantiate(dentry, inode);
961 err = v9fs_fid_add(dentry, fid);
962 if (err < 0)
963 goto error;
964 fid = NULL;
965 } else {
966 /*
967 * Not in cached mode. No need to populate
968 * inode with stat. We need to get an inode
969 * so that we can set the acl with dentry
970 */
971 inode = v9fs_get_inode(dir->i_sb, mode);
972 if (IS_ERR(inode)) {
973 err = PTR_ERR(inode);
974 goto error;
975 }
976 d_set_d_op(dentry, &v9fs_dentry_operations);
977 d_instantiate(dentry, inode);
978 }
979 /* Now set the ACL based on the default value */
980 v9fs_set_create_acl(dentry, dacl, pacl);
981
982error:
983 if (fid)
984 p9_client_clunk(fid);
985 return err;
986}
987
988/** 647/**
989 * v9fs_vfs_lookup - VFS lookup hook to "walk" to a new inode 648 * v9fs_vfs_lookup - VFS lookup hook to "walk" to a new inode
990 * @dir: inode that is being walked from 649 * @dir: inode that is being walked from
@@ -993,7 +652,7 @@ error:
993 * 652 *
994 */ 653 */
995 654
996static struct dentry *v9fs_vfs_lookup(struct inode *dir, struct dentry *dentry, 655struct dentry *v9fs_vfs_lookup(struct inode *dir, struct dentry *dentry,
997 struct nameidata *nameidata) 656 struct nameidata *nameidata)
998{ 657{
999 struct super_block *sb; 658 struct super_block *sb;
@@ -1063,7 +722,7 @@ error:
1063 * 722 *
1064 */ 723 */
1065 724
1066static int v9fs_vfs_unlink(struct inode *i, struct dentry *d) 725int v9fs_vfs_unlink(struct inode *i, struct dentry *d)
1067{ 726{
1068 return v9fs_remove(i, d, 0); 727 return v9fs_remove(i, d, 0);
1069} 728}
@@ -1075,7 +734,7 @@ static int v9fs_vfs_unlink(struct inode *i, struct dentry *d)
1075 * 734 *
1076 */ 735 */
1077 736
1078static int v9fs_vfs_rmdir(struct inode *i, struct dentry *d) 737int v9fs_vfs_rmdir(struct inode *i, struct dentry *d)
1079{ 738{
1080 return v9fs_remove(i, d, 1); 739 return v9fs_remove(i, d, 1);
1081} 740}
@@ -1089,7 +748,7 @@ static int v9fs_vfs_rmdir(struct inode *i, struct dentry *d)
1089 * 748 *
1090 */ 749 */
1091 750
1092static int 751int
1093v9fs_vfs_rename(struct inode *old_dir, struct dentry *old_dentry, 752v9fs_vfs_rename(struct inode *old_dir, struct dentry *old_dentry,
1094 struct inode *new_dir, struct dentry *new_dentry) 753 struct inode *new_dir, struct dentry *new_dentry)
1095{ 754{
@@ -1196,42 +855,6 @@ v9fs_vfs_getattr(struct vfsmount *mnt, struct dentry *dentry,
1196 return 0; 855 return 0;
1197} 856}
1198 857
1199static int
1200v9fs_vfs_getattr_dotl(struct vfsmount *mnt, struct dentry *dentry,
1201 struct kstat *stat)
1202{
1203 int err;
1204 struct v9fs_session_info *v9ses;
1205 struct p9_fid *fid;
1206 struct p9_stat_dotl *st;
1207
1208 P9_DPRINTK(P9_DEBUG_VFS, "dentry: %p\n", dentry);
1209 err = -EPERM;
1210 v9ses = v9fs_inode2v9ses(dentry->d_inode);
1211 if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE)
1212 return simple_getattr(mnt, dentry, stat);
1213
1214 fid = v9fs_fid_lookup(dentry);
1215 if (IS_ERR(fid))
1216 return PTR_ERR(fid);
1217
1218 /* Ask for all the fields in stat structure. Server will return
1219 * whatever it supports
1220 */
1221
1222 st = p9_client_getattr_dotl(fid, P9_STATS_ALL);
1223 if (IS_ERR(st))
1224 return PTR_ERR(st);
1225
1226 v9fs_stat2inode_dotl(st, dentry->d_inode);
1227 generic_fillattr(dentry->d_inode, stat);
1228 /* Change block size to what the server returned */
1229 stat->blksize = st->st_blksize;
1230
1231 kfree(st);
1232 return 0;
1233}
1234
1235/** 858/**
1236 * v9fs_vfs_setattr - set file metadata 859 * v9fs_vfs_setattr - set file metadata
1237 * @dentry: file whose metadata to set 860 * @dentry: file whose metadata to set
@@ -1291,64 +914,6 @@ static int v9fs_vfs_setattr(struct dentry *dentry, struct iattr *iattr)
1291} 914}
1292 915
1293/** 916/**
1294 * v9fs_vfs_setattr_dotl - set file metadata
1295 * @dentry: file whose metadata to set
1296 * @iattr: metadata assignment structure
1297 *
1298 */
1299
1300int v9fs_vfs_setattr_dotl(struct dentry *dentry, struct iattr *iattr)
1301{
1302 int retval;
1303 struct v9fs_session_info *v9ses;
1304 struct p9_fid *fid;
1305 struct p9_iattr_dotl p9attr;
1306
1307 P9_DPRINTK(P9_DEBUG_VFS, "\n");
1308
1309 retval = inode_change_ok(dentry->d_inode, iattr);
1310 if (retval)
1311 return retval;
1312
1313 p9attr.valid = iattr->ia_valid;
1314 p9attr.mode = iattr->ia_mode;
1315 p9attr.uid = iattr->ia_uid;
1316 p9attr.gid = iattr->ia_gid;
1317 p9attr.size = iattr->ia_size;
1318 p9attr.atime_sec = iattr->ia_atime.tv_sec;
1319 p9attr.atime_nsec = iattr->ia_atime.tv_nsec;
1320 p9attr.mtime_sec = iattr->ia_mtime.tv_sec;
1321 p9attr.mtime_nsec = iattr->ia_mtime.tv_nsec;
1322
1323 retval = -EPERM;
1324 v9ses = v9fs_inode2v9ses(dentry->d_inode);
1325 fid = v9fs_fid_lookup(dentry);
1326 if (IS_ERR(fid))
1327 return PTR_ERR(fid);
1328
1329 retval = p9_client_setattr(fid, &p9attr);
1330 if (retval < 0)
1331 return retval;
1332
1333 if ((iattr->ia_valid & ATTR_SIZE) &&
1334 iattr->ia_size != i_size_read(dentry->d_inode)) {
1335 retval = vmtruncate(dentry->d_inode, iattr->ia_size);
1336 if (retval)
1337 return retval;
1338 }
1339
1340 setattr_copy(dentry->d_inode, iattr);
1341 mark_inode_dirty(dentry->d_inode);
1342 if (iattr->ia_valid & ATTR_MODE) {
1343 /* We also want to update ACL when we update mode bits */
1344 retval = v9fs_acl_chmod(dentry);
1345 if (retval < 0)
1346 return retval;
1347 }
1348 return 0;
1349}
1350
1351/**
1352 * v9fs_stat2inode - populate an inode structure with mistat info 917 * v9fs_stat2inode - populate an inode structure with mistat info
1353 * @stat: Plan 9 metadata (mistat) structure 918 * @stat: Plan 9 metadata (mistat) structure
1354 * @inode: inode to populate 919 * @inode: inode to populate
@@ -1426,77 +991,6 @@ v9fs_stat2inode(struct p9_wstat *stat, struct inode *inode,
1426} 991}
1427 992
1428/** 993/**
1429 * v9fs_stat2inode_dotl - populate an inode structure with stat info
1430 * @stat: stat structure
1431 * @inode: inode to populate
1432 * @sb: superblock of filesystem
1433 *
1434 */
1435
1436void
1437v9fs_stat2inode_dotl(struct p9_stat_dotl *stat, struct inode *inode)
1438{
1439
1440 if ((stat->st_result_mask & P9_STATS_BASIC) == P9_STATS_BASIC) {
1441 inode->i_atime.tv_sec = stat->st_atime_sec;
1442 inode->i_atime.tv_nsec = stat->st_atime_nsec;
1443 inode->i_mtime.tv_sec = stat->st_mtime_sec;
1444 inode->i_mtime.tv_nsec = stat->st_mtime_nsec;
1445 inode->i_ctime.tv_sec = stat->st_ctime_sec;
1446 inode->i_ctime.tv_nsec = stat->st_ctime_nsec;
1447 inode->i_uid = stat->st_uid;
1448 inode->i_gid = stat->st_gid;
1449 inode->i_nlink = stat->st_nlink;
1450 inode->i_mode = stat->st_mode;
1451 inode->i_rdev = new_decode_dev(stat->st_rdev);
1452
1453 if ((S_ISBLK(inode->i_mode)) || (S_ISCHR(inode->i_mode)))
1454 init_special_inode(inode, inode->i_mode, inode->i_rdev);
1455
1456 i_size_write(inode, stat->st_size);
1457 inode->i_blocks = stat->st_blocks;
1458 } else {
1459 if (stat->st_result_mask & P9_STATS_ATIME) {
1460 inode->i_atime.tv_sec = stat->st_atime_sec;
1461 inode->i_atime.tv_nsec = stat->st_atime_nsec;
1462 }
1463 if (stat->st_result_mask & P9_STATS_MTIME) {
1464 inode->i_mtime.tv_sec = stat->st_mtime_sec;
1465 inode->i_mtime.tv_nsec = stat->st_mtime_nsec;
1466 }
1467 if (stat->st_result_mask & P9_STATS_CTIME) {
1468 inode->i_ctime.tv_sec = stat->st_ctime_sec;
1469 inode->i_ctime.tv_nsec = stat->st_ctime_nsec;
1470 }
1471 if (stat->st_result_mask & P9_STATS_UID)
1472 inode->i_uid = stat->st_uid;
1473 if (stat->st_result_mask & P9_STATS_GID)
1474 inode->i_gid = stat->st_gid;
1475 if (stat->st_result_mask & P9_STATS_NLINK)
1476 inode->i_nlink = stat->st_nlink;
1477 if (stat->st_result_mask & P9_STATS_MODE) {
1478 inode->i_mode = stat->st_mode;
1479 if ((S_ISBLK(inode->i_mode)) ||
1480 (S_ISCHR(inode->i_mode)))
1481 init_special_inode(inode, inode->i_mode,
1482 inode->i_rdev);
1483 }
1484 if (stat->st_result_mask & P9_STATS_RDEV)
1485 inode->i_rdev = new_decode_dev(stat->st_rdev);
1486 if (stat->st_result_mask & P9_STATS_SIZE)
1487 i_size_write(inode, stat->st_size);
1488 if (stat->st_result_mask & P9_STATS_BLOCKS)
1489 inode->i_blocks = stat->st_blocks;
1490 }
1491 if (stat->st_result_mask & P9_STATS_GEN)
1492 inode->i_generation = stat->st_gen;
1493
1494 /* Currently we don't support P9_STATS_BTIME and P9_STATS_DATA_VERSION
1495 * because the inode structure does not have fields for them.
1496 */
1497}
1498
1499/**
1500 * v9fs_qid2ino - convert qid into inode number 994 * v9fs_qid2ino - convert qid into inode number
1501 * @qid: qid to hash 995 * @qid: qid to hash
1502 * 996 *
@@ -1602,7 +1096,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
1602 * 1096 *
1603 */ 1097 */
1604 1098
1605static void 1099void
1606v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p) 1100v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
1607{ 1101{
1608 char *s = nd_get_link(nd); 1102 char *s = nd_get_link(nd);
@@ -1646,94 +1140,6 @@ static int v9fs_vfs_mkspecial(struct inode *dir, struct dentry *dentry,
1646} 1140}
1647 1141
1648/** 1142/**
1649 * v9fs_vfs_symlink_dotl - helper function to create symlinks
1650 * @dir: directory inode containing symlink
1651 * @dentry: dentry for symlink
1652 * @symname: symlink data
1653 *
1654 * See Also: 9P2000.L RFC for more information
1655 *
1656 */
1657
1658static int
1659v9fs_vfs_symlink_dotl(struct inode *dir, struct dentry *dentry,
1660 const char *symname)
1661{
1662 struct v9fs_session_info *v9ses;
1663 struct p9_fid *dfid;
1664 struct p9_fid *fid = NULL;
1665 struct inode *inode;
1666 struct p9_qid qid;
1667 char *name;
1668 int err;
1669 gid_t gid;
1670
1671 name = (char *) dentry->d_name.name;
1672 P9_DPRINTK(P9_DEBUG_VFS, "v9fs_vfs_symlink_dotl : %lu,%s,%s\n",
1673 dir->i_ino, name, symname);
1674 v9ses = v9fs_inode2v9ses(dir);
1675
1676 dfid = v9fs_fid_lookup(dentry->d_parent);
1677 if (IS_ERR(dfid)) {
1678 err = PTR_ERR(dfid);
1679 P9_DPRINTK(P9_DEBUG_VFS, "fid lookup failed %d\n", err);
1680 return err;
1681 }
1682
1683 gid = v9fs_get_fsgid_for_create(dir);
1684
1685 /* Server doesn't alter fid on TSYMLINK. Hence no need to clone it. */
1686 err = p9_client_symlink(dfid, name, (char *)symname, gid, &qid);
1687
1688 if (err < 0) {
1689 P9_DPRINTK(P9_DEBUG_VFS, "p9_client_symlink failed %d\n", err);
1690 goto error;
1691 }
1692
1693 if (v9ses->cache) {
1694 /* Now walk from the parent so we can get an unopened fid. */
1695 fid = p9_client_walk(dfid, 1, &name, 1);
1696 if (IS_ERR(fid)) {
1697 err = PTR_ERR(fid);
1698 P9_DPRINTK(P9_DEBUG_VFS, "p9_client_walk failed %d\n",
1699 err);
1700 fid = NULL;
1701 goto error;
1702 }
1703
1704 /* instantiate inode and assign the unopened fid to dentry */
1705 inode = v9fs_inode_from_fid(v9ses, fid, dir->i_sb);
1706 if (IS_ERR(inode)) {
1707 err = PTR_ERR(inode);
1708 P9_DPRINTK(P9_DEBUG_VFS, "inode creation failed %d\n",
1709 err);
1710 goto error;
1711 }
1712 d_set_d_op(dentry, &v9fs_cached_dentry_operations);
1713 d_instantiate(dentry, inode);
1714 err = v9fs_fid_add(dentry, fid);
1715 if (err < 0)
1716 goto error;
1717 fid = NULL;
1718 } else {
1719 /* Not in cached mode. No need to populate inode with stat */
1720 inode = v9fs_get_inode(dir->i_sb, S_IFLNK);
1721 if (IS_ERR(inode)) {
1722 err = PTR_ERR(inode);
1723 goto error;
1724 }
1725 d_set_d_op(dentry, &v9fs_dentry_operations);
1726 d_instantiate(dentry, inode);
1727 }
1728
1729error:
1730 if (fid)
1731 p9_client_clunk(fid);
1732
1733 return err;
1734}
1735
1736/**
1737 * v9fs_vfs_symlink - helper function to create symlinks 1143 * v9fs_vfs_symlink - helper function to create symlinks
1738 * @dir: directory inode containing symlink 1144 * @dir: directory inode containing symlink
1739 * @dentry: dentry for symlink 1145 * @dentry: dentry for symlink
@@ -1792,77 +1198,6 @@ clunk_fid:
1792} 1198}
1793 1199
1794/** 1200/**
1795 * v9fs_vfs_link_dotl - create a hardlink for dotl
1796 * @old_dentry: dentry for file to link to
1797 * @dir: inode destination for new link
1798 * @dentry: dentry for link
1799 *
1800 */
1801
1802static int
1803v9fs_vfs_link_dotl(struct dentry *old_dentry, struct inode *dir,
1804 struct dentry *dentry)
1805{
1806 int err;
1807 struct p9_fid *dfid, *oldfid;
1808 char *name;
1809 struct v9fs_session_info *v9ses;
1810 struct dentry *dir_dentry;
1811
1812 P9_DPRINTK(P9_DEBUG_VFS, "dir ino: %lu, old_name: %s, new_name: %s\n",
1813 dir->i_ino, old_dentry->d_name.name,
1814 dentry->d_name.name);
1815
1816 v9ses = v9fs_inode2v9ses(dir);
1817 dir_dentry = v9fs_dentry_from_dir_inode(dir);
1818 dfid = v9fs_fid_lookup(dir_dentry);
1819 if (IS_ERR(dfid))
1820 return PTR_ERR(dfid);
1821
1822 oldfid = v9fs_fid_lookup(old_dentry);
1823 if (IS_ERR(oldfid))
1824 return PTR_ERR(oldfid);
1825
1826 name = (char *) dentry->d_name.name;
1827
1828 err = p9_client_link(dfid, oldfid, (char *)dentry->d_name.name);
1829
1830 if (err < 0) {
1831 P9_DPRINTK(P9_DEBUG_VFS, "p9_client_link failed %d\n", err);
1832 return err;
1833 }
1834
1835 if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) {
1836 /* Get the latest stat info from server. */
1837 struct p9_fid *fid;
1838 struct p9_stat_dotl *st;
1839
1840 fid = v9fs_fid_lookup(old_dentry);
1841 if (IS_ERR(fid))
1842 return PTR_ERR(fid);
1843
1844 st = p9_client_getattr_dotl(fid, P9_STATS_BASIC);
1845 if (IS_ERR(st))
1846 return PTR_ERR(st);
1847
1848 v9fs_stat2inode_dotl(st, old_dentry->d_inode);
1849
1850 kfree(st);
1851 } else {
1852 /* Caching disabled. No need to get upto date stat info.
1853 * This dentry will be released immediately. So, just hold the
1854 * inode
1855 */
1856 ihold(old_dentry->d_inode);
1857 }
1858
1859 d_set_d_op(dentry, old_dentry->d_op);
1860 d_instantiate(dentry, old_dentry->d_inode);
1861
1862 return err;
1863}
1864
1865/**
1866 * v9fs_vfs_mknod - create a special file 1201 * v9fs_vfs_mknod - create a special file
1867 * @dir: inode destination for new link 1202 * @dir: inode destination for new link
1868 * @dentry: dentry for file 1203 * @dentry: dentry for file
@@ -1907,160 +1242,6 @@ v9fs_vfs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t rdev)
1907 return retval; 1242 return retval;
1908} 1243}
1909 1244
1910/**
1911 * v9fs_vfs_mknod_dotl - create a special file
1912 * @dir: inode destination for new link
1913 * @dentry: dentry for file
1914 * @mode: mode for creation
1915 * @rdev: device associated with special file
1916 *
1917 */
1918static int
1919v9fs_vfs_mknod_dotl(struct inode *dir, struct dentry *dentry, int omode,
1920 dev_t rdev)
1921{
1922 int err;
1923 char *name;
1924 mode_t mode;
1925 struct v9fs_session_info *v9ses;
1926 struct p9_fid *fid = NULL, *dfid = NULL;
1927 struct inode *inode;
1928 gid_t gid;
1929 struct p9_qid qid;
1930 struct dentry *dir_dentry;
1931 struct posix_acl *dacl = NULL, *pacl = NULL;
1932
1933 P9_DPRINTK(P9_DEBUG_VFS,
1934 " %lu,%s mode: %x MAJOR: %u MINOR: %u\n", dir->i_ino,
1935 dentry->d_name.name, omode, MAJOR(rdev), MINOR(rdev));
1936
1937 if (!new_valid_dev(rdev))
1938 return -EINVAL;
1939
1940 v9ses = v9fs_inode2v9ses(dir);
1941 dir_dentry = v9fs_dentry_from_dir_inode(dir);
1942 dfid = v9fs_fid_lookup(dir_dentry);
1943 if (IS_ERR(dfid)) {
1944 err = PTR_ERR(dfid);
1945 P9_DPRINTK(P9_DEBUG_VFS, "fid lookup failed %d\n", err);
1946 dfid = NULL;
1947 goto error;
1948 }
1949
1950 gid = v9fs_get_fsgid_for_create(dir);
1951 mode = omode;
1952 /* Update mode based on ACL value */
1953 err = v9fs_acl_mode(dir, &mode, &dacl, &pacl);
1954 if (err) {
1955 P9_DPRINTK(P9_DEBUG_VFS,
1956 "Failed to get acl values in mknod %d\n", err);
1957 goto error;
1958 }
1959 name = (char *) dentry->d_name.name;
1960
1961 err = p9_client_mknod_dotl(dfid, name, mode, rdev, gid, &qid);
1962 if (err < 0)
1963 goto error;
1964
1965 /* instantiate inode and assign the unopened fid to the dentry */
1966 if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) {
1967 fid = p9_client_walk(dfid, 1, &name, 1);
1968 if (IS_ERR(fid)) {
1969 err = PTR_ERR(fid);
1970 P9_DPRINTK(P9_DEBUG_VFS, "p9_client_walk failed %d\n",
1971 err);
1972 fid = NULL;
1973 goto error;
1974 }
1975
1976 inode = v9fs_inode_from_fid(v9ses, fid, dir->i_sb);
1977 if (IS_ERR(inode)) {
1978 err = PTR_ERR(inode);
1979 P9_DPRINTK(P9_DEBUG_VFS, "inode creation failed %d\n",
1980 err);
1981 goto error;
1982 }
1983 d_set_d_op(dentry, &v9fs_cached_dentry_operations);
1984 d_instantiate(dentry, inode);
1985 err = v9fs_fid_add(dentry, fid);
1986 if (err < 0)
1987 goto error;
1988 fid = NULL;
1989 } else {
1990 /*
1991 * Not in cached mode. No need to populate inode with stat.
1992 * socket syscall returns a fd, so we need instantiate
1993 */
1994 inode = v9fs_get_inode(dir->i_sb, mode);
1995 if (IS_ERR(inode)) {
1996 err = PTR_ERR(inode);
1997 goto error;
1998 }
1999 d_set_d_op(dentry, &v9fs_dentry_operations);
2000 d_instantiate(dentry, inode);
2001 }
2002 /* Now set the ACL based on the default value */
2003 v9fs_set_create_acl(dentry, dacl, pacl);
2004error:
2005 if (fid)
2006 p9_client_clunk(fid);
2007 return err;
2008}
2009
2010static int
2011v9fs_vfs_readlink_dotl(struct dentry *dentry, char *buffer, int buflen)
2012{
2013 int retval;
2014 struct p9_fid *fid;
2015 char *target = NULL;
2016
2017 P9_DPRINTK(P9_DEBUG_VFS, " %s\n", dentry->d_name.name);
2018 retval = -EPERM;
2019 fid = v9fs_fid_lookup(dentry);
2020 if (IS_ERR(fid))
2021 return PTR_ERR(fid);
2022
2023 retval = p9_client_readlink(fid, &target);
2024 if (retval < 0)
2025 return retval;
2026
2027 strncpy(buffer, target, buflen);
2028 P9_DPRINTK(P9_DEBUG_VFS, "%s -> %s\n", dentry->d_name.name, buffer);
2029
2030 retval = strnlen(buffer, buflen);
2031 return retval;
2032}
2033
2034/**
2035 * v9fs_vfs_follow_link_dotl - follow a symlink path
2036 * @dentry: dentry for symlink
2037 * @nd: nameidata
2038 *
2039 */
2040
2041static void *
2042v9fs_vfs_follow_link_dotl(struct dentry *dentry, struct nameidata *nd)
2043{
2044 int len = 0;
2045 char *link = __getname();
2046
2047 P9_DPRINTK(P9_DEBUG_VFS, "%s n", dentry->d_name.name);
2048
2049 if (!link)
2050 link = ERR_PTR(-ENOMEM);
2051 else {
2052 len = v9fs_vfs_readlink_dotl(dentry, link, PATH_MAX);
2053 if (len < 0) {
2054 __putname(link);
2055 link = ERR_PTR(len);
2056 } else
2057 link[min(len, PATH_MAX-1)] = 0;
2058 }
2059 nd_set_link(nd, link);
2060
2061 return NULL;
2062}
2063
2064static const struct inode_operations v9fs_dir_inode_operations_dotu = { 1245static const struct inode_operations v9fs_dir_inode_operations_dotu = {
2065 .create = v9fs_vfs_create, 1246 .create = v9fs_vfs_create,
2066 .lookup = v9fs_vfs_lookup, 1247 .lookup = v9fs_vfs_lookup,
@@ -2075,25 +1256,6 @@ static const struct inode_operations v9fs_dir_inode_operations_dotu = {
2075 .setattr = v9fs_vfs_setattr, 1256 .setattr = v9fs_vfs_setattr,
2076}; 1257};
2077 1258
2078static const struct inode_operations v9fs_dir_inode_operations_dotl = {
2079 .create = v9fs_vfs_create_dotl,
2080 .lookup = v9fs_vfs_lookup,
2081 .link = v9fs_vfs_link_dotl,
2082 .symlink = v9fs_vfs_symlink_dotl,
2083 .unlink = v9fs_vfs_unlink,
2084 .mkdir = v9fs_vfs_mkdir_dotl,
2085 .rmdir = v9fs_vfs_rmdir,
2086 .mknod = v9fs_vfs_mknod_dotl,
2087 .rename = v9fs_vfs_rename,
2088 .getattr = v9fs_vfs_getattr_dotl,
2089 .setattr = v9fs_vfs_setattr_dotl,
2090 .setxattr = generic_setxattr,
2091 .getxattr = generic_getxattr,
2092 .removexattr = generic_removexattr,
2093 .listxattr = v9fs_listxattr,
2094 .check_acl = v9fs_check_acl,
2095};
2096
2097static const struct inode_operations v9fs_dir_inode_operations = { 1259static const struct inode_operations v9fs_dir_inode_operations = {
2098 .create = v9fs_vfs_create, 1260 .create = v9fs_vfs_create,
2099 .lookup = v9fs_vfs_lookup, 1261 .lookup = v9fs_vfs_lookup,
@@ -2111,16 +1273,6 @@ static const struct inode_operations v9fs_file_inode_operations = {
2111 .setattr = v9fs_vfs_setattr, 1273 .setattr = v9fs_vfs_setattr,
2112}; 1274};
2113 1275
2114static const struct inode_operations v9fs_file_inode_operations_dotl = {
2115 .getattr = v9fs_vfs_getattr_dotl,
2116 .setattr = v9fs_vfs_setattr_dotl,
2117 .setxattr = generic_setxattr,
2118 .getxattr = generic_getxattr,
2119 .removexattr = generic_removexattr,
2120 .listxattr = v9fs_listxattr,
2121 .check_acl = v9fs_check_acl,
2122};
2123
2124static const struct inode_operations v9fs_symlink_inode_operations = { 1276static const struct inode_operations v9fs_symlink_inode_operations = {
2125 .readlink = generic_readlink, 1277 .readlink = generic_readlink,
2126 .follow_link = v9fs_vfs_follow_link, 1278 .follow_link = v9fs_vfs_follow_link,
@@ -2129,14 +1281,3 @@ static const struct inode_operations v9fs_symlink_inode_operations = {
2129 .setattr = v9fs_vfs_setattr, 1281 .setattr = v9fs_vfs_setattr,
2130}; 1282};
2131 1283
2132static const struct inode_operations v9fs_symlink_inode_operations_dotl = {
2133 .readlink = v9fs_vfs_readlink_dotl,
2134 .follow_link = v9fs_vfs_follow_link_dotl,
2135 .put_link = v9fs_vfs_put_link,
2136 .getattr = v9fs_vfs_getattr_dotl,
2137 .setattr = v9fs_vfs_setattr_dotl,
2138 .setxattr = generic_setxattr,
2139 .getxattr = generic_getxattr,
2140 .removexattr = generic_removexattr,
2141 .listxattr = v9fs_listxattr,
2142};
diff --git a/fs/9p/vfs_inode_dotl.c b/fs/9p/vfs_inode_dotl.c
new file mode 100644
index 000000000000..fe3ffa9aace4
--- /dev/null
+++ b/fs/9p/vfs_inode_dotl.c
@@ -0,0 +1,824 @@
1/*
2 * linux/fs/9p/vfs_inode_dotl.c
3 *
4 * This file contains vfs inode ops for the 9P2000.L protocol.
5 *
6 * Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com>
7 * Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov>
8 *
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.
12 *
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.
17 *
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
23 *
24 */
25
26#include <linux/module.h>
27#include <linux/errno.h>
28#include <linux/fs.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>
42
43#include "v9fs.h"
44#include "v9fs_vfs.h"
45#include "fid.h"
46#include "cache.h"
47#include "xattr.h"
48#include "acl.h"
49
50static int
51v9fs_vfs_mknod_dotl(struct inode *dir, struct dentry *dentry, int omode,
52 dev_t rdev);
53
54/**
55 * v9fs_get_fsgid_for_create - Helper function to get the gid for creating a
56 * new file system object. This checks the S_ISGID to determine the owning
57 * group of the new file system object.
58 */
59
60static gid_t v9fs_get_fsgid_for_create(struct inode *dir_inode)
61{
62 BUG_ON(dir_inode == NULL);
63
64 if (dir_inode->i_mode & S_ISGID) {
65 /* set_gid bit is set.*/
66 return dir_inode->i_gid;
67 }
68 return current_fsgid();
69}
70
71/**
72 * v9fs_dentry_from_dir_inode - helper function to get the dentry from
73 * dir inode.
74 *
75 */
76
77static struct dentry *v9fs_dentry_from_dir_inode(struct inode *inode)
78{
79 struct dentry *dentry;
80
81 spin_lock(&inode->i_lock);
82 /* Directory should have only one entry. */
83 BUG_ON(S_ISDIR(inode->i_mode) && !list_is_singular(&inode->i_dentry));
84 dentry = list_entry(inode->i_dentry.next, struct dentry, d_alias);
85 spin_unlock(&inode->i_lock);
86 return dentry;
87}
88
89struct inode *
90v9fs_inode_dotl(struct v9fs_session_info *v9ses, struct p9_fid *fid,
91 struct super_block *sb)
92{
93 struct inode *ret = NULL;
94 int err;
95 struct p9_stat_dotl *st;
96
97 st = p9_client_getattr_dotl(fid, P9_STATS_BASIC);
98 if (IS_ERR(st))
99 return ERR_CAST(st);
100
101 ret = v9fs_get_inode(sb, st->st_mode);
102 if (IS_ERR(ret)) {
103 err = PTR_ERR(ret);
104 goto error;
105 }
106
107 v9fs_stat2inode_dotl(st, ret);
108 ret->i_ino = v9fs_qid2ino(&st->qid);
109#ifdef CONFIG_9P_FSCACHE
110 v9fs_vcookie_set_qid(ret, &st->qid);
111 v9fs_cache_inode_get_cookie(ret);
112#endif
113 err = v9fs_get_acl(ret, fid);
114 if (err) {
115 iput(ret);
116 goto error;
117 }
118 kfree(st);
119 return ret;
120error:
121 kfree(st);
122 return ERR_PTR(err);
123}
124
125/**
126 * v9fs_vfs_create_dotl - VFS hook to create files for 9P2000.L protocol.
127 * @dir: directory inode that is being created
128 * @dentry: dentry that is being deleted
129 * @mode: create permissions
130 * @nd: path information
131 *
132 */
133
134static int
135v9fs_vfs_create_dotl(struct inode *dir, struct dentry *dentry, int omode,
136 struct nameidata *nd)
137{
138 int err = 0;
139 char *name = NULL;
140 gid_t gid;
141 int flags;
142 mode_t mode;
143 struct v9fs_session_info *v9ses;
144 struct p9_fid *fid = NULL;
145 struct p9_fid *dfid, *ofid;
146 struct file *filp;
147 struct p9_qid qid;
148 struct inode *inode;
149 struct posix_acl *pacl = NULL, *dacl = NULL;
150
151 v9ses = v9fs_inode2v9ses(dir);
152 if (nd && nd->flags & LOOKUP_OPEN)
153 flags = nd->intent.open.flags - 1;
154 else {
155 /*
156 * create call without LOOKUP_OPEN is due
157 * to mknod of regular files. So use mknod
158 * operation.
159 */
160 return v9fs_vfs_mknod_dotl(dir, dentry, omode, 0);
161 }
162
163 name = (char *) dentry->d_name.name;
164 P9_DPRINTK(P9_DEBUG_VFS, "v9fs_vfs_create_dotl: name:%s flags:0x%x "
165 "mode:0x%x\n", name, flags, omode);
166
167 dfid = v9fs_fid_lookup(dentry->d_parent);
168 if (IS_ERR(dfid)) {
169 err = PTR_ERR(dfid);
170 P9_DPRINTK(P9_DEBUG_VFS, "fid lookup failed %d\n", err);
171 return err;
172 }
173
174 /* clone a fid to use for creation */
175 ofid = p9_client_walk(dfid, 0, NULL, 1);
176 if (IS_ERR(ofid)) {
177 err = PTR_ERR(ofid);
178 P9_DPRINTK(P9_DEBUG_VFS, "p9_client_walk failed %d\n", err);
179 return err;
180 }
181
182 gid = v9fs_get_fsgid_for_create(dir);
183
184 mode = omode;
185 /* Update mode based on ACL value */
186 err = v9fs_acl_mode(dir, &mode, &dacl, &pacl);
187 if (err) {
188 P9_DPRINTK(P9_DEBUG_VFS,
189 "Failed to get acl values in creat %d\n", err);
190 goto error;
191 }
192 err = p9_client_create_dotl(ofid, name, flags, mode, gid, &qid);
193 if (err < 0) {
194 P9_DPRINTK(P9_DEBUG_VFS,
195 "p9_client_open_dotl failed in creat %d\n",
196 err);
197 goto error;
198 }
199
200 /* instantiate inode and assign the unopened fid to the dentry */
201 fid = p9_client_walk(dfid, 1, &name, 1);
202 if (IS_ERR(fid)) {
203 err = PTR_ERR(fid);
204 P9_DPRINTK(P9_DEBUG_VFS, "p9_client_walk failed %d\n", err);
205 fid = NULL;
206 goto error;
207 }
208 inode = v9fs_inode_from_fid(v9ses, fid, dir->i_sb);
209 if (IS_ERR(inode)) {
210 err = PTR_ERR(inode);
211 P9_DPRINTK(P9_DEBUG_VFS, "inode creation failed %d\n", err);
212 goto error;
213 }
214 d_instantiate(dentry, inode);
215 err = v9fs_fid_add(dentry, fid);
216 if (err < 0)
217 goto error;
218
219 /* Now set the ACL based on the default value */
220 v9fs_set_create_acl(dentry, dacl, pacl);
221
222 /* Since we are opening a file, assign the open fid to the file */
223 filp = lookup_instantiate_filp(nd, dentry, generic_file_open);
224 if (IS_ERR(filp)) {
225 p9_client_clunk(ofid);
226 return PTR_ERR(filp);
227 }
228 filp->private_data = ofid;
229 return 0;
230
231error:
232 if (ofid)
233 p9_client_clunk(ofid);
234 if (fid)
235 p9_client_clunk(fid);
236 return err;
237}
238
239/**
240 * v9fs_vfs_mkdir_dotl - VFS mkdir hook to create a directory
241 * @dir: inode that is being unlinked
242 * @dentry: dentry that is being unlinked
243 * @mode: mode for new directory
244 *
245 */
246
247static int v9fs_vfs_mkdir_dotl(struct inode *dir,
248 struct dentry *dentry, int omode)
249{
250 int err;
251 struct v9fs_session_info *v9ses;
252 struct p9_fid *fid = NULL, *dfid = NULL;
253 gid_t gid;
254 char *name;
255 mode_t mode;
256 struct inode *inode;
257 struct p9_qid qid;
258 struct dentry *dir_dentry;
259 struct posix_acl *dacl = NULL, *pacl = NULL;
260
261 P9_DPRINTK(P9_DEBUG_VFS, "name %s\n", dentry->d_name.name);
262 err = 0;
263 v9ses = v9fs_inode2v9ses(dir);
264
265 omode |= S_IFDIR;
266 if (dir->i_mode & S_ISGID)
267 omode |= S_ISGID;
268
269 dir_dentry = v9fs_dentry_from_dir_inode(dir);
270 dfid = v9fs_fid_lookup(dir_dentry);
271 if (IS_ERR(dfid)) {
272 err = PTR_ERR(dfid);
273 P9_DPRINTK(P9_DEBUG_VFS, "fid lookup failed %d\n", err);
274 dfid = NULL;
275 goto error;
276 }
277
278 gid = v9fs_get_fsgid_for_create(dir);
279 mode = omode;
280 /* Update mode based on ACL value */
281 err = v9fs_acl_mode(dir, &mode, &dacl, &pacl);
282 if (err) {
283 P9_DPRINTK(P9_DEBUG_VFS,
284 "Failed to get acl values in mkdir %d\n", err);
285 goto error;
286 }
287 name = (char *) dentry->d_name.name;
288 err = p9_client_mkdir_dotl(dfid, name, mode, gid, &qid);
289 if (err < 0)
290 goto error;
291
292 /* instantiate inode and assign the unopened fid to the dentry */
293 if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) {
294 fid = p9_client_walk(dfid, 1, &name, 1);
295 if (IS_ERR(fid)) {
296 err = PTR_ERR(fid);
297 P9_DPRINTK(P9_DEBUG_VFS, "p9_client_walk failed %d\n",
298 err);
299 fid = NULL;
300 goto error;
301 }
302
303 inode = v9fs_inode_from_fid(v9ses, fid, dir->i_sb);
304 if (IS_ERR(inode)) {
305 err = PTR_ERR(inode);
306 P9_DPRINTK(P9_DEBUG_VFS, "inode creation failed %d\n",
307 err);
308 goto error;
309 }
310 d_instantiate(dentry, inode);
311 err = v9fs_fid_add(dentry, fid);
312 if (err < 0)
313 goto error;
314 fid = NULL;
315 } else {
316 /*
317 * Not in cached mode. No need to populate
318 * inode with stat. We need to get an inode
319 * so that we can set the acl with dentry
320 */
321 inode = v9fs_get_inode(dir->i_sb, mode);
322 if (IS_ERR(inode)) {
323 err = PTR_ERR(inode);
324 goto error;
325 }
326 d_instantiate(dentry, inode);
327 }
328 /* Now set the ACL based on the default value */
329 v9fs_set_create_acl(dentry, dacl, pacl);
330
331error:
332 if (fid)
333 p9_client_clunk(fid);
334 return err;
335}
336
337static int
338v9fs_vfs_getattr_dotl(struct vfsmount *mnt, struct dentry *dentry,
339 struct kstat *stat)
340{
341 int err;
342 struct v9fs_session_info *v9ses;
343 struct p9_fid *fid;
344 struct p9_stat_dotl *st;
345
346 P9_DPRINTK(P9_DEBUG_VFS, "dentry: %p\n", dentry);
347 err = -EPERM;
348 v9ses = v9fs_inode2v9ses(dentry->d_inode);
349 if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE)
350 return simple_getattr(mnt, dentry, stat);
351
352 fid = v9fs_fid_lookup(dentry);
353 if (IS_ERR(fid))
354 return PTR_ERR(fid);
355
356 /* Ask for all the fields in stat structure. Server will return
357 * whatever it supports
358 */
359
360 st = p9_client_getattr_dotl(fid, P9_STATS_ALL);
361 if (IS_ERR(st))
362 return PTR_ERR(st);
363
364 v9fs_stat2inode_dotl(st, dentry->d_inode);
365 generic_fillattr(dentry->d_inode, stat);
366 /* Change block size to what the server returned */
367 stat->blksize = st->st_blksize;
368
369 kfree(st);
370 return 0;
371}
372
373/**
374 * v9fs_vfs_setattr_dotl - set file metadata
375 * @dentry: file whose metadata to set
376 * @iattr: metadata assignment structure
377 *
378 */
379
380int v9fs_vfs_setattr_dotl(struct dentry *dentry, struct iattr *iattr)
381{
382 int retval;
383 struct v9fs_session_info *v9ses;
384 struct p9_fid *fid;
385 struct p9_iattr_dotl p9attr;
386
387 P9_DPRINTK(P9_DEBUG_VFS, "\n");
388
389 retval = inode_change_ok(dentry->d_inode, iattr);
390 if (retval)
391 return retval;
392
393 p9attr.valid = iattr->ia_valid;
394 p9attr.mode = iattr->ia_mode;
395 p9attr.uid = iattr->ia_uid;
396 p9attr.gid = iattr->ia_gid;
397 p9attr.size = iattr->ia_size;
398 p9attr.atime_sec = iattr->ia_atime.tv_sec;
399 p9attr.atime_nsec = iattr->ia_atime.tv_nsec;
400 p9attr.mtime_sec = iattr->ia_mtime.tv_sec;
401 p9attr.mtime_nsec = iattr->ia_mtime.tv_nsec;
402
403 retval = -EPERM;
404 v9ses = v9fs_inode2v9ses(dentry->d_inode);
405 fid = v9fs_fid_lookup(dentry);
406 if (IS_ERR(fid))
407 return PTR_ERR(fid);
408
409 retval = p9_client_setattr(fid, &p9attr);
410 if (retval < 0)
411 return retval;
412
413 if ((iattr->ia_valid & ATTR_SIZE) &&
414 iattr->ia_size != i_size_read(dentry->d_inode)) {
415 retval = vmtruncate(dentry->d_inode, iattr->ia_size);
416 if (retval)
417 return retval;
418 }
419
420 setattr_copy(dentry->d_inode, iattr);
421 mark_inode_dirty(dentry->d_inode);
422 if (iattr->ia_valid & ATTR_MODE) {
423 /* We also want to update ACL when we update mode bits */
424 retval = v9fs_acl_chmod(dentry);
425 if (retval < 0)
426 return retval;
427 }
428 return 0;
429}
430
431/**
432 * v9fs_stat2inode_dotl - populate an inode structure with stat info
433 * @stat: stat structure
434 * @inode: inode to populate
435 * @sb: superblock of filesystem
436 *
437 */
438
439void
440v9fs_stat2inode_dotl(struct p9_stat_dotl *stat, struct inode *inode)
441{
442
443 if ((stat->st_result_mask & P9_STATS_BASIC) == P9_STATS_BASIC) {
444 inode->i_atime.tv_sec = stat->st_atime_sec;
445 inode->i_atime.tv_nsec = stat->st_atime_nsec;
446 inode->i_mtime.tv_sec = stat->st_mtime_sec;
447 inode->i_mtime.tv_nsec = stat->st_mtime_nsec;
448 inode->i_ctime.tv_sec = stat->st_ctime_sec;
449 inode->i_ctime.tv_nsec = stat->st_ctime_nsec;
450 inode->i_uid = stat->st_uid;
451 inode->i_gid = stat->st_gid;
452 inode->i_nlink = stat->st_nlink;
453 inode->i_mode = stat->st_mode;
454 inode->i_rdev = new_decode_dev(stat->st_rdev);
455
456 if ((S_ISBLK(inode->i_mode)) || (S_ISCHR(inode->i_mode)))
457 init_special_inode(inode, inode->i_mode, inode->i_rdev);
458
459 i_size_write(inode, stat->st_size);
460 inode->i_blocks = stat->st_blocks;
461 } else {
462 if (stat->st_result_mask & P9_STATS_ATIME) {
463 inode->i_atime.tv_sec = stat->st_atime_sec;
464 inode->i_atime.tv_nsec = stat->st_atime_nsec;
465 }
466 if (stat->st_result_mask & P9_STATS_MTIME) {
467 inode->i_mtime.tv_sec = stat->st_mtime_sec;
468 inode->i_mtime.tv_nsec = stat->st_mtime_nsec;
469 }
470 if (stat->st_result_mask & P9_STATS_CTIME) {
471 inode->i_ctime.tv_sec = stat->st_ctime_sec;
472 inode->i_ctime.tv_nsec = stat->st_ctime_nsec;
473 }
474 if (stat->st_result_mask & P9_STATS_UID)
475 inode->i_uid = stat->st_uid;
476 if (stat->st_result_mask & P9_STATS_GID)
477 inode->i_gid = stat->st_gid;
478 if (stat->st_result_mask & P9_STATS_NLINK)
479 inode->i_nlink = stat->st_nlink;
480 if (stat->st_result_mask & P9_STATS_MODE) {
481 inode->i_mode = stat->st_mode;
482 if ((S_ISBLK(inode->i_mode)) ||
483 (S_ISCHR(inode->i_mode)))
484 init_special_inode(inode, inode->i_mode,
485 inode->i_rdev);
486 }
487 if (stat->st_result_mask & P9_STATS_RDEV)
488 inode->i_rdev = new_decode_dev(stat->st_rdev);
489 if (stat->st_result_mask & P9_STATS_SIZE)
490 i_size_write(inode, stat->st_size);
491 if (stat->st_result_mask & P9_STATS_BLOCKS)
492 inode->i_blocks = stat->st_blocks;
493 }
494 if (stat->st_result_mask & P9_STATS_GEN)
495 inode->i_generation = stat->st_gen;
496
497 /* Currently we don't support P9_STATS_BTIME and P9_STATS_DATA_VERSION
498 * because the inode structure does not have fields for them.
499 */
500}
501
502static int
503v9fs_vfs_symlink_dotl(struct inode *dir, struct dentry *dentry,
504 const char *symname)
505{
506 struct v9fs_session_info *v9ses;
507 struct p9_fid *dfid;
508 struct p9_fid *fid = NULL;
509 struct inode *inode;
510 struct p9_qid qid;
511 char *name;
512 int err;
513 gid_t gid;
514
515 name = (char *) dentry->d_name.name;
516 P9_DPRINTK(P9_DEBUG_VFS, "v9fs_vfs_symlink_dotl : %lu,%s,%s\n",
517 dir->i_ino, name, symname);
518 v9ses = v9fs_inode2v9ses(dir);
519
520 dfid = v9fs_fid_lookup(dentry->d_parent);
521 if (IS_ERR(dfid)) {
522 err = PTR_ERR(dfid);
523 P9_DPRINTK(P9_DEBUG_VFS, "fid lookup failed %d\n", err);
524 return err;
525 }
526
527 gid = v9fs_get_fsgid_for_create(dir);
528
529 /* Server doesn't alter fid on TSYMLINK. Hence no need to clone it. */
530 err = p9_client_symlink(dfid, name, (char *)symname, gid, &qid);
531
532 if (err < 0) {
533 P9_DPRINTK(P9_DEBUG_VFS, "p9_client_symlink failed %d\n", err);
534 goto error;
535 }
536
537 if (v9ses->cache) {
538 /* Now walk from the parent so we can get an unopened fid. */
539 fid = p9_client_walk(dfid, 1, &name, 1);
540 if (IS_ERR(fid)) {
541 err = PTR_ERR(fid);
542 P9_DPRINTK(P9_DEBUG_VFS, "p9_client_walk failed %d\n",
543 err);
544 fid = NULL;
545 goto error;
546 }
547
548 /* instantiate inode and assign the unopened fid to dentry */
549 inode = v9fs_inode_from_fid(v9ses, fid, dir->i_sb);
550 if (IS_ERR(inode)) {
551 err = PTR_ERR(inode);
552 P9_DPRINTK(P9_DEBUG_VFS, "inode creation failed %d\n",
553 err);
554 goto error;
555 }
556 d_instantiate(dentry, inode);
557 err = v9fs_fid_add(dentry, fid);
558 if (err < 0)
559 goto error;
560 fid = NULL;
561 } else {
562 /* Not in cached mode. No need to populate inode with stat */
563 inode = v9fs_get_inode(dir->i_sb, S_IFLNK);
564 if (IS_ERR(inode)) {
565 err = PTR_ERR(inode);
566 goto error;
567 }
568 d_instantiate(dentry, inode);
569 }
570
571error:
572 if (fid)
573 p9_client_clunk(fid);
574
575 return err;
576}
577
578/**
579 * v9fs_vfs_link_dotl - create a hardlink for dotl
580 * @old_dentry: dentry for file to link to
581 * @dir: inode destination for new link
582 * @dentry: dentry for link
583 *
584 */
585
586static int
587v9fs_vfs_link_dotl(struct dentry *old_dentry, struct inode *dir,
588 struct dentry *dentry)
589{
590 int err;
591 struct p9_fid *dfid, *oldfid;
592 char *name;
593 struct v9fs_session_info *v9ses;
594 struct dentry *dir_dentry;
595
596 P9_DPRINTK(P9_DEBUG_VFS, "dir ino: %lu, old_name: %s, new_name: %s\n",
597 dir->i_ino, old_dentry->d_name.name,
598 dentry->d_name.name);
599
600 v9ses = v9fs_inode2v9ses(dir);
601 dir_dentry = v9fs_dentry_from_dir_inode(dir);
602 dfid = v9fs_fid_lookup(dir_dentry);
603 if (IS_ERR(dfid))
604 return PTR_ERR(dfid);
605
606 oldfid = v9fs_fid_lookup(old_dentry);
607 if (IS_ERR(oldfid))
608 return PTR_ERR(oldfid);
609
610 name = (char *) dentry->d_name.name;
611
612 err = p9_client_link(dfid, oldfid, (char *)dentry->d_name.name);
613
614 if (err < 0) {
615 P9_DPRINTK(P9_DEBUG_VFS, "p9_client_link failed %d\n", err);
616 return err;
617 }
618
619 if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) {
620 /* Get the latest stat info from server. */
621 struct p9_fid *fid;
622 struct p9_stat_dotl *st;
623
624 fid = v9fs_fid_lookup(old_dentry);
625 if (IS_ERR(fid))
626 return PTR_ERR(fid);
627
628 st = p9_client_getattr_dotl(fid, P9_STATS_BASIC);
629 if (IS_ERR(st))
630 return PTR_ERR(st);
631
632 v9fs_stat2inode_dotl(st, old_dentry->d_inode);
633
634 kfree(st);
635 } else {
636 /* Caching disabled. No need to get upto date stat info.
637 * This dentry will be released immediately. So, just hold the
638 * inode
639 */
640 ihold(old_dentry->d_inode);
641 }
642 d_instantiate(dentry, old_dentry->d_inode);
643
644 return err;
645}
646
647/**
648 * v9fs_vfs_mknod_dotl - create a special file
649 * @dir: inode destination for new link
650 * @dentry: dentry for file
651 * @mode: mode for creation
652 * @rdev: device associated with special file
653 *
654 */
655static int
656v9fs_vfs_mknod_dotl(struct inode *dir, struct dentry *dentry, int omode,
657 dev_t rdev)
658{
659 int err;
660 char *name;
661 mode_t mode;
662 struct v9fs_session_info *v9ses;
663 struct p9_fid *fid = NULL, *dfid = NULL;
664 struct inode *inode;
665 gid_t gid;
666 struct p9_qid qid;
667 struct dentry *dir_dentry;
668 struct posix_acl *dacl = NULL, *pacl = NULL;
669
670 P9_DPRINTK(P9_DEBUG_VFS,
671 " %lu,%s mode: %x MAJOR: %u MINOR: %u\n", dir->i_ino,
672 dentry->d_name.name, omode, MAJOR(rdev), MINOR(rdev));
673
674 if (!new_valid_dev(rdev))
675 return -EINVAL;
676
677 v9ses = v9fs_inode2v9ses(dir);
678 dir_dentry = v9fs_dentry_from_dir_inode(dir);
679 dfid = v9fs_fid_lookup(dir_dentry);
680 if (IS_ERR(dfid)) {
681 err = PTR_ERR(dfid);
682 P9_DPRINTK(P9_DEBUG_VFS, "fid lookup failed %d\n", err);
683 dfid = NULL;
684 goto error;
685 }
686
687 gid = v9fs_get_fsgid_for_create(dir);
688 mode = omode;
689 /* Update mode based on ACL value */
690 err = v9fs_acl_mode(dir, &mode, &dacl, &pacl);
691 if (err) {
692 P9_DPRINTK(P9_DEBUG_VFS,
693 "Failed to get acl values in mknod %d\n", err);
694 goto error;
695 }
696 name = (char *) dentry->d_name.name;
697
698 err = p9_client_mknod_dotl(dfid, name, mode, rdev, gid, &qid);
699 if (err < 0)
700 goto error;
701
702 /* instantiate inode and assign the unopened fid to the dentry */
703 if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) {
704 fid = p9_client_walk(dfid, 1, &name, 1);
705 if (IS_ERR(fid)) {
706 err = PTR_ERR(fid);
707 P9_DPRINTK(P9_DEBUG_VFS, "p9_client_walk failed %d\n",
708 err);
709 fid = NULL;
710 goto error;
711 }
712
713 inode = v9fs_inode_from_fid(v9ses, fid, dir->i_sb);
714 if (IS_ERR(inode)) {
715 err = PTR_ERR(inode);
716 P9_DPRINTK(P9_DEBUG_VFS, "inode creation failed %d\n",
717 err);
718 goto error;
719 }
720 d_instantiate(dentry, inode);
721 err = v9fs_fid_add(dentry, fid);
722 if (err < 0)
723 goto error;
724 fid = NULL;
725 } else {
726 /*
727 * Not in cached mode. No need to populate inode with stat.
728 * socket syscall returns a fd, so we need instantiate
729 */
730 inode = v9fs_get_inode(dir->i_sb, mode);
731 if (IS_ERR(inode)) {
732 err = PTR_ERR(inode);
733 goto error;
734 }
735 d_instantiate(dentry, inode);
736 }
737 /* Now set the ACL based on the default value */
738 v9fs_set_create_acl(dentry, dacl, pacl);
739error:
740 if (fid)
741 p9_client_clunk(fid);
742 return err;
743}
744
745/**
746 * v9fs_vfs_follow_link_dotl - follow a symlink path
747 * @dentry: dentry for symlink
748 * @nd: nameidata
749 *
750 */
751
752static void *
753v9fs_vfs_follow_link_dotl(struct dentry *dentry, struct nameidata *nd)
754{
755 int retval;
756 struct p9_fid *fid;
757 char *link = __getname();
758 char *target;
759
760 P9_DPRINTK(P9_DEBUG_VFS, "%s\n", dentry->d_name.name);
761
762 if (!link) {
763 link = ERR_PTR(-ENOMEM);
764 goto ndset;
765 }
766 fid = v9fs_fid_lookup(dentry);
767 if (IS_ERR(fid)) {
768 __putname(link);
769 link = ERR_PTR(PTR_ERR(fid));
770 goto ndset;
771 }
772 retval = p9_client_readlink(fid, &target);
773 if (!retval) {
774 strcpy(link, target);
775 kfree(target);
776 goto ndset;
777 }
778 __putname(link);
779 link = ERR_PTR(retval);
780ndset:
781 nd_set_link(nd, link);
782 return NULL;
783}
784
785const struct inode_operations v9fs_dir_inode_operations_dotl = {
786 .create = v9fs_vfs_create_dotl,
787 .lookup = v9fs_vfs_lookup,
788 .link = v9fs_vfs_link_dotl,
789 .symlink = v9fs_vfs_symlink_dotl,
790 .unlink = v9fs_vfs_unlink,
791 .mkdir = v9fs_vfs_mkdir_dotl,
792 .rmdir = v9fs_vfs_rmdir,
793 .mknod = v9fs_vfs_mknod_dotl,
794 .rename = v9fs_vfs_rename,
795 .getattr = v9fs_vfs_getattr_dotl,
796 .setattr = v9fs_vfs_setattr_dotl,
797 .setxattr = generic_setxattr,
798 .getxattr = generic_getxattr,
799 .removexattr = generic_removexattr,
800 .listxattr = v9fs_listxattr,
801 .check_acl = v9fs_check_acl,
802};
803
804const struct inode_operations v9fs_file_inode_operations_dotl = {
805 .getattr = v9fs_vfs_getattr_dotl,
806 .setattr = v9fs_vfs_setattr_dotl,
807 .setxattr = generic_setxattr,
808 .getxattr = generic_getxattr,
809 .removexattr = generic_removexattr,
810 .listxattr = v9fs_listxattr,
811 .check_acl = v9fs_check_acl,
812};
813
814const struct inode_operations v9fs_symlink_inode_operations_dotl = {
815 .readlink = generic_readlink,
816 .follow_link = v9fs_vfs_follow_link_dotl,
817 .put_link = v9fs_vfs_put_link,
818 .getattr = v9fs_vfs_getattr_dotl,
819 .setattr = v9fs_vfs_setattr_dotl,
820 .setxattr = generic_setxattr,
821 .getxattr = generic_getxattr,
822 .removexattr = generic_removexattr,
823 .listxattr = v9fs_listxattr,
824};
diff --git a/fs/9p/xattr.c b/fs/9p/xattr.c
index 43ec7df84336..d288773871b3 100644
--- a/fs/9p/xattr.c
+++ b/fs/9p/xattr.c
@@ -133,7 +133,7 @@ int v9fs_xattr_set(struct dentry *dentry, const char *name,
133 "p9_client_xattrcreate failed %d\n", retval); 133 "p9_client_xattrcreate failed %d\n", retval);
134 goto error; 134 goto error;
135 } 135 }
136 msize = fid->clnt->msize;; 136 msize = fid->clnt->msize;
137 while (value_len) { 137 while (value_len) {
138 if (value_len > (msize - P9_IOHDRSZ)) 138 if (value_len > (msize - P9_IOHDRSZ))
139 write_count = msize - P9_IOHDRSZ; 139 write_count = msize - P9_IOHDRSZ;