aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--fs/kernfs/dir.c8
-rw-r--r--fs/kernfs/file.c23
-rw-r--r--fs/kernfs/kernfs-internal.h2
-rw-r--r--fs/sysfs/file.c4
-rw-r--r--include/linux/kernfs.h27
5 files changed, 36 insertions, 28 deletions
diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c
index ba5f372a226d..e1681775abd5 100644
--- a/fs/kernfs/dir.c
+++ b/fs/kernfs/dir.c
@@ -240,7 +240,7 @@ void kernfs_put(struct kernfs_node *kn)
240 240
241 if (kernfs_type(kn) == KERNFS_LINK) 241 if (kernfs_type(kn) == KERNFS_LINK)
242 kernfs_put(kn->symlink.target_kn); 242 kernfs_put(kn->symlink.target_kn);
243 if (kernfs_type(kn) & KERNFS_COPY_NAME) 243 if (!(kn->flags & KERNFS_STATIC_NAME))
244 kfree(kn->name); 244 kfree(kn->name);
245 if (kn->iattr) { 245 if (kn->iattr) {
246 if (kn->iattr->ia_secdata) 246 if (kn->iattr->ia_secdata)
@@ -336,13 +336,13 @@ const struct dentry_operations kernfs_dops = {
336}; 336};
337 337
338struct kernfs_node *kernfs_new_node(struct kernfs_root *root, const char *name, 338struct kernfs_node *kernfs_new_node(struct kernfs_root *root, const char *name,
339 umode_t mode, int type) 339 umode_t mode, unsigned flags)
340{ 340{
341 char *dup_name = NULL; 341 char *dup_name = NULL;
342 struct kernfs_node *kn; 342 struct kernfs_node *kn;
343 int ret; 343 int ret;
344 344
345 if (type & KERNFS_COPY_NAME) { 345 if (!(flags & KERNFS_STATIC_NAME)) {
346 name = dup_name = kstrdup(name, GFP_KERNEL); 346 name = dup_name = kstrdup(name, GFP_KERNEL);
347 if (!name) 347 if (!name)
348 return NULL; 348 return NULL;
@@ -362,7 +362,7 @@ struct kernfs_node *kernfs_new_node(struct kernfs_root *root, const char *name,
362 362
363 kn->name = name; 363 kn->name = name;
364 kn->mode = mode; 364 kn->mode = mode;
365 kn->flags = type | KERNFS_REMOVED; 365 kn->flags = flags | KERNFS_REMOVED;
366 366
367 return kn; 367 return kn;
368 368
diff --git a/fs/kernfs/file.c b/fs/kernfs/file.c
index 053cfd9a6a40..316604cc3a1c 100644
--- a/fs/kernfs/file.c
+++ b/fs/kernfs/file.c
@@ -762,7 +762,7 @@ const struct file_operations kernfs_file_fops = {
762}; 762};
763 763
764/** 764/**
765 * kernfs_create_file_ns_key - create a file 765 * __kernfs_create_file - kernfs internal function to create a file
766 * @parent: directory to create the file in 766 * @parent: directory to create the file in
767 * @name: name of the file 767 * @name: name of the file
768 * @mode: mode of the file 768 * @mode: mode of the file
@@ -770,23 +770,30 @@ const struct file_operations kernfs_file_fops = {
770 * @ops: kernfs operations for the file 770 * @ops: kernfs operations for the file
771 * @priv: private data for the file 771 * @priv: private data for the file
772 * @ns: optional namespace tag of the file 772 * @ns: optional namespace tag of the file
773 * @static_name: don't copy file name
773 * @key: lockdep key for the file's active_ref, %NULL to disable lockdep 774 * @key: lockdep key for the file's active_ref, %NULL to disable lockdep
774 * 775 *
775 * Returns the created node on success, ERR_PTR() value on error. 776 * Returns the created node on success, ERR_PTR() value on error.
776 */ 777 */
777struct kernfs_node *kernfs_create_file_ns_key(struct kernfs_node *parent, 778struct kernfs_node *__kernfs_create_file(struct kernfs_node *parent,
778 const char *name, 779 const char *name,
779 umode_t mode, loff_t size, 780 umode_t mode, loff_t size,
780 const struct kernfs_ops *ops, 781 const struct kernfs_ops *ops,
781 void *priv, const void *ns, 782 void *priv, const void *ns,
782 struct lock_class_key *key) 783 bool name_is_static,
784 struct lock_class_key *key)
783{ 785{
784 struct kernfs_addrm_cxt acxt; 786 struct kernfs_addrm_cxt acxt;
785 struct kernfs_node *kn; 787 struct kernfs_node *kn;
788 unsigned flags;
786 int rc; 789 int rc;
787 790
791 flags = KERNFS_FILE;
792 if (name_is_static)
793 flags |= KERNFS_STATIC_NAME;
794
788 kn = kernfs_new_node(kernfs_root(parent), name, 795 kn = kernfs_new_node(kernfs_root(parent), name,
789 (mode & S_IALLUGO) | S_IFREG, KERNFS_FILE); 796 (mode & S_IALLUGO) | S_IFREG, flags);
790 if (!kn) 797 if (!kn)
791 return ERR_PTR(-ENOMEM); 798 return ERR_PTR(-ENOMEM);
792 799
diff --git a/fs/kernfs/kernfs-internal.h b/fs/kernfs/kernfs-internal.h
index a4ff491fd59c..c6ba5bc37a98 100644
--- a/fs/kernfs/kernfs-internal.h
+++ b/fs/kernfs/kernfs-internal.h
@@ -105,7 +105,7 @@ int kernfs_add_one(struct kernfs_addrm_cxt *acxt, struct kernfs_node *kn,
105 struct kernfs_node *parent); 105 struct kernfs_node *parent);
106void kernfs_addrm_finish(struct kernfs_addrm_cxt *acxt); 106void kernfs_addrm_finish(struct kernfs_addrm_cxt *acxt);
107struct kernfs_node *kernfs_new_node(struct kernfs_root *root, const char *name, 107struct kernfs_node *kernfs_new_node(struct kernfs_root *root, const char *name,
108 umode_t mode, int type); 108 umode_t mode, unsigned flags);
109 109
110/* 110/*
111 * file.c 111 * file.c
diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
index fe6388fbd154..810cf6e613e5 100644
--- a/fs/sysfs/file.c
+++ b/fs/sysfs/file.c
@@ -252,8 +252,8 @@ int sysfs_add_file_mode_ns(struct kernfs_node *parent,
252 if (!attr->ignore_lockdep) 252 if (!attr->ignore_lockdep)
253 key = attr->key ?: (struct lock_class_key *)&attr->skey; 253 key = attr->key ?: (struct lock_class_key *)&attr->skey;
254#endif 254#endif
255 kn = kernfs_create_file_ns_key(parent, attr->name, mode, size, 255 kn = __kernfs_create_file(parent, attr->name, mode, size, ops,
256 ops, (void *)attr, ns, key); 256 (void *)attr, ns, true, key);
257 if (IS_ERR(kn)) { 257 if (IS_ERR(kn)) {
258 if (PTR_ERR(kn) == -EEXIST) 258 if (PTR_ERR(kn) == -EEXIST)
259 sysfs_warn_dup(parent, attr->name); 259 sysfs_warn_dup(parent, attr->name);
diff --git a/include/linux/kernfs.h b/include/linux/kernfs.h
index 0ca2aedfd31b..321ed84ad4ce 100644
--- a/include/linux/kernfs.h
+++ b/include/linux/kernfs.h
@@ -34,7 +34,6 @@ enum kernfs_node_type {
34}; 34};
35 35
36#define KERNFS_TYPE_MASK 0x000f 36#define KERNFS_TYPE_MASK 0x000f
37#define KERNFS_COPY_NAME (KERNFS_DIR | KERNFS_LINK)
38#define KERNFS_ACTIVE_REF KERNFS_FILE 37#define KERNFS_ACTIVE_REF KERNFS_FILE
39#define KERNFS_FLAG_MASK ~KERNFS_TYPE_MASK 38#define KERNFS_FLAG_MASK ~KERNFS_TYPE_MASK
40 39
@@ -44,6 +43,7 @@ enum kernfs_node_flag {
44 KERNFS_HAS_SEQ_SHOW = 0x0040, 43 KERNFS_HAS_SEQ_SHOW = 0x0040,
45 KERNFS_HAS_MMAP = 0x0080, 44 KERNFS_HAS_MMAP = 0x0080,
46 KERNFS_LOCKDEP = 0x0100, 45 KERNFS_LOCKDEP = 0x0100,
46 KERNFS_STATIC_NAME = 0x0200,
47}; 47};
48 48
49/* type-specific structures for kernfs_node union members */ 49/* type-specific structures for kernfs_node union members */
@@ -212,12 +212,13 @@ void kernfs_destroy_root(struct kernfs_root *root);
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, umode_t mode, 213 const char *name, umode_t mode,
214 void *priv, 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(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,
218 const struct kernfs_ops *ops, 218 const struct kernfs_ops *ops,
219 void *priv, const void *ns, 219 void *priv, const void *ns,
220 struct lock_class_key *key); 220 bool name_is_static,
221 struct lock_class_key *key);
221struct kernfs_node *kernfs_create_link(struct kernfs_node *parent, 222struct kernfs_node *kernfs_create_link(struct kernfs_node *parent,
222 const char *name, 223 const char *name,
223 struct kernfs_node *target); 224 struct kernfs_node *target);
@@ -265,10 +266,10 @@ kernfs_create_dir_ns(struct kernfs_node *parent, const char *name,
265{ return ERR_PTR(-ENOSYS); } 266{ return ERR_PTR(-ENOSYS); }
266 267
267static inline struct kernfs_node * 268static inline struct kernfs_node *
268kernfs_create_file_ns_key(struct kernfs_node *parent, const char *name, 269__kernfs_create_file(struct kernfs_node *parent, const char *name,
269 umode_t mode, loff_t size, 270 umode_t mode, loff_t size, const struct kernfs_ops *ops,
270 const struct kernfs_ops *ops, void *priv, 271 void *priv, const void *ns, bool name_is_static,
271 const void *ns, struct lock_class_key *key) 272 struct lock_class_key *key)
272{ return ERR_PTR(-ENOSYS); } 273{ return ERR_PTR(-ENOSYS); }
273 274
274static inline struct kernfs_node * 275static inline struct kernfs_node *
@@ -330,8 +331,8 @@ kernfs_create_file_ns(struct kernfs_node *parent, const char *name,
330#ifdef CONFIG_DEBUG_LOCK_ALLOC 331#ifdef CONFIG_DEBUG_LOCK_ALLOC
331 key = (struct lock_class_key *)&ops->lockdep_key; 332 key = (struct lock_class_key *)&ops->lockdep_key;
332#endif 333#endif
333 return kernfs_create_file_ns_key(parent, name, mode, size, ops, priv, 334 return __kernfs_create_file(parent, name, mode, size, ops, priv, ns,
334 ns, key); 335 false, key);
335} 336}
336 337
337static inline struct kernfs_node * 338static inline struct kernfs_node *