Commit 74bd8b7d authored by SeongJae Park's avatar SeongJae Park Committed by Andrew Morton

mm/damon/sysfs: move targets setup code to a separated function

This commit separates DAMON sysfs interface's monitoring context targets
setup code to a new function for better readability.

Link: https://lkml.kernel.org/r/20220429160606.127307-8-sj@kernel.orgSigned-off-by: default avatarSeongJae Park <sj@kernel.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
parent 0a890a9f
......@@ -2120,38 +2120,45 @@ static int damon_sysfs_set_regions(struct damon_target *t,
return 0;
}
static int damon_sysfs_set_targets(struct damon_ctx *ctx,
struct damon_sysfs_targets *sysfs_targets)
static int damon_sysfs_add_target(struct damon_sysfs_target *sys_target,
struct damon_ctx *ctx)
{
int i, err;
/* Multiple physical address space monitoring targets makes no sense */
if (ctx->ops.id == DAMON_OPS_PADDR && sysfs_targets->nr > 1)
return -EINVAL;
for (i = 0; i < sysfs_targets->nr; i++) {
struct damon_sysfs_target *sys_target =
sysfs_targets->targets_arr[i];
struct damon_target *t = damon_new_target();
int err = -EINVAL;
if (!t) {
damon_sysfs_destroy_targets(ctx);
if (!t)
return -ENOMEM;
}
if (ctx->ops.id == DAMON_OPS_VADDR ||
ctx->ops.id == DAMON_OPS_FVADDR) {
t->pid = find_get_pid(sys_target->pid);
if (!t->pid) {
damon_sysfs_destroy_targets(ctx);
return -EINVAL;
}
if (!t->pid)
goto destroy_targets_out;
}
damon_add_target(ctx, t);
err = damon_sysfs_set_regions(t, sys_target->regions);
if (err) {
if (err)
goto destroy_targets_out;
return 0;
destroy_targets_out:
damon_sysfs_destroy_targets(ctx);
return err;
}
}
static int damon_sysfs_set_targets(struct damon_ctx *ctx,
struct damon_sysfs_targets *sysfs_targets)
{
int i, err;
/* Multiple physical address space monitoring targets makes no sense */
if (ctx->ops.id == DAMON_OPS_PADDR && sysfs_targets->nr > 1)
return -EINVAL;
for (i = 0; i < sysfs_targets->nr; i++) {
err = damon_sysfs_add_target(
sysfs_targets->targets_arr[i], ctx);
if (err)
return err;
}
return 0;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment