X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=lustre%2Fliblustre%2Ftests%2Fecho_test.c;h=6e609b4e02073f3902b2bcc45a6187bed8356320;hb=7af2428511c286788d9c73c436cb43d6f791821f;hp=139a10a3865250423d3e107b3c5f67dd59aafb9c;hpb=9f59ef764e80542d82f3b78902615124ddac1020;p=fs%2Flustre-release.git diff --git a/lustre/liblustre/tests/echo_test.c b/lustre/liblustre/tests/echo_test.c index 139a10a..6e609b4 100644 --- a/lustre/liblustre/tests/echo_test.c +++ b/lustre/liblustre/tests/echo_test.c @@ -1,113 +1,85 @@ /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*- * vim:expandtab:shiftwidth=8:tabstop=8: + * + * GPL HEADER START + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 only, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License version 2 for more details (a copy is included + * in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU General Public License + * version 2 along with this program; If not, see + * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf + * + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + * + * GPL HEADER END + */ +/* + * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved. + * Use is subject to license terms. + */ +/* + * This file is part of Lustre, http://www.lustre.org/ + * Lustre is a trademark of Sun Microsystems, Inc. + * + * lustre/liblustre/tests/echo_test.c + * + * Lustre Light user test program */ -#include -#include -#include -#include - -#include /* needed for parse_dump */ - #include -#include -#include -#include +#include +#include +#include #define LIBLUSTRE_TEST 1 #include "../utils/lctl.c" -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); - -void *inter_module_get(char *arg) -{ - if (!strcmp(arg, "tcpnal_ni")) - return &tcpnal_ni; - else if (!strcmp(arg, "ldlm_cli_cancel_unused")) - return ldlm_cli_cancel_unused; - else if (!strcmp(arg, "ldlm_namespace_cleanup")) - return ldlm_namespace_cleanup; - else if (!strcmp(arg, "ldlm_replay_locks")) - return ldlm_replay_locks; - else - return NULL; -} - -/* XXX move to proper place */ -char *portals_nid2str(int nal, ptl_nid_t nid, char *str) -{ - switch(nal){ - case TCPNAL: - /* userspace NAL */ - case SOCKNAL: - 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: - snprintf(str, PTL_NALFMT_SIZE - 1, "%u:%u", - (__u32)(nid >> 32), (__u32)nid); - break; - default: - 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; - ptl_pid_t port; - int count; - int size; -}; +#include "../lutil.h" -struct task_struct *current; -int -libcfs_nal_cmd(struct portals_cfg *pcfg) +#ifdef CRAY_XT3 +int _sysio_lustre_init(void) { - CERROR("empty function!!!\n"); + /* + * This is an aweful HACK. Basically the problem is on + * Catamount, the build system links in liblustre.a to + * all the test executables, and at this point its not + * clear how to modify the build system to prevent this + * from happening. So providing our own call to + * _sysio_lustre_init() that does nothing, prevents + * liblustre.a from initializing. + * + * Why is liblustre.a initializing a problem anyway. Well + * this main() in this module calls init_obdclass(), as + * well as the llite_lib.c's _sysio_lustre_init(). Two + * calls to init_obdclass() cause an assertion. Secondly + * it doesn't even logically make sense, this is module + * does not need lustre file system functionality, it's + * just the echo_tester. + * + */ + /*lprintf("--> THIS OVERRIDES liblustre.a INITIALIZATION <--\n");*/ return 0; } +#endif -int init_current(int argc, char **argv) -{ - current = malloc(sizeof(*current)); - strncpy(current->comm, argv[0], sizeof(current->comm)); - current->pid = getpid(); - return 0; -} - -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); - } - return rc; -} extern int class_handle_ioctl(unsigned int cmd, unsigned long arg); -int liblustre_ioctl(int dev_id, unsigned int opc, void *ptr) +static int liblustre_ioctl(int dev_id, unsigned int opc, void *ptr) { int rc = -EINVAL; @@ -125,15 +97,6 @@ int liblustre_ioctl(int dev_id, unsigned int opc, void *ptr) return rc; } -static void generate_random_uuid(unsigned char uuid_out[16]) -{ - int *arr = (int*)uuid_out; - int i; - - for (i = 0; i < sizeof(uuid_out)/sizeof(int); i++) - arr[i] = rand(); -} - static char *echo_server_nid = NULL; static char *echo_server_ostname = "obd1"; static char *osc_dev_name = "OSC_DEV_NAME"; @@ -141,84 +104,81 @@ static char *echo_dev_name = "ECHO_CLIENT_DEV_NAME"; static int connect_echo_client(void) { - struct lustre_cfg lcfg; - ptl_nid_t nid; + struct lustre_cfg *lcfg; + struct lustre_cfg_bufs bufs; + lnet_nid_t nid; char *peer = "ECHO_PEER_NID"; class_uuid_t osc_uuid, echo_uuid; struct obd_uuid osc_uuid_str, echo_uuid_str; - int nal, err; + int err; ENTRY; - generate_random_uuid(osc_uuid); + ll_generate_random_uuid(osc_uuid); class_uuid_unparse(osc_uuid, &osc_uuid_str); - generate_random_uuid(echo_uuid); + ll_generate_random_uuid(echo_uuid); class_uuid_unparse(echo_uuid, &echo_uuid_str); - if (ptl_parse_nid(&nid, echo_server_nid)) { + nid = libcfs_str2nid(echo_server_nid); + if (nid == LNET_NID_ANY) { CERROR("Can't parse NID %s\n", echo_server_nid); RETURN(-EINVAL); } - nal = ptl_name2nal("tcp"); - if (nal <= 0) { - CERROR("Can't parse NAL tcp\n"); - RETURN(-EINVAL); - } - /* 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); + /* add uuid */ + 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; + 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); + /* attach osc */ + lustre_cfg_bufs_reset(&bufs, osc_dev_name); + lustre_cfg_bufs_set_string(&bufs, 1, 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); @@ -229,37 +189,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); @@ -270,9 +237,11 @@ static int disconnect_echo_client(void) static void usage(const char *s) { - printf("Usage: %s -s ost_host_name [-n ost_name]\n", s); + printf("Usage: %s -s ost_host_name [-n ost_name] [-x lctl_options ...]\n", s); printf(" ost_host_name: the host name of echo server\n"); printf(" ost_name: ost name, default is \"obd1\"\n"); + printf(" lctl_options: options to pass to lctl.\n"); + printf(" (e.g. -x --device 1 test_getattr 10000 -5)\n"); } extern int time_ptlwait1; @@ -282,8 +251,13 @@ extern int time_ptlselect; int main(int argc, char **argv) { int c, rc; + int xindex = -1; /* index of -x option */ - while ((c = getopt(argc, argv, "s:n:")) != -1) { + /* loop until all options are consumed or we hit + * a -x option + */ + while ((c = getopt(argc, argv, "s:n:x:")) != -1 && + xindex == -1) { switch (c) { case 's': echo_server_nid = optarg; @@ -291,13 +265,20 @@ int main(int argc, char **argv) case 'n': echo_server_ostname = optarg; break; + case 'x': + xindex = optind-1; + break; default: usage(argv[0]); return 1; } } - if (optind != argc) + /* + * Only warn with usage() if the -x option isn't specificed + * because when using -x this check is not valid. + */ + if (optind != argc && xindex == -1) usage(argv[0]); if (!echo_server_nid) { @@ -305,17 +286,15 @@ int main(int argc, char **argv) return 1; } - srand(time(NULL)); + libcfs_debug = 0; + libcfs_subsystem_debug = 0; - tcpnal_mynid = rand(); -#if 1 - portal_debug = 0; - portal_subsystem_debug = 0; -#endif + liblustre_init_random(); - if (init_current(argc, argv) || + if (liblustre_init_current(argv[0]) || init_obdclass() || init_lib_portals() || ptlrpc_init() || + lmv_init() || mdc_init() || lov_init() || osc_init() || @@ -330,7 +309,21 @@ int main(int argc, char **argv) set_ioc_handler(liblustre_ioctl); - rc = lctl_main(1, &argv[0]); + + /* + * If the -x option is not specified pass no args to lctl + * otherwise pass all the options after the "-x" to lctl + * + * HACK: in the case when the -x option is specified + * lctl sees argv[0] == "-x" and not the real argv[0] seen + * in this function. If that is a problem, a mapping will + * have to be done to fix that. However for normal functioning + * it seems to be irrelavant + */ + if( xindex == -1 ) + rc = lctl_main(1, &argv[0]); + else + rc = lctl_main(argc-xindex+1, &argv[xindex-1]); rc |= disconnect_echo_client();