aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2013-12-11 16:02:55 -0500
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2013-12-17 11:59:15 -0500
commitbb8b9d095c5c56cce99576cfef0cf9b989f7120d (patch)
tree9cc1ae8c8954de2d0dbb0b0f4c29a411d4716809
parentc637b8acbe079edb477d887041755b489036f146 (diff)
kernfs: add @mode to kernfs_create_dir[_ns]()
sysfs assumed 0755 for all newly created directories and kernfs inherited it. This assumption is unnecessarily restrictive and inconsistent with kernfs_create_file[_ns](). This patch adds @mode parameter to kernfs_create_dir[_ns]() and update uses in sysfs accordingly. Among others, this will be useful for implementations of the planned ->mkdir() method. This patch doesn't introduce any behavior differences. Signed-off-by: Tejun Heo <tj@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--fs/kernfs/dir.c9
-rw-r--r--fs/sysfs/dir.c3
-rw-r--r--fs/sysfs/group.c3
-rw-r--r--include/linux/kernfs.h13
4 files changed, 16 insertions, 12 deletions
diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c
index 6520066c49ea..e55bb02f15a4 100644
--- a/fs/kernfs/dir.c
+++ b/fs/kernfs/dir.c
@@ -639,22 +639,23 @@ void kernfs_destroy_root(struct kernfs_root *root)
639 * kernfs_create_dir_ns - create a directory 639 * kernfs_create_dir_ns - create a directory
640 * @parent: parent in which to create a new directory 640 * @parent: parent in which to create a new directory
641 * @name: name of the new directory 641 * @name: name of the new directory
642 * @mode: mode of the new directory
642 * @priv: opaque data associated with the new directory 643 * @priv: opaque data associated with the new directory
643 * @ns: optional namespace tag of the directory 644 * @ns: optional namespace tag of the directory
644 * 645 *
645 * Returns the created node on success, ERR_PTR() value on failure. 646 * Returns the created node on success, ERR_PTR() value on failure.
646 */ 647 */
647struct kernfs_node *kernfs_create_dir_ns(struct kernfs_node *parent, 648struct kernfs_node *kernfs_create_dir_ns(struct kernfs_node *parent,
648 const char *name, void *priv, 649 const char *name, umode_t mode,
649 const void *ns) 650 void *priv, const void *ns)
650{ 651{
651 umode_t mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
652 struct kernfs_addrm_cxt acxt; 652 struct kernfs_addrm_cxt acxt;
653 struct kernfs_node *kn; 653 struct kernfs_node *kn;
654 int rc; 654 int rc;
655 655
656 /* allocate */ 656 /* allocate */
657 kn = kernfs_new_node(kernfs_root(parent), name, mode, KERNFS_DIR); 657 kn = kernfs_new_node(kernfs_root(parent), name, mode | S_IFDIR,
658 KERNFS_DIR);
658 if (!kn) 659 if (!kn)
659 return ERR_PTR(-ENOMEM); 660 return ERR_PTR(-ENOMEM);
660 661
diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
index aa007401bfc9..ee0d761c3179 100644
--- a/fs/sysfs/dir.c
+++ b/fs/sysfs/dir.c
@@ -73,7 +73,8 @@ int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
73 if (!parent) 73 if (!parent)
74 return -ENOENT; 74 return -ENOENT;
75 75
76 kn = kernfs_create_dir_ns(parent, kobject_name(kobj), kobj, ns); 76 kn = kernfs_create_dir_ns(parent, kobject_name(kobj),
77 S_IRWXU | S_IRUGO | S_IXUGO, kobj, ns);
77 if (IS_ERR(kn)) { 78 if (IS_ERR(kn)) {
78 if (PTR_ERR(kn) == -EEXIST) 79 if (PTR_ERR(kn) == -EEXIST)
79 sysfs_warn_dup(parent, kobject_name(kobj)); 80 sysfs_warn_dup(parent, kobject_name(kobj));
diff --git a/fs/sysfs/group.c b/fs/sysfs/group.c
index 4d00d3996477..6b579387c67a 100644
--- a/fs/sysfs/group.c
+++ b/fs/sysfs/group.c
@@ -100,7 +100,8 @@ static int internal_create_group(struct kobject *kobj, int update,
100 return -EINVAL; 100 return -EINVAL;
101 } 101 }
102 if (grp->name) { 102 if (grp->name) {
103 kn = kernfs_create_dir(kobj->sd, grp->name, kobj); 103 kn = kernfs_create_dir(kobj->sd, grp->name,
104 S_IRWXU | S_IRUGO | S_IXUGO, kobj);
104 if (IS_ERR(kn)) { 105 if (IS_ERR(kn)) {
105 if (PTR_ERR(kn) == -EEXIST) 106 if (PTR_ERR(kn) == -EEXIST)
106 sysfs_warn_dup(kobj->sd, grp->name); 107 sysfs_warn_dup(kobj->sd, grp->name);
diff --git a/include/linux/kernfs.h b/include/linux/kernfs.h
index e9c4e3a03960..0ca2aedfd31b 100644
--- a/include/linux/kernfs.h
+++ b/include/linux/kernfs.h
@@ -210,8 +210,8 @@ struct kernfs_root *kernfs_create_root(void *priv);
210void kernfs_destroy_root(struct kernfs_root *root); 210void kernfs_destroy_root(struct kernfs_root *root);
211 211
212struct kernfs_node *kernfs_create_dir_ns(struct kernfs_node *parent, 212struct kernfs_node *kernfs_create_dir_ns(struct kernfs_node *parent,
213 const char *name, void *priv, 213 const char *name, umode_t mode,
214 const void *ns); 214 void *priv, const void *ns);
215struct kernfs_node *kernfs_create_file_ns_key(struct kernfs_node *parent, 215struct kernfs_node *kernfs_create_file_ns_key(struct kernfs_node *parent,
216 const char *name, 216 const char *name,
217 umode_t mode, loff_t size, 217 umode_t mode, loff_t size,
@@ -260,8 +260,8 @@ static inline struct kernfs_root *kernfs_create_root(void *priv)
260static inline void kernfs_destroy_root(struct kernfs_root *root) { } 260static inline void kernfs_destroy_root(struct kernfs_root *root) { }
261 261
262static inline struct kernfs_node * 262static inline struct kernfs_node *
263kernfs_create_dir_ns(struct kernfs_node *parent, const char *name, void *priv, 263kernfs_create_dir_ns(struct kernfs_node *parent, const char *name,
264 const void *ns) 264 umode_t mode, void *priv, const void *ns)
265{ return ERR_PTR(-ENOSYS); } 265{ return ERR_PTR(-ENOSYS); }
266 266
267static inline struct kernfs_node * 267static inline struct kernfs_node *
@@ -314,9 +314,10 @@ kernfs_find_and_get(struct kernfs_node *kn, const char *name)
314} 314}
315 315
316static inline struct kernfs_node * 316static inline struct kernfs_node *
317kernfs_create_dir(struct kernfs_node *parent, const char *name, void *priv) 317kernfs_create_dir(struct kernfs_node *parent, const char *name, umode_t mode,
318 void *priv)
318{ 319{
319 return kernfs_create_dir_ns(parent, name, priv, NULL); 320 return kernfs_create_dir_ns(parent, name, mode, priv, NULL);
320} 321}
321 322
322static inline struct kernfs_node * 323static inline struct kernfs_node *