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