struct shared_data {
pthread_mutex_t mutex;
pthread_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;
+ 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;
static int thread;
static int nthreads;
#else
-const int thread = 0;
+const int thread;
const int nthreads = 1;
#endif
static int do_device(char *func, char *devname);
-static int get_mgs_device()
+static int get_mgs_device(void)
{
- char mgs[] = "$MGS";
- static int mgs_device = -1;
+ char mgs[] = "$MGS";
+ static int mgs_device = -1;
+
+ if (mgs_device == -1) {
+ int rc;
- if (mgs_device == -1) {
- int rc;
- do_disconnect(NULL, 1);
- rc = do_device("mgsioc", mgs);
- if (rc) {
- fprintf(stderr,
- "This command must be run on the MGS.\n");
- errno = ENODEV;
- return -1;
- }
- mgs_device = cur_device;
- }
- return mgs_device;
+ do_disconnect(NULL, 1);
+ rc = do_device("mgsioc", mgs);
+ if (rc) {
+ fprintf(stderr,
+ "This command must be run on the MGS.\n");
+ errno = ENODEV;
+ return -1;
+ }
+ mgs_device = cur_device;
+ }
+ return mgs_device;
}
/* Returns -1 on error with errno set */
return strdup(buf);
}
-
#define BAD_VERBOSE (-999999999)
#define N2D_OFF 0x100 /* So we can tell between error codes and devices */
return rc - N2D_OFF;
if (try_digit)
- ret = strtoul(name, NULL, 0);
+ ret = strtoul(name, NULL, 0);
else
fprintf(stderr, "No device found for name %s: %s\n",
- name, strerror(rc));
- return ret;
+ name, strerror(rc));
+ return ret;
}
char *jt_cmdname(char *func)
{
- static char buf[512];
+ static char buf[512];
- if (thread) {
- sprintf(buf, "%s-%d", func, thread);
- return buf;
- }
+ if (thread) {
+ sprintf(buf, "%s-%d", func, thread);
+ return buf;
+ }
- return func;
+ return func;
}
#define difftime(a, b) \
- ((a)->tv_sec - (b)->tv_sec + \
- ((a)->tv_usec - (b)->tv_usec) / 1000000.0)
+ ((a)->tv_sec - (b)->tv_sec + \
+ ((a)->tv_usec - (b)->tv_usec) / 1000000.0)
static int be_verbose(int verbose, struct timeval *next_time,
- __u64 num, __u64 *next_num, int num_total)
+ __u64 num, __u64 *next_num, int num_total)
{
- struct timeval now;
+ struct timeval now;
- if (!verbose)
- return 0;
+ if (!verbose)
+ return 0;
- if (next_time != NULL)
- gettimeofday(&now, NULL);
+ if (next_time)
+ gettimeofday(&now, NULL);
- /* A positive verbosity means to print every X iterations */
- if (verbose > 0 && (num >= *next_num || num >= num_total)) {
- *next_num += verbose;
- if (next_time) {
- next_time->tv_sec = now.tv_sec - verbose;
- next_time->tv_usec = now.tv_usec;
- }
- return 1;
- }
+ /* A positive verbosity means to print every X iterations */
+ if (verbose > 0 && (num >= *next_num || num >= num_total)) {
+ *next_num += verbose;
+ if (next_time) {
+ next_time->tv_sec = now.tv_sec - verbose;
+ next_time->tv_usec = now.tv_usec;
+ }
+ return 1;
+ }
- /* A negative verbosity means to print at most each X seconds */
- if (verbose < 0 && next_time != NULL &&
- difftime(&now, next_time) >= 0.0){
- next_time->tv_sec = now.tv_sec - verbose;
- next_time->tv_usec = now.tv_usec;
- *next_num = num;
- return 1;
- }
+ /* A negative verbosity means to print at most each X seconds */
+ if (verbose < 0 && next_time && difftime(&now, next_time) >= 0.0) {
+ next_time->tv_sec = now.tv_sec - verbose;
+ next_time->tv_usec = now.tv_usec;
+ *next_num = num;
+ return 1;
+ }
- return 0;
+ return 0;
}
static int get_verbose(char *func, const char *arg)
{
- int verbose;
- char *end;
+ int verbose;
+ char *end;
- if (!arg || arg[0] == 'v')
- verbose = 1;
- else if (arg[0] == 's' || arg[0] == 'q')
- verbose = 0;
- else {
- verbose = (int)strtoul(arg, &end, 0);
- if (*end) {
- fprintf(stderr, "error: %s: bad verbose option '%s'\n",
- jt_cmdname(func), arg);
- return BAD_VERBOSE;
- }
- }
+ if (!arg || arg[0] == 'v') {
+ verbose = 1;
+ } else if (arg[0] == 's' || arg[0] == 'q') {
+ verbose = 0;
+ } else {
+ verbose = (int)strtoul(arg, &end, 0);
+ if (*end) {
+ fprintf(stderr, "error: %s: bad verbose option '%s'\n",
+ jt_cmdname(func), arg);
+ return BAD_VERBOSE;
+ }
+ }
- if (verbose < 0)
- printf("Print status every %d seconds\n", -verbose);
- else if (verbose == 1)
- printf("Print status every operation\n");
- else if (verbose > 1)
- printf("Print status every %d operations\n", verbose);
+ if (verbose < 0)
+ printf("Print status every %d seconds\n", -verbose);
+ else if (verbose == 1)
+ printf("Print status every operation\n");
+ else if (verbose > 1)
+ printf("Print status every %d operations\n", verbose);
- return verbose;
+ return verbose;
}
int do_disconnect(char *func, int verbose)
{
- lcfg_set_devname(NULL);
- cur_device = -1;
- return 0;
+ lcfg_set_devname(NULL);
+ cur_device = -1;
+ return 0;
}
#ifdef MAX_THREADS
static int shmem_setup(void)
{
- 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 errno;
- }
-
- /* Attatch to new segment */
- shared_data = (struct shared_data *)shmat(shmid, NULL, 0);
-
- if (shared_data == (struct shared_data *)(-1)) {
- fprintf(stderr, "Can't attach shared data: %s\n",
- strerror(errno));
- shared_data = NULL;
- return errno;
- }
-
- /* Mark segment as destroyed, so it will disappear when we exit.
- * Forks will inherit attached segments, so we should be OK.
- */
- 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");
+ 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 errno;
+ }
+
+ /* Attatch to new segment */
+ shared_data = (struct shared_data *)shmat(shmid, NULL, 0);
+
+ if (shared_data == (struct shared_data *)(-1)) {
+ fprintf(stderr, "Can't attach shared data: %s\n",
+ strerror(errno));
+ shared_data = NULL;
+ return errno;
+ }
+
+ /*
+ * Mark segment as destroyed, so it will disappear when we exit.
+ * Forks will inherit attached segments, so we should be OK.
+ */
+ 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");
goto out;
- }
+ }
- rc = pthread_condattr_setpshared(&cattr, PTHREAD_PROCESS_SHARED);
- if (rc != 0) {
- fprintf(stderr, "Can't set shared cond attr\n");
+ rc = pthread_condattr_setpshared(&cattr, PTHREAD_PROCESS_SHARED);
+ if (rc != 0) {
+ fprintf(stderr, "Can't set shared cond attr\n");
goto out;
- }
+ }
- pthread_mutex_init(&shared_data->mutex, &mattr);
- pthread_cond_init(&shared_data->cond, &cattr);
+ pthread_mutex_init(&shared_data->mutex, &mattr);
+ pthread_cond_init(&shared_data->cond, &cattr);
out:
- pthread_mutexattr_destroy(&mattr);
- pthread_condattr_destroy(&cattr);
+ pthread_mutexattr_destroy(&mattr);
+ pthread_condattr_destroy(&cattr);
return rc;
}
static inline void shmem_reset(int total_threads)
{
- if (shared_data == NULL)
- return;
+ if (!shared_data)
+ return;
- memset(&shared_data->body, 0, sizeof(shared_data->body));
- memset(counter_snapshot, 0, sizeof(counter_snapshot));
- prev_valid = 0;
- shared_data->stopping = 0;
- shared_data->body.start_barrier = total_threads;
- shared_data->body.stop_barrier = total_threads;
+ memset(&shared_data->body, 0, sizeof(shared_data->body));
+ memset(counter_snapshot, 0, sizeof(counter_snapshot));
+ prev_valid = 0;
+ shared_data->stopping = 0;
+ shared_data->body.start_barrier = total_threads;
+ shared_data->body.stop_barrier = total_threads;
}
static inline void shmem_bump(__u32 counter)
{
- static bool running_not_bumped = true;
+ static bool running_not_bumped = true;
- if (shared_data == NULL || thread <= 0 || thread > MAX_THREADS)
- return;
+ if (!shared_data || thread <= 0 || thread > MAX_THREADS)
+ return;
- shmem_lock();
- shared_data->body.counters[thread - 1] += counter;
- if (running_not_bumped) {
- shared_data->body.thr_running++;
- running_not_bumped = false;
- }
- shmem_unlock();
+ shmem_lock();
+ shared_data->body.counters[thread - 1] += counter;
+ if (running_not_bumped) {
+ shared_data->body.thr_running++;
+ running_not_bumped = false;
+ }
+ shmem_unlock();
}
static void shmem_total(int total_threads)
{
- __u64 total = 0;
- double secs;
- int i;
+ __u64 total = 0;
+ double secs;
+ int i;
- if (shared_data == NULL || total_threads > MAX_THREADS)
- return;
+ if (!shared_data || total_threads > MAX_THREADS)
+ return;
- shmem_lock();
- for (i = 0; i < total_threads; i++)
- total += shared_data->body.counters[i];
+ 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();
+ secs = difftime(&shared_data->body.end_time,
+ &shared_data->body.start_time);
+ shmem_unlock();
printf("Total: total %ju threads %d sec %f %f/second\n",
(uintmax_t)total, total_threads, secs, total / secs);
static void shmem_snap(int total_threads, int live_threads)
{
- struct timeval this_time;
- int non_zero = 0;
- __u64 total = 0;
- double secs;
- int running;
- int i;
+ struct timeval this_time;
+ int non_zero = 0;
+ __u64 total = 0;
+ double secs;
+ int running;
+ int i;
- if (shared_data == NULL || total_threads > MAX_THREADS)
- return;
+ if (!shared_data || total_threads > MAX_THREADS)
+ return;
- shmem_lock();
- memcpy(counter_snapshot[0], shared_data->body.counters,
- total_threads * sizeof(counter_snapshot[0][0]));
- running = shared_data->body.thr_running;
- shmem_unlock();
+ shmem_lock();
+ memcpy(counter_snapshot[0], shared_data->body.counters,
+ total_threads * sizeof(counter_snapshot[0][0]));
+ running = shared_data->body.thr_running;
+ shmem_unlock();
- gettimeofday(&this_time, NULL);
+ gettimeofday(&this_time, NULL);
- for (i = 0; i < total_threads; i++) {
- long long this_count =
- counter_snapshot[0][i] - counter_snapshot[1][i];
+ for (i = 0; i < total_threads; i++) {
+ long long this_count =
+ counter_snapshot[0][i] - counter_snapshot[1][i];
- if (this_count != 0) {
- non_zero++;
- total += this_count;
- }
- }
+ if (this_count != 0) {
+ non_zero++;
+ total += this_count;
+ }
+ }
- secs = difftime(&this_time, &prev_time);
+ 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);
static void shmem_stop(void)
{
- if (shared_data == NULL)
- return;
+ if (!shared_data)
+ return;
- shared_data->stopping = 1;
+ shared_data->stopping = 1;
}
static void shmem_cleanup(void)
{
- if (shared_data == NULL)
- return;
+ if (!shared_data)
+ return;
- shmem_stop();
+ shmem_stop();
- pthread_mutex_destroy(&shared_data->mutex);
- pthread_cond_destroy(&shared_data->cond);
+ pthread_mutex_destroy(&shared_data->mutex);
+ pthread_cond_destroy(&shared_data->cond);
}
static int shmem_running(void)
{
- return (shared_data == NULL || !shared_data->stopping);
+ return (!shared_data || !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);
+ 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();
- }
+ 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)
{
- return 0;
+ return 0;
}
static inline void shmem_reset(int total_threads)
{
}
-static void shmem_lock()
+static void shmem_lock(void)
{
}
-static void shmem_unlock()
+static void shmem_unlock(void)
{
}
static int shmem_running(void)
{
- return 1;
+ return 1;
}
#endif
static int do_device(char *func, char *devname)
{
- int dev;
+ int dev;
- dev = parse_devname(func, devname);
- if (dev < 0)
- return -1;
+ dev = parse_devname(func, devname);
+ if (dev < 0)
+ return -1;
- lcfg_set_devname(devname);
- cur_device = dev;
- return 0;
+ lcfg_set_devname(devname);
+ cur_device = dev;
+ return 0;
}
-int jt_obd_get_device()
+int jt_obd_get_device(void)
{
- return cur_device;
+ return cur_device;
}
int jt_obd_device(int argc, char **argv)
{
- int rc;
+ int rc;
- if (argc > 2)
- return CMD_HELP;
+ if (argc > 2)
+ return CMD_HELP;
- if (argc == 1) {
- printf("current device is %d - %s\n",
- cur_device, lcfg_get_devname() ? : "not set");
- return 0;
- }
- rc = do_device("device", argv[1]);
- return rc;
+ if (argc == 1) {
+ printf("current device is %d - %s\n",
+ cur_device, lcfg_get_devname() ? : "not set");
+ return 0;
+ }
+ rc = do_device("device", argv[1]);
+ return rc;
}
int jt_opt_device(int argc, char **argv)
{
- int ret;
- int rc;
+ int ret;
+ int rc;
- if (argc < 3)
- return CMD_HELP;
+ if (argc < 3)
+ return CMD_HELP;
- rc = do_device("device", argv[1]);
+ rc = do_device("device", argv[1]);
- if (!rc)
- rc = Parser_execarg(argc - 2, argv + 2, cmdlist);
+ if (!rc)
+ rc = Parser_execarg(argc - 2, argv + 2, cmdlist);
- ret = do_disconnect(argv[0], 0);
- if (!rc)
- rc = ret;
+ ret = do_disconnect(argv[0], 0);
+ if (!rc)
+ rc = ret;
- return rc;
+ return rc;
}
#ifdef MAX_THREADS
-static void parent_sighandler (int sig)
+static void parent_sighandler(int sig)
{
- return;
}
int jt_opt_threads(int argc, char **argv)
{
static char cmdstr[129];
- sigset_t saveset;
- sigset_t sigset;
- struct sigaction sigact;
- struct sigaction saveact1;
- struct sigaction saveact2;
- unsigned long threads;
- __u64 next_thread;
- int verbose;
- int rc = 0;
- int report_count = -1;
- char *end;
- int i;
-
- if (argc < 5)
- return CMD_HELP;
-
- threads = strtoul(argv[1], &end, 0);
-
- if (*end == '.')
- report_count = strtoul(end + 1, &end, 0);
-
- if (*end || threads > MAX_THREADS) {
- fprintf(stderr, "error: %s: invalid thread count '%s'\n",
- jt_cmdname(argv[0]), argv[1]);
- return CMD_HELP;
- }
-
- verbose = get_verbose(argv[0], argv[2]);
- if (verbose == BAD_VERBOSE)
- return CMD_HELP;
-
- if (verbose != 0) {
- snprintf(cmdstr, sizeof(cmdstr), "%s", argv[4]);
- for (i = 5; i < argc; i++)
+ sigset_t saveset;
+ sigset_t sigset;
+ struct sigaction sigact;
+ struct sigaction saveact1;
+ struct sigaction saveact2;
+ unsigned long threads;
+ __u64 next_thread;
+ int verbose;
+ int rc = 0;
+ int report_count = -1;
+ char *end;
+ int i;
+
+ if (argc < 5)
+ return CMD_HELP;
+
+ threads = strtoul(argv[1], &end, 0);
+
+ if (*end == '.')
+ report_count = strtoul(end + 1, &end, 0);
+
+ if (*end || threads > MAX_THREADS) {
+ fprintf(stderr, "error: %s: invalid thread count '%s'\n",
+ jt_cmdname(argv[0]), argv[1]);
+ return CMD_HELP;
+ }
+
+ verbose = get_verbose(argv[0], argv[2]);
+ if (verbose == BAD_VERBOSE)
+ return CMD_HELP;
+
+ if (verbose != 0) {
+ snprintf(cmdstr, sizeof(cmdstr), "%s", argv[4]);
+ for (i = 5; i < argc; i++)
snprintf(cmdstr + strlen(cmdstr),
sizeof(cmdstr) - strlen(cmdstr),
" %s", argv[i]);
- printf("%s: starting %ld threads on device %s running %s\n",
- argv[0], threads, argv[3], cmdstr);
- }
-
- shmem_reset(threads);
-
- sigemptyset(&sigset);
- sigaddset(&sigset, SIGALRM);
- sigaddset(&sigset, SIGCHLD);
- sigprocmask(SIG_BLOCK, &sigset, &saveset);
-
- nthreads = threads;
-
- for (i = 1, next_thread = verbose; i <= threads; i++) {
- rc = fork();
- if (rc < 0) {
- fprintf(stderr, "error: %s: #%d - %s\n", argv[0], i,
- strerror(rc = errno));
- break;
- } else if (rc == 0) {
- sigprocmask(SIG_SETMASK, &saveset, NULL);
-
- thread = i;
- argv[2] = "--device";
- 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);
- rc = 0;
- }
-
- if (!thread) { /* parent process */
- int live_threads = threads;
-
- sigemptyset(&sigset);
- sigemptyset(&sigact.sa_mask);
- sigact.sa_handler = parent_sighandler;
- sigact.sa_flags = 0;
-
- sigaction(SIGALRM, &sigact, &saveact1);
- sigaction(SIGCHLD, &sigact, &saveact2);
-
- while (live_threads > 0) {
- int status;
- pid_t ret;
-
- if (verbose < 0) /* periodic stats */
- alarm(-verbose);
-
- sigsuspend(&sigset);
- alarm(0);
-
- while (live_threads > 0) {
- ret = waitpid(0, &status, WNOHANG);
- if (ret == 0)
- break;
-
- if (ret < 0) {
- fprintf(stderr, "error: %s: wait - %s\n",
- argv[0], strerror(errno));
- if (!rc)
- rc = errno;
- continue;
- } else {
- /*
- * This is a hack. We _should_ be able
- * to use WIFEXITED(status) to see if
- * there was an error, but it appears
- * to be broken and it always returns 1
- * (OK). See wait(2).
- */
- int err = WEXITSTATUS(status);
- if (err || WIFSIGNALED(status))
- fprintf(stderr,
- "%s: PID %d had rc=%d\n",
- argv[0], ret, err);
- if (!rc)
- rc = err;
-
- live_threads--;
- }
- }
-
- /* Show stats while all threads running */
- if (verbose < 0) {
- shmem_snap(threads, live_threads);
- if (report_count > 0 && --report_count == 0)
- shmem_stop();
- }
- }
- sigaction(SIGCHLD, &saveact2, NULL);
- sigaction(SIGALRM, &saveact1, NULL);
- }
-
- shmem_total(threads);
- sigprocmask(SIG_SETMASK, &saveset, NULL);
-
- return rc;
+ printf("%s: starting %ld threads on device %s running %s\n",
+ argv[0], threads, argv[3], cmdstr);
+ }
+
+ shmem_reset(threads);
+
+ sigemptyset(&sigset);
+ sigaddset(&sigset, SIGALRM);
+ sigaddset(&sigset, SIGCHLD);
+ sigprocmask(SIG_BLOCK, &sigset, &saveset);
+
+ nthreads = threads;
+
+ for (i = 1, next_thread = verbose; i <= threads; i++) {
+ rc = fork();
+ if (rc < 0) {
+ fprintf(stderr, "error: %s: #%d - %s\n", argv[0], i,
+ strerror(rc = errno));
+ break;
+ } else if (rc == 0) {
+ sigprocmask(SIG_SETMASK, &saveset, NULL);
+
+ thread = i;
+ argv[2] = "--device";
+ 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);
+ rc = 0;
+ }
+
+ if (!thread) { /* parent process */
+ int live_threads = threads;
+
+ sigemptyset(&sigset);
+ sigemptyset(&sigact.sa_mask);
+ sigact.sa_handler = parent_sighandler;
+ sigact.sa_flags = 0;
+
+ sigaction(SIGALRM, &sigact, &saveact1);
+ sigaction(SIGCHLD, &sigact, &saveact2);
+
+ while (live_threads > 0) {
+ int status;
+ pid_t ret;
+
+ if (verbose < 0) /* periodic stats */
+ alarm(-verbose);
+
+ sigsuspend(&sigset);
+ alarm(0);
+
+ while (live_threads > 0) {
+ ret = waitpid(0, &status, WNOHANG);
+ if (ret == 0)
+ break;
+
+ if (ret < 0) {
+ fprintf(stderr,
+ "error: %s: wait - %s\n",
+ argv[0], strerror(errno));
+ if (!rc)
+ rc = errno;
+ continue;
+ } else {
+ /*
+ * This is a hack. We _should_ be able
+ * to use WIFEXITED(status) to see if
+ * there was an error, but it appears
+ * to be broken and it always returns 1
+ * (OK). See wait(2).
+ */
+ int err = WEXITSTATUS(status);
+
+ if (err || WIFSIGNALED(status))
+ fprintf(stderr,
+ "%s: PID %d had rc=%d\n",
+ argv[0], ret, err);
+ if (!rc)
+ rc = err;
+
+ live_threads--;
+ }
+ }
+
+ /* Show stats while all threads running */
+ if (verbose < 0) {
+ shmem_snap(threads, live_threads);
+ if (report_count > 0 && --report_count == 0)
+ shmem_stop();
+ }
+ }
+ sigaction(SIGCHLD, &saveact2, NULL);
+ sigaction(SIGALRM, &saveact1, NULL);
+ }
+
+ shmem_total(threads);
+ sigprocmask(SIG_SETMASK, &saveset, NULL);
+
+ return rc;
}
#else
int jt_opt_threads(int argc, char **argv)
{
- fprintf(stderr, "%s not-supported in a single-threaded runtime\n",
- jt_cmdname(argv[0]));
- return CMD_HELP;
+ fprintf(stderr, "%s not-supported in a single-threaded runtime\n",
+ jt_cmdname(argv[0]));
+ return CMD_HELP;
}
#endif
int jt_opt_net(int argc, char **argv)
{
- char *arg2[3];
- int rc;
+ char *arg2[3];
+ int rc;
- if (argc < 3)
- return CMD_HELP;
+ if (argc < 3)
+ return CMD_HELP;
- arg2[0] = argv[0];
- arg2[1] = argv[1];
- arg2[2] = NULL;
- rc = jt_ptl_network (2, arg2);
+ arg2[0] = argv[0];
+ arg2[1] = argv[1];
+ arg2[2] = NULL;
+ rc = jt_ptl_network(2, arg2);
- if (!rc)
- rc = Parser_execarg(argc - 2, argv + 2, cmdlist);
+ if (!rc)
+ rc = Parser_execarg(argc - 2, argv + 2, cmdlist);
- return rc;
+ return rc;
}
#ifdef HAVE_SERVER_SUPPORT
-/* Place this here so we can build tools that work with
+/*
+ * Place this here so we can build tools that work with
* older Lustre versions
*/
#ifndef OBD_IOC_NO_TRANSNO
if (cfs_get_param_paths(&path, param, obd_name) != 0)
goto try_mdc;
fp = fopen(path.gl_pathv[0], "r");
- if (fp == NULL) {
+ if (!fp) {
/* need to free path data before retry */
cfs_free_param_data(&path);
try_mdc:
/* get device list by ioctl */
int jt_obd_list_ioctl(int argc, char **argv)
{
- int rc, index;
- char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf;
- struct obd_ioctl_data *data = (struct obd_ioctl_data *)buf;
+ int rc, index;
+ char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf;
+ struct obd_ioctl_data *data = (struct obd_ioctl_data *)buf;
- if (argc > 2)
- return CMD_HELP;
- /* Just ignore a -t option. Only supported with /proc. */
- else if (argc == 2 && strcmp(argv[1], "-t") != 0)
- return CMD_HELP;
+ if (argc > 2)
+ return CMD_HELP;
+ /* Just ignore a -t option. Only supported with /proc. */
+ else if (argc == 2 && strcmp(argv[1], "-t") != 0)
+ return CMD_HELP;
- for (index = 0;; index++) {
- memset(buf, 0, sizeof(rawbuf));
- data->ioc_version = OBD_IOCTL_VERSION;
- data->ioc_inllen1 =
+ for (index = 0;; index++) {
+ memset(buf, 0, sizeof(rawbuf));
+ data->ioc_version = OBD_IOCTL_VERSION;
+ data->ioc_inllen1 =
sizeof(rawbuf) - __ALIGN_KERNEL(sizeof(*data), 8);
data->ioc_inlbuf1 = buf + __ALIGN_KERNEL(sizeof(*data), 8);
data->ioc_len = obd_ioctl_packlen(data);
if (space->jt_id > space->jt_width)
space->jt_id = space->jt_width;
- *count = space->jt_id - fid->f_oid;
- return 0;
+ *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;
- __u64 total_count = 0;
- char *name = NULL;
- struct jt_fid_space fid_space = {0};
- int version = 0;
+ 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;
+ __u64 total_count = 0;
+ char *name = NULL;
+ struct jt_fid_space fid_space = {0};
+ int version = 0;
struct option long_opts[] = {
{ .val = 'b', .name = "child_base_id",
.has_arg = required_argument },
{ .val = 'v', .name = "version", .has_arg = no_argument },
{ .name = NULL } };
- while ((c = getopt_long(argc, argv, "b:c:d:D:m:n:t:v",
- 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;
- 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;
- }
+ while ((c = getopt_long(argc, argv, "b:c:d:D:m:n:t:v",
+ 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;
+ 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();
- }
+ 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 {
+ /*
+ * If parent directory is not specified, try to get the directory
+ * from name
+ */
+ if (!parent_basedir) {
+ char *last_lash;
+
+ if (!name) {
+ 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 || 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 + 1;
snprintf(dirname, namelen, "%s", name);
name = last_lash + 1;
}
- data.ioc_pbuf1 = dirname;
- data.ioc_plen1 = strlen(dirname);
+ 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);
- }
+ data.ioc_pbuf2 = name;
+ data.ioc_plen2 = strlen(name);
+ } else {
+ if (name) {
+ data.ioc_pbuf2 = name;
+ data.ioc_plen2 = strlen(name);
+ }
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);
- }
+ 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;
+ 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;
+ 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 };
+ gettimeofday(&start, NULL);
+ while (shmem_running()) {
+ struct lu_fid fid = { 0 };
if (child_base_id != -1)
data.ioc_obdo2.o_oi.oi.oi_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_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_oi.oi_fid = fid;
}
}
shmem_bump(data.ioc_count);
- gettimeofday(&end_time, NULL);
- diff = difftime(&end_time, &start);
- if (seconds > 0 && (__u64)diff > seconds)
- break;
+ 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 >= 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));
- }
+ 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();
- }
+ if (thread) {
+ shmem_lock();
+ shmem_end_time_locked();
+ shmem_unlock();
+ }
#endif
- return rc;
+ return rc;
}
int jt_obd_test_create(int argc, char **argv)
{
- return jt_obd_md_common(argc, argv, ECHO_MD_CREATE);
+ 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);
+ 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);
+ 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);
+ 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);
+ 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);
+ 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);
+ return jt_obd_md_common(argc, argv, ECHO_MD_GETATTR);
}
int jt_obd_create(int argc, char **argv)
struct timeval next_time;
__u64 count = 1, next_count, base_id = 1;
int verbose = 1, mode = 0100644, rc = 0, i;
- char *end;
+ char *end;
- memset(&data, 0, sizeof(data));
- data.ioc_dev = cur_device;
+ memset(&data, 0, sizeof(data));
+ data.ioc_dev = cur_device;
if (argc < 2 || argc > 4)
return CMD_HELP;
- count = strtoull(argv[1], &end, 0);
- if (*end) {
- fprintf(stderr, "error: %s: invalid iteration count '%s'\n",
- jt_cmdname(argv[0]), argv[1]);
- return CMD_HELP;
- }
-
- if (argc > 2) {
- mode = strtoul(argv[2], &end, 0);
- if (*end) {
- fprintf(stderr, "error: %s: invalid mode '%s'\n",
- jt_cmdname(argv[0]), argv[2]);
- return CMD_HELP;
- }
- if (!(mode & S_IFMT))
- mode |= S_IFREG;
- }
-
- if (argc > 3) {
- verbose = get_verbose(argv[0], argv[3]);
- if (verbose == BAD_VERBOSE)
- return CMD_HELP;
- }
+ count = strtoull(argv[1], &end, 0);
+ if (*end) {
+ fprintf(stderr, "error: %s: invalid iteration count '%s'\n",
+ jt_cmdname(argv[0]), argv[1]);
+ return CMD_HELP;
+ }
+
+ if (argc > 2) {
+ mode = strtoul(argv[2], &end, 0);
+ if (*end) {
+ fprintf(stderr, "error: %s: invalid mode '%s'\n",
+ jt_cmdname(argv[0]), argv[2]);
+ return CMD_HELP;
+ }
+ if (!(mode & S_IFMT))
+ mode |= S_IFREG;
+ }
+
+ if (argc > 3) {
+ verbose = get_verbose(argv[0], argv[3]);
+ if (verbose == BAD_VERBOSE)
+ return CMD_HELP;
+ }
printf("%s: %jd objects\n", jt_cmdname(argv[0]), (uintmax_t)count);
- gettimeofday(&next_time, NULL);
- next_time.tv_sec -= verbose;
+ 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++) {
+ for (i = 1, next_count = verbose; i <= count && shmem_running(); i++) {
/*
* base_id is 1 so we don't need to worry about it being
* greater than OBIF_MAX_OID
if (be_verbose(verbose, &next_time, i, &next_count, count))
printf("%s: #%d is object id %#jx\n",
jt_cmdname(argv[0]), i,
- (uintmax_t) ostid_id(&data.ioc_obdo1.o_oi));
+ (uintmax_t)ostid_id(&data.ioc_obdo1.o_oi));
}
return rc;
return CMD_HELP;
}
- if (argc >= 3) {
- verbose = get_verbose(argv[0], argv[2]);
- if (verbose == BAD_VERBOSE)
- return CMD_HELP;
- }
-
- if (argc >= 4) {
- if (argv[3][0] == 't') {
- objid = strtoull(argv[3] + 1, &end, 0);
- if (thread)
- objid += thread - 1;
- } else
- objid = strtoull(argv[3], &end, 0);
- if (*end) {
- fprintf(stderr, "error: %s: invalid objid '%s'\n",
- jt_cmdname(argv[0]), argv[3]);
- return CMD_HELP;
- }
- }
-
- gettimeofday(&start, NULL);
- next_time.tv_sec = start.tv_sec - verbose;
- next_time.tv_usec = start.tv_usec;
- if (verbose != 0)
+ if (argc >= 3) {
+ verbose = get_verbose(argv[0], argv[2]);
+ if (verbose == BAD_VERBOSE)
+ return CMD_HELP;
+ }
+
+ if (argc >= 4) {
+ if (argv[3][0] == 't') {
+ objid = strtoull(argv[3] + 1, &end, 0);
+ if (thread)
+ objid += thread - 1;
+ } else {
+ objid = strtoull(argv[3], &end, 0);
+ }
+ if (*end) {
+ fprintf(stderr, "error: %s: invalid objid '%s'\n",
+ jt_cmdname(argv[0]), argv[3]);
+ return CMD_HELP;
+ }
+ }
+
+ gettimeofday(&start, NULL);
+ next_time.tv_sec = start.tv_sec - verbose;
+ next_time.tv_usec = start.tv_usec;
+ if (verbose != 0)
printf("%s: setting %jd attrs (objid %#jx): %s",
jt_cmdname(argv[0]), (uintmax_t)count,
(uintmax_t)objid, ctime(&start.tv_sec));
jt_cmdname(argv[0]), (uintmax_t)i);
}
- if (!rc) {
- struct timeval end;
- double diff;
+ if (!rc) {
+ struct timeval end;
+ double diff;
- gettimeofday(&end, NULL);
+ gettimeofday(&end, NULL);
- diff = difftime(&end, &start);
+ diff = difftime(&end, &start);
- --i;
- if (verbose != 0)
+ --i;
+ if (verbose != 0)
printf("%s: %jd attrs in %.3fs (%.3f attr/s): %s",
jt_cmdname(argv[0]), (uintmax_t)i, diff,
i / diff, ctime(&end.tv_sec));
- }
- return rc;
+ }
+ return rc;
}
int jt_obd_destroy(int argc, char **argv)
{
- struct obd_ioctl_data data;
- struct timeval next_time;
- char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf;
- __u64 count = 1, next_count;
- int verbose = 1;
- __u64 id;
- char *end;
- int rc = 0, i;
+ struct obd_ioctl_data data;
+ struct timeval next_time;
+ char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf;
+ __u64 count = 1, next_count;
+ int verbose = 1;
+ __u64 id;
+ char *end;
+ int rc = 0, i;
- memset(&data, 0, sizeof(data));
- data.ioc_dev = cur_device;
- if (argc < 2 || argc > 4)
- return CMD_HELP;
+ memset(&data, 0, sizeof(data));
+ data.ioc_dev = cur_device;
+ if (argc < 2 || argc > 4)
+ return CMD_HELP;
errno = 0;
- id = strtoull(argv[1], &end, 0);
- if (*end || id == 0 || errno != 0) {
- fprintf(stderr, "error: %s: invalid objid '%s'\n",
- jt_cmdname(argv[0]), argv[1]);
- return CMD_HELP;
- }
- if (argc > 2) {
- count = strtoull(argv[2], &end, 0);
- if (*end) {
- fprintf(stderr,
- "error: %s: invalid iteration count '%s'\n",
- jt_cmdname(argv[0]), argv[2]);
- return CMD_HELP;
- }
- }
-
- if (argc > 3) {
- verbose = get_verbose(argv[0], argv[3]);
- if (verbose == BAD_VERBOSE)
- return CMD_HELP;
- }
+ id = strtoull(argv[1], &end, 0);
+ if (*end || id == 0 || errno != 0) {
+ fprintf(stderr, "error: %s: invalid objid '%s'\n",
+ jt_cmdname(argv[0]), argv[1]);
+ return CMD_HELP;
+ }
+ if (argc > 2) {
+ count = strtoull(argv[2], &end, 0);
+ if (*end) {
+ fprintf(stderr,
+ "error: %s: invalid iteration count '%s'\n",
+ jt_cmdname(argv[0]), argv[2]);
+ return CMD_HELP;
+ }
+ }
+
+ if (argc > 3) {
+ verbose = get_verbose(argv[0], argv[3]);
+ if (verbose == BAD_VERBOSE)
+ return CMD_HELP;
+ }
printf("%s: %jd objects\n", jt_cmdname(argv[0]), (uintmax_t)count);
gettimeofday(&next_time, NULL);
objid = strtoull(argv[3] + 1, &end, 0);
if (thread)
objid += thread - 1;
- } else
+ } else {
objid = strtoull(argv[3], &end, 0);
+ }
if (*end) {
fprintf(stderr, "error: %s: invalid objid '%s'\n",
jt_cmdname(argv[0]), argv[3]);
return -E2BIG;
}
- data.ioc_obdo1.o_oi.oi_fid.f_oid = objid;
- data.ioc_obdo1.o_mode = S_IFREG;
- data.ioc_obdo1.o_valid = 0xffffffff;
- memset(buf, 0, sizeof(rawbuf));
- rc = llapi_ioctl_pack(&data, &buf, sizeof(rawbuf));
- if (rc) {
- fprintf(stderr, "error: %s: invalid ioctl\n",
- jt_cmdname(argv[0]));
- return rc;
+ data.ioc_obdo1.o_oi.oi_fid.f_oid = objid;
+ data.ioc_obdo1.o_mode = S_IFREG;
+ data.ioc_obdo1.o_valid = 0xffffffff;
+ memset(buf, 0, sizeof(rawbuf));
+ rc = llapi_ioctl_pack(&data, &buf, sizeof(rawbuf));
+ if (rc) {
+ fprintf(stderr, "error: %s: invalid ioctl\n",
+ jt_cmdname(argv[0]));
+ return rc;
+ }
+ rc = l_ioctl(OBD_DEV_ID, OBD_IOC_GETATTR, &data);
+ shmem_bump(1);
+ if (rc < 0) {
+ fprintf(stderr, "error: %s: #%jd - %d:%s\n",
+ jt_cmdname(argv[0]), (uintmax_t)i,
+ errno, strerror(rc = errno));
+ break;
+ }
+ if (be_verbose(verbose, &next_time, i, &next_count, count))
+ printf("%s: got attr #%jd\n",
+ jt_cmdname(argv[0]), (uintmax_t)i);
+ }
+
+ if (!rc) {
+ struct timeval end;
+ double diff;
+
+ gettimeofday(&end, NULL);
+
+ diff = difftime(&end, &start);
+
+ --i;
+ if (verbose != 0)
+ printf("%s: %jd attrs in %.3fs (%.3f attr/s): %s",
+ jt_cmdname(argv[0]), (uintmax_t)i, diff,
+ i / diff, ctime(&end.tv_sec));
+ }
+
+ return rc;
+}
+
+/*
+ * test_brw <cnt> count
+ * <r|w[r(repeat)x(noverify)]> mode
+ * <q|v|#(print interval)> verbosity
+ * <npages[+offset]> blocksize
+ * <[[<interleave_threads>]t(inc obj by thread#)]obj> object
+ * [p|g<args>] batch
+ */
+int jt_obd_test_brw(int argc, char **argv)
+{
+ struct obd_ioctl_data data;
+ struct timeval start, next_time;
+ char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf;
+ __u64 count, next_count, len, stride, thr_offset = 0, objid = 3;
+ int write = 0, verbose = 1, cmd, i, rc = 0, pages = 1;
+ int offset_pages = 0;
+ long n;
+ int repeat_offset = 0;
+ unsigned long long ull;
+ int nthr_per_obj = 0;
+ int verify = 1;
+ int obj_idx = 0;
+ char *end;
+
+ if (argc < 2 || argc > 7) {
+ fprintf(stderr, "error: %s: bad number of arguments: %d\n",
+ jt_cmdname(argv[0]), argc);
+ return CMD_HELP;
+ }
+
+ count = strtoull(argv[1], &end, 0);
+ if (*end) {
+ fprintf(stderr, "error: %s: bad iteration count '%s'\n",
+ jt_cmdname(argv[0]), argv[1]);
+ return CMD_HELP;
+ }
+
+ if (argc >= 3) {
+ if (argv[2][0] == 'w' || argv[2][0] == '1')
+ write = 1;
+ /* else it's a read */
+
+ if (argv[2][0] != 0)
+ for (i = 1; argv[2][i] != 0; i++)
+ switch (argv[2][i]) {
+ case 'r':
+ repeat_offset = 1;
+ break;
+
+ case 'x':
+ verify = 0;
+ break;
+
+ default:
+ fprintf(stderr,
+ "Can't parse cmd '%s'\n",
+ argv[2]);
+ return CMD_HELP;
+ }
+ }
+
+ if (argc >= 4) {
+ verbose = get_verbose(argv[0], argv[3]);
+ if (verbose == BAD_VERBOSE)
+ return CMD_HELP;
+ }
+
+ if (argc >= 5) {
+ pages = strtoul(argv[4], &end, 0);
+
+ if (*end == '+')
+ offset_pages = strtoul(end + 1, &end, 0);
+
+ if (*end != 0 || offset_pages < 0 || offset_pages >= pages) {
+ fprintf(stderr, "error: %s: bad npages[+offset] parameter '%s'\n",
+ jt_cmdname(argv[0]), argv[4]);
+ return CMD_HELP;
+ }
+ }
+
+ if (argc >= 6) {
+ if (thread && (n = strtol(argv[5], &end, 0)) > 0 &&
+ *end == 't' && (ull = strtoull(end + 1, &end, 0)) > 0 &&
+ *end == 0) {
+ nthr_per_obj = n;
+ objid = ull;
+ } else if (thread && argv[5][0] == 't') {
+ nthr_per_obj = 1;
+ objid = strtoull(argv[5] + 1, &end, 0);
+ } else {
+ nthr_per_obj = 0;
+ objid = strtoull(argv[5], &end, 0);
}
- rc = l_ioctl(OBD_DEV_ID, OBD_IOC_GETATTR, &data);
- shmem_bump(1);
- if (rc < 0) {
- fprintf(stderr, "error: %s: #%jd - %d:%s\n",
- jt_cmdname(argv[0]), (uintmax_t)i,
- errno, strerror(rc = errno));
- break;
+ if (*end) {
+ fprintf(stderr, "error: %s: bad objid '%s'\n",
+ jt_cmdname(argv[0]), argv[5]);
+ return CMD_HELP;
}
- if (be_verbose(verbose, &next_time, i, &next_count, count))
- printf("%s: got attr #%jd\n",
- jt_cmdname(argv[0]), (uintmax_t)i);
}
- if (!rc) {
- struct timeval end;
- double diff;
-
- gettimeofday(&end, NULL);
+ memset(&data, 0, sizeof(data));
+ data.ioc_dev = cur_device;
- diff = difftime(&end, &start);
+ /*
+ * communicate the 'type' of brw test and batching to echo_client.
+ * don't start. we'd love to refactor this lctl->echo_client
+ * interface
+ */
+ data.ioc_pbuf1 = (void *)1;
+ data.ioc_plen1 = 1;
+
+ if (argc >= 7) {
+ switch (argv[6][0]) {
+ case 'g': /* plug and unplug */
+ data.ioc_pbuf1 = (void *)2;
+ data.ioc_plen1 = strtoull(argv[6] + 1, &end, 0);
+ break;
+ case 'p': /* prep and commit */
+ data.ioc_pbuf1 = (void *)3;
+ data.ioc_plen1 = strtoull(argv[6] + 1, &end, 0);
+ break;
+ default:
+ fprintf(stderr,
+ "error: %s: batching '%s' needs to specify 'p' or 'g'\n",
+ jt_cmdname(argv[0]), argv[6]);
+ return CMD_HELP;
+ }
- --i;
- if (verbose != 0)
- printf("%s: %jd attrs in %.3fs (%.3f attr/s): %s",
- jt_cmdname(argv[0]), (uintmax_t)i, diff,
- i / diff, ctime(&end.tv_sec));
+ if (*end) {
+ fprintf(stderr, "error: %s: bad batching '%s'\n",
+ jt_cmdname(argv[0]), argv[6]);
+ return CMD_HELP;
+ }
+ data.ioc_plen1 *= getpagesize();
}
- return rc;
-}
-
-/* test_brw <cnt> count
- <r|w[r(repeat)x(noverify)]> mode
- <q|v|#(print interval)> verbosity
- <npages[+offset]> blocksize
- <[[<interleave_threads>]t(inc obj by thread#)]obj> object
- [p|g<args>] batch */
-int jt_obd_test_brw(int argc, char **argv)
-{
- struct obd_ioctl_data data;
- struct timeval start, next_time;
- char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf;
- __u64 count, next_count, len, stride, thr_offset = 0, objid = 3;
- int write = 0, verbose = 1, cmd, i, rc = 0, pages = 1;
- int offset_pages = 0;
- long n;
- int repeat_offset = 0;
- unsigned long long ull;
- int nthr_per_obj = 0;
- int verify = 1;
- int obj_idx = 0;
- char *end;
-
- if (argc < 2 || argc > 7) {
- fprintf(stderr, "error: %s: bad number of arguments: %d\n",
- jt_cmdname(argv[0]), argc);
- return CMD_HELP;
- }
-
- count = strtoull(argv[1], &end, 0);
- if (*end) {
- fprintf(stderr, "error: %s: bad iteration count '%s'\n",
- jt_cmdname(argv[0]), argv[1]);
- return CMD_HELP;
- }
-
- if (argc >= 3) {
- if (argv[2][0] == 'w' || argv[2][0] == '1')
- write = 1;
- /* else it's a read */
-
- if (argv[2][0] != 0)
- for (i = 1; argv[2][i] != 0; i++)
- switch (argv[2][i]) {
- case 'r':
- repeat_offset = 1;
- break;
-
- case 'x':
- verify = 0;
- break;
-
- default:
- fprintf (stderr, "Can't parse cmd '%s'\n",
- argv[2]);
- return CMD_HELP;
- }
- }
-
- if (argc >= 4) {
- verbose = get_verbose(argv[0], argv[3]);
- if (verbose == BAD_VERBOSE)
- return CMD_HELP;
- }
-
- if (argc >= 5) {
- pages = strtoul(argv[4], &end, 0);
-
- if (*end == '+')
- offset_pages = strtoul(end + 1, &end, 0);
-
- if (*end != 0 ||
- offset_pages < 0 || offset_pages >= pages) {
- fprintf(stderr, "error: %s: bad npages[+offset] parameter '%s'\n",
- jt_cmdname(argv[0]), argv[4]);
- return CMD_HELP;
- }
- }
-
- if (argc >= 6) {
- if (thread &&
- (n = strtol(argv[5], &end, 0)) > 0 &&
- *end == 't' &&
- (ull = strtoull(end + 1, &end, 0)) > 0 &&
- *end == 0) {
- nthr_per_obj = n;
- objid = ull;
- } else if (thread &&
- argv[5][0] == 't') {
- nthr_per_obj = 1;
- objid = strtoull(argv[5] + 1, &end, 0);
- } else {
- nthr_per_obj = 0;
- objid = strtoull(argv[5], &end, 0);
- }
- if (*end) {
- fprintf(stderr, "error: %s: bad objid '%s'\n",
- jt_cmdname(argv[0]), argv[5]);
- return CMD_HELP;
- }
- }
-
- memset(&data, 0, sizeof(data));
- data.ioc_dev = cur_device;
-
- /* communicate the 'type' of brw test and batching to echo_client.
- * don't start. we'd love to refactor this lctl->echo_client
- * interface */
- data.ioc_pbuf1 = (void *)1;
- data.ioc_plen1 = 1;
-
- if (argc >= 7) {
- switch(argv[6][0]) {
- case 'g': /* plug and unplug */
- data.ioc_pbuf1 = (void *)2;
- data.ioc_plen1 = strtoull(argv[6] + 1, &end,
- 0);
- break;
- case 'p': /* prep and commit */
- data.ioc_pbuf1 = (void *)3;
- data.ioc_plen1 = strtoull(argv[6] + 1, &end,
- 0);
- break;
- default:
- fprintf(stderr, "error: %s: batching '%s' "
- "needs to specify 'p' or 'g'\n",
- jt_cmdname(argv[0]), argv[6]);
- return CMD_HELP;
- }
-
- if (*end) {
- fprintf(stderr, "error: %s: bad batching '%s'\n",
- jt_cmdname(argv[0]), argv[6]);
- return CMD_HELP;
- }
- data.ioc_plen1 *= getpagesize();
- }
-
- len = pages * getpagesize();
- thr_offset = offset_pages * getpagesize();
- stride = len;
+ len = pages * getpagesize();
+ thr_offset = offset_pages * getpagesize();
+ stride = len;
#ifdef MAX_THREADS
- if (thread) {
- shmem_lock ();
- if (nthr_per_obj != 0) {
- /* threads interleave */
- obj_idx = (thread - 1)/nthr_per_obj;
- objid += obj_idx;
- stride *= nthr_per_obj;
- 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;
- }
-
- shmem_start_time_locked();
- shmem_unlock ();
- }
+ if (thread) {
+ shmem_lock();
+ if (nthr_per_obj != 0) {
+ /* threads interleave */
+ obj_idx = (thread - 1) / nthr_per_obj;
+ objid += obj_idx;
+ stride *= nthr_per_obj;
+ 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;
+ }
+
+ shmem_start_time_locked();
+ shmem_unlock();
+ }
#endif
ostid_set_seq_echo(&data.ioc_obdo1.o_oi);
data.ioc_count = len;
data.ioc_offset = (repeat_offset ? 0 : thr_offset);
- gettimeofday(&start, NULL);
- next_time.tv_sec = start.tv_sec - verbose;
- next_time.tv_usec = start.tv_usec;
+ gettimeofday(&start, NULL);
+ next_time.tv_sec = start.tv_sec - verbose;
+ next_time.tv_usec = start.tv_usec;
- if (verbose != 0)
+ if (verbose != 0)
printf("%s: %s %jux%d pages (obj %#jx, off %ju): %s",
jt_cmdname(argv[0]), write ? "writing" : "reading",
- (uintmax_t)count, pages, (uintmax_t) objid,
+ (uintmax_t)count, pages, (uintmax_t)objid,
(uintmax_t)data.ioc_offset, ctime(&start.tv_sec));
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);
+ data.ioc_obdo1.o_valid &= ~(OBD_MD_FLBLOCKS | OBD_MD_FLGRANT);
memset(buf, 0, sizeof(rawbuf));
rc = llapi_ioctl_pack(&data, &buf, sizeof(rawbuf));
if (rc) {
break;
} else if (be_verbose(verbose, &next_time, i,
&next_count, count)) {
- shmem_lock ();
+ shmem_lock();
printf("%s: %s number %d @ %jd:%ju for %d\n",
jt_cmdname(argv[0]), write ? "write" : "read", i,
(uintmax_t)ostid_id(&data.ioc_obdo1.o_oi),
(uintmax_t)data.ioc_offset,
(int)(pages * getpagesize()));
- shmem_unlock ();
+ shmem_unlock();
}
- if (!repeat_offset) {
+ if (!repeat_offset) {
#ifdef MAX_THREADS
- if (stride == len) {
- data.ioc_offset += stride;
- } else if (i < count) {
- shmem_lock ();
- data.ioc_offset =
- shared_data->body.offsets[obj_idx];
- shared_data->body.offsets[obj_idx] += len;
- shmem_unlock ();
- }
+ if (stride == len) {
+ data.ioc_offset += stride;
+ } else if (i < count) {
+ shmem_lock();
+ data.ioc_offset =
+ shared_data->body.offsets[obj_idx];
+ shared_data->body.offsets[obj_idx] += len;
+ shmem_unlock();
+ }
#else
- data.ioc_offset += len;
- obj_idx = 0; /* avoids an unused var warning */
+ data.ioc_offset += len;
+ obj_idx = 0; /* avoids an unused var warning */
#endif
- }
- }
+ }
+ }
- if (!rc) {
- struct timeval end;
- double diff;
+ if (!rc) {
+ struct timeval end;
+ double diff;
- gettimeofday(&end, NULL);
+ gettimeofday(&end, NULL);
- diff = difftime(&end, &start);
+ diff = difftime(&end, &start);
- --i;
- if (verbose != 0)
- printf("%s: %s %dx%d pages in %.3fs (%.3f MB/s): %s",
- jt_cmdname(argv[0]), write ? "wrote" : "read",
- i, pages, diff,
- ((double)i * pages * getpagesize()) /
- (diff * 1048576.0),
- ctime(&end.tv_sec));
- }
+ --i;
+ if (verbose != 0)
+ printf("%s: %s %dx%d pages in %.3fs (%.3f MB/s): %s",
+ jt_cmdname(argv[0]), write ? "wrote" : "read",
+ i, pages, diff,
+ ((double)i * pages * getpagesize()) /
+ (diff * 1048576.0), ctime(&end.tv_sec));
+ }
#ifdef MAX_THREADS
- if (thread) {
- shmem_lock();
- shmem_end_time_locked();
- shmem_unlock();
- }
+ if (thread) {
+ shmem_lock();
+ shmem_end_time_locked();
+ shmem_unlock();
+ }
#endif
- return rc;
+ return rc;
}
int jt_obd_lov_getconfig(int argc, char **argv)
{
- struct obd_ioctl_data data;
- struct lov_desc desc;
- struct obd_uuid *uuidarray;
- char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf;
- __u32 *obdgens;
- char *path;
- int rc, fd;
-
- memset(&data, 0, sizeof(data));
- data.ioc_dev = cur_device;
-
- if (argc != 2)
- return CMD_HELP;
-
- path = argv[1];
- fd = open(path, O_RDONLY);
- if (fd < 0) {
- fprintf(stderr, "open \"%s\" failed: %s\n", path,
- strerror(errno));
- return -errno;
- }
-
- memset(&desc, 0, sizeof(desc));
- obd_str2uuid(&desc.ld_uuid, argv[1]);
- desc.ld_tgt_count = ((MAX_IOC_BUFLEN-sizeof(data)-sizeof(desc)) /
- (sizeof(*uuidarray) + sizeof(*obdgens)));
+ struct obd_ioctl_data data;
+ struct lov_desc desc;
+ struct obd_uuid *uuidarray;
+ char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf;
+ __u32 *obdgens;
+ char *path;
+ int rc, fd;
+
+ memset(&data, 0, sizeof(data));
+ data.ioc_dev = cur_device;
+
+ if (argc != 2)
+ return CMD_HELP;
+
+ path = argv[1];
+ fd = open(path, O_RDONLY);
+ if (fd < 0) {
+ fprintf(stderr, "open \"%s\" failed: %s\n", path,
+ strerror(errno));
+ return -errno;
+ }
+
+ memset(&desc, 0, sizeof(desc));
+ obd_str2uuid(&desc.ld_uuid, argv[1]);
+ desc.ld_tgt_count = ((MAX_IOC_BUFLEN - sizeof(data) - sizeof(desc)) /
+ (sizeof(*uuidarray) + sizeof(*obdgens)));
repeat:
- uuidarray = calloc(desc.ld_tgt_count, sizeof(*uuidarray));
- if (!uuidarray) {
- fprintf(stderr, "error: %s: no memory for %d uuid's\n",
- jt_cmdname(argv[0]), desc.ld_tgt_count);
- rc = -ENOMEM;
- goto out;
- }
- obdgens = calloc(desc.ld_tgt_count, sizeof(*obdgens));
- if (!obdgens) {
- fprintf(stderr, "error: %s: no memory for %d generation #'s\n",
- jt_cmdname(argv[0]), desc.ld_tgt_count);
- rc = -ENOMEM;
- goto out_uuidarray;
- }
-
- memset(buf, 0, sizeof(rawbuf));
- data.ioc_inllen1 = sizeof(desc);
- data.ioc_inlbuf1 = (char *)&desc;
- data.ioc_inllen2 = desc.ld_tgt_count * sizeof(*uuidarray);
- data.ioc_inlbuf2 = (char *)uuidarray;
- data.ioc_inllen3 = desc.ld_tgt_count * sizeof(*obdgens);
- data.ioc_inlbuf3 = (char *)obdgens;
+ uuidarray = calloc(desc.ld_tgt_count, sizeof(*uuidarray));
+ if (!uuidarray) {
+ fprintf(stderr, "error: %s: no memory for %d uuid's\n",
+ jt_cmdname(argv[0]), desc.ld_tgt_count);
+ rc = -ENOMEM;
+ goto out;
+ }
+ obdgens = calloc(desc.ld_tgt_count, sizeof(*obdgens));
+ if (!obdgens) {
+ fprintf(stderr, "error: %s: no memory for %d generation #'s\n",
+ jt_cmdname(argv[0]), desc.ld_tgt_count);
+ rc = -ENOMEM;
+ goto out_uuidarray;
+ }
+
+ memset(buf, 0, sizeof(rawbuf));
+ data.ioc_inllen1 = sizeof(desc);
+ data.ioc_inlbuf1 = (char *)&desc;
+ data.ioc_inllen2 = desc.ld_tgt_count * sizeof(*uuidarray);
+ data.ioc_inlbuf2 = (char *)uuidarray;
+ data.ioc_inllen3 = desc.ld_tgt_count * sizeof(*obdgens);
+ data.ioc_inlbuf3 = (char *)obdgens;
if (llapi_ioctl_pack(&data, &buf, sizeof(rawbuf))) {
fprintf(stderr, "error: %s: invalid ioctl\n",
int i;
if (llapi_ioctl_unpack(&data, buf, sizeof(rawbuf))) {
- fprintf(stderr, "error: %s: invalid reply\n",
- jt_cmdname(argv[0]));
- rc = -EINVAL;
- goto out;
- }
- if (desc.ld_default_stripe_count == (__u32)-1)
- printf("default_stripe_count: %d\n", -1);
- else
- printf("default_stripe_count: %u\n",
- desc.ld_default_stripe_count);
+ fprintf(stderr, "error: %s: invalid reply\n",
+ jt_cmdname(argv[0]));
+ rc = -EINVAL;
+ goto out;
+ }
+ if (desc.ld_default_stripe_count == (__u32)-1)
+ printf("default_stripe_count: %d\n", -1);
+ else
+ printf("default_stripe_count: %u\n",
+ desc.ld_default_stripe_count);
printf("default_stripe_size: %ju\n",
(uintmax_t)desc.ld_default_stripe_size);
printf("default_stripe_offset: %jd\n",
(uintmax_t)desc.ld_default_stripe_offset);
- printf("default_stripe_pattern: %u\n", desc.ld_pattern);
- printf("obd_count: %u\n", desc.ld_tgt_count);
- printf("OBDS:\tobdidx\t\tobdgen\t\t obduuid\n");
- uuidp = uuidarray;
- genp = obdgens;
- for (i = 0; i < desc.ld_tgt_count; i++, uuidp++, genp++)
- printf("\t%6u\t%14u\t\t %s\n", i, *genp, (char *)uuidp);
- }
+ printf("default_stripe_pattern: %u\n", desc.ld_pattern);
+ printf("obd_count: %u\n", desc.ld_tgt_count);
+ printf("OBDS:\tobdidx\t\tobdgen\t\t obduuid\n");
+ uuidp = uuidarray;
+ genp = obdgens;
+ for (i = 0; i < desc.ld_tgt_count; i++, uuidp++, genp++)
+ printf("\t%6u\t%14u\t\t %s\n", i, *genp, (char *)uuidp);
+ }
out_obdgens:
- free(obdgens);
+ free(obdgens);
out_uuidarray:
- free(uuidarray);
+ free(uuidarray);
out:
- close(fd);
- return rc;
+ close(fd);
+ return rc;
}
static int do_activate(int argc, char **argv, int flag)
if (verbose) {
rc = llapi_ioctl_unpack(&data, buf, sizeof(rawbuf));
- if (rc) {
- fprintf(stderr, "error: %s: invalid reply\n",
- jt_cmdname(argv[0]));
- return rc;
- }
- printf("%s: mode %o uid %d gid %d\n", child,
- data.ioc_obdo1.o_mode, data.ioc_obdo1.o_uid,
- data.ioc_obdo1.o_gid);
- }
+ if (rc) {
+ fprintf(stderr, "error: %s: invalid reply\n",
+ jt_cmdname(argv[0]));
+ return rc;
+ }
+ printf("%s: mode %o uid %d gid %d\n",
+ child, data.ioc_obdo1.o_mode, data.ioc_obdo1.o_uid,
+ data.ioc_obdo1.o_gid);
+ }
- return rc;
+ return rc;
}
int jt_lcfg_fork(int argc, char **argv)
int jt_llog_catlist(int argc, char **argv)
{
- struct obd_ioctl_data data;
- char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf;
- int rc;
+ struct obd_ioctl_data data;
+ char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf;
+ int rc;
- if (argc != 1)
- return CMD_HELP;
+ if (argc != 1)
+ return CMD_HELP;
- memset(&data, 0, sizeof(data));
- data.ioc_dev = cur_device;
+ memset(&data, 0, sizeof(data));
+ data.ioc_dev = cur_device;
data.ioc_inllen1 = sizeof(rawbuf) - __ALIGN_KERNEL(sizeof(data), 8);
memset(buf, 0, sizeof(rawbuf));
rc = llapi_ioctl_pack(&data, &buf, sizeof(rawbuf));
char *endp;
int c;
- if (catalog == NULL || start == NULL || end == NULL)
+ if (!catalog || !start || !end)
return -EINVAL;
/* now process command line arguments*/
*argc -= optind;
*argv += optind;
- /* support old optional positional parameters only if they were
+ /*
+ * support old optional positional parameters only if they were
* not already specified with named arguments: logname [start [end]]
*/
if (*argc >= 1) {
return rc;
}
-/* Parse catalog, log ID, and optionally a log index with either optional
+/*
+ * Parse catalog, log ID, and optionally a log index with either optional
* arguments or positional arguments. Only the initial catalog argument
* may be positional with other optional arguments.
*
*argv += optind;
/* Allow catalog to be specified as first option without --catalog */
- if (data->ioc_inlbuf1 == NULL && *argc > 0) {
+ if (!data->ioc_inlbuf1 && *argc > 0) {
data->ioc_inlbuf1 = (*argv)[0];
data->ioc_inllen1 = strlen((*argv)[0]) + 1;
(*argc)--;
/* Parse catalog file (in inlbuf1) and named parameters */
rc = llog_parse_catalog_log_idx(&argc, &argv, "c:hi:l:", 3, &data);
- /* Handle old positional parameters if not using named parameters,
+ /*
+ * Handle old positional parameters if not using named parameters,
* either "<catalog> <log_idx>" or "<catalog> <log_id> <log_idx>".
* It was "inlbuf3 = log_idx", and "inlbuf2 = log_id" (ignored by
* config log cancel), and shows why I hate positional parameters.
data.ioc_inlbuf3 = argv[1];
}
- if (data.ioc_inlbuf1 == NULL || data.ioc_inlbuf3 == NULL)
+ if (!data.ioc_inlbuf1 || !data.ioc_inlbuf3)
/* missing mandatory parameters */
return CMD_HELP;
void obd_finalize(int argc, char **argv)
{
- struct sigaction sigact;
+ struct sigaction sigact;
/* sigact initialization */
- sigact.sa_handler = signal_server;
- sigfillset(&sigact.sa_mask);
- sigact.sa_flags = SA_RESTART;
+ sigact.sa_handler = signal_server;
+ sigfillset(&sigact.sa_mask);
+ sigact.sa_flags = SA_RESTART;
/* coverity[uninit_use_in_call] */
- sigaction(SIGINT, &sigact, NULL);
+ sigaction(SIGINT, &sigact, NULL);
- shmem_cleanup();
- do_disconnect(argv[0], 1);
+ shmem_cleanup();
+ do_disconnect(argv[0], 1);
}
/**
last_index = strstr(((struct obd_ioctl_data *)buf)->ioc_bulk,
"last_index:");
return strtol(last_index + 11, NULL, 10);
- } else {
- rc = -errno;
}
+ rc = -errno;
+
return rc;
}
* \param ostname[in] pointer to ost name
*
* \retval 1 if ostname is found
- * 0 if ostname is not found
+ * 0 if ostname is not found
*/
static int llog_search_ost(char *logname, long last_index, char *ostname)
{
ostname, cmd);
}
-static int check_pool_cmd(enum lcfg_command_type cmd,
- char *fsname, char *poolname,
- char *ostname)
+static int check_pool_cmd(enum lcfg_command_type cmd, char *fsname,
+ char *poolname, char *ostname)
{
- int rc;
+ int rc;
rc = lctl_search_ost(fsname, poolname, ostname, cmd);
- if (rc < 0 && (cmd != LCFG_POOL_NEW)) {
- fprintf(stderr, "Pool %s.%s not found\n",
- fsname, poolname);
- return rc;
- }
-
- switch (cmd) {
- case LCFG_POOL_NEW: {
- if (ostname != NULL)
+ if (rc < 0 && (cmd != LCFG_POOL_NEW)) {
+ fprintf(stderr, "Pool %s.%s not found\n",
+ fsname, poolname);
+ return rc;
+ }
+
+ switch (cmd) {
+ case LCFG_POOL_NEW: {
+ if (ostname)
return -EINVAL;
- if (rc >= 0) {
- fprintf(stderr, "Pool %s.%s already exists\n",
- fsname, poolname);
- return -EEXIST;
- }
- return 0;
- }
- case LCFG_POOL_DEL: {
- if (ostname != NULL)
+ if (rc >= 0) {
+ fprintf(stderr, "Pool %s.%s already exists\n",
+ fsname, poolname);
+ return -EEXIST;
+ }
+ return 0;
+ }
+ case LCFG_POOL_DEL: {
+ if (ostname)
return -EINVAL;
- if (rc == 1) {
- fprintf(stderr, "Pool %s.%s not empty, "
- "please remove all members\n",
- fsname, poolname);
- return -ENOTEMPTY;
- }
- return 0;
- }
- case LCFG_POOL_ADD: {
- if (rc == 1) {
- fprintf(stderr, "OST %s is already in pool %s.%s\n",
- ostname, fsname, poolname);
- return -EEXIST;
- }
+ if (rc == 1) {
+ fprintf(stderr,
+ "Pool %s.%s not empty, please remove all members\n",
+ fsname, poolname);
+ return -ENOTEMPTY;
+ }
+ return 0;
+ }
+ case LCFG_POOL_ADD: {
+ if (rc == 1) {
+ fprintf(stderr, "OST %s is already in pool %s.%s\n",
+ ostname, fsname, poolname);
+ return -EEXIST;
+ }
rc = lctl_search_ost(fsname, NULL, ostname, cmd);
- if (rc == 0) {
- fprintf(stderr, "OST %s is not part of the '%s' fs.\n",
- ostname, fsname);
- return -ENOENT;
- }
- return 0;
- }
- case LCFG_POOL_REM: {
- if (rc == 0) {
- fprintf(stderr, "OST %s not found in pool %s.%s\n",
- ostname, fsname, poolname);
- return -ENOENT;
- }
- return 0;
- }
- default:
- break;
- } /* switch */
- return -EINVAL;
-}
-
-/* This check only verifies that the changes have been "pushed out" to
- the client successfully. This involves waiting for a config update,
- and so may fail because of problems in that code or post-command
- network loss. So reporting a warning is appropriate, but not a failure.
-*/
-static int check_pool_cmd_result(enum lcfg_command_type cmd,
- char *fsname, char *poolname,
- char *ostname)
-{
- int cpt = 10;
- int rc = 0;
-
- switch (cmd) {
- case LCFG_POOL_NEW: {
- do {
+ if (rc == 0) {
+ fprintf(stderr, "OST %s is not part of the '%s' fs.\n",
+ ostname, fsname);
+ return -ENOENT;
+ }
+ return 0;
+ }
+ case LCFG_POOL_REM: {
+ if (rc == 0) {
+ fprintf(stderr, "OST %s not found in pool %s.%s\n",
+ ostname, fsname, poolname);
+ return -ENOENT;
+ }
+ return 0;
+ }
+ default:
+ break;
+ } /* switch */
+ return -EINVAL;
+}
+
+/*
+ * This check only verifies that the changes have been "pushed out" to
+ * the client successfully. This involves waiting for a config update,
+ * and so may fail because of problems in that code or post-command
+ * network loss. So reporting a warning is appropriate, but not a failure.
+ */
+static int check_pool_cmd_result(enum lcfg_command_type cmd, char *fsname,
+ char *poolname, char *ostname)
+{
+ int cpt = 10;
+ int rc = 0;
+
+ switch (cmd) {
+ case LCFG_POOL_NEW: {
+ do {
rc = lctl_search_ost(fsname, poolname, NULL, cmd);
- if (rc == -ENODEV)
- return rc;
- if (rc < 0)
- sleep(2);
- cpt--;
- } while ((rc < 0) && (cpt > 0));
- if (rc >= 0) {
- fprintf(stderr, "Pool %s.%s created\n",
- fsname, poolname);
- return 0;
- } else {
- fprintf(stderr, "Warning, pool %s.%s not found\n",
- fsname, poolname);
- return -ENOENT;
- }
- }
- case LCFG_POOL_DEL: {
- do {
+ if (rc == -ENODEV)
+ return rc;
+ if (rc < 0)
+ sleep(2);
+ cpt--;
+ } while ((rc < 0) && (cpt > 0));
+ if (rc >= 0) {
+ fprintf(stderr, "Pool %s.%s created\n",
+ fsname, poolname);
+ return 0;
+ }
+
+ fprintf(stderr, "Warning, pool %s.%s not found\n", fsname,
+ poolname);
+ return -ENOENT;
+ }
+ case LCFG_POOL_DEL: {
+ do {
rc = lctl_search_ost(fsname, poolname, NULL, cmd);
- if (rc == -ENODEV)
- return rc;
- if (rc >= 0)
- sleep(2);
- cpt--;
- } while ((rc >= 0) && (cpt > 0));
- if (rc < 0) {
- fprintf(stderr, "Pool %s.%s destroyed\n",
- fsname, poolname);
- return 0;
- } else {
- fprintf(stderr, "Warning, pool %s.%s still found\n",
- fsname, poolname);
- return -EEXIST;
- }
- }
- case LCFG_POOL_ADD: {
- do {
+ if (rc == -ENODEV)
+ return rc;
+ if (rc >= 0)
+ sleep(2);
+ cpt--;
+ } while ((rc >= 0) && (cpt > 0));
+ if (rc < 0) {
+ fprintf(stderr, "Pool %s.%s destroyed\n",
+ fsname, poolname);
+ return 0;
+ }
+
+ fprintf(stderr, "Warning, pool %s.%s still found\n", fsname,
+ poolname);
+ return -EEXIST;
+ }
+ case LCFG_POOL_ADD: {
+ do {
rc = lctl_search_ost(fsname, poolname, ostname, cmd);
- if (rc == -ENODEV)
- return rc;
- if (rc != 1)
- sleep(2);
- cpt--;
- } while ((rc != 1) && (cpt > 0));
- if (rc == 1) {
- fprintf(stderr, "OST %s added to pool %s.%s\n",
- ostname, fsname, poolname);
- return 0;
- } else {
- fprintf(stderr, "Warning, OST %s not found in pool %s.%s\n",
- ostname, fsname, poolname);
- return -ENOENT;
- }
- }
- case LCFG_POOL_REM: {
- do {
+ if (rc == -ENODEV)
+ return rc;
+ if (rc != 1)
+ sleep(2);
+ cpt--;
+ } while ((rc != 1) && (cpt > 0));
+ if (rc == 1) {
+ fprintf(stderr, "OST %s added to pool %s.%s\n",
+ ostname, fsname, poolname);
+ return 0;
+ }
+ fprintf(stderr, "Warning, OST %s not found in pool %s.%s\n",
+ ostname, fsname, poolname);
+ return -ENOENT;
+ }
+ case LCFG_POOL_REM: {
+ do {
rc = lctl_search_ost(fsname, poolname, ostname, cmd);
- if (rc == -ENODEV)
- return rc;
- if (rc == 1)
- sleep(2);
- cpt--;
- } while ((rc == 1) && (cpt > 0));
- if (rc != 1) {
- fprintf(stderr, "OST %s removed from pool %s.%s\n",
- ostname, fsname, poolname);
- return 0;
- } else {
- fprintf(stderr, "Warning, OST %s still found in pool %s.%s\n",
- ostname, fsname, poolname);
- return -EEXIST;
- }
- }
- default:
- break;
- }
- return -EINVAL;
+ if (rc == -ENODEV)
+ return rc;
+ if (rc == 1)
+ sleep(2);
+ cpt--;
+ } while ((rc == 1) && (cpt > 0));
+ if (rc != 1) {
+ fprintf(stderr, "OST %s removed from pool %s.%s\n",
+ ostname, fsname, poolname);
+ return 0;
+ }
+ fprintf(stderr, "Warning, OST %s still found in pool %s.%s\n",
+ ostname, fsname, poolname);
+ return -EEXIST;
+ }
+ default:
+ break;
+ }
+ return -EINVAL;
}
static int check_and_complete_ostname(char *fsname, char *ostname)
{
- char *ptr;
- char real_ostname[MAX_OBD_NAME + 1];
- char i;
-
- /* if OST name does not start with fsname, we add it */
- /* if not check if the fsname is the right one */
- ptr = strchr(ostname, '-');
- if (ptr == NULL) {
- sprintf(real_ostname, "%s-%s", fsname, ostname);
- } else if (strncmp(ostname, fsname, strlen(fsname)) != 0) {
- fprintf(stderr, "%s does not start with fsname %s\n",
- ostname, fsname);
- return -EINVAL;
- } else {
- if (strlen(ostname) > sizeof(real_ostname)-1)
+ char *ptr;
+ char real_ostname[MAX_OBD_NAME + 1];
+ char i;
+
+ /* if OST name does not start with fsname, we add it */
+ /* if not check if the fsname is the right one */
+ ptr = strchr(ostname, '-');
+ if (!ptr) {
+ sprintf(real_ostname, "%s-%s", fsname, ostname);
+ } else if (strncmp(ostname, fsname, strlen(fsname)) != 0) {
+ fprintf(stderr, "%s does not start with fsname %s\n",
+ ostname, fsname);
+ return -EINVAL;
+ } else {
+ if (strlen(ostname) > sizeof(real_ostname) - 1)
return -E2BIG;
+
strncpy(real_ostname, ostname, sizeof(real_ostname));
- }
- /* real_ostname is fsname-????? */
- ptr = real_ostname + strlen(fsname) + 1;
- if (strncmp(ptr, "OST", 3) != 0) {
- fprintf(stderr, "%s does not start by %s-OST nor OST\n",
- ostname, fsname);
- return -EINVAL;
- }
- /* real_ostname is fsname-OST????? */
- ptr += 3;
- for (i = 0; i < 4; i++) {
- if (!isxdigit(*ptr)) {
- fprintf(stderr,
- "ost's index in %s is not an hexa number\n",
- ostname);
- return -EINVAL;
- }
- ptr++;
- }
- /* real_ostname is fsname-OSTXXXX????? */
- /* if OST name does not end with _UUID, we add it */
- if (*ptr == '\0') {
- strcat(real_ostname, "_UUID");
- } else if (strcmp(ptr, "_UUID") != 0) {
- fprintf(stderr,
- "ostname %s does not end with _UUID\n", ostname);
- return -EINVAL;
- }
- /* real_ostname is fsname-OSTXXXX_UUID */
- strcpy(ostname, real_ostname);
- return 0;
+ }
+
+ /* real_ostname is fsname-????? */
+ ptr = real_ostname + strlen(fsname) + 1;
+ if (strncmp(ptr, "OST", 3) != 0) {
+ fprintf(stderr, "%s does not start by %s-OST nor OST\n",
+ ostname, fsname);
+ return -EINVAL;
+ }
+ /* real_ostname is fsname-OST????? */
+ ptr += 3;
+ for (i = 0; i < 4; i++) {
+ if (!isxdigit(*ptr)) {
+ fprintf(stderr,
+ "ost's index in %s is not an hexa number\n",
+ ostname);
+ return -EINVAL;
+ }
+ ptr++;
+ }
+ /* real_ostname is fsname-OSTXXXX????? */
+ /* if OST name does not end with _UUID, we add it */
+ if (*ptr == '\0') {
+ strcat(real_ostname, "_UUID");
+ } else if (strcmp(ptr, "_UUID") != 0) {
+ fprintf(stderr,
+ "ostname %s does not end with _UUID\n", ostname);
+ return -EINVAL;
+ }
+ /* real_ostname is fsname-OSTXXXX_UUID */
+ strcpy(ostname, real_ostname);
+ return 0;
}
/* returns 0 or -errno */
-static int pool_cmd(enum lcfg_command_type cmd,
- char *cmdname, char *fullpoolname,
- char *fsname, char *poolname, char *ostname)
-{
- int rc = 0;
- struct obd_ioctl_data data;
- struct lustre_cfg_bufs bufs;
- struct lustre_cfg *lcfg;
- char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf;
-
- rc = check_pool_cmd(cmd, fsname, poolname, ostname);
- if (rc == -ENODEV)
- fprintf(stderr, "Can't verify pool command since there "
- "is no local MDT or client, proceeding anyhow...\n");
- else if (rc)
- return rc;
-
- lustre_cfg_bufs_reset(&bufs, NULL);
- lustre_cfg_bufs_set_string(&bufs, 0, cmdname);
- lustre_cfg_bufs_set_string(&bufs, 1, fullpoolname);
- if (ostname != NULL)
- lustre_cfg_bufs_set_string(&bufs, 2, ostname);
+static int pool_cmd(enum lcfg_command_type cmd, char *cmdname,
+ char *fullpoolname, char *fsname, char *poolname,
+ char *ostname)
+{
+ int rc = 0;
+ struct obd_ioctl_data data;
+ struct lustre_cfg_bufs bufs;
+ struct lustre_cfg *lcfg;
+ char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf;
+
+ rc = check_pool_cmd(cmd, fsname, poolname, ostname);
+ if (rc == -ENODEV)
+ fprintf(stderr,
+ "Can't verify pool command since there is no local MDT or client, proceeding anyhow...\n");
+ else if (rc)
+ return rc;
+ lustre_cfg_bufs_reset(&bufs, NULL);
+ lustre_cfg_bufs_set_string(&bufs, 0, cmdname);
+ lustre_cfg_bufs_set_string(&bufs, 1, fullpoolname);
+ if (ostname)
+ lustre_cfg_bufs_set_string(&bufs, 2, ostname);
lcfg = malloc(lustre_cfg_len(bufs.lcfg_bufcount, bufs.lcfg_buflen));
- if (lcfg == NULL)
+ if (!lcfg)
return -ENOMEM;
lustre_cfg_init(lcfg, cmd, &bufs);
rc = -errno;
switch (rc) {
case -ENAMETOOLONG:
- fprintf(stderr, "error: %s: either the pool or file "
- "system name is too long (max pool name len "
- "is %d and file system name is %d)\n",
- jt_cmdname(cmdname), LOV_MAXPOOLNAME,
- LUSTRE_MAXFSNAME);
+ fprintf(stderr,
+ "error: %s: either the pool or file system name is too long (max pool name len is %d and file system name is %d)\n",
+ jt_cmdname(cmdname), LOV_MAXPOOLNAME, LUSTRE_MAXFSNAME);
break;
case -EINVAL:
- fprintf(stderr, "error: %s can contain only "
- "alphanumeric characters, underscores, and "
- "dashes besides the required '.'\n",
+ fprintf(stderr,
+ "error: %s can contain only alphanumeric characters, underscores, and dashes besides the required '.'\n",
jt_cmdname(cmdname));
default:
break;
va_start(ap, ret_size);
arg = va_arg(ap, char *);
- while (arg != NULL) {
+ while (arg) {
lustre_cfg_bufs_set_string(&bufs, i, arg);
i++;
arg = va_arg(ap, char *);
va_end(ap);
lcfg = malloc(lustre_cfg_len(bufs.lcfg_bufcount, bufs.lcfg_buflen));
- if (lcfg == NULL)
+ if (!lcfg)
return -ENOMEM;
lustre_cfg_init(lcfg, cmd, &bufs);
data.ioc_type = LUSTRE_CFG_TYPE;
data.ioc_plen1 = lustre_cfg_len(lcfg->lcfg_bufcount,
- lcfg->lcfg_buflens);
+ lcfg->lcfg_buflens);
data.ioc_pbuf1 = (void *)lcfg;
memset(buf, 0, sizeof(rawbuf));
rc = llapi_ioctl_pack(&data, &buf, sizeof(rawbuf));
if (rc != 0) {
- fprintf(stderr, "error: invalid ioctl: %08x errno: %d with "
- "rc=%d\n", cmd, errno, rc);
+ fprintf(stderr,
+ "error: invalid ioctl: %08x errno: %d with rc=%d\n",
+ cmd, errno, rc);
goto out;
}
rc = l_ioctl(OBD_DEV_ID, OBD_IOC_NODEMAP, buf);
if (rc != 0) {
- fprintf(stderr, "error: invalid ioctl: %08x errno: %d with "
- "rc=%d\n", cmd, errno, rc);
+ fprintf(stderr,
+ "error: invalid ioctl: %08x errno: %d with rc=%d\n",
+ cmd, errno, rc);
goto out;
}
- if (ret_data != NULL) {
+ if (ret_data) {
rc = llapi_ioctl_unpack(&data, buf, sizeof(rawbuf));
if (rc != 0)
goto out;
*/
int jt_nodemap_test_nid(int argc, char **argv)
{
-
char rawbuf[MAX_IOC_BUFLEN];
int rc;
}
}
- if (nidstr == NULL || typestr == NULL || idstr == NULL) {
- fprintf(stderr, "usage: nodemap_test_id --nid <nid> "
- "--idtype [uid|gid] --id <id>\n");
+ if (!nidstr || !typestr || !idstr) {
+ fprintf(stderr,
+ "usage: nodemap_test_id --nid <nid> --idtype [uid|gid] --id <id>\n");
return -1;
}
if (rc < 0) {
if (rc == -EINVAL)
fprintf(stderr,
- "error: nodemap_xxx_range: nid range uses "
- "currently unsupported features\n");
+ "error: nodemap_xxx_range: nid range uses currently unsupported features\n");
else if (rc == -ERANGE)
fprintf(stderr,
- "error: nodemap_xxx_range: nodemap ranges must "
- "be contiguous\n");
+ "error: nodemap_xxx_range: nodemap ranges must be contiguous\n");
return rc;
}
}
}
- if (nodemap_name == NULL || nodemap_range == NULL) {
- fprintf(stderr, "usage: nodemap_add_range --name <name> "
- "--range <range>\n");
+ if (!nodemap_name || !nodemap_range) {
+ fprintf(stderr,
+ "usage: nodemap_add_range --name <name> --range <range>\n");
return -1;
}
nodemap_name, nid_range, NULL);
if (rc != 0) {
errno = -rc;
- fprintf(stderr, "error: %s: cannot add range '%s' to nodemap "
- "'%s': rc = %d\n",
+ fprintf(stderr,
+ "error: %s: cannot add range '%s' to nodemap '%s': rc = %d\n",
jt_cmdname(argv[0]), nodemap_range, nodemap_name, rc);
}
}
}
- if (nodemap_name == NULL || nodemap_range == NULL) {
- fprintf(stderr, "usage: nodemap_del_range --name <name> "
- "--range <range>\n");
+ if (!nodemap_name || !nodemap_range) {
+ fprintf(stderr,
+ "usage: nodemap_del_range --name <name> --range <range>\n");
return -1;
}
nodemap_name, nid_range, NULL);
if (rc != 0) {
errno = -rc;
- fprintf(stderr, "error: %s: cannot delete range '%s' to "
- "nodemap '%s': rc = %d\n",
+ fprintf(stderr,
+ "error: %s: cannot delete range '%s' to nodemap '%s': rc = %d\n",
jt_cmdname(argv[0]), nodemap_range, nodemap_name, rc);
}
}
}
- if (nodemap_name == NULL || fileset_name == NULL) {
- fprintf(stderr, "usage: nodemap_set_fileset --name <name> "
- "--fileset <fileset>\n");
+ if (!nodemap_name || !fileset_name) {
+ fprintf(stderr,
+ "usage: nodemap_set_fileset --name <name> --fileset <fileset>\n");
return -1;
}
nodemap_name, fileset_name, NULL);
if (rc != 0) {
errno = -rc;
- fprintf(stderr, "error: %s: cannot set fileset '%s' on nodemap "
- "'%s': rc = %d\n",
+ fprintf(stderr,
+ "error: %s: cannot set fileset '%s' on nodemap '%s': rc = %d\n",
jt_cmdname(argv[0]), fileset_name, nodemap_name, rc);
}
}
}
- if (nodemap_name == NULL || sepol == NULL) {
- fprintf(stderr, "usage: nodemap_set_sepol --name <name> "
- "--sepol <sepol>\n");
+ if (!nodemap_name || !sepol) {
+ fprintf(stderr,
+ "usage: nodemap_set_sepol --name <name> --sepol <sepol>\n");
return -1;
}
nodemap_name, sepol, NULL);
if (rc != 0) {
errno = -rc;
- fprintf(stderr, "error: %s: cannot set sepol '%s' on nodemap "
- "'%s': rc = %d\n",
+ fprintf(stderr,
+ "error: %s: cannot set sepol '%s' on nodemap '%s': rc = %d\n",
jt_cmdname(argv[0]), sepol, nodemap_name, rc);
}
}
}
- if (nodemap_name == NULL || param == NULL || value == NULL) {
- fprintf(stderr, "usage: nodemap_modify --name <nodemap_name> "
- "--property <property_name> --value <value>\n");
- fprintf(stderr, "valid properties: admin trusted map_mode "
- "squash_uid squash_gid deny_unknown audit_mode\n");
+ if (!nodemap_name || !param || !value) {
+ fprintf(stderr,
+ "usage: nodemap_modify --name <nodemap_name> --property <property_name> --value <value>\n");
+ fprintf(stderr,
+ "valid properties: admin trusted map_mode squash_uid squash_gid deny_unknown audit_mode\n");
return -1;
}
} else if (strcmp("audit_mode", param) == 0) {
cmd = LCFG_NODEMAP_AUDIT_MODE;
} else {
- fprintf(stderr, "error: %s: nodemap_modify invalid "
- "subcommand: %s\n",
+ fprintf(stderr,
+ "error: %s: nodemap_modify invalid subcommand: %s\n",
jt_cmdname(argv[0]), param);
return -1;
}
value, NULL);
if (rc != 0) {
errno = -rc;
- fprintf(stderr, "error: %s: cannot modify nodemap '%s' "
- "to param '%s': value '%s': rc = %d\n",
+ fprintf(stderr,
+ "error: %s: cannot modify nodemap '%s' to param '%s': value '%s': rc = %d\n",
jt_cmdname(argv[0]), nodemap_name, param, value, rc);
}
}
}
- if (nodemap_name == NULL || idmap == NULL || idtype == NULL) {
- fprintf(stderr, "usage: %s --name <name> --idtype [uid | gid]"
- " --idmap <client id>:<filesystem id>\n", argv[0]);
+ if (!nodemap_name || !idmap || !idtype) {
+ fprintf(stderr,
+ "usage: %s --name <name> --idtype [uid | gid] --idmap <client id>:<filesystem id>\n",
+ argv[0]);
return -1;
}
} else if (strcmp("gid", idtype) == 0) {
cmd = LCFG_NODEMAP_ADD_GIDMAP;
} else {
- fprintf(stderr, "usage: %s --name <name> --idtype [uid | gid]"
- " --idmap <client id>:<filesystem id>\n", argv[0]);
+ fprintf(stderr,
+ "usage: %s --name <name> --idtype [uid | gid] --idmap <client id>:<filesystem id>\n",
+ argv[0]);
return -1;
}
rc = nodemap_cmd(cmd, NULL, 0, argv[0], nodemap_name, idmap, NULL);
if (rc != 0) {
errno = -rc;
- fprintf(stderr, "cannot add %smap '%s' to nodemap '%s'"
- ": rc = %d\n", idtype, idmap, nodemap_name, rc);
+ fprintf(stderr,
+ "cannot add %smap '%s' to nodemap '%s': rc = %d\n",
+ idtype, idmap, nodemap_name, rc);
}
return rc;
}
}
- if (nodemap_name == NULL || idmap == NULL || idtype == NULL) {
- fprintf(stderr, "usage: %s --name <name> --idtype [uid | gid]"
- " --idmap <client id>:<filesystem id>\n", argv[0]);
+ if (!nodemap_name || !idmap || !idtype) {
+ fprintf(stderr,
+ "usage: %s --name <name> --idtype [uid | gid] --idmap <client id>:<filesystem id>\n",
+ argv[0]);
return -1;
}
rc = nodemap_cmd(cmd, NULL, 0, argv[0], nodemap_name, idmap, NULL);
if (rc != 0) {
errno = -rc;
- fprintf(stderr, "cannot delete %smap '%s' from nodemap '%s'"
- ": rc = %d\n", idtype, idmap, nodemap_name, rc);
+ fprintf(stderr,
+ "cannot delete %smap '%s' from nodemap '%s': rc = %d\n",
+ idtype, idmap, nodemap_name, rc);
}
return rc;
*/
static int get_array_idx(char *rule, char *format, int **array)
{
- char *start, *end, *ptr;
- unsigned int lo, hi, step;
- int array_sz = 0;
- int i, array_idx;
- int rc;
-
- start = strchr(rule, '[');
- end = strchr(rule, ']');
- if ((start == NULL) || (end == NULL)) {
- *array = malloc(sizeof(int));
- if (*array == NULL)
- return 0;
- strcpy(format, rule);
- array_sz = 1;
- return array_sz;
- }
- *start = '\0';
- *end = '\0';
- end++;
- start++;
- /* put in format the printf format (the rule without the range) */
- sprintf(format, "%s%%.4x%s", rule, end);
-
- array_idx = 0;
- array_sz = 0;
- *array = NULL;
- /* loop on , separator */
- do {
- /* extract the 3 fields */
- rc = sscanf(start, "%x-%x/%u", &lo, &hi, &step);
- switch (rc) {
- case 0:
+ char *start, *end, *ptr;
+ unsigned int lo, hi, step;
+ int array_sz = 0;
+ int i, array_idx;
+ int rc;
+
+ start = strchr(rule, '[');
+ end = strchr(rule, ']');
+ if ((!start) || (!end)) {
+ *array = malloc(sizeof(int));
+ if (!*array)
+ return 0;
+ strcpy(format, rule);
+ array_sz = 1;
+ return array_sz;
+ }
+ *start = '\0';
+ *end = '\0';
+ end++;
+ start++;
+ /* put in format the printf format (the rule without the range) */
+ sprintf(format, "%s%%.4x%s", rule, end);
+
+ array_idx = 0;
+ array_sz = 0;
+ *array = NULL;
+ /* loop on , separator */
+ do {
+ /* extract the 3 fields */
+ rc = sscanf(start, "%x-%x/%u", &lo, &hi, &step);
+ switch (rc) {
+ case 0:
goto err;
case 1: {
void *tmp;
array_sz++;
tmp = realloc(*array, array_sz * sizeof(int));
- if (tmp == NULL)
+ if (!tmp)
goto err;
*array = tmp;
- (*array)[array_idx] = lo;
- array_idx++;
- break;
- }
- case 2: {
- step = 1;
- /* do not break to share code with case 3: */
- }
- case 3: {
+ (*array)[array_idx] = lo;
+ array_idx++;
+ break;
+ }
+ case 2: {
+ step = 1;
+ /* do not break to share code with case 3: */
+ }
+ case 3: {
void *tmp;
if ((hi < lo) || (step == 0))
goto err;
array_sz += (hi - lo) / step + 1;
tmp = realloc(*array, array_sz * sizeof(int));
- if (tmp == NULL)
+ if (!tmp)
goto err;
*array = tmp;
- for (i = lo; i <= hi; i+=step, array_idx++)
- (*array)[array_idx] = i;
- break;
- }
- }
- ptr = strchr(start, ',');
- if (ptr != NULL)
- start = ptr + 1;
-
- } while (ptr != NULL);
- return array_sz;
+ for (i = lo; i <= hi; i += step, array_idx++)
+ (*array)[array_idx] = i;
+ break;
+ }
+ }
+ ptr = strchr(start, ',');
+ if (ptr)
+ start = ptr + 1;
+
+ } while (ptr);
+ return array_sz;
err:
- if (*array != NULL) {
+ if (*array) {
free(*array);
*array = NULL;
}
if (name_len <= 0 || name_len > sizeof(tmp->lpn_name))
return -EINVAL;
tmp = malloc(sizeof(struct llog_pool_name));
- if (tmp == NULL) {
+ if (!tmp) {
rc = -ENOMEM;
goto out;
}
snprintf(fsname, PATH_MAX + 1, "%s", param);
ptr = strchr(fsname, '.');
- if (ptr == NULL) {
+ if (!ptr) {
if (strcmp(cmd, "pool_list") == 0) {
poolname = NULL;
goto out;
return llapi_poollist(argv[1]);
if (get_mgs_device() > 0)
return llog_poollist(fsname, poolname);
- fprintf(stderr, "Cannot run pool_list command "
- "since there is no local MGS/MDT or client\n");
+ fprintf(stderr,
+ "Cannot run pool_list command since there is no local MGS/MDT or client\n");
return CMD_HELP;
} else {
return CMD_HELP;
if (rc)
break;
- for (i = 2; i < argc; i++) {
- int j;
-
- array_sz = get_array_idx(argv[i], format, &array);
- if (array_sz == 0)
- return CMD_HELP;
-
- cmds = malloc(array_sz * sizeof(cmds[0]));
- if (cmds != NULL) {
- ostnames_buf = malloc(array_sz *
- (MAX_OBD_NAME + 1));
- } else {
- free(array);
- rc = -ENOMEM;
- goto out;
- }
-
- for (j = 0; j < array_sz; j++) {
- char ostname[MAX_OBD_NAME + 1];
-
- snprintf(ostname, MAX_OBD_NAME, format,
- array[j]);
- ostname[MAX_OBD_NAME] = '\0';
-
- rc = check_and_complete_ostname(fsname,ostname);
- if (rc) {
- free(array);
- free(cmds);
- if (ostnames_buf)
- free(ostnames_buf);
- goto out;
- }
- if (ostnames_buf != NULL) {
- cmds[j].ostname =
- &ostnames_buf[(MAX_OBD_NAME + 1) * j];
- strcpy(cmds[j].ostname, ostname);
- } else {
- cmds[j].ostname = NULL;
- }
- cmds[j].rc = pool_cmd(cmd, argv[0], argv[1],
- fsname, poolname,
- ostname);
- /* Return an err if any of the add/dels fail */
- if (!rc)
- rc = cmds[j].rc;
- }
- for (j = 0; j < array_sz; j++) {
- if (!cmds[j].rc) {
- char ostname[MAX_OBD_NAME + 1];
-
- if (!cmds[j].ostname) {
- snprintf(ostname, MAX_OBD_NAME,
- format, array[j]);
- ostname[MAX_OBD_NAME] = '\0';
- check_and_complete_ostname(
- fsname, ostname);
- } else {
- strcpy(ostname,
- cmds[j].ostname);
- }
- check_pool_cmd_result(cmd, fsname,
- poolname,ostname);
- }
- }
- if (array_sz > 0)
- free(array);
- if (cmds)
- free(cmds);
- if (ostnames_buf != NULL)
+ for (i = 2; i < argc; i++) {
+ int j;
+
+ array_sz = get_array_idx(argv[i], format, &array);
+ if (array_sz == 0)
+ return CMD_HELP;
+
+ cmds = malloc(array_sz * sizeof(cmds[0]));
+ if (cmds) {
+ ostnames_buf = malloc(array_sz *
+ (MAX_OBD_NAME + 1));
+ } else {
+ free(array);
+ rc = -ENOMEM;
+ goto out;
+ }
+
+ for (j = 0; j < array_sz; j++) {
+ char ostname[MAX_OBD_NAME + 1];
+
+ snprintf(ostname, MAX_OBD_NAME, format,
+ array[j]);
+ ostname[MAX_OBD_NAME] = '\0';
+
+ rc = check_and_complete_ostname(fsname,
+ ostname);
+ if (rc) {
+ free(array);
+ free(cmds);
+ if (ostnames_buf)
+ free(ostnames_buf);
+ goto out;
+ }
+ if (ostnames_buf) {
+ cmds[j].ostname =
+ &ostnames_buf[(MAX_OBD_NAME + 1) * j];
+ strcpy(cmds[j].ostname, ostname);
+ } else {
+ cmds[j].ostname = NULL;
+ }
+ cmds[j].rc = pool_cmd(cmd, argv[0], argv[1],
+ fsname, poolname,
+ ostname);
+ /* Return an err if any of the add/dels fail */
+ if (!rc)
+ rc = cmds[j].rc;
+ }
+ for (j = 0; j < array_sz; j++) {
+ if (!cmds[j].rc) {
+ char ostname[MAX_OBD_NAME + 1];
+
+ if (!cmds[j].ostname) {
+ snprintf(ostname, MAX_OBD_NAME,
+ format, array[j]);
+ ostname[MAX_OBD_NAME] = '\0';
+ check_and_complete_ostname(
+ fsname, ostname);
+ } else {
+ strcpy(ostname,
+ cmds[j].ostname);
+ }
+ check_pool_cmd_result(cmd, fsname,
+ poolname,
+ ostname);
+ }
+ }
+ if (array_sz > 0)
+ free(array);
+ if (cmds)
+ free(cmds);
+ if (ostnames_buf)
free(ostnames_buf);
- }
- /* fall through */
- }
- } /* switch */
+ }
+ /* fall through */
+ }
+ } /* switch */
out:
- if (rc != 0) {
- errno = -rc;
- perror(argv[0]);
- }
+ if (rc != 0) {
+ errno = -rc;
+ perror(argv[0]);
+ }
- return rc;
+ return rc;
}
#ifdef HAVE_SERVER_SUPPORT
bc.bc_timeout = BARRIER_TIMEOUT_DEFAULT;
if (strlen(argv[1]) > 8) {
- fprintf(stderr, "%s: fsname name %s is too long. "
- "It should not exceed 8.\n", argv[0], argv[1]);
+ fprintf(stderr,
+ "%s: fsname name %s is too long. It should not exceed 8.\n",
+ argv[0], argv[1]);
return -EINVAL;
}
bc.bc_cmd = BC_THAW;
if (strlen(argv[1]) > 8) {
- fprintf(stderr, "fsname name %s is too long. "
- "It should not exceed 8.\n", argv[1]);
+ fprintf(stderr,
+ "fsname name %s is too long. It should not exceed 8.\n",
+ argv[1]);
return -EINVAL;
}
name = argv[optind];
if (strlen(name) > 8) {
- fprintf(stderr, "fsname name %s is too long. "
- "It should not exceed 8.\n", name);
+ fprintf(stderr,
+ "fsname name %s is too long. It should not exceed 8.\n",
+ name);
return -EINVAL;
}
bc.bc_timeout = BARRIER_TIMEOUT_DEFAULT;
if (strlen(argv[1]) > 8) {
- fprintf(stderr, "fsname name %s is too long. "
- "It should not exceed 8.\n", argv[1]);
+ fprintf(stderr,
+ "fsname name %s is too long. It should not exceed 8.\n",
+ argv[1]);
return -EINVAL;
}
!(id == ULLONG_MAX && group == ULLONG_MAX && argc == 1))
return CMD_HELP;
- memset(&data, 0, sizeof data);
+ memset(&data, 0, sizeof(data));
data.ioc_dev = cur_device;
if (argc == 1) {
rc = llapi_fid_parse(fidstr, &fid, NULL);
data.ioc_inlbuf4 = (char *)&group;
data.ioc_inllen4 = sizeof(group);
}
- data.ioc_inlbuf2 = (char *) &version;
- data.ioc_inllen2 = sizeof version;
+ data.ioc_inlbuf2 = (char *)&version;
+ data.ioc_inllen2 = sizeof(version);
- memset(buf, 0, sizeof *buf);
+ memset(buf, 0, sizeof(*buf));
rc = llapi_ioctl_pack(&data, &buf, sizeof(rawbuf));
if (rc) {
fprintf(stderr, "error: %s: packing ioctl arguments: %s\n",
return -errno;
}
- llapi_ioctl_unpack(&data, buf, sizeof rawbuf);
+ llapi_ioctl_unpack(&data, buf, sizeof(rawbuf));
printf("%#jx\n", (uintmax_t)version);
return 0;
}
}
- if (cur_device < 0 || device == NULL)
+ if (cur_device < 0 || !device)
return CMD_HELP;
data.ioc_dev = cur_device;
if (rc < 0) {
fprintf(stderr, "error: %s: cannot pack ioctl: %s\n",
jt_cmdname(argv[0]), strerror(-rc));
- return rc;
+ return rc;
}
rc = l_ioctl(OBD_DEV_ID, OBD_IOC_CHANGELOG_REG, buf);
int id;
int rc;
- if (argc != 2 || cur_device < 0 || device == NULL)
+ if (argc != 2 || cur_device < 0 || !device)
return CMD_HELP;
rc = sscanf(argv[1], CHANGELOG_USER_PREFIX"%d", &id);
int rc;
optind = 1;
- while ((rc = getopt_long(argc, argv, "p:",
- long_opts, NULL)) != -1) {
+ while ((rc = getopt_long(argc, argv, "p:", long_opts, NULL)) != -1) {
switch (rc) {
case 'p':
param = optarg;