* Author: Fan, Yong <fan.yong@intel.com>
*/
-#ifndef EXPORT_SYMTAB
-# define EXPORT_SYMTAB
-#endif
#define DEBUG_SUBSYSTEM S_LFSCK
#include <lustre/lustre_idl.h>
#include <lu_object.h>
#include <dt_object.h>
+#include <md_object.h>
#include <lustre_linkea.h>
#include <lustre_fid.h>
#include <lustre_lib.h>
static const char lfsck_namespace_name[] = "lfsck_namespace";
-static void lfsck_namespace_le_to_cpu(struct lfsck_namespace *des,
+static void lfsck_namespace_le_to_cpu(struct lfsck_namespace *dst,
struct lfsck_namespace *src)
{
- des->ln_magic = le32_to_cpu(src->ln_magic);
- des->ln_status = le32_to_cpu(src->ln_status);
- des->ln_flags = le32_to_cpu(src->ln_flags);
- des->ln_success_count = le32_to_cpu(src->ln_success_count);
- des->ln_run_time_phase1 = le32_to_cpu(src->ln_run_time_phase1);
- des->ln_run_time_phase2 = le32_to_cpu(src->ln_run_time_phase2);
- des->ln_time_last_complete = le64_to_cpu(src->ln_time_last_complete);
- des->ln_time_latest_start = le64_to_cpu(src->ln_time_latest_start);
- des->ln_time_last_checkpoint =
+ dst->ln_magic = le32_to_cpu(src->ln_magic);
+ dst->ln_status = le32_to_cpu(src->ln_status);
+ dst->ln_flags = le32_to_cpu(src->ln_flags);
+ dst->ln_success_count = le32_to_cpu(src->ln_success_count);
+ dst->ln_run_time_phase1 = le32_to_cpu(src->ln_run_time_phase1);
+ dst->ln_run_time_phase2 = le32_to_cpu(src->ln_run_time_phase2);
+ dst->ln_time_last_complete = le64_to_cpu(src->ln_time_last_complete);
+ dst->ln_time_latest_start = le64_to_cpu(src->ln_time_latest_start);
+ dst->ln_time_last_checkpoint =
le64_to_cpu(src->ln_time_last_checkpoint);
- lfsck_position_le_to_cpu(&des->ln_pos_latest_start,
+ lfsck_position_le_to_cpu(&dst->ln_pos_latest_start,
&src->ln_pos_latest_start);
- lfsck_position_le_to_cpu(&des->ln_pos_last_checkpoint,
+ lfsck_position_le_to_cpu(&dst->ln_pos_last_checkpoint,
&src->ln_pos_last_checkpoint);
- lfsck_position_le_to_cpu(&des->ln_pos_first_inconsistent,
+ lfsck_position_le_to_cpu(&dst->ln_pos_first_inconsistent,
&src->ln_pos_first_inconsistent);
- des->ln_items_checked = le64_to_cpu(src->ln_items_checked);
- des->ln_items_repaired = le64_to_cpu(src->ln_items_repaired);
- des->ln_items_failed = le64_to_cpu(src->ln_items_failed);
- des->ln_dirs_checked = le64_to_cpu(src->ln_dirs_checked);
- des->ln_mlinked_checked = le64_to_cpu(src->ln_mlinked_checked);
- des->ln_objs_checked_phase2 = le64_to_cpu(src->ln_objs_checked_phase2);
- des->ln_objs_repaired_phase2 =
+ dst->ln_items_checked = le64_to_cpu(src->ln_items_checked);
+ dst->ln_items_repaired = le64_to_cpu(src->ln_items_repaired);
+ dst->ln_items_failed = le64_to_cpu(src->ln_items_failed);
+ dst->ln_dirs_checked = le64_to_cpu(src->ln_dirs_checked);
+ dst->ln_mlinked_checked = le64_to_cpu(src->ln_mlinked_checked);
+ dst->ln_objs_checked_phase2 = le64_to_cpu(src->ln_objs_checked_phase2);
+ dst->ln_objs_repaired_phase2 =
le64_to_cpu(src->ln_objs_repaired_phase2);
- des->ln_objs_failed_phase2 = le64_to_cpu(src->ln_objs_failed_phase2);
- des->ln_objs_nlink_repaired = le64_to_cpu(src->ln_objs_nlink_repaired);
- des->ln_objs_lost_found = le64_to_cpu(src->ln_objs_lost_found);
- fid_le_to_cpu(&des->ln_fid_latest_scanned_phase2,
+ dst->ln_objs_failed_phase2 = le64_to_cpu(src->ln_objs_failed_phase2);
+ dst->ln_objs_nlink_repaired = le64_to_cpu(src->ln_objs_nlink_repaired);
+ dst->ln_objs_lost_found = le64_to_cpu(src->ln_objs_lost_found);
+ fid_le_to_cpu(&dst->ln_fid_latest_scanned_phase2,
&src->ln_fid_latest_scanned_phase2);
+ dst->ln_dirent_repaired = le64_to_cpu(src->ln_dirent_repaired);
+ dst->ln_linkea_repaired = le64_to_cpu(src->ln_linkea_repaired);
}
-static void lfsck_namespace_cpu_to_le(struct lfsck_namespace *des,
+static void lfsck_namespace_cpu_to_le(struct lfsck_namespace *dst,
struct lfsck_namespace *src)
{
- des->ln_magic = cpu_to_le32(src->ln_magic);
- des->ln_status = cpu_to_le32(src->ln_status);
- des->ln_flags = cpu_to_le32(src->ln_flags);
- des->ln_success_count = cpu_to_le32(src->ln_success_count);
- des->ln_run_time_phase1 = cpu_to_le32(src->ln_run_time_phase1);
- des->ln_run_time_phase2 = cpu_to_le32(src->ln_run_time_phase2);
- des->ln_time_last_complete = cpu_to_le64(src->ln_time_last_complete);
- des->ln_time_latest_start = cpu_to_le64(src->ln_time_latest_start);
- des->ln_time_last_checkpoint =
+ dst->ln_magic = cpu_to_le32(src->ln_magic);
+ dst->ln_status = cpu_to_le32(src->ln_status);
+ dst->ln_flags = cpu_to_le32(src->ln_flags);
+ dst->ln_success_count = cpu_to_le32(src->ln_success_count);
+ dst->ln_run_time_phase1 = cpu_to_le32(src->ln_run_time_phase1);
+ dst->ln_run_time_phase2 = cpu_to_le32(src->ln_run_time_phase2);
+ dst->ln_time_last_complete = cpu_to_le64(src->ln_time_last_complete);
+ dst->ln_time_latest_start = cpu_to_le64(src->ln_time_latest_start);
+ dst->ln_time_last_checkpoint =
cpu_to_le64(src->ln_time_last_checkpoint);
- lfsck_position_cpu_to_le(&des->ln_pos_latest_start,
+ lfsck_position_cpu_to_le(&dst->ln_pos_latest_start,
&src->ln_pos_latest_start);
- lfsck_position_cpu_to_le(&des->ln_pos_last_checkpoint,
+ lfsck_position_cpu_to_le(&dst->ln_pos_last_checkpoint,
&src->ln_pos_last_checkpoint);
- lfsck_position_cpu_to_le(&des->ln_pos_first_inconsistent,
+ lfsck_position_cpu_to_le(&dst->ln_pos_first_inconsistent,
&src->ln_pos_first_inconsistent);
- des->ln_items_checked = cpu_to_le64(src->ln_items_checked);
- des->ln_items_repaired = cpu_to_le64(src->ln_items_repaired);
- des->ln_items_failed = cpu_to_le64(src->ln_items_failed);
- des->ln_dirs_checked = cpu_to_le64(src->ln_dirs_checked);
- des->ln_mlinked_checked = cpu_to_le64(src->ln_mlinked_checked);
- des->ln_objs_checked_phase2 = cpu_to_le64(src->ln_objs_checked_phase2);
- des->ln_objs_repaired_phase2 =
+ dst->ln_items_checked = cpu_to_le64(src->ln_items_checked);
+ dst->ln_items_repaired = cpu_to_le64(src->ln_items_repaired);
+ dst->ln_items_failed = cpu_to_le64(src->ln_items_failed);
+ dst->ln_dirs_checked = cpu_to_le64(src->ln_dirs_checked);
+ dst->ln_mlinked_checked = cpu_to_le64(src->ln_mlinked_checked);
+ dst->ln_objs_checked_phase2 = cpu_to_le64(src->ln_objs_checked_phase2);
+ dst->ln_objs_repaired_phase2 =
cpu_to_le64(src->ln_objs_repaired_phase2);
- des->ln_objs_failed_phase2 = cpu_to_le64(src->ln_objs_failed_phase2);
- des->ln_objs_nlink_repaired = cpu_to_le64(src->ln_objs_nlink_repaired);
- des->ln_objs_lost_found = cpu_to_le64(src->ln_objs_lost_found);
- fid_cpu_to_le(&des->ln_fid_latest_scanned_phase2,
+ dst->ln_objs_failed_phase2 = cpu_to_le64(src->ln_objs_failed_phase2);
+ dst->ln_objs_nlink_repaired = cpu_to_le64(src->ln_objs_nlink_repaired);
+ dst->ln_objs_lost_found = cpu_to_le64(src->ln_objs_lost_found);
+ fid_cpu_to_le(&dst->ln_fid_latest_scanned_phase2,
&src->ln_fid_latest_scanned_phase2);
+ dst->ln_dirent_repaired = cpu_to_le64(src->ln_dirent_repaired);
+ dst->ln_linkea_repaired = cpu_to_le64(src->ln_linkea_repaired);
}
/**
lfsck_namespace_le_to_cpu(ns,
(struct lfsck_namespace *)com->lc_file_disk);
if (ns->ln_magic != LFSCK_NAMESPACE_MAGIC) {
- CWARN("%.16s: invalid lfsck_namespace magic "
- "0x%x != 0x%x\n",
- lfsck_lfsck2name(com->lc_lfsck),
- ns->ln_magic, LFSCK_NAMESPACE_MAGIC);
+ CWARN("%s: invalid lfsck_namespace magic %#x != %#x\n",
+ lfsck_lfsck2name(com->lc_lfsck), ns->ln_magic,
+ LFSCK_NAMESPACE_MAGIC);
rc = 1;
} else {
rc = 0;
}
} else if (rc != -ENODATA) {
- CERROR("%.16s: fail to load lfsck_namespace, expected = %d, "
+ CERROR("%s: fail to load lfsck_namespace: expected = %d, "
"rc = %d\n", lfsck_lfsck2name(com->lc_lfsck), len, rc);
if (rc >= 0)
rc = 1;
handle = dt_trans_create(env, lfsck->li_bottom);
if (IS_ERR(handle)) {
rc = PTR_ERR(handle);
- CERROR("%.16s: fail to create trans for storing "
- "lfsck_namespace: %d\n,", lfsck_lfsck2name(lfsck), rc);
+ CERROR("%s: fail to create trans for storing lfsck_namespace: "
+ "rc = %d\n", lfsck_lfsck2name(lfsck), rc);
RETURN(rc);
}
lfsck_buf_get(env, com->lc_file_disk, len),
XATTR_NAME_LFSCK_NAMESPACE, 0, handle);
if (rc != 0) {
- CERROR("%.16s: fail to declare trans for storing "
- "lfsck_namespace: %d\n,", lfsck_lfsck2name(lfsck), rc);
+ CERROR("%s: fail to declare trans for storing lfsck_namespace: "
+ "rc = %d\n", lfsck_lfsck2name(lfsck), rc);
GOTO(out, rc);
}
rc = dt_trans_start_local(env, lfsck->li_bottom, handle);
if (rc != 0) {
- CERROR("%.16s: fail to start trans for storing "
- "lfsck_namespace: %d\n,", lfsck_lfsck2name(lfsck), rc);
+ CERROR("%s: fail to start trans for storing lfsck_namespace: "
+ "rc = %d\n", lfsck_lfsck2name(lfsck), rc);
GOTO(out, rc);
}
init ? LU_XATTR_CREATE : LU_XATTR_REPLACE,
handle, BYPASS_CAPA);
if (rc != 0)
- CERROR("%.16s: fail to store lfsck_namespace, len = %d, "
+ CERROR("%s: fail to store lfsck_namespace: len = %d, "
"rc = %d\n", lfsck_lfsck2name(lfsck), len, rc);
GOTO(out, rc);
static int lfsck_namespace_init(const struct lu_env *env,
struct lfsck_component *com)
{
- struct lfsck_namespace *ns = (struct lfsck_namespace *)com->lc_file_ram;
+ struct lfsck_namespace *ns = com->lc_file_ram;
int rc;
memset(ns, 0, sizeof(*ns));
rc = dt_delete(env, obj, (const struct dt_key *)key, handle,
BYPASS_CAPA);
if (rc != 0) {
- CERROR("%s: fail to insert "DFID", rc = %d\n",
+ CERROR("%s: fail to insert "DFID": rc = %d\n",
lfsck_lfsck2name(com->lc_lfsck), PFID(fid), rc);
GOTO(out, rc);
}
ldata->ld_buf =
lu_buf_check_and_alloc(&lfsck_env_info(env)->lti_linkea_buf,
- CFS_PAGE_SIZE);
+ PAGE_CACHE_SIZE);
if (ldata->ld_buf->lb_buf == NULL)
return -ENOMEM;
struct lu_fid *cfid = &info->lti_fid2;
struct lfsck_instance *lfsck = com->lc_lfsck;
struct lfsck_bookmark *bk = &lfsck->li_bookmark_ram;
- struct lfsck_namespace *ns =
- (struct lfsck_namespace *)com->lc_file_ram;
+ struct lfsck_namespace *ns = com->lc_file_ram;
struct linkea_data ldata = { 0 };
struct thandle *handle = NULL;
bool locked = false;
if (rc == 0 && !lfsck_is_dead_obj(child) &&
ldata.ld_leh != NULL &&
ldata.ld_leh->leh_reccount != la->la_nlink)
- CWARN("%.16s: the object "DFID" linkEA entry count %u "
+ CWARN("%s: the object "DFID" linkEA entry count %u "
"may not match its hardlink count %u\n",
lfsck_lfsck2name(lfsck), PFID(cfid),
ldata.ld_leh->leh_reccount, la->la_nlink);
struct lfsck_component *com, bool init)
{
struct lfsck_instance *lfsck = com->lc_lfsck;
- struct lfsck_namespace *ns =
- (struct lfsck_namespace *)com->lc_file_ram;
+ struct lfsck_namespace *ns = com->lc_file_ram;
+ struct dt_object *root;
struct dt_object *dto;
int rc;
ENTRY;
+ root = dt_locate(env, lfsck->li_bottom, &lfsck->li_local_root_fid);
+ if (IS_ERR(root))
+ RETURN(PTR_ERR(root));
+
+ if (unlikely(!dt_try_as_dir(env, root))) {
+ lu_object_put(env, &root->do_lu);
+ RETURN(-ENOTDIR);
+ }
+
down_write(&com->lc_sem);
if (init) {
memset(ns, 0, sizeof(*ns));
ns->ln_magic = LFSCK_NAMESPACE_MAGIC;
ns->ln_status = LS_INIT;
- rc = local_object_unlink(env, lfsck->li_bottom, lfsck->li_local_root,
+ rc = local_object_unlink(env, lfsck->li_bottom, root,
lfsck_namespace_name);
if (rc != 0)
GOTO(out, rc);
- dto = local_index_find_or_create(env, lfsck->li_los, lfsck->li_local_root,
+ lfsck_object_put(env, com->lc_obj);
+ com->lc_obj = NULL;
+ dto = local_index_find_or_create(env, lfsck->li_los, root,
lfsck_namespace_name,
S_IFREG | S_IRUGO | S_IWUSR,
&dt_lfsck_features);
out:
up_write(&com->lc_sem);
+ lu_object_put(env, &root->do_lu);
return rc;
}
lfsck_namespace_fail(const struct lu_env *env, struct lfsck_component *com,
bool new_checked)
{
- struct lfsck_namespace *ns = (struct lfsck_namespace *)com->lc_file_ram;
+ struct lfsck_namespace *ns = com->lc_file_ram;
down_write(&com->lc_sem);
if (new_checked)
struct lfsck_component *com, bool init)
{
struct lfsck_instance *lfsck = com->lc_lfsck;
- struct lfsck_namespace *ns =
- (struct lfsck_namespace *)com->lc_file_ram;
+ struct lfsck_namespace *ns = com->lc_file_ram;
int rc;
if (com->lc_new_checked == 0 && !init)
}
static int lfsck_namespace_prep(const struct lu_env *env,
- struct lfsck_component *com)
+ struct lfsck_component *com,
+ struct lfsck_start_param *lsp)
{
struct lfsck_instance *lfsck = com->lc_lfsck;
- struct lfsck_namespace *ns =
- (struct lfsck_namespace *)com->lc_file_ram;
+ struct lfsck_namespace *ns = com->lc_file_ram;
struct lfsck_position *pos = &com->lc_pos_start;
if (ns->ln_status == LS_COMPLETED) {
struct lu_attr *la = &info->lti_la;
struct lfsck_instance *lfsck = com->lc_lfsck;
struct lfsck_bookmark *bk = &lfsck->li_bookmark_ram;
- struct lfsck_namespace *ns =
- (struct lfsck_namespace *)com->lc_file_ram;
+ struct lfsck_namespace *ns = com->lc_file_ram;
struct linkea_data ldata = { 0 };
- const struct lu_fid *pfid =
- lu_object_fid(&lfsck->li_obj_dir->do_lu);
+ const struct lu_fid *pfid = lfsck_dto2fid(lfsck->li_obj_dir);
const struct lu_fid *cfid = lfsck_dto2fid(obj);
const struct lu_name *cname;
struct thandle *handle = NULL;
if (ent->lde_attrs & LUDA_UPGRADE) {
ns->ln_flags |= LF_UPGRADE;
+ ns->ln_dirent_repaired++;
repaired = true;
} else if (ent->lde_attrs & LUDA_REPAIR) {
ns->ln_flags |= LF_INCONSISTENT;
+ ns->ln_dirent_repaired++;
repaired = true;
}
nodata:
if (bk->lb_param & LPF_DRYRUN) {
+ ns->ln_linkea_repaired++;
repaired = true;
goto record;
}
GOTO(stop, rc);
count = ldata.ld_leh->leh_reccount;
+ ns->ln_linkea_repaired++;
repaired = true;
} else {
GOTO(stop, rc);
if (!(bk->lb_param & LPF_FAILOUT))
rc = 0;
} else {
- if (repaired)
+ if (repaired) {
ns->ln_items_repaired++;
- else
+ if (bk->lb_param & LPF_DRYRUN &&
+ lfsck_pos_is_zero(&ns->ln_pos_first_inconsistent))
+ lfsck_pos_fill(env, lfsck,
+ &ns->ln_pos_first_inconsistent,
+ false);
+ } else {
com->lc_journal = 0;
+ }
rc = 0;
}
up_write(&com->lc_sem);
int result, bool init)
{
struct lfsck_instance *lfsck = com->lc_lfsck;
- struct lfsck_namespace *ns =
- (struct lfsck_namespace *)com->lc_file_ram;
+ struct lfsck_namespace *ns = com->lc_file_ram;
int rc;
down_write(&com->lc_sem);
cfs_list_del_init(&com->lc_link_dir);
cfs_list_add_tail(&com->lc_link, &lfsck->li_list_double_scan);
} else if (result == 0) {
- if (lfsck->li_paused) {
- ns->ln_status = LS_PAUSED;
- } else {
+ ns->ln_status = lfsck->li_status;
+ if (ns->ln_status == 0)
ns->ln_status = LS_STOPPED;
+ if (ns->ln_status != LS_PAUSED) {
cfs_list_del_init(&com->lc_link);
cfs_list_del_init(&com->lc_link_dir);
cfs_list_add_tail(&com->lc_link, &lfsck->li_list_idle);
{
struct lfsck_instance *lfsck = com->lc_lfsck;
struct lfsck_bookmark *bk = &lfsck->li_bookmark_ram;
- struct lfsck_namespace *ns =
- (struct lfsck_namespace *)com->lc_file_ram;
+ struct lfsck_namespace *ns = com->lc_file_ram;
int save = len;
int ret = -ENOSPC;
int rc;
down_read(&com->lc_sem);
rc = snprintf(buf, len,
"name: lfsck_namespace\n"
- "magic: 0x%x\n"
+ "magic: %#x\n"
"version: %d\n"
"status: %s\n",
ns->ln_magic,
bk->lb_version,
- lfsck_status_names[ns->ln_status]);
+ lfsck_status2names(ns->ln_status));
if (rc <= 0)
goto out;
lfsck->li_time_last_checkpoint;
__u64 checked = ns->ln_items_checked + com->lc_new_checked;
__u64 speed = checked;
- __u64 new_checked = com->lc_new_checked * CFS_HZ;
+ __u64 new_checked = com->lc_new_checked * HZ;
__u32 rtime = ns->ln_run_time_phase1 +
cfs_duration_sec(duration + HALF_SEC);
"failed_phase2: "LPU64"\n"
"dirs: "LPU64"\n"
"M-linked: "LPU64"\n"
+ "dirent_repaired: "LPU64"\n"
+ "linkea_repaired: "LPU64"\n"
"nlinks_repaired: "LPU64"\n"
"lost_found: "LPU64"\n"
"success_count: %u\n"
ns->ln_objs_failed_phase2,
ns->ln_dirs_checked,
ns->ln_mlinked_checked,
+ ns->ln_dirent_repaired,
+ ns->ln_linkea_repaired,
ns->ln_objs_nlink_repaired,
ns->ln_objs_lost_found,
ns->ln_success_count,
pos.lp_dir_cookie = 0;
} else {
pos.lp_dir_parent =
- *lu_object_fid(&lfsck->li_obj_dir->do_lu);
+ *lfsck_dto2fid(lfsck->li_obj_dir);
}
} else {
fid_zero(&pos.lp_dir_parent);
com->lc_new_checked;
__u64 speed1 = ns->ln_items_checked;
__u64 speed2 = checked;
- __u64 new_checked = com->lc_new_checked * CFS_HZ;
+ __u64 new_checked = com->lc_new_checked * HZ;
__u32 rtime = ns->ln_run_time_phase2 +
cfs_duration_sec(duration + HALF_SEC);
"failed_phase2: "LPU64"\n"
"dirs: "LPU64"\n"
"M-linked: "LPU64"\n"
+ "dirent_repaired: "LPU64"\n"
+ "linkea_repaired: "LPU64"\n"
"nlinks_repaired: "LPU64"\n"
"lost_found: "LPU64"\n"
"success_count: %u\n"
ns->ln_objs_failed_phase2,
ns->ln_dirs_checked,
ns->ln_mlinked_checked,
+ ns->ln_dirent_repaired,
+ ns->ln_linkea_repaired,
ns->ln_objs_nlink_repaired,
ns->ln_objs_lost_found,
ns->ln_success_count,
"failed_phase2: "LPU64"\n"
"dirs: "LPU64"\n"
"M-linked: "LPU64"\n"
+ "dirent_repaired: "LPU64"\n"
+ "linkea_repaired: "LPU64"\n"
"nlinks_repaired: "LPU64"\n"
"lost_found: "LPU64"\n"
"success_count: %u\n"
ns->ln_objs_failed_phase2,
ns->ln_dirs_checked,
ns->ln_mlinked_checked,
+ ns->ln_dirent_repaired,
+ ns->ln_linkea_repaired,
ns->ln_objs_nlink_repaired,
ns->ln_objs_lost_found,
ns->ln_success_count,
return ret;
}
-static int lfsck_namespace_double_scan(const struct lu_env *env,
- struct lfsck_component *com)
+static int lfsck_namespace_double_scan_main(void *args)
{
+ struct lfsck_thread_args *lta = args;
+ const struct lu_env *env = <a->lta_env;
+ struct lfsck_component *com = lta->lta_com;
struct lfsck_instance *lfsck = com->lc_lfsck;
struct ptlrpc_thread *thread = &lfsck->li_thread;
struct lfsck_bookmark *bk = &lfsck->li_bookmark_ram;
- struct lfsck_namespace *ns =
- (struct lfsck_namespace *)com->lc_file_ram;
+ struct lfsck_namespace *ns = com->lc_file_ram;
struct dt_object *obj = com->lc_obj;
const struct dt_it_ops *iops = &obj->do_index_ops->dio_it;
struct dt_object *target;
struct dt_key *key;
struct lu_fid fid;
int rc;
- __u8 flags;
+ __u8 flags = 0;
ENTRY;
- lfsck->li_new_scanned = 0;
- lfsck->li_time_last_checkpoint = cfs_time_current();
- lfsck->li_time_next_checkpoint = lfsck->li_time_last_checkpoint +
+ com->lc_new_checked = 0;
+ com->lc_new_scanned = 0;
+ com->lc_time_last_checkpoint = cfs_time_current();
+ com->lc_time_next_checkpoint = com->lc_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));
+ GOTO(out, rc = PTR_ERR(di));
fid_cpu_to_be(&fid, &ns->ln_fid_latest_scanned_phase2);
rc = iops->get(env, di, (const struct dt_key *)&fid);
lfsck_object_put(env, target);
checkpoint:
- lfsck->li_new_scanned++;
com->lc_new_checked++;
+ com->lc_new_scanned++;
ns->ln_fid_latest_scanned_phase2 = fid;
if (rc > 0)
ns->ln_objs_repaired_phase2++;
if (rc < 0 && bk->lb_param & LPF_FAILOUT)
GOTO(put, rc);
- if (unlikely(cfs_time_beforeq(lfsck->li_time_next_checkpoint,
+ if (unlikely(cfs_time_beforeq(com->lc_time_next_checkpoint,
cfs_time_current())) &&
com->lc_new_checked != 0) {
down_write(&com->lc_sem);
ns->ln_run_time_phase2 +=
cfs_duration_sec(cfs_time_current() +
- HALF_SEC - lfsck->li_time_last_checkpoint);
+ HALF_SEC - com->lc_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;
if (rc != 0)
GOTO(put, rc);
- lfsck->li_time_last_checkpoint = cfs_time_current();
- lfsck->li_time_next_checkpoint =
- lfsck->li_time_last_checkpoint +
+ com->lc_time_last_checkpoint = cfs_time_current();
+ com->lc_time_next_checkpoint =
+ com->lc_time_last_checkpoint +
cfs_time_seconds(LFSCK_CHECKPOINT_INTERVAL);
}
- lfsck_control_speed(lfsck);
+ lfsck_control_speed_by_self(com);
if (unlikely(!thread_is_running(thread)))
GOTO(put, rc = 0);
fini:
iops->fini(env, di);
- down_write(&com->lc_sem);
+out:
+ down_write(&com->lc_sem);
ns->ln_run_time_phase2 += cfs_duration_sec(cfs_time_current() +
HALF_SEC - lfsck->li_time_last_checkpoint);
ns->ln_time_last_checkpoint = cfs_time_current_sec();
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_flags &= ~(LF_SCANNED_ONCE | LF_INCONSISTENT);
ns->ln_time_last_complete = ns->ln_time_last_checkpoint;
ns->ln_success_count++;
} else if (rc == 0) {
- if (lfsck->li_paused)
- ns->ln_status = LS_PAUSED;
- else
+ ns->ln_status = lfsck->li_status;
+ if (ns->ln_status == 0)
ns->ln_status = LS_STOPPED;
} else {
ns->ln_status = LS_FAILED;
}
- if (ns->ln_status != LS_PAUSED) {
- spin_lock(&lfsck->li_lock);
- cfs_list_del_init(&com->lc_link);
- cfs_list_add_tail(&com->lc_link, &lfsck->li_list_idle);
- spin_unlock(&lfsck->li_lock);
- }
-
rc = lfsck_namespace_store(env, com, false);
-
up_write(&com->lc_sem);
+ if (atomic_dec_and_test(&lfsck->li_double_scan_count))
+ wake_up_all(&thread->t_ctl_waitq);
+
+ lfsck_thread_args_fini(lta);
+
return rc;
}
+static int lfsck_namespace_double_scan(const struct lu_env *env,
+ struct lfsck_component *com)
+{
+ struct lfsck_instance *lfsck = com->lc_lfsck;
+ struct lfsck_namespace *ns = com->lc_file_ram;
+ struct lfsck_thread_args *lta;
+ long rc;
+ ENTRY;
+
+ if (unlikely(ns->ln_status != LS_SCANNING_PHASE2))
+ RETURN(0);
+
+ lta = lfsck_thread_args_init(lfsck, com, NULL);
+ if (IS_ERR(lta))
+ RETURN(PTR_ERR(lta));
+
+ atomic_inc(&lfsck->li_double_scan_count);
+ rc = PTR_ERR(kthread_run(lfsck_namespace_double_scan_main, lta,
+ "lfsck_namespace"));
+ if (IS_ERR_VALUE(rc)) {
+ CERROR("%s: cannot start LFSCK namespace thread: rc = %ld\n",
+ lfsck_lfsck2name(lfsck), rc);
+ atomic_dec(&lfsck->li_double_scan_count);
+ lfsck_thread_args_fini(lta);
+ } else {
+ rc = 0;
+ }
+
+ RETURN(rc);
+}
+
+static int lfsck_namespace_in_notify(const struct lu_env *env,
+ struct lfsck_component *com,
+ struct lfsck_request *lr)
+{
+ return 0;
+}
+
+static int lfsck_namespace_query(const struct lu_env *env,
+ struct lfsck_component *com)
+{
+ struct lfsck_namespace *ns = com->lc_file_ram;
+
+ return ns->ln_status;
+}
+
static struct lfsck_operations lfsck_namespace_ops = {
.lfsck_reset = lfsck_namespace_reset,
.lfsck_fail = lfsck_namespace_fail,
.lfsck_post = lfsck_namespace_post,
.lfsck_dump = lfsck_namespace_dump,
.lfsck_double_scan = lfsck_namespace_double_scan,
+ .lfsck_in_notify = lfsck_namespace_in_notify,
+ .lfsck_query = lfsck_namespace_query,
};
int lfsck_namespace_setup(const struct lu_env *env,
{
struct lfsck_component *com;
struct lfsck_namespace *ns;
+ struct dt_object *root = NULL;
struct dt_object *obj;
int rc;
ENTRY;
if (com->lc_file_disk == NULL)
GOTO(out, rc = -ENOMEM);
- obj = local_index_find_or_create(env, lfsck->li_los,
- lfsck->li_local_root,
+ root = dt_locate(env, lfsck->li_bottom, &lfsck->li_local_root_fid);
+ if (IS_ERR(root))
+ GOTO(out, rc = PTR_ERR(root));
+
+ if (unlikely(!dt_try_as_dir(env, root)))
+ GOTO(out, rc = -ENOTDIR);
+
+ obj = local_index_find_or_create(env, lfsck->li_los, root,
lfsck_namespace_name,
S_IFREG | S_IRUGO | S_IWUSR,
&dt_lfsck_features);
if (rc != 0)
GOTO(out, rc);
- ns = (struct lfsck_namespace *)com->lc_file_ram;
+ ns = com->lc_file_ram;
switch (ns->ln_status) {
case LS_INIT:
case LS_COMPLETED:
case LS_FAILED:
case LS_STOPPED:
+ spin_lock(&lfsck->li_lock);
cfs_list_add_tail(&com->lc_link, &lfsck->li_list_idle);
+ spin_unlock(&lfsck->li_lock);
break;
default:
- CERROR("%s: unknown lfsck_namespace status: %u\n",
+ CERROR("%s: unknown lfsck_namespace status: rc = %u\n",
lfsck_lfsck2name(lfsck), ns->ln_status);
/* fall through */
case LS_SCANNING_PHASE1:
/* fall through */
case LS_PAUSED:
case LS_CRASHED:
+ spin_lock(&lfsck->li_lock);
cfs_list_add_tail(&com->lc_link, &lfsck->li_list_scan);
cfs_list_add_tail(&com->lc_link_dir, &lfsck->li_list_dir);
+ spin_unlock(&lfsck->li_lock);
break;
}
GOTO(out, rc = 0);
out:
+ if (root != NULL && !IS_ERR(root))
+ lu_object_put(env, &root->do_lu);
if (rc != 0)
lfsck_component_cleanup(env, com);
return rc;