]> git.ipfire.org Git - people/ms/linux.git/blame - fs/9p/vfs_inode_dotl.c
fs/9p: Add . and .. dentry revalidation flag
[people/ms/linux.git] / fs / 9p / vfs_inode_dotl.c
CommitLineData
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
50static int
51v9fs_vfs_mknod_dotl(struct inode *dir, struct dentry *dentry, int omode,
52 dev_t rdev);
53
54/**
55 * v9fs_get_fsgid_for_create - Helper function to get the gid for creating a
56 * new file system object. This checks the S_ISGID to determine the owning
57 * group of the new file system object.
58 */
59
60static gid_t v9fs_get_fsgid_for_create(struct inode *dir_inode)
61{
62 BUG_ON(dir_inode == NULL);
63
64 if (dir_inode->i_mode & S_ISGID) {
65 /* set_gid bit is set.*/
66 return dir_inode->i_gid;
67 }
68 return current_fsgid();
69}
70
71/**
72 * v9fs_dentry_from_dir_inode - helper function to get the dentry from
73 * dir inode.
74 *
75 */
76
77static struct dentry *v9fs_dentry_from_dir_inode(struct inode *inode)
78{
79 struct dentry *dentry;
80
81 spin_lock(&inode->i_lock);
82 /* Directory should have only one entry. */
83 BUG_ON(S_ISDIR(inode->i_mode) && !list_is_singular(&inode->i_dentry));
84 dentry = list_entry(inode->i_dentry.next, struct dentry, d_alias);
85 spin_unlock(&inode->i_lock);
86 return dentry;
87}
88
5ffc0cb3
AK
89static 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;
125error:
126 unlock_new_inode(inode);
127 iput(inode);
128 return ERR_PTR(retval);
129
130}
131
53c06f4e 132struct inode *
a78ce05d
AK
133v9fs_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
157static int
158v9fs_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
275error:
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
291static 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);
b271ec47 374 inc_nlink(dir);
53c06f4e
AK
375error:
376 if (fid)
377 p9_client_clunk(fid);
378 return err;
379}
380
381static int
382v9fs_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
425int 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
3bc86de3 458 v9fs_invalidate_inode_attr(dentry->d_inode);
53c06f4e
AK
459 if ((iattr->ia_valid & ATTR_SIZE) &&
460 iattr->ia_size != i_size_read(dentry->d_inode)) {
461 retval = vmtruncate(dentry->d_inode, iattr->ia_size);
462 if (retval)
463 return retval;
464 }
465
466 setattr_copy(dentry->d_inode, iattr);
467 mark_inode_dirty(dentry->d_inode);
468 if (iattr->ia_valid & ATTR_MODE) {
469 /* We also want to update ACL when we update mode bits */
470 retval = v9fs_acl_chmod(dentry);
471 if (retval < 0)
472 return retval;
473 }
474 return 0;
475}
476
477/**
478 * v9fs_stat2inode_dotl - populate an inode structure with stat info
479 * @stat: stat structure
480 * @inode: inode to populate
481 * @sb: superblock of filesystem
482 *
483 */
484
485void
486v9fs_stat2inode_dotl(struct p9_stat_dotl *stat, struct inode *inode)
487{
b3cbea03 488 struct v9fs_inode *v9inode = V9FS_I(inode);
53c06f4e
AK
489
490 if ((stat->st_result_mask & P9_STATS_BASIC) == P9_STATS_BASIC) {
491 inode->i_atime.tv_sec = stat->st_atime_sec;
492 inode->i_atime.tv_nsec = stat->st_atime_nsec;
493 inode->i_mtime.tv_sec = stat->st_mtime_sec;
494 inode->i_mtime.tv_nsec = stat->st_mtime_nsec;
495 inode->i_ctime.tv_sec = stat->st_ctime_sec;
496 inode->i_ctime.tv_nsec = stat->st_ctime_nsec;
497 inode->i_uid = stat->st_uid;
498 inode->i_gid = stat->st_gid;
499 inode->i_nlink = stat->st_nlink;
500 inode->i_mode = stat->st_mode;
501 inode->i_rdev = new_decode_dev(stat->st_rdev);
502
503 if ((S_ISBLK(inode->i_mode)) || (S_ISCHR(inode->i_mode)))
504 init_special_inode(inode, inode->i_mode, inode->i_rdev);
505
506 i_size_write(inode, stat->st_size);
507 inode->i_blocks = stat->st_blocks;
508 } else {
509 if (stat->st_result_mask & P9_STATS_ATIME) {
510 inode->i_atime.tv_sec = stat->st_atime_sec;
511 inode->i_atime.tv_nsec = stat->st_atime_nsec;
512 }
513 if (stat->st_result_mask & P9_STATS_MTIME) {
514 inode->i_mtime.tv_sec = stat->st_mtime_sec;
515 inode->i_mtime.tv_nsec = stat->st_mtime_nsec;
516 }
517 if (stat->st_result_mask & P9_STATS_CTIME) {
518 inode->i_ctime.tv_sec = stat->st_ctime_sec;
519 inode->i_ctime.tv_nsec = stat->st_ctime_nsec;
520 }
521 if (stat->st_result_mask & P9_STATS_UID)
522 inode->i_uid = stat->st_uid;
523 if (stat->st_result_mask & P9_STATS_GID)
524 inode->i_gid = stat->st_gid;
525 if (stat->st_result_mask & P9_STATS_NLINK)
526 inode->i_nlink = stat->st_nlink;
527 if (stat->st_result_mask & P9_STATS_MODE) {
528 inode->i_mode = stat->st_mode;
529 if ((S_ISBLK(inode->i_mode)) ||
530 (S_ISCHR(inode->i_mode)))
531 init_special_inode(inode, inode->i_mode,
532 inode->i_rdev);
533 }
534 if (stat->st_result_mask & P9_STATS_RDEV)
535 inode->i_rdev = new_decode_dev(stat->st_rdev);
536 if (stat->st_result_mask & P9_STATS_SIZE)
537 i_size_write(inode, stat->st_size);
538 if (stat->st_result_mask & P9_STATS_BLOCKS)
539 inode->i_blocks = stat->st_blocks;
540 }
541 if (stat->st_result_mask & P9_STATS_GEN)
542 inode->i_generation = stat->st_gen;
543
544 /* Currently we don't support P9_STATS_BTIME and P9_STATS_DATA_VERSION
545 * because the inode structure does not have fields for them.
546 */
b3cbea03 547 v9inode->cache_validity &= ~V9FS_INO_INVALID_ATTR;
53c06f4e
AK
548}
549
550static int
551v9fs_vfs_symlink_dotl(struct inode *dir, struct dentry *dentry,
552 const char *symname)
553{
554 struct v9fs_session_info *v9ses;
555 struct p9_fid *dfid;
556 struct p9_fid *fid = NULL;
557 struct inode *inode;
558 struct p9_qid qid;
559 char *name;
560 int err;
561 gid_t gid;
562
563 name = (char *) dentry->d_name.name;
564 P9_DPRINTK(P9_DEBUG_VFS, "v9fs_vfs_symlink_dotl : %lu,%s,%s\n",
565 dir->i_ino, name, symname);
566 v9ses = v9fs_inode2v9ses(dir);
567
568 dfid = v9fs_fid_lookup(dentry->d_parent);
569 if (IS_ERR(dfid)) {
570 err = PTR_ERR(dfid);
571 P9_DPRINTK(P9_DEBUG_VFS, "fid lookup failed %d\n", err);
572 return err;
573 }
574
575 gid = v9fs_get_fsgid_for_create(dir);
576
577 /* Server doesn't alter fid on TSYMLINK. Hence no need to clone it. */
578 err = p9_client_symlink(dfid, name, (char *)symname, gid, &qid);
579
580 if (err < 0) {
581 P9_DPRINTK(P9_DEBUG_VFS, "p9_client_symlink failed %d\n", err);
582 goto error;
583 }
584
585 if (v9ses->cache) {
586 /* Now walk from the parent so we can get an unopened fid. */
587 fid = p9_client_walk(dfid, 1, &name, 1);
588 if (IS_ERR(fid)) {
589 err = PTR_ERR(fid);
590 P9_DPRINTK(P9_DEBUG_VFS, "p9_client_walk failed %d\n",
591 err);
592 fid = NULL;
593 goto error;
594 }
595
596 /* instantiate inode and assign the unopened fid to dentry */
a78ce05d 597 inode = v9fs_get_inode_from_fid(v9ses, fid, dir->i_sb);
53c06f4e
AK
598 if (IS_ERR(inode)) {
599 err = PTR_ERR(inode);
600 P9_DPRINTK(P9_DEBUG_VFS, "inode creation failed %d\n",
601 err);
602 goto error;
603 }
53c06f4e
AK
604 d_instantiate(dentry, inode);
605 err = v9fs_fid_add(dentry, fid);
606 if (err < 0)
607 goto error;
608 fid = NULL;
609 } else {
610 /* Not in cached mode. No need to populate inode with stat */
611 inode = v9fs_get_inode(dir->i_sb, S_IFLNK);
612 if (IS_ERR(inode)) {
613 err = PTR_ERR(inode);
614 goto error;
615 }
53c06f4e
AK
616 d_instantiate(dentry, inode);
617 }
618
619error:
620 if (fid)
621 p9_client_clunk(fid);
622
623 return err;
624}
625
626/**
627 * v9fs_vfs_link_dotl - create a hardlink for dotl
628 * @old_dentry: dentry for file to link to
629 * @dir: inode destination for new link
630 * @dentry: dentry for link
631 *
632 */
633
634static int
635v9fs_vfs_link_dotl(struct dentry *old_dentry, struct inode *dir,
636 struct dentry *dentry)
637{
638 int err;
639 struct p9_fid *dfid, *oldfid;
640 char *name;
641 struct v9fs_session_info *v9ses;
642 struct dentry *dir_dentry;
643
644 P9_DPRINTK(P9_DEBUG_VFS, "dir ino: %lu, old_name: %s, new_name: %s\n",
645 dir->i_ino, old_dentry->d_name.name,
646 dentry->d_name.name);
647
648 v9ses = v9fs_inode2v9ses(dir);
649 dir_dentry = v9fs_dentry_from_dir_inode(dir);
650 dfid = v9fs_fid_lookup(dir_dentry);
651 if (IS_ERR(dfid))
652 return PTR_ERR(dfid);
653
654 oldfid = v9fs_fid_lookup(old_dentry);
655 if (IS_ERR(oldfid))
656 return PTR_ERR(oldfid);
657
658 name = (char *) dentry->d_name.name;
659
660 err = p9_client_link(dfid, oldfid, (char *)dentry->d_name.name);
661
662 if (err < 0) {
663 P9_DPRINTK(P9_DEBUG_VFS, "p9_client_link failed %d\n", err);
664 return err;
665 }
666
667 if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) {
668 /* Get the latest stat info from server. */
669 struct p9_fid *fid;
670 struct p9_stat_dotl *st;
671
672 fid = v9fs_fid_lookup(old_dentry);
673 if (IS_ERR(fid))
674 return PTR_ERR(fid);
675
676 st = p9_client_getattr_dotl(fid, P9_STATS_BASIC);
677 if (IS_ERR(st))
678 return PTR_ERR(st);
679
680 v9fs_stat2inode_dotl(st, old_dentry->d_inode);
681
682 kfree(st);
53c06f4e 683 }
20656a49 684 ihold(old_dentry->d_inode);
53c06f4e
AK
685 d_instantiate(dentry, old_dentry->d_inode);
686
687 return err;
688}
689
690/**
691 * v9fs_vfs_mknod_dotl - create a special file
692 * @dir: inode destination for new link
693 * @dentry: dentry for file
694 * @mode: mode for creation
695 * @rdev: device associated with special file
696 *
697 */
698static int
699v9fs_vfs_mknod_dotl(struct inode *dir, struct dentry *dentry, int omode,
700 dev_t rdev)
701{
702 int err;
703 char *name;
704 mode_t mode;
705 struct v9fs_session_info *v9ses;
706 struct p9_fid *fid = NULL, *dfid = NULL;
707 struct inode *inode;
708 gid_t gid;
709 struct p9_qid qid;
710 struct dentry *dir_dentry;
711 struct posix_acl *dacl = NULL, *pacl = NULL;
712
713 P9_DPRINTK(P9_DEBUG_VFS,
714 " %lu,%s mode: %x MAJOR: %u MINOR: %u\n", dir->i_ino,
715 dentry->d_name.name, omode, MAJOR(rdev), MINOR(rdev));
716
717 if (!new_valid_dev(rdev))
718 return -EINVAL;
719
720 v9ses = v9fs_inode2v9ses(dir);
721 dir_dentry = v9fs_dentry_from_dir_inode(dir);
722 dfid = v9fs_fid_lookup(dir_dentry);
723 if (IS_ERR(dfid)) {
724 err = PTR_ERR(dfid);
725 P9_DPRINTK(P9_DEBUG_VFS, "fid lookup failed %d\n", err);
726 dfid = NULL;
727 goto error;
728 }
729
730 gid = v9fs_get_fsgid_for_create(dir);
731 mode = omode;
732 /* Update mode based on ACL value */
733 err = v9fs_acl_mode(dir, &mode, &dacl, &pacl);
734 if (err) {
735 P9_DPRINTK(P9_DEBUG_VFS,
736 "Failed to get acl values in mknod %d\n", err);
737 goto error;
738 }
739 name = (char *) dentry->d_name.name;
740
741 err = p9_client_mknod_dotl(dfid, name, mode, rdev, gid, &qid);
742 if (err < 0)
743 goto error;
744
745 /* instantiate inode and assign the unopened fid to the dentry */
746 if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) {
747 fid = p9_client_walk(dfid, 1, &name, 1);
748 if (IS_ERR(fid)) {
749 err = PTR_ERR(fid);
750 P9_DPRINTK(P9_DEBUG_VFS, "p9_client_walk failed %d\n",
751 err);
752 fid = NULL;
753 goto error;
754 }
755
a78ce05d 756 inode = v9fs_get_inode_from_fid(v9ses, fid, dir->i_sb);
53c06f4e
AK
757 if (IS_ERR(inode)) {
758 err = PTR_ERR(inode);
759 P9_DPRINTK(P9_DEBUG_VFS, "inode creation failed %d\n",
760 err);
761 goto error;
762 }
53c06f4e
AK
763 d_instantiate(dentry, inode);
764 err = v9fs_fid_add(dentry, fid);
765 if (err < 0)
766 goto error;
767 fid = NULL;
768 } else {
769 /*
770 * Not in cached mode. No need to populate inode with stat.
771 * socket syscall returns a fd, so we need instantiate
772 */
773 inode = v9fs_get_inode(dir->i_sb, mode);
774 if (IS_ERR(inode)) {
775 err = PTR_ERR(inode);
776 goto error;
777 }
53c06f4e
AK
778 d_instantiate(dentry, inode);
779 }
780 /* Now set the ACL based on the default value */
781 v9fs_set_create_acl(dentry, dacl, pacl);
782error:
783 if (fid)
784 p9_client_clunk(fid);
785 return err;
786}
787
53c06f4e
AK
788/**
789 * v9fs_vfs_follow_link_dotl - follow a symlink path
790 * @dentry: dentry for symlink
791 * @nd: nameidata
792 *
793 */
794
795static void *
796v9fs_vfs_follow_link_dotl(struct dentry *dentry, struct nameidata *nd)
797{
31b6ceac
MK
798 int retval;
799 struct p9_fid *fid;
53c06f4e 800 char *link = __getname();
31b6ceac 801 char *target;
53c06f4e 802
31b6ceac 803 P9_DPRINTK(P9_DEBUG_VFS, "%s\n", dentry->d_name.name);
53c06f4e 804
31b6ceac 805 if (!link) {
53c06f4e 806 link = ERR_PTR(-ENOMEM);
31b6ceac 807 goto ndset;
53c06f4e 808 }
31b6ceac
MK
809 fid = v9fs_fid_lookup(dentry);
810 if (IS_ERR(fid)) {
811 __putname(link);
812 link = ERR_PTR(PTR_ERR(fid));
813 goto ndset;
814 }
815 retval = p9_client_readlink(fid, &target);
816 if (!retval) {
817 strcpy(link, target);
818 kfree(target);
819 goto ndset;
820 }
821 __putname(link);
822 link = ERR_PTR(retval);
823ndset:
53c06f4e 824 nd_set_link(nd, link);
53c06f4e
AK
825 return NULL;
826}
827
b3cbea03
AK
828int v9fs_refresh_inode_dotl(struct p9_fid *fid, struct inode *inode)
829{
830 loff_t i_size;
831 struct p9_stat_dotl *st;
832 struct v9fs_session_info *v9ses;
833
834 v9ses = v9fs_inode2v9ses(inode);
835 st = p9_client_getattr_dotl(fid, P9_STATS_ALL);
836 if (IS_ERR(st))
837 return PTR_ERR(st);
838
839 spin_lock(&inode->i_lock);
840 /*
841 * We don't want to refresh inode->i_size,
842 * because we may have cached data
843 */
844 i_size = inode->i_size;
845 v9fs_stat2inode_dotl(st, inode);
846 if (v9ses->cache)
847 inode->i_size = i_size;
848 spin_unlock(&inode->i_lock);
849 kfree(st);
850 return 0;
851}
852
53c06f4e
AK
853const struct inode_operations v9fs_dir_inode_operations_dotl = {
854 .create = v9fs_vfs_create_dotl,
855 .lookup = v9fs_vfs_lookup,
856 .link = v9fs_vfs_link_dotl,
857 .symlink = v9fs_vfs_symlink_dotl,
858 .unlink = v9fs_vfs_unlink,
859 .mkdir = v9fs_vfs_mkdir_dotl,
860 .rmdir = v9fs_vfs_rmdir,
861 .mknod = v9fs_vfs_mknod_dotl,
862 .rename = v9fs_vfs_rename,
863 .getattr = v9fs_vfs_getattr_dotl,
864 .setattr = v9fs_vfs_setattr_dotl,
865 .setxattr = generic_setxattr,
866 .getxattr = generic_getxattr,
867 .removexattr = generic_removexattr,
868 .listxattr = v9fs_listxattr,
869 .check_acl = v9fs_check_acl,
870};
871
872const struct inode_operations v9fs_file_inode_operations_dotl = {
873 .getattr = v9fs_vfs_getattr_dotl,
874 .setattr = v9fs_vfs_setattr_dotl,
875 .setxattr = generic_setxattr,
876 .getxattr = generic_getxattr,
877 .removexattr = generic_removexattr,
878 .listxattr = v9fs_listxattr,
879 .check_acl = v9fs_check_acl,
880};
881
882const struct inode_operations v9fs_symlink_inode_operations_dotl = {
31b6ceac 883 .readlink = generic_readlink,
53c06f4e
AK
884 .follow_link = v9fs_vfs_follow_link_dotl,
885 .put_link = v9fs_vfs_put_link,
886 .getattr = v9fs_vfs_getattr_dotl,
887 .setattr = v9fs_vfs_setattr_dotl,
888 .setxattr = generic_setxattr,
889 .getxattr = generic_getxattr,
890 .removexattr = generic_removexattr,
891 .listxattr = v9fs_listxattr,
892};