Skip to content

Commit cdf0122

Browse files
dhowellsAl Viro
authored andcommitted
VFS: Provide empty name qstr
Provide an empty name (ie. "") qstr for general use. Signed-off-by: David Howells <[email protected]> Signed-off-by: Al Viro <[email protected]>
1 parent ee416bc commit cdf0122

File tree

6 files changed

+15
-10
lines changed

6 files changed

+15
-10
lines changed

fs/dcache.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@ EXPORT_SYMBOL(rename_lock);
9090

9191
static struct kmem_cache *dentry_cache __read_mostly;
9292

93+
const struct qstr empty_name = QSTR_INIT("", 0);
94+
EXPORT_SYMBOL(empty_name);
95+
const struct qstr slash_name = QSTR_INIT("/", 1);
96+
EXPORT_SYMBOL(slash_name);
97+
9398
/*
9499
* This is the single most critical data structure when it comes
95100
* to the dcache: the hashtable for lookups. Somebody should try
@@ -1578,8 +1583,7 @@ struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name)
15781583
*/
15791584
dentry->d_iname[DNAME_INLINE_LEN-1] = 0;
15801585
if (unlikely(!name)) {
1581-
static const struct qstr anon = QSTR_INIT("/", 1);
1582-
name = &anon;
1586+
name = &slash_name;
15831587
dname = dentry->d_iname;
15841588
} else if (name->len > DNAME_INLINE_LEN-1) {
15851589
size_t size = offsetof(struct external_name, name[1]);

fs/gfs2/dir.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -872,7 +872,6 @@ static struct gfs2_leaf *new_leaf(struct inode *inode, struct buffer_head **pbh,
872872
struct buffer_head *bh;
873873
struct gfs2_leaf *leaf;
874874
struct gfs2_dirent *dent;
875-
struct qstr name = { .name = "" };
876875
struct timespec tv = current_time(inode);
877876

878877
error = gfs2_alloc_blocks(ip, &bn, &n, 0, NULL);
@@ -896,7 +895,7 @@ static struct gfs2_leaf *new_leaf(struct inode *inode, struct buffer_head **pbh,
896895
leaf->lf_sec = cpu_to_be64(tv.tv_sec);
897896
memset(leaf->lf_reserved2, 0, sizeof(leaf->lf_reserved2));
898897
dent = (struct gfs2_dirent *)(leaf+1);
899-
gfs2_qstr2dirent(&name, bh->b_size - sizeof(struct gfs2_leaf), dent);
898+
gfs2_qstr2dirent(&empty_name, bh->b_size - sizeof(struct gfs2_leaf), dent);
900899
*pbh = bh;
901900
return leaf;
902901
}

fs/namei.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3400,7 +3400,6 @@ static int do_last(struct nameidata *nd,
34003400

34013401
struct dentry *vfs_tmpfile(struct dentry *dentry, umode_t mode, int open_flag)
34023402
{
3403-
static const struct qstr name = QSTR_INIT("/", 1);
34043403
struct dentry *child = NULL;
34053404
struct inode *dir = dentry->d_inode;
34063405
struct inode *inode;
@@ -3414,7 +3413,7 @@ struct dentry *vfs_tmpfile(struct dentry *dentry, umode_t mode, int open_flag)
34143413
if (!dir->i_op->tmpfile)
34153414
goto out_err;
34163415
error = -ENOMEM;
3417-
child = d_alloc(dentry, &name);
3416+
child = d_alloc(dentry, &slash_name);
34183417
if (unlikely(!child))
34193418
goto out_err;
34203419
error = dir->i_op->tmpfile(dir, child, mode);

fs/nsfs.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ static void nsfs_evict(struct inode *inode)
5353
static void *__ns_get_path(struct path *path, struct ns_common *ns)
5454
{
5555
struct vfsmount *mnt = nsfs_mnt;
56-
struct qstr qname = { .name = "", };
5756
struct dentry *dentry;
5857
struct inode *inode;
5958
unsigned long d;
@@ -85,7 +84,7 @@ static void *__ns_get_path(struct path *path, struct ns_common *ns)
8584
inode->i_fop = &ns_file_operations;
8685
inode->i_private = ns;
8786

88-
dentry = d_alloc_pseudo(mnt->mnt_sb, &qname);
87+
dentry = d_alloc_pseudo(mnt->mnt_sb, &empty_name);
8988
if (!dentry) {
9089
iput(inode);
9190
return ERR_PTR(-ENOMEM);

fs/pipe.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -739,13 +739,12 @@ int create_pipe_files(struct file **res, int flags)
739739
struct inode *inode = get_pipe_inode();
740740
struct file *f;
741741
struct path path;
742-
static struct qstr name = { .name = "" };
743742

744743
if (!inode)
745744
return -ENFILE;
746745

747746
err = -ENOMEM;
748-
path.dentry = d_alloc_pseudo(pipe_mnt->mnt_sb, &name);
747+
path.dentry = d_alloc_pseudo(pipe_mnt->mnt_sb, &empty_name);
749748
if (!path.dentry)
750749
goto err_inode;
751750
path.mnt = mntget(pipe_mnt);

include/linux/dcache.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ struct qstr {
5555

5656
#define QSTR_INIT(n,l) { { { .len = l } }, .name = n }
5757

58+
extern const char empty_string[];
59+
extern const struct qstr empty_name;
60+
extern const char slash_string[];
61+
extern const struct qstr slash_name;
62+
5863
struct dentry_stat_t {
5964
long nr_dentry;
6065
long nr_unused;

0 commit comments

Comments
 (0)