]> git.proxmox.com Git - qemu-server.git/blame - PVE/QemuServer/Drive.pm
fix #3075: add TPM v1.2 and v2.0 support via swtpm
[qemu-server.git] / PVE / QemuServer / Drive.pm
CommitLineData
e0fd2b2f
FE
1package PVE::QemuServer::Drive;
2
3use strict;
4use warnings;
5
6use PVE::Storage;
7use PVE::JSONSchema qw(get_standard_option);
8
9use base qw(Exporter);
10
11our @EXPORT_OK = qw(
12is_valid_drivename
13drive_is_cloudinit
14drive_is_cdrom
75748d44 15drive_is_read_only
e0fd2b2f
FE
16parse_drive
17print_drive
e0fd2b2f
FE
18);
19
20our $QEMU_FORMAT_RE = qr/raw|cow|qcow|qcow2|qed|vmdk|cloop/;
21
22PVE::JSONSchema::register_standard_option('pve-qm-image-format', {
23 type => 'string',
24 enum => [qw(raw cow qcow qed qcow2 vmdk cloop)],
25 description => "The drive's backing file's data format.",
26 optional => 1,
27});
28
29my $MAX_IDE_DISKS = 4;
30my $MAX_SCSI_DISKS = 31;
31my $MAX_VIRTIO_DISKS = 16;
32our $MAX_SATA_DISKS = 6;
33our $MAX_UNUSED_DISKS = 256;
34
35our $drivedesc_hash;
36
37my %drivedesc_base = (
38 volume => { alias => 'file' },
39 file => {
40 type => 'string',
41 format => 'pve-volume-id-or-qm-path',
42 default_key => 1,
43 format_description => 'volume',
44 description => "The drive's backing volume.",
45 },
46 media => {
47 type => 'string',
48 enum => [qw(cdrom disk)],
49 description => "The drive's media type.",
50 default => 'disk',
51 optional => 1
52 },
53 cyls => {
54 type => 'integer',
55 description => "Force the drive's physical geometry to have a specific cylinder count.",
56 optional => 1
57 },
58 heads => {
59 type => 'integer',
60 description => "Force the drive's physical geometry to have a specific head count.",
61 optional => 1
62 },
63 secs => {
64 type => 'integer',
65 description => "Force the drive's physical geometry to have a specific sector count.",
66 optional => 1
67 },
68 trans => {
69 type => 'string',
70 enum => [qw(none lba auto)],
71 description => "Force disk geometry bios translation mode.",
72 optional => 1,
73 },
74 snapshot => {
75 type => 'boolean',
76 description => "Controls qemu's snapshot mode feature."
77 . " If activated, changes made to the disk are temporary and will"
78 . " be discarded when the VM is shutdown.",
79 optional => 1,
80 },
81 cache => {
82 type => 'string',
83 enum => [qw(none writethrough writeback unsafe directsync)],
84 description => "The drive's cache mode",
85 optional => 1,
86 },
87 format => get_standard_option('pve-qm-image-format'),
88 size => {
89 type => 'string',
90 format => 'disk-size',
91 format_description => 'DiskSize',
92 description => "Disk size. This is purely informational and has no effect.",
93 optional => 1,
94 },
95 backup => {
96 type => 'boolean',
97 description => "Whether the drive should be included when making backups.",
98 optional => 1,
99 },
100 replicate => {
101 type => 'boolean',
102 description => 'Whether the drive should considered for replication jobs.',
103 optional => 1,
104 default => 1,
105 },
106 rerror => {
107 type => 'string',
108 enum => [qw(ignore report stop)],
109 description => 'Read error action.',
110 optional => 1,
111 },
112 werror => {
113 type => 'string',
114 enum => [qw(enospc ignore report stop)],
115 description => 'Write error action.',
116 optional => 1,
117 },
118 aio => {
119 type => 'string',
59e59342 120 enum => [qw(native threads io_uring)],
e0fd2b2f
FE
121 description => 'AIO type to use.',
122 optional => 1,
123 },
124 discard => {
125 type => 'string',
126 enum => [qw(ignore on)],
127 description => 'Controls whether to pass discard/trim requests to the underlying storage.',
128 optional => 1,
129 },
130 detect_zeroes => {
131 type => 'boolean',
132 description => 'Controls whether to detect and try to optimize writes of zeroes.',
133 optional => 1,
134 },
135 serial => {
136 type => 'string',
137 format => 'urlencoded',
138 format_description => 'serial',
139 maxLength => 20*3, # *3 since it's %xx url enoded
140 description => "The drive's reported serial number, url-encoded, up to 20 bytes long.",
141 optional => 1,
142 },
143 shared => {
144 type => 'boolean',
145 description => 'Mark this locally-managed volume as available on all nodes',
146 verbose_description => "Mark this locally-managed volume as available on all nodes.\n\nWARNING: This option does not share the volume automatically, it assumes it is shared already!",
147 optional => 1,
148 default => 0,
149 }
150);
151
152my %iothread_fmt = ( iothread => {
153 type => 'boolean',
154 description => "Whether to use iothreads for this drive",
155 optional => 1,
156});
157
158my %model_fmt = (
159 model => {
160 type => 'string',
161 format => 'urlencoded',
162 format_description => 'model',
163 maxLength => 40*3, # *3 since it's %xx url enoded
164 description => "The drive's reported model name, url-encoded, up to 40 bytes long.",
165 optional => 1,
166 },
167);
168
169my %queues_fmt = (
170 queues => {
171 type => 'integer',
172 description => "Number of queues.",
173 minimum => 2,
174 optional => 1
175 }
176);
177
178my %scsiblock_fmt = (
179 scsiblock => {
180 type => 'boolean',
181 description => "whether to use scsi-block for full passthrough of host block device\n\nWARNING: can lead to I/O errors in combination with low memory or high memory fragmentation on host",
182 optional => 1,
183 default => 0,
184 },
185);
186
187my %ssd_fmt = (
188 ssd => {
189 type => 'boolean',
190 description => "Whether to expose this drive as an SSD, rather than a rotational hard disk.",
191 optional => 1,
192 },
193);
194
195my %wwn_fmt = (
196 wwn => {
197 type => 'string',
198 pattern => qr/^(0x)[0-9a-fA-F]{16}/,
199 format_description => 'wwn',
200 description => "The drive's worldwide name, encoded as 16 bytes hex string, prefixed by '0x'.",
201 optional => 1,
202 },
203);
204
205my $add_throttle_desc = sub {
206 my ($key, $type, $what, $unit, $longunit, $minimum) = @_;
207 my $d = {
208 type => $type,
209 format_description => $unit,
210 description => "Maximum $what in $longunit.",
211 optional => 1,
212 };
213 $d->{minimum} = $minimum if defined($minimum);
214 $drivedesc_base{$key} = $d;
215};
216# throughput: (leaky bucket)
217$add_throttle_desc->('bps', 'integer', 'r/w speed', 'bps', 'bytes per second');
218$add_throttle_desc->('bps_rd', 'integer', 'read speed', 'bps', 'bytes per second');
219$add_throttle_desc->('bps_wr', 'integer', 'write speed', 'bps', 'bytes per second');
220$add_throttle_desc->('mbps', 'number', 'r/w speed', 'mbps', 'megabytes per second');
221$add_throttle_desc->('mbps_rd', 'number', 'read speed', 'mbps', 'megabytes per second');
222$add_throttle_desc->('mbps_wr', 'number', 'write speed', 'mbps', 'megabytes per second');
223$add_throttle_desc->('iops', 'integer', 'r/w I/O', 'iops', 'operations per second');
224$add_throttle_desc->('iops_rd', 'integer', 'read I/O', 'iops', 'operations per second');
225$add_throttle_desc->('iops_wr', 'integer', 'write I/O', 'iops', 'operations per second');
226
227# pools: (pool of IO before throttling starts taking effect)
228$add_throttle_desc->('mbps_max', 'number', 'unthrottled r/w pool', 'mbps', 'megabytes per second');
229$add_throttle_desc->('mbps_rd_max', 'number', 'unthrottled read pool', 'mbps', 'megabytes per second');
230$add_throttle_desc->('mbps_wr_max', 'number', 'unthrottled write pool', 'mbps', 'megabytes per second');
231$add_throttle_desc->('iops_max', 'integer', 'unthrottled r/w I/O pool', 'iops', 'operations per second');
232$add_throttle_desc->('iops_rd_max', 'integer', 'unthrottled read I/O pool', 'iops', 'operations per second');
233$add_throttle_desc->('iops_wr_max', 'integer', 'unthrottled write I/O pool', 'iops', 'operations per second');
234
235# burst lengths
236$add_throttle_desc->('bps_max_length', 'integer', 'length of I/O bursts', 'seconds', 'seconds', 1);
237$add_throttle_desc->('bps_rd_max_length', 'integer', 'length of read I/O bursts', 'seconds', 'seconds', 1);
238$add_throttle_desc->('bps_wr_max_length', 'integer', 'length of write I/O bursts', 'seconds', 'seconds', 1);
239$add_throttle_desc->('iops_max_length', 'integer', 'length of I/O bursts', 'seconds', 'seconds', 1);
240$add_throttle_desc->('iops_rd_max_length', 'integer', 'length of read I/O bursts', 'seconds', 'seconds', 1);
241$add_throttle_desc->('iops_wr_max_length', 'integer', 'length of write I/O bursts', 'seconds', 'seconds', 1);
242
243# legacy support
244$drivedesc_base{'bps_rd_length'} = { alias => 'bps_rd_max_length' };
245$drivedesc_base{'bps_wr_length'} = { alias => 'bps_wr_max_length' };
246$drivedesc_base{'iops_rd_length'} = { alias => 'iops_rd_max_length' };
247$drivedesc_base{'iops_wr_length'} = { alias => 'iops_wr_max_length' };
248
249my $ide_fmt = {
250 %drivedesc_base,
251 %model_fmt,
252 %ssd_fmt,
253 %wwn_fmt,
254};
255PVE::JSONSchema::register_format("pve-qm-ide", $ide_fmt);
256
98c3d99e
FE
257my $ALLOCATION_SYNTAX_DESC =
258 "Use the special syntax STORAGE_ID:SIZE_IN_GiB to allocate a new volume.";
259
e0fd2b2f
FE
260my $idedesc = {
261 optional => 1,
262 type => 'string', format => $ide_fmt,
98c3d99e
FE
263 description => "Use volume as IDE hard disk or CD-ROM (n is 0 to " .($MAX_IDE_DISKS -1) . "). " .
264 $ALLOCATION_SYNTAX_DESC,
e0fd2b2f
FE
265};
266PVE::JSONSchema::register_standard_option("pve-qm-ide", $idedesc);
267
268my $scsi_fmt = {
269 %drivedesc_base,
270 %iothread_fmt,
271 %queues_fmt,
272 %scsiblock_fmt,
273 %ssd_fmt,
274 %wwn_fmt,
275};
276my $scsidesc = {
277 optional => 1,
278 type => 'string', format => $scsi_fmt,
98c3d99e
FE
279 description => "Use volume as SCSI hard disk or CD-ROM (n is 0 to " . ($MAX_SCSI_DISKS - 1) . "). " .
280 $ALLOCATION_SYNTAX_DESC,
e0fd2b2f
FE
281};
282PVE::JSONSchema::register_standard_option("pve-qm-scsi", $scsidesc);
283
284my $sata_fmt = {
285 %drivedesc_base,
286 %ssd_fmt,
287 %wwn_fmt,
288};
289my $satadesc = {
290 optional => 1,
291 type => 'string', format => $sata_fmt,
98c3d99e
FE
292 description => "Use volume as SATA hard disk or CD-ROM (n is 0 to " . ($MAX_SATA_DISKS - 1). "). " .
293 $ALLOCATION_SYNTAX_DESC,
e0fd2b2f
FE
294};
295PVE::JSONSchema::register_standard_option("pve-qm-sata", $satadesc);
296
297my $virtio_fmt = {
298 %drivedesc_base,
299 %iothread_fmt,
300};
301my $virtiodesc = {
302 optional => 1,
303 type => 'string', format => $virtio_fmt,
98c3d99e
FE
304 description => "Use volume as VIRTIO hard disk (n is 0 to " . ($MAX_VIRTIO_DISKS - 1) . "). " .
305 $ALLOCATION_SYNTAX_DESC,
e0fd2b2f
FE
306};
307PVE::JSONSchema::register_standard_option("pve-qm-virtio", $virtiodesc);
308
e0fd2b2f
FE
309my $efidisk_fmt = {
310 volume => { alias => 'file' },
311 file => {
312 type => 'string',
313 format => 'pve-volume-id-or-qm-path',
314 default_key => 1,
315 format_description => 'volume',
316 description => "The drive's backing volume.",
317 },
318 format => get_standard_option('pve-qm-image-format'),
319 size => {
320 type => 'string',
321 format => 'disk-size',
322 format_description => 'DiskSize',
323 description => "Disk size. This is purely informational and has no effect.",
324 optional => 1,
325 },
326};
327
328my $efidisk_desc = {
329 optional => 1,
330 type => 'string', format => $efidisk_fmt,
98c3d99e
FE
331 description => "Configure a Disk for storing EFI vars. " .
332 $ALLOCATION_SYNTAX_DESC . " Note that SIZE_IN_GiB is ignored here " .
333 "and that the default EFI vars are copied to the volume instead.",
e0fd2b2f
FE
334};
335
336PVE::JSONSchema::register_standard_option("pve-qm-efidisk", $efidisk_desc);
337
f9dde219
SR
338my %tpmversion_fmt = (
339 version => {
340 type => 'string',
341 enum => [qw(v1.2 v2.0)],
342 description => "The TPM interface version. v2.0 is newer and should be "
343 . "preferred. Note that this cannot be changed later on.",
344 optional => 1,
345 default => 'v2.0',
346 },
347);
348my $tpmstate_fmt = {
349 volume => { alias => 'file' },
350 file => {
351 type => 'string',
352 format => 'pve-volume-id-or-qm-path',
353 default_key => 1,
354 format_description => 'volume',
355 description => "The drive's backing volume.",
356 },
357 size => {
358 type => 'string',
359 format => 'disk-size',
360 format_description => 'DiskSize',
361 description => "Disk size. This is purely informational and has no effect.",
362 optional => 1,
363 },
364 %tpmversion_fmt,
365};
366my $tpmstate_desc = {
367 optional => 1,
368 type => 'string', format => $tpmstate_fmt,
369 description => "Configure a Disk for storing TPM state. " .
370 $ALLOCATION_SYNTAX_DESC . " Note that SIZE_IN_GiB is ignored here " .
371 "and that the default size of 4 MiB will always be used instead. The " .
372 "format is also fixed to 'raw'.",
373};
374use constant TPMSTATE_DISK_SIZE => 4 * 1024 * 1024;
375
376my $alldrive_fmt = {
377 %drivedesc_base,
378 %iothread_fmt,
379 %model_fmt,
380 %queues_fmt,
381 %scsiblock_fmt,
382 %ssd_fmt,
383 %wwn_fmt,
384 %tpmversion_fmt,
385};
386
43c4c7b6
FE
387my $unused_fmt = {
388 volume => { alias => 'file' },
389 file => {
390 type => 'string',
391 format => 'pve-volume-id',
392 default_key => 1,
393 format_description => 'volume',
394 description => "The drive's backing volume.",
395 },
396};
397
398my $unuseddesc = {
399 optional => 1,
400 type => 'string', format => $unused_fmt,
401 description => "Reference to unused volumes. This is used internally, and should not be modified manually.",
402};
403
e0fd2b2f
FE
404for (my $i = 0; $i < $MAX_IDE_DISKS; $i++) {
405 $drivedesc_hash->{"ide$i"} = $idedesc;
406}
407
408for (my $i = 0; $i < $MAX_SATA_DISKS; $i++) {
409 $drivedesc_hash->{"sata$i"} = $satadesc;
410}
411
412for (my $i = 0; $i < $MAX_SCSI_DISKS; $i++) {
413 $drivedesc_hash->{"scsi$i"} = $scsidesc;
414}
415
416for (my $i = 0; $i < $MAX_VIRTIO_DISKS; $i++) {
417 $drivedesc_hash->{"virtio$i"} = $virtiodesc;
418}
419
420$drivedesc_hash->{efidisk0} = $efidisk_desc;
f9dde219 421$drivedesc_hash->{tpmstate0} = $tpmstate_desc;
e0fd2b2f 422
43c4c7b6
FE
423for (my $i = 0; $i < $MAX_UNUSED_DISKS; $i++) {
424 $drivedesc_hash->{"unused$i"} = $unuseddesc;
425}
e0fd2b2f
FE
426
427sub valid_drive_names {
428 # order is important - used to autoselect boot disk
429 return ((map { "ide$_" } (0 .. ($MAX_IDE_DISKS - 1))),
430 (map { "scsi$_" } (0 .. ($MAX_SCSI_DISKS - 1))),
431 (map { "virtio$_" } (0 .. ($MAX_VIRTIO_DISKS - 1))),
432 (map { "sata$_" } (0 .. ($MAX_SATA_DISKS - 1))),
f9dde219
SR
433 'efidisk0',
434 'tpmstate0');
e0fd2b2f
FE
435}
436
437sub is_valid_drivename {
438 my $dev = shift;
439
43c4c7b6 440 return defined($drivedesc_hash->{$dev}) && $dev !~ /^unused\d+$/;
e0fd2b2f
FE
441}
442
443PVE::JSONSchema::register_format('pve-qm-bootdisk', \&verify_bootdisk);
444sub verify_bootdisk {
445 my ($value, $noerr) = @_;
446
447 return $value if is_valid_drivename($value);
448
d1c1af4b 449 return if $noerr;
e0fd2b2f
FE
450
451 die "invalid boot disk '$value'\n";
452}
453
454sub drive_is_cloudinit {
455 my ($drive) = @_;
456 return $drive->{file} =~ m@[:/]vm-\d+-cloudinit(?:\.$QEMU_FORMAT_RE)?$@;
457}
458
459sub drive_is_cdrom {
460 my ($drive, $exclude_cloudinit) = @_;
461
462 return 0 if $exclude_cloudinit && drive_is_cloudinit($drive);
463
464 return $drive && $drive->{media} && ($drive->{media} eq 'cdrom');
465}
466
75748d44
FG
467sub drive_is_read_only {
468 my ($conf, $drive) = @_;
469
470 return 0 if !PVE::QemuConfig->is_template($conf);
471
472 # don't support being marked read-only
473 return $drive->{interface} ne 'sata' && $drive->{interface} ne 'ide';
474}
475
e0fd2b2f
FE
476# ideX = [volume=]volume-id[,media=d][,cyls=c,heads=h,secs=s[,trans=t]]
477# [,snapshot=on|off][,cache=on|off][,format=f][,backup=yes|no]
478# [,rerror=ignore|report|stop][,werror=enospc|ignore|report|stop]
479# [,aio=native|threads][,discard=ignore|on][,detect_zeroes=on|off]
480# [,iothread=on][,serial=serial][,model=model]
481
482sub parse_drive {
483 my ($key, $data) = @_;
484
485 my ($interface, $index);
486
487 if ($key =~ m/^([^\d]+)(\d+)$/) {
488 $interface = $1;
489 $index = $2;
490 } else {
d1c1af4b 491 return;
e0fd2b2f
FE
492 }
493
43c4c7b6 494 if (!defined($drivedesc_hash->{$key})) {
e0fd2b2f 495 warn "invalid drive key: $key\n";
d1c1af4b 496 return;
e0fd2b2f 497 }
43c4c7b6
FE
498
499 my $desc = $drivedesc_hash->{$key}->{format};
e0fd2b2f 500 my $res = eval { PVE::JSONSchema::parse_property_string($desc, $data) };
d1c1af4b 501 return if !$res;
e0fd2b2f
FE
502 $res->{interface} = $interface;
503 $res->{index} = $index;
504
505 my $error = 0;
506 foreach my $opt (qw(bps bps_rd bps_wr)) {
507 if (my $bps = defined(delete $res->{$opt})) {
508 if (defined($res->{"m$opt"})) {
509 warn "both $opt and m$opt specified\n";
510 ++$error;
511 next;
512 }
513 $res->{"m$opt"} = sprintf("%.3f", $bps / (1024*1024.0));
514 }
515 }
516
517 # can't use the schema's 'requires' because of the mbps* => bps* "transforming aliases"
518 for my $requirement (
519 [mbps_max => 'mbps'],
520 [mbps_rd_max => 'mbps_rd'],
521 [mbps_wr_max => 'mbps_wr'],
522 [miops_max => 'miops'],
523 [miops_rd_max => 'miops_rd'],
524 [miops_wr_max => 'miops_wr'],
525 [bps_max_length => 'mbps_max'],
526 [bps_rd_max_length => 'mbps_rd_max'],
527 [bps_wr_max_length => 'mbps_wr_max'],
528 [iops_max_length => 'iops_max'],
529 [iops_rd_max_length => 'iops_rd_max'],
530 [iops_wr_max_length => 'iops_wr_max']) {
531 my ($option, $requires) = @$requirement;
532 if ($res->{$option} && !$res->{$requires}) {
533 warn "$option requires $requires\n";
534 ++$error;
535 }
536 }
537
d1c1af4b 538 return if $error;
e0fd2b2f 539
d1c1af4b
TL
540 return if $res->{mbps_rd} && $res->{mbps};
541 return if $res->{mbps_wr} && $res->{mbps};
542 return if $res->{iops_rd} && $res->{iops};
543 return if $res->{iops_wr} && $res->{iops};
e0fd2b2f
FE
544
545 if ($res->{media} && ($res->{media} eq 'cdrom')) {
d1c1af4b
TL
546 return if $res->{snapshot} || $res->{trans} || $res->{format};
547 return if $res->{heads} || $res->{secs} || $res->{cyls};
548 return if $res->{interface} eq 'virtio';
e0fd2b2f
FE
549 }
550
551 if (my $size = $res->{size}) {
d1c1af4b 552 return if !defined($res->{size} = PVE::JSONSchema::parse_size($size));
e0fd2b2f
FE
553 }
554
555 return $res;
556}
557
558sub print_drive {
559 my ($drive) = @_;
560 my $skip = [ 'index', 'interface' ];
561 return PVE::JSONSchema::print_property_string($drive, $alldrive_fmt, $skip);
562}
563
2141a802
SR
564sub get_bootdisks {
565 my ($conf) = @_;
566
f7d1505b
TL
567 my $bootcfg;
568 $bootcfg = PVE::JSONSchema::parse_property_string('pve-qm-boot', $conf->{boot}) if $conf->{boot};
2141a802
SR
569
570 if (!defined($bootcfg) || $bootcfg->{legacy}) {
571 return [$conf->{bootdisk}] if $conf->{bootdisk};
572 return [];
573 }
574
575 my @list = PVE::Tools::split_list($bootcfg->{order});
576 @list = grep {is_valid_drivename($_)} @list;
577 return \@list;
578}
579
776c5f50 580sub bootdisk_size {
e0fd2b2f
FE
581 my ($storecfg, $conf) = @_;
582
2141a802 583 my $bootdisks = get_bootdisks($conf);
d1c1af4b 584 return if !@$bootdisks;
30664f14
DC
585 for my $bootdisk (@$bootdisks) {
586 next if !is_valid_drivename($bootdisk);
587 next if !$conf->{$bootdisk};
588 my $drive = parse_drive($bootdisk, $conf->{$bootdisk});
589 next if !defined($drive);
590 next if drive_is_cdrom($drive);
591 my $volid = $drive->{file};
592 next if !$volid;
593 return $drive->{size};
594 }
e0fd2b2f 595
30664f14 596 return;
e0fd2b2f
FE
597}
598
599sub update_disksize {
9b29cbd0 600 my ($drive, $newsize) = @_;
e0fd2b2f 601
d1c1af4b 602 return if !defined($newsize);
e0fd2b2f 603
63e313f3 604 my $oldsize = $drive->{size} // 0;
e0fd2b2f 605
63e313f3 606 if ($newsize != $oldsize) {
e0fd2b2f
FE
607 $drive->{size} = $newsize;
608
609 my $old_fmt = PVE::JSONSchema::format_size($oldsize);
610 my $new_fmt = PVE::JSONSchema::format_size($newsize);
611
9b29cbd0
FE
612 my $msg = "size of disk '$drive->{file}' updated from $old_fmt to $new_fmt";
613
614 return ($drive, $msg);
e0fd2b2f
FE
615 }
616
d1c1af4b 617 return;
e0fd2b2f
FE
618}
619
620sub is_volume_in_use {
621 my ($storecfg, $conf, $skip_drive, $volid) = @_;
622
623 my $path = PVE::Storage::path($storecfg, $volid);
624
625 my $scan_config = sub {
ab5b97d8 626 my ($cref) = @_;
e0fd2b2f
FE
627
628 foreach my $key (keys %$cref) {
629 my $value = $cref->{$key};
630 if (is_valid_drivename($key)) {
631 next if $skip_drive && $key eq $skip_drive;
632 my $drive = parse_drive($key, $value);
633 next if !$drive || !$drive->{file} || drive_is_cdrom($drive);
634 return 1 if $volid eq $drive->{file};
635 if ($drive->{file} =~ m!^/!) {
636 return 1 if $drive->{file} eq $path;
637 } else {
638 my ($storeid, $volname) = PVE::Storage::parse_volume_id($drive->{file}, 1);
639 next if !$storeid;
640 my $scfg = PVE::Storage::storage_config($storecfg, $storeid, 1);
641 next if !$scfg;
a0d8d859 642 return 1 if $path eq PVE::Storage::path($storecfg, $drive->{file});
e0fd2b2f
FE
643 }
644 }
645 }
646
647 return 0;
648 };
649
650 return 1 if &$scan_config($conf);
651
652 undef $skip_drive;
653
ab5b97d8
FE
654 for my $snap (values %{$conf->{snapshots}}) {
655 return 1 if $scan_config->($snap);
e0fd2b2f
FE
656 }
657
658 return 0;
659}
660
661sub resolve_first_disk {
5cfa9f5f 662 my ($conf, $cdrom) = @_;
e0fd2b2f 663 my @disks = valid_drive_names();
5cfa9f5f 664 foreach my $ds (@disks) {
e0fd2b2f
FE
665 next if !$conf->{$ds};
666 my $disk = parse_drive($ds, $conf->{$ds});
5cfa9f5f
SR
667 next if drive_is_cdrom($disk) xor $cdrom;
668 return $ds;
e0fd2b2f 669 }
d1c1af4b 670 return;
e0fd2b2f
FE
671}
672
6731;