From nobody Sun Nov 24 23:06:09 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=bytedance.com ARC-Seal: i=1; a=rsa-sha256; t=1720177089; cv=none; d=zohomail.com; s=zohoarc; b=TrhatV/8M/nsYHeQLEZApYsCtbbfqlw2aHTlwD4Kdv+Bh3m6X8aLKrllkl6MAlzUNEZulm7rj2z844nrVOgM+AfTVFN3Rm/8agBniRF0Kmi98dny0f1xXqTOrolSAsRJgxJG/BWiZS0moJ/+vhtxylMAGDW0Oam1v8CqeysRZSc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1720177089; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=vnnlaAsHMDMy1W0jqBEpl+WRDzxCFDRuHFC4XpL5tjY=; b=B1aiXseKV+EonPzYSPWdEWqQKmHtjWPWFkUn0gU0YjHlWKbk/fSwT/RH5LjXgo2vS4THM0Rq1NLJa9nFxXGwjQ1B9vfKg2IlcZZzxuyOUNBOyLFthGwCD1/PLhBXgk9qz3zKG1C/YPz2JK7qMqBkztWdQYud5029kR2Xt1DyAVM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 172017708953287.60385026030531; Fri, 5 Jul 2024 03:58:09 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sPgcn-0002XS-0D; Fri, 05 Jul 2024 06:57:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sPgck-0002Sx-1n for qemu-devel@nongnu.org; Fri, 05 Jul 2024 06:57:06 -0400 Received: from mail-pf1-x42f.google.com ([2607:f8b0:4864:20::42f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sPgce-0006ew-9q for qemu-devel@nongnu.org; Fri, 05 Jul 2024 06:57:05 -0400 Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-70af22a9c19so1062417b3a.2 for ; Fri, 05 Jul 2024 03:56:59 -0700 (PDT) Received: from n37-006-243.byted.org ([180.184.84.173]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fac0ba60a2sm141292125ad.0.2024.07.05.03.56.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jul 2024 03:56:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1720177019; x=1720781819; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=vnnlaAsHMDMy1W0jqBEpl+WRDzxCFDRuHFC4XpL5tjY=; b=C/GAvGZVKOhdLm9M1Q77I76xgG060b3SMUPsC3mnbAnifZJwNmmoF+VJ5p0aS6CHTg ooLXQKXy/L2V3SzZ9zvzbGTVOLi3jbKcICjJzpNUQNkV/wa0Iu7B1h1Y7bw6JNRPyVYs ZuB4o7rpjPCYzxLlQd9fNmCFjXiF0MwWZuOfrLmYbPv4aGlPBptLaIu3MVdn4Ai5UOjj n7BapS8XkrX7EDueawLskRFKI0rmpHcrULzwOM1biWeFBiBAws74SNFyPqBG3sRgJIjT jI6G7xdYpB+Vk4kDklKVFy+KMtEJK7LE+wHHxBpcAjDJ58DhyuqkfXPSFkhLR01eCcID Stmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720177019; x=1720781819; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vnnlaAsHMDMy1W0jqBEpl+WRDzxCFDRuHFC4XpL5tjY=; b=Z3We18m5HPsRRML+102RbcM0KD175VLSCyx+VOdBT8XpkYB/cqXu+9vOLOwIXrun+V 6YAsTHP5nFKiPWnHn53RA/UDZFGpdyvneROHbOU1bUdU9r1V898DTLLw2cUZA+wsu7i2 jUgWJaoZHp6tlToOC7cC9XWXt5zNKlF30jdBSEQlSg8o+KvWHAiG5aBMj1IyyKbKHlVz 6L0lbv8yd+4rChrkt27MKA0lkJslYk1O5eARa2dEgkpjmeOVLLRbFe6UAS6vL13wtaDL 35PFs6tHjCQi7ZTs8f9Ryhw5Z3MypfRxm87dUjhSTHqoHWHBHK33Q5XC2sVE89e26a3D tzGg== X-Forwarded-Encrypted: i=1; AJvYcCU3ivnrz5gt2wXaB+a1vUq/9Ssra0jYhFC1zVeylbBsMgkkRw5hdHu9eJw+FemeMcT9jALAkle6kUv/0R1cQvE7baef+wk= X-Gm-Message-State: AOJu0YyOAPf3CiUIm7A02JVAE38v7ShLmUZt5v+UYYYdYxU3tjhjSgdc ZRoq9fPuH0JsIXz6WOfVar904no/DDDpPb6pAYXHaWDi6WNjEdq8TMVhht4l6Gc= X-Google-Smtp-Source: AGHT+IEzPBnUv22JiHc+NpW7hEF7mwdFoUuzgd/H5ZQ82I91Z8wP4L7jtbTfdlYJN+cJ+gwey6RXcw== X-Received: by 2002:a05:6a21:329a:b0:1c0:dc29:8dbe with SMTP id adf61e73a8af0-1c0dc298ea7mr1071748637.62.1720177018853; Fri, 05 Jul 2024 03:56:58 -0700 (PDT) From: Changqi Lu To: qemu-block@nongnu.org, qemu-devel@nongnu.org Cc: kwolf@redhat.com, hreitz@redhat.com, stefanha@redhat.com, fam@euphon.net, ronniesahlberg@gmail.com, pbonzini@redhat.com, pl@dlhnet.de, kbusch@kernel.org, its@irrelevant.dk, foss@defmacro.it, philmd@linaro.org, pizhenwei@bytedance.com, Changqi Lu , Klaus Jensen Subject: [PATCH v7 09/10] hw/nvme: add reservation protocal command Date: Fri, 5 Jul 2024 18:56:13 +0800 Message-Id: <20240705105614.3377694-10-luchangqi.123@bytedance.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20240705105614.3377694-1-luchangqi.123@bytedance.com> References: <20240705105614.3377694-1-luchangqi.123@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::42f; envelope-from=luchangqi.123@bytedance.com; helo=mail-pf1-x42f.google.com X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1, DKIM_SIGNED=0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @bytedance.com) X-ZM-MESSAGEID: 1720177091421100010 Content-Type: text/plain; charset="utf-8" Add reservation acquire, reservation register, reservation release and reservation report commands in the nvme device layer. By introducing these commands, this enables the nvme device to perform reservation-related tasks, including querying keys, querying reservation status, registering reservation keys, initiating and releasing reservations, as well as clearing and preempting reservations held by other keys. These commands are crucial for management and control of shared storage resources in a persistent manner. Signed-off-by: Changqi Lu Signed-off-by: zhenwei pi Acked-by: Klaus Jensen --- hw/nvme/ctrl.c | 323 ++++++++++++++++++++++++++++++++++++++++++- hw/nvme/nvme.h | 4 + include/block/nvme.h | 37 +++++ 3 files changed, 363 insertions(+), 1 deletion(-) diff --git a/hw/nvme/ctrl.c b/hw/nvme/ctrl.c index ad212de723..a69a499078 100644 --- a/hw/nvme/ctrl.c +++ b/hw/nvme/ctrl.c @@ -294,6 +294,10 @@ static const uint32_t nvme_cse_iocs_nvm[256] =3D { [NVME_CMD_COMPARE] =3D NVME_CMD_EFF_CSUPP, [NVME_CMD_IO_MGMT_RECV] =3D NVME_CMD_EFF_CSUPP, [NVME_CMD_IO_MGMT_SEND] =3D NVME_CMD_EFF_CSUPP | NVME_CMD_EFF_= LBCC, + [NVME_CMD_RESV_REGISTER] =3D NVME_CMD_EFF_CSUPP, + [NVME_CMD_RESV_REPORT] =3D NVME_CMD_EFF_CSUPP, + [NVME_CMD_RESV_ACQUIRE] =3D NVME_CMD_EFF_CSUPP, + [NVME_CMD_RESV_RELEASE] =3D NVME_CMD_EFF_CSUPP, }; =20 static const uint32_t nvme_cse_iocs_zoned[256] =3D { @@ -308,6 +312,10 @@ static const uint32_t nvme_cse_iocs_zoned[256] =3D { [NVME_CMD_ZONE_APPEND] =3D NVME_CMD_EFF_CSUPP | NVME_CMD_EFF_= LBCC, [NVME_CMD_ZONE_MGMT_SEND] =3D NVME_CMD_EFF_CSUPP | NVME_CMD_EFF_= LBCC, [NVME_CMD_ZONE_MGMT_RECV] =3D NVME_CMD_EFF_CSUPP, + [NVME_CMD_RESV_REGISTER] =3D NVME_CMD_EFF_CSUPP, + [NVME_CMD_RESV_REPORT] =3D NVME_CMD_EFF_CSUPP, + [NVME_CMD_RESV_ACQUIRE] =3D NVME_CMD_EFF_CSUPP, + [NVME_CMD_RESV_RELEASE] =3D NVME_CMD_EFF_CSUPP, }; =20 static void nvme_process_sq(void *opaque); @@ -1745,6 +1753,7 @@ static void nvme_aio_err(NvmeRequest *req, int ret) =20 switch (req->cmd.opcode) { case NVME_CMD_READ: + case NVME_CMD_RESV_REPORT: status =3D NVME_UNRECOVERED_READ; break; case NVME_CMD_FLUSH: @@ -1752,6 +1761,9 @@ static void nvme_aio_err(NvmeRequest *req, int ret) case NVME_CMD_WRITE_ZEROES: case NVME_CMD_ZONE_APPEND: case NVME_CMD_COPY: + case NVME_CMD_RESV_REGISTER: + case NVME_CMD_RESV_ACQUIRE: + case NVME_CMD_RESV_RELEASE: status =3D NVME_WRITE_FAULT; break; default: @@ -2127,7 +2139,10 @@ static inline bool nvme_is_write(NvmeRequest *req) =20 return rw->opcode =3D=3D NVME_CMD_WRITE || rw->opcode =3D=3D NVME_CMD_ZONE_APPEND || - rw->opcode =3D=3D NVME_CMD_WRITE_ZEROES; + rw->opcode =3D=3D NVME_CMD_WRITE_ZEROES || + rw->opcode =3D=3D NVME_CMD_RESV_REGISTER || + rw->opcode =3D=3D NVME_CMD_RESV_ACQUIRE || + rw->opcode =3D=3D NVME_CMD_RESV_RELEASE; } =20 static void nvme_misc_cb(void *opaque, int ret) @@ -2692,6 +2707,304 @@ static uint16_t nvme_verify(NvmeCtrl *n, NvmeReques= t *req) return NVME_NO_COMPLETE; } =20 +typedef struct NvmeKeyInfo { + uint64_t cr_key; + uint64_t nr_key; +} NvmeKeyInfo; + +static uint16_t nvme_resv_register(NvmeCtrl *n, NvmeRequest *req) +{ + int ret; + NvmeKeyInfo key_info; + NvmeNamespace *ns =3D req->ns; + uint32_t cdw10 =3D le32_to_cpu(req->cmd.cdw10); + bool ignore_key =3D cdw10 >> 3 & 0x1; + uint8_t action =3D cdw10 & 0x7; + uint8_t ptpl =3D cdw10 >> 30 & 0x3; + bool aptpl; + + switch (ptpl) { + case NVME_RESV_PTPL_NO_CHANGE: + aptpl =3D (ns->id_ns.rescap & NVME_PR_CAP_PTPL) ? true : false; + break; + case NVME_RESV_PTPL_DISABLE: + aptpl =3D false; + break; + case NVME_RESV_PTPL_ENABLE: + aptpl =3D true; + break; + default: + return NVME_INVALID_FIELD; + } + + ret =3D nvme_h2c(n, (uint8_t *)&key_info, sizeof(NvmeKeyInfo), req); + if (ret) { + return ret; + } + + switch (action) { + case NVME_RESV_REGISTER_ACTION_REGISTER: + req->aiocb =3D blk_aio_pr_register(ns->blkconf.blk, 0, + key_info.nr_key, 0, aptpl, + ignore_key, nvme_misc_cb, + req); + break; + case NVME_RESV_REGISTER_ACTION_UNREGISTER: + req->aiocb =3D blk_aio_pr_register(ns->blkconf.blk, key_info.cr_ke= y, 0, + 0, aptpl, ignore_key, + nvme_misc_cb, req); + break; + case NVME_RESV_REGISTER_ACTION_REPLACE: + req->aiocb =3D blk_aio_pr_register(ns->blkconf.blk, key_info.cr_ke= y, + key_info.nr_key, 0, aptpl, ignore= _key, + nvme_misc_cb, req); + break; + default: + return NVME_INVALID_FIELD; + } + + return NVME_NO_COMPLETE; +} + +static uint16_t nvme_resv_release(NvmeCtrl *n, NvmeRequest *req) +{ + int ret; + uint64_t cr_key; + NvmeNamespace *ns =3D req->ns; + uint32_t cdw10 =3D le32_to_cpu(req->cmd.cdw10); + uint8_t action =3D cdw10 & 0x7; + NvmeResvType type =3D cdw10 >> 8 & 0xff; + + ret =3D nvme_h2c(n, (uint8_t *)&cr_key, sizeof(cr_key), req); + if (ret) { + return ret; + } + + switch (action) { + case NVME_RESV_RELEASE_ACTION_RELEASE: + req->aiocb =3D blk_aio_pr_release(ns->blkconf.blk, cr_key, + nvme_pr_type_to_block(type), + nvme_misc_cb, req); + break; + case NVME_RESV_RELEASE_ACTION_CLEAR: + req->aiocb =3D blk_aio_pr_clear(ns->blkconf.blk, cr_key, + nvme_misc_cb, req); + break; + default: + return NVME_INVALID_FIELD; + } + + return NVME_NO_COMPLETE; +} + +static uint16_t nvme_resv_acquire(NvmeCtrl *n, NvmeRequest *req) +{ + int ret; + NvmeKeyInfo key_info; + NvmeNamespace *ns =3D req->ns; + uint32_t cdw10 =3D le32_to_cpu(req->cmd.cdw10); + uint8_t action =3D cdw10 & 0x7; + NvmeResvType type =3D cdw10 >> 8 & 0xff; + + ret =3D nvme_h2c(n, (uint8_t *)&key_info, sizeof(NvmeKeyInfo), req); + if (ret) { + return ret; + } + + switch (action) { + case NVME_RESV_ACQUIRE_ACTION_ACQUIRE: + req->aiocb =3D blk_aio_pr_reserve(ns->blkconf.blk, key_info.cr_key, + nvme_pr_type_to_block(type), + nvme_misc_cb, req); + break; + case NVME_RESV_ACQUIRE_ACTION_PREEMPT: + req->aiocb =3D blk_aio_pr_preempt(ns->blkconf.blk, + key_info.cr_key, key_info.nr_key, + nvme_pr_type_to_block(type), + false, nvme_misc_cb, req); + break; + case NVME_RESV_ACQUIRE_ACTION_PREEMPT_AND_ABORT: + req->aiocb =3D blk_aio_pr_preempt(ns->blkconf.blk, key_info.cr_key, + key_info.nr_key, type, true, + nvme_misc_cb, req); + break; + default: + return NVME_INVALID_FIELD; + } + + return NVME_NO_COMPLETE; +} + +typedef struct NvmeResvKeys { + uint32_t generation; + uint32_t num_keys; + uint64_t *keys; + NvmeRequest *req; +} NvmeResvKeys; + +typedef struct NvmeReadReservation { + uint32_t generation; + uint64_t key; + BlockPrType type; + NvmeRequest *req; + NvmeResvKeys *keys_info; +} NvmeReadReservation; + +static int nvme_read_reservation_cb(NvmeReadReservation *reservation) +{ + int rc; + NvmeReservationStatus *nvme_status; + NvmeRequest *req =3D reservation->req; + NvmeCtrl *n =3D req->sq->ctrl; + NvmeResvKeys *keys_info =3D reservation->keys_info; + int len =3D sizeof(NvmeReservationStatusHeader) + + sizeof(NvmeRegisteredCtrl) * keys_info->num_keys; + + nvme_status =3D g_malloc(len); + nvme_status->header.gen =3D reservation->generation; + nvme_status->header.rtype =3D block_pr_type_to_nvme(reservation->type); + nvme_status->header.regctl =3D keys_info->num_keys; + for (int i =3D 0; i < keys_info->num_keys; i++) { + nvme_status->regctl_ds[i].cntlid =3D nvme_ctrl(req)->cntlid; + nvme_status->regctl_ds[i].rkey =3D keys_info->keys[i]; + nvme_status->regctl_ds[i].rcsts =3D keys_info->keys[i] =3D=3D + reservation->key ? 1 : 0; + /* hostid is not supported currently */ + memset(&nvme_status->regctl_ds[i].hostid, 0, 8); + } + + rc =3D nvme_c2h(n, (uint8_t *)nvme_status, len, req); + g_free(nvme_status); + return rc; +} + +static int nvme_read_reservation_ext_cb(NvmeReadReservation *reservation) +{ + int rc; + NvmeReservationStatusExt *nvme_status_ext; + NvmeRequest *req =3D reservation->req; + NvmeCtrl *n =3D req->sq->ctrl; + NvmeResvKeys *keys_info =3D reservation->keys_info; + int len =3D sizeof(NvmeReservationStatusHeader) + + sizeof(uint8_t) * 40 + + sizeof(NvmeRegisteredCtrlExt) * keys_info->num_keys; + + nvme_status_ext =3D g_malloc(len); + nvme_status_ext->header.gen =3D cpu_to_be32(reservation->generation); + nvme_status_ext->header.rtype =3D block_pr_type_to_nvme(reservation->t= ype); + nvme_status_ext->header.regctl =3D cpu_to_be16(keys_info->num_keys); + + for (int i =3D 0; i < keys_info->num_keys; i++) { + uint16_t ctnlid =3D nvme_ctrl(req)->cntlid; + nvme_status_ext->regctl_eds[i].cntlid =3D cpu_to_be16(ctnlid); + nvme_status_ext->regctl_eds[i].rkey =3D cpu_to_be64(keys_info->key= s[i]); + nvme_status_ext->regctl_eds[i].rcsts =3D keys_info->keys[i] =3D=3D + reservation->key ? 1 : 0; + /* hostid is not supported currently */ + memset(&nvme_status_ext->regctl_eds[i].hostid, 0, 16); + } + + rc =3D nvme_c2h(n, (uint8_t *)nvme_status_ext, len, req); + g_free(nvme_status_ext); + return rc; +} + +static void nvme_resv_read_reservation_cb(void *opaque, int ret) +{ + NvmeReadReservation *reservation =3D opaque; + NvmeRequest *req =3D reservation->req; + bool eds =3D req->cmd.cdw11 & 0x1; + NvmeResvKeys *keys_info =3D reservation->keys_info; + + if (ret < 0) { + goto out; + } + + if (eds) { + ret =3D nvme_read_reservation_ext_cb(reservation); + } else { + ret =3D nvme_read_reservation_cb(reservation); + } + +out: + g_free(keys_info->keys); + g_free(keys_info); + g_free(reservation); + nvme_misc_cb(req, ret); +} + +static void nvme_resv_read_keys_cb(void *opaque, int ret) +{ + NvmeResvKeys *keys_info =3D opaque; + NvmeRequest *req =3D keys_info->req; + NvmeNamespace *ns =3D req->ns; + NvmeReadReservation *reservation; + + if (ret < 0) { + goto out; + } + + keys_info->num_keys =3D MIN(ret, keys_info->num_keys); + reservation =3D g_new0(NvmeReadReservation, 1); + memset(reservation, 0, sizeof(*reservation)); + reservation->req =3D req; + reservation->keys_info =3D keys_info; + + req->aiocb =3D blk_aio_pr_read_reservation(ns->blkconf.blk, + &reservation->generation, &reservation->key, + &reservation->type, nvme_resv_read_reservation_cb, + reservation); + return; + +out: + g_free(keys_info->keys); + g_free(keys_info); + nvme_misc_cb(req, ret); +} + + +static uint16_t nvme_resv_report(NvmeCtrl *n, NvmeRequest *req) +{ + int num_keys; + uint32_t cdw10 =3D req->cmd.cdw10; + uint32_t cdw11 =3D req->cmd.cdw11; + int buflen =3D (cdw10 + 1) * sizeof(uint32_t); + bool eds =3D cdw11 & 0x1; + NvmeNamespace *ns =3D req->ns; + NvmeResvKeys *keys_info; + + if (eds) { + if (buflen < sizeof(NvmeReservationStatusHeader) + + sizeof(uint8_t) * 40) { + return NVME_INVALID_FIELD; + } + + num_keys =3D (buflen - sizeof(NvmeReservationStatusHeader) - + sizeof(uint8_t) * 40) / + sizeof(struct NvmeRegisteredCtrlExt); + } else { + if (buflen < sizeof(NvmeReservationStatusHeader)) { + return NVME_INVALID_FIELD; + } + + num_keys =3D (buflen - sizeof(NvmeReservationStatusHeader)) / + sizeof(struct NvmeRegisteredCtrl); + } + + keys_info =3D g_new0(NvmeResvKeys, 1); + keys_info->generation =3D 0; + /* num_keys is the maximum number of keys that can be transmitted */ + keys_info->num_keys =3D num_keys; + keys_info->keys =3D g_malloc(sizeof(uint64_t) * num_keys); + keys_info->req =3D req; + + req->aiocb =3D blk_aio_pr_read_keys(ns->blkconf.blk, &keys_info->gener= ation, + keys_info->num_keys, keys_info->keys, + nvme_resv_read_keys_cb, keys_info); + + return NVME_NO_COMPLETE; +} + typedef struct NvmeCopyAIOCB { BlockAIOCB common; BlockAIOCB *aiocb; @@ -4469,6 +4782,14 @@ static uint16_t nvme_io_cmd(NvmeCtrl *n, NvmeRequest= *req) return nvme_dsm(n, req); case NVME_CMD_VERIFY: return nvme_verify(n, req); + case NVME_CMD_RESV_REGISTER: + return nvme_resv_register(n, req); + case NVME_CMD_RESV_REPORT: + return nvme_resv_report(n, req); + case NVME_CMD_RESV_ACQUIRE: + return nvme_resv_acquire(n, req); + case NVME_CMD_RESV_RELEASE: + return nvme_resv_release(n, req); case NVME_CMD_COPY: return nvme_copy(n, req); case NVME_CMD_ZONE_MGMT_SEND: diff --git a/hw/nvme/nvme.h b/hw/nvme/nvme.h index 6d0e456348..fdd919c2b1 100644 --- a/hw/nvme/nvme.h +++ b/hw/nvme/nvme.h @@ -470,6 +470,10 @@ static inline const char *nvme_io_opc_str(uint8_t opc) case NVME_CMD_ZONE_MGMT_SEND: return "NVME_ZONED_CMD_MGMT_SEND"; case NVME_CMD_ZONE_MGMT_RECV: return "NVME_ZONED_CMD_MGMT_RECV"; case NVME_CMD_ZONE_APPEND: return "NVME_ZONED_CMD_ZONE_APPEND"; + case NVME_CMD_RESV_REGISTER: return "NVME_CMD_RESV_REGISTER"; + case NVME_CMD_RESV_REPORT: return "NVME_CMD_RESV_REPORT"; + case NVME_CMD_RESV_ACQUIRE: return "NVME_CMD_RESV_ACQUIRE"; + case NVME_CMD_RESV_RELEASE: return "NVME_CMD_RESV_RELEASE"; default: return "NVME_NVM_CMD_UNKNOWN"; } } diff --git a/include/block/nvme.h b/include/block/nvme.h index 9b9eaeb3a7..2f24570d4a 100644 --- a/include/block/nvme.h +++ b/include/block/nvme.h @@ -702,6 +702,43 @@ typedef enum NVMEPrCap { NVME_PR_CAP_EX_AC_AR), } NvmePrCap; =20 +typedef struct QEMU_PACKED NvmeRegisteredCtrl { + uint16_t cntlid; + uint8_t rcsts; + uint8_t rsvd3[5]; + uint8_t hostid[8]; + uint64_t rkey; +} NvmeRegisteredCtrl; + +typedef struct QEMU_PACKED NvmeRegisteredCtrlExt { + uint16_t cntlid; + uint8_t rcsts; + uint8_t rsvd3[5]; + uint64_t rkey; + uint8_t hostid[16]; + uint8_t rsvd32[32]; +} NvmeRegisteredCtrlExt; + +typedef struct QEMU_PACKED NvmeReservationStatusHeader { + uint32_t gen; + uint8_t rtype; + uint16_t regctl; + uint16_t resv5; + uint8_t ptpls; + uint8_t resv10[14]; +} NvmeReservationStatusHeader; + +typedef struct QEMU_PACKED NvmeReservationStatus { + struct NvmeReservationStatusHeader header; + struct NvmeRegisteredCtrl regctl_ds[]; +} NvmeReservationStatus; + +typedef struct QEMU_PACKED NvmeReservationStatusExt { + struct NvmeReservationStatusHeader header; + uint8_t rsvd24[40]; + struct NvmeRegisteredCtrlExt regctl_eds[]; +} NvmeReservationStatusExt; + typedef struct QEMU_PACKED NvmeDeleteQ { uint8_t opcode; uint8_t flags; --=20 2.20.1