Whamcloud - gitweb
LU-10086 libcfs: use dynamic minors for /dev/{lnet,obd} 41/29741/2
authorJohn L. Hammond <john.hammond@intel.com>
Tue, 24 Oct 2017 15:28:57 +0000 (10:28 -0500)
committerOleg Drokin <oleg.drokin@intel.com>
Mon, 6 Nov 2017 03:43:04 +0000 (03:43 +0000)
Request dynamic minor allocation when registering /dev/lnet and
/dev/obd. Remove the obsolete create-device-if-not-found code from
register_ioc_dev().

Signed-off-by: John L. Hammond <john.hammond@intel.com>
Change-Id: I59c70912b4729f58a76dc6107b3e1d7379c6d7a3
Reviewed-on: https://review.whamcloud.com/29741
Tested-by: Jenkins
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: Andreas Dilger <andreas.dilger@intel.com>
Reviewed-by: Jian Yu <jian.yu@intel.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
15 files changed:
libcfs/include/libcfs/linux/libcfs.h
libcfs/include/libcfs/util/ioctl.h
libcfs/libcfs/linux/linux-debug.c
libcfs/libcfs/linux/linux-module.c
libcfs/libcfs/module.c
libcfs/libcfs/util/l_ioctl.c
lnet/include/uapi/linux/lnet/lnetctl.h
lnet/utils/lnetconfig/liblnetconfig.c
lnet/utils/lst.c
lustre/include/uapi/linux/lustre/lustre_ioctl.h
lustre/obdclass/class_obd.c
lustre/obdclass/linux/linux-module.c
lustre/utils/lustre_rsync.c
lustre/utils/obd.c
lustre/utils/portals.c

index 7f8f97b..0f67a87 100644 (file)
@@ -53,7 +53,6 @@
 #include <linux/kernel.h>
 #include <linux/kmod.h>
 #include <linux/kthread.h>
-#include <linux/miscdevice.h>
 #include <linux/mm.h>
 #include <linux/module.h>
 #include <linux/moduleparam.h>
index eddd4f1..b6f4f67 100644 (file)
@@ -62,7 +62,7 @@ do {                                                  \
 /* FIXME - rename these to libcfs_ */
 int libcfs_ioctl_pack(struct libcfs_ioctl_data *data, char **pbuf, int max);
 void libcfs_ioctl_unpack(struct libcfs_ioctl_data *data, char *pbuf);
-int register_ioc_dev(int dev_id, const char *dev_name, int major, int minor);
+int register_ioc_dev(int dev_id, const char *dev_name);
 void unregister_ioc_dev(int dev_id);
 int l_ioctl(int dev_id, unsigned int opc, void *buf);
 #endif
index 72a3a4f..6d6768d 100644 (file)
@@ -53,7 +53,6 @@
 #include <linux/fs.h>
 #include <linux/stat.h>
 #include <asm/uaccess.h>
-#include <linux/miscdevice.h>
 #include <linux/version.h>
 
 # define DEBUG_SUBSYSTEM S_LNET
index 6da5565..839f932 100644 (file)
 
 #define DEBUG_SUBSYSTEM S_LNET
 
+#include <linux/miscdevice.h>
 #include <libcfs/libcfs.h>
 
-#define LNET_MINOR 240
-
 static inline size_t libcfs_ioctl_packlen(struct libcfs_ioctl_data *data)
 {
        size_t len = sizeof(*data);
@@ -168,7 +167,7 @@ static struct file_operations libcfs_fops = {
 };
 
 struct miscdevice libcfs_dev = {
-       .minor  = LNET_MINOR,
+       .minor  = MISC_DYNAMIC_MINOR,
        .name   = "lnet",
        .fops   = &libcfs_fops
 };
index 6ec93f4..cdfd83e 100644 (file)
@@ -29,6 +29,7 @@
  * This file is part of Lustre, http://www.lustre.org/
  * Lustre is a trademark of Sun Microsystems, Inc.
  */
+#include <linux/miscdevice.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/mm.h>
index 1615f0b..2e69648 100644 (file)
 #include <linux/lnet/lnetctl.h>
 
 struct ioc_dev {
-        const char * dev_name;
-        int dev_fd;
-        int dev_major;
-        int dev_minor;
+       const char *dev_name;
+       int dev_fd;
 };
 
 static struct ioc_dev ioc_dev_list[10];
 
-struct dump_hdr {
-        int magic;
-        int dev_id;
-        unsigned int opc;
-};
-
-/* Catamount has no <linux/kdev_t.h>, so just define it here */
-#ifndef MKDEV
-# define MKDEV(a,b) (((a) << 8) | (b))
-#endif
-
 static int
 open_ioc_dev(int dev_id)
 {
@@ -75,17 +62,6 @@ open_ioc_dev(int dev_id)
         if (ioc_dev_list[dev_id].dev_fd < 0) {
                int fd = open(dev_name, O_RDWR);
 
-               /* Make the /dev/ node if we need to */
-               if (fd < 0 && errno == ENOENT) {
-                       if (mknod(dev_name, S_IFCHR|S_IWUSR|S_IRUSR,
-                                 MKDEV(ioc_dev_list[dev_id].dev_major,
-                                       ioc_dev_list[dev_id].dev_minor)) == 0)
-                               fd = open(dev_name, O_RDWR);
-                        else
-                                fprintf(stderr, "mknod %s failed: %s\n",
-                                        dev_name, strerror(errno));
-                }
-
                 if (fd < 0) {
                         fprintf(stderr, "opening %s failed: %s\n"
                                 "hint: the kernel modules may not be loaded\n",
@@ -114,9 +90,8 @@ int l_ioctl(int dev_id, unsigned int opc, void *buf)
 
 /* register a device to send ioctls to.  */
 int
-register_ioc_dev(int dev_id, const char *dev_name, int major, int minor)
+register_ioc_dev(int dev_id, const char *dev_name)
 {
-
        if (dev_id < 0 ||
             dev_id >= sizeof(ioc_dev_list) / sizeof(ioc_dev_list[0]))
                 return -EINVAL;
@@ -125,8 +100,6 @@ register_ioc_dev(int dev_id, const char *dev_name, int major, int minor)
 
         ioc_dev_list[dev_id].dev_name = dev_name;
         ioc_dev_list[dev_id].dev_fd = -1;
-        ioc_dev_list[dev_id].dev_major = major;
-        ioc_dev_list[dev_id].dev_minor = minor;
 
         return dev_id;
 }
index c39ca43..49d7215 100644 (file)
@@ -134,7 +134,5 @@ struct lnet_fault_stat {
 
 #define LNET_DEV_ID    0
 #define LNET_DEV_PATH  "/dev/lnet"
-#define LNET_DEV_MAJOR 10
-#define LNET_DEV_MINOR 240
 
 #endif
index b372837..969143b 100644 (file)
@@ -396,8 +396,7 @@ failed:
 
 int lustre_lnet_config_lib_init(void)
 {
-       return register_ioc_dev(LNET_DEV_ID, LNET_DEV_PATH,
-                               LNET_DEV_MAJOR, LNET_DEV_MINOR);
+       return register_ioc_dev(LNET_DEV_ID, LNET_DEV_PATH);
 }
 
 void lustre_lnet_config_lib_uninit(void)
index e5e8abb..c47fd5d 100644 (file)
@@ -3336,8 +3336,7 @@ main(int argc, char **argv)
 #ifdef USE_DLC
        rc = lustre_lnet_config_lib_init();
 #else
-       rc = register_ioc_dev(LNET_DEV_ID, LNET_DEV_PATH,
-                             LNET_DEV_MAJOR, LNET_DEV_MINOR);
+       rc = register_ioc_dev(LNET_DEV_ID, LNET_DEV_PATH);
 #endif
        if (rc < 0)
                goto errorout;
index 9a28842..3cf2350 100644 (file)
@@ -66,8 +66,6 @@ enum md_echo_cmd {
 #define OBD_DEV_ID 1
 #define OBD_DEV_NAME "obd"
 #define OBD_DEV_PATH "/dev/" OBD_DEV_NAME
-#define OBD_DEV_MAJOR 10
-#define OBD_DEV_MINOR 241
 
 #define OBD_IOCTL_VERSION      0x00010004
 #define OBD_DEV_BY_DEVNAME     0xffffd0de
index 6648a0e..56be7fd 100644 (file)
@@ -32,6 +32,7 @@
 
 #define DEBUG_SUBSYSTEM S_CLASS
 
+#include <linux/miscdevice.h>
 #include <linux/user_namespace.h>
 #ifdef HAVE_UIDGID_HEADER
 # include <linux/uidgid.h>
@@ -448,7 +449,7 @@ static int __init obdclass_init(void)
 
        err = misc_register(&obd_psdev);
        if (err) {
-               CERROR("cannot register %d err %d\n", OBD_DEV_MINOR, err);
+               CERROR("cannot register OBD miscdevice: err = %d\n", err);
                goto cleanup_class_handle;
        }
 
index 6441c03..5d0782e 100644 (file)
@@ -41,7 +41,6 @@
 #include <linux/module.h>
 #include <linux/errno.h>
 #include <linux/kernel.h>
-#include <linux/major.h>
 #include <linux/sched.h>
 #include <linux/lp.h>
 #include <linux/slab.h>
@@ -269,9 +268,9 @@ static struct file_operations obd_psdev_fops = {
 
 /* modules setup */
 struct miscdevice obd_psdev = {
-        .minor = OBD_DEV_MINOR,
-        .name  = OBD_DEV_NAME,
-        .fops  = &obd_psdev_fops,
+       .minor  = MISC_DYNAMIC_MINOR,
+       .name   = OBD_DEV_NAME,
+       .fops   = &obd_psdev_fops,
 };
 
 static ssize_t version_show(struct kobject *kobj, struct attribute *attr,
index fc971dc..c005a98 100644 (file)
@@ -1793,8 +1793,7 @@ int main(int argc, char *argv[])
 
         /* This plumbing is needed for some of the ioctls behind
            llapi calls to work. */
-       register_ioc_dev(OBD_DEV_ID, OBD_DEV_PATH,
-                        OBD_DEV_MAJOR, OBD_DEV_MINOR);
+       register_ioc_dev(OBD_DEV_ID, OBD_DEV_PATH);
 
         rc = lr_locate_rsync();
         if (use_rsync && rc != 0) {
index 33b67ca..0cc3361 100644 (file)
@@ -2864,8 +2864,7 @@ int obd_initialize(int argc, char **argv)
        if (shmem_setup() != 0)
                return -1;
 
-       register_ioc_dev(OBD_DEV_ID, OBD_DEV_PATH,
-                        OBD_DEV_MAJOR, OBD_DEV_MINOR);
+       register_ioc_dev(OBD_DEV_ID, OBD_DEV_PATH);
 
        return 0;
 }
index 12aec42..3597eaf 100644 (file)
@@ -287,8 +287,8 @@ int ptl_initialize(int argc, char **argv)
        if (argc > 1)
                g_net_interactive = true;
 
-        register_ioc_dev(LNET_DEV_ID, LNET_DEV_PATH,
-                         LNET_DEV_MAJOR, LNET_DEV_MINOR);
+       register_ioc_dev(LNET_DEV_ID, LNET_DEV_PATH);
+
         return 0;
 }