From nobody Wed May 14 14:01:08 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 152406570419315.183810237009766; Wed, 18 Apr 2018 08:35:04 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7BF3D3142282; Wed, 18 Apr 2018 15:35:02 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3F9307D660; Wed, 18 Apr 2018 15:35:02 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id BA0B5180596E; Wed, 18 Apr 2018 15:35:01 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w3IFXr2Q009092 for ; Wed, 18 Apr 2018 11:33:53 -0400 Received: by smtp.corp.redhat.com (Postfix) id 82BD71134CD3; Wed, 18 Apr 2018 15:33:53 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id 091A31134CCD; Wed, 18 Apr 2018 15:33:52 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Wed, 18 Apr 2018 17:33:38 +0200 Message-Id: <713ca5060d78377729df3feafa630ff64b97943d.1524065411.git.pkrempa@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-loop: libvir-list@redhat.com Cc: Peter Krempa Subject: [libvirt] [PATCH v3 7/7] qemu: Format 'write-cache' parameter for disk frontends X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Wed, 18 Apr 2018 15:35:03 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The disk cache mode translates to various frontend and backend attributes for the qemu block layer. For the frontend device the 'writeback' parameter is used and provided as 'write-cache'. Implement this so that we can later switch to using -blockdev where we will not pass the cachemode directly any more. Signed-off-by: Peter Krempa Reviewed-by: J=EF=BF=BDn Tomko --- src/qemu/qemu_command.c | 27 ++++++++++++++++++= ++++ .../disk-drive-write-cache.x86_64-2.7.0.args | 10 ++++---- .../disk-drive-write-cache.x86_64-latest.args | 10 ++++---- 3 files changed, 39 insertions(+), 8 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 238c6ed620..b666f3715f 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -1824,6 +1824,30 @@ qemuCheckIOThreads(const virDomainDef *def, } +static int +qemuBuildDriveDevCacheStr(virDomainDiskDefPtr disk, + virBufferPtr buf, + virQEMUCapsPtr qemuCaps) +{ + bool wb; + + if (disk->cachemode =3D=3D VIR_DOMAIN_DISK_CACHE_DEFAULT) + return 0; + + if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DISK_WRITE_CACHE)) + return 0; + + if (qemuDomainDiskCachemodeFlags(disk->cachemode, &wb, NULL, NULL) < 0) + return -1; + + virBufferStrcat(buf, ",write-cache=3D", + virTristateSwitchTypeToString(virTristateSwitchFromBoo= l(wb)), + NULL); + + return 0; +} + + char * qemuBuildDriveDevStr(const virDomainDef *def, virDomainDiskDefPtr disk, @@ -2140,6 +2164,9 @@ qemuBuildDriveDevStr(const virDomainDef *def, } } + if (qemuBuildDriveDevCacheStr(disk, &opt, qemuCaps) < 0) + goto error; + if (virBufferCheckError(&opt) < 0) goto error; diff --git a/tests/qemuxml2argvdata/disk-drive-write-cache.x86_64-2.7.0.arg= s b/tests/qemuxml2argvdata/disk-drive-write-cache.x86_64-2.7.0.args index 9af27dbbaf..7b67f4369c 100644 --- a/tests/qemuxml2argvdata/disk-drive-write-cache.x86_64-2.7.0.args +++ b/tests/qemuxml2argvdata/disk-drive-write-cache.x86_64-2.7.0.args @@ -28,16 +28,18 @@ server,nowait \ -device lsi,id=3Dscsi0,bus=3Dpci.0,addr=3D0x2 \ -drive file=3D/dev/HostVG/QEMUGuest1,format=3Dqcow2,if=3Dnone,id=3Ddrive-i= de0-0-0,\ cache=3Dwriteback \ --device ide-hd,bus=3Dide.0,unit=3D0,drive=3Ddrive-ide0-0-0,id=3Dide0-0-0,b= ootindex=3D1 \ +-device ide-hd,bus=3Dide.0,unit=3D0,drive=3Ddrive-ide0-0-0,id=3Dide0-0-0,b= ootindex=3D1,\ +write-cache=3Don \ -drive file=3D/dev/HostVG/QEMUGuest1,format=3Dqcow2,if=3Dnone,id=3Ddrive-s= csi0-0-0,\ cache=3Dnone \ --device scsi-hd,bus=3Dscsi0.0,scsi-id=3D0,drive=3Ddrive-scsi0-0-0,id=3Dscs= i0-0-0 \ +-device scsi-hd,bus=3Dscsi0.0,scsi-id=3D0,drive=3Ddrive-scsi0-0-0,id=3Dscs= i0-0-0,\ +write-cache=3Don \ -drive file=3D/dev/HostVG/QEMUGuest1,format=3Dqcow2,if=3Dnone,id=3Ddrive-v= irtio-disk0,\ cache=3Dwritethrough \ -device virtio-blk-pci,scsi=3Doff,bus=3Dpci.0,addr=3D0x3,drive=3Ddrive-vir= tio-disk0,\ -id=3Dvirtio-disk0 \ +id=3Dvirtio-disk0,write-cache=3Doff \ -drive file=3D/dev/HostVG/QEMUGuest1,format=3Dqcow2,if=3Dnone,id=3Ddrive-u= sb-disk1,\ cache=3Ddirectsync \ -device usb-storage,bus=3Dusb.0,port=3D1,drive=3Ddrive-usb-disk1,id=3Dusb-= disk1,\ -removable=3Doff \ +removable=3Doff,write-cache=3Doff \ -msg timestamp=3Don diff --git a/tests/qemuxml2argvdata/disk-drive-write-cache.x86_64-latest.ar= gs b/tests/qemuxml2argvdata/disk-drive-write-cache.x86_64-latest.args index b4bef87529..a63c5b7477 100644 --- a/tests/qemuxml2argvdata/disk-drive-write-cache.x86_64-latest.args +++ b/tests/qemuxml2argvdata/disk-drive-write-cache.x86_64-latest.args @@ -28,18 +28,20 @@ server,nowait \ -device lsi,id=3Dscsi0,bus=3Dpci.0,addr=3D0x2 \ -drive file=3D/dev/HostVG/QEMUGuest1,format=3Dqcow2,if=3Dnone,id=3Ddrive-i= de0-0-0,\ cache=3Dwriteback \ --device ide-hd,bus=3Dide.0,unit=3D0,drive=3Ddrive-ide0-0-0,id=3Dide0-0-0,b= ootindex=3D1 \ +-device ide-hd,bus=3Dide.0,unit=3D0,drive=3Ddrive-ide0-0-0,id=3Dide0-0-0,b= ootindex=3D1,\ +write-cache=3Don \ -drive file=3D/dev/HostVG/QEMUGuest1,format=3Dqcow2,if=3Dnone,id=3Ddrive-s= csi0-0-0,\ cache=3Dnone \ --device scsi-hd,bus=3Dscsi0.0,scsi-id=3D0,drive=3Ddrive-scsi0-0-0,id=3Dscs= i0-0-0 \ +-device scsi-hd,bus=3Dscsi0.0,scsi-id=3D0,drive=3Ddrive-scsi0-0-0,id=3Dscs= i0-0-0,\ +write-cache=3Don \ -drive file=3D/dev/HostVG/QEMUGuest1,format=3Dqcow2,if=3Dnone,id=3Ddrive-v= irtio-disk0,\ cache=3Dwritethrough \ -device virtio-blk-pci,scsi=3Doff,bus=3Dpci.0,addr=3D0x3,drive=3Ddrive-vir= tio-disk0,\ -id=3Dvirtio-disk0 \ +id=3Dvirtio-disk0,write-cache=3Doff \ -drive file=3D/dev/HostVG/QEMUGuest1,format=3Dqcow2,if=3Dnone,id=3Ddrive-u= sb-disk1,\ cache=3Ddirectsync \ -device usb-storage,bus=3Dusb.0,port=3D1,drive=3Ddrive-usb-disk1,id=3Dusb-= disk1,\ -removable=3Doff \ +removable=3Doff,write-cache=3Doff \ -sandbox on,obsolete=3Ddeny,elevateprivileges=3Ddeny,spawn=3Ddeny,\ resourcecontrol=3Ddeny \ -msg timestamp=3Don --=20 2.16.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list