aboutsummaryrefslogtreecommitdiffstats
path: root/fs/9p/vfs_inode.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/9p/vfs_inode.c')
-rw-r--r--fs/9p/vfs_inode.c1071
1 files changed, 238 insertions, 833 deletions
diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
index 9e670d527646..7f6c67703195 100644
--- a/fs/9p/vfs_inode.c
+++ b/fs/9p/vfs_inode.c
@@ -36,6 +36,7 @@
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 <linux/xattr.h>
39#include <linux/posix_acl.h>
39#include <net/9p/9p.h> 40#include <net/9p/9p.h>
40#include <net/9p/client.h> 41#include <net/9p/client.h>
41 42
@@ -44,14 +45,12 @@
44#include "fid.h" 45#include "fid.h"
45#include "cache.h" 46#include "cache.h"
46#include "xattr.h" 47#include "xattr.h"
48#include "acl.h"
47 49
48static const struct inode_operations v9fs_dir_inode_operations; 50static const struct inode_operations v9fs_dir_inode_operations;
49static const struct inode_operations v9fs_dir_inode_operations_dotu; 51static const struct inode_operations v9fs_dir_inode_operations_dotu;
50static const struct inode_operations v9fs_dir_inode_operations_dotl;
51static const struct inode_operations v9fs_file_inode_operations; 52static const struct inode_operations v9fs_file_inode_operations;
52static const struct inode_operations v9fs_file_inode_operations_dotl;
53static const struct inode_operations v9fs_symlink_inode_operations; 53static const struct inode_operations v9fs_symlink_inode_operations;
54static const struct inode_operations v9fs_symlink_inode_operations_dotl;
55 54
56/** 55/**
57 * unixmode2p9mode - convert unix mode bits to plan 9 56 * unixmode2p9mode - convert unix mode bits to plan 9
@@ -204,26 +203,26 @@ v9fs_blank_wstat(struct p9_wstat *wstat)
204 wstat->extension = NULL; 203 wstat->extension = NULL;
205} 204}
206 205
207#ifdef CONFIG_9P_FSCACHE
208/** 206/**
209 * v9fs_alloc_inode - helper function to allocate an inode 207 * v9fs_alloc_inode - helper function to allocate an inode
210 * This callback is executed before setting up the inode so that we
211 * can associate a vcookie with each inode.
212 * 208 *
213 */ 209 */
214
215struct inode *v9fs_alloc_inode(struct super_block *sb) 210struct inode *v9fs_alloc_inode(struct super_block *sb)
216{ 211{
217 struct v9fs_cookie *vcookie; 212 struct v9fs_inode *v9inode;
218 vcookie = (struct v9fs_cookie *)kmem_cache_alloc(vcookie_cache, 213 v9inode = (struct v9fs_inode *)kmem_cache_alloc(v9fs_inode_cache,
219 GFP_KERNEL); 214 GFP_KERNEL);
220 if (!vcookie) 215 if (!v9inode)
221 return NULL; 216 return NULL;
222 217#ifdef CONFIG_9P_FSCACHE
223 vcookie->fscache = NULL; 218 v9inode->fscache = NULL;
224 vcookie->qid = NULL; 219 v9inode->fscache_key = NULL;
225 spin_lock_init(&vcookie->lock); 220 spin_lock_init(&v9inode->fscache_lock);
226 return &vcookie->inode; 221#endif
222 v9inode->writeback_fid = NULL;
223 v9inode->cache_validity = 0;
224 mutex_init(&v9inode->v_mutex);
225 return &v9inode->vfs_inode;
227} 226}
228 227
229/** 228/**
@@ -231,67 +230,22 @@ struct inode *v9fs_alloc_inode(struct super_block *sb)
231 * 230 *
232 */ 231 */
233 232
234void v9fs_destroy_inode(struct inode *inode) 233static void v9fs_i_callback(struct rcu_head *head)
235{
236 kmem_cache_free(vcookie_cache, v9fs_inode2cookie(inode));
237}
238#endif
239
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{ 234{
248 BUG_ON(dir_inode == NULL); 235 struct inode *inode = container_of(head, struct inode, i_rcu);
249 236 INIT_LIST_HEAD(&inode->i_dentry);
250 if (dir_inode->i_mode & S_ISGID) { 237 kmem_cache_free(v9fs_inode_cache, V9FS_I(inode));
251 /* set_gid bit is set.*/
252 return dir_inode->i_gid;
253 }
254 return current_fsgid();
255} 238}
256 239
257/** 240void v9fs_destroy_inode(struct inode *inode)
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{ 241{
265 struct dentry *dentry; 242 call_rcu(&inode->i_rcu, v9fs_i_callback);
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} 243}
274 244
275/** 245int v9fs_init_inode(struct v9fs_session_info *v9ses,
276 * v9fs_get_inode - helper function to setup an inode 246 struct inode *inode, int mode)
277 * @sb: superblock
278 * @mode: mode to setup inode with
279 *
280 */
281
282struct inode *v9fs_get_inode(struct super_block *sb, int mode)
283{ 247{
284 int err; 248 int err = 0;
285 struct inode *inode;
286 struct v9fs_session_info *v9ses = sb->s_fs_info;
287
288 P9_DPRINTK(P9_DEBUG_VFS, "super block: %p mode: %o\n", sb, mode);
289
290 inode = new_inode(sb);
291 if (!inode) {
292 P9_EPRINTK(KERN_WARNING, "Problem allocating inode\n");
293 return ERR_PTR(-ENOMEM);
294 }
295 249
296 inode_init_owner(inode, NULL, mode); 250 inode_init_owner(inode, NULL, mode);
297 inode->i_blocks = 0; 251 inode->i_blocks = 0;
@@ -321,14 +275,20 @@ struct inode *v9fs_get_inode(struct super_block *sb, int mode)
321 case S_IFREG: 275 case S_IFREG:
322 if (v9fs_proto_dotl(v9ses)) { 276 if (v9fs_proto_dotl(v9ses)) {
323 inode->i_op = &v9fs_file_inode_operations_dotl; 277 inode->i_op = &v9fs_file_inode_operations_dotl;
324 inode->i_fop = &v9fs_file_operations_dotl; 278 if (v9ses->cache)
279 inode->i_fop =
280 &v9fs_cached_file_operations_dotl;
281 else
282 inode->i_fop = &v9fs_file_operations_dotl;
325 } else { 283 } else {
326 inode->i_op = &v9fs_file_inode_operations; 284 inode->i_op = &v9fs_file_inode_operations;
327 inode->i_fop = &v9fs_file_operations; 285 if (v9ses->cache)
286 inode->i_fop = &v9fs_cached_file_operations;
287 else
288 inode->i_fop = &v9fs_file_operations;
328 } 289 }
329 290
330 break; 291 break;
331
332 case S_IFLNK: 292 case S_IFLNK:
333 if (!v9fs_proto_dotu(v9ses) && !v9fs_proto_dotl(v9ses)) { 293 if (!v9fs_proto_dotu(v9ses) && !v9fs_proto_dotl(v9ses)) {
334 P9_DPRINTK(P9_DEBUG_ERROR, "extended modes used with " 294 P9_DPRINTK(P9_DEBUG_ERROR, "extended modes used with "
@@ -364,12 +324,37 @@ struct inode *v9fs_get_inode(struct super_block *sb, int mode)
364 err = -EINVAL; 324 err = -EINVAL;
365 goto error; 325 goto error;
366 } 326 }
327error:
328 return err;
367 329
368 return inode; 330}
369 331
370error: 332/**
371 iput(inode); 333 * v9fs_get_inode - helper function to setup an inode
372 return ERR_PTR(err); 334 * @sb: superblock
335 * @mode: mode to setup inode with
336 *
337 */
338
339struct inode *v9fs_get_inode(struct super_block *sb, int mode)
340{
341 int err;
342 struct inode *inode;
343 struct v9fs_session_info *v9ses = sb->s_fs_info;
344
345 P9_DPRINTK(P9_DEBUG_VFS, "super block: %p mode: %o\n", sb, mode);
346
347 inode = new_inode(sb);
348 if (!inode) {
349 P9_EPRINTK(KERN_WARNING, "Problem allocating inode\n");
350 return ERR_PTR(-ENOMEM);
351 }
352 err = v9fs_init_inode(v9ses, inode, mode);
353 if (err) {
354 iput(inode);
355 return ERR_PTR(err);
356 }
357 return inode;
373} 358}
374 359
375/* 360/*
@@ -432,6 +417,8 @@ error:
432 */ 417 */
433void v9fs_evict_inode(struct inode *inode) 418void v9fs_evict_inode(struct inode *inode)
434{ 419{
420 struct v9fs_inode *v9inode = V9FS_I(inode);
421
435 truncate_inode_pages(inode->i_mapping, 0); 422 truncate_inode_pages(inode->i_mapping, 0);
436 end_writeback(inode); 423 end_writeback(inode);
437 filemap_fdatawrite(inode->i_mapping); 424 filemap_fdatawrite(inode->i_mapping);
@@ -439,90 +426,67 @@ void v9fs_evict_inode(struct inode *inode)
439#ifdef CONFIG_9P_FSCACHE 426#ifdef CONFIG_9P_FSCACHE
440 v9fs_cache_inode_put_cookie(inode); 427 v9fs_cache_inode_put_cookie(inode);
441#endif 428#endif
429 /* clunk the fid stashed in writeback_fid */
430 if (v9inode->writeback_fid) {
431 p9_client_clunk(v9inode->writeback_fid);
432 v9inode->writeback_fid = NULL;
433 }
442} 434}
443 435
444static struct inode * 436static struct inode *v9fs_qid_iget(struct super_block *sb,
445v9fs_inode(struct v9fs_session_info *v9ses, struct p9_fid *fid, 437 struct p9_qid *qid,
446 struct super_block *sb) 438 struct p9_wstat *st)
447{ 439{
448 int err, umode; 440 int retval, umode;
449 struct inode *ret = NULL; 441 unsigned long i_ino;
450 struct p9_wstat *st; 442 struct inode *inode;
451 443 struct v9fs_session_info *v9ses = sb->s_fs_info;
452 st = p9_client_stat(fid);
453 if (IS_ERR(st))
454 return ERR_CAST(st);
455 444
445 i_ino = v9fs_qid2ino(qid);
446 inode = iget_locked(sb, i_ino);
447 if (!inode)
448 return ERR_PTR(-ENOMEM);
449 if (!(inode->i_state & I_NEW))
450 return inode;
451 /*
452 * initialize the inode with the stat info
453 * FIXME!! we may need support for stale inodes
454 * later.
455 */
456 umode = p9mode2unixmode(v9ses, st->mode); 456 umode = p9mode2unixmode(v9ses, st->mode);
457 ret = v9fs_get_inode(sb, umode); 457 retval = v9fs_init_inode(v9ses, inode, umode);
458 if (IS_ERR(ret)) { 458 if (retval)
459 err = PTR_ERR(ret);
460 goto error; 459 goto error;
461 }
462
463 v9fs_stat2inode(st, ret, sb);
464 ret->i_ino = v9fs_qid2ino(&st->qid);
465 460
461 v9fs_stat2inode(st, inode, sb);
466#ifdef CONFIG_9P_FSCACHE 462#ifdef CONFIG_9P_FSCACHE
467 v9fs_vcookie_set_qid(ret, &st->qid); 463 v9fs_fscache_set_key(inode, &st->qid);
468 v9fs_cache_inode_get_cookie(ret); 464 v9fs_cache_inode_get_cookie(inode);
469#endif 465#endif
470 p9stat_free(st); 466 unlock_new_inode(inode);
471 kfree(st); 467 return inode;
472 return ret;
473error: 468error:
474 p9stat_free(st); 469 unlock_new_inode(inode);
475 kfree(st); 470 iput(inode);
476 return ERR_PTR(err); 471 return ERR_PTR(retval);
472
477} 473}
478 474
479static struct inode * 475struct inode *
480v9fs_inode_dotl(struct v9fs_session_info *v9ses, struct p9_fid *fid, 476v9fs_inode_from_fid(struct v9fs_session_info *v9ses, struct p9_fid *fid,
481 struct super_block *sb) 477 struct super_block *sb)
482{ 478{
483 struct inode *ret = NULL; 479 struct p9_wstat *st;
484 int err; 480 struct inode *inode = NULL;
485 struct p9_stat_dotl *st;
486 481
487 st = p9_client_getattr_dotl(fid, P9_STATS_BASIC); 482 st = p9_client_stat(fid);
488 if (IS_ERR(st)) 483 if (IS_ERR(st))
489 return ERR_CAST(st); 484 return ERR_CAST(st);
490 485
491 ret = v9fs_get_inode(sb, st->st_mode); 486 inode = v9fs_qid_iget(sb, &st->qid, st);
492 if (IS_ERR(ret)) { 487 p9stat_free(st);
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); 488 kfree(st);
507 return ERR_PTR(err); 489 return inode;
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} 490}
527 491
528/** 492/**
@@ -536,8 +500,8 @@ v9fs_inode_from_fid(struct v9fs_session_info *v9ses, struct p9_fid *fid,
536static int v9fs_remove(struct inode *dir, struct dentry *file, int rmdir) 500static int v9fs_remove(struct inode *dir, struct dentry *file, int rmdir)
537{ 501{
538 int retval; 502 int retval;
539 struct inode *file_inode;
540 struct p9_fid *v9fid; 503 struct p9_fid *v9fid;
504 struct inode *file_inode;
541 505
542 P9_DPRINTK(P9_DEBUG_VFS, "inode: %p dentry: %p rmdir: %d\n", dir, file, 506 P9_DPRINTK(P9_DEBUG_VFS, "inode: %p dentry: %p rmdir: %d\n", dir, file,
543 rmdir); 507 rmdir);
@@ -548,18 +512,23 @@ static int v9fs_remove(struct inode *dir, struct dentry *file, int rmdir)
548 return PTR_ERR(v9fid); 512 return PTR_ERR(v9fid);
549 513
550 retval = p9_client_remove(v9fid); 514 retval = p9_client_remove(v9fid);
551 if (!retval) 515 if (!retval) {
552 drop_nlink(file_inode); 516 /*
553 return retval; 517 * directories on unlink should have zero
554} 518 * link count
519 */
520 if (rmdir) {
521 clear_nlink(file_inode);
522 drop_nlink(dir);
523 } else
524 drop_nlink(file_inode);
555 525
556static int 526 v9fs_invalidate_inode_attr(file_inode);
557v9fs_open_created(struct inode *inode, struct file *file) 527 v9fs_invalidate_inode_attr(dir);
558{ 528 }
559 return 0; 529 return retval;
560} 530}
561 531
562
563/** 532/**
564 * v9fs_create - Create a file 533 * v9fs_create - Create a file
565 * @v9ses: session information 534 * @v9ses: session information
@@ -616,18 +585,12 @@ v9fs_create(struct v9fs_session_info *v9ses, struct inode *dir,
616 } 585 }
617 586
618 /* instantiate inode and assign the unopened fid to the dentry */ 587 /* instantiate inode and assign the unopened fid to the dentry */
619 inode = v9fs_inode_from_fid(v9ses, fid, dir->i_sb); 588 inode = v9fs_get_inode_from_fid(v9ses, fid, dir->i_sb);
620 if (IS_ERR(inode)) { 589 if (IS_ERR(inode)) {
621 err = PTR_ERR(inode); 590 err = PTR_ERR(inode);
622 P9_DPRINTK(P9_DEBUG_VFS, "inode creation failed %d\n", err); 591 P9_DPRINTK(P9_DEBUG_VFS, "inode creation failed %d\n", err);
623 goto error; 592 goto error;
624 } 593 }
625
626 if (v9ses->cache)
627 dentry->d_op = &v9fs_cached_dentry_operations;
628 else
629 dentry->d_op = &v9fs_dentry_operations;
630
631 d_instantiate(dentry, inode); 594 d_instantiate(dentry, inode);
632 err = v9fs_fid_add(dentry, fid); 595 err = v9fs_fid_add(dentry, fid);
633 if (err < 0) 596 if (err < 0)
@@ -646,121 +609,6 @@ error:
646} 609}
647 610
648/** 611/**
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 if (v9ses->cache)
734 dentry->d_op = &v9fs_cached_dentry_operations;
735 else
736 dentry->d_op = &v9fs_dentry_operations;
737 d_instantiate(dentry, inode);
738 err = v9fs_fid_add(dentry, fid);
739 if (err < 0)
740 goto error;
741
742 /* if we are opening a file, assign the open fid to the file */
743 if (nd && nd->flags & LOOKUP_OPEN) {
744 filp = lookup_instantiate_filp(nd, dentry, v9fs_open_created);
745 if (IS_ERR(filp)) {
746 p9_client_clunk(ofid);
747 return PTR_ERR(filp);
748 }
749 filp->private_data = ofid;
750 } else
751 p9_client_clunk(ofid);
752
753 return 0;
754
755error:
756 if (ofid)
757 p9_client_clunk(ofid);
758 if (fid)
759 p9_client_clunk(fid);
760 return err;
761}
762
763/**
764 * v9fs_vfs_create - VFS hook to create files 612 * v9fs_vfs_create - VFS hook to create files
765 * @dir: directory inode that is being created 613 * @dir: directory inode that is being created
766 * @dentry: dentry that is being deleted 614 * @dentry: dentry that is being deleted
@@ -776,9 +624,10 @@ v9fs_vfs_create(struct inode *dir, struct dentry *dentry, int mode,
776 int err; 624 int err;
777 u32 perm; 625 u32 perm;
778 int flags; 626 int flags;
779 struct v9fs_session_info *v9ses;
780 struct p9_fid *fid;
781 struct file *filp; 627 struct file *filp;
628 struct v9fs_inode *v9inode;
629 struct v9fs_session_info *v9ses;
630 struct p9_fid *fid, *inode_fid;
782 631
783 err = 0; 632 err = 0;
784 fid = NULL; 633 fid = NULL;
@@ -798,15 +647,40 @@ v9fs_vfs_create(struct inode *dir, struct dentry *dentry, int mode,
798 goto error; 647 goto error;
799 } 648 }
800 649
650 v9fs_invalidate_inode_attr(dir);
801 /* if we are opening a file, assign the open fid to the file */ 651 /* if we are opening a file, assign the open fid to the file */
802 if (nd && nd->flags & LOOKUP_OPEN) { 652 if (nd && nd->flags & LOOKUP_OPEN) {
803 filp = lookup_instantiate_filp(nd, dentry, v9fs_open_created); 653 v9inode = V9FS_I(dentry->d_inode);
654 mutex_lock(&v9inode->v_mutex);
655 if (v9ses->cache && !v9inode->writeback_fid &&
656 ((flags & O_ACCMODE) != O_RDONLY)) {
657 /*
658 * clone a fid and add it to writeback_fid
659 * we do it during open time instead of
660 * page dirty time via write_begin/page_mkwrite
661 * because we want write after unlink usecase
662 * to work.
663 */
664 inode_fid = v9fs_writeback_fid(dentry);
665 if (IS_ERR(inode_fid)) {
666 err = PTR_ERR(inode_fid);
667 mutex_unlock(&v9inode->v_mutex);
668 goto error;
669 }
670 v9inode->writeback_fid = (void *) inode_fid;
671 }
672 mutex_unlock(&v9inode->v_mutex);
673 filp = lookup_instantiate_filp(nd, dentry, generic_file_open);
804 if (IS_ERR(filp)) { 674 if (IS_ERR(filp)) {
805 err = PTR_ERR(filp); 675 err = PTR_ERR(filp);
806 goto error; 676 goto error;
807 } 677 }
808 678
809 filp->private_data = fid; 679 filp->private_data = fid;
680#ifdef CONFIG_9P_FSCACHE
681 if (v9ses->cache)
682 v9fs_cache_inode_set_cookie(dentry->d_inode, filp);
683#endif
810 } else 684 } else
811 p9_client_clunk(fid); 685 p9_client_clunk(fid);
812 686
@@ -831,8 +705,8 @@ static int v9fs_vfs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
831{ 705{
832 int err; 706 int err;
833 u32 perm; 707 u32 perm;
834 struct v9fs_session_info *v9ses;
835 struct p9_fid *fid; 708 struct p9_fid *fid;
709 struct v9fs_session_info *v9ses;
836 710
837 P9_DPRINTK(P9_DEBUG_VFS, "name %s\n", dentry->d_name.name); 711 P9_DPRINTK(P9_DEBUG_VFS, "name %s\n", dentry->d_name.name);
838 err = 0; 712 err = 0;
@@ -842,6 +716,9 @@ static int v9fs_vfs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
842 if (IS_ERR(fid)) { 716 if (IS_ERR(fid)) {
843 err = PTR_ERR(fid); 717 err = PTR_ERR(fid);
844 fid = NULL; 718 fid = NULL;
719 } else {
720 inc_nlink(dir);
721 v9fs_invalidate_inode_attr(dir);
845 } 722 }
846 723
847 if (fid) 724 if (fid)
@@ -850,83 +727,6 @@ static int v9fs_vfs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
850 return err; 727 return err;
851} 728}
852 729
853
854/**
855 * v9fs_vfs_mkdir_dotl - VFS mkdir hook to create a directory
856 * @dir: inode that is being unlinked
857 * @dentry: dentry that is being unlinked
858 * @mode: mode for new directory
859 *
860 */
861
862static int v9fs_vfs_mkdir_dotl(struct inode *dir, struct dentry *dentry,
863 int mode)
864{
865 int err;
866 struct v9fs_session_info *v9ses;
867 struct p9_fid *fid = NULL, *dfid = NULL;
868 gid_t gid;
869 char *name;
870 struct inode *inode;
871 struct p9_qid qid;
872 struct dentry *dir_dentry;
873
874 P9_DPRINTK(P9_DEBUG_VFS, "name %s\n", dentry->d_name.name);
875 err = 0;
876 v9ses = v9fs_inode2v9ses(dir);
877
878 mode |= S_IFDIR;
879 dir_dentry = v9fs_dentry_from_dir_inode(dir);
880 dfid = v9fs_fid_lookup(dir_dentry);
881 if (IS_ERR(dfid)) {
882 err = PTR_ERR(dfid);
883 P9_DPRINTK(P9_DEBUG_VFS, "fid lookup failed %d\n", err);
884 dfid = NULL;
885 goto error;
886 }
887
888 gid = v9fs_get_fsgid_for_create(dir);
889 if (gid < 0) {
890 P9_DPRINTK(P9_DEBUG_VFS, "v9fs_get_fsgid_for_create failed\n");
891 goto error;
892 }
893
894 name = (char *) dentry->d_name.name;
895 err = p9_client_mkdir_dotl(dfid, name, mode, gid, &qid);
896 if (err < 0)
897 goto error;
898
899 /* instantiate inode and assign the unopened fid to the dentry */
900 if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) {
901 fid = p9_client_walk(dfid, 1, &name, 1);
902 if (IS_ERR(fid)) {
903 err = PTR_ERR(fid);
904 P9_DPRINTK(P9_DEBUG_VFS, "p9_client_walk failed %d\n",
905 err);
906 fid = NULL;
907 goto error;
908 }
909
910 inode = v9fs_inode_from_fid(v9ses, fid, dir->i_sb);
911 if (IS_ERR(inode)) {
912 err = PTR_ERR(inode);
913 P9_DPRINTK(P9_DEBUG_VFS, "inode creation failed %d\n",
914 err);
915 goto error;
916 }
917 dentry->d_op = &v9fs_cached_dentry_operations;
918 d_instantiate(dentry, inode);
919 err = v9fs_fid_add(dentry, fid);
920 if (err < 0)
921 goto error;
922 fid = NULL;
923 }
924error:
925 if (fid)
926 p9_client_clunk(fid);
927 return err;
928}
929
930/** 730/**
931 * v9fs_vfs_lookup - VFS lookup hook to "walk" to a new inode 731 * v9fs_vfs_lookup - VFS lookup hook to "walk" to a new inode
932 * @dir: inode that is being walked from 732 * @dir: inode that is being walked from
@@ -935,7 +735,7 @@ error:
935 * 735 *
936 */ 736 */
937 737
938static struct dentry *v9fs_vfs_lookup(struct inode *dir, struct dentry *dentry, 738struct dentry *v9fs_vfs_lookup(struct inode *dir, struct dentry *dentry,
939 struct nameidata *nameidata) 739 struct nameidata *nameidata)
940{ 740{
941 struct super_block *sb; 741 struct super_block *sb;
@@ -970,7 +770,7 @@ static struct dentry *v9fs_vfs_lookup(struct inode *dir, struct dentry *dentry,
970 return ERR_PTR(result); 770 return ERR_PTR(result);
971 } 771 }
972 772
973 inode = v9fs_inode_from_fid(v9ses, fid, dir->i_sb); 773 inode = v9fs_get_inode_from_fid(v9ses, fid, dir->i_sb);
974 if (IS_ERR(inode)) { 774 if (IS_ERR(inode)) {
975 result = PTR_ERR(inode); 775 result = PTR_ERR(inode);
976 inode = NULL; 776 inode = NULL;
@@ -979,17 +779,14 @@ static struct dentry *v9fs_vfs_lookup(struct inode *dir, struct dentry *dentry,
979 779
980 result = v9fs_fid_add(dentry, fid); 780 result = v9fs_fid_add(dentry, fid);
981 if (result < 0) 781 if (result < 0)
982 goto error; 782 goto error_iput;
983 783
984inst_out: 784inst_out:
985 if (v9ses->cache)
986 dentry->d_op = &v9fs_cached_dentry_operations;
987 else
988 dentry->d_op = &v9fs_dentry_operations;
989
990 d_add(dentry, inode); 785 d_add(dentry, inode);
991 return NULL; 786 return NULL;
992 787
788error_iput:
789 iput(inode);
993error: 790error:
994 p9_client_clunk(fid); 791 p9_client_clunk(fid);
995 792
@@ -1003,7 +800,7 @@ error:
1003 * 800 *
1004 */ 801 */
1005 802
1006static int v9fs_vfs_unlink(struct inode *i, struct dentry *d) 803int v9fs_vfs_unlink(struct inode *i, struct dentry *d)
1007{ 804{
1008 return v9fs_remove(i, d, 0); 805 return v9fs_remove(i, d, 0);
1009} 806}
@@ -1015,7 +812,7 @@ static int v9fs_vfs_unlink(struct inode *i, struct dentry *d)
1015 * 812 *
1016 */ 813 */
1017 814
1018static int v9fs_vfs_rmdir(struct inode *i, struct dentry *d) 815int v9fs_vfs_rmdir(struct inode *i, struct dentry *d)
1019{ 816{
1020 return v9fs_remove(i, d, 1); 817 return v9fs_remove(i, d, 1);
1021} 818}
@@ -1029,21 +826,23 @@ static int v9fs_vfs_rmdir(struct inode *i, struct dentry *d)
1029 * 826 *
1030 */ 827 */
1031 828
1032static int 829int
1033v9fs_vfs_rename(struct inode *old_dir, struct dentry *old_dentry, 830v9fs_vfs_rename(struct inode *old_dir, struct dentry *old_dentry,
1034 struct inode *new_dir, struct dentry *new_dentry) 831 struct inode *new_dir, struct dentry *new_dentry)
1035{ 832{
833 int retval;
1036 struct inode *old_inode; 834 struct inode *old_inode;
835 struct inode *new_inode;
1037 struct v9fs_session_info *v9ses; 836 struct v9fs_session_info *v9ses;
1038 struct p9_fid *oldfid; 837 struct p9_fid *oldfid;
1039 struct p9_fid *olddirfid; 838 struct p9_fid *olddirfid;
1040 struct p9_fid *newdirfid; 839 struct p9_fid *newdirfid;
1041 struct p9_wstat wstat; 840 struct p9_wstat wstat;
1042 int retval;
1043 841
1044 P9_DPRINTK(P9_DEBUG_VFS, "\n"); 842 P9_DPRINTK(P9_DEBUG_VFS, "\n");
1045 retval = 0; 843 retval = 0;
1046 old_inode = old_dentry->d_inode; 844 old_inode = old_dentry->d_inode;
845 new_inode = new_dentry->d_inode;
1047 v9ses = v9fs_inode2v9ses(old_inode); 846 v9ses = v9fs_inode2v9ses(old_inode);
1048 oldfid = v9fs_fid_lookup(old_dentry); 847 oldfid = v9fs_fid_lookup(old_dentry);
1049 if (IS_ERR(oldfid)) 848 if (IS_ERR(oldfid))
@@ -1084,9 +883,30 @@ v9fs_vfs_rename(struct inode *old_dir, struct dentry *old_dentry,
1084 retval = p9_client_wstat(oldfid, &wstat); 883 retval = p9_client_wstat(oldfid, &wstat);
1085 884
1086clunk_newdir: 885clunk_newdir:
1087 if (!retval) 886 if (!retval) {
887 if (new_inode) {
888 if (S_ISDIR(new_inode->i_mode))
889 clear_nlink(new_inode);
890 else
891 drop_nlink(new_inode);
892 /*
893 * Work around vfs rename rehash bug with
894 * FS_RENAME_DOES_D_MOVE
895 */
896 v9fs_invalidate_inode_attr(new_inode);
897 }
898 if (S_ISDIR(old_inode->i_mode)) {
899 if (!new_inode)
900 inc_nlink(new_dir);
901 drop_nlink(old_dir);
902 }
903 v9fs_invalidate_inode_attr(old_inode);
904 v9fs_invalidate_inode_attr(old_dir);
905 v9fs_invalidate_inode_attr(new_dir);
906
1088 /* successful rename */ 907 /* successful rename */
1089 d_move(old_dentry, new_dentry); 908 d_move(old_dentry, new_dentry);
909 }
1090 up_write(&v9ses->rename_sem); 910 up_write(&v9ses->rename_sem);
1091 p9_client_clunk(newdirfid); 911 p9_client_clunk(newdirfid);
1092 912
@@ -1116,10 +936,11 @@ v9fs_vfs_getattr(struct vfsmount *mnt, struct dentry *dentry,
1116 936
1117 P9_DPRINTK(P9_DEBUG_VFS, "dentry: %p\n", dentry); 937 P9_DPRINTK(P9_DEBUG_VFS, "dentry: %p\n", dentry);
1118 err = -EPERM; 938 err = -EPERM;
1119 v9ses = v9fs_inode2v9ses(dentry->d_inode); 939 v9ses = v9fs_dentry2v9ses(dentry);
1120 if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) 940 if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) {
1121 return simple_getattr(mnt, dentry, stat); 941 generic_fillattr(dentry->d_inode, stat);
1122 942 return 0;
943 }
1123 fid = v9fs_fid_lookup(dentry); 944 fid = v9fs_fid_lookup(dentry);
1124 if (IS_ERR(fid)) 945 if (IS_ERR(fid))
1125 return PTR_ERR(fid); 946 return PTR_ERR(fid);
@@ -1136,42 +957,6 @@ v9fs_vfs_getattr(struct vfsmount *mnt, struct dentry *dentry,
1136 return 0; 957 return 0;
1137} 958}
1138 959
1139static int
1140v9fs_vfs_getattr_dotl(struct vfsmount *mnt, struct dentry *dentry,
1141 struct kstat *stat)
1142{
1143 int err;
1144 struct v9fs_session_info *v9ses;
1145 struct p9_fid *fid;
1146 struct p9_stat_dotl *st;
1147
1148 P9_DPRINTK(P9_DEBUG_VFS, "dentry: %p\n", dentry);
1149 err = -EPERM;
1150 v9ses = v9fs_inode2v9ses(dentry->d_inode);
1151 if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE)
1152 return simple_getattr(mnt, dentry, stat);
1153
1154 fid = v9fs_fid_lookup(dentry);
1155 if (IS_ERR(fid))
1156 return PTR_ERR(fid);
1157
1158 /* Ask for all the fields in stat structure. Server will return
1159 * whatever it supports
1160 */
1161
1162 st = p9_client_getattr_dotl(fid, P9_STATS_ALL);
1163 if (IS_ERR(st))
1164 return PTR_ERR(st);
1165
1166 v9fs_stat2inode_dotl(st, dentry->d_inode);
1167 generic_fillattr(dentry->d_inode, stat);
1168 /* Change block size to what the server returned */
1169 stat->blksize = st->st_blksize;
1170
1171 kfree(st);
1172 return 0;
1173}
1174
1175/** 960/**
1176 * v9fs_vfs_setattr - set file metadata 961 * v9fs_vfs_setattr - set file metadata
1177 * @dentry: file whose metadata to set 962 * @dentry: file whose metadata to set
@@ -1187,8 +972,12 @@ static int v9fs_vfs_setattr(struct dentry *dentry, struct iattr *iattr)
1187 struct p9_wstat wstat; 972 struct p9_wstat wstat;
1188 973
1189 P9_DPRINTK(P9_DEBUG_VFS, "\n"); 974 P9_DPRINTK(P9_DEBUG_VFS, "\n");
975 retval = inode_change_ok(dentry->d_inode, iattr);
976 if (retval)
977 return retval;
978
1190 retval = -EPERM; 979 retval = -EPERM;
1191 v9ses = v9fs_inode2v9ses(dentry->d_inode); 980 v9ses = v9fs_dentry2v9ses(dentry);
1192 fid = v9fs_fid_lookup(dentry); 981 fid = v9fs_fid_lookup(dentry);
1193 if(IS_ERR(fid)) 982 if(IS_ERR(fid))
1194 return PTR_ERR(fid); 983 return PTR_ERR(fid);
@@ -1214,68 +1003,19 @@ static int v9fs_vfs_setattr(struct dentry *dentry, struct iattr *iattr)
1214 wstat.n_gid = iattr->ia_gid; 1003 wstat.n_gid = iattr->ia_gid;
1215 } 1004 }
1216 1005
1006 /* Write all dirty data */
1007 if (S_ISREG(dentry->d_inode->i_mode))
1008 filemap_write_and_wait(dentry->d_inode->i_mapping);
1009
1217 retval = p9_client_wstat(fid, &wstat); 1010 retval = p9_client_wstat(fid, &wstat);
1218 if (retval < 0) 1011 if (retval < 0)
1219 return retval; 1012 return retval;
1220 1013
1221 if ((iattr->ia_valid & ATTR_SIZE) && 1014 if ((iattr->ia_valid & ATTR_SIZE) &&
1222 iattr->ia_size != i_size_read(dentry->d_inode)) { 1015 iattr->ia_size != i_size_read(dentry->d_inode))
1223 retval = vmtruncate(dentry->d_inode, iattr->ia_size); 1016 truncate_setsize(dentry->d_inode, iattr->ia_size);
1224 if (retval)
1225 return retval;
1226 }
1227 1017
1228 setattr_copy(dentry->d_inode, iattr); 1018 v9fs_invalidate_inode_attr(dentry->d_inode);
1229 mark_inode_dirty(dentry->d_inode);
1230 return 0;
1231}
1232
1233/**
1234 * v9fs_vfs_setattr_dotl - set file metadata
1235 * @dentry: file whose metadata to set
1236 * @iattr: metadata assignment structure
1237 *
1238 */
1239
1240static int v9fs_vfs_setattr_dotl(struct dentry *dentry, struct iattr *iattr)
1241{
1242 int retval;
1243 struct v9fs_session_info *v9ses;
1244 struct p9_fid *fid;
1245 struct p9_iattr_dotl p9attr;
1246
1247 P9_DPRINTK(P9_DEBUG_VFS, "\n");
1248
1249 retval = inode_change_ok(dentry->d_inode, iattr);
1250 if (retval)
1251 return retval;
1252
1253 p9attr.valid = iattr->ia_valid;
1254 p9attr.mode = iattr->ia_mode;
1255 p9attr.uid = iattr->ia_uid;
1256 p9attr.gid = iattr->ia_gid;
1257 p9attr.size = iattr->ia_size;
1258 p9attr.atime_sec = iattr->ia_atime.tv_sec;
1259 p9attr.atime_nsec = iattr->ia_atime.tv_nsec;
1260 p9attr.mtime_sec = iattr->ia_mtime.tv_sec;
1261 p9attr.mtime_nsec = iattr->ia_mtime.tv_nsec;
1262
1263 retval = -EPERM;
1264 v9ses = v9fs_inode2v9ses(dentry->d_inode);
1265 fid = v9fs_fid_lookup(dentry);
1266 if (IS_ERR(fid))
1267 return PTR_ERR(fid);
1268
1269 retval = p9_client_setattr(fid, &p9attr);
1270 if (retval < 0)
1271 return retval;
1272
1273 if ((iattr->ia_valid & ATTR_SIZE) &&
1274 iattr->ia_size != i_size_read(dentry->d_inode)) {
1275 retval = vmtruncate(dentry->d_inode, iattr->ia_size);
1276 if (retval)
1277 return retval;
1278 }
1279 1019
1280 setattr_copy(dentry->d_inode, iattr); 1020 setattr_copy(dentry->d_inode, iattr);
1281 mark_inode_dirty(dentry->d_inode); 1021 mark_inode_dirty(dentry->d_inode);
@@ -1298,6 +1038,7 @@ v9fs_stat2inode(struct p9_wstat *stat, struct inode *inode,
1298 char tag_name[14]; 1038 char tag_name[14];
1299 unsigned int i_nlink; 1039 unsigned int i_nlink;
1300 struct v9fs_session_info *v9ses = sb->s_fs_info; 1040 struct v9fs_session_info *v9ses = sb->s_fs_info;
1041 struct v9fs_inode *v9inode = V9FS_I(inode);
1301 1042
1302 inode->i_nlink = 1; 1043 inode->i_nlink = 1;
1303 1044
@@ -1357,77 +1098,7 @@ v9fs_stat2inode(struct p9_wstat *stat, struct inode *inode,
1357 1098
1358 /* not real number of blocks, but 512 byte ones ... */ 1099 /* not real number of blocks, but 512 byte ones ... */
1359 inode->i_blocks = (i_size_read(inode) + 512 - 1) >> 9; 1100 inode->i_blocks = (i_size_read(inode) + 512 - 1) >> 9;
1360} 1101 v9inode->cache_validity &= ~V9FS_INO_INVALID_ATTR;
1361
1362/**
1363 * v9fs_stat2inode_dotl - populate an inode structure with stat info
1364 * @stat: stat structure
1365 * @inode: inode to populate
1366 * @sb: superblock of filesystem
1367 *
1368 */
1369
1370void
1371v9fs_stat2inode_dotl(struct p9_stat_dotl *stat, struct inode *inode)
1372{
1373
1374 if ((stat->st_result_mask & P9_STATS_BASIC) == P9_STATS_BASIC) {
1375 inode->i_atime.tv_sec = stat->st_atime_sec;
1376 inode->i_atime.tv_nsec = stat->st_atime_nsec;
1377 inode->i_mtime.tv_sec = stat->st_mtime_sec;
1378 inode->i_mtime.tv_nsec = stat->st_mtime_nsec;
1379 inode->i_ctime.tv_sec = stat->st_ctime_sec;
1380 inode->i_ctime.tv_nsec = stat->st_ctime_nsec;
1381 inode->i_uid = stat->st_uid;
1382 inode->i_gid = stat->st_gid;
1383 inode->i_nlink = stat->st_nlink;
1384 inode->i_mode = stat->st_mode;
1385 inode->i_rdev = new_decode_dev(stat->st_rdev);
1386
1387 if ((S_ISBLK(inode->i_mode)) || (S_ISCHR(inode->i_mode)))
1388 init_special_inode(inode, inode->i_mode, inode->i_rdev);
1389
1390 i_size_write(inode, stat->st_size);
1391 inode->i_blocks = stat->st_blocks;
1392 } else {
1393 if (stat->st_result_mask & P9_STATS_ATIME) {
1394 inode->i_atime.tv_sec = stat->st_atime_sec;
1395 inode->i_atime.tv_nsec = stat->st_atime_nsec;
1396 }
1397 if (stat->st_result_mask & P9_STATS_MTIME) {
1398 inode->i_mtime.tv_sec = stat->st_mtime_sec;
1399 inode->i_mtime.tv_nsec = stat->st_mtime_nsec;
1400 }
1401 if (stat->st_result_mask & P9_STATS_CTIME) {
1402 inode->i_ctime.tv_sec = stat->st_ctime_sec;
1403 inode->i_ctime.tv_nsec = stat->st_ctime_nsec;
1404 }
1405 if (stat->st_result_mask & P9_STATS_UID)
1406 inode->i_uid = stat->st_uid;
1407 if (stat->st_result_mask & P9_STATS_GID)
1408 inode->i_gid = stat->st_gid;
1409 if (stat->st_result_mask & P9_STATS_NLINK)
1410 inode->i_nlink = stat->st_nlink;
1411 if (stat->st_result_mask & P9_STATS_MODE) {
1412 inode->i_mode = stat->st_mode;
1413 if ((S_ISBLK(inode->i_mode)) ||
1414 (S_ISCHR(inode->i_mode)))
1415 init_special_inode(inode, inode->i_mode,
1416 inode->i_rdev);
1417 }
1418 if (stat->st_result_mask & P9_STATS_RDEV)
1419 inode->i_rdev = new_decode_dev(stat->st_rdev);
1420 if (stat->st_result_mask & P9_STATS_SIZE)
1421 i_size_write(inode, stat->st_size);
1422 if (stat->st_result_mask & P9_STATS_BLOCKS)
1423 inode->i_blocks = stat->st_blocks;
1424 }
1425 if (stat->st_result_mask & P9_STATS_GEN)
1426 inode->i_generation = stat->st_gen;
1427
1428 /* Currently we don't support P9_STATS_BTIME and P9_STATS_DATA_VERSION
1429 * because the inode structure does not have fields for them.
1430 */
1431} 1102}
1432 1103
1433/** 1104/**
@@ -1468,12 +1139,12 @@ static int v9fs_readlink(struct dentry *dentry, char *buffer, int buflen)
1468 1139
1469 P9_DPRINTK(P9_DEBUG_VFS, " %s\n", dentry->d_name.name); 1140 P9_DPRINTK(P9_DEBUG_VFS, " %s\n", dentry->d_name.name);
1470 retval = -EPERM; 1141 retval = -EPERM;
1471 v9ses = v9fs_inode2v9ses(dentry->d_inode); 1142 v9ses = v9fs_dentry2v9ses(dentry);
1472 fid = v9fs_fid_lookup(dentry); 1143 fid = v9fs_fid_lookup(dentry);
1473 if (IS_ERR(fid)) 1144 if (IS_ERR(fid))
1474 return PTR_ERR(fid); 1145 return PTR_ERR(fid);
1475 1146
1476 if (!v9fs_proto_dotu(v9ses) && !v9fs_proto_dotl(v9ses)) 1147 if (!v9fs_proto_dotu(v9ses))
1477 return -EBADF; 1148 return -EBADF;
1478 1149
1479 st = p9_client_stat(fid); 1150 st = p9_client_stat(fid);
@@ -1536,7 +1207,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
1536 * 1207 *
1537 */ 1208 */
1538 1209
1539static void 1210void
1540v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p) 1211v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
1541{ 1212{
1542 char *s = nd_get_link(nd); 1213 char *s = nd_get_link(nd);
@@ -1560,8 +1231,8 @@ static int v9fs_vfs_mkspecial(struct inode *dir, struct dentry *dentry,
1560 int mode, const char *extension) 1231 int mode, const char *extension)
1561{ 1232{
1562 u32 perm; 1233 u32 perm;
1563 struct v9fs_session_info *v9ses;
1564 struct p9_fid *fid; 1234 struct p9_fid *fid;
1235 struct v9fs_session_info *v9ses;
1565 1236
1566 v9ses = v9fs_inode2v9ses(dir); 1237 v9ses = v9fs_inode2v9ses(dir);
1567 if (!v9fs_proto_dotu(v9ses)) { 1238 if (!v9fs_proto_dotu(v9ses)) {
@@ -1575,104 +1246,12 @@ static int v9fs_vfs_mkspecial(struct inode *dir, struct dentry *dentry,
1575 if (IS_ERR(fid)) 1246 if (IS_ERR(fid))
1576 return PTR_ERR(fid); 1247 return PTR_ERR(fid);
1577 1248
1249 v9fs_invalidate_inode_attr(dir);
1578 p9_client_clunk(fid); 1250 p9_client_clunk(fid);
1579 return 0; 1251 return 0;
1580} 1252}
1581 1253
1582/** 1254/**
1583 * v9fs_vfs_symlink_dotl - helper function to create symlinks
1584 * @dir: directory inode containing symlink
1585 * @dentry: dentry for symlink
1586 * @symname: symlink data
1587 *
1588 * See Also: 9P2000.L RFC for more information
1589 *
1590 */
1591
1592static int
1593v9fs_vfs_symlink_dotl(struct inode *dir, struct dentry *dentry,
1594 const char *symname)
1595{
1596 struct v9fs_session_info *v9ses;
1597 struct p9_fid *dfid;
1598 struct p9_fid *fid = NULL;
1599 struct inode *inode;
1600 struct p9_qid qid;
1601 char *name;
1602 int err;
1603 gid_t gid;
1604
1605 name = (char *) dentry->d_name.name;
1606 P9_DPRINTK(P9_DEBUG_VFS, "v9fs_vfs_symlink_dotl : %lu,%s,%s\n",
1607 dir->i_ino, name, symname);
1608 v9ses = v9fs_inode2v9ses(dir);
1609
1610 dfid = v9fs_fid_lookup(dentry->d_parent);
1611 if (IS_ERR(dfid)) {
1612 err = PTR_ERR(dfid);
1613 P9_DPRINTK(P9_DEBUG_VFS, "fid lookup failed %d\n", err);
1614 return err;
1615 }
1616
1617 gid = v9fs_get_fsgid_for_create(dir);
1618
1619 if (gid < 0) {
1620 P9_DPRINTK(P9_DEBUG_VFS, "v9fs_get_egid failed %d\n", gid);
1621 goto error;
1622 }
1623
1624 /* Server doesn't alter fid on TSYMLINK. Hence no need to clone it. */
1625 err = p9_client_symlink(dfid, name, (char *)symname, gid, &qid);
1626
1627 if (err < 0) {
1628 P9_DPRINTK(P9_DEBUG_VFS, "p9_client_symlink failed %d\n", err);
1629 goto error;
1630 }
1631
1632 if (v9ses->cache) {
1633 /* Now walk from the parent so we can get an unopened fid. */
1634 fid = p9_client_walk(dfid, 1, &name, 1);
1635 if (IS_ERR(fid)) {
1636 err = PTR_ERR(fid);
1637 P9_DPRINTK(P9_DEBUG_VFS, "p9_client_walk failed %d\n",
1638 err);
1639 fid = NULL;
1640 goto error;
1641 }
1642
1643 /* instantiate inode and assign the unopened fid to dentry */
1644 inode = v9fs_inode_from_fid(v9ses, fid, dir->i_sb);
1645 if (IS_ERR(inode)) {
1646 err = PTR_ERR(inode);
1647 P9_DPRINTK(P9_DEBUG_VFS, "inode creation failed %d\n",
1648 err);
1649 goto error;
1650 }
1651 dentry->d_op = &v9fs_cached_dentry_operations;
1652 d_instantiate(dentry, inode);
1653 err = v9fs_fid_add(dentry, fid);
1654 if (err < 0)
1655 goto error;
1656 fid = NULL;
1657 } else {
1658 /* Not in cached mode. No need to populate inode with stat */
1659 inode = v9fs_get_inode(dir->i_sb, S_IFLNK);
1660 if (IS_ERR(inode)) {
1661 err = PTR_ERR(inode);
1662 goto error;
1663 }
1664 dentry->d_op = &v9fs_dentry_operations;
1665 d_instantiate(dentry, inode);
1666 }
1667
1668error:
1669 if (fid)
1670 p9_client_clunk(fid);
1671
1672 return err;
1673}
1674
1675/**
1676 * v9fs_vfs_symlink - helper function to create symlinks 1255 * v9fs_vfs_symlink - helper function to create symlinks
1677 * @dir: directory inode containing symlink 1256 * @dir: directory inode containing symlink
1678 * @dentry: dentry for symlink 1257 * @dentry: dentry for symlink
@@ -1704,8 +1283,8 @@ v9fs_vfs_link(struct dentry *old_dentry, struct inode *dir,
1704 struct dentry *dentry) 1283 struct dentry *dentry)
1705{ 1284{
1706 int retval; 1285 int retval;
1707 struct p9_fid *oldfid;
1708 char *name; 1286 char *name;
1287 struct p9_fid *oldfid;
1709 1288
1710 P9_DPRINTK(P9_DEBUG_VFS, 1289 P9_DPRINTK(P9_DEBUG_VFS,
1711 " %lu,%s,%s\n", dir->i_ino, dentry->d_name.name, 1290 " %lu,%s,%s\n", dir->i_ino, dentry->d_name.name,
@@ -1724,83 +1303,16 @@ v9fs_vfs_link(struct dentry *old_dentry, struct inode *dir,
1724 sprintf(name, "%d\n", oldfid->fid); 1303 sprintf(name, "%d\n", oldfid->fid);
1725 retval = v9fs_vfs_mkspecial(dir, dentry, P9_DMLINK, name); 1304 retval = v9fs_vfs_mkspecial(dir, dentry, P9_DMLINK, name);
1726 __putname(name); 1305 __putname(name);
1727 1306 if (!retval) {
1307 v9fs_refresh_inode(oldfid, old_dentry->d_inode);
1308 v9fs_invalidate_inode_attr(dir);
1309 }
1728clunk_fid: 1310clunk_fid:
1729 p9_client_clunk(oldfid); 1311 p9_client_clunk(oldfid);
1730 return retval; 1312 return retval;
1731} 1313}
1732 1314
1733/** 1315/**
1734 * v9fs_vfs_link_dotl - create a hardlink for dotl
1735 * @old_dentry: dentry for file to link to
1736 * @dir: inode destination for new link
1737 * @dentry: dentry for link
1738 *
1739 */
1740
1741static int
1742v9fs_vfs_link_dotl(struct dentry *old_dentry, struct inode *dir,
1743 struct dentry *dentry)
1744{
1745 int err;
1746 struct p9_fid *dfid, *oldfid;
1747 char *name;
1748 struct v9fs_session_info *v9ses;
1749 struct dentry *dir_dentry;
1750
1751 P9_DPRINTK(P9_DEBUG_VFS, "dir ino: %lu, old_name: %s, new_name: %s\n",
1752 dir->i_ino, old_dentry->d_name.name,
1753 dentry->d_name.name);
1754
1755 v9ses = v9fs_inode2v9ses(dir);
1756 dir_dentry = v9fs_dentry_from_dir_inode(dir);
1757 dfid = v9fs_fid_lookup(dir_dentry);
1758 if (IS_ERR(dfid))
1759 return PTR_ERR(dfid);
1760
1761 oldfid = v9fs_fid_lookup(old_dentry);
1762 if (IS_ERR(oldfid))
1763 return PTR_ERR(oldfid);
1764
1765 name = (char *) dentry->d_name.name;
1766
1767 err = p9_client_link(dfid, oldfid, (char *)dentry->d_name.name);
1768
1769 if (err < 0) {
1770 P9_DPRINTK(P9_DEBUG_VFS, "p9_client_link failed %d\n", err);
1771 return err;
1772 }
1773
1774 if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) {
1775 /* Get the latest stat info from server. */
1776 struct p9_fid *fid;
1777 struct p9_stat_dotl *st;
1778
1779 fid = v9fs_fid_lookup(old_dentry);
1780 if (IS_ERR(fid))
1781 return PTR_ERR(fid);
1782
1783 st = p9_client_getattr_dotl(fid, P9_STATS_BASIC);
1784 if (IS_ERR(st))
1785 return PTR_ERR(st);
1786
1787 v9fs_stat2inode_dotl(st, old_dentry->d_inode);
1788
1789 kfree(st);
1790 } else {
1791 /* Caching disabled. No need to get upto date stat info.
1792 * This dentry will be released immediately. So, just i_count++
1793 */
1794 atomic_inc(&old_dentry->d_inode->i_count);
1795 }
1796
1797 dentry->d_op = old_dentry->d_op;
1798 d_instantiate(dentry, old_dentry->d_inode);
1799
1800 return err;
1801}
1802
1803/**
1804 * v9fs_vfs_mknod - create a special file 1316 * v9fs_vfs_mknod - create a special file
1805 * @dir: inode destination for new link 1317 * @dir: inode destination for new link
1806 * @dentry: dentry for file 1318 * @dentry: dentry for file
@@ -1845,98 +1357,30 @@ v9fs_vfs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t rdev)
1845 return retval; 1357 return retval;
1846} 1358}
1847 1359
1848/** 1360int v9fs_refresh_inode(struct p9_fid *fid, struct inode *inode)
1849 * v9fs_vfs_mknod_dotl - create a special file
1850 * @dir: inode destination for new link
1851 * @dentry: dentry for file
1852 * @mode: mode for creation
1853 * @rdev: device associated with special file
1854 *
1855 */
1856static int
1857v9fs_vfs_mknod_dotl(struct inode *dir, struct dentry *dentry, int mode,
1858 dev_t rdev)
1859{ 1361{
1860 int err; 1362 loff_t i_size;
1861 char *name; 1363 struct p9_wstat *st;
1862 struct v9fs_session_info *v9ses; 1364 struct v9fs_session_info *v9ses;
1863 struct p9_fid *fid = NULL, *dfid = NULL;
1864 struct inode *inode;
1865 gid_t gid;
1866 struct p9_qid qid;
1867 struct dentry *dir_dentry;
1868
1869 P9_DPRINTK(P9_DEBUG_VFS,
1870 " %lu,%s mode: %x MAJOR: %u MINOR: %u\n", dir->i_ino,
1871 dentry->d_name.name, mode, MAJOR(rdev), MINOR(rdev));
1872
1873 if (!new_valid_dev(rdev))
1874 return -EINVAL;
1875 1365
1876 v9ses = v9fs_inode2v9ses(dir); 1366 v9ses = v9fs_inode2v9ses(inode);
1877 dir_dentry = v9fs_dentry_from_dir_inode(dir); 1367 st = p9_client_stat(fid);
1878 dfid = v9fs_fid_lookup(dir_dentry); 1368 if (IS_ERR(st))
1879 if (IS_ERR(dfid)) { 1369 return PTR_ERR(st);
1880 err = PTR_ERR(dfid);
1881 P9_DPRINTK(P9_DEBUG_VFS, "fid lookup failed %d\n", err);
1882 dfid = NULL;
1883 goto error;
1884 }
1885
1886 gid = v9fs_get_fsgid_for_create(dir);
1887 if (gid < 0) {
1888 P9_DPRINTK(P9_DEBUG_VFS, "v9fs_get_fsgid_for_create failed\n");
1889 goto error;
1890 }
1891
1892 name = (char *) dentry->d_name.name;
1893
1894 err = p9_client_mknod_dotl(dfid, name, mode, rdev, gid, &qid);
1895 if (err < 0)
1896 goto error;
1897
1898 /* instantiate inode and assign the unopened fid to the dentry */
1899 if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) {
1900 fid = p9_client_walk(dfid, 1, &name, 1);
1901 if (IS_ERR(fid)) {
1902 err = PTR_ERR(fid);
1903 P9_DPRINTK(P9_DEBUG_VFS, "p9_client_walk failed %d\n",
1904 err);
1905 fid = NULL;
1906 goto error;
1907 }
1908
1909 inode = v9fs_inode_from_fid(v9ses, fid, dir->i_sb);
1910 if (IS_ERR(inode)) {
1911 err = PTR_ERR(inode);
1912 P9_DPRINTK(P9_DEBUG_VFS, "inode creation failed %d\n",
1913 err);
1914 goto error;
1915 }
1916 dentry->d_op = &v9fs_cached_dentry_operations;
1917 d_instantiate(dentry, inode);
1918 err = v9fs_fid_add(dentry, fid);
1919 if (err < 0)
1920 goto error;
1921 fid = NULL;
1922 } else {
1923 /*
1924 * Not in cached mode. No need to populate inode with stat.
1925 * socket syscall returns a fd, so we need instantiate
1926 */
1927 inode = v9fs_get_inode(dir->i_sb, mode);
1928 if (IS_ERR(inode)) {
1929 err = PTR_ERR(inode);
1930 goto error;
1931 }
1932 dentry->d_op = &v9fs_dentry_operations;
1933 d_instantiate(dentry, inode);
1934 }
1935 1370
1936error: 1371 spin_lock(&inode->i_lock);
1937 if (fid) 1372 /*
1938 p9_client_clunk(fid); 1373 * We don't want to refresh inode->i_size,
1939 return err; 1374 * because we may have cached data
1375 */
1376 i_size = inode->i_size;
1377 v9fs_stat2inode(st, inode, inode->i_sb);
1378 if (v9ses->cache)
1379 inode->i_size = i_size;
1380 spin_unlock(&inode->i_lock);
1381 p9stat_free(st);
1382 kfree(st);
1383 return 0;
1940} 1384}
1941 1385
1942static const struct inode_operations v9fs_dir_inode_operations_dotu = { 1386static const struct inode_operations v9fs_dir_inode_operations_dotu = {
@@ -1953,25 +1397,6 @@ static const struct inode_operations v9fs_dir_inode_operations_dotu = {
1953 .setattr = v9fs_vfs_setattr, 1397 .setattr = v9fs_vfs_setattr,
1954}; 1398};
1955 1399
1956static const struct inode_operations v9fs_dir_inode_operations_dotl = {
1957 .create = v9fs_vfs_create_dotl,
1958 .lookup = v9fs_vfs_lookup,
1959 .link = v9fs_vfs_link_dotl,
1960 .symlink = v9fs_vfs_symlink_dotl,
1961 .unlink = v9fs_vfs_unlink,
1962 .mkdir = v9fs_vfs_mkdir_dotl,
1963 .rmdir = v9fs_vfs_rmdir,
1964 .mknod = v9fs_vfs_mknod_dotl,
1965 .rename = v9fs_vfs_rename,
1966 .getattr = v9fs_vfs_getattr_dotl,
1967 .setattr = v9fs_vfs_setattr_dotl,
1968 .setxattr = generic_setxattr,
1969 .getxattr = generic_getxattr,
1970 .removexattr = generic_removexattr,
1971 .listxattr = v9fs_listxattr,
1972
1973};
1974
1975static const struct inode_operations v9fs_dir_inode_operations = { 1400static const struct inode_operations v9fs_dir_inode_operations = {
1976 .create = v9fs_vfs_create, 1401 .create = v9fs_vfs_create,
1977 .lookup = v9fs_vfs_lookup, 1402 .lookup = v9fs_vfs_lookup,
@@ -1989,15 +1414,6 @@ static const struct inode_operations v9fs_file_inode_operations = {
1989 .setattr = v9fs_vfs_setattr, 1414 .setattr = v9fs_vfs_setattr,
1990}; 1415};
1991 1416
1992static const struct inode_operations v9fs_file_inode_operations_dotl = {
1993 .getattr = v9fs_vfs_getattr_dotl,
1994 .setattr = v9fs_vfs_setattr_dotl,
1995 .setxattr = generic_setxattr,
1996 .getxattr = generic_getxattr,
1997 .removexattr = generic_removexattr,
1998 .listxattr = v9fs_listxattr,
1999};
2000
2001static const struct inode_operations v9fs_symlink_inode_operations = { 1417static const struct inode_operations v9fs_symlink_inode_operations = {
2002 .readlink = generic_readlink, 1418 .readlink = generic_readlink,
2003 .follow_link = v9fs_vfs_follow_link, 1419 .follow_link = v9fs_vfs_follow_link,
@@ -2006,14 +1422,3 @@ static const struct inode_operations v9fs_symlink_inode_operations = {
2006 .setattr = v9fs_vfs_setattr, 1422 .setattr = v9fs_vfs_setattr,
2007}; 1423};
2008 1424
2009static const struct inode_operations v9fs_symlink_inode_operations_dotl = {
2010 .readlink = generic_readlink,
2011 .follow_link = v9fs_vfs_follow_link,
2012 .put_link = v9fs_vfs_put_link,
2013 .getattr = v9fs_vfs_getattr_dotl,
2014 .setattr = v9fs_vfs_setattr_dotl,
2015 .setxattr = generic_setxattr,
2016 .getxattr = generic_getxattr,
2017 .removexattr = generic_removexattr,
2018 .listxattr = v9fs_listxattr,
2019};