all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Alexandre Derumier via pve-devel <pve-devel@lists.proxmox.com>
To: pve-devel@lists.proxmox.com
Cc: Alexandre Derumier <alexandre.derumier@groupe-cyllene.com>
Subject: [pve-devel] [PATCH qemu-server 5/6] convert disk controller device to json format
Date: Fri, 27 Jun 2025 14:42:27 +0200	[thread overview]
Message-ID: <mailman.694.1751028184.395.pve-devel@lists.proxmox.com> (raw)
In-Reply-To: <20250627124228.1542397-1-alexandre.derumier@groupe-cyllene.com>

[-- Attachment #1: Type: message/rfc822, Size: 8033 bytes --]

From: Alexandre Derumier <alexandre.derumier@groupe-cyllene.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH qemu-server 5/6] convert disk controller device to json format
Date: Fri, 27 Jun 2025 14:42:27 +0200
Message-ID: <20250627124228.1542397-6-alexandre.derumier@groupe-cyllene.com>

Signed-off-by: Alexandre Derumier <alexandre.derumier@groupe-cyllene.com>
---
 src/PVE/QemuServer.pm             | 12 ++++++------
 src/PVE/QemuServer/DriveDevice.pm | 23 +++++++++++------------
 2 files changed, 17 insertions(+), 18 deletions(-)

diff --git a/src/PVE/QemuServer.pm b/src/PVE/QemuServer.pm
index 6ee156e2..e43cf41f 100644
--- a/src/PVE/QemuServer.pm
+++ b/src/PVE/QemuServer.pm
@@ -72,7 +72,7 @@ use PVE::QemuServer::Drive qw(
     print_drive
     storage_allows_io_uring_default
 );
-use PVE::QemuServer::DriveDevice qw(print_drivedevice_controller get_drivedevice get_drivedevice_iothread scsihw_infos);
+use PVE::QemuServer::DriveDevice qw(get_drivedevice_controller get_drivedevice get_drivedevice_iothread scsihw_infos);
 use PVE::QemuServer::Machine;
 use PVE::QemuServer::Memory qw(get_current_memory);
 use PVE::QemuServer::MetaInfo;
@@ -3467,8 +3467,8 @@ sub config_to_command {
             my $iothread = get_drivedevice_iothread($conf, $drive);
             push @$cmd, '-object', to_json($iothread, { canonical => 1 }) if $iothread;
 
-            my $controller = print_drivedevice_controller($conf, $drive, $iothread, $scsihw, $arch, $bridges, $used_controller);
-            push @$devices, '-device', $controller if $controller;
+            my $drive_controller = get_drivedevice_controller($conf, $drive, $iothread, $scsihw, $arch, $bridges, $used_controller);
+            push @$devices, '-device', to_json($drive_controller, { canonical => 1 }) if $drive_controller;
 
             my $live_restore = $live_restore_backing->{$ds};
             my $live_blockdev_name = undef;
@@ -3747,10 +3747,10 @@ sub vm_deviceplug {
     } elsif ($deviceid =~ m/^(virtioscsi|scsihw)(\d+)$/) {
         my $scsihw = defined($conf->{scsihw}) ? $conf->{scsihw} : "lsi";
         my $iothread = get_drivedevice_iothread($conf, $device);
-        my $controller = print_drivedevice_controller($conf, $device, $iothread, $scsihw, $arch);
+        my $controller = get_drivedevice_controller($conf, $device, $iothread, $scsihw, $arch);
 
         qemu_iothread_add($vmid, $deviceid, $device) if $iothread;
-        qemu_deviceadd($vmid, $controller);
+        qmp_deviceadd($vmid, $controller);
         qemu_deviceaddverify($vmid, $deviceid);
     } elsif ($deviceid =~ m/^(scsi)(\d+)$/) {
         qemu_findorcreatescsihw($storecfg, $conf, $vmid, $device, $arch, $machine_type);
@@ -3832,7 +3832,7 @@ sub vm_deviceunplug {
         qemu_drivedel($vmid, $deviceid);
         qemu_iothread_del($vmid, $deviceid, $device);
     } elsif ($deviceid =~ m/^(virtioscsi|scsihw)(\d+)$/) {
-        qemu_devicedel($vmid, $deviceid);
+        qmp_devicedel($vmid, $deviceid);
         qemu_devicedelverify($vmid, $deviceid);
     } elsif ($deviceid =~ m/^(scsi)(\d+)$/) {
         my $device = parse_drive($deviceid, $conf->{$deviceid});
diff --git a/src/PVE/QemuServer/DriveDevice.pm b/src/PVE/QemuServer/DriveDevice.pm
index ab62c4ff..6c478ca6 100644
--- a/src/PVE/QemuServer/DriveDevice.pm
+++ b/src/PVE/QemuServer/DriveDevice.pm
@@ -14,7 +14,7 @@ use base qw(Exporter);
 
 our @EXPORT_OK = qw(
     get_drivedevice
-    print_drivedevice_controller
+    get_drivedevice_controller
     get_drivedevice_iothread
     scsihw_infos
 );
@@ -170,7 +170,7 @@ sub get_drivedevice {
     return $device;
 }
 
-sub print_drivedevice_controller {
+sub get_drivedevice_controller {
     my ($conf, $drive, $iothread_enabled, $scsihw, $arch, $bridges, $used_controller) = @_;
 
     if ($drive->{interface} eq 'scsi') {
@@ -178,36 +178,35 @@ sub print_drivedevice_controller {
 	my ($maxdev, $controller, $controller_prefix) = scsihw_infos($conf, $drive);
 	return if $used_controller->{scsi}->{$controller};
 
-	my $pciaddr = print_pci_addr("$controller_prefix$controller", $bridges, $arch);
+	my $controllerid = "$controller_prefix$controller";
+	my $pciaddr = get_pci_addr($controllerid, $bridges, $arch);
 	my $scsihw_type =
 	    $scsihw =~ m/^virtio-scsi-single/ ? "virtio-scsi-pci" : $scsihw;
 
+        my $device = { id => $controllerid, driver => $scsihw_type, addr => $pciaddr->{addr}, bus => $pciaddr->{bus} };
+        $device->{iothread} = "iothread-$controllerid" if $iothread_enabled;
 
-	my $iothread = $iothread_enabled ? ",iothread=iothread-$controller_prefix$controller" : "";
-
-	my $queues = '';
 	if (
 	    $conf->{scsihw}
 	    && $conf->{scsihw} eq "virtio-scsi-single"
 	    && $drive->{queues}
 	) {
-	    $queues = ",num_queues=$drive->{queues}";
+	    $device->{'num_queues'} = int($drive->{queues});
 	}
 
-
 	$used_controller->{scsi}->{$controller} = 1;
-	return "$scsihw_type,id=$controller_prefix$controller$pciaddr$iothread$queues";
+	return $device;
     }
 
     if ($drive->{interface} eq 'sata') {
 	my $controller = int($drive->{index} / $PVE::QemuServer::Drive::MAX_SATA_DISKS);
 	return if $used_controller->{ahci}->{$controller};
 
-	my $pciaddr = print_pci_addr("ahci$controller", $bridges, $arch);
+	my $controllerid = "ahci$controller";
+	my $pciaddr = get_pci_addr($controllerid, $bridges, $arch);
 
 	$used_controller->{ahci}->{$controller} = 1;
-	return "ahci,id=ahci$controller,multifunction=on$pciaddr";
-
+        return { driver => 'ahci', id => $controllerid, multifunction => 'on', addr => $pciaddr->{addr}, bus => $pciaddr->{bus} };
     }
 }
 
-- 
2.39.5



[-- Attachment #2: Type: text/plain, Size: 160 bytes --]

_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel

  parent reply	other threads:[~2025-06-27 12:42 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20250627124228.1542397-1-alexandre.derumier@groupe-cyllene.com>
2025-06-27 12:42 ` [pve-devel] [PATCH qemu-server 1/6] pci: add get_pci_addr Alexandre Derumier via pve-devel
2025-06-27 12:42 ` [pve-devel] [PATCH qemu-server 2/6] qmphelpers: add qmp_deviceadd && qmp_devicedel Alexandre Derumier via pve-devel
2025-06-27 12:42 ` [pve-devel] [PATCH qemu-server 3/6] convert drive device to json format Alexandre Derumier via pve-devel
2025-06-27 12:42 ` [pve-devel] [PATCH qemu-server 4/6] convert iothread to json Alexandre Derumier via pve-devel
2025-06-27 12:42 ` Alexandre Derumier via pve-devel [this message]
2025-06-27 12:42 ` [pve-devel] [PATCH qemu-server 6/6] tests: cfg2cmd: convert drive devices to json format Alexandre Derumier via pve-devel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=mailman.694.1751028184.395.pve-devel@lists.proxmox.com \
    --to=pve-devel@lists.proxmox.com \
    --cc=alexandre.derumier@groupe-cyllene.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal