Whamcloud - gitweb
LU-3267 utils: missing setting echo seq for getattr/setattr
[fs/lustre-release.git] / lustre / utils / obd.c
index 178d1e3..bbcb244 100644 (file)
@@ -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/
 #include <obd.h>          /* for struct lov_stripe_md */
 #include <lustre/lustre_build_version.h>
 
-#include <obd_class.h>
 #include <lnet/lnetctl.h>
 #include <libcfs/libcfsutil.h>
-#include <lustre/liblustreapi.h>
+#include <lustre/lustreapi.h>
 
 #define MAX_STRING_SIZE 128
 #define DEVICES_LIST "/proc/fs/lustre/devices"
@@ -108,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)
@@ -206,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);
 }
 
 
@@ -237,10 +234,10 @@ static int do_name2dev(char *func, char *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)
@@ -304,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);
@@ -333,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);
@@ -560,8 +558,8 @@ static void shmem_total(int total_threads)
                         &shared_data->body.start_time);
         shmem_unlock();
 
-        printf("Total: total %llu threads %d sec %f %f/second\n", total,
-                total_threads, secs, total / secs);
+        printf("Total: total "LPU64" threads %d sec %f %f/second\n",
+               total, total_threads, secs, total / secs);
 
         return;
 }
@@ -632,6 +630,25 @@ static int shmem_running(void)
 {
         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 int shmem_setup(void)
 {
@@ -1174,11 +1191,9 @@ int jt_obd_md_common(int argc, char **argv, int cmd)
 {
         struct obd_ioctl_data  data;
         struct timeval         start;
-        struct timeval         next_time;
         struct timeval         end_time;
         char                   rawbuf[MAX_IOC_BUFLEN];
         char                  *buf = rawbuf;
-        int                    verbose = 1;
         int                    mode = 0000644;
         int                    create_mode;
         int                    rc = 0;
@@ -1271,7 +1286,7 @@ int jt_obd_md_common(int argc, char **argv, int cmd)
                 case 't':
                         seconds = strtoull(optarg, &end, 0);
                         if (*end) {
-                                fprintf(stderr, "error: %s: senconds '%s'\n",
+                                fprintf(stderr, "error: %s: seconds '%s'\n",
                                         jt_cmdname(argv[0]), optarg);
                                 return CMD_HELP;
                         }
@@ -1282,10 +1297,11 @@ int jt_obd_md_common(int argc, char **argv, int cmd)
                 case 'x':
                         xattr_size = strtoul(optarg, &end, 0);
                         if (*end) {
-                                fprintf(stderr, "error: %s: senconds '%s'\n",
+                                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' "
@@ -1336,16 +1352,7 @@ int jt_obd_md_common(int argc, char **argv, int cmd)
                         child_base_id +=  (thread - 1) * \
                                           (MAX_BASE_ID / nthreads);
 
-                shared_data->body.start_barrier--;
-                if (shared_data->body.start_barrier == 0) {
-                        shmem_wakeup_all();
-
-                        gettimeofday(&shared_data->body.start_time, NULL);
-                        printf("%s: start at %s", jt_cmdname(argv[0]),
-                               ctime(&shared_data->body.start_time.tv_sec));
-                } else {
-                        shmem_wait();
-                }
+                shmem_start_time_locked();
                 shmem_unlock();
         }
 #endif
@@ -1405,12 +1412,10 @@ int jt_obd_md_common(int argc, char **argv, int cmd)
         data.ioc_command = cmd;
 
         gettimeofday(&start, NULL);
-        next_time.tv_sec = start.tv_sec - verbose;
-        next_time.tv_usec = start.tv_usec;
         while (shmem_running()) {
-                struct lu_fid fid;
+                struct lu_fid fid = { 0 };
 
-                data.ioc_obdo2.o_id = child_base_id;
+               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 |
@@ -1427,8 +1432,6 @@ int jt_obd_md_common(int argc, char **argv, int cmd)
                         data.ioc_count = MD_STEP_COUNT;
                 }
 
-                child_base_id += data.ioc_count;
-                count += data.ioc_count;
                 if (cmd == ECHO_MD_CREATE || cmd == ECHO_MD_MKDIR) {
                         /*Allocate fids for the create */
                         rc = jt_obd_alloc_fids(&fid_space, &fid,
@@ -1437,9 +1440,12 @@ int jt_obd_md_common(int argc, char **argv, int cmd)
                                 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;
+                       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) {
@@ -1476,12 +1482,7 @@ int jt_obd_md_common(int argc, char **argv, int cmd)
 #ifdef MAX_THREADS
         if (thread) {
                 shmem_lock();
-                shared_data->body.stop_barrier--;
-                if (shared_data->body.stop_barrier == 0) {
-                        gettimeofday(&shared_data->body.end_time, NULL);
-                        printf("%s: end at %s", jt_cmdname(argv[0]),
-                                ctime(&shared_data->body.end_time.tv_sec));
-                }
+                shmem_end_time_locked();
                 shmem_unlock();
         }
 #endif
@@ -1534,7 +1535,7 @@ 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;
 
@@ -1567,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));
@@ -1619,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;
 }
@@ -1638,7 +1641,8 @@ int jt_obd_setattr(int argc, char **argv)
         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]);
@@ -1717,8 +1721,9 @@ 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, 0, sizeof(rawbuf));
@@ -1801,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));
@@ -1840,18 +1846,20 @@ int jt_obd_getattr(int argc, char **argv)
         if (argc != 2)
                 return CMD_HELP;
 
-        memset(&data, 0, 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));
@@ -1866,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;
 }
@@ -1922,17 +1930,18 @@ 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, 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;
-                }
+               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(1);
                 if (rc < 0) {
@@ -2123,22 +2132,19 @@ int jt_obd_test_brw(int argc, char **argv)
                         thr_offset += (thread - 1) * len;
                 }
 
-                shared_data->body.start_barrier--;
-                if (shared_data->body.start_barrier == 0)
-                        shmem_wakeup_all();
-                else
-                        shmem_wait();
-
+                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;
@@ -2167,12 +2173,12 @@ int jt_obd_test_brw(int argc, char **argv)
                                 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) {
@@ -2211,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;
 }
 
@@ -2415,6 +2428,56 @@ static int do_activate(int argc, char **argv, int flag)
         return rc;
 }
 
+/**
+ * Replace nids for given device.
+ * lctl replace_nids <devicename> <nid1>[,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 <MDT partition> -o nosvc <mount point>
+ * 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);
@@ -2984,7 +3047,7 @@ 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;
 
         if (shmem_setup() != 0)
@@ -3000,9 +3063,11 @@ 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_cleanup();
@@ -3530,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);