* GPL HEADER END
*/
/*
- * Copyright 2008 Sun Microsystems, Inc. All rights reserved
+ * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
* Use is subject to license terms.
*/
/*
* Author: Robert Read <rread@clusterfs.com>
*/
-#include <stdlib.h>
#include <sys/ioctl.h>
-#include <fcntl.h>
#include <sys/socket.h>
+#include <sys/stat.h>
+#include <sys/time.h>
#include <sys/types.h>
+#include <sys/un.h>
#include <sys/wait.h>
-#include <sys/stat.h>
-#include <stdio.h>
-#include <stdarg.h>
-#include <signal.h>
+
#include <ctype.h>
+#include <errno.h>
+#include <fcntl.h>
#include <glob.h>
+#include <signal.h>
+#include <stdarg.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+#include <unistd.h>
#include "obdctl.h"
#include <obd.h> /* for struct lov_stripe_md */
#include <lustre/lustre_build_version.h>
-#include <unistd.h>
-#include <sys/un.h>
-#include <time.h>
-#include <sys/time.h>
-#include <errno.h>
-#include <string.h>
-
#include <obd_class.h>
#include <lnet/lnetctl.h>
#include <libcfs/libcfsutil.h>
-#include <stdio.h>
#include <lustre/liblustreapi.h>
#define MAX_STRING_SIZE 128
"\nctime: "LPU64"\nsize: "LPU64"\nblocks: "LPU64
"\nblksize: %u\nmode: %o\nuid: %d\ngid: %d\nflags: %x\n"
"misc: %x\nnlink: %d,\nvalid "LPX64"\n",
- obd->o_id, obd->o_gr, obd->o_atime, obd->o_mtime, obd->o_ctime,
+ obd->o_id, obd->o_seq, obd->o_atime, obd->o_mtime, obd->o_ctime,
obd->o_size, obd->o_blocks, obd->o_blksize, obd->o_mode,
obd->o_uid, obd->o_gid, obd->o_flags, obd->o_misc,
obd->o_nlink, obd->o_valid);
static inline void shmem_bump(void)
{
- static int bumped_running;
+ static bool running_not_bumped = true;
if (shared_data == NULL || thread <= 0 || thread > MAX_THREADS)
return;
shmem_lock();
shared_data->counters[thread - 1]++;
- if (!bumped_running)
+ if (running_not_bumped) {
shared_data->running++;
+ running_not_bumped = false;
+ }
shmem_unlock();
- bumped_running = 1;
}
static void shmem_snap(int total_threads, int live_threads)
(prev_time.tv_sec + prev_time.tv_usec / 1000000.0);
if (prev_valid &&
- live_threads == total_threads &&
- secs > 0.0) /* someone screwed with the time? */
+ secs > 1.0) /* someone screwed with the time? */
printf("%d/%d Total: %f/second\n", non_zero, total_threads, total / secs);
memcpy(counter_snapshot[1], counter_snapshot[0],
thread = i;
argv[2] = "--device";
- return jt_opt_device(argc - 2, argv + 2);
+ exit(jt_opt_device(argc - 2, argv + 2));
} else if (be_verbose(verbose, NULL, i, &next_thread, threads))
printf("%s: thread #%d (PID %d) started\n",
argv[0], i, rc);
int jt_get_version(int argc, char **argv)
{
int rc;
- char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf;
- struct obd_ioctl_data *data = (struct obd_ioctl_data *)buf;
+ char rawbuf[MAX_IOC_BUFLEN];
+ char *version;
if (argc != 1)
return CMD_HELP;
- memset(buf, 0, sizeof(rawbuf));
- data->ioc_version = OBD_IOCTL_VERSION;
- data->ioc_inllen1 = sizeof(rawbuf) - size_round(sizeof(*data));
- data->ioc_inlbuf1 = buf + size_round(sizeof(*data));
- data->ioc_len = obd_ioctl_packlen(data);
-
- rc = l2_ioctl(OBD_DEV_ID, OBD_GET_VERSION, buf);
- if (rc < 0)
+ rc = llapi_get_version(rawbuf, MAX_IOC_BUFLEN, &version);
+ if (rc)
fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
- strerror(rc = errno));
- else {
- printf("Lustre version: %s\n", data->ioc_bulk);
- }
+ strerror(-rc));
+ else
+ printf("Lustre version: %s\n", version);
printf("lctl version: %s\n", BUILD_VERSION);
return rc;
goto fail;
got_one:
- fgets(buf, sizeof(buf), fp);
+ /* should not ignore fgets(3)'s return value */
+ if (!fgets(buf, sizeof(buf), fp)) {
+ fprintf(stderr, "reading from %s: %s", buf, strerror(errno));
+ fclose(fp);
+ return;
+ }
fclose(fp);
/* trim trailing newlines */
for (index = 0;; index++) {
memset(buf, 0, sizeof(rawbuf));
data->ioc_version = OBD_IOCTL_VERSION;
- data->ioc_inllen1 = sizeof(rawbuf) - size_round(sizeof(*data));
- data->ioc_inlbuf1 = buf + size_round(sizeof(*data));
+ data->ioc_inllen1 =
+ sizeof(rawbuf) - cfs_size_round(sizeof(*data));
+ data->ioc_inlbuf1 = buf + cfs_size_round(sizeof(*data));
data->ioc_len = obd_ioctl_packlen(data);
data->ioc_count = index;
return CMD_HELP;
}
- if (argc < 5)
+ if (argc < 5) {
reset_lsmb (&lsm_buffer); /* will set default */
- else {
+ } else {
rc = parse_lsm (&lsm_buffer, argv[4]);
if (rc != 0) {
fprintf(stderr, "error: %s: invalid lsm '%s'\n",
obj_idx = (thread - 1)/nthr_per_obj;
objid += obj_idx;
stride *= nthr_per_obj;
- if (thread == 1)
+ if ((thread - 1) % nthr_per_obj == 0)
shared_data->offsets[obj_idx] = stride + thr_offset;
thr_offset += ((thread - 1) % nthr_per_obj) * len;
} else {
l_cond_broadcast(&shared_data->cond);
else
l_cond_wait(&shared_data->cond,
- &shared_data->mutex);
+ &shared_data->mutex);
shmem_unlock ();
}
memset(&data, 0x00, sizeof(data));
data.ioc_dev = cur_device;
- data.ioc_inllen1 = sizeof(rawbuf) - size_round(sizeof(data));
+ data.ioc_inllen1 = sizeof(rawbuf) - cfs_size_round(sizeof(data));
memset(buf, 0, sizeof(rawbuf));
rc = obd_ioctl_pack(&data, &buf, sizeof(rawbuf));
if (rc) {
data.ioc_dev = cur_device;
data.ioc_inllen1 = strlen(argv[1]) + 1;
data.ioc_inlbuf1 = argv[1];
- data.ioc_inllen2 = sizeof(rawbuf) - size_round(sizeof(data)) -
- size_round(data.ioc_inllen1);
+ data.ioc_inllen2 = sizeof(rawbuf) - cfs_size_round(sizeof(data)) -
+ cfs_size_round(data.ioc_inllen1);
memset(buf, 0, sizeof(rawbuf));
rc = obd_ioctl_pack(&data, &buf, sizeof(rawbuf));
if (rc) {
data.ioc_inllen3 = strlen(to) + 1;
data.ioc_inlbuf3 = to;
}
- data.ioc_inllen4 = sizeof(rawbuf) - size_round(sizeof(data)) -
- size_round(data.ioc_inllen1) -
- size_round(data.ioc_inllen2) -
- size_round(data.ioc_inllen3);
+ data.ioc_inllen4 = sizeof(rawbuf) - cfs_size_round(sizeof(data)) -
+ cfs_size_round(data.ioc_inllen1) -
+ cfs_size_round(data.ioc_inllen2) -
+ cfs_size_round(data.ioc_inllen3);
memset(buf, 0, sizeof(rawbuf));
rc = obd_ioctl_pack(&data, &buf, sizeof(rawbuf));
if (rc) {
data.ioc_inllen3 = strlen(to) + 1;
data.ioc_inlbuf3 = to;
}
- data.ioc_inllen4 = sizeof(rawbuf) - size_round(sizeof(data)) -
- size_round(data.ioc_inllen1) -
- size_round(data.ioc_inllen2) -
- size_round(data.ioc_inllen3);
+ data.ioc_inllen4 = sizeof(rawbuf) - cfs_size_round(sizeof(data)) -
+ cfs_size_round(data.ioc_inllen1) -
+ cfs_size_round(data.ioc_inllen2) -
+ cfs_size_round(data.ioc_inllen3);
memset(buf, 0, sizeof(rawbuf));
rc = obd_ioctl_pack(&data, &buf, sizeof(rawbuf));
if (rc) {
{
char *filename;
int rc, fd;
- __u64 ino;
+ struct lu_fid fid;
if (argc != 2)
return CMD_HELP;
return CMD_HELP;
}
- rc = ioctl(fd, LL_IOC_LLOOP_INFO, &ino);
+ rc = ioctl(fd, LL_IOC_LLOOP_INFO, &fid);
if (rc < 0) {
rc = errno;
fprintf(stderr, "error: %s\n", strerror(errno));
goto out;
}
fprintf(stdout, "lloop device info: ");
- if (ino == 0ULL)
+ if (fid_is_zero(&fid))
fprintf(stdout, "Not attached\n");
else
- fprintf(stdout, "attached to inode "LPU64"\n", ino);
+ fprintf(stdout, "attached to inode "DFID"\n", PFID(&fid));
out:
close(fd);
return -rc;
do_disconnect(argv[0], 1);
}
-static int find_target_obdpath(char *fsname, char *path)
-{
- glob_t glob_info;
- char pattern[PATH_MAX + 1];
- int rc;
-
- snprintf(pattern, PATH_MAX,
- "/proc/fs/lustre/lov/%s-*/target_obd",
- fsname);
- rc = glob(pattern, GLOB_BRACE, NULL, &glob_info);
- if (rc == GLOB_NOMATCH)
- return -ENODEV;
- else if (rc)
- return -EINVAL;
-
- strcpy(path, glob_info.gl_pathv[0]);
- globfree(&glob_info);
- return 0;
-}
-
-static int find_poolpath(char *fsname, char *poolname, char *poolpath)
+static int check_pool_cmd(enum lcfg_command_type cmd,
+ char *fsname, char *poolname,
+ char *ostname)
{
- glob_t glob_info;
- char pattern[PATH_MAX + 1];
int rc;
- snprintf(pattern, PATH_MAX,
- "/proc/fs/lustre/lov/%s-*/pools/%s",
- fsname, poolname);
- rc = glob(pattern, GLOB_BRACE, NULL, &glob_info);
- /* If no pools, make sure the lov is available */
- if ((rc == GLOB_NOMATCH) &&
- (find_target_obdpath(fsname, poolpath) == -ENODEV))
- return -ENODEV;
- if (rc)
- return -EINVAL;
-
- strcpy(poolpath, glob_info.gl_pathv[0]);
- globfree(&glob_info);
- return 0;
-}
-
-/*
- * if pool is NULL, search ostname in target_obd
- * if pool is no NULL
- * if pool not found returns < 0
- * if ostname is NULL, returns 1 if pool is not empty and 0 if pool empty
- * if ostname is not NULL, returns 1 if OST is in pool and 0 if not
- */
-static int search_ost(char *fsname, char *poolname, char *ostname)
-{
- FILE *fd;
- char buffer[PATH_MAX + 1];
- int len = 0, rc;
-
- if (ostname != NULL)
- len = strlen(ostname);
-
- if (poolname == NULL)
- rc = find_target_obdpath(fsname, buffer);
- else
- rc = find_poolpath(fsname, poolname, buffer);
- if (rc)
+ rc = llapi_search_ost(fsname, poolname, ostname);
+ if (rc < 0 && (cmd != LCFG_POOL_NEW)) {
+ fprintf(stderr, "Pool %s.%s not found\n",
+ fsname, poolname);
return rc;
-
- if ((fd = fopen(buffer, "r")) == NULL)
- return -EINVAL;
-
- while (fgets(buffer, sizeof(buffer), fd) != NULL) {
- if (poolname == NULL) {
- char *ptr;
- /* Search for an ostname in the list of OSTs
- Line format is IDX: fsname-OSTxxxx_UUID STATUS */
- ptr = strchr(buffer, ' ');
- if ((ptr != NULL) &&
- (strncmp(ptr + 1, ostname, len) == 0)) {
- fclose(fd);
- return 1;
- }
- } else {
- /* Search for an ostname in a pool,
- (or an existing non-empty pool if no ostname) */
- if ((ostname == NULL) ||
- (strncmp(buffer, ostname, len) == 0)) {
- fclose(fd);
- return 1;
- }
- }
}
- fclose(fd);
- return 0;
-}
-
-static int check_pool_cmd(enum lcfg_command_type cmd,
- char *fsname, char *poolname,
- char *ostname)
-{
- int rc = 0;
switch (cmd) {
case LCFG_POOL_NEW: {
- if (search_ost(fsname, poolname, NULL) >= 0) {
+ LASSERT(ostname == NULL);
+ if (rc >= 0) {
fprintf(stderr, "Pool %s.%s already exists\n",
fsname, poolname);
return -EEXIST;
return 0;
}
case LCFG_POOL_DEL: {
- rc = search_ost(fsname, poolname, NULL);
- if (rc < 0) {
- fprintf(stderr, "Pool %s.%s not found\n",
- fsname, poolname);
- return rc;
- }
+ LASSERT(ostname == NULL);
if (rc == 1) {
fprintf(stderr, "Pool %s.%s not empty, "
"please remove all members\n",
return 0;
}
case LCFG_POOL_ADD: {
- rc = search_ost(fsname, NULL, ostname);
- if (rc == 0) {
- fprintf(stderr, "OST %s not found in lov of %s\n",
- ostname, fsname);
- return -ENOENT;
- }
- rc = search_ost(fsname, poolname, ostname);
- if (rc < 0) {
- fprintf(stderr, "Pool %s.%s not found\n",
- fsname, poolname);
- return rc;
- }
if (rc == 1) {
- fprintf(stderr, "OST %s already in pool %s.%s\n",
+ fprintf(stderr, "OST %s is already in pool %s.%s\n",
ostname, fsname, poolname);
return -EEXIST;
}
+ rc = llapi_search_ost(fsname, NULL, ostname);
+ 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: {
- rc = search_ost(fsname, poolname, ostname);
- if (rc < 0) {
- fprintf(stderr, "Pool %s.%s not found\n",
- fsname, poolname);
- return rc;
- }
if (rc == 0) {
fprintf(stderr, "OST %s not found in pool %s.%s\n",
ostname, fsname, poolname);
}
return 0;
}
- default: {
- }
- }
- return 0;
+ default:
+ break;
+ } /* switch */
+ return -EINVAL;
}
-static void check_pool_cmd_result(enum lcfg_command_type cmd,
- char *fsname, char *poolname,
- char *ostname)
+/* 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, rc = 0;
+ int cpt = 10;
+ int rc = 0;
- cpt = 10;
switch (cmd) {
case LCFG_POOL_NEW: {
do {
- rc = search_ost(fsname, poolname, NULL);
+ rc = llapi_search_ost(fsname, poolname, NULL);
if (rc == -ENODEV)
- return;
+ return rc;
if (rc < 0)
sleep(2);
cpt--;
} while ((rc < 0) && (cpt > 0));
- if (rc >= 0)
+ if (rc >= 0) {
fprintf(stderr, "Pool %s.%s created\n",
fsname, poolname);
- else
+ return 0;
+ } else {
fprintf(stderr, "Warning, pool %s.%s not found\n",
fsname, poolname);
- return;
+ return -ENOENT;
+ }
}
case LCFG_POOL_DEL: {
do {
- rc = search_ost(fsname, poolname, NULL);
+ rc = llapi_search_ost(fsname, poolname, NULL);
if (rc == -ENODEV)
- return;
+ return rc;
if (rc >= 0)
sleep(2);
cpt--;
} while ((rc >= 0) && (cpt > 0));
- if (rc < 0)
+ if (rc < 0) {
fprintf(stderr, "Pool %s.%s destroyed\n",
fsname, poolname);
- else
+ return 0;
+ } else {
fprintf(stderr, "Warning, pool %s.%s still found\n",
fsname, poolname);
- return;
+ return -EEXIST;
+ }
}
case LCFG_POOL_ADD: {
do {
- rc = search_ost(fsname, poolname, ostname);
+ rc = llapi_search_ost(fsname, poolname, ostname);
if (rc == -ENODEV)
- return;
+ return rc;
if (rc != 1)
sleep(2);
cpt--;
} while ((rc != 1) && (cpt > 0));
- if (rc == 1)
+ if (rc == 1) {
fprintf(stderr, "OST %s added to pool %s.%s\n",
ostname, fsname, poolname);
- else
+ return 0;
+ } else {
fprintf(stderr, "Warning, OST %s not found in pool %s.%s\n",
ostname, fsname, poolname);
- return;
+ return -ENOENT;
+ }
}
case LCFG_POOL_REM: {
do {
- rc = search_ost(fsname, poolname, ostname);
+ rc = llapi_search_ost(fsname, poolname, ostname);
if (rc == -ENODEV)
- return;
+ return rc;
if (rc == 1)
sleep(2);
cpt--;
} while ((rc == 1) && (cpt > 0));
- if (rc != 1)
+ if (rc != 1) {
fprintf(stderr, "OST %s removed from pool %s.%s\n",
ostname, fsname, poolname);
- else
+ return 0;
+ } else {
fprintf(stderr, "Warning, OST %s still found in pool %s.%s\n",
ostname, fsname, poolname);
- return;
- }
- default: {
+ return -EEXIST;
+ }
}
+ default:
+ break;
}
+ return -EINVAL;
}
static int check_and_complete_ostname(char *fsname, char *ostname)
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) {
if (ostnames_buf);
free(ostnames_buf);
}
- return 0;
- }
+ /* fall through */
}
-
+ } /* switch */
out:
- if ((rc == -EINVAL) || (rc == -ENOENT))
- fprintf(stderr, "Does the fs, pool or ost exist?\n");
if (rc != 0) {
errno = -rc;
perror(argv[0]);
return rc;
}
+int jt_get_obj_version(int argc, char **argv)
+{
+ struct lu_fid fid;
+ struct obd_ioctl_data data;
+ __u64 version;
+ char rawbuf[MAX_IOC_BUFLEN], *buf = rawbuf, *fidstr;
+ int rc;
+
+ if (argc != 2)
+ return CMD_HELP;
+
+ fidstr = argv[1];
+ while (*fidstr == '[')
+ fidstr++;
+ sscanf(fidstr, SFID, RFID(&fid));
+ if (!fid_is_sane(&fid)) {
+ fprintf(stderr, "bad FID format [%s], should be "DFID"\n",
+ fidstr, (__u64)1, 2, 0);
+ return -EINVAL;
+ }
+
+ memset(&data, 0, sizeof data);
+ data.ioc_dev = cur_device;
+ data.ioc_inlbuf1 = (char *) &fid;
+ data.ioc_inllen1 = sizeof fid;
+ data.ioc_inlbuf2 = (char *) &version;
+ data.ioc_inllen2 = sizeof version;
+
+ memset(buf, 0, sizeof *buf);
+ rc = obd_ioctl_pack(&data, &buf, sizeof rawbuf);
+ if (rc) {
+ fprintf(stderr, "error: %s: packing ioctl arguments: %s\n",
+ jt_cmdname(argv[0]), strerror(-rc));
+ return rc;
+ }
+
+ rc = l2_ioctl(OBD_DEV_ID, OBD_IOC_GET_OBJ_VERSION, buf);
+ if (rc == -1) {
+ fprintf(stderr, "error: %s: ioctl: %s\n",
+ jt_cmdname(argv[0]), strerror(errno));
+ return -errno;
+ }
+
+ obd_ioctl_unpack(&data, buf, sizeof rawbuf);
+ printf(LPX64"\n", version);
+ return 0;
+}
+
void llapi_ping_target(char *obd_type, char *obd_name,
char *obd_uuid, void *args)
{
if (rc)
rc = errno;
if (rc == ENOTCONN || rc == ESHUTDOWN) {
- printf("%s inactive.\n", obd_name);
+ printf("%s: INACTIVE\n", obd_name);
} else if (rc) {
- fprintf(stderr, "error: check '%s' %s\n",
+ printf("%s: check error: %s\n",
obd_name, strerror(errno));
} else {
- printf("%s active.\n", obd_name);
+ printf("%s: active\n", obd_name);
}
}