From: Patrick Monnerat <[email protected]>
Create ioctl device node for megaraid_sas driver. Let this node be
managed by udev. Fix a typo.
Reported-by: [email protected]
To: Neela Syam Kolli <[email protected]>
Cc: "James E.J. Bottomley" <[email protected]>
Cc: [email protected]
Cc: [email protected]
Signed-off-by: Patrick Monnerat <[email protected]>
---
diff -uprN
linux-3.8.11-200.1pm.fc18.x86_64.orig/drivers/scsi/megaraid/megaraid_sas
_base.c
linux-3.8.11-200.1pm.fc18.x86_64.new/drivers/scsi/megaraid/megaraid_sas_
base.c
---
linux-3.8.11-200.1pm.fc18.x86_64.orig/drivers/scsi/megaraid/megaraid_sas
_base.c 2013-02-19 00:58:34.000000000 +0100
+++
linux-3.8.11-200.1pm.fc18.x86_64.new/drivers/scsi/megaraid/megaraid_sas_
base.c 2013-05-06 13:39:27.903234426 +0200
@@ -49,6 +49,7 @@
#include <linux/blkdev.h>
#include <linux/mutex.h>
#include <linux/poll.h>
+#include <linux/device.h>
#include <scsi/scsi.h>
#include <scsi/scsi_cmnd.h>
@@ -127,6 +128,8 @@ static struct pci_device_id megasas_pci_
MODULE_DEVICE_TABLE(pci, megasas_pci_table);
+static struct class *megasas_mgmt_class;
+static struct device *megasas_mgmt_device;
static int megasas_mgmt_majorno;
static struct megasas_mgmt_info megasas_mgmt_info;
static struct fasync_struct *megasas_async_queue;
@@ -5450,7 +5453,7 @@ static int __init megasas_init(void)
rval = pci_register_driver(&megasas_pci_driver);
if (rval) {
- printk(KERN_DEBUG "megasas: PCI hotplug regisration
failed \n");
+ printk(KERN_DEBUG "megasas: PCI hotplug registration
failed\n");
goto err_pcidrv;
}
@@ -5477,8 +5480,28 @@ static int __init megasas_init(void)
if (rval)
goto err_dcf_support_device_change;
- return rval;
+ /*
+ * Register as an udev-controlled device.
+ */
+ megasas_mgmt_class = class_create(THIS_MODULE, "megaraid");
+ rval = PTR_ERR(megasas_mgmt_class);
+ if (IS_ERR(megasas_mgmt_class))
+ goto err_class;
+
+ megasas_mgmt_device = device_create(megasas_mgmt_class, NULL,
+ MKDEV(megasas_mgmt_majorno,
0),
+ NULL, "megaraid_sas_ioctl");
+ rval = PTR_ERR(megasas_mgmt_device);
+ if (IS_ERR(megasas_mgmt_device))
+ goto err_create_device;
+ return 0;
+
+err_create_device:
+ class_destroy(megasas_mgmt_class);
+err_class:
+ driver_remove_file(&megasas_pci_driver.driver,
+ &driver_attr_support_device_change);
err_dcf_support_device_change:
driver_remove_file(&megasas_pci_driver.driver,
&driver_attr_dbg_lvl);
@@ -5504,6 +5527,9 @@ err_pcidrv:
*/
static void __exit megasas_exit(void)
{
+ device_destroy(megasas_mgmt_class, MKDEV(megasas_mgmt_majorno,
0));
+ class_destroy(megasas_mgmt_class);
+
driver_remove_file(&megasas_pci_driver.driver,
&driver_attr_dbg_lvl);
driver_remove_file(&megasas_pci_driver.driver,
"Patrick Monnerat" <[email protected]> writes:
> From: Patrick Monnerat <[email protected]>
>
> Create ioctl device node for megaraid_sas driver. Let this node be
> managed by udev. Fix a typo.
Or maybe just simplify it all and use a misc device instead? See how
this is done in e.g. drivers/scsi/mpt3sas/mpt3sas_ctl.c or
drivers/message/fusion/mptctl.c
Bjørn
On 05/06/2013 04:23 PM, Bjørn Mork wrote:
> "Patrick Monnerat" <[email protected]> writes:
>> Create ioctl device node for megaraid_sas driver. Let this node be
>> managed by udev. Fix a typo.
>
> Or maybe just simplify it all and use a misc device instead? See how
> this is done in e.g. drivers/scsi/mpt3sas/mpt3sas_ctl.c or
> drivers/message/fusion/mptctl.c
Yes, could be done that way, But I want to retain compatibility with
existing shell scripts doing things like:
DEVICE=/dev/megaraid_sas_ioctl_node
DEVICENAME=megaraid_sas_ioctl
DEVICEPERM=400
MAJOR=`grep "$DEVICENAME" /proc/devices | awk '{print $1}'`
if [ -n "$MAJOR" -a ! -e "$DEVICE" ]; then
mknod "$DEVICE" c "$MAJOR" 0
chmod "$DEVICEPERM" "$DEVICE"
fi
Snippets like this one appear both in open-source projects and Dell scripts.
Patrick
On 05/06/2013 04:23 PM, Bjørn Mork wrote:
> "Patrick Monnerat" <[email protected]> writes:
>> Create ioctl device node for megaraid_sas driver. Let this node be
>> managed by udev. Fix a typo.
>
> Or maybe just simplify it all and use a misc device instead? See how
> this is done in e.g. drivers/scsi/mpt3sas/mpt3sas_ctl.c or
> drivers/message/fusion/mptctl.c
Yes, could be done that way, but I want to retain compatibility with
existing shell scripts doing things like:
DEVICE=/dev/megaraid_sas_ioctl_node
DEVICENAME=megaraid_sas_ioctl
DEVICEPERM=400
MAJOR=`grep "$DEVICENAME" /proc/devices | awk '{print $1}'`
if [ -n "$MAJOR" -a ! -e "$DEVICE" ]; then
mknod "$DEVICE" c "$MAJOR" 0
chmod "$DEVICEPERM" "$DEVICE"
fi
????{.n?+???????+%?????ݶ??w??{.n?+????{??G?????{ay?ʇڙ?,j??f???h?????????z_??(?階?ݢj"???m??????G????????????&???~???iO???z??v?^?m????????????I?