From nobody Tue Mar 3 03:05:56 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass(p=reject dis=none) header.from=lists.libvirt.org ARC-Seal: i=1; a=rsa-sha256; t=1771237442; cv=none; d=zohomail.com; s=zohoarc; b=LHmjybPYQqI0WVzQ0a2qYq3x+NF9Zc5oFRCBrVHNx1mrWOp33xyGg/u5kgDEBMJyA66wqaMC8kH/hj+o11N+64F50xHeFXsVmy62quCqwoZLX1EvDRrGmYvgc6KX5gqPQox+vY53oYSsrQuwI05MHJoMSC7OgA707POF73Lq41g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1771237442; h=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:List-Subscribe:List-Post:List-Owner:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:Subject:Subject:To:To:Message-Id:Cc; bh=5ADWb+Qw55yG3WBLeaP1xydCXNztqypzSJOAbHDJvlM=; b=YmovwPddHrSzdB1DOhz9PGiiuQWfV4EsZH65iCyFqGSXqtyhWmJp6+nswYYpeHSpCAi0g01/jUIj78m/CkGgtquTDB28xLBiMNBFxS3ah/f8oTI7vRTwR8P9m9z6obOa3zhkYQBGQVeuXKsxpQdJ/Xfm6eY4WR9NQ3f+lE9gcUE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1771237442129898.7903974542281; Mon, 16 Feb 2026 02:24:02 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 993) id 7B7C63F365; Mon, 16 Feb 2026 05:24:00 -0500 (EST) Received: from [172.19.199.9] (lists.libvirt.org [8.43.85.245]) by lists.libvirt.org (Postfix) with ESMTP id 078B13FB01; Mon, 16 Feb 2026 05:23:21 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 993) id 35DE83F36E; Mon, 16 Feb 2026 05:23:17 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (3072 bits) server-digest SHA256) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 99C263F365 for ; Mon, 16 Feb 2026 05:23:16 -0500 (EST) Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-113-xX7sjQ64MxS_w0gjOFKCSA-1; Mon, 16 Feb 2026 05:23:14 -0500 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 7FC3A1955BD9 for ; Mon, 16 Feb 2026 10:23:13 +0000 (UTC) Received: from moe (unknown [10.43.3.236]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id E118D19560AD for ; Mon, 16 Feb 2026 10:23:12 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_PASS autolearn=unavailable autolearn_force=no version=4.0.1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1771237396; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=5ADWb+Qw55yG3WBLeaP1xydCXNztqypzSJOAbHDJvlM=; b=V37rGNGjGTa3C+rKwNd72ZbnTyUXwnXifQ5wrwd3C81jIte7L7LzDls9THjd2jMYhqrIjI qcZqnqLgDKeQBZgXnknK9L67gZgm98B1iZIcWZGUFZuwqKmzABFvbriHNsfvlmxm8DZtqi bF7piJSR2mH1nADR81sDmE4HljZK+4c= X-MC-Unique: xX7sjQ64MxS_w0gjOFKCSA-1 X-Mimecast-MFC-AGG-ID: xX7sjQ64MxS_w0gjOFKCSA_1771237393 To: devel@lists.libvirt.org Subject: [PATCH] virstorageobj: Make virStoragePoolObjAddVol() report an error on failure Date: Mon, 16 Feb 2026 11:23:10 +0100 Message-ID: <33021e933c85149c36bbbe8e2fa9e7ec6c760aab.1771237214.git.mprivozn@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: 0Xfn9TOYGS6ok34wFk69607BvlT5IcLGnlRrM4qq67M_1771237393 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-ID-Hash: ITNRTDIPIJQ5L7BEJBPGTBNLJ4DPJ5SC X-Message-ID-Hash: ITNRTDIPIJQ5L7BEJBPGTBNLJ4DPJ5SC X-MailFrom: mprivozn@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-devel.lists.libvirt.org-0; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Michal Privoznik via Devel Reply-To: Michal Privoznik X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1771237442591158500 From: Michal Privoznik Adding a storage volume into a pool is done by calling virStoragePoolObjAddVol(). This function may fail if another volume already exists with the same key/name/target. In some cases the storage driver does check for duplicates before calling the function. But in some cases (e.g. when refreshing an RBD pool in virStorageBackendRBDRefreshPool()) it doesn't. The problem here is that the function reports no error upon failure and leaves it as an exercise for caller. Well, no caller does that. Therefore, make the function report an error. The advantage of this approach is - the function can report more accurate error message than any caller ever could. NB=C2=B8 this stems from a discussion on the users list [1], and while this does NOT solve the original issue, it fixes one of the symptoms. 1: https://lists.libvirt.org/archives/list/users@lists.libvirt.org/message/= BALVNCRQM4KBKGV4RQ7BMKSX7UIJKLQH/ Signed-off-by: Michal Privoznik Reviewed-by: Jiri Denemark --- This can be very easily reproduced with test driver. No need for ceph. Just duplicate a volume in a custom test driver XML. Before this patch you'd get: error: failed to connect to the hypervisor error: An error occurred, but the cause is unknown After: error: failed to connect to the hypervisor error: operation failed: volume with target path '/dev/disk/by-path/pci-000= 0:00:17.0-ata-30' already exist src/conf/virstorageobj.c | 45 +++++++++++++++++++++++++++++++++------- 1 file changed, 37 insertions(+), 8 deletions(-) diff --git a/src/conf/virstorageobj.c b/src/conf/virstorageobj.c index 59fa5da372..ac79ff4c26 100644 --- a/src/conf/virstorageobj.c +++ b/src/conf/virstorageobj.c @@ -621,19 +621,44 @@ virStoragePoolObjAddVol(virStoragePoolObj *obj, virStorageVolObj *volobj =3D NULL; virStorageVolObjList *volumes =3D obj->volumes; =20 + if (!voldef->key) { + virReportError(VIR_ERR_OPERATION_FAILED, "%s", + _("volume is missing key")); + return -1; + } + if (!voldef->name) { + virReportError(VIR_ERR_OPERATION_FAILED, "%s", + _("volume is missing name")); + return -1; + } + if (!voldef->target.path) { + virReportError(VIR_ERR_OPERATION_FAILED, "%s", + _("volume is missing target path")); + return -1; + } + virObjectRWLockWrite(volumes); =20 - if (!voldef->key || !voldef->name || !voldef->target.path || - g_hash_table_contains(volumes->objsKey, voldef->key) || - g_hash_table_contains(volumes->objsName, voldef->name) || - g_hash_table_contains(volumes->objsPath, voldef->target.path)) { - virObjectRWUnlock(volumes); - return -1; + if (g_hash_table_contains(volumes->objsKey, voldef->key)) { + virReportError(VIR_ERR_OPERATION_FAILED, + _("volume with key '%1$s' already exist"), + voldef->key); + goto error; + } + if (g_hash_table_contains(volumes->objsName, voldef->name)) { + virReportError(VIR_ERR_STORAGE_VOL_EXIST, + _("'%1$s'"), voldef->name); + goto error; + } + if (g_hash_table_contains(volumes->objsPath, voldef->target.path)) { + virReportError(VIR_ERR_OPERATION_FAILED, + _("volume with target path '%1$s' already exist"), + voldef->target.path); + goto error; } =20 if (!(volobj =3D virStorageVolObjNew())) { - virObjectRWUnlock(volumes); - return -1; + goto error; } =20 VIR_WITH_OBJECT_LOCK_GUARD(volobj) { @@ -652,6 +677,10 @@ virStoragePoolObjAddVol(virStoragePoolObj *obj, virObjectUnref(volobj); virObjectRWUnlock(volumes); return 0; + + error: + virObjectRWUnlock(volumes); + return -1; } =20 =20 --=20 2.52.0