Commit e7ddba03 authored by James Morris's avatar James Morris Committed by Linus Torvalds

[PATCH] Add d_alloc_name() to libfs

This patch consolidates several occurrences of duplicated code into a new
libfs function d_alloc_name().
Signed-off-by: default avatarJames Morris <jmorris@redhat.com>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent e9eef9fe
...@@ -173,13 +173,8 @@ static struct dentry *ibmasmfs_create_file (struct super_block *sb, ...@@ -173,13 +173,8 @@ static struct dentry *ibmasmfs_create_file (struct super_block *sb,
{ {
struct dentry *dentry; struct dentry *dentry;
struct inode *inode; struct inode *inode;
struct qstr qname;
qname.name = name; dentry = d_alloc_name(parent, name);
qname.len = strlen (name);
qname.hash = full_name_hash(name, qname.len);
dentry = d_alloc(parent, &qname);
if (!dentry) if (!dentry)
return NULL; return NULL;
...@@ -202,12 +197,8 @@ static struct dentry *ibmasmfs_create_dir (struct super_block *sb, ...@@ -202,12 +197,8 @@ static struct dentry *ibmasmfs_create_dir (struct super_block *sb,
{ {
struct dentry *dentry; struct dentry *dentry;
struct inode *inode; struct inode *inode;
struct qstr qname;
qname.name = name; dentry = d_alloc_name(parent, name);
qname.len = strlen (name);
qname.hash = full_name_hash(name, qname.len);
dentry = d_alloc(parent, &qname);
if (!dentry) if (!dentry)
return NULL; return NULL;
......
...@@ -135,11 +135,8 @@ static struct dentry * __oprofilefs_create_file(struct super_block * sb, ...@@ -135,11 +135,8 @@ static struct dentry * __oprofilefs_create_file(struct super_block * sb,
{ {
struct dentry * dentry; struct dentry * dentry;
struct inode * inode; struct inode * inode;
struct qstr qname;
qname.name = name; dentry = d_alloc_name(root, name);
qname.len = strlen(name);
qname.hash = full_name_hash(qname.name, qname.len);
dentry = d_alloc(root, &qname);
if (!dentry) if (!dentry)
return NULL; return NULL;
inode = oprofilefs_get_inode(sb, S_IFREG | perm); inode = oprofilefs_get_inode(sb, S_IFREG | perm);
...@@ -228,11 +225,8 @@ struct dentry * oprofilefs_mkdir(struct super_block * sb, ...@@ -228,11 +225,8 @@ struct dentry * oprofilefs_mkdir(struct super_block * sb,
{ {
struct dentry * dentry; struct dentry * dentry;
struct inode * inode; struct inode * inode;
struct qstr qname;
qname.name = name; dentry = d_alloc_name(root, name);
qname.len = strlen(name);
qname.hash = full_name_hash(qname.name, qname.len);
dentry = d_alloc(root, &qname);
if (!dentry) if (!dentry)
return NULL; return NULL;
inode = oprofilefs_get_inode(sb, S_IFDIR | 0755); inode = oprofilefs_get_inode(sb, S_IFDIR | 0755);
......
...@@ -1981,12 +1981,8 @@ gadgetfs_create_file (struct super_block *sb, char const *name, ...@@ -1981,12 +1981,8 @@ gadgetfs_create_file (struct super_block *sb, char const *name,
{ {
struct dentry *dentry; struct dentry *dentry;
struct inode *inode; struct inode *inode;
struct qstr qname;
qname.name = name; dentry = d_alloc_name(sb->s_root, name);
qname.len = strlen (name);
qname.hash = full_name_hash (qname.name, qname.len);
dentry = d_alloc (sb->s_root, &qname);
if (!dentry) if (!dentry)
return NULL; return NULL;
......
...@@ -743,6 +743,16 @@ struct dentry *d_alloc(struct dentry * parent, const struct qstr *name) ...@@ -743,6 +743,16 @@ struct dentry *d_alloc(struct dentry * parent, const struct qstr *name)
return dentry; return dentry;
} }
struct dentry *d_alloc_name(struct dentry *parent, const char *name)
{
struct qstr q;
q.name = name;
q.len = strlen(name);
q.hash = full_name_hash(q.name, q.len);
return d_alloc(parent, &q);
}
/** /**
* d_instantiate - fill in inode information for a dentry * d_instantiate - fill in inode information for a dentry
* @entry: dentry to complete * @entry: dentry to complete
......
...@@ -391,13 +391,9 @@ int simple_fill_super(struct super_block *s, int magic, struct tree_descr *files ...@@ -391,13 +391,9 @@ int simple_fill_super(struct super_block *s, int magic, struct tree_descr *files
return -ENOMEM; return -ENOMEM;
} }
for (i = 0; !files->name || files->name[0]; i++, files++) { for (i = 0; !files->name || files->name[0]; i++, files++) {
struct qstr name;
if (!files->name) if (!files->name)
continue; continue;
name.name = files->name; dentry = d_alloc_name(root, files->name);
name.len = strlen(name.name);
name.hash = full_name_hash(name.name, name.len);
dentry = d_alloc(root, &name);
if (!dentry) if (!dentry)
goto out; goto out;
inode = new_inode(s); inode = new_inode(s);
...@@ -530,6 +526,7 @@ EXPORT_SYMBOL(simple_commit_write); ...@@ -530,6 +526,7 @@ EXPORT_SYMBOL(simple_commit_write);
EXPORT_SYMBOL(simple_dir_inode_operations); EXPORT_SYMBOL(simple_dir_inode_operations);
EXPORT_SYMBOL(simple_dir_operations); EXPORT_SYMBOL(simple_dir_operations);
EXPORT_SYMBOL(simple_empty); EXPORT_SYMBOL(simple_empty);
EXPORT_SYMBOL(d_alloc_name);
EXPORT_SYMBOL(simple_fill_super); EXPORT_SYMBOL(simple_fill_super);
EXPORT_SYMBOL(simple_getattr); EXPORT_SYMBOL(simple_getattr);
EXPORT_SYMBOL(simple_link); EXPORT_SYMBOL(simple_link);
......
...@@ -1571,6 +1571,7 @@ extern ssize_t generic_read_dir(struct file *, char __user *, size_t, loff_t *); ...@@ -1571,6 +1571,7 @@ extern ssize_t generic_read_dir(struct file *, char __user *, size_t, loff_t *);
extern struct file_operations simple_dir_operations; extern struct file_operations simple_dir_operations;
extern struct inode_operations simple_dir_inode_operations; extern struct inode_operations simple_dir_inode_operations;
struct tree_descr { char *name; struct file_operations *ops; int mode; }; struct tree_descr { char *name; struct file_operations *ops; int mode; };
struct dentry *d_alloc_name(struct dentry *, const char *);
extern int simple_fill_super(struct super_block *, int, struct tree_descr *); extern int simple_fill_super(struct super_block *, int, struct tree_descr *);
extern int simple_pin_fs(char *name, struct vfsmount **mount, int *count); extern int simple_pin_fs(char *name, struct vfsmount **mount, int *count);
extern void simple_release_fs(struct vfsmount **mount, int *count); extern void simple_release_fs(struct vfsmount **mount, int *count);
......
...@@ -523,16 +523,12 @@ rpc_populate(struct dentry *parent, ...@@ -523,16 +523,12 @@ rpc_populate(struct dentry *parent,
{ {
struct inode *inode, *dir = parent->d_inode; struct inode *inode, *dir = parent->d_inode;
void *private = RPC_I(dir)->private; void *private = RPC_I(dir)->private;
struct qstr name;
struct dentry *dentry; struct dentry *dentry;
int mode, i; int mode, i;
down(&dir->i_sem); down(&dir->i_sem);
for (i = start; i < eof; i++) { for (i = start; i < eof; i++) {
name.name = files[i].name; dentry = d_alloc_name(parent, files[i].name);
name.len = strlen(name.name);
name.hash = full_name_hash(name.name, name.len);
dentry = d_alloc(parent, &name);
if (!dentry) if (!dentry)
goto out_bad; goto out_bad;
mode = files[i].mode; mode = files[i].mode;
......
...@@ -818,7 +818,6 @@ static int sel_make_bools(void) ...@@ -818,7 +818,6 @@ static int sel_make_bools(void)
struct dentry *dir = bool_dir; struct dentry *dir = bool_dir;
struct inode *inode = NULL; struct inode *inode = NULL;
struct inode_security_struct *isec; struct inode_security_struct *isec;
struct qstr qname;
char **names = NULL, *page; char **names = NULL, *page;
int num; int num;
int *values = NULL; int *values = NULL;
...@@ -838,10 +837,7 @@ static int sel_make_bools(void) ...@@ -838,10 +837,7 @@ static int sel_make_bools(void)
goto out; goto out;
for (i = 0; i < num; i++) { for (i = 0; i < num; i++) {
qname.name = names[i]; dentry = d_alloc_name(dir, names[i]);
qname.len = strlen(qname.name);
qname.hash = full_name_hash(qname.name, qname.len);
dentry = d_alloc(dir, &qname);
if (!dentry) { if (!dentry) {
ret = -ENOMEM; ret = -ENOMEM;
goto err; goto err;
...@@ -896,7 +892,6 @@ static int sel_fill_super(struct super_block * sb, void * data, int silent) ...@@ -896,7 +892,6 @@ static int sel_fill_super(struct super_block * sb, void * data, int silent)
int ret; int ret;
struct dentry *dentry; struct dentry *dentry;
struct inode *inode; struct inode *inode;
struct qstr qname;
struct inode_security_struct *isec; struct inode_security_struct *isec;
static struct tree_descr selinux_files[] = { static struct tree_descr selinux_files[] = {
...@@ -917,10 +912,7 @@ static int sel_fill_super(struct super_block * sb, void * data, int silent) ...@@ -917,10 +912,7 @@ static int sel_fill_super(struct super_block * sb, void * data, int silent)
if (ret) if (ret)
return ret; return ret;
qname.name = BOOL_DIR_NAME; dentry = d_alloc_name(sb->s_root, BOOL_DIR_NAME);
qname.len = strlen(qname.name);
qname.hash = full_name_hash(qname.name, qname.len);
dentry = d_alloc(sb->s_root, &qname);
if (!dentry) if (!dentry)
return -ENOMEM; return -ENOMEM;
...@@ -935,10 +927,7 @@ static int sel_fill_super(struct super_block * sb, void * data, int silent) ...@@ -935,10 +927,7 @@ static int sel_fill_super(struct super_block * sb, void * data, int silent)
if (ret) if (ret)
goto out; goto out;
qname.name = NULL_FILE_NAME; dentry = d_alloc_name(sb->s_root, NULL_FILE_NAME);
qname.len = strlen(qname.name);
qname.hash = full_name_hash(qname.name, qname.len);
dentry = d_alloc(sb->s_root, &qname);
if (!dentry) if (!dentry)
return -ENOMEM; return -ENOMEM;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment