if (!llapi_is_lustre_mnt(&mnt))
continue;
+ if ((want & WANT_INDEX) && (idx++ != index))
+ continue;
+
mntlen = strlen(mnt.mnt_dir);
ptr = strrchr(mnt.mnt_fsname, '/');
if (!ptr && !len) {
}
ptr++;
- if ((want & WANT_INDEX) && (idx++ != index))
- continue;
-
/* Check the fsname for a match, if given */
if (!(want & WANT_FSNAME) && fsname != NULL &&
(strlen(fsname) > 0) && (strcmp(ptr, fsname) != 0))
return get_root_path(want, fsname, NULL, mntdir, idx);
}
+/* Given a path, find the corresponding Lustre fsname */
int llapi_search_fsname(const char *pathname, char *fsname)
{
+ char *path = (char*)pathname, buf[PATH_MAX + 1];
+
+ if (pathname[0] != '/') { /* Need a absolute path */
+ memset(buf, '\0', sizeof(buf));
+ if (realpath(pathname, buf) == NULL) {
+ llapi_err(LLAPI_MSG_ERROR, "pathname '%s' cannot expand",
+ pathname);
+ return -EINVAL;
+ }
+ path = buf;
+ }
return get_root_path(WANT_FSNAME | WANT_ERROR, fsname, NULL,
- (char *)pathname, -1);
+ path, -1);
}
/* return the first file matching this pattern */
free(param->lmd);
}
+static int cb_common_fini(char *path, DIR *parent, DIR *d, void *data,
+ cfs_dirent_t *de)
+{
+ struct find_param *param = (struct find_param *)data;
+ param->depth--;
+ return 0;
+}
+
+static DIR *opendir_parent(char *path)
+{
+ DIR *parent;
+ char *fname;
+ char c;
+
+ fname = strrchr(path, '/');
+ if (fname == NULL)
+ return opendir(".");
+
+ c = fname[1];
+ fname[1] = '\0';
+ parent = opendir(path);
+ fname[1] = c;
+ return parent;
+}
+
+int llapi_mds_getfileinfo(char *path, DIR *parent,
+ struct lov_user_mds_data *lmd)
+{
+ lstat_t *st = &lmd->lmd_st;
+ char *fname = strrchr(path, '/');
+ int ret = 0;
+
+ if (parent == NULL)
+ return -EINVAL;
+
+ fname = (fname == NULL ? path : fname + 1);
+ /* retrieve needed file info */
+ strncpy((char *)lmd, fname,
+ lov_mds_md_size(MAX_LOV_UUID_COUNT, LOV_MAGIC));
+ ret = ioctl(dirfd(parent), IOC_MDC_GETFILEINFO, (void *)lmd);
+
+ if (ret) {
+ if (errno == ENOTTY) {
+ /* ioctl is not supported, it is not a lustre fs.
+ * Do the regular lstat(2) instead. */
+ ret = lstat_f(path, st);
+ if (ret) {
+ llapi_err(LLAPI_MSG_ERROR,
+ "error: %s: lstat failed for %s",
+ __func__, path);
+ return ret;
+ }
+ } else if (errno == ENOENT) {
+ llapi_err(LLAPI_MSG_WARN,
+ "warning: %s: %s does not exist",
+ __func__, path);
+ return -ENOENT;
+ } else {
+ llapi_err(LLAPI_MSG_ERROR,
+ "error: %s: IOC_MDC_GETFILEINFO failed for %s",
+ __func__, path);
+ return ret;
+ }
+ }
+
+ return 0;
+}
+
+static int llapi_semantic_traverse(char *path, int size, DIR *parent,
+ semantic_func_t sem_init,
+ semantic_func_t sem_fini, void *data,
+ cfs_dirent_t *de)
+{
+ cfs_dirent_t *dent;
+ int len, ret;
+ DIR *d, *p = NULL;
+
+ ret = 0;
+ len = strlen(path);
+
+ d = opendir(path);
+ if (!d && errno != ENOTDIR) {
+ llapi_err(LLAPI_MSG_ERROR, "%s: Failed to open '%s'",
+ __func__, path);
+ return -EINVAL;
+ } else if (!d && !parent) {
+ /* ENOTDIR. Open the parent dir. */
+ p = opendir_parent(path);
+ if (!p)
+ GOTO(out, ret = -EINVAL);
+ }
+
+ if (sem_init && (ret = sem_init(path, parent ?: p, d, data, de)))
+ goto err;
+
+ if (!d)
+ GOTO(out, ret = 0);
+
+ while ((dent = readdir64(d)) != NULL) {
+ ((struct find_param *)data)->have_fileinfo = 0;
+
+ if (!strcmp(dent->d_name, ".") || !strcmp(dent->d_name, ".."))
+ continue;
+
+ /* Don't traverse .lustre directory */
+ if (!(strcmp(dent->d_name, dot_lustre_name)))
+ continue;
+
+ path[len] = 0;
+ if ((len + dent->d_reclen + 2) > size) {
+ llapi_err(LLAPI_MSG_ERROR,
+ "error: %s: string buffer is too small",
+ __func__);
+ break;
+ }
+ strcat(path, "/");
+ strcat(path, dent->d_name);
+
+ if (dent->d_type == DT_UNKNOWN) {
+ lstat_t *st = &((struct find_param *)data)->lmd->lmd_st;
+
+ ret = llapi_mds_getfileinfo(path, d,
+ ((struct find_param *)data)->lmd);
+ if (ret == 0) {
+ ((struct find_param *)data)->have_fileinfo = 1;
+ dent->d_type =
+ llapi_filetype_dir_table[st->st_mode &
+ S_IFMT];
+ }
+ if (ret == -ENOENT)
+ continue;
+ }
+
+ switch (dent->d_type) {
+ case DT_UNKNOWN:
+ llapi_err(LLAPI_MSG_ERROR,
+ "error: %s: '%s' is UNKNOWN type %d",
+ __func__, dent->d_name, dent->d_type);
+ break;
+ case DT_DIR:
+ ret = llapi_semantic_traverse(path, size, d, sem_init,
+ sem_fini, data, dent);
+ if (ret < 0)
+ goto out;
+ break;
+ default:
+ ret = 0;
+ if (sem_init) {
+ ret = sem_init(path, d, NULL, data, dent);
+ if (ret < 0)
+ goto out;
+ }
+ if (sem_fini && ret == 0)
+ sem_fini(path, d, NULL, data, dent);
+ }
+ }
+
+out:
+ path[len] = 0;
+
+ if (sem_fini)
+ sem_fini(path, parent, d, data, de);
+err:
+ if (d)
+ closedir(d);
+ if (p)
+ closedir(p);
+ return ret;
+}
+
+static int param_callback(char *path, semantic_func_t sem_init,
+ semantic_func_t sem_fini, struct find_param *param)
+{
+ int ret, len = strlen(path);
+ char *buf;
+
+ if (len > PATH_MAX) {
+ llapi_err(LLAPI_MSG_ERROR, "Path name '%s' is too long", path);
+ return -EINVAL;
+ }
+
+ buf = (char *)malloc(PATH_MAX + 1);
+ if (!buf)
+ return -ENOMEM;
+
+ ret = common_param_init(param);
+ if (ret)
+ goto out;
+ param->depth = 0;
+
+ strncpy(buf, path, PATH_MAX + 1);
+ ret = llapi_semantic_traverse(buf, PATH_MAX + 1, NULL, sem_init,
+ sem_fini, param, NULL);
+out:
+ find_param_fini(param);
+ free(buf);
+ return ret < 0 ? ret : 0;
+}
+
int llapi_file_fget_lov_uuid(int fd, struct obd_uuid *lov_name)
{
int rc = ioctl(fd, OBD_IOC_GETNAME, lov_name);
*/
int llapi_uuid_match(char *real_uuid, char *search_uuid)
{
- int cmplen = strlen(real_uuid) - 5;
+ int cmplen = strlen(real_uuid);
+ int searchlen = strlen(search_uuid);
+
+ if (cmplen > 5 && strcmp(real_uuid + cmplen - 5, "_UUID") == 0)
+ cmplen -= 5;
+ if (searchlen > 5 && strcmp(search_uuid + searchlen - 5, "_UUID") == 0)
+ searchlen -= 5;
- if ((strlen(search_uuid) > cmplen) && isxdigit(search_uuid[cmplen])) {
- /* OST00000003 doesn't match OST0000 */
- llapi_err(LLAPI_MSG_ERROR, "Bad UUID format '%s'", search_uuid);
+ /* The UUIDs may legitimately be different lengths, if
+ * the system was upgraded from an older version. */
+ if (cmplen != searchlen)
return 0;
- }
return (strncmp(search_uuid, real_uuid, cmplen) == 0);
}
FILE *fp;
int rc = 0, index;
+ if (param->got_uuids)
+ return rc;
+
/* Get the lov name */
rc = llapi_file_fget_lov_uuid(dirfd(dir), &lov_uuid);
if (rc) {
fclose(fp);
- if (!param->quiet && param->obduuid &&
- (param->obdindex == OBD_NOT_FOUND)) {
+ if (param->obduuid && (param->obdindex == OBD_NOT_FOUND)) {
llapi_err_noerrno(LLAPI_MSG_ERROR,
"error: %s: unknown obduuid: %s",
- __FUNCTION__, param->obduuid->uuid);
+ __func__, param->obduuid->uuid);
rc = -EINVAL;
}
param->obdindexes[obdnum] = OBD_NOT_FOUND;
llapi_err_noerrno(LLAPI_MSG_ERROR,
"error: %s: unknown obduuid: %s",
- __FUNCTION__,
+ __func__,
param->obduuid[obdnum].uuid);
ret = -EINVAL;
}
return ret;
}
+static int cb_ostlist(char *path, DIR *parent, DIR *d, void *data,
+ struct dirent64 *de)
+{
+ struct find_param *param = (struct find_param *)data;
+
+ LASSERT(parent != NULL || d != NULL);
+
+ /* Prepare odb. */
+ return setup_obd_uuid(d ? d : parent, path, param);
+}
+
+int llapi_ostlist(char *path, struct find_param *param)
+{
+ return param_callback(path, cb_ostlist, cb_common_fini, param);
+}
+
static void lov_dump_user_lmm_header(struct lov_user_md *lum, char *path,
- int is_dir, int verbose, int quiet,
+ int is_dir, int verbose, int depth,
char *pool_name)
{
char *prefix = is_dir ? "" : "lmm_";
char nl = is_dir ? ' ' : '\n';
- if (verbose && path)
+ if (is_dir && lum->lmm_object_gr == LOV_OBJECT_GROUP_DEFAULT) {
+ lum->lmm_object_gr = LOV_OBJECT_GROUP_CLEAR;
+ if (verbose & VERBOSE_DETAIL)
+ llapi_printf(LLAPI_MSG_NORMAL, "(Default) ");
+ }
+
+ if (depth && path && ((verbose != VERBOSE_OBJID) || !is_dir))
llapi_printf(LLAPI_MSG_NORMAL, "%s\n", path);
if ((verbose & VERBOSE_DETAIL) && !is_dir) {
}
if (verbose & VERBOSE_COUNT) {
- if (!quiet)
+ if (verbose & ~VERBOSE_COUNT)
llapi_printf(LLAPI_MSG_NORMAL, "%sstripe_count: ",
prefix);
llapi_printf(LLAPI_MSG_NORMAL, "%hd%c",
}
if (verbose & VERBOSE_SIZE) {
- if (!quiet)
+ if (verbose & ~VERBOSE_SIZE)
llapi_printf(LLAPI_MSG_NORMAL, "%sstripe_size: ",
prefix);
llapi_printf(LLAPI_MSG_NORMAL, "%u%c", lum->lmm_stripe_size,
}
if (verbose & VERBOSE_OFFSET) {
- if (!quiet)
- llapi_printf(LLAPI_MSG_NORMAL, "%sstripe_offset: ",
+ if (verbose & ~VERBOSE_OFFSET)
+ llapi_printf(LLAPI_MSG_NORMAL, "%sstripe_offset: ",
prefix);
llapi_printf(LLAPI_MSG_NORMAL, "%u%c",
lum->lmm_objects[0].l_ost_idx, nl);
}
- if ((verbose & VERBOSE_POOL) && (pool_name != NULL))
- llapi_printf(LLAPI_MSG_NORMAL, "pool: %s%c", pool_name, nl);
+ if ((verbose & VERBOSE_POOL) && (pool_name != NULL)) {
+ llapi_printf(LLAPI_MSG_NORMAL, "pool: %s", pool_name);
+ is_dir = 1;
+ }
- if (is_dir)
+ if (is_dir && (verbose != VERBOSE_OBJID))
llapi_printf(LLAPI_MSG_NORMAL, "\n");
}
void lov_dump_user_lmm_v1v3(struct lov_user_md *lum, char *pool_name,
struct lov_user_ost_data_v1 *objects,
char *path, int is_dir,
- int obdindex, int quiet, int header, int body)
+ int obdindex, int depth, int header)
{
- int i, obdstripe = 0;
+ int i, obdstripe = (obdindex != OBD_NOT_FOUND) ? 0 : 1;
- if (obdindex != OBD_NOT_FOUND) {
+ if (!obdstripe) {
for (i = 0; !is_dir && i < lum->lmm_stripe_count; i++) {
if (obdindex == objects[i].l_ost_idx) {
- llapi_printf(LLAPI_MSG_NORMAL, "%s\n", path);
obdstripe = 1;
break;
}
}
- } else {
- if (!quiet)
- llapi_printf(LLAPI_MSG_NORMAL, "%s\n", path);
- obdstripe = 1;
}
- /* if it's a directory */
- if (is_dir) {
- if (obdstripe == 1) {
- if (lum->lmm_object_gr == LOV_OBJECT_GROUP_DEFAULT) {
- llapi_printf(LLAPI_MSG_NORMAL, "(Default) ");
- lum->lmm_object_gr = LOV_OBJECT_GROUP_CLEAR;
- }
- /* maintain original behavior */
- if (!header)
- header |= VERBOSE_ALL;
- lov_dump_user_lmm_header(lum, path, is_dir, header,
- quiet, pool_name);
- }
- return;
- }
-
- if (header && (obdstripe == 1))
- lov_dump_user_lmm_header(lum, NULL, is_dir, header, quiet,
+ if (obdstripe == 1)
+ lov_dump_user_lmm_header(lum, path, is_dir, header, depth,
pool_name);
- if (body) {
- if ((!quiet) && (obdstripe == 1))
+ if (!is_dir && (header & VERBOSE_OBJID)) {
+ if (obdstripe == 1)
llapi_printf(LLAPI_MSG_NORMAL,
"\tobdidx\t\t objid\t\tobjid\t\t group\n");
lov_dump_user_lmm_v1v3(¶m->lmd->lmd_lmm, NULL,
param->lmd->lmd_lmm.lmm_objects,
path, is_dir,
- param->obdindex, param->quiet,
- param->verbose,
- (param->verbose || !param->obduuid));
+ param->obdindex, param->maxdepth,
+ param->verbose);
break;
case LOV_USER_MAGIC_V3: {
char pool_name[LOV_MAXPOOLNAME + 1];
objects = lmmv3->lmm_objects;
lov_dump_user_lmm_v1v3(¶m->lmd->lmd_lmm, pool_name,
objects, path, is_dir,
- param->obdindex, param->quiet,
- param->verbose,
- (param->verbose || !param->obduuid));
+ param->obdindex, param->maxdepth,
+ param->verbose);
break;
}
default:
{
struct obd_ioctl_data data = { 0 };
char rawbuf[8192];
- char *buf = rawbuf;
- int rc;
-
- if (dirfd < 0 || name == NULL)
- return -EINVAL;
-
- data.ioc_version = OBD_IOCTL_VERSION;
- data.ioc_len = sizeof(data);
- data.ioc_inlbuf1 = (char *)name;
- data.ioc_inllen1 = strlen(name) + 1;
-
- rc = obd_ioctl_pack(&data, &buf, sizeof(rawbuf));
- if (rc) {
- llapi_err(LLAPI_MSG_ERROR,
- "error: IOC_MDC_LOOKUP pack failed for '%s': rc %d",
- name, rc);
- return rc;
- }
-
- return ioctl(dirfd, IOC_MDC_LOOKUP, buf);
-}
-
-int llapi_mds_getfileinfo(char *path, DIR *parent,
- struct lov_user_mds_data *lmd)
-{
- lstat_t *st = &lmd->lmd_st;
- char *fname = strrchr(path, '/');
- int ret = 0;
-
- if (parent == NULL)
- return -EINVAL;
-
- fname = (fname == NULL ? path : fname + 1);
- /* retrieve needed file info */
- strncpy((char *)lmd, fname,
- lov_mds_md_size(MAX_LOV_UUID_COUNT, LOV_MAGIC));
- ret = ioctl(dirfd(parent), IOC_MDC_GETFILEINFO, (void *)lmd);
-
- if (ret) {
- if (errno == ENOTTY) {
- /* ioctl is not supported, it is not a lustre fs.
- * Do the regular lstat(2) instead. */
- ret = lstat_f(path, st);
- if (ret) {
- llapi_err(LLAPI_MSG_ERROR,
- "error: %s: lstat failed for %s",
- __FUNCTION__, path);
- return ret;
- }
- } else if (errno == ENOENT) {
- llapi_err(LLAPI_MSG_WARN,
- "warning: %s: %s does not exist",
- __FUNCTION__, path);
- return -ENOENT;
- } else {
- llapi_err(LLAPI_MSG_ERROR,
- "error: %s: IOC_MDC_GETFILEINFO failed for %s",
- __FUNCTION__, path);
- return ret;
- }
- }
-
- return 0;
-}
-
-static DIR *opendir_parent(char *path)
-{
- DIR *parent;
- char *fname;
- char c;
-
- fname = strrchr(path, '/');
- if (fname == NULL)
- return opendir(".");
-
- c = fname[1];
- fname[1] = '\0';
- parent = opendir(path);
- fname[1] = c;
- return parent;
-}
-
-static int llapi_semantic_traverse(char *path, int size, DIR *parent,
- semantic_func_t sem_init,
- semantic_func_t sem_fini, void *data,
- cfs_dirent_t *de)
-{
- cfs_dirent_t *dent;
- int len, ret;
- DIR *d, *p = NULL;
-
- ret = 0;
- len = strlen(path);
-
- d = opendir(path);
- if (!d && errno != ENOTDIR) {
- llapi_err(LLAPI_MSG_ERROR, "%s: Failed to open '%s'",
- __FUNCTION__, path);
- return -EINVAL;
- } else if (!d && !parent) {
- /* ENOTDIR. Open the parent dir. */
- p = opendir_parent(path);
- if (!p)
- GOTO(out, ret = -EINVAL);
- }
-
- if (sem_init && (ret = sem_init(path, parent ?: p, d, data, de)))
- goto err;
-
- if (!d)
- GOTO(out, ret = 0);
-
- while ((dent = readdir64(d)) != NULL) {
- ((struct find_param *)data)->have_fileinfo = 0;
-
- if (!strcmp(dent->d_name, ".") || !strcmp(dent->d_name, ".."))
- continue;
-
- /* Don't traverse .lustre directory */
- if (!(strcmp(dent->d_name, dot_lustre_name)))
- continue;
-
- path[len] = 0;
- if ((len + dent->d_reclen + 2) > size) {
- llapi_err(LLAPI_MSG_ERROR,
- "error: %s: string buffer is too small",
- __FUNCTION__);
- break;
- }
- strcat(path, "/");
- strcat(path, dent->d_name);
+ char *buf = rawbuf;
+ int rc;
- if (dent->d_type == DT_UNKNOWN) {
- lstat_t *st = &((struct find_param *)data)->lmd->lmd_st;
+ if (dirfd < 0 || name == NULL)
+ return -EINVAL;
- ret = llapi_mds_getfileinfo(path, d,
- ((struct find_param *)data)->lmd);
- if (ret == 0) {
- ((struct find_param *)data)->have_fileinfo = 1;
- dent->d_type =
- llapi_filetype_dir_table[st->st_mode &
- S_IFMT];
- }
- if (ret == -ENOENT)
- continue;
- }
+ data.ioc_version = OBD_IOCTL_VERSION;
+ data.ioc_len = sizeof(data);
+ data.ioc_inlbuf1 = (char *)name;
+ data.ioc_inllen1 = strlen(name) + 1;
- switch (dent->d_type) {
- case DT_UNKNOWN:
- llapi_err(LLAPI_MSG_ERROR,
- "error: %s: '%s' is UNKNOWN type %d",
- __FUNCTION__, dent->d_name, dent->d_type);
- break;
- case DT_DIR:
- ret = llapi_semantic_traverse(path, size, d, sem_init,
- sem_fini, data, dent);
- if (ret < 0)
- goto out;
- break;
- default:
- ret = 0;
- if (sem_init) {
- ret = sem_init(path, d, NULL, data, dent);
- if (ret < 0)
- goto out;
- }
- if (sem_fini && ret == 0)
- sem_fini(path, d, NULL, data, dent);
- }
+ rc = obd_ioctl_pack(&data, &buf, sizeof(rawbuf));
+ if (rc) {
+ llapi_err(LLAPI_MSG_ERROR,
+ "error: IOC_MDC_LOOKUP pack failed for '%s': rc %d",
+ name, rc);
+ return rc;
}
-out:
- path[len] = 0;
-
- if (sem_fini)
- sem_fini(path, parent, d, data, de);
-err:
- if (d)
- closedir(d);
- if (p)
- closedir(p);
- return ret;
+ return ioctl(dirfd, IOC_MDC_LOOKUP, buf);
}
/* Check if the value matches 1 of the given criteria (e.g. --atime +/-N).
if (ret) {
llapi_err(LLAPI_MSG_ERROR,
"error: %s: lstat failed for %s",
- __FUNCTION__, path);
+ __func__, path);
return ret;
}
} else if (errno == ENOENT) {
llapi_err(LLAPI_MSG_WARN,
"warning: %s: %s does not exist",
- __FUNCTION__, path);
+ __func__, path);
goto decided;
} else {
llapi_err(LLAPI_MSG_ERROR,"error: %s: %s failed for %s",
- __FUNCTION__, dir ? "LL_IOC_MDC_GETINFO" :
+ __func__, dir ? "LL_IOC_MDC_GETINFO" :
"IOC_MDC_GETFILEINFO", path);
return ret;
}
i < param->lmd->lmd_lmm.lmm_stripe_count; i++) {
for (j = 0; j < param->num_obds; j++) {
if (param->obdindexes[j] ==
- lmm_objects[i].l_ost_idx)
+ lmm_objects[i].l_ost_idx) {
+ if (param->exclude_obd)
+ goto decided;
goto obd_matches;
+ }
}
}
- if (i == param->lmd->lmd_lmm.lmm_stripe_count)
+ if (i == param->lmd->lmd_lmm.lmm_stripe_count) {
+ if (param->exclude_obd)
+ goto obd_matches;
goto decided;
+ }
}
}
The regular stat is almost of the same speed as some new
'glimpse-size-ioctl'. */
if (!decision && S_ISREG(st->st_mode) &&
- (param->lmd->lmd_lmm.lmm_stripe_count || param->size)) {
+ param->lmd->lmd_lmm.lmm_stripe_count &&
+ (param->size ||param->atime || param->mtime || param->ctime)) {
if (param->obdindex != OBD_NOT_FOUND) {
/* Check whether the obd is active or not, if it is
* not active, just print the object affected by this
if (errno == ENOENT) {
llapi_err(LLAPI_MSG_ERROR,
"warning: %s: %s does not exist",
- __FUNCTION__, path);
+ __func__, path);
goto decided;
} else {
llapi_err(LLAPI_MSG_ERROR,
"%s: IOC_LOV_GETINFO on %s failed",
- __FUNCTION__, path);
+ __func__, path);
return ret;
}
}
return 0;
}
-static int cb_common_fini(char *path, DIR *parent, DIR *d, void *data,
- cfs_dirent_t *de)
+int llapi_find(char *path, struct find_param *param)
{
- struct find_param *param = (struct find_param *)data;
- param->depth--;
+ return param_callback(path, cb_find_init, cb_common_fini, param);
+}
+
+/*
+ * Get MDT number that the file/directory inode referenced
+ * by the open fd resides on.
+ * Return 0 and mdtidx on success, or -ve errno.
+ */
+int llapi_file_fget_mdtidx(int fd, int *mdtidx)
+{
+ if (ioctl(fd, LL_IOC_GET_MDTIDX, &mdtidx) < 0)
+ return -errno;
return 0;
}
-int llapi_find(char *path, struct find_param *param)
+static int cb_get_mdt_index(char *path, DIR *parent, DIR *d, void *data,
+ cfs_dirent_t *de)
{
- char *buf;
- int ret, len = strlen(path);
+ struct find_param *param = (struct find_param *)data;
+ int ret = 0;
+ int mdtidx;
- if (len > PATH_MAX) {
- llapi_err(LLAPI_MSG_ERROR, "%s: Path name '%s' is too long",
- __FUNCTION__, path);
- return -EINVAL;
- }
+ LASSERT(parent != NULL || d != NULL);
- buf = (char *)malloc(PATH_MAX + 1);
- if (!buf)
- return -ENOMEM;
+ if (d) {
+ ret = llapi_file_fget_mdtidx(dirfd(d), &mdtidx);
+ } else if (parent) {
+ int fd;
+
+ fd = open(path, O_RDONLY);
+ if (fd > 0) {
+ ret = llapi_file_fget_mdtidx(fd, &mdtidx);
+ close(fd);
+ } else {
+ ret = fd;
+ }
+ }
- ret = common_param_init(param);
if (ret) {
- free(buf);
+ if (errno == ENODATA) {
+ if (!param->obduuid)
+ llapi_printf(LLAPI_MSG_NORMAL,
+ "%s has no stripe info\n", path);
+ goto out;
+ } else if (errno == ENOTTY) {
+ llapi_err(LLAPI_MSG_ERROR,
+ "%s: '%s' not on a Lustre fs?",
+ __func__, path);
+ } else if (errno == ENOENT) {
+ llapi_err(LLAPI_MSG_WARN,
+ "warning: %s: %s does not exist",
+ __func__, path);
+ goto out;
+ } else {
+ llapi_err(LLAPI_MSG_ERROR,
+ "error: %s: LL_IOC_GET_MDTIDX failed for %s",
+ __func__, path);
+ }
return ret;
}
- param->depth = 0;
+ if (param->quiet)
+ llapi_printf(LLAPI_MSG_NORMAL, "%d\n", mdtidx);
+ else
+ llapi_printf(LLAPI_MSG_NORMAL, "%s MDT index: %d\n",
+ path, mdtidx);
- strncpy(buf, path, PATH_MAX + 1);
- ret = llapi_semantic_traverse(buf, PATH_MAX + 1, NULL, cb_find_init,
- cb_common_fini, param, NULL);
+out:
+ /* Do not get down anymore? */
+ if (param->depth == param->maxdepth)
+ return 1;
- find_param_fini(param);
- free(buf);
- return ret < 0 ? ret : 0;
+ param->depth++;
+ return 0;
}
static int cb_getstripe(char *path, DIR *parent, DIR *d, void *data,
LASSERT(parent != NULL || d != NULL);
- /* Prepare odb. */
- if (!param->got_uuids) {
+ if (param->obduuid) {
+ param->quiet = 1;
ret = setup_obd_uuid(d ? d : parent, path, param);
if (ret)
return ret;
fname = (fname == NULL ? path : fname + 1);
strncpy((char *)¶m->lmd->lmd_lmm, fname, param->lumlen);
+
ret = ioctl(dirfd(parent), IOC_MDC_GETFILESTRIPE,
(void *)¶m->lmd->lmd_lmm);
}
if (ret) {
if (errno == ENODATA) {
- if (!param->obduuid && !param->quiet)
+ if (!param->obduuid)
llapi_printf(LLAPI_MSG_NORMAL,
"%s has no stripe info\n", path);
goto out;
} else if (errno == ENOTTY) {
llapi_err(LLAPI_MSG_ERROR,
"%s: '%s' not on a Lustre fs?",
- __FUNCTION__, path);
+ __func__, path);
} else if (errno == ENOENT) {
llapi_err(LLAPI_MSG_WARN,
"warning: %s: %s does not exist",
- __FUNCTION__, path);
+ __func__, path);
goto out;
} else {
llapi_err(LLAPI_MSG_ERROR,
"error: %s: %s failed for %s",
- __FUNCTION__, d ? "LL_IOC_LOV_GETSTRIPE" :
+ __func__, d ? "LL_IOC_LOV_GETSTRIPE" :
"IOC_MDC_GETFILESTRIPE", path);
}
return ret;
}
- llapi_lov_dump_user_lmm(param, path, d ? 1 : 0);
+ if (!param->get_mdt_index)
+ llapi_lov_dump_user_lmm(param, path, d ? 1 : 0);
+
out:
/* Do not get down anymore? */
if (param->depth == param->maxdepth)
int llapi_getstripe(char *path, struct find_param *param)
{
- char *buf;
- int ret = 0, len = strlen(path);
-
- if (len > PATH_MAX) {
- llapi_err(LLAPI_MSG_ERROR,
- "%s: Path name '%s' is too long",
- __FUNCTION__, path);
- return -EINVAL;
- }
-
- buf = (char *)malloc(PATH_MAX + 1);
- if (!buf)
- return -ENOMEM;
-
- ret = common_param_init(param);
- if (ret) {
- free(buf);
- return ret;
- }
-
- param->depth = 0;
-
- strncpy(buf, path, PATH_MAX + 1);
- ret = llapi_semantic_traverse(buf, PATH_MAX + 1, NULL, cb_getstripe,
- cb_common_fini, param, NULL);
- find_param_fini(param);
- free(buf);
- return ret < 0 ? ret : 0;
+ return param_callback(path, param->get_mdt_index ?
+ cb_get_mdt_index : cb_getstripe,
+ cb_common_fini, param);
}
int llapi_obd_statfs(char *path, __u32 type, __u32 index,
if (fd < 0) {
rc = errno ? -errno : -EBADF;
llapi_err(LLAPI_MSG_ERROR, "error: %s: opening '%s'",
- __FUNCTION__, path);
+ __func__, path);
return rc;
}
rc = ioctl(fd, IOC_OBD_STATFS, (void *)rawbuf);
} else if (errno == ENOENT) {
llapi_err(LLAPI_MSG_ERROR,
"warning: %s: %s does not exist",
- __FUNCTION__, path);
+ __func__, path);
rc = 0;
} else if (errno != EISDIR) {
rc = errno;
int llapi_quotachown(char *path, int flag)
{
struct find_param param;
- char *buf;
- int ret = 0, len = strlen(path);
-
- if (len > PATH_MAX) {
- llapi_err(LLAPI_MSG_ERROR, "%s: Path name '%s' is too long",
- __FUNCTION__, path);
- return -EINVAL;
- }
-
- buf = (char *)malloc(PATH_MAX + 1);
- if (!buf)
- return -ENOMEM;
memset(¶m, 0, sizeof(param));
param.recursive = 1;
param.verbose = 0;
param.quiet = 1;
- ret = common_param_init(¶m);
- if (ret)
- goto out;
-
- strncpy(buf, path, PATH_MAX + 1);
- ret = llapi_semantic_traverse(buf, PATH_MAX + 1, NULL, cb_quotachown,
- NULL, ¶m, NULL);
-out:
- find_param_fini(¶m);
- free(buf);
- return ret;
+ return param_callback(path, cb_quotachown, NULL, ¶m);
}
#include <pwd.h>
/* Print mdtname 'name' into 'buf' using 'format'. Add -MDT0000 if needed.
* format must have %s%s, buf must be > 16
+ * Eg: if name = "lustre-MDT0000", "lustre", or "lustre-MDT0000_UUID"
+ * then buf = "lustre-MDT0000"
*/
static int get_mdtname(char *name, char *format, char *buf)
{
return sprintf(buf, format, name, suffix);
}
+/** ioctl on filsystem root, with mdtindex sent as data
+ * \param mdtname path, fsname, or mdtname (lutre-MDT0004)
+ * \param mdtidxp pointer to integer within data to be filled in with the
+ * mdt index (0 if no mdt is specified). NULL won't be filled.
+ */
+static int root_ioctl(const char *mdtname, int opc, void *data, int *mdtidxp,
+ int want_error)
+{
+ char fsname[20];
+ char *ptr;
+ int fd, index, rc;
+
+ /* Take path, fsname, or MDTname. Assume MDT0000 in the former cases.
+ Open root and parse mdt index. */
+ if (mdtname[0] == '/') {
+ index = 0;
+ rc = get_root_path(WANT_FD | want_error, NULL, &fd,
+ (char *)mdtname, -1);
+ } else {
+ if (get_mdtname((char *)mdtname, "%s%s", fsname) < 0)
+ return -EINVAL;
+ ptr = fsname + strlen(fsname) - 8;
+ *ptr = '\0';
+ index = strtol(ptr + 4, NULL, 10);
+ rc = get_root_path(WANT_FD | want_error, fsname, &fd, NULL, -1);
+ }
+ if (rc < 0) {
+ if (want_error)
+ llapi_err(LLAPI_MSG_ERROR | LLAPI_MSG_NO_ERRNO,
+ "Can't open %s: %d\n", mdtname, rc);
+ return rc;
+ }
+
+ if (mdtidxp)
+ *mdtidxp = index;
+
+ rc = ioctl(fd, opc, data);
+ if (rc && want_error)
+ llapi_err(LLAPI_MSG_ERROR, "ioctl %d err %d", opc, rc);
+
+ close(fd);
+ return rc;
+}
+
/****** Changelog API ********/
+
+static int changelog_ioctl(const char *mdtname, int opc, int id,
+ long long recno, int flags)
+{
+ struct ioc_changelog data;
+ int *idx;
+
+ data.icc_id = id;
+ data.icc_recno = recno;
+ data.icc_flags = flags;
+ idx = (int *)(&data.icc_mdtindex);
+
+ return root_ioctl(mdtname, opc, &data, idx, WANT_ERROR);
+}
+
#define CHANGELOG_PRIV_MAGIC 0xCA8E1080
struct changelog_private {
int magic;
int flags;
- lustre_netlink lnl;
+ lustre_kernelcomm kuc;
+ char *buf;
};
/** Start reading from a changelog
long long startrec)
{
struct changelog_private *cp;
- struct changelog_show cs = {};
- char mdtname[20];
- char pattern[PATH_MAX];
- char trigger[PATH_MAX];
- int fd, rc, pid;
-
- /* Find mdtname from path, fsname, mdtname, or mdtname_UUID */
- if (device[0] == '/') {
- if ((rc = llapi_search_fsname(device, mdtname)))
- return rc;
- if ((rc = get_mdtname(mdtname, "%s%s", mdtname)) < 0)
- return rc;
- } else {
- if ((rc = get_mdtname((char *)device, "%s%s", mdtname)) < 0)
- return rc;
- }
-
- /* Find corresponding mdc trigger */
- snprintf(pattern, PATH_MAX,
- "/proc/fs/lustre/mdc/%s-*/changelog_trigger", mdtname);
- rc = first_match(pattern, trigger);
- if (rc)
- return rc;
-
- /* Make sure we can write the trigger */
- fd = open(trigger, O_WRONLY);
- if (fd < 0)
- return -errno;
+ int rc;
/* Set up the receiver control struct */
cp = malloc(sizeof(*cp));
- if (cp == NULL) {
- close(fd);
+ if (cp == NULL)
return -ENOMEM;
+
+ cp->buf = malloc(CR_MAXSIZE);
+ if (cp->buf == NULL) {
+ rc = -ENOMEM;
+ goto out_free;
}
cp->magic = CHANGELOG_PRIV_MAGIC;
cp->flags = flags;
- /* Start the receiver */
- rc = libcfs_ulnl_start(&cp->lnl, 0 /* unicast */);
+
+ /* Set up the receiver */
+ rc = libcfs_ukuc_start(&cp->kuc, 0 /* no group registration */);
if (rc < 0)
goto out_free;
- /* We need to trigger Lustre to start sending messages now.
- We could send a lnl message to a kernel listener,
- or write into proc. Proc has the advantage of running in this
- context, avoiding the need for a kernel thread. */
- cs.cs_pid = getpid();
- cs.cs_startrec = startrec;
- cs.cs_flags = flags & CHANGELOG_FLAG_BLOCK ? LNL_FL_BLOCK : 0;
- if ((pid = fork()) < 0) {
- goto out_free;
- } else if (!pid) {
- /* Write triggers Lustre to start sending, but it
- won't return until it is complete, meaning everything
- got shipped through lnl (or error). So we trigger it
- from a child process here, allowing the llapi call to
- return and wait for the lnl messages. */
- rc = write(fd, &cs, sizeof(cs));
- exit(rc);
+ *priv = cp;
+
+ /* Tell the kernel to start sending */
+ rc = changelog_ioctl(device, OBD_IOC_CHANGELOG_SEND, cp->kuc.lk_wfd,
+ startrec, flags);
+ /* Only the kernel reference keeps the write side open */
+ close(cp->kuc.lk_wfd);
+ cp->kuc.lk_wfd = 0;
+ if (rc < 0) {
+ /* frees and clears priv */
+ llapi_changelog_fini(priv);
+ return rc;
}
- close(fd);
- *priv = cp;
return 0;
out_free:
+ if (cp->buf)
+ free(cp->buf);
free(cp);
- close(fd);
return rc;
}
if (!cp || (cp->magic != CHANGELOG_PRIV_MAGIC))
return -EINVAL;
- libcfs_ulnl_stop(&cp->lnl);
+ libcfs_ukuc_stop(&cp->kuc);
+ free(cp->buf);
free(cp);
*priv = NULL;
return 0;
int llapi_changelog_recv(void *priv, struct changelog_rec **rech)
{
struct changelog_private *cp = (struct changelog_private *)priv;
- struct lnl_hdr *lnlh;
+ struct kuc_hdr *kuch;
int rc = 0;
if (!cp || (cp->magic != CHANGELOG_PRIV_MAGIC))
return -EINVAL;
repeat:
- rc = libcfs_ulnl_msg_get(&cp->lnl, CR_MAXSIZE, LNL_TRANSPORT_CHANGELOG,
- &lnlh);
+ rc = libcfs_ukuc_msg_get(&cp->kuc, cp->buf, CR_MAXSIZE,
+ KUC_TRANSPORT_CHANGELOG);
if (rc < 0)
return rc;
- if ((lnlh->lnl_transport != LNL_TRANSPORT_CHANGELOG) ||
- ((lnlh->lnl_msgtype != CL_RECORD) &&
- (lnlh->lnl_msgtype != CL_EOF))) {
+ kuch = (struct kuc_hdr *)cp->buf;
+ if ((kuch->kuc_transport != KUC_TRANSPORT_CHANGELOG) ||
+ ((kuch->kuc_msgtype != CL_RECORD) &&
+ (kuch->kuc_msgtype != CL_EOF))) {
llapi_err(LLAPI_MSG_ERROR | LLAPI_MSG_NO_ERRNO,
"Unknown changelog message type %d:%d\n",
- lnlh->lnl_transport, lnlh->lnl_msgtype);
+ kuch->kuc_transport, kuch->kuc_msgtype);
rc = -EPROTO;
goto out_free;
}
- if (lnlh->lnl_msgtype == CL_EOF) {
+ if (kuch->kuc_msgtype == CL_EOF) {
if (cp->flags & CHANGELOG_FLAG_FOLLOW) {
/* Ignore EOFs */
goto repeat;
}
/* Our message is a changelog_rec */
- *rech = (struct changelog_rec *)(lnlh + 1);
+ *rech = (struct changelog_rec *)(kuch + 1);
return 0;
out_free:
- libcfs_ulnl_msg_free(&lnlh);
*rech = NULL;
return rc;
}
/** Release the changelog record when done with it. */
int llapi_changelog_free(struct changelog_rec **rech)
{
- if (*rech) {
- struct lnl_hdr *lnlh = (struct lnl_hdr *)*rech - 1;
- libcfs_ulnl_msg_free(&lnlh);
- }
*rech = NULL;
return 0;
}
int llapi_changelog_clear(const char *mdtname, const char *idstr,
long long endrec)
{
- struct ioc_changelog_clear data;
- char fsname[17];
- char *ptr;
- int id, fd, index, rc;
+ int id;
if (endrec < 0) {
llapi_err(LLAPI_MSG_ERROR | LLAPI_MSG_NO_ERRNO,
return -EINVAL;
}
- /* Take path, fsname, or MDTNAME. Assume MDT0000 in the former cases */
- if (mdtname[0] == '/') {
- index = 0;
- fd = open(mdtname, O_RDONLY | O_DIRECTORY | O_NONBLOCK);
- rc = fd < 0 ? -errno : 0;
- } else {
- if (get_mdtname((char *)mdtname, "%s%s", fsname) < 0)
- return -EINVAL;
- ptr = fsname + strlen(fsname) - 8;
- *ptr = '\0';
- index = strtol(ptr + 4, NULL, 10);
- rc = get_root_path(WANT_FD | WANT_ERROR, fsname, &fd, NULL, -1);
- }
- if (rc < 0) {
- llapi_err(LLAPI_MSG_ERROR | LLAPI_MSG_NO_ERRNO,
- "Can't open %s: %d\n", mdtname, rc);
- return rc;
- }
-
- data.icc_mdtindex = index;
- data.icc_id = id;
- data.icc_recno = endrec;
- rc = ioctl(fd, OBD_IOC_CHANGELOG_CLEAR, &data);
- if (rc)
- llapi_err(LLAPI_MSG_ERROR, "ioctl err %d", rc);
-
- close(fd);
- return rc;
+ return changelog_ioctl(mdtname, OBD_IOC_CHANGELOG_CLEAR, id, endrec, 0);
}
int llapi_fid2path(const char *device, const char *fidstr, char *buf,
#define CT_PRIV_MAGIC 0xC0BE2001
struct copytool_private {
int magic;
- lustre_netlink lnl;
- int archive_num_count;
- int archive_nums[0];
+ char *buf;
+ char *fsname;
+ lustre_kernelcomm kuc;
+ __u32 archives;
};
#include <libcfs/libcfs.h>
/** Register a copytool
- * @param priv Opaque private control structure
+ * @param[out] priv Opaque private control structure
+ * @param fsname Lustre filesystem
* @param flags Open flags, currently unused (e.g. O_NONBLOCK)
- * @param archive_num_count
- * @param archive_nums Which archive numbers this copytool is responsible for
+ * @param archive_count
+ * @param archives Which archive numbers this copytool is responsible for
*/
-int llapi_copytool_start(void **priv, int flags, int archive_num_count,
- int *archive_nums)
+int llapi_copytool_start(void **priv, char *fsname, int flags,
+ int archive_count, int *archives)
{
struct copytool_private *ct;
int rc;
- if (archive_num_count > 0 && archive_nums == NULL) {
+ if (archive_count > 0 && archives == NULL) {
llapi_err(LLAPI_MSG_ERROR | LLAPI_MSG_NO_ERRNO,
"NULL archive numbers");
return -EINVAL;
}
- ct = malloc(sizeof(*ct) +
- archive_num_count * sizeof(ct->archive_nums[0]));
+ ct = malloc(sizeof(*ct));
if (ct == NULL)
return -ENOMEM;
+ ct->buf = malloc(HAL_MAXSIZE);
+ ct->fsname = malloc(strlen(fsname) + 1);
+ if (ct->buf == NULL || ct->fsname == NULL) {
+ rc = -ENOMEM;
+ goto out_err;
+ }
+ strcpy(ct->fsname, fsname);
ct->magic = CT_PRIV_MAGIC;
- ct->archive_num_count = archive_num_count;
- if (ct->archive_num_count > 0)
- memcpy(ct->archive_nums, archive_nums, archive_num_count *
- sizeof(ct->archive_nums[0]));
+ ct->archives = 0;
+ for (rc = 0; rc < archive_count; rc++) {
+ if (archives[rc] > sizeof(ct->archives)) {
+ llapi_err(LLAPI_MSG_ERROR | LLAPI_MSG_NO_ERRNO,
+ "Maximum of %d archives supported",
+ sizeof(ct->archives));
+ goto out_err;
+ }
+ ct->archives |= 1 << archives[rc];
+ }
+ /* special case: if no archives specified, default to archive #0. */
+ if (ct->archives == 0)
+ ct->archives = 1;
- rc = libcfs_ulnl_start(&ct->lnl, LNL_GRP_HSM);
+ rc = libcfs_ukuc_start(&ct->kuc, KUC_GRP_HSM);
+ if (rc < 0)
+ goto out_err;
+
+ /* Storing archive(s) in lk_data; see mdc_ioc_hsm_ct_start */
+ ct->kuc.lk_data = ct->archives;
+ rc = root_ioctl(ct->fsname, LL_IOC_HSM_CT_START, &(ct->kuc), NULL,
+ WANT_ERROR);
+ /* Only the kernel reference keeps the write side open */
+ close(ct->kuc.lk_wfd);
+ ct->kuc.lk_wfd = 0;
if (rc < 0)
goto out_err;
return 0;
out_err:
+ if (ct->buf)
+ free(ct->buf);
+ if (ct->fsname)
+ free(ct->fsname);
free(ct);
return rc;
}
if (!ct || (ct->magic != CT_PRIV_MAGIC))
return -EINVAL;
- libcfs_ulnl_stop(&ct->lnl);
+ /* Tell the kernel to stop sending us messages */
+ ct->kuc.lk_flags = LK_FLG_STOP;
+ root_ioctl(ct->fsname, LL_IOC_HSM_CT_START, &(ct->kuc), NULL, 0);
+
+ /* Shut down the kernelcomms */
+ libcfs_ukuc_stop(&ct->kuc);
+
+ free(ct->buf);
+ free(ct->fsname);
free(ct);
*priv = NULL;
return 0;
int llapi_copytool_recv(void *priv, struct hsm_action_list **halh, int *msgsize)
{
struct copytool_private *ct = (struct copytool_private *)priv;
- struct lnl_hdr *lnlh;
+ struct kuc_hdr *kuch;
struct hsm_action_list *hal;
int rc = 0;
if (halh == NULL || msgsize == NULL)
return -EINVAL;
- rc = libcfs_ulnl_msg_get(&ct->lnl, HAL_MAXSIZE,
- LNL_TRANSPORT_HSM, &lnlh);
+ rc = libcfs_ukuc_msg_get(&ct->kuc, ct->buf, HAL_MAXSIZE,
+ KUC_TRANSPORT_HSM);
if (rc < 0)
return rc;
/* Handle generic messages */
- if (lnlh->lnl_transport == LNL_TRANSPORT_GENERIC &&
- lnlh->lnl_msgtype == LNL_MSG_SHUTDOWN) {
+ kuch = (struct kuc_hdr *)ct->buf;
+ if (kuch->kuc_transport == KUC_TRANSPORT_GENERIC &&
+ kuch->kuc_msgtype == KUC_MSG_SHUTDOWN) {
rc = -ESHUTDOWN;
goto out_free;
}
- if (lnlh->lnl_transport != LNL_TRANSPORT_HSM ||
- lnlh->lnl_msgtype != HMT_ACTION_LIST) {
+ if (kuch->kuc_transport != KUC_TRANSPORT_HSM ||
+ kuch->kuc_msgtype != HMT_ACTION_LIST) {
llapi_err(LLAPI_MSG_ERROR | LLAPI_MSG_NO_ERRNO,
"Unknown HSM message type %d:%d\n",
- lnlh->lnl_transport, lnlh->lnl_msgtype);
+ kuch->kuc_transport, kuch->kuc_msgtype);
rc = -EPROTO;
goto out_free;
}
/* Our message is an hsm_action_list */
- hal = (struct hsm_action_list *)(lnlh + 1);
+ hal = (struct hsm_action_list *)(kuch + 1);
/* Check that we have registered for this archive # */
- for (rc = 0; rc < ct->archive_num_count; rc++) {
- if (hal->hal_archive_num == ct->archive_nums[rc])
- break;
- }
- if (rc >= ct->archive_num_count) {
- CDEBUG(D_INFO, "This copytool does not service archive #%d, "
- "ignoring this request.\n", hal->hal_archive_num);
+ if (((1 << hal->hal_archive_num) & ct->archives) == 0) {
+ llapi_err(LLAPI_MSG_INFO | LLAPI_MSG_NO_ERRNO,
+ "Ignoring request for archive #%d (bitmask %#x)\n",
+ hal->hal_archive_num, ct->archives);
rc = 0;
goto out_free;
}
*halh = hal;
- *msgsize = lnlh->lnl_msglen - sizeof(*lnlh);
+ *msgsize = kuch->kuc_msglen - sizeof(*kuch);
return 0;
out_free:
- libcfs_ulnl_msg_free(&lnlh);
*halh = NULL;
*msgsize = 0;
return rc;
/** Release the action list when done with it. */
int llapi_copytool_free(struct hsm_action_list **hal)
{
- if (*hal) {
- struct lnl_hdr *lnlh = (struct lnl_hdr *)*hal - 1;
- libcfs_ulnl_msg_free(&lnlh);
- }
*hal = NULL;
return 0;
}