Whamcloud - gitweb
LU-2783 ofd: Implement OBD_IOC_GET_OBJ_VERSION
[fs/lustre-release.git] / lustre / utils / obd.c
index f821810..53f2fc5 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, 2012, 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,8 +107,6 @@ const int thread = 0;
 const int nthreads = 1;
 #endif
 
-#define MAX_IOC_BUFLEN 8192
-
 static int cur_device = -1;
 
 struct lov_oinfo lov_oinfos[LOV_MAX_STRIPE_COUNT];
@@ -236,10 +233,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)
@@ -559,8 +556,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;
 }
@@ -1433,8 +1430,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,
@@ -1446,6 +1441,10 @@ int jt_obd_md_common(int argc, char **argv, int cmd)
                         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) {
@@ -2418,6 +2417,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);
@@ -3003,9 +3052,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();
@@ -3533,31 +3584,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);