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);
}
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;
if (IS_ERR(root))
RETURN(PTR_ERR(root));
- dt_try_as_dir(env, 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) {
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)
struct lfsck_component *com)
{
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;
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);
{
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;
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);
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;
__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);
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);
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 (IS_ERR(root))
GOTO(out, rc = PTR_ERR(root));
- dt_try_as_dir(env, 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,
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;
}