]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blobdiff - src/patches/suse-2.6.27.31/patches.suse/raw_device_max_minors_param.diff
Added missing Xen Kernel Patches which were not commited because
[people/pmueller/ipfire-2.x.git] / src / patches / suse-2.6.27.31 / patches.suse / raw_device_max_minors_param.diff
diff --git a/src/patches/suse-2.6.27.31/patches.suse/raw_device_max_minors_param.diff b/src/patches/suse-2.6.27.31/patches.suse/raw_device_max_minors_param.diff
new file mode 100644 (file)
index 0000000..2971d63
--- /dev/null
@@ -0,0 +1,112 @@
+From: Jan Kara <jack@suse.cz>
+Subject: Allow setting of number of raw devices as a module parameter
+References: FATE 302178
+Patch-mainline: never
+
+Allow setting of maximal number of raw devices as a module parameter. This requires
+changing of static array into a vmalloced one (the array is going to be too large
+for kmalloc).
+
+Signed-off-by: Jan Kara <jack@suse.cz>
+
+---
+ drivers/char/Kconfig |    2 +-
+ drivers/char/raw.c   |   33 +++++++++++++++++++++++++++------
+ 2 files changed, 28 insertions(+), 7 deletions(-)
+
+--- a/drivers/char/Kconfig
++++ b/drivers/char/Kconfig
+@@ -1026,7 +1026,7 @@ config RAW_DRIVER
+           with the O_DIRECT flag.
+ config MAX_RAW_DEVS
+-      int "Maximum number of RAW devices to support (1-8192)"
++      int "Maximum number of RAW devices to support (1-65536)"
+       depends on RAW_DRIVER
+       default "256"
+       help
+--- a/drivers/char/raw.c
++++ b/drivers/char/raw.c
+@@ -20,6 +20,7 @@
+ #include <linux/device.h>
+ #include <linux/mutex.h>
+ #include <linux/smp_lock.h>
++#include <linux/vmalloc.h>
+ #include <asm/uaccess.h>
+@@ -29,10 +30,15 @@ struct raw_device_data {
+ };
+ static struct class *raw_class;
+-static struct raw_device_data raw_devices[MAX_RAW_MINORS];
++static struct raw_device_data *raw_devices;
+ static DEFINE_MUTEX(raw_mutex);
+ static const struct file_operations raw_ctl_fops; /* forward declaration */
++static int max_raw_minors = MAX_RAW_MINORS;
++
++module_param(max_raw_minors, int, 0);
++MODULE_PARM_DESC(max_raw_minors, "Maximum number of raw devices (1-65536)");
++
+ /*
+  * Open/close code for raw IO.
+  *
+@@ -158,7 +164,7 @@ static int raw_ctl_ioctl(struct inode *i
+                       goto out;
+               }
+-              if (rq.raw_minor <= 0 || rq.raw_minor >= MAX_RAW_MINORS) {
++              if (rq.raw_minor <= 0 || rq.raw_minor >= max_raw_minors) {
+                       err = -EINVAL;
+                       goto out;
+               }
+@@ -266,12 +272,26 @@ static int __init raw_init(void)
+       dev_t dev = MKDEV(RAW_MAJOR, 0);
+       int ret;
+-      ret = register_chrdev_region(dev, MAX_RAW_MINORS, "raw");
++      if (max_raw_minors < 1 || max_raw_minors > 65536) {
++              printk(KERN_WARNING "raw: invalid max_raw_minors (must be"
++                      " between 1 and 65536), using %d\n", MAX_RAW_MINORS);
++              max_raw_minors = MAX_RAW_MINORS;
++      }
++
++      raw_devices = vmalloc(sizeof(struct raw_device_data) * max_raw_minors);
++      if (!raw_devices) {
++              printk(KERN_ERR "Not enough memory for raw device structures\n");
++              ret = -ENOMEM;
++              goto error;
++      }
++      memset(raw_devices, 0, sizeof(struct raw_device_data) * max_raw_minors);
++
++      ret = register_chrdev_region(dev, max_raw_minors, "raw");
+       if (ret)
+               goto error;
+       cdev_init(&raw_cdev, &raw_fops);
+-      ret = cdev_add(&raw_cdev, dev, MAX_RAW_MINORS);
++      ret = cdev_add(&raw_cdev, dev, max_raw_minors);
+       if (ret) {
+               kobject_put(&raw_cdev.kobj);
+               goto error_region;
+@@ -290,8 +310,9 @@ static int __init raw_init(void)
+       return 0;
+ error_region:
+-      unregister_chrdev_region(dev, MAX_RAW_MINORS);
++      unregister_chrdev_region(dev, max_raw_minors);
+ error:
++      vfree(raw_devices);
+       return ret;
+ }
+@@ -300,7 +321,7 @@ static void __exit raw_exit(void)
+       device_destroy(raw_class, MKDEV(RAW_MAJOR, 0));
+       class_destroy(raw_class);
+       cdev_del(&raw_cdev);
+-      unregister_chrdev_region(MKDEV(RAW_MAJOR, 0), MAX_RAW_MINORS);
++      unregister_chrdev_region(MKDEV(RAW_MAJOR, 0), max_raw_minors);
+ }
+ module_init(raw_init);