aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/kernfs.h
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2013-11-28 14:54:29 -0500
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2013-11-29 20:48:15 -0500
commit517e64f57883bd63c5a4ab8b3d0d3ed68c55d0cf (patch)
tree573f1e42c269ab32985511788a612ed3d7a99347 /include/linux/kernfs.h
parent2b25a62901a1af654c2604f19592b13742ad1601 (diff)
sysfs, kernfs: revamp sysfs_dirent active_ref lockdep annotation
Currently, sysfs_dirent active_ref lockdep annotation uses attribute->[s]key as the lockdep key, which forces kernfs_create_file_ns() to assume that sysfs_dirent->priv is pointing to a struct attribute which may not be true for non-sysfs users. This patch restructures the lockdep annotation such that * kernfs_ops contains lockdep_key which is used by default for files created kernfs_create_file_ns(). * kernfs_create_file_ns_key() is introduced which takes an extra @key argument. The created file will use the specified key for active_ref lockdep annotation. If NULL is specified, lockdep for the file is disabled. * sysfs_add_file_mode_ns() is updated to use kernfs_create_file_ns_key() with the appropriate key from the attribute or NULL if ignore_lockdep is set. This makes the lockdep annotation properly contained in kernfs while allowing sysfs to cleanly keep its current behavior. 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>
Diffstat (limited to 'include/linux/kernfs.h')
-rw-r--r--include/linux/kernfs.h37
1 files changed, 29 insertions, 8 deletions
diff --git a/include/linux/kernfs.h b/include/linux/kernfs.h
index f20796ecc76e..105d09dcb064 100644
--- a/include/linux/kernfs.h
+++ b/include/linux/kernfs.h
@@ -11,6 +11,7 @@
11#include <linux/err.h> 11#include <linux/err.h>
12#include <linux/list.h> 12#include <linux/list.h>
13#include <linux/mutex.h> 13#include <linux/mutex.h>
14#include <linux/lockdep.h>
14 15
15struct file; 16struct file;
16struct iattr; 17struct iattr;
@@ -62,6 +63,10 @@ struct kernfs_ops {
62 loff_t off); 63 loff_t off);
63 64
64 int (*mmap)(struct sysfs_open_file *of, struct vm_area_struct *vma); 65 int (*mmap)(struct sysfs_open_file *of, struct vm_area_struct *vma);
66
67#ifdef CONFIG_DEBUG_LOCK_ALLOC
68 struct lock_class_key lockdep_key;
69#endif
65}; 70};
66 71
67#ifdef CONFIG_SYSFS 72#ifdef CONFIG_SYSFS
@@ -69,11 +74,12 @@ struct kernfs_ops {
69struct sysfs_dirent *kernfs_create_dir_ns(struct sysfs_dirent *parent, 74struct sysfs_dirent *kernfs_create_dir_ns(struct sysfs_dirent *parent,
70 const char *name, void *priv, 75 const char *name, void *priv,
71 const void *ns); 76 const void *ns);
72struct sysfs_dirent *kernfs_create_file_ns(struct sysfs_dirent *parent, 77struct sysfs_dirent *kernfs_create_file_ns_key(struct sysfs_dirent *parent,
73 const char *name, 78 const char *name,
74 umode_t mode, loff_t size, 79 umode_t mode, loff_t size,
75 const struct kernfs_ops *ops, 80 const struct kernfs_ops *ops,
76 void *priv, const void *ns); 81 void *priv, const void *ns,
82 struct lock_class_key *key);
77struct sysfs_dirent *kernfs_create_link(struct sysfs_dirent *parent, 83struct sysfs_dirent *kernfs_create_link(struct sysfs_dirent *parent,
78 const char *name, 84 const char *name,
79 struct sysfs_dirent *target); 85 struct sysfs_dirent *target);
@@ -94,9 +100,10 @@ kernfs_create_dir_ns(struct sysfs_dirent *parent, const char *name, void *priv,
94{ return ERR_PTR(-ENOSYS); } 100{ return ERR_PTR(-ENOSYS); }
95 101
96static inline struct sysfs_dirent * 102static inline struct sysfs_dirent *
97kernfs_create_file_ns(struct sysfs_dirent *parent, const char *name, 103kernfs_create_file_ns_key(struct sysfs_dirent *parent, const char *name,
98 umode_t mode, loff_t size, const struct kernfs_ops *ops, 104 umode_t mode, loff_t size,
99 void *priv, const void *ns) 105 const struct kernfs_ops *ops, void *priv,
106 const void *ns, struct lock_class_key *key)
100{ return ERR_PTR(-ENOSYS); } 107{ return ERR_PTR(-ENOSYS); }
101 108
102static inline struct sysfs_dirent * 109static inline struct sysfs_dirent *
@@ -132,6 +139,20 @@ kernfs_create_dir(struct sysfs_dirent *parent, const char *name, void *priv)
132} 139}
133 140
134static inline struct sysfs_dirent * 141static inline struct sysfs_dirent *
142kernfs_create_file_ns(struct sysfs_dirent *parent, const char *name,
143 umode_t mode, loff_t size, const struct kernfs_ops *ops,
144 void *priv, const void *ns)
145{
146 struct lock_class_key *key = NULL;
147
148#ifdef CONFIG_DEBUG_LOCK_ALLOC
149 key = (struct lock_class_key *)&ops->lockdep_key;
150#endif
151 return kernfs_create_file_ns_key(parent, name, mode, size, ops, priv,
152 ns, key);
153}
154
155static inline struct sysfs_dirent *
135kernfs_create_file(struct sysfs_dirent *parent, const char *name, umode_t mode, 156kernfs_create_file(struct sysfs_dirent *parent, const char *name, umode_t mode,
136 loff_t size, const struct kernfs_ops *ops, void *priv) 157 loff_t size, const struct kernfs_ops *ops, void *priv)
137{ 158{