X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=blobdiff_plain;f=lustre%2Futils%2Fobd.c;h=e6b9f110da1b9c245f516804d8325aca0ee82020;hp=9fe5d4bac6fdbd574874f708f593a6db37c97146;hb=7bf1d7c6cb7d0a7231b3fdcb9e3d3ec3129fb427;hpb=5833895424f425d6552eedd8a34488dad0c1676b;ds=sidebyside diff --git a/lustre/utils/obd.c b/lustre/utils/obd.c index 9fe5d4b..e6b9f11 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. @@ -26,8 +24,10 @@ * GPL HEADER END */ /* - * Copyright 2008 Sun Microsystems, Inc. All rights reserved + * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. + * + * Copyright (c) 2011, 2012, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ @@ -41,36 +41,35 @@ * 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" @@ -80,16 +79,21 @@ #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; @@ -207,7 +208,7 @@ char *obdo_print(struct obdo *obd) "\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_gr, obd->o_atime, obd->o_mtime, obd->o_ctime, + 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); @@ -225,17 +226,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) @@ -431,15 +432,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 +454,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 +463,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 +500,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 +575,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,13 +592,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 && - live_threads == total_threads && - secs > 0.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])); @@ -550,24 +610,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) { } @@ -579,7 +669,7 @@ static void shmem_unlock() { } -static void shmem_stop(void) +static void shmem_cleanup(void) { } @@ -715,7 +805,7 @@ int jt_opt_threads(int argc, char **argv) thread = i; argv[2] = "--device"; - return jt_opt_device(argc - 2, argv + 2); + exit(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); @@ -785,6 +875,7 @@ int jt_opt_threads(int argc, char **argv) sigaction(SIGALRM, &saveact1, NULL); } + shmem_total(threads); sigprocmask(SIG_SETMASK, &saveset, NULL); return rc; @@ -823,7 +914,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) @@ -850,7 +941,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) @@ -877,7 +968,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) @@ -901,25 +992,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) - size_round(sizeof(*data)); - data->ioc_inlbuf1 = buf + 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; @@ -953,7 +1037,12 @@ try_mdc: goto fail; got_one: - fgets(buf, sizeof(buf), fp); + /* should not ignore fgets(3)'s return value */ + if (!fgets(buf, sizeof(buf), fp)) { + fprintf(stderr, "reading from %s: %s", buf, strerror(errno)); + fclose(fp); + return; + } fclose(fp); /* trim trailing newlines */ @@ -986,8 +1075,9 @@ int jt_obd_list_ioctl(int argc, char **argv) for (index = 0;; index++) { memset(buf, 0, sizeof(rawbuf)); data->ioc_version = OBD_IOCTL_VERSION; - data->ioc_inllen1 = sizeof(rawbuf) - size_round(sizeof(*data)); - data->ioc_inlbuf1 = buf + size_round(sizeof(*data)); + 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); data->ioc_count = index; @@ -1040,6 +1130,399 @@ 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; + + data.ioc_obdo2.o_id = 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; + } + data.ioc_obdo1.o_seq = fid.f_seq; + data.ioc_obdo1.o_id = fid.f_oid; + } + + 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 @@ -1055,7 +1538,7 @@ int jt_obd_create(int argc, char **argv) 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; @@ -1084,9 +1567,9 @@ int jt_obd_create(int argc, char **argv) return CMD_HELP; } - if (argc < 5) + if (argc < 5) { reset_lsmb (&lsm_buffer); /* will set default */ - else { + } else { rc = parse_lsm (&lsm_buffer, argv[4]); if (rc != 0) { fprintf(stderr, "error: %s: invalid lsm '%s'\n", @@ -1123,7 +1606,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)); @@ -1150,7 +1633,7 @@ 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; @@ -1198,7 +1681,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) { @@ -1238,7 +1721,7 @@ int jt_obd_test_setattr(int argc, char **argv) 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; - 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", @@ -1246,7 +1729,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)); @@ -1287,7 +1770,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; @@ -1332,7 +1815,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)); @@ -1357,7 +1840,7 @@ int jt_obd_getattr(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_obdo1.o_id = strtoull(argv[1], &end, 0); if (*end) { @@ -1403,7 +1886,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) { @@ -1443,7 +1926,7 @@ int jt_obd_test_getattr(int argc, char **argv) data.ioc_obdo1.o_id = objid; data.ioc_obdo1.o_mode = S_IFREG; data.ioc_obdo1.o_valid = 0xffffffff; - 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", @@ -1451,7 +1934,7 @@ int jt_obd_test_getattr(int argc, char **argv) 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)); @@ -1582,7 +2065,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. @@ -1630,21 +2113,17 @@ 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) - 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 @@ -1668,7 +2147,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", @@ -1676,7 +2155,7 @@ 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), @@ -1697,8 +2176,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 @@ -1726,6 +2206,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; } @@ -1739,7 +2226,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) @@ -1774,7 +2261,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); @@ -1841,7 +2328,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; @@ -1880,7 +2367,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) @@ -1907,7 +2394,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; @@ -1930,6 +2417,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); @@ -1946,7 +2483,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; @@ -1987,7 +2524,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; @@ -2039,7 +2576,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]; @@ -2068,9 +2605,9 @@ 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) - size_round(sizeof(data)); + data.ioc_inllen1 = sizeof(rawbuf) - cfs_size_round(sizeof(data)); memset(buf, 0, sizeof(rawbuf)); rc = obd_ioctl_pack(&data, &buf, sizeof(rawbuf)); if (rc) { @@ -2097,12 +2634,12 @@ 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]; - data.ioc_inllen2 = sizeof(rawbuf) - size_round(sizeof(data)) - - size_round(data.ioc_inllen1); + data.ioc_inllen2 = sizeof(rawbuf) - cfs_size_round(sizeof(data)) - + cfs_size_round(data.ioc_inllen1); memset(buf, 0, sizeof(rawbuf)); rc = obd_ioctl_pack(&data, &buf, sizeof(rawbuf)); if (rc) { @@ -2130,7 +2667,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]; @@ -2146,10 +2683,10 @@ int jt_llog_print(int argc, char **argv) data.ioc_inllen3 = strlen(to) + 1; data.ioc_inlbuf3 = to; } - data.ioc_inllen4 = sizeof(rawbuf) - size_round(sizeof(data)) - - size_round(data.ioc_inllen1) - - size_round(data.ioc_inllen2) - - size_round(data.ioc_inllen3); + data.ioc_inllen4 = sizeof(rawbuf) - cfs_size_round(sizeof(data)) - + cfs_size_round(data.ioc_inllen1) - + cfs_size_round(data.ioc_inllen2) - + cfs_size_round(data.ioc_inllen3); memset(buf, 0, sizeof(rawbuf)); rc = obd_ioctl_pack(&data, &buf, sizeof(rawbuf)); if (rc) { @@ -2177,7 +2714,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]; @@ -2212,7 +2749,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]; @@ -2228,10 +2765,10 @@ int jt_llog_check(int argc, char **argv) data.ioc_inllen3 = strlen(to) + 1; data.ioc_inlbuf3 = to; } - data.ioc_inllen4 = sizeof(rawbuf) - size_round(sizeof(data)) - - size_round(data.ioc_inllen1) - - size_round(data.ioc_inllen2) - - size_round(data.ioc_inllen3); + data.ioc_inllen4 = sizeof(rawbuf) - cfs_size_round(sizeof(data)) - + cfs_size_round(data.ioc_inllen1) - + cfs_size_round(data.ioc_inllen2) - + cfs_size_round(data.ioc_inllen3); memset(buf, 0, sizeof(rawbuf)); rc = obd_ioctl_pack(&data, &buf, sizeof(rawbuf)); if (rc) { @@ -2258,7 +2795,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]; @@ -2457,7 +2994,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; @@ -2470,17 +3007,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; @@ -2499,10 +3036,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); @@ -2513,115 +3052,24 @@ 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); } -static int find_target_obdpath(char *fsname, char *path) -{ - glob_t glob_info; - char pattern[PATH_MAX + 1]; - int rc; - - snprintf(pattern, PATH_MAX, - "/proc/fs/lustre/lov/%s-*/target_obd", - fsname); - rc = glob(pattern, GLOB_BRACE, NULL, &glob_info); - if (rc == GLOB_NOMATCH) - return -ENODEV; - else if (rc) - return -EINVAL; - - strcpy(path, glob_info.gl_pathv[0]); - globfree(&glob_info); - return 0; -} - -static int find_poolpath(char *fsname, char *poolname, char *poolpath) -{ - glob_t glob_info; - char pattern[PATH_MAX + 1]; - int rc; - - snprintf(pattern, PATH_MAX, - "/proc/fs/lustre/lov/%s-*/pools/%s", - fsname, poolname); - rc = glob(pattern, GLOB_BRACE, NULL, &glob_info); - /* If no pools, make sure the lov is available */ - if ((rc == GLOB_NOMATCH) && - (find_target_obdpath(fsname, poolpath) == -ENODEV)) - return -ENODEV; - if (rc) - return -EINVAL; - - strcpy(poolpath, glob_info.gl_pathv[0]); - globfree(&glob_info); - return 0; -} - -/* - * if pool is NULL, search ostname in target_obd - * if pool is no NULL - * if pool not found returns errno < 0 - * if ostname is NULL, returns 1 if pool is not empty and 0 if pool empty - * if ostname is not NULL, returns 1 if OST is in pool and 0 if not - */ -static int search_ost(char *fsname, char *poolname, char *ostname) -{ - FILE *fd; - char buffer[PATH_MAX + 1]; - int len = 0, rc; - - if (ostname != NULL) - len = strlen(ostname); - - if (poolname == NULL) - rc = find_target_obdpath(fsname, buffer); - else - rc = find_poolpath(fsname, poolname, buffer); - if (rc) - return rc; - - if ((fd = fopen(buffer, "r")) == NULL) - return -EINVAL; - - while (fgets(buffer, sizeof(buffer), fd) != NULL) { - if (poolname == NULL) { - char *ptr; - /* Search for an ostname in the list of OSTs - Line format is IDX: fsname-OSTxxxx_UUID STATUS */ - ptr = strchr(buffer, ' '); - if ((ptr != NULL) && - (strncmp(ptr + 1, ostname, len) == 0)) { - fclose(fd); - return 1; - } - } else { - /* Search for an ostname in a pool, - (or an existing non-empty pool if no ostname) */ - if ((ostname == NULL) || - (strncmp(buffer, ostname, len) == 0)) { - fclose(fd); - return 1; - } - } - } - fclose(fd); - return 0; -} - static int check_pool_cmd(enum lcfg_command_type cmd, char *fsname, char *poolname, char *ostname) { int rc; - rc = search_ost(fsname, poolname, ostname); + rc = llapi_search_ost(fsname, poolname, ostname); if (rc < 0 && (cmd != LCFG_POOL_NEW)) { fprintf(stderr, "Pool %s.%s not found\n", fsname, poolname); @@ -2654,7 +3102,7 @@ static int check_pool_cmd(enum lcfg_command_type cmd, ostname, fsname, poolname); return -EEXIST; } - rc = search_ost(fsname, NULL, ostname); + rc = llapi_search_ost(fsname, NULL, ostname); if (rc == 0) { fprintf(stderr, "OST %s is not part of the '%s' fs.\n", ostname, fsname); @@ -2691,7 +3139,7 @@ static int check_pool_cmd_result(enum lcfg_command_type cmd, switch (cmd) { case LCFG_POOL_NEW: { do { - rc = search_ost(fsname, poolname, NULL); + rc = llapi_search_ost(fsname, poolname, NULL); if (rc == -ENODEV) return rc; if (rc < 0) @@ -2710,7 +3158,7 @@ static int check_pool_cmd_result(enum lcfg_command_type cmd, } case LCFG_POOL_DEL: { do { - rc = search_ost(fsname, poolname, NULL); + rc = llapi_search_ost(fsname, poolname, NULL); if (rc == -ENODEV) return rc; if (rc >= 0) @@ -2729,7 +3177,7 @@ static int check_pool_cmd_result(enum lcfg_command_type cmd, } case LCFG_POOL_ADD: { do { - rc = search_ost(fsname, poolname, ostname); + rc = llapi_search_ost(fsname, poolname, ostname); if (rc == -ENODEV) return rc; if (rc != 1) @@ -2748,7 +3196,7 @@ static int check_pool_cmd_result(enum lcfg_command_type cmd, } case LCFG_POOL_REM: { do { - rc = search_ost(fsname, poolname, ostname); + rc = llapi_search_ost(fsname, poolname, ostname); if (rc == -ENODEV) return rc; if (rc == 1) @@ -2851,7 +3299,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; @@ -3134,6 +3582,54 @@ out: return rc; } +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; + + memset(buf, 0, sizeof *buf); + rc = obd_ioctl_pack(&data, &buf, sizeof rawbuf); + if (rc) { + fprintf(stderr, "error: %s: packing ioctl arguments: %s\n", + jt_cmdname(argv[0]), strerror(-rc)); + return rc; + } + + rc = l2_ioctl(OBD_DEV_ID, OBD_IOC_GET_OBJ_VERSION, buf); + if (rc == -1) { + fprintf(stderr, "error: %s: ioctl: %s\n", + jt_cmdname(argv[0]), strerror(errno)); + return -errno; + } + + obd_ioctl_unpack(&data, buf, sizeof rawbuf); + printf(LPX64"\n", version); + return 0; +} + void llapi_ping_target(char *obd_type, char *obd_name, char *obd_uuid, void *args) { @@ -3154,12 +3650,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); } } @@ -3177,7 +3673,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)); @@ -3232,7 +3728,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));