The numerical unique component id.
.TP
.B --component-flags <\fIflags\fR>
-Component flags. Available flags: \fBinit\fR: instatiated component.
+Component flags. Available flags: \fBinit\fR: instantiated component.
+\fB^init\fR: uninstantiated component.
.TP
.B --component-add
Add specified components to an existing composite file.
.B #include <lustre/lustreapi.h>
.PP
.BI "int llapi_layout_file_comp_del(const char *" path ",
-.BI " uint32_t "id );
+.BI " uint32_t "id ", uint32_t "flags );
.fi
.SH DESCRIPTION
.PP
Deletes the layout component(s) specified by
.I id
+or
+.I flags
from an existing file. The
.I id
-can be a real unique component ID or a
-.IR lcme_id .
+must be a real unique component ID, when
+.I flags
+is specified,
+.I id
+must be set to zero.
Available
-.IR lcme_id
+.IR flags
are:
.PP
-.BR LCME_ID_ALL:
-All components in the layout.
+.BR LCME_FL_INIT:
+Instantiated components in the layout.
.PP
-.BR LCME_ID_NONE|LCME_FL_INIT:
-All the instantiated components in the layout.
+.BR LCME_FL_NEG|LCME_FL_INIT:
+Uninstantiated components in the layout.
.SH RETURN VALUES
Returns 0 on success, or -1 if an error occurred (in which case, errno is
set appropriately).
.SM ENOENT
.I path
doesn't exist or the specified component isn't found in file.
-.SH TODO
-Add description for the
-.IR lcme_id .
.SH "SEE ALSO"
.BR llapi_layout_alloc (3),
.BR llapi_layout_file_open (3),
LCME_FL_OFFLINE = 0x00000004, /* Not used */
LCME_FL_PREFERRED = 0x00000008, /* Not used */
LCME_FL_INIT = 0x00000010, /* instantiated */
+ LCME_FL_NEG = 0x80000000 /* used to indicate a negative flag,
+ won't be stored on disk */
};
-#define LCME_KNOWN_FLAGS LCME_FL_INIT
+#define LCME_KNOWN_FLAGS (LCME_FL_NEG | LCME_FL_INIT)
/* lcme_id can be specified as certain flags, and the the first
* bit of lcme_id is used to indicate that the ID is representing
LCME_ID_INVAL = 0x0,
LCME_ID_MAX = 0x7FFFFFFF,
LCME_ID_ALL = 0xFFFFFFFF,
- LCME_ID_NONE = 0x80000000
+ LCME_ID_NOT_ID = LCME_FL_NEG
};
#define LCME_ID_MASK LCME_ID_MAX
int llapi_layout_file_comp_add(const char *path,
const struct llapi_layout *layout);
/**
- * Delete component(s) by the specified component id (accepting lcme_id
- * wildcards also) from an existing file.
+ * Delete component(s) by the specified component id or flags.
*/
-int llapi_layout_file_comp_del(const char *path, uint32_t id);
+int llapi_layout_file_comp_del(const char *path, uint32_t id, uint32_t flags);
/**
* Change flags or other parameters of the component(s) by component ID of an
* existing file. The component to be modified is specified by the
if (i == lo->ldo_comp_cnt)
return id;
}
- if (end > LCME_ID_MAX) {
+ if (end == LCME_ID_MAX) {
start = 1;
end = min(lo->ldo_layout_gen & LCME_ID_MASK,
(__u32)(LCME_ID_MAX - 1));
struct thandle *th)
{
struct lod_thread_info *info = lod_env_info(env);
- struct dt_object *next = dt_object_child(dt);
- struct lod_device *d = lu2lod_dev(dt->do_lu.lo_dev);
- struct lod_object *lo = lod_dt_obj(dt);
- struct lu_attr *attr = &lod_env_info(env)->lti_attr;
- __u32 id;
- int rc, i, j, left;
+ struct dt_object *next = dt_object_child(dt);
+ struct lod_device *d = lu2lod_dev(dt->do_lu.lo_dev);
+ struct lod_object *lo = lod_dt_obj(dt);
+ struct lu_attr *attr = &lod_env_info(env)->lti_attr;
+ struct lov_comp_md_v1 *comp_v1 = buf->lb_buf;
+ __u32 magic, id, flags, neg_flags = 0;
+ int rc, i, j, left;
ENTRY;
LASSERT(lo->ldo_is_composite);
- id = *(__u32 *)buf->lb_buf;
- if (id == 0 || id == LCME_ID_NONE) {
- CDEBUG(D_LAYOUT, "%s: invalid component id %#x\n",
- lod2obd(d)->obd_name, id);
+ rc = lod_verify_striping(d, buf, false, 0);
+ if (rc != 0)
+ RETURN(rc);
+
+ magic = comp_v1->lcm_magic;
+ if (magic == __swab32(LOV_USER_MAGIC_COMP_V1)) {
+ lustre_swab_lov_comp_md_v1(comp_v1);
+ magic = comp_v1->lcm_magic;
+ }
+
+ if (magic != LOV_USER_MAGIC_COMP_V1)
+ RETURN(-EINVAL);
+
+ id = comp_v1->lcm_entries[0].lcme_id;
+ flags = comp_v1->lcm_entries[0].lcme_flags;
+
+ if (id > LCME_ID_MAX || (flags & ~LCME_KNOWN_FLAGS)) {
+ CDEBUG(D_LAYOUT, "%s: invalid component id %#x, flags %#x\n",
+ lod2obd(d)->obd_name, id, flags);
RETURN(-EINVAL);
}
+ if (id != LCME_ID_INVAL && flags != 0) {
+ CDEBUG(D_LAYOUT, "%s: specified both id and flags.\n",
+ lod2obd(d)->obd_name);
+ RETURN(-EINVAL);
+ }
+
+ if (flags & LCME_FL_NEG) {
+ neg_flags = flags & ~LCME_FL_NEG;
+ flags = 0;
+ }
+
left = lo->ldo_comp_cnt;
if (left <= 0)
RETURN(-EINVAL);
lod_comp = &lo->ldo_comp_entries[i];
- if (id <= LCME_ID_MAX && id != lod_comp->llc_id)
+ if (id != LCME_ID_INVAL && id != lod_comp->llc_id)
+ continue;
+ else if (flags && !(flags & lod_comp->llc_flags))
continue;
- else if (id > LCME_ID_MAX && id < LCME_ID_ALL &&
- !(id & lod_comp->llc_flags))
+ else if (neg_flags && (neg_flags & lod_comp->llc_flags))
continue;
if (left != (i + 1)) {
llapi_layout_free(layout);
/* delete non-tail component will fail */
- rc = llapi_layout_file_comp_del(path, id[0]);
+ rc = llapi_layout_file_comp_del(path, id[0], 0);
ASSERTF(rc < 0 && errno == EINVAL, "rc %d, errno %d", rc, errno);
- rc = llapi_layout_file_comp_del(path, id[1]);
+ rc = llapi_layout_file_comp_del(path, id[1], 0);
ASSERTF(rc == 0, "rc %d, errno %d", rc, errno);
/* verify the composite layout after deleting */
local left=$3
local size=$4
- local opt="-I"
- if [ $id == "init" ]; then
- opt="--component-flags"
+ local opt="-I "
+ if [ $id == "init" -o $id == "^init" ]; then
+ opt="--component-flags="
fi
- $LFS setstripe --component-del $opt $id $comp_file ||
+ $LFS setstripe --component-del $opt$id $comp_file ||
error "Delete component $id from $comp_file failed"
local comp_cnt=$($LFS getstripe --component-count $comp_file)
$LFS setstripe -E 1M -E 16M -E -1 $comp_file ||
error "Create second $comp_file failed"
- #instantiate all components, so that objs are allocted
- dd if=/dev/zero of=$comp_file bs=1k count=1 seek=17k
-
+ del_comp_and_verify $comp_file "^init" 1 0
del_comp_and_verify $comp_file "init" 0 0
rm -f $comp_file || error "Delete second $comp_file failed"
+
}
run_test 3 "Delete component from existing file"
" <filename>\n"
"\tcomp_id: Unique component ID\n"
"\tcomp_flags: 'init' indicating all instantiated components\n"
+ "\t '^init' indicating all uninstantiated components\n"
"\t-I and -F can't be specified at the same time\n"
" or\n"
"To add component(s) to an existing composite file:\n"
fprintf(stderr, "Invalid component flags %#x\n", flags);
return -EINVAL;
}
- comp_id = LCME_ID_NONE | flags;
} else if (comp_id > LCME_ID_MAX) {
fprintf(stderr, "Invalid component id %u\n", comp_id);
return -EINVAL;
}
- rc = llapi_layout_file_comp_del(fname, comp_id);
+ rc = llapi_layout_file_comp_del(fname, comp_id, flags);
if (rc)
fprintf(stderr, "Delete component %#x from %s failed. %s\n",
comp_id, fname, strerror(errno));
return 0;
}
+static inline bool comp_flags_is_neg(__u32 flags)
+{
+ return flags & LCME_FL_NEG;
+}
+
+static inline void comp_flags_set_neg(__u32 *flags)
+{
+ *flags |= LCME_FL_NEG;
+}
+
+static inline void comp_flags_clear_neg(__u32 *flags)
+{
+ *flags &= ~LCME_FL_NEG;
+}
+
static int comp_name2flags(__u32 *flags, char *name)
{
char *ptr;
+ __u32 neg_flags = 0;
if (name == NULL)
return -EINVAL;
break;
if (strcmp(flg, "init") == 0)
*flags |= LCME_FL_INIT;
+ else if (strcmp(flg, "^init") == 0)
+ neg_flags |= LCME_FL_INIT;
else
return -EINVAL;
}
- return (*flags == 0) ? -EINVAL : 0;
+
+ if (*flags == 0 && neg_flags == 0)
+ return -EINVAL;
+ /* don't support mixed flags for now */
+ if (*flags && neg_flags)
+ return -EINVAL;
+
+ if (neg_flags) {
+ *flags = neg_flags;
+ comp_flags_set_neg(flags);
+ }
+
+ return 0;
}
enum {
}
/**
- * Delete component(s) by the specified component id (accepting lcme_id
- * wildcards also) from an existing file.
+ * Delete component(s) by the specified component id or component flags
+ * from an existing file.
*
* \param[in] path path name of the file
- * \param[in] id unique component ID or an lcme_id
- * (LCME_ID_NONE | LCME_FL_* )
+ * \param[in] id unique component ID
+ * \param[in] flags flags: LCME_FL_* or;
+ * negative flags: (LCME_FL_NEG|LCME_FL_*)
*/
-int llapi_layout_file_comp_del(const char *path, uint32_t id)
+int llapi_layout_file_comp_del(const char *path, uint32_t id, uint32_t flags)
{
- int rc, fd;
+ int rc, fd, lum_size;
+ struct llapi_layout *layout;
+ struct llapi_layout_comp *comp;
+ struct lov_user_md *lum;
- if (path == NULL || id == 0) {
+ if (path == NULL || id > LCME_ID_MAX || (flags & ~LCME_KNOWN_FLAGS)) {
errno = EINVAL;
return -1;
}
- fd = open(path, O_RDWR);
- if (fd < 0)
+ /* Can only specify ID or flags, not both. */
+ if (id != 0 && flags != 0) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ layout = llapi_layout_alloc();
+ if (layout == NULL)
+ return -1;
+
+ llapi_layout_comp_extent_set(layout, 0, LUSTRE_EOF);
+ comp = __llapi_layout_cur_comp(layout);
+ comp->llc_id = id;
+ comp->llc_flags = flags;
+
+ lum = llapi_layout_to_lum(layout);
+ if (lum == NULL) {
+ llapi_layout_free(layout);
return -1;
+ }
+ lum_size = ((struct lov_comp_md_v1 *)lum)->lcm_size;
+
+ fd = open(path, O_RDWR);
+ if (fd < 0) {
+ rc = -1;
+ goto out;
+ }
- rc = fsetxattr(fd, XATTR_LUSTRE_LOV".del", &id, sizeof(id), 0);
+ rc = fsetxattr(fd, XATTR_LUSTRE_LOV".del", lum, lum_size, 0);
if (rc < 0) {
int tmp_errno = errno;
close(fd);
errno = tmp_errno;
- return -1;
+ rc = -1;
+ goto out;
}
close(fd);
- return 0;
+out:
+ free(lum);
+ llapi_layout_free(layout);
+ return rc;
}
/**