From nobody Tue Feb 10 01:50:24 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.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.129.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=1685941665; cv=none; d=zohomail.com; s=zohoarc; b=VE4EibdTYOFHTsuDxUZiju0aVHNUcbrGrnm/RS4b4tLtnZomJPzMngO3x71SPoFSFtFlv7LYbTF0WMeyFOCquu7kbENlHkJU4IdI/a9K5ypnPQdzLqN6AW51td+cjwdk3Hp1YxLyxltWG2o/xYCWeyVFLzOe2ABouC0oGH1kWqQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685941665; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=/BBHFLnHMWfyNT5RuBO1/Rtv7wSKg93g5h12QQxkWtw=; b=bqBM1d/9GnTez7bYx5T7o8CBChjKN1n3s/X4HhPT5PT+SiO2+CAPyPes459yGqWoRr/bpPOSH3Qw47oqbf6s1MzX6LiM3Cexn7SQ8rAWlaEDSlxLkiNAowazQO10i0H47uHgJVqBomiPzdpmUnoONpdBHSWKOTSMJ/oCuUPSu98= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.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.129.124]) by mx.zohomail.com with SMTPS id 1685941665650413.3305635582335; Sun, 4 Jun 2023 22:07:45 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-369-8QG8U05nP_2zdXyBbsq0ag-1; Mon, 05 Jun 2023 01:07:39 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4ECE91C05ADD; Mon, 5 Jun 2023 05:07:37 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id E3E19C154D7; Mon, 5 Jun 2023 05:07:36 +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 B9AAD19465A0; Mon, 5 Jun 2023 05:07:36 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id DB8F21946595 for ; Mon, 5 Jun 2023 05:07:35 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id B95539E75; Mon, 5 Jun 2023 05:07:35 +0000 (UTC) Received: from localhost.localdomain (ovpn-12-23.pek2.redhat.com [10.72.12.23]) by smtp.corp.redhat.com (Postfix) with ESMTP id 52DB07AE4; Mon, 5 Jun 2023 05:07:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685941664; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=/BBHFLnHMWfyNT5RuBO1/Rtv7wSKg93g5h12QQxkWtw=; b=ROAYNW57VgOuLuH/etydhJxdxJ+42PUlZJDThjxa/Id7nNcWGS9YwrTjlgH4LOKJ+dEDXg tWDWay9jcohkAYABjG+/qTb+4S50mpRSBjD1zE0q8Qbdkrq9jRz7oIwpwDbab6Bpl0YutT OIiGj2TMPv4TOIcqIMiuG3sz1CqwZ4A= X-MC-Unique: 8QG8U05nP_2zdXyBbsq0ag-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Han Han To: libvir-list@redhat.com Subject: [PATCH] qemu: Support removable for scsi disk Date: Mon, 5 Jun 2023 13:07:29 +0800 Message-Id: <20230605050729.1194184-1-hhan@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 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: , Cc: Han Han Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 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: 1685941667189100001 Content-Type: text/plain; charset="utf-8"; x-default="true" Allow //disk/target@removable for scsi disk devices, since QEMU has support the removable attribute for scsi-hd device from v0.14.0[1]. [1]: 419e691f8e: scsi-disk: Allow overriding SCSI INQUIRY removable bit Signed-off-by: Han Han Reviewed-by: Michal Privoznik --- docs/formatdomain.rst | 2 +- src/conf/domain_validate.c | 5 +++-- src/qemu/qemu_command.c | 6 ++++-- ...gs =3D> disk-device-removable.x86_64-latest.args} | 14 +++++++++----- ...ice-removable.xml =3D> disk-device-removable.xml} | 5 +++++ tests/qemuxml2argvtest.c | 2 +- 6 files changed, 23 insertions(+), 11 deletions(-) rename tests/qemuxml2argvdata/{disk-usb-device-removable.x86_64-latest.arg= s =3D> disk-device-removable.x86_64-latest.args} (70%) rename tests/qemuxml2argvdata/{disk-usb-device-removable.xml =3D> disk-dev= ice-removable.xml} (80%) diff --git a/docs/formatdomain.rst b/docs/formatdomain.rst index c3526439bf..676e4b9fd3 100644 --- a/docs/formatdomain.rst +++ b/docs/formatdomain.rst @@ -3094,7 +3094,7 @@ paravirtualized driver is specified via the ``disk`` = element. CDROM or Floppy disk), the value can be either "open" or "closed", defa= ults to "closed". NB, the value of ``tray`` could be updated while the domai= n is running. The optional attribute ``removable`` sets the removable flag f= or USB - disks, and its value can be either "on" or "off", defaulting to "off". + or SCSI disks, and its value can be either "on" or "off", defaulting to= "off". The optional attribute ``rotation_rate`` sets the rotation rate of the storage for disks on a SCSI, IDE, or SATA bus. Values in the range 1025= to 65534 are used to indicate rotational media speed in revolutions per mi= nute. diff --git a/src/conf/domain_validate.c b/src/conf/domain_validate.c index 80d6a2ffd9..e7122f6297 100644 --- a/src/conf/domain_validate.c +++ b/src/conf/domain_validate.c @@ -881,9 +881,10 @@ virDomainDiskDefValidate(const virDomainDef *def, } =20 if (disk->removable !=3D VIR_TRISTATE_SWITCH_ABSENT && - disk->bus !=3D VIR_DOMAIN_DISK_BUS_USB) { + disk->bus !=3D VIR_DOMAIN_DISK_BUS_USB && + !(disk->bus =3D=3D VIR_DOMAIN_DISK_BUS_SCSI && disk->device =3D=3D= VIR_DOMAIN_DISK_DEVICE_DISK)) { virReportError(VIR_ERR_XML_ERROR, "%s", - _("removable is only valid for usb disks")); + _("removable is only valid for usb or scsi disks")); return -1; } =20 diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 72363238b8..5ec912ddee 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -1781,10 +1781,12 @@ qemuBuildDiskDeviceProps(const virDomainDef *def, if (disk->device =3D=3D VIR_DOMAIN_DISK_DEVICE_LUN) { driver =3D "scsi-block"; } else { - if (disk->device =3D=3D VIR_DOMAIN_DISK_DEVICE_CDROM) + if (disk->device =3D=3D VIR_DOMAIN_DISK_DEVICE_CDROM) { driver =3D "scsi-cd"; - else + } else { driver =3D "scsi-hd"; + removable =3D disk->removable; + } =20 /* qemu historically used the name of -drive as one of the dev= ice * ids in the Vital Product Data Device Identification page if diff --git a/tests/qemuxml2argvdata/disk-usb-device-removable.x86_64-latest= .args b/tests/qemuxml2argvdata/disk-device-removable.x86_64-latest.args similarity index 70% rename from tests/qemuxml2argvdata/disk-usb-device-removable.x86_64-latest.= args rename to tests/qemuxml2argvdata/disk-device-removable.x86_64-latest.args index c5bfd8e8e0..106f7b9ce2 100644 --- a/tests/qemuxml2argvdata/disk-usb-device-removable.x86_64-latest.args +++ b/tests/qemuxml2argvdata/disk-device-removable.x86_64-latest.args @@ -27,13 +27,17 @@ XDG_CONFIG_HOME=3D/var/lib/libvirt/qemu/domain--1-QEMUG= uest1/.config \ -no-shutdown \ -boot strict=3Don \ -device '{"driver":"piix3-usb-uhci","id":"usb","bus":"pci.0","addr":"0x1.0= x2"}' \ --blockdev '{"driver":"host_device","filename":"/dev/HostVG/QEMUGuest1","no= de-name":"libvirt-2-storage","auto-read-only":true,"discard":"unmap"}' \ +-device '{"driver":"virtio-scsi-pci","id":"scsi0","bus":"pci.0","addr":"0x= 2"}' \ +-blockdev '{"driver":"host_device","filename":"/dev/HostVG/QEMUGuest1","no= de-name":"libvirt-3-storage","auto-read-only":true,"discard":"unmap"}' \ +-blockdev '{"node-name":"libvirt-3-format","read-only":false,"driver":"raw= ","file":"libvirt-3-storage"}' \ +-device '{"driver":"ide-hd","bus":"ide.0","unit":0,"drive":"libvirt-3-form= at","id":"ide0-0-0","bootindex":1}' \ +-blockdev '{"driver":"file","filename":"/tmp/usbdisk.img","node-name":"lib= virt-2-storage","auto-read-only":true,"discard":"unmap"}' \ -blockdev '{"node-name":"libvirt-2-format","read-only":false,"driver":"raw= ","file":"libvirt-2-storage"}' \ --device '{"driver":"ide-hd","bus":"ide.0","unit":0,"drive":"libvirt-2-form= at","id":"ide0-0-0","bootindex":1}' \ --blockdev '{"driver":"file","filename":"/tmp/usbdisk.img","node-name":"lib= virt-1-storage","auto-read-only":true,"discard":"unmap"}' \ +-device '{"driver":"usb-storage","bus":"usb.0","port":"1","drive":"libvirt= -2-format","id":"usb-disk0","removable":true}' \ +-blockdev '{"driver":"file","filename":"/tmp/scsidisk.img","node-name":"li= bvirt-1-storage","auto-read-only":true,"discard":"unmap"}' \ -blockdev '{"node-name":"libvirt-1-format","read-only":false,"driver":"raw= ","file":"libvirt-1-storage"}' \ --device '{"driver":"usb-storage","bus":"usb.0","port":"1","drive":"libvirt= -1-format","id":"usb-disk0","removable":true}' \ +-device '{"driver":"scsi-hd","bus":"scsi0.0","channel":0,"scsi-id":0,"lun"= :1,"device_id":"drive-scsi0-0-0-1","drive":"libvirt-1-format","id":"scsi0-0= -0-1","removable":true}' \ -audiodev '{"id":"audio1","driver":"none"}' \ --device '{"driver":"virtio-balloon-pci","id":"balloon0","bus":"pci.0","add= r":"0x2"}' \ +-device '{"driver":"virtio-balloon-pci","id":"balloon0","bus":"pci.0","add= r":"0x3"}' \ -sandbox on,obsolete=3Ddeny,elevateprivileges=3Ddeny,spawn=3Ddeny,resource= control=3Ddeny \ -msg timestamp=3Don diff --git a/tests/qemuxml2argvdata/disk-usb-device-removable.xml b/tests/q= emuxml2argvdata/disk-device-removable.xml similarity index 80% rename from tests/qemuxml2argvdata/disk-usb-device-removable.xml rename to tests/qemuxml2argvdata/disk-device-removable.xml index 927a8e8b3e..9400c84863 100644 --- a/tests/qemuxml2argvdata/disk-usb-device-removable.xml +++ b/tests/qemuxml2argvdata/disk-device-removable.xml @@ -22,6 +22,11 @@ + + + + + diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index d914d8cbea..d6a9ab865d 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -1227,7 +1227,7 @@ mymain(void) DO_TEST_CAPS_LATEST_PARSE_ERROR("disk-device-lun-type-invalid"); DO_TEST_CAPS_LATEST_PARSE_ERROR("disk-attaching-partition-nosupport"); DO_TEST_CAPS_LATEST("disk-usb-device"); - DO_TEST_CAPS_LATEST("disk-usb-device-removable"); + DO_TEST_CAPS_LATEST("disk-device-removable"); DO_TEST_CAPS_LATEST_PARSE_ERROR("disk-usb-pci"); DO_TEST_CAPS_LATEST("disk-scsi"); DO_TEST_CAPS_LATEST("disk-scsi-device-auto"); --=20 2.40.1