提交 270b5ac2 编写于 作者: D David Howells 提交者: Al Viro

proc: Add proc_mkdir_data()

Add proc_mkdir_data() to allow procfs directories to be created that are
annotated at the time of creation with private data rather than doing this
post-creation.  This means no access is then required to the proc_dir_entry
struct to set this.
Signed-off-by: NDavid Howells <dhowells@redhat.com>
Acked-by: NMauro Carvalho Chehab <mchehab@redhat.com>
Acked-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
cc: Neela Syam Kolli <megaraidlinux@lsi.com>
cc: Jerry Chuang <jerry-chuang@realtek.com>
cc: linux-scsi@vger.kernel.org
cc: devel@driverdev.osuosl.org
cc: linux-wireless@vger.kernel.org
Signed-off-by: NAl Viro <viro@zeniv.linux.org.uk>
上级 34db8aaf
...@@ -1913,14 +1913,12 @@ static void i2o_proc_device_add(struct proc_dir_entry *dir, ...@@ -1913,14 +1913,12 @@ static void i2o_proc_device_add(struct proc_dir_entry *dir,
osm_debug("adding device /proc/i2o/%s/%s\n", dev->iop->name, buff); osm_debug("adding device /proc/i2o/%s/%s\n", dev->iop->name, buff);
devdir = proc_mkdir(buff, dir); devdir = proc_mkdir_data(buff, 0, dir, dev);
if (!devdir) { if (!devdir) {
osm_warn("Could not allocate procdir!\n"); osm_warn("Could not allocate procdir!\n");
return; return;
} }
devdir->data = dev;
i2o_proc_create_entries(devdir, generic_dev_entries, dev); i2o_proc_create_entries(devdir, generic_dev_entries, dev);
/* Inform core that we want updates about this device's status */ /* Inform core that we want updates about this device's status */
...@@ -1954,12 +1952,10 @@ static int i2o_proc_iop_add(struct proc_dir_entry *dir, ...@@ -1954,12 +1952,10 @@ static int i2o_proc_iop_add(struct proc_dir_entry *dir,
osm_debug("adding IOP /proc/i2o/%s\n", c->name); osm_debug("adding IOP /proc/i2o/%s\n", c->name);
iopdir = proc_mkdir(c->name, dir); iopdir = proc_mkdir_data(c->name, 0, dir, c);
if (!iopdir) if (!iopdir)
return -1; return -1;
iopdir->data = c;
i2o_proc_create_entries(iopdir, i2o_proc_generic_iop_entries, c); i2o_proc_create_entries(iopdir, i2o_proc_generic_iop_entries, c);
list_for_each_entry(dev, &c->devices, list) list_for_each_entry(dev, &c->devices, list)
......
...@@ -2818,12 +2818,12 @@ mega_create_proc_entry(int index, struct proc_dir_entry *parent) ...@@ -2818,12 +2818,12 @@ mega_create_proc_entry(int index, struct proc_dir_entry *parent)
sprintf(string, "hba%d", adapter->host->host_no); sprintf(string, "hba%d", adapter->host->host_no);
dir = adapter->controller_proc_dir_entry = proc_mkdir(string, parent); dir = adapter->controller_proc_dir_entry =
proc_mkdir_data(string, 0, parent, adapter);
if(!dir) { if(!dir) {
printk(KERN_WARNING "\nmegaraid: proc_mkdir failed\n"); printk(KERN_WARNING "\nmegaraid: proc_mkdir failed\n");
return; return;
} }
dir->data = adapter;
for (f = mega_proc_files; f->name; f++) { for (f = mega_proc_files; f->name; f++) {
de = proc_create_data(f->name, S_IRUSR, dir, &mega_proc_fops, de = proc_create_data(f->name, S_IRUSR, dir, &mega_proc_fops,
......
...@@ -672,13 +672,12 @@ void rtl8192_proc_init_one(struct net_device *dev) ...@@ -672,13 +672,12 @@ void rtl8192_proc_init_one(struct net_device *dev)
struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev); struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
if (rtl8192_proc) { if (rtl8192_proc) {
priv->dir_dev = proc_mkdir(dev->name, rtl8192_proc); priv->dir_dev = proc_mkdir_data(dev->name, 0, rtl8192_proc, dev);
if (!priv->dir_dev) { if (!priv->dir_dev) {
RT_TRACE(COMP_ERR, "Unable to initialize /proc/net/rtl8192/%s\n", RT_TRACE(COMP_ERR, "Unable to initialize /proc/net/rtl8192/%s\n",
dev->name); dev->name);
return; return;
} }
priv->dir_dev->data = dev;
for (f = rtl8192_proc_files; f->name[0]; f++) { for (f = rtl8192_proc_files; f->name[0]; f++) {
if (!proc_create_data(f->name, S_IFREG | S_IRUGO, if (!proc_create_data(f->name, S_IFREG | S_IRUGO,
......
...@@ -428,13 +428,17 @@ struct proc_dir_entry *proc_symlink(const char *name, ...@@ -428,13 +428,17 @@ struct proc_dir_entry *proc_symlink(const char *name,
} }
EXPORT_SYMBOL(proc_symlink); EXPORT_SYMBOL(proc_symlink);
struct proc_dir_entry *proc_mkdir_mode(const char *name, umode_t mode, struct proc_dir_entry *proc_mkdir_data(const char *name, umode_t mode,
struct proc_dir_entry *parent) struct proc_dir_entry *parent, void *data)
{ {
struct proc_dir_entry *ent; struct proc_dir_entry *ent;
if (mode == 0)
mode = S_IRUGO | S_IXUGO;
ent = __proc_create(&parent, name, S_IFDIR | mode, 2); ent = __proc_create(&parent, name, S_IFDIR | mode, 2);
if (ent) { if (ent) {
ent->data = data;
if (proc_register(parent, ent) < 0) { if (proc_register(parent, ent) < 0) {
kfree(ent); kfree(ent);
ent = NULL; ent = NULL;
...@@ -442,29 +446,19 @@ struct proc_dir_entry *proc_mkdir_mode(const char *name, umode_t mode, ...@@ -442,29 +446,19 @@ struct proc_dir_entry *proc_mkdir_mode(const char *name, umode_t mode,
} }
return ent; return ent;
} }
EXPORT_SYMBOL(proc_mkdir_mode); EXPORT_SYMBOL_GPL(proc_mkdir_data);
struct proc_dir_entry *proc_net_mkdir(struct net *net, const char *name, struct proc_dir_entry *proc_mkdir_mode(const char *name, umode_t mode,
struct proc_dir_entry *parent) struct proc_dir_entry *parent)
{ {
struct proc_dir_entry *ent; return proc_mkdir_data(name, mode, parent, NULL);
ent = __proc_create(&parent, name, S_IFDIR | S_IRUGO | S_IXUGO, 2);
if (ent) {
ent->data = net;
if (proc_register(parent, ent) < 0) {
kfree(ent);
ent = NULL;
}
}
return ent;
} }
EXPORT_SYMBOL_GPL(proc_net_mkdir); EXPORT_SYMBOL(proc_mkdir_mode);
struct proc_dir_entry *proc_mkdir(const char *name, struct proc_dir_entry *proc_mkdir(const char *name,
struct proc_dir_entry *parent) struct proc_dir_entry *parent)
{ {
return proc_mkdir_mode(name, S_IRUGO | S_IXUGO, parent); return proc_mkdir_data(name, 0, parent, NULL);
} }
EXPORT_SYMBOL(proc_mkdir); EXPORT_SYMBOL(proc_mkdir);
......
...@@ -479,9 +479,8 @@ int reiserfs_proc_info_init(struct super_block *sb) ...@@ -479,9 +479,8 @@ int reiserfs_proc_info_init(struct super_block *sb)
*s = '!'; *s = '!';
spin_lock_init(&__PINFO(sb).lock); spin_lock_init(&__PINFO(sb).lock);
REISERFS_SB(sb)->procdir = proc_mkdir(b, proc_info_root); REISERFS_SB(sb)->procdir = proc_mkdir_data(b, 0, proc_info_root, sb);
if (REISERFS_SB(sb)->procdir) { if (REISERFS_SB(sb)->procdir) {
REISERFS_SB(sb)->procdir->data = sb;
add_file(sb, "version", show_version); add_file(sb, "version", show_version);
add_file(sb, "super", show_super); add_file(sb, "super", show_super);
add_file(sb, "per-level", show_per_level); add_file(sb, "per-level", show_per_level);
......
...@@ -73,6 +73,8 @@ extern int remove_proc_subtree(const char *name, struct proc_dir_entry *parent); ...@@ -73,6 +73,8 @@ extern int remove_proc_subtree(const char *name, struct proc_dir_entry *parent);
extern struct proc_dir_entry *proc_symlink(const char *, extern struct proc_dir_entry *proc_symlink(const char *,
struct proc_dir_entry *, const char *); struct proc_dir_entry *, const char *);
extern struct proc_dir_entry *proc_mkdir(const char *,struct proc_dir_entry *); extern struct proc_dir_entry *proc_mkdir(const char *,struct proc_dir_entry *);
extern struct proc_dir_entry *proc_mkdir_data(const char *, umode_t,
struct proc_dir_entry *, void *);
extern struct proc_dir_entry *proc_mkdir_mode(const char *name, umode_t mode, extern struct proc_dir_entry *proc_mkdir_mode(const char *name, umode_t mode,
struct proc_dir_entry *parent); struct proc_dir_entry *parent);
...@@ -82,9 +84,6 @@ static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode, ...@@ -82,9 +84,6 @@ static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
return proc_create_data(name, mode, parent, proc_fops, NULL); return proc_create_data(name, mode, parent, proc_fops, NULL);
} }
extern struct proc_dir_entry *proc_net_mkdir(struct net *net, const char *name,
struct proc_dir_entry *parent);
extern void proc_set_size(struct proc_dir_entry *, loff_t); extern void proc_set_size(struct proc_dir_entry *, loff_t);
extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t); extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
#else #else
...@@ -108,6 +107,8 @@ static inline struct proc_dir_entry *proc_symlink(const char *name, ...@@ -108,6 +107,8 @@ static inline struct proc_dir_entry *proc_symlink(const char *name,
struct proc_dir_entry *parent,const char *dest) {return NULL;} struct proc_dir_entry *parent,const char *dest) {return NULL;}
static inline struct proc_dir_entry *proc_mkdir(const char *name, static inline struct proc_dir_entry *proc_mkdir(const char *name,
struct proc_dir_entry *parent) {return NULL;} struct proc_dir_entry *parent) {return NULL;}
static inline struct proc_dir_entry *proc_mkdir_data(const char *name,
umode_t mode, struct proc_dir_entry *parent, void *data) { return NULL; }
static inline struct proc_dir_entry *proc_mkdir_mode(const char *name, static inline struct proc_dir_entry *proc_mkdir_mode(const char *name,
umode_t mode, struct proc_dir_entry *parent) { return NULL; } umode_t mode, struct proc_dir_entry *parent) { return NULL; }
static inline void proc_set_size(struct proc_dir_entry *de, loff_t size) {} static inline void proc_set_size(struct proc_dir_entry *de, loff_t size) {}
...@@ -153,4 +154,10 @@ static inline void *PDE_DATA(const struct inode *inode) ...@@ -153,4 +154,10 @@ static inline void *PDE_DATA(const struct inode *inode)
return PROC_I(inode)->pde->data; return PROC_I(inode)->pde->data;
} }
static inline struct proc_dir_entry *proc_net_mkdir(
struct net *net, const char *name, struct proc_dir_entry *parent)
{
return proc_mkdir_data(name, 0, parent, net);
}
#endif /* _LINUX_PROC_FS_H */ #endif /* _LINUX_PROC_FS_H */
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册