public inbox for netdev@vger.kernel.org 
 help / color / mirror / Atom feed
From: Petr Machata <petrm@nvidia•com>
To: Jakub Kicinski <kuba@kernel•org>
Cc: Petr Machata <petrm@nvidia•com>, <netdev@vger•kernel.org>,
	"David S. Miller" <davem@davemloft•net>,
	Ido Schimmel <idosch@nvidia•com>
Subject: Re: [PATCH net-next 1/3] netdevsim: Introduce support for L3 offload xstats
Date: Fri, 11 Mar 2022 10:18:39 +0100	[thread overview]
Message-ID: <87y21g96de.fsf@nvidia.com> (raw)
In-Reply-To: <20220310211301.477e323c@kicinski-fedora-pc1c0hjn.dhcp.thefacebook.com>


Jakub Kicinski <kuba@kernel•org> writes:

> On Thu, 10 Mar 2022 17:12:22 +0100 Petr Machata wrote:
>> +static ssize_t nsim_dev_hwstats_l3_enable_write(struct file *file,
>> +						const char __user *data,
>> +						size_t count, loff_t *ppos)
>> +{
>> +	return nsim_dev_hwstats_do_write(file, data, count, ppos,
>> +					 NSIM_DEV_HWSTATS_DO_ENABLE,
>> +					 NETDEV_OFFLOAD_XSTATS_TYPE_L3);
>> +}
>
> I think you could avoid having the three wrappers if you kept 
> separate fops and added a switch to the write function keying 
> on debugfs_real_fops().
>
> With that:
>
> Acked-by: Jakub Kicinski <kuba@kernel•org>

How about this?

struct nsim_dev_hwstats_fops {
	const struct file_operations fops;
	enum nsim_dev_hwstats_do action;
	enum netdev_offload_xstats_type type;
};

static ssize_t
nsim_dev_hwstats_do_write(struct file *file,
			  const char __user *data,
			  size_t count, loff_t *ppos)
{
	struct nsim_dev_hwstats *hwstats = file->private_data;
	struct nsim_dev_hwstats_fops *hwsfops;
	struct list_head *hwsdev_list;
	int ifindex;
	int err;

	hwsfops = container_of(debugfs_real_fops(file),
			       struct nsim_dev_hwstats_fops, fops);

	[...]

	switch (hwsfops->action) {
	case NSIM_DEV_HWSTATS_DO_DISABLE:
		err = nsim_dev_hwstats_disable_ifindex(hwstats, ifindex,
						       hwsfops->type,
						       hwsdev_list);
		break;
	[...]
}

const struct file_operations nsim_dev_hwstats_generic_fops = {
	.open = simple_open,
	.write = nsim_dev_hwstats_do_write,
	.llseek = generic_file_llseek,
	.owner = THIS_MODULE,
};

static const struct nsim_dev_hwstats_fops nsim_dev_hwstats_l3_disable_fops = {
	.fops = nsim_dev_hwstats_generic_fops,
	.action = NSIM_DEV_HWSTATS_DO_DISABLE,
	.type = NETDEV_OFFLOAD_XSTATS_TYPE_L3,
};

static const struct nsim_dev_hwstats_fops nsim_dev_hwstats_l3_enable_fops = {
	.fops = nsim_dev_hwstats_generic_fops,
	.action = NSIM_DEV_HWSTATS_DO_ENABLE,
	.type = NETDEV_OFFLOAD_XSTATS_TYPE_L3,
};

[...]

  reply	other threads:[~2022-03-11  9:38 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-10 16:12 [PATCH net-next 0/3] netdevsim: Support for L3 HW stats Petr Machata
2022-03-10 16:12 ` [PATCH net-next 1/3] netdevsim: Introduce support for L3 offload xstats Petr Machata
2022-03-11  5:13   ` Jakub Kicinski
2022-03-11  9:18     ` Petr Machata [this message]
2022-03-11 16:06       ` Jakub Kicinski
2022-03-11 16:07         ` Jakub Kicinski
2022-03-11 17:31           ` Petr Machata
2022-03-10 16:12 ` [PATCH net-next 2/3] selftests: netdevsim: hw_stats_l3: Add a new test Petr Machata
2022-03-10 16:12 ` [PATCH net-next 3/3] selftests: mlxsw: " Petr Machata

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87y21g96de.fsf@nvidia.com \
    --to=petrm@nvidia$(echo .)com \
    --cc=davem@davemloft$(echo .)net \
    --cc=idosch@nvidia$(echo .)com \
    --cc=kuba@kernel$(echo .)org \
    --cc=netdev@vger$(echo .)kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox