X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=lustre%2Futils%2Fobd.c;h=bbcb244faf2276e6a1533199a50efedaf61ab184;hb=3e2d4d2d7477dd338a87de103027d37865285e44;hp=619c96b978dc3d204e0b997b35a2a0f654d62f84;hpb=004cc2b4c6eb32672985e2f4b4bbf9413e314547;p=fs%2Flustre-release.git diff --git a/lustre/utils/obd.c b/lustre/utils/obd.c index 619c96b..bbcb244 100644 --- a/lustre/utils/obd.c +++ b/lustre/utils/obd.c @@ -1,6 +1,4 @@ -/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*- - * vim:expandtab:shiftwidth=8:tabstop=8: - * +/* * GPL HEADER START * * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. @@ -28,6 +26,8 @@ /* * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. + * + * Copyright (c) 2011, 2013, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ @@ -41,55 +41,59 @@ * Author: Robert Read */ -#include #include -#include #include +#include +#include #include +#include #include -#include -#include -#include -#include + #include +#include +#include #include +#include +#include +#include +#include +#include +#include +#include +#include #include "obdctl.h" #include /* for struct lov_stripe_md */ #include -#include -#include -#include -#include -#include -#include - -#include #include #include -#include -#include +#include #define MAX_STRING_SIZE 128 #define DEVICES_LIST "/proc/fs/lustre/devices" -#if HAVE_PTHREAD +#if HAVE_LIBPTHREAD #include #include #include -#define MAX_THREADS 1024 - +#define MAX_THREADS 4096 +#define MAX_BASE_ID 0xffffffff struct shared_data { - __u64 counters[MAX_THREADS]; - __u64 offsets[MAX_THREADS]; - int running; - int barrier; - int stop; l_mutex_t mutex; l_cond_t cond; + int stopping; + struct { + __u64 counters[MAX_THREADS]; + __u64 offsets[MAX_THREADS]; + int thr_running; + int start_barrier; + int stop_barrier; + struct timeval start_time; + struct timeval end_time; + } body; }; static struct shared_data *shared_data; @@ -103,16 +107,13 @@ const int thread = 0; const int nthreads = 1; #endif -#define MAX_IOC_BUFLEN 8192 - static int cur_device = -1; -#define MAX_STRIPES 170 -struct lov_oinfo lov_oinfos[MAX_STRIPES]; +struct lov_oinfo lov_oinfos[LOV_MAX_STRIPE_COUNT]; struct lsm_buffer { struct lov_stripe_md lsm; - struct lov_oinfo *ptrs[MAX_STRIPES]; + struct lov_oinfo *ptrs[LOV_MAX_STRIPE_COUNT]; } lsm_buffer; static int l2_ioctl(int dev_id, int opc, void *buf) @@ -126,7 +127,7 @@ int lcfg_ioctl(char * func, int dev_id, struct lustre_cfg *lcfg) char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf; int rc; - memset(&data, 0x00, sizeof(data)); + memset(&data, 0, sizeof(data)); data.ioc_dev = cur_device; data.ioc_type = LUSTRE_CFG_TYPE; data.ioc_plen1 = lustre_cfg_len(lcfg->lcfg_bufcount, @@ -174,7 +175,7 @@ int lcfg_mgs_ioctl(char *func, int dev_id, struct lustre_cfg *lcfg) char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf; int rc; - memset(&data, 0x00, sizeof(data)); + memset(&data, 0, sizeof(data)); rc = data.ioc_dev = get_mgs_device(); if (rc < 0) goto out; @@ -201,17 +202,18 @@ out: char *obdo_print(struct obdo *obd) { - char buf[1024]; + char buf[1024]; - sprintf(buf, "id: "LPX64"\ngrp: "LPX64"\natime: "LPU64"\nmtime: "LPU64 - "\nctime: "LPU64"\nsize: "LPU64"\nblocks: "LPU64 - "\nblksize: %u\nmode: %o\nuid: %d\ngid: %d\nflags: %x\n" - "misc: %x\nnlink: %d,\nvalid "LPX64"\n", - obd->o_id, obd->o_seq, 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_misc, - obd->o_nlink, obd->o_valid); - return strdup(buf); + sprintf(buf, "id: "LPX64"\ngrp: "LPX64"\natime: "LPU64"\nmtime: "LPU64 + "\nctime: "LPU64"\nsize: "LPU64"\nblocks: "LPU64 + "\nblksize: %u\nmode: %o\nuid: %d\ngid: %d\nflags: %x\n" + "misc: %x\nnlink: %d,\nvalid "LPX64"\n", + ostid_id(&obd->o_oi), ostid_seq(&obd->o_oi), 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_misc, + obd->o_nlink, obd->o_valid); + return strdup(buf); } @@ -225,17 +227,17 @@ static int do_name2dev(char *func, char *name) char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf; int rc; - memset(&data, 0x00, sizeof(data)); + memset(&data, 0, sizeof(data)); data.ioc_dev = cur_device; data.ioc_inllen1 = strlen(name) + 1; data.ioc_inlbuf1 = name; memset(buf, 0, sizeof(rawbuf)); rc = obd_ioctl_pack(&data, &buf, sizeof(rawbuf)); - if (rc) { + if (rc < 0) { fprintf(stderr, "error: %s: invalid ioctl\n", jt_cmdname(func)); - return rc; + return -rc; } rc = l2_ioctl(OBD_DEV_ID, OBD_IOC_NAME2DEV, buf); if (rc < 0) @@ -299,10 +301,10 @@ parse_lsm (struct lsm_buffer *lsmb, char *string) reset_lsmb (lsmb); - lsm->lsm_object_id = strtoull (string, &end, 0); - if (end == string) - return (-1); - string = end; + ostid_set_id(&lsm->lsm_oi, strtoull(string, &end, 0)); + if (end == string) + return -1; + string = end; if (*string == 0) return (0); @@ -328,17 +330,18 @@ parse_lsm (struct lsm_buffer *lsmb, char *string) if (*string == 0) /* don't have to specify obj ids */ return (0); - for (i = 0; i < lsm->lsm_stripe_count; i++) { - if (*string != '@') - return (-1); - string++; - lsm->lsm_oinfo[i]->loi_ost_idx = strtoul(string, &end, 0); - if (*end != ':') - return (-1); - string = end + 1; - lsm->lsm_oinfo[i]->loi_id = strtoull(string, &end, 0); - string = end; - } + for (i = 0; i < lsm->lsm_stripe_count; i++) { + if (*string != '@') + return (-1); + string++; + lsm->lsm_oinfo[i]->loi_ost_idx = strtoul(string, &end, 0); + if (*end != ':') + return (-1); + string = end + 1; + ostid_set_id(&lsm->lsm_oinfo[i]->loi_oi, + strtoull(string, &end, 0)); + string = end; + } if (*string != 0) return (-1); @@ -431,15 +434,19 @@ int do_disconnect(char *func, int verbose) } #ifdef MAX_THREADS -static void shmem_setup(void) +static int shmem_setup(void) { - /* Create new segment */ - int shmid = shmget(IPC_PRIVATE, sizeof(*shared_data), 0600); + pthread_mutexattr_t mattr; + pthread_condattr_t cattr; + int rc; + int shmid; + /* Create new segment */ + shmid = shmget(IPC_PRIVATE, sizeof(*shared_data), 0600); if (shmid == -1) { fprintf(stderr, "Can't create shared data: %s\n", strerror(errno)); - return; + return errno; } /* Attatch to new segment */ @@ -449,7 +456,7 @@ static void shmem_setup(void) fprintf(stderr, "Can't attach shared data: %s\n", strerror(errno)); shared_data = NULL; - return; + return errno; } /* Mark segment as destroyed, so it will disappear when we exit. @@ -458,7 +465,31 @@ static void shmem_setup(void) if (shmctl(shmid, IPC_RMID, NULL) == -1) { fprintf(stderr, "Can't destroy shared data: %s\n", strerror(errno)); + return errno; + } + + pthread_mutexattr_init(&mattr); + pthread_condattr_init(&cattr); + + rc = pthread_mutexattr_setpshared(&mattr, PTHREAD_PROCESS_SHARED); + if (rc != 0) { + fprintf(stderr, "Can't set shared mutex attr\n"); + return rc; } + + rc = pthread_condattr_setpshared(&cattr, PTHREAD_PROCESS_SHARED); + if (rc != 0) { + fprintf(stderr, "Can't set shared cond attr\n"); + return rc; + } + + pthread_mutex_init(&shared_data->mutex, &mattr); + pthread_cond_init(&shared_data->cond, &cattr); + + pthread_mutexattr_destroy(&mattr); + pthread_condattr_destroy(&cattr); + + return 0; } static inline void shmem_lock(void) @@ -471,32 +502,66 @@ static inline void shmem_unlock(void) l_mutex_unlock(&shared_data->mutex); } +static inline void shmem_wait(void) +{ + l_cond_wait(&shared_data->cond, &shared_data->mutex); +} + +static inline void shmem_wakeup_all(void) +{ + l_cond_broadcast(&shared_data->cond); +} + static inline void shmem_reset(int total_threads) { if (shared_data == NULL) return; - memset(shared_data, 0, sizeof(*shared_data)); - l_mutex_init(&shared_data->mutex); - l_cond_init(&shared_data->cond); + memset(&shared_data->body, 0, sizeof(shared_data->body)); memset(counter_snapshot, 0, sizeof(counter_snapshot)); prev_valid = 0; - shared_data->barrier = total_threads; + shared_data->stopping = 0; + shared_data->body.start_barrier = total_threads; + shared_data->body.stop_barrier = total_threads; } -static inline void shmem_bump(void) +static inline void shmem_bump(__u32 counter) { - static int bumped_running; + static bool running_not_bumped = true; if (shared_data == NULL || thread <= 0 || thread > MAX_THREADS) return; shmem_lock(); - shared_data->counters[thread - 1]++; - if (!bumped_running) - shared_data->running++; + shared_data->body.counters[thread - 1] += counter; + if (running_not_bumped) { + shared_data->body.thr_running++; + running_not_bumped = false; + } shmem_unlock(); - bumped_running = 1; +} + +static void shmem_total(int total_threads) +{ + __u64 total = 0; + double secs; + int i; + + if (shared_data == NULL || total_threads > MAX_THREADS) + return; + + shmem_lock(); + for (i = 0; i < total_threads; i++) + total += shared_data->body.counters[i]; + + secs = difftime(&shared_data->body.end_time, + &shared_data->body.start_time); + shmem_unlock(); + + printf("Total: total "LPU64" threads %d sec %f %f/second\n", + total, total_threads, secs, total / secs); + + return; } static void shmem_snap(int total_threads, int live_threads) @@ -512,9 +577,9 @@ static void shmem_snap(int total_threads, int live_threads) return; shmem_lock(); - memcpy(counter_snapshot[0], shared_data->counters, + memcpy(counter_snapshot[0], shared_data->body.counters, total_threads * sizeof(counter_snapshot[0][0])); - running = shared_data->running; + running = shared_data->body.thr_running; shmem_unlock(); gettimeofday(&this_time, NULL); @@ -529,12 +594,10 @@ static void shmem_snap(int total_threads, int live_threads) } } - secs = (this_time.tv_sec + this_time.tv_usec / 1000000.0) - - (prev_time.tv_sec + prev_time.tv_usec / 1000000.0); - - if (prev_valid && - secs > 1.0) /* someone screwed with the time? */ - printf("%d/%d Total: %f/second\n", non_zero, total_threads, total / secs); + secs = difftime(&this_time, &prev_time); + if (prev_valid && secs > 1.0) /* someone screwed with the time? */ + printf("%d/%d Total: %f/second\n", non_zero, total_threads, + total / secs); memcpy(counter_snapshot[1], counter_snapshot[0], total_threads * sizeof(counter_snapshot[0][0])); @@ -549,24 +612,54 @@ static void shmem_stop(void) if (shared_data == NULL) return; - shared_data->stop = 1; + shared_data->stopping = 1; +} + +static void shmem_cleanup(void) +{ + if (shared_data == NULL) + return; + + shmem_stop(); + + pthread_mutex_destroy(&shared_data->mutex); + pthread_cond_destroy(&shared_data->cond); } static int shmem_running(void) { - return (shared_data == NULL || - !shared_data->stop); + return (shared_data == NULL || !shared_data->stopping); +} + +static void shmem_end_time_locked(void) +{ + shared_data->body.stop_barrier--; + if (shared_data->body.stop_barrier == 0) + gettimeofday(&shared_data->body.end_time, NULL); } + +static void shmem_start_time_locked(void) +{ + shared_data->body.start_barrier--; + if (shared_data->body.start_barrier == 0) { + shmem_wakeup_all(); + gettimeofday(&shared_data->body.start_time, NULL); + } else { + shmem_wait(); + } +} + #else -static void shmem_setup(void) +static int shmem_setup(void) { + return 0; } static inline void shmem_reset(int total_threads) { } -static inline void shmem_bump(void) +static inline void shmem_bump(__u32 counters) { } @@ -578,7 +671,7 @@ static void shmem_unlock() { } -static void shmem_stop(void) +static void shmem_cleanup(void) { } @@ -784,6 +877,7 @@ int jt_opt_threads(int argc, char **argv) sigaction(SIGALRM, &saveact1, NULL); } + shmem_total(threads); sigprocmask(SIG_SETMASK, &saveset, NULL); return rc; @@ -822,7 +916,7 @@ int jt_obd_no_transno(int argc, char **argv) char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf; int rc; - memset(&data, 0x00, sizeof(data)); + memset(&data, 0, sizeof(data)); data.ioc_dev = cur_device; if (argc != 1) @@ -849,7 +943,7 @@ int jt_obd_set_readonly(int argc, char **argv) char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf; int rc; - memset(&data, 0x00, sizeof(data)); + memset(&data, 0, sizeof(data)); data.ioc_dev = cur_device; if (argc != 1) @@ -876,7 +970,7 @@ int jt_obd_abort_recovery(int argc, char **argv) char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf; int rc; - memset(&data, 0x00, sizeof(data)); + memset(&data, 0, sizeof(data)); data.ioc_dev = cur_device; if (argc != 1) @@ -900,25 +994,18 @@ int jt_obd_abort_recovery(int argc, char **argv) int jt_get_version(int argc, char **argv) { int rc; - char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf; - struct obd_ioctl_data *data = (struct obd_ioctl_data *)buf; + char rawbuf[MAX_IOC_BUFLEN]; + char *version; if (argc != 1) return CMD_HELP; - memset(buf, 0, sizeof(rawbuf)); - data->ioc_version = OBD_IOCTL_VERSION; - data->ioc_inllen1 = sizeof(rawbuf) - cfs_size_round(sizeof(*data)); - data->ioc_inlbuf1 = buf + cfs_size_round(sizeof(*data)); - data->ioc_len = obd_ioctl_packlen(data); - - rc = l2_ioctl(OBD_DEV_ID, OBD_GET_VERSION, buf); - if (rc < 0) + rc = llapi_get_version(rawbuf, MAX_IOC_BUFLEN, &version); + if (rc) fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]), - strerror(rc = errno)); - else { - printf("Lustre version: %s\n", data->ioc_bulk); - } + strerror(-rc)); + else + printf("Lustre version: %s\n", version); printf("lctl version: %s\n", BUILD_VERSION); return rc; @@ -1045,6 +1132,398 @@ int jt_obd_list(int argc, char **argv) return 0; } +struct jt_fid_space { + obd_seq jt_seq; + obd_id jt_id; + int jt_width; +}; + +int jt_obd_alloc_fids(struct jt_fid_space *space, struct lu_fid *fid, + __u64 *count) +{ + int rc; + + if (space->jt_seq == 0 || space->jt_id == space->jt_width) { + struct obd_ioctl_data data; + char rawbuf[MAX_IOC_BUFLEN]; + char *buf = rawbuf; + __u64 seqnr; + int max_count; + + memset(&data, 0, sizeof(data)); + data.ioc_dev = cur_device; + + data.ioc_pbuf1 = (char *)&seqnr; + data.ioc_plen1 = sizeof(seqnr); + + data.ioc_pbuf2 = (char *)&max_count; + data.ioc_plen2 = sizeof(max_count); + + memset(buf, 0, sizeof(rawbuf)); + rc = obd_ioctl_pack(&data, &buf, sizeof(rawbuf)); + if (rc) { + fprintf(stderr, "error: invalid ioctl rc = %d\n", rc); + return rc; + } + + rc = l2_ioctl(OBD_DEV_ID, OBD_IOC_ECHO_ALLOC_SEQ, buf); + if (rc) { + fprintf(stderr, "ioctl error: rc = %d\n", rc); + return rc; + } + + space->jt_seq = *(__u64 *)data.ioc_pbuf1; + space->jt_width = *(int *)data.ioc_pbuf2; + space->jt_id = 1; + } + fid->f_seq = space->jt_seq; + fid->f_oid = space->jt_id; + fid->f_ver = 0; + + space->jt_id = min(space->jt_id + *count, space->jt_width); + + *count = space->jt_id - fid->f_oid; + return 0; +} + +#define MD_STEP_COUNT 1000 +int jt_obd_md_common(int argc, char **argv, int cmd) +{ + struct obd_ioctl_data data; + struct timeval start; + struct timeval end_time; + char rawbuf[MAX_IOC_BUFLEN]; + char *buf = rawbuf; + int mode = 0000644; + int create_mode; + int rc = 0; + char *parent_basedir = NULL; + char dirname[4096]; + int parent_base_id = 0; + int parent_count = 1; + __u64 child_base_id = -1; + int stripe_count = 0; + int stripe_index = -1; + int count = 0; + char *end; + __u64 seconds = 0; + double diff; + int c; + int xattr_size = 0; + __u64 total_count = 0; + char *name = NULL; + struct jt_fid_space fid_space = {0}; + int version = 0; + struct option long_opts[] = { + {"child_base_id", required_argument, 0, 'b'}, + {"stripe_count", required_argument, 0, 'c'}, + {"parent_basedir", required_argument, 0, 'd'}, + {"parent_dircount", required_argument, 0, 'D'}, + {"stripe_index", required_argument, 0, 'i'}, + {"mode", required_argument, 0, 'm'}, + {"count", required_argument, 0, 'n'}, + {"time", required_argument, 0, 't'}, + {"version", no_argument, 0, 'v'}, + {"xattr_size", required_argument, 0, 'x'}, + {0, 0, 0, 0} + }; + + optind = 0; + while ((c = getopt_long(argc, argv, "b:c:d:D:m:n:t:vx:", + long_opts, NULL)) >= 0) { + switch (c) { + case 'b': + child_base_id = strtoull(optarg, &end, 0); + if (*end) { + fprintf(stderr, "error: %s: bad child_base_id" + " '%s'\n", jt_cmdname(argv[0]), optarg); + return CMD_HELP; + } + break; + case 'c': + stripe_count = strtoul(optarg, &end, 0); + if (*end) { + fprintf(stderr, "error: %s: bad stripe count" + " '%s'\n", jt_cmdname(argv[0]), optarg); + return CMD_HELP; + } + break; + case 'd': + parent_basedir = optarg; + break; + case 'D': + parent_count = strtoul(optarg, &end, 0); + if (*end) { + fprintf(stderr, "error: %s: bad parent count" + " '%s'\n", jt_cmdname(argv[0]), optarg); + return CMD_HELP; + } + break; + case 'i': + stripe_index = strtoul(optarg, &end, 0); + if (*end) { + fprintf(stderr, "error: %s: bad stripe index" + " '%s'\n", jt_cmdname(argv[0]), optarg); + return CMD_HELP; + } + break; + case 'm': + mode = strtoul(optarg, &end, 0); + if (*end) { + fprintf(stderr, "error: %s: bad mode '%s'\n", + jt_cmdname(argv[0]), optarg); + return CMD_HELP; + } + break; + case 'n': + total_count = strtoul(optarg, &end, 0); + if (*end || total_count == 0) { + fprintf(stderr, "%s: bad child count '%s'\n", + jt_cmdname(argv[0]), optarg); + return CMD_HELP; + } + break; + case 't': + seconds = strtoull(optarg, &end, 0); + if (*end) { + fprintf(stderr, "error: %s: seconds '%s'\n", + jt_cmdname(argv[0]), optarg); + return CMD_HELP; + } + break; + case 'v': + version = 1; + break; + case 'x': + xattr_size = strtoul(optarg, &end, 0); + if (*end) { + fprintf(stderr, "error: %s: xattr_size '%s'\n", + jt_cmdname(argv[0]), optarg); + return CMD_HELP; + } + SET_BUT_UNUSED(xattr_size); + break; + default: + fprintf(stderr, "error: %s: option '%s' " + "unrecognized\n", argv[0], argv[optind - 1]); + return CMD_HELP; + } + } + + memset(&data, 0, sizeof(data)); + data.ioc_dev = cur_device; + if (child_base_id == -1) { + if (optind >= argc) + return CMD_HELP; + name = argv[optind]; + total_count = 1; + } else { + if (optind < argc) { + fprintf(stderr, "child_base_id and name can not" + " specified at the same time\n"); + return CMD_HELP; + } + } + + if (stripe_count == 0 && stripe_index != -1) { + fprintf(stderr, "If stripe_count is 0, stripe_index can not" + "be specified\n"); + return CMD_HELP; + } + + if (total_count == 0 && seconds == 0) { + fprintf(stderr, "count or seconds needs to be indicated\n"); + return CMD_HELP; + } + + if (parent_count <= 0) { + fprintf(stderr, "parent count must < 0\n"); + return CMD_HELP; + } + +#ifdef MAX_THREADS + if (thread) { + shmem_lock(); + /* threads interleave */ + if (parent_base_id != -1) + parent_base_id += (thread - 1) % parent_count; + + if (child_base_id != -1) + child_base_id += (thread - 1) * \ + (MAX_BASE_ID / nthreads); + + shmem_start_time_locked(); + shmem_unlock(); + } +#endif + /* If parent directory is not specified, try to get the directory + * from name */ + if (parent_basedir == NULL) { + char *last_lash; + if (name == NULL) { + fprintf(stderr, "parent_basedir or name must be" + "indicated!\n"); + return CMD_HELP; + } + /*Get directory and name from name*/ + last_lash = strrchr(name, '/'); + if (last_lash == NULL || name[0] != '/') { + fprintf(stderr, "Can not locate %s\n", name); + return CMD_HELP; + } + + if (last_lash == name) { + sprintf(dirname, "%s", "/"); + name++; + } else { + int namelen = (unsigned long)last_lash - + (unsigned long)name; + snprintf(dirname, namelen, "%s", name); + } + + data.ioc_pbuf1 = dirname; + data.ioc_plen1 = strlen(dirname); + + data.ioc_pbuf2 = name; + data.ioc_plen2 = strlen(name); + } else { + if (name != NULL) { + data.ioc_pbuf2 = name; + data.ioc_plen2 = strlen(name); + } else { + if (parent_base_id > 0) + sprintf(dirname, "%s%d", parent_basedir, + parent_base_id); + else + sprintf(dirname, "%s", parent_basedir); + } + data.ioc_pbuf1 = dirname; + data.ioc_plen1 = strlen(dirname); + } + + if (cmd == ECHO_MD_MKDIR || cmd == ECHO_MD_RMDIR) + create_mode = S_IFDIR; + else + create_mode = S_IFREG; + + data.ioc_obdo1.o_mode = mode | S_IFDIR; + data.ioc_obdo1.o_valid = OBD_MD_FLID | OBD_MD_FLTYPE | OBD_MD_FLMODE | + OBD_MD_FLFLAGS | OBD_MD_FLGROUP; + data.ioc_command = cmd; + + gettimeofday(&start, NULL); + while (shmem_running()) { + struct lu_fid fid = { 0 }; + + ostid_set_id(&data.ioc_obdo2.o_oi, child_base_id); + data.ioc_obdo2.o_mode = mode | create_mode; + data.ioc_obdo2.o_valid = OBD_MD_FLID | OBD_MD_FLTYPE | + OBD_MD_FLMODE | OBD_MD_FLFLAGS | + OBD_MD_FLGROUP; + data.ioc_obdo2.o_misc = stripe_count; + data.ioc_obdo2.o_stripe_idx = stripe_index; + + if (total_count > 0) { + if ((total_count - count) > MD_STEP_COUNT) + data.ioc_count = MD_STEP_COUNT; + else + data.ioc_count = total_count - count; + } else { + data.ioc_count = MD_STEP_COUNT; + } + + if (cmd == ECHO_MD_CREATE || cmd == ECHO_MD_MKDIR) { + /*Allocate fids for the create */ + rc = jt_obd_alloc_fids(&fid_space, &fid, + &data.ioc_count); + if (rc) { + fprintf(stderr, "Allocate fids error %d.\n",rc); + return rc; + } + fid_to_ostid(&fid, &data.ioc_obdo1.o_oi); + } + + child_base_id += data.ioc_count; + count += data.ioc_count; + + memset(buf, 0, sizeof(rawbuf)); + rc = obd_ioctl_pack(&data, &buf, sizeof(rawbuf)); + if (rc) { + fprintf(stderr, "error: %s: invalid ioctl %d\n", + jt_cmdname(argv[0]), rc); + return rc; + } + + rc = l2_ioctl(OBD_DEV_ID, OBD_IOC_ECHO_MD, buf); + if (rc) { + fprintf(stderr, "error: %s: %s\n", + jt_cmdname(argv[0]), strerror(rc = errno)); + return rc; + } + shmem_bump(data.ioc_count); + + gettimeofday(&end_time, NULL); + diff = difftime(&end_time, &start); + if (seconds > 0 && (__u64)diff > seconds) + break; + + if (count >= total_count && total_count > 0) + break; + } + + if (count > 0 && version) { + gettimeofday(&end_time, NULL); + diff = difftime(&end_time, &start); + printf("%s: %d in %.3fs (%.3f /s): %s", + jt_cmdname(argv[0]), count, diff, + (double)count/diff, ctime(&end_time.tv_sec)); + } + +#ifdef MAX_THREADS + if (thread) { + shmem_lock(); + shmem_end_time_locked(); + shmem_unlock(); + } +#endif + return rc; +} + +int jt_obd_test_create(int argc, char **argv) +{ + return jt_obd_md_common(argc, argv, ECHO_MD_CREATE); +} + +int jt_obd_test_mkdir(int argc, char **argv) +{ + return jt_obd_md_common(argc, argv, ECHO_MD_MKDIR); +} + +int jt_obd_test_destroy(int argc, char **argv) +{ + return jt_obd_md_common(argc, argv, ECHO_MD_DESTROY); +} + +int jt_obd_test_rmdir(int argc, char **argv) +{ + return jt_obd_md_common(argc, argv, ECHO_MD_RMDIR); +} + +int jt_obd_test_lookup(int argc, char **argv) +{ + return jt_obd_md_common(argc, argv, ECHO_MD_LOOKUP); +} + +int jt_obd_test_setxattr(int argc, char **argv) +{ + return jt_obd_md_common(argc, argv, ECHO_MD_SETATTR); +} + +int jt_obd_test_md_getattr(int argc, char **argv) +{ + return jt_obd_md_common(argc, argv, ECHO_MD_GETATTR); +} + /* Create one or more objects, arg[4] may describe stripe meta-data. If * not, defaults assumed. This echo-client instance stashes the stripe * object ids. Use get_stripe on this node to print full lsm and @@ -1056,11 +1535,11 @@ int jt_obd_create(int argc, char **argv) char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf; struct obd_ioctl_data data; struct timeval next_time; - __u64 count = 1, next_count, base_id = 0; + __u64 count = 1, next_count, base_id = 1; int verbose = 1, mode = 0100644, rc = 0, i, valid_lsm = 0; char *end; - memset(&data, 0x00, sizeof(data)); + memset(&data, 0, sizeof(data)); data.ioc_dev = cur_device; if (argc < 2 || argc > 5) return CMD_HELP; @@ -1089,35 +1568,36 @@ int jt_obd_create(int argc, char **argv) return CMD_HELP; } - if (argc < 5) { - reset_lsmb (&lsm_buffer); /* will set default */ - } else { - rc = parse_lsm (&lsm_buffer, argv[4]); - if (rc != 0) { - fprintf(stderr, "error: %s: invalid lsm '%s'\n", - jt_cmdname(argv[0]), argv[4]); - return CMD_HELP; - } - base_id = lsm_buffer.lsm.lsm_object_id; - valid_lsm = 1; - } + if (argc < 5) { + reset_lsmb(&lsm_buffer); /* will set default */ + } else { + rc = parse_lsm(&lsm_buffer, argv[4]); + if (rc != 0) { + fprintf(stderr, "error: %s: invalid lsm '%s'\n", + jt_cmdname(argv[0]), argv[4]); + return CMD_HELP; + } + base_id = ostid_id(&lsm_buffer.lsm.lsm_oi); + valid_lsm = 1; + } printf("%s: "LPD64" objects\n", jt_cmdname(argv[0]), count); gettimeofday(&next_time, NULL); next_time.tv_sec -= verbose; + ostid_set_seq_echo(&data.ioc_obdo1.o_oi); for (i = 1, next_count = verbose; i <= count && shmem_running(); i++) { - data.ioc_obdo1.o_mode = mode; - data.ioc_obdo1.o_id = base_id; - data.ioc_obdo1.o_uid = 0; - data.ioc_obdo1.o_gid = 0; - data.ioc_obdo1.o_valid = OBD_MD_FLTYPE | OBD_MD_FLMODE | - OBD_MD_FLID | OBD_MD_FLUID | OBD_MD_FLGID; - - if (valid_lsm) { - data.ioc_plen1 = sizeof lsm_buffer; - data.ioc_pbuf1 = (char *)&lsm_buffer; - } + data.ioc_obdo1.o_mode = mode; + ostid_set_id(&data.ioc_obdo1.o_oi, base_id); + data.ioc_obdo1.o_uid = 0; + data.ioc_obdo1.o_gid = 0; + data.ioc_obdo1.o_valid = OBD_MD_FLTYPE | OBD_MD_FLMODE | + OBD_MD_FLID | OBD_MD_FLUID | + OBD_MD_FLGID | OBD_MD_FLGROUP; + if (valid_lsm) { + data.ioc_plen1 = sizeof lsm_buffer; + data.ioc_pbuf1 = (char *)&lsm_buffer; + } memset(buf, 0, sizeof(rawbuf)); rc = obd_ioctl_pack(&data, &buf, sizeof(rawbuf)); @@ -1128,7 +1608,7 @@ int jt_obd_create(int argc, char **argv) } rc = l2_ioctl(OBD_DEV_ID, OBD_IOC_CREATE, buf); obd_ioctl_unpack(&data, buf, sizeof(rawbuf)); - shmem_bump(); + shmem_bump(1); if (rc < 0) { fprintf(stderr, "error: %s: #%d - %s\n", jt_cmdname(argv[0]), i, strerror(rc = errno)); @@ -1141,9 +1621,10 @@ int jt_obd_create(int argc, char **argv) break; } - if (be_verbose(verbose, &next_time, i, &next_count, count)) - printf("%s: #%d is object id "LPX64"\n", - jt_cmdname(argv[0]), i, data.ioc_obdo1.o_id); + if (be_verbose(verbose, &next_time, i, &next_count, count)) + printf("%s: #%d is object id "LPX64"\n", + jt_cmdname(argv[0]), i, + ostid_id(&data.ioc_obdo1.o_oi)); } return rc; } @@ -1155,12 +1636,13 @@ int jt_obd_setattr(int argc, char **argv) char *end; int rc; - memset(&data, 0x00, sizeof(data)); + memset(&data, 0, sizeof(data)); data.ioc_dev = cur_device; if (argc != 2) return CMD_HELP; - data.ioc_obdo1.o_id = strtoull(argv[1], &end, 0); + ostid_set_seq_echo(&data.ioc_obdo1.o_oi); + ostid_set_id(&data.ioc_obdo1.o_oi, strtoull(argv[1], &end, 0)); if (*end) { fprintf(stderr, "error: %s: invalid objid '%s'\n", jt_cmdname(argv[0]), argv[1]); @@ -1203,7 +1685,7 @@ int jt_obd_test_setattr(int argc, char **argv) if (argc < 2 || argc > 4) return CMD_HELP; - memset(&data, 0x00, sizeof(data)); + memset(&data, 0, sizeof(data)); data.ioc_dev = cur_device; count = strtoull(argv[1], &end, 0); if (*end) { @@ -1239,11 +1721,12 @@ int jt_obd_test_setattr(int argc, char **argv) printf("%s: setting "LPD64" attrs (objid "LPX64"): %s", jt_cmdname(argv[0]), count, objid, ctime(&start.tv_sec)); + ostid_set_seq_echo(&data.ioc_obdo1.o_oi); for (i = 1, next_count = verbose; i <= count && shmem_running(); i++) { - data.ioc_obdo1.o_id = objid; + ostid_set_id(&data.ioc_obdo1.o_oi, objid); data.ioc_obdo1.o_mode = S_IFREG; data.ioc_obdo1.o_valid = OBD_MD_FLID | OBD_MD_FLTYPE | OBD_MD_FLMODE; - memset(buf, 0x00, sizeof(rawbuf)); + memset(buf, 0, sizeof(rawbuf)); rc = obd_ioctl_pack(&data, &buf, sizeof(rawbuf)); if (rc) { fprintf(stderr, "error: %s: invalid ioctl\n", @@ -1251,7 +1734,7 @@ int jt_obd_test_setattr(int argc, char **argv) return rc; } rc = l2_ioctl(OBD_DEV_ID, OBD_IOC_SETATTR, &data); - shmem_bump(); + shmem_bump(1); if (rc < 0) { fprintf(stderr, "error: %s: #"LPD64" - %d:%s\n", jt_cmdname(argv[0]), i, errno, strerror(rc = errno)); @@ -1292,7 +1775,7 @@ int jt_obd_destroy(int argc, char **argv) char *end; int rc = 0, i; - memset(&data, 0x00, sizeof(data)); + memset(&data, 0, sizeof(data)); data.ioc_dev = cur_device; if (argc < 2 || argc > 4) return CMD_HELP; @@ -1323,10 +1806,11 @@ int jt_obd_destroy(int argc, char **argv) gettimeofday(&next_time, NULL); next_time.tv_sec -= verbose; + ostid_set_seq_echo(&data.ioc_obdo1.o_oi); for (i = 1, next_count = verbose; i <= count && shmem_running(); i++, id++) { - data.ioc_obdo1.o_id = id; - data.ioc_obdo1.o_mode = S_IFREG | 0644; - data.ioc_obdo1.o_valid = OBD_MD_FLID | OBD_MD_FLMODE; + ostid_set_id(&data.ioc_obdo1.o_oi, id); + data.ioc_obdo1.o_mode = S_IFREG | 0644; + data.ioc_obdo1.o_valid = OBD_MD_FLID | OBD_MD_FLMODE; memset(buf, 0, sizeof(rawbuf)); rc = obd_ioctl_pack(&data, &buf, sizeof(rawbuf)); @@ -1337,7 +1821,7 @@ int jt_obd_destroy(int argc, char **argv) } rc = l2_ioctl(OBD_DEV_ID, OBD_IOC_DESTROY, buf); obd_ioctl_unpack(&data, buf, sizeof(rawbuf)); - shmem_bump(); + shmem_bump(1); if (rc < 0) { fprintf(stderr, "error: %s: objid "LPX64": %s\n", jt_cmdname(argv[0]), id, strerror(rc = errno)); @@ -1362,18 +1846,20 @@ int jt_obd_getattr(int argc, char **argv) if (argc != 2) return CMD_HELP; - memset(&data, 0x00, sizeof(data)); - data.ioc_dev = cur_device; - data.ioc_obdo1.o_id = strtoull(argv[1], &end, 0); - if (*end) { - fprintf(stderr, "error: %s: invalid objid '%s'\n", - jt_cmdname(argv[0]), argv[1]); - return CMD_HELP; - } - /* to help obd filter */ - data.ioc_obdo1.o_mode = 0100644; - data.ioc_obdo1.o_valid = 0xffffffff; - printf("%s: object id "LPX64"\n", jt_cmdname(argv[0]),data.ioc_obdo1.o_id); + memset(&data, 0, sizeof(data)); + data.ioc_dev = cur_device; + ostid_set_seq_echo(&data.ioc_obdo1.o_oi); + ostid_set_id(&data.ioc_obdo1.o_oi, strtoull(argv[1], &end, 0)); + if (*end) { + fprintf(stderr, "error: %s: invalid objid '%s'\n", + jt_cmdname(argv[0]), argv[1]); + return CMD_HELP; + } + /* to help obd filter */ + data.ioc_obdo1.o_mode = 0100644; + data.ioc_obdo1.o_valid = 0xffffffff; + printf("%s: object id "LPX64"\n", jt_cmdname(argv[0]), + ostid_id(&data.ioc_obdo1.o_oi)); memset(buf, 0, sizeof(rawbuf)); rc = obd_ioctl_pack(&data, &buf, sizeof(rawbuf)); @@ -1388,8 +1874,8 @@ int jt_obd_getattr(int argc, char **argv) fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]), strerror(rc = errno)); } else { - printf("%s: object id "LPX64", mode %o\n", jt_cmdname(argv[0]), - data.ioc_obdo1.o_id, data.ioc_obdo1.o_mode); + printf("%s: object id "LPU64", mode %o\n", jt_cmdname(argv[0]), + ostid_id(&data.ioc_obdo1.o_oi), data.ioc_obdo1.o_mode); } return rc; } @@ -1408,7 +1894,7 @@ int jt_obd_test_getattr(int argc, char **argv) if (argc < 2 || argc > 4) return CMD_HELP; - memset(&data, 0x00, sizeof(data)); + memset(&data, 0, sizeof(data)); data.ioc_dev = cur_device; count = strtoull(argv[1], &end, 0); if (*end) { @@ -1444,19 +1930,20 @@ int jt_obd_test_getattr(int argc, char **argv) printf("%s: getting "LPD64" attrs (objid "LPX64"): %s", jt_cmdname(argv[0]), count, objid, ctime(&start.tv_sec)); + ostid_set_seq_echo(&data.ioc_obdo1.o_oi); for (i = 1, next_count = verbose; i <= count && shmem_running(); i++) { - data.ioc_obdo1.o_id = objid; - data.ioc_obdo1.o_mode = S_IFREG; - data.ioc_obdo1.o_valid = 0xffffffff; - memset(buf, 0x00, sizeof(rawbuf)); - rc = obd_ioctl_pack(&data, &buf, sizeof(rawbuf)); - if (rc) { - fprintf(stderr, "error: %s: invalid ioctl\n", - jt_cmdname(argv[0])); - return rc; - } + ostid_set_id(&data.ioc_obdo1.o_oi, objid); + data.ioc_obdo1.o_mode = S_IFREG; + data.ioc_obdo1.o_valid = 0xffffffff; + memset(buf, 0, sizeof(rawbuf)); + rc = obd_ioctl_pack(&data, &buf, sizeof(rawbuf)); + if (rc) { + fprintf(stderr, "error: %s: invalid ioctl\n", + jt_cmdname(argv[0])); + return rc; + } rc = l2_ioctl(OBD_DEV_ID, OBD_IOC_GETATTR, &data); - shmem_bump(); + shmem_bump(1); if (rc < 0) { fprintf(stderr, "error: %s: #"LPD64" - %d:%s\n", jt_cmdname(argv[0]), i, errno, strerror(rc = errno)); @@ -1587,7 +2074,7 @@ int jt_obd_test_brw(int argc, char **argv) } } - memset(&data, 0x00, sizeof(data)); + memset(&data, 0, sizeof(data)); data.ioc_dev = cur_device; /* communicate the 'type' of brw test and batching to echo_client. @@ -1635,31 +2122,29 @@ int jt_obd_test_brw(int argc, char **argv) obj_idx = (thread - 1)/nthr_per_obj; objid += obj_idx; stride *= nthr_per_obj; - if ((thread - 1) % nthr_per_obj == 0) - shared_data->offsets[obj_idx] = stride + thr_offset; + if ((thread - 1) % nthr_per_obj == 0) { + shared_data->body.offsets[obj_idx] = + stride + thr_offset; + } thr_offset += ((thread - 1) % nthr_per_obj) * len; } else { /* threads disjoint */ thr_offset += (thread - 1) * len; } - shared_data->barrier--; - if (shared_data->barrier == 0) - l_cond_broadcast(&shared_data->cond); - else - l_cond_wait(&shared_data->cond, - &shared_data->mutex); - + shmem_start_time_locked(); shmem_unlock (); } #endif - data.ioc_obdo1.o_id = objid; - data.ioc_obdo1.o_mode = S_IFREG; - data.ioc_obdo1.o_valid = OBD_MD_FLID | OBD_MD_FLTYPE | OBD_MD_FLMODE | OBD_MD_FLFLAGS; - data.ioc_obdo1.o_flags = (verify ? OBD_FL_DEBUG_CHECK : 0); - data.ioc_count = len; - data.ioc_offset = (repeat_offset ? 0 : thr_offset); + ostid_set_seq_echo(&data.ioc_obdo1.o_oi); + ostid_set_id(&data.ioc_obdo1.o_oi, objid); + data.ioc_obdo1.o_mode = S_IFREG; + data.ioc_obdo1.o_valid = OBD_MD_FLID | OBD_MD_FLTYPE | OBD_MD_FLMODE | + OBD_MD_FLFLAGS | OBD_MD_FLGROUP; + data.ioc_obdo1.o_flags = (verify ? OBD_FL_DEBUG_CHECK : 0); + data.ioc_count = len; + data.ioc_offset = (repeat_offset ? 0 : thr_offset); gettimeofday(&start, NULL); next_time.tv_sec = start.tv_sec - verbose; @@ -1673,7 +2158,7 @@ int jt_obd_test_brw(int argc, char **argv) cmd = write ? OBD_IOC_BRW_WRITE : OBD_IOC_BRW_READ; for (i = 1, next_count = verbose; i <= count && shmem_running(); i++) { data.ioc_obdo1.o_valid &= ~(OBD_MD_FLBLOCKS|OBD_MD_FLGRANT); - memset(buf, 0x00, sizeof(rawbuf)); + memset(buf, 0, sizeof(rawbuf)); rc = obd_ioctl_pack(&data, &buf, sizeof(rawbuf)); if (rc) { fprintf(stderr, "error: %s: invalid ioctl\n", @@ -1681,19 +2166,19 @@ int jt_obd_test_brw(int argc, char **argv) return rc; } rc = l2_ioctl(OBD_DEV_ID, cmd, buf); - shmem_bump(); + shmem_bump(1); if (rc) { fprintf(stderr, "error: %s: #%d - %s on %s\n", jt_cmdname(argv[0]), i, strerror(rc = errno), write ? "write" : "read"); break; } else if (be_verbose(verbose, &next_time,i, &next_count,count)) { - shmem_lock (); - printf("%s: %s number %d @ "LPD64":"LPU64" for %d\n", - jt_cmdname(argv[0]), write ? "write" : "read", i, - data.ioc_obdo1.o_id, data.ioc_offset, - (int)(pages * getpagesize())); - shmem_unlock (); + shmem_lock (); + printf("%s: %s number %d @ "LPD64":"LPU64" for %d\n", + jt_cmdname(argv[0]), write ? "write" : "read", i, + ostid_id(&data.ioc_obdo1.o_oi), data.ioc_offset, + (int)(pages * getpagesize())); + shmem_unlock (); } if (!repeat_offset) { @@ -1702,8 +2187,9 @@ int jt_obd_test_brw(int argc, char **argv) data.ioc_offset += stride; } else if (i < count) { shmem_lock (); - data.ioc_offset = shared_data->offsets[obj_idx]; - shared_data->offsets[obj_idx] += len; + data.ioc_offset = + shared_data->body.offsets[obj_idx]; + shared_data->body.offsets[obj_idx] += len; shmem_unlock (); } #else @@ -1731,6 +2217,13 @@ int jt_obd_test_brw(int argc, char **argv) ctime(&end.tv_sec)); } +#ifdef MAX_THREADS + if (thread) { + shmem_lock(); + shmem_end_time_locked(); + shmem_unlock(); + } +#endif return rc; } @@ -1744,7 +2237,7 @@ int jt_obd_lov_getconfig(int argc, char **argv) char *path; int rc, fd; - memset(&data, 0x00, sizeof(data)); + memset(&data, 0, sizeof(data)); data.ioc_dev = cur_device; if (argc != 2) @@ -1779,7 +2272,7 @@ repeat: goto out_uuidarray; } - memset(buf, 0x00, sizeof(rawbuf)); + memset(buf, 0, sizeof(rawbuf)); data.ioc_inllen1 = sizeof(desc); data.ioc_inlbuf1 = (char *)&desc; data.ioc_inllen2 = desc.ld_tgt_count * sizeof(*uuidarray); @@ -1846,7 +2339,7 @@ int jt_obd_ldlm_regress_start(int argc, char **argv) char argstring[200]; int i, count = sizeof(argstring) - 1; - memset(&data, 0x00, sizeof(data)); + memset(&data, 0, sizeof(data)); data.ioc_dev = cur_device; if (argc > 5) return CMD_HELP; @@ -1885,7 +2378,7 @@ int jt_obd_ldlm_regress_stop(int argc, char **argv) char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf; struct obd_ioctl_data data; - memset(&data, 0x00, sizeof(data)); + memset(&data, 0, sizeof(data)); data.ioc_dev = cur_device; if (argc != 1) @@ -1912,7 +2405,7 @@ static int do_activate(int argc, char **argv, int flag) char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf; int rc; - memset(&data, 0x00, sizeof(data)); + memset(&data, 0, sizeof(data)); data.ioc_dev = cur_device; if (argc != 1) return CMD_HELP; @@ -1935,6 +2428,56 @@ static int do_activate(int argc, char **argv, int flag) return rc; } +/** + * Replace nids for given device. + * lctl replace_nids [,nid2,nid3] + * Command should be started on MGS server. + * Only MGS server should be started (command execution + * returns error in another cases). Command mount + * -t lustre -o nosvc + * can be used for that. + * + * llogs for MDTs and clients are processed. All + * records copied as is except add_uuid and setup. This records + * are skipped and recorded with new nids and uuid. + * + * \see mgs_replace_nids + * \see mgs_replace_nids_log + * \see mgs_replace_handler + */ +int jt_replace_nids(int argc, char **argv) +{ + int rc; + char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf; + struct obd_ioctl_data data; + + memset(&data, 0, sizeof(data)); + data.ioc_dev = get_mgs_device(); + if (argc != 3) + return CMD_HELP; + + data.ioc_inllen1 = strlen(argv[1]) + 1; + data.ioc_inlbuf1 = argv[1]; + + data.ioc_inllen2 = strlen(argv[2]) + 1; + data.ioc_inlbuf2 = argv[2]; + memset(buf, 0, sizeof(rawbuf)); + rc = obd_ioctl_pack(&data, &buf, sizeof(rawbuf)); + if (rc) { + fprintf(stderr, "error: %s: invalid ioctl\n", + jt_cmdname(argv[0])); + return rc; + } + + rc = l2_ioctl(OBD_DEV_ID, OBD_IOC_REPLACE_NIDS, buf); + if (rc < 0) { + fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]), + strerror(rc = errno)); + } + + return rc; +} + int jt_obd_deactivate(int argc, char **argv) { return do_activate(argc, argv, 0); @@ -1951,7 +2494,7 @@ int jt_obd_recover(int argc, char **argv) char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf; struct obd_ioctl_data data; - memset(&data, 0x00, sizeof(data)); + memset(&data, 0, sizeof(data)); data.ioc_dev = cur_device; if (argc > 2) return CMD_HELP; @@ -1992,7 +2535,7 @@ int jt_obd_mdc_lookup(int argc, char **argv) if (argc == 4) verbose = get_verbose(argv[0], argv[3]); - memset(&data, 0x00, sizeof(data)); + memset(&data, 0, sizeof(data)); data.ioc_dev = cur_device; data.ioc_inllen1 = strlen(child) + 1; @@ -2044,7 +2587,7 @@ int jt_cfg_dump_log(int argc, char **argv) if (argc != 2) return CMD_HELP; - memset(&data, 0x00, sizeof(data)); + memset(&data, 0, sizeof(data)); data.ioc_dev = cur_device; data.ioc_inllen1 = strlen(argv[1]) + 1; data.ioc_inlbuf1 = argv[1]; @@ -2073,7 +2616,7 @@ int jt_llog_catlist(int argc, char **argv) if (argc != 1) return CMD_HELP; - memset(&data, 0x00, sizeof(data)); + memset(&data, 0, sizeof(data)); data.ioc_dev = cur_device; data.ioc_inllen1 = sizeof(rawbuf) - cfs_size_round(sizeof(data)); memset(buf, 0, sizeof(rawbuf)); @@ -2102,7 +2645,7 @@ int jt_llog_info(int argc, char **argv) if (argc != 2) return CMD_HELP; - memset(&data, 0x00, sizeof(data)); + memset(&data, 0, sizeof(data)); data.ioc_dev = cur_device; data.ioc_inllen1 = strlen(argv[1]) + 1; data.ioc_inlbuf1 = argv[1]; @@ -2135,7 +2678,7 @@ int jt_llog_print(int argc, char **argv) if (argc != 2 && argc != 4) return CMD_HELP; - memset(&data, 0x00, sizeof(data)); + memset(&data, 0, sizeof(data)); data.ioc_dev = cur_device; data.ioc_inllen1 = strlen(argv[1]) + 1; data.ioc_inlbuf1 = argv[1]; @@ -2182,7 +2725,7 @@ int jt_llog_cancel(int argc, char **argv) if (argc != 4) return CMD_HELP; - memset(&data, 0x00, sizeof(data)); + memset(&data, 0, sizeof(data)); data.ioc_dev = cur_device; data.ioc_inllen1 = strlen(argv[1]) + 1; data.ioc_inlbuf1 = argv[1]; @@ -2217,7 +2760,7 @@ int jt_llog_check(int argc, char **argv) if (argc != 2 && argc != 4) return CMD_HELP; - memset(&data, 0x00, sizeof(data)); + memset(&data, 0, sizeof(data)); data.ioc_dev = cur_device; data.ioc_inllen1 = strlen(argv[1]) + 1; data.ioc_inlbuf1 = argv[1]; @@ -2263,7 +2806,7 @@ int jt_llog_remove(int argc, char **argv) if (argc != 3 && argc != 2) return CMD_HELP; - memset(&data, 0x00, sizeof(data)); + memset(&data, 0, sizeof(data)); data.ioc_dev = cur_device; data.ioc_inllen1 = strlen(argv[1]) + 1; data.ioc_inlbuf1 = argv[1]; @@ -2462,7 +3005,7 @@ int jt_blockdev_info(int argc, char **argv) { char *filename; int rc, fd; - __u64 ino; + struct lu_fid fid; if (argc != 2) return CMD_HELP; @@ -2475,17 +3018,17 @@ int jt_blockdev_info(int argc, char **argv) return CMD_HELP; } - rc = ioctl(fd, LL_IOC_LLOOP_INFO, &ino); + rc = ioctl(fd, LL_IOC_LLOOP_INFO, &fid); if (rc < 0) { rc = errno; fprintf(stderr, "error: %s\n", strerror(errno)); goto out; } fprintf(stdout, "lloop device info: "); - if (ino == 0ULL) + if (fid_is_zero(&fid)) fprintf(stdout, "Not attached\n"); else - fprintf(stdout, "attached to inode "LPU64"\n", ino); + fprintf(stdout, "attached to inode "DFID"\n", PFID(&fid)); out: close(fd); return -rc; @@ -2504,10 +3047,12 @@ int obd_initialize(int argc, char **argv) { int i; - for (i = 0; i < MAX_STRIPES; i++) + for (i = 0; i < LOV_MAX_STRIPE_COUNT; i++) lsm_buffer.lsm.lsm_oinfo[i] = lov_oinfos + i; - shmem_setup(); + if (shmem_setup() != 0) + return -1; + register_ioc_dev(OBD_DEV_ID, OBD_DEV_PATH, OBD_DEV_MAJOR, OBD_DEV_MINOR); @@ -2518,12 +3063,14 @@ void obd_finalize(int argc, char **argv) { struct sigaction sigact; + /* sigact initialization */ sigact.sa_handler = signal_server; sigfillset(&sigact.sa_mask); sigact.sa_flags = SA_RESTART; + /* coverity[uninit_use_in_call] */ sigaction(SIGINT, &sigact, NULL); - shmem_stop(); + shmem_cleanup(); do_disconnect(argv[0], 1); } @@ -2763,7 +3310,7 @@ static int pool_cmd(enum lcfg_command_type cmd, return rc; } - memset(&data, 0x00, sizeof(data)); + memset(&data, 0, sizeof(data)); rc = data.ioc_dev = get_mgs_device(); if (rc < 0) goto out; @@ -3048,31 +3595,50 @@ out: int jt_get_obj_version(int argc, char **argv) { - struct lu_fid fid; - struct obd_ioctl_data data; - __u64 version; - char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf, *fidstr; - int rc; - - if (argc != 2) - return CMD_HELP; - - fidstr = argv[1]; - while (*fidstr == '[') - fidstr++; - sscanf(fidstr, SFID, RFID(&fid)); - if (!fid_is_sane(&fid)) { - fprintf(stderr, "bad FID format [%s], should be "DFID"\n", - fidstr, (__u64)1, 2, 0); - return -EINVAL; - } - - memset(&data, 0, sizeof data); - data.ioc_dev = cur_device; - data.ioc_inlbuf1 = (char *) &fid; - data.ioc_inllen1 = sizeof fid; - data.ioc_inlbuf2 = (char *) &version; - data.ioc_inllen2 = sizeof version; + struct lu_fid fid; + struct obd_ioctl_data data; + __u64 version, id = ULLONG_MAX, group = ULLONG_MAX; + char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf, *fidstr; + int rc, c; + + while ((c = getopt(argc, argv, "i:g:")) != -1) { + switch (c) { + case 'i': + id = strtoull(optarg, NULL, 0); + break; + case 'g': + group = strtoull(optarg, NULL, 0); + break; + default: + return CMD_HELP; + } + } + + argc -= optind; + argv += optind; + + if (!(id != ULLONG_MAX && group != ULLONG_MAX && argc == 0) && + !(id == ULLONG_MAX && group == ULLONG_MAX && argc == 1)) + return CMD_HELP; + + memset(&data, 0, sizeof data); + data.ioc_dev = cur_device; + if (argc == 1) { + fidstr = *argv; + while (*fidstr == '[') + fidstr++; + sscanf(fidstr, SFID, RFID(&fid)); + + data.ioc_inlbuf1 = (char *) &fid; + data.ioc_inllen1 = sizeof fid; + } else { + data.ioc_inlbuf3 = (char *) &id; + data.ioc_inllen3 = sizeof id; + data.ioc_inlbuf4 = (char *) &group; + data.ioc_inllen4 = sizeof group; + } + data.ioc_inlbuf2 = (char *) &version; + data.ioc_inllen2 = sizeof version; memset(buf, 0, sizeof *buf); rc = obd_ioctl_pack(&data, &buf, sizeof rawbuf); @@ -3114,12 +3680,12 @@ void llapi_ping_target(char *obd_type, char *obd_name, if (rc) rc = errno; if (rc == ENOTCONN || rc == ESHUTDOWN) { - printf("%s inactive.\n", obd_name); + printf("%s: INACTIVE\n", obd_name); } else if (rc) { - fprintf(stderr, "error: check '%s' %s\n", + printf("%s: check error: %s\n", obd_name, strerror(errno)); } else { - printf("%s active.\n", obd_name); + printf("%s: active\n", obd_name); } } @@ -3137,7 +3703,7 @@ int jt_changelog_register(int argc, char **argv) if (cur_device < 0) return CMD_HELP; - memset(&data, 0x00, sizeof(data)); + memset(&data, 0, sizeof(data)); data.ioc_dev = cur_device; memset(buf, 0, sizeof(rawbuf)); rc = obd_ioctl_pack(&data, &buf, sizeof(rawbuf)); @@ -3192,7 +3758,7 @@ int jt_changelog_deregister(int argc, char **argv) return CMD_HELP; } - memset(&data, 0x00, sizeof(data)); + memset(&data, 0, sizeof(data)); data.ioc_dev = cur_device; data.ioc_u32_1 = id; memset(buf, 0, sizeof(rawbuf));