]>
Commit | Line | Data |
---|---|---|
53c06f4e AK |
1 | /* |
2 | * linux/fs/9p/vfs_inode_dotl.c | |
3 | * | |
4 | * This file contains vfs inode ops for the 9P2000.L protocol. | |
5 | * | |
6 | * Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com> | |
7 | * Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov> | |
8 | * | |
9 | * This program is free software; you can redistribute it and/or modify | |
10 | * it under the terms of the GNU General Public License version 2 | |
11 | * as published by the Free Software Foundation. | |
12 | * | |
13 | * This program is distributed in the hope that it will be useful, | |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | * GNU General Public License for more details. | |
17 | * | |
18 | * You should have received a copy of the GNU General Public License | |
19 | * along with this program; if not, write to: | |
20 | * Free Software Foundation | |
21 | * 51 Franklin Street, Fifth Floor | |
22 | * Boston, MA 02111-1301 USA | |
23 | * | |
24 | */ | |
25 | ||
26 | #include <linux/module.h> | |
27 | #include <linux/errno.h> | |
28 | #include <linux/fs.h> | |
29 | #include <linux/file.h> | |
30 | #include <linux/pagemap.h> | |
31 | #include <linux/stat.h> | |
32 | #include <linux/string.h> | |
33 | #include <linux/inet.h> | |
34 | #include <linux/namei.h> | |
35 | #include <linux/idr.h> | |
36 | #include <linux/sched.h> | |
37 | #include <linux/slab.h> | |
38 | #include <linux/xattr.h> | |
39 | #include <linux/posix_acl.h> | |
40 | #include <net/9p/9p.h> | |
41 | #include <net/9p/client.h> | |
42 | ||
43 | #include "v9fs.h" | |
44 | #include "v9fs_vfs.h" | |
45 | #include "fid.h" | |
46 | #include "cache.h" | |
47 | #include "xattr.h" | |
48 | #include "acl.h" | |
49 | ||
50 | static int | |
51 | v9fs_vfs_mknod_dotl(struct inode *dir, struct dentry *dentry, int omode, | |
52 | dev_t rdev); | |
53 | ||
54 | /** | |
55 | * v9fs_get_fsgid_for_create - Helper function to get the gid for creating a | |
56 | * new file system object. This checks the S_ISGID to determine the owning | |
57 | * group of the new file system object. | |
58 | */ | |
59 | ||
60 | static gid_t v9fs_get_fsgid_for_create(struct inode *dir_inode) | |
61 | { | |
62 | BUG_ON(dir_inode == NULL); | |
63 | ||
64 | if (dir_inode->i_mode & S_ISGID) { | |
65 | /* set_gid bit is set.*/ | |
66 | return dir_inode->i_gid; | |
67 | } | |
68 | return current_fsgid(); | |
69 | } | |
70 | ||
71 | /** | |
72 | * v9fs_dentry_from_dir_inode - helper function to get the dentry from | |
73 | * dir inode. | |
74 | * | |
75 | */ | |
76 | ||
77 | static struct dentry *v9fs_dentry_from_dir_inode(struct inode *inode) | |
78 | { | |
79 | struct dentry *dentry; | |
80 | ||
81 | spin_lock(&inode->i_lock); | |
82 | /* Directory should have only one entry. */ | |
83 | BUG_ON(S_ISDIR(inode->i_mode) && !list_is_singular(&inode->i_dentry)); | |
84 | dentry = list_entry(inode->i_dentry.next, struct dentry, d_alias); | |
85 | spin_unlock(&inode->i_lock); | |
86 | return dentry; | |
87 | } | |
88 | ||
5ffc0cb3 AK |
89 | static struct inode *v9fs_qid_iget_dotl(struct super_block *sb, |
90 | struct p9_qid *qid, | |
91 | struct p9_fid *fid, | |
92 | struct p9_stat_dotl *st) | |
93 | { | |
94 | int retval; | |
95 | unsigned long i_ino; | |
96 | struct inode *inode; | |
97 | struct v9fs_session_info *v9ses = sb->s_fs_info; | |
98 | ||
99 | i_ino = v9fs_qid2ino(qid); | |
100 | inode = iget_locked(sb, i_ino); | |
101 | if (!inode) | |
102 | return ERR_PTR(-ENOMEM); | |
103 | if (!(inode->i_state & I_NEW)) | |
104 | return inode; | |
105 | /* | |
106 | * initialize the inode with the stat info | |
107 | * FIXME!! we may need support for stale inodes | |
108 | * later. | |
109 | */ | |
110 | retval = v9fs_init_inode(v9ses, inode, st->st_mode); | |
111 | if (retval) | |
112 | goto error; | |
113 | ||
114 | v9fs_stat2inode_dotl(st, inode); | |
115 | #ifdef CONFIG_9P_FSCACHE | |
a78ce05d | 116 | v9fs_fscache_set_key(inode, &st->qid); |
5ffc0cb3 AK |
117 | v9fs_cache_inode_get_cookie(inode); |
118 | #endif | |
119 | retval = v9fs_get_acl(inode, fid); | |
120 | if (retval) | |
121 | goto error; | |
122 | ||
123 | unlock_new_inode(inode); | |
124 | return inode; | |
125 | error: | |
126 | unlock_new_inode(inode); | |
127 | iput(inode); | |
128 | return ERR_PTR(retval); | |
129 | ||
130 | } | |
131 | ||
53c06f4e | 132 | struct inode * |
a78ce05d AK |
133 | v9fs_inode_from_fid_dotl(struct v9fs_session_info *v9ses, struct p9_fid *fid, |
134 | struct super_block *sb) | |
53c06f4e | 135 | { |
53c06f4e | 136 | struct p9_stat_dotl *st; |
5ffc0cb3 | 137 | struct inode *inode = NULL; |
53c06f4e AK |
138 | |
139 | st = p9_client_getattr_dotl(fid, P9_STATS_BASIC); | |
140 | if (IS_ERR(st)) | |
141 | return ERR_CAST(st); | |
142 | ||
5ffc0cb3 | 143 | inode = v9fs_qid_iget_dotl(sb, &st->qid, fid, st); |
53c06f4e | 144 | kfree(st); |
5ffc0cb3 | 145 | return inode; |
53c06f4e AK |
146 | } |
147 | ||
148 | /** | |
149 | * v9fs_vfs_create_dotl - VFS hook to create files for 9P2000.L protocol. | |
150 | * @dir: directory inode that is being created | |
151 | * @dentry: dentry that is being deleted | |
152 | * @mode: create permissions | |
153 | * @nd: path information | |
154 | * | |
155 | */ | |
156 | ||
157 | static int | |
158 | v9fs_vfs_create_dotl(struct inode *dir, struct dentry *dentry, int omode, | |
159 | struct nameidata *nd) | |
160 | { | |
161 | int err = 0; | |
53c06f4e AK |
162 | gid_t gid; |
163 | int flags; | |
164 | mode_t mode; | |
6b39f6d2 | 165 | char *name = NULL; |
53c06f4e AK |
166 | struct file *filp; |
167 | struct p9_qid qid; | |
168 | struct inode *inode; | |
6b39f6d2 AK |
169 | struct p9_fid *fid = NULL; |
170 | struct v9fs_inode *v9inode; | |
171 | struct p9_fid *dfid, *ofid, *inode_fid; | |
172 | struct v9fs_session_info *v9ses; | |
53c06f4e AK |
173 | struct posix_acl *pacl = NULL, *dacl = NULL; |
174 | ||
175 | v9ses = v9fs_inode2v9ses(dir); | |
176 | if (nd && nd->flags & LOOKUP_OPEN) | |
177 | flags = nd->intent.open.flags - 1; | |
178 | else { | |
179 | /* | |
180 | * create call without LOOKUP_OPEN is due | |
181 | * to mknod of regular files. So use mknod | |
182 | * operation. | |
183 | */ | |
184 | return v9fs_vfs_mknod_dotl(dir, dentry, omode, 0); | |
185 | } | |
186 | ||
187 | name = (char *) dentry->d_name.name; | |
188 | P9_DPRINTK(P9_DEBUG_VFS, "v9fs_vfs_create_dotl: name:%s flags:0x%x " | |
189 | "mode:0x%x\n", name, flags, omode); | |
190 | ||
191 | dfid = v9fs_fid_lookup(dentry->d_parent); | |
192 | if (IS_ERR(dfid)) { | |
193 | err = PTR_ERR(dfid); | |
194 | P9_DPRINTK(P9_DEBUG_VFS, "fid lookup failed %d\n", err); | |
195 | return err; | |
196 | } | |
197 | ||
198 | /* clone a fid to use for creation */ | |
199 | ofid = p9_client_walk(dfid, 0, NULL, 1); | |
200 | if (IS_ERR(ofid)) { | |
201 | err = PTR_ERR(ofid); | |
202 | P9_DPRINTK(P9_DEBUG_VFS, "p9_client_walk failed %d\n", err); | |
203 | return err; | |
204 | } | |
205 | ||
206 | gid = v9fs_get_fsgid_for_create(dir); | |
207 | ||
208 | mode = omode; | |
209 | /* Update mode based on ACL value */ | |
210 | err = v9fs_acl_mode(dir, &mode, &dacl, &pacl); | |
211 | if (err) { | |
212 | P9_DPRINTK(P9_DEBUG_VFS, | |
213 | "Failed to get acl values in creat %d\n", err); | |
214 | goto error; | |
215 | } | |
216 | err = p9_client_create_dotl(ofid, name, flags, mode, gid, &qid); | |
217 | if (err < 0) { | |
218 | P9_DPRINTK(P9_DEBUG_VFS, | |
219 | "p9_client_open_dotl failed in creat %d\n", | |
220 | err); | |
221 | goto error; | |
222 | } | |
53c06f4e | 223 | |
af7542fc AK |
224 | /* instantiate inode and assign the unopened fid to the dentry */ |
225 | fid = p9_client_walk(dfid, 1, &name, 1); | |
226 | if (IS_ERR(fid)) { | |
227 | err = PTR_ERR(fid); | |
c25a61f5 | 228 | P9_DPRINTK(P9_DEBUG_VFS, "p9_client_walk failed %d\n", err); |
53c06f4e | 229 | fid = NULL; |
af7542fc | 230 | goto error; |
53c06f4e | 231 | } |
a78ce05d | 232 | inode = v9fs_get_inode_from_fid(v9ses, fid, dir->i_sb); |
af7542fc AK |
233 | if (IS_ERR(inode)) { |
234 | err = PTR_ERR(inode); | |
235 | P9_DPRINTK(P9_DEBUG_VFS, "inode creation failed %d\n", err); | |
236 | goto error; | |
237 | } | |
af7542fc AK |
238 | d_instantiate(dentry, inode); |
239 | err = v9fs_fid_add(dentry, fid); | |
240 | if (err < 0) | |
241 | goto error; | |
242 | ||
53c06f4e AK |
243 | /* Now set the ACL based on the default value */ |
244 | v9fs_set_create_acl(dentry, dacl, pacl); | |
6b39f6d2 AK |
245 | |
246 | v9inode = V9FS_I(inode); | |
247 | if (v9ses->cache && !v9inode->writeback_fid) { | |
3cf387d7 | 248 | /* |
6b39f6d2 | 249 | * clone a fid and add it to writeback_fid |
3cf387d7 AK |
250 | * we do it during open time instead of |
251 | * page dirty time via write_begin/page_mkwrite | |
252 | * because we want write after unlink usecase | |
253 | * to work. | |
254 | */ | |
255 | inode_fid = v9fs_writeback_fid(dentry); | |
256 | if (IS_ERR(inode_fid)) { | |
257 | err = PTR_ERR(inode_fid); | |
258 | goto error; | |
259 | } | |
6b39f6d2 | 260 | v9inode->writeback_fid = (void *) inode_fid; |
3cf387d7 | 261 | } |
af7542fc AK |
262 | /* Since we are opening a file, assign the open fid to the file */ |
263 | filp = lookup_instantiate_filp(nd, dentry, generic_file_open); | |
264 | if (IS_ERR(filp)) { | |
53c06f4e | 265 | p9_client_clunk(ofid); |
af7542fc AK |
266 | return PTR_ERR(filp); |
267 | } | |
268 | filp->private_data = ofid; | |
46848de0 AK |
269 | #ifdef CONFIG_9P_FSCACHE |
270 | if (v9ses->cache) | |
271 | v9fs_cache_inode_set_cookie(inode, filp); | |
272 | #endif | |
53c06f4e AK |
273 | return 0; |
274 | ||
275 | error: | |
276 | if (ofid) | |
277 | p9_client_clunk(ofid); | |
278 | if (fid) | |
279 | p9_client_clunk(fid); | |
280 | return err; | |
281 | } | |
282 | ||
283 | /** | |
284 | * v9fs_vfs_mkdir_dotl - VFS mkdir hook to create a directory | |
285 | * @dir: inode that is being unlinked | |
286 | * @dentry: dentry that is being unlinked | |
287 | * @mode: mode for new directory | |
288 | * | |
289 | */ | |
290 | ||
291 | static int v9fs_vfs_mkdir_dotl(struct inode *dir, | |
292 | struct dentry *dentry, int omode) | |
293 | { | |
294 | int err; | |
295 | struct v9fs_session_info *v9ses; | |
296 | struct p9_fid *fid = NULL, *dfid = NULL; | |
297 | gid_t gid; | |
298 | char *name; | |
299 | mode_t mode; | |
300 | struct inode *inode; | |
301 | struct p9_qid qid; | |
302 | struct dentry *dir_dentry; | |
303 | struct posix_acl *dacl = NULL, *pacl = NULL; | |
304 | ||
305 | P9_DPRINTK(P9_DEBUG_VFS, "name %s\n", dentry->d_name.name); | |
306 | err = 0; | |
307 | v9ses = v9fs_inode2v9ses(dir); | |
308 | ||
309 | omode |= S_IFDIR; | |
310 | if (dir->i_mode & S_ISGID) | |
311 | omode |= S_ISGID; | |
312 | ||
313 | dir_dentry = v9fs_dentry_from_dir_inode(dir); | |
314 | dfid = v9fs_fid_lookup(dir_dentry); | |
315 | if (IS_ERR(dfid)) { | |
316 | err = PTR_ERR(dfid); | |
317 | P9_DPRINTK(P9_DEBUG_VFS, "fid lookup failed %d\n", err); | |
318 | dfid = NULL; | |
319 | goto error; | |
320 | } | |
321 | ||
322 | gid = v9fs_get_fsgid_for_create(dir); | |
323 | mode = omode; | |
324 | /* Update mode based on ACL value */ | |
325 | err = v9fs_acl_mode(dir, &mode, &dacl, &pacl); | |
326 | if (err) { | |
327 | P9_DPRINTK(P9_DEBUG_VFS, | |
328 | "Failed to get acl values in mkdir %d\n", err); | |
329 | goto error; | |
330 | } | |
331 | name = (char *) dentry->d_name.name; | |
332 | err = p9_client_mkdir_dotl(dfid, name, mode, gid, &qid); | |
333 | if (err < 0) | |
334 | goto error; | |
335 | ||
336 | /* instantiate inode and assign the unopened fid to the dentry */ | |
337 | if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) { | |
338 | fid = p9_client_walk(dfid, 1, &name, 1); | |
339 | if (IS_ERR(fid)) { | |
340 | err = PTR_ERR(fid); | |
341 | P9_DPRINTK(P9_DEBUG_VFS, "p9_client_walk failed %d\n", | |
342 | err); | |
343 | fid = NULL; | |
344 | goto error; | |
345 | } | |
346 | ||
a78ce05d | 347 | inode = v9fs_get_inode_from_fid(v9ses, fid, dir->i_sb); |
53c06f4e AK |
348 | if (IS_ERR(inode)) { |
349 | err = PTR_ERR(inode); | |
350 | P9_DPRINTK(P9_DEBUG_VFS, "inode creation failed %d\n", | |
351 | err); | |
352 | goto error; | |
353 | } | |
53c06f4e AK |
354 | d_instantiate(dentry, inode); |
355 | err = v9fs_fid_add(dentry, fid); | |
356 | if (err < 0) | |
357 | goto error; | |
358 | fid = NULL; | |
359 | } else { | |
360 | /* | |
361 | * Not in cached mode. No need to populate | |
362 | * inode with stat. We need to get an inode | |
363 | * so that we can set the acl with dentry | |
364 | */ | |
365 | inode = v9fs_get_inode(dir->i_sb, mode); | |
366 | if (IS_ERR(inode)) { | |
367 | err = PTR_ERR(inode); | |
368 | goto error; | |
369 | } | |
53c06f4e AK |
370 | d_instantiate(dentry, inode); |
371 | } | |
372 | /* Now set the ACL based on the default value */ | |
373 | v9fs_set_create_acl(dentry, dacl, pacl); | |
374 | ||
375 | error: | |
376 | if (fid) | |
377 | p9_client_clunk(fid); | |
378 | return err; | |
379 | } | |
380 | ||
381 | static int | |
382 | v9fs_vfs_getattr_dotl(struct vfsmount *mnt, struct dentry *dentry, | |
383 | struct kstat *stat) | |
384 | { | |
385 | int err; | |
386 | struct v9fs_session_info *v9ses; | |
387 | struct p9_fid *fid; | |
388 | struct p9_stat_dotl *st; | |
389 | ||
390 | P9_DPRINTK(P9_DEBUG_VFS, "dentry: %p\n", dentry); | |
391 | err = -EPERM; | |
392 | v9ses = v9fs_inode2v9ses(dentry->d_inode); | |
a1211908 AK |
393 | if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) { |
394 | generic_fillattr(dentry->d_inode, stat); | |
395 | return 0; | |
396 | } | |
53c06f4e AK |
397 | fid = v9fs_fid_lookup(dentry); |
398 | if (IS_ERR(fid)) | |
399 | return PTR_ERR(fid); | |
400 | ||
401 | /* Ask for all the fields in stat structure. Server will return | |
402 | * whatever it supports | |
403 | */ | |
404 | ||
405 | st = p9_client_getattr_dotl(fid, P9_STATS_ALL); | |
406 | if (IS_ERR(st)) | |
407 | return PTR_ERR(st); | |
408 | ||
409 | v9fs_stat2inode_dotl(st, dentry->d_inode); | |
410 | generic_fillattr(dentry->d_inode, stat); | |
411 | /* Change block size to what the server returned */ | |
412 | stat->blksize = st->st_blksize; | |
413 | ||
414 | kfree(st); | |
415 | return 0; | |
416 | } | |
417 | ||
418 | /** | |
419 | * v9fs_vfs_setattr_dotl - set file metadata | |
420 | * @dentry: file whose metadata to set | |
421 | * @iattr: metadata assignment structure | |
422 | * | |
423 | */ | |
424 | ||
425 | int v9fs_vfs_setattr_dotl(struct dentry *dentry, struct iattr *iattr) | |
426 | { | |
427 | int retval; | |
428 | struct v9fs_session_info *v9ses; | |
429 | struct p9_fid *fid; | |
430 | struct p9_iattr_dotl p9attr; | |
431 | ||
432 | P9_DPRINTK(P9_DEBUG_VFS, "\n"); | |
433 | ||
434 | retval = inode_change_ok(dentry->d_inode, iattr); | |
435 | if (retval) | |
436 | return retval; | |
437 | ||
438 | p9attr.valid = iattr->ia_valid; | |
439 | p9attr.mode = iattr->ia_mode; | |
440 | p9attr.uid = iattr->ia_uid; | |
441 | p9attr.gid = iattr->ia_gid; | |
442 | p9attr.size = iattr->ia_size; | |
443 | p9attr.atime_sec = iattr->ia_atime.tv_sec; | |
444 | p9attr.atime_nsec = iattr->ia_atime.tv_nsec; | |
445 | p9attr.mtime_sec = iattr->ia_mtime.tv_sec; | |
446 | p9attr.mtime_nsec = iattr->ia_mtime.tv_nsec; | |
447 | ||
448 | retval = -EPERM; | |
449 | v9ses = v9fs_inode2v9ses(dentry->d_inode); | |
450 | fid = v9fs_fid_lookup(dentry); | |
451 | if (IS_ERR(fid)) | |
452 | return PTR_ERR(fid); | |
453 | ||
454 | retval = p9_client_setattr(fid, &p9attr); | |
455 | if (retval < 0) | |
456 | return retval; | |
457 | ||
458 | if ((iattr->ia_valid & ATTR_SIZE) && | |
459 | iattr->ia_size != i_size_read(dentry->d_inode)) { | |
460 | retval = vmtruncate(dentry->d_inode, iattr->ia_size); | |
461 | if (retval) | |
462 | return retval; | |
463 | } | |
464 | ||
465 | setattr_copy(dentry->d_inode, iattr); | |
466 | mark_inode_dirty(dentry->d_inode); | |
467 | if (iattr->ia_valid & ATTR_MODE) { | |
468 | /* We also want to update ACL when we update mode bits */ | |
469 | retval = v9fs_acl_chmod(dentry); | |
470 | if (retval < 0) | |
471 | return retval; | |
472 | } | |
473 | return 0; | |
474 | } | |
475 | ||
476 | /** | |
477 | * v9fs_stat2inode_dotl - populate an inode structure with stat info | |
478 | * @stat: stat structure | |
479 | * @inode: inode to populate | |
480 | * @sb: superblock of filesystem | |
481 | * | |
482 | */ | |
483 | ||
484 | void | |
485 | v9fs_stat2inode_dotl(struct p9_stat_dotl *stat, struct inode *inode) | |
486 | { | |
487 | ||
488 | if ((stat->st_result_mask & P9_STATS_BASIC) == P9_STATS_BASIC) { | |
489 | inode->i_atime.tv_sec = stat->st_atime_sec; | |
490 | inode->i_atime.tv_nsec = stat->st_atime_nsec; | |
491 | inode->i_mtime.tv_sec = stat->st_mtime_sec; | |
492 | inode->i_mtime.tv_nsec = stat->st_mtime_nsec; | |
493 | inode->i_ctime.tv_sec = stat->st_ctime_sec; | |
494 | inode->i_ctime.tv_nsec = stat->st_ctime_nsec; | |
495 | inode->i_uid = stat->st_uid; | |
496 | inode->i_gid = stat->st_gid; | |
497 | inode->i_nlink = stat->st_nlink; | |
498 | inode->i_mode = stat->st_mode; | |
499 | inode->i_rdev = new_decode_dev(stat->st_rdev); | |
500 | ||
501 | if ((S_ISBLK(inode->i_mode)) || (S_ISCHR(inode->i_mode))) | |
502 | init_special_inode(inode, inode->i_mode, inode->i_rdev); | |
503 | ||
504 | i_size_write(inode, stat->st_size); | |
505 | inode->i_blocks = stat->st_blocks; | |
506 | } else { | |
507 | if (stat->st_result_mask & P9_STATS_ATIME) { | |
508 | inode->i_atime.tv_sec = stat->st_atime_sec; | |
509 | inode->i_atime.tv_nsec = stat->st_atime_nsec; | |
510 | } | |
511 | if (stat->st_result_mask & P9_STATS_MTIME) { | |
512 | inode->i_mtime.tv_sec = stat->st_mtime_sec; | |
513 | inode->i_mtime.tv_nsec = stat->st_mtime_nsec; | |
514 | } | |
515 | if (stat->st_result_mask & P9_STATS_CTIME) { | |
516 | inode->i_ctime.tv_sec = stat->st_ctime_sec; | |
517 | inode->i_ctime.tv_nsec = stat->st_ctime_nsec; | |
518 | } | |
519 | if (stat->st_result_mask & P9_STATS_UID) | |
520 | inode->i_uid = stat->st_uid; | |
521 | if (stat->st_result_mask & P9_STATS_GID) | |
522 | inode->i_gid = stat->st_gid; | |
523 | if (stat->st_result_mask & P9_STATS_NLINK) | |
524 | inode->i_nlink = stat->st_nlink; | |
525 | if (stat->st_result_mask & P9_STATS_MODE) { | |
526 | inode->i_mode = stat->st_mode; | |
527 | if ((S_ISBLK(inode->i_mode)) || | |
528 | (S_ISCHR(inode->i_mode))) | |
529 | init_special_inode(inode, inode->i_mode, | |
530 | inode->i_rdev); | |
531 | } | |
532 | if (stat->st_result_mask & P9_STATS_RDEV) | |
533 | inode->i_rdev = new_decode_dev(stat->st_rdev); | |
534 | if (stat->st_result_mask & P9_STATS_SIZE) | |
535 | i_size_write(inode, stat->st_size); | |
536 | if (stat->st_result_mask & P9_STATS_BLOCKS) | |
537 | inode->i_blocks = stat->st_blocks; | |
538 | } | |
539 | if (stat->st_result_mask & P9_STATS_GEN) | |
540 | inode->i_generation = stat->st_gen; | |
541 | ||
542 | /* Currently we don't support P9_STATS_BTIME and P9_STATS_DATA_VERSION | |
543 | * because the inode structure does not have fields for them. | |
544 | */ | |
545 | } | |
546 | ||
547 | static int | |
548 | v9fs_vfs_symlink_dotl(struct inode *dir, struct dentry *dentry, | |
549 | const char *symname) | |
550 | { | |
551 | struct v9fs_session_info *v9ses; | |
552 | struct p9_fid *dfid; | |
553 | struct p9_fid *fid = NULL; | |
554 | struct inode *inode; | |
555 | struct p9_qid qid; | |
556 | char *name; | |
557 | int err; | |
558 | gid_t gid; | |
559 | ||
560 | name = (char *) dentry->d_name.name; | |
561 | P9_DPRINTK(P9_DEBUG_VFS, "v9fs_vfs_symlink_dotl : %lu,%s,%s\n", | |
562 | dir->i_ino, name, symname); | |
563 | v9ses = v9fs_inode2v9ses(dir); | |
564 | ||
565 | dfid = v9fs_fid_lookup(dentry->d_parent); | |
566 | if (IS_ERR(dfid)) { | |
567 | err = PTR_ERR(dfid); | |
568 | P9_DPRINTK(P9_DEBUG_VFS, "fid lookup failed %d\n", err); | |
569 | return err; | |
570 | } | |
571 | ||
572 | gid = v9fs_get_fsgid_for_create(dir); | |
573 | ||
574 | /* Server doesn't alter fid on TSYMLINK. Hence no need to clone it. */ | |
575 | err = p9_client_symlink(dfid, name, (char *)symname, gid, &qid); | |
576 | ||
577 | if (err < 0) { | |
578 | P9_DPRINTK(P9_DEBUG_VFS, "p9_client_symlink failed %d\n", err); | |
579 | goto error; | |
580 | } | |
581 | ||
582 | if (v9ses->cache) { | |
583 | /* Now walk from the parent so we can get an unopened fid. */ | |
584 | fid = p9_client_walk(dfid, 1, &name, 1); | |
585 | if (IS_ERR(fid)) { | |
586 | err = PTR_ERR(fid); | |
587 | P9_DPRINTK(P9_DEBUG_VFS, "p9_client_walk failed %d\n", | |
588 | err); | |
589 | fid = NULL; | |
590 | goto error; | |
591 | } | |
592 | ||
593 | /* instantiate inode and assign the unopened fid to dentry */ | |
a78ce05d | 594 | inode = v9fs_get_inode_from_fid(v9ses, fid, dir->i_sb); |
53c06f4e AK |
595 | if (IS_ERR(inode)) { |
596 | err = PTR_ERR(inode); | |
597 | P9_DPRINTK(P9_DEBUG_VFS, "inode creation failed %d\n", | |
598 | err); | |
599 | goto error; | |
600 | } | |
53c06f4e AK |
601 | d_instantiate(dentry, inode); |
602 | err = v9fs_fid_add(dentry, fid); | |
603 | if (err < 0) | |
604 | goto error; | |
605 | fid = NULL; | |
606 | } else { | |
607 | /* Not in cached mode. No need to populate inode with stat */ | |
608 | inode = v9fs_get_inode(dir->i_sb, S_IFLNK); | |
609 | if (IS_ERR(inode)) { | |
610 | err = PTR_ERR(inode); | |
611 | goto error; | |
612 | } | |
53c06f4e AK |
613 | d_instantiate(dentry, inode); |
614 | } | |
615 | ||
616 | error: | |
617 | if (fid) | |
618 | p9_client_clunk(fid); | |
619 | ||
620 | return err; | |
621 | } | |
622 | ||
623 | /** | |
624 | * v9fs_vfs_link_dotl - create a hardlink for dotl | |
625 | * @old_dentry: dentry for file to link to | |
626 | * @dir: inode destination for new link | |
627 | * @dentry: dentry for link | |
628 | * | |
629 | */ | |
630 | ||
631 | static int | |
632 | v9fs_vfs_link_dotl(struct dentry *old_dentry, struct inode *dir, | |
633 | struct dentry *dentry) | |
634 | { | |
635 | int err; | |
636 | struct p9_fid *dfid, *oldfid; | |
637 | char *name; | |
638 | struct v9fs_session_info *v9ses; | |
639 | struct dentry *dir_dentry; | |
640 | ||
641 | P9_DPRINTK(P9_DEBUG_VFS, "dir ino: %lu, old_name: %s, new_name: %s\n", | |
642 | dir->i_ino, old_dentry->d_name.name, | |
643 | dentry->d_name.name); | |
644 | ||
645 | v9ses = v9fs_inode2v9ses(dir); | |
646 | dir_dentry = v9fs_dentry_from_dir_inode(dir); | |
647 | dfid = v9fs_fid_lookup(dir_dentry); | |
648 | if (IS_ERR(dfid)) | |
649 | return PTR_ERR(dfid); | |
650 | ||
651 | oldfid = v9fs_fid_lookup(old_dentry); | |
652 | if (IS_ERR(oldfid)) | |
653 | return PTR_ERR(oldfid); | |
654 | ||
655 | name = (char *) dentry->d_name.name; | |
656 | ||
657 | err = p9_client_link(dfid, oldfid, (char *)dentry->d_name.name); | |
658 | ||
659 | if (err < 0) { | |
660 | P9_DPRINTK(P9_DEBUG_VFS, "p9_client_link failed %d\n", err); | |
661 | return err; | |
662 | } | |
663 | ||
664 | if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) { | |
665 | /* Get the latest stat info from server. */ | |
666 | struct p9_fid *fid; | |
667 | struct p9_stat_dotl *st; | |
668 | ||
669 | fid = v9fs_fid_lookup(old_dentry); | |
670 | if (IS_ERR(fid)) | |
671 | return PTR_ERR(fid); | |
672 | ||
673 | st = p9_client_getattr_dotl(fid, P9_STATS_BASIC); | |
674 | if (IS_ERR(st)) | |
675 | return PTR_ERR(st); | |
676 | ||
677 | v9fs_stat2inode_dotl(st, old_dentry->d_inode); | |
678 | ||
679 | kfree(st); | |
53c06f4e | 680 | } |
20656a49 | 681 | ihold(old_dentry->d_inode); |
53c06f4e AK |
682 | d_instantiate(dentry, old_dentry->d_inode); |
683 | ||
684 | return err; | |
685 | } | |
686 | ||
687 | /** | |
688 | * v9fs_vfs_mknod_dotl - create a special file | |
689 | * @dir: inode destination for new link | |
690 | * @dentry: dentry for file | |
691 | * @mode: mode for creation | |
692 | * @rdev: device associated with special file | |
693 | * | |
694 | */ | |
695 | static int | |
696 | v9fs_vfs_mknod_dotl(struct inode *dir, struct dentry *dentry, int omode, | |
697 | dev_t rdev) | |
698 | { | |
699 | int err; | |
700 | char *name; | |
701 | mode_t mode; | |
702 | struct v9fs_session_info *v9ses; | |
703 | struct p9_fid *fid = NULL, *dfid = NULL; | |
704 | struct inode *inode; | |
705 | gid_t gid; | |
706 | struct p9_qid qid; | |
707 | struct dentry *dir_dentry; | |
708 | struct posix_acl *dacl = NULL, *pacl = NULL; | |
709 | ||
710 | P9_DPRINTK(P9_DEBUG_VFS, | |
711 | " %lu,%s mode: %x MAJOR: %u MINOR: %u\n", dir->i_ino, | |
712 | dentry->d_name.name, omode, MAJOR(rdev), MINOR(rdev)); | |
713 | ||
714 | if (!new_valid_dev(rdev)) | |
715 | return -EINVAL; | |
716 | ||
717 | v9ses = v9fs_inode2v9ses(dir); | |
718 | dir_dentry = v9fs_dentry_from_dir_inode(dir); | |
719 | dfid = v9fs_fid_lookup(dir_dentry); | |
720 | if (IS_ERR(dfid)) { | |
721 | err = PTR_ERR(dfid); | |
722 | P9_DPRINTK(P9_DEBUG_VFS, "fid lookup failed %d\n", err); | |
723 | dfid = NULL; | |
724 | goto error; | |
725 | } | |
726 | ||
727 | gid = v9fs_get_fsgid_for_create(dir); | |
728 | mode = omode; | |
729 | /* Update mode based on ACL value */ | |
730 | err = v9fs_acl_mode(dir, &mode, &dacl, &pacl); | |
731 | if (err) { | |
732 | P9_DPRINTK(P9_DEBUG_VFS, | |
733 | "Failed to get acl values in mknod %d\n", err); | |
734 | goto error; | |
735 | } | |
736 | name = (char *) dentry->d_name.name; | |
737 | ||
738 | err = p9_client_mknod_dotl(dfid, name, mode, rdev, gid, &qid); | |
739 | if (err < 0) | |
740 | goto error; | |
741 | ||
742 | /* instantiate inode and assign the unopened fid to the dentry */ | |
743 | if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) { | |
744 | fid = p9_client_walk(dfid, 1, &name, 1); | |
745 | if (IS_ERR(fid)) { | |
746 | err = PTR_ERR(fid); | |
747 | P9_DPRINTK(P9_DEBUG_VFS, "p9_client_walk failed %d\n", | |
748 | err); | |
749 | fid = NULL; | |
750 | goto error; | |
751 | } | |
752 | ||
a78ce05d | 753 | inode = v9fs_get_inode_from_fid(v9ses, fid, dir->i_sb); |
53c06f4e AK |
754 | if (IS_ERR(inode)) { |
755 | err = PTR_ERR(inode); | |
756 | P9_DPRINTK(P9_DEBUG_VFS, "inode creation failed %d\n", | |
757 | err); | |
758 | goto error; | |
759 | } | |
53c06f4e AK |
760 | d_instantiate(dentry, inode); |
761 | err = v9fs_fid_add(dentry, fid); | |
762 | if (err < 0) | |
763 | goto error; | |
764 | fid = NULL; | |
765 | } else { | |
766 | /* | |
767 | * Not in cached mode. No need to populate inode with stat. | |
768 | * socket syscall returns a fd, so we need instantiate | |
769 | */ | |
770 | inode = v9fs_get_inode(dir->i_sb, mode); | |
771 | if (IS_ERR(inode)) { | |
772 | err = PTR_ERR(inode); | |
773 | goto error; | |
774 | } | |
53c06f4e AK |
775 | d_instantiate(dentry, inode); |
776 | } | |
777 | /* Now set the ACL based on the default value */ | |
778 | v9fs_set_create_acl(dentry, dacl, pacl); | |
779 | error: | |
780 | if (fid) | |
781 | p9_client_clunk(fid); | |
782 | return err; | |
783 | } | |
784 | ||
53c06f4e AK |
785 | /** |
786 | * v9fs_vfs_follow_link_dotl - follow a symlink path | |
787 | * @dentry: dentry for symlink | |
788 | * @nd: nameidata | |
789 | * | |
790 | */ | |
791 | ||
792 | static void * | |
793 | v9fs_vfs_follow_link_dotl(struct dentry *dentry, struct nameidata *nd) | |
794 | { | |
31b6ceac MK |
795 | int retval; |
796 | struct p9_fid *fid; | |
53c06f4e | 797 | char *link = __getname(); |
31b6ceac | 798 | char *target; |
53c06f4e | 799 | |
31b6ceac | 800 | P9_DPRINTK(P9_DEBUG_VFS, "%s\n", dentry->d_name.name); |
53c06f4e | 801 | |
31b6ceac | 802 | if (!link) { |
53c06f4e | 803 | link = ERR_PTR(-ENOMEM); |
31b6ceac | 804 | goto ndset; |
53c06f4e | 805 | } |
31b6ceac MK |
806 | fid = v9fs_fid_lookup(dentry); |
807 | if (IS_ERR(fid)) { | |
808 | __putname(link); | |
809 | link = ERR_PTR(PTR_ERR(fid)); | |
810 | goto ndset; | |
811 | } | |
812 | retval = p9_client_readlink(fid, &target); | |
813 | if (!retval) { | |
814 | strcpy(link, target); | |
815 | kfree(target); | |
816 | goto ndset; | |
817 | } | |
818 | __putname(link); | |
819 | link = ERR_PTR(retval); | |
820 | ndset: | |
53c06f4e | 821 | nd_set_link(nd, link); |
53c06f4e AK |
822 | return NULL; |
823 | } | |
824 | ||
825 | const struct inode_operations v9fs_dir_inode_operations_dotl = { | |
826 | .create = v9fs_vfs_create_dotl, | |
827 | .lookup = v9fs_vfs_lookup, | |
828 | .link = v9fs_vfs_link_dotl, | |
829 | .symlink = v9fs_vfs_symlink_dotl, | |
830 | .unlink = v9fs_vfs_unlink, | |
831 | .mkdir = v9fs_vfs_mkdir_dotl, | |
832 | .rmdir = v9fs_vfs_rmdir, | |
833 | .mknod = v9fs_vfs_mknod_dotl, | |
834 | .rename = v9fs_vfs_rename, | |
835 | .getattr = v9fs_vfs_getattr_dotl, | |
836 | .setattr = v9fs_vfs_setattr_dotl, | |
837 | .setxattr = generic_setxattr, | |
838 | .getxattr = generic_getxattr, | |
839 | .removexattr = generic_removexattr, | |
840 | .listxattr = v9fs_listxattr, | |
841 | .check_acl = v9fs_check_acl, | |
842 | }; | |
843 | ||
844 | const struct inode_operations v9fs_file_inode_operations_dotl = { | |
845 | .getattr = v9fs_vfs_getattr_dotl, | |
846 | .setattr = v9fs_vfs_setattr_dotl, | |
847 | .setxattr = generic_setxattr, | |
848 | .getxattr = generic_getxattr, | |
849 | .removexattr = generic_removexattr, | |
850 | .listxattr = v9fs_listxattr, | |
851 | .check_acl = v9fs_check_acl, | |
852 | }; | |
853 | ||
854 | const struct inode_operations v9fs_symlink_inode_operations_dotl = { | |
31b6ceac | 855 | .readlink = generic_readlink, |
53c06f4e AK |
856 | .follow_link = v9fs_vfs_follow_link_dotl, |
857 | .put_link = v9fs_vfs_put_link, | |
858 | .getattr = v9fs_vfs_getattr_dotl, | |
859 | .setattr = v9fs_vfs_setattr_dotl, | |
860 | .setxattr = generic_setxattr, | |
861 | .getxattr = generic_getxattr, | |
862 | .removexattr = generic_removexattr, | |
863 | .listxattr = v9fs_listxattr, | |
864 | }; |