Util-Linux Archive on lore.kernel.org
 help / color / Atom feed
From: Karel Zak <kzak@redhat.com>
To: Damien Le Moal <damien.lemoal@wdc.com>
Cc: util-linux@vger.kernel.org,
	Benno Schulenberg <bensberg@justemail.net>,
	Aravind Ramesh <Aravind.Ramesh@wdc.com>,
	Hans Holmnerg <Hans.Holmberg@wdc.com>
Subject: Re: [PATCH v2] blkzone: add open/close/finish commands
Date: Wed, 25 Mar 2020 12:36:04 +0100
Message-ID: <20200325113604.j7qlb7zdzm2azxjm@ws.net.home> (raw)
In-Reply-To: <20200324100217.47549-1-damien.lemoal@wdc.com>

On Tue, Mar 24, 2020 at 07:02:17PM +0900, Damien Le Moal wrote:
>  sys-utils/blkzone.8 | 27 +++++++++++++++--
>  sys-utils/blkzone.c | 74 ++++++++++++++++++++++++++++++++++++++++-----
>  2 files changed, 91 insertions(+), 10 deletions(-)

Applied, thanks.

>  static const struct blkzone_command commands[] = {
>  	{ "report",	blkzone_report, N_("Report zone information about the given device") },
> -	{ "reset",	blkzone_reset,  N_("Reset a range of zones.") }
> +	{ "reset",	blkzone_action, N_("Reset a range of zones.") },
> +	{ "open",	blkzone_action, N_("Open a range of zones.") },
> +	{ "close",	blkzone_action, N_("Close a range of zones.") },
> +	{ "finish",	blkzone_action, N_("Set a range of zones to Full.") }
> +};
> +
> +/*
> + * The action values must match the command index in the command array.
> + */
> +enum blkzone_action {
> +	BLK_ZONE_NO_ACTION = 0,
> +	BLK_ZONE_RESET,
> +	BLK_ZONE_OPEN,
> +	BLK_ZONE_CLOSE,
> +	BLK_ZONE_FINISH,
>  };

If you add ioctl_cmd and ioctl_name to the struct blkzone_command,
and you define commands[] as:

 commands[] = {
    { 
        .name = "report",
        .handler = blkzone_report,
        .help = N_("Report zone information about the given device") 
    },{
        .name = "reset",
        .handler = blkzone_action,
        .help = N_("Reset a range of zones."),
        .ioctl_cmd = BLKRESETZONE,
        .ioctl_name = "BLKRESETZONE"
    },
    ...
 };

than you do not need this switch() and command_action()

>  
> +	switch (command_action(ctl->command)) {
> +	case BLK_ZONE_RESET:
> +		ioctl_cmd = BLKRESETZONE;
> +		ioctl_name = "BLKRESETZONE";
> +		break;
> +	case BLK_ZONE_OPEN:
> +		ioctl_cmd = BLKOPENZONE;
> +		ioctl_name = "BLKOPENZONE";
> +		break;
> +	case BLK_ZONE_CLOSE:
> +		ioctl_cmd = BLKCLOSEZONE;
> +		ioctl_name = "BLKCLOSEZONE";
> +		break;
> +	case BLK_ZONE_FINISH:
> +		ioctl_cmd = BLKFINISHZONE;
> +		ioctl_name = "BLKFINISHZONE";
> +		break;
> +	case BLK_ZONE_NO_ACTION:
> +		/* fallthrough */
> +	default:
> +		errx(EXIT_FAILURE, _("Invalid zone action"));
  
but you can use ctl->command.ioclt_cmd  etc.

Just idea :-)

 Karel

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com


  reply index

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-24 10:02 Damien Le Moal
2020-03-25 11:36 ` Karel Zak [this message]
2020-03-25 11:37   ` Damien Le Moal
2020-03-25 15:12   ` Damien Le Moal
2020-03-25 16:56     ` Karel Zak

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=20200325113604.j7qlb7zdzm2azxjm@ws.net.home \
    --to=kzak@redhat.com \
    --cc=Aravind.Ramesh@wdc.com \
    --cc=Hans.Holmberg@wdc.com \
    --cc=bensberg@justemail.net \
    --cc=damien.lemoal@wdc.com \
    --cc=util-linux@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Util-Linux Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/util-linux/0 util-linux/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 util-linux util-linux/ https://lore.kernel.org/util-linux \
		util-linux@vger.kernel.org
	public-inbox-index util-linux

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.util-linux


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git