Whamcloud - gitweb
LU-10086 libcfs: use dynamic minors for /dev/{lnet,obd} 45/29945/3
authorJohn L. Hammond <john.hammond@intel.com>
Tue, 24 Oct 2017 15:28:57 +0000 (10:28 -0500)
committerJohn L. Hammond <john.hammond@intel.com>
Mon, 27 Nov 2017 15:13:05 +0000 (15:13 +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().

Lustre-change: https://review.whamcloud.com/29741
Lustre-commit: e446c1667dc9136e3a1cb3603c3851975b68e0ac

Signed-off-by: John L. Hammond <john.hammond@intel.com>
Change-Id: I59c70912b4729f58a76dc6107b3e1d7379c6d7a3
Reviewed-by: Andreas Dilger <andreas.dilger@intel.com>
Reviewed-by: Jian Yu <jian.yu@intel.com>
Signed-off-by: Minh Diep <minh.diep@intel.com>
Reviewed-on: https://review.whamcloud.com/29945
Tested-by: Jenkins
Tested-by: Maloo <hpdd-maloo@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/lnet/lnetctl.h
lnet/utils/lnetconfig/liblnetconfig.c
lnet/utils/lst.c
lnet/utils/portals.c
lustre/include/uapi/linux/lustre_ioctl.h
lustre/obdclass/class_obd.c
lustre/obdclass/linux/linux-module.c
lustre/utils/lustre_rsync.c
lustre/utils/obd.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 4f2dd88..600bf27 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 e8080f3..b70a135 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 0cf8924..ceec870 100644 (file)
 #include <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 3d7fd27..bdd0cb4 100644 (file)
@@ -126,7 +126,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 2630d7e..9b915df 100644 (file)
@@ -334,8 +334,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 78359fe..4c2e182 100644 (file)
@@ -3336,6 +3336,10 @@ main(int argc, char **argv)
         if (rc < 0)
                 goto errorout;
 
+       rc = register_ioc_dev(LNET_DEV_ID, LNET_DEV_PATH);
+       if (rc < 0)
+               goto errorout;
+
         Parser_init("lst > ", lst_cmdlist);
 
         if (argc != 1)  {
index 81aedd5..015afd3 100644 (file)
@@ -286,8 +286,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;
 }
 
index 2e8ee29..cb4ec46 100644 (file)
 #include <linux/types.h>
 #include <lustre/lustre_idl.h>
 
+#ifndef __KERNEL__
+# define __user
+#endif
+
 #if !defined(__KERNEL__) && !defined(LUSTRE_UTILS)
 # error This file is for Lustre internal use only.
 #endif
@@ -57,8 +61,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 d65a85d..913ae54 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>
@@ -532,7 +533,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 6cee4d7..dabbf58 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>
@@ -267,9 +266,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 2be588c..7d9dc09 100644 (file)
 #include <time.h>
 #include <sys/xattr.h>
 #include <linux/types.h>
+#include <linux/lustre_ioctl.h>
 
 #include <libcfs/libcfs_debug.h>
+#include <libcfs/util/ioctl.h>
 #include <libcfs/util/string.h>
 #include <libcfs/util/parser.h>
 #include <lustre/lustreapi.h>
@@ -1792,10 +1794,7 @@ int main(int argc, char *argv[])
 
         /* This plumbing is needed for some of the ioctls behind
            llapi calls to work. */
-        if (obd_initialize(argc, argv) < 0) {
-                fprintf(stderr, "obd_initialize failed.\n");
-                exit(-1);
-        }
+       register_ioc_dev(OBD_DEV_ID, OBD_DEV_PATH);
 
         rc = lr_locate_rsync();
         if (use_rsync && rc != 0) {
index c521d2b..2e84177 100644 (file)
@@ -2862,8 +2862,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;
 }