203
203
wstat->extension = NULL;
206
#ifdef CONFIG_9P_FSCACHE
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.
214
210
struct inode *v9fs_alloc_inode(struct super_block *sb)
216
struct v9fs_cookie *vcookie;
217
vcookie = (struct v9fs_cookie *)kmem_cache_alloc(vcookie_cache,
212
struct v9fs_inode *v9inode;
213
v9inode = (struct v9fs_inode *)kmem_cache_alloc(v9fs_inode_cache,
222
vcookie->fscache = 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);
222
v9inode->writeback_fid = NULL;
223
v9inode->cache_validity = 0;
224
mutex_init(&v9inode->v_mutex);
225
return &v9inode->vfs_inode;
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));
240
240
void v9fs_destroy_inode(struct inode *inode)
242
242
call_rcu(&inode->i_rcu, v9fs_i_callback);
247
* v9fs_get_inode - helper function to setup an inode
249
* @mode: mode to setup inode with
253
struct inode *v9fs_get_inode(struct super_block *sb, int mode)
245
int v9fs_init_inode(struct v9fs_session_info *v9ses,
246
struct inode *inode, int mode)
257
struct v9fs_session_info *v9ses = sb->s_fs_info;
259
P9_DPRINTK(P9_DEBUG_VFS, "super block: %p mode: %o\n", sb, mode);
261
inode = new_inode(sb);
263
P9_EPRINTK(KERN_WARNING, "Problem allocating inode\n");
264
return ERR_PTR(-ENOMEM);
267
250
inode_init_owner(inode, NULL, mode);
268
251
inode->i_blocks = 0;
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;
280
&v9fs_cached_file_operations_dotl;
282
inode->i_fop = &v9fs_file_operations_dotl;
297
284
inode->i_op = &v9fs_file_inode_operations;
298
inode->i_fop = &v9fs_file_operations;
286
inode->i_fop = &v9fs_cached_file_operations;
288
inode->i_fop = &v9fs_file_operations;
304
293
if (!v9fs_proto_dotu(v9ses) && !v9fs_proto_dotl(v9ses)) {
305
294
P9_DPRINTK(P9_DEBUG_ERROR, "extended modes used with "
333
* v9fs_get_inode - helper function to setup an inode
335
* @mode: mode to setup inode with
339
struct inode *v9fs_get_inode(struct super_block *sb, int mode)
343
struct v9fs_session_info *v9ses = sb->s_fs_info;
345
P9_DPRINTK(P9_DEBUG_VFS, "super block: %p mode: %o\n", sb, mode);
347
inode = new_inode(sb);
349
P9_EPRINTK(KERN_WARNING, "Problem allocating inode\n");
350
return ERR_PTR(-ENOMEM);
352
err = v9fs_init_inode(v9ses, inode, mode);
404
418
void v9fs_evict_inode(struct inode *inode)
420
struct v9fs_inode *v9inode = V9FS_I(inode);
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);
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;
436
static struct inode *v9fs_qid_iget(struct super_block *sb,
443
struct v9fs_session_info *v9ses = sb->s_fs_info;
445
i_ino = v9fs_qid2ino(qid);
446
inode = iget_locked(sb, i_ino);
448
return ERR_PTR(-ENOMEM);
449
if (!(inode->i_state & I_NEW))
452
* initialize the inode with the stat info
453
* FIXME!! we may need support for stale inodes
456
umode = p9mode2unixmode(v9ses, st->mode);
457
retval = v9fs_init_inode(v9ses, inode, umode);
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);
466
unlock_new_inode(inode);
469
unlock_new_inode(inode);
471
return ERR_PTR(retval);
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)
420
struct inode *ret = NULL;
421
479
struct p9_wstat *st;
480
struct inode *inode = NULL;
423
482
st = p9_client_stat(fid);
425
484
return ERR_CAST(st);
427
umode = p9mode2unixmode(v9ses, st->mode);
428
ret = v9fs_get_inode(sb, umode);
434
v9fs_stat2inode(st, ret, sb);
435
ret->i_ino = v9fs_qid2ino(&st->qid);
437
#ifdef CONFIG_9P_FSCACHE
438
v9fs_vcookie_set_qid(ret, &st->qid);
439
v9fs_cache_inode_get_cookie(ret);
486
inode = v9fs_qid_iget(sb, &st->qid, st);
458
500
static int v9fs_remove(struct inode *dir, struct dentry *file, int rmdir)
503
struct p9_fid *v9fid;
461
504
struct inode *file_inode;
462
struct p9_fid *v9fid;
464
506
P9_DPRINTK(P9_DEBUG_VFS, "inode: %p dentry: %p rmdir: %d\n", dir, file,
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);
573
struct v9fs_session_info *v9ses;
575
627
struct file *filp;
628
struct v9fs_inode *v9inode;
629
struct v9fs_session_info *v9ses;
630
struct p9_fid *fid, *inode_fid;
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)) {
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
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);
670
v9inode->writeback_fid = (void *) inode_fid;
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);
747
830
v9fs_vfs_rename(struct inode *old_dir, struct dentry *old_dentry,
748
831
struct inode *new_dir, struct dentry *new_dentry)
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;
758
842
P9_DPRINTK(P9_DEBUG_VFS, "\n");
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);
888
if (S_ISDIR(new_inode->i_mode))
889
clear_nlink(new_inode);
891
drop_nlink(new_inode);
893
* Work around vfs rename rehash bug with
894
* FS_RENAME_DOES_D_MOVE
896
v9fs_invalidate_inode_attr(new_inode);
898
if (S_ISDIR(old_inode->i_mode)) {
903
v9fs_invalidate_inode_attr(old_inode);
904
v9fs_invalidate_inode_attr(old_dir);
905
v9fs_invalidate_inode_attr(new_dir);
802
907
/* successful rename */
803
908
d_move(old_dentry, new_dentry);
804
910
up_write(&v9ses->rename_sem);
805
911
p9_client_clunk(newdirfid);
831
937
P9_DPRINTK(P9_DEBUG_VFS, "dentry: %p\n", dentry);
833
v9ses = v9fs_inode2v9ses(dentry->d_inode);
834
if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE)
835
return simple_getattr(mnt, dentry, stat);
939
v9ses = v9fs_dentry2v9ses(dentry);
940
if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) {
941
generic_fillattr(dentry->d_inode, stat);
837
944
fid = v9fs_fid_lookup(dentry);
839
946
return PTR_ERR(fid);
865
972
struct p9_wstat wstat;
867
974
P9_DPRINTK(P9_DEBUG_VFS, "\n");
975
retval = inode_change_ok(dentry->d_inode, iattr);
869
v9ses = v9fs_inode2v9ses(dentry->d_inode);
980
v9ses = v9fs_dentry2v9ses(dentry);
870
981
fid = v9fs_fid_lookup(dentry);
872
983
return PTR_ERR(fid);
892
1003
wstat.n_gid = iattr->ia_gid;
1006
/* Write all dirty data */
1007
if (S_ISREG(dentry->d_inode->i_mode))
1008
filemap_write_and_wait(dentry->d_inode->i_mapping);
895
1010
retval = p9_client_wstat(fid, &wstat);
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);
1015
iattr->ia_size != i_size_read(dentry->d_inode))
1016
truncate_setsize(dentry->d_inode, iattr->ia_size);
1018
v9fs_invalidate_inode_attr(dentry->d_inode);
906
1020
setattr_copy(dentry->d_inode, iattr);
907
1021
mark_inode_dirty(dentry->d_inode);
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)
1118
1235
struct v9fs_session_info *v9ses;
1121
1237
v9ses = v9fs_inode2v9ses(dir);
1122
1238
if (!v9fs_proto_dotu(v9ses)) {
1186
1303
sprintf(name, "%d\n", oldfid->fid);
1187
1304
retval = v9fs_vfs_mkspecial(dir, dentry, P9_DMLINK, name);
1188
1305
__putname(name);
1307
v9fs_refresh_inode(oldfid, old_dentry->d_inode);
1308
v9fs_invalidate_inode_attr(dir);
1191
1311
p9_client_clunk(oldfid);
1360
int v9fs_refresh_inode(struct p9_fid *fid, struct inode *inode)
1363
struct p9_wstat *st;
1364
struct v9fs_session_info *v9ses;
1366
v9ses = v9fs_inode2v9ses(inode);
1367
st = p9_client_stat(fid);
1371
spin_lock(&inode->i_lock);
1373
* We don't want to refresh inode->i_size,
1374
* because we may have cached data
1376
i_size = inode->i_size;
1377
v9fs_stat2inode(st, inode, inode->i_sb);
1379
inode->i_size = i_size;
1380
spin_unlock(&inode->i_lock);
1240
1386
static const struct inode_operations v9fs_dir_inode_operations_dotu = {
1241
1387
.create = v9fs_vfs_create,
1242
1388
.lookup = v9fs_vfs_lookup,