struct dt_object *child = com->lc_obj;
struct dt_object *parent;
struct thandle *handle;
+ bool locked = false;
int rc;
ENTRY;
if (IS_ERR(parent))
RETURN(rc = PTR_ERR(parent));
- if (dt_try_as_dir(env, parent))
+ if (!dt_try_as_dir(env, parent))
GOTO(out, rc = -ENOTDIR);
handle = dt_trans_create(env, mdd->mdd_bottom);
if (rc != 0)
GOTO(stop, rc);
+ dt_write_lock(env, child, MOR_TGT_CHILD);
+ locked = true;
rc = dt_delete(env, parent, (struct dt_key *)lfsck_namespace_name,
handle, BYPASS_CAPA);
if (rc != 0)
rc = dt_destroy(env, child, handle);
+
+ GOTO(stop, rc);
+
+stop:
+ if (locked)
+ dt_write_unlock(env, child);
+
if (rc == 0) {
lu_object_put(env, &child->do_lu);
com->lc_obj = NULL;
}
- GOTO(stop, rc);
-
-stop:
dt_trans_stop(env, mdd->mdd_bottom, handle);
out:
return rc;
}
+static int mdd_lfsck_namespace_delete(const struct lu_env *env,
+ struct lfsck_component *com,
+ const struct lu_fid *fid)
+{
+ struct mdd_device *mdd = mdd_lfsck2mdd(com->lc_lfsck);
+ struct lu_fid *key = &mdd_env_info(env)->mti_fid;
+ struct thandle *handle;
+ struct dt_object *obj = com->lc_obj;
+ int rc;
+ ENTRY;
+
+ handle = dt_trans_create(env, mdd->mdd_bottom);
+ if (IS_ERR(handle))
+ RETURN(PTR_ERR(handle));
+
+ rc = dt_declare_delete(env, obj, (const struct dt_key *)fid, handle);
+ if (rc != 0)
+ GOTO(out, rc);
+
+ rc = dt_trans_start_local(env, mdd->mdd_bottom, handle);
+ if (rc != 0)
+ GOTO(out, rc);
+
+ fid_cpu_to_be(key, fid);
+ rc = dt_delete(env, obj, (const struct dt_key *)key, handle,
+ BYPASS_CAPA);
+
+ GOTO(out, rc);
+
+out:
+ dt_trans_stop(env, mdd->mdd_bottom, handle);
+ return rc;
+}
+
static int mdd_lfsck_namespace_update(const struct lu_env *env,
struct lfsck_component *com,
const struct lu_fid *fid,
return rc;
}
+/**
+ * \retval +ve repaired
+ * \retval 0 no need to repair
+ * \retval -ve error cases
+ */
+static int mdd_lfsck_namespace_double_scan_one(const struct lu_env *env,
+ struct lfsck_component *com,
+ struct mdd_object *child,
+ __u8 flags)
+{
+ struct mdd_thread_info *info = mdd_env_info(env);
+ struct lu_attr *la = &info->mti_la;
+ struct lu_name *cname = &info->mti_name;
+ struct lu_fid *pfid = &info->mti_fid;
+ struct lu_fid *cfid = &info->mti_fid2;
+ struct md_lfsck *lfsck = com->lc_lfsck;
+ struct mdd_device *mdd = mdd_lfsck2mdd(lfsck);
+ struct lfsck_bookmark *bk = &lfsck->ml_bookmark_ram;
+ struct lfsck_namespace *ns =
+ (struct lfsck_namespace *)com->lc_file_ram;
+ struct linkea_data ldata = { 0 };
+ struct thandle *handle = NULL;
+ bool locked = false;
+ bool update = false;
+ int count;
+ int rc;
+ ENTRY;
+
+ if (com->lc_journal) {
+
+again:
+ LASSERT(!locked);
+
+ com->lc_journal = 1;
+ handle = mdd_trans_create(env, mdd);
+ if (IS_ERR(handle))
+ RETURN(rc = PTR_ERR(handle));
+
+ rc = mdd_declare_links_add(env, child, handle, NULL);
+ if (rc != 0)
+ GOTO(stop, rc);
+
+ rc = mdd_trans_start(env, mdd, handle);
+ if (rc != 0)
+ GOTO(stop, rc);
+
+ mdd_write_lock(env, child, MOR_TGT_CHILD);
+ locked = true;
+ }
+
+ if (unlikely(mdd_is_dead_obj(child)))
+ GOTO(stop, rc = 0);
+
+ rc = mdd_links_read(env, child, &ldata);
+ if (rc != 0) {
+ if ((bk->lb_param & LPF_DRYRUN) &&
+ (rc == -EINVAL || rc == -ENODATA))
+ rc = 1;
+
+ GOTO(stop, rc);
+ }
+
+ rc = mdd_la_get(env, child, la, BYPASS_CAPA);
+ if (rc != 0)
+ GOTO(stop, rc);
+
+ ldata.ld_lee = LINKEA_FIRST_ENTRY(ldata);
+ count = ldata.ld_leh->leh_reccount;
+ while (count-- > 0) {
+ struct mdd_object *parent = NULL;
+ struct dt_object *dir;
+
+ linkea_entry_unpack(ldata.ld_lee, &ldata.ld_reclen, cname,
+ pfid);
+ if (!fid_is_sane(pfid))
+ goto shrink;
+
+ parent = mdd_object_find(env, mdd, pfid);
+ if (parent == NULL)
+ goto shrink;
+ else if (IS_ERR(parent))
+ GOTO(stop, rc = PTR_ERR(parent));
+
+ if (!mdd_object_exists(parent))
+ goto shrink;
+
+ /* XXX: need more processing for remote object in the future. */
+ if (mdd_object_remote(parent)) {
+ mdd_object_put(env, parent);
+ ldata.ld_lee = LINKEA_NEXT_ENTRY(ldata);
+ continue;
+ }
+
+ dir = mdd_object_child(parent);
+ if (unlikely(!dt_try_as_dir(env, dir)))
+ goto shrink;
+
+ /* To guarantee the 'name' is terminated with '0'. */
+ memcpy(info->mti_key, cname->ln_name, cname->ln_namelen);
+ info->mti_key[cname->ln_namelen] = 0;
+ cname->ln_name = info->mti_key;
+ rc = dt_lookup(env, dir, (struct dt_rec *)cfid,
+ (const struct dt_key *)cname->ln_name,
+ BYPASS_CAPA);
+ if (rc != 0 && rc != -ENOENT) {
+ mdd_object_put(env, parent);
+ GOTO(stop, rc);
+ }
+
+ if (rc == 0) {
+ if (lu_fid_eq(cfid, mdo2fid(child))) {
+ mdd_object_put(env, parent);
+ ldata.ld_lee = LINKEA_NEXT_ENTRY(ldata);
+ continue;
+ }
+
+ goto shrink;
+ }
+
+ if (ldata.ld_leh->leh_reccount > la->la_nlink)
+ goto shrink;
+
+ /* XXX: For the case of there is linkea entry, but without name
+ * entry pointing to the object, and the object link count
+ * isn't less than the count of name entries, then add the
+ * name entry back to namespace.
+ *
+ * It is out of LFSCK 1.5 scope, will implement it in the
+ * future. Keep the linkEA entry. */
+ mdd_object_put(env, parent);
+ ldata.ld_lee = LINKEA_NEXT_ENTRY(ldata);
+ continue;
+
+shrink:
+ if (parent != NULL)
+ mdd_object_put(env, parent);
+ if (bk->lb_param & LPF_DRYRUN)
+ RETURN(1);
+
+ CDEBUG(D_LFSCK, "Remove linkEA: "DFID"[%.*s], "DFID"\n",
+ PFID(mdo2fid(child)), cname->ln_namelen, cname->ln_name,
+ PFID(pfid));
+ linkea_del_buf(&ldata, cname);
+ update = true;
+ }
+
+ if (update) {
+ if (!com->lc_journal) {
+ com->lc_journal = 1;
+ goto again;
+ }
+
+ rc = mdd_links_write(env, child, &ldata, handle);
+ }
+
+ GOTO(stop, rc);
+
+stop:
+ if (locked)
+ mdd_write_unlock(env, child);
+
+ if (handle != NULL)
+ mdd_trans_stop(env, mdd, rc, handle);
+
+ if (rc == 0 && update) {
+ ns->ln_objs_nlink_repaired++;
+ rc = 1;
+ }
+ return rc;
+}
+
/* namespace APIs */
static int mdd_lfsck_namespace_reset(const struct lu_env *env,
return rc;
/* For insert new linkEA entry. */
- rc = mdd_declare_links_add(env, obj, handle);
+ rc = mdd_declare_links_add(env, obj, handle, NULL);
return rc;
}
struct lfsck_namespace *ns =
(struct lfsck_namespace *)com->lc_file_ram;
struct mdd_device *mdd = mdd_lfsck2mdd(lfsck);
- struct mdd_link_data ldata = { 0 };
+ struct linkea_data ldata = { 0 };
const struct lu_fid *pfid =
lu_object_fid(&lfsck->ml_obj_dir->do_lu);
const struct lu_fid *cfid = mdo2fid(obj);
rc = mdd_links_read(env, obj, &ldata);
if (rc == 0) {
- count = ldata.ml_leh->leh_reccount;
- rc = mdd_links_find(env, obj, &ldata, cname, pfid);
+ count = ldata.ld_leh->leh_reccount;
+ rc = linkea_links_find(&ldata, cname, pfid);
if (rc == 0) {
/* For dir, if there are more than one linkea entries,
* then remove all the other redundant linkea entries.*/
}
nodata:
- rc = mdd_links_new(env, &ldata);
+ rc = linkea_data_new(&ldata, &mdd_env_info(env)->mti_link_buf);
if (rc != 0)
GOTO(stop, rc);
if (!com->lc_journal)
goto again;
- rc = mdd_links_add_buf(env, &ldata, cname, pfid);
+ rc = linkea_add_buf(&ldata, cname, pfid);
if (rc != 0)
GOTO(stop, rc);
if (rc != 0)
GOTO(stop, rc);
- count = ldata.ml_leh->leh_reccount;
+ count = ldata.ld_leh->leh_reccount;
repaired = true;
} else {
GOTO(stop, rc);
return ret;
}
-/* XXX: to be implemented in other patch. */
static int mdd_lfsck_namespace_double_scan(const struct lu_env *env,
struct lfsck_component *com)
{
struct md_lfsck *lfsck = com->lc_lfsck;
+ struct ptlrpc_thread *thread = &lfsck->ml_thread;
+ struct mdd_device *mdd = mdd_lfsck2mdd(lfsck);
struct lfsck_bookmark *bk = &lfsck->ml_bookmark_ram;
struct lfsck_namespace *ns =
(struct lfsck_namespace *)com->lc_file_ram;
+ struct dt_object *obj = com->lc_obj;
+ const struct dt_it_ops *iops = &obj->do_index_ops->dio_it;
+ struct mdd_object *target;
+ struct dt_it *di;
+ struct dt_key *key;
+ struct lu_fid fid;
int rc;
+ __u8 flags;
+ ENTRY;
+ lfsck->ml_new_scanned = 0;
+ lfsck->ml_time_last_checkpoint = cfs_time_current();
+ lfsck->ml_time_next_checkpoint = lfsck->ml_time_last_checkpoint +
+ cfs_time_seconds(LFSCK_CHECKPOINT_INTERVAL);
+
+ di = iops->init(env, obj, 0, BYPASS_CAPA);
+ if (IS_ERR(di))
+ RETURN(PTR_ERR(di));
+
+ fid_cpu_to_be(&fid, &ns->ln_fid_latest_scanned_phase2);
+ rc = iops->get(env, di, (const struct dt_key *)&fid);
+ if (rc < 0)
+ GOTO(fini, rc);
+
+ /* Skip the start one, which either has been processed or non-exist. */
+ rc = iops->next(env, di);
+ if (rc != 0)
+ GOTO(put, rc);
+
+ if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_NO_DOUBLESCAN))
+ GOTO(put, rc = 0);
+
+ do {
+ if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_DELAY3) &&
+ cfs_fail_val > 0) {
+ struct l_wait_info lwi;
+
+ lwi = LWI_TIMEOUT(cfs_time_seconds(cfs_fail_val),
+ NULL, NULL);
+ l_wait_event(thread->t_ctl_waitq,
+ !thread_is_running(thread),
+ &lwi);
+ }
+
+ key = iops->key(env, di);
+ fid_be_to_cpu(&fid, (const struct lu_fid *)key);
+ target = mdd_object_find(env, mdd, &fid);
+ down_write(&com->lc_sem);
+ if (target == NULL) {
+ rc = 0;
+ goto checkpoint;
+ } else if (IS_ERR(target)) {
+ rc = PTR_ERR(target);
+ goto checkpoint;
+ }
+
+ /* XXX: need more processing for remote object in the future. */
+ if (!mdd_object_exists(target) || mdd_object_remote(target))
+ goto obj_put;
+
+ rc = iops->rec(env, di, (struct dt_rec *)&flags, 0);
+ if (rc == 0)
+ rc = mdd_lfsck_namespace_double_scan_one(env, com,
+ target, flags);
+
+obj_put:
+ mdd_object_put(env, target);
+
+checkpoint:
+ lfsck->ml_new_scanned++;
+ com->lc_new_checked++;
+ ns->ln_fid_latest_scanned_phase2 = fid;
+ if (rc > 0)
+ ns->ln_objs_repaired_phase2++;
+ else if (rc < 0)
+ ns->ln_objs_failed_phase2++;
+ up_write(&com->lc_sem);
+
+ if ((rc == 0) || ((rc > 0) && !(bk->lb_param & LPF_DRYRUN))) {
+ mdd_lfsck_namespace_delete(env, com, &fid);
+ } else if (rc < 0) {
+ flags |= LLF_REPAIR_FAILED;
+ mdd_lfsck_namespace_update(env, com, &fid, flags, true);
+ }
+
+ if (rc < 0 && bk->lb_param & LPF_FAILOUT)
+ GOTO(put, rc);
+
+ if (likely(cfs_time_beforeq(cfs_time_current(),
+ lfsck->ml_time_next_checkpoint)) ||
+ com->lc_new_checked == 0)
+ goto speed;
+
+ down_write(&com->lc_sem);
+ ns->ln_run_time_phase2 += cfs_duration_sec(cfs_time_current() +
+ HALF_SEC - lfsck->ml_time_last_checkpoint);
+ ns->ln_time_last_checkpoint = cfs_time_current_sec();
+ ns->ln_objs_checked_phase2 += com->lc_new_checked;
+ com->lc_new_checked = 0;
+ rc = mdd_lfsck_namespace_store(env, com, false);
+ up_write(&com->lc_sem);
+ if (rc != 0)
+ GOTO(put, rc);
+
+ lfsck->ml_time_last_checkpoint = cfs_time_current();
+ lfsck->ml_time_next_checkpoint = lfsck->ml_time_last_checkpoint +
+ cfs_time_seconds(LFSCK_CHECKPOINT_INTERVAL);
+
+speed:
+ mdd_lfsck_control_speed(lfsck);
+ if (unlikely(!thread_is_running(thread)))
+ GOTO(put, rc = 0);
+
+ rc = iops->next(env, di);
+ } while (rc == 0);
+
+ GOTO(put, rc);
+
+put:
+ iops->put(env, di);
+
+fini:
+ iops->fini(env, di);
down_write(&com->lc_sem);
+ ns->ln_run_time_phase2 += cfs_duration_sec(cfs_time_current() +
+ HALF_SEC - lfsck->ml_time_last_checkpoint);
ns->ln_time_last_checkpoint = cfs_time_current_sec();
+ ns->ln_objs_checked_phase2 += com->lc_new_checked;
com->lc_new_checked = 0;
- com->lc_journal = 0;
- ns->ln_status = LS_COMPLETED;
- if (!(bk->lb_param & LPF_DRYRUN))
- ns->ln_flags &=
- ~(LF_SCANNED_ONCE | LF_INCONSISTENT | LF_UPGRADE);
- ns->ln_time_last_complete = ns->ln_time_last_checkpoint;
- ns->ln_success_count++;
+ if (rc > 0) {
+ com->lc_journal = 0;
+ ns->ln_status = LS_COMPLETED;
+ if (!(bk->lb_param & LPF_DRYRUN))
+ ns->ln_flags &=
+ ~(LF_SCANNED_ONCE | LF_INCONSISTENT | LF_UPGRADE);
+ ns->ln_time_last_complete = ns->ln_time_last_checkpoint;
+ ns->ln_success_count++;
+ } else if (rc == 0) {
+ if (lfsck->ml_paused)
+ ns->ln_status = LS_PAUSED;
+ else
+ ns->ln_status = LS_STOPPED;
+ } else {
+ ns->ln_status = LS_FAILED;
+ }
- spin_lock(&lfsck->ml_lock);
- cfs_list_del_init(&com->lc_link);
- cfs_list_add_tail(&com->lc_link, &lfsck->ml_list_idle);
- spin_unlock(&lfsck->ml_lock);
+ if (ns->ln_status != LS_PAUSED) {
+ spin_lock(&lfsck->ml_lock);
+ cfs_list_del_init(&com->lc_link);
+ cfs_list_add_tail(&com->lc_link, &lfsck->ml_list_idle);
+ spin_unlock(&lfsck->ml_lock);
+ }
rc = mdd_lfsck_namespace_store(env, com, false);
else if (IS_ERR(obj))
return PTR_ERR(obj);
- /* XXX: need more processing for remote object in the future. */
- if (!mdd_object_exists(obj) || mdd_object_remote(obj)) {
+ if (!mdd_object_exists(obj)) {
mdd_object_put(env, obj);
return 0;
}
+ /* Currently, only client visible directory can be remote. */
+ if (mdd_object_remote(obj)) {
+ mdd_object_put(env, obj);
+ return 1;
+ }
+
depth++;
}
return 0;
/* Init otable-based iterator. */
if (pos == NULL) {
rc = iops->load(env, lfsck->ml_di_oit, 0);
- GOTO(out, rc = (rc >= 0 ? 0 : rc));
+ if (rc > 0) {
+ lfsck->ml_oit_over = 1;
+ rc = 0;
+ }
+
+ GOTO(out, rc);
}
rc = iops->load(env, lfsck->ml_di_oit, pos->lp_oit_cookie);
if (rc < 0)
GOTO(out, rc);
+ else if (rc > 0)
+ lfsck->ml_oit_over = 1;
if (fid_is_zero(&pos->lp_dir_parent))
GOTO(out, rc = 0);
&lwi);
}
+ if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_CRASH))
+ RETURN(0);
+
lfsck->ml_new_scanned++;
rc = iops->rec(env, di, (struct dt_rec *)fid, 0);
if (rc != 0) {
if (lfsck->ml_paused && cfs_list_empty(&lfsck->ml_list_scan))
oit_iops->put(&env, oit_di);
- rc = mdd_lfsck_post(&env, lfsck, rc);
+ if (!OBD_FAIL_CHECK(OBD_FAIL_LFSCK_CRASH))
+ rc = mdd_lfsck_post(&env, lfsck, rc);
if (lfsck->ml_di_dir != NULL)
mdd_lfsck_close_dir(&env, lfsck);
RETURN(-ENOTSUPP);
/* start == NULL means auto trigger paused LFSCK. */
- if (start == NULL && cfs_list_empty(&lfsck->ml_list_scan))
+ if ((start == NULL) &&
+ (cfs_list_empty(&lfsck->ml_list_scan) ||
+ OBD_FAIL_CHECK(OBD_FAIL_LFSCK_NO_AUTO)))
RETURN(0);
mutex_lock(&lfsck->ml_mutex);
struct l_wait_info lwi = { 0 };
ENTRY;
+ if (!lfsck->ml_initialized)
+ RETURN(0);
+
mutex_lock(&lfsck->ml_mutex);
spin_lock(&lfsck->ml_lock);
if (thread_is_init(thread) || thread_is_stopped(thread)) {