Whamcloud - gitweb
- reorganize so same functions are used by both obdctl and lctl
authorrread <rread>
Wed, 7 Aug 2002 23:28:48 +0000 (23:28 +0000)
committerrread <rread>
Wed, 7 Aug 2002 23:28:48 +0000 (23:28 +0000)
- obdctl functions moved to obd.c
- removed libxml2 dependency

lustre/configure.in
lustre/utils/Makefile.am
lustre/utils/debug.c [deleted file]
lustre/utils/lctl.c
lustre/utils/lctl.h [deleted file]
lustre/utils/network.c [deleted file]
lustre/utils/obd.c [moved from lustre/utils/device.c with 52% similarity]
lustre/utils/obdctl.c
lustre/utils/obdctl.h [new file with mode: 0644]
lustre/utils/parser.c

index b7b4155..9813df7 100644 (file)
@@ -15,15 +15,6 @@ AC_PROG_RANLIB
 # 
 # Check for required packages
 
-# AC_PATH_PROG([XML2_CONFIG], [xml2-config], [],)
-# if test -z "$XML2_CONFIG"; then
-#      AC_MSG_ERROR([xml2-config not found; libxml2-dev libraries must be installed.])
-# fi
-# XML2_CFLAGS=$($XML2_CONFIG --cflags)
-# XML2_LIBS=$($XML2_CONFIG --libs)
-# AC_SUBST(XML2_CFLAGS)
-# AC_SUBST(XML2_LIBS)
-
 # this doesn't seem to work on older autoconf
 # AC_CHECK_LIB(readline, readline,,)
 
index 0320ff2..9778767 100644 (file)
@@ -1,14 +1,14 @@
 # Administration utilities Makefile
 DEFS=
 
-CFLAGS:=-g -O2 -I. -I/usr/include/libxml2 -I/usr/include/glib-1.2 -I$(PORTALS)/include \
--I/usr/lib/glib/include -I$(srcdir)/../include -Wall
+CFLAGS:=-g -O2 -I. -I$(PORTALS)/include  -I$(srcdir)/../include -Wall\
+ -L$(PORTALS)/linux/utils
 KFLAGS:=
 CPPFLAGS = $(HAVE_LIBREADLINE)
-obdctl_LDADD := $(LIBREADLINE) -lxml2 # -lefence
-lctl_LDADD := $(LIBREADLINE)
+obdctl_LDADD := $(LIBREADLINE)
+lctl_LDADD := $(LIBREADLINE) -lptlctl
 sbin_PROGRAMS = lctl obdctl
-obdctl_SOURCES = parser.c obdctl.c parser.h
-lctl_SOURCES = parser.c network.c device.c debug.c lctl.c lctl.h parser.h
+obdctl_SOURCES = parser.c obdctl.c obd.c parser.h
+lctl_SOURCES = parser.c obd.c lctl.c lctl.h parser.h
 
 include $(top_srcdir)/Rules
diff --git a/lustre/utils/debug.c b/lustre/utils/debug.c
deleted file mode 100644 (file)
index e87a30c..0000000
+++ /dev/null
@@ -1,445 +0,0 @@
-/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
- * vim:expandtab:shiftwidth=8:tabstop=8:
- *
- * Copyright (C) 2001, 2002 Cluster File Systems, Inc.
- *
- *   This file is part of Portals, http://www.sf.net/projects/lustre/
- *
- *   Portals is free software; you can redistribute it and/or
- *   modify it under the terms of version 2 of the GNU General Public
- *   License as published by the Free Software Foundation.
- *
- *   Portals 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 for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with Portals; if not, write to the Free Software
- *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- * Some day I'll split all of this functionality into a cfs_debug module
- * of its own.  That day is not today.
- *
- */
-
-#include <stdio.h>
-#include <netdb.h>
-#include <stdlib.h>
-#include <string.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <unistd.h>
-#include <time.h>
-
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <sys/ioctl.h>
-#include <sys/stat.h>
-#include <sys/mman.h>
-#include <asm/atomic.h>
-#include <linux/module.h>
-#include <portals/api-support.h>
-
-#include "lctl.h"
-
-/* current debug flag
- */
-int lctl_debug;
-
-static char rawbuf[8192];
-static char *buf = rawbuf;
-static int max = 8192;
-static int g_pfd = -1;
-static int subsystem_array[1 << 8];
-static int debug_mask = ~0;
-
-static const char *portal_debug_subsystems[] =
-        {"undefined", "mdc", "mds", "osc", "ost", "class", "obdfs", "llite",
-         "rpc", "ext2obd", "portals", "socknal", "qswnal", "pinger", "filter",
-         "obdtrace", "echo", "ldlm", "lov", "gmnal", "router", NULL};
-static const char *portal_debug_masks[] =
-        {"trace", "inode", "super", "ext2", "malloc", "cache", "info", "ioctl",
-         "blocks", "net", "warning", "buffs", "other", "dentry", "portals",
-         "page", "dlmtrace", NULL};
-
-int debug_setup(int argc, char **argv) {
-        memset(subsystem_array, 1, sizeof(subsystem_array));
-        return 0;
-}
-
-static int do_debug_mask(char *name, int enable) {
-        int found = 0, i;
-
-        for (i = 0; portal_debug_subsystems[i] != NULL; i++) {
-                if (strcasecmp(name, portal_debug_subsystems[i]) == 0 ||
-                    strcasecmp(name, "all_subs") == 0) {
-                        fprintf(stderr, "%s output from subsystem \"%s\"\n",
-                                enable ? "Enabling" : "Disabling",
-                                portal_debug_subsystems[i]);
-                        subsystem_array[i] = enable;
-                        found = 1;
-                }
-        }
-        for (i = 0; portal_debug_masks[i] != NULL; i++) {
-                if (strcasecmp(name, portal_debug_masks[i]) == 0 ||
-                    strcasecmp(name, "all_types") == 0) {
-                        fprintf(stderr, "%s output of type \"%s\"\n",
-                                enable ? "Enabling" : "Disabling",
-                                portal_debug_masks[i]);
-                        if (enable)
-                                debug_mask |= (1 << i);
-                        else
-                                debug_mask &= ~(1 << i);
-                        found = 1;
-                }
-        }
-
-        return found;
-}
-
-/* if 'raw' is true, don't strip the debug information from the
- * front of the lines */
-static void dump_buffer(FILE *fd, char *buf, int size, int raw) {
-        char *p, *z;
-        unsigned long subsystem, debug, dropped = 0, kept = 0;
-        int max_sub, max_type;
-
-        for (max_sub = 0; portal_debug_subsystems[max_sub] != NULL; max_sub++)
-                ;
-        for (max_type = 0; portal_debug_masks[max_type] != NULL; max_type++)
-                ;
-
-        while (size) {
-                p = memchr(buf, '\n', size);
-                if (!p)
-                        break;
-                subsystem = strtoul(buf, &z, 16);
-                debug = strtoul(z + 1, &z, 16);
-
-                z++;
-                /* for some reason %*s isn't working. */
-                *p = '\0';
-                if (subsystem < max_sub &&
-                    subsystem_array[subsystem] &&
-                    (!debug || (debug_mask & debug))) {
-                        if (raw)
-                                fprintf(fd, "%s\n", buf);
-                        else
-                                fprintf(fd, "%s\n", z);
-                        //printf("%s\n", buf);
-                        kept++;
-                } else {
-                        //fprintf(stderr, "dropping line (%lx:%lx): %s\n", subsystem, debug, buf);
-                        dropped++;
-                }
-                *p = '\n';
-                p++;
-                size -= (p - buf);
-                buf = p;
-        }
-
-        fprintf(stderr, "Debug log: %lu lines, %lu kept, %lu dropped.\n",
-                dropped + kept, kept, dropped);
-}
-
-int jt_debug_kernel(int argc, char **argv) {
-        int rc, raw = 0;
-        FILE *fd = stdout;
-        const int databuf_size = (6 << 20);
-        struct portal_ioctl_data data, *newdata;
-        char *databuf = NULL;
-
-        PORTALS_CONNECT;
-
-        if (argc > 3)
-                return CMD_HELP;
-
-        if (argc > 1) {
-                fd = fopen(argv[1], "w");
-                if (fd == NULL) {
-                        fprintf(stderr, "fopen(%s) failed: %s\n", argv[1],
-                                strerror(errno));
-                        return -1;
-                }
-        }
-        if (argc > 2)
-                raw = atoi(argv[2]);
-
-        databuf = malloc(databuf_size);
-        if (!databuf) {
-                fprintf(stderr, "No memory for buffer.\n");
-                goto out;
-        }
-
-        memset(&data, 0, sizeof(data));
-        data.ioc_plen1 = databuf_size;
-        data.ioc_pbuf1 = databuf;
-
-        if (portal_ioctl_pack(&data, &buf, max) != 0) {
-                fprintf(stderr, "portal_ioctl_pack failed.\n");
-                goto out;
-        }
-
-        rc = ioctl(g_pfd, IOC_PORTAL_GET_DEBUG, buf);
-        if (rc) {
-                fprintf(stderr, "IOC_PORTAL_GET_DEBUG failed: %s\n",
-                        strerror(errno));
-                goto out;
-        }
-
-        newdata = (struct portal_ioctl_data *)buf;
-        if (newdata->ioc_size > 0)
-                dump_buffer(fd, databuf, newdata->ioc_size, raw);
-        else
-                fprintf(stderr, "No data in the debug buffer.\n");
-
-out:
-        if (databuf)
-                free(databuf);
-        if (fd != stdout)
-                fclose(fd);
-        return 0;
-}
-
-int jt_debug_file(int argc, char **argv) {
-        int rc, fd = -1, raw = 0;
-        FILE *output = stdout;
-        char *databuf = NULL;
-        struct stat statbuf;
-
-        if (argc > 4 || argc < 2)
-                return CMD_HELP;
-
-        fd = open(argv[1], O_RDONLY);
-        if (fd < 0) {
-                fprintf(stderr, "fopen(%s) failed: %s\n", argv[1],
-                        strerror(errno));
-                return -1;
-        }
-        rc = fstat(fd, &statbuf);
-        if (rc < 0) {
-                fprintf(stderr, "fstat failed: %s\n", strerror(errno));
-                goto out;
-        }
-
-        if (argc == 3) {
-                output = fopen(argv[2], "w");
-                if (output == NULL) {
-                        fprintf(stderr, "fopen(%s) failed: %s\n", argv[2],
-                                strerror(errno));
-                        goto out;
-                }
-        }
-
-        if (argc == 4)
-                raw = atoi(argv[3]);
-
-        databuf = mmap(NULL, statbuf.st_size, PROT_READ | PROT_WRITE,
-                       MAP_PRIVATE, fd, 0);
-        if (databuf == NULL) {
-                fprintf(stderr, "mmap failed: %s\n", strerror(errno));
-                goto out;
-        }
-
-        dump_buffer(output, databuf, statbuf.st_size, raw);
-
-out:
-        if (databuf)
-                munmap(databuf, statbuf.st_size);
-        if (output != stdout)
-                fclose(output);
-        if (fd > 0)
-                close(fd);
-        return 0;
-}
-
-int jt_debug_clear(int argc, char **argv) {
-        int rc;
-        struct portal_ioctl_data data;
-
-        PORTALS_CONNECT;
-        if (argc != 1)
-                return CMD_HELP;
-
-        memset(&data, 0, sizeof(data));
-        if (portal_ioctl_pack(&data, &buf, max) != 0) {
-                fprintf(stderr, "portal_ioctl_pack failed.\n");
-                return -1;
-        }
-
-        rc = ioctl(g_pfd, IOC_PORTAL_CLEAR_DEBUG, buf);
-        if (rc) {
-                fprintf(stderr, "IOC_PORTAL_CLEAR_DEBUG failed: %s\n",
-                        strerror(errno));
-                return -1;
-        }
-        return 0;
-}
-
-int jt_debug_mark(int argc, char **argv) {
-        int rc;
-        struct portal_ioctl_data data;
-        char *text;
-        time_t now = time(NULL);
-
-        PORTALS_CONNECT;
-        if (argc > 2)
-                return CMD_HELP;
-
-        if (argc == 2) {
-                text = argv[1];
-        } else {
-                text = ctime(&now);
-                text[strlen(text) - 1] = '\0'; /* stupid \n */
-        }
-
-        memset(&data, 0, sizeof(data));
-        data.ioc_inllen1 = strlen(text) + 1;
-        data.ioc_inlbuf1 = text;
-        if (portal_ioctl_pack(&data, &buf, max) != 0) {
-                fprintf(stderr, "portal_ioctl_pack failed.\n");
-                return -1;
-        }
-
-        rc = ioctl(g_pfd, IOC_PORTAL_MARK_DEBUG, buf);
-        if (rc) {
-                fprintf(stderr, "IOC_PORTAL_MARK_DEBUG failed: %s\n",
-                        strerror(errno));
-                return -1;
-        }
-        return 0;
-}
-
-int jt_debug_filter(int argc, char **argv) {
-        int   i;
-        
-        if (argc < 2) 
-                return CMD_HELP;
-
-        for (i = 1; i < argc; i++)
-                if (!do_debug_mask(argv[i], 0))
-                        fprintf(stderr, "Unknown subsystem or "
-                                "debug type: %s\n", argv[i]);
-        return 0;
-}
-
-int jt_debug_show(int argc, char **argv) {
-        int i;
-        
-        if (argc < 2)
-                return CMD_HELP;
-
-        for (i = 1; i < argc; i++)
-                if (!do_debug_mask(argv[i], 1))
-                        fprintf(stderr, "Unknown subsystem or "
-                                "debug type: %s\n", argv[i]);
-
-        return 0;
-}
-
-int jt_debug_list(int argc, char **argv) {
-        int i;
-
-        if (argc != 2)
-                return CMD_HELP; 
-
-        if (strcasecmp(argv[1], "subs") == 0) {
-                printf("Subsystems: all_subs");
-                for (i = 0; portal_debug_subsystems[i] != NULL; i++)
-                        printf(", %s", portal_debug_subsystems[i]);
-                printf("\n");
-        } else if (strcasecmp(argv[1], "types") == 0) {
-                printf("Types: all_types");
-                for (i = 0; portal_debug_masks[i] != NULL; i++)
-                        printf(", %s", portal_debug_masks[i]);
-                printf("\n");
-        }
-        return 0;
-}
-
-int jt_debug_modules(int argc, char **argv) {
-        char *modules[] = {"portals", "ksocknal", "obdclass", "ptlrpc",
-                           "obdext2", "ost", "osc", "mds", "mdc", "llite",
-                           "obdecho", "ldlm", "obdfilter", "extN", "lov",
-                           "mds_ext2", "mds_ext3", "mds_extN", NULL};
-        char *paths[] = {"portals/linux/oslib", "portals/linux/socknal",
-                         "lustre/obdclass", "lustre/ptlrpc", "lustre/obdext2",
-                         "lustre/ost", "lustre/osc", "lustre/mds", "lustre/mdc",
-                         "lustre/llite", "lustre/obdecho", "lustre/ldlm",
-                         "lustre/obdfilter", "lustre/extN", "lustre/lov",
-                         "lustre/mds", "lustre/mds", "lustre/mds", NULL};
-        char *path = "..";
-        char *kernel = "linux";
-        int i;
-
-        if (argc >= 2)
-                path = argv[1];
-        if (argc == 3) 
-                kernel = argv[2];
-        if (argc > 3) {
-                printf("%s [path] [kernel]\n", argv[0]);
-                return 0;
-        }
-
-        printf("set height 1000\n"
-               "symbol-file\n"
-               "delete\n"
-               "symbol-file %s\n"
-               "b panic\n"
-               "b stop\n", kernel); 
-
-        for (i = 0; modules[i] != NULL; i++) {
-                struct module_info info;
-                int rc;
-                size_t crap;
-                int query_module(const char *name, int which, void *buf,
-                                 size_t bufsize, size_t *ret);
-
-                rc = query_module(modules[i], QM_INFO, &info, sizeof(info),
-                                  &crap);
-                if (rc < 0) {
-                        if (errno != ENOENT)
-                                printf("query_module(%s) failed: %s\n",
-                                       modules[i], strerror(errno));
-                } else {
-                        printf("add-symbol-file %s/%s/%s.o 0x%0lx\n", path,
-                               paths[i], modules[i],
-                               info.addr + sizeof(struct module));
-                }
-        }
-        printf("set height 24\n");
-
-        return 0;
-}
-
-int jt_debug_panic(int argc, char **argv) {
-        int rc;
-        struct portal_ioctl_data data;
-
-        PORTALS_CONNECT;
-        if (argc != 1)
-                return CMD_HELP;
-
-        memset(&data, 0, sizeof(data));
-        if (portal_ioctl_pack(&data, &buf, max) != 0) {
-                fprintf(stderr, "portal_ioctl_pack failed.\n");
-                return -1;
-        }
-
-        rc = ioctl(g_pfd, IOC_PORTAL_PANIC, buf);
-        if (rc) {
-                fprintf(stderr, "IOC_PORTAL_PANIC failed: %s\n",
-                        strerror(errno));
-                return -1;
-        }
-        return 0;
-}
-
-int jt_debug_lctl(int argc, char **argv) {
-        if (argc == 2) {
-                lctl_debug = strtoul(argv[1], NULL, 0);
-        } else
-                printf("current lctl_debug: 0x%x\n", lctl_debug);
-        return 0;
-}
index 5b59cce..c7a5b33 100644 (file)
@@ -5,6 +5,7 @@
  *   Author: Peter J. Braam <braam@clusterfs.com>
  *   Author: Phil Schwan <phil@clusterfs.com>
  *   Author: Robert Read <rread@clusterfs.com> 
+ *
  *   This file is part of Lustre, http://www.lustre.org.
  *
  *   Lustre is free software; you can redistribute it and/or
 
 
 #include <stdlib.h>
-#include <sys/ioctl.h>
-#include <fcntl.h>
-#include <sys/socket.h>
-#include <sys/types.h>
-#include <sys/wait.h>
-#include <sys/stat.h>
 #include <stdio.h>
-#include <stdarg.h>
-#include <signal.h>
-#define printk printf
-
-
-#include <linux/lustre_lib.h>
-#include <linux/lustre_idl.h>
-#include <linux/lustre_dlm.h>
-
-#include <unistd.h>
-#include <sys/un.h>
-#include <time.h>
-#include <sys/time.h>
-#include <netinet/in.h>
-#include <errno.h>
-#include <string.h>
-#include <asm/page.h>   /* needed for PAGE_SIZE - rread*/ 
-
-#include "lctl.h"
-
-#define __KERNEL__
-#include <linux/list.h>
-#undef __KERNEL__
-
-int thread;
-
-command_t cmdlist[];
+#include <portals/ptlctl.h>
+#include "obdctl.h"
+#include "parser.h"
 
 static int jt_quit(int argc, char **argv) {
         Parser_quit(argc, argv);
@@ -76,89 +47,91 @@ command_t cmdlist[] = {
 
         /* Network configuration commands */
         {"==== network config ====", jt_noop, 0, "network config"},
-        {"network", jt_net_network, 0, "commands that follow apply to net\n"
+        {"network", jt_ptl_setup, 0, "commands that follow apply to net\n"
          "usage: network <tcp/elan/myrinet>"},       
-        {"connect", jt_net_connect, 0, "connect to a remote nid\n"
+        {"connect", jt_ptl_connect, 0, "connect to a remote nid\n"
          "usage: connect [[<hostname> <port>] | <elan id>]"},
-        {"disconnect", jt_net_disconnect, 0, "disconnect from a remote nid\n"
+        {"disconnect", jt_ptl_disconnect, 0, "disconnect from a remote nid\n"
          "usage: disconnect <nid>"},
-        {"mynid", jt_net_mynid, 0, "inform the socknal of the local nid. "
+        {"mynid", jt_ptl_mynid, 0, "inform the socknal of the local nid. "
          "The nid defaults to hostname for tcp networks and is automatically "
          "setup for elan/myrinet networks.\n"
          "usage: mynid [nid]"},
-        {"add_uuid", jt_net_add_uuid, 0, "associate a uuid with a nid\n"
+        {"add_uuid", jt_ptl_add_uuid, 0, "associate a uuid with a nid\n"
          "usage: add_uuid <uuid> <nid>"},
-        {"del_uuid", jt_net_del_uuid, 0, "delete a uuid association\n"
+        {"del_uuid", jt_ptl_del_uuid, 0, "delete a uuid association\n"
          "usage: del_uuid <uuid>"},
-        {"add_route", jt_net_add_route, 0,
+        {"add_route", jt_ptl_add_route, 0,
          "add an entry to the routing table\n"
          "usage: add_route <gateway> <target> [target]"},
-        {"del_route", jt_net_del_route, 0,
+        {"del_route", jt_ptl_del_route, 0,
          "delete an entry from the routing table\n"
          "usage: del_route <target>"},
-        {"route_list", jt_net_route_list, 0, "print the routing table\n"
+        {"route_list", jt_ptl_print_routes, 0, "print the routing table\n"
          "usage: route_list"},
-        {"recv_mem", jt_net_recv_mem, 0, "set socket receive buffer size, "
+        {"recv_mem", jt_ptl_rxmem, 0, "set socket receive buffer size, "
          "if size is omited the current size is reported.\n"
          "usage: recv_mem [size]"},
-        {"send_mem", jt_net_send_mem, 0, "set socket send buffer size, "
+        {"send_mem", jt_ptl_txmem, 0, "set socket send buffer size, "
          "if size is omited the current size is reported.\n"
          "usage: send_mem [size]"},
-        {"nagle", jt_net_nagle, 0, "enable/disable nagle, omiting the "
+        {"nagle", jt_ptl_nagle, 0, "enable/disable nagle, omiting the "
          "argument will cause the current nagle setting to be reported.\n" 
          "usage: nagle [on/off]"},       
                 
         /* Device selection commands */
         {"=== device selection ===", jt_noop, 0, "device selection"},
-        {"newdev", jt_dev_newdev, 0, "create a new device\n"
+        {"newdev", jt_obd_newdev, 0, "create a new device\n"
          "usage: newdev"},
-        {"uuid2dev", jt_dev_uuid2dev, 0,
+#if 0
+        {"uuid2dev", jt_obd_uuid2dev, 0,
          "find a uuid and make it the current device\n"
          "usage: uuid2dev <uuid>"},
-        {"name2dev", jt_dev_name2dev, 0,
+#endif
+        {"name2dev", jt_obd_name2dev, 0,
          "find a name and make it the current device\n"
          "usage: name2dev <name>"},
-        {"device", jt_dev_device, 0, "set current device to devno\n"
+        {"device", jt_obd_device, 0, "set current device to devno\n"
          "usage: device <devno>"},
-        {"device_list", jt_dev_list, 0, "show all devices\n"
+        {"device_list", jt_obd_list, 0, "show all devices\n"
          "usage: device_list"},
          
         /* Device configuration commands */
         {"==== device config =====", jt_noop, 0, "device config"},
-        {"attach", jt_dev_attach, 0, "name and type the device\n"
+        {"attach", jt_obd_attach, 0, "name and type the device\n"
          "usage: attach type [name [uuid]]"},
-        {"setup", jt_dev_setup, 0,
+        {"setup", jt_obd_setup, 0,
          "type specific device configuration information\n"
          "usage: setup <args...>"},
-        {"cleanup", jt_dev_cleanup, 0, "cleanup setup\n"
+        {"cleanup", jt_obd_cleanup, 0, "cleanup setup\n"
          "usage: cleanup"},
-        {"detach", jt_dev_detach, 0, "un-name a device\n"
+        {"detach", jt_obd_detach, 0, "un-name a device\n"
          "usage: detach"},
-        {"lovconfig", jt_dev_lov_config, 0,
+        {"lovconfig", jt_obd_lov_config, 0,
          "write lov configuration to a mds device\n"
          "usage: lovconfig lov-uuid stripcount stripsize pattern UUID1 [UUID2 ...]"},
 
         /* Device operations */
         {"=== device operations ==", jt_noop, 0, "device operations"},
-        {"probe", jt_dev_probe, 0,
+        {"probe", jt_obd_connect, 0,
          "build a connection handle to a device.  This command is used too "
          "suspend configuration until lctl has ensured that the mds and osc "
          "services are available.  This is to avoid mount failures in a "
          "rebooting cluster.\n"
          "usage: probe [<timeout]"},
-        {"close", jt_dev_close, 0, "close the connection handle\n"
+        {"close", jt_obd_disconnect, 0, "close the connection handle\n"
          "usage: close"},
-        {"getattr", jt_dev_getattr, 0, "get attribute for id\n"
+        {"getattr", jt_obd_getattr, 0, "get attribute for id\n"
          "usage: getattr <id>"},
-        {"setattr", jt_dev_setattr, 0, "set attribute for id\n"
+        {"setattr", jt_obd_setattr, 0, "set attribute for id\n"
          "usage: setattr <id> <mode>"},
-        {"test_getattr", jt_dev_test_getattr, 0,
+        {"test_getattr", jt_obd_test_getattr, 0,
          "perform count number of getattr's\n"
          "usage: test_getattr <count> [verbose]"},
-        {"test_brw", jt_dev_test_brw, 0,
+        {"test_brw", jt_obd_test_brw, 0,
          "perform count number of bulk read/writes\n"
          "usage: test_brw <count> [write [verbose [pages [obdos]]]]"},
-        {"test_ldlm", jt_dev_test_ldlm, 0, "perform lock manager test\n"
+        {"test_ldlm", jt_obd_test_ldlm, 0, "perform lock manager test\n"
          "usage: test_ldlm"},
 
 #if 0
@@ -168,29 +141,26 @@ command_t cmdlist[] = {
 #endif
         /* Debug commands */
         {"======== debug =========", jt_noop, 0, "debug"},
-        {"debug_lctl", jt_debug_lctl, 0,
-         "set debug status of lctl "
-         "usage: debug_kernel [file] [raw]"},
-        {"debug_kernel", jt_debug_kernel, 0,
+        {"debug_kernel", jt_dbg_debug_kernel, 0,
          "get debug buffer and dump to a file"
          "usage: debug_kernel [file] [raw]"},
-        {"debug_file", jt_debug_file, 0,
+        {"debug_file", jt_dbg_debug_file, 0,
          "read debug buffer from input and dump to output"
          "usage: debug_file <input> [output] [raw]"},
-        {"clear", jt_debug_clear, 0, "clear kernel debug buffer\n"
+        {"clear", jt_dbg_clear_debug_buf, 0, "clear kernel debug buffer\n"
          "usage: clear"},
-        {"mark", jt_debug_mark, 0,"insert marker text in kernel debug buffer\n"
+        {"mark", jt_dbg_mark_debug_buf, 0,"insert marker text in kernel debug buffer\n"
          "usage: mark <text>"},
-        {"filter", jt_debug_filter, 0, "filter message type\n"
+        {"filter", jt_dbg_filter, 0, "filter message type\n"
          "usage: filter <subsystem id/debug mask>"},
-        {"show", jt_debug_show, 0, "show message type\n"
+        {"show", jt_dbg_show, 0, "show message type\n"
          "usage: show <subsystem id/debug mask>"},
-        {"debug_list", jt_debug_list, 0, "list subsystem and debug types\n"
+        {"debug_list", jt_dbg_list, 0, "list subsystem and debug types\n"
          "usage: debug_list <subs/types>"},
-        {"modules", jt_debug_modules, 0,
+        {"modules", jt_dbg_modules, 0,
          "provide gdb-friendly module information\n"
          "usage: modules <path>"},
-        {"panic", jt_debug_panic, 0, "force the kernel to panic\n"
+        {"panic", jt_dbg_panic, 0, "force the kernel to panic\n"
          "usage: panic"},
          
         /* User interface commands */
@@ -201,171 +171,19 @@ command_t cmdlist[] = {
         { 0, 0, 0, NULL }
 };
 
-static void signal_server(int sig) {
-        if (sig == SIGINT) {
-                do_disconnect("sigint", 1);
-                exit(1);
-        } else {
-                fprintf(stderr, "%s: got signal %d\n", cmdname("sigint"), sig);
-        }
-}
-
-int get_verbose(const char *arg)
-{
-        int verbose;
-
-        if (!arg || arg[0] == 'v')
-                verbose = 1;
-        else if (arg[0] == 's' || arg[0] == 'q')
-                verbose = 0;
-        else
-                verbose = (int) strtoul(arg, NULL, 0);
-
-        if (verbose < 0)
-                printf("Print status every %d seconds\n", -verbose);
-        else if (verbose == 1)
-                printf("Print status every operation\n");
-        else if (verbose > 1)
-                printf("Print status every %d operations\n", verbose);
-
-        return verbose;
-}
-
-int be_verbose(int verbose, struct timeval *next_time,
-                      int num, int *next_num, int num_total)
-{
-        struct timeval now;
-
-        if (!verbose)
-                return 0;
-
-        if (next_time != NULL)
-                gettimeofday(&now, NULL);
-
-        /* A positive verbosity means to print every X iterations */
-        if (verbose > 0 &&
-            (next_num == NULL || num >= *next_num || num >= num_total)) {
-                *next_num += verbose;
-                if (next_time) {
-                        next_time->tv_sec = now.tv_sec - verbose;
-                        next_time->tv_usec = now.tv_usec;
-                }
-                return 1;
-        }
-
-        /* A negative verbosity means to print at most each X seconds */
-        if (verbose < 0 && next_time != NULL && difftime(&now, next_time) >= 0){
-                next_time->tv_sec = now.tv_sec - verbose;
-                next_time->tv_usec = now.tv_usec;
-                if (next_num)
-                        *next_num = num;
-                return 1;
-        }
-
-        return 0;
-}
-
-int jt_opt_threads(int argc, char **argv)
-{
-        int threads, next_thread;
-        int verbose;
-        int i, j;
-        int rc = 0;
-
-        if (argc < 5) {
-                fprintf(stderr,
-                        "usage: %s numthreads verbose devno <cmd [args ...]>\n",
-                        argv[0]);
-                return -1;
-        }
-
-        threads = strtoul(argv[1], NULL, 0);
-
-        verbose = get_verbose(argv[2]);
-
-        printf("%s: starting %d threads on device %s running %s\n",
-               argv[0], threads, argv[3], argv[4]);
 
-        for (i = 1, next_thread = verbose; i <= threads; i++) {
-                rc = fork();
-                if (rc < 0) {
-                        fprintf(stderr, "error: %s: #%d - %s\n", argv[0], i,
-                                strerror(rc = errno));
-                        break;
-                } else if (rc == 0) {
-                        thread = i;
-                        argv[2] = "--device";
-                        return jt_opt_device(argc - 2, argv + 2);
-                } else if (be_verbose(verbose, NULL, i, &next_thread, threads))
-                        printf("%s: thread #%d (PID %d) started\n",
-                               argv[0], i, rc);
-                rc = 0;
-        }
-
-        if (!thread) { /* parent process */
-                if (!verbose)
-                        printf("%s: started %d threads\n\n", argv[0], i - 1);
-                else
-                        printf("\n");
 
-                for (j = 1; j < i; j++) {
-                        int status;
-                        int ret = wait(&status);
-
-                        if (ret < 0) {
-                                fprintf(stderr, "error: %s: wait - %s\n",
-                                        argv[0], strerror(errno));
-                                if (!rc)
-                                        rc = errno;
-                        } else {
-                                /*
-                                 * This is a hack.  We _should_ be able to use
-                                 * WIFEXITED(status) to see if there was an
-                                 * error, but it appears to be broken and it
-                                 * always returns 1 (OK).  See wait(2).
-                                 */
-                                int err = WEXITSTATUS(status);
-                                if (err)
-                                        fprintf(stderr,
-                                                "%s: PID %d had rc=%d\n",
-                                                argv[0], ret, err);
-                                if (!rc)
-                                        rc = err;
-                        }
-                }
-        }
-
-        return rc;
-}
-
-char *cmdname(char *func)
+int main(int argc, char **argv) 
 {
-       static char buf[512];
-       
-       if (thread) {
-               sprintf(buf, "%s-%d", func, thread);
-               return buf;
-       }
-
-       return func;
-}
-
-int main(int argc, char **argv) {
-        struct sigaction sigact;
         int rc;
 
-        sigact.sa_handler = signal_server;
-        sigfillset(&sigact.sa_mask);
-        sigact.sa_flags = SA_RESTART;
-        sigaction(SIGINT, &sigact, NULL);
+        setlinebuf(stdout);
 
-        if (network_setup(argc, argv) < 0)
+        if (ptl_initialize(argc, argv) < 0)
                 exit(1);
-        
-        if (device_setup(argc, argv) < 0)
+        if (obd_initialize(argc, argv) < 0)
                 exit(2);
-
-        if (debug_setup(argc, argv) < 0)
+        if (dbg_initialize(argc, argv) < 0)
                 exit(3);
         
         if (argc > 1) {
@@ -375,7 +193,7 @@ int main(int argc, char **argv) {
                 rc = Parser_commands();
         }
 
-        do_disconnect(argv[0], 1);
+        obd_cleanup(argc, argv);
         return rc;
 }
 
diff --git a/lustre/utils/lctl.h b/lustre/utils/lctl.h
deleted file mode 100644 (file)
index 0014182..0000000
+++ /dev/null
@@ -1,153 +0,0 @@
-#ifndef _LCTL_H_
-#define _LCTL_H_
-
-#include "parser.h"
-extern command_t cmdlist[];
-
-/* Network configuration commands */ 
-int jt_net_network(int argc, char **argv);
-int jt_net_connect(int argc, char **argv);
-int jt_net_disconnect(int argc, char **argv);
-int jt_net_add_uuid(int argc, char **argv);
-int jt_net_del_uuid(int argc, char **argv);
-int jt_net_mynid(int argc, char **argv);
-int jt_net_add_route(int argc, char **argv);
-int jt_net_del_route(int argc, char **argv);
-int jt_net_route_list(int argc, char **argv);
-int jt_net_recv_mem(int argc, char **argv);
-int jt_net_send_mem(int argc, char **argv);
-int jt_net_nagle(int argc, char **argv);
-
-/* Device selection commands */
-int jt_opt_device(int argc, char **argv);
-int jt_dev_newdev(int argc, char **argv);
-int jt_dev_uuid2dev(int argc, char **argv);
-int jt_dev_name2dev(int argc, char **argv);
-int jt_dev_device(int argc, char **argv);
-int jt_dev_list(int argc, char **argv);
-
-/* Device configuration commands */
-int jt_dev_attach(int argc, char **argv);
-int jt_dev_setup(int argc, char **argv);
-int jt_dev_cleanup(int argc, char **argv);
-int jt_dev_detach(int argc, char **argv);
-int jt_dev_lov_config(int argc, char **argv);
-
-/* Device operations */
-int jt_dev_probe(int argc, char **argv);
-int jt_dev_close(int argc, char **argv);
-int jt_dev_getattr(int argc, char **argv);
-int jt_dev_setattr(int argc, char **argv);
-int jt_dev_test_getattr(int argc, char **argv);
-int jt_dev_test_brw(int argc, char **argv);
-int jt_dev_test_ldlm(int argc, char **argv);
-
-/* Debug commands */
-int jt_debug_kernel(int argc, char **argv);
-int jt_debug_file(int argc, char **argv);
-int jt_debug_clear(int argc, char **argv);
-int jt_debug_mark(int argc, char **argv);
-int jt_debug_filter(int argc, char **argv);
-int jt_debug_show(int argc, char **argv);
-int jt_debug_list(int argc, char **argv);
-int jt_debug_modules(int argc, char **argv);
-int jt_debug_panic(int argc, char **argv);
-int jt_debug_lctl(int argc, char **argv);
-
-int do_disconnect(char *func, int verbose);
-int network_setup(int argc, char **argv);
-int device_setup(int argc, char **argv);
-int debug_setup(int argc, char **argv);
-
-int jt_opt_threads(int argc, char **argv);
-char *cmdname(char *func);
-int get_verbose(const char *arg);
-int be_verbose(int verbose, struct timeval *next_time,
-              int num, int *next_num, int num_total);
-
-#define LCTL_DEBUG
-#ifdef LCTL_DEBUG
-extern int lctl_debug;
-#define D_LCTL 1
-
-#ifdef CDEBUG
-#undef CDEBUG
-#endif
-#define CDEBUG(mask, format, a...)                                    \
-        do {                                                            \
-                if (lctl_debug & mask) {                           \
-                        printf("(%s:%s L%d): " format, __FILE__,        \
-                               __FUNCTION__, __LINE__ , ## a);          \
-                }                                                       \
-        } while (0)
-#else  /* !LCTL_DEBUG */
-#  define CDEBUG(mask, format, a...) do {} while (0)
-#endif /* LCTL_DEBUG */
-
-
-#ifdef CERROR
-#undef CERROR
-#endif
-#define CERROR(format, a...)                                    \
-do {                                                            \
-        fprintf(stderr, "(%s:%s L%d): " format, __FILE__, __FUNCTION__, \
-               __LINE__ , ## a);                                \
-} while (0)
-
-/* So we can tell between error codes and devices */
-#define N2D_OFF         0x100
-
-#define IOCINIT(data)                                                   \
-do {                                                                    \
-        memset(&data, 0, sizeof(data));                                 \
-        data.ioc_version = OBD_IOCTL_VERSION;                           \
-        data.ioc_addr = conn_addr;                                      \
-        data.ioc_cookie = conn_cookie;                                  \
-        data.ioc_len = sizeof(data);                                    \
-        if (fd < 0) {                                                   \
-                fprintf(stderr, "No device open, use device\n");        \
-                return 1;                                               \
-        }                                                               \
-} while (0)
-
-#define PORTALS_CONNECT                                                 \
-do {                                                                    \
-        if (g_pfd != -1)                                                \
-                break;                                                  \
-                                                                        \
-        g_pfd = open("/dev/portals", O_RDWR);                           \
-        if (g_pfd < 0) {                                                \
-                fprintf(stderr, "error: failed to open /dev/portals: %s\n" \
-                       "hint: the portals module may not be loaded\n",    \
-                       strerror(errno));                               \
-                return -1;                                              \
-        }                                                               \
-} while(0)
-
-#define LUSTRE_CONNECT(func)                                            \
-do {                                                                    \
-        if (fd != -1)                                                   \
-                break;                                                  \
-                                                                        \
-        fd = open("/dev/obd", O_RDWR);                                  \
-        if (fd < 0) {                                                   \
-                fprintf(stderr, "error: %s failed to open /dev/obd: %s\n" \
-                       "hint: the lustre modules may not be loaded\n",   \
-                       cmdname(func), strerror(errno));                \
-                return -1;                                              \
-        }                                                               \
-} while(0)
-
-#define difftime(a, b)                                                  \
-        ((double)((a)->tv_sec - (b)->tv_sec) +                          \
-        ((double)((a)->tv_usec - (b)->tv_usec) / 1000000))
-
-
-typedef struct {
-       char *name;
-       int num;
-} name2num_t;
-
-
-#endif
-
diff --git a/lustre/utils/network.c b/lustre/utils/network.c
deleted file mode 100644 (file)
index 8f10f11..0000000
+++ /dev/null
@@ -1,729 +0,0 @@
-/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
- * vim:expandtab:shiftwidth=8:tabstop=8:
- *
- * Copyright (C) 2001, 2002 Cluster File Systems, Inc.
- *
- *   This file is a modified version of the ptlctl tool which is
- *   part of Portals, http://www.sf.net/projects/lustre/
- *
- *   Portals is free software; you can redistribute it and/or
- *   modify it under the terms of version 2 of the GNU General Public
- *   License as published by the Free Software Foundation.
- *
- *   Portals 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 for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with Portals; if not, write to the Free Software
- *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- */
-
-#include <stdio.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/tcp.h>
-#include <netdb.h>
-#include <stdlib.h>
-#include <string.h>
-#include <fcntl.h>
-#include <sys/ioctl.h>
-#include <errno.h>
-#include <unistd.h>
-#include <time.h>
-#include <portals/api-support.h>
-
-#include "lctl.h"
-
-static char rawbuf[8192];
-static char *buf = rawbuf;
-static int max = 8192;
-
-static unsigned int g_nid = 0;
-static unsigned int g_nal = 0;
-static unsigned short g_port = 0;
-static int g_pfd = -1;
-
-static int g_socket_txmem = 0;
-static int g_socket_rxmem = 0;
-static int g_socket_nonagle = 1;
-
-static name2num_t nalnames[] = {
-        {"tcp",                SOCKNAL},
-        {"elan",       QSWNAL},
-        {"gm",         GMNAL},
-        {NULL,         -1}
-};
-
-int network_setup(int argc, char **argv) {
-        PORTALS_CONNECT;
-        return 0;
-}
-
-static name2num_t *name2num_lookup_name(name2num_t *table, char *str) {
-        while (table->name != NULL)
-                if (!strcmp (str, table->name))
-                        return (table);
-                else
-                        table++;
-        return (NULL);
-}
-
-static name2num_t *name2num_lookup_num(name2num_t *table, int num) {
-        while (table->name != NULL)
-                if (num == table->num)
-                        return (table);
-                else
-                        table++;
-        return (NULL);
-}
-
-static int name2nal(char *str) {
-        name2num_t *e = name2num_lookup_name (nalnames, str);
-
-        return ((e == NULL) ? 0 : e->num);
-}
-
-static char *nal2name (int nal) {
-        name2num_t *e = name2num_lookup_num (nalnames, nal);
-
-        return ((e == NULL) ? "???" : e->name);
-}
-
-static int nid2nal(ptl_nid_t nid) {
-        /* BIG pragmatic assumption */
-        return ((((__u32)nid) & 0xffff0000) != 0 ? SOCKNAL : QSWNAL);
-}
-
-static int parse_nid(ptl_nid_t *nidp, char *str) {
-        struct hostent *he;
-        int             a;
-        int             b;
-        int             c;
-        int             d;
-        
-        if (sscanf (str, "%d.%d.%d.%d", &a, &b, &c, &d) == 4 &&
-            (a & ~0xff) == 0 && (b & ~0xff) == 0 &&
-            (c & ~0xff) == 0 && (d & ~0xff) == 0) {
-                __u32 addr = (a<<24)|(b<<16)|(c<<8)|d;
-                *nidp = (ptl_nid_t)addr;
-                return (0);
-        }
-        
-        if ((('a' <= str[0] && str[0] <= 'z') ||
-             ('A' <= str[0] && str[0] <= 'Z')) &&
-             (he = gethostbyname (str)) != NULL) {
-                __u32 addr = *(__u32 *)he->h_addr;
-                *nidp = (ptl_nid_t)ntohl(addr);  /* HOST byte order */
-                return (0);
-        }
-
-        if (sscanf (str, "%i", &a) == 1) {
-                *nidp = (ptl_nid_t)a;
-                return (0);
-        }
-
-        return (-1);
-}
-
-static char *nid2str (char *buffer, ptl_nid_t nid) {
-        switch (nid2nal(nid)) {
-        case QSWNAL:
-                sprintf (buffer, "%Ld", nid);
-                return (buffer);
-                
-        case SOCKNAL: {
-                __u32 addr = htonl((__u32)nid); /* back to NETWORK byte order*/
-                struct hostent *he = gethostbyaddr ((const char *)&addr,
-                        sizeof(addr), AF_INET);
-                
-                if (he != NULL) {
-                        strcpy (buffer, he->h_name);
-                } else {
-                        addr = (__u32)nid;
-                        sprintf(buffer, "%d.%d.%d.%d", (addr>>24)&0xff,
-                                (addr>>16)&0xff, (addr>>8)&0xff, addr&0xff);
-                }
-                return (buffer);
-        }
-        
-        default:
-                sprintf (buffer, "nid2nal broken");
-                return (buffer);
-        }
-}
-        
-int jt_net_network(int argc, char **argv) {
-        int  nal;
-        
-        if (argc != 2 || (nal = name2nal (argv[1])) == 0)
-                return CMD_HELP;
-
-        g_nal = nal;
-        return (0);
-}
-
-int jt_net_connect(int argc, char **argv) {
-        if (argc < 2)
-                return CMD_HELP;
-
-        if (g_nal == 0) {
-                fprintf(stderr, "Error: you must run the 'setup' command "
-                        "first.\n");
-                return -1;
-        }
-
-        if (g_nal == SOCKNAL) {
-                struct hostent *he;
-                struct portal_ioctl_data data;
-                struct sockaddr_in srvaddr;
-                int fd, rc;
-                int nonagle = 0;
-                int rxmem = 0;
-                int txmem = 0;
-                int o;
-                int olen;
-                
-                if (argc != 3)
-                        return CMD_HELP;
-
-                he = gethostbyname(argv[1]);
-                if (!he) {
-                        fprintf(stderr, "gethostbyname error: %s\n",
-                                strerror(errno));
-                        return -1;
-                }
-
-                g_port = atol(argv[2]);
-
-                memset(&srvaddr, 0, sizeof(srvaddr));
-                srvaddr.sin_family = AF_INET;
-                srvaddr.sin_port = htons(g_port);
-                srvaddr.sin_addr.s_addr = *(__u32 *)he->h_addr;
-        
-                fd = socket(PF_INET, SOCK_STREAM, 0);
-                if ( fd < 0 ) {
-                        fprintf(stderr, "socket() failed: %s\n",
-                                strerror(errno));
-                        return -1;
-                }
-
-                if (g_socket_nonagle) {
-                        o = 1;
-                        if (setsockopt(fd, IPPROTO_TCP, TCP_NODELAY,
-                            &o, sizeof (o)) != 0) { 
-                                fprintf(stderr, "cannot disable nagle: %s\n",
-                                        strerror(errno));
-                                return (-1);
-                        }
-                }
-
-                if (g_socket_rxmem != 0) {
-                        o = g_socket_rxmem;
-                        if (setsockopt(fd, SOL_SOCKET, SO_RCVBUF,
-                            &o, sizeof (o)) != 0) { 
-                                fprintf(stderr, "cannot set receive buffer "
-                                        "size: %s\n", strerror(errno));
-                                return (-1);
-                        }
-                }
-
-                if (g_socket_txmem != 0) {
-                        o = g_socket_txmem;
-                        if (setsockopt(fd, SOL_SOCKET, SO_SNDBUF,
-                            &o, sizeof (o)) != 0) { 
-                                fprintf(stderr, "cannot set send buffer "
-                                        "size: %s\n", strerror(errno));
-                                return (-1);
-                        }
-                }
-
-                rc = connect(fd, (struct sockaddr *)&srvaddr, sizeof(srvaddr));
-                if ( rc == -1 ) { 
-                        fprintf(stderr, "connect() failed: %s\n",
-                                strerror(errno));
-                        return -1;
-                }
-
-                olen = sizeof (txmem);
-                if (getsockopt (fd, SOL_SOCKET, SO_SNDBUF, &txmem, &olen) != 0)
-                        fprintf(stderr, "Can't get send buffer size: %s\n",
-                                strerror(errno));
-                olen = sizeof (rxmem);
-                if (getsockopt (fd, SOL_SOCKET, SO_RCVBUF, &rxmem, &olen) != 0)
-                        fprintf(stderr, "Can't get receive buffer size: %s\n",
-                                strerror(errno));
-                olen = sizeof (nonagle);
-                if (getsockopt(fd,IPPROTO_TCP,TCP_NODELAY,&nonagle,&olen) != 0)
-                        fprintf(stderr, "Can't get nagle: %s\n",
-                                strerror(errno));
-
-                printf("Connected to %s (snd %d, rcv %d, nagle %s)\n",
-                        argv[1],txmem,rxmem,nonagle ? "Disabled" : "Enabled");
-
-                PORTAL_IOC_INIT(data);
-                data.ioc_fd = fd;
-                /* HOST byte order */
-                data.ioc_nid = ntohl(srvaddr.sin_addr.s_addr);
-
-                rc = ioctl(g_pfd, IOC_PORTAL_REGISTER_CLIENT_FD, &data);
-                if (rc) {
-                        fprintf(stderr, "failed to register fd with portals: "
-                                "%s\n", strerror(errno));
-                        return -1;
-                }
-
-                g_nid = ntohl (srvaddr.sin_addr.s_addr); /* HOST byte order */
-                printf("Connection to 0x%x registered with socknal\n",
-                        g_nid);
-
-                rc = close(fd);
-                if (rc) {
-                        fprintf(stderr, "close failed: %d\n", rc);
-                }
-        } else if (g_nal == QSWNAL) {
-                g_nid = atoi(argv[1]);
-        } else if (g_nal == GMNAL) {
-                g_nid = atoi(argv[1]);
-        } else {
-                fprintf(stderr, "This should never happen.  Also it is very "
-                        "bad.\n");
-        }
-
-        return 0;
-}
-
-int jt_net_disconnect(int argc, char **argv) {
-        if (argc > 2)
-                return CMD_HELP;
-        
-        if (g_nal == 0) {
-                fprintf(stderr, "Error: you must run the 'network' command "
-                        "first.\n");
-                return -1;
-        }
-
-        if (g_nal == SOCKNAL) {
-                struct hostent *he;
-                struct portal_ioctl_data data;
-                int rc;
-
-                PORTAL_IOC_INIT(data);
-                if (argc == 2) {
-                        he = gethostbyname(argv[1]);
-                        if (!he) {
-                                fprintf(stderr, "gethostbyname error: %s\n",
-                                        strerror(errno));
-                                return -1;
-                        }
-                        
-                        /* HOST byte order */
-                        data.ioc_nid = ntohl (*(__u32 *)he->h_addr);
-
-                } else {
-                        fprintf(stderr, "Disconnecting ALL connections.\n");
-                        /* leave ioc_nid zeroed == disconnect all */
-                }
-                rc = ioctl(g_pfd, IOC_PORTAL_CLOSE_CONNECTION, &data);
-                if (rc) {
-                        fprintf(stderr, "failed to remove connection: %s\n",
-                                strerror(errno));
-                        return -1;
-                }
-        } else if (g_nal == QSWNAL) {
-                printf("'disconnect' doesn't make any sense for "
-                        "elan.\n");
-        } else if (g_nal == GMNAL) {
-                printf("'disconnect' doesn't make any sense for "
-                        "GM.\n");
-        } else {
-                fprintf(stderr, "This should never happen.  Also it is very "
-                        "bad.\n");
-        }
-
-        return 0;
-}
-
-/*
-int jt_net_ping(int argc, char **argv) {
-        int       rc;
-        ptl_nid_t nid;
-        long      count   = 1;
-        long      size    = 4;
-        long      timeout = 1;
-        struct portal_ioctl_data data;
-
-        if (argc < 2) {
-                fprintf(stderr, "usage: %s nid [count] [size] [timeout "
-                        (secs)]\n", argv[0]);
-                return 0;
-        }
-
-        if (g_nal == 0) {
-                fprintf(stderr, "Error: you must run the 'setup' command "
-                        "first.\n");
-                return -1;
-        }
-
-        if (parse_nid (&nid, argv[1]) != 0) {
-                fprintf (stderr, "Can\'t parse nid \"%s\"\n", argv[1]);
-                return (-1);
-        }
-        
-        if (argc > 2) {
-                count = atol(argv[2]);
-
-                if (count < 0 || count > 20000) {
-                        fprintf(stderr, "are you insane? "
-                                "%ld is a crazy count.\n", count);
-                        return -1;
-                }
-        }
-        
-        if (argc > 3)
-                size= atol(argv[3]);
-
-        if (argc > 4)
-                timeout = atol (argv[4]);
-        
-        PORTAL_IOC_INIT (data);
-        data.ioc_count   = count;
-        data.ioc_size    = size;
-        data.ioc_nid     = (__u32)nid;
-        data.ioc_nal     = g_nal;
-        data.ioc_timeout = timeout;
-        
-        rc = ioctl(g_pfd, IOC_PORTAL_PING, &data);
-        if (rc) {
-                fprintf(stderr, "failed to start pinger: %s\n",
-                        strerror(errno));
-                return -1;
-        }
-        fprintf(stderr, "Pinger started, take cover...\n");
-        return 0;
-}
-*/
-
-int jt_net_mynid(int argc, char **argv) {
-        int rc;
-        struct hostent *h;
-        char buf[1024], *hostname;
-        struct portal_ioctl_data data;
-        ptl_nid_t mynid;
-        
-        if (argc > 2)
-                return CMD_HELP;
-
-        if (g_nal == 0) {
-                fprintf(stderr, "Error: you must run the 'setup' command "
-                        "first.\n");
-                return -1;
-        }
-
-        if (g_nal == QSWNAL) {
-                fprintf(stderr, "'mynid' doesn't make any sense for elan.\n");
-                return -1;
-        } else  if (g_nal == GMNAL) {
-                fprintf(stderr, "'mynid' doesn't make any sense for GM.\n");
-                return -1;
-        } 
-        
-        if (g_nal != SOCKNAL) {
-                fprintf(stderr, "This should never happen.  Also it is very "
-                        "bad.\n");
-                return -1;
-        }
-
-        if (argc == 1) {
-                if (gethostname(buf, sizeof(buf)) != 0) {
-                        fprintf(stderr, "gethostname failed: %s\n",
-                                strerror(errno));
-                        return -1;
-                }
-                hostname = buf;
-        } else {
-                hostname = argv[1];
-        }
-
-        h = gethostbyname(hostname);
-
-        if (!h) {
-                fprintf(stderr, "cannot get address for host '%s': %d\n",
-                        hostname, h_errno);
-                return -1;
-        }
-        mynid = (ptl_nid_t)ntohl (*(__u32 *)h->h_addr); /* HOST byte order */
-        
-        PORTAL_IOC_INIT(data);
-        data.ioc_nid = (__u32)mynid;
-
-        rc = ioctl(g_pfd, IOC_PORTAL_REGISTER_MYNID, &data);
-        if (rc < 0)
-                fprintf(stderr, "IOC_PORTAL_REGISTER_MYNID failed: %s\n",
-                       strerror(errno));
-        else
-                printf("registered my nid 0x%Lx (%s)\n",
-                        mynid, hostname);
-        return 0;
-}
-
-int jt_net_add_uuid(int argc, char **argv) {
-        char tmp[64];
-        int rc;
-        struct portal_ioctl_data data;
-        ptl_nid_t nid = g_nid;
-        
-        if (argc != 3)
-                return CMD_HELP;
-
-        if (parse_nid(&nid, argv[2]) != 0) {
-                fprintf (stderr, "Can't parse NID %s\n", argv[2]);
-                return (-1);
-        }
-
-        if (g_nal == 0) {
-                fprintf(stderr, "Error: you must run the 'setup' command "
-                        "first.\n");
-                return -1;
-        }
-
-        memset(&data, 0, sizeof(data));
-        data.ioc_nid = nid;
-        data.ioc_inllen1 = strlen(argv[1]) + 1;
-        data.ioc_inlbuf1 = argv[1];
-        data.ioc_nal = g_nal;
-        if (portal_ioctl_pack(&data, &buf, max) != 0) {
-                fprintf(stderr, "portal_ioctl_pack failed.\n");
-                return -1;
-        }
-
-        rc = ioctl(g_pfd, IOC_PORTAL_ADD_UUID, buf);
-        if (rc) {
-                fprintf(stderr, "IOC_PORTAL_ADD_UUID failed: %s\n",
-                        strerror(errno));
-                return -1;
-        }
-
-        printf ("Added uuid %s: %s\n", argv[1], nid2str (tmp, nid));
-        return 0;
-}
-
-#if 0
-static int jt_close_uuid(int argc, char **argv)
-{
-        int rc;
-        struct portal_ioctl_data data;
-
-        if (argc != 2) {
-                fprintf(stderr, "usage: %s <uuid>\n", argv[0]);
-                return 0;
-        }
-
-        if (g_nal == 0) {
-                fprintf(stderr, "Error: you must run the 'setup' command "
-                        "first.\n");
-                return -1;
-        }
-
-        memset(&data, 0, sizeof(data));
-        data.ioc_inllen1 = strlen(argv[1]) + 1;
-        data.ioc_inlbuf1 = argv[1];
-        data.ioc_nal = g_nal;
-        if (portal_ioctl_pack(&data, &buf, max) != 0) {
-                fprintf(stderr, "portal_ioctl_pack failed.\n");
-                return -1;
-        }
-
-        rc = ioctl(g_pfd, IOC_PORTAL_CLOSE_UUID, buf);
-        if (rc) {
-                fprintf(stderr, "IOC_PORTAL_CLOSE_UUID failed: %s\n",
-                        strerror(errno));
-                return -1;
-        }
-        return 0;
-}
-#endif
-
-int jt_net_del_uuid(int argc, char **argv) {
-        int rc;
-        struct portal_ioctl_data data;
-
-        if (argc != 2)
-                return CMD_HELP;
-
-        if (g_nal == 0) {
-                fprintf(stderr, "Error: you must run the 'setup' command "
-                        "first.\n");
-                return -1;
-        }
-
-        memset(&data, 0, sizeof(data));
-        data.ioc_inllen1 = strlen(argv[1]) + 1;
-        data.ioc_inlbuf1 = argv[1];
-        data.ioc_nal = g_nal;
-        if (portal_ioctl_pack(&data, &buf, max) != 0) {
-                fprintf(stderr, "portal_ioctl_pack failed.\n");
-                return -1;
-        }
-
-        rc = ioctl(g_pfd, IOC_PORTAL_DEL_UUID, buf);
-        if (rc) {
-                fprintf(stderr, "IOC_PORTAL_DEL_UUID failed: %s\n",
-                        strerror(errno));
-                return -1;
-        }
-        return 0;
-}
-
-int jt_net_add_route (int argc, char **argv) {
-        struct portal_ioctl_data data;
-        ptl_nid_t                nid1;
-        ptl_nid_t                nid2;
-        ptl_nid_t                gateway_nid;
-        int                      gateway_nal;
-        int                      rc;
-        
-        if (argc < 3)
-                return CMD_HELP;
-
-        if (parse_nid (&gateway_nid, argv[1]) != 0) {
-                fprintf (stderr, "Can't parse gateway NID \"%s\"\n", argv[1]);
-                return (-1);
-        }
-
-        gateway_nal = nid2nal (gateway_nid);
-        if (parse_nid (&nid1, argv[2]) != 0) {
-                fprintf(stderr, "Can't parse first target NID \"%s\"\n",
-                        argv[2]);
-                return (-1);
-        }
-
-        if (argc < 4) {
-                nid2 = nid1;
-        } else if (parse_nid (&nid2, argv[3]) != 0) {
-                fprintf(stderr, "Can't parse second target NID \"%s\"\n",
-                        argv[4]);
-                return (-1);
-        }
-
-        PORTAL_IOC_INIT(data);
-        data.ioc_nid = gateway_nid;
-        data.ioc_nal = gateway_nal;
-        data.ioc_nid2 = MIN (nid1, nid2);
-        data.ioc_nid3 = MAX (nid1, nid2);
-
-        rc = ioctl (g_pfd, IOC_PORTAL_ADD_ROUTE, &data);
-        if (rc != 0) {
-                fprintf(stderr, "IOC_PORTAL_ADD_ROUTE failed: %s\n",
-                        strerror (errno));
-                return (-1);
-        }
-        
-        return (0);
-}
-
-int jt_net_del_route(int argc, char **argv) {
-        struct portal_ioctl_data data;
-        ptl_nid_t                nid;
-        int                      rc;
-        
-        if (argc < 2)
-                return CMD_HELP;
-
-        if (parse_nid (&nid, argv[1]) != 0) {
-                fprintf (stderr, "Can't parse target NID \"%s\"\n", argv[1]);
-                return (-1);
-        }
-
-        PORTAL_IOC_INIT(data);
-        data.ioc_nid = nid;
-
-        rc = ioctl (g_pfd, IOC_PORTAL_DEL_ROUTE, &data);
-        if (rc != 0) {
-                fprintf(stderr, "IOC_PORTAL_DEL_ROUTE (0x%Lx) failed: %s\n",
-                        nid, strerror (errno));
-                return (-1);
-        }
-        
-        return (0);
-}
-
-int jt_net_route_list(int argc, char **argv) {
-        char                      buffer[3][128];
-        struct portal_ioctl_data  data;
-        int                       rc;
-        int                       index;
-        int                      gateway_nal;
-        ptl_nid_t                gateway_nid;
-        ptl_nid_t                nid1;
-        ptl_nid_t                nid2;
-        
-        for (index = 0;;index++) {
-                PORTAL_IOC_INIT(data);
-                data.ioc_count = index;
-                
-                rc = ioctl (g_pfd, IOC_PORTAL_GET_ROUTE, &data);
-                if (rc != 0)
-                        break;
-
-                gateway_nal = data.ioc_nal;
-                gateway_nid = data.ioc_nid;
-                nid1 = data.ioc_nid2;
-                nid2 = data.ioc_nid3;
-                
-                printf ("%8s %18s : %s - %s\n", 
-                        nal2name (gateway_nal), 
-                        nid2str (buffer[0], gateway_nid),
-                        nid2str (buffer[1], nid1),
-                        nid2str (buffer[2], nid2));
-        }
-        return (0);
-}
-
-int jt_net_recv_mem(int argc, char **argv) {
-        int size;
-        
-        if (argc > 1) {
-                if (Parser_size (&size, argv[1]) != 0 || size < 0) {
-                        fprintf (stderr, "Can't parse size %s\n", argv[1]);
-                        return (0);
-                }
-
-                g_socket_rxmem = size;
-        }
-
-        printf ("Socket rxmem = %d\n", g_socket_rxmem);        
-        return (0);
-}
-
-int jt_net_send_mem(int argc, char **argv) {
-        int size;
-        
-        if (argc > 1) {
-                if (Parser_size (&size, argv[1]) != 0 || size < 0) {
-                        fprintf (stderr, "Can't parse size %s\n", argv[1]);
-                        return (0);
-                }
-                g_socket_txmem = size;
-        }
-
-        printf ("Socket txmem = %d\n", g_socket_txmem);
-        return (0);
-}
-
-int jt_net_nagle(int argc, char **argv) {
-        int enable;
-
-        if (argc > 1) {
-                if (Parser_bool (&enable, argv[1]) != 0) {
-                        fprintf (stderr, "Can't parse boolean %s\n", argv[1]);
-                        return (0);
-                }
-                g_socket_nonagle = !enable;
-        }
-
-        printf ("Nagle %s\n", g_socket_nonagle ? "disabled" : "enabled");
-        return (0);
-}
similarity index 52%
rename from lustre/utils/device.c
rename to lustre/utils/obd.c
index 24e05b3..a3363d4 100644 (file)
@@ -4,7 +4,7 @@
  *  Copyright (C) 2002 Cluster File Systems, Inc.
  *   Author: Peter J. Braam <braam@clusterfs.com>
  *   Author: Phil Schwan <phil@clusterfs.com>
- *   Author: Brian Behlendorf <behlendorf1@llnl.gov
+ *   Author: Robert Read <rread@clusterfs.com
  *
  *   This file is part of Lustre, http://www.lustre.org.
  *
@@ -23,6 +23,7 @@
  *
  */
 
+
 #include <stdlib.h>
 #include <sys/ioctl.h>
 #include <fcntl.h>
@@ -35,7 +36,6 @@
 #include <signal.h>
 #define printk printf
 
-
 #include <linux/lustre_lib.h>
 #include <linux/lustre_idl.h>
 #include <linux/lustre_dlm.h>
 #include <netinet/in.h>
 #include <errno.h>
 #include <string.h>
-#include <asm/page.h>   /* needed for PAGE_SIZE - rread*/ 
 
-#include "parser.h"
-#include "lctl.h"
+#include <asm/page.h>           /* needed for PAGE_SIZE - rread */
 
 #define __KERNEL__
 #include <linux/list.h>
 #undef __KERNEL__
 
-static int fd = -1;
-static uint64_t conn_addr = -1;
-static uint64_t conn_cookie;
-static char rawbuf[8192];
-static char *buf = rawbuf;
-static int max = 8192;
+#include "obdctl.h"
+#include "parser.h"
+#include <stdio.h>
+
+#define SHMEM_STATS 1
+#if SHMEM_STATS
+# include <sys/ipc.h>
+# include <sys/shm.h>
 
-#if 0
-static int thread;
+# define MAX_SHMEM_COUNT 1024
+static long long *shared_counters;
+static long long counter_snapshot[2][MAX_SHMEM_COUNT];
+struct timeval prev_time;
 #endif
 
-int device_setup(int argc, char **argv) {
-        return 0;
+int fd = -1;
+uint64_t conn_addr = -1;
+uint64_t conn_cookie;
+char rawbuf[8192];
+char *buf = rawbuf;
+int max = 8192;
+
+static int thread;
+
+static int getfd(char *func);
+static char *cmdname(char *func);
+
+#define IOCINIT(data)                                                   \
+do {                                                                    \
+        memset(&data, 0, sizeof(data));                                 \
+        data.ioc_version = OBD_IOCTL_VERSION;                           \
+        data.ioc_addr = conn_addr;                                      \
+        data.ioc_cookie = conn_cookie;                                  \
+        data.ioc_len = sizeof(data);                                    \
+        if (fd < 0) {                                                   \
+                fprintf(stderr, "No device open, use device\n");        \
+                return 1;                                               \
+        }                                                               \
+} while (0)
+
+/*
+    pack "LL LL LL LL LL LL LL L L L L L L L L L a60 a60 L L L",
+    $obdo->{id}, 0,
+    $obdo->{gr}, 0,
+    $obdo->{atime}, 0,
+    $obdo->{mtime}, 0 ,
+    $obdo->{ctime}, 0,
+    $obdo->{size}, 0,
+    $obdo->{blocks}, 0,
+    $obdo->{blksize},
+    $obdo->{mode},
+    $obdo->{uid},
+    $obdo->{gid},
+    $obdo->{flags},
+    $obdo->{obdflags},
+    $obdo->{nlink},
+    $obdo->{generation},
+    $obdo->{valid},
+    $obdo->{inline},
+    $obdo->{obdmd},
+    0, 0, # struct list_head
+    0;  #  struct obd_ops
+}
+
+*/
+
+char *obdo_print(struct obdo *obd)
+{
+        char buf[1024];
+
+        sprintf(buf, "id: %Ld\ngrp: %Ld\natime: %Ld\nmtime: %Ld\nctime: %Ld\n"
+                "size: %Ld\nblocks: %Ld\nblksize: %d\nmode: %o\nuid: %d\n"
+                "gid: %d\nflags: %x\nobdflags: %x\nnlink: %d,\nvalid %x\n",
+                obd->o_id,
+                obd->o_gr,
+                obd->o_atime,
+                obd->o_mtime,
+                obd->o_ctime,
+                obd->o_size,
+                obd->o_blocks,
+                obd->o_blksize,
+                obd->o_mode,
+                obd->o_uid,
+                obd->o_gid,
+                obd->o_flags, obd->o_obdflags, obd->o_nlink, obd->o_valid);
+        return strdup(buf);
 }
 
-/* Misc support functions */
-static int do_name2dev(char *func, char *name) {
+
+
+#define N2D_OFF 0x100      /* So we can tell between error codes and devices */
+
+static int do_name2dev(char *func, char *name)
+{
         struct obd_ioctl_data data;
         int rc;
 
-        LUSTRE_CONNECT(func);
+        if (getfd(func))
+                return -1;
+
         IOCINIT(data);
 
         data.ioc_inllen1 = strlen(name) + 1;
@@ -86,7 +163,7 @@ static int do_name2dev(char *func, char *name) {
                 fprintf(stderr, "error: %s: invalid ioctl\n", cmdname(func));
                 return -2;
         }
-        rc = ioctl(fd, OBD_IOC_NAME2DEV , buf);
+        rc = ioctl(fd, OBD_IOC_NAME2DEV, buf);
         if (rc < 0) {
                 fprintf(stderr, "error: %s: %s - %s\n", cmdname(func),
                         name, strerror(rc = errno));
@@ -126,214 +203,265 @@ static int parse_devname(char * func, char *name)
         return ret;
 }
 
-
-#if 0
-/* pack "LL LL LL LL LL LL LL L L L L L L L L L a60 a60 L L L" */
-static char * obdo_print(struct obdo *obd)
+static char *cmdname(char *func)
 {
-        char buf[1024];
+        static char buf[512];
 
-        sprintf(buf, "id: %Ld\ngrp: %Ld\natime: %Ld\nmtime: %Ld\nctime: %Ld\n"
-                "size: %Ld\nblocks: %Ld\nblksize: %d\nmode: %o\nuid: %d\n"
-                "gid: %d\nflags: %x\nobdflags: %x\nnlink: %d,\nvalid %x\n",
-                obd->o_id,
-                obd->o_gr,
-                obd->o_atime,
-                obd->o_mtime,
-                obd->o_ctime,
-                obd->o_size,
-                obd->o_blocks,
-                obd->o_blksize,
-                obd->o_mode,
-                obd->o_uid,
-                obd->o_gid,
-                obd->o_flags,
-                obd->o_obdflags,
-                obd->o_nlink,
-                obd->o_valid);
-        return strdup(buf);
+        if (thread) {
+                sprintf(buf, "%s-%d", func, thread);
+                return buf;
+        }
+
+        return func;
 }
-#endif
 
-/* Device selection commands */
-int jt_dev_newdev(int argc, char **argv) 
+static int getfd(char *func)
 {
-        int rc;
-        struct obd_ioctl_data data;
+        if (fd == -1)
+                fd = open("/dev/obd", O_RDWR);
+        if (fd == -1) {
+                fprintf(stderr, "error: %s: opening /dev/obd: %s\n"
+                        "hint: lustre kernel modules may not be loaded.\n",
+                        cmdname(func), strerror(errno));
+                return -1;
+        }
+        return 0;
+}
 
-        LUSTRE_CONNECT(argv[0]);
-        IOCINIT(data);
+#define difftime(a, b)                                          \
+        ((double)(a)->tv_sec - (b)->tv_sec +                    \
+         ((double)((a)->tv_usec - (b)->tv_usec) / 1000000))
 
-        if (argc != 1)
-                return CMD_HELP;
+static int be_verbose(int verbose, struct timeval *next_time,
+                      int num, int *next_num, int num_total)
+{
+        struct timeval now;
 
-        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);
+        if (!verbose)
+                return 0;
+
+        if (next_time != NULL)
+                gettimeofday(&now, NULL);
+
+        /* A positive verbosity means to print every X iterations */
+        if (verbose > 0 &&
+            (next_num == NULL || num >= *next_num || num >= num_total)) {
+                *next_num += verbose;
+                if (next_time) {
+                        next_time->tv_sec = now.tv_sec - verbose;
+                        next_time->tv_usec = now.tv_usec;
+                }
+                return 1;
         }
 
-        return rc;
+        /* A negative verbosity means to print at most each X seconds */
+        if (verbose < 0 && next_time != NULL && difftime(&now, next_time) >= 0) {
+                next_time->tv_sec = now.tv_sec - verbose;
+                next_time->tv_usec = now.tv_usec;
+                if (next_num)
+                        *next_num = num;
+                return 1;
+        }
+
+        return 0;
 }
 
-static int do_device(char *func, int dev) {
-        struct obd_ioctl_data data;
+static int get_verbose(const char *arg)
+{
+        int verbose;
 
-        memset(&data, 0, sizeof(data));
-        data.ioc_dev = dev;
-        LUSTRE_CONNECT(func);
+        if (!arg || arg[0] == 'v')
+                verbose = 1;
+        else if (arg[0] == 's' || arg[0] == 'q')
+                verbose = 0;
+        else
+                verbose = (int)strtoul(arg, NULL, 0);
 
-        if (obd_ioctl_pack(&data, &buf, max)) {
-                CERROR("error: %s: invalid ioctl\n", cmdname(func));
-                return -2;
-        }
+        if (verbose < 0)
+                printf("Print status every %d seconds\n", -verbose);
+        else if (verbose == 1)
+                printf("Print status every operation\n");
+        else if (verbose > 1)
+                printf("Print status every %d operations\n", verbose);
 
-        return ioctl(fd, OBD_IOC_DEVICE , buf);
+        return verbose;
 }
 
-int jt_dev_device(int argc, char **argv) 
+int do_disconnect(char *func, int verbose)
 {
-        int rc, dev;
-        do_disconnect(argv[0], 1);
+        int rc;
+        struct obd_ioctl_data data;
 
-        if (argc != 2)
-                return CMD_HELP;
-        dev = parse_devname(argv[0], argv[1]);
-        if (dev < 0) {
-                return -1; 
+        if (conn_addr == -1)
+                return 0;
+
+        IOCINIT(data);
+
+        rc = ioctl(fd, OBD_IOC_DISCONNECT, &data);
+        if (rc < 0) {
+                fprintf(stderr, "error: %s: %x %s\n", cmdname(func),
+                        OBD_IOC_DISCONNECT, strerror(errno));
+        } else {
+                if (verbose)
+                        printf("%s: disconnected conn %Lx\n", cmdname(func),
+                               conn_addr);
+                conn_addr = -1;
         }
-        rc = do_device(argv[0], dev);
-        if (rc < 0)
-                fprintf(stderr, "error: %s: %s\n", cmdname(argv[0]),
-                        strerror(rc = errno));
 
         return rc;
 }
 
-static int do_uuid2dev(char *func, char *name) {
-        return 0;
+#if SHMEM_STATS
+static void shmem_setup(void)
+{
+        int shmid = shmget(IPC_PRIVATE, sizeof(counter_snapshot[0]), 0600);
+
+        if (shmid == -1) {
+                fprintf(stderr, "Can't create shared memory counters: %s\n",
+                        strerror(errno));
+                return;
+        }
+
+        shared_counters = (long long *)shmat(shmid, NULL, 0);
+
+        if (shared_counters == (long long *)(-1)) {
+                fprintf(stderr, "Can't attach shared memory counters: %s\n",
+                        strerror(errno));
+                shared_counters = NULL;
+                return;
+        }
 }
 
-int jt_dev_uuid2dev(int argc, char **argv) 
+static inline void shmem_reset(void)
 {
-        do_uuid2dev(NULL, NULL);
-        return 0;
+        if (shared_counters == NULL)
+                return;
+
+        memset(shared_counters, 0, sizeof(counter_snapshot[0]));
+        memset(counter_snapshot, 0, sizeof(counter_snapshot));
+        gettimeofday(&prev_time, NULL);
 }
 
-int jt_dev_name2dev(int argc, char **argv) 
+static inline void shmem_bump(void)
 {
-        int rc;
-        if (argc != 2)
-                return CMD_HELP;
+        if (shared_counters == NULL || thread <= 0 || thread > MAX_SHMEM_COUNT)
+                return;
 
-        rc = do_name2dev(argv[0], argv[1]);
-        if (rc >= N2D_OFF) {
-                int dev = rc - N2D_OFF;
-                rc = do_device(argv[0], dev);
-                if (rc == 0)
-                        printf("%d\n", dev);
-        }
-        return rc;
+        shared_counters[thread - 1]++;
 }
 
-int jt_dev_list(int argc, char **argv) 
+static void shmem_snap(int n)
 {
-        int rc;
-        char buf[1024];
-        struct obd_ioctl_data *data = (struct obd_ioctl_data *)buf;
+        struct timeval this_time;
+        int non_zero = 0;
+        long long total = 0;
+        double secs;
+        int i;
 
-        LUSTRE_CONNECT(argv[0]);
-        memset(buf, 0, sizeof(buf));
-        data->ioc_version = OBD_IOCTL_VERSION;
-        data->ioc_addr = conn_addr;
-        data->ioc_cookie = conn_addr;
-        data->ioc_len = sizeof(buf);
-        data->ioc_inllen1 = sizeof(buf) - size_round(sizeof(*data));
+        if (shared_counters == NULL || n > MAX_SHMEM_COUNT)
+                return;
 
-        if (argc != 1)
-                return CMD_HELP;
-                
-        rc = ioctl(fd, OBD_IOC_LIST , data);
-        if (rc < 0)
-                fprintf(stderr, "error: %s: %s\n", cmdname(argv[0]),
-                        strerror(rc=errno));
-        else {
-                printf("%s", data->ioc_bulk);
+        memcpy(counter_snapshot[1], counter_snapshot[0],
+               n * sizeof(counter_snapshot[0][0]));
+        memcpy(counter_snapshot[0], shared_counters,
+               n * sizeof(counter_snapshot[0][0]));
+        gettimeofday(&this_time, NULL);
+
+        for (i = 0; i < n; i++) {
+                long long this_count =
+                        counter_snapshot[0][i] - counter_snapshot[1][i];
+
+                if (this_count != 0) {
+                        non_zero++;
+                        total += this_count;
+                }
         }
 
-        return rc;
+        secs = (this_time.tv_sec + this_time.tv_usec / 1000000.0) -
+                (prev_time.tv_sec + prev_time.tv_usec / 1000000.0);
+
+        printf("%d/%d Total: %f/second\n", non_zero, n, total / secs);
+
+        prev_time = this_time;
 }
 
-/* Device configuration commands */
-int do_disconnect(char *func, int verbose) 
+#define SHMEM_SETUP()  shmem_setup()
+#define SHMEM_RESET()  shmem_reset()
+#define SHMEM_BUMP()   shmem_bump()
+#define SHMEM_SNAP(n)  shmem_snap(n)
+#else
+#define SHMEM_SETUP()
+#define SHMEM_RESET()
+#define SHMEM_BUMP()
+#define SHMEM_SNAP(n)
+#endif
+
+extern command_t cmdlist[];
+
+static int do_device(char *func, int dev)
 {
-        int rc;
         struct obd_ioctl_data data;
 
-        if (conn_addr == -1) 
-                return 0; 
+        memset(&data, 0, sizeof(data));
 
-        IOCINIT(data);
+        data.ioc_dev = dev;
 
-        rc = ioctl(fd, OBD_IOC_DISCONNECT , &data);
-        if (rc < 0) {
-                fprintf(stderr, "error: %s: %x %s\n", cmdname(func),
-                        OBD_IOC_DISCONNECT, strerror(errno));
-        } else {
-                if (verbose)
-                        printf("%s: disconnected conn %Lx\n", cmdname(func),
-                               conn_addr);
-                conn_addr = -1;
+        if (getfd(func))
+                return -1;
+
+        if (obd_ioctl_pack(&data, &buf, max)) {
+                fprintf(stderr, "error: %s: invalid ioctl\n", cmdname(func));
+                return -2;
         }
 
-        return rc;
+        return ioctl(fd, OBD_IOC_DEVICE, buf);
 }
 
-#if 0
-static int jt_dev_newconn(int argc, char **argv)
+int jt_obd_device(int argc, char **argv)
 {
-        int rc;a
-        struct obd_ioctl_data data;
+        int rc, dev;
+        do_disconnect(argv[0], 1);
 
-        IOCINIT(data);
-        if (argc != 1) {
-                fprintf(stderr, "usage: %s\n", cmdname(argv[0]));
-                return -1;
+        if (argc != 2) 
+                return CMD_HELP;
+
+        dev = parse_devname(argv[0], argv[1]);
+        if (dev < 0) {
+                return -1; 
         }
 
-        rc = ioctl(fd, OBD_IOC_RECOVD_NEWCONN , &data);
+        rc = do_device(argv[0], dev);
         if (rc < 0)
                 fprintf(stderr, "error: %s: %s\n", cmdname(argv[0]),
                         strerror(rc = errno));
 
         return rc;
 }
-#endif
 
-int jt_dev_probe(int argc, char **argv) 
+int jt_obd_connect(int argc, char **argv)
 {
-        int rc;
         struct obd_ioctl_data data;
+        int rc;
 
         IOCINIT(data);
+
         do_disconnect(argv[0], 1);
 
         if (argc != 1)
                 return CMD_HELP;
 
-        rc = ioctl(fd, OBD_IOC_CONNECT , &data);
+        rc = ioctl(fd, OBD_IOC_CONNECT, &data);
         if (rc < 0)
                 fprintf(stderr, "error: %s: %x %s\n", cmdname(argv[0]),
                         OBD_IOC_CONNECT, strerror(rc = errno));
-        else
+        else {
                 conn_addr = data.ioc_addr;
                 conn_cookie = data.ioc_cookie;
+        }
         return rc;
 }
 
-int jt_dev_close(int argc, char **argv) 
+int jt_obd_disconnect(int argc, char **argv)
 {
         if (argc != 1)
                 return CMD_HELP;
@@ -361,11 +489,12 @@ int jt_opt_device(int argc, char **argv)
         if (!rc) {
                 arg2[0] = "connect";
                 arg2[1] = NULL;
-                rc = jt_dev_probe(1, arg2);
+                rc = jt_obd_connect(1, arg2);
         }
 
         if (!rc)
                 rc = Parser_execarg(argc - 2, argv + 2, cmdlist);
+
         ret = do_disconnect(argv[0], 0);
         if (!rc)
                 rc = ret;
@@ -373,81 +502,107 @@ int jt_opt_device(int argc, char **argv)
         return rc;
 }
 
-
-int jt_dev_attach(int argc, char **argv) 
+int jt_opt_threads(int argc, char **argv)
 {
-        int rc;
-        struct obd_ioctl_data data;
-
-        IOCINIT(data);
-        if (argc != 2 && argc != 3 && argc != 4)
-                return CMD_HELP;
+        int threads, next_thread;
+        int verbose;
+        int rc = 0;
+        int i;
 
-        data.ioc_inllen1 =  strlen(argv[1]) + 1;
-        data.ioc_inlbuf1 = argv[1];
-        if (argc >= 3) {
-                data.ioc_inllen2 = strlen(argv[2]) + 1;
-                data.ioc_inlbuf2 = argv[2];
+        if (argc < 5) {
+                fprintf(stderr,
+                        "usage: %s numthreads verbose devno <cmd [args ...]>\n",
+                        argv[0]);
+                return -1;
         }
 
-        if (argc == 4) {
-                data.ioc_inllen3 = strlen(argv[3]) + 1;
-                data.ioc_inlbuf3 = argv[3];
-        }
+        threads = strtoul(argv[1], NULL, 0);
 
-        if (obd_ioctl_pack(&data, &buf, max)) {
-                fprintf(stderr, "error: %s: invalid ioctl\n",cmdname(argv[0]));
-                return -2;
+        verbose = get_verbose(argv[2]);
+
+        if (verbose != 0)
+                printf("%s: starting %d threads on device %s running %s\n",
+                       argv[0], threads, argv[3], argv[4]);
+
+        SHMEM_RESET();
+
+        for (i = 1, next_thread = verbose; i <= threads; i++) {
+                rc = fork();
+                if (rc < 0) {
+                        fprintf(stderr, "error: %s: #%d - %s\n", argv[0], i,
+                                strerror(rc = errno));
+                        break;
+                } else if (rc == 0) {
+                        thread = i;
+                        argv[2] = "--device";
+                        return jt_opt_device(argc - 2, argv + 2);
+                } else if (be_verbose(verbose, NULL, i, &next_thread, threads))
+                        printf("%s: thread #%d (PID %d) started\n",
+                               argv[0], i, rc);
+                rc = 0;
         }
 
-        rc = ioctl(fd, OBD_IOC_ATTACH , buf);
-        if (rc < 0)
-                fprintf(stderr, "error: %s: %x %s\n", cmdname(argv[0]),
-                        OBD_IOC_ATTACH, strerror(rc = errno));
-        else if (argc == 3) {
-                char name[1024];
-                if (strlen(argv[2]) > 128) {
-                        printf("Name too long to set environment\n");
-                        return -EINVAL;
-                }
-                snprintf(name, 512, "LUSTRE_DEV_%s", argv[2]);
-                rc = setenv(name, argv[1], 1);
-                if (rc) {
-                        printf("error setting env variable %s\n", name);
+        if (!thread) {          /* parent process */
+                int live_threads = threads;
+
+                while (live_threads > 0) {
+                        int status;
+                        pid_t ret;
+
+                        ret = waitpid(0, &status, verbose < 0 ? WNOHANG : 0);
+                        if (ret == 0) {
+                                if (verbose >= 0)
+                                        abort();
+
+                                sleep(-verbose);
+                                SHMEM_SNAP(threads);
+                                continue;
+                        }
+
+                        if (ret < 0) {
+                                fprintf(stderr, "error: %s: wait - %s\n",
+                                        argv[0], strerror(errno));
+                                if (!rc)
+                                        rc = errno;
+                        } else {
+                                /*
+                                 * This is a hack.  We _should_ be able to use
+                                 * WIFEXITED(status) to see if there was an
+                                 * error, but it appears to be broken and it
+                                 * always returns 1 (OK).  See wait(2).
+                                 */
+                                int err = WEXITSTATUS(status);
+                                if (err)
+                                        fprintf(stderr,
+                                                "%s: PID %d had rc=%d\n",
+                                                argv[0], ret, err);
+                                if (!rc)
+                                        rc = err;
+
+                                live_threads--;
+                        }
                 }
         }
 
         return rc;
 }
 
-int jt_dev_setup(int argc, char **argv) 
+int jt_obd_detach(int argc, char **argv)
 {
-        int rc;
         struct obd_ioctl_data data;
+        int rc;
 
         IOCINIT(data);
-        if (argc > 3)
-                return CMD_HELP;
-                
-        data.ioc_dev = -1;
-        if (argc > 1) {
-                data.ioc_dev = parse_devname(argv[0], argv[1]);
-                if (data.ioc_dev < 0) 
-                        return rc = -1;
 
-                data.ioc_inllen1 = strlen(argv[1]) + 1;
-                data.ioc_inlbuf1 = argv[1];
-        }
-        if ( argc == 3 ) {
-                data.ioc_inllen2 = strlen(argv[2]) + 1;
-                data.ioc_inlbuf2 = argv[2];
-        }
+        if (argc != 1) 
+                return CMD_HELP;
 
         if (obd_ioctl_pack(&data, &buf, max)) {
                 fprintf(stderr, "error: %s: invalid ioctl\n", cmdname(argv[0]));
                 return -2;
         }
-        rc = ioctl(fd, OBD_IOC_SETUP , buf);
+
+        rc = ioctl(fd, OBD_IOC_DETACH, buf);
         if (rc < 0)
                 fprintf(stderr, "error: %s: %s\n", cmdname(argv[0]),
                         strerror(rc = errno));
@@ -455,119 +610,191 @@ int jt_dev_setup(int argc, char **argv)
         return rc;
 }
 
-int jt_dev_detach(int argc, char **argv) 
+int jt_obd_cleanup(int argc, char **argv)
 {
-        int rc;
         struct obd_ioctl_data data;
+        int rc;
 
         IOCINIT(data);
-        if (argc != 1)
-                return CMD_HELP;
 
-        if (obd_ioctl_pack(&data, &buf, max)) {
-                fprintf(stderr, "error: %s: invalid ioctl\n", cmdname(argv[0]));
-                return -2;
-        }
+        if (argc != 1) 
+                return CMD_HELP;
 
-        rc = ioctl(fd, OBD_IOC_DETACH , buf);
+        rc = ioctl(fd, OBD_IOC_CLEANUP, &data);
         if (rc < 0)
                 fprintf(stderr, "error: %s: %s\n", cmdname(argv[0]),
-                        strerror(rc=errno));
+                        strerror(rc = errno));
 
         return rc;
 }
 
-int jt_dev_cleanup(int argc, char **argv) 
+int jt_obd_newdev(int argc, char **argv)
 {
         int rc;
         struct obd_ioctl_data data;
 
+        if (getfd(argv[0]))
+                return -1;
+
         IOCINIT(data);
-        if (argc != 1)
+
+        if (argc != 1) 
+                return CMD_HELP;
+
+        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;
+}
+
+int jt_obd_list(int argc, char **argv)
+{
+        int rc;
+        char buf[1024];
+        struct obd_ioctl_data *data = (struct obd_ioctl_data *)buf;
+
+        if (getfd(argv[0]))
+                return -1;
+
+        memset(buf, 0, sizeof(buf));
+        data->ioc_version = OBD_IOCTL_VERSION;
+        data->ioc_addr = conn_addr;
+        data->ioc_cookie = conn_addr;
+        data->ioc_len = sizeof(buf);
+        data->ioc_inllen1 = sizeof(buf) - size_round(sizeof(*data));
+
+        if (argc != 1) 
                 return CMD_HELP;
 
-        rc = ioctl(fd, OBD_IOC_CLEANUP , &data);
+        rc = ioctl(fd, OBD_IOC_LIST, data);
         if (rc < 0)
-                CERROR("error: %s: %s\n", cmdname(argv[0]),
-                        strerror(rc=errno));
+                fprintf(stderr, "error: %s: %s\n", cmdname(argv[0]),
+                        strerror(rc = errno));
+        else {
+                printf("%s", data->ioc_bulk);
+        }
+
         return rc;
 }
 
-int jt_dev_lov_config(int argc, char **argv) 
+int jt_obd_attach(int argc, char **argv)
 {
         struct obd_ioctl_data data;
-        struct lov_desc desc; 
-        uuid_t *uuidarray;
-        int rc, size, i;
+        int rc;
 
         IOCINIT(data);
-        if (argc <= 6)
+
+        if (argc != 2 && argc != 3 && argc != 4) 
                 return CMD_HELP;
 
-        if (strlen(argv[1]) > sizeof(uuid_t) - 1) { 
-                fprintf(stderr, "lov_config: no %dB memory for uuid's\n", 
-                        strlen(argv[1]));
-                return -ENOMEM;
+        data.ioc_inllen1 = strlen(argv[1]) + 1;
+        data.ioc_inlbuf1 = argv[1];
+        if (argc >= 3) {
+                data.ioc_inllen2 = strlen(argv[2]) + 1;
+                data.ioc_inlbuf2 = argv[2];
         }
-            
-        memset(&desc, 0, sizeof(desc)); 
-        strcpy(desc.ld_uuid, argv[1]); 
-        desc.ld_default_stripe_count = strtoul(argv[2], NULL, 0); 
-        desc.ld_default_stripe_size = (__u64) strtoul(argv[3], NULL, 0); 
-        desc.ld_default_stripe_offset = (__u64) strtoul(argv[3], NULL, 0); 
-        desc.ld_pattern = strtoul(argv[5], NULL, 0); 
-        desc.ld_tgt_count = argc - 6;
 
+        if (argc == 4) {
+                data.ioc_inllen3 = strlen(argv[3]) + 1;
+                data.ioc_inlbuf3 = argv[3];
+        }
 
-        size = sizeof(uuid_t) * desc.ld_tgt_count;
-        uuidarray = malloc(size);
-        if (!uuidarray) { 
-                fprintf(stderr, "lov_config: no %dB memory for uuid's\n", 
-                        size);
-                return -ENOMEM;
+        if (obd_ioctl_pack(&data, &buf, max)) {
+                fprintf(stderr, "error: %s: invalid ioctl\n", cmdname(argv[0]));
+                return -2;
         }
-        memset(uuidarray, 0, size); 
-        for (i=6 ; i < argc ; i++) { 
-                char *buf = (char *) (uuidarray + i -6 );
-                if (strlen(argv[i]) >= sizeof(uuid_t)) { 
-                        fprintf(stderr, "lov_config: arg %d (%s) too long\n",  
-                                i, argv[i]);
-                        free(uuidarray);
+
+        rc = ioctl(fd, OBD_IOC_ATTACH, buf);
+        if (rc < 0)
+                fprintf(stderr, "error: %s: %x %s\n", cmdname(argv[0]),
+                        OBD_IOC_ATTACH, strerror(rc = errno));
+        else if (argc == 3) {
+                char name[1024];
+                if (strlen(argv[2]) > 128) {
+                        printf("Name too long to set environment\n");
                         return -EINVAL;
                 }
-                strcpy(buf, argv[i]); 
+                snprintf(name, 512, "LUSTRE_DEV_%s", argv[2]);
+                rc = setenv(name, argv[1], 1);
+                if (rc) {
+                        printf("error setting env variable %s\n", name);
+                }
         }
 
-        data.ioc_inllen1 = sizeof(desc); 
-        data.ioc_inlbuf1 = (char *)&desc;
-        data.ioc_inllen2 = size;
-        data.ioc_inlbuf2 = (char *)uuidarray;
+        return rc;
+}
 
-        if (obd_ioctl_pack(&data, &buf, max)) {
-                fprintf(stderr, "error: %s: invalid ioctl\n",cmdname(argv[0]));
-                return -EINVAL;
+int jt_obd_name2dev(int argc, char **argv)
+{
+        int rc;
+        if (argc != 2) 
+                return CMD_HELP;
+
+        rc = do_name2dev(argv[0], argv[1]);
+        if (rc >= N2D_OFF) {
+                int dev = rc - N2D_OFF;
+                rc = do_device(argv[0], dev);
+                if (rc == 0)
+                        printf("%d\n", dev);
         }
+        return rc;
+}
+
+int jt_obd_setup(int argc, char **argv)
+{
+        struct obd_ioctl_data data;
+        int rc;
 
-        rc = ioctl(fd, OBD_IOC_LOV_CONFIG , buf);
+        IOCINIT(data);
+
+        if (argc > 3) 
+                return CMD_HELP;
+
+        data.ioc_dev = -1;
+        if (argc > 1) {
+                data.ioc_dev = parse_devname(argv[0], argv[1]);
+                if (data.ioc_dev < 0)
+                        return -1;
+                data.ioc_inllen1 = strlen(argv[1]) + 1;
+                data.ioc_inlbuf1 = argv[1];
+        }
+        if (argc == 3) {
+                data.ioc_inllen2 = strlen(argv[2]) + 1;
+                data.ioc_inlbuf2 = argv[2];
+        }
+
+        if (obd_ioctl_pack(&data, &buf, max)) {
+                fprintf(stderr, "error: %s: invalid ioctl\n", cmdname(argv[0]));
+                return -2;
+        }
+        rc = ioctl(fd, OBD_IOC_SETUP, buf);
         if (rc < 0)
-                fprintf(stderr, "lov_config: error: %s: %s\n", 
-                        cmdname(argv[0]),strerror(rc = errno));
-        free(uuidarray);
+                fprintf(stderr, "error: %s: %s\n", cmdname(argv[0]),
+                        strerror(rc = errno));
+
         return rc;
 }
 
-#if 0
-int jt_dev_create(int argc, char **argv) {
+
+int jt_obd_create(int argc, char **argv)
+{
         struct obd_ioctl_data data;
         struct timeval next_time;
         int count = 1, next_count;
         int verbose;
-        int i;
+        int rc = 0, i;
 
         IOCINIT(data);
-        if (argc < 2 || argc > 4)
-                return CMD_HELP;
-
+        if (argc < 2 || argc > 4) {
+                fprintf(stderr, "usage: %s num [mode] [verbose]\n",
+                        cmdname(argv[0]));
+                return -1;
+        }
         count = strtoul(argv[1], NULL, 0);
 
         if (argc > 2)
@@ -582,8 +809,9 @@ int jt_dev_create(int argc, char **argv) {
         gettimeofday(&next_time, NULL);
         next_time.tv_sec -= verbose;
 
-        for (i = 1, next_count = verbose; i <= count ; i++) {
-                rc = ioctl(fd, OBD_IOC_CREATE , &data);
+        for (i = 1, next_count = verbose; i <= count; i++) {
+                rc = ioctl(fd, OBD_IOC_CREATE, &data);
+                SHMEM_BUMP();
                 if (rc < 0) {
                         fprintf(stderr, "error: %s: #%d - %s\n",
                                 cmdname(argv[0]), i, strerror(rc = errno));
@@ -596,42 +824,42 @@ int jt_dev_create(int argc, char **argv) {
         return rc;
 }
 
-int jt_dev_destroy(int argc, char **argv) {
+int jt_obd_setattr(int argc, char **argv)
+{
         struct obd_ioctl_data data;
+        int rc;
 
         IOCINIT(data);
-        if (argc != 2) {
-                fprintf(stderr, "usage: %s id\n", cmdname(argv[0]));
-                return -1;
-        }
+        if (argc != 2)
+                return CMD_HELP;
 
         data.ioc_obdo1.o_id = strtoul(argv[1], NULL, 0);
-        data.ioc_obdo1.o_mode = S_IFREG|0644;
+        data.ioc_obdo1.o_mode = S_IFREG | strtoul(argv[2], NULL, 0);
+        data.ioc_obdo1.o_valid = OBD_MD_FLMODE;
 
-        rc = ioctl(fd, OBD_IOC_DESTROY , &data);
+        rc = ioctl(fd, OBD_IOC_SETATTR, &data);
         if (rc < 0)
                 fprintf(stderr, "error: %s: %s\n", cmdname(argv[0]),
                         strerror(rc = errno));
 
         return rc;
 }
-#endif
 
-/* Device configuration commands */
-int jt_dev_setattr(int argc, char **argv) 
+int jt_obd_destroy(int argc, char **argv)
 {
-        int rc;
         struct obd_ioctl_data data;
+        int rc;
 
         IOCINIT(data);
-        if (argc != 2)
-                return CMD_HELP;
-                
+        if (argc != 2) {
+                fprintf(stderr, "usage: %s id\n", cmdname(argv[0]));
+                return -1;
+        }
+
         data.ioc_obdo1.o_id = strtoul(argv[1], NULL, 0);
-        data.ioc_obdo1.o_mode = S_IFREG | strtoul(argv[2], NULL, 0);
-        data.ioc_obdo1.o_valid = OBD_MD_FLMODE;
+        data.ioc_obdo1.o_mode = S_IFREG | 0644;
 
-        rc = ioctl(fd, OBD_IOC_SETATTR , &data);
+        rc = ioctl(fd, OBD_IOC_DESTROY, &data);
         if (rc < 0)
                 fprintf(stderr, "error: %s: %s\n", cmdname(argv[0]),
                         strerror(rc = errno));
@@ -639,12 +867,12 @@ int jt_dev_setattr(int argc, char **argv)
         return rc;
 }
 
-int jt_dev_getattr(int argc, char **argv) 
+int jt_obd_getattr(int argc, char **argv)
 {
-        int rc;
         struct obd_ioctl_data data;
+        int rc;
 
-        if (argc != 2)
+        if (argc != 2) 
                 return CMD_HELP;
 
         IOCINIT(data);
@@ -654,10 +882,10 @@ int jt_dev_getattr(int argc, char **argv)
         data.ioc_obdo1.o_valid = 0xffffffff;
         printf("%s: object id %Ld\n", cmdname(argv[0]), data.ioc_obdo1.o_id);
 
-        rc = ioctl(fd, OBD_IOC_GETATTR , &data);
+        rc = ioctl(fd, OBD_IOC_GETATTR, &data);
         if (rc) {
                 fprintf(stderr, "error: %s: %s\n", cmdname(argv[0]),
-                        strerror(rc=errno));
+                        strerror(rc = errno));
         } else {
                 printf("%s: object id %Ld, mode %o\n", cmdname(argv[0]),
                        data.ioc_obdo1.o_id, data.ioc_obdo1.o_mode);
@@ -665,13 +893,13 @@ int jt_dev_getattr(int argc, char **argv)
         return rc;
 }
 
-int jt_dev_test_getattr(int argc, char **argv) 
+int jt_obd_test_getattr(int argc, char **argv)
 {
-        int rc = 0;
         struct obd_ioctl_data data;
         struct timeval start, next_time;
         int i, count, next_count;
         int verbose;
+        int rc = 0;
 
         if (argc != 2 && argc != 3)
                 return CMD_HELP;
@@ -689,20 +917,24 @@ int jt_dev_test_getattr(int argc, char **argv)
         gettimeofday(&start, NULL);
         next_time.tv_sec = start.tv_sec - verbose;
         next_time.tv_usec = start.tv_usec;
-        printf("%s: getting %d attrs (testing only): %s", cmdname(argv[0]),
-               count, ctime(&start.tv_sec));
+        if (verbose != 0)
+                printf("%s: getting %d attrs (testing only): %s",
+                       cmdname(argv[0]), count, ctime(&start.tv_sec));
 
         for (i = 1, next_count = verbose; i <= count; i++) {
-                rc = ioctl(fd, OBD_IOC_GETATTR , &data);
+                rc = ioctl(fd, OBD_IOC_GETATTR, &data);
+                SHMEM_BUMP();
                 if (rc < 0) {
                         fprintf(stderr, "error: %s: #%d - %s\n",
                                 cmdname(argv[0]), i, strerror(rc = errno));
                         break;
                 } else {
-                        if (be_verbose(verbose, &next_time, i,&next_count,count))
-                        printf("%s: got attr #%d\n", cmdname(argv[0]), i);
-               }
-       }
+                        if (be_verbose
+                            (verbose, &next_time, i, &next_count, count))
+                                printf("%s: got attr #%d\n", cmdname(argv[0]),
+                                       i);
+                }
+        }
 
         if (!rc) {
                 struct timeval end;
@@ -713,16 +945,16 @@ int jt_dev_test_getattr(int argc, char **argv)
                 diff = difftime(&end, &start);
 
                 --i;
-                printf("%s: %d attrs in %.4gs (%.4g attr/s): %s",
-                       cmdname(argv[0]), i, diff, (double)i / diff,
-                       ctime(&end.tv_sec));
+                if (verbose != 0)
+                        printf("%s: %d attrs in %.4gs (%.4g attr/s): %s",
+                               cmdname(argv[0]), i, diff, (double)i / diff,
+                               ctime(&end.tv_sec));
         }
         return rc;
 }
 
-int jt_dev_test_brw(int argc, char **argv) 
+int jt_obd_test_brw(int argc, char **argv)
 {
-        int rc = 0;
         struct obd_ioctl_data data;
         struct timeval start, next_time;
         char *bulk, *b;
@@ -730,8 +962,9 @@ int jt_dev_test_brw(int argc, char **argv)
         int verbose = 1, write = 0, rw;
         int i, o, p;
         int len;
+        int rc = 0;
 
-        if (argc < 2 || argc > 6)
+        if (argc < 2 || argc > 6) 
                 return CMD_HELP;
 
         count = strtoul(argv[1], NULL, 0);
@@ -760,7 +993,7 @@ int jt_dev_test_brw(int argc, char **argv)
 
         bulk = calloc(obdos, len);
         if (!bulk) {
-                fprintf(stderr,"error: %s: no memory allocating %dx%d pages\n",
+                fprintf(stderr, "error: %s: no memory allocating %dx%d pages\n",
                         cmdname(argv[0]), obdos, pages);
                 return -2;
         }
@@ -780,9 +1013,10 @@ int jt_dev_test_brw(int argc, char **argv)
         next_time.tv_sec = start.tv_sec - verbose;
         next_time.tv_usec = start.tv_usec;
 
-        printf("%s: %s %d (%dx%d pages) (testing only): %s",
-               cmdname(argv[0]), write ? "writing" : "reading",
-               count, obdos, pages, ctime(&start.tv_sec));
+        if (verbose != 0)
+                printf("%s: %s %d (%dx%d pages) (testing only): %s",
+                       cmdname(argv[0]), write ? "writing" : "reading",
+                       count, obdos, pages, ctime(&start.tv_sec));
 
         /*
          * We will put in the start time (and loop count inside the loop)
@@ -807,12 +1041,14 @@ int jt_dev_test_brw(int argc, char **argv)
                 }
 
                 rc = ioctl(fd, rw, &data);
+                SHMEM_BUMP();
                 if (rc) {
                         fprintf(stderr, "error: %s: #%d - %s on %s\n",
                                 cmdname(argv[0]), i, strerror(rc = errno),
                                 write ? "write" : "read");
                         break;
-                } else if (be_verbose(verbose,&next_time,i,&next_count,count))
+                } else if (be_verbose
+                           (verbose, &next_time, i, &next_count, count))
                         printf("%s: %s number %d\n", cmdname(argv[0]),
                                write ? "write" : "read", i);
         }
@@ -828,21 +1064,88 @@ int jt_dev_test_brw(int argc, char **argv)
                 diff = difftime(&end, &start);
 
                 --i;
-                printf("%s: %s %dx%dx%d pages in %.4gs (%.4g pg/s): %s",
-                       cmdname(argv[0]), write ? "wrote" : "read", obdos,
-                       pages, i, diff, (double)obdos * i * pages / diff,
-                       ctime(&end.tv_sec));
+                if (verbose != 0)
+                        printf("%s: %s %dx%dx%d pages in %.4gs (%.4g pg/s): %s",
+                               cmdname(argv[0]), write ? "wrote" : "read",
+                               obdos, pages, i, diff,
+                               (double)obdos * i * pages / diff,
+                               ctime(&end.tv_sec));
         }
         return rc;
 }
 
-int jt_dev_test_ldlm(int argc, char **argv) 
+int jt_obd_lov_config(int argc, char **argv)
 {
-        int rc;
         struct obd_ioctl_data data;
+        struct lov_desc desc;
+        uuid_t *uuidarray;
+        int rc, size, i;
+        IOCINIT(data);
+
+        printf("WARNING: obdctl lovconfig NOT MAINTAINED\n");
+        return -1;
+
+        if (argc <= 6)
+                return CMD_HELP;
+
+        if (strlen(argv[1]) > sizeof(uuid_t) - 1) {
+                fprintf(stderr, "lov_config: no %dB memory for uuid's\n",
+                        strlen(argv[1]));
+                return -ENOMEM;
+        }
+
+        memset(&desc, 0, sizeof(desc));
+        strcpy(desc.ld_uuid, argv[1]);
+        desc.ld_default_stripe_count = strtoul(argv[2], NULL, 0);
+        desc.ld_default_stripe_size = strtoul(argv[3], NULL, 0);
+        desc.ld_default_stripe_offset = (__u64) strtoul(argv[4], NULL, 0); 
+        desc.ld_pattern = strtoul(argv[5], NULL, 0);
+        desc.ld_tgt_count = argc - 6;
+
+
+        size = sizeof(uuid_t) * desc.ld_tgt_count;
+        uuidarray = malloc(size);
+        if (!uuidarray) {
+                fprintf(stderr, "lov_config: no %dB memory for uuid's\n", size);
+                return -ENOMEM;
+        }
+        memset(uuidarray, 0, size);
+        for (i = 6; i < argc; i++) {
+                char *buf = (char *)(uuidarray + i - 6);
+                if (strlen(argv[i]) >= sizeof(uuid_t)) {
+                        fprintf(stderr, "lov_config: arg %d (%s) too long\n",
+                                i, argv[i]);
+                        free(uuidarray);
+                        return -EINVAL;
+                }
+                strcpy(buf, argv[i]);
+        }
+
+        data.ioc_inllen1 = sizeof(desc);
+        data.ioc_inlbuf1 = (char *)&desc;
+        data.ioc_inllen2 = size;
+        data.ioc_inlbuf2 = (char *)uuidarray;
+
+        if (obd_ioctl_pack(&data, &buf, max)) {
+                fprintf(stderr, "error: %s: invalid ioctl\n", cmdname(argv[0]));
+                return -EINVAL;
+        }
+
+        rc = ioctl(fd, OBD_IOC_LOV_CONFIG, buf);
+        if (rc < 0)
+                fprintf(stderr, "lov_config: error: %s: %s\n",
+                        cmdname(argv[0]), strerror(rc = errno));
+        free(uuidarray);
+        return rc;
+}
+
+int jt_obd_test_ldlm(int argc, char **argv)
+{
+        struct obd_ioctl_data data;
+        int rc;
 
         IOCINIT(data);
-        if (argc != 1)
+        if (argc != 1) 
                 return CMD_HELP;
 
         rc = ioctl(fd, IOC_LDLM_TEST, &data);
@@ -852,3 +1155,65 @@ int jt_dev_test_ldlm(int argc, char **argv)
         return rc;
 }
 
+int jt_obd_dump_ldlm(int argc, char **argv)
+{
+        struct obd_ioctl_data data;
+        int rc;
+
+        IOCINIT(data);
+        if (argc != 1) {
+                fprintf(stderr, "usage: %s\n", cmdname(argv[0]));
+                return 1;
+        }
+
+        rc = ioctl(fd, IOC_LDLM_DUMP, &data);
+        if (rc)
+                fprintf(stderr, "error: %s failed: %s\n",
+                        cmdname(argv[0]), strerror(rc = errno));
+        return rc;
+}
+
+int jt_obd_newconn(int argc, char **argv)
+{
+        int rc;
+        struct obd_ioctl_data data;
+
+        IOCINIT(data);
+        if (argc != 1) 
+                return CMD_HELP;
+
+        rc = ioctl(fd, OBD_IOC_RECOVD_NEWCONN, &data);
+        if (rc < 0)
+                fprintf(stderr, "error: %s: %s\n", cmdname(argv[0]),
+                        strerror(rc = errno));
+
+        return rc;
+}
+
+static void signal_server(int sig)
+{
+        if (sig == SIGINT) {
+                do_disconnect("sigint", 1);
+                exit(1);
+        } else
+                fprintf(stderr, "%s: got signal %d\n", cmdname("sigint"), sig);
+}
+
+int obd_initialize(int argc, char **argv) 
+{
+        SHMEM_SETUP();
+        return 0;
+}
+
+
+void obd_cleanup(int argc, char **argv) 
+{
+        struct sigaction sigact;
+
+        sigact.sa_handler = signal_server;
+        sigfillset(&sigact.sa_mask);
+        sigact.sa_flags = SA_RESTART;
+        sigaction(SIGINT, &sigact, NULL);
+
+        do_disconnect(argv[0], 1);
+}
index 6fbd1a7..6714200 100644 (file)
 
 
 #include <stdlib.h>
-#include <sys/ioctl.h>
-#include <fcntl.h>
-#include <sys/socket.h>
-#include <sys/types.h>
-#include <sys/wait.h>
-#include <sys/stat.h>
 #include <stdio.h>
-#include <stdarg.h>
-#include <signal.h>
-#define printk printf
 
-#include <linux/lustre_lib.h>
-#include <linux/lustre_idl.h>
-#include <linux/lustre_dlm.h>
-
-#include <libxml/xmlmemory.h>
-#include <libxml/parser.h>
-
-#include <unistd.h>
-#include <sys/un.h>
-#include <time.h>
-#include <sys/time.h>
-#include <netinet/in.h>
-#include <errno.h>
-#include <string.h>
-
-#include <asm/page.h>           /* needed for PAGE_SIZE - rread */
-
-#define __KERNEL__
-#include <linux/list.h>
-#undef __KERNEL__
-
-#include "parser.h"
-#include <stdio.h>
-
-#define SHMEM_STATS 1
-#if SHMEM_STATS
-# include <sys/ipc.h>
-# include <sys/shm.h>
-
-# define MAX_SHMEM_COUNT 1024
-static long long *shared_counters;
-static long long counter_snapshot[2][MAX_SHMEM_COUNT];
-struct timeval prev_time;
-#endif
-
-static int jt_newdev(int argc, char **argv);
-static int jt_attach(int argc, char **argv);
-static int jt_setup(int argc, char **argv);
-
-
-int fd = -1;
-uint64_t conn_addr = -1;
-uint64_t conn_cookie;
-char rawbuf[8192];
-char *buf = rawbuf;
-int max = 8192;
-int thread;
-int rc = 0;
-
-#define IOCINIT(data)                                                   \
-do {                                                                    \
-        memset(&data, 0, sizeof(data));                                 \
-        data.ioc_version = OBD_IOCTL_VERSION;                           \
-        data.ioc_addr = conn_addr;                                      \
-        data.ioc_cookie = conn_cookie;                                  \
-        data.ioc_len = sizeof(data);                                    \
-        if (fd < 0) {                                                   \
-                fprintf(stderr, "No device open, use device\n");        \
-                return 1;                                               \
-        }                                                               \
-} while (0)
-
-/*
-    pack "LL LL LL LL LL LL LL L L L L L L L L L a60 a60 L L L",
-    $obdo->{id}, 0,
-    $obdo->{gr}, 0,
-    $obdo->{atime}, 0,
-    $obdo->{mtime}, 0 ,
-    $obdo->{ctime}, 0,
-    $obdo->{size}, 0,
-    $obdo->{blocks}, 0,
-    $obdo->{blksize},
-    $obdo->{mode},
-    $obdo->{uid},
-    $obdo->{gid},
-    $obdo->{flags},
-    $obdo->{obdflags},
-    $obdo->{nlink},
-    $obdo->{generation},
-    $obdo->{valid},
-    $obdo->{inline},
-    $obdo->{obdmd},
-    0, 0, # struct list_head
-    0;  #  struct obd_ops
-}
-
-*/
-
-char *obdo_print(struct obdo *obd)
-{
-        char buf[1024];
-
-        sprintf(buf, "id: %Ld\ngrp: %Ld\natime: %Ld\nmtime: %Ld\nctime: %Ld\n"
-                "size: %Ld\nblocks: %Ld\nblksize: %d\nmode: %o\nuid: %d\n"
-                "gid: %d\nflags: %x\nobdflags: %x\nnlink: %d,\nvalid %x\n",
-                obd->o_id,
-                obd->o_gr,
-                obd->o_atime,
-                obd->o_mtime,
-                obd->o_ctime,
-                obd->o_size,
-                obd->o_blocks,
-                obd->o_blksize,
-                obd->o_mode,
-                obd->o_uid,
-                obd->o_gid,
-                obd->o_flags, obd->o_obdflags, obd->o_nlink, obd->o_valid);
-        return strdup(buf);
-}
-
-static char *cmdname(char *func)
-{
-        static char buf[512];
-
-        if (thread) {
-                sprintf(buf, "%s-%d", func, thread);
-                return buf;
-        }
-
-        return func;
-}
-
-int getfd(char *func)
-{
-        if (fd == -1)
-                fd = open("/dev/obd", O_RDWR);
-        if (fd == -1) {
-                fprintf(stderr, "error: %s: opening /dev/obd: %s\n",
-                        cmdname(func), strerror(errno));
-                return -1;
-        }
-        return 0;
-}
-
-#define difftime(a, b)                                          \
-        ((double)(a)->tv_sec - (b)->tv_sec +                    \
-         ((double)((a)->tv_usec - (b)->tv_usec) / 1000000))
-
-static int be_verbose(int verbose, struct timeval *next_time,
-                      int num, int *next_num, int num_total)
-{
-        struct timeval now;
-
-        if (!verbose)
-                return 0;
-
-        if (next_time != NULL)
-                gettimeofday(&now, NULL);
-
-        /* A positive verbosity means to print every X iterations */
-        if (verbose > 0 &&
-            (next_num == NULL || num >= *next_num || num >= num_total)) {
-                *next_num += verbose;
-                if (next_time) {
-                        next_time->tv_sec = now.tv_sec - verbose;
-                        next_time->tv_usec = now.tv_usec;
-                }
-                return 1;
-        }
-
-        /* A negative verbosity means to print at most each X seconds */
-        if (verbose < 0 && next_time != NULL && difftime(&now, next_time) >= 0) {
-                next_time->tv_sec = now.tv_sec - verbose;
-                next_time->tv_usec = now.tv_usec;
-                if (next_num)
-                        *next_num = num;
-                return 1;
-        }
-
-        return 0;
-}
-
-static int get_verbose(const char *arg)
-{
-        int verbose;
-
-        if (!arg || arg[0] == 'v')
-                verbose = 1;
-        else if (arg[0] == 's' || arg[0] == 'q')
-                verbose = 0;
-        else
-                verbose = (int)strtoul(arg, NULL, 0);
-
-        if (verbose < 0)
-                printf("Print status every %d seconds\n", -verbose);
-        else if (verbose == 1)
-                printf("Print status every operation\n");
-        else if (verbose > 1)
-                printf("Print status every %d operations\n", verbose);
-
-        return verbose;
-}
-
-static int do_disconnect(char *func, int verbose)
-{
-        struct obd_ioctl_data data;
-
-        if (conn_addr == -1)
-                return 0;
-
-        IOCINIT(data);
-
-        rc = ioctl(fd, OBD_IOC_DISCONNECT, &data);
-        if (rc < 0) {
-                fprintf(stderr, "error: %s: %x %s\n", cmdname(func),
-                        OBD_IOC_DISCONNECT, strerror(errno));
-        } else {
-                if (verbose)
-                        printf("%s: disconnected conn %Lx\n", cmdname(func),
-                               conn_addr);
-                conn_addr = -1;
-        }
-
-        return rc;
-}
-
-#if SHMEM_STATS
-static void shmem_setup(void)
-{
-        int shmid = shmget(IPC_PRIVATE, sizeof(counter_snapshot[0]), 0600);
-
-        if (shmid == -1) {
-                fprintf(stderr, "Can't create shared memory counters: %s\n",
-                        strerror(errno));
-                return;
-        }
-
-        shared_counters = (long long *)shmat(shmid, NULL, 0);
-
-        if (shared_counters == (long long *)(-1)) {
-                fprintf(stderr, "Can't attach shared memory counters: %s\n",
-                        strerror(errno));
-                shared_counters = NULL;
-                return;
-        }
-}
-
-static inline void shmem_reset(void)
-{
-        if (shared_counters == NULL)
-                return;
-
-        memset(shared_counters, 0, sizeof(counter_snapshot[0]));
-        memset(counter_snapshot, 0, sizeof(counter_snapshot));
-        gettimeofday(&prev_time, NULL);
-}
-
-static inline void shmem_bump(void)
-{
-        if (shared_counters == NULL || thread <= 0 || thread > MAX_SHMEM_COUNT)
-                return;
-
-        shared_counters[thread - 1]++;
-}
-
-static void shmem_snap(int n)
-{
-        struct timeval this_time;
-        int non_zero = 0;
-        long long total = 0;
-        double secs;
-        int i;
-
-        if (shared_counters == NULL || n > MAX_SHMEM_COUNT)
-                return;
-
-        memcpy(counter_snapshot[1], counter_snapshot[0],
-               n * sizeof(counter_snapshot[0][0]));
-        memcpy(counter_snapshot[0], shared_counters,
-               n * sizeof(counter_snapshot[0][0]));
-        gettimeofday(&this_time, NULL);
-
-        for (i = 0; i < n; i++) {
-                long long this_count =
-                        counter_snapshot[0][i] - counter_snapshot[1][i];
-
-                if (this_count != 0) {
-                        non_zero++;
-                        total += this_count;
-                }
-        }
-
-        secs = (this_time.tv_sec + this_time.tv_usec / 1000000.0) -
-                (prev_time.tv_sec + prev_time.tv_usec / 1000000.0);
-
-        printf("%d/%d Total: %f/second\n", non_zero, n, total / secs);
-
-        prev_time = this_time;
-}
-
-#define SHMEM_SETUP()  shmem_setup()
-#define SHMEM_RESET()  shmem_reset()
-#define SHMEM_BUMP()   shmem_bump()
-#define SHMEM_SNAP(n)  shmem_snap(n)
-#else
-#define SHMEM_SETUP()
-#define SHMEM_RESET()
-#define SHMEM_BUMP()
-#define SHMEM_SNAP(n)
-#endif
-
-extern command_t cmdlist[];
-
-static int xml_command(char *cmd, ...)
-{
-        va_list args;
-        char *arg, *cmds[8];
-        int i = 1, j;
-
-        cmds[0] = cmd;
-        va_start(args, cmd);
-
-        while (((arg = va_arg(args, char *)) != NULL) && (i < 8)) {
-                cmds[i] = arg;
-                i++;
-        }
-
-        va_end(args);
-
-        printf("obdctl > ");
-        for (j = 0; j < i; j++)
-                printf("%s ", cmds[j]);
-
-        printf("\n");
-
-        return Parser_execarg(i, cmds, cmdlist);
-}
-
-#if 0
-static network_t *xml_network(xmlDocPtr doc, xmlNodePtr root)
-{
-        xmlNodePtr cur = root->xmlChildrenNode;
-        network_t *net;
-
-        if ((net = (network_t *) calloc(1, sizeof(network_t))) == NULL) {
-                printf("error: unable to malloc network_t\n");
-                return NULL;
-        }
-
-        net->type = xmlGetProp(root, "type");
-        if (net->type == NULL) {
-                printf("error: type attrib required (tcp, elan, myrinet)\n");
-                free(net);
-                return NULL;
-        }
-
-        while (cur != NULL) {
-                if (!xmlStrcmp(cur->name, "server"))
-                        net->server = xmlNodeGetContent(cur);
-
-                if (!xmlStrcmp(cur->name, "port"))
-                        net->port = atoi(xmlNodeGetContent(cur));
-
-                cur = cur->next;
-        }
-
-        if (net->server == NULL) {
-                printf("error: <server> tag required\n");
-                free(net);
-                return NULL;
-        }
-
-        return net;
-}
-#endif
-
-static int xml_mds(xmlDocPtr doc, xmlNodePtr root,
-                   char *serv_name, char *serv_uuid)
-{
-        xmlNodePtr cur = root->xmlChildrenNode;
-        char *fstype = NULL, *device = NULL;
-        int rc;
-
-        printf("--- Setting up MDS ---\n");
-        while (cur != NULL) {
-                if (!xmlStrcmp(cur->name, "fstype"))
-                        fstype = xmlNodeGetContent(cur);
-
-                if (!xmlStrcmp(cur->name, "device"))
-                        device = xmlNodeGetContent(cur);
-
-                /* FIXME: Parse the network bits
-                 * if (!xmlStrcmp(cur->name, "network")) {
-                 *       net = xml_network(doc, cur);
-                 *       if (net == NULL)
-                 *               return -1;
-                 * }
-                 * free(net);
-                 */
-                cur = cur->next;
-        }
-
-        if ((fstype == NULL) || (device == NULL)) {
-                printf("error: <fstype> and <device> tags required\n");
-                return -1;
-        }
-
-        if ((rc = xml_command("newdev", NULL)) != 0)
-                return rc;
-
-        if ((rc =
-             xml_command("attach", "mds", serv_name, serv_uuid, NULL)) != 0)
-                return rc;
-
-        if ((rc = xml_command("setup", device, fstype, NULL)) != 0)
-                return rc;
-
-        return 0;
-}
-
-static int xml_obd(xmlDocPtr doc, xmlNodePtr root,
-                   char *serv_name, char *serv_uuid)
-{
-        char *obdtype, *format = NULL, *fstype = NULL, *device = NULL;
-        xmlNodePtr cur = root->xmlChildrenNode;
-        int rc;
-
-        obdtype = xmlGetProp(root, "type");
-        printf("--- Setting up OBD ---\n");
-
-        while (cur != NULL) {
-                if (!xmlStrcmp(cur->name, "fstype"))
-                        fstype = xmlNodeGetContent(cur);
-
-                if (!xmlStrcmp(cur->name, "device"))
-                        device = xmlNodeGetContent(cur);
-
-                if (!xmlStrcmp(cur->name, "autoformat"))
-                        format = xmlNodeGetContent(cur);
-
-                cur = cur->next;
-        }
-
-        if ((obdtype == NULL) || (fstype == NULL) || (device == NULL)) {
-                printf("error: 'type' attrib and <fstype> "
-                       "and <device> tags required\n");
-                return -1;
-        }
-
-        /* FIXME: Building and configuring loopback devices should go here
-         * but is currently unsupported.  You'll have to use the scripts
-         * for now until support is added, or specify a real device.
-         */
-
-        if ((rc = xml_command("newdev", NULL)) != 0)
-                return rc;
-
-        if ((rc = xml_command("attach", obdtype,
-                              serv_name, serv_uuid, NULL)) != 0)
-                return rc;
-
-        if ((rc = xml_command("setup", device, fstype, NULL)) != 0)
-                return rc;
-
-        return 0;
-}
-
-static int xml_ost(xmlDocPtr doc, xmlNodePtr root,
-                   char *serv_name, char *serv_uuid)
-{
-        char *server_name = NULL, *server_uuid = NULL;
-        char *failover_name = NULL, *failover_uuid = NULL;
-        xmlNodePtr cur = root->xmlChildrenNode;
-        int server_num, failover_num, rc;
-
-        printf("--- Setting up OST ---\n");
-        while (cur != NULL) {
-                if (!xmlStrcmp(cur->name, "server_id")) {
-                        server_num = atoi(xmlGetProp(cur, "num"));
-                        server_name = xmlGetProp(cur, "name");
-                        server_uuid = xmlGetProp(cur, "uuid");
-                }
-
-                /* FIXME: Properly handle multiple failover servers */
-                if (!xmlStrcmp(cur->name, "failover_id")) {
-                        failover_num = atoi(xmlGetProp(cur, "num"));
-                        failover_name = xmlGetProp(cur, "name");
-                        failover_uuid = xmlGetProp(cur, "uuid");
-                }
-
-                cur = cur->next;
-        }
-
-        if ((server_name == NULL) || (server_uuid == NULL)) {
-                printf("error: atleast the <server_id> tag is required\n");
-                return -1;
-        }
-
-        if ((rc = xml_command("newdev", NULL)) != 0)
-                return rc;
-
-        if ((rc =
-             xml_command("attach", "ost", serv_name, serv_uuid, NULL)) != 0)
-                return rc;
-
-        if ((rc = xml_command("setup", server_name, NULL)) != 0)
-                return rc;
-
-        return 0;
-}
-
-static int xml_osc(xmlDocPtr doc, xmlNodePtr root,
-                   char *serv_name, char *serv_uuid)
-{
-        char *ost_name = NULL, *ost_uuid = NULL;
-        xmlNodePtr cur = root->xmlChildrenNode;
-        int ost_num, rc = 0;
-
-        printf("--- Setting up OSC ---\n");
-        while (cur != NULL) {
-                if (!xmlStrcmp(cur->name, "service_id")) {
-                        ost_num = atoi(xmlGetProp(cur, "num"));
-                        ost_name = xmlGetProp(cur, "name");
-                        ost_uuid = xmlGetProp(cur, "uuid");
-                }
-
-                cur = cur->next;
-        }
-
-        if ((ost_name == NULL) || (ost_uuid == NULL)) {
-                printf("error: atleast the <service_id> tag is required\n");
-                return -1;
-        }
-
-        if ((rc = xml_command("newdev", NULL)) != 0)
-                return rc;
-
-        if ((rc =
-             xml_command("attach", "osc", serv_name, serv_uuid, NULL)) != 0)
-                return rc;
-
-        if ((rc = xml_command("setup", ost_uuid, "localhost", NULL)) != 0)
-                return rc;
-
-        return 0;
-}
-
-static int xml_mdc(xmlDocPtr doc, xmlNodePtr root,
-                   char *serv_name, char *serv_uuid)
-{
-        char *mds_name = NULL, *mds_uuid = NULL;
-        xmlNodePtr cur = root->xmlChildrenNode;
-        int mds_num, rc = 0;
-
-        printf("--- Setting up MDC ---\n");
-        while (cur != NULL) {
-                if (!xmlStrcmp(cur->name, "service_id")) {
-                        mds_num = atoi(xmlGetProp(cur, "num"));
-                        mds_name = xmlGetProp(cur, "name");
-                        mds_uuid = xmlGetProp(cur, "uuid");
-                }
-
-                cur = cur->next;
-        }
-
-        if ((mds_name == NULL) || (mds_uuid == NULL)) {
-                printf("error: atleast the <service_id> tag is required\n");
-                return -1;
-        }
-
-        if ((rc = xml_command("newdev", NULL)) != 0)
-                return rc;
-
-        if ((rc =
-             xml_command("attach", "mdc", serv_name, serv_uuid, NULL)) != 0)
-                return rc;
-
-        if ((rc = xml_command("setup", mds_uuid, "localhost", NULL)) != 0)
-                return rc;
-
-        return 0;
-}
-
-static int xml_lov(xmlDocPtr doc, xmlNodePtr root,
-                   char *serv_name, char *serv_uuid)
-{
-        printf("--- Setting up LOV ---\n");
-        return 0;
-}
-
-static int xml_router(xmlDocPtr doc, xmlNodePtr root,
-                      char *serv_name, char *serv_uuid)
-{
-        printf("--- Setting up ROUTER ---\n");
-        return 0;
-}
-
-static int xml_ldlm(xmlDocPtr doc, xmlNodePtr root,
-                    char *serv_name, char *serv_uuid)
-{
-        int rc;
-
-        printf("--- Setting up LDLM ---\n");
-        if ((rc = xml_command("newdev", NULL)) != 0)
-                return rc;
-
-        if ((rc =
-             xml_command("attach", "ldlm", serv_name, serv_uuid, NULL)) != 0)
-                return rc;
-
-        if ((rc = xml_command("setup", NULL)) != 0)
-                return rc;
-
-        return 0;
-}
-
-static int xml_service(xmlDocPtr doc, xmlNodePtr root,
-                       int serv_num, char *serv_name, char *serv_uuid)
-{
-        xmlNodePtr cur = root;
-        char *name, *uuid;
-
-        while (cur != NULL) {
-                name = xmlGetProp(cur, "name");
-                uuid = xmlGetProp(cur, "uuid");
-
-                if (xmlStrcmp(name, serv_name) || xmlStrcmp(uuid, serv_uuid)) {
-                        cur = cur->next;
-                        continue;
-                }
-
-                if (!xmlStrcmp(cur->name, "mds"))
-                        return xml_mds(doc, cur, name, uuid);
-                else if (!xmlStrcmp(cur->name, "obd"))
-                        return xml_obd(doc, cur, name, uuid);
-                else if (!xmlStrcmp(cur->name, "ost"))
-                        return xml_ost(doc, cur, name, uuid);
-                else if (!xmlStrcmp(cur->name, "osc"))
-                        return xml_osc(doc, cur, name, uuid);
-                else if (!xmlStrcmp(cur->name, "mdc"))
-                        return xml_mdc(doc, cur, name, uuid);
-                else if (!xmlStrcmp(cur->name, "lov"))
-                        return xml_lov(doc, cur, name, uuid);
-                else if (!xmlStrcmp(cur->name, "router"))
-                        return xml_router(doc, cur, name, uuid);
-                else if (!xmlStrcmp(cur->name, "ldlm"))
-                        return xml_ldlm(doc, cur, name, uuid);
-                else
-                        return -1;
-
-                cur = cur->next;
-        }
-
-        printf("error: No XML config branch for name=%s uuid=%s\n",
-               serv_name, serv_uuid);
-        return -1;
-}
-
-static int xml_profile(xmlDocPtr doc, xmlNodePtr root,
-                       int prof_num, char *prof_name, char *prof_uuid)
-{
-        xmlNodePtr parent, cur = root;
-        char *name, *uuid, *srv_name, *srv_uuid;
-        int rc = 0, num;
-
-        while (cur != NULL) {
-                name = xmlGetProp(cur, "name");
-                uuid = xmlGetProp(cur, "uuid");
-
-                if (xmlStrcmp(cur->name, "profile") ||
-                    xmlStrcmp(name, prof_name) || xmlStrcmp(uuid, prof_uuid)) {
-                        cur = cur->next;
-                        continue;
-                }
-
-                /* FIXME: Doesn't understand mountpoints yet
-                 *        xml_mountpoint(doc, root, ...);
-                 */
-
-                /* Setup each service in turn
-                 * FIXME: Should be sorted by "num" attr, we shouldn't
-                 *        assume they're in order in the XML document.
-                 */
-                parent = cur;
-                cur = cur->xmlChildrenNode;
-                while (cur != NULL) {
-                        if (!xmlStrcmp(cur->name, "service_id")) {
-                                num = atoi(xmlGetProp(cur, "num"));
-                                rc = xml_service(doc, root, num,
-                                                 srv_name =
-                                                 xmlGetProp(cur, "name"),
-                                                 srv_uuid =
-                                                 xmlGetProp(cur, "uuid"));
-                                if (rc != 0) {
-                                        printf("error: service config\n");
-                                        return rc;
-                                }
-                        }
-
-                        cur = cur->next;
-                }
-
-                cur = parent->next;
-        }
-
-        return rc;
-}
-
-static int xml_node(xmlDocPtr doc, xmlNodePtr root)
-{
-        xmlNodePtr parent, cur = root;
-        char *name, *uuid;
-        int rc = 0, num;
-
-        /* Walk the node tags looking for ours */
-        while (cur != NULL) {
-                if (xmlStrcmp(cur->name, "node")) {
-                        cur = cur->next;
-                        continue;
-                }
-
-                name = xmlGetProp(cur, "name");
-                if (name == NULL)
-                        return -1;
-
-                uuid = xmlGetProp(cur, "uuid");
-                if (uuid == NULL)
-                        return -1;
-
-                /* FIXME: Verify our NAME and UUID against /etc/lustre/id
-                 *        so we're sure we are who we think we are.
-                 */
-
-                /* Setup each profile in turn
-                 * FIXME: Should be sorted by "num" attr, we shouldn't
-                 *        assume they're in order in the XML document.
-                 */
-                parent = cur;
-                cur = cur->xmlChildrenNode;
-                while (cur != NULL) {
-                        if (!xmlStrcmp(cur->name, "profile_id")) {
-                                num = atoi(xmlGetProp(cur, "num"));
-                                rc = xml_profile(doc, root, num,
-                                                 xmlGetProp(cur, "name"),
-                                                 xmlGetProp(cur, "uuid"));
-                                if (rc != 0)
-                                        return rc;
-                        }
-
-                        cur = cur->next;
-                }
-
-                cur = parent->next;
-        }
-
-        return rc;
-}
-
-static int do_xml(char *func, char *file)
-{
-        xmlDocPtr doc;
-        xmlNodePtr cur;
-        int rc;
-
-        doc = xmlParseFile(file);
-        if (doc == NULL) {
-                fprintf(stderr, "error: Unable to parse XML\n");
-                return -1;
-        }
-
-        cur = xmlDocGetRootElement(doc);
-        if (cur == NULL) {
-                fprintf(stderr, "error: Empty XML\n");
-                xmlFreeDoc(doc);
-                return -1;
-        }
-
-        if (xmlStrcmp(cur->name, (const xmlChar *)"lustre")) {
-                fprintf(stderr, "error: Root node != <lustre>\n");
-                xmlFreeDoc(doc);
-                return -1;
-        }
-
-        /* FIXME: Validate the XML against the DTD here */
-
-        /* FIXME: Merge all the text nodes under each branch and 
-         *        prune empty nodes.  Just to make the parsing more
-         *        tolerant, the exact location of nested tags isn't
-         *        critical for this.
-         */
-
-        rc = xml_node(doc, cur->xmlChildrenNode);
-        xmlFreeDoc(doc);
-
-        return rc;
-}
-
-static int do_device(char *func, int dev)
-{
-        struct obd_ioctl_data data;
-
-        memset(&data, 0, sizeof(data));
-
-        data.ioc_dev = dev;
-
-        if (getfd(func))
-                return -1;
-
-        if (obd_ioctl_pack(&data, &buf, max)) {
-                fprintf(stderr, "error: %s: invalid ioctl\n", cmdname(func));
-                return -2;
-        }
-
-        return ioctl(fd, OBD_IOC_DEVICE, buf);
-}
-
-static int jt_device(int argc, char **argv)
-{
-        do_disconnect(argv[0], 1);
-
-        if (argc != 2) {
-                fprintf(stderr, "usage: %s devno\n", cmdname(argv[0]));
-                return -1;
-        }
-
-        rc = do_device(argv[0], strtoul(argv[1], NULL, 0));
-
-        if (rc < 0)
-                fprintf(stderr, "error: %s: %s\n", cmdname(argv[0]),
-                        strerror(rc = errno));
-
-        return rc;
-}
-
-static int jt_connect(int argc, char **argv)
-{
-        struct obd_ioctl_data data;
-
-        IOCINIT(data);
-
-        do_disconnect(argv[0], 1);
-
-        if (argc != 1) {
-                fprintf(stderr, "usage: %s\n", cmdname(argv[0]));
-                return -1;
-        }
-
-        rc = ioctl(fd, OBD_IOC_CONNECT, &data);
-        if (rc < 0)
-                fprintf(stderr, "error: %s: %x %s\n", cmdname(argv[0]),
-                        OBD_IOC_CONNECT, strerror(rc = errno));
-        else
-                conn_addr = data.ioc_addr;
-        conn_cookie = data.ioc_cookie;
-        return rc;
-}
-
-static int jt_disconnect(int argc, char **argv)
-{
-        if (argc != 1) {
-                fprintf(stderr, "usage: %s\n", cmdname(argv[0]));
-                return -1;
-        }
-
-        if (conn_addr == -1)
-                return 0;
-
-        return do_disconnect(argv[0], 0);
-}
-
-static int jt__xml(int argc, char **argv)
-{
-        if (argc < 2) {
-                fprintf(stderr, "usage: %s <xml file> <command [args ...]>\n",
-                        cmdname(argv[0]));
-                return -1;
-        }
-
-        return do_xml("xml", argv[1]);
-}
-
-static int jt__device(int argc, char **argv)
-{
-        char *arg2[3];
-        int ret;
-
-        if (argc < 3) {
-                fprintf(stderr, "usage: %s devno <command [args ...]>\n",
-                        cmdname(argv[0]));
-                return -1;
-        }
-
-        rc = do_device("device", strtoul(argv[1], NULL, 0));
-
-        if (!rc) {
-                arg2[0] = "connect";
-                arg2[1] = NULL;
-                rc = jt_connect(1, arg2);
-        }
-
-        if (!rc)
-                rc = Parser_execarg(argc - 2, argv + 2, cmdlist);
-
-        ret = do_disconnect(argv[0], 0);
-        if (!rc)
-                rc = ret;
-
-        return rc;
-}
-
-static int jt__threads(int argc, char **argv)
-{
-        int threads, next_thread;
-        int verbose;
-        int i;
-
-        if (argc < 5) {
-                fprintf(stderr,
-                        "usage: %s numthreads verbose devno <cmd [args ...]>\n",
-                        argv[0]);
-                return -1;
-        }
-
-        threads = strtoul(argv[1], NULL, 0);
-
-        verbose = get_verbose(argv[2]);
-
-        if (verbose != 0)
-                printf("%s: starting %d threads on device %s running %s\n",
-                       argv[0], threads, argv[3], argv[4]);
-
-        SHMEM_RESET();
-
-        for (i = 1, next_thread = verbose; i <= threads; i++) {
-                rc = fork();
-                if (rc < 0) {
-                        fprintf(stderr, "error: %s: #%d - %s\n", argv[0], i,
-                                strerror(rc = errno));
-                        break;
-                } else if (rc == 0) {
-                        thread = i;
-                        argv[2] = "--device";
-                        return jt__device(argc - 2, argv + 2);
-                } else if (be_verbose(verbose, NULL, i, &next_thread, threads))
-                        printf("%s: thread #%d (PID %d) started\n",
-                               argv[0], i, rc);
-                rc = 0;
-        }
-
-        if (!thread) {          /* parent process */
-                int live_threads = threads;
-
-                while (live_threads > 0) {
-                        int status;
-                        pid_t ret;
-
-                        ret = waitpid(0, &status, verbose < 0 ? WNOHANG : 0);
-                        if (ret == 0) {
-                                if (verbose >= 0)
-                                        abort();
-
-                                sleep(-verbose);
-                                SHMEM_SNAP(threads);
-                                continue;
-                        }
-
-                        if (ret < 0) {
-                                fprintf(stderr, "error: %s: wait - %s\n",
-                                        argv[0], strerror(errno));
-                                if (!rc)
-                                        rc = errno;
-                        } else {
-                                /*
-                                 * This is a hack.  We _should_ be able to use
-                                 * WIFEXITED(status) to see if there was an
-                                 * error, but it appears to be broken and it
-                                 * always returns 1 (OK).  See wait(2).
-                                 */
-                                int err = WEXITSTATUS(status);
-                                if (err)
-                                        fprintf(stderr,
-                                                "%s: PID %d had rc=%d\n",
-                                                argv[0], ret, err);
-                                if (!rc)
-                                        rc = err;
-
-                                live_threads--;
-                        }
-                }
-        }
-
-        return rc;
-}
-
-static int jt_detach(int argc, char **argv)
-{
-        struct obd_ioctl_data data;
-
-        IOCINIT(data);
-
-        if (argc != 1) {
-                fprintf(stderr, "usage: %s\n", cmdname(argv[0]));
-                return -1;
-        }
-
-        if (obd_ioctl_pack(&data, &buf, max)) {
-                fprintf(stderr, "error: %s: invalid ioctl\n", cmdname(argv[0]));
-                return -2;
-        }
-
-        rc = ioctl(fd, OBD_IOC_DETACH, buf);
-        if (rc < 0)
-                fprintf(stderr, "error: %s: %s\n", cmdname(argv[0]),
-                        strerror(rc = errno));
-
-        return rc;
-}
-
-static int jt_cleanup(int argc, char **argv)
-{
-        struct obd_ioctl_data data;
-
-        IOCINIT(data);
-
-        if (argc != 1) {
-                fprintf(stderr, "usage: %s\n", cmdname(argv[0]));
-                return -1;
-        }
-
-        rc = ioctl(fd, OBD_IOC_CLEANUP, &data);
-        if (rc < 0)
-                fprintf(stderr, "error: %s: %s\n", cmdname(argv[0]),
-                        strerror(rc = errno));
-
-        return rc;
-}
-
-static int jt_newdev(int argc, char **argv)
-{
-        struct obd_ioctl_data data;
-
-        if (getfd(argv[0]))
-                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_list(int argc, char **argv)
-{
-        char buf[1024];
-        struct obd_ioctl_data *data = (struct obd_ioctl_data *)buf;
-
-        if (getfd(argv[0]))
-                return -1;
-
-        memset(buf, 0, sizeof(buf));
-        data->ioc_version = OBD_IOCTL_VERSION;
-        data->ioc_addr = conn_addr;
-        data->ioc_cookie = conn_addr;
-        data->ioc_len = sizeof(buf);
-        data->ioc_inllen1 = sizeof(buf) - size_round(sizeof(*data));
-
-        if (argc != 1) {
-                fprintf(stderr, "usage: %s\n", cmdname(argv[0]));
-                return -1;
-        }
-
-        rc = ioctl(fd, OBD_IOC_LIST, data);
-        if (rc < 0)
-                fprintf(stderr, "error: %s: %s\n", cmdname(argv[0]),
-                        strerror(rc = errno));
-        else {
-                printf("%s", data->ioc_bulk);
-        }
-
-        return rc;
-}
-
-static int jt_attach(int argc, char **argv)
-{
-        struct obd_ioctl_data data;
-
-        IOCINIT(data);
-
-        if (argc != 2 && argc != 3 && argc != 4) {
-                fprintf(stderr, "usage: %s type [name [uuid]]\n",
-                        cmdname(argv[0]));
-                return -1;
-        }
-
-        data.ioc_inllen1 = strlen(argv[1]) + 1;
-        data.ioc_inlbuf1 = argv[1];
-        if (argc >= 3) {
-                data.ioc_inllen2 = strlen(argv[2]) + 1;
-                data.ioc_inlbuf2 = argv[2];
-        }
-
-        if (argc == 4) {
-                data.ioc_inllen3 = strlen(argv[3]) + 1;
-                data.ioc_inlbuf3 = argv[3];
-        }
-
-        if (obd_ioctl_pack(&data, &buf, max)) {
-                fprintf(stderr, "error: %s: invalid ioctl\n", cmdname(argv[0]));
-                return -2;
-        }
-
-        rc = ioctl(fd, OBD_IOC_ATTACH, buf);
-        if (rc < 0)
-                fprintf(stderr, "error: %s: %x %s\n", cmdname(argv[0]),
-                        OBD_IOC_ATTACH, strerror(rc = errno));
-        else if (argc == 3) {
-                char name[1024];
-                if (strlen(argv[2]) > 128) {
-                        printf("Name too long to set environment\n");
-                        return -EINVAL;
-                }
-                snprintf(name, 512, "LUSTRE_DEV_%s", argv[2]);
-                rc = setenv(name, argv[1], 1);
-                if (rc) {
-                        printf("error setting env variable %s\n", name);
-                }
-        }
-
-        return rc;
-}
-
-#define N2D_OFF 0x100      /* So we can tell between error codes and devices */
-
-static int do_name2dev(char *func, char *name)
-{
-        struct obd_ioctl_data data;
-
-        if (getfd(func))
-                return -1;
-
-        IOCINIT(data);
-
-        data.ioc_inllen1 = strlen(name) + 1;
-        data.ioc_inlbuf1 = name;
-
-        if (obd_ioctl_pack(&data, &buf, max)) {
-                fprintf(stderr, "error: %s: invalid ioctl\n", cmdname(func));
-                return -2;
-        }
-        rc = ioctl(fd, OBD_IOC_NAME2DEV, buf);
-        if (rc < 0) {
-                fprintf(stderr, "error: %s: %s - %s\n", cmdname(func),
-                        name, strerror(rc = errno));
-                return rc;
-        }
-
-        memcpy((char *)(&data), buf, sizeof(data));
-
-        return data.ioc_dev + N2D_OFF;
-}
-
-static int jt_name2dev(int argc, char **argv)
-{
-        if (argc != 2) {
-                Parser_printhelp("name2dev");
-                return -1;
-        }
-
-        rc = do_name2dev(argv[0], argv[1]);
-        if (rc >= N2D_OFF) {
-                int dev = rc - N2D_OFF;
-                rc = do_device(argv[0], dev);
-                if (rc == 0)
-                        printf("%d\n", dev);
-        }
-        return rc;
-}
-
-static int jt_setup(int argc, char **argv)
-{
-        struct obd_ioctl_data data;
-
-        IOCINIT(data);
-
-        if (argc > 3) {
-                fprintf(stderr, "usage: %s [device] [fstype]\n",
-                        cmdname(argv[0]));
-                return -1;
-        }
-
-        data.ioc_dev = -1;
-        if (argc > 1) {
-                if (argv[1][0] == '$') {
-                        rc = do_name2dev(argv[0], argv[1] + 1);
-                        if (rc >= N2D_OFF) {
-                                printf("%s is device %d\n", argv[1],
-                                       rc - N2D_OFF);
-                                data.ioc_dev = rc - N2D_OFF;
-                        }
-                } else
-                        data.ioc_dev = strtoul(argv[1], NULL, 0);
-                data.ioc_inllen1 = strlen(argv[1]) + 1;
-                data.ioc_inlbuf1 = argv[1];
-        }
-        if (argc == 3) {
-                data.ioc_inllen2 = strlen(argv[2]) + 1;
-                data.ioc_inlbuf2 = argv[2];
-        }
-
-        if (obd_ioctl_pack(&data, &buf, max)) {
-                fprintf(stderr, "error: %s: invalid ioctl\n", cmdname(argv[0]));
-                return -2;
-        }
-        rc = ioctl(fd, OBD_IOC_SETUP, buf);
-        if (rc < 0)
-                fprintf(stderr, "error: %s: %s\n", cmdname(argv[0]),
-                        strerror(rc = errno));
-
-        return rc;
-}
-
-
-static int jt_create(int argc, char **argv)
-{
-        struct obd_ioctl_data data;
-        struct timeval next_time;
-        int count = 1, next_count;
-        int verbose;
-        int i;
-
-        IOCINIT(data);
-        if (argc < 2 || argc > 4) {
-                fprintf(stderr, "usage: %s num [mode] [verbose]\n",
-                        cmdname(argv[0]));
-                return -1;
-        }
-        count = strtoul(argv[1], NULL, 0);
-
-        if (argc > 2)
-                data.ioc_obdo1.o_mode = strtoul(argv[2], NULL, 0);
-        else
-                data.ioc_obdo1.o_mode = 0100644;
-        data.ioc_obdo1.o_valid = OBD_MD_FLMODE;
-
-        verbose = get_verbose(argv[3]);
-
-        printf("%s: %d obdos\n", cmdname(argv[0]), count);
-        gettimeofday(&next_time, NULL);
-        next_time.tv_sec -= verbose;
-
-        for (i = 1, next_count = verbose; i <= count; i++) {
-                rc = ioctl(fd, OBD_IOC_CREATE, &data);
-                SHMEM_BUMP();
-                if (rc < 0) {
-                        fprintf(stderr, "error: %s: #%d - %s\n",
-                                cmdname(argv[0]), i, strerror(rc = errno));
-                        break;
-                }
-                if (be_verbose(verbose, &next_time, i, &next_count, count))
-                        printf("%s: #%d is object id %Ld\n", cmdname(argv[0]),
-                               i, data.ioc_obdo1.o_id);
-        }
-        return rc;
-}
-
-static int jt_setattr(int argc, char **argv)
-{
-        struct obd_ioctl_data data;
-
-        IOCINIT(data);
-        if (argc != 2) {
-                fprintf(stderr, "usage: %s id mode\n", cmdname(argv[0]));
-                return -1;
-        }
-
-        data.ioc_obdo1.o_id = strtoul(argv[1], NULL, 0);
-        data.ioc_obdo1.o_mode = S_IFREG | strtoul(argv[2], NULL, 0);
-        data.ioc_obdo1.o_valid = OBD_MD_FLMODE;
-
-        rc = ioctl(fd, OBD_IOC_SETATTR, &data);
-        if (rc < 0)
-                fprintf(stderr, "error: %s: %s\n", cmdname(argv[0]),
-                        strerror(rc = errno));
-
-        return rc;
-}
-
-static int jt_destroy(int argc, char **argv)
-{
-        struct obd_ioctl_data data;
-
-        IOCINIT(data);
-        if (argc != 2) {
-                fprintf(stderr, "usage: %s id\n", cmdname(argv[0]));
-                return -1;
-        }
-
-        data.ioc_obdo1.o_id = strtoul(argv[1], NULL, 0);
-        data.ioc_obdo1.o_mode = S_IFREG | 0644;
-
-        rc = ioctl(fd, OBD_IOC_DESTROY, &data);
-        if (rc < 0)
-                fprintf(stderr, "error: %s: %s\n", cmdname(argv[0]),
-                        strerror(rc = errno));
-
-        return rc;
-}
-
-static int jt_getattr(int argc, char **argv)
-{
-        struct obd_ioctl_data data;
-
-        if (argc != 2) {
-                fprintf(stderr, "usage: %s id\n", cmdname(argv[0]));
-                return -1;
-        }
-
-        IOCINIT(data);
-        data.ioc_obdo1.o_id = strtoul(argv[1], NULL, 0);
-        /* to help obd filter */
-        data.ioc_obdo1.o_mode = 0100644;
-        data.ioc_obdo1.o_valid = 0xffffffff;
-        printf("%s: object id %Ld\n", cmdname(argv[0]), data.ioc_obdo1.o_id);
-
-        rc = ioctl(fd, OBD_IOC_GETATTR, &data);
-        if (rc) {
-                fprintf(stderr, "error: %s: %s\n", cmdname(argv[0]),
-                        strerror(rc = errno));
-        } else {
-                printf("%s: object id %Ld, mode %o\n", cmdname(argv[0]),
-                       data.ioc_obdo1.o_id, data.ioc_obdo1.o_mode);
-        }
-        return rc;
-}
-
-static int jt_test_getattr(int argc, char **argv)
-{
-        struct obd_ioctl_data data;
-        struct timeval start, next_time;
-        int i, count, next_count;
-        int verbose;
-
-        if (argc != 2 && argc != 3) {
-                fprintf(stderr, "usage: %s count [verbose]\n",
-                        cmdname(argv[0]));
-                return -1;
-        }
-
-        IOCINIT(data);
-        count = strtoul(argv[1], NULL, 0);
-
-        if (argc == 3)
-                verbose = get_verbose(argv[2]);
-        else
-                verbose = 1;
-
-        data.ioc_obdo1.o_valid = 0xffffffff;
-        data.ioc_obdo1.o_id = 2;
-        gettimeofday(&start, NULL);
-        next_time.tv_sec = start.tv_sec - verbose;
-        next_time.tv_usec = start.tv_usec;
-        if (verbose != 0)
-                printf("%s: getting %d attrs (testing only): %s",
-                       cmdname(argv[0]), count, ctime(&start.tv_sec));
-
-        for (i = 1, next_count = verbose; i <= count; i++) {
-                rc = ioctl(fd, OBD_IOC_GETATTR, &data);
-                SHMEM_BUMP();
-                if (rc < 0) {
-                        fprintf(stderr, "error: %s: #%d - %s\n",
-                                cmdname(argv[0]), i, strerror(rc = errno));
-                        break;
-                } else {
-                        if (be_verbose
-                            (verbose, &next_time, i, &next_count, count))
-                                printf("%s: got attr #%d\n", cmdname(argv[0]),
-                                       i);
-                }
-        }
-
-        if (!rc) {
-                struct timeval end;
-                double diff;
-
-                gettimeofday(&end, NULL);
-
-                diff = difftime(&end, &start);
-
-                --i;
-                if (verbose != 0)
-                        printf("%s: %d attrs in %.4gs (%.4g attr/s): %s",
-                               cmdname(argv[0]), i, diff, (double)i / diff,
-                               ctime(&end.tv_sec));
-        }
-        return rc;
-}
-
-static int jt_test_brw(int argc, char **argv)
-{
-        struct obd_ioctl_data data;
-        struct timeval start, next_time;
-        char *bulk, *b;
-        int pages = 1, obdos = 1, count, next_count;
-        int verbose = 1, write = 0, rw;
-        int i, o, p;
-        int len;
-
-        if (argc < 2 || argc > 6) {
-                fprintf(stderr,
-                        "usage: %s count [write [verbose [pages [obdos]]]]\n",
-                        cmdname(argv[0]));
-                return -1;
-        }
-
-        count = strtoul(argv[1], NULL, 0);
-
-        if (argc >= 3) {
-                if (argv[2][0] == 'w' || argv[2][0] == '1')
-                        write = 1;
-                else if (argv[2][0] == 'r' || argv[2][0] == '0')
-                        write = 0;
-
-                verbose = get_verbose(argv[3]);
-        }
-
-        if (argc >= 5)
-                pages = strtoul(argv[4], NULL, 0);
-        if (argc >= 6)
-                obdos = strtoul(argv[5], NULL, 0);
-
-        if (obdos != 1 && obdos != 2) {
-                fprintf(stderr, "error: %s: only 1 or 2 obdos supported\n",
-                        cmdname(argv[0]));
-                return -2;
-        }
-
-        len = pages * PAGE_SIZE;
-
-        bulk = calloc(obdos, len);
-        if (!bulk) {
-                fprintf(stderr, "error: %s: no memory allocating %dx%d pages\n",
-                        cmdname(argv[0]), obdos, pages);
-                return -2;
-        }
-        IOCINIT(data);
-        data.ioc_obdo1.o_id = 2;
-        data.ioc_count = len;
-        data.ioc_offset = 0;
-        data.ioc_plen1 = len;
-        data.ioc_pbuf1 = bulk;
-        if (obdos > 1) {
-                data.ioc_obdo2.o_id = 3;
-                data.ioc_plen2 = len;
-                data.ioc_pbuf2 = bulk + len;
-        }
-
-        gettimeofday(&start, NULL);
-        next_time.tv_sec = start.tv_sec - verbose;
-        next_time.tv_usec = start.tv_usec;
-
-        if (verbose != 0)
-                printf("%s: %s %d (%dx%d pages) (testing only): %s",
-                       cmdname(argv[0]), write ? "writing" : "reading",
-                       count, obdos, pages, ctime(&start.tv_sec));
-
-        /*
-         * We will put in the start time (and loop count inside the loop)
-         * at the beginning of each page so that we will be able to validate
-         * (at some later time) whether the data actually made it or not.
-         *
-         * XXX we do not currently use any of this memory in OBD_IOC_BRW_*
-         *     just to avoid the overhead of the copy_{to,from}_user.  It
-         *     can be fixed if we ever need to send real data around.
-         */
-        for (o = 0, b = bulk; o < obdos; o++)
-                for (p = 0; p < pages; p++, b += PAGE_SIZE)
-                        memcpy(b, &start, sizeof(start));
-
-        rw = write ? OBD_IOC_BRW_WRITE : OBD_IOC_BRW_READ;
-        for (i = 1, next_count = verbose; i <= count; i++) {
-                if (write) {
-                        b = bulk + sizeof(struct timeval);
-                        for (o = 0; o < obdos; o++)
-                                for (p = 0; p < pages; p++, b += PAGE_SIZE)
-                                        memcpy(b, &count, sizeof(count));
-                }
-
-                rc = ioctl(fd, rw, &data);
-                SHMEM_BUMP();
-                if (rc) {
-                        fprintf(stderr, "error: %s: #%d - %s on %s\n",
-                                cmdname(argv[0]), i, strerror(rc = errno),
-                                write ? "write" : "read");
-                        break;
-                } else if (be_verbose
-                           (verbose, &next_time, i, &next_count, count))
-                        printf("%s: %s number %d\n", cmdname(argv[0]),
-                               write ? "write" : "read", i);
-        }
-
-        free(bulk);
-
-        if (!rc) {
-                struct timeval end;
-                double diff;
-
-                gettimeofday(&end, NULL);
-
-                diff = difftime(&end, &start);
-
-                --i;
-                if (verbose != 0)
-                        printf("%s: %s %dx%dx%d pages in %.4gs (%.4g pg/s): %s",
-                               cmdname(argv[0]), write ? "wrote" : "read",
-                               obdos, pages, i, diff,
-                               (double)obdos * i * pages / diff,
-                               ctime(&end.tv_sec));
-        }
-        return rc;
-}
-
-static int jt_lov_config(int argc, char **argv)
-{
-        struct obd_ioctl_data data;
-        struct lov_desc desc;
-        uuid_t *uuidarray;
-        int size, i;
-        IOCINIT(data);
-
-        printf("WARNING: obdctl lovconfig NOT MAINTAINED\n");
-        return -1;
-
-        if (argc <= 5) {
-                Parser_printhelp("lovconfig");
-                return -1;
-        }
-
-        if (strlen(argv[1]) > sizeof(uuid_t) - 1) {
-                fprintf(stderr, "lov_config: no %dB memory for uuid's\n",
-                        strlen(argv[1]));
-                return -ENOMEM;
-        }
-
-        memset(&desc, 0, sizeof(desc));
-        strcpy(desc.ld_uuid, argv[1]);
-        desc.ld_default_stripe_count = strtoul(argv[2], NULL, 0);
-        desc.ld_default_stripe_size = strtoul(argv[3], NULL, 0);
-        desc.ld_pattern = strtoul(argv[4], NULL, 0);
-        desc.ld_tgt_count = argc - 5;
-
-
-        size = sizeof(uuid_t) * desc.ld_tgt_count;
-        uuidarray = malloc(size);
-        if (!uuidarray) {
-                fprintf(stderr, "lov_config: no %dB memory for uuid's\n", size);
-                return -ENOMEM;
-        }
-        memset(uuidarray, 0, size);
-        for (i = 5; i < argc; i++) {
-                char *buf = (char *)(uuidarray + i - 5);
-                if (strlen(argv[i]) >= sizeof(uuid_t)) {
-                        fprintf(stderr, "lov_config: arg %d (%s) too long\n",
-                                i, argv[i]);
-                        free(uuidarray);
-                        return -EINVAL;
-                }
-                strcpy(buf, argv[i]);
-        }
-
-        data.ioc_inllen1 = sizeof(desc);
-        data.ioc_inlbuf1 = (char *)&desc;
-        data.ioc_inllen2 = size;
-        data.ioc_inlbuf2 = (char *)uuidarray;
-
-        if (obd_ioctl_pack(&data, &buf, max)) {
-                fprintf(stderr, "error: %s: invalid ioctl\n", cmdname(argv[0]));
-                return -EINVAL;
-        }
-
-        rc = ioctl(fd, OBD_IOC_LOV_CONFIG, buf);
-        if (rc < 0)
-                fprintf(stderr, "lov_config: error: %s: %s\n",
-                        cmdname(argv[0]), strerror(rc = errno));
-        free(uuidarray);
-        return rc;
-}
-
-static int jt_test_ldlm(int argc, char **argv)
-{
-        struct obd_ioctl_data data;
-
-        IOCINIT(data);
-        if (argc != 1) {
-                fprintf(stderr, "usage: %s\n", cmdname(argv[0]));
-                return 1;
-        }
-
-        rc = ioctl(fd, IOC_LDLM_TEST, &data);
-        if (rc)
-                fprintf(stderr, "error: %s: test failed: %s\n",
-                        cmdname(argv[0]), strerror(rc = errno));
-        return rc;
-}
-
-static int jt_dump_ldlm(int argc, char **argv)
-{
-        struct obd_ioctl_data data;
-
-        IOCINIT(data);
-        if (argc != 1) {
-                fprintf(stderr, "usage: %s\n", cmdname(argv[0]));
-                return 1;
-        }
-
-        rc = ioctl(fd, IOC_LDLM_DUMP, &data);
-        if (rc)
-                fprintf(stderr, "error: %s failed: %s\n",
-                        cmdname(argv[0]), strerror(rc = errno));
-        return rc;
-}
-
-static int jt_newconn(int argc, char **argv)
-{
-        struct obd_ioctl_data data;
-
-        IOCINIT(data);
-        if (argc != 1) {
-                fprintf(stderr, "usage: %s\n", cmdname(argv[0]));
-                return -1;
-        }
-
-        rc = ioctl(fd, OBD_IOC_RECOVD_NEWCONN, &data);
-        if (rc < 0)
-                fprintf(stderr, "error: %s: %s\n", cmdname(argv[0]),
-                        strerror(rc = errno));
+#include "obdctl.h"
+#include "parser.h"
 
-        return rc;
-}
+/* the functions that were in here are now in obd.c */
 
 static int jt_quit(int argc, char **argv)
 {
+        int rc = 0;
         Parser_quit(argc, argv);
 
         return rc;
@@ -1684,39 +41,38 @@ static int jt_quit(int argc, char **argv)
 
 command_t cmdlist[] = {
         /* Metacommands */
-        {"--xml", jt__xml, 0, "--xml <xml file> <command [args ...]>"},
-        {"--device", jt__device, 0, "--device <devno> <command [args ...]>"},
-        {"--threads", jt__threads, 0,
+        {"--device", jt_opt_device, 0, "--device <devno> <command [args ...]>"},
+        {"--threads", jt_opt_threads, 0,
          "--threads <threads> <devno> <command [args ...]>"},
 
         /* Device configuration commands */
-        {"lovconfig", jt_lov_config, 0, "configure lov data on MDS "
+        {"lovconfig", jt_obd_lov_config, 0, "configure lov data on MDS "
          "[usage: lovconfig lov-uuid stripecount, stripesize, pattern, UUID1, [UUID2, ...]"},
-        {"list", jt_list, 0, "list the devices (no args)"},
-        {"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,
+        {"list", jt_obd_list, 0, "list the devices (no args)"},
+        {"newdev", jt_obd_newdev, 0, "set device to a new unused obd (no args)"},
+        {"device", jt_obd_device, 0, "set current device (args device_no name)"},
+        {"name2dev", jt_obd_name2dev, 0,
          "set device by name [usage: name2dev devname]"},
-        {"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: )"},
-        {"cleanup", jt_cleanup, 0, "cleanup the current device (arg: )"},
+        {"attach", jt_obd_attach, 0, "name the type of device (args: type data"},
+        {"setup", jt_obd_setup, 0, "setup device (args: <blkdev> [data]"},
+        {"detach", jt_obd_detach, 0, "detach the current device (arg: )"},
+        {"cleanup", jt_obd_cleanup, 0, "cleanup the current device (arg: )"},
 
         /* Session commands */
-        {"connect", jt_connect, 0, "connect - get a connection to device"},
-        {"disconnect", jt_disconnect, 0,
+        {"connect", jt_obd_connect, 0, "connect - get a connection to device"},
+        {"disconnect", jt_obd_disconnect, 0,
          "disconnect - break connection to device"},
 
         /* Session operations */
-        {"create", jt_create, 0, "create [count [mode [verbose]]]"},
-        {"destroy", jt_destroy, 0, "destroy <id>"},
-        {"getattr", jt_getattr, 0, "getattr <id>"},
-        {"setattr", jt_setattr, 0, "setattr <id> <mode>"},
-        {"newconn", jt_newconn, 0, "newconn [newuuid]"},
-        {"test_getattr", jt_test_getattr, 0, "test_getattr <count> [verbose]"},
-        {"test_brw", jt_test_brw, 0, "test_brw <count> [write [verbose]]"},
-        {"test_ldlm", jt_test_ldlm, 0, "test lock manager (no args)"},
-        {"dump_ldlm", jt_dump_ldlm, 0, "dump all lock manager state (no args)"},
+        {"create", jt_obd_create, 0, "create [count [mode [verbose]]]"},
+        {"destroy", jt_obd_destroy, 0, "destroy <id>"},
+        {"getattr", jt_obd_getattr, 0, "getattr <id>"},
+        {"setattr", jt_obd_setattr, 0, "setattr <id> <mode>"},
+        {"newconn", jt_obd_newconn, 0, "newconn [newuuid]"},
+        {"test_getattr", jt_obd_test_getattr, 0, "test_getattr <count> [verbose]"},
+        {"test_brw", jt_obd_test_brw, 0, "test_brw <count> [write [verbose]]"},
+        {"test_ldlm", jt_obd_test_ldlm, 0, "test lock manager (no args)"},
+        {"dump_ldlm", jt_obd_dump_ldlm, 0, "dump all lock manager state (no args)"},
 
         /* User interface commands */
         {"help", Parser_help, 0, "help"},
@@ -1726,26 +82,14 @@ command_t cmdlist[] = {
 };
 
 
-static void signal_server(int sig)
-{
-        if (sig == SIGINT) {
-                do_disconnect("sigint", 1);
-                exit(1);
-        } else
-                fprintf(stderr, "%s: got signal %d\n", cmdname("sigint"), sig);
-}
-
 int main(int argc, char **argv)
 {
-        struct sigaction sigact;
-
-        sigact.sa_handler = signal_server;
-        sigfillset(&sigact.sa_mask);
-        sigact.sa_flags = SA_RESTART;
-        sigaction(SIGINT, &sigact, NULL);
+        int rc;
 
         setlinebuf(stdout);
-        SHMEM_SETUP();
+
+        if (obd_initialize(argc, argv) < 0)
+                exit(1);
 
         if (argc > 1) {
                 rc = Parser_execarg(argc - 1, argv + 1, cmdlist);
@@ -1754,6 +98,6 @@ int main(int argc, char **argv)
                 rc = Parser_commands();
         }
 
-        do_disconnect(argv[0], 1);
+        obd_cleanup(argc, argv);
         return rc;
 }
diff --git a/lustre/utils/obdctl.h b/lustre/utils/obdctl.h
new file mode 100644 (file)
index 0000000..c075261
--- /dev/null
@@ -0,0 +1,57 @@
+/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
+ * vim:expandtab:shiftwidth=8:tabstop=8:
+ *
+ *  Copyright (C) 2002 Cluster File Systems, Inc.
+ *
+ *   Author: Peter J. Braam <braam@clusterfs.com>
+ *   Author: Phil Schwan <phil@clusterfs.com>
+ *   Author: Robert Read <rread@clusterfs.com> 
+ *
+ *   This file is part of Lustre, http://www.lustre.org.
+ *
+ *   Lustre is free software; you can redistribute it and/or
+ *   modify it under the terms of version 2 of the GNU General Public
+ *   License as published by the Free Software Foundation.
+ *
+ *   Lustre 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 for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with Lustre; if not, write to the Free Software
+ *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+#ifndef _OBDCTL_H_
+#define _OBDCTL_H_
+
+int do_disconnect(char *func, int verbose);
+int obd_initialize(int argc, char **argv);
+void obd_cleanup(int argc, char **argv);
+
+int jt_opt_device(int argc, char **argv);
+int jt_opt_threads(int argc, char **argv);
+
+int jt_obd_device(int argc, char **argv);
+int jt_obd_connect(int argc, char **argv);
+int jt_obd_disconnect(int argc, char **argv);
+int jt_obd_detach(int argc, char **argv);
+int jt_obd_cleanup(int argc, char **argv);
+int jt_obd_newdev(int argc, char **argv);
+int jt_obd_list(int argc, char **argv);
+int jt_obd_attach(int argc, char **argv);
+int jt_obd_name2dev(int argc, char **argv);
+int jt_obd_setup(int argc, char **argv);
+int jt_obd_create(int argc, char **argv);
+int jt_obd_setattr(int argc, char **argv);
+int jt_obd_destroy(int argc, char **argv);
+int jt_obd_getattr(int argc, char **argv);
+int jt_obd_test_getattr(int argc, char **argv);
+int jt_obd_test_brw(int argc, char **argv);
+int jt_obd_lov_config(int argc, char **argv);
+int jt_obd_test_ldlm(int argc, char **argv);
+int jt_obd_dump_ldlm(int argc, char **argv);
+int jt_obd_newconn(int argc, char **argv);
+
+#endif
index 0ecfd42..9b75d60 100644 (file)
@@ -339,6 +339,9 @@ int Parser_commands(void)
                         add_history(s);
                         rc = execute_line(s);
                 }
+                /* stop on error if not-interactive */
+                if (rc != 0 && !interactive)
+                        done = 1;
 
                 free(line);
         }