#define _GNU_SOURCE
#endif
+#include <ctype.h>
#include <mntent.h>
#include <stdlib.h>
#include <stdio.h>
char *fsname;
char *ptr;
DIR *dir;
- struct dirent pool;
- struct dirent *cookie = NULL;
+ struct dirent *pool;
int rc = 0;
unsigned int nb_entries = 0;
unsigned int used = 0;
goto free_path;
}
- while(1) {
- rc = readdir_r(dir, &pool, &cookie);
- if (rc != 0) {
+ do {
+ errno = 0;
+ pool = readdir(dir);
+ if (pool == NULL) {
rc = -errno;
- llapi_error(LLAPI_MSG_ERROR, rc,
- "Error reading pool list for '%s'", name);
- goto free_path;
- } else if ((rc == 0) && (cookie == NULL)) {
- /* end of directory */
- break;
+ goto free_dir;
}
/* ignore . and .. */
- if (!strcmp(pool.d_name, ".") || !strcmp(pool.d_name, ".."))
+ if (!strcmp(pool->d_name, ".") || !strcmp(pool->d_name, ".."))
continue;
/* check output bounds */
}
/* +2 for '.' and final '\0' */
- if (used + strlen(pool.d_name) + strlen(fsname) + 2
+ if (used + strlen(pool->d_name) + strlen(fsname) + 2
> buffer_size) {
rc = -EOVERFLOW;
goto free_dir;
}
- sprintf(buffer + used, "%s.%s", fsname, pool.d_name);
+ sprintf(buffer + used, "%s.%s", fsname, pool->d_name);
poollist[nb_entries] = buffer + used;
- used += strlen(pool.d_name) + strlen(fsname) + 2;
+ used += strlen(pool->d_name) + strlen(fsname) + 2;
nb_entries++;
- }
+ } while (1);
free_dir:
+ if (rc)
+ llapi_error(LLAPI_MSG_ERROR, rc,
+ "Error reading pool list for '%s'", name);
closedir(dir);
free_path:
cfs_free_param_data(&pathname);
LDF_IS_RAW = 0x0002,
LDF_INDENT = 0x0004,
LDF_SKIP_OBJS = 0x0008,
+ LDF_YAML = 0x0010,
};
static void lov_dump_user_lmm_header(struct lov_user_md *lum, char *path,
bool is_dir = flags & LDF_IS_DIR;
bool is_raw = flags & LDF_IS_RAW;
bool indent = flags & LDF_INDENT;
+ bool yaml = flags & LDF_YAML;
bool skip_objs = flags & LDF_SKIP_OBJS;
char *prefix = is_dir ? "" : "lmm_";
char *separator = "";
llapi_printf(LLAPI_MSG_NORMAL, "%s(Default) ", space);
}
- if (!indent && depth && path && ((verbose != VERBOSE_OBJID) || !is_dir))
+ if (!yaml && !indent && depth && path &&
+ ((verbose != VERBOSE_OBJID) || !is_dir))
llapi_printf(LLAPI_MSG_NORMAL, "%s\n", path);
if ((verbose & VERBOSE_DETAIL) && !is_dir) {
(uintmax_t)lmm_oi_id(&lum->lmm_oi));
}
if ((verbose & (VERBOSE_DETAIL | VERBOSE_DFID)) && !is_dir) {
+ __u64 seq;
+ __u32 oid;
+ __u32 ver;
+
if (verbose & ~VERBOSE_DFID)
llapi_printf(LLAPI_MSG_NORMAL, "%slmm_fid: ",
space);
* separate lmm_oi_seq() and lmm_oi_id() routines for this.
*
* For newer layout types hopefully this will be a real FID. */
- llapi_printf(LLAPI_MSG_NORMAL, DFID"\n",
- lmm_oi_seq(&lum->lmm_oi) == 0 ?
- lmm_oi_id(&lum->lmm_oi) :
- lmm_oi_seq(&lum->lmm_oi),
- lmm_oi_seq(&lum->lmm_oi) == 0 ?
- 0 : (__u32)lmm_oi_id(&lum->lmm_oi),
- (__u32)(lmm_oi_id(&lum->lmm_oi) >> 32));
+ seq = lmm_oi_seq(&lum->lmm_oi) == 0 ?
+ lmm_oi_id(&lum->lmm_oi) : lmm_oi_seq(&lum->lmm_oi);
+ oid = lmm_oi_seq(&lum->lmm_oi) == 0 ?
+ 0 : (__u32)lmm_oi_id(&lum->lmm_oi);
+ ver = (__u32)(lmm_oi_id(&lum->lmm_oi) >> 32);
+ if (yaml)
+ llapi_printf(LLAPI_MSG_NORMAL, DFID_NOBRACE"\n",
+ seq, oid, ver);
+ else
+ llapi_printf(LLAPI_MSG_NORMAL, DFID"\n",
+ seq, oid, ver);
}
if (verbose & VERBOSE_COUNT) {
llapi_printf(LLAPI_MSG_NORMAL, "%hd",
(__s16)lum->lmm_stripe_count);
}
- separator = is_dir ? " " : "\n";
+ if (!yaml && is_dir)
+ separator = " ";
+ else
+ separator = "\n";
}
if (verbose & VERBOSE_SIZE) {
llapi_printf(LLAPI_MSG_NORMAL, "%u",
lum->lmm_stripe_size);
}
- separator = is_dir ? " " : "\n";
+ if (!yaml && is_dir)
+ separator = " ";
+ else
+ separator = "\n";
}
if ((verbose & VERBOSE_LAYOUT) && !is_dir) {
else
llapi_printf(LLAPI_MSG_NORMAL, "%u",
objects[0].l_ost_idx);
- separator = is_dir ? " " : "\n";
+ if (!yaml && is_dir)
+ separator = " ";
+ else
+ separator = "\n";
}
if ((verbose & VERBOSE_POOL) && pool_name && (pool_name[0] != '\0')) {
llapi_printf(LLAPI_MSG_NORMAL, "%s%spool: ",
space, prefix);
llapi_printf(LLAPI_MSG_NORMAL, "%s", pool_name);
- separator = is_dir ? " " : "\n";
+ if (!yaml && is_dir)
+ separator = " ";
+ else
+ separator = "\n";
}
if (strlen(separator) != 0)
bool is_dir = flags & LDF_IS_DIR;
bool indent = flags & LDF_INDENT;
bool skip_objs = flags & LDF_SKIP_OBJS;
+ bool yaml = flags & LDF_YAML;
int i, obdstripe = (obdindex != OBD_NOT_FOUND) ? 0 : 1;
if (!obdstripe) {
if (indent)
llapi_printf(LLAPI_MSG_NORMAL,
"%6slmm_objects:\n", " ");
+ else if (yaml)
+ llapi_printf(LLAPI_MSG_NORMAL, "lmm_objects:\n");
else
llapi_printf(LLAPI_MSG_NORMAL,
"\tobdidx\t\t objid\t\t objid\t\t group\n");
if (obdindex != OBD_NOT_FOUND && obdindex != idx)
continue;
- if (indent) {
+ if (yaml) {
+ struct lu_fid fid = { 0 };
+
+ ostid_to_fid(&fid, &objects[i].l_ost_oi, idx);
+ llapi_printf(LLAPI_MSG_NORMAL,
+ "%sl_ost_idx: %d\n", space, idx);
+ llapi_printf(LLAPI_MSG_NORMAL,
+ "%8sl_fid: "DFID_NOBRACE"\n",
+ " ", PFID(&fid));
+ } else if (indent) {
struct lu_fid fid = { 0 };
ostid_to_fid(&fid, &objects[i].l_ost_oi, idx);
}
void lmv_dump_user_lmm(struct lmv_user_md *lum, char *pool_name,
- char *path, int obdindex, int depth, int verbose)
+ char *path, int obdindex, int depth, int verbose,
+ enum lov_dump_flags flags)
{
struct lmv_user_mds_data *objects = lum->lum_objects;
char *prefix = lum->lum_magic == LMV_USER_MAGIC ? "(Default)" : "";
int i, obdstripe = 0;
char *separator = "";
+ bool yaml = flags & LDF_YAML;
if (obdindex != OBD_NOT_FOUND) {
if (lum->lum_stripe_count == 0) {
llapi_printf(LLAPI_MSG_NORMAL, "lmv_stripe_count: ");
llapi_printf(LLAPI_MSG_NORMAL, "%u",
(int)lum->lum_stripe_count);
- if (verbose & VERBOSE_OFFSET)
+ if ((verbose & VERBOSE_OFFSET) && !yaml)
separator = " ";
else
separator = "\n";
llapi_printf(LLAPI_MSG_NORMAL, "lmv_stripe_offset: ");
llapi_printf(LLAPI_MSG_NORMAL, "%d",
(int)lum->lum_stripe_offset);
- if (verbose & VERBOSE_HASH_TYPE)
+ if (verbose & VERBOSE_HASH_TYPE && !yaml)
separator = " ";
else
separator = "\n";
struct lov_comp_md_v1 *comp_v1 = (void *)¶m->fp_lmd->lmd_lmm;
int depth = param->fp_max_depth;
int verbose = param->fp_verbose;
+ bool yaml = flags & LDF_YAML;
if (depth && path && ((verbose != VERBOSE_OBJID) ||
- !(flags & LDF_IS_DIR)))
+ !(flags & LDF_IS_DIR)) && !yaml)
llapi_printf(LLAPI_MSG_NORMAL, "%s\n", path);
if (verbose & VERBOSE_DETAIL) {
llapi_printf(LLAPI_MSG_NORMAL, "%2slcm_entry_count: ",
" ");
llapi_printf(LLAPI_MSG_NORMAL, "%u\n",
- comp_v1->lcm_entry_count);
+ comp_v1->lcm_magic == LOV_USER_MAGIC_COMP_V1 ?
+ comp_v1->lcm_entry_count : 0);
}
- if (verbose & VERBOSE_DETAIL)
+ if (verbose & VERBOSE_DETAIL && !yaml)
llapi_printf(LLAPI_MSG_NORMAL, "components:\n");
}
+static void comp_flags2str(__u32 comp_flags)
+{
+ bool found = false;
+ int i = 0;
+
+ if (!comp_flags) {
+ llapi_printf(LLAPI_MSG_NORMAL, "0");
+ return;
+ }
+ for (i = 0; i < ARRAY_SIZE(comp_flags_table); i++) {
+ if (comp_flags & comp_flags_table[i].cfn_flag) {
+ if (found)
+ llapi_printf(LLAPI_MSG_NORMAL, ",");
+ llapi_printf(LLAPI_MSG_NORMAL, "%s",
+ comp_flags_table[i].cfn_name);
+ comp_flags &= ~comp_flags_table[i].cfn_flag;
+ found = true;
+ }
+ }
+ if (comp_flags) {
+ if (found)
+ llapi_printf(LLAPI_MSG_NORMAL, ",");
+ llapi_printf(LLAPI_MSG_NORMAL, "%#x", comp_flags);
+ }
+}
+
static void lov_dump_comp_v1_entry(struct find_param *param,
enum lov_dump_flags flags, int index)
{
struct lov_comp_md_entry_v1 *entry;
char *separator = "";
int verbose = param->fp_verbose;
+ bool yaml = flags & LDF_YAML;
entry = &comp_v1->lcm_entries[index];
+ if (yaml)
+ llapi_printf(LLAPI_MSG_NORMAL, "%2scomponent%d:\n", " ", index);
+
if (verbose & VERBOSE_COMP_ID) {
- if (verbose & VERBOSE_DETAIL)
+ if (verbose & VERBOSE_DETAIL && !yaml)
llapi_printf(LLAPI_MSG_NORMAL,
"%slcme_id: ", " - ");
else if (verbose & ~VERBOSE_COMP_ID)
llapi_printf(LLAPI_MSG_NORMAL,
"%4slcme_id: ", " ");
- if (!(flags & LDF_IS_DIR))
+ if (entry->lcme_id != LCME_ID_INVAL)
llapi_printf(LLAPI_MSG_NORMAL, "%u", entry->lcme_id);
else
llapi_printf(LLAPI_MSG_NORMAL, "N/A");
if (verbose & ~VERBOSE_COMP_FLAGS)
llapi_printf(LLAPI_MSG_NORMAL,
"%4slcme_flags: ", " ");
- llapi_printf(LLAPI_MSG_NORMAL, "%#x", entry->lcme_flags);
+ comp_flags2str(entry->lcme_flags);
separator = "\n";
}
separator = "\n";
}
- if (verbose & VERBOSE_DETAIL) {
+ if (yaml) {
+ llapi_printf(LLAPI_MSG_NORMAL, "%s", separator);
+ llapi_printf(LLAPI_MSG_NORMAL, "%4ssub_layout:\n", " ");
+ } else if (verbose & VERBOSE_DETAIL) {
llapi_printf(LLAPI_MSG_NORMAL, "%s", separator);
llapi_printf(LLAPI_MSG_NORMAL, "%4slcme_offset: %u\n",
" ", entry->lcme_offset);
pool_name[0] = '\0';
}
+static inline bool
+print_last_init_comp(struct find_param *param)
+{
+ /* print all component info */
+ if ((param->fp_verbose & VERBOSE_DEFAULT) == VERBOSE_DEFAULT)
+ return false;
+
+ /* print specific component info */
+ if (param->fp_check_comp_id || param->fp_check_comp_flags ||
+ param->fp_check_comp_start || param->fp_check_comp_end)
+ return false;
+
+ return true;
+}
+
+static int find_comp_end_cmp(unsigned long long end, struct find_param *param)
+{
+ int match;
+
+ if (param->fp_comp_end == LUSTRE_EOF) {
+ if (param->fp_comp_end_sign == 0) /* equal to EOF */
+ match = end == LUSTRE_EOF ? 1 : -1;
+ else if (param->fp_comp_end_sign > 0) /* at most EOF */
+ match = end == LUSTRE_EOF ? -1 : 1;
+ else /* at least EOF */
+ match = -1;
+ if (param->fp_exclude_comp_end)
+ match = ~match + 1;
+ } else {
+ unsigned long long margin;
+
+ margin = end == LUSTRE_EOF ? 0 : param->fp_comp_end_units;
+ match = find_value_cmp(end, param->fp_comp_end,
+ param->fp_comp_end_sign,
+ param->fp_exclude_comp_end, margin, 0);
+ }
+
+ return match;
+}
+
/**
* An example of "getstripe -v" for a two components PFL file:
*
for (i = 0; i < comp_v1->lcm_entry_count; i++) {
entry = &comp_v1->lcm_entries[i];
- if (param->fp_check_comp_flags &&
- !(param->fp_comp_flags & entry->lcme_flags))
- continue;
-
- if (entry->lcme_flags & LCME_FL_INIT)
- flags &= ~LDF_SKIP_OBJS;
- else
- flags |= LDF_SKIP_OBJS;
+ if (param->fp_check_comp_flags) {
+ if ((param->fp_exclude_comp_flags &&
+ (param->fp_comp_flags & entry->lcme_flags)) ||
+ (!param->fp_exclude_comp_flags &&
+ !(param->fp_comp_flags & entry->lcme_flags)))
+ continue;
+ }
if (param->fp_check_comp_id &&
param->fp_comp_id != entry->lcme_id)
}
if (param->fp_check_comp_end) {
- unsigned long long margin;
-
- margin = entry->lcme_extent.e_end == LUSTRE_EOF ?
- 0 : param->fp_comp_end_units;
-
- match = find_value_cmp(entry->lcme_extent.e_end,
- param->fp_comp_end,
- param->fp_comp_end_sign,
- 0, margin, 0);
+ match = find_comp_end_cmp(entry->lcme_extent.e_end,
+ param);
if (match == -1)
continue;
}
+ if (print_last_init_comp(param)) {
+ /**
+ * if part of stripe info is needed, we'd print only
+ * the last instantiated component info.
+ */
+ if (entry->lcme_flags & LCME_FL_INIT)
+ continue;
+ else
+ break;
+ }
+
+ if (entry->lcme_flags & LCME_FL_INIT)
+ flags &= ~LDF_SKIP_OBJS;
+ else
+ flags |= LDF_SKIP_OBJS;
+
+ lov_dump_comp_v1_entry(param, flags, i);
+
+ v1 = lov_comp_entry(comp_v1, i);
+ objects = lov_v1v3_objects(v1);
+ lov_v1v3_pool_name(v1, pool_name);
+
+ lov_dump_user_lmm_v1v3(v1, pool_name, objects, path, obdindex,
+ param->fp_max_depth, param->fp_verbose,
+ flags);
+ }
+ if (print_last_init_comp(param)) {
+ /**
+ * directory layout contains only layout template, print the
+ * last component.
+ */
+ if (i == 0)
+ i = comp_v1->lcm_entry_count - 1;
+ else
+ i--;
+ flags &= ~LDF_SKIP_OBJS;
+
lov_dump_comp_v1_entry(param, flags, i);
v1 = lov_comp_entry(comp_v1, i);
}
}
-static void llapi_lov_dump_user_lmm(struct find_param *param, char *path,
- enum lov_dump_flags flags)
+#define VERBOSE_COMP_OPTS (VERBOSE_COMP_COUNT | VERBOSE_COMP_ID | \
+ VERBOSE_COMP_START | VERBOSE_COMP_END | \
+ VERBOSE_COMP_FLAGS)
+
+static inline bool has_any_comp_options(struct find_param *param)
{
- __u32 magic;
+ int verbose = param->fp_verbose;
- if (param->fp_get_lmv || param->fp_get_default_lmv)
- magic = (__u32)param->fp_lmv_md->lum_magic;
- else
- magic = *(__u32 *)¶m->fp_lmd->lmd_lmm; /* lum->lmm_magic */
+ if (param->fp_check_comp_id || param->fp_check_comp_count ||
+ param->fp_check_comp_start || param->fp_check_comp_end ||
+ param->fp_check_comp_flags)
+ return true;
- if (param->fp_raw)
- flags |= LDF_IS_RAW;
+ /* show full layout information, not component specific */
+ if ((verbose & ~VERBOSE_DETAIL) == VERBOSE_DEFAULT)
+ return false;
- switch (magic) {
- case LOV_USER_MAGIC_V1:
+ return verbose & VERBOSE_COMP_OPTS;
+}
+
+struct lov_user_mds_data *lov_forge_comp_v1(struct lov_user_mds_data *orig,
+ bool is_dir)
+{
+ struct lov_user_md *lum = &orig->lmd_lmm;
+ struct lov_user_mds_data *new;
+ struct lov_comp_md_v1 *comp_v1;
+ struct lov_comp_md_entry_v1 *ent;
+ int lum_off = sizeof(*comp_v1) + sizeof(*ent);
+ int lum_size = lov_user_md_size(is_dir ? 0 : lum->lmm_stripe_count,
+ lum->lmm_magic);
+
+ new = malloc(sizeof(lstat_t) + lum_off + lum_size);
+ if (new == NULL) {
+ llapi_printf(LLAPI_MSG_NORMAL, "out of memory\n");
+ return new;
+ }
+
+ memcpy(new, orig, sizeof(lstat_t));
+
+ comp_v1 = (struct lov_comp_md_v1 *)&new->lmd_lmm;
+ comp_v1->lcm_magic = lum->lmm_magic;
+ comp_v1->lcm_size = lum_off + lum_size;
+ comp_v1->lcm_layout_gen = is_dir ? 0 : lum->lmm_layout_gen;
+ comp_v1->lcm_flags = 0;
+ comp_v1->lcm_entry_count = 1;
+
+ ent = &comp_v1->lcm_entries[0];
+ ent->lcme_id = 0;
+ ent->lcme_flags = is_dir ? 0 : LCME_FL_INIT;
+ ent->lcme_extent.e_start = 0;
+ ent->lcme_extent.e_end = LUSTRE_EOF;
+ ent->lcme_offset = lum_off;
+ ent->lcme_size = lum_size;
+
+ memcpy((char *)comp_v1 + lum_off, lum, lum_size);
+
+ return new;
+}
+
+static void lov_dump_plain_user_lmm(struct find_param *param, char *path,
+ enum lov_dump_flags flags)
+{
+ __u32 magic = *(__u32 *)¶m->fp_lmd->lmd_lmm;
+
+ if (has_any_comp_options(param)) {
+ struct lov_user_mds_data *new_lmd, *orig_lmd;
+
+ orig_lmd = param->fp_lmd;
+ new_lmd = lov_forge_comp_v1(orig_lmd, flags & LDF_IS_DIR);
+ if (new_lmd != NULL) {
+ param->fp_lmd = new_lmd;
+ lov_dump_comp_v1(param, path, flags);
+ param->fp_lmd = orig_lmd;
+ free(new_lmd);
+ }
+ return;
+ }
+
+ if (magic == LOV_USER_MAGIC_V1) {
lov_dump_user_lmm_v1v3(¶m->fp_lmd->lmd_lmm, NULL,
param->fp_lmd->lmd_lmm.lmm_objects,
path, param->fp_obd_index,
param->fp_max_depth, param->fp_verbose,
flags);
- break;
- case LOV_USER_MAGIC_V3: {
+ } else {
char pool_name[LOV_MAXPOOLNAME + 1];
struct lov_user_ost_data_v1 *objects;
struct lov_user_md_v3 *lmmv3 = (void *)¶m->fp_lmd->lmd_lmm;
objects, path, param->fp_obd_index,
param->fp_max_depth, param->fp_verbose,
flags);
+ }
+}
+
+static void llapi_lov_dump_user_lmm(struct find_param *param, char *path,
+ enum lov_dump_flags flags)
+{
+ __u32 magic;
+
+ if (param->fp_get_lmv || param->fp_get_default_lmv)
+ magic = (__u32)param->fp_lmv_md->lum_magic;
+ else
+ magic = *(__u32 *)¶m->fp_lmd->lmd_lmm; /* lum->lmm_magic */
+
+ if (param->fp_raw)
+ flags |= LDF_IS_RAW;
+ if (param->fp_yaml)
+ flags |= LDF_YAML;
+
+ switch (magic) {
+ case LOV_USER_MAGIC_V1:
+ case LOV_USER_MAGIC_V3:
+ lov_dump_plain_user_lmm(param, path, flags);
break;
- }
case LMV_MAGIC_V1:
case LMV_USER_MAGIC: {
char pool_name[LOV_MAXPOOLNAME + 1];
lum = (struct lmv_user_md *)param->fp_lmv_md;
strlcpy(pool_name, lum->lum_pool_name, sizeof(pool_name));
lmv_dump_user_lmm(lum, pool_name, path, param->fp_obd_index,
- param->fp_max_depth, param->fp_verbose);
+ param->fp_max_depth, param->fp_verbose,
+ flags);
break;
}
case LOV_USER_MAGIC_COMP_V1:
static int find_check_comp_options(struct find_param *param)
{
- struct lov_comp_md_v1 *comp_v1;
+ lstat_t *st = ¶m->fp_lmd->lmd_st;
+ struct lov_comp_md_v1 *comp_v1, *forged_v1 = NULL;
struct lov_user_md_v1 *v1 = ¶m->fp_lmd->lmd_lmm;
struct lov_comp_md_entry_v1 *entry;
- int i, ret;
-
- if (v1->lmm_magic != LOV_USER_MAGIC_COMP_V1) {
- if ((param->fp_check_comp_count &&
- !param->fp_exclude_comp_count) ||
- (param->fp_check_comp_flags &&
- !param->fp_exclude_comp_flags) ||
- (param->fp_check_comp_start &&
- !param->fp_exclude_comp_start) ||
- (param->fp_check_comp_end &&
- !param->fp_exclude_comp_end))
+ int i, ret = 0;
+
+ if (v1->lmm_magic == LOV_USER_MAGIC_COMP_V1) {
+ comp_v1 = (struct lov_comp_md_v1 *)v1;
+ } else {
+ forged_v1 = malloc(sizeof(*forged_v1) + sizeof(*entry));
+ if (forged_v1 == NULL)
return -1;
- else
- return 1;
+ comp_v1 = forged_v1;
+ comp_v1->lcm_entry_count = 1;
+ entry = &comp_v1->lcm_entries[0];
+ entry->lcme_flags = S_ISDIR(st->st_mode) ? 0 : LCME_FL_INIT;
+ entry->lcme_extent.e_start = 0;
+ entry->lcme_extent.e_end = LUSTRE_EOF;
}
- comp_v1 = (struct lov_comp_md_v1 *)v1;
+ /* invalid case, don't match for any kind of search. */
+ if (comp_v1->lcm_entry_count == 0) {
+ ret = -1;
+ goto out;
+ }
if (param->fp_check_comp_count) {
- ret = find_value_cmp(comp_v1->lcm_entry_count,
+ ret = find_value_cmp(forged_v1 ? 0 : comp_v1->lcm_entry_count,
param->fp_comp_count,
param->fp_comp_count_sign,
param->fp_exclude_comp_count, 1, 0);
if (ret == -1)
- return ret;
- }
-
- if (comp_v1->lcm_entry_count == 0) {
- if ((param->fp_check_comp_flags &&
- !param->fp_exclude_comp_flags) ||
- (param->fp_check_comp_start &&
- !param->fp_exclude_comp_start) ||
- (param->fp_check_comp_end &&
- !param->fp_exclude_comp_end))
- return -1;
+ goto out;
}
- if (param->fp_check_comp_flags) {
- for (i = 0; i < comp_v1->lcm_entry_count; i++) {
- entry = &comp_v1->lcm_entries[i];
+ ret = 1;
+ for (i = 0; i < comp_v1->lcm_entry_count; i++) {
+ entry = &comp_v1->lcm_entries[i];
+ if (param->fp_check_comp_flags) {
if (((entry->lcme_flags & param->fp_comp_flags) &&
param->fp_exclude_comp_flags) ||
(!(entry->lcme_flags & param->fp_comp_flags) &&
ret = -1;
else
ret = 1;
- /* If any flags matches */
- if (ret != -1)
- break;
- }
- if (ret == -1)
- return ret;
- }
- if (param->fp_check_comp_start) {
- for (i = 0; i < comp_v1->lcm_entry_count; i++) {
- entry = &comp_v1->lcm_entries[i];
+ if (ret == -1)
+ continue;
+ }
+ if (param->fp_check_comp_start) {
ret = find_value_cmp(entry->lcme_extent.e_start,
param->fp_comp_start,
param->fp_comp_start_sign,
param->fp_exclude_comp_start,
param->fp_comp_start_units, 0);
- /* If any extent start matches */
- if (ret != -1)
- break;
+ if (ret == -1)
+ continue;
}
- if (ret == -1)
- return ret;
- }
- if (param->fp_check_comp_end) {
- for (i = 0; i < comp_v1->lcm_entry_count; i++) {
- unsigned long long margin;
- entry = &comp_v1->lcm_entries[i];
-
- margin = entry->lcme_extent.e_end == LUSTRE_EOF ?
- 0 : param->fp_comp_end_units;
-
- ret = find_value_cmp(entry->lcme_extent.e_end,
- param->fp_comp_end,
- param->fp_comp_end_sign,
- param->fp_exclude_comp_end, margin,
- 0);
- /* If any extent end matches */
- if (ret != -1)
- break;
+ if (param->fp_check_comp_end) {
+ ret = find_comp_end_cmp(entry->lcme_extent.e_end,
+ param);
+ if (ret == -1)
+ continue;
}
- if (ret == -1)
- return ret;
- }
- return 1;
+ /* the component matches all criteria */
+ break;
+ }
+out:
+ if (forged_v1 != NULL)
+ free(forged_v1);
+ return ret;
}
static bool find_check_lmm_info(struct find_param *param)
return param->fp_check_pool || param->fp_check_stripe_count ||
param->fp_check_stripe_size || param->fp_check_layout ||
param->fp_check_comp_count || param->fp_check_comp_end ||
- param->fp_check_comp_start || param->fp_check_comp_flags;
+ param->fp_check_comp_start || param->fp_check_comp_flags ||
+ param->fp_check_projid;
+}
+
+/*
+ * Get file/directory project id.
+ * by the open fd resides on.
+ * Return 0 and project id on success, or -ve errno.
+ */
+static int fget_projid(int fd, int *projid)
+{
+ struct fsxattr fsx;
+ int rc;
+
+ rc = ioctl(fd, LL_IOC_FSGETXATTR, &fsx);
+ if (rc)
+ return -errno;
+
+ *projid = fsx.fsx_projid;
+ return 0;
}
static int cb_find_init(char *path, DIR *parent, DIR **dirp,
int checked_type = 0;
int ret = 0;
__u32 stripe_count = 0;
+ int fd = -2;
if (parent == NULL && dir == NULL)
return -EINVAL;
if (ret != 0)
return ret;
}
+
+ param->fp_lmd->lmd_lmm.lmm_magic = 0;
ret = get_lmd_info(path, parent, dir, param->fp_lmd,
param->fp_lum_size);
if (ret == 0 && param->fp_lmd->lmd_lmm.lmm_magic == 0 &&
ret = llapi_file_fget_mdtidx(dirfd(dir),
¶m->fp_file_mdt_index);
} else if (S_ISREG(st->st_mode)) {
- int fd;
-
/* FIXME: we could get the MDT index from the
* file's FID in lmd->lmd_lmm.lmm_oi without
* opening the file, once we are sure that
if (fd > 0) {
ret = llapi_file_fget_mdtidx(fd,
¶m->fp_file_mdt_index);
- close(fd);
} else {
ret = -errno;
}
if (ret == -ENOENT)
goto decided;
- return ret;
+ goto out;
} else {
stripe_count = find_get_stripe_count(param);
}
ret = setup_target_indexes(dir ? dir : parent, path,
param);
if (ret)
- return ret;
+ goto out;
param->fp_dev = st->st_dev;
} else if (!lustre_fs && param->fp_got_uuids) {
}
}
+ if (param->fp_check_projid) {
+ int projid = 0;
+
+ if (fd == -2)
+ fd = open(path, O_RDONLY);
+
+ if (fd > 0)
+ ret = fget_projid(fd, &projid);
+ else
+ ret = -errno;
+ if (ret)
+ goto out;
+ if (projid == param->fp_projid) {
+ if (param->fp_exclude_uid)
+ goto decided;
+ } else {
+ if (!param->fp_exclude_projid)
+ goto decided;
+ }
+ }
+
if (param->fp_check_pool) {
decision = find_check_pool(param);
if (decision == -1)
__func__, path);
goto decided;
} else {
- ret = -errno;
- llapi_error(LLAPI_MSG_ERROR, ret,
- "%s: IOC_LOV_GETINFO on %s failed",
- __func__, path);
- return ret;
- }
- }
+ ret = -errno;
+ llapi_error(LLAPI_MSG_ERROR, ret,
+ "%s: IOC_LOV_GETINFO on %s failed",
+ __func__, path);
+ goto out;
+ }
+ }
- /* Check the time on osc. */
- decision = find_time_check(st, param, 0);
- if (decision == -1)
- goto decided;
- }
+ /* Check the time on osc. */
+ decision = find_time_check(st, param, 0);
+ if (decision == -1)
+ goto decided;
+ }
if (param->fp_check_size)
decision = find_value_cmp(st->st_size, param->fp_size,
param->fp_exclude_size,
param->fp_size_units, 0);
- if (decision != -1) {
- llapi_printf(LLAPI_MSG_NORMAL, "%s", path);
+ if (decision != -1) {
+ llapi_printf(LLAPI_MSG_NORMAL, "%s", path);
if (param->fp_zero_end)
- llapi_printf(LLAPI_MSG_NORMAL, "%c", '\0');
- else
- llapi_printf(LLAPI_MSG_NORMAL, "\n");
- }
+ llapi_printf(LLAPI_MSG_NORMAL, "%c", '\0');
+ else
+ llapi_printf(LLAPI_MSG_NORMAL, "\n");
+ }
decided:
- /* Do not get down anymore? */
- if (param->fp_depth == param->fp_max_depth)
- return 1;
-
+ ret = 0;
+ /* Do not get down anymore? */
+ if (param->fp_depth == param->fp_max_depth) {
+ ret = 1;
+ goto out;
+ }
param->fp_depth++;
-
- return 0;
+out:
+ if (fd > 0)
+ close(fd);
+ return ret;
}
static int cb_migrate_mdt_init(char *path, DIR *parent, DIR **dirp,
int root_ioctl(const char *mdtname, int opc, void *data, int *mdtidxp,
int want_error)
{
- char fsname[20];
- char *ptr;
+ char fsname[20];
+ char *ptr;
int fd, rc;
long index;
- /* 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_noerrno(LLAPI_MSG_ERROR,
- "Can't open %s: %d\n", mdtname, rc);
- return 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, 16);
+ rc = get_root_path(WANT_FD | want_error, fsname, &fd, NULL, -1);
+ }
+ if (rc < 0) {
+ if (want_error)
+ llapi_err_noerrno(LLAPI_MSG_ERROR,
+ "Can't open %s: %d\n", mdtname, rc);
+ return rc;
+ }
- if (mdtidxp)
- *mdtidxp = index;
+ if (mdtidxp)
+ *mdtidxp = index;
- rc = ioctl(fd, opc, data);
- if (rc == -1)
- rc = -errno;
- else
- rc = 0;
- close(fd);
- return rc;
+ rc = ioctl(fd, opc, data);
+ if (rc == -1)
+ rc = -errno;
+ else
+ rc = 0;
+ close(fd);
+ return rc;
}
int llapi_fid2path(const char *device, const char *fidstr, char *buf,