X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=blobdiff_plain;f=lustre%2Fmdd%2Fmdd_orphans.c;h=3fa6b8bcc4dc111b242bf017303c5c4720de8e09;hp=7b99a931688198f0f90905036a5fff04ca89b9e9;hb=e2ac6e1eaa108eef3493837e9bd881629582ea1d;hpb=5d89450b462f76fe2a377e7253595a162dae309b diff --git a/lustre/mdd/mdd_orphans.c b/lustre/mdd/mdd_orphans.c index 7b99a93..3fa6b8bc 100644 --- a/lustre/mdd/mdd_orphans.c +++ b/lustre/mdd/mdd_orphans.c @@ -45,7 +45,7 @@ #include #include "mdd_internal.h" -static const char mdd_orphan_index_name[] = "PENDING"; +static const char mdd_orphan_index_name[] = MDT_ORPHAN_DIR; static const char dotdot[] = ".."; enum { @@ -164,7 +164,7 @@ int mdd_orphan_insert(const struct lu_env *env, struct mdd_object *obj, LASSERT(mdd_write_locked(env, obj) != 0); LASSERT(!(obj->mod_flags & ORPHAN_OBJ)); - dt_write_lock(env, mdd->mdd_orphans, MOR_TGT_ORPHAN); + dt_write_lock(env, mdd->mdd_orphans, DT_TGT_ORPHAN); rc = mdd_orphan_insert_obj(env, mdd, obj, th); if (rc) @@ -210,13 +210,13 @@ int mdd_orphan_declare_delete(const struct lu_env *env, struct mdd_object *obj, if (rc) return rc; + if (!mdd_object_exists(obj)) + return -ENOENT; + rc = mdo_declare_ref_del(env, obj, th); if (rc) return rc; - if (!lu_object_exists(&obj->mod_obj.mo_lu)) - return -ENOENT; - if (S_ISDIR(mdd_object_type(obj))) { rc = mdo_declare_ref_del(env, obj, th); if (rc) @@ -244,7 +244,7 @@ int mdd_orphan_delete(const struct lu_env *env, struct mdd_object *obj, struct mdd_device *mdd = mdo2mdd(&obj->mod_obj); struct dt_object *dor = mdd->mdd_orphans; struct dt_key *key; - int rc; + int rc = 0; ENTRY; @@ -255,7 +255,10 @@ int mdd_orphan_delete(const struct lu_env *env, struct mdd_object *obj, LASSERT(dor); key = mdd_orphan_key_fill(env, mdo2fid(obj)); - dt_write_lock(env, mdd->mdd_orphans, MOR_TGT_ORPHAN); + dt_write_lock(env, mdd->mdd_orphans, DT_TGT_ORPHAN); + + if (OBD_FAIL_CHECK(OBD_FAIL_MDS_ORPHAN_DELETE)) + goto ref_del; rc = dt_delete(env, mdd->mdd_orphans, key, th); if (rc == -ENOENT) { @@ -263,6 +266,7 @@ int mdd_orphan_delete(const struct lu_env *env, struct mdd_object *obj, rc = dt_delete(env, mdd->mdd_orphans, key, th); } +ref_del: if (!rc) { /* lov objects will be destroyed by caller */ mdo_ref_del(env, obj, th); @@ -286,6 +290,7 @@ static int mdd_orphan_destroy(const struct lu_env *env, struct mdd_object *obj, { struct thandle *th = NULL; struct mdd_device *mdd = mdo2mdd(&obj->mod_obj); + bool orphan_exists = true; int rc = 0; ENTRY; @@ -298,23 +303,31 @@ static int mdd_orphan_destroy(const struct lu_env *env, struct mdd_object *obj, RETURN(rc); } + mdd_write_lock(env, obj, DT_TGT_CHILD); rc = mdd_orphan_declare_delete(env, obj, th); - if (rc) - GOTO(stop, rc); - - rc = mdo_declare_destroy(env, obj, th); - if (rc) - GOTO(stop, rc); + if (rc == -ENOENT) + orphan_exists = false; + else if (rc) + GOTO(unlock, rc); + + if (orphan_exists) { + rc = mdo_declare_destroy(env, obj, th); + if (rc) + GOTO(unlock, rc); + } rc = mdd_trans_start(env, mdd, th); if (rc) - GOTO(stop, rc); + GOTO(unlock, rc); - mdd_write_lock(env, obj, MOR_TGT_CHILD); if (likely(obj->mod_count == 0)) { - dt_write_lock(env, mdd->mdd_orphans, MOR_TGT_ORPHAN); + dt_write_lock(env, mdd->mdd_orphans, DT_TGT_ORPHAN); rc = dt_delete(env, mdd->mdd_orphans, key, th); - if (rc == 0) { + if (rc) { + CERROR("%s: could not delete orphan "DFID": rc = %d\n", + mdd2obd_dev(mdd)->obd_name, PFID(mdo2fid(obj)), + rc); + } else if (orphan_exists) { mdo_ref_del(env, obj, th); if (S_ISDIR(mdd_object_type(obj))) { mdo_ref_del(env, obj, th); @@ -322,15 +335,15 @@ static int mdd_orphan_destroy(const struct lu_env *env, struct mdd_object *obj, } rc = mdo_destroy(env, obj, th); } else { - CERROR("%s: could not delete orphan "DFID": rc = %d\n", - mdd2obd_dev(mdd)->obd_name, PFID(mdo2fid(obj)), - rc); + CWARN("%s: orphan %s "DFID" doesn't exist\n", + mdd2obd_dev(mdd)->obd_name, (char *)key, + PFID(mdo2fid(obj))); } dt_write_unlock(env, mdd->mdd_orphans); } +unlock: mdd_write_unlock(env, obj); -stop: rc = mdd_trans_stop(env, mdd, 0, th); RETURN(rc); @@ -362,11 +375,11 @@ static int mdd_orphan_key_test_and_delete(const struct lu_env *env, if (mdo->mod_count == 0) { CDEBUG(D_HA, "Found orphan "DFID", delete it\n", PFID(lf)); rc = mdd_orphan_destroy(env, mdo, key); - if (rc) /* so replay-single.sh test_37 works */ + if (rc) /* below message checked in replay-single.sh test_37 */ CERROR("%s: error unlinking orphan "DFID": rc = %d\n", mdd2obd_dev(mdd)->obd_name, PFID(lf), rc); } else { - mdd_write_lock(env, mdo, MOR_TGT_CHILD); + mdd_write_lock(env, mdo, DT_TGT_CHILD); if (likely(mdo->mod_count > 0)) { CDEBUG(D_HA, "Found orphan "DFID" count %d, skip it\n", PFID(lf), mdo->mod_count);