linux-nvme.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: hch@lst.de (Christoph Hellwig)
Subject: [RFC PATCH] nvmet: add support for ns write protect feature
Date: Tue, 17 Jul 2018 15:34:08 +0200	[thread overview]
Message-ID: <20180717133408.GB15079@lst.de> (raw)
In-Reply-To: <20180710035424.29088-1-chaitanya.kulkarni@wdc.com>


> +int nvmet_ns_is_wp(struct nvmet_ns *ns)
> +{
> +	switch (ns->wp_state) {
> +	case NVME_NS_NO_WRITE_PROTECT:
> +		return 0;
> +	case NVME_NS_WRITE_PROTECT:
> +		return 1;
> +	}
> +	WARN_ON("invalid ns write protect state");
> +	return -1;

I'd much rather have a

	'bool		readonly'

flag in nvmet_ns and then we don't need this helper.

> +bool nvmet_ns_wp_cmd_allow(struct nvmet_req *req)
> +{
> +	bool ret = false;
> +
> +	switch (req->cmd->common.opcode) {
> +	case nvme_cmd_dsm: /* allow DSM ? */

don't think so, at least for discards.

> +	case nvme_cmd_read:
> +	case nvme_cmd_flush:
> +		/* fall thru */
> +		ret = true;
> +		goto out;
> +	}

I think we need separate helpers here for the I/O vs admin queues
as the opcodes can theoretically overlap.  

Also instead of the goto you can just return directly here.

>  {
>  	u32 len = le16_to_cpu(cmd->get_log_page.numdu);
> @@ -140,7 +198,7 @@ static void nvmet_execute_get_log_cmd_effects_ns(struct nvmet_req *req)
>  	log->acs[nvme_admin_get_log_page]	= cpu_to_le32(1 << 0);
>  	log->acs[nvme_admin_identify]		= cpu_to_le32(1 << 0);
>  	log->acs[nvme_admin_abort_cmd]		= cpu_to_le32(1 << 0);
> -	log->acs[nvme_admin_set_features]	= cpu_to_le32(1 << 0);
> +	log->acs[nvme_admin_set_features]	= cpu_to_le32(1 << 16 | 1 << 0);

This looks unrelated?

> @@ -342,6 +402,8 @@ static void nvmet_execute_identify_ns(struct nvmet_req *req)
>  
>  	id->lbaf[0].ds = ns->blksize_shift;
>  
> +	id->nsattr = nvmet_ns_is_wp(ns);

Please do something like:

	if (ns->readonly)
		id->nsattr |= (1 << 0);

to make the code a little more obvious.

> +	if (nvmet_ns_is_wp(req->ns) && !nvmet_ns_wp_cmd_allow(req))
> +		return NVME_SC_NS_WRITE_PROTECTED;

I think this wants an unlikely annotation.

Btw, a patch for the host to look at nsattr and set the linux gendisk
readonly would also be very helpful!

      reply	other threads:[~2018-07-17 13:34 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-10  3:54 [RFC PATCH] nvmet: add support for ns write protect feature Chaitanya Kulkarni
2018-07-17 13:34 ` Christoph Hellwig [this message]

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=20180717133408.GB15079@lst.de \
    --to=hch@lst.de \
    /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
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;
as well as URLs for NNTP newsgroup(s).