Skip to content

Commit 3d18f80

Browse files
neilbrownbrauner
authored andcommitted
VFS: rename kern_path_locked() and related functions.
kern_path_locked() is now only used to prepare for removing an object from the filesystem (and that is the only credible reason for wanting a positive locked dentry). Thus it corresponds to kern_path_create() and so should have a corresponding name. Unfortunately the name "kern_path_create" is somewhat misleading as it doesn't actually create anything. The recently added simple_start_creating() provides a better pattern I believe. The "start" can be matched with "end" to bracket the creating or removing. So this patch changes names: kern_path_locked -> start_removing_path kern_path_create -> start_creating_path user_path_create -> start_creating_user_path user_path_locked_at -> start_removing_user_path_at done_path_create -> end_creating_path and also introduces end_removing_path() which is identical to end_creating_path(). __start_removing_path (which was __kern_path_locked) is enhanced to call mnt_want_write() for consistency with the start_creating_path(). Reviewed-by: Amir Goldstein <amir73il@gmail.com> Signed-off-by: NeilBrown <neil@brown.name> Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent 76a53de commit 3d18f80

11 files changed

Lines changed: 93 additions & 67 deletions

File tree

Documentation/filesystems/porting.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1285,3 +1285,15 @@ rather than a VMA, as the VMA at this stage is not yet valid.
12851285
The vm_area_desc provides the minimum required information for a filesystem
12861286
to initialise state upon memory mapping of a file-backed region, and output
12871287
parameters for the file system to set this state.
1288+
1289+
---
1290+
1291+
**mandatory**
1292+
1293+
Several functions are renamed:
1294+
1295+
- kern_path_locked -> start_removing_path
1296+
- kern_path_create -> start_creating_path
1297+
- user_path_create -> start_creating_user_path
1298+
- user_path_locked_at -> start_removing_user_path_at
1299+
- done_path_create -> end_creating_path

arch/powerpc/platforms/cell/spufs/syscalls.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,11 @@ static long do_spu_create(const char __user *pathname, unsigned int flags,
6767
struct dentry *dentry;
6868
int ret;
6969

70-
dentry = user_path_create(AT_FDCWD, pathname, &path, LOOKUP_DIRECTORY);
70+
dentry = start_creating_user_path(AT_FDCWD, pathname, &path, LOOKUP_DIRECTORY);
7171
ret = PTR_ERR(dentry);
7272
if (!IS_ERR(dentry)) {
7373
ret = spufs_create(&path, dentry, flags, mode, neighbor);
74-
done_path_create(&path, dentry);
74+
end_creating_path(&path, dentry);
7575
}
7676

7777
return ret;

drivers/base/devtmpfs.c

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -176,15 +176,15 @@ static int dev_mkdir(const char *name, umode_t mode)
176176
struct dentry *dentry;
177177
struct path path;
178178

179-
dentry = kern_path_create(AT_FDCWD, name, &path, LOOKUP_DIRECTORY);
179+
dentry = start_creating_path(AT_FDCWD, name, &path, LOOKUP_DIRECTORY);
180180
if (IS_ERR(dentry))
181181
return PTR_ERR(dentry);
182182

183183
dentry = vfs_mkdir(&nop_mnt_idmap, d_inode(path.dentry), dentry, mode);
184184
if (!IS_ERR(dentry))
185185
/* mark as kernel-created inode */
186186
d_inode(dentry)->i_private = &thread;
187-
done_path_create(&path, dentry);
187+
end_creating_path(&path, dentry);
188188
return PTR_ERR_OR_ZERO(dentry);
189189
}
190190

@@ -222,10 +222,10 @@ static int handle_create(const char *nodename, umode_t mode, kuid_t uid,
222222
struct path path;
223223
int err;
224224

225-
dentry = kern_path_create(AT_FDCWD, nodename, &path, 0);
225+
dentry = start_creating_path(AT_FDCWD, nodename, &path, 0);
226226
if (dentry == ERR_PTR(-ENOENT)) {
227227
create_path(nodename);
228-
dentry = kern_path_create(AT_FDCWD, nodename, &path, 0);
228+
dentry = start_creating_path(AT_FDCWD, nodename, &path, 0);
229229
}
230230
if (IS_ERR(dentry))
231231
return PTR_ERR(dentry);
@@ -246,7 +246,7 @@ static int handle_create(const char *nodename, umode_t mode, kuid_t uid,
246246
/* mark as kernel-created inode */
247247
d_inode(dentry)->i_private = &thread;
248248
}
249-
done_path_create(&path, dentry);
249+
end_creating_path(&path, dentry);
250250
return err;
251251
}
252252

@@ -256,7 +256,7 @@ static int dev_rmdir(const char *name)
256256
struct dentry *dentry;
257257
int err;
258258

259-
dentry = kern_path_locked(name, &parent);
259+
dentry = start_removing_path(name, &parent);
260260
if (IS_ERR(dentry))
261261
return PTR_ERR(dentry);
262262
if (d_inode(dentry)->i_private == &thread)
@@ -265,9 +265,7 @@ static int dev_rmdir(const char *name)
265265
else
266266
err = -EPERM;
267267

268-
dput(dentry);
269-
inode_unlock(d_inode(parent.dentry));
270-
path_put(&parent);
268+
end_removing_path(&parent, dentry);
271269
return err;
272270
}
273271

@@ -325,7 +323,7 @@ static int handle_remove(const char *nodename, struct device *dev)
325323
int deleted = 0;
326324
int err = 0;
327325

328-
dentry = kern_path_locked(nodename, &parent);
326+
dentry = start_removing_path(nodename, &parent);
329327
if (IS_ERR(dentry))
330328
return PTR_ERR(dentry);
331329

@@ -349,10 +347,8 @@ static int handle_remove(const char *nodename, struct device *dev)
349347
if (!err || err == -ENOENT)
350348
deleted = 1;
351349
}
352-
dput(dentry);
353-
inode_unlock(d_inode(parent.dentry));
350+
end_removing_path(&parent, dentry);
354351

355-
path_put(&parent);
356352
if (deleted && strchr(nodename, '/'))
357353
delete_path(nodename);
358354
return err;

fs/bcachefs/fs-ioctl.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ static long bch2_ioctl_subvolume_create(struct bch_fs *c, struct file *filp,
255255
snapshot_src = inode_inum(to_bch_ei(src_path.dentry->d_inode));
256256
}
257257

258-
dst_dentry = user_path_create(arg.dirfd,
258+
dst_dentry = start_creating_user_path(arg.dirfd,
259259
(const char __user *)(unsigned long)arg.dst_ptr,
260260
&dst_path, lookup_flags);
261261
error = PTR_ERR_OR_ZERO(dst_dentry);
@@ -314,7 +314,7 @@ static long bch2_ioctl_subvolume_create(struct bch_fs *c, struct file *filp,
314314
d_instantiate(dst_dentry, &inode->v);
315315
fsnotify_mkdir(dir, dst_dentry);
316316
err3:
317-
done_path_create(&dst_path, dst_dentry);
317+
end_creating_path(&dst_path, dst_dentry);
318318
err2:
319319
if (arg.src_ptr)
320320
path_put(&src_path);
@@ -334,7 +334,7 @@ static long bch2_ioctl_subvolume_destroy(struct bch_fs *c, struct file *filp,
334334
if (arg.flags)
335335
return -EINVAL;
336336

337-
victim = user_path_locked_at(arg.dirfd, name, &path);
337+
victim = start_removing_user_path_at(arg.dirfd, name, &path);
338338
if (IS_ERR(victim))
339339
return PTR_ERR(victim);
340340

@@ -351,9 +351,7 @@ static long bch2_ioctl_subvolume_destroy(struct bch_fs *c, struct file *filp,
351351
d_invalidate(victim);
352352
}
353353
err:
354-
inode_unlock(dir);
355-
dput(victim);
356-
path_put(&path);
354+
end_removing_path(&path, victim);
357355
return ret;
358356
}
359357

fs/init.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ int __init init_mknod(const char *filename, umode_t mode, unsigned int dev)
149149
else if (!(S_ISBLK(mode) || S_ISCHR(mode)))
150150
return -EINVAL;
151151

152-
dentry = kern_path_create(AT_FDCWD, filename, &path, 0);
152+
dentry = start_creating_path(AT_FDCWD, filename, &path, 0);
153153
if (IS_ERR(dentry))
154154
return PTR_ERR(dentry);
155155

@@ -158,7 +158,7 @@ int __init init_mknod(const char *filename, umode_t mode, unsigned int dev)
158158
if (!error)
159159
error = vfs_mknod(mnt_idmap(path.mnt), path.dentry->d_inode,
160160
dentry, mode, new_decode_dev(dev));
161-
done_path_create(&path, dentry);
161+
end_creating_path(&path, dentry);
162162
return error;
163163
}
164164

@@ -173,7 +173,7 @@ int __init init_link(const char *oldname, const char *newname)
173173
if (error)
174174
return error;
175175

176-
new_dentry = kern_path_create(AT_FDCWD, newname, &new_path, 0);
176+
new_dentry = start_creating_path(AT_FDCWD, newname, &new_path, 0);
177177
error = PTR_ERR(new_dentry);
178178
if (IS_ERR(new_dentry))
179179
goto out;
@@ -191,7 +191,7 @@ int __init init_link(const char *oldname, const char *newname)
191191
error = vfs_link(old_path.dentry, idmap, new_path.dentry->d_inode,
192192
new_dentry, NULL);
193193
out_dput:
194-
done_path_create(&new_path, new_dentry);
194+
end_creating_path(&new_path, new_dentry);
195195
out:
196196
path_put(&old_path);
197197
return error;
@@ -203,14 +203,14 @@ int __init init_symlink(const char *oldname, const char *newname)
203203
struct path path;
204204
int error;
205205

206-
dentry = kern_path_create(AT_FDCWD, newname, &path, 0);
206+
dentry = start_creating_path(AT_FDCWD, newname, &path, 0);
207207
if (IS_ERR(dentry))
208208
return PTR_ERR(dentry);
209209
error = security_path_symlink(&path, dentry, oldname);
210210
if (!error)
211211
error = vfs_symlink(mnt_idmap(path.mnt), path.dentry->d_inode,
212212
dentry, oldname);
213-
done_path_create(&path, dentry);
213+
end_creating_path(&path, dentry);
214214
return error;
215215
}
216216

@@ -225,7 +225,8 @@ int __init init_mkdir(const char *pathname, umode_t mode)
225225
struct path path;
226226
int error;
227227

228-
dentry = kern_path_create(AT_FDCWD, pathname, &path, LOOKUP_DIRECTORY);
228+
dentry = start_creating_path(AT_FDCWD, pathname, &path,
229+
LOOKUP_DIRECTORY);
229230
if (IS_ERR(dentry))
230231
return PTR_ERR(dentry);
231232
mode = mode_strip_umask(d_inode(path.dentry), mode);
@@ -236,7 +237,7 @@ int __init init_mkdir(const char *pathname, umode_t mode)
236237
if (IS_ERR(dentry))
237238
error = PTR_ERR(dentry);
238239
}
239-
done_path_create(&path, dentry);
240+
end_creating_path(&path, dentry);
240241
return error;
241242
}
242243

fs/namei.c

Lines changed: 37 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2758,7 +2758,8 @@ static int filename_parentat(int dfd, struct filename *name,
27582758
}
27592759

27602760
/* does lookup, returns the object with parent locked */
2761-
static struct dentry *__kern_path_locked(int dfd, struct filename *name, struct path *path)
2761+
static struct dentry *__start_removing_path(int dfd, struct filename *name,
2762+
struct path *path)
27622763
{
27632764
struct path parent_path __free(path_put) = {};
27642765
struct dentry *d;
@@ -2770,15 +2771,26 @@ static struct dentry *__kern_path_locked(int dfd, struct filename *name, struct
27702771
return ERR_PTR(error);
27712772
if (unlikely(type != LAST_NORM))
27722773
return ERR_PTR(-EINVAL);
2774+
/* don't fail immediately if it's r/o, at least try to report other errors */
2775+
error = mnt_want_write(parent_path.mnt);
27732776
inode_lock_nested(parent_path.dentry->d_inode, I_MUTEX_PARENT);
27742777
d = lookup_one_qstr_excl(&last, parent_path.dentry, 0);
2775-
if (IS_ERR(d)) {
2776-
inode_unlock(parent_path.dentry->d_inode);
2777-
return d;
2778-
}
2778+
if (IS_ERR(d))
2779+
goto unlock;
2780+
if (error)
2781+
goto fail;
27792782
path->dentry = no_free_ptr(parent_path.dentry);
27802783
path->mnt = no_free_ptr(parent_path.mnt);
27812784
return d;
2785+
2786+
fail:
2787+
dput(d);
2788+
d = ERR_PTR(error);
2789+
unlock:
2790+
inode_unlock(parent_path.dentry->d_inode);
2791+
if (!error)
2792+
mnt_drop_write(parent_path.mnt);
2793+
return d;
27822794
}
27832795

27842796
/**
@@ -2816,24 +2828,26 @@ struct dentry *kern_path_parent(const char *name, struct path *path)
28162828
return d;
28172829
}
28182830

2819-
struct dentry *kern_path_locked(const char *name, struct path *path)
2831+
struct dentry *start_removing_path(const char *name, struct path *path)
28202832
{
28212833
struct filename *filename = getname_kernel(name);
2822-
struct dentry *res = __kern_path_locked(AT_FDCWD, filename, path);
2834+
struct dentry *res = __start_removing_path(AT_FDCWD, filename, path);
28232835

28242836
putname(filename);
28252837
return res;
28262838
}
28272839

2828-
struct dentry *user_path_locked_at(int dfd, const char __user *name, struct path *path)
2840+
struct dentry *start_removing_user_path_at(int dfd,
2841+
const char __user *name,
2842+
struct path *path)
28292843
{
28302844
struct filename *filename = getname(name);
2831-
struct dentry *res = __kern_path_locked(dfd, filename, path);
2845+
struct dentry *res = __start_removing_path(dfd, filename, path);
28322846

28332847
putname(filename);
28342848
return res;
28352849
}
2836-
EXPORT_SYMBOL(user_path_locked_at);
2850+
EXPORT_SYMBOL(start_removing_user_path_at);
28372851

28382852
int kern_path(const char *name, unsigned int flags, struct path *path)
28392853
{
@@ -4223,37 +4237,38 @@ static struct dentry *filename_create(int dfd, struct filename *name,
42234237
return dentry;
42244238
}
42254239

4226-
struct dentry *kern_path_create(int dfd, const char *pathname,
4227-
struct path *path, unsigned int lookup_flags)
4240+
struct dentry *start_creating_path(int dfd, const char *pathname,
4241+
struct path *path, unsigned int lookup_flags)
42284242
{
42294243
struct filename *filename = getname_kernel(pathname);
42304244
struct dentry *res = filename_create(dfd, filename, path, lookup_flags);
42314245

42324246
putname(filename);
42334247
return res;
42344248
}
4235-
EXPORT_SYMBOL(kern_path_create);
4249+
EXPORT_SYMBOL(start_creating_path);
42364250

4237-
void done_path_create(struct path *path, struct dentry *dentry)
4251+
void end_creating_path(struct path *path, struct dentry *dentry)
42384252
{
42394253
if (!IS_ERR(dentry))
42404254
dput(dentry);
42414255
inode_unlock(path->dentry->d_inode);
42424256
mnt_drop_write(path->mnt);
42434257
path_put(path);
42444258
}
4245-
EXPORT_SYMBOL(done_path_create);
4259+
EXPORT_SYMBOL(end_creating_path);
42464260

4247-
inline struct dentry *user_path_create(int dfd, const char __user *pathname,
4248-
struct path *path, unsigned int lookup_flags)
4261+
inline struct dentry *start_creating_user_path(
4262+
int dfd, const char __user *pathname,
4263+
struct path *path, unsigned int lookup_flags)
42494264
{
42504265
struct filename *filename = getname(pathname);
42514266
struct dentry *res = filename_create(dfd, filename, path, lookup_flags);
42524267

42534268
putname(filename);
42544269
return res;
42554270
}
4256-
EXPORT_SYMBOL(user_path_create);
4271+
EXPORT_SYMBOL(start_creating_user_path);
42574272

42584273
/**
42594274
* vfs_mknod - create device node or file
@@ -4361,7 +4376,7 @@ static int do_mknodat(int dfd, struct filename *name, umode_t mode,
43614376
break;
43624377
}
43634378
out2:
4364-
done_path_create(&path, dentry);
4379+
end_creating_path(&path, dentry);
43654380
if (retry_estale(error, lookup_flags)) {
43664381
lookup_flags |= LOOKUP_REVAL;
43674382
goto retry;
@@ -4465,7 +4480,7 @@ int do_mkdirat(int dfd, struct filename *name, umode_t mode)
44654480
if (IS_ERR(dentry))
44664481
error = PTR_ERR(dentry);
44674482
}
4468-
done_path_create(&path, dentry);
4483+
end_creating_path(&path, dentry);
44694484
if (retry_estale(error, lookup_flags)) {
44704485
lookup_flags |= LOOKUP_REVAL;
44714486
goto retry;
@@ -4819,7 +4834,7 @@ int do_symlinkat(struct filename *from, int newdfd, struct filename *to)
48194834
if (!error)
48204835
error = vfs_symlink(mnt_idmap(path.mnt), path.dentry->d_inode,
48214836
dentry, from->name);
4822-
done_path_create(&path, dentry);
4837+
end_creating_path(&path, dentry);
48234838
if (retry_estale(error, lookup_flags)) {
48244839
lookup_flags |= LOOKUP_REVAL;
48254840
goto retry;
@@ -4988,7 +5003,7 @@ int do_linkat(int olddfd, struct filename *old, int newdfd,
49885003
error = vfs_link(old_path.dentry, idmap, new_path.dentry->d_inode,
49895004
new_dentry, &delegated_inode);
49905005
out_dput:
4991-
done_path_create(&new_path, new_dentry);
5006+
end_creating_path(&new_path, new_dentry);
49925007
if (delegated_inode) {
49935008
error = break_deleg_wait(&delegated_inode);
49945009
if (!error) {

fs/ocfs2/refcounttree.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4418,7 +4418,7 @@ int ocfs2_reflink_ioctl(struct inode *inode,
44184418
return error;
44194419
}
44204420

4421-
new_dentry = user_path_create(AT_FDCWD, newname, &new_path, 0);
4421+
new_dentry = start_creating_user_path(AT_FDCWD, newname, &new_path, 0);
44224422
error = PTR_ERR(new_dentry);
44234423
if (IS_ERR(new_dentry)) {
44244424
mlog_errno(error);
@@ -4435,7 +4435,7 @@ int ocfs2_reflink_ioctl(struct inode *inode,
44354435
d_inode(new_path.dentry),
44364436
new_dentry, preserve);
44374437
out_dput:
4438-
done_path_create(&new_path, new_dentry);
4438+
end_creating_path(&new_path, new_dentry);
44394439
out:
44404440
path_put(&old_path);
44414441

0 commit comments

Comments
 (0)