aboutsummaryrefslogtreecommitdiffstats
path: root/fs/cachefiles/namei.c
diff options
context:
space:
mode:
authorDavid Howells <dhowells@redhat.com>2015-03-06 09:08:58 -0500
committerAl Viro <viro@zeniv.linux.org.uk>2015-04-15 15:06:54 -0400
commit5153bc817cdbed826a18938393cc1f81ebbbd898 (patch)
tree0efd65b8539dd457b62e420cfed958fdd6dad003 /fs/cachefiles/namei.c
parentee8ac4d61c2cf43bdd427e70db97ac330e61570d (diff)
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>
Diffstat (limited to 'fs/cachefiles/namei.c')
-rw-r--r--fs/cachefiles/namei.c52
1 files changed, 26 insertions, 26 deletions
diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
index 1e51714eb33e..61396359863f 100644
--- a/fs/cachefiles/namei.c
+++ b/fs/cachefiles/namei.c
@@ -286,13 +286,13 @@ static int cachefiles_bury_object(struct cachefiles_cache *cache,
286 if (ret < 0) { 286 if (ret < 0) {
287 cachefiles_io_error(cache, "Unlink security error"); 287 cachefiles_io_error(cache, "Unlink security error");
288 } else { 288 } else {
289 ret = vfs_unlink(dir->d_inode, rep, NULL); 289 ret = vfs_unlink(d_inode(dir), rep, NULL);
290 290
291 if (preemptive) 291 if (preemptive)
292 cachefiles_mark_object_buried(cache, rep); 292 cachefiles_mark_object_buried(cache, rep);
293 } 293 }
294 294
295 mutex_unlock(&dir->d_inode->i_mutex); 295 mutex_unlock(&d_inode(dir)->i_mutex);
296 296
297 if (ret == -EIO) 297 if (ret == -EIO)
298 cachefiles_io_error(cache, "Unlink failed"); 298 cachefiles_io_error(cache, "Unlink failed");
@@ -303,7 +303,7 @@ static int cachefiles_bury_object(struct cachefiles_cache *cache,
303 303
304 /* directories have to be moved to the graveyard */ 304 /* directories have to be moved to the graveyard */
305 _debug("move stale object to graveyard"); 305 _debug("move stale object to graveyard");
306 mutex_unlock(&dir->d_inode->i_mutex); 306 mutex_unlock(&d_inode(dir)->i_mutex);
307 307
308try_again: 308try_again:
309 /* first step is to make up a grave dentry in the graveyard */ 309 /* first step is to make up a grave dentry in the graveyard */
@@ -387,8 +387,8 @@ try_again:
387 if (ret < 0) { 387 if (ret < 0) {
388 cachefiles_io_error(cache, "Rename security error %d", ret); 388 cachefiles_io_error(cache, "Rename security error %d", ret);
389 } else { 389 } else {
390 ret = vfs_rename(dir->d_inode, rep, 390 ret = vfs_rename(d_inode(dir), rep,
391 cache->graveyard->d_inode, grave, NULL, 0); 391 d_inode(cache->graveyard), grave, NULL, 0);
392 if (ret != 0 && ret != -ENOMEM) 392 if (ret != 0 && ret != -ENOMEM)
393 cachefiles_io_error(cache, 393 cachefiles_io_error(cache,
394 "Rename failed with error %d", ret); 394 "Rename failed with error %d", ret);
@@ -420,13 +420,13 @@ int cachefiles_delete_object(struct cachefiles_cache *cache,
420 420
421 dir = dget_parent(object->dentry); 421 dir = dget_parent(object->dentry);
422 422
423 mutex_lock_nested(&dir->d_inode->i_mutex, I_MUTEX_PARENT); 423 mutex_lock_nested(&d_inode(dir)->i_mutex, I_MUTEX_PARENT);
424 424
425 if (test_bit(CACHEFILES_OBJECT_BURIED, &object->flags)) { 425 if (test_bit(CACHEFILES_OBJECT_BURIED, &object->flags)) {
426 /* object allocation for the same key preemptively deleted this 426 /* object allocation for the same key preemptively deleted this
427 * object's file so that it could create its own file */ 427 * object's file so that it could create its own file */
428 _debug("object preemptively buried"); 428 _debug("object preemptively buried");
429 mutex_unlock(&dir->d_inode->i_mutex); 429 mutex_unlock(&d_inode(dir)->i_mutex);
430 ret = 0; 430 ret = 0;
431 } else { 431 } else {
432 /* we need to check that our parent is _still_ our parent - it 432 /* we need to check that our parent is _still_ our parent - it
@@ -438,7 +438,7 @@ int cachefiles_delete_object(struct cachefiles_cache *cache,
438 /* it got moved, presumably by cachefilesd culling it, 438 /* it got moved, presumably by cachefilesd culling it,
439 * so it's no longer in the key path and we can ignore 439 * so it's no longer in the key path and we can ignore
440 * it */ 440 * it */
441 mutex_unlock(&dir->d_inode->i_mutex); 441 mutex_unlock(&d_inode(dir)->i_mutex);
442 ret = 0; 442 ret = 0;
443 } 443 }
444 } 444 }
@@ -497,7 +497,7 @@ lookup_again:
497 /* search the current directory for the element name */ 497 /* search the current directory for the element name */
498 _debug("lookup '%s'", name); 498 _debug("lookup '%s'", name);
499 499
500 mutex_lock_nested(&dir->d_inode->i_mutex, I_MUTEX_PARENT); 500 mutex_lock_nested(&d_inode(dir)->i_mutex, I_MUTEX_PARENT);
501 501
502 start = jiffies; 502 start = jiffies;
503 next = lookup_one_len(name, dir, nlen); 503 next = lookup_one_len(name, dir, nlen);
@@ -529,7 +529,7 @@ lookup_again:
529 if (ret < 0) 529 if (ret < 0)
530 goto create_error; 530 goto create_error;
531 start = jiffies; 531 start = jiffies;
532 ret = vfs_mkdir(dir->d_inode, next, 0); 532 ret = vfs_mkdir(d_inode(dir), next, 0);
533 cachefiles_hist(cachefiles_mkdir_histogram, start); 533 cachefiles_hist(cachefiles_mkdir_histogram, start);
534 if (ret < 0) 534 if (ret < 0)
535 goto create_error; 535 goto create_error;
@@ -558,7 +558,7 @@ lookup_again:
558 if (ret < 0) 558 if (ret < 0)
559 goto create_error; 559 goto create_error;
560 start = jiffies; 560 start = jiffies;
561 ret = vfs_create(dir->d_inode, next, S_IFREG, true); 561 ret = vfs_create(d_inode(dir), next, S_IFREG, true);
562 cachefiles_hist(cachefiles_create_histogram, start); 562 cachefiles_hist(cachefiles_create_histogram, start);
563 if (ret < 0) 563 if (ret < 0)
564 goto create_error; 564 goto create_error;
@@ -581,7 +581,7 @@ lookup_again:
581 /* process the next component */ 581 /* process the next component */
582 if (key) { 582 if (key) {
583 _debug("advance"); 583 _debug("advance");
584 mutex_unlock(&dir->d_inode->i_mutex); 584 mutex_unlock(&d_inode(dir)->i_mutex);
585 dput(dir); 585 dput(dir);
586 dir = next; 586 dir = next;
587 next = NULL; 587 next = NULL;
@@ -617,7 +617,7 @@ lookup_again:
617 /* note that we're now using this object */ 617 /* note that we're now using this object */
618 ret = cachefiles_mark_object_active(cache, object); 618 ret = cachefiles_mark_object_active(cache, object);
619 619
620 mutex_unlock(&dir->d_inode->i_mutex); 620 mutex_unlock(&d_inode(dir)->i_mutex);
621 dput(dir); 621 dput(dir);
622 dir = NULL; 622 dir = NULL;
623 623
@@ -695,7 +695,7 @@ lookup_error:
695 cachefiles_io_error(cache, "Lookup failed"); 695 cachefiles_io_error(cache, "Lookup failed");
696 next = NULL; 696 next = NULL;
697error: 697error:
698 mutex_unlock(&dir->d_inode->i_mutex); 698 mutex_unlock(&d_inode(dir)->i_mutex);
699 dput(next); 699 dput(next);
700error_out2: 700error_out2:
701 dput(dir); 701 dput(dir);
@@ -719,7 +719,7 @@ struct dentry *cachefiles_get_directory(struct cachefiles_cache *cache,
719 _enter(",,%s", dirname); 719 _enter(",,%s", dirname);
720 720
721 /* search the current directory for the element name */ 721 /* search the current directory for the element name */
722 mutex_lock(&dir->d_inode->i_mutex); 722 mutex_lock(&d_inode(dir)->i_mutex);
723 723
724 start = jiffies; 724 start = jiffies;
725 subdir = lookup_one_len(dirname, dir, strlen(dirname)); 725 subdir = lookup_one_len(dirname, dir, strlen(dirname));
@@ -746,7 +746,7 @@ struct dentry *cachefiles_get_directory(struct cachefiles_cache *cache,
746 ret = security_path_mkdir(&path, subdir, 0700); 746 ret = security_path_mkdir(&path, subdir, 0700);
747 if (ret < 0) 747 if (ret < 0)
748 goto mkdir_error; 748 goto mkdir_error;
749 ret = vfs_mkdir(dir->d_inode, subdir, 0700); 749 ret = vfs_mkdir(d_inode(dir), subdir, 0700);
750 if (ret < 0) 750 if (ret < 0)
751 goto mkdir_error; 751 goto mkdir_error;
752 752
@@ -758,7 +758,7 @@ struct dentry *cachefiles_get_directory(struct cachefiles_cache *cache,
758 subdir->d_inode->i_ino); 758 subdir->d_inode->i_ino);
759 } 759 }
760 760
761 mutex_unlock(&dir->d_inode->i_mutex); 761 mutex_unlock(&d_inode(dir)->i_mutex);
762 762
763 /* we need to make sure the subdir is a directory */ 763 /* we need to make sure the subdir is a directory */
764 ASSERT(subdir->d_inode); 764 ASSERT(subdir->d_inode);
@@ -790,19 +790,19 @@ check_error:
790 return ERR_PTR(ret); 790 return ERR_PTR(ret);
791 791
792mkdir_error: 792mkdir_error:
793 mutex_unlock(&dir->d_inode->i_mutex); 793 mutex_unlock(&d_inode(dir)->i_mutex);
794 dput(subdir); 794 dput(subdir);
795 pr_err("mkdir %s failed with error %d\n", dirname, ret); 795 pr_err("mkdir %s failed with error %d\n", dirname, ret);
796 return ERR_PTR(ret); 796 return ERR_PTR(ret);
797 797
798lookup_error: 798lookup_error:
799 mutex_unlock(&dir->d_inode->i_mutex); 799 mutex_unlock(&d_inode(dir)->i_mutex);
800 ret = PTR_ERR(subdir); 800 ret = PTR_ERR(subdir);
801 pr_err("Lookup %s failed with error %d\n", dirname, ret); 801 pr_err("Lookup %s failed with error %d\n", dirname, ret);
802 return ERR_PTR(ret); 802 return ERR_PTR(ret);
803 803
804nomem_d_alloc: 804nomem_d_alloc:
805 mutex_unlock(&dir->d_inode->i_mutex); 805 mutex_unlock(&d_inode(dir)->i_mutex);
806 _leave(" = -ENOMEM"); 806 _leave(" = -ENOMEM");
807 return ERR_PTR(-ENOMEM); 807 return ERR_PTR(-ENOMEM);
808} 808}
@@ -827,7 +827,7 @@ static struct dentry *cachefiles_check_active(struct cachefiles_cache *cache,
827 // dir, filename); 827 // dir, filename);
828 828
829 /* look up the victim */ 829 /* 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);
831 831
832 start = jiffies; 832 start = jiffies;
833 victim = lookup_one_len(filename, dir, strlen(filename)); 833 victim = lookup_one_len(filename, dir, strlen(filename));
@@ -842,7 +842,7 @@ static struct dentry *cachefiles_check_active(struct cachefiles_cache *cache,
842 * at the netfs's request whilst the cull was in progress 842 * at the netfs's request whilst the cull was in progress
843 */ 843 */
844 if (!victim->d_inode) { 844 if (!victim->d_inode) {
845 mutex_unlock(&dir->d_inode->i_mutex); 845 mutex_unlock(&d_inode(dir)->i_mutex);
846 dput(victim); 846 dput(victim);
847 _leave(" = -ENOENT [absent]"); 847 _leave(" = -ENOENT [absent]");
848 return ERR_PTR(-ENOENT); 848 return ERR_PTR(-ENOENT);
@@ -871,13 +871,13 @@ static struct dentry *cachefiles_check_active(struct cachefiles_cache *cache,
871 871
872object_in_use: 872object_in_use:
873 read_unlock(&cache->active_lock); 873 read_unlock(&cache->active_lock);
874 mutex_unlock(&dir->d_inode->i_mutex); 874 mutex_unlock(&d_inode(dir)->i_mutex);
875 dput(victim); 875 dput(victim);
876 //_leave(" = -EBUSY [in use]"); 876 //_leave(" = -EBUSY [in use]");
877 return ERR_PTR(-EBUSY); 877 return ERR_PTR(-EBUSY);
878 878
879lookup_error: 879lookup_error:
880 mutex_unlock(&dir->d_inode->i_mutex); 880 mutex_unlock(&d_inode(dir)->i_mutex);
881 ret = PTR_ERR(victim); 881 ret = PTR_ERR(victim);
882 if (ret == -ENOENT) { 882 if (ret == -ENOENT) {
883 /* file or dir now absent - probably retired by netfs */ 883 /* file or dir now absent - probably retired by netfs */
@@ -936,7 +936,7 @@ int cachefiles_cull(struct cachefiles_cache *cache, struct dentry *dir,
936 return 0; 936 return 0;
937 937
938error_unlock: 938error_unlock:
939 mutex_unlock(&dir->d_inode->i_mutex); 939 mutex_unlock(&d_inode(dir)->i_mutex);
940error: 940error:
941 dput(victim); 941 dput(victim);
942 if (ret == -ENOENT) { 942 if (ret == -ENOENT) {
@@ -971,7 +971,7 @@ int cachefiles_check_in_use(struct cachefiles_cache *cache, struct dentry *dir,
971 if (IS_ERR(victim)) 971 if (IS_ERR(victim))
972 return PTR_ERR(victim); 972 return PTR_ERR(victim);
973 973
974 mutex_unlock(&dir->d_inode->i_mutex); 974 mutex_unlock(&d_inode(dir)->i_mutex);
975 dput(victim); 975 dput(victim);
976 //_leave(" = 0"); 976 //_leave(" = 0");
977 return 0; 977 return 0;