From nobody Sat Sep 28 21:01:16 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=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1592405986; cv=none; d=zohomail.com; s=zohoarc; b=XJUC92z3Qgevu5+wn/4A5cRumRBZzIhK9Yl65ddorRNse0SSsD20hn01ARN8Un45F2QAP6riM224aw79nvnQtE0Q1dKL5YQcaLvTDX7xn3QV/+ZRUGtfOtlvsy+uGeTcjMbebkKcw620uUWYrXpo7mNC1Qz4wFg5tO5O5dta7kM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1592405986; h=Content-Type: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; bh=Iyw/Q2JpgVOyfsqbzKlZnH45NH/c7NT9F6B2ehHiDmE=; b=Qgiaty2gSLWiwIT8uyIbVw8khf8FuCTBQYuwXjhb/Vd2KcaZI3uzbpeO9Df7I9ABByEj0lETB3pUN5sOtvIIDW45tZwPu9thDzJOJzTzAlChQmqRZKzVTf6ZYt2oIJI6G2Dil0Of0BxRV+j0h1RYb+l2tELaPkJv78029rv/Ti0= 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=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1592405986824207.4139919744057; Wed, 17 Jun 2020 07:59:46 -0700 (PDT) Received: from localhost ([::1]:33660 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jlZXW-0007US-05 for importer@patchew.org; Wed, 17 Jun 2020 10:59:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45278) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jlZNn-00033j-8f for qemu-devel@nongnu.org; Wed, 17 Jun 2020 10:49:45 -0400 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:40778 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jlZNi-0001iP-Fj for qemu-devel@nongnu.org; Wed, 17 Jun 2020 10:49:42 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-350-MSht19-UPWCKRkseYOg_mQ-1; Wed, 17 Jun 2020 10:49:35 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 87D5918A267A; Wed, 17 Jun 2020 14:49:34 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-114-44.ams2.redhat.com [10.36.114.44]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8FFF17CAA0; Wed, 17 Jun 2020 14:49:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1592405377; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Iyw/Q2JpgVOyfsqbzKlZnH45NH/c7NT9F6B2ehHiDmE=; b=FEvUsNtVTIGViq5tNl+qat3takKf6mFELJUqnrVMZBeIkpz1CQ8rAeWTN3Wp7XeJlUBO7h v9Y+MyE5baAuXFBrgRbqPqzYjbcqesCHvn25/bXIwv4JTRwnU6H/p38YYmwS+hpIGfW+eG 8WkRHms5xoGVab7igsibJui/TMKAdRE= X-MC-Unique: MSht19-UPWCKRkseYOg_mQ-1 From: Kevin Wolf To: qemu-block@nongnu.org Subject: [PULL 16/43] hw/block/nvme: factor out property/constraint checks Date: Wed, 17 Jun 2020 16:48:42 +0200 Message-Id: <20200617144909.192176-17-kwolf@redhat.com> In-Reply-To: <20200617144909.192176-1-kwolf@redhat.com> References: <20200617144909.192176-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" 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=205.139.110.61; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/17 02:02:46 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) From: Klaus Jensen Signed-off-by: Klaus Jensen Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Maxim Levitsky Reviewed-by: Keith Busch Message-Id: <20200609190333.59390-11-its@irrelevant.dk> Signed-off-by: Kevin Wolf --- hw/block/nvme.c | 48 ++++++++++++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 18 deletions(-) diff --git a/hw/block/nvme.c b/hw/block/nvme.c index 61447220a8..ee669ee8dc 100644 --- a/hw/block/nvme.c +++ b/hw/block/nvme.c @@ -1354,24 +1354,19 @@ static const MemoryRegionOps nvme_cmb_ops =3D { }, }; =20 -static void nvme_realize(PCIDevice *pci_dev, Error **errp) +static void nvme_check_constraints(NvmeCtrl *n, Error **errp) { - NvmeCtrl *n =3D NVME(pci_dev); - NvmeIdCtrl *id =3D &n->id_ctrl; - - int i; - int64_t bs_size; - uint8_t *pci_conf; + NvmeParams *params =3D &n->params; =20 - if (n->params.num_queues) { + if (params->num_queues) { warn_report("num_queues is deprecated; please use max_ioqpairs " "instead"); =20 - n->params.max_ioqpairs =3D n->params.num_queues - 1; + params->max_ioqpairs =3D params->num_queues - 1; } =20 - if (n->params.max_ioqpairs < 1 || - n->params.max_ioqpairs > PCI_MSIX_FLAGS_QSIZE) { + if (params->max_ioqpairs < 1 || + params->max_ioqpairs > PCI_MSIX_FLAGS_QSIZE) { error_setg(errp, "max_ioqpairs must be between 1 and %d", PCI_MSIX_FLAGS_QSIZE); return; @@ -1382,13 +1377,7 @@ static void nvme_realize(PCIDevice *pci_dev, Error *= *errp) return; } =20 - bs_size =3D blk_getlength(n->conf.blk); - if (bs_size < 0) { - error_setg(errp, "could not get backing file size"); - return; - } - - if (!n->params.serial) { + if (!params->serial) { error_setg(errp, "serial property not set"); return; } @@ -1408,6 +1397,29 @@ static void nvme_realize(PCIDevice *pci_dev, Error *= *errp) =20 host_memory_backend_set_mapped(n->pmrdev, true); } +} + +static void nvme_realize(PCIDevice *pci_dev, Error **errp) +{ + NvmeCtrl *n =3D NVME(pci_dev); + NvmeIdCtrl *id =3D &n->id_ctrl; + Error *local_err =3D NULL; + + int i; + int64_t bs_size; + uint8_t *pci_conf; + + nvme_check_constraints(n, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } + + bs_size =3D blk_getlength(n->conf.blk); + if (bs_size < 0) { + error_setg(errp, "could not get backing file size"); + return; + } =20 blkconf_blocksizes(&n->conf); if (!blkconf_apply_backend_options(&n->conf, blk_is_read_only(n->conf.= blk), --=20 2.25.4