Whamcloud - gitweb
* new network config snapshot
[fs/lustre-release.git] / lustre / liblustre / tests / echo_test.c
index ca2caaa..ef54cd2 100644 (file)
@@ -3,6 +3,7 @@
 #include <sys/socket.h>
 #include <arpa/inet.h>
 
+#include <portals/api-support.h> /* needed for ptpctl.h */
 #include <portals/ptlctl.h>    /* needed for parse_dump */
 
 
@@ -10,6 +11,7 @@
 #include <linux/obd.h>
 #include <linux/obd_class.h>
 #include <procbridge.h>
+#include <linux/obd_ost.h>
 
 #define LIBLUSTRE_TEST 1
 #include "../utils/lctl.c"
@@ -18,14 +20,11 @@ struct ldlm_namespace;
 struct ldlm_res_id;
 struct obd_import;
 
-unsigned int portal_subsystem_debug = ~0 - (S_PORTALS | S_QSWNAL | S_SOCKNAL |
-                                            S_GMNAL | S_IBNAL);
-                                                                                                                        
+unsigned int portal_subsystem_debug = ~0 - (S_PORTALS | S_NAL);
+
 void *inter_module_get(char *arg)
 {
-        if (!strcmp(arg, "tcpnal_ni"))
-                return &tcpnal_ni;
-        else if (!strcmp(arg, "ldlm_cli_cancel_unused"))
+        if (!strcmp(arg, "ldlm_cli_cancel_unused"))
                 return ldlm_cli_cancel_unused;
         else if (!strcmp(arg, "ldlm_namespace_cleanup"))
                 return ldlm_namespace_cleanup;
@@ -36,29 +35,31 @@ void *inter_module_get(char *arg)
 }
 
 /* XXX move to proper place */
+#error
 char *portals_nid2str(int nal, ptl_nid_t nid, char *str)
 {
         switch(nal){
         case TCPNAL:
                 /* userspace NAL */
         case SOCKNAL:
-                sprintf(str, "%u:%d.%d.%d.%d", (__u32)(nid >> 32),
-                        HIPQUAD(nid));
+                snprintf(str, PTL_NALFMT_SIZE - 1, "%u:%u.%u.%u.%u",
+                         (__u32)(nid >> 32), HIPQUAD(nid));
                 break;
         case QSWNAL:
         case GMNAL:
         case IBNAL:
         case SCIMACNAL:
-                sprintf(str, "%u:%u", (__u32)(nid >> 32), (__u32)nid);
+                snprintf(str, PTL_NALFMT_SIZE - 1, "%u:%u",
+                         (__u32)(nid >> 32), (__u32)nid);
                 break;
         default:
-                return NULL;
+                snprintf(str, PTL_NALFMT_SIZE - 1, "?%d? %llx",
+                         nal, (long long)nid);
+                break;
         }
         return str;
 }
 
-ptl_handle_ni_t         tcpnal_ni;
-
 struct pingcli_args {
         ptl_nid_t mynid;
         ptl_nid_t nid;
@@ -69,11 +70,28 @@ struct pingcli_args {
 
 struct task_struct *current;
 
+/* portals interfaces */
 int
-libcfs_nal_cmd(struct portals_cfg *pcfg)
+kportal_nal_cmd(struct portals_cfg *pcfg)
 {
+#if 0
+        __u32 nal = pcfg->pcfg_nal;
+        int rc = -EINVAL;
+
+        ENTRY;
+
+        down(&nal_cmd_sem);
+        if (nal > 0 && nal <= NAL_MAX_NR && nal_cmd[nal].nch_handler) {
+                CDEBUG(D_IOCTL, "calling handler nal: %d, cmd: %d\n", nal, 
+                       pcfg->pcfg_command);
+                rc = nal_cmd[nal].nch_handler(pcfg, nal_cmd[nal].nch_private);
+        }
+        up(&nal_cmd_sem);
+        RETURN(rc);
+#else
         CERROR("empty function!!!\n");
         return 0;
+#endif
 }
 
 int init_current(int argc, char **argv)
@@ -88,14 +106,11 @@ ptl_nid_t tcpnal_mynid;
 
 int init_lib_portals()
 {
-       int max_interfaces;
         int rc;
 
-        rc = PtlInit(&max_interfaces);
-        if (rc != 0) {
-                CERROR("ksocknal: PtlNIInit failed: error %d\n", rc);
-                RETURN (rc);
-        }
+        rc = PtlInit();
+        if (rc != PTL_OK)
+                CERROR("PtlInit failed: error %d\n", rc);
         return rc;
 }
 
@@ -135,7 +150,8 @@ static char *echo_dev_name = "ECHO_CLIENT_DEV_NAME";
 
 static int connect_echo_client(void)
 {
-       struct lustre_cfg lcfg;
+       struct lustre_cfg *lcfg;
+        struct lustre_cfg_bufs bufs;
        ptl_nid_t nid;
        char *peer = "ECHO_PEER_NID";
        class_uuid_t osc_uuid, echo_uuid;
@@ -159,60 +175,60 @@ static int connect_echo_client(void)
         }
 
        /* add uuid */
-        LCFG_INIT(lcfg, LCFG_ADD_UUID, NULL);
-        lcfg.lcfg_nid = nid;
-        lcfg.lcfg_inllen1 = strlen(peer) + 1;
-        lcfg.lcfg_inlbuf1 = peer;
-        lcfg.lcfg_nal = nal;
-        err = class_process_config(&lcfg);
+        lustre_cfg_bufs_reset(&bufs, NULL);
+        lustre_cfg_bufs_set_string(&bufs, 1, peer);
+        lcfg = lustre_cfg_new(LCFG_ADD_UUID, &bufs);
+        lcfg->lcfg_nid = nid;
+        lcfg->lcfg_nal = nal;
+        err = class_process_config(lcfg);
+        lustre_cfg_free(lcfg);
         if (err < 0) {
                CERROR("failed add_uuid\n");
                 RETURN(-EINVAL);
        }
 
        /* attach osc */
-        LCFG_INIT(lcfg, LCFG_ATTACH, osc_dev_name);
-        lcfg.lcfg_inlbuf1 = "osc";
-        lcfg.lcfg_inllen1 = strlen(lcfg.lcfg_inlbuf1) + 1;
-        lcfg.lcfg_inlbuf2 = osc_uuid_str.uuid;
-        lcfg.lcfg_inllen2 = strlen(lcfg.lcfg_inlbuf2) + 1;
-        err = class_process_config(&lcfg);
+        lustre_cfg_bufs_reset(&bufs, LUSTRE_OSC_NAME);
+        lustre_cfg_bufs_set_string(&bufs, 2, osc_uuid_str.uuid);
+        lcfg = lustre_cfg_new(LCFG_ATTACH, &bufs);
+        err = class_process_config(lcfg);
+        lustre_cfg_free(lcfg);
         if (err < 0) {
                CERROR("failed attach osc\n");
                 RETURN(-EINVAL);
        }
 
        /* setup osc */
-        LCFG_INIT(lcfg, LCFG_SETUP, osc_dev_name);
-        lcfg.lcfg_inlbuf1 = echo_server_ostname;
-        lcfg.lcfg_inllen1 = strlen(lcfg.lcfg_inlbuf1) + 1;
-        lcfg.lcfg_inlbuf2 = peer;
-        lcfg.lcfg_inllen2 = strlen(lcfg.lcfg_inlbuf2) + 1;
-        err = class_process_config(&lcfg);
+        lustre_cfg_bufs_reset(&bufs, osc_dev_name);
+        lustre_cfg_bufs_set_string(&bufs, 1, echo_server_ostname);
+        lustre_cfg_bufs_set_string(&bufs, 2, peer);
+        lcfg = lustre_cfg_new(LCFG_SETUP, &bufs);
+        err = class_process_config(lcfg);
+        lustre_cfg_free(lcfg);
         if (err < 0) {
                CERROR("failed setup osc\n");
                 RETURN(-EINVAL);
        }
 
        /* attach echo_client */
-        LCFG_INIT(lcfg, LCFG_ATTACH, echo_dev_name);
-        lcfg.lcfg_inlbuf1 = "echo_client";
-        lcfg.lcfg_inllen1 = strlen(lcfg.lcfg_inlbuf1) + 1;
-        lcfg.lcfg_inlbuf2 = echo_uuid_str.uuid;
-        lcfg.lcfg_inllen2 = strlen(lcfg.lcfg_inlbuf2) + 1;
-        err = class_process_config(&lcfg);
+        lustre_cfg_bufs_reset(&bufs, echo_dev_name);
+        lustre_cfg_bufs_set_string(&bufs, 1, "echo_client");
+        lustre_cfg_bufs_set_string(&bufs, 2, echo_uuid_str.uuid);
+        lcfg = lustre_cfg_new(LCFG_ATTACH, &bufs);
+        err = class_process_config(lcfg);
+        lustre_cfg_free(lcfg);
         if (err < 0) {
                CERROR("failed attach echo_client\n");
                 RETURN(-EINVAL);
        }
 
        /* setup echo_client */
-        LCFG_INIT(lcfg, LCFG_SETUP, echo_dev_name);
-        lcfg.lcfg_inlbuf1 = osc_dev_name;
-        lcfg.lcfg_inllen1 = strlen(lcfg.lcfg_inlbuf1) + 1;
-        lcfg.lcfg_inlbuf2 = NULL;
-        lcfg.lcfg_inllen2 = 0;
-        err = class_process_config(&lcfg);
+        lustre_cfg_bufs_reset(&bufs, echo_dev_name);
+        lustre_cfg_bufs_set_string(&bufs, 1, osc_dev_name);
+        lustre_cfg_bufs_set_string(&bufs, 2, NULL);
+        lcfg = lustre_cfg_new(LCFG_SETUP, &bufs);
+        err = class_process_config(lcfg);
+        lustre_cfg_free(lcfg);
         if (err < 0) {
                CERROR("failed setup echo_client\n");
                 RETURN(-EINVAL);
@@ -223,37 +239,44 @@ static int connect_echo_client(void)
 
 static int disconnect_echo_client(void)
 {
-       struct lustre_cfg lcfg;
+       struct lustre_cfg_bufs bufs;
+        struct lustre_cfg *lcfg = NULL;
        int err;
        ENTRY;
 
        /* cleanup echo_client */
-        LCFG_INIT(lcfg, LCFG_CLEANUP, echo_dev_name);
-        err = class_process_config(&lcfg);
+        lustre_cfg_bufs_reset(&bufs, echo_dev_name);
+        lcfg = lustre_cfg_new(LCFG_CLEANUP, &bufs);
+        err = class_process_config(lcfg);
         if (err < 0) {
+                lustre_cfg_free(lcfg);
                CERROR("failed cleanup echo_client\n");
                 RETURN(-EINVAL);
        }
 
        /* detach echo_client */
-        LCFG_INIT(lcfg, LCFG_DETACH, echo_dev_name);
-        err = class_process_config(&lcfg);
+        lcfg->lcfg_command = LCFG_DETACH;
+        err = class_process_config(lcfg);
+        lustre_cfg_free(lcfg);
         if (err < 0) {
                CERROR("failed detach echo_client\n");
                 RETURN(-EINVAL);
        }
 
        /* cleanup osc */
-        LCFG_INIT(lcfg, LCFG_CLEANUP, osc_dev_name);
-        err = class_process_config(&lcfg);
+        lustre_cfg_bufs_reset(&bufs, osc_dev_name);
+        lcfg = lustre_cfg_new(LCFG_CLEANUP, &bufs);
+        err = class_process_config(lcfg);
         if (err < 0) {
+                lustre_cfg_free(lcfg);
                CERROR("failed cleanup osc device\n");
                 RETURN(-EINVAL);
        }
 
        /* detach osc */
-        LCFG_INIT(lcfg, LCFG_DETACH, osc_dev_name);
-        err = class_process_config(&lcfg);
+        lcfg->lcfg_command = LCFG_DETACH;
+        err = class_process_config(lcfg);
+        lustre_cfg_free(lcfg);
         if (err < 0) {
                CERROR("failed detach osc device\n");
                 RETURN(-EINVAL);
@@ -310,6 +333,7 @@ int main(int argc, char **argv)
         if (init_current(argc, argv) ||
            init_obdclass() || init_lib_portals() ||
            ptlrpc_init() ||
+           ldlm_init() ||
            mdc_init() ||
            lov_init() ||
            osc_init() ||