Skip to content

Commit 4f5ea5a

Browse files
committed
Merge patch series "vfs: preparatory changes to centralize locking of create/remove/rename"
NeilBrown <neilb@ownmail.net> says: This is a re-re-revised selection of cleanups and API renaming which continues my work to centralise locking of create/remove/rename operations. * patches from https://lore.kernel.org/20250922043121.193821-2-neilb@ownmail.net: debugfs: rename start_creating() to debugfs_start_creating() VFS: rename kern_path_locked() and related functions. VFS/audit: introduce kern_path_parent() for audit VFS: unify old_mnt_idmap and new_mnt_idmap in renamedata VFS: discard err2 in filename_create() VFS/ovl: add lookup_one_positive_killable() Signed-off-by: Christian Brauner <brauner@kernel.org>
2 parents 8f5ae30 + 0a2c705 commit 4f5ea5a

20 files changed

Lines changed: 216 additions & 130 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/cachefiles/namei.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -387,10 +387,9 @@ int cachefiles_bury_object(struct cachefiles_cache *cache,
387387
cachefiles_io_error(cache, "Rename security error %d", ret);
388388
} else {
389389
struct renamedata rd = {
390-
.old_mnt_idmap = &nop_mnt_idmap,
390+
.mnt_idmap = &nop_mnt_idmap,
391391
.old_parent = dir,
392392
.old_dentry = rep,
393-
.new_mnt_idmap = &nop_mnt_idmap,
394393
.new_parent = cache->graveyard,
395394
.new_dentry = grave,
396395
};

fs/debugfs/inode.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,8 @@ struct dentry *debugfs_lookup(const char *name, struct dentry *parent)
353353
}
354354
EXPORT_SYMBOL_GPL(debugfs_lookup);
355355

356-
static struct dentry *start_creating(const char *name, struct dentry *parent)
356+
static struct dentry *debugfs_start_creating(const char *name,
357+
struct dentry *parent)
357358
{
358359
struct dentry *dentry;
359360
int error;
@@ -419,7 +420,7 @@ static struct dentry *__debugfs_create_file(const char *name, umode_t mode,
419420
if (!(mode & S_IFMT))
420421
mode |= S_IFREG;
421422
BUG_ON(!S_ISREG(mode));
422-
dentry = start_creating(name, parent);
423+
dentry = debugfs_start_creating(name, parent);
423424

424425
if (IS_ERR(dentry))
425426
return dentry;
@@ -568,7 +569,7 @@ EXPORT_SYMBOL_GPL(debugfs_create_file_size);
568569
*/
569570
struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
570571
{
571-
struct dentry *dentry = start_creating(name, parent);
572+
struct dentry *dentry = debugfs_start_creating(name, parent);
572573
struct inode *inode;
573574

574575
if (IS_ERR(dentry))
@@ -615,7 +616,7 @@ struct dentry *debugfs_create_automount(const char *name,
615616
debugfs_automount_t f,
616617
void *data)
617618
{
618-
struct dentry *dentry = start_creating(name, parent);
619+
struct dentry *dentry = debugfs_start_creating(name, parent);
619620
struct inode *inode;
620621

621622
if (IS_ERR(dentry))
@@ -678,7 +679,7 @@ struct dentry *debugfs_create_symlink(const char *name, struct dentry *parent,
678679
if (!link)
679680
return ERR_PTR(-ENOMEM);
680681

681-
dentry = start_creating(name, parent);
682+
dentry = debugfs_start_creating(name, parent);
682683
if (IS_ERR(dentry)) {
683684
kfree(link);
684685
return dentry;

fs/ecryptfs/inode.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -634,10 +634,9 @@ ecryptfs_rename(struct mnt_idmap *idmap, struct inode *old_dir,
634634
goto out_lock;
635635
}
636636

637-
rd.old_mnt_idmap = &nop_mnt_idmap;
637+
rd.mnt_idmap = &nop_mnt_idmap;
638638
rd.old_parent = lower_old_dir_dentry;
639639
rd.old_dentry = lower_old_dentry;
640-
rd.new_mnt_idmap = &nop_mnt_idmap;
641640
rd.new_parent = lower_new_dir_dentry;
642641
rd.new_dentry = lower_new_dentry;
643642
rc = vfs_rename(&rd);

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

0 commit comments

Comments
 (0)