optional => 1,
type => 'boolean',
description => "Allow hotplug for disk and network device",
- default => 0,
+ default => 1,
},
reboot => {
optional => 1,
return $devices;
}
+sub hotplug_enabled {
+ my ($conf) = @_;
+
+ my $default = $confdesc->{'hotplug'}->{default};
+
+ return defined($conf->{hotplug}) ? $conf->{hotplug} : $default;
+}
+
sub vm_deviceplug {
my ($storecfg, $conf, $vmid, $deviceid, $device) = @_;
- die "internal error" if !$conf->{hotplug};
+ die "internal error" if !hotplug_enabled($conf);
my $q35 = machine_type_is_q35($conf);
sub vm_deviceunplug {
my ($vmid, $conf, $deviceid) = @_;
- die "internal error" if !$conf->{hotplug};
+ die "internal error" if !hotplug_enabled($conf);
my $devices_list = vm_devices_list($vmid);
return 1 if !defined($devices_list->{$deviceid});
$conf = load_config($vmid); # update/reload
}
- my $hotplug = defined($conf->{hotplug}) ? $conf->{hotplug} : $defaults->{hotplug};
+ my $hotplug = hotplug_enabled($conf);
my @delete = PVE::Tools::split_list($conf->{pending}->{delete});
foreach my $opt (@delete) {
my $newnet = parse_net($value);
+ my $hotplug = hotplug_enabled($conf);
+
if ($conf->{$opt}) {
my $oldnet = parse_net($conf->{$opt});
!($newnet->{bridge} && $oldnet->{bridge})) { # bridge/nat mode change
# for non online change, we try to hot-unplug
- die "skip\n" if !$conf->{hotplug};
+ die "skip\n" if !$hotplug;
vm_deviceunplug($vmid, $conf, $opt);
} else {
}
}
- if ($conf->{hotplug}) {
+ if ($hotplug) {
vm_deviceplug($storecfg, $conf, $vmid, $opt, $newnet);
} else {
die "skip\n";
my $drive = parse_drive($opt, $value);
+ my $hotplug = hotplug_enabled($conf);
+
if ($conf->{$opt}) {
if (my $old_drive = parse_drive($opt, $conf->{$opt})) {
if ($drive->{file} ne $old_drive->{file}) {
- die "skip\n" if !$conf->{hotplug};
+ die "skip\n" if !$hotplug;
# unplug and register as unused
vm_deviceunplug($vmid, $conf, $opt);
}
} else {
- die "skip\n" if !$conf->{hotplug} || $opt =~ m/(ide|sata)(\d+)/;
+ die "skip\n" if !$hotplug || $opt =~ m/(ide|sata)(\d+)/;
# hotplug new disks
vm_deviceplug($storecfg, $conf, $vmid, $opt, $drive);
}