buf->lb_len = info->lti_ea_store_size;
lmm = info->lti_ea_store;
magic = le32_to_cpu(lmm->lmm_magic);
- if (magic == LOV_MAGIC_COMP_V1) {
+ if (magic == LOV_MAGIC_COMP_V1 || magic == LOV_MAGIC_SEL) {
struct lov_comp_md_v1 *lcm = buf->lb_buf;
struct lov_comp_md_entry_v1 *lcme =
&lcm->lcm_entries[0];
buf->lb_buf = info->lti_ea_store;
buf->lb_len = info->lti_ea_store_size;
lcm = buf->lb_buf;
- if (le32_to_cpu(lcm->lcm_magic) != LOV_MAGIC_COMP_V1)
+ if (le32_to_cpu(lcm->lcm_magic) != LOV_MAGIC_COMP_V1 &&
+ le32_to_cpu(lcm->lcm_magic) != LOV_MAGIC_SEL)
RETURN(-EINVAL);
le32_add_cpu(&lcm->lcm_layout_gen, 1);
RETURN(rc = rc1 != 0 ? rc1 : rc);
}
+ if ((rc > 0) && buf->lb_buf && strcmp(name, XATTR_NAME_LOV) == 0) {
+ struct lov_comp_md_v1 *lcm = buf->lb_buf;
+
+ if (lcm->lcm_magic == cpu_to_le32(LOV_MAGIC_SEL))
+ lcm->lcm_magic = cpu_to_le32(LOV_MAGIC_COMP_V1);
+ }
+
if (rc != -ENODATA || !S_ISDIR(dt->do_lu.lo_header->loh_attr & S_IFMT))
RETURN(rc);
continue;
tgt_dt = tgt->ltd_tgt;
- rc = dt_statfs(env, tgt_dt, &info->lti_osfs, NULL);
+ rc = dt_statfs(env, tgt_dt, &info->lti_osfs);
if (rc) {
/* this OSP doesn't feel well */
rc = 0;
rc = lod_layout_convert(info);
break;
case LOV_MAGIC_COMP_V1:
+ case LOV_MAGIC_SEL:
rc = 0;
break;
default:
pool_name);
break;
case LOV_USER_MAGIC_COMP_V1:
+ {
+ struct lov_comp_md_v1 *lcm = (struct lov_comp_md_v1 *)lum;
+ struct lov_comp_md_entry_v1 *lcme;
+ int i, comp_cnt;
+
+ comp_cnt = le16_to_cpu(lcm->lcm_entry_count);
+ for (i = 0; i < comp_cnt; i++) {
+ lcme = &lcm->lcm_entries[i];
+ if (lcme->lcme_flags & cpu_to_le32(LCME_FL_EXTENSION)) {
+ lcm->lcm_magic = cpu_to_le32(LOV_MAGIC_SEL);
+ break;
+ }
+ }
+
is_del = false;
break;
+ }
default:
CERROR("Invalid magic %x\n", lum->lmm_magic);
RETURN(-EINVAL);
/* if it's source stripe of migrating directory, don't create */
if (!((lo->ldo_dir_hash_type & LMV_HASH_FLAG_MIGRATION) &&
i >= lo->ldo_dir_migrate_offset)) {
- dt_write_lock(env, dto, MOR_TGT_CHILD);
+ dt_write_lock(env, dto, DT_TGT_CHILD);
rc = lod_sub_create(env, dto, attr, NULL, dof, th);
if (rc != 0) {
dt_write_unlock(env, dto);
RETURN(rc);
}
+static __u32 lod_gen_component_id(struct lod_object *lo,
+ int mirror_id, int comp_idx);
+
+/**
+ * Repeat an existing component
+ *
+ * Creates a new layout by replicating an existing component. Uses striping
+ * policy from previous component as a template for the striping for the new
+ * new component.
+ *
+ * New component starts with zero length, will be extended (or removed) before
+ * returning layout to client.
+ *
+ * NB: Reallocates layout components array (lo->ldo_comp_entries), invalidating
+ * any pre-existing pointers to components. Handle with care.
+ *
+ * \param[in] env execution environment for this thread
+ * \param[in,out] lo object to update the layout of
+ * \param[in] index index of component to copy
+ *
+ * \retval 0 on success
+ * \retval negative errno on error
+ */
+static int lod_layout_repeat_comp(const struct lu_env *env,
+ struct lod_object *lo, int index)
+{
+ struct lod_layout_component *lod_comp;
+ struct lod_layout_component *new_comp = NULL;
+ struct lod_layout_component *comp_array;
+ int rc = 0, i, new_cnt = lo->ldo_comp_cnt + 1;
+ __u16 mirror_id;
+ int offset = 0;
+ ENTRY;
+
+ lod_comp = &lo->ldo_comp_entries[index];
+ LASSERT(lod_comp_inited(lod_comp) && lod_comp->llc_id != LCME_ID_INVAL);
+
+ CDEBUG(D_LAYOUT, "repeating component %d\n", index);
+
+ OBD_ALLOC(comp_array, sizeof(*comp_array) * new_cnt);
+ if (comp_array == NULL)
+ GOTO(out, rc = -ENOMEM);
+
+ for (i = 0; i < lo->ldo_comp_cnt; i++) {
+ memcpy(&comp_array[i + offset], &lo->ldo_comp_entries[i],
+ sizeof(*comp_array));
+
+ /* Duplicate this component in to the next slot */
+ if (i == index) {
+ new_comp = &comp_array[i + 1];
+ memcpy(&comp_array[i + 1], &lo->ldo_comp_entries[i],
+ sizeof(*comp_array));
+ /* We must now skip this new component when copying */
+ offset = 1;
+ }
+ }
+
+ /* Set up copied component */
+ new_comp->llc_flags &= ~LCME_FL_INIT;
+ new_comp->llc_stripe = NULL;
+ new_comp->llc_stripes_allocated = 0;
+ new_comp->llc_stripe_offset = LOV_OFFSET_DEFAULT;
+ /* for uninstantiated components, layout gen stores default stripe
+ * offset */
+ new_comp->llc_layout_gen = lod_comp->llc_stripe_offset;
+ /* This makes the repeated component zero-length, placed at the end of
+ * the preceding component */
+ new_comp->llc_extent.e_start = new_comp->llc_extent.e_end;
+ new_comp->llc_timestamp = lod_comp->llc_timestamp;
+ new_comp->llc_pool = NULL;
+
+ rc = lod_set_pool(&new_comp->llc_pool, lod_comp->llc_pool);
+ if (rc)
+ GOTO(out, rc);
+
+ if (new_comp->llc_ostlist.op_array) {
+ __u32 *op_array = NULL;
+
+ OBD_ALLOC(op_array, new_comp->llc_ostlist.op_size);
+ if (!op_array)
+ GOTO(out, rc = -ENOMEM);
+ memcpy(op_array, &new_comp->llc_ostlist.op_array,
+ new_comp->llc_ostlist.op_size);
+ new_comp->llc_ostlist.op_array = op_array;
+ }
+
+ OBD_FREE(lo->ldo_comp_entries,
+ sizeof(*comp_array) * lo->ldo_comp_cnt);
+ lo->ldo_comp_entries = comp_array;
+ lo->ldo_comp_cnt = new_cnt;
+
+ /* Generate an id for the new component */
+ mirror_id = mirror_id_of(new_comp->llc_id);
+ new_comp->llc_id = LCME_ID_INVAL;
+ new_comp->llc_id = lod_gen_component_id(lo, mirror_id, index + 1);
+ if (new_comp->llc_id == LCME_ID_INVAL)
+ GOTO(out, rc = -ERANGE);
+
+ EXIT;
+out:
+ if (rc)
+ OBD_FREE(comp_array, sizeof(*comp_array) * new_cnt);
+
+ return rc;
+}
+
static int lod_layout_data_init(struct lod_thread_info *info, __u32 comp_cnt)
{
ENTRY;
ENTRY;
+ LASSERT(lo->ldo_is_composite);
+ LASSERT(lo->ldo_comp_cnt > 0 && lo->ldo_comp_entries != NULL);
+
rc = lod_layout_data_init(info, lo->ldo_comp_cnt);
if (rc)
RETURN(rc);
struct lu_attr *attr = &lod_env_info(env)->lti_attr;
int rc;
- LASSERT(lo->ldo_is_composite);
LASSERT(lo->ldo_mirror_count == 1);
- LASSERT(lo->ldo_comp_cnt > 0 && lo->ldo_comp_entries != NULL);
rc = lod_layout_del_prep_layout(env, lo, th);
if (rc < 0)
if (!S_ISDIR(dt->do_lu.lo_header->loh_attr))
RETURN(0);
- /* set xattr to each stripes, if needed */
+ /* NB: don't delete stripe LMV, because when we do this, normally we
+ * will remove stripes, besides, if directory LMV is corrupt, this will
+ * prevent deleting its LMV and fixing it (via LFSCK).
+ */
+ if (!strcmp(name, XATTR_NAME_LMV))
+ RETURN(0);
+
rc = lod_striping_load(env, lo);
if (rc != 0)
RETURN(rc);
if (rc != 0 || !S_ISDIR(dt->do_lu.lo_header->loh_attr))
RETURN(rc);
+ if (!strcmp(name, XATTR_NAME_LMV))
+ RETURN(0);
+
if (lo->ldo_dir_stripe_count == 0)
RETURN(0);
lustre_swab_lov_user_md_v3(v3);
lustre_swab_lov_user_md_objects(v3->lmm_objects,
v3->lmm_stripe_count);
- } else if (v1->lmm_magic == __swab32(LOV_USER_MAGIC_COMP_V1)) {
+ } else if (v1->lmm_magic == __swab32(LOV_USER_MAGIC_COMP_V1) ||
+ v1->lmm_magic == __swab32(LOV_USER_MAGIC_SEL)) {
comp_v1 = (struct lov_comp_md_v1 *)v1;
lustre_swab_lov_comp_md_v1(comp_v1);
}
if (v1->lmm_magic != LOV_MAGIC_V3 && v1->lmm_magic != LOV_MAGIC_V1 &&
v1->lmm_magic != LOV_MAGIC_COMP_V1 &&
+ v1->lmm_magic != LOV_MAGIC_SEL &&
v1->lmm_magic != LOV_USER_MAGIC_SPECIFIC)
RETURN(-ENOTSUPP);
- if (v1->lmm_magic == LOV_MAGIC_COMP_V1) {
+ if (v1->lmm_magic == LOV_MAGIC_COMP_V1 ||
+ v1->lmm_magic == LOV_MAGIC_SEL) {
comp_v1 = (struct lov_comp_md_v1 *)v1;
comp_cnt = comp_v1->lcm_entry_count;
if (comp_cnt == 0)
if (!OBD_FAIL_CHECK(OBD_FAIL_LFSCK_LOST_SPEOBJ) ||
i == cfs_fail_val) {
- dt_write_lock(env, stripe, MOR_TGT_CHILD);
+ dt_write_lock(env, stripe, DT_TGT_CHILD);
rc = lod_sub_ref_del(env, stripe, th);
dt_write_unlock(env, stripe);
if (rc != 0)
break;
}
- rc = dt_statfs(env, ost->ltd_ost, sfs, &info);
+ rc = dt_statfs_info(env, ost->ltd_ost, sfs, &info);
if (rc) {
CDEBUG(D_LAYOUT, "statfs failed for ost %d, error %d\n",
index, rc);
return new_end;
}
+/* As lod_sel_handler() could be re-entered for the same component several
+ * times, this is the data for the next call. Fields could be changed to
+ * component indexes when needed, (e.g. if there is no need to instantiate
+ * all the previous components up to the current position) to tell the caller
+ * where to start over from. */
+struct sel_data {
+ int sd_force;
+ int sd_repeat;
+};
+
/**
* Process extent updates for a particular layout component
*
* extension space component, move the start of the next component down
* accordingly, then notify the caller to restart processing w/the new
* layout.
- * b. If there is no following component, we extend the current component
- * regardless.
+ * b. If there is no following component, we try repeating the current
+ * component, creating a new component using the current one as a
+ * template (keeping its stripe properties but not specific striping),
+ * and try assigning striping for this component. If there is sufficient
+ * free space on the OSTs chosen for this component, it is instantiated
+ * and i/o continues there.
+ *
+ * If there is not sufficient space on the new OSTs, we remove this new
+ * component & extend the current component.
*
* Note further that uninited components followed by extension space can be zero
* length meaning that we will try to extend them before initializing them, and
struct lod_object *lo,
struct lu_extent *extent,
struct thandle *th, int *max_comp,
- int index, int write, int *force)
+ int index, int write,
+ struct sel_data *sd)
{
struct lod_device *d = lu2lod_dev(lo->ldo_obj.do_lu.lo_dev);
struct lod_thread_info *info = lod_env_info(env);
struct lod_layout_component *next = NULL;
__u64 extension_size;
__u64 new_end = 0;
+ bool repeated;
int change = 0;
int rc = 0;
ENTRY;
info->lti_count = 1;
info->lti_comp_idx[0] = index - 1;
rc = lod_declare_instantiate_components(env, lo, th);
- /* ENOSPC tells us we can't use this component, so it's the
- * same as if check_extension failed. But if there is no next,
- * we have no fall back if we failed to stripe this, and we
- * should return the error. */
- if (rc == -ENOSPC && next)
+ /* ENOSPC tells us we can't use this component. If there is
+ * a next or we are repeating, we either spill over (next) or
+ * extend the original comp (repeat). Otherwise, return the
+ * error to the user. */
+ if (rc == -ENOSPC && (next || sd->sd_repeat))
rc = 1;
if (rc < 0)
RETURN(rc);
}
- if (*force == 0 && rc == 0)
+ if (sd->sd_force == 0 && rc == 0)
rc = !lod_sel_osts_allowed(env, lo, index - 1,
extension_size, extent,
&lod_comp->llc_extent, write);
- *force = 0;
+
+ repeated = !!(sd->sd_repeat);
+ sd->sd_repeat = 0;
+ sd->sd_force = 0;
/* Extend previous component */
if (rc == 0) {
change--;
}
lod_sel_adjust_extents(env, lo, *max_comp, index);
+ } else if (lod_comp_inited(prev)) {
+ /* If there is no next, and the previous component is
+ * INIT'ed, try repeating the previous component. */
+ LASSERT(repeated == 0);
+ rc = lod_layout_repeat_comp(env, lo, index - 1);
+ if (rc < 0)
+ RETURN(rc);
+ change++;
+ /* The previous component is a repeated component.
+ * Record this so we don't keep trying to repeat it. */
+ sd->sd_repeat = 1;
} else {
- *force = 1;
+ /* If the previous component is not INIT'ed, this may
+ * be a component we have just instantiated but failed
+ * to extend. Or even a repeated component we failed
+ * to prepare a striping for. Do not repeat but instead
+ * remove the repeated component & force the extention
+ * of the original one */
+ sd->sd_force = 1;
+ if (repeated) {
+ prev->llc_id = LCME_ID_INVAL;
+ change--;
+ }
}
}
struct lod_thread_info *info = lod_env_info(env);
struct lod_layout_component *lod_comp;
bool layout_changed = false;
+ struct sel_data sd = { 0 };
int start_index;
int i = 0;
int max_comp = 0;
int rc = 0, rc2;
int change = 0;
- int force = 0;
ENTRY;
/* This makes us work on the components of the chosen mirror */
if (lod_comp->llc_flags & LCME_FL_EXTENSION) {
layout_changed = true;
rc = lod_sel_handler(env, lo, extent, th, &max_comp,
- i, write, &force);
+ i, write, &sd);
if (rc < 0)
GOTO(out, rc);
}
}
- /* We may have removed components. If so, we must update the start &
- * ends of all the mirrors after the current one, and the end of the
- * current mirror.
- */
+ /* We may have added or removed components. If so, we must update the
+ * start & ends of all the mirrors after the current one, and the end
+ * of the current mirror. */
change = max_comp - 1 - lo->ldo_mirrors[pick].lme_end;
if (change) {
lo->ldo_mirrors[pick].lme_end += change;
ENTRY;
rc = lod_fld_lookup(env, lod, lu_object_fid(lo), &idx, &type);
- if (rc != 0) {
- /* Note: Sometimes, it will Return EAGAIN here, see
- * ptrlpc_import_delay_req(), which might confuse
- * lu_object_find_at() and make it wait there incorrectly.
- * so we convert it to EIO here.*/
- if (rc == -EAGAIN)
- rc = -EIO;
-
+ if (rc != 0)
RETURN(rc);
- }
if (type == LU_SEQ_RANGE_MDT &&
idx == lu_site2seq(lo->lo_dev->ld_site)->ss_node_id) {