From nobody Mon Feb 9 00:55:45 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1698234065; cv=none; d=zohomail.com; s=zohoarc; b=P3djQguQFHU7ZIyGAv3T/Yh5KO06hqW1gd8Lh+a7/XN8B9OxLVpnOPHPV7IZh5CkhBriK/iZUpgGA2ogtTo3LlM4NgMX8ElpiZ4oPK4+OXoBT/m/vH9W8CNpN5GiCZKi62uMrbQ3/wrKCteTaj9mBNZdgvfWY+J62AdyzBbk/1g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1698234065; h=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To:Cc; bh=3e12CsC7LePkPpcNyJPb2vsLplIdI+WYRqPY8EdnEWk=; b=VUuvzBSEp7s3Esb9r74Y/hb75zaPD5LvnaNTo7J4WxTjGovzKSCaRkfkum0w9e1B2iRWVvLwX77Qjyf9KuYmRyXx27W7eeIsVy9X9Dce4CIYJ6K+0vXdkZU4O9b3ke9fuLVAM2/USDfelszwmTOKb/zpLxk7CFg4mrIDfo67gno= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1698234065474966.6286930718451; Wed, 25 Oct 2023 04:41:05 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-317-JMiDqiErMOuCNK0ZQtFs4g-1; Wed, 25 Oct 2023 07:40:13 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (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 mimecast-mx02.redhat.com (Postfix) with ESMTPS id B22B538143B3; Wed, 25 Oct 2023 11:39:58 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 339691121319; Wed, 25 Oct 2023 11:39:58 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id DA82219465B8; Wed, 25 Oct 2023 11:39:57 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 0FFAC1946586 for ; Wed, 25 Oct 2023 11:39:57 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 01CAF492BFD; Wed, 25 Oct 2023 11:39:57 +0000 (UTC) Received: from speedmetal.lan (unknown [10.45.242.14]) by smtp.corp.redhat.com (Postfix) with ESMTP id 81FCE492BFA for ; Wed, 25 Oct 2023 11:39:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1698234064; h=from:from:sender:sender: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: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=3e12CsC7LePkPpcNyJPb2vsLplIdI+WYRqPY8EdnEWk=; b=E+bllxCwHAz9Ibsgy+kE+245yW+YEv/E7G50igwyJBV0jyKLV09cLMcuAzhGZBbllYUi46 HCXmOZEQl+0Vzf7VEm/1qVkPuqVFqqJi2mFFZ1QzadvBY+DinRrnXexwuOhNTq5N4r9DHi jS56M085ETotVPxvPeXQc+Rw9i5h+Zs= X-MC-Unique: JMiDqiErMOuCNK0ZQtFs4g-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 16/22] qemu: block: Add helper to add common properties for -blockdev configuration Date: Wed, 25 Oct 2023 13:39:26 +0200 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.10 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1698234067569100003 Content-Type: text/plain; charset="utf-8" The new helper replaces qemuBlockStorageSourceGetBlockdevFormatCommonProps and the two inline instances generating the common properties for a blockdev layer. The new helper is to be used for both the format layer and the storage backing layer, thus a new parameter 'effective' switches between the modes. Signed-off-by: Peter Krempa --- src/qemu/qemu_block.c | 128 +++++++++++++++++++++++++++++------------- 1 file changed, 88 insertions(+), 40 deletions(-) diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c index 689eb535cb..aeb05a7f00 100644 --- a/src/qemu/qemu_block.c +++ b/src/qemu/qemu_block.c @@ -931,6 +931,90 @@ qemuBlockStorageSourceGetBlockdevGetCacheProps(virStor= ageSource *src, } +/** + * qemuBlockStorageSourceAddBlockdevCommonProps: + * @props: JSON object to append the props to + * @src: storage source + * @nodename: nodename to use for @src + * @effective: Whether props for the effective(topmost) layer are to be fo= rmatted + * + * Add the common props (node name, read-only state, cache configuration, = discard) + * to a JSON object for a -blockdev definition. If @effective is true, + * the props are configured for the topmost layer used to access the data, + * otherwise the props are configured for the storage protocol backing a f= ormat + * layer. + */ +static int +qemuBlockStorageSourceAddBlockdevCommonProps(virJSONValue **props, + virStorageSource *src, + const char *nodename, + bool effective) +{ + virStorageType actualType =3D virStorageSourceGetActualType(src); + g_autoptr(virJSONValue) cache =3D NULL; + const char *detectZeroes =3D NULL; + const char *discard =3D NULL; + virTristateBool autoReadOnly =3D VIR_TRISTATE_BOOL_ABSENT; + virTristateBool readOnly =3D VIR_TRISTATE_BOOL_ABSENT; + + if (qemuBlockNodeNameValidate(nodename) < 0) + return -1; + + if (qemuBlockStorageSourceGetBlockdevGetCacheProps(src, &cache) < 0) + return -1; + + if (effective) { + virDomainDiskDetectZeroes dz =3D virDomainDiskGetDetectZeroesMode(= src->discard, + sr= c->detect_zeroes); + + if (src->discard !=3D VIR_DOMAIN_DISK_DISCARD_DEFAULT) + discard =3D virDomainDiskDiscardTypeToString(src->discard); + + if (dz !=3D VIR_DOMAIN_DISK_DETECT_ZEROES_DEFAULT) + detectZeroes =3D virDomainDiskDetectZeroesTypeToString(dz); + + autoReadOnly =3D VIR_TRISTATE_BOOL_ABSENT; + readOnly =3D virTristateBoolFromBool(src->readonly); + } else { + /* when passing a FD to qemu via the /dev/fdset mechanism qemu + * fetches the appropriate FD from the fdset by checking that it h= as + * the correct accessmode. Now with 'auto-read-only' in effect qemu + * wants to use a read-only FD first. If the user didn't pass mult= iple + * FDs the feature will not work regardless, so we'll not enable i= t. */ + if ((actualType =3D=3D VIR_STORAGE_TYPE_FILE || actualType =3D=3D = VIR_STORAGE_TYPE_BLOCK) && + src->fdtuple && src->fdtuple->nfds =3D=3D 1) { + autoReadOnly =3D VIR_TRISTATE_BOOL_ABSENT; + + /* now we setup the normal readonly flag. If user requested wr= ite access honour it */ + if (src->fdtuple->writable) + readOnly =3D VIR_TRISTATE_BOOL_NO; + else + readOnly =3D virTristateBoolFromBool(src->readonly); + } else { + autoReadOnly =3D VIR_TRISTATE_BOOL_YES; + } + + discard =3D "unmap"; + } + + /* currently unhandled global properties: + * '*force-share': 'bool' + */ + + if (virJSONValueObjectAdd(props, + "s:node-name", nodename, + "T:read-only", readOnly, + "T:auto-read-only", autoReadOnly, + "S:discard", discard, + "S:detect-zeroes", detectZeroes, + "A:cache", &cache, + NULL) < 0) + return -1; + + return 0; +} + + /** * qemuBlockStorageSourceGetBackendProps: * @src: disk source @@ -1265,52 +1349,16 @@ qemuBlockStorageSourceGetFormatQcow2Props(virStorag= eSource *src, } -static virJSONValue * -qemuBlockStorageSourceGetBlockdevFormatCommonProps(virStorageSource *src) -{ - const char *detectZeroes =3D NULL; - const char *discard =3D NULL; - virDomainDiskDetectZeroes detectZeroesMode =3D virDomainDiskGetDetectZ= eroesMode(src->discard, - = src->detect_zeroes); - g_autoptr(virJSONValue) props =3D NULL; - g_autoptr(virJSONValue) cache =3D NULL; - - if (qemuBlockNodeNameValidate(qemuBlockStorageSourceGetFormatNodename(= src)) < 0) - return NULL; - - if (qemuBlockStorageSourceGetBlockdevGetCacheProps(src, &cache) < 0) - return NULL; - - if (src->discard) - discard =3D virDomainDiskDiscardTypeToString(src->discard); - - if (detectZeroesMode) - detectZeroes =3D virDomainDiskDetectZeroesTypeToString(detectZeroe= sMode); - - /* currently unhandled global properties: - * '*force-share': 'bool' - */ - - if (virJSONValueObjectAdd(&props, - "s:node-name", qemuBlockStorageSourceGetForm= atNodename(src), - "b:read-only", src->readonly, - "S:discard", discard, - "S:detect-zeroes", detectZeroes, - "A:cache", &cache, - NULL) < 0) - return NULL; - - return g_steal_pointer(&props); -} - - static virJSONValue * qemuBlockStorageSourceGetBlockdevFormatProps(virStorageSource *src) { const char *driver =3D NULL; g_autoptr(virJSONValue) props =3D NULL; - if (!(props =3D qemuBlockStorageSourceGetBlockdevFormatCommonProps(src= ))) + if (qemuBlockStorageSourceAddBlockdevCommonProps(&props, + src, + qemuBlockStorageSourc= eGetFormatNodename(src), + true) < 0) return NULL; switch ((virStorageFileFormat) src->format) { --=20 2.41.0