Skip to content

Commit 2011067

Browse files
neilbrownbrauner
authored andcommitted
cachefiles: Use lookup_one() rather than lookup_one_len()
cachefiles uses some VFS interfaces (such as vfs_mkdir) which take an explicit mnt_idmap, and it passes &nop_mnt_idmap as cachefiles doesn't yet support idmapped mounts. It also uses the lookup_one_len() family of functions which implicitly use &nop_mnt_idmap. This mixture of implicit and explicit could be confusing. When we eventually update cachefiles to support idmap mounts it would be best if all places which need an idmap determined from the mount point were similar and easily found. So this patch changes cachefiles to use lookup_one(), lookup_one_unlocked(), and lookup_one_positive_unlocked(), passing &nop_mnt_idmap. This has the benefit of removing the remaining user of the lookup_one_len functions where permission checking is actually needed. Other callers don't care about permission checking and using these function only where permission checking is needed is a valuable simplification. This requires passing the name in a qstr. This is easily done with QSTR() as the name is always nul terminated, and often strlen is used anyway. ->d_name_len is removed as no longer useful. Signed-off-by: NeilBrown <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Christian Brauner <[email protected]>
1 parent 8ad9248 commit 2011067

File tree

3 files changed

+7
-9
lines changed

3 files changed

+7
-9
lines changed

fs/cachefiles/internal.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ struct cachefiles_object {
7171
int debug_id;
7272
spinlock_t lock;
7373
refcount_t ref;
74-
u8 d_name_len; /* Length of filename */
7574
enum cachefiles_content content_info:8; /* Info about content presence */
7675
unsigned long flags;
7776
#define CACHEFILES_OBJECT_USING_TMPFILE 0 /* Have an unlinked tmpfile */

fs/cachefiles/key.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ bool cachefiles_cook_key(struct cachefiles_object *object)
132132
success:
133133
name[len] = 0;
134134
object->d_name = name;
135-
object->d_name_len = len;
136135
_leave(" = %s", object->d_name);
137136
return true;
138137
}

fs/cachefiles/namei.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ struct dentry *cachefiles_get_directory(struct cachefiles_cache *cache,
9898
retry:
9999
ret = cachefiles_inject_read_error();
100100
if (ret == 0)
101-
subdir = lookup_one_len(dirname, dir, strlen(dirname));
101+
subdir = lookup_one(&nop_mnt_idmap, &QSTR(dirname), dir);
102102
else
103103
subdir = ERR_PTR(ret);
104104
trace_cachefiles_lookup(NULL, dir, subdir);
@@ -338,7 +338,7 @@ int cachefiles_bury_object(struct cachefiles_cache *cache,
338338
return -EIO;
339339
}
340340

341-
grave = lookup_one_len(nbuffer, cache->graveyard, strlen(nbuffer));
341+
grave = lookup_one(&nop_mnt_idmap, &QSTR(nbuffer), cache->graveyard);
342342
if (IS_ERR(grave)) {
343343
unlock_rename(cache->graveyard, dir);
344344
trace_cachefiles_vfs_error(object, d_inode(cache->graveyard),
@@ -630,8 +630,8 @@ bool cachefiles_look_up_object(struct cachefiles_object *object)
630630
/* Look up path "cache/vol/fanout/file". */
631631
ret = cachefiles_inject_read_error();
632632
if (ret == 0)
633-
dentry = lookup_positive_unlocked(object->d_name, fan,
634-
object->d_name_len);
633+
dentry = lookup_one_positive_unlocked(&nop_mnt_idmap,
634+
&QSTR(object->d_name), fan);
635635
else
636636
dentry = ERR_PTR(ret);
637637
trace_cachefiles_lookup(object, fan, dentry);
@@ -683,7 +683,7 @@ bool cachefiles_commit_tmpfile(struct cachefiles_cache *cache,
683683
inode_lock_nested(d_inode(fan), I_MUTEX_PARENT);
684684
ret = cachefiles_inject_read_error();
685685
if (ret == 0)
686-
dentry = lookup_one_len(object->d_name, fan, object->d_name_len);
686+
dentry = lookup_one(&nop_mnt_idmap, &QSTR(object->d_name), fan);
687687
else
688688
dentry = ERR_PTR(ret);
689689
if (IS_ERR(dentry)) {
@@ -702,7 +702,7 @@ bool cachefiles_commit_tmpfile(struct cachefiles_cache *cache,
702702
dput(dentry);
703703
ret = cachefiles_inject_read_error();
704704
if (ret == 0)
705-
dentry = lookup_one_len(object->d_name, fan, object->d_name_len);
705+
dentry = lookup_one(&nop_mnt_idmap, &QSTR(object->d_name), fan);
706706
else
707707
dentry = ERR_PTR(ret);
708708
if (IS_ERR(dentry)) {
@@ -751,7 +751,7 @@ static struct dentry *cachefiles_lookup_for_cull(struct cachefiles_cache *cache,
751751

752752
inode_lock_nested(d_inode(dir), I_MUTEX_PARENT);
753753

754-
victim = lookup_one_len(filename, dir, strlen(filename));
754+
victim = lookup_one(&nop_mnt_idmap, &QSTR(filename), dir);
755755
if (IS_ERR(victim))
756756
goto lookup_error;
757757
if (d_is_negative(victim))

0 commit comments

Comments
 (0)