3w-xxxx: Add tw_sysfs_init() so udev will create /dev/twe* devices.
PATCH 1/1 3w-xxxx: Add tw_sysfs_init() so udev will create /dev/twe* devices.
Add tw_sysfs_init() to register 3w-xxxx driver with sysfs. This also causes udev to create /dev/twe* devices with the correct SELinux security context.
---
____________________________________________________________________________________
Be a better Heartthrob. Get better relationship answers from someone who knows. Yahoo! Answers - Check it out.
http://answers.yahoo.com/dir/?link=list&sid=396545433
3w-xxxx.c renamed from 3w-xxxx.c.orig +35 -3
@@ -194,6 +194,7 @@1.26.02.002 - Free irq handler in __tw_shutdown(). Turn on RCD bit for caching mode page. Serialize reset code. +1.26.02.003 - Add tw_sysfs_init() so udev will create /dev/twe* devices. */ #include <linux/module.h>
@@ -217,11 +218,13 @@#include "3w-xxxx.h" /* Globals */ -#define TW_DRIVER_VERSION "1.26.02.002" +#define TW_DRIVER_VERSION "1.26.02.003"static TW_Device_Extension *tw_device_extension_list[TW_MAX_SLOT ];static int tw_device_extension_count =0 ;static int twe_major =-1 ; +static struct class *tw_sysfs_class; +/* Module parameters */ MODULE_AUTHOR ("AMCC" );MODULE_DESCRIPTION ("3ware Storage Controller Linux Driver" );
@@ -1047,6 +1050,33 @@ static const struct file_operations tw_f .release = NULL }; +/* This function will create the twe* sysfs entries */ +static int tw_sysfs_init (void ) { +int i; +struct class_device *tw_class_member; + + twe_major =register_chrdev (0 ,"twe" , &tw_fops); +if (twe_major <0 ) { +printk (KERN_WARNING "3w-xxxx: Failed to register character device.\n" ); +return twe_major; + } +/* register twe* devices with sysfs */ + tw_sysfs_class =class_create (THIS_MODULE ,"twe" ); +if (IS_ERR (tw_sysfs_class)) { +printk (KERN_WARNING "3w-xxxx: Failed to create sysfs class.\n" ); +return PTR_ERR (tw_sysfs_class); + } + +for (i =0 ; i <TW_MAX_UNITS ; i++) { + tw_class_member =class_device_create (tw_sysfs_class,NULL ,MKDEV (twe_major,i),NULL ,"twe%d" ,i); +if (IS_ERR (tw_class_member)) { +printk (KERN_WARNING "3w-xxxx: Unable to add sysfs class member twe%d\n" , i); +return PTR_ERR (tw_class_member); + } + } +return 0 ; +}/* End tw_sysfs_init() */ +/* This function will free up device extension resources */ static void tw_free_device_extension (TW_Device_Extension *tw_dev) {
@@ -2420,8 +2450,9 @@ static int __devinit tw_probe(struct pciscsi_scan_host (host);if (twe_major ==-1 ) { -if ((twe_major =register_chrdev (0 ,"twe" , &tw_fops)) <0 ) -printk (KERN_WARNING "3w-xxxx: Failed to register character device." ); +if (tw_sysfs_init () <0 ) { +printk (KERN_WARNING "3w-xxxx: Failed to initialize sysfs for device." ); + } }return 0 ;
@@ -2449,6 +2480,7 @@ static void tw_remove(struct pci_dev *pd/* Unregister character device */ if (twe_major >=0 ) {unregister_chrdev (twe_major,"twe" ); +class_destroy (tw_sysfs_class); twe_major =-1 ; }
Quoted 5 lines · Joshua Daniel Franklin
Add
tw_sysfs_init()to register 3w-xxxx driver with sysfs. This also causes udev to create/dev/twe*devices with the correct SELinux security context.Signed-off-by Joshua Daniel Franklin <[email protected]>
Thanks for the patch.
I have one problem with this patch:
You are calling "class_device_create()" from 0 to "TW_MAX_UNITS" which is 16... shouldn't you be calling this only once per each controller instance that is discovered
via twa_probe() ?
Also, no other scsi LLDD drivers are calling "class_device_create()", so I wonder if
this is acceptable to scsi maintainers?
Right now we have our userspace tools creating the /dev/tweX devices.
-Adam
Quoted 7 lines · --- adam radford
I have one problem with this patch:
You are calling "
class_device_create()" from 0 to "TW_MAX_UNITS" which is 16...
shouldn't you be calling this only once per each controller instance that is discovered
viatwa_probe()?
Well, I was just trying to emulate what the userspace tools do, which is create all 16 devices whether or not they're physically present. I actually tried with only twe0 (I have only one card in my test system) and smartd seems to try to find twe1-15 anyway. I'm not sure what it's doing, but I assume it's talking to the driver.
Quoted 3 lines
Also, no other scsi LLDD drivers are calling "
class_device_create()", so I wonder if
this is acceptable to scsi maintainers?
I wondered the same thing. I think perhaps the only issue is with SELinux mentioned below which is rare and so it's a low priority to use sysfs. There may be other reasons I'm not aware of, though.
Quoted 1 line
Right now we have our userspace tools creating the
/dev/tweXdevices.
Yes, unfortunately that leaves the /dev/tweX devices with the wrong SELinux security context and harald@redhat suggested this approach:
https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=232218
I'd be happy to hear alternative solutions, but it sounds like they do not want to use a custom udev rule.
____________________________________________________________________________________
Get the free Yahoo! toolbar and rest assured with the added security of spyware protection.
http://new.toolbar.yahoo.com/toolbar/features/norton/index.php