From nobody Sun Feb 8 23:06:10 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=1698234024; cv=none; d=zohomail.com; s=zohoarc; b=PC39lJCzIdRMawsX66MfD7iIFj5eB6gLxNJvA907wbea0UzJvUE+RfRyDh4vgdauyzE5c9iJFgbD3RnTwqWpXu1F69oKfAMBDo1oAPnEC03TIhlIARbwes/C/piR0FTxDTmTnBv/cm4KOx0N6cVlV0uHDC9CkK0euIK9PAYGCzA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1698234024; 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=i429SgVDmoNwzGkOnt0fHxhBVKTIzyLMRPEC0qg8y0I=; b=NvPNtnqTd5cAiNZvFv+oXrs/vAJvKW/oJ9EyeNpWArW1tcCajTAssrxXu971sF03+J3DhSdu1S8v7uIgVIsnoDsDK+GHOAi9zvxzgrMaztFDilFXArLmreuqqxi/eKd6KwlBsN0Pi8IFMQDWjexWs0vy2Ta+qii1E5uAihhjfp8= 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 1698234024351459.95372224823154; Wed, 25 Oct 2023 04:40:24 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-108-LegDdRK2MASsZwVGdNjLwQ-1; Wed, 25 Oct 2023 07:40:06 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (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 1B37481654A; Wed, 25 Oct 2023 11:39:50 +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 00A4220268F8; Wed, 25 Oct 2023 11:39:50 +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 94C7119466E6; Wed, 25 Oct 2023 11:39:49 +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 4DF791946586 for ; Wed, 25 Oct 2023 11:39:49 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 3D8B6492BFB; Wed, 25 Oct 2023 11:39:49 +0000 (UTC) Received: from speedmetal.lan (unknown [10.45.242.14]) by smtp.corp.redhat.com (Postfix) with ESMTP id C0A7C492BFA for ; Wed, 25 Oct 2023 11:39:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1698234023; 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=i429SgVDmoNwzGkOnt0fHxhBVKTIzyLMRPEC0qg8y0I=; b=BoxWVdUVzgeCblGZyxqmxYth9pGs2Cj4Qew7AOwa7actBP3cujedc4DVdOsQjWr6pGXQGb myjo5QaW/WpHz8JbO8luATUOwRPadLfzNZdSiZWyA0F+bdhIRiN0sCAa3jaNg8aZ7TRUDO FiFBZyiQnvo+ThD4Dj57vgbyEwtBOkU= X-MC-Unique: LegDdRK2MASsZwVGdNjLwQ-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 07/22] qemuDomainDiskCachemodeFlags: Simplify usage Date: Wed, 25 Oct 2023 13:39:17 +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.4 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: 1698234025444100009 Content-Type: text/plain; charset="utf-8" Return whether a relevant cachemode was presented rather than returning an error, so that callers can be simplified. Use the proper enum type as argument rather than typecasting in the switch statement. Signed-off-by: Peter Krempa --- src/qemu/qemu_block.c | 5 +---- src/qemu/qemu_command.c | 15 ++++++--------- src/qemu/qemu_domain.c | 31 +++++++++++++++++-------------- src/qemu/qemu_domain.h | 4 ++-- 4 files changed, 26 insertions(+), 29 deletions(-) diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c index 3be12b47e3..0f47b5b37f 100644 --- a/src/qemu/qemu_block.c +++ b/src/qemu/qemu_block.c @@ -919,12 +919,9 @@ qemuBlockStorageSourceGetBlockdevGetCacheProps(virStor= ageSource *src, bool direct =3D false; bool noflush =3D false; - if (src->cachemode =3D=3D VIR_DOMAIN_DISK_CACHE_DEFAULT) + if (!qemuDomainDiskCachemodeFlags(src->cachemode, NULL, &direct, &nofl= ush)) return 0; - if (qemuDomainDiskCachemodeFlags(src->cachemode, NULL, &direct, &noflu= sh) < 0) - return -1; - if (virJSONValueObjectAdd(&cacheobj, "b:direct", direct, "b:no-flush", noflush, diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index dbef8d0068..fd0f12f304 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -1889,16 +1889,13 @@ qemuBuildDiskDeviceProps(const virDomainDef *def, wwn =3D virJSONValueNewNumberUlong(w); } - if (disk->cachemode !=3D VIR_DOMAIN_DISK_CACHE_DEFAULT) { - /* VIR_DOMAIN_DISK_DEVICE_LUN translates into 'scsi-block' - * where any caching setting makes no sense. */ - if (disk->device !=3D VIR_DOMAIN_DISK_DEVICE_LUN) { - bool wb; - - if (qemuDomainDiskCachemodeFlags(disk->cachemode, &wb, NULL, - NULL) < 0) - return NULL; + /* 'write-cache' component of disk->cachemode is set on device level. + * VIR_DOMAIN_DISK_DEVICE_LUN translates into 'scsi-block' where any + * caching setting makes no sense. */ + if (disk->device !=3D VIR_DOMAIN_DISK_DEVICE_LUN) { + bool wb; + if (qemuDomainDiskCachemodeFlags(disk->cachemode, &wb, NULL, NULL)= ) { writeCache =3D virTristateSwitchFromBool(wb); } } diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 995aa3f79c..0b36a49bdf 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -11406,13 +11406,18 @@ qemuDomainPrepareHostdev(virDomainHostdevDef *hos= tdev, /** * qemuDomainDiskCachemodeFlags: + * @cachemode: aggregated cache mode + * @writeback: populated with 'writeback' component of @cachemode (may be = NULL) + * @direct: populated with 'direct' component of @cachemode (may be NULL) + * @noflush: populated with 'noflush' component of @cachemode (may be NULL) * - * Converts disk cachemode to the cache mode options for qemu. Returns -1 = for - * invalid @cachemode values and fills the flags and returns 0 on success. - * Flags may be NULL. + * Converts disk @cachemode to the cache mode options for qemu according t= o the + * table below. + * + * Returns true if @cachemode is a relevant cache mode setting. */ -int -qemuDomainDiskCachemodeFlags(int cachemode, +bool +qemuDomainDiskCachemodeFlags(virDomainDiskCache cachemode, bool *writeback, bool *direct, bool *noflush) @@ -11442,40 +11447,38 @@ qemuDomainDiskCachemodeFlags(int cachemode, *writeback =3D true; *direct =3D true; *noflush =3D false; - break; + return true; case VIR_DOMAIN_DISK_CACHE_WRITETHRU: *writeback =3D false; *direct =3D false; *noflush =3D false; - break; + return true; case VIR_DOMAIN_DISK_CACHE_WRITEBACK: *writeback =3D true; *direct =3D false; *noflush =3D false; - break; + return true; case VIR_DOMAIN_DISK_CACHE_DIRECTSYNC: *writeback =3D false; *direct =3D true; *noflush =3D false; - break; + return true; case VIR_DOMAIN_DISK_CACHE_UNSAFE: *writeback =3D true; *direct =3D false; *noflush =3D true; - break; + return true; case VIR_DOMAIN_DISK_CACHE_DEFAULT: case VIR_DOMAIN_DISK_CACHE_LAST: - default: - virReportEnumRangeError(virDomainDiskCache, cachemode); - return -1; + return false; } - return 0; + return false; } diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h index a3fc6acaaa..1e56e50672 100644 --- a/src/qemu/qemu_domain.h +++ b/src/qemu/qemu_domain.h @@ -1008,8 +1008,8 @@ qemuDomainPrepareDiskSource(virDomainDiskDef *disk, qemuDomainObjPrivate *priv, virQEMUDriverConfig *cfg); -int -qemuDomainDiskCachemodeFlags(int cachemode, +bool +qemuDomainDiskCachemodeFlags(virDomainDiskCache cachemode, bool *writeback, bool *direct, bool *noflush); --=20 2.41.0