From nobody Tue Feb 10 09:01:49 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1562311636; cv=none; d=zoho.com; s=zohoarc; b=hn3O8mkzVrdV6sqTbiJ454/xC8ScPgjTuhfITRPVEHC8PXpW0f8HJHjyWc1JJiBGoSsTwjrJS0b1TuWuHm1dQbPSckmTufPzRMi04rwzWHJ9XdA/rZNvzObHpUcfZOG5EL5nyR4pSfBMZ0CyPUCCwa6uTCgfiQYHBQVIchqv9CA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562311636; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=kKP0YGmS5GuD1bjIuDqn5b4Qew8bExHhuUb7866zKME=; b=cMMxhegcG5Rpp+1W5RYiaTNSlO0FoVWdsY1c09/uDfpBIY+GB21fK1D9cWT1A78r00Xglxb5oYyuJkPv37ITcsRjOxWH4GGHqgip93El8qeoDHn9k/Nu2CAMhVeMOY4ykmsImF0cCHb1aT4PFJ5R+tY3X5/zN7KxqN4WSTJPup0= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1562311636787429.37198843365854; Fri, 5 Jul 2019 00:27:16 -0700 (PDT) Received: from localhost ([::1]:50100 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hjIcl-0000Nv-Ro for importer@patchew.org; Fri, 05 Jul 2019 03:27:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44098) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hjIZZ-0005Gz-Lb for qemu-devel@nongnu.org; Fri, 05 Jul 2019 03:24:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hjIZX-0005k5-UF for qemu-devel@nongnu.org; Fri, 05 Jul 2019 03:23:57 -0400 Received: from charlie.dont.surf ([128.199.63.193]:50494) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hjIZV-0005fm-1a; Fri, 05 Jul 2019 03:23:53 -0400 Received: from localhost.localdomain (ip-5-186-120-196.cgn.fibianet.dk [5.186.120.196]) by charlie.dont.surf (Postfix) with ESMTPSA id D78D1BF644; Fri, 5 Jul 2019 07:23:50 +0000 (UTC) From: Klaus Birkelund Jensen To: qemu-block@nongnu.org Date: Fri, 5 Jul 2019 09:23:18 +0200 Message-Id: <20190705072333.17171-2-klaus@birkelund.eu> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190705072333.17171-1-klaus@birkelund.eu> References: <20190705072333.17171-1-klaus@birkelund.eu> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 128.199.63.193 Subject: [Qemu-devel] [PATCH 01/16] nvme: simplify namespace code X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, matt.fitzpatrick@oakgatetech.com, qemu-devel@nongnu.org, armbru@redhat.com, keith.busch@intel.com, mreitz@redhat.com, lersek@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" The device model currently only supports a single namespace and also specifically sets num_namespaces to 1. Take this into account and simplify the code. Signed-off-by: Klaus Birkelund Jensen --- hw/block/nvme.c | 26 +++++++------------------- hw/block/nvme.h | 2 +- 2 files changed, 8 insertions(+), 20 deletions(-) diff --git a/hw/block/nvme.c b/hw/block/nvme.c index 36d6a8bb3a3e..28ebaf1368b1 100644 --- a/hw/block/nvme.c +++ b/hw/block/nvme.c @@ -424,7 +424,7 @@ static uint16_t nvme_io_cmd(NvmeCtrl *n, NvmeCmd *cmd, = NvmeRequest *req) return NVME_INVALID_NSID | NVME_DNR; } =20 - ns =3D &n->namespaces[nsid - 1]; + ns =3D &n->namespace; switch (cmd->opcode) { case NVME_CMD_FLUSH: return nvme_flush(n, ns, cmd, req); @@ -670,7 +670,7 @@ static uint16_t nvme_identify_ns(NvmeCtrl *n, NvmeIdent= ify *c) return NVME_INVALID_NSID | NVME_DNR; } =20 - ns =3D &n->namespaces[nsid - 1]; + ns =3D &n->namespace; =20 return nvme_dma_read_prp(n, (uint8_t *)&ns->id_ns, sizeof(ns->id_ns), prp1, prp2); @@ -1306,8 +1306,8 @@ static void nvme_realize(PCIDevice *pci_dev, Error **= errp) { NvmeCtrl *n =3D NVME(pci_dev); NvmeIdCtrl *id =3D &n->id_ctrl; + NvmeIdNs *id_ns =3D &n->namespace.id_ns; =20 - int i; int64_t bs_size; uint8_t *pci_conf; =20 @@ -1347,7 +1347,6 @@ static void nvme_realize(PCIDevice *pci_dev, Error **= errp) n->reg_size =3D pow2ceil(0x1004 + 2 * (n->num_queues + 1) * 4); n->ns_size =3D bs_size / (uint64_t)n->num_namespaces; =20 - n->namespaces =3D g_new0(NvmeNamespace, n->num_namespaces); n->sq =3D g_new0(NvmeSQueue *, n->num_queues); n->cq =3D g_new0(NvmeCQueue *, n->num_queues); =20 @@ -1416,20 +1415,10 @@ static void nvme_realize(PCIDevice *pci_dev, Error = **errp) =20 } =20 - for (i =3D 0; i < n->num_namespaces; i++) { - NvmeNamespace *ns =3D &n->namespaces[i]; - NvmeIdNs *id_ns =3D &ns->id_ns; - id_ns->nsfeat =3D 0; - id_ns->nlbaf =3D 0; - id_ns->flbas =3D 0; - id_ns->mc =3D 0; - id_ns->dpc =3D 0; - id_ns->dps =3D 0; - id_ns->lbaf[0].ds =3D BDRV_SECTOR_BITS; - id_ns->ncap =3D id_ns->nuse =3D id_ns->nsze =3D - cpu_to_le64(n->ns_size >> - id_ns->lbaf[NVME_ID_NS_FLBAS_INDEX(ns->id_ns.flbas)].ds); - } + id_ns->lbaf[0].ds =3D BDRV_SECTOR_BITS; + id_ns->ncap =3D id_ns->nuse =3D id_ns->nsze =3D + cpu_to_le64(n->ns_size >> + id_ns->lbaf[NVME_ID_NS_FLBAS_INDEX(id_ns->flbas)].ds); } =20 static void nvme_exit(PCIDevice *pci_dev) @@ -1437,7 +1426,6 @@ static void nvme_exit(PCIDevice *pci_dev) NvmeCtrl *n =3D NVME(pci_dev); =20 nvme_clear_ctrl(n); - g_free(n->namespaces); g_free(n->cq); g_free(n->sq); =20 diff --git a/hw/block/nvme.h b/hw/block/nvme.h index 557194ee1954..40cedb1ec932 100644 --- a/hw/block/nvme.h +++ b/hw/block/nvme.h @@ -83,7 +83,7 @@ typedef struct NvmeCtrl { uint64_t timestamp_set_qemu_clock_ms; /* QEMU clock time */ =20 char *serial; - NvmeNamespace *namespaces; + NvmeNamespace namespace; NvmeSQueue **sq; NvmeCQueue **cq; NvmeSQueue admin_sq; --=20 2.20.1