aboutsummaryrefslogtreecommitdiffstats
path: root/fs/9p/vfs_inode.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/9p/vfs_inode.c')
-rw-r--r--fs/9p/vfs_inode.c770
1 files changed, 739 insertions, 31 deletions
diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
index 4331b3b5ee1c..d97c34a24f7a 100644
--- a/fs/9p/vfs_inode.c
+++ b/fs/9p/vfs_inode.c
@@ -35,6 +35,7 @@
35#include <linux/idr.h> 35#include <linux/idr.h>
36#include <linux/sched.h> 36#include <linux/sched.h>
37#include <linux/slab.h> 37#include <linux/slab.h>
38#include <linux/xattr.h>
38#include <net/9p/9p.h> 39#include <net/9p/9p.h>
39#include <net/9p/client.h> 40#include <net/9p/client.h>
40 41
@@ -42,6 +43,7 @@
42#include "v9fs_vfs.h" 43#include "v9fs_vfs.h"
43#include "fid.h" 44#include "fid.h"
44#include "cache.h" 45#include "cache.h"
46#include "xattr.h"
45 47
46static const struct inode_operations v9fs_dir_inode_operations; 48static const struct inode_operations v9fs_dir_inode_operations;
47static const struct inode_operations v9fs_dir_inode_operations_dotu; 49static const struct inode_operations v9fs_dir_inode_operations_dotu;
@@ -236,6 +238,41 @@ void v9fs_destroy_inode(struct inode *inode)
236#endif 238#endif
237 239
238/** 240/**
241 * v9fs_get_fsgid_for_create - Helper function to get the gid for creating a
242 * new file system object. This checks the S_ISGID to determine the owning
243 * group of the new file system object.
244 */
245
246static gid_t v9fs_get_fsgid_for_create(struct inode *dir_inode)
247{
248 BUG_ON(dir_inode == NULL);
249
250 if (dir_inode->i_mode & S_ISGID) {
251 /* set_gid bit is set.*/
252 return dir_inode->i_gid;
253 }
254 return current_fsgid();
255}
256
257/**
258 * v9fs_dentry_from_dir_inode - helper function to get the dentry from
259 * dir inode.
260 *
261 */
262
263static struct dentry *v9fs_dentry_from_dir_inode(struct inode *inode)
264{
265 struct dentry *dentry;
266
267 spin_lock(&dcache_lock);
268 /* Directory should have only one entry. */
269 BUG_ON(S_ISDIR(inode->i_mode) && !list_is_singular(&inode->i_dentry));
270 dentry = list_entry(inode->i_dentry.next, struct dentry, d_alias);
271 spin_unlock(&dcache_lock);
272 return dentry;
273}
274
275/**
239 * v9fs_get_inode - helper function to setup an inode 276 * v9fs_get_inode - helper function to setup an inode
240 * @sb: superblock 277 * @sb: superblock
241 * @mode: mode to setup inode with 278 * @mode: mode to setup inode with
@@ -267,7 +304,13 @@ struct inode *v9fs_get_inode(struct super_block *sb, int mode)
267 case S_IFBLK: 304 case S_IFBLK:
268 case S_IFCHR: 305 case S_IFCHR:
269 case S_IFSOCK: 306 case S_IFSOCK:
270 if (!v9fs_proto_dotu(v9ses)) { 307 if (v9fs_proto_dotl(v9ses)) {
308 inode->i_op = &v9fs_file_inode_operations_dotl;
309 inode->i_fop = &v9fs_file_operations_dotl;
310 } else if (v9fs_proto_dotu(v9ses)) {
311 inode->i_op = &v9fs_file_inode_operations;
312 inode->i_fop = &v9fs_file_operations;
313 } else {
271 P9_DPRINTK(P9_DEBUG_ERROR, 314 P9_DPRINTK(P9_DEBUG_ERROR,
272 "special files without extended mode\n"); 315 "special files without extended mode\n");
273 err = -EINVAL; 316 err = -EINVAL;
@@ -387,8 +430,10 @@ error:
387 * @inode: inode to release 430 * @inode: inode to release
388 * 431 *
389 */ 432 */
390void v9fs_clear_inode(struct inode *inode) 433void v9fs_evict_inode(struct inode *inode)
391{ 434{
435 truncate_inode_pages(inode->i_mapping, 0);
436 end_writeback(inode);
392 filemap_fdatawrite(inode->i_mapping); 437 filemap_fdatawrite(inode->i_mapping);
393 438
394#ifdef CONFIG_9P_FSCACHE 439#ifdef CONFIG_9P_FSCACHE
@@ -396,23 +441,14 @@ void v9fs_clear_inode(struct inode *inode)
396#endif 441#endif
397} 442}
398 443
399/**
400 * v9fs_inode_from_fid - populate an inode by issuing a attribute request
401 * @v9ses: session information
402 * @fid: fid to issue attribute request for
403 * @sb: superblock on which to create inode
404 *
405 */
406
407static struct inode * 444static struct inode *
408v9fs_inode_from_fid(struct v9fs_session_info *v9ses, struct p9_fid *fid, 445v9fs_inode(struct v9fs_session_info *v9ses, struct p9_fid *fid,
409 struct super_block *sb) 446 struct super_block *sb)
410{ 447{
411 int err, umode; 448 int err, umode;
412 struct inode *ret; 449 struct inode *ret = NULL;
413 struct p9_wstat *st; 450 struct p9_wstat *st;
414 451
415 ret = NULL;
416 st = p9_client_stat(fid); 452 st = p9_client_stat(fid);
417 if (IS_ERR(st)) 453 if (IS_ERR(st))
418 return ERR_CAST(st); 454 return ERR_CAST(st);
@@ -433,15 +469,62 @@ v9fs_inode_from_fid(struct v9fs_session_info *v9ses, struct p9_fid *fid,
433#endif 469#endif
434 p9stat_free(st); 470 p9stat_free(st);
435 kfree(st); 471 kfree(st);
436
437 return ret; 472 return ret;
438
439error: 473error:
440 p9stat_free(st); 474 p9stat_free(st);
441 kfree(st); 475 kfree(st);
442 return ERR_PTR(err); 476 return ERR_PTR(err);
443} 477}
444 478
479static struct inode *
480v9fs_inode_dotl(struct v9fs_session_info *v9ses, struct p9_fid *fid,
481 struct super_block *sb)
482{
483 struct inode *ret = NULL;
484 int err;
485 struct p9_stat_dotl *st;
486
487 st = p9_client_getattr_dotl(fid, P9_STATS_BASIC);
488 if (IS_ERR(st))
489 return ERR_CAST(st);
490
491 ret = v9fs_get_inode(sb, st->st_mode);
492 if (IS_ERR(ret)) {
493 err = PTR_ERR(ret);
494 goto error;
495 }
496
497 v9fs_stat2inode_dotl(st, ret);
498 ret->i_ino = v9fs_qid2ino(&st->qid);
499#ifdef CONFIG_9P_FSCACHE
500 v9fs_vcookie_set_qid(ret, &st->qid);
501 v9fs_cache_inode_get_cookie(ret);
502#endif
503 kfree(st);
504 return ret;
505error:
506 kfree(st);
507 return ERR_PTR(err);
508}
509
510/**
511 * v9fs_inode_from_fid - Helper routine to populate an inode by
512 * issuing a attribute request
513 * @v9ses: session information
514 * @fid: fid to issue attribute request for
515 * @sb: superblock on which to create inode
516 *
517 */
518static inline struct inode *
519v9fs_inode_from_fid(struct v9fs_session_info *v9ses, struct p9_fid *fid,
520 struct super_block *sb)
521{
522 if (v9fs_proto_dotl(v9ses))
523 return v9fs_inode_dotl(v9ses, fid, sb);
524 else
525 return v9fs_inode(v9ses, fid, sb);
526}
527
445/** 528/**
446 * v9fs_remove - helper function to remove files and directories 529 * v9fs_remove - helper function to remove files and directories
447 * @dir: directory inode that is being deleted 530 * @dir: directory inode that is being deleted
@@ -563,6 +646,118 @@ error:
563} 646}
564 647
565/** 648/**
649 * v9fs_vfs_create_dotl - VFS hook to create files for 9P2000.L protocol.
650 * @dir: directory inode that is being created
651 * @dentry: dentry that is being deleted
652 * @mode: create permissions
653 * @nd: path information
654 *
655 */
656
657static int
658v9fs_vfs_create_dotl(struct inode *dir, struct dentry *dentry, int mode,
659 struct nameidata *nd)
660{
661 int err = 0;
662 char *name = NULL;
663 gid_t gid;
664 int flags;
665 struct v9fs_session_info *v9ses;
666 struct p9_fid *fid = NULL;
667 struct p9_fid *dfid, *ofid;
668 struct file *filp;
669 struct p9_qid qid;
670 struct inode *inode;
671
672 v9ses = v9fs_inode2v9ses(dir);
673 if (nd && nd->flags & LOOKUP_OPEN)
674 flags = nd->intent.open.flags - 1;
675 else
676 flags = O_RDWR;
677
678 name = (char *) dentry->d_name.name;
679 P9_DPRINTK(P9_DEBUG_VFS, "v9fs_vfs_create_dotl: name:%s flags:0x%x "
680 "mode:0x%x\n", name, flags, mode);
681
682 dfid = v9fs_fid_lookup(dentry->d_parent);
683 if (IS_ERR(dfid)) {
684 err = PTR_ERR(dfid);
685 P9_DPRINTK(P9_DEBUG_VFS, "fid lookup failed %d\n", err);
686 return err;
687 }
688
689 /* clone a fid to use for creation */
690 ofid = p9_client_walk(dfid, 0, NULL, 1);
691 if (IS_ERR(ofid)) {
692 err = PTR_ERR(ofid);
693 P9_DPRINTK(P9_DEBUG_VFS, "p9_client_walk failed %d\n", err);
694 return err;
695 }
696
697 gid = v9fs_get_fsgid_for_create(dir);
698 err = p9_client_create_dotl(ofid, name, flags, mode, gid, &qid);
699 if (err < 0) {
700 P9_DPRINTK(P9_DEBUG_VFS,
701 "p9_client_open_dotl failed in creat %d\n",
702 err);
703 goto error;
704 }
705
706 /* No need to populate the inode if we are not opening the file AND
707 * not in cached mode.
708 */
709 if (!v9ses->cache && !(nd && nd->flags & LOOKUP_OPEN)) {
710 /* Not in cached mode. No need to populate inode with stat */
711 dentry->d_op = &v9fs_dentry_operations;
712 p9_client_clunk(ofid);
713 d_instantiate(dentry, NULL);
714 return 0;
715 }
716
717 /* Now walk from the parent so we can get an unopened fid. */
718 fid = p9_client_walk(dfid, 1, &name, 1);
719 if (IS_ERR(fid)) {
720 err = PTR_ERR(fid);
721 P9_DPRINTK(P9_DEBUG_VFS, "p9_client_walk failed %d\n", err);
722 fid = NULL;
723 goto error;
724 }
725
726 /* instantiate inode and assign the unopened fid to dentry */
727 inode = v9fs_inode_from_fid(v9ses, fid, dir->i_sb);
728 if (IS_ERR(inode)) {
729 err = PTR_ERR(inode);
730 P9_DPRINTK(P9_DEBUG_VFS, "inode creation failed %d\n", err);
731 goto error;
732 }
733 dentry->d_op = &v9fs_cached_dentry_operations;
734 d_instantiate(dentry, inode);
735 err = v9fs_fid_add(dentry, fid);
736 if (err < 0)
737 goto error;
738
739 /* if we are opening a file, assign the open fid to the file */
740 if (nd && nd->flags & LOOKUP_OPEN) {
741 filp = lookup_instantiate_filp(nd, dentry, v9fs_open_created);
742 if (IS_ERR(filp)) {
743 p9_client_clunk(ofid);
744 return PTR_ERR(filp);
745 }
746 filp->private_data = ofid;
747 } else
748 p9_client_clunk(ofid);
749
750 return 0;
751
752error:
753 if (ofid)
754 p9_client_clunk(ofid);
755 if (fid)
756 p9_client_clunk(fid);
757 return err;
758}
759
760/**
566 * v9fs_vfs_create - VFS hook to create files 761 * v9fs_vfs_create - VFS hook to create files
567 * @dir: directory inode that is being created 762 * @dir: directory inode that is being created
568 * @dentry: dentry that is being deleted 763 * @dentry: dentry that is being deleted
@@ -652,6 +847,83 @@ static int v9fs_vfs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
652 return err; 847 return err;
653} 848}
654 849
850
851/**
852 * v9fs_vfs_mkdir_dotl - VFS mkdir hook to create a directory
853 * @dir: inode that is being unlinked
854 * @dentry: dentry that is being unlinked
855 * @mode: mode for new directory
856 *
857 */
858
859static int v9fs_vfs_mkdir_dotl(struct inode *dir, struct dentry *dentry,
860 int mode)
861{
862 int err;
863 struct v9fs_session_info *v9ses;
864 struct p9_fid *fid = NULL, *dfid = NULL;
865 gid_t gid;
866 char *name;
867 struct inode *inode;
868 struct p9_qid qid;
869 struct dentry *dir_dentry;
870
871 P9_DPRINTK(P9_DEBUG_VFS, "name %s\n", dentry->d_name.name);
872 err = 0;
873 v9ses = v9fs_inode2v9ses(dir);
874
875 mode |= S_IFDIR;
876 dir_dentry = v9fs_dentry_from_dir_inode(dir);
877 dfid = v9fs_fid_lookup(dir_dentry);
878 if (IS_ERR(dfid)) {
879 err = PTR_ERR(dfid);
880 P9_DPRINTK(P9_DEBUG_VFS, "fid lookup failed %d\n", err);
881 dfid = NULL;
882 goto error;
883 }
884
885 gid = v9fs_get_fsgid_for_create(dir);
886 if (gid < 0) {
887 P9_DPRINTK(P9_DEBUG_VFS, "v9fs_get_fsgid_for_create failed\n");
888 goto error;
889 }
890
891 name = (char *) dentry->d_name.name;
892 err = p9_client_mkdir_dotl(dfid, name, mode, gid, &qid);
893 if (err < 0)
894 goto error;
895
896 /* instantiate inode and assign the unopened fid to the dentry */
897 if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) {
898 fid = p9_client_walk(dfid, 1, &name, 1);
899 if (IS_ERR(fid)) {
900 err = PTR_ERR(fid);
901 P9_DPRINTK(P9_DEBUG_VFS, "p9_client_walk failed %d\n",
902 err);
903 fid = NULL;
904 goto error;
905 }
906
907 inode = v9fs_inode_from_fid(v9ses, fid, dir->i_sb);
908 if (IS_ERR(inode)) {
909 err = PTR_ERR(inode);
910 P9_DPRINTK(P9_DEBUG_VFS, "inode creation failed %d\n",
911 err);
912 goto error;
913 }
914 dentry->d_op = &v9fs_cached_dentry_operations;
915 d_instantiate(dentry, inode);
916 err = v9fs_fid_add(dentry, fid);
917 if (err < 0)
918 goto error;
919 fid = NULL;
920 }
921error:
922 if (fid)
923 p9_client_clunk(fid);
924 return err;
925}
926
655/** 927/**
656 * v9fs_vfs_lookup - VFS lookup hook to "walk" to a new inode 928 * v9fs_vfs_lookup - VFS lookup hook to "walk" to a new inode
657 * @dir: inode that is being walked from 929 * @dir: inode that is being walked from
@@ -678,6 +950,7 @@ static struct dentry *v9fs_vfs_lookup(struct inode *dir, struct dentry *dentry,
678 950
679 sb = dir->i_sb; 951 sb = dir->i_sb;
680 v9ses = v9fs_inode2v9ses(dir); 952 v9ses = v9fs_inode2v9ses(dir);
953 /* We can walk d_parent because we hold the dir->i_mutex */
681 dfid = v9fs_fid_lookup(dentry->d_parent); 954 dfid = v9fs_fid_lookup(dentry->d_parent);
682 if (IS_ERR(dfid)) 955 if (IS_ERR(dfid))
683 return ERR_CAST(dfid); 956 return ERR_CAST(dfid);
@@ -785,27 +1058,33 @@ v9fs_vfs_rename(struct inode *old_dir, struct dentry *old_dentry,
785 goto clunk_olddir; 1058 goto clunk_olddir;
786 } 1059 }
787 1060
1061 down_write(&v9ses->rename_sem);
788 if (v9fs_proto_dotl(v9ses)) { 1062 if (v9fs_proto_dotl(v9ses)) {
789 retval = p9_client_rename(oldfid, newdirfid, 1063 retval = p9_client_rename(oldfid, newdirfid,
790 (char *) new_dentry->d_name.name); 1064 (char *) new_dentry->d_name.name);
791 if (retval != -ENOSYS) 1065 if (retval != -ENOSYS)
792 goto clunk_newdir; 1066 goto clunk_newdir;
793 } 1067 }
1068 if (old_dentry->d_parent != new_dentry->d_parent) {
1069 /*
1070 * 9P .u can only handle file rename in the same directory
1071 */
794 1072
795 /* 9P can only handle file rename in the same directory */
796 if (memcmp(&olddirfid->qid, &newdirfid->qid, sizeof(newdirfid->qid))) {
797 P9_DPRINTK(P9_DEBUG_ERROR, 1073 P9_DPRINTK(P9_DEBUG_ERROR,
798 "old dir and new dir are different\n"); 1074 "old dir and new dir are different\n");
799 retval = -EXDEV; 1075 retval = -EXDEV;
800 goto clunk_newdir; 1076 goto clunk_newdir;
801 } 1077 }
802
803 v9fs_blank_wstat(&wstat); 1078 v9fs_blank_wstat(&wstat);
804 wstat.muid = v9ses->uname; 1079 wstat.muid = v9ses->uname;
805 wstat.name = (char *) new_dentry->d_name.name; 1080 wstat.name = (char *) new_dentry->d_name.name;
806 retval = p9_client_wstat(oldfid, &wstat); 1081 retval = p9_client_wstat(oldfid, &wstat);
807 1082
808clunk_newdir: 1083clunk_newdir:
1084 if (!retval)
1085 /* successful rename */
1086 d_move(old_dentry, new_dentry);
1087 up_write(&v9ses->rename_sem);
809 p9_client_clunk(newdirfid); 1088 p9_client_clunk(newdirfid);
810 1089
811clunk_olddir: 1090clunk_olddir:
@@ -853,6 +1132,42 @@ v9fs_vfs_getattr(struct vfsmount *mnt, struct dentry *dentry,
853 return 0; 1132 return 0;
854} 1133}
855 1134
1135static int
1136v9fs_vfs_getattr_dotl(struct vfsmount *mnt, struct dentry *dentry,
1137 struct kstat *stat)
1138{
1139 int err;
1140 struct v9fs_session_info *v9ses;
1141 struct p9_fid *fid;
1142 struct p9_stat_dotl *st;
1143
1144 P9_DPRINTK(P9_DEBUG_VFS, "dentry: %p\n", dentry);
1145 err = -EPERM;
1146 v9ses = v9fs_inode2v9ses(dentry->d_inode);
1147 if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE)
1148 return simple_getattr(mnt, dentry, stat);
1149
1150 fid = v9fs_fid_lookup(dentry);
1151 if (IS_ERR(fid))
1152 return PTR_ERR(fid);
1153
1154 /* Ask for all the fields in stat structure. Server will return
1155 * whatever it supports
1156 */
1157
1158 st = p9_client_getattr_dotl(fid, P9_STATS_ALL);
1159 if (IS_ERR(st))
1160 return PTR_ERR(st);
1161
1162 v9fs_stat2inode_dotl(st, dentry->d_inode);
1163 generic_fillattr(dentry->d_inode, stat);
1164 /* Change block size to what the server returned */
1165 stat->blksize = st->st_blksize;
1166
1167 kfree(st);
1168 return 0;
1169}
1170
856/** 1171/**
857 * v9fs_vfs_setattr - set file metadata 1172 * v9fs_vfs_setattr - set file metadata
858 * @dentry: file whose metadata to set 1173 * @dentry: file whose metadata to set
@@ -896,6 +1211,58 @@ static int v9fs_vfs_setattr(struct dentry *dentry, struct iattr *iattr)
896 } 1211 }
897 1212
898 retval = p9_client_wstat(fid, &wstat); 1213 retval = p9_client_wstat(fid, &wstat);
1214 if (retval < 0)
1215 return retval;
1216
1217 if ((iattr->ia_valid & ATTR_SIZE) &&
1218 iattr->ia_size != i_size_read(dentry->d_inode)) {
1219 retval = vmtruncate(dentry->d_inode, iattr->ia_size);
1220 if (retval)
1221 return retval;
1222 }
1223
1224 setattr_copy(dentry->d_inode, iattr);
1225 mark_inode_dirty(dentry->d_inode);
1226 return 0;
1227}
1228
1229/**
1230 * v9fs_vfs_setattr_dotl - set file metadata
1231 * @dentry: file whose metadata to set
1232 * @iattr: metadata assignment structure
1233 *
1234 */
1235
1236static int v9fs_vfs_setattr_dotl(struct dentry *dentry, struct iattr *iattr)
1237{
1238 int retval;
1239 struct v9fs_session_info *v9ses;
1240 struct p9_fid *fid;
1241 struct p9_iattr_dotl p9attr;
1242
1243 P9_DPRINTK(P9_DEBUG_VFS, "\n");
1244
1245 retval = inode_change_ok(dentry->d_inode, iattr);
1246 if (retval)
1247 return retval;
1248
1249 p9attr.valid = iattr->ia_valid;
1250 p9attr.mode = iattr->ia_mode;
1251 p9attr.uid = iattr->ia_uid;
1252 p9attr.gid = iattr->ia_gid;
1253 p9attr.size = iattr->ia_size;
1254 p9attr.atime_sec = iattr->ia_atime.tv_sec;
1255 p9attr.atime_nsec = iattr->ia_atime.tv_nsec;
1256 p9attr.mtime_sec = iattr->ia_mtime.tv_sec;
1257 p9attr.mtime_nsec = iattr->ia_mtime.tv_nsec;
1258
1259 retval = -EPERM;
1260 v9ses = v9fs_inode2v9ses(dentry->d_inode);
1261 fid = v9fs_fid_lookup(dentry);
1262 if (IS_ERR(fid))
1263 return PTR_ERR(fid);
1264
1265 retval = p9_client_setattr(fid, &p9attr);
899 if (retval >= 0) 1266 if (retval >= 0)
900 retval = inode_setattr(dentry->d_inode, iattr); 1267 retval = inode_setattr(dentry->d_inode, iattr);
901 1268
@@ -980,6 +1347,77 @@ v9fs_stat2inode(struct p9_wstat *stat, struct inode *inode,
980} 1347}
981 1348
982/** 1349/**
1350 * v9fs_stat2inode_dotl - populate an inode structure with stat info
1351 * @stat: stat structure
1352 * @inode: inode to populate
1353 * @sb: superblock of filesystem
1354 *
1355 */
1356
1357void
1358v9fs_stat2inode_dotl(struct p9_stat_dotl *stat, struct inode *inode)
1359{
1360
1361 if ((stat->st_result_mask & P9_STATS_BASIC) == P9_STATS_BASIC) {
1362 inode->i_atime.tv_sec = stat->st_atime_sec;
1363 inode->i_atime.tv_nsec = stat->st_atime_nsec;
1364 inode->i_mtime.tv_sec = stat->st_mtime_sec;
1365 inode->i_mtime.tv_nsec = stat->st_mtime_nsec;
1366 inode->i_ctime.tv_sec = stat->st_ctime_sec;
1367 inode->i_ctime.tv_nsec = stat->st_ctime_nsec;
1368 inode->i_uid = stat->st_uid;
1369 inode->i_gid = stat->st_gid;
1370 inode->i_nlink = stat->st_nlink;
1371 inode->i_mode = stat->st_mode;
1372 inode->i_rdev = new_decode_dev(stat->st_rdev);
1373
1374 if ((S_ISBLK(inode->i_mode)) || (S_ISCHR(inode->i_mode)))
1375 init_special_inode(inode, inode->i_mode, inode->i_rdev);
1376
1377 i_size_write(inode, stat->st_size);
1378 inode->i_blocks = stat->st_blocks;
1379 } else {
1380 if (stat->st_result_mask & P9_STATS_ATIME) {
1381 inode->i_atime.tv_sec = stat->st_atime_sec;
1382 inode->i_atime.tv_nsec = stat->st_atime_nsec;
1383 }
1384 if (stat->st_result_mask & P9_STATS_MTIME) {
1385 inode->i_mtime.tv_sec = stat->st_mtime_sec;
1386 inode->i_mtime.tv_nsec = stat->st_mtime_nsec;
1387 }
1388 if (stat->st_result_mask & P9_STATS_CTIME) {
1389 inode->i_ctime.tv_sec = stat->st_ctime_sec;
1390 inode->i_ctime.tv_nsec = stat->st_ctime_nsec;
1391 }
1392 if (stat->st_result_mask & P9_STATS_UID)
1393 inode->i_uid = stat->st_uid;
1394 if (stat->st_result_mask & P9_STATS_GID)
1395 inode->i_gid = stat->st_gid;
1396 if (stat->st_result_mask & P9_STATS_NLINK)
1397 inode->i_nlink = stat->st_nlink;
1398 if (stat->st_result_mask & P9_STATS_MODE) {
1399 inode->i_mode = stat->st_mode;
1400 if ((S_ISBLK(inode->i_mode)) ||
1401 (S_ISCHR(inode->i_mode)))
1402 init_special_inode(inode, inode->i_mode,
1403 inode->i_rdev);
1404 }
1405 if (stat->st_result_mask & P9_STATS_RDEV)
1406 inode->i_rdev = new_decode_dev(stat->st_rdev);
1407 if (stat->st_result_mask & P9_STATS_SIZE)
1408 i_size_write(inode, stat->st_size);
1409 if (stat->st_result_mask & P9_STATS_BLOCKS)
1410 inode->i_blocks = stat->st_blocks;
1411 }
1412 if (stat->st_result_mask & P9_STATS_GEN)
1413 inode->i_generation = stat->st_gen;
1414
1415 /* Currently we don't support P9_STATS_BTIME and P9_STATS_DATA_VERSION
1416 * because the inode structure does not have fields for them.
1417 */
1418}
1419
1420/**
983 * v9fs_qid2ino - convert qid into inode number 1421 * v9fs_qid2ino - convert qid into inode number
984 * @qid: qid to hash 1422 * @qid: qid to hash
985 * 1423 *
@@ -1022,7 +1460,7 @@ static int v9fs_readlink(struct dentry *dentry, char *buffer, int buflen)
1022 if (IS_ERR(fid)) 1460 if (IS_ERR(fid))
1023 return PTR_ERR(fid); 1461 return PTR_ERR(fid);
1024 1462
1025 if (!v9fs_proto_dotu(v9ses)) 1463 if (!v9fs_proto_dotu(v9ses) && !v9fs_proto_dotl(v9ses))
1026 return -EBADF; 1464 return -EBADF;
1027 1465
1028 st = p9_client_stat(fid); 1466 st = p9_client_stat(fid);
@@ -1128,6 +1566,99 @@ static int v9fs_vfs_mkspecial(struct inode *dir, struct dentry *dentry,
1128} 1566}
1129 1567
1130/** 1568/**
1569 * v9fs_vfs_symlink_dotl - helper function to create symlinks
1570 * @dir: directory inode containing symlink
1571 * @dentry: dentry for symlink
1572 * @symname: symlink data
1573 *
1574 * See Also: 9P2000.L RFC for more information
1575 *
1576 */
1577
1578static int
1579v9fs_vfs_symlink_dotl(struct inode *dir, struct dentry *dentry,
1580 const char *symname)
1581{
1582 struct v9fs_session_info *v9ses;
1583 struct p9_fid *dfid;
1584 struct p9_fid *fid = NULL;
1585 struct inode *inode;
1586 struct p9_qid qid;
1587 char *name;
1588 int err;
1589 gid_t gid;
1590
1591 name = (char *) dentry->d_name.name;
1592 P9_DPRINTK(P9_DEBUG_VFS, "v9fs_vfs_symlink_dotl : %lu,%s,%s\n",
1593 dir->i_ino, name, symname);
1594 v9ses = v9fs_inode2v9ses(dir);
1595
1596 dfid = v9fs_fid_lookup(dentry->d_parent);
1597 if (IS_ERR(dfid)) {
1598 err = PTR_ERR(dfid);
1599 P9_DPRINTK(P9_DEBUG_VFS, "fid lookup failed %d\n", err);
1600 return err;
1601 }
1602
1603 gid = v9fs_get_fsgid_for_create(dir);
1604
1605 if (gid < 0) {
1606 P9_DPRINTK(P9_DEBUG_VFS, "v9fs_get_egid failed %d\n", gid);
1607 goto error;
1608 }
1609
1610 /* Server doesn't alter fid on TSYMLINK. Hence no need to clone it. */
1611 err = p9_client_symlink(dfid, name, (char *)symname, gid, &qid);
1612
1613 if (err < 0) {
1614 P9_DPRINTK(P9_DEBUG_VFS, "p9_client_symlink failed %d\n", err);
1615 goto error;
1616 }
1617
1618 if (v9ses->cache) {
1619 /* Now walk from the parent so we can get an unopened fid. */
1620 fid = p9_client_walk(dfid, 1, &name, 1);
1621 if (IS_ERR(fid)) {
1622 err = PTR_ERR(fid);
1623 P9_DPRINTK(P9_DEBUG_VFS, "p9_client_walk failed %d\n",
1624 err);
1625 fid = NULL;
1626 goto error;
1627 }
1628
1629 /* instantiate inode and assign the unopened fid to dentry */
1630 inode = v9fs_inode_from_fid(v9ses, fid, dir->i_sb);
1631 if (IS_ERR(inode)) {
1632 err = PTR_ERR(inode);
1633 P9_DPRINTK(P9_DEBUG_VFS, "inode creation failed %d\n",
1634 err);
1635 goto error;
1636 }
1637 dentry->d_op = &v9fs_cached_dentry_operations;
1638 d_instantiate(dentry, inode);
1639 err = v9fs_fid_add(dentry, fid);
1640 if (err < 0)
1641 goto error;
1642 fid = NULL;
1643 } else {
1644 /* Not in cached mode. No need to populate inode with stat */
1645 inode = v9fs_get_inode(dir->i_sb, S_IFLNK);
1646 if (IS_ERR(inode)) {
1647 err = PTR_ERR(inode);
1648 goto error;
1649 }
1650 dentry->d_op = &v9fs_dentry_operations;
1651 d_instantiate(dentry, inode);
1652 }
1653
1654error:
1655 if (fid)
1656 p9_client_clunk(fid);
1657
1658 return err;
1659}
1660
1661/**
1131 * v9fs_vfs_symlink - helper function to create symlinks 1662 * v9fs_vfs_symlink - helper function to create symlinks
1132 * @dir: directory inode containing symlink 1663 * @dir: directory inode containing symlink
1133 * @dentry: dentry for symlink 1664 * @dentry: dentry for symlink
@@ -1186,6 +1717,76 @@ clunk_fid:
1186} 1717}
1187 1718
1188/** 1719/**
1720 * v9fs_vfs_link_dotl - create a hardlink for dotl
1721 * @old_dentry: dentry for file to link to
1722 * @dir: inode destination for new link
1723 * @dentry: dentry for link
1724 *
1725 */
1726
1727static int
1728v9fs_vfs_link_dotl(struct dentry *old_dentry, struct inode *dir,
1729 struct dentry *dentry)
1730{
1731 int err;
1732 struct p9_fid *dfid, *oldfid;
1733 char *name;
1734 struct v9fs_session_info *v9ses;
1735 struct dentry *dir_dentry;
1736
1737 P9_DPRINTK(P9_DEBUG_VFS, "dir ino: %lu, old_name: %s, new_name: %s\n",
1738 dir->i_ino, old_dentry->d_name.name,
1739 dentry->d_name.name);
1740
1741 v9ses = v9fs_inode2v9ses(dir);
1742 dir_dentry = v9fs_dentry_from_dir_inode(dir);
1743 dfid = v9fs_fid_lookup(dir_dentry);
1744 if (IS_ERR(dfid))
1745 return PTR_ERR(dfid);
1746
1747 oldfid = v9fs_fid_lookup(old_dentry);
1748 if (IS_ERR(oldfid))
1749 return PTR_ERR(oldfid);
1750
1751 name = (char *) dentry->d_name.name;
1752
1753 err = p9_client_link(dfid, oldfid, (char *)dentry->d_name.name);
1754
1755 if (err < 0) {
1756 P9_DPRINTK(P9_DEBUG_VFS, "p9_client_link failed %d\n", err);
1757 return err;
1758 }
1759
1760 if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) {
1761 /* Get the latest stat info from server. */
1762 struct p9_fid *fid;
1763 struct p9_stat_dotl *st;
1764
1765 fid = v9fs_fid_lookup(old_dentry);
1766 if (IS_ERR(fid))
1767 return PTR_ERR(fid);
1768
1769 st = p9_client_getattr_dotl(fid, P9_STATS_BASIC);
1770 if (IS_ERR(st))
1771 return PTR_ERR(st);
1772
1773 v9fs_stat2inode_dotl(st, old_dentry->d_inode);
1774
1775 kfree(st);
1776 } else {
1777 /* Caching disabled. No need to get upto date stat info.
1778 * This dentry will be released immediately. So, just i_count++
1779 */
1780 atomic_inc(&old_dentry->d_inode->i_count);
1781 }
1782
1783 dentry->d_op = old_dentry->d_op;
1784 d_instantiate(dentry, old_dentry->d_inode);
1785
1786 return err;
1787}
1788
1789/**
1189 * v9fs_vfs_mknod - create a special file 1790 * v9fs_vfs_mknod - create a special file
1190 * @dir: inode destination for new link 1791 * @dir: inode destination for new link
1191 * @dentry: dentry for file 1792 * @dentry: dentry for file
@@ -1230,6 +1831,100 @@ v9fs_vfs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t rdev)
1230 return retval; 1831 return retval;
1231} 1832}
1232 1833
1834/**
1835 * v9fs_vfs_mknod_dotl - create a special file
1836 * @dir: inode destination for new link
1837 * @dentry: dentry for file
1838 * @mode: mode for creation
1839 * @rdev: device associated with special file
1840 *
1841 */
1842static int
1843v9fs_vfs_mknod_dotl(struct inode *dir, struct dentry *dentry, int mode,
1844 dev_t rdev)
1845{
1846 int err;
1847 char *name;
1848 struct v9fs_session_info *v9ses;
1849 struct p9_fid *fid = NULL, *dfid = NULL;
1850 struct inode *inode;
1851 gid_t gid;
1852 struct p9_qid qid;
1853 struct dentry *dir_dentry;
1854
1855 P9_DPRINTK(P9_DEBUG_VFS,
1856 " %lu,%s mode: %x MAJOR: %u MINOR: %u\n", dir->i_ino,
1857 dentry->d_name.name, mode, MAJOR(rdev), MINOR(rdev));
1858
1859 if (!new_valid_dev(rdev))
1860 return -EINVAL;
1861
1862 v9ses = v9fs_inode2v9ses(dir);
1863 dir_dentry = v9fs_dentry_from_dir_inode(dir);
1864 dfid = v9fs_fid_lookup(dir_dentry);
1865 if (IS_ERR(dfid)) {
1866 err = PTR_ERR(dfid);
1867 P9_DPRINTK(P9_DEBUG_VFS, "fid lookup failed %d\n", err);
1868 dfid = NULL;
1869 goto error;
1870 }
1871
1872 gid = v9fs_get_fsgid_for_create(dir);
1873 if (gid < 0) {
1874 P9_DPRINTK(P9_DEBUG_VFS, "v9fs_get_fsgid_for_create failed\n");
1875 goto error;
1876 }
1877
1878 name = (char *) dentry->d_name.name;
1879
1880 err = p9_client_mknod_dotl(dfid, name, mode, rdev, gid, &qid);
1881 if (err < 0)
1882 goto error;
1883
1884 /* instantiate inode and assign the unopened fid to the dentry */
1885 if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) {
1886 fid = p9_client_walk(dfid, 1, &name, 1);
1887 if (IS_ERR(fid)) {
1888 err = PTR_ERR(fid);
1889 P9_DPRINTK(P9_DEBUG_VFS, "p9_client_walk failed %d\n",
1890 err);
1891 fid = NULL;
1892 goto error;
1893 }
1894
1895 inode = v9fs_inode_from_fid(v9ses, fid, dir->i_sb);
1896 if (IS_ERR(inode)) {
1897 err = PTR_ERR(inode);
1898 P9_DPRINTK(P9_DEBUG_VFS, "inode creation failed %d\n",
1899 err);
1900 goto error;
1901 }
1902 dentry->d_op = &v9fs_cached_dentry_operations;
1903 d_instantiate(dentry, inode);
1904 err = v9fs_fid_add(dentry, fid);
1905 if (err < 0)
1906 goto error;
1907 fid = NULL;
1908 } else {
1909 /*
1910 * Not in cached mode. No need to populate inode with stat.
1911 * socket syscall returns a fd, so we need instantiate
1912 */
1913 inode = v9fs_get_inode(dir->i_sb, mode);
1914 if (IS_ERR(inode)) {
1915 err = PTR_ERR(inode);
1916 goto error;
1917 }
1918 dentry->d_op = &v9fs_dentry_operations;
1919 d_instantiate(dentry, inode);
1920 }
1921
1922error:
1923 if (fid)
1924 p9_client_clunk(fid);
1925 return err;
1926}
1927
1233static const struct inode_operations v9fs_dir_inode_operations_dotu = { 1928static const struct inode_operations v9fs_dir_inode_operations_dotu = {
1234 .create = v9fs_vfs_create, 1929 .create = v9fs_vfs_create,
1235 .lookup = v9fs_vfs_lookup, 1930 .lookup = v9fs_vfs_lookup,
@@ -1238,24 +1933,29 @@ static const struct inode_operations v9fs_dir_inode_operations_dotu = {
1238 .unlink = v9fs_vfs_unlink, 1933 .unlink = v9fs_vfs_unlink,
1239 .mkdir = v9fs_vfs_mkdir, 1934 .mkdir = v9fs_vfs_mkdir,
1240 .rmdir = v9fs_vfs_rmdir, 1935 .rmdir = v9fs_vfs_rmdir,
1241 .mknod = v9fs_vfs_mknod, 1936 .mknod = v9fs_vfs_mknod_dotl,
1242 .rename = v9fs_vfs_rename, 1937 .rename = v9fs_vfs_rename,
1243 .getattr = v9fs_vfs_getattr, 1938 .getattr = v9fs_vfs_getattr,
1244 .setattr = v9fs_vfs_setattr, 1939 .setattr = v9fs_vfs_setattr,
1245}; 1940};
1246 1941
1247static const struct inode_operations v9fs_dir_inode_operations_dotl = { 1942static const struct inode_operations v9fs_dir_inode_operations_dotl = {
1248 .create = v9fs_vfs_create, 1943 .create = v9fs_vfs_create_dotl,
1249 .lookup = v9fs_vfs_lookup, 1944 .lookup = v9fs_vfs_lookup,
1250 .symlink = v9fs_vfs_symlink, 1945 .link = v9fs_vfs_link_dotl,
1251 .link = v9fs_vfs_link, 1946 .symlink = v9fs_vfs_symlink_dotl,
1252 .unlink = v9fs_vfs_unlink, 1947 .unlink = v9fs_vfs_unlink,
1253 .mkdir = v9fs_vfs_mkdir, 1948 .mkdir = v9fs_vfs_mkdir_dotl,
1254 .rmdir = v9fs_vfs_rmdir, 1949 .rmdir = v9fs_vfs_rmdir,
1255 .mknod = v9fs_vfs_mknod, 1950 .mknod = v9fs_vfs_mknod_dotl,
1256 .rename = v9fs_vfs_rename, 1951 .rename = v9fs_vfs_rename,
1257 .getattr = v9fs_vfs_getattr, 1952 .getattr = v9fs_vfs_getattr_dotl,
1258 .setattr = v9fs_vfs_setattr, 1953 .setattr = v9fs_vfs_setattr_dotl,
1954 .setxattr = generic_setxattr,
1955 .getxattr = generic_getxattr,
1956 .removexattr = generic_removexattr,
1957 .listxattr = v9fs_listxattr,
1958
1259}; 1959};
1260 1960
1261static const struct inode_operations v9fs_dir_inode_operations = { 1961static const struct inode_operations v9fs_dir_inode_operations = {
@@ -1276,8 +1976,12 @@ static const struct inode_operations v9fs_file_inode_operations = {
1276}; 1976};
1277 1977
1278static const struct inode_operations v9fs_file_inode_operations_dotl = { 1978static const struct inode_operations v9fs_file_inode_operations_dotl = {
1279 .getattr = v9fs_vfs_getattr, 1979 .getattr = v9fs_vfs_getattr_dotl,
1280 .setattr = v9fs_vfs_setattr, 1980 .setattr = v9fs_vfs_setattr_dotl,
1981 .setxattr = generic_setxattr,
1982 .getxattr = generic_getxattr,
1983 .removexattr = generic_removexattr,
1984 .listxattr = v9fs_listxattr,
1281}; 1985};
1282 1986
1283static const struct inode_operations v9fs_symlink_inode_operations = { 1987static const struct inode_operations v9fs_symlink_inode_operations = {
@@ -1292,6 +1996,10 @@ static const struct inode_operations v9fs_symlink_inode_operations_dotl = {
1292 .readlink = generic_readlink, 1996 .readlink = generic_readlink,
1293 .follow_link = v9fs_vfs_follow_link, 1997 .follow_link = v9fs_vfs_follow_link,
1294 .put_link = v9fs_vfs_put_link, 1998 .put_link = v9fs_vfs_put_link,
1295 .getattr = v9fs_vfs_getattr, 1999 .getattr = v9fs_vfs_getattr_dotl,
1296 .setattr = v9fs_vfs_setattr, 2000 .setattr = v9fs_vfs_setattr_dotl,
2001 .setxattr = generic_setxattr,
2002 .getxattr = generic_getxattr,
2003 .removexattr = generic_removexattr,
2004 .listxattr = v9fs_listxattr,
1297}; 2005};