Skip to content

Commit 5153bc8

Browse files
dhowellsAl Viro
authored andcommitted
VFS: Cachefiles should perform fs modifications on the top layer only
Cachefiles should perform fs modifications (eg. vfs_unlink()) on the top layer only and should not attempt to alter the lower layer. Signed-off-by: David Howells <dhowells@redhat.com> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent ee8ac4d commit 5153bc8

2 files changed

Lines changed: 28 additions & 28 deletions

File tree

‎fs/cachefiles/interface.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ static int cachefiles_attr_changed(struct fscache_object *_object)
446446
return 0;
447447

448448
cachefiles_begin_secure(cache, &saved_cred);
449-
mutex_lock(&object->backer->d_inode->i_mutex);
449+
mutex_lock(&d_inode(object->backer)->i_mutex);
450450

451451
/* if there's an extension to a partial page at the end of the backing
452452
* file, we need to discard the partial page so that we pick up new
@@ -465,7 +465,7 @@ static int cachefiles_attr_changed(struct fscache_object *_object)
465465
ret = notify_change(object->backer, &newattrs, NULL);
466466

467467
truncate_failed:
468-
mutex_unlock(&object->backer->d_inode->i_mutex);
468+
mutex_unlock(&d_inode(object->backer)->i_mutex);
469469
cachefiles_end_secure(cache, saved_cred);
470470

471471
if (ret == -EIO) {

‎fs/cachefiles/namei.c‎

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -286,13 +286,13 @@ static int cachefiles_bury_object(struct cachefiles_cache *cache,
286286
if (ret < 0) {
287287
cachefiles_io_error(cache, "Unlink security error");
288288
} else {
289-
ret = vfs_unlink(dir->d_inode, rep, NULL);
289+
ret = vfs_unlink(d_inode(dir), rep, NULL);
290290

291291
if (preemptive)
292292
cachefiles_mark_object_buried(cache, rep);
293293
}
294294

295-
mutex_unlock(&dir->d_inode->i_mutex);
295+
mutex_unlock(&d_inode(dir)->i_mutex);
296296

297297
if (ret == -EIO)
298298
cachefiles_io_error(cache, "Unlink failed");
@@ -303,7 +303,7 @@ static int cachefiles_bury_object(struct cachefiles_cache *cache,
303303

304304
/* directories have to be moved to the graveyard */
305305
_debug("move stale object to graveyard");
306-
mutex_unlock(&dir->d_inode->i_mutex);
306+
mutex_unlock(&d_inode(dir)->i_mutex);
307307

308308
try_again:
309309
/* first step is to make up a grave dentry in the graveyard */
@@ -387,8 +387,8 @@ static int cachefiles_bury_object(struct cachefiles_cache *cache,
387387
if (ret < 0) {
388388
cachefiles_io_error(cache, "Rename security error %d", ret);
389389
} else {
390-
ret = vfs_rename(dir->d_inode, rep,
391-
cache->graveyard->d_inode, grave, NULL, 0);
390+
ret = vfs_rename(d_inode(dir), rep,
391+
d_inode(cache->graveyard), grave, NULL, 0);
392392
if (ret != 0 && ret != -ENOMEM)
393393
cachefiles_io_error(cache,
394394
"Rename failed with error %d", ret);
@@ -420,13 +420,13 @@ int cachefiles_delete_object(struct cachefiles_cache *cache,
420420

421421
dir = dget_parent(object->dentry);
422422

423-
mutex_lock_nested(&dir->d_inode->i_mutex, I_MUTEX_PARENT);
423+
mutex_lock_nested(&d_inode(dir)->i_mutex, I_MUTEX_PARENT);
424424

425425
if (test_bit(CACHEFILES_OBJECT_BURIED, &object->flags)) {
426426
/* object allocation for the same key preemptively deleted this
427427
* object's file so that it could create its own file */
428428
_debug("object preemptively buried");
429-
mutex_unlock(&dir->d_inode->i_mutex);
429+
mutex_unlock(&d_inode(dir)->i_mutex);
430430
ret = 0;
431431
} else {
432432
/* we need to check that our parent is _still_ our parent - it
@@ -438,7 +438,7 @@ int cachefiles_delete_object(struct cachefiles_cache *cache,
438438
/* it got moved, presumably by cachefilesd culling it,
439439
* so it's no longer in the key path and we can ignore
440440
* it */
441-
mutex_unlock(&dir->d_inode->i_mutex);
441+
mutex_unlock(&d_inode(dir)->i_mutex);
442442
ret = 0;
443443
}
444444
}
@@ -497,7 +497,7 @@ int cachefiles_walk_to_object(struct cachefiles_object *parent,
497497
/* search the current directory for the element name */
498498
_debug("lookup '%s'", name);
499499

500-
mutex_lock_nested(&dir->d_inode->i_mutex, I_MUTEX_PARENT);
500+
mutex_lock_nested(&d_inode(dir)->i_mutex, I_MUTEX_PARENT);
501501

502502
start = jiffies;
503503
next = lookup_one_len(name, dir, nlen);
@@ -529,7 +529,7 @@ int cachefiles_walk_to_object(struct cachefiles_object *parent,
529529
if (ret < 0)
530530
goto create_error;
531531
start = jiffies;
532-
ret = vfs_mkdir(dir->d_inode, next, 0);
532+
ret = vfs_mkdir(d_inode(dir), next, 0);
533533
cachefiles_hist(cachefiles_mkdir_histogram, start);
534534
if (ret < 0)
535535
goto create_error;
@@ -558,7 +558,7 @@ int cachefiles_walk_to_object(struct cachefiles_object *parent,
558558
if (ret < 0)
559559
goto create_error;
560560
start = jiffies;
561-
ret = vfs_create(dir->d_inode, next, S_IFREG, true);
561+
ret = vfs_create(d_inode(dir), next, S_IFREG, true);
562562
cachefiles_hist(cachefiles_create_histogram, start);
563563
if (ret < 0)
564564
goto create_error;
@@ -581,7 +581,7 @@ int cachefiles_walk_to_object(struct cachefiles_object *parent,
581581
/* process the next component */
582582
if (key) {
583583
_debug("advance");
584-
mutex_unlock(&dir->d_inode->i_mutex);
584+
mutex_unlock(&d_inode(dir)->i_mutex);
585585
dput(dir);
586586
dir = next;
587587
next = NULL;
@@ -617,7 +617,7 @@ int cachefiles_walk_to_object(struct cachefiles_object *parent,
617617
/* note that we're now using this object */
618618
ret = cachefiles_mark_object_active(cache, object);
619619

620-
mutex_unlock(&dir->d_inode->i_mutex);
620+
mutex_unlock(&d_inode(dir)->i_mutex);
621621
dput(dir);
622622
dir = NULL;
623623

@@ -695,7 +695,7 @@ int cachefiles_walk_to_object(struct cachefiles_object *parent,
695695
cachefiles_io_error(cache, "Lookup failed");
696696
next = NULL;
697697
error:
698-
mutex_unlock(&dir->d_inode->i_mutex);
698+
mutex_unlock(&d_inode(dir)->i_mutex);
699699
dput(next);
700700
error_out2:
701701
dput(dir);
@@ -719,7 +719,7 @@ struct dentry *cachefiles_get_directory(struct cachefiles_cache *cache,
719719
_enter(",,%s", dirname);
720720

721721
/* search the current directory for the element name */
722-
mutex_lock(&dir->d_inode->i_mutex);
722+
mutex_lock(&d_inode(dir)->i_mutex);
723723

724724
start = jiffies;
725725
subdir = lookup_one_len(dirname, dir, strlen(dirname));
@@ -746,7 +746,7 @@ struct dentry *cachefiles_get_directory(struct cachefiles_cache *cache,
746746
ret = security_path_mkdir(&path, subdir, 0700);
747747
if (ret < 0)
748748
goto mkdir_error;
749-
ret = vfs_mkdir(dir->d_inode, subdir, 0700);
749+
ret = vfs_mkdir(d_inode(dir), subdir, 0700);
750750
if (ret < 0)
751751
goto mkdir_error;
752752

@@ -758,7 +758,7 @@ struct dentry *cachefiles_get_directory(struct cachefiles_cache *cache,
758758
subdir->d_inode->i_ino);
759759
}
760760

761-
mutex_unlock(&dir->d_inode->i_mutex);
761+
mutex_unlock(&d_inode(dir)->i_mutex);
762762

763763
/* we need to make sure the subdir is a directory */
764764
ASSERT(subdir->d_inode);
@@ -790,19 +790,19 @@ struct dentry *cachefiles_get_directory(struct cachefiles_cache *cache,
790790
return ERR_PTR(ret);
791791

792792
mkdir_error:
793-
mutex_unlock(&dir->d_inode->i_mutex);
793+
mutex_unlock(&d_inode(dir)->i_mutex);
794794
dput(subdir);
795795
pr_err("mkdir %s failed with error %d\n", dirname, ret);
796796
return ERR_PTR(ret);
797797

798798
lookup_error:
799-
mutex_unlock(&dir->d_inode->i_mutex);
799+
mutex_unlock(&d_inode(dir)->i_mutex);
800800
ret = PTR_ERR(subdir);
801801
pr_err("Lookup %s failed with error %d\n", dirname, ret);
802802
return ERR_PTR(ret);
803803

804804
nomem_d_alloc:
805-
mutex_unlock(&dir->d_inode->i_mutex);
805+
mutex_unlock(&d_inode(dir)->i_mutex);
806806
_leave(" = -ENOMEM");
807807
return ERR_PTR(-ENOMEM);
808808
}
@@ -827,7 +827,7 @@ static struct dentry *cachefiles_check_active(struct cachefiles_cache *cache,
827827
// dir, filename);
828828

829829
/* look up the victim */
830-
mutex_lock_nested(&dir->d_inode->i_mutex, I_MUTEX_PARENT);
830+
mutex_lock_nested(&d_inode(dir)->i_mutex, I_MUTEX_PARENT);
831831

832832
start = jiffies;
833833
victim = lookup_one_len(filename, dir, strlen(filename));
@@ -842,7 +842,7 @@ static struct dentry *cachefiles_check_active(struct cachefiles_cache *cache,
842842
* at the netfs's request whilst the cull was in progress
843843
*/
844844
if (!victim->d_inode) {
845-
mutex_unlock(&dir->d_inode->i_mutex);
845+
mutex_unlock(&d_inode(dir)->i_mutex);
846846
dput(victim);
847847
_leave(" = -ENOENT [absent]");
848848
return ERR_PTR(-ENOENT);
@@ -871,13 +871,13 @@ static struct dentry *cachefiles_check_active(struct cachefiles_cache *cache,
871871

872872
object_in_use:
873873
read_unlock(&cache->active_lock);
874-
mutex_unlock(&dir->d_inode->i_mutex);
874+
mutex_unlock(&d_inode(dir)->i_mutex);
875875
dput(victim);
876876
//_leave(" = -EBUSY [in use]");
877877
return ERR_PTR(-EBUSY);
878878

879879
lookup_error:
880-
mutex_unlock(&dir->d_inode->i_mutex);
880+
mutex_unlock(&d_inode(dir)->i_mutex);
881881
ret = PTR_ERR(victim);
882882
if (ret == -ENOENT) {
883883
/* file or dir now absent - probably retired by netfs */
@@ -936,7 +936,7 @@ int cachefiles_cull(struct cachefiles_cache *cache, struct dentry *dir,
936936
return 0;
937937

938938
error_unlock:
939-
mutex_unlock(&dir->d_inode->i_mutex);
939+
mutex_unlock(&d_inode(dir)->i_mutex);
940940
error:
941941
dput(victim);
942942
if (ret == -ENOENT) {
@@ -971,7 +971,7 @@ int cachefiles_check_in_use(struct cachefiles_cache *cache, struct dentry *dir,
971971
if (IS_ERR(victim))
972972
return PTR_ERR(victim);
973973

974-
mutex_unlock(&dir->d_inode->i_mutex);
974+
mutex_unlock(&d_inode(dir)->i_mutex);
975975
dput(victim);
976976
//_leave(" = 0");
977977
return 0;

0 commit comments

Comments
 (0)