Skip to content

Commit ec2447c

Browse files
author
Nick Piggin
committed
hostfs: simplify locking
Remove dcache_lock locking from hostfs filesystem, and move it into dcache helpers. All that is required is a coherent path name. Protection from concurrent modification of the namespace after path name generation is not provided in current code, because dcache_lock is dropped before the path is used. Signed-off-by: Nick Piggin <npiggin@kernel.dk>
1 parent b1e6a01 commit ec2447c

3 files changed

Lines changed: 24 additions & 17 deletions

File tree

‎fs/dcache.c‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2171,7 +2171,7 @@ char *dynamic_dname(struct dentry *dentry, char *buffer, int buflen,
21712171
/*
21722172
* Write full pathname from the root of the filesystem into the buffer.
21732173
*/
2174-
char *__dentry_path(struct dentry *dentry, char *buf, int buflen)
2174+
static char *__dentry_path(struct dentry *dentry, char *buf, int buflen)
21752175
{
21762176
char *end = buf + buflen;
21772177
char *retval;
@@ -2198,7 +2198,18 @@ char *__dentry_path(struct dentry *dentry, char *buf, int buflen)
21982198
Elong:
21992199
return ERR_PTR(-ENAMETOOLONG);
22002200
}
2201-
EXPORT_SYMBOL(__dentry_path);
2201+
2202+
char *dentry_path_raw(struct dentry *dentry, char *buf, int buflen)
2203+
{
2204+
char *retval;
2205+
2206+
spin_lock(&dcache_lock);
2207+
retval = __dentry_path(dentry, buf, buflen);
2208+
spin_unlock(&dcache_lock);
2209+
2210+
return retval;
2211+
}
2212+
EXPORT_SYMBOL(dentry_path_raw);
22022213

22032214
char *dentry_path(struct dentry *dentry, char *buf, int buflen)
22042215
{

‎fs/hostfs/hostfs_kern.c‎

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,10 @@ __uml_setup("hostfs=", hostfs_args,
9292

9393
static char *__dentry_name(struct dentry *dentry, char *name)
9494
{
95-
char *p = __dentry_path(dentry, name, PATH_MAX);
95+
char *p = dentry_path_raw(dentry, name, PATH_MAX);
9696
char *root;
9797
size_t len;
9898

99-
spin_unlock(&dcache_lock);
100-
10199
root = dentry->d_sb->s_fs_info;
102100
len = strlen(root);
103101
if (IS_ERR(p)) {
@@ -123,25 +121,23 @@ static char *dentry_name(struct dentry *dentry)
123121
if (!name)
124122
return NULL;
125123

126-
spin_lock(&dcache_lock);
127124
return __dentry_name(dentry, name); /* will unlock */
128125
}
129126

130127
static char *inode_name(struct inode *ino)
131128
{
132129
struct dentry *dentry;
133-
char *name = __getname();
134-
if (!name)
135-
return NULL;
130+
char *name;
136131

137-
spin_lock(&dcache_lock);
138-
if (list_empty(&ino->i_dentry)) {
139-
spin_unlock(&dcache_lock);
140-
__putname(name);
132+
dentry = d_find_alias(ino);
133+
if (!dentry)
141134
return NULL;
142-
}
143-
dentry = list_first_entry(&ino->i_dentry, struct dentry, d_alias);
144-
return __dentry_name(dentry, name); /* will unlock */
135+
136+
name = dentry_name(dentry);
137+
138+
dput(dentry);
139+
140+
return name;
145141
}
146142

147143
static char *follow_link(char *link)

‎include/linux/dcache.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ extern char *dynamic_dname(struct dentry *, char *, int, const char *, ...);
311311
extern char *__d_path(const struct path *path, struct path *root, char *, int);
312312
extern char *d_path(const struct path *, char *, int);
313313
extern char *d_path_with_unreachable(const struct path *, char *, int);
314-
extern char *__dentry_path(struct dentry *, char *, int);
314+
extern char *dentry_path_raw(struct dentry *, char *, int);
315315
extern char *dentry_path(struct dentry *, char *, int);
316316

317317
/* Allocation counts.. */

0 commit comments

Comments
 (0)