blockdev: add helper to get node below throttle node

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
This commit is contained in:
Fiona Ebner 2025-07-02 18:28:03 +02:00 committed by Fabian Grünbichler
parent 61efcc5556
commit d2efc5074c

View file

@ -139,6 +139,30 @@ sub top_node_name {
return "drive-$drive_id";
}
sub get_node_name_below_throttle {
my ($vmid, $device_id, $assert_top_is_throttle) = @_;
my $block_info = get_block_info($vmid);
my $drive_id = $device_id =~ s/^drive-//r;
my $inserted = $block_info->{$drive_id}->{inserted}
or die "no block node inserted for drive '$drive_id'\n";
if ($inserted->{drv} ne 'throttle') {
die "$device_id: unexpected top node $inserted->{'node-name'} ($inserted->{drv})\n"
if $assert_top_is_throttle;
# before the switch to -blockdev, the top node was not throttle
return $inserted->{'node-name'};
}
my $children = { map { $_->{child} => $_ } $inserted->{children}->@* };
if (my $node_name = $children->{file}->{'node-name'}) {
return $node_name;
}
die "$device_id: throttle node without file child node name!\n";
}
my sub read_only_json_option {
my ($drive, $options) = @_;