diff options
author | David Howells <dhowells@redhat.com> | 2017-07-04 12:25:22 -0400 |
---|---|---|
committer | Al Viro <viro@zeniv.linux.org.uk> | 2017-07-06 03:27:09 -0400 |
commit | cdf01226b26e98c79c13b335fbe0cbbbe850cf44 (patch) | |
tree | 979318b9a3b69b03b39f6e66d3ffa75b82565ddc | |
parent | ee416bcdba9975065de571e09de1f7ebfde2156a (diff) |
VFS: Provide empty name qstr
Provide an empty name (ie. "") qstr for general use.
Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
-rw-r--r-- | fs/dcache.c | 8 | ||||
-rw-r--r-- | fs/gfs2/dir.c | 3 | ||||
-rw-r--r-- | fs/namei.c | 3 | ||||
-rw-r--r-- | fs/nsfs.c | 3 | ||||
-rw-r--r-- | fs/pipe.c | 3 | ||||
-rw-r--r-- | include/linux/dcache.h | 5 |
6 files changed, 15 insertions, 10 deletions
diff --git a/fs/dcache.c b/fs/dcache.c index a9f995f6859e..95efb7b2bf84 100644 --- a/fs/dcache.c +++ b/fs/dcache.c | |||
@@ -90,6 +90,11 @@ EXPORT_SYMBOL(rename_lock); | |||
90 | 90 | ||
91 | static struct kmem_cache *dentry_cache __read_mostly; | 91 | static struct kmem_cache *dentry_cache __read_mostly; |
92 | 92 | ||
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 | |||
93 | /* | 98 | /* |
94 | * This is the single most critical data structure when it comes | 99 | * This is the single most critical data structure when it comes |
95 | * to the dcache: the hashtable for lookups. Somebody should try | 100 | * 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) | |||
1578 | */ | 1583 | */ |
1579 | dentry->d_iname[DNAME_INLINE_LEN-1] = 0; | 1584 | dentry->d_iname[DNAME_INLINE_LEN-1] = 0; |
1580 | if (unlikely(!name)) { | 1585 | if (unlikely(!name)) { |
1581 | static const struct qstr anon = QSTR_INIT("/", 1); | 1586 | name = &slash_name; |
1582 | name = &anon; | ||
1583 | dname = dentry->d_iname; | 1587 | dname = dentry->d_iname; |
1584 | } else if (name->len > DNAME_INLINE_LEN-1) { | 1588 | } else if (name->len > DNAME_INLINE_LEN-1) { |
1585 | size_t size = offsetof(struct external_name, name[1]); | 1589 | size_t size = offsetof(struct external_name, name[1]); |
diff --git a/fs/gfs2/dir.c b/fs/gfs2/dir.c index 79113219be5f..a5dfff6a033e 100644 --- a/fs/gfs2/dir.c +++ b/fs/gfs2/dir.c | |||
@@ -872,7 +872,6 @@ static struct gfs2_leaf *new_leaf(struct inode *inode, struct buffer_head **pbh, | |||
872 | struct buffer_head *bh; | 872 | struct buffer_head *bh; |
873 | struct gfs2_leaf *leaf; | 873 | struct gfs2_leaf *leaf; |
874 | struct gfs2_dirent *dent; | 874 | struct gfs2_dirent *dent; |
875 | struct qstr name = { .name = "" }; | ||
876 | struct timespec tv = current_time(inode); | 875 | struct timespec tv = current_time(inode); |
877 | 876 | ||
878 | error = gfs2_alloc_blocks(ip, &bn, &n, 0, NULL); | 877 | 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, | |||
896 | leaf->lf_sec = cpu_to_be64(tv.tv_sec); | 895 | leaf->lf_sec = cpu_to_be64(tv.tv_sec); |
897 | memset(leaf->lf_reserved2, 0, sizeof(leaf->lf_reserved2)); | 896 | memset(leaf->lf_reserved2, 0, sizeof(leaf->lf_reserved2)); |
898 | dent = (struct gfs2_dirent *)(leaf+1); | 897 | 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); |
900 | *pbh = bh; | 899 | *pbh = bh; |
901 | return leaf; | 900 | return leaf; |
902 | } | 901 | } |
diff --git a/fs/namei.c b/fs/namei.c index 6571a5f5112e..0d35760fee00 100644 --- a/fs/namei.c +++ b/fs/namei.c | |||
@@ -3400,7 +3400,6 @@ out: | |||
3400 | 3400 | ||
3401 | struct dentry *vfs_tmpfile(struct dentry *dentry, umode_t mode, int open_flag) | 3401 | struct dentry *vfs_tmpfile(struct dentry *dentry, umode_t mode, int open_flag) |
3402 | { | 3402 | { |
3403 | static const struct qstr name = QSTR_INIT("/", 1); | ||
3404 | struct dentry *child = NULL; | 3403 | struct dentry *child = NULL; |
3405 | struct inode *dir = dentry->d_inode; | 3404 | struct inode *dir = dentry->d_inode; |
3406 | struct inode *inode; | 3405 | struct inode *inode; |
@@ -3414,7 +3413,7 @@ struct dentry *vfs_tmpfile(struct dentry *dentry, umode_t mode, int open_flag) | |||
3414 | if (!dir->i_op->tmpfile) | 3413 | if (!dir->i_op->tmpfile) |
3415 | goto out_err; | 3414 | goto out_err; |
3416 | error = -ENOMEM; | 3415 | error = -ENOMEM; |
3417 | child = d_alloc(dentry, &name); | 3416 | child = d_alloc(dentry, &slash_name); |
3418 | if (unlikely(!child)) | 3417 | if (unlikely(!child)) |
3419 | goto out_err; | 3418 | goto out_err; |
3420 | error = dir->i_op->tmpfile(dir, child, mode); | 3419 | error = dir->i_op->tmpfile(dir, child, mode); |
@@ -53,7 +53,6 @@ static void nsfs_evict(struct inode *inode) | |||
53 | static void *__ns_get_path(struct path *path, struct ns_common *ns) | 53 | static void *__ns_get_path(struct path *path, struct ns_common *ns) |
54 | { | 54 | { |
55 | struct vfsmount *mnt = nsfs_mnt; | 55 | struct vfsmount *mnt = nsfs_mnt; |
56 | struct qstr qname = { .name = "", }; | ||
57 | struct dentry *dentry; | 56 | struct dentry *dentry; |
58 | struct inode *inode; | 57 | struct inode *inode; |
59 | unsigned long d; | 58 | unsigned long d; |
@@ -85,7 +84,7 @@ slow: | |||
85 | inode->i_fop = &ns_file_operations; | 84 | inode->i_fop = &ns_file_operations; |
86 | inode->i_private = ns; | 85 | inode->i_private = ns; |
87 | 86 | ||
88 | dentry = d_alloc_pseudo(mnt->mnt_sb, &qname); | 87 | dentry = d_alloc_pseudo(mnt->mnt_sb, &empty_name); |
89 | if (!dentry) { | 88 | if (!dentry) { |
90 | iput(inode); | 89 | iput(inode); |
91 | return ERR_PTR(-ENOMEM); | 90 | return ERR_PTR(-ENOMEM); |
@@ -739,13 +739,12 @@ int create_pipe_files(struct file **res, int flags) | |||
739 | struct inode *inode = get_pipe_inode(); | 739 | struct inode *inode = get_pipe_inode(); |
740 | struct file *f; | 740 | struct file *f; |
741 | struct path path; | 741 | struct path path; |
742 | static struct qstr name = { .name = "" }; | ||
743 | 742 | ||
744 | if (!inode) | 743 | if (!inode) |
745 | return -ENFILE; | 744 | return -ENFILE; |
746 | 745 | ||
747 | err = -ENOMEM; | 746 | 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); |
749 | if (!path.dentry) | 748 | if (!path.dentry) |
750 | goto err_inode; | 749 | goto err_inode; |
751 | path.mnt = mntget(pipe_mnt); | 750 | path.mnt = mntget(pipe_mnt); |
diff --git a/include/linux/dcache.h b/include/linux/dcache.h index d2e38dc6172c..3f65a4fa72ed 100644 --- a/include/linux/dcache.h +++ b/include/linux/dcache.h | |||
@@ -55,6 +55,11 @@ struct qstr { | |||
55 | 55 | ||
56 | #define QSTR_INIT(n,l) { { { .len = l } }, .name = n } | 56 | #define QSTR_INIT(n,l) { { { .len = l } }, .name = n } |
57 | 57 | ||
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 | |||
58 | struct dentry_stat_t { | 63 | struct dentry_stat_t { |
59 | long nr_dentry; | 64 | long nr_dentry; |
60 | long nr_unused; | 65 | long nr_unused; |