From: Klaus Jensen <its@irrelevant.dk>
To: Changqi Lu <luchangqi.123@bytedance.com>
Cc: qemu-block@nongnu.org, qemu-devel@nongnu.org, kwolf@redhat.com,
hreitz@redhat.com, stefanha@redhat.com, fam@euphon.net,
ronniesahlberg@gmail.com, pbonzini@redhat.com, pl@dlhnet.de,
kbusch@kernel.org, foss@defmacro.it, philmd@linaro.org,
pizhenwei@bytedance.com
Subject: Re: [PATCH v7 07/10] hw/nvme: add helper functions for converting reservation types
Date: Mon, 8 Jul 2024 10:18:37 +0200 [thread overview]
Message-ID: <Zoug3X2md0oskFu-@cormorant.local> (raw)
In-Reply-To: <20240705105614.3377694-8-luchangqi.123@bytedance.com>
[-- Attachment #1: Type: text/plain, Size: 4018 bytes --]
On Jul 5 18:56, Changqi Lu wrote:
> This commit introduces two helper functions
> that facilitate the conversion between the
> reservation types used in the NVME protocol
> and those used in the block layer.
>
> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
> Signed-off-by: Changqi Lu <luchangqi.123@bytedance.com>
> Signed-off-by: zhenwei pi <pizhenwei@bytedance.com>
> ---
> hw/nvme/nvme.h | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 84 insertions(+)
>
> diff --git a/hw/nvme/nvme.h b/hw/nvme/nvme.h
> index bed8191bd5..6d0e456348 100644
> --- a/hw/nvme/nvme.h
> +++ b/hw/nvme/nvme.h
> @@ -474,6 +474,90 @@ static inline const char *nvme_io_opc_str(uint8_t opc)
> }
> }
>
> +static inline NvmeResvType block_pr_type_to_nvme(BlockPrType type)
> +{
> + switch (type) {
> + case BLK_PR_WRITE_EXCLUSIVE:
> + return NVME_RESV_WRITE_EXCLUSIVE;
> + case BLK_PR_EXCLUSIVE_ACCESS:
> + return NVME_RESV_EXCLUSIVE_ACCESS;
> + case BLK_PR_WRITE_EXCLUSIVE_REGS_ONLY:
> + return NVME_RESV_WRITE_EXCLUSIVE_REGS_ONLY;
> + case BLK_PR_EXCLUSIVE_ACCESS_REGS_ONLY:
> + return NVME_RESV_EXCLUSIVE_ACCESS_REGS_ONLY;
> + case BLK_PR_WRITE_EXCLUSIVE_ALL_REGS:
> + return NVME_RESV_WRITE_EXCLUSIVE_ALL_REGS;
> + case BLK_PR_EXCLUSIVE_ACCESS_ALL_REGS:
> + return NVME_RESV_EXCLUSIVE_ACCESS_ALL_REGS;
> + }
> +
> + return 0;
> +}
> +
> +static inline BlockPrType nvme_pr_type_to_block(NvmeResvType type)
> +{
> + switch (type) {
> + case NVME_RESV_WRITE_EXCLUSIVE:
> + return BLK_PR_WRITE_EXCLUSIVE;
> + case NVME_RESV_EXCLUSIVE_ACCESS:
> + return BLK_PR_EXCLUSIVE_ACCESS;
> + case NVME_RESV_WRITE_EXCLUSIVE_REGS_ONLY:
> + return BLK_PR_WRITE_EXCLUSIVE_REGS_ONLY;
> + case NVME_RESV_EXCLUSIVE_ACCESS_REGS_ONLY:
> + return BLK_PR_EXCLUSIVE_ACCESS_REGS_ONLY;
> + case NVME_RESV_WRITE_EXCLUSIVE_ALL_REGS:
> + return BLK_PR_WRITE_EXCLUSIVE_ALL_REGS;
> + case NVME_RESV_EXCLUSIVE_ACCESS_ALL_REGS:
> + return BLK_PR_EXCLUSIVE_ACCESS_ALL_REGS;
> + }
> +
> + return 0;
> +}
> +
> +static inline uint8_t nvme_pr_cap_to_block(uint16_t nvme_pr_cap)
> +{
> + uint8_t res = 0;
> +
> + res |= (nvme_pr_cap & NVME_PR_CAP_PTPL) ?
> + NVME_PR_CAP_PTPL : 0;
> + res |= (nvme_pr_cap & NVME_PR_CAP_WR_EX) ?
> + BLK_PR_CAP_WR_EX : 0;
> + res |= (nvme_pr_cap & NVME_PR_CAP_EX_AC) ?
> + BLK_PR_CAP_EX_AC : 0;
> + res |= (nvme_pr_cap & NVME_PR_CAP_WR_EX_RO) ?
> + BLK_PR_CAP_WR_EX_RO : 0;
> + res |= (nvme_pr_cap & NVME_PR_CAP_EX_AC_RO) ?
> + BLK_PR_CAP_EX_AC_RO : 0;
> + res |= (nvme_pr_cap & NVME_PR_CAP_WR_EX_AR) ?
> + BLK_PR_CAP_WR_EX_AR : 0;
> + res |= (nvme_pr_cap & NVME_PR_CAP_EX_AC_AR) ?
> + BLK_PR_CAP_EX_AC_AR : 0;
> +
> + return res;
> +}
> +
> +static inline uint8_t block_pr_cap_to_nvme(uint8_t block_pr_cap)
> +{
> + uint16_t res = 0;
> +
> + res |= (block_pr_cap & BLK_PR_CAP_PTPL) ?
> + NVME_PR_CAP_PTPL : 0;
> + res |= (block_pr_cap & BLK_PR_CAP_WR_EX) ?
> + NVME_PR_CAP_WR_EX : 0;
> + res |= (block_pr_cap & BLK_PR_CAP_EX_AC) ?
> + NVME_PR_CAP_EX_AC : 0;
> + res |= (block_pr_cap & BLK_PR_CAP_WR_EX_RO) ?
> + NVME_PR_CAP_WR_EX_RO : 0;
> + res |= (block_pr_cap & BLK_PR_CAP_EX_AC_RO) ?
> + NVME_PR_CAP_EX_AC_RO : 0;
> + res |= (block_pr_cap & BLK_PR_CAP_WR_EX_AR) ?
> + NVME_PR_CAP_WR_EX_AR : 0;
> + res |= (block_pr_cap & BLK_PR_CAP_EX_AC_AR) ?
> + NVME_PR_CAP_EX_AC_AR : 0;
> +
> + return res;
> +}
> +
> typedef struct NvmeSQueue {
> struct NvmeCtrl *ctrl;
> uint16_t sqid;
> --
> 2.20.1
>
Reviewed-by: Klaus Jensen <k.jensen@samsung.com>
--
One of us - No more doubt, silence or taboo about mental illness.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
next prev parent reply other threads:[~2024-07-08 8:19 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-05 10:56 [PATCH v7 00/10] Support persistent reservation operations Changqi Lu
2024-07-05 10:56 ` [PATCH v7 01/10] block: add persistent reservation in/out api Changqi Lu
2024-07-05 10:56 ` [PATCH v7 02/10] block/raw: add persistent reservation in/out driver Changqi Lu
2024-07-05 10:56 ` [PATCH v7 03/10] scsi/constant: add persistent reservation in/out protocol constants Changqi Lu
2024-07-05 10:56 ` [PATCH v7 04/10] scsi/util: add helper functions for persistent reservation types conversion Changqi Lu
2024-07-05 10:56 ` [PATCH v7 05/10] hw/scsi: add persistent reservation in/out api for scsi device Changqi Lu
2024-07-08 8:11 ` Stefan Hajnoczi
2024-07-05 10:56 ` [PATCH v7 06/10] block/nvme: add reservation command protocol constants Changqi Lu
2024-07-08 8:45 ` Stefan Hajnoczi
2024-07-05 10:56 ` [PATCH v7 07/10] hw/nvme: add helper functions for converting reservation types Changqi Lu
2024-07-08 8:18 ` Klaus Jensen [this message]
2024-07-05 10:56 ` [PATCH v7 08/10] hw/nvme: enable ONCS and rescap function Changqi Lu
2024-07-08 8:12 ` Stefan Hajnoczi
2024-07-08 8:18 ` Klaus Jensen
2024-07-05 10:56 ` [PATCH v7 09/10] hw/nvme: add reservation protocal command Changqi Lu
2024-07-05 10:56 ` [PATCH v7 10/10] block/iscsi: add persistent reservation in/out driver Changqi Lu
2024-07-08 8:45 ` Stefan Hajnoczi
2024-07-08 8:45 ` [PATCH v7 00/10] Support persistent reservation operations Stefan Hajnoczi
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=Zoug3X2md0oskFu-@cormorant.local \
--to=its@irrelevant.dk \
--cc=fam@euphon.net \
--cc=foss@defmacro.it \
--cc=hreitz@redhat.com \
--cc=kbusch@kernel.org \
--cc=kwolf@redhat.com \
--cc=luchangqi.123@bytedance.com \
--cc=pbonzini@redhat.com \
--cc=philmd@linaro.org \
--cc=pizhenwei@bytedance.com \
--cc=pl@dlhnet.de \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=ronniesahlberg@gmail.com \
--cc=stefanha@redhat.com \
/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).