Whamcloud - gitweb
LU-1889 build: fix false 'uninitialized scalar variable' errs
[fs/lustre-release.git] / lustre / utils / obd.c
index 4965781..ad3ec68 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, Whamcloud, Inc.
  */
 /*
  * 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];
@@ -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;
 }
@@ -631,6 +628,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)
 {
@@ -1173,11 +1189,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;
@@ -1270,7 +1284,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;
                         }
@@ -1281,10 +1295,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' "
@@ -1335,16 +1350,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
@@ -1404,8 +1410,6 @@ 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;
 
@@ -1426,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,
@@ -1439,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) {
@@ -1475,12 +1481,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
@@ -2122,12 +2123,7 @@ 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
@@ -2210,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;
 }
 
@@ -2999,9 +3002,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();