[pve-devel] [RFC PATCH v9 6/6] delete cloudinit images as if they weren't cdroms
Wolfgang Bumiller
w.bumiller at proxmox.com
Thu Aug 6 12:05:14 CEST 2015
---
PVE/API2/Qemu.pm | 2 +-
PVE/QemuServer.pm | 14 +++++++++-----
2 files changed, 10 insertions(+), 6 deletions(-)
diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
index a19ad87..4dcbb26 100644
--- a/PVE/API2/Qemu.pm
+++ b/PVE/API2/Qemu.pm
@@ -41,7 +41,7 @@ my $resolve_cdrom_alias = sub {
my $test_deallocate_drive = sub {
my ($storecfg, $vmid, $key, $drive, $force) = @_;
- if (!PVE::QemuServer::drive_is_cdrom($drive)) {
+ if (!PVE::QemuServer::drive_is_cdrom($drive, 1)) {
my $volid = $drive->{file};
if ( PVE::QemuServer::vm_is_volid_owner($storecfg, $vmid, $volid)) {
if ($force || $key =~ m/^unused/) {
diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 7bdb655..1cb6b3c 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -36,6 +36,8 @@ my $qemu_snap_storage = {rbd => 1, sheepdog => 1};
my $cpuinfo = PVE::ProcFSTools::read_cpuinfo();
+my $QEMU_FORMAT_RE = qr/raw|cow|qcow|qcow2|qed|vmdk|cloop/;
+
# Note about locking: we use flock on the config file protect
# against concurent actions.
# Aditionaly, we have a 'lock' setting in the config file. This
@@ -955,7 +957,7 @@ sub parse_drive {
return undef if $res->{secs} && $res->{secs} !~ m/^\d+$/;
return undef if $res->{media} && $res->{media} !~ m/^(disk|cdrom)$/;
return undef if $res->{trans} && $res->{trans} !~ m/^(none|lba|auto)$/;
- return undef if $res->{format} && $res->{format} !~ m/^(raw|cow|qcow|qed|qcow2|vmdk|cloop)$/;
+ return undef if $res->{format} && $res->{format} !~ m/^($QEMU_FORMAT_RE)$/;
return undef if $res->{rerror} && $res->{rerror} !~ m/^(ignore|report|stop)$/;
return undef if $res->{werror} && $res->{werror} !~ m/^(enospc|ignore|report|stop)$/;
return undef if $res->{backup} && $res->{backup} !~ m/^(yes|no)$/;
@@ -1295,7 +1297,9 @@ sub print_netdev_full {
}
sub drive_is_cdrom {
- my ($drive) = @_;
+ my ($drive, $exclude_cloudinit) = @_;
+
+ return 0 if $exclude_cloudinit && $drive->{file} =~ m@[:/]vm-\d+-cloudinit(?:\.$QEMU_FORMAT_RE)?$@;
return $drive && $drive->{media} && ($drive->{media} eq 'cdrom');
@@ -1544,7 +1548,7 @@ sub vmconfig_undelete_pending_option {
sub vmconfig_register_unused_drive {
my ($storecfg, $vmid, $conf, $drive) = @_;
- if (!drive_is_cdrom($drive)) {
+ if (!drive_is_cdrom($drive, 1)) {
my $volid = $drive->{file};
if (vm_is_volid_owner($storecfg, $vmid, $volid)) {
add_unused_volume($conf, $volid, $vmid);
@@ -1910,7 +1914,7 @@ sub destroy_vm {
foreach_drive($conf, sub {
my ($ds, $drive) = @_;
- return if drive_is_cdrom($drive);
+ return if drive_is_cdrom($drive, 1);
my $volid = $drive->{file};
@@ -6204,7 +6208,7 @@ sub qemu_img_convert {
sub qemu_img_format {
my ($scfg, $volname) = @_;
- if ($scfg->{path} && $volname =~ m/\.(raw|cow|qcow|qcow2|qed|vmdk|cloop)$/) {
+ if ($scfg->{path} && $volname =~ m/\.($QEMU_FORMAT_RE)$/) {
return $1;
} else {
return "raw";
--
2.1.4
More information about the pve-devel
mailing list