~ubuntu-branches/ubuntu/precise/linux-ti-omap4/precise

« back to all changes in this revision

Viewing changes to fs/9p/vfs_inode.c

  • Committer: Bazaar Package Importer
  • Author(s): Paolo Pisati
  • Date: 2011-06-29 15:23:51 UTC
  • mfrom: (26.1.1 natty-proposed)
  • Revision ID: james.westby@ubuntu.com-20110629152351-xs96tm303d95rpbk
Tags: 3.0.0-1200.2
* Rebased against 3.0.0-6.7
* BSP from TI based on 3.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
203
203
        wstat->extension = NULL;
204
204
}
205
205
 
206
 
#ifdef CONFIG_9P_FSCACHE
207
206
/**
208
207
 * v9fs_alloc_inode - helper function to allocate an inode
209
 
 * This callback is executed before setting up the inode so that we
210
 
 * can associate a vcookie with each inode.
211
208
 *
212
209
 */
213
 
 
214
210
struct inode *v9fs_alloc_inode(struct super_block *sb)
215
211
{
216
 
        struct v9fs_cookie *vcookie;
217
 
        vcookie = (struct v9fs_cookie *)kmem_cache_alloc(vcookie_cache,
218
 
                                                         GFP_KERNEL);
219
 
        if (!vcookie)
 
212
        struct v9fs_inode *v9inode;
 
213
        v9inode = (struct v9fs_inode *)kmem_cache_alloc(v9fs_inode_cache,
 
214
                                                        GFP_KERNEL);
 
215
        if (!v9inode)
220
216
                return NULL;
221
 
 
222
 
        vcookie->fscache = NULL;
223
 
        vcookie->qid = NULL;
224
 
        spin_lock_init(&vcookie->lock);
225
 
        return &vcookie->inode;
 
217
#ifdef CONFIG_9P_FSCACHE
 
218
        v9inode->fscache = NULL;
 
219
        v9inode->fscache_key = NULL;
 
220
        spin_lock_init(&v9inode->fscache_lock);
 
221
#endif
 
222
        v9inode->writeback_fid = NULL;
 
223
        v9inode->cache_validity = 0;
 
224
        mutex_init(&v9inode->v_mutex);
 
225
        return &v9inode->vfs_inode;
226
226
}
227
227
 
228
228
/**
234
234
{
235
235
        struct inode *inode = container_of(head, struct inode, i_rcu);
236
236
        INIT_LIST_HEAD(&inode->i_dentry);
237
 
        kmem_cache_free(vcookie_cache, v9fs_inode2cookie(inode));
 
237
        kmem_cache_free(v9fs_inode_cache, V9FS_I(inode));
238
238
}
239
239
 
240
240
void v9fs_destroy_inode(struct inode *inode)
241
241
{
242
242
        call_rcu(&inode->i_rcu, v9fs_i_callback);
243
243
}
244
 
#endif
245
 
 
246
 
/**
247
 
 * v9fs_get_inode - helper function to setup an inode
248
 
 * @sb: superblock
249
 
 * @mode: mode to setup inode with
250
 
 *
251
 
 */
252
 
 
253
 
struct inode *v9fs_get_inode(struct super_block *sb, int mode)
 
244
 
 
245
int v9fs_init_inode(struct v9fs_session_info *v9ses,
 
246
                    struct inode *inode, int mode)
254
247
{
255
 
        int err;
256
 
        struct inode *inode;
257
 
        struct v9fs_session_info *v9ses = sb->s_fs_info;
258
 
 
259
 
        P9_DPRINTK(P9_DEBUG_VFS, "super block: %p mode: %o\n", sb, mode);
260
 
 
261
 
        inode = new_inode(sb);
262
 
        if (!inode) {
263
 
                P9_EPRINTK(KERN_WARNING, "Problem allocating inode\n");
264
 
                return ERR_PTR(-ENOMEM);
265
 
        }
 
248
        int err = 0;
266
249
 
267
250
        inode_init_owner(inode, NULL, mode);
268
251
        inode->i_blocks = 0;
292
275
        case S_IFREG:
293
276
                if (v9fs_proto_dotl(v9ses)) {
294
277
                        inode->i_op = &v9fs_file_inode_operations_dotl;
295
 
                        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;
296
283
                } else {
297
284
                        inode->i_op = &v9fs_file_inode_operations;
298
 
                        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;
299
289
                }
300
290
 
301
291
                break;
302
 
 
303
292
        case S_IFLNK:
304
293
                if (!v9fs_proto_dotu(v9ses) && !v9fs_proto_dotl(v9ses)) {
305
294
                        P9_DPRINTK(P9_DEBUG_ERROR, "extended modes used with "
335
324
                err = -EINVAL;
336
325
                goto error;
337
326
        }
338
 
 
 
327
error:
 
328
        return err;
 
329
 
 
330
}
 
331
 
 
332
/**
 
333
 * v9fs_get_inode - helper function to setup an inode
 
334
 * @sb: superblock
 
335
 * @mode: mode to setup inode with
 
336
 *
 
337
 */
 
338
 
 
339
struct 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
        }
339
357
        return inode;
340
 
 
341
 
error:
342
 
        iput(inode);
343
 
        return ERR_PTR(err);
344
358
}
345
359
 
346
360
/*
403
417
 */
404
418
void v9fs_evict_inode(struct inode *inode)
405
419
{
 
420
        struct v9fs_inode *v9inode = V9FS_I(inode);
 
421
 
406
422
        truncate_inode_pages(inode->i_mapping, 0);
407
423
        end_writeback(inode);
408
424
        filemap_fdatawrite(inode->i_mapping);
410
426
#ifdef CONFIG_9P_FSCACHE
411
427
        v9fs_cache_inode_put_cookie(inode);
412
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
        }
 
434
}
 
435
 
 
436
static struct inode *v9fs_qid_iget(struct super_block *sb,
 
437
                                   struct p9_qid *qid,
 
438
                                   struct p9_wstat *st)
 
439
{
 
440
        int retval, umode;
 
441
        unsigned long i_ino;
 
442
        struct inode *inode;
 
443
        struct v9fs_session_info *v9ses = sb->s_fs_info;
 
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);
 
457
        retval = v9fs_init_inode(v9ses, inode, umode);
 
458
        if (retval)
 
459
                goto error;
 
460
 
 
461
        v9fs_stat2inode(st, inode, sb);
 
462
#ifdef CONFIG_9P_FSCACHE
 
463
        v9fs_fscache_set_key(inode, &st->qid);
 
464
        v9fs_cache_inode_get_cookie(inode);
 
465
#endif
 
466
        unlock_new_inode(inode);
 
467
        return inode;
 
468
error:
 
469
        unlock_new_inode(inode);
 
470
        iput(inode);
 
471
        return ERR_PTR(retval);
 
472
 
413
473
}
414
474
 
415
475
struct inode *
416
 
v9fs_inode(struct v9fs_session_info *v9ses, struct p9_fid *fid,
417
 
        struct super_block *sb)
 
476
v9fs_inode_from_fid(struct v9fs_session_info *v9ses, struct p9_fid *fid,
 
477
                    struct super_block *sb)
418
478
{
419
 
        int err, umode;
420
 
        struct inode *ret = NULL;
421
479
        struct p9_wstat *st;
 
480
        struct inode *inode = NULL;
422
481
 
423
482
        st = p9_client_stat(fid);
424
483
        if (IS_ERR(st))
425
484
                return ERR_CAST(st);
426
485
 
427
 
        umode = p9mode2unixmode(v9ses, st->mode);
428
 
        ret = v9fs_get_inode(sb, umode);
429
 
        if (IS_ERR(ret)) {
430
 
                err = PTR_ERR(ret);
431
 
                goto error;
432
 
        }
433
 
 
434
 
        v9fs_stat2inode(st, ret, sb);
435
 
        ret->i_ino = v9fs_qid2ino(&st->qid);
436
 
 
437
 
#ifdef CONFIG_9P_FSCACHE
438
 
        v9fs_vcookie_set_qid(ret, &st->qid);
439
 
        v9fs_cache_inode_get_cookie(ret);
440
 
#endif
441
 
        p9stat_free(st);
442
 
        kfree(st);
443
 
        return ret;
444
 
error:
445
 
        p9stat_free(st);
446
 
        kfree(st);
447
 
        return ERR_PTR(err);
 
486
        inode = v9fs_qid_iget(sb, &st->qid, st);
 
487
        p9stat_free(st);
 
488
        kfree(st);
 
489
        return inode;
448
490
}
449
491
 
450
492
/**
458
500
static int v9fs_remove(struct inode *dir, struct dentry *file, int rmdir)
459
501
{
460
502
        int retval;
 
503
        struct p9_fid *v9fid;
461
504
        struct inode *file_inode;
462
 
        struct p9_fid *v9fid;
463
505
 
464
506
        P9_DPRINTK(P9_DEBUG_VFS, "inode: %p dentry: %p rmdir: %d\n", dir, file,
465
507
                rmdir);
470
512
                return PTR_ERR(v9fid);
471
513
 
472
514
        retval = p9_client_remove(v9fid);
473
 
        if (!retval)
474
 
                drop_nlink(file_inode);
 
515
        if (!retval) {
 
516
                /*
 
517
                 * directories on unlink should have zero
 
518
                 * link count
 
519
                 */
 
520
                if (rmdir) {
 
521
                        clear_nlink(file_inode);
 
522
                        drop_nlink(dir);
 
523
                } else
 
524
                        drop_nlink(file_inode);
 
525
 
 
526
                v9fs_invalidate_inode_attr(file_inode);
 
527
                v9fs_invalidate_inode_attr(dir);
 
528
        }
475
529
        return retval;
476
530
}
477
531
 
531
585
        }
532
586
 
533
587
        /* instantiate inode and assign the unopened fid to the dentry */
534
 
        inode = v9fs_inode_from_fid(v9ses, fid, dir->i_sb);
 
588
        inode = v9fs_get_inode_from_fid(v9ses, fid, dir->i_sb);
535
589
        if (IS_ERR(inode)) {
536
590
                err = PTR_ERR(inode);
537
591
                P9_DPRINTK(P9_DEBUG_VFS, "inode creation failed %d\n", err);
570
624
        int err;
571
625
        u32 perm;
572
626
        int flags;
573
 
        struct v9fs_session_info *v9ses;
574
 
        struct p9_fid *fid;
575
627
        struct file *filp;
 
628
        struct v9fs_inode *v9inode;
 
629
        struct v9fs_session_info *v9ses;
 
630
        struct p9_fid *fid, *inode_fid;
576
631
 
577
632
        err = 0;
578
633
        fid = NULL;
592
647
                goto error;
593
648
        }
594
649
 
 
650
        v9fs_invalidate_inode_attr(dir);
595
651
        /* if we are opening a file, assign the open fid to the file */
596
652
        if (nd && nd->flags & LOOKUP_OPEN) {
 
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);
597
673
                filp = lookup_instantiate_filp(nd, dentry, generic_file_open);
598
674
                if (IS_ERR(filp)) {
599
675
                        err = PTR_ERR(filp);
601
677
                }
602
678
 
603
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
604
684
        } else
605
685
                p9_client_clunk(fid);
606
686
 
625
705
{
626
706
        int err;
627
707
        u32 perm;
 
708
        struct p9_fid *fid;
628
709
        struct v9fs_session_info *v9ses;
629
 
        struct p9_fid *fid;
630
710
 
631
711
        P9_DPRINTK(P9_DEBUG_VFS, "name %s\n", dentry->d_name.name);
632
712
        err = 0;
636
716
        if (IS_ERR(fid)) {
637
717
                err = PTR_ERR(fid);
638
718
                fid = NULL;
 
719
        } else {
 
720
                inc_nlink(dir);
 
721
                v9fs_invalidate_inode_attr(dir);
639
722
        }
640
723
 
641
724
        if (fid)
687
770
                return ERR_PTR(result);
688
771
        }
689
772
 
690
 
        inode = v9fs_inode_from_fid(v9ses, fid, dir->i_sb);
 
773
        inode = v9fs_get_inode_from_fid(v9ses, fid, dir->i_sb);
691
774
        if (IS_ERR(inode)) {
692
775
                result = PTR_ERR(inode);
693
776
                inode = NULL;
747
830
v9fs_vfs_rename(struct inode *old_dir, struct dentry *old_dentry,
748
831
                struct inode *new_dir, struct dentry *new_dentry)
749
832
{
 
833
        int retval;
750
834
        struct inode *old_inode;
 
835
        struct inode *new_inode;
751
836
        struct v9fs_session_info *v9ses;
752
837
        struct p9_fid *oldfid;
753
838
        struct p9_fid *olddirfid;
754
839
        struct p9_fid *newdirfid;
755
840
        struct p9_wstat wstat;
756
 
        int retval;
757
841
 
758
842
        P9_DPRINTK(P9_DEBUG_VFS, "\n");
759
843
        retval = 0;
760
844
        old_inode = old_dentry->d_inode;
 
845
        new_inode = new_dentry->d_inode;
761
846
        v9ses = v9fs_inode2v9ses(old_inode);
762
847
        oldfid = v9fs_fid_lookup(old_dentry);
763
848
        if (IS_ERR(oldfid))
798
883
        retval = p9_client_wstat(oldfid, &wstat);
799
884
 
800
885
clunk_newdir:
801
 
        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
 
802
907
                /* successful rename */
803
908
                d_move(old_dentry, new_dentry);
 
909
        }
804
910
        up_write(&v9ses->rename_sem);
805
911
        p9_client_clunk(newdirfid);
806
912
 
830
936
 
831
937
        P9_DPRINTK(P9_DEBUG_VFS, "dentry: %p\n", dentry);
832
938
        err = -EPERM;
833
 
        v9ses = v9fs_inode2v9ses(dentry->d_inode);
834
 
        if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE)
835
 
                return simple_getattr(mnt, dentry, stat);
836
 
 
 
939
        v9ses = v9fs_dentry2v9ses(dentry);
 
940
        if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) {
 
941
                generic_fillattr(dentry->d_inode, stat);
 
942
                return 0;
 
943
        }
837
944
        fid = v9fs_fid_lookup(dentry);
838
945
        if (IS_ERR(fid))
839
946
                return PTR_ERR(fid);
865
972
        struct p9_wstat wstat;
866
973
 
867
974
        P9_DPRINTK(P9_DEBUG_VFS, "\n");
 
975
        retval = inode_change_ok(dentry->d_inode, iattr);
 
976
        if (retval)
 
977
                return retval;
 
978
 
868
979
        retval = -EPERM;
869
 
        v9ses = v9fs_inode2v9ses(dentry->d_inode);
 
980
        v9ses = v9fs_dentry2v9ses(dentry);
870
981
        fid = v9fs_fid_lookup(dentry);
871
982
        if(IS_ERR(fid))
872
983
                return PTR_ERR(fid);
892
1003
                        wstat.n_gid = iattr->ia_gid;
893
1004
        }
894
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
 
895
1010
        retval = p9_client_wstat(fid, &wstat);
896
1011
        if (retval < 0)
897
1012
                return retval;
898
1013
 
899
1014
        if ((iattr->ia_valid & ATTR_SIZE) &&
900
 
            iattr->ia_size != i_size_read(dentry->d_inode)) {
901
 
                retval = vmtruncate(dentry->d_inode, iattr->ia_size);
902
 
                if (retval)
903
 
                        return retval;
904
 
        }
 
1015
            iattr->ia_size != i_size_read(dentry->d_inode))
 
1016
                truncate_setsize(dentry->d_inode, iattr->ia_size);
 
1017
 
 
1018
        v9fs_invalidate_inode_attr(dentry->d_inode);
905
1019
 
906
1020
        setattr_copy(dentry->d_inode, iattr);
907
1021
        mark_inode_dirty(dentry->d_inode);
924
1038
        char tag_name[14];
925
1039
        unsigned int i_nlink;
926
1040
        struct v9fs_session_info *v9ses = sb->s_fs_info;
 
1041
        struct v9fs_inode *v9inode = V9FS_I(inode);
927
1042
 
928
1043
        inode->i_nlink = 1;
929
1044
 
983
1098
 
984
1099
        /* not real number of blocks, but 512 byte ones ... */
985
1100
        inode->i_blocks = (i_size_read(inode) + 512 - 1) >> 9;
 
1101
        v9inode->cache_validity &= ~V9FS_INO_INVALID_ATTR;
986
1102
}
987
1103
 
988
1104
/**
1023
1139
 
1024
1140
        P9_DPRINTK(P9_DEBUG_VFS, " %s\n", dentry->d_name.name);
1025
1141
        retval = -EPERM;
1026
 
        v9ses = v9fs_inode2v9ses(dentry->d_inode);
 
1142
        v9ses = v9fs_dentry2v9ses(dentry);
1027
1143
        fid = v9fs_fid_lookup(dentry);
1028
1144
        if (IS_ERR(fid))
1029
1145
                return PTR_ERR(fid);
1115
1231
        int mode, const char *extension)
1116
1232
{
1117
1233
        u32 perm;
 
1234
        struct p9_fid *fid;
1118
1235
        struct v9fs_session_info *v9ses;
1119
 
        struct p9_fid *fid;
1120
1236
 
1121
1237
        v9ses = v9fs_inode2v9ses(dir);
1122
1238
        if (!v9fs_proto_dotu(v9ses)) {
1130
1246
        if (IS_ERR(fid))
1131
1247
                return PTR_ERR(fid);
1132
1248
 
 
1249
        v9fs_invalidate_inode_attr(dir);
1133
1250
        p9_client_clunk(fid);
1134
1251
        return 0;
1135
1252
}
1166
1283
              struct dentry *dentry)
1167
1284
{
1168
1285
        int retval;
 
1286
        char *name;
1169
1287
        struct p9_fid *oldfid;
1170
 
        char *name;
1171
1288
 
1172
1289
        P9_DPRINTK(P9_DEBUG_VFS,
1173
1290
                " %lu,%s,%s\n", dir->i_ino, dentry->d_name.name,
1186
1303
        sprintf(name, "%d\n", oldfid->fid);
1187
1304
        retval = v9fs_vfs_mkspecial(dir, dentry, P9_DMLINK, name);
1188
1305
        __putname(name);
1189
 
 
 
1306
        if (!retval) {
 
1307
                v9fs_refresh_inode(oldfid, old_dentry->d_inode);
 
1308
                v9fs_invalidate_inode_attr(dir);
 
1309
        }
1190
1310
clunk_fid:
1191
1311
        p9_client_clunk(oldfid);
1192
1312
        return retval;
1237
1357
        return retval;
1238
1358
}
1239
1359
 
 
1360
int v9fs_refresh_inode(struct p9_fid *fid, struct inode *inode)
 
1361
{
 
1362
        loff_t i_size;
 
1363
        struct p9_wstat *st;
 
1364
        struct v9fs_session_info *v9ses;
 
1365
 
 
1366
        v9ses = v9fs_inode2v9ses(inode);
 
1367
        st = p9_client_stat(fid);
 
1368
        if (IS_ERR(st))
 
1369
                return PTR_ERR(st);
 
1370
 
 
1371
        spin_lock(&inode->i_lock);
 
1372
        /*
 
1373
         * We don't want to refresh inode->i_size,
 
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;
 
1384
}
 
1385
 
1240
1386
static const struct inode_operations v9fs_dir_inode_operations_dotu = {
1241
1387
        .create = v9fs_vfs_create,
1242
1388
        .lookup = v9fs_vfs_lookup,