Whamcloud - gitweb
- fix mds_connect memory leak
authorbraam <braam>
Mon, 22 Apr 2002 06:56:45 +0000 (06:56 +0000)
committerbraam <braam>
Mon, 22 Apr 2002 06:56:45 +0000 (06:56 +0000)
- install name parameter for jt_attach in obdctl
- add name2dev feature to find device by name

lustre/include/linux/lustre_idl.h
lustre/include/linux/obd.h
lustre/obdclass/class_obd.c
lustre/utils/obdctl.c

index 260a26c..74c9c90 100644 (file)
@@ -549,6 +549,7 @@ static inline int obd_ioctl_getdata(char *buf, char *end, void *arg)
 #define OBD_IOC_MODULE_DEBUG           _IOWR('f', 26, long)
 #define OBD_IOC_BRW_READ               _IOWR('f', 27, long)
 #define OBD_IOC_BRW_WRITE              _IOWR('f', 28, long)
+#define OBD_IOC_NAME2DEV               _IOWR('f', 29, long)
 
 #define OBD_IOC_DEC_FS_USE_COUNT       _IO  ('f', 32      )
 
index 6604d53..1485ef0 100644 (file)
@@ -151,6 +151,9 @@ struct osc_obd {
 #define MAX_MULTI       16
 struct obd_device {
         struct obd_type *obd_type;
+        char *obd_name;
+        __u8 obd_uuid[37];
+
         int obd_minor;
         int obd_flags;
         int obd_refcnt;
index f89d10f..a49c31a 100644 (file)
@@ -87,6 +87,23 @@ static int obd_class_release(struct inode * inode, struct file * file)
         RETURN(0);
 }
 
+static int obd_class_name2dev(char *name)
+{
+        int res = -1;
+        int i;
+
+        for (i=0; i < MAX_OBD_DEVICES; i++) { 
+                struct obd_device *obd = &obd_dev[i];
+                if (obd->obd_name && 
+                    strcmp(name, obd->obd_name) == 0) {
+                        res = i; 
+                        return res;
+                }
+        }
+                
+        return res;
+}
+
 /* 
  * support functions: we could use inter-module communication, but this 
  * is more portable to other OS's
@@ -167,6 +184,27 @@ static int obd_class_ioctl (struct inode * inode, struct file * filp,
                 RETURN(0);
         }
 
+        case OBD_IOC_NAME2DEV: { 
+                int dev;
+                if (!data->ioc_inlbuf1) { 
+                        CERROR("No name passed!\n");
+                        RETURN(-EINVAL);
+                }
+                CDEBUG(D_IOCTL, "device name %s\n", data->ioc_inlbuf1);
+                dev = obd_class_name2dev(data->ioc_inlbuf1);
+                data->ioc_dev= dev;
+                if (dev == -1) { 
+                        CERROR("No device for name %s!\n", data->ioc_inlbuf1);
+                        RETURN(-EINVAL);
+                }
+
+                CDEBUG(D_IOCTL, "device name %s, dev %d\n", data->ioc_inlbuf1, 
+                       dev);
+                filp->private_data = &obd_dev[data->ioc_dev];
+                err = copy_to_user((int *)arg, data, sizeof(*data));
+                RETURN(err);
+        }
+
         case OBD_IOC_ATTACH: {
                 struct obd_type *type;
 
@@ -194,8 +232,7 @@ static int obd_class_ioctl (struct inode * inode, struct file * filp,
 
                 /* do the attach */
                 if (OBT(obd) && OBP(obd, attach))
-                        err = OBP(obd, attach)(obd, sizeof(*data), data);
-
+                        err = OBP(obd,attach)(obd, sizeof(*data), data);
                 if (err) {
                         obd->obd_type = NULL;
                 } else {
@@ -205,6 +242,16 @@ static int obd_class_ioctl (struct inode * inode, struct file * filp,
                                obd->obd_minor, data->ioc_inlbuf1);
                         obd->obd_proc_entry = 
                                 proc_lustre_register_obd_device(obd);
+                        if (data->ioc_inlbuf2) { 
+                                int len = strlen(data->ioc_inlbuf2);
+                                OBD_ALLOC(obd->obd_name, len + 1); 
+                                if (!obd->obd_name) { 
+                                        CERROR("no memory\n"); 
+                                        LBUG();
+                                }
+                                memcpy(obd->obd_name, data->ioc_inlbuf2, len+1);
+                        }
+
                         MOD_INC_USE_COUNT;
                 }
 
@@ -231,6 +278,11 @@ static int obd_class_ioctl (struct inode * inode, struct file * filp,
                                obd->obd_minor);
                         RETURN(-EBUSY);
                 }
+                
+                if (obd->obd_name) { 
+                        OBD_FREE(obd->obd_name, strlen(obd->obd_name)+ 1);
+                        obd->obd_name = NULL;
+                }
 
                 if (obd->obd_proc_entry)
                         proc_lustre_release_obd_device(obd);
index 56c758e..9d60972 100644 (file)
@@ -134,7 +134,7 @@ static char *cmdname(char *func)
         return func;
 }
 
-#define difftime(a, b)                                         \
+#define difftime(a, b)                                          \
         ((double)(a)->tv_sec - (b)->tv_sec +                    \
          ((double)((a)->tv_usec - (b)->tv_usec) / 1000000))
 
@@ -440,7 +440,7 @@ static int jt_attach(int argc, char **argv)
         IOCINIT(data);
 
         if (argc != 2 && argc != 3) {
-                fprintf(stderr, "usage: %s type [data]\n", cmdname(argv[0]));
+                fprintf(stderr, "usage: %s type [name [uuid]]\n", cmdname(argv[0]));
                 return -1;
         }
 
@@ -471,6 +471,43 @@ static int jt_attach(int argc, char **argv)
         return rc;
 }
 
+static int jt_name2dev(int argc, char **argv)
+{
+        struct obd_ioctl_data data;
+        int rc;
+
+        IOCINIT(data);
+
+        if (argc != 2) { 
+                fprintf(stderr, "usage: %s name\n", cmdname(argv[0]));
+                return -1;
+        }
+
+        data.ioc_inllen1 =  strlen(argv[1]) + 1;
+        data.ioc_inlbuf1 = argv[1];
+
+        printf("%s: len %d addr %p name %s\n",
+               cmdname(argv[0]), data.ioc_len, buf,
+               MKSTR(data.ioc_inlbuf1));
+
+        if (obd_ioctl_pack(&data, &buf, max)) {
+                fprintf(stderr, "error: %s: invalid ioctl\n", cmdname(argv[0]));
+                return -2;
+        }
+        printf("%s: len %d addr %p raw %p name %s and %s\n",
+               cmdname(argv[0]), data.ioc_len, buf, rawbuf,
+               MKSTR(data.ioc_inlbuf1), &buf[516]);
+
+        rc = ioctl(fd, OBD_IOC_NAME2DEV , buf);
+        if (rc < 0)
+                fprintf(stderr, "error: %s: %x %s\n", cmdname(argv[0]),
+                        OBD_IOC_NAME2DEV, strerror(rc = errno));
+        memcpy((char *)(&data), buf, sizeof(data));
+        printf("device set to %d (name %s)\n", data.ioc_dev, argv[1]);
+
+        return rc;
+}
+
 static int jt_setup(int argc, char **argv)
 {
         struct obd_ioctl_data data;
@@ -827,7 +864,8 @@ command_t cmdlist[] = {
                 "--threads <threads> <devno> <command [args ...]>"},
 
         /* Device configuration commands */
-        {"device", jt_device, 0, "set current device (args device no)"},
+        {"device", jt_device, 0, "set current device (args device_no name)"},
+        {"name2dev", jt_name2dev, 0, "set device by name (args name)"},
         {"attach", jt_attach, 0, "name the type of device (args: type data"},
         {"setup", jt_setup, 0, "setup device (args: <blkdev> [data]"},
         {"detach", jt_detach, 0, "detach the current device (arg: )"},