Re: [PATCH v12 20/31] fs/resctrl: Refactor mkdir_mondata_subdir()

From: Luck, Tony

Date: Mon Oct 27 2025 - 19:00:18 EST


On Thu, Oct 23, 2025 at 10:45:06AM -0700, Reinette Chatre wrote:
> > + sprintf(name, "mon_sub_%s_%02d", r->name, hdr->id);
> > + ckn = kernfs_create_dir(kn, name, parent_kn->mode, prgrp);
>
> Noting here that kn was created earlier with mode of parent_kn->mode. It thus looks to me like
> above can also be written as:
> ckn = kernfs_create_dir(kn, name, kn->mode, prgrp);
>
> The reason I mention this is that this patch adds a third copy of a very similar code snippet
> (kernfs_create_dir(), rdtgroup_kn_set_ugid(), mon_add_all_files()) that looks like a good
> candidate for a helper?

I looked at this. But the helper needs a lot of arguments to cover these
three cases. Something like:

static struct kernfs_node *make_and_fill_mondir(struct kernfs_node *parent_kn,
char *name, umode_t mode,
struct rdtgroup *prgrp,
struct rdt_domain_hdr *hdr,
struct rdt_resource *r,
int domid)
{
code here
}

A subset of this repeated pattern (just the kernfs_create_dir(),
rdtgroup_kn_set_ugid()) happens on every(?) mkdir. Perhaps a better helper (for
cleanup patch unrelated to this series) would build the rdtgroup_kn_set_ugid()
into a new rdtgroup_add_dir() helper?

-Tony