#define LL_MAXQUOTAS 3
#endif
+#ifndef ARRAY_SIZE
+#define ARRAY_SIZE(a) ((sizeof(a)) / (sizeof((a)[0])))
+#endif
+
extern bool liblustreapi_initialized;
*/
int llapi_layout_comp_extent_set(struct llapi_layout *layout,
uint64_t start, uint64_t end);
+
+/* PFL component flags table */
+static const struct comp_flag_name {
+ enum lov_comp_md_entry_flags cfn_flag;
+ const char *cfn_name;
+} comp_flags_table[] = {
+ { LCME_FL_INIT, "init" },
+ /* For now, only "init" is supported
+ { LCME_FL_PRIMARY, "primary" },
+ { LCME_FL_STALE, "stale" },
+ { LCME_FL_OFFLINE, "offline" },
+ { LCME_FL_PREFERRED, "preferred" }
+ */
+};
+
/**
* Gets the attribute flags of the current component.
*/
*flags &= ~LCME_FL_NEG;
}
-static int comp_name2flags(__u32 *flags, char *name)
+static int comp_str2flags(__u32 *flags, char *string)
{
- char *ptr;
+ char *name;
__u32 neg_flags = 0;
- if (name == NULL)
+ if (string == NULL)
return -EINVAL;
*flags = 0;
- for (ptr = name; ; ptr = NULL) {
- char *flg = strtok(ptr, ",");
- if (flg == NULL)
- break;
- if (strcmp(flg, "init") == 0)
- *flags |= LCME_FL_INIT;
- else if (strcmp(flg, "^init") == 0)
- neg_flags |= LCME_FL_INIT;
- else
+ for (name = strtok(string, ","); name; name = strtok(NULL, ",")) {
+ bool found = false;
+ int i;
+
+ for (i = 0; i < ARRAY_SIZE(comp_flags_table); i++) {
+ __u32 comp_flag = comp_flags_table[i].cfn_flag;
+ const char *comp_name = comp_flags_table[i].cfn_name;
+
+ if (strcmp(name, comp_name) == 0) {
+ *flags |= comp_flag;
+ found = true;
+ } else if (strncmp(name, "^", 1) == 0 &&
+ strcmp(name + 1, comp_name) == 0) {
+ neg_flags |= comp_flag;
+ found = true;
+ }
+ }
+ if (!found) {
+ llapi_printf(LLAPI_MSG_ERROR, "Component flag "
+ "'%s' is not supported.\n", name);
return -EINVAL;
+ }
}
if (*flags == 0 && neg_flags == 0)
comp_del = 1;
break;
case LFS_COMP_FLAGS_OPT:
- result = comp_name2flags(&lsa.lsa_comp_flags, optarg);
+ result = comp_str2flags(&lsa.lsa_comp_flags, optarg);
if (result != 0) {
fprintf(stderr, "error: %s: bad comp flags "
"'%s'\n", argv[0], optarg);
param.fp_exclude_comp_count = !!neg_opt;
break;
case LFS_COMP_FLAGS_OPT:
- rc = comp_name2flags(¶m.fp_comp_flags, optarg);
+ rc = comp_str2flags(¶m.fp_comp_flags, optarg);
if (rc || comp_flags_is_neg(param.fp_comp_flags)) {
fprintf(stderr, "error: bad component flags "
"'%s'\n", optarg);
case LFS_COMP_FLAGS_OPT:
if (optarg != NULL) {
__u32 *flags = ¶m->fp_comp_flags;
- rc = comp_name2flags(flags, optarg);
+ rc = comp_str2flags(flags, optarg);
if (rc != 0) {
fprintf(stderr, "error: %s bad "
"component flags '%s'.\n",
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)
{
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";
}