return rc;
}
+/* If there are more than one MDT-objects claim as the OST-object's parent,
+ * and the OST-object only recognizes one of them, then we need to generate
+ * new OST-object(s) with new fid(s) for the non-recognized MDT-object(s). */
+static int lfsck_layout_repair_multiple_references(const struct lu_env *env,
+ struct lfsck_component *com,
+ struct lfsck_layout_req *llr,
+ struct lu_attr *la,
+ struct lu_buf *buf)
+{
+ struct lfsck_thread_info *info = lfsck_env_info(env);
+ struct dt_allocation_hint *hint = &info->lti_hint;
+ struct dt_object_format *dof = &info->lti_dof;
+ struct dt_device *pdev = com->lc_lfsck->li_next;
+ struct ost_id *oi = &info->lti_oi;
+ struct dt_object *parent = llr->llr_parent->llo_obj;
+ struct dt_device *cdev = lfsck_obj2dt_dev(llr->llr_child);
+ struct dt_object *child = NULL;
+ struct lu_device *d = &cdev->dd_lu_dev;
+ struct lu_object *o = NULL;
+ struct thandle *handle;
+ struct lov_mds_md_v1 *lmm;
+ struct lov_ost_data_v1 *objs;
+ struct lustre_handle lh = { 0 };
+ __u32 magic;
+ int rc;
+ ENTRY;
+
+ CDEBUG(D_LFSCK, "Repair multiple references for: parent "DFID
+ ", OST-index %u, stripe-index %u, owner %u:%u\n",
+ PFID(lfsck_dto2fid(parent)), llr->llr_ost_idx,
+ llr->llr_lov_idx, la->la_uid, la->la_gid);
+
+ rc = lfsck_layout_lock(env, com, parent, &lh,
+ MDS_INODELOCK_LAYOUT | MDS_INODELOCK_XATTR);
+ if (rc != 0)
+ RETURN(rc);
+
+ handle = dt_trans_create(env, pdev);
+ if (IS_ERR(handle))
+ GOTO(unlock1, rc = PTR_ERR(handle));
+
+ o = lu_object_anon(env, d, NULL);
+ if (IS_ERR(o))
+ GOTO(stop, rc = PTR_ERR(o));
+
+ child = container_of(o, struct dt_object, do_lu);
+ o = lu_object_locate(o->lo_header, d->ld_type);
+ if (unlikely(o == NULL))
+ GOTO(stop, rc = -EINVAL);
+
+ child = container_of(o, struct dt_object, do_lu);
+ la->la_valid = LA_UID | LA_GID;
+ hint->dah_parent = NULL;
+ hint->dah_mode = 0;
+ dof->dof_type = DFT_REGULAR;
+ rc = dt_declare_create(env, child, la, NULL, NULL, handle);
+ if (rc != 0)
+ GOTO(stop, rc);
+
+ rc = dt_declare_xattr_set(env, parent, buf, XATTR_NAME_LOV,
+ LU_XATTR_REPLACE, handle);
+ if (rc != 0)
+ GOTO(stop, rc);
+
+ rc = dt_trans_start(env, pdev, handle);
+ if (rc != 0)
+ GOTO(stop, rc);
+
+ dt_write_lock(env, parent, 0);
+ if (unlikely(lu_object_is_dying(parent->do_lu.lo_header)))
+ GOTO(unlock2, rc = 0);
+
+ rc = dt_xattr_get(env, parent, buf, XATTR_NAME_LOV, BYPASS_CAPA);
+ if (unlikely(rc == 0 || rc == -ENODATA || rc == -ERANGE))
+ GOTO(unlock2, rc = 0);
+
+ lmm = buf->lb_buf;
+ rc = lfsck_layout_verify_header(lmm);
+ if (rc != 0)
+ GOTO(unlock2, rc);
+
+ /* Someone change layout during the LFSCK, no need to repair then. */
+ if (le16_to_cpu(lmm->lmm_layout_gen) != llr->llr_parent->llo_gen)
+ GOTO(unlock2, rc = 0);
+
+ rc = dt_create(env, child, la, hint, dof, handle);
+ if (rc != 0)
+ GOTO(unlock2, rc);
+
+ /* Currently, we only support LOV_MAGIC_V1/LOV_MAGIC_V3 which has
+ * been verified in lfsck_layout_verify_header() already. If some
+ * new magic introduced in the future, then layout LFSCK needs to
+ * be updated also. */
+ magic = le32_to_cpu(lmm->lmm_magic);
+ if (magic == LOV_MAGIC_V1) {
+ objs = &(lmm->lmm_objects[0]);
+ } else {
+ LASSERT(magic == LOV_MAGIC_V3);
+ objs = &((struct lov_mds_md_v3 *)lmm)->lmm_objects[0];
+ }
+
+ lmm->lmm_layout_gen = cpu_to_le16(llr->llr_parent->llo_gen + 1);
+ fid_to_ostid(lu_object_fid(&child->do_lu), oi);
+ ostid_cpu_to_le(oi, &objs[llr->llr_lov_idx].l_ost_oi);
+ objs[llr->llr_lov_idx].l_ost_gen = cpu_to_le32(0);
+ objs[llr->llr_lov_idx].l_ost_idx = cpu_to_le32(llr->llr_ost_idx);
+ rc = dt_xattr_set(env, parent, buf, XATTR_NAME_LOV,
+ LU_XATTR_REPLACE, handle, BYPASS_CAPA);
+
+ GOTO(unlock2, rc = (rc == 0 ? 1 : rc));
+
+unlock2:
+ dt_write_unlock(env, parent);
+
+stop:
+ if (child != NULL)
+ lu_object_put(env, &child->do_lu);
+
+ dt_trans_stop(env, pdev, handle);
+
+unlock1:
+ lfsck_layout_unlock(&lh);
+
+ return rc;
+}
+
+/* If the MDT-object and the OST-object have different owner information,
+ * then trust the MDT-object, because the normal chown/chgrp handle order
+ * is from MDT to OST, and it is possible that some chown/chgrp operation
+ * is partly done. */
+static int lfsck_layout_repair_owner(const struct lu_env *env,
+ struct lfsck_component *com,
+ struct lfsck_layout_req *llr,
+ struct lu_attr *pla)
+{
+ struct lfsck_thread_info *info = lfsck_env_info(env);
+ struct lu_attr *tla = &info->lti_la3;
+ struct dt_object *parent = llr->llr_parent->llo_obj;
+ struct dt_object *child = llr->llr_child;
+ struct dt_device *dev = lfsck_obj2dt_dev(child);
+ struct thandle *handle;
+ int rc;
+ ENTRY;
+
+ CDEBUG(D_LFSCK, "Repair inconsistent file owner for: parent "DFID
+ ", child "DFID", OST-index %u, stripe-index %u, owner %u:%u\n",
+ PFID(lfsck_dto2fid(parent)), PFID(lfsck_dto2fid(child)),
+ llr->llr_ost_idx, llr->llr_lov_idx, pla->la_uid, pla->la_gid);
+
+ handle = dt_trans_create(env, dev);
+ if (IS_ERR(handle))
+ RETURN(PTR_ERR(handle));
+
+ tla->la_uid = pla->la_uid;
+ tla->la_gid = pla->la_gid;
+ tla->la_valid = LA_UID | LA_GID;
+ rc = dt_declare_attr_set(env, child, tla, handle);
+ if (rc != 0)
+ GOTO(stop, rc);
+
+ rc = dt_trans_start(env, dev, handle);
+ if (rc != 0)
+ GOTO(stop, rc);
+
+ /* Use the dt_object lock to serialize with destroy and attr_set. */
+ dt_read_lock(env, parent, 0);
+ if (unlikely(lu_object_is_dying(parent->do_lu.lo_header)))
+ GOTO(unlock, rc = 1);
+
+ /* Get the latest parent's owner. */
+ rc = dt_attr_get(env, parent, tla, BYPASS_CAPA);
+ if (rc != 0) {
+ CWARN("%s: fail to get the latest parent's ("DFID") owner, "
+ "not sure whether some others chown/chgrp during the "
+ "LFSCK: rc = %d\n", lfsck_lfsck2name(com->lc_lfsck),
+ PFID(lfsck_dto2fid(parent)), rc);
+
+ GOTO(unlock, rc);
+ }
+
+ /* Some others chown/chgrp during the LFSCK, needs to do nothing. */
+ if (unlikely(tla->la_uid != pla->la_uid ||
+ tla->la_gid != pla->la_gid))
+ GOTO(unlock, rc = 1);
+
+ tla->la_valid = LA_UID | LA_GID;
+ rc = dt_attr_set(env, child, tla, handle, BYPASS_CAPA);
+
+ GOTO(unlock, rc);
+
+unlock:
+ dt_read_unlock(env, parent);
+
+stop:
+ rc = lfsck_layout_trans_stop(env, dev, handle, rc);
+
+ return rc;
+}
+
/* Check whether the OST-object correctly back points to the
* MDT-object (@parent) via the XATTR_NAME_FID xattr (@pfid). */
static int lfsck_layout_check_parent(const struct lu_env *env,
if (fid_is_zero(pfid)) {
/* client never wrote. */
- if (cla->la_size == 0 && cla->la_blocks == 0)
+ if (cla->la_size == 0 && cla->la_blocks == 0) {
+ if (unlikely(cla->la_uid != pla->la_uid ||
+ cla->la_gid != pla->la_gid))
+ RETURN (LLIT_INCONSISTENT_OWNER);
+
RETURN(0);
+ }
RETURN(LLIT_UNMATCHED_PAIR);
}
struct lfsck_thread_info *info = lfsck_env_info(env);
struct filter_fid_old *pea = &info->lti_old_pfid;
struct lu_fid *pfid = &info->lti_fid;
- struct lu_buf *buf;
+ struct lu_buf *buf = NULL;
struct dt_object *parent = llr->llr_parent->llo_obj;
struct dt_object *child = llr->llr_child;
struct lu_attr *pla = &info->lti_la;
if (rc < 0)
GOTO(out, rc);
- /* XXX: other inconsistency will be checked in other patches. */
+ if (unlikely(cla->la_uid != pla->la_uid ||
+ cla->la_gid != pla->la_gid)) {
+ type = LLIT_INCONSISTENT_OWNER;
+ goto repair;
+ }
repair:
if (bk->lb_param & LPF_DRYRUN) {
case LLIT_UNMATCHED_PAIR:
rc = lfsck_layout_repair_unmatched_pair(env, com, llr, pla);
break;
-
- /* XXX: other inconsistency will be fixed in other patches. */
-
case LLIT_MULTIPLE_REFERENCED:
+ rc = lfsck_layout_repair_multiple_references(env, com, llr,
+ pla, buf);
break;
case LLIT_INCONSISTENT_OWNER:
+ rc = lfsck_layout_repair_owner(env, com, llr, pla);
break;
default:
rc = 0;
{
struct thandle *th = NULL;
struct thandle_update *tu = NULL;
- int rc;
+ int rc = 0;
OBD_ALLOC_PTR(th);
if (unlikely(th == NULL))
INIT_LIST_HEAD(&tu->tu_remote_update_list);
tu->tu_only_remote_trans = 1;
+ th->th_update = tu;
+
out:
if (rc != 0) {
if (tu != NULL)
/* If the transaction only includes remote update, it should
* still be asynchronous */
- if (tu->tu_only_remote_trans) {
+ if (is_only_remote_trans(th)) {
struct osp_async_update_args *args;
struct ptlrpc_request *req;
* If it is remote unlink, it will send the remote req before
* the local transaction, i.e. delete the name entry remote
* first, then destroy the local object. */
- if (!tu->tu_only_remote_trans && !tu->tu_sent_after_local_trans)
+ if (!is_only_remote_trans(th) && !tu->tu_sent_after_local_trans)
rc = osp_trans_trigger(env, dt2osp_dev(dt), update, th);
return rc;
LASSERT(tu != NULL);
/* Check whether there are updates related with this OSP */
update = out_find_update(tu, dt);
- if (update == NULL)
- return rc;
+ if (update == NULL) {
+ if (!is_only_remote_trans(th))
+ return rc;
+ goto put;
+ }
- if (update->ur_buf->ub_count == 0)
- GOTO(free, rc);
+ if (update->ur_buf->ub_count == 0) {
+ out_destroy_update_req(update);
+ goto put;
+ }
- if (tu->tu_only_remote_trans) {
- if (th->th_result == 0)
+ if (is_only_remote_trans(th)) {
+ if (th->th_result == 0) {
rc = osp_trans_trigger(env, dt2osp_dev(dt),
update, th);
- else
+ } else {
rc = th->th_result;
+ out_destroy_update_req(update);
+ }
} else {
if (tu->tu_sent_after_local_trans)
rc = osp_trans_trigger(env, dt2osp_dev(dt),
update, th);
rc = update->ur_rc;
+ out_destroy_update_req(update);
}
-free:
- out_destroy_update_req(update);
+
+put:
thandle_put(th);
return rc;
}
ALWAYS_EXCEPT="$ALWAYS_EXCEPT 2c"
[[ $(lustre_version_code ost1) -lt $(version_code 2.5.55) ]] &&
- ALWAYS_EXCEPT="$ALWAYS_EXCEPT 11 12 13 14 15"
+ ALWAYS_EXCEPT="$ALWAYS_EXCEPT 11 12 13 14 15 16 17"
build_test_filter
}
run_test 15b "LFSCK can repair unmatched MDT-object/OST-object pairs (2)"
+test_16() {
+ echo "#####"
+ echo "If the OST-object's owner information does not match the owner"
+ echo "information stored in the MDT-object, then the LFSCK trust the"
+ echo "MDT-object and update the OST-object's owner information."
+ echo "#####"
+
+ echo "stopall"
+ stopall > /dev/null
+ echo "formatall"
+ formatall > /dev/null
+ echo "setupall"
+ setupall > /dev/null
+
+ mkdir -p $DIR/$tdir
+ $LFS setstripe -c 1 -i 0 $DIR/$tdir
+ dd if=/dev/zero of=$DIR/$tdir/f0 bs=1M count=1
+ cancel_lru_locks osc
+ sync
+ sleep 2
+
+ echo "Inject failure stub to skip OST-object owner changing"
+ #define OBD_FAIL_LFSCK_BAD_OWNER 0x1613
+ do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1613
+ chown 1.1 $DIR/$tdir/f0
+ do_facet $SINGLEMDS $LCTL set_param fail_loc=0
+
+ echo "Trigger layout LFSCK to find out inconsistent OST-object owner"
+ echo "and fix them"
+
+ $START_LAYOUT || error "(1) Fail to start LFSCK for layout!"
+
+ wait_update_facet $SINGLEMDS "$LCTL get_param -n \
+ mdd.${MDT_DEV}.lfsck_layout |
+ awk '/^status/ { print \\\$2 }'" "completed" 3 || return 2
+
+ local repaired=$($SHOW_LAYOUT |
+ awk '/^repaired_inconsistent_owner/ { print $2 }')
+ [ $repaired -eq 1 ] ||
+ error "(3) Fail to repair inconsistent owner: $repaired"
+}
+run_test 16 "LFSCK can repair inconsistent MDT-object/OST-object owner"
+
+test_17() {
+ echo "#####"
+ echo "If more than one MDT-objects reference the same OST-object,"
+ echo "and the OST-object only recognizes one MDT-object, then the"
+ echo "LFSCK should create new OST-objects for such non-recognized"
+ echo "MDT-objects."
+ echo "#####"
+
+ echo "stopall"
+ stopall > /dev/null
+ echo "formatall"
+ formatall > /dev/null
+ echo "setupall"
+ setupall > /dev/null
+
+ mkdir -p $DIR/$tdir
+ $LFS setstripe -c 1 -i 0 $DIR/$tdir
+
+ echo "Inject failure stub to make two MDT-objects to refernce"
+ echo "the OST-object"
+
+ do_facet $SINGLEMDS $LCTL set_param fail_val=0
+ #define OBD_FAIL_LFSCK_MULTIPLE_REF 0x1614
+ do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1614
+
+ dd if=/dev/zero of=$DIR/$tdir/guard bs=1M count=1
+ cancel_lru_locks osc
+ sync
+ sleep 2
+
+ createmany -o $DIR/$tdir/f 1 > /dev/null 2>&1
+
+ do_facet $SINGLEMDS $LCTL set_param fail_loc=0
+ do_facet $SINGLEMDS $LCTL set_param fail_val=0
+
+ echo "stopall to cleanup object cache"
+ stopall > /dev/null
+ echo "setupall"
+ setupall > /dev/null
+
+ echo "$DIR/$tdir/f0 and $DIR/$tdir/guard use the same OST-objects"
+ local size=$(ls -l $DIR/$tdir/f0 | awk '{ print $5 }')
+ [ $size -eq 1048576 ] ||
+ error "(1) f0 (wrong) size should be 1048576, but got $size"
+
+ echo "Trigger layout LFSCK to find out multiple refenced MDT-objects"
+ echo "and fix them"
+
+ $START_LAYOUT || error "(2) Fail to start LFSCK for layout!"
+
+ wait_update_facet $SINGLEMDS "$LCTL get_param -n \
+ mdd.${MDT_DEV}.lfsck_layout |
+ awk '/^status/ { print \\\$2 }'" "completed" 3 || return 3
+
+ local repaired=$($SHOW_LAYOUT |
+ awk '/^repaired_multiple_referenced/ { print $2 }')
+ [ $repaired -eq 1 ] ||
+ error "(4) Fail to repair multiple references: $repaired"
+
+ echo "$DIR/$tdir/f0 and $DIR/$tdir/guard should use diff OST-objects"
+ dd if=/dev/zero of=$DIR/$tdir/f0 bs=1M count=2 ||
+ error "(5) Fail to write f0."
+ size=$(ls -l $DIR/$tdir/guard | awk '{ print $5 }')
+ [ $size -eq 1048576 ] ||
+ error "(6) guard size should be 1048576, but got $size"
+}
+run_test 17 "LFSCK can repair multiple references"
+
$LCTL set_param debug=-lfsck > /dev/null || true
# restore MDS/OST size