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,
{
struct dentry *dentry;
struct inode *inode;
struct qstr qname;
qname.name = name;
qname.len = strlen (name);
qname.hash = full_name_hash(name, qname.len);
dentry = d_alloc(parent, &qname);
dentry = d_alloc_name(parent, name);
if (!dentry)
return NULL;
......@@ -202,12 +197,8 @@ static struct dentry *ibmasmfs_create_dir (struct super_block *sb,
{
struct dentry *dentry;
struct inode *inode;
struct qstr qname;
qname.name = name;
qname.len = strlen (name);
qname.hash = full_name_hash(name, qname.len);
dentry = d_alloc(parent, &qname);
dentry = d_alloc_name(parent, name);
if (!dentry)
return NULL;
......
......@@ -135,11 +135,8 @@ static struct dentry * __oprofilefs_create_file(struct super_block * sb,
{
struct dentry * dentry;
struct inode * inode;
struct qstr qname;
qname.name = name;
qname.len = strlen(name);
qname.hash = full_name_hash(qname.name, qname.len);
dentry = d_alloc(root, &qname);
dentry = d_alloc_name(root, name);
if (!dentry)
return NULL;
inode = oprofilefs_get_inode(sb, S_IFREG | perm);
......@@ -228,11 +225,8 @@ struct dentry * oprofilefs_mkdir(struct super_block * sb,
{
struct dentry * dentry;
struct inode * inode;
struct qstr qname;
qname.name = name;
qname.len = strlen(name);
qname.hash = full_name_hash(qname.name, qname.len);
dentry = d_alloc(root, &qname);
dentry = d_alloc_name(root, name);
if (!dentry)
return NULL;
inode = oprofilefs_get_inode(sb, S_IFDIR | 0755);
......
......@@ -1981,12 +1981,8 @@ gadgetfs_create_file (struct super_block *sb, char const *name,
{
struct dentry *dentry;
struct inode *inode;
struct qstr qname;
qname.name = name;
qname.len = strlen (name);
qname.hash = full_name_hash (qname.name, qname.len);
dentry = d_alloc (sb->s_root, &qname);
dentry = d_alloc_name(sb->s_root, name);
if (!dentry)
return NULL;
......
......@@ -743,6 +743,16 @@ struct dentry *d_alloc(struct dentry * parent, const struct qstr *name)
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
* @entry: dentry to complete
......
......@@ -391,13 +391,9 @@ int simple_fill_super(struct super_block *s, int magic, struct tree_descr *files
return -ENOMEM;
}
for (i = 0; !files->name || files->name[0]; i++, files++) {
struct qstr name;
if (!files->name)
continue;
name.name = files->name;
name.len = strlen(name.name);
name.hash = full_name_hash(name.name, name.len);
dentry = d_alloc(root, &name);
dentry = d_alloc_name(root, files->name);
if (!dentry)
goto out;
inode = new_inode(s);
......@@ -530,6 +526,7 @@ EXPORT_SYMBOL(simple_commit_write);
EXPORT_SYMBOL(simple_dir_inode_operations);
EXPORT_SYMBOL(simple_dir_operations);
EXPORT_SYMBOL(simple_empty);
EXPORT_SYMBOL(d_alloc_name);
EXPORT_SYMBOL(simple_fill_super);
EXPORT_SYMBOL(simple_getattr);
EXPORT_SYMBOL(simple_link);
......
......@@ -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 inode_operations simple_dir_inode_operations;
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_pin_fs(char *name, struct vfsmount **mount, int *count);
extern void simple_release_fs(struct vfsmount **mount, int *count);
......
......@@ -523,16 +523,12 @@ rpc_populate(struct dentry *parent,
{
struct inode *inode, *dir = parent->d_inode;
void *private = RPC_I(dir)->private;
struct qstr name;
struct dentry *dentry;
int mode, i;
down(&dir->i_sem);
for (i = start; i < eof; i++) {
name.name = files[i].name;
name.len = strlen(name.name);
name.hash = full_name_hash(name.name, name.len);
dentry = d_alloc(parent, &name);
dentry = d_alloc_name(parent, files[i].name);
if (!dentry)
goto out_bad;
mode = files[i].mode;
......
......@@ -818,7 +818,6 @@ static int sel_make_bools(void)
struct dentry *dir = bool_dir;
struct inode *inode = NULL;
struct inode_security_struct *isec;
struct qstr qname;
char **names = NULL, *page;
int num;
int *values = NULL;
......@@ -838,10 +837,7 @@ static int sel_make_bools(void)
goto out;
for (i = 0; i < num; i++) {
qname.name = names[i];
qname.len = strlen(qname.name);
qname.hash = full_name_hash(qname.name, qname.len);
dentry = d_alloc(dir, &qname);
dentry = d_alloc_name(dir, names[i]);
if (!dentry) {
ret = -ENOMEM;
goto err;
......@@ -896,7 +892,6 @@ static int sel_fill_super(struct super_block * sb, void * data, int silent)
int ret;
struct dentry *dentry;
struct inode *inode;
struct qstr qname;
struct inode_security_struct *isec;
static struct tree_descr selinux_files[] = {
......@@ -917,10 +912,7 @@ static int sel_fill_super(struct super_block * sb, void * data, int silent)
if (ret)
return ret;
qname.name = BOOL_DIR_NAME;
qname.len = strlen(qname.name);
qname.hash = full_name_hash(qname.name, qname.len);
dentry = d_alloc(sb->s_root, &qname);
dentry = d_alloc_name(sb->s_root, BOOL_DIR_NAME);
if (!dentry)
return -ENOMEM;
......@@ -935,10 +927,7 @@ static int sel_fill_super(struct super_block * sb, void * data, int silent)
if (ret)
goto out;
qname.name = NULL_FILE_NAME;
qname.len = strlen(qname.name);
qname.hash = full_name_hash(qname.name, qname.len);
dentry = d_alloc(sb->s_root, &qname);
dentry = d_alloc_name(sb->s_root, NULL_FILE_NAME);
if (!dentry)
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