diff options
author | Jeff Mahoney <jeffm@suse.de> | 2012-08-18 15:20:37 -0400 |
---|---|---|
committer | James Bottomley <JBottomley@Parallels.com> | 2012-09-14 12:59:28 -0400 |
commit | af23782beff27e720318fc44495287b9961a88e1 (patch) | |
tree | 66971f49df2d948f8d1250013a7e44e1deccd688 /drivers/scsi/st.c | |
parent | 06047689a976de5f7cd1067971191cca4b77af1c (diff) |
[SCSI] st: Use static class attributes
st currently sets up and tears down class attributes manually for
every tape drive in the system. This patch uses a statically defined
class with class attributes to let the device core do it for us.
Reviewed-by: Lee Duncan <lduncan@suse.com>
Signed-off-by: Jeff Mahoney <jeffm@suse.com>
Acked-by: Kai Mäkisara <kai.makisara@kolumbus.fi>
Signed-off-by: James Bottomley <JBottomley@Parallels.com>
Diffstat (limited to 'drivers/scsi/st.c')
-rw-r--r-- | drivers/scsi/st.c | 74 |
1 files changed, 33 insertions, 41 deletions
diff --git a/drivers/scsi/st.c b/drivers/scsi/st.c index e41998cb098e..03303ae44434 100644 --- a/drivers/scsi/st.c +++ b/drivers/scsi/st.c | |||
@@ -84,7 +84,8 @@ static int try_wdio = 1; | |||
84 | static int st_dev_max; | 84 | static int st_dev_max; |
85 | static int st_nr_dev; | 85 | static int st_nr_dev; |
86 | 86 | ||
87 | static struct class *st_sysfs_class; | 87 | static struct class st_sysfs_class; |
88 | static struct device_attribute st_dev_attrs[]; | ||
88 | 89 | ||
89 | MODULE_AUTHOR("Kai Makisara"); | 90 | MODULE_AUTHOR("Kai Makisara"); |
90 | MODULE_DESCRIPTION("SCSI tape (st) driver"); | 91 | MODULE_DESCRIPTION("SCSI tape (st) driver"); |
@@ -4195,7 +4196,7 @@ out_free_tape: | |||
4195 | if (STm->cdevs[j]) { | 4196 | if (STm->cdevs[j]) { |
4196 | if (cdev == STm->cdevs[j]) | 4197 | if (cdev == STm->cdevs[j]) |
4197 | cdev = NULL; | 4198 | cdev = NULL; |
4198 | device_destroy(st_sysfs_class, | 4199 | device_destroy(&st_sysfs_class, |
4199 | MKDEV(SCSI_TAPE_MAJOR, | 4200 | MKDEV(SCSI_TAPE_MAJOR, |
4200 | TAPE_MINOR(i, mode, j))); | 4201 | TAPE_MINOR(i, mode, j))); |
4201 | cdev_del(STm->cdevs[j]); | 4202 | cdev_del(STm->cdevs[j]); |
@@ -4236,7 +4237,7 @@ static int st_remove(struct device *dev) | |||
4236 | "tape"); | 4237 | "tape"); |
4237 | for (mode = 0; mode < ST_NBR_MODES; ++mode) { | 4238 | for (mode = 0; mode < ST_NBR_MODES; ++mode) { |
4238 | for (j=0; j < 2; j++) { | 4239 | for (j=0; j < 2; j++) { |
4239 | device_destroy(st_sysfs_class, | 4240 | device_destroy(&st_sysfs_class, |
4240 | MKDEV(SCSI_TAPE_MAJOR, | 4241 | MKDEV(SCSI_TAPE_MAJOR, |
4241 | TAPE_MINOR(i, mode, j))); | 4242 | TAPE_MINOR(i, mode, j))); |
4242 | cdev_del(tpnt->modes[mode].cdevs[j]); | 4243 | cdev_del(tpnt->modes[mode].cdevs[j]); |
@@ -4283,6 +4284,11 @@ static void scsi_tape_release(struct kref *kref) | |||
4283 | return; | 4284 | return; |
4284 | } | 4285 | } |
4285 | 4286 | ||
4287 | static struct class st_sysfs_class = { | ||
4288 | .name = "scsi_tape", | ||
4289 | .dev_attrs = st_dev_attrs, | ||
4290 | }; | ||
4291 | |||
4286 | static int __init init_st(void) | 4292 | static int __init init_st(void) |
4287 | { | 4293 | { |
4288 | int err; | 4294 | int err; |
@@ -4292,10 +4298,10 @@ static int __init init_st(void) | |||
4292 | printk(KERN_INFO "st: Version %s, fixed bufsize %d, s/g segs %d\n", | 4298 | printk(KERN_INFO "st: Version %s, fixed bufsize %d, s/g segs %d\n", |
4293 | verstr, st_fixed_buffer_size, st_max_sg_segs); | 4299 | verstr, st_fixed_buffer_size, st_max_sg_segs); |
4294 | 4300 | ||
4295 | st_sysfs_class = class_create(THIS_MODULE, "scsi_tape"); | 4301 | err = class_register(&st_sysfs_class); |
4296 | if (IS_ERR(st_sysfs_class)) { | 4302 | if (err) { |
4297 | printk(KERN_ERR "Unable create sysfs class for SCSI tapes\n"); | 4303 | pr_err("Unable register sysfs class for SCSI tapes\n"); |
4298 | return PTR_ERR(st_sysfs_class); | 4304 | return err; |
4299 | } | 4305 | } |
4300 | 4306 | ||
4301 | err = register_chrdev_region(MKDEV(SCSI_TAPE_MAJOR, 0), | 4307 | err = register_chrdev_region(MKDEV(SCSI_TAPE_MAJOR, 0), |
@@ -4322,7 +4328,7 @@ err_chrdev: | |||
4322 | unregister_chrdev_region(MKDEV(SCSI_TAPE_MAJOR, 0), | 4328 | unregister_chrdev_region(MKDEV(SCSI_TAPE_MAJOR, 0), |
4323 | ST_MAX_TAPE_ENTRIES); | 4329 | ST_MAX_TAPE_ENTRIES); |
4324 | err_class: | 4330 | err_class: |
4325 | class_destroy(st_sysfs_class); | 4331 | class_unregister(&st_sysfs_class); |
4326 | return err; | 4332 | return err; |
4327 | } | 4333 | } |
4328 | 4334 | ||
@@ -4332,7 +4338,7 @@ static void __exit exit_st(void) | |||
4332 | scsi_unregister_driver(&st_template.gendrv); | 4338 | scsi_unregister_driver(&st_template.gendrv); |
4333 | unregister_chrdev_region(MKDEV(SCSI_TAPE_MAJOR, 0), | 4339 | unregister_chrdev_region(MKDEV(SCSI_TAPE_MAJOR, 0), |
4334 | ST_MAX_TAPE_ENTRIES); | 4340 | ST_MAX_TAPE_ENTRIES); |
4335 | class_destroy(st_sysfs_class); | 4341 | class_unregister(&st_sysfs_class); |
4336 | kfree(scsi_tapes); | 4342 | kfree(scsi_tapes); |
4337 | printk(KERN_INFO "st: Unloaded.\n"); | 4343 | printk(KERN_INFO "st: Unloaded.\n"); |
4338 | } | 4344 | } |
@@ -4405,10 +4411,9 @@ static void do_remove_sysfs_files(void) | |||
4405 | driver_remove_file(sysfs, &driver_attr_try_direct_io); | 4411 | driver_remove_file(sysfs, &driver_attr_try_direct_io); |
4406 | } | 4412 | } |
4407 | 4413 | ||
4408 | |||
4409 | /* The sysfs simple class interface */ | 4414 | /* The sysfs simple class interface */ |
4410 | static ssize_t | 4415 | static ssize_t |
4411 | st_defined_show(struct device *dev, struct device_attribute *attr, char *buf) | 4416 | defined_show(struct device *dev, struct device_attribute *attr, char *buf) |
4412 | { | 4417 | { |
4413 | struct st_modedef *STm = dev_get_drvdata(dev); | 4418 | struct st_modedef *STm = dev_get_drvdata(dev); |
4414 | ssize_t l = 0; | 4419 | ssize_t l = 0; |
@@ -4417,10 +4422,9 @@ st_defined_show(struct device *dev, struct device_attribute *attr, char *buf) | |||
4417 | return l; | 4422 | return l; |
4418 | } | 4423 | } |
4419 | 4424 | ||
4420 | DEVICE_ATTR(defined, S_IRUGO, st_defined_show, NULL); | ||
4421 | |||
4422 | static ssize_t | 4425 | static ssize_t |
4423 | st_defblk_show(struct device *dev, struct device_attribute *attr, char *buf) | 4426 | default_blksize_show(struct device *dev, struct device_attribute *attr, |
4427 | char *buf) | ||
4424 | { | 4428 | { |
4425 | struct st_modedef *STm = dev_get_drvdata(dev); | 4429 | struct st_modedef *STm = dev_get_drvdata(dev); |
4426 | ssize_t l = 0; | 4430 | ssize_t l = 0; |
@@ -4429,10 +4433,10 @@ st_defblk_show(struct device *dev, struct device_attribute *attr, char *buf) | |||
4429 | return l; | 4433 | return l; |
4430 | } | 4434 | } |
4431 | 4435 | ||
4432 | DEVICE_ATTR(default_blksize, S_IRUGO, st_defblk_show, NULL); | ||
4433 | 4436 | ||
4434 | static ssize_t | 4437 | static ssize_t |
4435 | st_defdensity_show(struct device *dev, struct device_attribute *attr, char *buf) | 4438 | default_density_show(struct device *dev, struct device_attribute *attr, |
4439 | char *buf) | ||
4436 | { | 4440 | { |
4437 | struct st_modedef *STm = dev_get_drvdata(dev); | 4441 | struct st_modedef *STm = dev_get_drvdata(dev); |
4438 | ssize_t l = 0; | 4442 | ssize_t l = 0; |
@@ -4443,11 +4447,9 @@ st_defdensity_show(struct device *dev, struct device_attribute *attr, char *buf) | |||
4443 | return l; | 4447 | return l; |
4444 | } | 4448 | } |
4445 | 4449 | ||
4446 | DEVICE_ATTR(default_density, S_IRUGO, st_defdensity_show, NULL); | ||
4447 | |||
4448 | static ssize_t | 4450 | static ssize_t |
4449 | st_defcompression_show(struct device *dev, struct device_attribute *attr, | 4451 | default_compression_show(struct device *dev, struct device_attribute *attr, |
4450 | char *buf) | 4452 | char *buf) |
4451 | { | 4453 | { |
4452 | struct st_modedef *STm = dev_get_drvdata(dev); | 4454 | struct st_modedef *STm = dev_get_drvdata(dev); |
4453 | ssize_t l = 0; | 4455 | ssize_t l = 0; |
@@ -4456,10 +4458,8 @@ st_defcompression_show(struct device *dev, struct device_attribute *attr, | |||
4456 | return l; | 4458 | return l; |
4457 | } | 4459 | } |
4458 | 4460 | ||
4459 | DEVICE_ATTR(default_compression, S_IRUGO, st_defcompression_show, NULL); | ||
4460 | |||
4461 | static ssize_t | 4461 | static ssize_t |
4462 | st_options_show(struct device *dev, struct device_attribute *attr, char *buf) | 4462 | options_show(struct device *dev, struct device_attribute *attr, char *buf) |
4463 | { | 4463 | { |
4464 | struct st_modedef *STm = dev_get_drvdata(dev); | 4464 | struct st_modedef *STm = dev_get_drvdata(dev); |
4465 | struct scsi_tape *STp; | 4465 | struct scsi_tape *STp; |
@@ -4498,7 +4498,14 @@ st_options_show(struct device *dev, struct device_attribute *attr, char *buf) | |||
4498 | return l; | 4498 | return l; |
4499 | } | 4499 | } |
4500 | 4500 | ||
4501 | DEVICE_ATTR(options, S_IRUGO, st_options_show, NULL); | 4501 | static struct device_attribute st_dev_attrs[] = { |
4502 | __ATTR_RO(defined), | ||
4503 | __ATTR_RO(default_blksize), | ||
4504 | __ATTR_RO(default_density), | ||
4505 | __ATTR_RO(default_compression), | ||
4506 | __ATTR_RO(options), | ||
4507 | __ATTR_NULL, | ||
4508 | }; | ||
4502 | 4509 | ||
4503 | static int do_create_class_files(struct scsi_tape *STp, int dev_num, int mode) | 4510 | static int do_create_class_files(struct scsi_tape *STp, int dev_num, int mode) |
4504 | { | 4511 | { |
@@ -4513,7 +4520,8 @@ static int do_create_class_files(struct scsi_tape *STp, int dev_num, int mode) | |||
4513 | snprintf(name, 10, "%s%s%s", rew ? "n" : "", | 4520 | snprintf(name, 10, "%s%s%s", rew ? "n" : "", |
4514 | STp->disk->disk_name, st_formats[i]); | 4521 | STp->disk->disk_name, st_formats[i]); |
4515 | st_class_member = | 4522 | st_class_member = |
4516 | device_create(st_sysfs_class, &STp->device->sdev_gendev, | 4523 | device_create(&st_sysfs_class, |
4524 | &STp->device->sdev_gendev, | ||
4517 | MKDEV(SCSI_TAPE_MAJOR, | 4525 | MKDEV(SCSI_TAPE_MAJOR, |
4518 | TAPE_MINOR(dev_num, mode, rew)), | 4526 | TAPE_MINOR(dev_num, mode, rew)), |
4519 | &STp->modes[mode], "%s", name); | 4527 | &STp->modes[mode], "%s", name); |
@@ -4524,22 +4532,6 @@ static int do_create_class_files(struct scsi_tape *STp, int dev_num, int mode) | |||
4524 | goto out; | 4532 | goto out; |
4525 | } | 4533 | } |
4526 | 4534 | ||
4527 | error = device_create_file(st_class_member, | ||
4528 | &dev_attr_defined); | ||
4529 | if (error) goto out; | ||
4530 | error = device_create_file(st_class_member, | ||
4531 | &dev_attr_default_blksize); | ||
4532 | if (error) goto out; | ||
4533 | error = device_create_file(st_class_member, | ||
4534 | &dev_attr_default_density); | ||
4535 | if (error) goto out; | ||
4536 | error = device_create_file(st_class_member, | ||
4537 | &dev_attr_default_compression); | ||
4538 | if (error) goto out; | ||
4539 | error = device_create_file(st_class_member, | ||
4540 | &dev_attr_options); | ||
4541 | if (error) goto out; | ||
4542 | |||
4543 | if (mode == 0 && rew == 0) { | 4535 | if (mode == 0 && rew == 0) { |
4544 | error = sysfs_create_link(&STp->device->sdev_gendev.kobj, | 4536 | error = sysfs_create_link(&STp->device->sdev_gendev.kobj, |
4545 | &st_class_member->kobj, | 4537 | &st_class_member->kobj, |