Whamcloud - gitweb
- newdev feature in obdctl
authorbraam <braam>
Tue, 23 Apr 2002 19:23:24 +0000 (19:23 +0000)
committerbraam <braam>
Tue, 23 Apr 2002 19:23:24 +0000 (19:23 +0000)
lustre/include/linux/lustre_idl.h
lustre/include/linux/obd.h
lustre/obdclass/class_obd.c
lustre/utils/obdctl.c

index 74c9c90..c36bf31 100644 (file)
@@ -550,6 +550,7 @@ static inline int obd_ioctl_getdata(char *buf, char *end, void *arg)
 #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_NEWDEV                 _IOWR('f', 30, long)
 
 #define OBD_IOC_DEC_FS_USE_COUNT       _IO  ('f', 32      )
 
index 1485ef0..b1b6a06 100644 (file)
@@ -196,6 +196,8 @@ struct obd_ops {
         int (*o_cleanup)(struct obd_device *dev);
         int (*o_connect)(struct obd_conn *conn);
         int (*o_disconnect)(struct obd_conn *conn);
+
+
         int (*o_statfs)(struct obd_conn *conn, struct statfs *statfs);
         int (*o_preallocate)(struct obd_conn *, obd_count *req, obd_id *ids);
         int (*o_create)(struct obd_conn *conn,  struct obdo *oa);
index 0aa6e78..a39dfcc 100644 (file)
@@ -158,7 +158,7 @@ static int obd_class_ioctl (struct inode * inode, struct file * filp,
         memset(buf, 0, sizeof(buf));
 
         if (!obd && cmd != OBD_IOC_DEVICE && cmd != TCGETS
-            && cmd != OBD_IOC_NAME2DEV) {
+            && cmd != OBD_IOC_NAME2DEV && cmd != OBD_IOC_NEWDEV) {
                 CERROR("OBD ioctl: No device\n");
                 RETURN(-EINVAL);
         }
@@ -207,6 +207,29 @@ static int obd_class_ioctl (struct inode * inode, struct file * filp,
                 RETURN(err);
         }
 
+        case OBD_IOC_NEWDEV: {
+                int dev = -1;
+                int i;
+
+                filp->private_data = NULL;
+                for (i = 0 ; i < MAX_OBD_DEVICES ; i++) { 
+                        struct obd_device *obd = &obd_dev[i];
+                        if (!obd->obd_type) { 
+                                filp->private_data = obd;
+                                dev = i;
+                                break;
+                        }
+                }
+
+                
+                data->ioc_dev = dev; 
+                if (dev == -1) 
+                        RETURN(-EINVAL); 
+
+                err = copy_to_user((int *)arg, data, sizeof(*data));
+                RETURN(err);
+        }
+
         case OBD_IOC_ATTACH: {
                 struct obd_type *type;
 
index 98517e8..b9fef32 100644 (file)
@@ -122,6 +122,18 @@ char * obdo_print(struct obdo *obd)
         return strdup(buf);
 }
 
+int getfd()
+{
+        if (fd == -1)                                           
+                fd = open("/dev/obd", O_RDWR);                     
+        if (fd == -1) {                                            
+                fprintf(stderr, "error: opening /dev/obd: %s\n",
+                        strerror(errno));         
+                return -1;
+        }
+        return 0;
+}
+
 static char *cmdname(char *func)
 {
         static char buf[512];
@@ -432,6 +444,32 @@ static int jt_cleanup(int argc, char **argv)
         return rc;
 }
 
+static int jt_newdev(int argc, char **argv)
+{
+        struct obd_ioctl_data data;
+        int rc;
+
+        if (getfd())
+                return -1;
+
+        IOCINIT(data);
+
+        if (argc != 1) {
+                fprintf(stderr, "usage: %s\n", cmdname(argv[0]));
+                return -1;
+        }
+
+        rc = ioctl(fd, OBD_IOC_NEWDEV , &data);
+        if (rc < 0)
+                fprintf(stderr, "error: %s: %s\n", cmdname(argv[0]),
+                        strerror(rc=errno));
+        else { 
+                printf("Current device set to %d\n", data.ioc_dev); 
+        }
+
+        return rc;
+}
+
 static int jt_attach(int argc, char **argv)
 {
         struct obd_ioctl_data data;
@@ -481,13 +519,8 @@ static int jt_name2dev(int argc, char **argv)
         struct obd_ioctl_data data;
         int rc;
 
-        if (fd == -1)
-                fd = open("/dev/obd", O_RDWR);
-        if (fd == -1) {
-                fprintf(stderr, "error: %s: opening /dev/obd: %s\n",
-                        cmdname(argv[0]), strerror(errno));
-                return errno;
-        }
+        if (getfd())
+                return -1;
 
         IOCINIT(data);
 
@@ -861,6 +894,7 @@ command_t cmdlist[] = {
                 "--threads <threads> <devno> <command [args ...]>"},
 
         /* Device configuration commands */
+        {"newdev", jt_newdev, 0, "set device to a new unused obd (no args)"},
         {"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"},