提交 b8b1483d 编写于 作者: C Christoph Hellwig

sg: simplify procfs code

Use remove_proc_subtree to remove the whole subtree on cleanup, and
unwind the registration loop into individual calls.  Switch to use
proc_create_seq where applicable.

Also don't bother handling proc_create* failures - the driver works
perfectly fine without the proc files, and the cleanup will handle
missing files gracefully.
Signed-off-by: NChristoph Hellwig <hch@lst.de>
上级 f7680bec
...@@ -66,7 +66,6 @@ static int sg_version_num = 30536; /* 2 digits for each component */ ...@@ -66,7 +66,6 @@ static int sg_version_num = 30536; /* 2 digits for each component */
static char *sg_version_date = "20140603"; static char *sg_version_date = "20140603";
static int sg_proc_init(void); static int sg_proc_init(void);
static void sg_proc_cleanup(void);
#endif #endif
#define SG_ALLOW_DIO_DEF 0 #define SG_ALLOW_DIO_DEF 0
...@@ -1661,7 +1660,7 @@ static void __exit ...@@ -1661,7 +1660,7 @@ static void __exit
exit_sg(void) exit_sg(void)
{ {
#ifdef CONFIG_SCSI_PROC_FS #ifdef CONFIG_SCSI_PROC_FS
sg_proc_cleanup(); remove_proc_subtree("scsi/sg", NULL);
#endif /* CONFIG_SCSI_PROC_FS */ #endif /* CONFIG_SCSI_PROC_FS */
scsi_unregister_interface(&sg_interface); scsi_unregister_interface(&sg_interface);
class_destroy(sg_sysfs_class); class_destroy(sg_sysfs_class);
...@@ -2274,11 +2273,6 @@ sg_get_dev(int dev) ...@@ -2274,11 +2273,6 @@ sg_get_dev(int dev)
} }
#ifdef CONFIG_SCSI_PROC_FS #ifdef CONFIG_SCSI_PROC_FS
static struct proc_dir_entry *sg_proc_sgp = NULL;
static char sg_proc_sg_dirname[] = "scsi/sg";
static int sg_proc_seq_show_int(struct seq_file *s, void *v); static int sg_proc_seq_show_int(struct seq_file *s, void *v);
static int sg_proc_single_open_adio(struct inode *inode, struct file *file); static int sg_proc_single_open_adio(struct inode *inode, struct file *file);
...@@ -2306,37 +2300,11 @@ static const struct file_operations dressz_fops = { ...@@ -2306,37 +2300,11 @@ static const struct file_operations dressz_fops = {
}; };
static int sg_proc_seq_show_version(struct seq_file *s, void *v); static int sg_proc_seq_show_version(struct seq_file *s, void *v);
static int sg_proc_single_open_version(struct inode *inode, struct file *file);
static const struct file_operations version_fops = {
.owner = THIS_MODULE,
.open = sg_proc_single_open_version,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release,
};
static int sg_proc_seq_show_devhdr(struct seq_file *s, void *v); static int sg_proc_seq_show_devhdr(struct seq_file *s, void *v);
static int sg_proc_single_open_devhdr(struct inode *inode, struct file *file);
static const struct file_operations devhdr_fops = {
.owner = THIS_MODULE,
.open = sg_proc_single_open_devhdr,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release,
};
static int sg_proc_seq_show_dev(struct seq_file *s, void *v); static int sg_proc_seq_show_dev(struct seq_file *s, void *v);
static int sg_proc_open_dev(struct inode *inode, struct file *file);
static void * dev_seq_start(struct seq_file *s, loff_t *pos); static void * dev_seq_start(struct seq_file *s, loff_t *pos);
static void * dev_seq_next(struct seq_file *s, void *v, loff_t *pos); static void * dev_seq_next(struct seq_file *s, void *v, loff_t *pos);
static void dev_seq_stop(struct seq_file *s, void *v); static void dev_seq_stop(struct seq_file *s, void *v);
static const struct file_operations dev_fops = {
.owner = THIS_MODULE,
.open = sg_proc_open_dev,
.read = seq_read,
.llseek = seq_lseek,
.release = seq_release,
};
static const struct seq_operations dev_seq_ops = { static const struct seq_operations dev_seq_ops = {
.start = dev_seq_start, .start = dev_seq_start,
.next = dev_seq_next, .next = dev_seq_next,
...@@ -2345,14 +2313,6 @@ static const struct seq_operations dev_seq_ops = { ...@@ -2345,14 +2313,6 @@ static const struct seq_operations dev_seq_ops = {
}; };
static int sg_proc_seq_show_devstrs(struct seq_file *s, void *v); static int sg_proc_seq_show_devstrs(struct seq_file *s, void *v);
static int sg_proc_open_devstrs(struct inode *inode, struct file *file);
static const struct file_operations devstrs_fops = {
.owner = THIS_MODULE,
.open = sg_proc_open_devstrs,
.read = seq_read,
.llseek = seq_lseek,
.release = seq_release,
};
static const struct seq_operations devstrs_seq_ops = { static const struct seq_operations devstrs_seq_ops = {
.start = dev_seq_start, .start = dev_seq_start,
.next = dev_seq_next, .next = dev_seq_next,
...@@ -2361,14 +2321,6 @@ static const struct seq_operations devstrs_seq_ops = { ...@@ -2361,14 +2321,6 @@ static const struct seq_operations devstrs_seq_ops = {
}; };
static int sg_proc_seq_show_debug(struct seq_file *s, void *v); static int sg_proc_seq_show_debug(struct seq_file *s, void *v);
static int sg_proc_open_debug(struct inode *inode, struct file *file);
static const struct file_operations debug_fops = {
.owner = THIS_MODULE,
.open = sg_proc_open_debug,
.read = seq_read,
.llseek = seq_lseek,
.release = seq_release,
};
static const struct seq_operations debug_seq_ops = { static const struct seq_operations debug_seq_ops = {
.start = dev_seq_start, .start = dev_seq_start,
.next = dev_seq_next, .next = dev_seq_next,
...@@ -2376,50 +2328,23 @@ static const struct seq_operations debug_seq_ops = { ...@@ -2376,50 +2328,23 @@ static const struct seq_operations debug_seq_ops = {
.show = sg_proc_seq_show_debug, .show = sg_proc_seq_show_debug,
}; };
struct sg_proc_leaf {
const char * name;
const struct file_operations * fops;
};
static const struct sg_proc_leaf sg_proc_leaf_arr[] = {
{"allow_dio", &adio_fops},
{"debug", &debug_fops},
{"def_reserved_size", &dressz_fops},
{"device_hdr", &devhdr_fops},
{"devices", &dev_fops},
{"device_strs", &devstrs_fops},
{"version", &version_fops}
};
static int static int
sg_proc_init(void) sg_proc_init(void)
{ {
int num_leaves = ARRAY_SIZE(sg_proc_leaf_arr); struct proc_dir_entry *p;
int k;
sg_proc_sgp = proc_mkdir(sg_proc_sg_dirname, NULL); p = proc_mkdir("scsi/sg", NULL);
if (!sg_proc_sgp) if (!p)
return 1; return 1;
for (k = 0; k < num_leaves; ++k) {
const struct sg_proc_leaf *leaf = &sg_proc_leaf_arr[k];
umode_t mask = leaf->fops->write ? S_IRUGO | S_IWUSR : S_IRUGO;
proc_create(leaf->name, mask, sg_proc_sgp, leaf->fops);
}
return 0;
}
static void proc_create("allow_dio", S_IRUGO | S_IWUSR, p, &adio_fops);
sg_proc_cleanup(void) proc_create_seq("debug", S_IRUGO, p, &debug_seq_ops);
{ proc_create("def_reserved_size", S_IRUGO | S_IWUSR, p, &dressz_fops);
int k; proc_create_single("device_hdr", S_IRUGO, p, sg_proc_seq_show_devhdr);
int num_leaves = ARRAY_SIZE(sg_proc_leaf_arr); proc_create_seq("devices", S_IRUGO, p, &dev_seq_ops);
proc_create_seq("device_strs", S_IRUGO, p, &devstrs_seq_ops);
if (!sg_proc_sgp) proc_create_single("version", S_IRUGO, p, sg_proc_seq_show_version);
return; return 0;
for (k = 0; k < num_leaves; ++k)
remove_proc_entry(sg_proc_leaf_arr[k].name, sg_proc_sgp);
remove_proc_entry(sg_proc_sg_dirname, NULL);
} }
...@@ -2482,22 +2407,12 @@ static int sg_proc_seq_show_version(struct seq_file *s, void *v) ...@@ -2482,22 +2407,12 @@ static int sg_proc_seq_show_version(struct seq_file *s, void *v)
return 0; return 0;
} }
static int sg_proc_single_open_version(struct inode *inode, struct file *file)
{
return single_open(file, sg_proc_seq_show_version, NULL);
}
static int sg_proc_seq_show_devhdr(struct seq_file *s, void *v) static int sg_proc_seq_show_devhdr(struct seq_file *s, void *v)
{ {
seq_puts(s, "host\tchan\tid\tlun\ttype\topens\tqdepth\tbusy\tonline\n"); seq_puts(s, "host\tchan\tid\tlun\ttype\topens\tqdepth\tbusy\tonline\n");
return 0; return 0;
} }
static int sg_proc_single_open_devhdr(struct inode *inode, struct file *file)
{
return single_open(file, sg_proc_seq_show_devhdr, NULL);
}
struct sg_proc_deviter { struct sg_proc_deviter {
loff_t index; loff_t index;
size_t max; size_t max;
...@@ -2531,11 +2446,6 @@ static void dev_seq_stop(struct seq_file *s, void *v) ...@@ -2531,11 +2446,6 @@ static void dev_seq_stop(struct seq_file *s, void *v)
kfree(s->private); kfree(s->private);
} }
static int sg_proc_open_dev(struct inode *inode, struct file *file)
{
return seq_open(file, &dev_seq_ops);
}
static int sg_proc_seq_show_dev(struct seq_file *s, void *v) static int sg_proc_seq_show_dev(struct seq_file *s, void *v)
{ {
struct sg_proc_deviter * it = (struct sg_proc_deviter *) v; struct sg_proc_deviter * it = (struct sg_proc_deviter *) v;
...@@ -2562,11 +2472,6 @@ static int sg_proc_seq_show_dev(struct seq_file *s, void *v) ...@@ -2562,11 +2472,6 @@ static int sg_proc_seq_show_dev(struct seq_file *s, void *v)
return 0; return 0;
} }
static int sg_proc_open_devstrs(struct inode *inode, struct file *file)
{
return seq_open(file, &devstrs_seq_ops);
}
static int sg_proc_seq_show_devstrs(struct seq_file *s, void *v) static int sg_proc_seq_show_devstrs(struct seq_file *s, void *v)
{ {
struct sg_proc_deviter * it = (struct sg_proc_deviter *) v; struct sg_proc_deviter * it = (struct sg_proc_deviter *) v;
...@@ -2650,11 +2555,6 @@ static void sg_proc_debug_helper(struct seq_file *s, Sg_device * sdp) ...@@ -2650,11 +2555,6 @@ static void sg_proc_debug_helper(struct seq_file *s, Sg_device * sdp)
} }
} }
static int sg_proc_open_debug(struct inode *inode, struct file *file)
{
return seq_open(file, &debug_seq_ops);
}
static int sg_proc_seq_show_debug(struct seq_file *s, void *v) static int sg_proc_seq_show_debug(struct seq_file *s, void *v)
{ {
struct sg_proc_deviter * it = (struct sg_proc_deviter *) v; struct sg_proc_deviter * it = (struct sg_proc_deviter *) v;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册