diff options
| author | Linus Torvalds <torvalds@linux-foundation.org> | 2010-08-03 17:36:16 -0400 |
|---|---|---|
| committer | Linus Torvalds <torvalds@linux-foundation.org> | 2010-08-03 17:36:16 -0400 |
| commit | b8b3e9058f0f1d5c5a81c7d3d46f373d5f59a82c (patch) | |
| tree | 1033085760392dc7e24a79bbeb276ce1a34314d0 | |
| parent | 51102ee5b8853d230e534cbcd0d888f0134738a3 (diff) | |
| parent | 327aec03ac4c7bbf5e41ff03ac3a84c424589f27 (diff) | |
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ericvh/v9fs
* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ericvh/v9fs: (22 commits)
9p: fix sparse warnings in new xattr code
fs/9p: remove sparse warning in vfs_inode
fs/9p: destroy fid on failed remove
fs/9p: Prevent parallel rename when doing fid_lookup
fs/9p: Add support user. xattr
net/9p: Implement TXATTRCREATE 9p call
net/9p: Implement attrwalk 9p call
9p: Implement LOPEN
fs/9p: This patch implements TLCREATE for 9p2000.L protocol.
9p: Implement TMKDIR
9p: Implement TMKNOD
9p: Define and implement TSYMLINK for 9P2000.L
9p: Define and implement TLINK for 9P2000.L
9p: Define and implement TLINK for 9P2000.L
9p: Implement client side of setattr for 9P2000.L protocol.
9p: getattr client implementation for 9P2000.L protocol.
fs/9p: Pass the correct user credentials during attach
net/9p: Handle the server returned error properly
9p: readdir implementation for 9p2000.L
9p: Make use of iounit for read/write
...
| -rw-r--r-- | fs/9p/Makefile | 4 | ||||
| -rw-r--r-- | fs/9p/fid.c | 111 | ||||
| -rw-r--r-- | fs/9p/v9fs.c | 3 | ||||
| -rw-r--r-- | fs/9p/v9fs.h | 1 | ||||
| -rw-r--r-- | fs/9p/v9fs_vfs.h | 1 | ||||
| -rw-r--r-- | fs/9p/vfs_dir.c | 134 | ||||
| -rw-r--r-- | fs/9p/vfs_file.c | 26 | ||||
| -rw-r--r-- | fs/9p/vfs_inode.c | 757 | ||||
| -rw-r--r-- | fs/9p/vfs_super.c | 50 | ||||
| -rw-r--r-- | fs/9p/xattr.c | 160 | ||||
| -rw-r--r-- | fs/9p/xattr.h | 27 | ||||
| -rw-r--r-- | fs/9p/xattr_user.c | 80 | ||||
| -rw-r--r-- | include/linux/virtio_9p.h | 1 | ||||
| -rw-r--r-- | include/net/9p/9p.h | 113 | ||||
| -rw-r--r-- | include/net/9p/client.h | 33 | ||||
| -rw-r--r-- | net/9p/client.c | 393 | ||||
| -rw-r--r-- | net/9p/protocol.c | 72 | ||||
| -rw-r--r-- | net/9p/trans_fd.c | 2 |
18 files changed, 1845 insertions, 123 deletions
diff --git a/fs/9p/Makefile b/fs/9p/Makefile index 1a940ec7af61..91fba025fcbe 100644 --- a/fs/9p/Makefile +++ b/fs/9p/Makefile | |||
| @@ -8,6 +8,8 @@ obj-$(CONFIG_9P_FS) := 9p.o | |||
| 8 | vfs_dir.o \ | 8 | vfs_dir.o \ |
| 9 | vfs_dentry.o \ | 9 | vfs_dentry.o \ |
| 10 | v9fs.o \ | 10 | v9fs.o \ |
| 11 | fid.o | 11 | fid.o \ |
| 12 | xattr.o \ | ||
| 13 | xattr_user.o | ||
| 12 | 14 | ||
| 13 | 9p-$(CONFIG_9P_FSCACHE) += cache.o | 15 | 9p-$(CONFIG_9P_FSCACHE) += cache.o |
diff --git a/fs/9p/fid.c b/fs/9p/fid.c index 7317b39b2815..358563689064 100644 --- a/fs/9p/fid.c +++ b/fs/9p/fid.c | |||
| @@ -97,6 +97,34 @@ static struct p9_fid *v9fs_fid_find(struct dentry *dentry, u32 uid, int any) | |||
| 97 | return ret; | 97 | return ret; |
| 98 | } | 98 | } |
| 99 | 99 | ||
| 100 | /* | ||
| 101 | * We need to hold v9ses->rename_sem as long as we hold references | ||
| 102 | * to returned path array. Array element contain pointers to | ||
| 103 | * dentry names. | ||
| 104 | */ | ||
| 105 | static int build_path_from_dentry(struct v9fs_session_info *v9ses, | ||
| 106 | struct dentry *dentry, char ***names) | ||
| 107 | { | ||
| 108 | int n = 0, i; | ||
| 109 | char **wnames; | ||
| 110 | struct dentry *ds; | ||
| 111 | |||
| 112 | for (ds = dentry; !IS_ROOT(ds); ds = ds->d_parent) | ||
| 113 | n++; | ||
| 114 | |||
| 115 | wnames = kmalloc(sizeof(char *) * n, GFP_KERNEL); | ||
| 116 | if (!wnames) | ||
| 117 | goto err_out; | ||
| 118 | |||
| 119 | for (ds = dentry, i = (n-1); i >= 0; i--, ds = ds->d_parent) | ||
| 120 | wnames[i] = (char *)ds->d_name.name; | ||
| 121 | |||
| 122 | *names = wnames; | ||
| 123 | return n; | ||
| 124 | err_out: | ||
| 125 | return -ENOMEM; | ||
| 126 | } | ||
| 127 | |||
| 100 | /** | 128 | /** |
| 101 | * v9fs_fid_lookup - lookup for a fid, try to walk if not found | 129 | * v9fs_fid_lookup - lookup for a fid, try to walk if not found |
| 102 | * @dentry: dentry to look for fid in | 130 | * @dentry: dentry to look for fid in |
| @@ -112,7 +140,7 @@ struct p9_fid *v9fs_fid_lookup(struct dentry *dentry) | |||
| 112 | int i, n, l, clone, any, access; | 140 | int i, n, l, clone, any, access; |
| 113 | u32 uid; | 141 | u32 uid; |
| 114 | struct p9_fid *fid, *old_fid = NULL; | 142 | struct p9_fid *fid, *old_fid = NULL; |
| 115 | struct dentry *d, *ds; | 143 | struct dentry *ds; |
| 116 | struct v9fs_session_info *v9ses; | 144 | struct v9fs_session_info *v9ses; |
| 117 | char **wnames, *uname; | 145 | char **wnames, *uname; |
| 118 | 146 | ||
| @@ -139,49 +167,62 @@ struct p9_fid *v9fs_fid_lookup(struct dentry *dentry) | |||
| 139 | fid = v9fs_fid_find(dentry, uid, any); | 167 | fid = v9fs_fid_find(dentry, uid, any); |
| 140 | if (fid) | 168 | if (fid) |
| 141 | return fid; | 169 | return fid; |
| 142 | 170 | /* | |
| 171 | * we don't have a matching fid. To do a TWALK we need | ||
| 172 | * parent fid. We need to prevent rename when we want to | ||
| 173 | * look at the parent. | ||
| 174 | */ | ||
| 175 | down_read(&v9ses->rename_sem); | ||
| 143 | ds = dentry->d_parent; | 176 | ds = dentry->d_parent; |
| 144 | fid = v9fs_fid_find(ds, uid, any); | 177 | fid = v9fs_fid_find(ds, uid, any); |
| 145 | if (!fid) { /* walk from the root */ | 178 | if (fid) { |
| 146 | n = 0; | 179 | /* Found the parent fid do a lookup with that */ |
| 147 | for (ds = dentry; !IS_ROOT(ds); ds = ds->d_parent) | 180 | fid = p9_client_walk(fid, 1, (char **)&dentry->d_name.name, 1); |
| 148 | n++; | 181 | goto fid_out; |
| 182 | } | ||
| 183 | up_read(&v9ses->rename_sem); | ||
| 149 | 184 | ||
| 150 | fid = v9fs_fid_find(ds, uid, any); | 185 | /* start from the root and try to do a lookup */ |
| 151 | if (!fid) { /* the user is not attached to the fs yet */ | 186 | fid = v9fs_fid_find(dentry->d_sb->s_root, uid, any); |
| 152 | if (access == V9FS_ACCESS_SINGLE) | 187 | if (!fid) { |
| 153 | return ERR_PTR(-EPERM); | 188 | /* the user is not attached to the fs yet */ |
| 189 | if (access == V9FS_ACCESS_SINGLE) | ||
| 190 | return ERR_PTR(-EPERM); | ||
| 154 | 191 | ||
| 155 | if (v9fs_proto_dotu(v9ses)) | 192 | if (v9fs_proto_dotu(v9ses) || v9fs_proto_dotl(v9ses)) |
| 156 | uname = NULL; | 193 | uname = NULL; |
| 157 | else | 194 | else |
| 158 | uname = v9ses->uname; | 195 | uname = v9ses->uname; |
| 159 | 196 | ||
| 160 | fid = p9_client_attach(v9ses->clnt, NULL, uname, uid, | 197 | fid = p9_client_attach(v9ses->clnt, NULL, uname, uid, |
| 161 | v9ses->aname); | 198 | v9ses->aname); |
| 162 | 199 | if (IS_ERR(fid)) | |
| 163 | if (IS_ERR(fid)) | 200 | return fid; |
| 164 | return fid; | ||
| 165 | |||
| 166 | v9fs_fid_add(ds, fid); | ||
| 167 | } | ||
| 168 | } else /* walk from the parent */ | ||
| 169 | n = 1; | ||
| 170 | 201 | ||
| 171 | if (ds == dentry) | 202 | v9fs_fid_add(dentry->d_sb->s_root, fid); |
| 203 | } | ||
| 204 | /* If we are root ourself just return that */ | ||
| 205 | if (dentry->d_sb->s_root == dentry) | ||
| 172 | return fid; | 206 | return fid; |
| 173 | 207 | /* | |
| 174 | wnames = kmalloc(sizeof(char *) * n, GFP_KERNEL); | 208 | * Do a multipath walk with attached root. |
| 175 | if (!wnames) | 209 | * When walking parent we need to make sure we |
| 176 | return ERR_PTR(-ENOMEM); | 210 | * don't have a parallel rename happening |
| 177 | 211 | */ | |
| 178 | for (d = dentry, i = (n-1); i >= 0; i--, d = d->d_parent) | 212 | down_read(&v9ses->rename_sem); |
| 179 | wnames[i] = (char *) d->d_name.name; | 213 | n = build_path_from_dentry(v9ses, dentry, &wnames); |
| 180 | 214 | if (n < 0) { | |
| 215 | fid = ERR_PTR(n); | ||
| 216 | goto err_out; | ||
| 217 | } | ||
| 181 | clone = 1; | 218 | clone = 1; |
| 182 | i = 0; | 219 | i = 0; |
| 183 | while (i < n) { | 220 | while (i < n) { |
| 184 | l = min(n - i, P9_MAXWELEM); | 221 | l = min(n - i, P9_MAXWELEM); |
| 222 | /* | ||
| 223 | * We need to hold rename lock when doing a multipath | ||
| 224 | * walk to ensure none of the patch component change | ||
| 225 | */ | ||
| 185 | fid = p9_client_walk(fid, l, &wnames[i], clone); | 226 | fid = p9_client_walk(fid, l, &wnames[i], clone); |
| 186 | if (IS_ERR(fid)) { | 227 | if (IS_ERR(fid)) { |
| 187 | if (old_fid) { | 228 | if (old_fid) { |
| @@ -193,15 +234,17 @@ struct p9_fid *v9fs_fid_lookup(struct dentry *dentry) | |||
| 193 | p9_client_clunk(old_fid); | 234 | p9_client_clunk(old_fid); |
| 194 | } | 235 | } |
| 195 | kfree(wnames); | 236 | kfree(wnames); |
| 196 | return fid; | 237 | goto err_out; |
| 197 | } | 238 | } |
| 198 | old_fid = fid; | 239 | old_fid = fid; |
| 199 | i += l; | 240 | i += l; |
| 200 | clone = 0; | 241 | clone = 0; |
| 201 | } | 242 | } |
| 202 | |||
| 203 | kfree(wnames); | 243 | kfree(wnames); |
| 244 | fid_out: | ||
| 204 | v9fs_fid_add(dentry, fid); | 245 | v9fs_fid_add(dentry, fid); |
| 246 | err_out: | ||
| 247 | up_read(&v9ses->rename_sem); | ||
| 205 | return fid; | 248 | return fid; |
| 206 | } | 249 | } |
| 207 | 250 | ||
diff --git a/fs/9p/v9fs.c b/fs/9p/v9fs.c index f8b86e92cd66..38dc0e067599 100644 --- a/fs/9p/v9fs.c +++ b/fs/9p/v9fs.c | |||
| @@ -237,6 +237,7 @@ struct p9_fid *v9fs_session_init(struct v9fs_session_info *v9ses, | |||
| 237 | __putname(v9ses->uname); | 237 | __putname(v9ses->uname); |
| 238 | return ERR_PTR(-ENOMEM); | 238 | return ERR_PTR(-ENOMEM); |
| 239 | } | 239 | } |
| 240 | init_rwsem(&v9ses->rename_sem); | ||
| 240 | 241 | ||
| 241 | rc = bdi_setup_and_register(&v9ses->bdi, "9p", BDI_CAP_MAP_COPY); | 242 | rc = bdi_setup_and_register(&v9ses->bdi, "9p", BDI_CAP_MAP_COPY); |
| 242 | if (rc) { | 243 | if (rc) { |
| @@ -278,7 +279,7 @@ struct p9_fid *v9fs_session_init(struct v9fs_session_info *v9ses, | |||
| 278 | v9ses->maxdata = v9ses->clnt->msize - P9_IOHDRSZ; | 279 | v9ses->maxdata = v9ses->clnt->msize - P9_IOHDRSZ; |
| 279 | 280 | ||
| 280 | /* for legacy mode, fall back to V9FS_ACCESS_ANY */ | 281 | /* for legacy mode, fall back to V9FS_ACCESS_ANY */ |
| 281 | if (!v9fs_proto_dotu(v9ses) && | 282 | if (!(v9fs_proto_dotu(v9ses) || v9fs_proto_dotl(v9ses)) && |
| 282 | ((v9ses->flags&V9FS_ACCESS_MASK) == V9FS_ACCESS_USER)) { | 283 | ((v9ses->flags&V9FS_ACCESS_MASK) == V9FS_ACCESS_USER)) { |
| 283 | 284 | ||
| 284 | v9ses->flags &= ~V9FS_ACCESS_MASK; | 285 | v9ses->flags &= ~V9FS_ACCESS_MASK; |
diff --git a/fs/9p/v9fs.h b/fs/9p/v9fs.h index bec4d0bcb458..4c963c9fc41f 100644 --- a/fs/9p/v9fs.h +++ b/fs/9p/v9fs.h | |||
| @@ -104,6 +104,7 @@ struct v9fs_session_info { | |||
| 104 | struct p9_client *clnt; /* 9p client */ | 104 | struct p9_client *clnt; /* 9p client */ |
| 105 | struct list_head slist; /* list of sessions registered with v9fs */ | 105 | struct list_head slist; /* list of sessions registered with v9fs */ |
| 106 | struct backing_dev_info bdi; | 106 | struct backing_dev_info bdi; |
| 107 | struct rw_semaphore rename_sem; | ||
| 107 | }; | 108 | }; |
| 108 | 109 | ||
| 109 | struct p9_fid *v9fs_session_init(struct v9fs_session_info *, const char *, | 110 | struct p9_fid *v9fs_session_init(struct v9fs_session_info *, const char *, |
diff --git a/fs/9p/v9fs_vfs.h b/fs/9p/v9fs_vfs.h index 32ef4009d030..f47c6bbb01b3 100644 --- a/fs/9p/v9fs_vfs.h +++ b/fs/9p/v9fs_vfs.h | |||
| @@ -55,6 +55,7 @@ struct inode *v9fs_get_inode(struct super_block *sb, int mode); | |||
| 55 | void v9fs_clear_inode(struct inode *inode); | 55 | void v9fs_clear_inode(struct inode *inode); |
| 56 | ino_t v9fs_qid2ino(struct p9_qid *qid); | 56 | ino_t v9fs_qid2ino(struct p9_qid *qid); |
| 57 | void v9fs_stat2inode(struct p9_wstat *, struct inode *, struct super_block *); | 57 | void v9fs_stat2inode(struct p9_wstat *, struct inode *, struct super_block *); |
| 58 | void v9fs_stat2inode_dotl(struct p9_stat_dotl *, struct inode *); | ||
| 58 | int v9fs_dir_release(struct inode *inode, struct file *filp); | 59 | int v9fs_dir_release(struct inode *inode, struct file *filp); |
| 59 | int v9fs_file_open(struct inode *inode, struct file *file); | 60 | int v9fs_file_open(struct inode *inode, struct file *file); |
| 60 | void v9fs_inode2stat(struct inode *inode, struct p9_wstat *stat); | 61 | void v9fs_inode2stat(struct inode *inode, struct p9_wstat *stat); |
diff --git a/fs/9p/vfs_dir.c b/fs/9p/vfs_dir.c index 36d961f342af..16c8a2a98c1b 100644 --- a/fs/9p/vfs_dir.c +++ b/fs/9p/vfs_dir.c | |||
| @@ -87,29 +87,19 @@ static void p9stat_init(struct p9_wstat *stbuf) | |||
| 87 | } | 87 | } |
| 88 | 88 | ||
| 89 | /** | 89 | /** |
| 90 | * v9fs_dir_readdir - read a directory | 90 | * v9fs_alloc_rdir_buf - Allocate buffer used for read and readdir |
| 91 | * @filp: opened file structure | 91 | * @filp: opened file structure |
| 92 | * @dirent: directory structure ??? | 92 | * @buflen: Length in bytes of buffer to allocate |
| 93 | * @filldir: function to populate directory structure ??? | ||
| 94 | * | 93 | * |
| 95 | */ | 94 | */ |
| 96 | 95 | ||
| 97 | static int v9fs_dir_readdir(struct file *filp, void *dirent, filldir_t filldir) | 96 | static int v9fs_alloc_rdir_buf(struct file *filp, int buflen) |
| 98 | { | 97 | { |
| 99 | int over; | ||
| 100 | struct p9_wstat st; | ||
| 101 | int err = 0; | ||
| 102 | struct p9_fid *fid; | ||
| 103 | int buflen; | ||
| 104 | int reclen = 0; | ||
| 105 | struct p9_rdir *rdir; | 98 | struct p9_rdir *rdir; |
| 99 | struct p9_fid *fid; | ||
| 100 | int err = 0; | ||
| 106 | 101 | ||
| 107 | P9_DPRINTK(P9_DEBUG_VFS, "name %s\n", filp->f_path.dentry->d_name.name); | ||
| 108 | fid = filp->private_data; | 102 | fid = filp->private_data; |
| 109 | |||
| 110 | buflen = fid->clnt->msize - P9_IOHDRSZ; | ||
| 111 | |||
| 112 | /* allocate rdir on demand */ | ||
| 113 | if (!fid->rdir) { | 103 | if (!fid->rdir) { |
| 114 | rdir = kmalloc(sizeof(struct p9_rdir) + buflen, GFP_KERNEL); | 104 | rdir = kmalloc(sizeof(struct p9_rdir) + buflen, GFP_KERNEL); |
| 115 | 105 | ||
| @@ -128,6 +118,36 @@ static int v9fs_dir_readdir(struct file *filp, void *dirent, filldir_t filldir) | |||
| 128 | spin_unlock(&filp->f_dentry->d_lock); | 118 | spin_unlock(&filp->f_dentry->d_lock); |
| 129 | kfree(rdir); | 119 | kfree(rdir); |
| 130 | } | 120 | } |
| 121 | exit: | ||
| 122 | return err; | ||
| 123 | } | ||
| 124 | |||
| 125 | /** | ||
| 126 | * v9fs_dir_readdir - read a directory | ||
| 127 | * @filp: opened file structure | ||
| 128 | * @dirent: directory structure ??? | ||
| 129 | * @filldir: function to populate directory structure ??? | ||
| 130 | * | ||
| 131 | */ | ||
| 132 | |||
| 133 | static int v9fs_dir_readdir(struct file *filp, void *dirent, filldir_t filldir) | ||
| 134 | { | ||
| 135 | int over; | ||
| 136 | struct p9_wstat st; | ||
| 137 | int err = 0; | ||
| 138 | struct p9_fid *fid; | ||
| 139 | int buflen; | ||
| 140 | int reclen = 0; | ||
| 141 | struct p9_rdir *rdir; | ||
| 142 | |||
| 143 | P9_DPRINTK(P9_DEBUG_VFS, "name %s\n", filp->f_path.dentry->d_name.name); | ||
| 144 | fid = filp->private_data; | ||
| 145 | |||
| 146 | buflen = fid->clnt->msize - P9_IOHDRSZ; | ||
| 147 | |||
| 148 | err = v9fs_alloc_rdir_buf(filp, buflen); | ||
| 149 | if (err) | ||
| 150 | goto exit; | ||
| 131 | rdir = (struct p9_rdir *) fid->rdir; | 151 | rdir = (struct p9_rdir *) fid->rdir; |
| 132 | 152 | ||
| 133 | err = mutex_lock_interruptible(&rdir->mutex); | 153 | err = mutex_lock_interruptible(&rdir->mutex); |
| @@ -176,6 +196,88 @@ exit: | |||
| 176 | return err; | 196 | return err; |
| 177 | } | 197 | } |
| 178 | 198 | ||
| 199 | /** | ||
| 200 | * v9fs_dir_readdir_dotl - read a directory | ||
| 201 | * @filp: opened file structure | ||
| 202 | * @dirent: buffer to fill dirent structures | ||
| 203 | * @filldir: function to populate dirent structures | ||
| 204 | * | ||
| 205 | */ | ||
| 206 | static int v9fs_dir_readdir_dotl(struct file *filp, void *dirent, | ||
| 207 | filldir_t filldir) | ||
| 208 | { | ||
| 209 | int over; | ||
| 210 | int err = 0; | ||
| 211 | struct p9_fid *fid; | ||
| 212 | int buflen; | ||
| 213 | struct p9_rdir *rdir; | ||
| 214 | struct p9_dirent curdirent; | ||
| 215 | u64 oldoffset = 0; | ||
| 216 | |||
| 217 | P9_DPRINTK(P9_DEBUG_VFS, "name %s\n", filp->f_path.dentry->d_name.name); | ||
| 218 | fid = filp->private_data; | ||
| 219 | |||
| 220 | buflen = fid->clnt->msize - P9_READDIRHDRSZ; | ||
| 221 | |||
| 222 | err = v9fs_alloc_rdir_buf(filp, buflen); | ||
| 223 | if (err) | ||
| 224 | goto exit; | ||
| 225 | rdir = (struct p9_rdir *) fid->rdir; | ||
| 226 | |||
| 227 | err = mutex_lock_interruptible(&rdir->mutex); | ||
| 228 | if (err) | ||
| 229 | return err; | ||
| 230 | |||
| 231 | while (err == 0) { | ||
| 232 | if (rdir->tail == rdir->head) { | ||
| 233 | err = p9_client_readdir(fid, rdir->buf, buflen, | ||
| 234 | filp->f_pos); | ||
| 235 | if (err <= 0) | ||
| 236 | goto unlock_and_exit; | ||
| 237 | |||
| 238 | rdir->head = 0; | ||
| 239 | rdir->tail = err; | ||
| 240 | } | ||
| 241 | |||
| 242 | while (rdir->head < rdir->tail) { | ||
| 243 | |||
| 244 | err = p9dirent_read(rdir->buf + rdir->head, | ||
| 245 | buflen - rdir->head, &curdirent, | ||
| 246 | fid->clnt->proto_version); | ||
| 247 | if (err < 0) { | ||
| 248 | P9_DPRINTK(P9_DEBUG_VFS, "returned %d\n", err); | ||
| 249 | err = -EIO; | ||
| 250 | goto unlock_and_exit; | ||
| 251 | } | ||
| 252 | |||
| 253 | /* d_off in dirent structure tracks the offset into | ||
| 254 | * the next dirent in the dir. However, filldir() | ||
| 255 | * expects offset into the current dirent. Hence | ||
| 256 | * while calling filldir send the offset from the | ||
| 257 | * previous dirent structure. | ||
| 258 | */ | ||
| 259 | over = filldir(dirent, curdirent.d_name, | ||
| 260 | strlen(curdirent.d_name), | ||
| 261 | oldoffset, v9fs_qid2ino(&curdirent.qid), | ||
| 262 | curdirent.d_type); | ||
| 263 | oldoffset = curdirent.d_off; | ||
| 264 | |||
| 265 | if (over) { | ||
| 266 | err = 0; | ||
| 267 | goto unlock_and_exit; | ||
| 268 | } | ||
| 269 | |||
| 270 | filp->f_pos = curdirent.d_off; | ||
| 271 | rdir->head += err; | ||
| 272 | } | ||
| 273 | } | ||
| 274 | |||
| 275 | unlock_and_exit: | ||
| 276 | mutex_unlock(&rdir->mutex); | ||
| 277 | exit: | ||
| 278 | return err; | ||
| 279 | } | ||
| 280 | |||
| 179 | 281 | ||
| 180 | /** | 282 | /** |
| 181 | * v9fs_dir_release - close a directory | 283 | * v9fs_dir_release - close a directory |
| @@ -207,7 +309,7 @@ const struct file_operations v9fs_dir_operations = { | |||
| 207 | const struct file_operations v9fs_dir_operations_dotl = { | 309 | const struct file_operations v9fs_dir_operations_dotl = { |
| 208 | .read = generic_read_dir, | 310 | .read = generic_read_dir, |
| 209 | .llseek = generic_file_llseek, | 311 | .llseek = generic_file_llseek, |
| 210 | .readdir = v9fs_dir_readdir, | 312 | .readdir = v9fs_dir_readdir_dotl, |
| 211 | .open = v9fs_file_open, | 313 | .open = v9fs_file_open, |
| 212 | .release = v9fs_dir_release, | 314 | .release = v9fs_dir_release, |
| 213 | }; | 315 | }; |
diff --git a/fs/9p/vfs_file.c b/fs/9p/vfs_file.c index 2bedc6c94fc2..e97c92bd6f16 100644 --- a/fs/9p/vfs_file.c +++ b/fs/9p/vfs_file.c | |||
| @@ -59,9 +59,13 @@ int v9fs_file_open(struct inode *inode, struct file *file) | |||
| 59 | struct p9_fid *fid; | 59 | struct p9_fid *fid; |
| 60 | int omode; | 60 | int omode; |
| 61 | 61 | ||
| 62 | P9_DPRINTK(P9_DEBUG_VFS, "inode: %p file: %p \n", inode, file); | 62 | P9_DPRINTK(P9_DEBUG_VFS, "inode: %p file: %p\n", inode, file); |
| 63 | v9ses = v9fs_inode2v9ses(inode); | 63 | v9ses = v9fs_inode2v9ses(inode); |
| 64 | omode = v9fs_uflags2omode(file->f_flags, v9fs_proto_dotu(v9ses)); | 64 | if (v9fs_proto_dotl(v9ses)) |
| 65 | omode = file->f_flags; | ||
| 66 | else | ||
| 67 | omode = v9fs_uflags2omode(file->f_flags, | ||
| 68 | v9fs_proto_dotu(v9ses)); | ||
| 65 | fid = file->private_data; | 69 | fid = file->private_data; |
| 66 | if (!fid) { | 70 | if (!fid) { |
| 67 | fid = v9fs_fid_clone(file->f_path.dentry); | 71 | fid = v9fs_fid_clone(file->f_path.dentry); |
| @@ -73,11 +77,12 @@ int v9fs_file_open(struct inode *inode, struct file *file) | |||
| 73 | p9_client_clunk(fid); | 77 | p9_client_clunk(fid); |
| 74 | return err; | 78 | return err; |
| 75 | } | 79 | } |
| 76 | if (omode & P9_OTRUNC) { | 80 | if (file->f_flags & O_TRUNC) { |
| 77 | i_size_write(inode, 0); | 81 | i_size_write(inode, 0); |
| 78 | inode->i_blocks = 0; | 82 | inode->i_blocks = 0; |
| 79 | } | 83 | } |
| 80 | if ((file->f_flags & O_APPEND) && (!v9fs_proto_dotu(v9ses))) | 84 | if ((file->f_flags & O_APPEND) && |
| 85 | (!v9fs_proto_dotu(v9ses) && !v9fs_proto_dotl(v9ses))) | ||
| 81 | generic_file_llseek(file, 0, SEEK_END); | 86 | generic_file_llseek(file, 0, SEEK_END); |
| 82 | } | 87 | } |
| 83 | 88 | ||
| @@ -139,7 +144,7 @@ ssize_t | |||
| 139 | v9fs_file_readn(struct file *filp, char *data, char __user *udata, u32 count, | 144 | v9fs_file_readn(struct file *filp, char *data, char __user *udata, u32 count, |
| 140 | u64 offset) | 145 | u64 offset) |
| 141 | { | 146 | { |
| 142 | int n, total; | 147 | int n, total, size; |
| 143 | struct p9_fid *fid = filp->private_data; | 148 | struct p9_fid *fid = filp->private_data; |
| 144 | 149 | ||
| 145 | P9_DPRINTK(P9_DEBUG_VFS, "fid %d offset %llu count %d\n", fid->fid, | 150 | P9_DPRINTK(P9_DEBUG_VFS, "fid %d offset %llu count %d\n", fid->fid, |
| @@ -147,6 +152,7 @@ v9fs_file_readn(struct file *filp, char *data, char __user *udata, u32 count, | |||
| 147 | 152 | ||
| 148 | n = 0; | 153 | n = 0; |
| 149 | total = 0; | 154 | total = 0; |
| 155 | size = fid->iounit ? fid->iounit : fid->clnt->msize - P9_IOHDRSZ; | ||
| 150 | do { | 156 | do { |
| 151 | n = p9_client_read(fid, data, udata, offset, count); | 157 | n = p9_client_read(fid, data, udata, offset, count); |
| 152 | if (n <= 0) | 158 | if (n <= 0) |
| @@ -160,7 +166,7 @@ v9fs_file_readn(struct file *filp, char *data, char __user *udata, u32 count, | |||
| 160 | offset += n; | 166 | offset += n; |
| 161 | count -= n; | 167 | count -= n; |
| 162 | total += n; | 168 | total += n; |
| 163 | } while (count > 0 && n == (fid->clnt->msize - P9_IOHDRSZ)); | 169 | } while (count > 0 && n == size); |
| 164 | 170 | ||
| 165 | if (n < 0) | 171 | if (n < 0) |
| 166 | total = n; | 172 | total = n; |
| @@ -183,11 +189,13 @@ v9fs_file_read(struct file *filp, char __user *udata, size_t count, | |||
| 183 | { | 189 | { |
| 184 | int ret; | 190 | int ret; |
| 185 | struct p9_fid *fid; | 191 | struct p9_fid *fid; |
| 192 | size_t size; | ||
| 186 | 193 | ||
| 187 | P9_DPRINTK(P9_DEBUG_VFS, "count %zu offset %lld\n", count, *offset); | 194 | P9_DPRINTK(P9_DEBUG_VFS, "count %zu offset %lld\n", count, *offset); |
| 188 | fid = filp->private_data; | 195 | fid = filp->private_data; |
| 189 | 196 | ||
| 190 | if (count > (fid->clnt->msize - P9_IOHDRSZ)) | 197 | size = fid->iounit ? fid->iounit : fid->clnt->msize - P9_IOHDRSZ; |
| 198 | if (count > size) | ||
| 191 | ret = v9fs_file_readn(filp, NULL, udata, count, *offset); | 199 | ret = v9fs_file_readn(filp, NULL, udata, count, *offset); |
| 192 | else | 200 | else |
| 193 | ret = p9_client_read(fid, NULL, udata, *offset, count); | 201 | ret = p9_client_read(fid, NULL, udata, *offset, count); |
| @@ -224,9 +232,7 @@ v9fs_file_write(struct file *filp, const char __user * data, | |||
| 224 | fid = filp->private_data; | 232 | fid = filp->private_data; |
| 225 | clnt = fid->clnt; | 233 | clnt = fid->clnt; |
| 226 | 234 | ||
| 227 | rsize = fid->iounit; | 235 | rsize = fid->iounit ? fid->iounit : clnt->msize - P9_IOHDRSZ; |
| 228 | if (!rsize || rsize > clnt->msize-P9_IOHDRSZ) | ||
| 229 | rsize = clnt->msize - P9_IOHDRSZ; | ||
| 230 | 236 | ||
| 231 | do { | 237 | do { |
| 232 | if (count < rsize) | 238 | if (count < rsize) |
diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c index 4331b3b5ee1c..6e94f3247cec 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 | ||
| 46 | static const struct inode_operations v9fs_dir_inode_operations; | 48 | static const struct inode_operations v9fs_dir_inode_operations; |
| 47 | static const struct inode_operations v9fs_dir_inode_operations_dotu; | 49 | static 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 | |||
| 246 | static 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 | |||
| 263 | static 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; |
| @@ -396,23 +439,14 @@ void v9fs_clear_inode(struct inode *inode) | |||
| 396 | #endif | 439 | #endif |
| 397 | } | 440 | } |
| 398 | 441 | ||
| 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 | |||
| 407 | static struct inode * | 442 | static struct inode * |
| 408 | v9fs_inode_from_fid(struct v9fs_session_info *v9ses, struct p9_fid *fid, | 443 | v9fs_inode(struct v9fs_session_info *v9ses, struct p9_fid *fid, |
| 409 | struct super_block *sb) | 444 | struct super_block *sb) |
| 410 | { | 445 | { |
| 411 | int err, umode; | 446 | int err, umode; |
| 412 | struct inode *ret; | 447 | struct inode *ret = NULL; |
| 413 | struct p9_wstat *st; | 448 | struct p9_wstat *st; |
| 414 | 449 | ||
| 415 | ret = NULL; | ||
| 416 | st = p9_client_stat(fid); | 450 | st = p9_client_stat(fid); |
| 417 | if (IS_ERR(st)) | 451 | if (IS_ERR(st)) |
| 418 | return ERR_CAST(st); | 452 | return ERR_CAST(st); |
| @@ -433,15 +467,62 @@ v9fs_inode_from_fid(struct v9fs_session_info *v9ses, struct p9_fid *fid, | |||
| 433 | #endif | 467 | #endif |
| 434 | p9stat_free(st); | 468 | p9stat_free(st); |
| 435 | kfree(st); | 469 | kfree(st); |
| 436 | |||
| 437 | return ret; | 470 | return ret; |
| 438 | |||
| 439 | error: | 471 | error: |
| 440 | p9stat_free(st); | 472 | p9stat_free(st); |
| 441 | kfree(st); | 473 | kfree(st); |
| 442 | return ERR_PTR(err); | 474 | return ERR_PTR(err); |
| 443 | } | 475 | } |
| 444 | 476 | ||
| 477 | static struct inode * | ||
| 478 | v9fs_inode_dotl(struct v9fs_session_info *v9ses, struct p9_fid *fid, | ||
| 479 | struct super_block *sb) | ||
| 480 | { | ||
| 481 | struct inode *ret = NULL; | ||
| 482 | int err; | ||
| 483 | struct p9_stat_dotl *st; | ||
| 484 | |||
| 485 | st = p9_client_getattr_dotl(fid, P9_STATS_BASIC); | ||
| 486 | if (IS_ERR(st)) | ||
| 487 | return ERR_CAST(st); | ||
| 488 | |||
| 489 | ret = v9fs_get_inode(sb, st->st_mode); | ||
| 490 | if (IS_ERR(ret)) { | ||
| 491 | err = PTR_ERR(ret); | ||
| 492 | goto error; | ||
| 493 | } | ||
| 494 | |||
| 495 | v9fs_stat2inode_dotl(st, ret); | ||
| 496 | ret->i_ino = v9fs_qid2ino(&st->qid); | ||
| 497 | #ifdef CONFIG_9P_FSCACHE | ||
| 498 | v9fs_vcookie_set_qid(ret, &st->qid); | ||
| 499 | v9fs_cache_inode_get_cookie(ret); | ||
| 500 | #endif | ||
| 501 | kfree(st); | ||
| 502 | return ret; | ||
| 503 | error: | ||
| 504 | kfree(st); | ||
| 505 | return ERR_PTR(err); | ||
| 506 | } | ||
| 507 | |||
| 508 | /** | ||
| 509 | * v9fs_inode_from_fid - Helper routine to populate an inode by | ||
| 510 | * issuing a attribute request | ||
| 511 | * @v9ses: session information | ||
| 512 | * @fid: fid to issue attribute request for | ||
| 513 | * @sb: superblock on which to create inode | ||
| 514 | * | ||
| 515 | */ | ||
| 516 | static inline struct inode * | ||
| 517 | v9fs_inode_from_fid(struct v9fs_session_info *v9ses, struct p9_fid *fid, | ||
| 518 | struct super_block *sb) | ||
| 519 | { | ||
| 520 | if (v9fs_proto_dotl(v9ses)) | ||
| 521 | return v9fs_inode_dotl(v9ses, fid, sb); | ||
| 522 | else | ||
| 523 | return v9fs_inode(v9ses, fid, sb); | ||
| 524 | } | ||
| 525 | |||
| 445 | /** | 526 | /** |
| 446 | * v9fs_remove - helper function to remove files and directories | 527 | * v9fs_remove - helper function to remove files and directories |
| 447 | * @dir: directory inode that is being deleted | 528 | * @dir: directory inode that is being deleted |
| @@ -563,6 +644,118 @@ error: | |||
| 563 | } | 644 | } |
| 564 | 645 | ||
| 565 | /** | 646 | /** |
| 647 | * v9fs_vfs_create_dotl - VFS hook to create files for 9P2000.L protocol. | ||
| 648 | * @dir: directory inode that is being created | ||
| 649 | * @dentry: dentry that is being deleted | ||
| 650 | * @mode: create permissions | ||
| 651 | * @nd: path information | ||
| 652 | * | ||
| 653 | */ | ||
| 654 | |||
| 655 | static int | ||
| 656 | v9fs_vfs_create_dotl(struct inode *dir, struct dentry *dentry, int mode, | ||
| 657 | struct nameidata *nd) | ||
| 658 | { | ||
| 659 | int err = 0; | ||
| 660 | char *name = NULL; | ||
| 661 | gid_t gid; | ||
| 662 | int flags; | ||
| 663 | struct v9fs_session_info *v9ses; | ||
| 664 | struct p9_fid *fid = NULL; | ||
| 665 | struct p9_fid *dfid, *ofid; | ||
| 666 | struct file *filp; | ||
| 667 | struct p9_qid qid; | ||
| 668 | struct inode *inode; | ||
| 669 | |||
| 670 | v9ses = v9fs_inode2v9ses(dir); | ||
| 671 | if (nd && nd->flags & LOOKUP_OPEN) | ||
| 672 | flags = nd->intent.open.flags - 1; | ||
| 673 | else | ||
| 674 | flags = O_RDWR; | ||
| 675 | |||
| 676 | name = (char *) dentry->d_name.name; | ||
| 677 | P9_DPRINTK(P9_DEBUG_VFS, "v9fs_vfs_create_dotl: name:%s flags:0x%x " | ||
| 678 | "mode:0x%x\n", name, flags, mode); | ||
| 679 | |||
| 680 | dfid = v9fs_fid_lookup(dentry->d_parent); | ||
| 681 | if (IS_ERR(dfid)) { | ||
| 682 | err = PTR_ERR(dfid); | ||
| 683 | P9_DPRINTK(P9_DEBUG_VFS, "fid lookup failed %d\n", err); | ||
| 684 | return err; | ||
| 685 | } | ||
| 686 | |||
| 687 | /* clone a fid to use for creation */ | ||
| 688 | ofid = p9_client_walk(dfid, 0, NULL, 1); | ||
| 689 | if (IS_ERR(ofid)) { | ||
| 690 | err = PTR_ERR(ofid); | ||
| 691 | P9_DPRINTK(P9_DEBUG_VFS, "p9_client_walk failed %d\n", err); | ||
| 692 | return err; | ||
| 693 | } | ||
| 694 | |||
| 695 | gid = v9fs_get_fsgid_for_create(dir); | ||
| 696 | err = p9_client_create_dotl(ofid, name, flags, mode, gid, &qid); | ||
| 697 | if (err < 0) { | ||
| 698 | P9_DPRINTK(P9_DEBUG_VFS, | ||
| 699 | "p9_client_open_dotl failed in creat %d\n", | ||
| 700 | err); | ||
| 701 | goto error; | ||
| 702 | } | ||
| 703 | |||
| 704 | /* No need to populate the inode if we are not opening the file AND | ||
| 705 | * not in cached mode. | ||
| 706 | */ | ||
| 707 | if (!v9ses->cache && !(nd && nd->flags & LOOKUP_OPEN)) { | ||
| 708 | /* Not in cached mode. No need to populate inode with stat */ | ||
| 709 | dentry->d_op = &v9fs_dentry_operations; | ||
| 710 | p9_client_clunk(ofid); | ||
| 711 | d_instantiate(dentry, NULL); | ||
| 712 | return 0; | ||
| 713 | } | ||
| 714 | |||
| 715 | /* Now walk from the parent so we can get an unopened fid. */ | ||
| 716 | fid = p9_client_walk(dfid, 1, &name, 1); | ||
| 717 | if (IS_ERR(fid)) { | ||
| 718 | err = PTR_ERR(fid); | ||
| 719 | P9_DPRINTK(P9_DEBUG_VFS, "p9_client_walk failed %d\n", err); | ||
| 720 | fid = NULL; | ||
| 721 | goto error; | ||
| 722 | } | ||
| 723 | |||
| 724 | /* instantiate inode and assign the unopened fid to dentry */ | ||
| 725 | inode = v9fs_inode_from_fid(v9ses, fid, dir->i_sb); | ||
| 726 | if (IS_ERR(inode)) { | ||
| 727 | err = PTR_ERR(inode); | ||
| 728 | P9_DPRINTK(P9_DEBUG_VFS, "inode creation failed %d\n", err); | ||
| 729 | goto error; | ||
| 730 | } | ||
| 731 | dentry->d_op = &v9fs_cached_dentry_operations; | ||
| 732 | d_instantiate(dentry, inode); | ||
| 733 | err = v9fs_fid_add(dentry, fid); | ||
| 734 | if (err < 0) | ||
| 735 | goto error; | ||
| 736 | |||
| 737 | /* if we are opening a file, assign the open fid to the file */ | ||
| 738 | if (nd && nd->flags & LOOKUP_OPEN) { | ||
| 739 | filp = lookup_instantiate_filp(nd, dentry, v9fs_open_created); | ||
| 740 | if (IS_ERR(filp)) { | ||
| 741 | p9_client_clunk(ofid); | ||
| 742 | return PTR_ERR(filp); | ||
| 743 | } | ||
| 744 | filp->private_data = ofid; | ||
| 745 | } else | ||
| 746 | p9_client_clunk(ofid); | ||
| 747 | |||
| 748 | return 0; | ||
| 749 | |||
| 750 | error: | ||
| 751 | if (ofid) | ||
| 752 | p9_client_clunk(ofid); | ||
| 753 | if (fid) | ||
| 754 | p9_client_clunk(fid); | ||
| 755 | return err; | ||
| 756 | } | ||
| 757 | |||
| 758 | /** | ||
| 566 | * v9fs_vfs_create - VFS hook to create files | 759 | * v9fs_vfs_create - VFS hook to create files |
| 567 | * @dir: directory inode that is being created | 760 | * @dir: directory inode that is being created |
| 568 | * @dentry: dentry that is being deleted | 761 | * @dentry: dentry that is being deleted |
| @@ -652,6 +845,83 @@ static int v9fs_vfs_mkdir(struct inode *dir, struct dentry *dentry, int mode) | |||
| 652 | return err; | 845 | return err; |
| 653 | } | 846 | } |
| 654 | 847 | ||
| 848 | |||
| 849 | /** | ||
| 850 | * v9fs_vfs_mkdir_dotl - VFS mkdir hook to create a directory | ||
| 851 | * @dir: inode that is being unlinked | ||
| 852 | * @dentry: dentry that is being unlinked | ||
| 853 | * @mode: mode for new directory | ||
| 854 | * | ||
| 855 | */ | ||
| 856 | |||
| 857 | static int v9fs_vfs_mkdir_dotl(struct inode *dir, struct dentry *dentry, | ||
| 858 | int mode) | ||
| 859 | { | ||
| 860 | int err; | ||
| 861 | struct v9fs_session_info *v9ses; | ||
| 862 | struct p9_fid *fid = NULL, *dfid = NULL; | ||
| 863 | gid_t gid; | ||
| 864 | char *name; | ||
| 865 | struct inode *inode; | ||
| 866 | struct p9_qid qid; | ||
| 867 | struct dentry *dir_dentry; | ||
| 868 | |||
| 869 | P9_DPRINTK(P9_DEBUG_VFS, "name %s\n", dentry->d_name.name); | ||
| 870 | err = 0; | ||
| 871 | v9ses = v9fs_inode2v9ses(dir); | ||
| 872 | |||
| 873 | mode |= S_IFDIR; | ||
| 874 | dir_dentry = v9fs_dentry_from_dir_inode(dir); | ||
| 875 | dfid = v9fs_fid_lookup(dir_dentry); | ||
| 876 | if (IS_ERR(dfid)) { | ||
| 877 | err = PTR_ERR(dfid); | ||
| 878 | P9_DPRINTK(P9_DEBUG_VFS, "fid lookup failed %d\n", err); | ||
| 879 | dfid = NULL; | ||
| 880 | goto error; | ||
| 881 | } | ||
| 882 | |||
| 883 | gid = v9fs_get_fsgid_for_create(dir); | ||
| 884 | if (gid < 0) { | ||
| 885 | P9_DPRINTK(P9_DEBUG_VFS, "v9fs_get_fsgid_for_create failed\n"); | ||
| 886 | goto error; | ||
| 887 | } | ||
| 888 | |||
| 889 | name = (char *) dentry->d_name.name; | ||
| 890 | err = p9_client_mkdir_dotl(dfid, name, mode, gid, &qid); | ||
| 891 | if (err < 0) | ||
| 892 | goto error; | ||
| 893 | |||
| 894 | /* instantiate inode and assign the unopened fid to the dentry */ | ||
| 895 | if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) { | ||
| 896 | fid = p9_client_walk(dfid, 1, &name, 1); | ||
| 897 | if (IS_ERR(fid)) { | ||
| 898 | err = PTR_ERR(fid); | ||
| 899 | P9_DPRINTK(P9_DEBUG_VFS, "p9_client_walk failed %d\n", | ||
| 900 | err); | ||
| 901 | fid = NULL; | ||
| 902 | goto error; | ||
| 903 | } | ||
| 904 | |||
| 905 | inode = v9fs_inode_from_fid(v9ses, fid, dir->i_sb); | ||
| 906 | if (IS_ERR(inode)) { | ||
| 907 | err = PTR_ERR(inode); | ||
| 908 | P9_DPRINTK(P9_DEBUG_VFS, "inode creation failed %d\n", | ||
| 909 | err); | ||
| 910 | goto error; | ||
| 911 | } | ||
| 912 | dentry->d_op = &v9fs_cached_dentry_operations; | ||
| 913 | d_instantiate(dentry, inode); | ||
| 914 | err = v9fs_fid_add(dentry, fid); | ||
| 915 | if (err < 0) | ||
| 916 | goto error; | ||
| 917 | fid = NULL; | ||
| 918 | } | ||
| 919 | error: | ||
| 920 | if (fid) | ||
| 921 | p9_client_clunk(fid); | ||
| 922 | return err; | ||
| 923 | } | ||
| 924 | |||
| 655 | /** | 925 | /** |
| 656 | * v9fs_vfs_lookup - VFS lookup hook to "walk" to a new inode | 926 | * v9fs_vfs_lookup - VFS lookup hook to "walk" to a new inode |
| 657 | * @dir: inode that is being walked from | 927 | * @dir: inode that is being walked from |
| @@ -678,6 +948,7 @@ static struct dentry *v9fs_vfs_lookup(struct inode *dir, struct dentry *dentry, | |||
| 678 | 948 | ||
| 679 | sb = dir->i_sb; | 949 | sb = dir->i_sb; |
| 680 | v9ses = v9fs_inode2v9ses(dir); | 950 | v9ses = v9fs_inode2v9ses(dir); |
| 951 | /* We can walk d_parent because we hold the dir->i_mutex */ | ||
| 681 | dfid = v9fs_fid_lookup(dentry->d_parent); | 952 | dfid = v9fs_fid_lookup(dentry->d_parent); |
| 682 | if (IS_ERR(dfid)) | 953 | if (IS_ERR(dfid)) |
| 683 | return ERR_CAST(dfid); | 954 | return ERR_CAST(dfid); |
| @@ -785,27 +1056,33 @@ v9fs_vfs_rename(struct inode *old_dir, struct dentry *old_dentry, | |||
| 785 | goto clunk_olddir; | 1056 | goto clunk_olddir; |
| 786 | } | 1057 | } |
| 787 | 1058 | ||
| 1059 | down_write(&v9ses->rename_sem); | ||
| 788 | if (v9fs_proto_dotl(v9ses)) { | 1060 | if (v9fs_proto_dotl(v9ses)) { |
| 789 | retval = p9_client_rename(oldfid, newdirfid, | 1061 | retval = p9_client_rename(oldfid, newdirfid, |
| 790 | (char *) new_dentry->d_name.name); | 1062 | (char *) new_dentry->d_name.name); |
| 791 | if (retval != -ENOSYS) | 1063 | if (retval != -ENOSYS) |
| 792 | goto clunk_newdir; | 1064 | goto clunk_newdir; |
| 793 | } | 1065 | } |
| 1066 | if (old_dentry->d_parent != new_dentry->d_parent) { | ||
| 1067 | /* | ||
| 1068 | * 9P .u can only handle file rename in the same directory | ||
| 1069 | */ | ||
| 794 | 1070 | ||
| 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, | 1071 | P9_DPRINTK(P9_DEBUG_ERROR, |
| 798 | "old dir and new dir are different\n"); | 1072 | "old dir and new dir are different\n"); |
| 799 | retval = -EXDEV; | 1073 | retval = -EXDEV; |
| 800 | goto clunk_newdir; | 1074 | goto clunk_newdir; |
| 801 | } | 1075 | } |
| 802 | |||
| 803 | v9fs_blank_wstat(&wstat); | 1076 | v9fs_blank_wstat(&wstat); |
| 804 | wstat.muid = v9ses->uname; | 1077 | wstat.muid = v9ses->uname; |
| 805 | wstat.name = (char *) new_dentry->d_name.name; | 1078 | wstat.name = (char *) new_dentry->d_name.name; |
| 806 | retval = p9_client_wstat(oldfid, &wstat); | 1079 | retval = p9_client_wstat(oldfid, &wstat); |
| 807 | 1080 | ||
| 808 | clunk_newdir: | 1081 | clunk_newdir: |
| 1082 | if (!retval) | ||
| 1083 | /* successful rename */ | ||
| 1084 | d_move(old_dentry, new_dentry); | ||
| 1085 | up_write(&v9ses->rename_sem); | ||
| 809 | p9_client_clunk(newdirfid); | 1086 | p9_client_clunk(newdirfid); |
| 810 | 1087 | ||
| 811 | clunk_olddir: | 1088 | clunk_olddir: |
| @@ -853,6 +1130,42 @@ v9fs_vfs_getattr(struct vfsmount *mnt, struct dentry *dentry, | |||
| 853 | return 0; | 1130 | return 0; |
| 854 | } | 1131 | } |
| 855 | 1132 | ||
| 1133 | static int | ||
| 1134 | v9fs_vfs_getattr_dotl(struct vfsmount *mnt, struct dentry *dentry, | ||
| 1135 | struct kstat *stat) | ||
| 1136 | { | ||
| 1137 | int err; | ||
| 1138 | struct v9fs_session_info *v9ses; | ||
| 1139 | struct p9_fid *fid; | ||
| 1140 | struct p9_stat_dotl *st; | ||
| 1141 | |||
| 1142 | P9_DPRINTK(P9_DEBUG_VFS, "dentry: %p\n", dentry); | ||
| 1143 | err = -EPERM; | ||
| 1144 | v9ses = v9fs_inode2v9ses(dentry->d_inode); | ||
| 1145 | if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) | ||
| 1146 | return simple_getattr(mnt, dentry, stat); | ||
| 1147 | |||
| 1148 | fid = v9fs_fid_lookup(dentry); | ||
| 1149 | if (IS_ERR(fid)) | ||
| 1150 | return PTR_ERR(fid); | ||
| 1151 | |||
| 1152 | /* Ask for all the fields in stat structure. Server will return | ||
| 1153 | * whatever it supports | ||
| 1154 | */ | ||
| 1155 | |||
| 1156 | st = p9_client_getattr_dotl(fid, P9_STATS_ALL); | ||
| 1157 | if (IS_ERR(st)) | ||
| 1158 | return PTR_ERR(st); | ||
| 1159 | |||
| 1160 | v9fs_stat2inode_dotl(st, dentry->d_inode); | ||
| 1161 | generic_fillattr(dentry->d_inode, stat); | ||
| 1162 | /* Change block size to what the server returned */ | ||
| 1163 | stat->blksize = st->st_blksize; | ||
| 1164 | |||
| 1165 | kfree(st); | ||
| 1166 | return 0; | ||
| 1167 | } | ||
| 1168 | |||
| 856 | /** | 1169 | /** |
| 857 | * v9fs_vfs_setattr - set file metadata | 1170 | * v9fs_vfs_setattr - set file metadata |
| 858 | * @dentry: file whose metadata to set | 1171 | * @dentry: file whose metadata to set |
| @@ -903,6 +1216,49 @@ static int v9fs_vfs_setattr(struct dentry *dentry, struct iattr *iattr) | |||
| 903 | } | 1216 | } |
| 904 | 1217 | ||
| 905 | /** | 1218 | /** |
| 1219 | * v9fs_vfs_setattr_dotl - set file metadata | ||
| 1220 | * @dentry: file whose metadata to set | ||
| 1221 | * @iattr: metadata assignment structure | ||
| 1222 | * | ||
| 1223 | */ | ||
| 1224 | |||
| 1225 | static int v9fs_vfs_setattr_dotl(struct dentry *dentry, struct iattr *iattr) | ||
| 1226 | { | ||
| 1227 | int retval; | ||
| 1228 | struct v9fs_session_info *v9ses; | ||
| 1229 | struct p9_fid *fid; | ||
| 1230 | struct p9_iattr_dotl p9attr; | ||
| 1231 | |||
| 1232 | P9_DPRINTK(P9_DEBUG_VFS, "\n"); | ||
| 1233 | |||
| 1234 | retval = inode_change_ok(dentry->d_inode, iattr); | ||
| 1235 | if (retval) | ||
| 1236 | return retval; | ||
| 1237 | |||
| 1238 | p9attr.valid = iattr->ia_valid; | ||
| 1239 | p9attr.mode = iattr->ia_mode; | ||
| 1240 | p9attr.uid = iattr->ia_uid; | ||
| 1241 | p9attr.gid = iattr->ia_gid; | ||
| 1242 | p9attr.size = iattr->ia_size; | ||
| 1243 | p9attr.atime_sec = iattr->ia_atime.tv_sec; | ||
| 1244 | p9attr.atime_nsec = iattr->ia_atime.tv_nsec; | ||
| 1245 | p9attr.mtime_sec = iattr->ia_mtime.tv_sec; | ||
| 1246 | p9attr.mtime_nsec = iattr->ia_mtime.tv_nsec; | ||
| 1247 | |||
| 1248 | retval = -EPERM; | ||
| 1249 | v9ses = v9fs_inode2v9ses(dentry->d_inode); | ||
| 1250 | fid = v9fs_fid_lookup(dentry); | ||
| 1251 | if (IS_ERR(fid)) | ||
| 1252 | return PTR_ERR(fid); | ||
| 1253 | |||
| 1254 | retval = p9_client_setattr(fid, &p9attr); | ||
| 1255 | if (retval >= 0) | ||
| 1256 | retval = inode_setattr(dentry->d_inode, iattr); | ||
| 1257 | |||
| 1258 | return retval; | ||
| 1259 | } | ||
| 1260 | |||
| 1261 | /** | ||
| 906 | * v9fs_stat2inode - populate an inode structure with mistat info | 1262 | * v9fs_stat2inode - populate an inode structure with mistat info |
| 907 | * @stat: Plan 9 metadata (mistat) structure | 1263 | * @stat: Plan 9 metadata (mistat) structure |
| 908 | * @inode: inode to populate | 1264 | * @inode: inode to populate |
| @@ -980,6 +1336,77 @@ v9fs_stat2inode(struct p9_wstat *stat, struct inode *inode, | |||
| 980 | } | 1336 | } |
| 981 | 1337 | ||
| 982 | /** | 1338 | /** |
| 1339 | * v9fs_stat2inode_dotl - populate an inode structure with stat info | ||
| 1340 | * @stat: stat structure | ||
| 1341 | * @inode: inode to populate | ||
| 1342 | * @sb: superblock of filesystem | ||
| 1343 | * | ||
| 1344 | */ | ||
| 1345 | |||
| 1346 | void | ||
| 1347 | v9fs_stat2inode_dotl(struct p9_stat_dotl *stat, struct inode *inode) | ||
| 1348 | { | ||
| 1349 | |||
| 1350 | if ((stat->st_result_mask & P9_STATS_BASIC) == P9_STATS_BASIC) { | ||
| 1351 | inode->i_atime.tv_sec = stat->st_atime_sec; | ||
| 1352 | inode->i_atime.tv_nsec = stat->st_atime_nsec; | ||
| 1353 | inode->i_mtime.tv_sec = stat->st_mtime_sec; | ||
| 1354 | inode->i_mtime.tv_nsec = stat->st_mtime_nsec; | ||
| 1355 | inode->i_ctime.tv_sec = stat->st_ctime_sec; | ||
| 1356 | inode->i_ctime.tv_nsec = stat->st_ctime_nsec; | ||
| 1357 | inode->i_uid = stat->st_uid; | ||
| 1358 | inode->i_gid = stat->st_gid; | ||
| 1359 | inode->i_nlink = stat->st_nlink; | ||
| 1360 | inode->i_mode = stat->st_mode; | ||
| 1361 | inode->i_rdev = new_decode_dev(stat->st_rdev); | ||
| 1362 | |||
| 1363 | if ((S_ISBLK(inode->i_mode)) || (S_ISCHR(inode->i_mode))) | ||
| 1364 | init_special_inode(inode, inode->i_mode, inode->i_rdev); | ||
| 1365 | |||
| 1366 | i_size_write(inode, stat->st_size); | ||
| 1367 | inode->i_blocks = stat->st_blocks; | ||
| 1368 | } else { | ||
| 1369 | if (stat->st_result_mask & P9_STATS_ATIME) { | ||
| 1370 | inode->i_atime.tv_sec = stat->st_atime_sec; | ||
| 1371 | inode->i_atime.tv_nsec = stat->st_atime_nsec; | ||
| 1372 | } | ||
| 1373 | if (stat->st_result_mask & P9_STATS_MTIME) { | ||
| 1374 | inode->i_mtime.tv_sec = stat->st_mtime_sec; | ||
| 1375 | inode->i_mtime.tv_nsec = stat->st_mtime_nsec; | ||
| 1376 | } | ||
| 1377 | if (stat->st_result_mask & P9_STATS_CTIME) { | ||
| 1378 | inode->i_ctime.tv_sec = stat->st_ctime_sec; | ||
| 1379 | inode->i_ctime.tv_nsec = stat->st_ctime_nsec; | ||
| 1380 | } | ||
| 1381 | if (stat->st_result_mask & P9_STATS_UID) | ||
| 1382 | inode->i_uid = stat->st_uid; | ||
| 1383 | if (stat->st_result_mask & P9_STATS_GID) | ||
| 1384 | inode->i_gid = stat->st_gid; | ||
| 1385 | if (stat->st_result_mask & P9_STATS_NLINK) | ||
| 1386 | inode->i_nlink = stat->st_nlink; | ||
| 1387 | if (stat->st_result_mask & P9_STATS_MODE) { | ||
| 1388 | inode->i_mode = stat->st_mode; | ||
| 1389 | if ((S_ISBLK(inode->i_mode)) || | ||
| 1390 | (S_ISCHR(inode->i_mode))) | ||
| 1391 | init_special_inode(inode, inode->i_mode, | ||
| 1392 | inode->i_rdev); | ||
| 1393 | } | ||
| 1394 | if (stat->st_result_mask & P9_STATS_RDEV) | ||
| 1395 | inode->i_rdev = new_decode_dev(stat->st_rdev); | ||
| 1396 | if (stat->st_result_mask & P9_STATS_SIZE) | ||
| 1397 | i_size_write(inode, stat->st_size); | ||
| 1398 | if (stat->st_result_mask & P9_STATS_BLOCKS) | ||
| 1399 | inode->i_blocks = stat->st_blocks; | ||
| 1400 | } | ||
| 1401 | if (stat->st_result_mask & P9_STATS_GEN) | ||
| 1402 | inode->i_generation = stat->st_gen; | ||
| 1403 | |||
| 1404 | /* Currently we don't support P9_STATS_BTIME and P9_STATS_DATA_VERSION | ||
| 1405 | * because the inode structure does not have fields for them. | ||
| 1406 | */ | ||
| 1407 | } | ||
| 1408 | |||
| 1409 | /** | ||
| 983 | * v9fs_qid2ino - convert qid into inode number | 1410 | * v9fs_qid2ino - convert qid into inode number |
| 984 | * @qid: qid to hash | 1411 | * @qid: qid to hash |
| 985 | * | 1412 | * |
| @@ -1022,7 +1449,7 @@ static int v9fs_readlink(struct dentry *dentry, char *buffer, int buflen) | |||
| 1022 | if (IS_ERR(fid)) | 1449 | if (IS_ERR(fid)) |
| 1023 | return PTR_ERR(fid); | 1450 | return PTR_ERR(fid); |
| 1024 | 1451 | ||
| 1025 | if (!v9fs_proto_dotu(v9ses)) | 1452 | if (!v9fs_proto_dotu(v9ses) && !v9fs_proto_dotl(v9ses)) |
| 1026 | return -EBADF; | 1453 | return -EBADF; |
| 1027 | 1454 | ||
| 1028 | st = p9_client_stat(fid); | 1455 | st = p9_client_stat(fid); |
| @@ -1128,6 +1555,99 @@ static int v9fs_vfs_mkspecial(struct inode *dir, struct dentry *dentry, | |||
| 1128 | } | 1555 | } |
| 1129 | 1556 | ||
| 1130 | /** | 1557 | /** |
| 1558 | * v9fs_vfs_symlink_dotl - helper function to create symlinks | ||
| 1559 | * @dir: directory inode containing symlink | ||
| 1560 | * @dentry: dentry for symlink | ||
| 1561 | * @symname: symlink data | ||
| 1562 | * | ||
| 1563 | * See Also: 9P2000.L RFC for more information | ||
| 1564 | * | ||
| 1565 | */ | ||
| 1566 | |||
| 1567 | static int | ||
| 1568 | v9fs_vfs_symlink_dotl(struct inode *dir, struct dentry *dentry, | ||
| 1569 | const char *symname) | ||
| 1570 | { | ||
| 1571 | struct v9fs_session_info *v9ses; | ||
| 1572 | struct p9_fid *dfid; | ||
| 1573 | struct p9_fid *fid = NULL; | ||
| 1574 | struct inode *inode; | ||
| 1575 | struct p9_qid qid; | ||
| 1576 | char *name; | ||
| 1577 | int err; | ||
| 1578 | gid_t gid; | ||
| 1579 | |||
| 1580 | name = (char *) dentry->d_name.name; | ||
| 1581 | P9_DPRINTK(P9_DEBUG_VFS, "v9fs_vfs_symlink_dotl : %lu,%s,%s\n", | ||
| 1582 | dir->i_ino, name, symname); | ||
| 1583 | v9ses = v9fs_inode2v9ses(dir); | ||
| 1584 | |||
| 1585 | dfid = v9fs_fid_lookup(dentry->d_parent); | ||
| 1586 | if (IS_ERR(dfid)) { | ||
| 1587 | err = PTR_ERR(dfid); | ||
| 1588 | P9_DPRINTK(P9_DEBUG_VFS, "fid lookup failed %d\n", err); | ||
| 1589 | return err; | ||
| 1590 | } | ||
| 1591 | |||
| 1592 | gid = v9fs_get_fsgid_for_create(dir); | ||
| 1593 | |||
| 1594 | if (gid < 0) { | ||
| 1595 | P9_DPRINTK(P9_DEBUG_VFS, "v9fs_get_egid failed %d\n", gid); | ||
| 1596 | goto error; | ||
| 1597 | } | ||
| 1598 | |||
| 1599 | /* Server doesn't alter fid on TSYMLINK. Hence no need to clone it. */ | ||
| 1600 | err = p9_client_symlink(dfid, name, (char *)symname, gid, &qid); | ||
| 1601 | |||
| 1602 | if (err < 0) { | ||
| 1603 | P9_DPRINTK(P9_DEBUG_VFS, "p9_client_symlink failed %d\n", err); | ||
| 1604 | goto error; | ||
| 1605 | } | ||
| 1606 | |||
| 1607 | if (v9ses->cache) { | ||
| 1608 | /* Now walk from the parent so we can get an unopened fid. */ | ||
| 1609 | fid = p9_client_walk(dfid, 1, &name, 1); | ||
| 1610 | if (IS_ERR(fid)) { | ||
| 1611 | err = PTR_ERR(fid); | ||
| 1612 | P9_DPRINTK(P9_DEBUG_VFS, "p9_client_walk failed %d\n", | ||
| 1613 | err); | ||
| 1614 | fid = NULL; | ||
| 1615 | goto error; | ||
| 1616 | } | ||
| 1617 | |||
| 1618 | /* instantiate inode and assign the unopened fid to dentry */ | ||
| 1619 | inode = v9fs_inode_from_fid(v9ses, fid, dir->i_sb); | ||
| 1620 | if (IS_ERR(inode)) { | ||
| 1621 | err = PTR_ERR(inode); | ||
| 1622 | P9_DPRINTK(P9_DEBUG_VFS, "inode creation failed %d\n", | ||
| 1623 | err); | ||
| 1624 | goto error; | ||
| 1625 | } | ||
| 1626 | dentry->d_op = &v9fs_cached_dentry_operations; | ||
| 1627 | d_instantiate(dentry, inode); | ||
| 1628 | err = v9fs_fid_add(dentry, fid); | ||
| 1629 | if (err < 0) | ||
| 1630 | goto error; | ||
| 1631 | fid = NULL; | ||
| 1632 | } else { | ||
| 1633 | /* Not in cached mode. No need to populate inode with stat */ | ||
| 1634 | inode = v9fs_get_inode(dir->i_sb, S_IFLNK); | ||
| 1635 | if (IS_ERR(inode)) { | ||
| 1636 | err = PTR_ERR(inode); | ||
| 1637 | goto error; | ||
| 1638 | } | ||
| 1639 | dentry->d_op = &v9fs_dentry_operations; | ||
| 1640 | d_instantiate(dentry, inode); | ||
| 1641 | } | ||
| 1642 | |||
| 1643 | error: | ||
| 1644 | if (fid) | ||
| 1645 | p9_client_clunk(fid); | ||
| 1646 | |||
| 1647 | return err; | ||
| 1648 | } | ||
| 1649 | |||
| 1650 | /** | ||
| 1131 | * v9fs_vfs_symlink - helper function to create symlinks | 1651 | * v9fs_vfs_symlink - helper function to create symlinks |
| 1132 | * @dir: directory inode containing symlink | 1652 | * @dir: directory inode containing symlink |
| 1133 | * @dentry: dentry for symlink | 1653 | * @dentry: dentry for symlink |
| @@ -1186,6 +1706,76 @@ clunk_fid: | |||
| 1186 | } | 1706 | } |
| 1187 | 1707 | ||
| 1188 | /** | 1708 | /** |
| 1709 | * v9fs_vfs_link_dotl - create a hardlink for dotl | ||
| 1710 | * @old_dentry: dentry for file to link to | ||
| 1711 | * @dir: inode destination for new link | ||
| 1712 | * @dentry: dentry for link | ||
| 1713 | * | ||
| 1714 | */ | ||
| 1715 | |||
| 1716 | static int | ||
| 1717 | v9fs_vfs_link_dotl(struct dentry *old_dentry, struct inode *dir, | ||
| 1718 | struct dentry *dentry) | ||
| 1719 | { | ||
| 1720 | int err; | ||
| 1721 | struct p9_fid *dfid, *oldfid; | ||
| 1722 | char *name; | ||
| 1723 | struct v9fs_session_info *v9ses; | ||
| 1724 | struct dentry *dir_dentry; | ||
| 1725 | |||
| 1726 | P9_DPRINTK(P9_DEBUG_VFS, "dir ino: %lu, old_name: %s, new_name: %s\n", | ||
| 1727 | dir->i_ino, old_dentry->d_name.name, | ||
| 1728 | dentry->d_name.name); | ||
| 1729 | |||
| 1730 | v9ses = v9fs_inode2v9ses(dir); | ||
| 1731 | dir_dentry = v9fs_dentry_from_dir_inode(dir); | ||
| 1732 | dfid = v9fs_fid_lookup(dir_dentry); | ||
| 1733 | if (IS_ERR(dfid)) | ||
| 1734 | return PTR_ERR(dfid); | ||
| 1735 | |||
| 1736 | oldfid = v9fs_fid_lookup(old_dentry); | ||
| 1737 | if (IS_ERR(oldfid)) | ||
| 1738 | return PTR_ERR(oldfid); | ||
| 1739 | |||
| 1740 | name = (char *) dentry->d_name.name; | ||
| 1741 | |||
| 1742 | err = p9_client_link(dfid, oldfid, (char *)dentry->d_name.name); | ||
| 1743 | |||
| 1744 | if (err < 0) { | ||
| 1745 | P9_DPRINTK(P9_DEBUG_VFS, "p9_client_link failed %d\n", err); | ||
| 1746 | return err; | ||
| 1747 | } | ||
| 1748 | |||
| 1749 | if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) { | ||
| 1750 | /* Get the latest stat info from server. */ | ||
| 1751 | struct p9_fid *fid; | ||
| 1752 | struct p9_stat_dotl *st; | ||
| 1753 | |||
| 1754 | fid = v9fs_fid_lookup(old_dentry); | ||
| 1755 | if (IS_ERR(fid)) | ||
| 1756 | return PTR_ERR(fid); | ||
| 1757 | |||
| 1758 | st = p9_client_getattr_dotl(fid, P9_STATS_BASIC); | ||
| 1759 | if (IS_ERR(st)) | ||
| 1760 | return PTR_ERR(st); | ||
| 1761 | |||
| 1762 | v9fs_stat2inode_dotl(st, old_dentry->d_inode); | ||
| 1763 | |||
| 1764 | kfree(st); | ||
| 1765 | } else { | ||
| 1766 | /* Caching disabled. No need to get upto date stat info. | ||
| 1767 | * This dentry will be released immediately. So, just i_count++ | ||
| 1768 | */ | ||
| 1769 | atomic_inc(&old_dentry->d_inode->i_count); | ||
| 1770 | } | ||
| 1771 | |||
| 1772 | dentry->d_op = old_dentry->d_op; | ||
| 1773 | d_instantiate(dentry, old_dentry->d_inode); | ||
| 1774 | |||
| 1775 | return err; | ||
| 1776 | } | ||
| 1777 | |||
| 1778 | /** | ||
| 1189 | * v9fs_vfs_mknod - create a special file | 1779 | * v9fs_vfs_mknod - create a special file |
| 1190 | * @dir: inode destination for new link | 1780 | * @dir: inode destination for new link |
| 1191 | * @dentry: dentry for file | 1781 | * @dentry: dentry for file |
| @@ -1230,6 +1820,100 @@ v9fs_vfs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t rdev) | |||
| 1230 | return retval; | 1820 | return retval; |
| 1231 | } | 1821 | } |
| 1232 | 1822 | ||
| 1823 | /** | ||
| 1824 | * v9fs_vfs_mknod_dotl - create a special file | ||
| 1825 | * @dir: inode destination for new link | ||
| 1826 | * @dentry: dentry for file | ||
| 1827 | * @mode: mode for creation | ||
| 1828 | * @rdev: device associated with special file | ||
| 1829 | * | ||
| 1830 | */ | ||
| 1831 | static int | ||
| 1832 | v9fs_vfs_mknod_dotl(struct inode *dir, struct dentry *dentry, int mode, | ||
| 1833 | dev_t rdev) | ||
| 1834 | { | ||
| 1835 | int err; | ||
| 1836 | char *name; | ||
| 1837 | struct v9fs_session_info *v9ses; | ||
| 1838 | struct p9_fid *fid = NULL, *dfid = NULL; | ||
| 1839 | struct inode *inode; | ||
| 1840 | gid_t gid; | ||
| 1841 | struct p9_qid qid; | ||
| 1842 | struct dentry *dir_dentry; | ||
| 1843 | |||
| 1844 | P9_DPRINTK(P9_DEBUG_VFS, | ||
| 1845 | " %lu,%s mode: %x MAJOR: %u MINOR: %u\n", dir->i_ino, | ||
| 1846 | dentry->d_name.name, mode, MAJOR(rdev), MINOR(rdev)); | ||
| 1847 | |||
| 1848 | if (!new_valid_dev(rdev)) | ||
| 1849 | return -EINVAL; | ||
| 1850 | |||
| 1851 | v9ses = v9fs_inode2v9ses(dir); | ||
| 1852 | dir_dentry = v9fs_dentry_from_dir_inode(dir); | ||
| 1853 | dfid = v9fs_fid_lookup(dir_dentry); | ||
| 1854 | if (IS_ERR(dfid)) { | ||
| 1855 | err = PTR_ERR(dfid); | ||
| 1856 | P9_DPRINTK(P9_DEBUG_VFS, "fid lookup failed %d\n", err); | ||
| 1857 | dfid = NULL; | ||
| 1858 | goto error; | ||
| 1859 | } | ||
| 1860 | |||
| 1861 | gid = v9fs_get_fsgid_for_create(dir); | ||
| 1862 | if (gid < 0) { | ||
| 1863 | P9_DPRINTK(P9_DEBUG_VFS, "v9fs_get_fsgid_for_create failed\n"); | ||
| 1864 | goto error; | ||
| 1865 | } | ||
| 1866 | |||
| 1867 | name = (char *) dentry->d_name.name; | ||
| 1868 | |||
| 1869 | err = p9_client_mknod_dotl(dfid, name, mode, rdev, gid, &qid); | ||
| 1870 | if (err < 0) | ||
| 1871 | goto error; | ||
| 1872 | |||
| 1873 | /* instantiate inode and assign the unopened fid to the dentry */ | ||
| 1874 | if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) { | ||
| 1875 | fid = p9_client_walk(dfid, 1, &name, 1); | ||
| 1876 | if (IS_ERR(fid)) { | ||
| 1877 | err = PTR_ERR(fid); | ||
| 1878 | P9_DPRINTK(P9_DEBUG_VFS, "p9_client_walk failed %d\n", | ||
| 1879 | err); | ||
| 1880 | fid = NULL; | ||
| 1881 | goto error; | ||
| 1882 | } | ||
| 1883 | |||
| 1884 | inode = v9fs_inode_from_fid(v9ses, fid, dir->i_sb); | ||
| 1885 | if (IS_ERR(inode)) { | ||
| 1886 | err = PTR_ERR(inode); | ||
| 1887 | P9_DPRINTK(P9_DEBUG_VFS, "inode creation failed %d\n", | ||
| 1888 | err); | ||
| 1889 | goto error; | ||
| 1890 | } | ||
| 1891 | dentry->d_op = &v9fs_cached_dentry_operations; | ||
| 1892 | d_instantiate(dentry, inode); | ||
| 1893 | err = v9fs_fid_add(dentry, fid); | ||
| 1894 | if (err < 0) | ||
| 1895 | goto error; | ||
| 1896 | fid = NULL; | ||
| 1897 | } else { | ||
| 1898 | /* | ||
| 1899 | * Not in cached mode. No need to populate inode with stat. | ||
| 1900 | * socket syscall returns a fd, so we need instantiate | ||
| 1901 | */ | ||
| 1902 | inode = v9fs_get_inode(dir->i_sb, mode); | ||
| 1903 | if (IS_ERR(inode)) { | ||
| 1904 | err = PTR_ERR(inode); | ||
| 1905 | goto error; | ||
| 1906 | } | ||
| 1907 | dentry->d_op = &v9fs_dentry_operations; | ||
| 1908 | d_instantiate(dentry, inode); | ||
| 1909 | } | ||
| 1910 | |||
| 1911 | error: | ||
| 1912 | if (fid) | ||
| 1913 | p9_client_clunk(fid); | ||
| 1914 | return err; | ||
| 1915 | } | ||
| 1916 | |||
| 1233 | static const struct inode_operations v9fs_dir_inode_operations_dotu = { | 1917 | static const struct inode_operations v9fs_dir_inode_operations_dotu = { |
| 1234 | .create = v9fs_vfs_create, | 1918 | .create = v9fs_vfs_create, |
| 1235 | .lookup = v9fs_vfs_lookup, | 1919 | .lookup = v9fs_vfs_lookup, |
| @@ -1238,24 +1922,29 @@ static const struct inode_operations v9fs_dir_inode_operations_dotu = { | |||
| 1238 | .unlink = v9fs_vfs_unlink, | 1922 | .unlink = v9fs_vfs_unlink, |
| 1239 | .mkdir = v9fs_vfs_mkdir, | 1923 | .mkdir = v9fs_vfs_mkdir, |
| 1240 | .rmdir = v9fs_vfs_rmdir, | 1924 | .rmdir = v9fs_vfs_rmdir, |
| 1241 | .mknod = v9fs_vfs_mknod, | 1925 | .mknod = v9fs_vfs_mknod_dotl, |
| 1242 | .rename = v9fs_vfs_rename, | 1926 | .rename = v9fs_vfs_rename, |
| 1243 | .getattr = v9fs_vfs_getattr, | 1927 | .getattr = v9fs_vfs_getattr, |
| 1244 | .setattr = v9fs_vfs_setattr, | 1928 | .setattr = v9fs_vfs_setattr, |
| 1245 | }; | 1929 | }; |
| 1246 | 1930 | ||
| 1247 | static const struct inode_operations v9fs_dir_inode_operations_dotl = { | 1931 | static const struct inode_operations v9fs_dir_inode_operations_dotl = { |
| 1248 | .create = v9fs_vfs_create, | 1932 | .create = v9fs_vfs_create_dotl, |
| 1249 | .lookup = v9fs_vfs_lookup, | 1933 | .lookup = v9fs_vfs_lookup, |
| 1250 | .symlink = v9fs_vfs_symlink, | 1934 | .link = v9fs_vfs_link_dotl, |
| 1251 | .link = v9fs_vfs_link, | 1935 | .symlink = v9fs_vfs_symlink_dotl, |
| 1252 | .unlink = v9fs_vfs_unlink, | 1936 | .unlink = v9fs_vfs_unlink, |
| 1253 | .mkdir = v9fs_vfs_mkdir, | 1937 | .mkdir = v9fs_vfs_mkdir_dotl, |
| 1254 | .rmdir = v9fs_vfs_rmdir, | 1938 | .rmdir = v9fs_vfs_rmdir, |
| 1255 | .mknod = v9fs_vfs_mknod, | 1939 | .mknod = v9fs_vfs_mknod_dotl, |
| 1256 | .rename = v9fs_vfs_rename, | 1940 | .rename = v9fs_vfs_rename, |
| 1257 | .getattr = v9fs_vfs_getattr, | 1941 | .getattr = v9fs_vfs_getattr_dotl, |
| 1258 | .setattr = v9fs_vfs_setattr, | 1942 | .setattr = v9fs_vfs_setattr_dotl, |
| 1943 | .setxattr = generic_setxattr, | ||
| 1944 | .getxattr = generic_getxattr, | ||
| 1945 | .removexattr = generic_removexattr, | ||
| 1946 | .listxattr = v9fs_listxattr, | ||
| 1947 | |||
| 1259 | }; | 1948 | }; |
| 1260 | 1949 | ||
| 1261 | static const struct inode_operations v9fs_dir_inode_operations = { | 1950 | static const struct inode_operations v9fs_dir_inode_operations = { |
| @@ -1276,8 +1965,12 @@ static const struct inode_operations v9fs_file_inode_operations = { | |||
| 1276 | }; | 1965 | }; |
| 1277 | 1966 | ||
| 1278 | static const struct inode_operations v9fs_file_inode_operations_dotl = { | 1967 | static const struct inode_operations v9fs_file_inode_operations_dotl = { |
| 1279 | .getattr = v9fs_vfs_getattr, | 1968 | .getattr = v9fs_vfs_getattr_dotl, |
| 1280 | .setattr = v9fs_vfs_setattr, | 1969 | .setattr = v9fs_vfs_setattr_dotl, |
| 1970 | .setxattr = generic_setxattr, | ||
| 1971 | .getxattr = generic_getxattr, | ||
| 1972 | .removexattr = generic_removexattr, | ||
| 1973 | .listxattr = v9fs_listxattr, | ||
| 1281 | }; | 1974 | }; |
| 1282 | 1975 | ||
| 1283 | static const struct inode_operations v9fs_symlink_inode_operations = { | 1976 | static const struct inode_operations v9fs_symlink_inode_operations = { |
| @@ -1292,6 +1985,10 @@ static const struct inode_operations v9fs_symlink_inode_operations_dotl = { | |||
| 1292 | .readlink = generic_readlink, | 1985 | .readlink = generic_readlink, |
| 1293 | .follow_link = v9fs_vfs_follow_link, | 1986 | .follow_link = v9fs_vfs_follow_link, |
| 1294 | .put_link = v9fs_vfs_put_link, | 1987 | .put_link = v9fs_vfs_put_link, |
| 1295 | .getattr = v9fs_vfs_getattr, | 1988 | .getattr = v9fs_vfs_getattr_dotl, |
| 1296 | .setattr = v9fs_vfs_setattr, | 1989 | .setattr = v9fs_vfs_setattr_dotl, |
| 1990 | .setxattr = generic_setxattr, | ||
| 1991 | .getxattr = generic_getxattr, | ||
| 1992 | .removexattr = generic_removexattr, | ||
| 1993 | .listxattr = v9fs_listxattr, | ||
| 1297 | }; | 1994 | }; |
diff --git a/fs/9p/vfs_super.c b/fs/9p/vfs_super.c index be74d020436e..4b9ede0b41b7 100644 --- a/fs/9p/vfs_super.c +++ b/fs/9p/vfs_super.c | |||
| @@ -45,6 +45,7 @@ | |||
| 45 | #include "v9fs.h" | 45 | #include "v9fs.h" |
| 46 | #include "v9fs_vfs.h" | 46 | #include "v9fs_vfs.h" |
| 47 | #include "fid.h" | 47 | #include "fid.h" |
| 48 | #include "xattr.h" | ||
| 48 | 49 | ||
| 49 | static const struct super_operations v9fs_super_ops, v9fs_super_ops_dotl; | 50 | static const struct super_operations v9fs_super_ops, v9fs_super_ops_dotl; |
| 50 | 51 | ||
| @@ -77,9 +78,10 @@ v9fs_fill_super(struct super_block *sb, struct v9fs_session_info *v9ses, | |||
| 77 | sb->s_blocksize_bits = fls(v9ses->maxdata - 1); | 78 | sb->s_blocksize_bits = fls(v9ses->maxdata - 1); |
| 78 | sb->s_blocksize = 1 << sb->s_blocksize_bits; | 79 | sb->s_blocksize = 1 << sb->s_blocksize_bits; |
| 79 | sb->s_magic = V9FS_MAGIC; | 80 | sb->s_magic = V9FS_MAGIC; |
| 80 | if (v9fs_proto_dotl(v9ses)) | 81 | if (v9fs_proto_dotl(v9ses)) { |
| 81 | sb->s_op = &v9fs_super_ops_dotl; | 82 | sb->s_op = &v9fs_super_ops_dotl; |
| 82 | else | 83 | sb->s_xattr = v9fs_xattr_handlers; |
| 84 | } else | ||
| 83 | sb->s_op = &v9fs_super_ops; | 85 | sb->s_op = &v9fs_super_ops; |
| 84 | sb->s_bdi = &v9ses->bdi; | 86 | sb->s_bdi = &v9ses->bdi; |
| 85 | 87 | ||
| @@ -107,7 +109,6 @@ static int v9fs_get_sb(struct file_system_type *fs_type, int flags, | |||
| 107 | struct inode *inode = NULL; | 109 | struct inode *inode = NULL; |
| 108 | struct dentry *root = NULL; | 110 | struct dentry *root = NULL; |
| 109 | struct v9fs_session_info *v9ses = NULL; | 111 | struct v9fs_session_info *v9ses = NULL; |
| 110 | struct p9_wstat *st = NULL; | ||
| 111 | int mode = S_IRWXUGO | S_ISVTX; | 112 | int mode = S_IRWXUGO | S_ISVTX; |
| 112 | struct p9_fid *fid; | 113 | struct p9_fid *fid; |
| 113 | int retval = 0; | 114 | int retval = 0; |
| @@ -124,16 +125,10 @@ static int v9fs_get_sb(struct file_system_type *fs_type, int flags, | |||
| 124 | goto close_session; | 125 | goto close_session; |
| 125 | } | 126 | } |
| 126 | 127 | ||
| 127 | st = p9_client_stat(fid); | ||
| 128 | if (IS_ERR(st)) { | ||
| 129 | retval = PTR_ERR(st); | ||
| 130 | goto clunk_fid; | ||
| 131 | } | ||
| 132 | |||
| 133 | sb = sget(fs_type, NULL, v9fs_set_super, v9ses); | 128 | sb = sget(fs_type, NULL, v9fs_set_super, v9ses); |
| 134 | if (IS_ERR(sb)) { | 129 | if (IS_ERR(sb)) { |
| 135 | retval = PTR_ERR(sb); | 130 | retval = PTR_ERR(sb); |
| 136 | goto free_stat; | 131 | goto clunk_fid; |
| 137 | } | 132 | } |
| 138 | v9fs_fill_super(sb, v9ses, flags, data); | 133 | v9fs_fill_super(sb, v9ses, flags, data); |
| 139 | 134 | ||
| @@ -151,22 +146,38 @@ static int v9fs_get_sb(struct file_system_type *fs_type, int flags, | |||
| 151 | } | 146 | } |
| 152 | 147 | ||
| 153 | sb->s_root = root; | 148 | sb->s_root = root; |
| 154 | root->d_inode->i_ino = v9fs_qid2ino(&st->qid); | ||
| 155 | 149 | ||
| 156 | v9fs_stat2inode(st, root->d_inode, sb); | 150 | if (v9fs_proto_dotl(v9ses)) { |
| 151 | struct p9_stat_dotl *st = NULL; | ||
| 152 | st = p9_client_getattr_dotl(fid, P9_STATS_BASIC); | ||
| 153 | if (IS_ERR(st)) { | ||
| 154 | retval = PTR_ERR(st); | ||
| 155 | goto clunk_fid; | ||
| 156 | } | ||
| 157 | |||
| 158 | v9fs_stat2inode_dotl(st, root->d_inode); | ||
| 159 | kfree(st); | ||
| 160 | } else { | ||
| 161 | struct p9_wstat *st = NULL; | ||
| 162 | st = p9_client_stat(fid); | ||
| 163 | if (IS_ERR(st)) { | ||
| 164 | retval = PTR_ERR(st); | ||
| 165 | goto clunk_fid; | ||
| 166 | } | ||
| 167 | |||
| 168 | root->d_inode->i_ino = v9fs_qid2ino(&st->qid); | ||
| 169 | v9fs_stat2inode(st, root->d_inode, sb); | ||
| 170 | |||
| 171 | p9stat_free(st); | ||
| 172 | kfree(st); | ||
| 173 | } | ||
| 157 | 174 | ||
| 158 | v9fs_fid_add(root, fid); | 175 | v9fs_fid_add(root, fid); |
| 159 | p9stat_free(st); | ||
| 160 | kfree(st); | ||
| 161 | 176 | ||
| 162 | P9_DPRINTK(P9_DEBUG_VFS, " simple set mount, return 0\n"); | 177 | P9_DPRINTK(P9_DEBUG_VFS, " simple set mount, return 0\n"); |
| 163 | simple_set_mnt(mnt, sb); | 178 | simple_set_mnt(mnt, sb); |
| 164 | return 0; | 179 | return 0; |
| 165 | 180 | ||
| 166 | free_stat: | ||
| 167 | p9stat_free(st); | ||
| 168 | kfree(st); | ||
| 169 | |||
| 170 | clunk_fid: | 181 | clunk_fid: |
| 171 | p9_client_clunk(fid); | 182 | p9_client_clunk(fid); |
| 172 | 183 | ||
| @@ -176,8 +187,6 @@ close_session: | |||
| 176 | return retval; | 187 | return retval; |
| 177 | 188 | ||
| 178 | release_sb: | 189 | release_sb: |
| 179 | p9stat_free(st); | ||
| 180 | kfree(st); | ||
| 181 | deactivate_locked_super(sb); | 190 | deactivate_locked_super(sb); |
| 182 | return retval; | 191 | return retval; |
| 183 | } | 192 | } |
| @@ -278,4 +287,5 @@ struct file_system_type v9fs_fs_type = { | |||
| 278 | .get_sb = v9fs_get_sb, | 287 | .get_sb = v9fs_get_sb, |
| 279 | .kill_sb = v9fs_kill_super, | 288 | .kill_sb = v9fs_kill_super, |
| 280 | .owner = THIS_MODULE, | 289 | .owner = THIS_MODULE, |
| 290 | .fs_flags = FS_RENAME_DOES_D_MOVE, | ||
| 281 | }; | 291 | }; |
diff --git a/fs/9p/xattr.c b/fs/9p/xattr.c new file mode 100644 index 000000000000..f88e5c2dc873 --- /dev/null +++ b/fs/9p/xattr.c | |||
| @@ -0,0 +1,160 @@ | |||
| 1 | /* | ||
| 2 | * Copyright IBM Corporation, 2010 | ||
| 3 | * Author Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com> | ||
| 4 | * | ||
| 5 | * This program is free software; you can redistribute it and/or modify it | ||
| 6 | * under the terms of version 2.1 of the GNU Lesser General Public License | ||
| 7 | * as published by the Free Software Foundation. | ||
| 8 | * | ||
| 9 | * This program is distributed in the hope that it would be useful, but | ||
| 10 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
| 12 | * | ||
| 13 | */ | ||
| 14 | |||
| 15 | #include <linux/module.h> | ||
| 16 | #include <linux/fs.h> | ||
| 17 | #include <linux/sched.h> | ||
| 18 | #include <net/9p/9p.h> | ||
| 19 | #include <net/9p/client.h> | ||
| 20 | |||
| 21 | #include "fid.h" | ||
| 22 | #include "xattr.h" | ||
| 23 | |||
| 24 | /* | ||
| 25 | * v9fs_xattr_get() | ||
| 26 | * | ||
| 27 | * Copy an extended attribute into the buffer | ||
| 28 | * provided, or compute the buffer size required. | ||
| 29 | * Buffer is NULL to compute the size of the buffer required. | ||
| 30 | * | ||
| 31 | * Returns a negative error number on failure, or the number of bytes | ||
| 32 | * used / required on success. | ||
| 33 | */ | ||
| 34 | ssize_t v9fs_xattr_get(struct dentry *dentry, const char *name, | ||
| 35 | void *buffer, size_t buffer_size) | ||
| 36 | { | ||
| 37 | ssize_t retval; | ||
| 38 | int msize, read_count; | ||
| 39 | u64 offset = 0, attr_size; | ||
| 40 | struct p9_fid *fid, *attr_fid; | ||
| 41 | |||
| 42 | P9_DPRINTK(P9_DEBUG_VFS, "%s: name = %s value_len = %zu\n", | ||
| 43 | __func__, name, buffer_size); | ||
| 44 | |||
| 45 | fid = v9fs_fid_lookup(dentry); | ||
| 46 | if (IS_ERR(fid)) | ||
| 47 | return PTR_ERR(fid); | ||
| 48 | |||
| 49 | attr_fid = p9_client_xattrwalk(fid, name, &attr_size); | ||
| 50 | if (IS_ERR(attr_fid)) { | ||
| 51 | retval = PTR_ERR(attr_fid); | ||
| 52 | P9_DPRINTK(P9_DEBUG_VFS, | ||
| 53 | "p9_client_attrwalk failed %zd\n", retval); | ||
| 54 | attr_fid = NULL; | ||
| 55 | goto error; | ||
| 56 | } | ||
| 57 | if (!buffer_size) { | ||
| 58 | /* request to get the attr_size */ | ||
| 59 | retval = attr_size; | ||
| 60 | goto error; | ||
| 61 | } | ||
| 62 | if (attr_size > buffer_size) { | ||
| 63 | retval = -ERANGE; | ||
| 64 | goto error; | ||
| 65 | } | ||
| 66 | msize = attr_fid->clnt->msize; | ||
| 67 | while (attr_size) { | ||
| 68 | if (attr_size > (msize - P9_IOHDRSZ)) | ||
| 69 | read_count = msize - P9_IOHDRSZ; | ||
| 70 | else | ||
| 71 | read_count = attr_size; | ||
| 72 | read_count = p9_client_read(attr_fid, ((char *)buffer)+offset, | ||
| 73 | NULL, offset, read_count); | ||
| 74 | if (read_count < 0) { | ||
| 75 | /* error in xattr read */ | ||
| 76 | retval = read_count; | ||
| 77 | goto error; | ||
| 78 | } | ||
| 79 | offset += read_count; | ||
| 80 | attr_size -= read_count; | ||
| 81 | } | ||
| 82 | /* Total read xattr bytes */ | ||
| 83 | retval = offset; | ||
| 84 | error: | ||
| 85 | if (attr_fid) | ||
| 86 | p9_client_clunk(attr_fid); | ||
| 87 | return retval; | ||
| 88 | |||
| 89 | } | ||
| 90 | |||
| 91 | /* | ||
| 92 | * v9fs_xattr_set() | ||
| 93 | * | ||
| 94 | * Create, replace or remove an extended attribute for this inode. Buffer | ||
| 95 | * is NULL to remove an existing extended attribute, and non-NULL to | ||
| 96 | * either replace an existing extended attribute, or create a new extended | ||
| 97 | * attribute. The flags XATTR_REPLACE and XATTR_CREATE | ||
| 98 | * specify that an extended attribute must exist and must not exist | ||
| 99 | * previous to the call, respectively. | ||
| 100 | * | ||
| 101 | * Returns 0, or a negative error number on failure. | ||
| 102 | */ | ||
| 103 | int v9fs_xattr_set(struct dentry *dentry, const char *name, | ||
| 104 | const void *value, size_t value_len, int flags) | ||
| 105 | { | ||
| 106 | u64 offset = 0; | ||
| 107 | int retval, msize, write_count; | ||
| 108 | struct p9_fid *fid = NULL; | ||
| 109 | |||
| 110 | P9_DPRINTK(P9_DEBUG_VFS, "%s: name = %s value_len = %zu flags = %d\n", | ||
| 111 | __func__, name, value_len, flags); | ||
| 112 | |||
| 113 | fid = v9fs_fid_clone(dentry); | ||
| 114 | if (IS_ERR(fid)) { | ||
| 115 | retval = PTR_ERR(fid); | ||
| 116 | fid = NULL; | ||
| 117 | goto error; | ||
| 118 | } | ||
| 119 | /* | ||
| 120 | * On success fid points to xattr | ||
| 121 | */ | ||
| 122 | retval = p9_client_xattrcreate(fid, name, value_len, flags); | ||
| 123 | if (retval < 0) { | ||
| 124 | P9_DPRINTK(P9_DEBUG_VFS, | ||
| 125 | "p9_client_xattrcreate failed %d\n", retval); | ||
| 126 | goto error; | ||
| 127 | } | ||
| 128 | msize = fid->clnt->msize;; | ||
| 129 | while (value_len) { | ||
| 130 | if (value_len > (msize - P9_IOHDRSZ)) | ||
| 131 | write_count = msize - P9_IOHDRSZ; | ||
| 132 | else | ||
| 133 | write_count = value_len; | ||
| 134 | write_count = p9_client_write(fid, ((char *)value)+offset, | ||
| 135 | NULL, offset, write_count); | ||
| 136 | if (write_count < 0) { | ||
| 137 | /* error in xattr write */ | ||
| 138 | retval = write_count; | ||
| 139 | goto error; | ||
| 140 | } | ||
| 141 | offset += write_count; | ||
| 142 | value_len -= write_count; | ||
| 143 | } | ||
| 144 | /* Total read xattr bytes */ | ||
| 145 | retval = offset; | ||
| 146 | error: | ||
| 147 | if (fid) | ||
| 148 | retval = p9_client_clunk(fid); | ||
| 149 | return retval; | ||
| 150 | } | ||
| 151 | |||
| 152 | ssize_t v9fs_listxattr(struct dentry *dentry, char *buffer, size_t buffer_size) | ||
| 153 | { | ||
| 154 | return v9fs_xattr_get(dentry, NULL, buffer, buffer_size); | ||
| 155 | } | ||
| 156 | |||
| 157 | const struct xattr_handler *v9fs_xattr_handlers[] = { | ||
| 158 | &v9fs_xattr_user_handler, | ||
| 159 | NULL | ||
| 160 | }; | ||
diff --git a/fs/9p/xattr.h b/fs/9p/xattr.h new file mode 100644 index 000000000000..9ddf672ae5c4 --- /dev/null +++ b/fs/9p/xattr.h | |||
| @@ -0,0 +1,27 @@ | |||
| 1 | /* | ||
| 2 | * Copyright IBM Corporation, 2010 | ||
| 3 | * Author Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com> | ||
| 4 | * | ||
| 5 | * This program is free software; you can redistribute it and/or modify it | ||
| 6 | * under the terms of version 2.1 of the GNU Lesser General Public License | ||
| 7 | * as published by the Free Software Foundation. | ||
| 8 | * | ||
| 9 | * This program is distributed in the hope that it would be useful, but | ||
| 10 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
| 12 | * | ||
| 13 | */ | ||
| 14 | #ifndef FS_9P_XATTR_H | ||
| 15 | #define FS_9P_XATTR_H | ||
| 16 | |||
| 17 | #include <linux/xattr.h> | ||
| 18 | |||
| 19 | extern const struct xattr_handler *v9fs_xattr_handlers[]; | ||
| 20 | extern struct xattr_handler v9fs_xattr_user_handler; | ||
| 21 | |||
| 22 | extern ssize_t v9fs_xattr_get(struct dentry *, const char *, | ||
| 23 | void *, size_t); | ||
| 24 | extern int v9fs_xattr_set(struct dentry *, const char *, | ||
| 25 | const void *, size_t, int); | ||
| 26 | extern ssize_t v9fs_listxattr(struct dentry *, char *, size_t); | ||
| 27 | #endif /* FS_9P_XATTR_H */ | ||
diff --git a/fs/9p/xattr_user.c b/fs/9p/xattr_user.c new file mode 100644 index 000000000000..d0b701b72080 --- /dev/null +++ b/fs/9p/xattr_user.c | |||
| @@ -0,0 +1,80 @@ | |||
| 1 | /* | ||
| 2 | * Copyright IBM Corporation, 2010 | ||
| 3 | * Author Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com> | ||
| 4 | * | ||
| 5 | * This program is free software; you can redistribute it and/or modify it | ||
| 6 | * under the terms of version 2.1 of the GNU Lesser General Public License | ||
| 7 | * as published by the Free Software Foundation. | ||
| 8 | * | ||
| 9 | * This program is distributed in the hope that it would be useful, but | ||
| 10 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
| 12 | * | ||
| 13 | */ | ||
| 14 | |||
| 15 | |||
| 16 | #include <linux/module.h> | ||
| 17 | #include <linux/string.h> | ||
| 18 | #include <linux/fs.h> | ||
| 19 | #include <linux/slab.h> | ||
| 20 | #include "xattr.h" | ||
| 21 | |||
| 22 | static int v9fs_xattr_user_get(struct dentry *dentry, const char *name, | ||
| 23 | void *buffer, size_t size, int type) | ||
| 24 | { | ||
| 25 | int retval; | ||
| 26 | char *full_name; | ||
| 27 | size_t name_len; | ||
| 28 | size_t prefix_len = XATTR_USER_PREFIX_LEN; | ||
| 29 | |||
| 30 | if (name == NULL) | ||
| 31 | return -EINVAL; | ||
| 32 | |||
| 33 | if (strcmp(name, "") == 0) | ||
| 34 | return -EINVAL; | ||
| 35 | |||
| 36 | name_len = strlen(name); | ||
| 37 | full_name = kmalloc(prefix_len + name_len + 1 , GFP_KERNEL); | ||
| 38 | if (!full_name) | ||
| 39 | return -ENOMEM; | ||
| 40 | memcpy(full_name, XATTR_USER_PREFIX, prefix_len); | ||
| 41 | memcpy(full_name+prefix_len, name, name_len); | ||
| 42 | full_name[prefix_len + name_len] = '\0'; | ||
| 43 | |||
| 44 | retval = v9fs_xattr_get(dentry, full_name, buffer, size); | ||
| 45 | kfree(full_name); | ||
| 46 | return retval; | ||
| 47 | } | ||
| 48 | |||
| 49 | static int v9fs_xattr_user_set(struct dentry *dentry, const char *name, | ||
| 50 | const void *value, size_t size, int flags, int type) | ||
| 51 | { | ||
| 52 | int retval; | ||
| 53 | char *full_name; | ||
| 54 | size_t name_len; | ||
| 55 | size_t prefix_len = XATTR_USER_PREFIX_LEN; | ||
| 56 | |||
| 57 | if (name == NULL) | ||
| 58 | return -EINVAL; | ||
| 59 | |||
| 60 | if (strcmp(name, "") == 0) | ||
| 61 | return -EINVAL; | ||
| 62 | |||
| 63 | name_len = strlen(name); | ||
| 64 | full_name = kmalloc(prefix_len + name_len + 1 , GFP_KERNEL); | ||
| 65 | if (!full_name) | ||
| 66 | return -ENOMEM; | ||
| 67 | memcpy(full_name, XATTR_USER_PREFIX, prefix_len); | ||
| 68 | memcpy(full_name + prefix_len, name, name_len); | ||
| 69 | full_name[prefix_len + name_len] = '\0'; | ||
| 70 | |||
| 71 | retval = v9fs_xattr_set(dentry, full_name, value, size, flags); | ||
| 72 | kfree(full_name); | ||
| 73 | return retval; | ||
| 74 | } | ||
| 75 | |||
| 76 | struct xattr_handler v9fs_xattr_user_handler = { | ||
| 77 | .prefix = XATTR_USER_PREFIX, | ||
| 78 | .get = v9fs_xattr_user_get, | ||
| 79 | .set = v9fs_xattr_user_set, | ||
| 80 | }; | ||
diff --git a/include/linux/virtio_9p.h b/include/linux/virtio_9p.h index 5cf11765146b..395c38a47adb 100644 --- a/include/linux/virtio_9p.h +++ b/include/linux/virtio_9p.h | |||
| @@ -4,6 +4,7 @@ | |||
| 4 | * compatible drivers/servers. */ | 4 | * compatible drivers/servers. */ |
| 5 | #include <linux/virtio_ids.h> | 5 | #include <linux/virtio_ids.h> |
| 6 | #include <linux/virtio_config.h> | 6 | #include <linux/virtio_config.h> |
| 7 | #include <linux/types.h> | ||
| 7 | 8 | ||
| 8 | /* The feature bitmap for virtio 9P */ | 9 | /* The feature bitmap for virtio 9P */ |
| 9 | 10 | ||
diff --git a/include/net/9p/9p.h b/include/net/9p/9p.h index 156c26bb8bd7..a8de812ccbc8 100644 --- a/include/net/9p/9p.h +++ b/include/net/9p/9p.h | |||
| @@ -88,8 +88,16 @@ do { \ | |||
| 88 | * enum p9_msg_t - 9P message types | 88 | * enum p9_msg_t - 9P message types |
| 89 | * @P9_TSTATFS: file system status request | 89 | * @P9_TSTATFS: file system status request |
| 90 | * @P9_RSTATFS: file system status response | 90 | * @P9_RSTATFS: file system status response |
| 91 | * @P9_TSYMLINK: make symlink request | ||
| 92 | * @P9_RSYMLINK: make symlink response | ||
| 93 | * @P9_TMKNOD: create a special file object request | ||
| 94 | * @P9_RMKNOD: create a special file object response | ||
| 95 | * @P9_TLCREATE: prepare a handle for I/O on an new file for 9P2000.L | ||
| 96 | * @P9_RLCREATE: response with file access information for 9P2000.L | ||
| 91 | * @P9_TRENAME: rename request | 97 | * @P9_TRENAME: rename request |
| 92 | * @P9_RRENAME: rename response | 98 | * @P9_RRENAME: rename response |
| 99 | * @P9_TMKDIR: create a directory request | ||
| 100 | * @P9_RMKDIR: create a directory response | ||
| 93 | * @P9_TVERSION: version handshake request | 101 | * @P9_TVERSION: version handshake request |
| 94 | * @P9_RVERSION: version handshake response | 102 | * @P9_RVERSION: version handshake response |
| 95 | * @P9_TAUTH: request to establish authentication channel | 103 | * @P9_TAUTH: request to establish authentication channel |
| @@ -131,8 +139,30 @@ do { \ | |||
| 131 | enum p9_msg_t { | 139 | enum p9_msg_t { |
| 132 | P9_TSTATFS = 8, | 140 | P9_TSTATFS = 8, |
| 133 | P9_RSTATFS, | 141 | P9_RSTATFS, |
| 142 | P9_TLOPEN = 12, | ||
| 143 | P9_RLOPEN, | ||
| 144 | P9_TLCREATE = 14, | ||
| 145 | P9_RLCREATE, | ||
| 146 | P9_TSYMLINK = 16, | ||
| 147 | P9_RSYMLINK, | ||
| 148 | P9_TMKNOD = 18, | ||
| 149 | P9_RMKNOD, | ||
| 134 | P9_TRENAME = 20, | 150 | P9_TRENAME = 20, |
| 135 | P9_RRENAME, | 151 | P9_RRENAME, |
| 152 | P9_TGETATTR = 24, | ||
| 153 | P9_RGETATTR, | ||
| 154 | P9_TSETATTR = 26, | ||
| 155 | P9_RSETATTR, | ||
| 156 | P9_TXATTRWALK = 30, | ||
| 157 | P9_RXATTRWALK, | ||
| 158 | P9_TXATTRCREATE = 32, | ||
| 159 | P9_RXATTRCREATE, | ||
| 160 | P9_TREADDIR = 40, | ||
| 161 | P9_RREADDIR, | ||
| 162 | P9_TLINK = 70, | ||
| 163 | P9_RLINK, | ||
| 164 | P9_TMKDIR = 72, | ||
| 165 | P9_RMKDIR, | ||
| 136 | P9_TVERSION = 100, | 166 | P9_TVERSION = 100, |
| 137 | P9_RVERSION, | 167 | P9_RVERSION, |
| 138 | P9_TAUTH = 102, | 168 | P9_TAUTH = 102, |
| @@ -275,6 +305,9 @@ enum p9_qid_t { | |||
| 275 | /* ample room for Twrite/Rread header */ | 305 | /* ample room for Twrite/Rread header */ |
| 276 | #define P9_IOHDRSZ 24 | 306 | #define P9_IOHDRSZ 24 |
| 277 | 307 | ||
| 308 | /* Room for readdir header */ | ||
| 309 | #define P9_READDIRHDRSZ 24 | ||
| 310 | |||
| 278 | /** | 311 | /** |
| 279 | * struct p9_str - length prefixed string type | 312 | * struct p9_str - length prefixed string type |
| 280 | * @len: length of the string | 313 | * @len: length of the string |
| @@ -357,6 +390,74 @@ struct p9_wstat { | |||
| 357 | u32 n_muid; /* 9p2000.u extensions */ | 390 | u32 n_muid; /* 9p2000.u extensions */ |
| 358 | }; | 391 | }; |
| 359 | 392 | ||
| 393 | struct p9_stat_dotl { | ||
| 394 | u64 st_result_mask; | ||
| 395 | struct p9_qid qid; | ||
| 396 | u32 st_mode; | ||
| 397 | u32 st_uid; | ||
| 398 | u32 st_gid; | ||
| 399 | u64 st_nlink; | ||
| 400 | u64 st_rdev; | ||
| 401 | u64 st_size; | ||
| 402 | u64 st_blksize; | ||
| 403 | u64 st_blocks; | ||
| 404 | u64 st_atime_sec; | ||
| 405 | u64 st_atime_nsec; | ||
| 406 | u64 st_mtime_sec; | ||
| 407 | u64 st_mtime_nsec; | ||
| 408 | u64 st_ctime_sec; | ||
| 409 | u64 st_ctime_nsec; | ||
| 410 | u64 st_btime_sec; | ||
| 411 | u64 st_btime_nsec; | ||
| 412 | u64 st_gen; | ||
| 413 | u64 st_data_version; | ||
| 414 | }; | ||
| 415 | |||
| 416 | #define P9_STATS_MODE 0x00000001ULL | ||
| 417 | #define P9_STATS_NLINK 0x00000002ULL | ||
| 418 | #define P9_STATS_UID 0x00000004ULL | ||
| 419 | #define P9_STATS_GID 0x00000008ULL | ||
| 420 | #define P9_STATS_RDEV 0x00000010ULL | ||
| 421 | #define P9_STATS_ATIME 0x00000020ULL | ||
| 422 | #define P9_STATS_MTIME 0x00000040ULL | ||
| 423 | #define P9_STATS_CTIME 0x00000080ULL | ||
| 424 | #define P9_STATS_INO 0x00000100ULL | ||
| 425 | #define P9_STATS_SIZE 0x00000200ULL | ||
| 426 | #define P9_STATS_BLOCKS 0x00000400ULL | ||
| 427 | |||
| 428 | #define P9_STATS_BTIME 0x00000800ULL | ||
| 429 | #define P9_STATS_GEN 0x00001000ULL | ||
| 430 | #define P9_STATS_DATA_VERSION 0x00002000ULL | ||
| 431 | |||
| 432 | #define P9_STATS_BASIC 0x000007ffULL /* Mask for fields up to BLOCKS */ | ||
| 433 | #define P9_STATS_ALL 0x00003fffULL /* Mask for All fields above */ | ||
| 434 | |||
| 435 | /** | ||
| 436 | * struct p9_iattr_dotl - P9 inode attribute for setattr | ||
| 437 | * @valid: bitfield specifying which fields are valid | ||
| 438 | * same as in struct iattr | ||
| 439 | * @mode: File permission bits | ||
| 440 | * @uid: user id of owner | ||
| 441 | * @gid: group id | ||
| 442 | * @size: File size | ||
| 443 | * @atime_sec: Last access time, seconds | ||
| 444 | * @atime_nsec: Last access time, nanoseconds | ||
| 445 | * @mtime_sec: Last modification time, seconds | ||
| 446 | * @mtime_nsec: Last modification time, nanoseconds | ||
| 447 | */ | ||
| 448 | |||
| 449 | struct p9_iattr_dotl { | ||
| 450 | u32 valid; | ||
| 451 | u32 mode; | ||
| 452 | u32 uid; | ||
| 453 | u32 gid; | ||
| 454 | u64 size; | ||
| 455 | u64 atime_sec; | ||
| 456 | u64 atime_nsec; | ||
| 457 | u64 mtime_sec; | ||
| 458 | u64 mtime_nsec; | ||
| 459 | }; | ||
| 460 | |||
| 360 | /* Structures for Protocol Operations */ | 461 | /* Structures for Protocol Operations */ |
| 361 | struct p9_tstatfs { | 462 | struct p9_tstatfs { |
| 362 | u32 fid; | 463 | u32 fid; |
| @@ -485,6 +586,18 @@ struct p9_rwrite { | |||
| 485 | u32 count; | 586 | u32 count; |
| 486 | }; | 587 | }; |
| 487 | 588 | ||
| 589 | struct p9_treaddir { | ||
| 590 | u32 fid; | ||
| 591 | u64 offset; | ||
| 592 | u32 count; | ||
| 593 | }; | ||
| 594 | |||
| 595 | struct p9_rreaddir { | ||
| 596 | u32 count; | ||
| 597 | u8 *data; | ||
| 598 | }; | ||
| 599 | |||
| 600 | |||
| 488 | struct p9_tclunk { | 601 | struct p9_tclunk { |
| 489 | u32 fid; | 602 | u32 fid; |
| 490 | }; | 603 | }; |
diff --git a/include/net/9p/client.h b/include/net/9p/client.h index 7dd3ed85c782..d1aa2cfb30f0 100644 --- a/include/net/9p/client.h +++ b/include/net/9p/client.h | |||
| @@ -195,6 +195,21 @@ struct p9_fid { | |||
| 195 | struct list_head dlist; /* list of all fids attached to a dentry */ | 195 | struct list_head dlist; /* list of all fids attached to a dentry */ |
| 196 | }; | 196 | }; |
| 197 | 197 | ||
| 198 | /** | ||
| 199 | * struct p9_dirent - directory entry structure | ||
| 200 | * @qid: The p9 server qid for this dirent | ||
| 201 | * @d_off: offset to the next dirent | ||
| 202 | * @d_type: type of file | ||
| 203 | * @d_name: file name | ||
| 204 | */ | ||
| 205 | |||
| 206 | struct p9_dirent { | ||
| 207 | struct p9_qid qid; | ||
| 208 | u64 d_off; | ||
| 209 | unsigned char d_type; | ||
| 210 | char d_name[256]; | ||
| 211 | }; | ||
| 212 | |||
| 198 | int p9_client_statfs(struct p9_fid *fid, struct p9_rstatfs *sb); | 213 | int p9_client_statfs(struct p9_fid *fid, struct p9_rstatfs *sb); |
| 199 | int p9_client_rename(struct p9_fid *fid, struct p9_fid *newdirfid, char *name); | 214 | int p9_client_rename(struct p9_fid *fid, struct p9_fid *newdirfid, char *name); |
| 200 | int p9_client_version(struct p9_client *); | 215 | int p9_client_version(struct p9_client *); |
| @@ -211,15 +226,31 @@ struct p9_fid *p9_client_walk(struct p9_fid *oldfid, int nwname, char **wnames, | |||
| 211 | int p9_client_open(struct p9_fid *fid, int mode); | 226 | int p9_client_open(struct p9_fid *fid, int mode); |
| 212 | int p9_client_fcreate(struct p9_fid *fid, char *name, u32 perm, int mode, | 227 | int p9_client_fcreate(struct p9_fid *fid, char *name, u32 perm, int mode, |
| 213 | char *extension); | 228 | char *extension); |
| 229 | int p9_client_link(struct p9_fid *fid, struct p9_fid *oldfid, char *newname); | ||
| 230 | int p9_client_symlink(struct p9_fid *fid, char *name, char *symname, gid_t gid, | ||
| 231 | struct p9_qid *qid); | ||
| 232 | int p9_client_create_dotl(struct p9_fid *ofid, char *name, u32 flags, u32 mode, | ||
| 233 | gid_t gid, struct p9_qid *qid); | ||
| 214 | int p9_client_clunk(struct p9_fid *fid); | 234 | int p9_client_clunk(struct p9_fid *fid); |
| 215 | int p9_client_remove(struct p9_fid *fid); | 235 | int p9_client_remove(struct p9_fid *fid); |
| 216 | int p9_client_read(struct p9_fid *fid, char *data, char __user *udata, | 236 | int p9_client_read(struct p9_fid *fid, char *data, char __user *udata, |
| 217 | u64 offset, u32 count); | 237 | u64 offset, u32 count); |
| 218 | int p9_client_write(struct p9_fid *fid, char *data, const char __user *udata, | 238 | int p9_client_write(struct p9_fid *fid, char *data, const char __user *udata, |
| 219 | u64 offset, u32 count); | 239 | u64 offset, u32 count); |
| 240 | int p9_client_readdir(struct p9_fid *fid, char *data, u32 count, u64 offset); | ||
| 241 | int p9dirent_read(char *buf, int len, struct p9_dirent *dirent, | ||
| 242 | int proto_version); | ||
| 220 | struct p9_wstat *p9_client_stat(struct p9_fid *fid); | 243 | struct p9_wstat *p9_client_stat(struct p9_fid *fid); |
| 221 | int p9_client_wstat(struct p9_fid *fid, struct p9_wstat *wst); | 244 | int p9_client_wstat(struct p9_fid *fid, struct p9_wstat *wst); |
| 245 | int p9_client_setattr(struct p9_fid *fid, struct p9_iattr_dotl *attr); | ||
| 246 | |||
| 247 | struct p9_stat_dotl *p9_client_getattr_dotl(struct p9_fid *fid, | ||
| 248 | u64 request_mask); | ||
| 222 | 249 | ||
| 250 | int p9_client_mknod_dotl(struct p9_fid *oldfid, char *name, int mode, | ||
| 251 | dev_t rdev, gid_t gid, struct p9_qid *); | ||
| 252 | int p9_client_mkdir_dotl(struct p9_fid *fid, char *name, int mode, | ||
| 253 | gid_t gid, struct p9_qid *); | ||
| 223 | struct p9_req_t *p9_tag_lookup(struct p9_client *, u16); | 254 | struct p9_req_t *p9_tag_lookup(struct p9_client *, u16); |
| 224 | void p9_client_cb(struct p9_client *c, struct p9_req_t *req); | 255 | void p9_client_cb(struct p9_client *c, struct p9_req_t *req); |
| 225 | 256 | ||
| @@ -229,5 +260,7 @@ void p9stat_free(struct p9_wstat *); | |||
| 229 | 260 | ||
| 230 | int p9_is_proto_dotu(struct p9_client *clnt); | 261 | int p9_is_proto_dotu(struct p9_client *clnt); |
| 231 | int p9_is_proto_dotl(struct p9_client *clnt); | 262 | int p9_is_proto_dotl(struct p9_client *clnt); |
| 263 | struct p9_fid *p9_client_xattrwalk(struct p9_fid *, const char *, u64 *); | ||
| 264 | int p9_client_xattrcreate(struct p9_fid *, const char *, u64, int); | ||
| 232 | 265 | ||
| 233 | #endif /* NET_9P_CLIENT_H */ | 266 | #endif /* NET_9P_CLIENT_H */ |
diff --git a/net/9p/client.c b/net/9p/client.c index 37c8da07a80b..dc6f2f26d023 100644 --- a/net/9p/client.c +++ b/net/9p/client.c | |||
| @@ -460,7 +460,8 @@ static int p9_check_errors(struct p9_client *c, struct p9_req_t *req) | |||
| 460 | return err; | 460 | return err; |
| 461 | } | 461 | } |
| 462 | 462 | ||
| 463 | if (p9_is_proto_dotu(c)) | 463 | if (p9_is_proto_dotu(c) || |
| 464 | p9_is_proto_dotl(c)) | ||
| 464 | err = -ecode; | 465 | err = -ecode; |
| 465 | 466 | ||
| 466 | if (!err || !IS_ERR_VALUE(err)) | 467 | if (!err || !IS_ERR_VALUE(err)) |
| @@ -1015,14 +1016,18 @@ int p9_client_open(struct p9_fid *fid, int mode) | |||
| 1015 | struct p9_qid qid; | 1016 | struct p9_qid qid; |
| 1016 | int iounit; | 1017 | int iounit; |
| 1017 | 1018 | ||
| 1018 | P9_DPRINTK(P9_DEBUG_9P, ">>> TOPEN fid %d mode %d\n", fid->fid, mode); | ||
| 1019 | err = 0; | ||
| 1020 | clnt = fid->clnt; | 1019 | clnt = fid->clnt; |
| 1020 | P9_DPRINTK(P9_DEBUG_9P, ">>> %s fid %d mode %d\n", | ||
| 1021 | p9_is_proto_dotl(clnt) ? "TLOPEN" : "TOPEN", fid->fid, mode); | ||
| 1022 | err = 0; | ||
| 1021 | 1023 | ||
| 1022 | if (fid->mode != -1) | 1024 | if (fid->mode != -1) |
| 1023 | return -EINVAL; | 1025 | return -EINVAL; |
| 1024 | 1026 | ||
| 1025 | req = p9_client_rpc(clnt, P9_TOPEN, "db", fid->fid, mode); | 1027 | if (p9_is_proto_dotl(clnt)) |
| 1028 | req = p9_client_rpc(clnt, P9_TLOPEN, "dd", fid->fid, mode); | ||
| 1029 | else | ||
| 1030 | req = p9_client_rpc(clnt, P9_TOPEN, "db", fid->fid, mode); | ||
| 1026 | if (IS_ERR(req)) { | 1031 | if (IS_ERR(req)) { |
| 1027 | err = PTR_ERR(req); | 1032 | err = PTR_ERR(req); |
| 1028 | goto error; | 1033 | goto error; |
| @@ -1034,10 +1039,9 @@ int p9_client_open(struct p9_fid *fid, int mode) | |||
| 1034 | goto free_and_error; | 1039 | goto free_and_error; |
| 1035 | } | 1040 | } |
| 1036 | 1041 | ||
| 1037 | P9_DPRINTK(P9_DEBUG_9P, "<<< ROPEN qid %x.%llx.%x iounit %x\n", | 1042 | P9_DPRINTK(P9_DEBUG_9P, "<<< %s qid %x.%llx.%x iounit %x\n", |
| 1038 | qid.type, | 1043 | p9_is_proto_dotl(clnt) ? "RLOPEN" : "ROPEN", qid.type, |
| 1039 | (unsigned long long)qid.path, | 1044 | (unsigned long long)qid.path, qid.version, iounit); |
| 1040 | qid.version, iounit); | ||
| 1041 | 1045 | ||
| 1042 | fid->mode = mode; | 1046 | fid->mode = mode; |
| 1043 | fid->iounit = iounit; | 1047 | fid->iounit = iounit; |
| @@ -1049,6 +1053,50 @@ error: | |||
| 1049 | } | 1053 | } |
| 1050 | EXPORT_SYMBOL(p9_client_open); | 1054 | EXPORT_SYMBOL(p9_client_open); |
| 1051 | 1055 | ||
| 1056 | int p9_client_create_dotl(struct p9_fid *ofid, char *name, u32 flags, u32 mode, | ||
| 1057 | gid_t gid, struct p9_qid *qid) | ||
| 1058 | { | ||
| 1059 | int err = 0; | ||
| 1060 | struct p9_client *clnt; | ||
| 1061 | struct p9_req_t *req; | ||
| 1062 | int iounit; | ||
| 1063 | |||
| 1064 | P9_DPRINTK(P9_DEBUG_9P, | ||
| 1065 | ">>> TLCREATE fid %d name %s flags %d mode %d gid %d\n", | ||
| 1066 | ofid->fid, name, flags, mode, gid); | ||
| 1067 | clnt = ofid->clnt; | ||
| 1068 | |||
| 1069 | if (ofid->mode != -1) | ||
| 1070 | return -EINVAL; | ||
| 1071 | |||
| 1072 | req = p9_client_rpc(clnt, P9_TLCREATE, "dsddd", ofid->fid, name, flags, | ||
| 1073 | mode, gid); | ||
| 1074 | if (IS_ERR(req)) { | ||
| 1075 | err = PTR_ERR(req); | ||
| 1076 | goto error; | ||
| 1077 | } | ||
| 1078 | |||
| 1079 | err = p9pdu_readf(req->rc, clnt->proto_version, "Qd", qid, &iounit); | ||
| 1080 | if (err) { | ||
| 1081 | p9pdu_dump(1, req->rc); | ||
| 1082 | goto free_and_error; | ||
| 1083 | } | ||
| 1084 | |||
| 1085 | P9_DPRINTK(P9_DEBUG_9P, "<<< RLCREATE qid %x.%llx.%x iounit %x\n", | ||
| 1086 | qid->type, | ||
| 1087 | (unsigned long long)qid->path, | ||
| 1088 | qid->version, iounit); | ||
| 1089 | |||
| 1090 | ofid->mode = mode; | ||
| 1091 | ofid->iounit = iounit; | ||
| 1092 | |||
| 1093 | free_and_error: | ||
| 1094 | p9_free_req(clnt, req); | ||
| 1095 | error: | ||
| 1096 | return err; | ||
| 1097 | } | ||
| 1098 | EXPORT_SYMBOL(p9_client_create_dotl); | ||
| 1099 | |||
| 1052 | int p9_client_fcreate(struct p9_fid *fid, char *name, u32 perm, int mode, | 1100 | int p9_client_fcreate(struct p9_fid *fid, char *name, u32 perm, int mode, |
| 1053 | char *extension) | 1101 | char *extension) |
| 1054 | { | 1102 | { |
| @@ -1094,6 +1142,59 @@ error: | |||
| 1094 | } | 1142 | } |
| 1095 | EXPORT_SYMBOL(p9_client_fcreate); | 1143 | EXPORT_SYMBOL(p9_client_fcreate); |
| 1096 | 1144 | ||
| 1145 | int p9_client_symlink(struct p9_fid *dfid, char *name, char *symtgt, gid_t gid, | ||
| 1146 | struct p9_qid *qid) | ||
| 1147 | { | ||
| 1148 | int err = 0; | ||
| 1149 | struct p9_client *clnt; | ||
| 1150 | struct p9_req_t *req; | ||
| 1151 | |||
| 1152 | P9_DPRINTK(P9_DEBUG_9P, ">>> TSYMLINK dfid %d name %s symtgt %s\n", | ||
| 1153 | dfid->fid, name, symtgt); | ||
| 1154 | clnt = dfid->clnt; | ||
| 1155 | |||
| 1156 | req = p9_client_rpc(clnt, P9_TSYMLINK, "dssd", dfid->fid, name, symtgt, | ||
| 1157 | gid); | ||
| 1158 | if (IS_ERR(req)) { | ||
| 1159 | err = PTR_ERR(req); | ||
| 1160 | goto error; | ||
| 1161 | } | ||
| 1162 | |||
| 1163 | err = p9pdu_readf(req->rc, clnt->proto_version, "Q", qid); | ||
| 1164 | if (err) { | ||
| 1165 | p9pdu_dump(1, req->rc); | ||
| 1166 | goto free_and_error; | ||
| 1167 | } | ||
| 1168 | |||
| 1169 | P9_DPRINTK(P9_DEBUG_9P, "<<< RSYMLINK qid %x.%llx.%x\n", | ||
| 1170 | qid->type, (unsigned long long)qid->path, qid->version); | ||
| 1171 | |||
| 1172 | free_and_error: | ||
| 1173 | p9_free_req(clnt, req); | ||
| 1174 | error: | ||
| 1175 | return err; | ||
| 1176 | } | ||
| 1177 | EXPORT_SYMBOL(p9_client_symlink); | ||
| 1178 | |||
| 1179 | int p9_client_link(struct p9_fid *dfid, struct p9_fid *oldfid, char *newname) | ||
| 1180 | { | ||
| 1181 | struct p9_client *clnt; | ||
| 1182 | struct p9_req_t *req; | ||
| 1183 | |||
| 1184 | P9_DPRINTK(P9_DEBUG_9P, ">>> TLINK dfid %d oldfid %d newname %s\n", | ||
| 1185 | dfid->fid, oldfid->fid, newname); | ||
| 1186 | clnt = dfid->clnt; | ||
| 1187 | req = p9_client_rpc(clnt, P9_TLINK, "dds", dfid->fid, oldfid->fid, | ||
| 1188 | newname); | ||
| 1189 | if (IS_ERR(req)) | ||
| 1190 | return PTR_ERR(req); | ||
| 1191 | |||
| 1192 | P9_DPRINTK(P9_DEBUG_9P, "<<< RLINK\n"); | ||
| 1193 | p9_free_req(clnt, req); | ||
| 1194 | return 0; | ||
| 1195 | } | ||
| 1196 | EXPORT_SYMBOL(p9_client_link); | ||
| 1197 | |||
| 1097 | int p9_client_clunk(struct p9_fid *fid) | 1198 | int p9_client_clunk(struct p9_fid *fid) |
| 1098 | { | 1199 | { |
| 1099 | int err; | 1200 | int err; |
| @@ -1139,9 +1240,8 @@ int p9_client_remove(struct p9_fid *fid) | |||
| 1139 | P9_DPRINTK(P9_DEBUG_9P, "<<< RREMOVE fid %d\n", fid->fid); | 1240 | P9_DPRINTK(P9_DEBUG_9P, "<<< RREMOVE fid %d\n", fid->fid); |
| 1140 | 1241 | ||
| 1141 | p9_free_req(clnt, req); | 1242 | p9_free_req(clnt, req); |
| 1142 | p9_fid_destroy(fid); | ||
| 1143 | |||
| 1144 | error: | 1243 | error: |
| 1244 | p9_fid_destroy(fid); | ||
| 1145 | return err; | 1245 | return err; |
| 1146 | } | 1246 | } |
| 1147 | EXPORT_SYMBOL(p9_client_remove); | 1247 | EXPORT_SYMBOL(p9_client_remove); |
| @@ -1302,6 +1402,65 @@ error: | |||
| 1302 | } | 1402 | } |
| 1303 | EXPORT_SYMBOL(p9_client_stat); | 1403 | EXPORT_SYMBOL(p9_client_stat); |
| 1304 | 1404 | ||
| 1405 | struct p9_stat_dotl *p9_client_getattr_dotl(struct p9_fid *fid, | ||
| 1406 | u64 request_mask) | ||
| 1407 | { | ||
| 1408 | int err; | ||
| 1409 | struct p9_client *clnt; | ||
| 1410 | struct p9_stat_dotl *ret = kmalloc(sizeof(struct p9_stat_dotl), | ||
| 1411 | GFP_KERNEL); | ||
| 1412 | struct p9_req_t *req; | ||
| 1413 | |||
| 1414 | P9_DPRINTK(P9_DEBUG_9P, ">>> TGETATTR fid %d, request_mask %lld\n", | ||
| 1415 | fid->fid, request_mask); | ||
| 1416 | |||
| 1417 | if (!ret) | ||
| 1418 | return ERR_PTR(-ENOMEM); | ||
| 1419 | |||
| 1420 | err = 0; | ||
| 1421 | clnt = fid->clnt; | ||
| 1422 | |||
| 1423 | req = p9_client_rpc(clnt, P9_TGETATTR, "dq", fid->fid, request_mask); | ||
| 1424 | if (IS_ERR(req)) { | ||
| 1425 | err = PTR_ERR(req); | ||
| 1426 | goto error; | ||
| 1427 | } | ||
| 1428 | |||
| 1429 | err = p9pdu_readf(req->rc, clnt->proto_version, "A", ret); | ||
| 1430 | if (err) { | ||
| 1431 | p9pdu_dump(1, req->rc); | ||
| 1432 | p9_free_req(clnt, req); | ||
| 1433 | goto error; | ||
| 1434 | } | ||
| 1435 | |||
| 1436 | P9_DPRINTK(P9_DEBUG_9P, | ||
| 1437 | "<<< RGETATTR st_result_mask=%lld\n" | ||
| 1438 | "<<< qid=%x.%llx.%x\n" | ||
| 1439 | "<<< st_mode=%8.8x st_nlink=%llu\n" | ||
| 1440 | "<<< st_uid=%d st_gid=%d\n" | ||
| 1441 | "<<< st_rdev=%llx st_size=%llx st_blksize=%llu st_blocks=%llu\n" | ||
| 1442 | "<<< st_atime_sec=%lld st_atime_nsec=%lld\n" | ||
| 1443 | "<<< st_mtime_sec=%lld st_mtime_nsec=%lld\n" | ||
| 1444 | "<<< st_ctime_sec=%lld st_ctime_nsec=%lld\n" | ||
| 1445 | "<<< st_btime_sec=%lld st_btime_nsec=%lld\n" | ||
| 1446 | "<<< st_gen=%lld st_data_version=%lld", | ||
| 1447 | ret->st_result_mask, ret->qid.type, ret->qid.path, | ||
| 1448 | ret->qid.version, ret->st_mode, ret->st_nlink, ret->st_uid, | ||
| 1449 | ret->st_gid, ret->st_rdev, ret->st_size, ret->st_blksize, | ||
| 1450 | ret->st_blocks, ret->st_atime_sec, ret->st_atime_nsec, | ||
| 1451 | ret->st_mtime_sec, ret->st_mtime_nsec, ret->st_ctime_sec, | ||
| 1452 | ret->st_ctime_nsec, ret->st_btime_sec, ret->st_btime_nsec, | ||
| 1453 | ret->st_gen, ret->st_data_version); | ||
| 1454 | |||
| 1455 | p9_free_req(clnt, req); | ||
| 1456 | return ret; | ||
| 1457 | |||
| 1458 | error: | ||
| 1459 | kfree(ret); | ||
| 1460 | return ERR_PTR(err); | ||
| 1461 | } | ||
| 1462 | EXPORT_SYMBOL(p9_client_getattr_dotl); | ||
| 1463 | |||
| 1305 | static int p9_client_statsize(struct p9_wstat *wst, int proto_version) | 1464 | static int p9_client_statsize(struct p9_wstat *wst, int proto_version) |
| 1306 | { | 1465 | { |
| 1307 | int ret; | 1466 | int ret; |
| @@ -1366,6 +1525,36 @@ error: | |||
| 1366 | } | 1525 | } |
| 1367 | EXPORT_SYMBOL(p9_client_wstat); | 1526 | EXPORT_SYMBOL(p9_client_wstat); |
| 1368 | 1527 | ||
| 1528 | int p9_client_setattr(struct p9_fid *fid, struct p9_iattr_dotl *p9attr) | ||
| 1529 | { | ||
| 1530 | int err; | ||
| 1531 | struct p9_req_t *req; | ||
| 1532 | struct p9_client *clnt; | ||
| 1533 | |||
| 1534 | err = 0; | ||
| 1535 | clnt = fid->clnt; | ||
| 1536 | P9_DPRINTK(P9_DEBUG_9P, ">>> TSETATTR fid %d\n", fid->fid); | ||
| 1537 | P9_DPRINTK(P9_DEBUG_9P, | ||
| 1538 | " valid=%x mode=%x uid=%d gid=%d size=%lld\n" | ||
| 1539 | " atime_sec=%lld atime_nsec=%lld\n" | ||
| 1540 | " mtime_sec=%lld mtime_nsec=%lld\n", | ||
| 1541 | p9attr->valid, p9attr->mode, p9attr->uid, p9attr->gid, | ||
| 1542 | p9attr->size, p9attr->atime_sec, p9attr->atime_nsec, | ||
| 1543 | p9attr->mtime_sec, p9attr->mtime_nsec); | ||
| 1544 | |||
| 1545 | req = p9_client_rpc(clnt, P9_TSETATTR, "dI", fid->fid, p9attr); | ||
| 1546 | |||
| 1547 | if (IS_ERR(req)) { | ||
| 1548 | err = PTR_ERR(req); | ||
| 1549 | goto error; | ||
| 1550 | } | ||
| 1551 | P9_DPRINTK(P9_DEBUG_9P, "<<< RSETATTR fid %d\n", fid->fid); | ||
| 1552 | p9_free_req(clnt, req); | ||
| 1553 | error: | ||
| 1554 | return err; | ||
| 1555 | } | ||
| 1556 | EXPORT_SYMBOL(p9_client_setattr); | ||
| 1557 | |||
| 1369 | int p9_client_statfs(struct p9_fid *fid, struct p9_rstatfs *sb) | 1558 | int p9_client_statfs(struct p9_fid *fid, struct p9_rstatfs *sb) |
| 1370 | { | 1559 | { |
| 1371 | int err; | 1560 | int err; |
| @@ -1432,3 +1621,187 @@ error: | |||
| 1432 | } | 1621 | } |
| 1433 | EXPORT_SYMBOL(p9_client_rename); | 1622 | EXPORT_SYMBOL(p9_client_rename); |
| 1434 | 1623 | ||
| 1624 | /* | ||
| 1625 | * An xattrwalk without @attr_name gives the fid for the lisxattr namespace | ||
| 1626 | */ | ||
| 1627 | struct p9_fid *p9_client_xattrwalk(struct p9_fid *file_fid, | ||
| 1628 | const char *attr_name, u64 *attr_size) | ||
| 1629 | { | ||
| 1630 | int err; | ||
| 1631 | struct p9_req_t *req; | ||
| 1632 | struct p9_client *clnt; | ||
| 1633 | struct p9_fid *attr_fid; | ||
| 1634 | |||
| 1635 | err = 0; | ||
| 1636 | clnt = file_fid->clnt; | ||
| 1637 | attr_fid = p9_fid_create(clnt); | ||
| 1638 | if (IS_ERR(attr_fid)) { | ||
| 1639 | err = PTR_ERR(attr_fid); | ||
| 1640 | attr_fid = NULL; | ||
| 1641 | goto error; | ||
| 1642 | } | ||
| 1643 | P9_DPRINTK(P9_DEBUG_9P, | ||
| 1644 | ">>> TXATTRWALK file_fid %d, attr_fid %d name %s\n", | ||
| 1645 | file_fid->fid, attr_fid->fid, attr_name); | ||
| 1646 | |||
| 1647 | req = p9_client_rpc(clnt, P9_TXATTRWALK, "dds", | ||
| 1648 | file_fid->fid, attr_fid->fid, attr_name); | ||
| 1649 | if (IS_ERR(req)) { | ||
| 1650 | err = PTR_ERR(req); | ||
| 1651 | goto error; | ||
| 1652 | } | ||
| 1653 | err = p9pdu_readf(req->rc, clnt->proto_version, "q", attr_size); | ||
| 1654 | if (err) { | ||
| 1655 | p9pdu_dump(1, req->rc); | ||
| 1656 | p9_free_req(clnt, req); | ||
| 1657 | goto clunk_fid; | ||
| 1658 | } | ||
| 1659 | p9_free_req(clnt, req); | ||
| 1660 | P9_DPRINTK(P9_DEBUG_9P, "<<< RXATTRWALK fid %d size %llu\n", | ||
| 1661 | attr_fid->fid, *attr_size); | ||
| 1662 | return attr_fid; | ||
| 1663 | clunk_fid: | ||
| 1664 | p9_client_clunk(attr_fid); | ||
| 1665 | attr_fid = NULL; | ||
| 1666 | error: | ||
| 1667 | if (attr_fid && (attr_fid != file_fid)) | ||
| 1668 | p9_fid_destroy(attr_fid); | ||
| 1669 | |||
| 1670 | return ERR_PTR(err); | ||
| 1671 | } | ||
| 1672 | EXPORT_SYMBOL_GPL(p9_client_xattrwalk); | ||
| 1673 | |||
| 1674 | int p9_client_xattrcreate(struct p9_fid *fid, const char *name, | ||
| 1675 | u64 attr_size, int flags) | ||
| 1676 | { | ||
| 1677 | int err; | ||
| 1678 | struct p9_req_t *req; | ||
| 1679 | struct p9_client *clnt; | ||
| 1680 | |||
| 1681 | P9_DPRINTK(P9_DEBUG_9P, | ||
| 1682 | ">>> TXATTRCREATE fid %d name %s size %lld flag %d\n", | ||
| 1683 | fid->fid, name, (long long)attr_size, flags); | ||
| 1684 | err = 0; | ||
| 1685 | clnt = fid->clnt; | ||
| 1686 | req = p9_client_rpc(clnt, P9_TXATTRCREATE, "dsqd", | ||
| 1687 | fid->fid, name, attr_size, flags); | ||
| 1688 | if (IS_ERR(req)) { | ||
| 1689 | err = PTR_ERR(req); | ||
| 1690 | goto error; | ||
| 1691 | } | ||
| 1692 | P9_DPRINTK(P9_DEBUG_9P, "<<< RXATTRCREATE fid %d\n", fid->fid); | ||
| 1693 | p9_free_req(clnt, req); | ||
| 1694 | error: | ||
| 1695 | return err; | ||
| 1696 | } | ||
| 1697 | EXPORT_SYMBOL_GPL(p9_client_xattrcreate); | ||
| 1698 | |||
| 1699 | int p9_client_readdir(struct p9_fid *fid, char *data, u32 count, u64 offset) | ||
| 1700 | { | ||
| 1701 | int err, rsize, total; | ||
| 1702 | struct p9_client *clnt; | ||
| 1703 | struct p9_req_t *req; | ||
| 1704 | char *dataptr; | ||
| 1705 | |||
| 1706 | P9_DPRINTK(P9_DEBUG_9P, ">>> TREADDIR fid %d offset %llu count %d\n", | ||
| 1707 | fid->fid, (long long unsigned) offset, count); | ||
| 1708 | |||
| 1709 | err = 0; | ||
| 1710 | clnt = fid->clnt; | ||
| 1711 | total = 0; | ||
| 1712 | |||
| 1713 | rsize = fid->iounit; | ||
| 1714 | if (!rsize || rsize > clnt->msize-P9_READDIRHDRSZ) | ||
| 1715 | rsize = clnt->msize - P9_READDIRHDRSZ; | ||
| 1716 | |||
| 1717 | if (count < rsize) | ||
| 1718 | rsize = count; | ||
| 1719 | |||
| 1720 | req = p9_client_rpc(clnt, P9_TREADDIR, "dqd", fid->fid, offset, rsize); | ||
| 1721 | if (IS_ERR(req)) { | ||
| 1722 | err = PTR_ERR(req); | ||
| 1723 | goto error; | ||
| 1724 | } | ||
| 1725 | |||
| 1726 | err = p9pdu_readf(req->rc, clnt->proto_version, "D", &count, &dataptr); | ||
| 1727 | if (err) { | ||
| 1728 | p9pdu_dump(1, req->rc); | ||
| 1729 | goto free_and_error; | ||
| 1730 | } | ||
| 1731 | |||
| 1732 | P9_DPRINTK(P9_DEBUG_9P, "<<< RREADDIR count %d\n", count); | ||
| 1733 | |||
| 1734 | if (data) | ||
| 1735 | memmove(data, dataptr, count); | ||
| 1736 | |||
| 1737 | p9_free_req(clnt, req); | ||
| 1738 | return count; | ||
| 1739 | |||
| 1740 | free_and_error: | ||
| 1741 | p9_free_req(clnt, req); | ||
| 1742 | error: | ||
| 1743 | return err; | ||
| 1744 | } | ||
| 1745 | EXPORT_SYMBOL(p9_client_readdir); | ||
| 1746 | |||
| 1747 | int p9_client_mknod_dotl(struct p9_fid *fid, char *name, int mode, | ||
| 1748 | dev_t rdev, gid_t gid, struct p9_qid *qid) | ||
| 1749 | { | ||
| 1750 | int err; | ||
| 1751 | struct p9_client *clnt; | ||
| 1752 | struct p9_req_t *req; | ||
| 1753 | |||
| 1754 | err = 0; | ||
| 1755 | clnt = fid->clnt; | ||
| 1756 | P9_DPRINTK(P9_DEBUG_9P, ">>> TMKNOD fid %d name %s mode %d major %d " | ||
| 1757 | "minor %d\n", fid->fid, name, mode, MAJOR(rdev), MINOR(rdev)); | ||
| 1758 | req = p9_client_rpc(clnt, P9_TMKNOD, "dsdddd", fid->fid, name, mode, | ||
| 1759 | MAJOR(rdev), MINOR(rdev), gid); | ||
| 1760 | if (IS_ERR(req)) | ||
| 1761 | return PTR_ERR(req); | ||
| 1762 | |||
| 1763 | err = p9pdu_readf(req->rc, clnt->proto_version, "Q", qid); | ||
| 1764 | if (err) { | ||
| 1765 | p9pdu_dump(1, req->rc); | ||
| 1766 | goto error; | ||
| 1767 | } | ||
| 1768 | P9_DPRINTK(P9_DEBUG_9P, "<<< RMKNOD qid %x.%llx.%x\n", qid->type, | ||
| 1769 | (unsigned long long)qid->path, qid->version); | ||
| 1770 | |||
| 1771 | error: | ||
| 1772 | p9_free_req(clnt, req); | ||
| 1773 | return err; | ||
| 1774 | |||
| 1775 | } | ||
| 1776 | EXPORT_SYMBOL(p9_client_mknod_dotl); | ||
| 1777 | |||
| 1778 | int p9_client_mkdir_dotl(struct p9_fid *fid, char *name, int mode, | ||
| 1779 | gid_t gid, struct p9_qid *qid) | ||
| 1780 | { | ||
| 1781 | int err; | ||
| 1782 | struct p9_client *clnt; | ||
| 1783 | struct p9_req_t *req; | ||
| 1784 | |||
| 1785 | err = 0; | ||
| 1786 | clnt = fid->clnt; | ||
| 1787 | P9_DPRINTK(P9_DEBUG_9P, ">>> TMKDIR fid %d name %s mode %d gid %d\n", | ||
| 1788 | fid->fid, name, mode, gid); | ||
| 1789 | req = p9_client_rpc(clnt, P9_TMKDIR, "dsdd", fid->fid, name, mode, | ||
| 1790 | gid); | ||
| 1791 | if (IS_ERR(req)) | ||
| 1792 | return PTR_ERR(req); | ||
| 1793 | |||
| 1794 | err = p9pdu_readf(req->rc, clnt->proto_version, "Q", qid); | ||
| 1795 | if (err) { | ||
| 1796 | p9pdu_dump(1, req->rc); | ||
| 1797 | goto error; | ||
| 1798 | } | ||
| 1799 | P9_DPRINTK(P9_DEBUG_9P, "<<< RMKDIR qid %x.%llx.%x\n", qid->type, | ||
| 1800 | (unsigned long long)qid->path, qid->version); | ||
| 1801 | |||
| 1802 | error: | ||
| 1803 | p9_free_req(clnt, req); | ||
| 1804 | return err; | ||
| 1805 | |||
| 1806 | } | ||
| 1807 | EXPORT_SYMBOL(p9_client_mkdir_dotl); | ||
diff --git a/net/9p/protocol.c b/net/9p/protocol.c index 149f82160130..3acd3afb20c8 100644 --- a/net/9p/protocol.c +++ b/net/9p/protocol.c | |||
| @@ -141,6 +141,7 @@ pdu_write_u(struct p9_fcall *pdu, const char __user *udata, size_t size) | |||
| 141 | D - data blob (int32_t size followed by void *, results are not freed) | 141 | D - data blob (int32_t size followed by void *, results are not freed) |
| 142 | T - array of strings (int16_t count, followed by strings) | 142 | T - array of strings (int16_t count, followed by strings) |
| 143 | R - array of qids (int16_t count, followed by qids) | 143 | R - array of qids (int16_t count, followed by qids) |
| 144 | A - stat for 9p2000.L (p9_stat_dotl) | ||
| 144 | ? - if optional = 1, continue parsing | 145 | ? - if optional = 1, continue parsing |
| 145 | */ | 146 | */ |
| 146 | 147 | ||
| @@ -340,6 +341,33 @@ p9pdu_vreadf(struct p9_fcall *pdu, int proto_version, const char *fmt, | |||
| 340 | } | 341 | } |
| 341 | } | 342 | } |
| 342 | break; | 343 | break; |
| 344 | case 'A': { | ||
| 345 | struct p9_stat_dotl *stbuf = | ||
| 346 | va_arg(ap, struct p9_stat_dotl *); | ||
| 347 | |||
| 348 | memset(stbuf, 0, sizeof(struct p9_stat_dotl)); | ||
| 349 | errcode = | ||
| 350 | p9pdu_readf(pdu, proto_version, | ||
| 351 | "qQdddqqqqqqqqqqqqqqq", | ||
| 352 | &stbuf->st_result_mask, | ||
| 353 | &stbuf->qid, | ||
| 354 | &stbuf->st_mode, | ||
| 355 | &stbuf->st_uid, &stbuf->st_gid, | ||
| 356 | &stbuf->st_nlink, | ||
| 357 | &stbuf->st_rdev, &stbuf->st_size, | ||
| 358 | &stbuf->st_blksize, &stbuf->st_blocks, | ||
| 359 | &stbuf->st_atime_sec, | ||
| 360 | &stbuf->st_atime_nsec, | ||
| 361 | &stbuf->st_mtime_sec, | ||
| 362 | &stbuf->st_mtime_nsec, | ||
| 363 | &stbuf->st_ctime_sec, | ||
| 364 | &stbuf->st_ctime_nsec, | ||
| 365 | &stbuf->st_btime_sec, | ||
| 366 | &stbuf->st_btime_nsec, | ||
| 367 | &stbuf->st_gen, | ||
| 368 | &stbuf->st_data_version); | ||
| 369 | } | ||
| 370 | break; | ||
| 343 | case '?': | 371 | case '?': |
| 344 | if ((proto_version != p9_proto_2000u) && | 372 | if ((proto_version != p9_proto_2000u) && |
| 345 | (proto_version != p9_proto_2000L)) | 373 | (proto_version != p9_proto_2000L)) |
| @@ -488,6 +516,23 @@ p9pdu_vwritef(struct p9_fcall *pdu, int proto_version, const char *fmt, | |||
| 488 | } | 516 | } |
| 489 | } | 517 | } |
| 490 | break; | 518 | break; |
| 519 | case 'I':{ | ||
| 520 | struct p9_iattr_dotl *p9attr = va_arg(ap, | ||
| 521 | struct p9_iattr_dotl *); | ||
| 522 | |||
| 523 | errcode = p9pdu_writef(pdu, proto_version, | ||
| 524 | "ddddqqqqq", | ||
| 525 | p9attr->valid, | ||
| 526 | p9attr->mode, | ||
| 527 | p9attr->uid, | ||
| 528 | p9attr->gid, | ||
| 529 | p9attr->size, | ||
| 530 | p9attr->atime_sec, | ||
| 531 | p9attr->atime_nsec, | ||
| 532 | p9attr->mtime_sec, | ||
| 533 | p9attr->mtime_nsec); | ||
| 534 | } | ||
| 535 | break; | ||
| 491 | case '?': | 536 | case '?': |
| 492 | if ((proto_version != p9_proto_2000u) && | 537 | if ((proto_version != p9_proto_2000u) && |
| 493 | (proto_version != p9_proto_2000L)) | 538 | (proto_version != p9_proto_2000L)) |
| @@ -580,3 +625,30 @@ void p9pdu_reset(struct p9_fcall *pdu) | |||
| 580 | pdu->offset = 0; | 625 | pdu->offset = 0; |
| 581 | pdu->size = 0; | 626 | pdu->size = 0; |
| 582 | } | 627 | } |
| 628 | |||
| 629 | int p9dirent_read(char *buf, int len, struct p9_dirent *dirent, | ||
| 630 | int proto_version) | ||
| 631 | { | ||
| 632 | struct p9_fcall fake_pdu; | ||
| 633 | int ret; | ||
| 634 | char *nameptr; | ||
| 635 | |||
| 636 | fake_pdu.size = len; | ||
| 637 | fake_pdu.capacity = len; | ||
| 638 | fake_pdu.sdata = buf; | ||
| 639 | fake_pdu.offset = 0; | ||
| 640 | |||
| 641 | ret = p9pdu_readf(&fake_pdu, proto_version, "Qqbs", &dirent->qid, | ||
| 642 | &dirent->d_off, &dirent->d_type, &nameptr); | ||
| 643 | if (ret) { | ||
| 644 | P9_DPRINTK(P9_DEBUG_9P, "<<< p9dirent_read failed: %d\n", ret); | ||
| 645 | p9pdu_dump(1, &fake_pdu); | ||
| 646 | goto out; | ||
| 647 | } | ||
| 648 | |||
| 649 | strcpy(dirent->d_name, nameptr); | ||
| 650 | |||
| 651 | out: | ||
| 652 | return fake_pdu.offset; | ||
| 653 | } | ||
| 654 | EXPORT_SYMBOL(p9dirent_read); | ||
diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c index 98ce9bcb0e15..c85109d809ca 100644 --- a/net/9p/trans_fd.c +++ b/net/9p/trans_fd.c | |||
| @@ -948,7 +948,7 @@ p9_fd_create_unix(struct p9_client *client, const char *addr, char *args) | |||
| 948 | 948 | ||
| 949 | csocket = NULL; | 949 | csocket = NULL; |
| 950 | 950 | ||
| 951 | if (strlen(addr) > UNIX_PATH_MAX) { | 951 | if (strlen(addr) >= UNIX_PATH_MAX) { |
| 952 | P9_EPRINTK(KERN_ERR, "p9_trans_unix: address too long: %s\n", | 952 | P9_EPRINTK(KERN_ERR, "p9_trans_unix: address too long: %s\n", |
| 953 | addr); | 953 | addr); |
| 954 | return -ENAMETOOLONG; | 954 | return -ENAMETOOLONG; |
