Commit a1c2aa1e authored by Al Viro's avatar Al Viro

selinuxfs: merge dentry allocation into sel_make_dir()

Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
parent e152c38a
...@@ -344,7 +344,7 @@ static int sel_make_classes(void); ...@@ -344,7 +344,7 @@ static int sel_make_classes(void);
static int sel_make_policycap(void); static int sel_make_policycap(void);
/* declaration for sel_make_class_dirs */ /* declaration for sel_make_class_dirs */
static int sel_make_dir(struct inode *dir, struct dentry *dentry, static struct dentry *sel_make_dir(struct dentry *dir, const char *name,
unsigned long *ino); unsigned long *ino);
static ssize_t sel_read_mls(struct file *filp, char __user *buf, static ssize_t sel_read_mls(struct file *filp, char __user *buf,
...@@ -1678,13 +1678,9 @@ static int sel_make_class_dir_entries(char *classname, int index, ...@@ -1678,13 +1678,9 @@ static int sel_make_class_dir_entries(char *classname, int index,
inode->i_ino = sel_class_to_ino(index); inode->i_ino = sel_class_to_ino(index);
d_add(dentry, inode); d_add(dentry, inode);
dentry = d_alloc_name(dir, "perms"); dentry = sel_make_dir(dir, "perms", &last_class_ino);
if (!dentry) if (IS_ERR(dentry))
return -ENOMEM; return PTR_ERR(dentry);
rc = sel_make_dir(dir->d_inode, dentry, &last_class_ino);
if (rc)
return rc;
rc = sel_make_perm_files(classname, index, dentry); rc = sel_make_perm_files(classname, index, dentry);
...@@ -1733,15 +1729,12 @@ static int sel_make_classes(void) ...@@ -1733,15 +1729,12 @@ static int sel_make_classes(void)
for (i = 0; i < nclasses; i++) { for (i = 0; i < nclasses; i++) {
struct dentry *class_name_dir; struct dentry *class_name_dir;
rc = -ENOMEM; class_name_dir = sel_make_dir(class_dir, classes[i],
class_name_dir = d_alloc_name(class_dir, classes[i]);
if (!class_name_dir)
goto out;
rc = sel_make_dir(class_dir->d_inode, class_name_dir,
&last_class_ino); &last_class_ino);
if (rc) if (IS_ERR(class_name_dir)) {
rc = PTR_ERR(class_name_dir);
goto out; goto out;
}
/* i+1 since class values are 1-indexed */ /* i+1 since class values are 1-indexed */
rc = sel_make_class_dir_entries(classes[i], i + 1, rc = sel_make_class_dir_entries(classes[i], i + 1,
...@@ -1787,14 +1780,20 @@ static int sel_make_policycap(void) ...@@ -1787,14 +1780,20 @@ static int sel_make_policycap(void)
return 0; return 0;
} }
static int sel_make_dir(struct inode *dir, struct dentry *dentry, static struct dentry *sel_make_dir(struct dentry *dir, const char *name,
unsigned long *ino) unsigned long *ino)
{ {
struct dentry *dentry = d_alloc_name(dir, name);
struct inode *inode; struct inode *inode;
inode = sel_make_inode(dir->i_sb, S_IFDIR | S_IRUGO | S_IXUGO); if (!dentry)
if (!inode) return ERR_PTR(-ENOMEM);
return -ENOMEM;
inode = sel_make_inode(dir->d_sb, S_IFDIR | S_IRUGO | S_IXUGO);
if (!inode) {
dput(dentry);
return ERR_PTR(-ENOMEM);
}
inode->i_op = &simple_dir_inode_operations; inode->i_op = &simple_dir_inode_operations;
inode->i_fop = &simple_dir_operations; inode->i_fop = &simple_dir_operations;
...@@ -1803,16 +1802,16 @@ static int sel_make_dir(struct inode *dir, struct dentry *dentry, ...@@ -1803,16 +1802,16 @@ static int sel_make_dir(struct inode *dir, struct dentry *dentry,
inc_nlink(inode); inc_nlink(inode);
d_add(dentry, inode); d_add(dentry, inode);
/* bump link count on parent directory, too */ /* bump link count on parent directory, too */
inc_nlink(dir); inc_nlink(dir->d_inode);
return 0; return dentry;
} }
static int sel_fill_super(struct super_block *sb, void *data, int silent) 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, *root_inode; struct inode *inode;
struct inode_security_struct *isec; struct inode_security_struct *isec;
static struct tree_descr selinux_files[] = { static struct tree_descr selinux_files[] = {
...@@ -1839,18 +1838,12 @@ static int sel_fill_super(struct super_block *sb, void *data, int silent) ...@@ -1839,18 +1838,12 @@ static int sel_fill_super(struct super_block *sb, void *data, int silent)
if (ret) if (ret)
goto err; goto err;
root_inode = sb->s_root->d_inode; bool_dir = sel_make_dir(sb->s_root, BOOL_DIR_NAME, &sel_last_ino);
if (IS_ERR(bool_dir)) {
ret = -ENOMEM; ret = PTR_ERR(bool_dir);
dentry = d_alloc_name(sb->s_root, BOOL_DIR_NAME); bool_dir = NULL;
if (!dentry)
goto err; goto err;
}
ret = sel_make_dir(root_inode, dentry, &sel_last_ino);
if (ret)
goto err;
bool_dir = dentry;
ret = -ENOMEM; ret = -ENOMEM;
dentry = d_alloc_name(sb->s_root, NULL_FILE_NAME); dentry = d_alloc_name(sb->s_root, NULL_FILE_NAME);
...@@ -1872,54 +1865,39 @@ static int sel_fill_super(struct super_block *sb, void *data, int silent) ...@@ -1872,54 +1865,39 @@ static int sel_fill_super(struct super_block *sb, void *data, int silent)
d_add(dentry, inode); d_add(dentry, inode);
selinux_null = dentry; selinux_null = dentry;
ret = -ENOMEM; dentry = sel_make_dir(sb->s_root, "avc", &sel_last_ino);
dentry = d_alloc_name(sb->s_root, "avc"); if (IS_ERR(dentry)) {
if (!dentry) ret = PTR_ERR(dentry);
goto err;
ret = sel_make_dir(root_inode, dentry, &sel_last_ino);
if (ret)
goto err; goto err;
}
ret = sel_make_avc_files(dentry); ret = sel_make_avc_files(dentry);
if (ret) if (ret)
goto err; goto err;
ret = -ENOMEM; dentry = sel_make_dir(sb->s_root, "initial_contexts", &sel_last_ino);
dentry = d_alloc_name(sb->s_root, "initial_contexts"); if (IS_ERR(dentry)) {
if (!dentry) ret = PTR_ERR(dentry);
goto err;
ret = sel_make_dir(root_inode, dentry, &sel_last_ino);
if (ret)
goto err; goto err;
}
ret = sel_make_initcon_files(dentry); ret = sel_make_initcon_files(dentry);
if (ret) if (ret)
goto err; goto err;
ret = -ENOMEM; class_dir = sel_make_dir(sb->s_root, "class", &sel_last_ino);
dentry = d_alloc_name(sb->s_root, "class"); if (IS_ERR(class_dir)) {
if (!dentry) ret = PTR_ERR(class_dir);
goto err; class_dir = NULL;
ret = sel_make_dir(root_inode, dentry, &sel_last_ino);
if (ret)
goto err;
class_dir = dentry;
ret = -ENOMEM;
dentry = d_alloc_name(sb->s_root, "policy_capabilities");
if (!dentry)
goto err; goto err;
}
ret = sel_make_dir(root_inode, dentry, &sel_last_ino); policycap_dir = sel_make_dir(sb->s_root, "policy_capabilities", &sel_last_ino);
if (ret) if (IS_ERR(policycap_dir)) {
ret = PTR_ERR(policycap_dir);
policycap_dir = NULL;
goto err; goto err;
}
policycap_dir = dentry;
return 0; return 0;
err: err:
printk(KERN_ERR "SELinux: %s: failed while creating inodes\n", printk(KERN_ERR "SELinux: %s: failed while creating inodes\n",
......
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