Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

new helper: simple_start_creating()

Set the things up for kernel-initiated creation of object in
a tree-in-dcache filesystem. With respect to locking it's
an equivalent of filename_create() - we either get a negative
dentry with locked parent, or ERR_PTR() and no locks taken.

tracefs and debugfs had that open-coded as part of their
object creation machinery; switched to calling new helper.

Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>

+31 -31
+3 -18
fs/debugfs/inode.c
··· 384 384 if (!parent) 385 385 parent = debugfs_mount->mnt_root; 386 386 387 - inode_lock(d_inode(parent)); 388 - if (unlikely(IS_DEADDIR(d_inode(parent)))) 389 - dentry = ERR_PTR(-ENOENT); 390 - else 391 - dentry = lookup_noperm(&QSTR(name), parent); 392 - if (!IS_ERR(dentry) && d_really_is_positive(dentry)) { 393 - if (d_is_dir(dentry)) 394 - pr_err("Directory '%s' with parent '%s' already present!\n", 395 - name, parent->d_name.name); 396 - else 397 - pr_err("File '%s' in directory '%s' already present!\n", 398 - name, parent->d_name.name); 399 - dput(dentry); 400 - dentry = ERR_PTR(-EEXIST); 401 - } 402 - 387 + dentry = simple_start_creating(parent, name); 403 388 if (IS_ERR(dentry)) { 404 - inode_unlock(d_inode(parent)); 389 + if (dentry == ERR_PTR(-EEXIST)) 390 + pr_err("'%s' already exists in '%pd'\n", name, parent); 405 391 simple_release_fs(&debugfs_mount, &debugfs_mount_count); 406 392 } 407 - 408 393 return dentry; 409 394 } 410 395
+25
fs/libfs.c
··· 2260 2260 */ 2261 2261 cmpxchg(stashed, dentry, NULL); 2262 2262 } 2263 + 2264 + /* parent must be held exclusive */ 2265 + struct dentry *simple_start_creating(struct dentry *parent, const char *name) 2266 + { 2267 + struct dentry *dentry; 2268 + struct inode *dir = d_inode(parent); 2269 + 2270 + inode_lock(dir); 2271 + if (unlikely(IS_DEADDIR(dir))) { 2272 + inode_unlock(dir); 2273 + return ERR_PTR(-ENOENT); 2274 + } 2275 + dentry = lookup_noperm(&QSTR(name), parent); 2276 + if (IS_ERR(dentry)) { 2277 + inode_unlock(dir); 2278 + return dentry; 2279 + } 2280 + if (dentry->d_inode) { 2281 + dput(dentry); 2282 + inode_unlock(dir); 2283 + return ERR_PTR(-EEXIST); 2284 + } 2285 + return dentry; 2286 + } 2287 + EXPORT_SYMBOL(simple_start_creating);
+2 -13
fs/tracefs/inode.c
··· 551 551 if (!parent) 552 552 parent = tracefs_mount->mnt_root; 553 553 554 - inode_lock(d_inode(parent)); 555 - if (unlikely(IS_DEADDIR(d_inode(parent)))) 556 - dentry = ERR_PTR(-ENOENT); 557 - else 558 - dentry = lookup_noperm(&QSTR(name), parent); 559 - if (!IS_ERR(dentry) && d_inode(dentry)) { 560 - dput(dentry); 561 - dentry = ERR_PTR(-EEXIST); 562 - } 563 - 564 - if (IS_ERR(dentry)) { 565 - inode_unlock(d_inode(parent)); 554 + dentry = simple_start_creating(parent, name); 555 + if (IS_ERR(dentry)) 566 556 simple_release_fs(&tracefs_mount, &tracefs_mount_count); 567 - } 568 557 569 558 return dentry; 570 559 }
+1
include/linux/fs.h
··· 3619 3619 const struct tree_descr *); 3620 3620 extern int simple_pin_fs(struct file_system_type *, struct vfsmount **mount, int *count); 3621 3621 extern void simple_release_fs(struct vfsmount **mount, int *count); 3622 + struct dentry *simple_start_creating(struct dentry *, const char *); 3622 3623 3623 3624 extern ssize_t simple_read_from_buffer(void __user *to, size_t count, 3624 3625 loff_t *ppos, const void *from, size_t available);