From nobody Tue Mar 3 03:04:39 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=pass; 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=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1771897282; cv=none; d=zohomail.com; s=zohoarc; b=SNJe1o4ndxCM7GeA1sg4/0dAXQZa9eLGGbSN9UN6vLfW4DlvrcwVtxS/naSAcg8Il4vBUfPklFivR1SfQuJ1PKd8CWs7wuoP53bseXIBpJjI/hEIIYQNLukFE2cs8dVeU2qHTf1g3L0UEPLm/hdnfVmGYlrmfOBPxzjwXR4LlU4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1771897282; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Owner:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=oUxzt0D58KzcA9Sg9+QabSYMjoX6Higtm9cWPnzSAPg=; b=m5O0vxaQ5bZLEIZYeMtsSa7mh5epfFGXxCLB7lWI6Atyib3CP1c59yFdvE+KA0lVr8xa/FMbDE5XJhE1+41b7wdp4i5nRe+nP4WkegVxxjU2wis4R6O1qSNQe9FtVoyeTkouXAr2bdNMsD//1D0HJeUjYthOnB6i2naAPkS0mqw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=none dis=none) Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1771897282550905.353255062275; Mon, 23 Feb 2026 17:41:22 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 993) id BB7B941BDD; Mon, 23 Feb 2026 20:41:22 -0500 (EST) Received: from [172.19.199.9] (lists.libvirt.org [8.43.85.245]) by lists.libvirt.org (Postfix) with ESMTP id AE58741CCB; Mon, 23 Feb 2026 20:40:01 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 993) id 7042141C7F; Mon, 23 Feb 2026 20:39:57 -0500 (EST) Received: from mail-vk1-f178.google.com (mail-vk1-f178.google.com [209.85.221.178]) (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 62C6941B54 for ; Mon, 23 Feb 2026 20:39:54 -0500 (EST) Received: by mail-vk1-f178.google.com with SMTP id 71dfb90a1353d-5663724e4daso4773836e0c.3 for ; Mon, 23 Feb 2026 17:39:54 -0800 (PST) Received: from localhost.localdomain ([2804:29b8:5090:5879:4cd3:397a:436f:4859]) by smtp.gmail.com with ESMTPSA id 71dfb90a1353d-568f60e0419sm6863782e0c.5.2026.02.23.17.39.50 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 23 Feb 2026 17:39:52 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,HELO_MISC_IP,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=gmail.com; s=20230601; t=1771897193; x=1772501993; darn=lists.libvirt.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=oUxzt0D58KzcA9Sg9+QabSYMjoX6Higtm9cWPnzSAPg=; b=DApO3hQTOuufOfSHnV1tRw7XYGmAIbbL+Wmd8dfh6Z82BfKl78AxiFLfpSIBG6YQEy 7rWeAlZlmNbV5mmFCkUHh2nGGYgeJhNajROZlxIV4t3VDFc+D4MAGGoZXagUcEIgZW8d r7cDen3jh1YJHZyI+RwM5BNx1munHjBqVZ6+1REAJqGIfWriE3h8HV82N+UFkQbrx5tg /Rn098YNDmHdO1y3eH2NjA447bLb3gKl6+kLmMyD+DvAAvD0xL1AI/dqXjaA+xjZqUKg 6BNfpSTqftxP7rRgGqlSnP8DqlY/Wf6YD+fwlpURQ3tVT9z/smzhve2Gy8C0/kTjnb5N kh2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771897193; x=1772501993; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=oUxzt0D58KzcA9Sg9+QabSYMjoX6Higtm9cWPnzSAPg=; b=k2IbHDg48X2GXWfIrOQ+I7Z3o7U05SIxiRdxBClUSH9fcMujG6lEIwfETs/DDVOtpf Cl1Uk2YsQKN1tXNxjyaIdoYljnYzBG67uwYbTDSCR1fy7AK5FyLVPJhGwbLiQ0OdY30r NsRfRwuqakF2WYePNnNcVNz0pB7d27SIR5wy+YRlX4wAhPjff1AdGfVdzs8h7efhWjgA zxc76yu85BoYzD/3OCt19B/rqrRbQx/veVIXaK7NECAYxCQVIGBworVp8d+Zr2ZobtXZ u+7PZuGHjHF0pdnNOOQSnTtVTRoZEamwtd2Ps9fuLbnI5vwAHuzPnqsrX8rMKVWquGXt asTg== X-Gm-Message-State: AOJu0YxWpHChAzYZXlhDLOFX77pdw//GXkTSJ8QVRk5krz1TXgdTB8JW +kBZ0tnr3th5zkjvFLeH+xvvQtf65BWBNoWfEjXVgaLyUETCfYwdkwS9P1t5ow== X-Gm-Gg: ATEYQzxr/M4n+TjbByV9NQaZQGFsUEw3tKO5gUik6hfkBgBezo1O15OWzXJ77vrhv+w gFGyoIc1nVAWtHzWP3hWeO7ePy/w01fJ6x2x2h0BxHOwgcE1F1/HEwKo/dEcCy90nXXuZC/Yp+a vxRPljDocnwUVirtV3YnlEQ9JnjSFnCfeAtRJ6OMgCoC7aTnddEOi6YFo1C1l+iB8gvWhVqcofB I1fbNVoT/8VCDSuCrRhxA5xZt72B9NZbYErY0MXdvuhTTyUbhACr7seMs5c6I9e5lKctbFOWQck lIVgkvPEsy/Q1/RBIn9oOJa9qkmOs5HgjLYCzn5o+mslERBCQI/1NGgN2LgpldeyCp8VeNE+v4p aq5zTi+pkxPl0Za9plWrfBVcRW5S+z0z8DDVAftB08SW5YhUraJSOI/utKhKsoUWi09CE1GrbaY ZMKsHLFnbud48HXZU8oX6knaxCZYC4/EkvsQDgpC20eMoYdwFOtAiEv/3fjdO4/ugq X-Received: by 2002:a05:6122:1d0f:b0:537:3e57:6bdc with SMTP id 71dfb90a1353d-568e48681efmr4618632e0c.12.1771897193429; Mon, 23 Feb 2026 17:39:53 -0800 (PST) From: Lucas Amaral To: devel@lists.libvirt.org Subject: [PATCH 1/2] storage: fix error code for async jobs check in pool operations Date: Mon, 23 Feb 2026 22:39:42 -0300 Message-ID: <20260224013943.37829-2-lucaaamaral@gmail.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260224013943.37829-1-lucaaamaral@gmail.com> References: <20260224013943.37829-1-lucaaamaral@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-ID-Hash: EIO3RNQS2QQS7ZJLEHVZPNLWM4SS7GIA X-Message-ID-Hash: EIO3RNQS2QQS7ZJLEHVZPNLWM4SS7GIA X-MailFrom: lucaaamaral@gmail.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 CC: Lucas Amaral 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: X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1771897284804158500 Content-Type: text/plain; charset="utf-8" storagePoolUndefine(), storagePoolDestroy(), storagePoolDelete(), and storagePoolRefresh() all report VIR_ERR_INTERNAL_ERROR when a pool has asynchronous jobs running. This error code implies a bug in libvirt, but the condition is a normal transient state that occurs during concurrent volume creation. Change the error code to VIR_ERR_OPERATION_INVALID, which is consistent with the adjacent checks for "pool is not active" and "pool is starting up" in the same functions. Signed-off-by: Lucas Amaral --- Build-tested on CentOS Stream 9 (297 OK, 0 failures). Validated by reproducing the async jobs error using LD_PRELOAD to inject a 15-second delay into fallocate64() for pool directory files (fallocate is instant on local filesystems, making the race window too narrow to hit otherwise). With this patch: Before: error: internal error: pool 'default' has asynchronous jobs running. After: error: Requested operation is not valid: pool 'default' has asynchronou= s jobs running. src/storage/storage_driver.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c index e19e032427..8f5c921157 100644 --- a/src/storage/storage_driver.c +++ b/src/storage/storage_driver.c @@ -868,7 +868,7 @@ storagePoolUndefine(virStoragePoolPtr pool) } =20 if (virStoragePoolObjGetAsyncjobs(obj) > 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, + virReportError(VIR_ERR_OPERATION_INVALID, _("pool '%1$s' has asynchronous jobs running."), def->name); goto cleanup; @@ -1089,7 +1089,7 @@ storagePoolDestroy(virStoragePoolPtr pool) } =20 if (virStoragePoolObjGetAsyncjobs(obj) > 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, + virReportError(VIR_ERR_OPERATION_INVALID, _("pool '%1$s' has asynchronous jobs running."), def->name); goto cleanup; @@ -1161,7 +1161,7 @@ storagePoolDelete(virStoragePoolPtr pool, } =20 if (virStoragePoolObjGetAsyncjobs(obj) > 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, + virReportError(VIR_ERR_OPERATION_INVALID, _("pool '%1$s' has asynchronous jobs running."), def->name); goto cleanup; --=20 2.52.0 From nobody Tue Mar 3 03:04:39 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=pass; 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=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1771897332; cv=none; d=zohomail.com; s=zohoarc; b=a7pl81jWZXRTJ7wnq61oy7saGORPu1dzisM+lpoMHOrEFzupumSkvQHYJrc8ZE2PcjJzO9wm8CkfkjLjPGroZDJ4W5SUpRbg2f3/0DW/j2ya8bSywaTubK+npYaUblPemvlRAbuPc1sRnMJqWc70fY0XFQ+UpHEwrIBPsYvGu4A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1771897332; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Owner:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=CLrCAOxB4572cKiNzgC4pUWRuFP8baUFnSdjjgZ9UY8=; b=QM9cGkcKCDpMq5IqNyT4EL3AOGat3Smmt1YTahrQnIXZT2bCo4Fp3f4RdQ5lJCiicc48kypqEIQfW956GyF3arotpOwNTwhjc+FirONjtGqthdIzqDG5VIUDzdr1rMZBKXgTUgcKguJpQZAqmKIOriDlkWUtsJ9+z65jv7R6sYA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=none dis=none) Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1771897332046848.7616170266963; Mon, 23 Feb 2026 17:42:12 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 993) id 1B6D341B5D; Mon, 23 Feb 2026 20:42:11 -0500 (EST) Received: from [172.19.199.9] (lists.libvirt.org [8.43.85.245]) by lists.libvirt.org (Postfix) with ESMTP id F358B41CDE; Mon, 23 Feb 2026 20:40:43 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 993) id 3DEB841BE0; Mon, 23 Feb 2026 20:40:40 -0500 (EST) Received: from mail-vk1-f175.google.com (mail-vk1-f175.google.com [209.85.221.175]) (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 029B541B64 for ; Mon, 23 Feb 2026 20:39:57 -0500 (EST) Received: by mail-vk1-f175.google.com with SMTP id 71dfb90a1353d-56706fd623fso3500029e0c.3 for ; Mon, 23 Feb 2026 17:39:56 -0800 (PST) Received: from localhost.localdomain ([2804:29b8:5090:5879:4cd3:397a:436f:4859]) by smtp.gmail.com with ESMTPSA id 71dfb90a1353d-568f60e0419sm6863782e0c.5.2026.02.23.17.39.53 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 23 Feb 2026 17:39:55 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,HELO_MISC_IP,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=gmail.com; s=20230601; t=1771897196; x=1772501996; darn=lists.libvirt.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=CLrCAOxB4572cKiNzgC4pUWRuFP8baUFnSdjjgZ9UY8=; b=lkOuIvk73F5JLwOTE6r5KfekuVSGA7xEpKF9j23gZkf3UQKsa+L9bDFqb5hc/oXK9o QX5IrhltObjvRvlMeQqYPZVbzDr3lCiEwYqGkyIDE9SHP1ALn7XGWk3Jt2spNDZeXKm+ UYG/m9qxo6eJrY2Zksma1s5TxmXadsAXoYV4/Cmt2esLUjhvB6/zZyJh17uAm0zV2B7A xu+8T0HbSFC/rgg+2YQul4w9yHFrp+ObJSJZckcyrd93qdbKoVdsZYPSibYiXapDZiI/ PkMGqowj+7mOMFhFQYE41uyYC7z/NskA58eJ5ZVkbimmqcBN0t117Tlie8L1q8aQ0fWe kQsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771897196; x=1772501996; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=CLrCAOxB4572cKiNzgC4pUWRuFP8baUFnSdjjgZ9UY8=; b=K3s3DURLlxx0rGFuOyxEvf3CgHvw+iAzlFHllHCXrSkMMIeBzyZvBfYTUeqj6oKPgv fF5q2JK8/IIpoR5NqZMHr4OpZAdG7XG6aBdHaHB4IFAuHgFOT0656CpgZ8bDZq5DPLae QAytyKAVOVB7s24vaM1g2NdSw+t7jEc0/9oRX0gNQ3pdz2qMpdkJukZiyj0sAl+naXzV fuw63Gm6AC+AXLZNhZ79W5EG+mfAVGDrqb1QQVXxaTQMq6NDRdtovwzy3eTB56pGiUY3 GSJXMCAfrIjxbNJkcmBvuTYKj4uVyUzKLISgPiHPlQLqCaLoar31joHoZVGN+fkHs+yz 4L5Q== X-Gm-Message-State: AOJu0Yw20THOkc0/fW+RhhziI7tGwKZLVl8eIjFs4A2jqt1f+5gnpUhp //5OHUT+WtU/cTxgjKuxNo1y8a1nmPB3qBlKqTdGLnZ+QojMlDxrtKh9X+uqHQ== X-Gm-Gg: ATEYQzxZ6iE1H4B6+0J1PM2P6bYrQANkY1a4WLIJ25gULUcZ8ksBZp7WiyZQBEiEFtk 4b+0brFcoICfl6w10uJNDX366EfNf+iMqlOdnZeT5zKN6iiWWTYAhGR3+uRR8jLX+D9RLL/Lkso b/X4NauJvtn6Y0dK7pe18FsOD5Fx0R/gvOKfbnA7XHMyWAz7e1o96pgZTVwEpEmlqlIT9a8VBIF 3TYDxA1maF+0mHATx6I6Zd1H8Z8Mw20eUTPLqREeM/4treK6tXIPbLxYNjOs9rMamFWaH06PYUV TwG1PtfzybjkPf34/jaJyYQjaPBUN3GNVV2PdcAjlj42R/cjylv9HSi0CwIg5BTWkkA9uEcxdvK XgHv82T1ISUW+Acm/Bcq98DwJsIOOor8jn0mzxRtyE8C18eWZ10otr8oUAPpRU7vpRoXEguGp4b 3kYFFM9k7TPI6txZYBU/xzP4RwM+tlmwOipr6q38EwGjmbPCtp2GaNsBSvj/UbErUW X-Received: by 2002:a05:6122:8cb:b0:567:d87:e18c with SMTP id 71dfb90a1353d-568e4891e9fmr3728500e0c.9.1771897196063; Mon, 23 Feb 2026 17:39:56 -0800 (PST) From: Lucas Amaral To: devel@lists.libvirt.org Subject: [PATCH 2/2] storage: wait for async jobs to drain during pool refresh Date: Mon, 23 Feb 2026 22:39:43 -0300 Message-ID: <20260224013943.37829-3-lucaaamaral@gmail.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260224013943.37829-1-lucaaamaral@gmail.com> References: <20260224013943.37829-1-lucaaamaral@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-ID-Hash: KUGIONXC3C3T7VA3HZK6PNXA7BGJYW4D X-Message-ID-Hash: KUGIONXC3C3T7VA3HZK6PNXA7BGJYW4D X-MailFrom: lucaaamaral@gmail.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 CC: Lucas Amaral 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: X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1771897333104158500 Content-Type: text/plain; charset="utf-8" When creating multiple VMs in parallel, concurrent volume creation holds an async job on the pool. A pool refresh during this window fails immediately with "pool has asynchronous jobs running", which causes cascading failures in parallel provisioning workflows. The refresh operation genuinely cannot run while a volume build is in progress (it clears all volume metadata via virStoragePoolObjClearVols), but the failure is premature since the async job will finish shortly. Add a condition variable to virStoragePoolObj that allows storagePoolRefresh() to wait up to 30 seconds for async jobs to drain. The volume build thread broadcasts the condition when it decrements asyncjobs to zero. After waking, the refresh function re-validates preconditions (pool still active, not starting) since the pool lock was released during the wait. Only storagePoolRefresh() gets the wait mechanism. The other three operations (destroy, undefine, delete) keep the immediate error because waiting to destroy or delete a pool during volume creation is not a sensible user workflow. Resolves: https://issues.redhat.com/browse/RHEL-150758 Signed-off-by: Lucas Amaral --- Build-tested on CentOS Stream 9 (297 OK, 0 failures). Runtime-validated using LD_PRELOAD to inject a 15-second delay into fallocate64() for pool directory files (the storage backend calls fallocate() directly in storage_util.c:331, which with LFS resolves to fallocate64; on local filesystems it completes in microseconds, making the race window too narrow to hit naturally). Reproduction steps (privileged CentOS Stream 9 container, virtstoraged): 1. Compile LD_PRELOAD shim that sleeps 15s in fallocate64() for files under /var/lib/libvirt/images/ larger than 1MB 2. Start virtstoraged with LD_PRELOAD 3. Create and start a dir-type pool 4. Start vol-create-as in background (triggers ~15s async job) 5. After 3s, call pool-refresh Before (unpatched): $ virsh vol-create-as default testvol 100M & $ sleep 3 && virsh pool-refresh default error: Failed to refresh pool default error: internal error: pool 'default' has asynchronous jobs running. After (both patches applied): $ virsh vol-create-as default testvol 100M & $ sleep 3 && virsh pool-refresh default Vol testvol created Pool default refreshed (waited ~12s for async job) pool-destroy correctly rejects immediately (no wait): $ virsh vol-create-as default testvol 100M & $ sleep 3 && virsh pool-destroy default error: Failed to destroy pool default error: Requested operation is not valid: pool 'default' has asynchronou= s jobs running. Vol testvol created src/conf/virstorageobj.c | 39 ++++++++++++++++++++++++++++++++++++ src/conf/virstorageobj.h | 3 +++ src/libvirt_private.syms | 1 + src/storage/storage_driver.c | 19 ++++++++++++++---- 4 files changed, 58 insertions(+), 4 deletions(-) diff --git a/src/conf/virstorageobj.c b/src/conf/virstorageobj.c index ac79ff4c26..2f8f1339ad 100644 --- a/src/conf/virstorageobj.c +++ b/src/conf/virstorageobj.c @@ -31,6 +31,7 @@ #include "virlog.h" #include "virscsihost.h" #include "virstring.h" +#include "virtime.h" #include "virvhba.h" =20 #define VIR_FROM_THIS VIR_FROM_STORAGE @@ -86,6 +87,7 @@ struct _virStoragePoolObj { bool starting; bool autostart; unsigned int asyncjobs; + virCond asyncjobsCond; =20 virStoragePoolDef *def; virStoragePoolDef *newDef; @@ -196,6 +198,11 @@ virStoragePoolObjNew(void) if (!(obj =3D virObjectLockableNew(virStoragePoolObjClass))) return NULL; =20 + if (virCondInit(&obj->asyncjobsCond) < 0) { + virObjectUnref(obj); + return NULL; + } + if (!(obj->volumes =3D virStorageVolObjListNew())) { virObjectUnref(obj); return NULL; @@ -338,6 +345,36 @@ void virStoragePoolObjDecrAsyncjobs(virStoragePoolObj *obj) { obj->asyncjobs--; + if (obj->asyncjobs =3D=3D 0) + virCondBroadcast(&obj->asyncjobsCond); +} + + +int +virStoragePoolObjWaitAsyncjobs(virStoragePoolObj *obj) +{ + unsigned long long deadline; + + if (virTimeMillisNow(&deadline) < 0) + return -1; + deadline +=3D 30 * 1000; + + while (obj->asyncjobs > 0) { + if (virCondWaitUntil(&obj->asyncjobsCond, + &obj->parent.lock, deadline) < 0) { + if (errno =3D=3D ETIMEDOUT) { + virReportError(VIR_ERR_OPERATION_TIMEOUT, + _("timed out waiting for async jobs on pool= '%1$s'"), + obj->def->name); + } else { + virReportSystemError(errno, "%s", + _("failed to wait for pool async jobs= ")); + } + return -1; + } + } + + return 0; } =20 =20 @@ -354,6 +391,8 @@ virStoragePoolObjDispose(void *opaque) =20 g_free(obj->configFile); g_free(obj->autostartLink); + + virCondDestroy(&obj->asyncjobsCond); } =20 =20 diff --git a/src/conf/virstorageobj.h b/src/conf/virstorageobj.h index e1eabfdb3a..a478d2f33e 100644 --- a/src/conf/virstorageobj.h +++ b/src/conf/virstorageobj.h @@ -110,6 +110,9 @@ virStoragePoolObjIncrAsyncjobs(virStoragePoolObj *obj); void virStoragePoolObjDecrAsyncjobs(virStoragePoolObj *obj); =20 +int +virStoragePoolObjWaitAsyncjobs(virStoragePoolObj *obj); + int virStoragePoolObjLoadAllConfigs(virStoragePoolObjList *pools, const char *configDir, diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index d8ae4f46cd..950ba51384 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1547,6 +1547,7 @@ virStoragePoolObjSetDef; virStoragePoolObjSetStarting; virStoragePoolObjVolumeGetNames; virStoragePoolObjVolumeListExport; +virStoragePoolObjWaitAsyncjobs; =20 =20 # cpu/cpu.h diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c index 8f5c921157..f7b5c8bfbd 100644 --- a/src/storage/storage_driver.c +++ b/src/storage/storage_driver.c @@ -1231,10 +1231,21 @@ storagePoolRefresh(virStoragePoolPtr pool, } =20 if (virStoragePoolObjGetAsyncjobs(obj) > 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("pool '%1$s' has asynchronous jobs running."), - def->name); - goto cleanup; + if (virStoragePoolObjWaitAsyncjobs(obj) < 0) + goto cleanup; + + if (!virStoragePoolObjIsActive(obj)) { + virReportError(VIR_ERR_OPERATION_INVALID, + _("storage pool '%1$s' is not active"), def->na= me); + goto cleanup; + } + + if (virStoragePoolObjIsStarting(obj)) { + virReportError(VIR_ERR_OPERATION_INVALID, + _("storage pool '%1$s' is starting up"), + def->name); + goto cleanup; + } } =20 stateFile =3D virFileBuildPath(driver->stateDir, def->name, ".xml"); --=20 2.52.0