From nobody Fri May 3 21:38:28 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=suse.de ARC-Seal: i=1; a=rsa-sha256; t=1631181209; cv=none; d=zohomail.com; s=zohoarc; b=k/iq9iOAiZ4iwQG/IGhvYSYRosrpT1d5TTbSbV6du4i/15y9cT5StKSjRbVrD1o9+WnRq3auokRt/2TdUTAfFH4cuJrYZ5JmUyanM1hVUJt0iA7OFXOFB+aKTfgmHGyHmuomvbEifsxA5zkJEO75lTANn9DH/M1ytoHF2iG8y04= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1631181209; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=X+joRS4X0wVBmqlG72PuPiRs2Q/VydB4oFy1KskMxCI=; b=m37/zn/ccSIqX1ip5RrEIsSeV5DfrFHpYMSJTRMSLTylXB0aMAd1klXScTubzUIgtvFLAvGKfkFTSL893oW5+ZCl9pTC2CMDidOZ3jv0Xci+6Jz8DQFRvPhtsB47DLaZ/OrpEliRRR/X2X+QP8zgyIrSa+Mxx67AC0DdT871woY= 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) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631181209402136.35116083398395; Thu, 9 Sep 2021 02:53:29 -0700 (PDT) Received: from localhost ([::1]:39220 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mOGkK-0007uQ-FT for importer@patchew.org; Thu, 09 Sep 2021 05:53:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50420) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mOGix-0006LH-Pr; Thu, 09 Sep 2021 05:52:03 -0400 Received: from smtp-out2.suse.de ([195.135.220.29]:49714) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mOGiw-0000WK-C3; Thu, 09 Sep 2021 05:52:03 -0400 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 7BE071FDDF; Thu, 9 Sep 2021 09:52:00 +0000 (UTC) Received: from adalid.arch.suse.de (adalid.arch.suse.de [10.161.8.13]) by relay2.suse.de (Postfix) with ESMTP id 389F9A3BA4; Thu, 9 Sep 2021 09:52:00 +0000 (UTC) Received: by adalid.arch.suse.de (Postfix, from userid 16045) id 2D2BD518E2B1; Thu, 9 Sep 2021 11:52:00 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1631181120; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=X+joRS4X0wVBmqlG72PuPiRs2Q/VydB4oFy1KskMxCI=; b=jWZ91wS1OAgKkkBo9U1SapyZNoNtT4TqiqMVKPoxaOUIZP4NVraQGXtaQV6k9S9TSn9Yk1 YcOGgD8EctcP4vGJkWJPizG1R80VXCdmlXNOCQ6UiZvAhfJdHF83atcIuz4ZH109Uz+1hJ JWheyUbR98Ux3vE8vALi4Z3cjrxjdYQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1631181120; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=X+joRS4X0wVBmqlG72PuPiRs2Q/VydB4oFy1KskMxCI=; b=l7dbwcV/11ncBODuquwRWkh3hS7vyzbc+3Ci50RCtuSgphB5G5rd6as7xpJeB8K0AmbB4U D57ioDoD0HgyGVBg== From: Hannes Reinecke To: Klaus Jensen Subject: [PATCH] hw/nvme: select first free NSID for legacy drive configuration Date: Thu, 9 Sep 2021 11:51:59 +0200 Message-Id: <20210909095159.122174-1-hare@suse.de> X-Mailer: git-send-email 2.29.2 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=195.135.220.29; envelope-from=hare@suse.de; helo=smtp-out2.suse.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no 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: qemu-devel@nongnu.org, qemu-block@nongnu.org, Hannes Reinecke Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @suse.de) X-ZM-MESSAGEID: 1631181209924100001 Content-Type: text/plain; charset="utf-8" If a legacy 'drive' argument is passed to the controller we cannot assume that '1' will be a free NSID, as the subsys might already have attached a namespace to this NSID. So select the first free one. Signed-off-by: Hannes Reinecke --- hw/nvme/ctrl.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/hw/nvme/ctrl.c b/hw/nvme/ctrl.c index 757cdff038..2c69031ca9 100644 --- a/hw/nvme/ctrl.c +++ b/hw/nvme/ctrl.c @@ -6546,8 +6546,15 @@ static void nvme_realize(PCIDevice *pci_dev, Error *= *errp) =20 /* setup a namespace if the controller drive property was given */ if (n->namespace.blkconf.blk) { + int i; ns =3D &n->namespace; - ns->params.nsid =3D 1; + for (i =3D 1; i <=3D NVME_MAX_NAMESPACES; i++) { + if (nvme_ns(n, i) || nvme_subsys_ns(n->subsys, i)) { + continue; + } + ns->params.nsid =3D i; + break; + } =20 if (nvme_ns_setup(ns, errp)) { return; --=20 2.26.2