示例#1
0
static int lfsck_bookmark_init(const struct lu_env *env,
                               struct lfsck_instance *lfsck)
{
    struct lfsck_bookmark *mb = &lfsck->li_bookmark_ram;
    int rc;

    memset(mb, 0, sizeof(*mb));
    mb->lb_magic = LFSCK_BOOKMARK_MAGIC;
    mb->lb_version = LFSCK_VERSION_V2;
    mutex_lock(&lfsck->li_mutex);
    rc = lfsck_bookmark_store(env, lfsck);
    mutex_unlock(&lfsck->li_mutex);
    return rc;
}
示例#2
0
int lfsck_bookmark_setup(const struct lu_env *env,
			 struct lfsck_instance *lfsck)
{
	struct dt_object *root;
	struct dt_object *obj;
	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))) {
		lfsck_object_put(env, root);

		RETURN(-ENOTDIR);
	}

	obj = local_file_find_or_create(env, lfsck->li_los, root,
					LFSCK_BOOKMARK,
					S_IFREG | S_IRUGO | S_IWUSR);
	lfsck_object_put(env, root);
	if (IS_ERR(obj))
		RETURN(PTR_ERR(obj));

	lfsck->li_bookmark_obj = obj;
	rc = lfsck_bookmark_load(env, lfsck);
	if (rc == 0) {
		struct lfsck_bookmark *mb = &lfsck->li_bookmark_ram;

		/* It is upgraded from old release, set it as
		 * LFSCK_ASYNC_WIN_DEFAULT to avoid memory pressure. */
		if (unlikely(mb->lb_async_windows == 0)) {
			mb->lb_async_windows = LFSCK_ASYNC_WIN_DEFAULT;
			mutex_lock(&lfsck->li_mutex);
			rc = lfsck_bookmark_store(env, lfsck);
			mutex_unlock(&lfsck->li_mutex);
		}
	} else if (rc == -ENODATA) {
		rc = lfsck_bookmark_init(env, lfsck);
	}

	RETURN(rc);
}
示例#3
0
int lfsck_set_param(const struct lu_env *env, struct lfsck_instance *lfsck,
		    struct lfsck_start *start, bool reset)
{
	struct lfsck_bookmark	*bk	= &lfsck->li_bookmark_ram;
	int			 rc	= 0;
	bool			 dirty	= false;

	if (start == NULL) {
		LASSERT(reset);

		if (bk->lb_param & LPF_ALL_TGT) {
			bk->lb_param &= ~LPF_ALL_TGT;
			dirty = true;
		}

		if (bk->lb_param & LPF_CREATE_OSTOBJ) {
			bk->lb_param &= ~LPF_CREATE_OSTOBJ;
			dirty = true;
		}

		if (bk->lb_param & LPF_CREATE_MDTOBJ) {
			bk->lb_param &= ~LPF_CREATE_MDTOBJ;
			dirty = true;
		}

		if (bk->lb_param & LPF_FAILOUT) {
			bk->lb_param &= ~LPF_FAILOUT;
			dirty = true;
		}

		if (bk->lb_param & LPF_DRYRUN) {
			bk->lb_param &= ~LPF_DRYRUN;
			dirty = true;
		}

		if (bk->lb_param & LPF_OST_ORPHAN) {
			bk->lb_param &= ~LPF_OST_ORPHAN;
			dirty = true;
		}

		if (__lfsck_set_speed(lfsck, LFSCK_SPEED_NO_LIMIT))
			dirty = true;

		if (bk->lb_async_windows != LFSCK_ASYNC_WIN_DEFAULT) {
			bk->lb_async_windows = LFSCK_ASYNC_WIN_DEFAULT;
			dirty = true;
		}
	} else {
		if ((bk->lb_param & LPF_ALL_TGT) &&
		    !(start->ls_flags & LPF_ALL_TGT)) {
			bk->lb_param &= ~LPF_ALL_TGT;
			dirty = true;
		} else if (!(bk->lb_param & LPF_ALL_TGT) &&
			   (start->ls_flags & LPF_ALL_TGT)) {
			bk->lb_param |= LPF_ALL_TGT;
			dirty = true;
		}

		if ((start->ls_valid & LSV_CREATE_OSTOBJ) || reset) {
			if ((bk->lb_param & LPF_CREATE_OSTOBJ) &&
			    !(start->ls_valid & LSV_CREATE_OSTOBJ)) {
				bk->lb_param &= ~LPF_CREATE_OSTOBJ;
				dirty = true;
			} else if (!(bk->lb_param & LPF_CREATE_OSTOBJ) &&
				   (start->ls_flags & LPF_CREATE_OSTOBJ)) {
				bk->lb_param |= LPF_CREATE_OSTOBJ;
				dirty = true;
			}
		}

		if ((start->ls_valid & LSV_CREATE_MDTOBJ) || reset) {
			if ((bk->lb_param & LPF_CREATE_MDTOBJ) &&
			    !(start->ls_valid & LSV_CREATE_MDTOBJ)) {
				bk->lb_param &= ~LPF_CREATE_MDTOBJ;
				dirty = true;
			} else if (!(bk->lb_param & LPF_CREATE_MDTOBJ) &&
				   (start->ls_flags & LPF_CREATE_MDTOBJ)) {
				bk->lb_param |= LPF_CREATE_MDTOBJ;
				dirty = true;
			}
		}

		if ((start->ls_valid & LSV_ERROR_HANDLE) || reset) {
			if ((bk->lb_param & LPF_FAILOUT) &&
			    !(start->ls_valid & LSV_ERROR_HANDLE)) {
				bk->lb_param &= ~LPF_FAILOUT;
				dirty = true;
			} else if (!(start->ls_flags & LPF_FAILOUT) &&
				   (bk->lb_param & LPF_FAILOUT)) {
				bk->lb_param &= ~LPF_FAILOUT;
				dirty = true;
			}
		}

		if ((start->ls_valid & LSV_DRYRUN) || reset) {
			if ((bk->lb_param & LPF_DRYRUN) &&
			   !(start->ls_valid & LSV_DRYRUN)) {
				bk->lb_param &= ~LPF_DRYRUN;
				dirty = true;
			} else if (!(start->ls_flags & LPF_DRYRUN) &&
				   (bk->lb_param & LPF_DRYRUN)) {
				bk->lb_param &= ~LPF_DRYRUN;
				lfsck->li_drop_dryrun = 1;
				dirty = true;
			}
		}

		if ((bk->lb_param & LPF_OST_ORPHAN) &&
		    !(start->ls_flags & LPF_OST_ORPHAN)) {
			bk->lb_param &= ~LPF_OST_ORPHAN;
			dirty = true;
		} else if (!(bk->lb_param & LPF_OST_ORPHAN) &&
			   (start->ls_flags & LPF_OST_ORPHAN)) {
			bk->lb_param |= LPF_OST_ORPHAN;
			dirty = true;
		}

		if (start->ls_valid & LSV_SPEED_LIMIT) {
			if (__lfsck_set_speed(lfsck, start->ls_speed_limit))
				dirty = true;
		} else if (reset) {
			if (__lfsck_set_speed(lfsck, LFSCK_SPEED_NO_LIMIT))
				dirty = true;
		}

		if (start->ls_valid & LSV_ASYNC_WINDOWS) {
			if (start->ls_async_windows < 1 ||
			    start->ls_async_windows > LFSCK_ASYNC_WIN_MAX)
				return -EINVAL;

			if (bk->lb_async_windows != start->ls_async_windows) {
				bk->lb_async_windows = start->ls_async_windows;
				dirty = true;
			}
		} else if (reset &&
			   bk->lb_async_windows != LFSCK_ASYNC_WIN_DEFAULT) {
			bk->lb_async_windows = LFSCK_ASYNC_WIN_DEFAULT;
			dirty = true;
		}
	}

	if (dirty)
		rc = lfsck_bookmark_store(env, lfsck);

	return rc;
}