[pve-devel] [PATCH v2 qemu-server] fix #2344: ignore cloudinit in replication check
Mira Limbeck
m.limbeck at proxmox.com
Fri Sep 27 16:22:01 CEST 2019
When adding a cloudinit disk it does not contain media=cdrom until it is
actually created. This means the check in check_replication fails to
detect cloudinit and it is recognized as normal disk. Then parse_volname
fails because it does not match the vm-$vmid-XYZ format. To fix this we
now check explicitly if the volname matches cloudinit and if so, return
early.
Additionally 2 small cleanups replacing cloudinit regexes with the
same check for volname matches cloudinit.
Signed-off-by: Mira Limbeck <m.limbeck at proxmox.com>
---
v2:
- instead of adding additional regexes remove them completely
PVE/API2/Qemu.pm | 19 ++++++++++---------
1 file changed, 10 insertions(+), 9 deletions(-)
diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
index 1e8d350..429b875 100644
--- a/PVE/API2/Qemu.pm
+++ b/PVE/API2/Qemu.pm
@@ -64,10 +64,9 @@ my $check_storage_access = sub {
my $isCDROM = PVE::QemuServer::drive_is_cdrom($drive);
my $volid = $drive->{file};
+ my ($storeid, $volname) = PVE::Storage::parse_volume_id($volid, 1);
- if (!$volid || ($volid eq 'none' || $volid eq 'cloudinit')) {
- # nothing to check
- } elsif ($volid =~ m/^(([^:\s]+):)?(cloudinit)$/) {
+ if (!$volid || ($volid eq 'none' || $volid eq 'cloudinit' || $volname eq 'cloudinit')) {
# nothing to check
} elsif ($isCDROM && ($volid eq 'cdrom')) {
$rpcenv->check($authuser, "/", ['Sys.Console']);
@@ -140,12 +139,13 @@ my $create_disks = sub {
my ($ds, $disk) = @_;
my $volid = $disk->{file};
+ my ($storeid, $volname) = PVE::Storage::parse_volume_id($volid, 1);
if (!$volid || $volid eq 'none' || $volid eq 'cdrom') {
delete $disk->{size};
$res->{$ds} = PVE::QemuServer::print_drive($vmid, $disk);
- } elsif ($volid =~ m!^(?:([^/:\s]+):)?cloudinit$!) {
- my $storeid = $1 || $default_storage;
+ } elsif ($volname eq 'cloudinit') {
+ $storeid = $storeid // $default_storage;
die "no storage ID specified (and no default storage)\n" if !$storeid;
my $scfg = PVE::Storage::storage_config($storecfg, $storeid);
my $name = "vm-$vmid-cloudinit";
@@ -198,8 +198,6 @@ my $create_disks = sub {
if ($volid_is_new) {
- my ($storeid, $volname) = PVE::Storage::parse_volume_id($volid, 1);
-
PVE::Storage::activate_volumes($storecfg, [ $volid ]) if $storeid;
my $size = PVE::Storage::volume_size_info($storecfg, $volid);
@@ -1100,12 +1098,15 @@ my $update_vm_api = sub {
my $volid = $drive->{file};
return if !$volid || !($drive->{replicate}//1);
return if PVE::QemuServer::drive_is_cdrom($drive);
- my ($storeid, $format);
+
+ my ($storeid, $volname) = PVE::Storage::parse_volume_id($volid, 1);
+ return if $volname eq 'cloudinit';
+
+ my $format;
if ($volid =~ $NEW_DISK_RE) {
$storeid = $2;
$format = $drive->{format} || PVE::Storage::storage_default_format($storecfg, $storeid);
} else {
- ($storeid, undef) = PVE::Storage::parse_volume_id($volid, 1);
$format = (PVE::Storage::parse_volname($storecfg, $volid))[6];
}
return if PVE::Storage::storage_can_replicate($storecfg, $storeid, $format);
--
2.20.1
More information about the pve-devel
mailing list