Whamcloud - gitweb
b=2353
authorrread <rread>
Fri, 19 Dec 2003 19:45:29 +0000 (19:45 +0000)
committerrread <rread>
Fri, 19 Dec 2003 19:45:29 +0000 (19:45 +0000)
r=shaver

Delete IOC_CONNECT,DISCONNECT and use obd_self_export instead
of creating connections for lctl. Also delete the IOC_DEVICE comamnd
and make the ioctl interface stateless.  The lctl probe command is now
a noop, and lctl device is still used to set the device, although the
current device state is only saved in lctl now, and not the kernel.

lustre/include/linux/lustre_lib.h
lustre/include/linux/obd_class.h
lustre/obdclass/class_obd.c
lustre/utils/lconf
lustre/utils/obd.c
lustre/utils/obdiolib.c
lustre/utils/obdiolib.h

index 41dfe21..79671e8 100644 (file)
@@ -398,8 +398,8 @@ static inline void obd_ioctl_freedata(char *buf, int len)
 #define OBD_IOC_GETATTR                _IOR ('f', 108, long)
 #define OBD_IOC_READ                   _IOWR('f', 109, long)
 #define OBD_IOC_WRITE                  _IOWR('f', 110, long)
-#define OBD_IOC_CONNECT                _IOR ('f', 111, long)
-#define OBD_IOC_DISCONNECT             _IOW ('f', 112, long)
+
+
 #define OBD_IOC_STATFS                 _IOWR('f', 113, long)
 #define OBD_IOC_SYNC                   _IOR ('f', 114, long)
 #define OBD_IOC_READ2                  _IOWR('f', 115, long)
@@ -408,7 +408,7 @@ static inline void obd_ioctl_freedata(char *buf, int len)
 #define OBD_IOC_COPY                   _IOWR('f', 120, long)
 #define OBD_IOC_MIGR                   _IOWR('f', 121, long)
 #define OBD_IOC_PUNCH                  _IOWR('f', 122, long)
-#define OBD_IOC_DEVICE                 _IOWR('f', 123, long)
+
 #define OBD_IOC_MODULE_DEBUG           _IOWR('f', 124, long)
 #define OBD_IOC_BRW_READ               _IOWR('f', 125, long)
 #define OBD_IOC_BRW_WRITE              _IOWR('f', 126, long)
index 0150a4e..9627eab 100644 (file)
@@ -1074,17 +1074,6 @@ static inline void obdo_free(struct obdo *oa)
 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
 extern void (*ptlrpc_abort_inflight_superhack)(struct obd_import *imp);
 
-struct obd_class_user_state {
-        struct obd_device     *ocus_current_obd;
-        struct list_head       ocus_conns;
-};
-
-struct obd_class_user_conn {
-        struct list_head       ocuc_chain;
-        struct obd_export     *ocuc_exp;
-};
-
-
 /* sysctl.c */
 extern void obd_sysctl_init (void);
 extern void obd_sysctl_clean (void);
index 68f9442..a59a831 100644 (file)
@@ -85,16 +85,8 @@ unsigned int obd_sync_filter; /* = 0, don't sync by default */
 /*  opening /dev/obd */
 static int obd_class_open(struct inode * inode, struct file * file)
 {
-        struct obd_class_user_state *ocus;
         ENTRY;
 
-        OBD_ALLOC(ocus, sizeof(*ocus));
-        if (ocus == NULL)
-                return (-ENOMEM);
-
-        INIT_LIST_HEAD(&ocus->ocus_conns);
-        file->private_data = ocus;
-
         PORTAL_MODULE_USE;
         RETURN(0);
 }
@@ -102,67 +94,13 @@ static int obd_class_open(struct inode * inode, struct file * file)
 /*  closing /dev/obd */
 static int obd_class_release(struct inode * inode, struct file * file)
 {
-        struct obd_class_user_state *ocus = file->private_data;
-        struct obd_class_user_conn  *c;
         ENTRY;
 
-        while (!list_empty (&ocus->ocus_conns)) {
-                c = list_entry (ocus->ocus_conns.next,
-                                struct obd_class_user_conn, ocuc_chain);
-                list_del (&c->ocuc_chain);
-
-                CDEBUG (D_IOCTL, "Auto-disconnect exp %p\n", c->ocuc_exp);
-
-                down (&obd_conf_sem);
-                obd_disconnect (c->ocuc_exp, 0);
-                up (&obd_conf_sem);
-
-                OBD_FREE (c, sizeof (*c));
-        }
-
-        OBD_FREE (ocus, sizeof (*ocus));
-
         PORTAL_MODULE_UNUSE;
         RETURN(0);
 }
 #endif
 
-static int obd_class_add_user_exp(struct obd_class_user_state *ocus,
-                                  struct obd_export *exp)
-{
-        struct obd_class_user_conn *c;
-        ENTRY;
-        /* NB holding obd_conf_sem */
-
-        OBD_ALLOC (c, sizeof (*c));
-        if (c == NULL)
-                RETURN(-ENOMEM);
-
-        c->ocuc_exp = class_export_get(exp);
-        list_add (&c->ocuc_chain, &ocus->ocus_conns);
-        RETURN(0);
-}
-
-static void obd_class_remove_user_exp(struct obd_class_user_state *ocus,
-                                      struct obd_export *exp)
-{
-        struct obd_class_user_conn *c;
-        ENTRY;
-
-        /* NB holding obd_conf_sem or last reference */
-
-        list_for_each_entry(c, &ocus->ocus_conns, ocuc_chain) {
-                if (exp == c->ocuc_exp) {
-                        list_del (&c->ocuc_chain);
-                        OBD_FREE (c, sizeof (*c));
-                        class_export_put(exp);
-                        EXIT;
-                        return;
-                }
-        }
-        EXIT;
-}
-
 static inline void obd_data2conn(struct lustre_handle *conn,
                                  struct obd_ioctl_data *data)
 {
@@ -204,14 +142,12 @@ out:
         RETURN(rc);
 }
 
-int class_handle_ioctl(struct obd_class_user_state *ocus, unsigned int cmd,
-                       unsigned long arg)
+int class_handle_ioctl(unsigned int cmd, unsigned long arg)
 {
         char *buf = NULL;
         struct obd_ioctl_data *data;
         struct portals_debug_ioctl_data *debug_data;
-        struct obd_device *obd = ocus->ocus_current_obd;
-        struct lustre_handle conn;
+        struct obd_device *obd = NULL;
         int err = 0, len = 0, serialised = 0;
         ENTRY;
 
@@ -250,13 +186,6 @@ int class_handle_ioctl(struct obd_class_user_state *ocus, unsigned int cmd,
         }
 
         CDEBUG(D_IOCTL, "cmd = %x, obd = %p\n", cmd, obd);
-        if (!obd && cmd != OBD_IOC_DEVICE &&
-            cmd != OBD_IOC_LIST && cmd != OBD_GET_VERSION &&
-            cmd != OBD_IOC_NAME2DEV && cmd != OBD_IOC_UUID2DEV &&
-            cmd != OBD_IOC_PROCESS_CFG) {
-                CERROR("OBD ioctl: No device\n");
-                GOTO(out, err = -EINVAL);
-        }
         if (obd_ioctl_getdata(&buf, &len, (void *)arg)) {
                 CERROR("OBD ioctl: data error\n");
                 GOTO(out, err = -EINVAL);
@@ -264,19 +193,6 @@ int class_handle_ioctl(struct obd_class_user_state *ocus, unsigned int cmd,
         data = (struct obd_ioctl_data *)buf;
 
         switch (cmd) {
-        case OBD_IOC_DEVICE: {
-                CDEBUG(D_IOCTL, "\n");
-                if (data->ioc_dev >= MAX_OBD_DEVICES) {
-                        CERROR("OBD ioctl: DEVICE invalid device %d\n",
-                               data->ioc_dev);
-                        ocus->ocus_current_obd = &obd_dev[data->ioc_dev];
-                        GOTO(out, err = -EINVAL);
-                }
-                CDEBUG(D_IOCTL, "device %d\n", data->ioc_dev);
-                ocus->ocus_current_obd = &obd_dev[data->ioc_dev];
-                GOTO(out, err = 0);
-        }
-
         case OBD_IOC_PROCESS_CFG: {
                 char *buf;
                 struct lustre_cfg *lcfg;
@@ -418,50 +334,27 @@ int class_handle_ioctl(struct obd_class_user_state *ocus, unsigned int cmd,
         }
 
 
-
-        case OBD_IOC_CONNECT: {
-                struct obd_export *exp;
-                obd_data2conn(&conn, data);
-
-                err = obd_connect(&conn, obd, &obd->obd_uuid);
-
-                CDEBUG(D_IOCTL, "assigned export "LPX64"\n", conn.cookie);
-                obd_conn2data(data, &conn);
-                if (err)
-                        GOTO(out, err);
-
-                exp = class_conn2export(&conn);
-                if (exp == NULL)
-                        GOTO(out, err = -EINVAL);
-
-                err = obd_class_add_user_exp(ocus, exp);
-                if (err != 0) {
-                        obd_disconnect(exp, 0);
-                        GOTO (out, err);
-                }
-
-                err = copy_to_user((void *)arg, data, sizeof(*data));
-                if (err != 0) {
-                        obd_class_remove_user_exp(ocus, exp);
-                        obd_disconnect(exp, 0);
-                        GOTO (out, err = -EFAULT);
-                }
-                class_export_put(exp);
-                GOTO(out, err);
+        case OBD_IOC_CLOSE_UUID: {
+                struct lustre_peer peer;
+                CDEBUG(D_IOCTL, "closing all connections to uuid %s\n",
+                       data->ioc_inlbuf1);
+                lustre_uuid_to_peer(data->ioc_inlbuf1, &peer);
+                GOTO(out, err = 0);
         }
 
-        case OBD_IOC_DISCONNECT: {
-                struct obd_export *exp;
-                obd_data2conn(&conn, data);
-                exp = class_conn2export(&conn);
-                if (exp == NULL)
-                        GOTO(out, err = -EINVAL);
+        }
 
-                obd_class_remove_user_exp(ocus, exp);
-                err = obd_disconnect(exp, 0);
-                GOTO(out, err);
+        if (data->ioc_dev >= MAX_OBD_DEVICES) {
+                CERROR("OBD ioctl: No device\n");
+                GOTO(out, err = -EINVAL);
+        } 
+        obd = &obd_dev[data->ioc_dev];
+        if (!(obd && obd->obd_set_up) || obd->obd_stopping) {
+                CERROR("OBD ioctl: device not setup %d \n", data->ioc_dev);
+                GOTO(out, err = -EINVAL);
         }
 
+        switch(cmd) {
         case OBD_IOC_NO_TRANSNO: {
                 if (!obd->obd_attached) {
                         CERROR("Device %d not attached\n", obd->obd_minor);
@@ -474,23 +367,8 @@ int class_handle_ioctl(struct obd_class_user_state *ocus, unsigned int cmd,
                 GOTO(out, err = 0);
         }
 
-        case OBD_IOC_CLOSE_UUID: {
-                struct lustre_peer peer;
-                CDEBUG(D_IOCTL, "closing all connections to uuid %s\n",
-                       data->ioc_inlbuf1);
-                lustre_uuid_to_peer(data->ioc_inlbuf1, &peer);
-                GOTO(out, err = 0);
-        }
-
         default: {
-                // obd_data2conn(&conn, data);
-                struct obd_class_user_conn *oconn;
-
-                if (list_empty(&ocus->ocus_conns)) 
-                        GOTO(out, err = -ENOTCONN);
-                        
-                oconn = list_entry(ocus->ocus_conns.next, struct obd_class_user_conn, ocuc_chain);
-                err = obd_iocontrol(cmd, oconn->ocuc_exp, len, data, NULL);
+                err = obd_iocontrol(cmd, obd->obd_self_export, len, data, NULL);
                 if (err)
                         GOTO(out, err);
 
@@ -517,7 +395,7 @@ int class_handle_ioctl(struct obd_class_user_state *ocus, unsigned int cmd,
 static int obd_class_ioctl(struct inode *inode, struct file *filp,
                            unsigned int cmd, unsigned long arg)
 {
-        return class_handle_ioctl(filp->private_data, cmd, arg);
+        return class_handle_ioctl(cmd, arg);
 }
 
 /* declare character device */
index 2a02815..11476ac 100755 (executable)
@@ -348,7 +348,6 @@ class LCTLInterface:
         elif self.record_device:
             cmds = """
     device $%s
-    probe
     record %s
     %s""" % (self.record_device, self.record_log, cmds)
             
@@ -443,7 +442,6 @@ class LCTLInterface:
     def recover(self, dev_name, new_conn):
         cmds = """
     device $%s
-    probe
     recover %s""" %(dev_name, new_conn)
         self.run(cmds)
                 
index 7719186..3b2250f 100644 (file)
@@ -54,6 +54,7 @@
 #include <linux/list.h>
 #undef __KERNEL__
 
+#include <linux/obd_class.h>
 #include <portals/ptlctl.h>
 #include "parser.h"
 #include <stdio.h>
@@ -70,13 +71,14 @@ struct timeval prev_time;
 #endif
 
 static int jt_recording;
-static uint64_t conn_cookie = -1;
 static char rawbuf[8192];
 static char *buf = rawbuf;
 static int max = sizeof(rawbuf);
 
 static int thread;
 
+static uint32_t cur_device = MAX_OBD_DEVICES;
+
 union lsm_buffer {
         char                 space [4096];
         struct lov_stripe_md lsm;
@@ -84,18 +86,13 @@ union lsm_buffer {
 
 static int l2_ioctl(int dev_id, int opc, void *buf)
 {
-//        if (jt_recording) {
-//                struct obd_ioctl_data *data = buf;
-//                data->ioc_command = opc;
-//                opc = OBD_IOC_DORECORD;
-//        }
         return l_ioctl(dev_id, opc, buf);
 }
 
 #define IOC_INIT(data)                                                  \
 do {                                                                    \
         memset(&data, 0, sizeof(data));                                 \
-        data.ioc_cookie = conn_cookie;                                  \
+        data.ioc_dev = cur_device;                                      \
 } while (0)
 
 #define IOC_PACK(func, data)                                            \
@@ -422,6 +419,7 @@ static int get_verbose(char *func, const char *arg)
 
 int do_disconnect(char *func, int verbose)
 {
+        cur_device = MAX_OBD_DEVICES;
         return 0;
 }
 
@@ -522,60 +520,36 @@ static void shmem_snap(int n)
 
 extern command_t cmdlist[];
 
-static int do_device(char *func, int dev)
+static int do_device(char *func, char *devname)
 {
         struct obd_ioctl_data data;
+        int dev;
 
         memset(&data, 0, sizeof(data));
 
-        data.ioc_dev = dev;
+        dev = parse_devname(func, devname);
+        if (dev < 0)
+                return -1;
 
-        IOC_PACK(func, data);
-        return l2_ioctl(OBD_DEV_ID, OBD_IOC_DEVICE, buf);
+        cur_device = dev;
+        return 0;
 }
 
 int jt_obd_device(int argc, char **argv)
 {
-        int rc, dev;
+        int rc;
         do_disconnect(argv[0], 1);
 
         if (argc != 2)
                 return CMD_HELP;
 
-        dev = parse_devname(argv[0], argv[1]);
-        if (dev < 0)
-                return -1;
-
-        rc = do_device(argv[0], dev);
-        if (rc < 0)
-                fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
-                        strerror(rc = errno));
-
+        rc = do_device(argv[0], argv[1]);
         return rc;
 }
 
 int jt_obd_connect(int argc, char **argv)
 {
-        struct obd_ioctl_data data;
-        int rc;
-
-        IOC_INIT(data);
-
-        do_disconnect(argv[0], 1);
-
-        /* XXX TODO: implement timeout per lctl usage for probe */
-        if (argc != 1)
-                return CMD_HELP;
-
-        IOC_PACK(argv[0], data);
-        rc = l2_ioctl(OBD_DEV_ID, OBD_IOC_CONNECT, buf);
-        IOC_UNPACK(argv[0], data);
-        if (rc < 0)
-                fprintf(stderr, "error: %s: OBD_IOC_CONNECT %s\n",
-                        jt_cmdname(argv[0]), strerror(rc = errno));
-        else
-                conn_cookie = data.ioc_cookie;
-        return rc;
+        return 0;
 }
 
 int jt_obd_disconnect(int argc, char **argv)
@@ -583,28 +557,18 @@ int jt_obd_disconnect(int argc, char **argv)
         if (argc != 1)
                 return CMD_HELP;
 
-        if (conn_cookie == -1)
-                return 0;
-
         return do_disconnect(argv[0], 0);
 }
 
 int jt_opt_device(int argc, char **argv)
 {
-        char *arg2[3];
         int ret;
         int rc;
 
         if (argc < 3)
                 return CMD_HELP;
 
-        rc = do_device("device", parse_devname(argv[0], argv[1]));
-
-        if (!rc) {
-                arg2[0] = "connect";
-                arg2[1] = NULL;
-                rc = jt_obd_connect(1, arg2);
-        }
+        rc = do_device("device", argv[1]);
 
         if (!rc)
                 rc = Parser_execarg(argc - 2, argv + 2, cmdlist);
@@ -792,7 +756,6 @@ int jt_get_version(int argc, char **argv)
 
         memset(buf, 0, sizeof(buf));
         data->ioc_version = OBD_IOCTL_VERSION;
-        data->ioc_cookie = conn_cookie;
         data->ioc_inllen1 = sizeof(buf) - size_round(sizeof(*data));
         data->ioc_len = obd_ioctl_packlen(data);
 
@@ -819,7 +782,6 @@ int jt_obd_list(int argc, char **argv)
 
         memset(buf, 0, sizeof(buf));
         data->ioc_version = OBD_IOCTL_VERSION;
-        data->ioc_cookie = conn_cookie;
         data->ioc_inllen1 = sizeof(buf) - size_round(sizeof(*data));
         data->ioc_len = obd_ioctl_packlen(data);
 
index 461a8c0..b948c45 100644 (file)
@@ -38,7 +38,7 @@ obdio_iocinit (struct obdio_conn *conn)
 {
         memset (&conn->oc_data, 0, sizeof (conn->oc_data));
         conn->oc_data.ioc_version = OBD_IOCTL_VERSION;
-        conn->oc_data.ioc_cookie = conn->oc_conn_cookie;
+        conn->oc_data.ioc_dev = conn->oc_device;
         conn->oc_data.ioc_len = sizeof (conn->oc_data);
 }
 
@@ -74,7 +74,6 @@ struct obdio_conn *
 obdio_connect (int device)
 {
         struct obdio_conn  *conn;
-        int                 rc;
 
         conn = malloc (sizeof (*conn));
         if (conn == NULL) {
@@ -90,24 +89,7 @@ obdio_connect (int device)
                 goto failed;
         }
 
-        obdio_iocinit (conn);
-        conn->oc_data.ioc_dev = device;
-        rc = obdio_ioctl (conn, OBD_IOC_DEVICE);
-        if (rc != 0) {
-                fprintf (stderr, "obdio_connect: Can't set device %d: %s\n",
-                         device, strerror (errno));
-                goto failed;
-        }
-
-        obdio_iocinit (conn);
-        rc = obdio_ioctl (conn, OBD_IOC_CONNECT);
-        if (rc != 0) {
-                fprintf(stderr, "obdio_connect: Can't connect to device "
-                        "%d: %s\n", device, strerror (errno));
-                goto failed;
-        }
-
-        conn->oc_conn_cookie = conn->oc_data.ioc_cookie;
+        conn->oc_device = device;
         return (conn);
 
  failed:
index b2ec6b6..51584a1 100644 (file)
@@ -34,7 +34,7 @@
 
 struct obdio_conn {
         int                    oc_fd;
-        uint64_t               oc_conn_cookie;
+        uint32_t               oc_device;
         struct obd_ioctl_data  oc_data;
         char                   oc_buffer[8192];
 };