> Alexandre Derumier via pve-devel <pve-devel@lists.proxmox.com> hat am 
> 22.04.2025 13:51 CEST geschrieben:

> +sub blockdev_rename {
> +    my ($storecfg, $vmid, $deviceid, $drive, $src_snap, $target_snap, 
> $parent_snap) = @_;
> +
> +    print "rename $src_snap to $target_snap\n";
> +
> +    my $volid = $drive->{file};
> +
> +    my $src_file_blockdev = generate_file_blockdev($storecfg, $drive, 
> $src_snap);
> +    my $src_fmt_blockdev = generate_format_blockdev($storecfg, $drive, 
> $src_file_blockdev, $src_snap);
> +    my $target_file_blockdev = generate_file_blockdev($storecfg, $drive, 
> $target_snap);
> +    my $target_fmt_blockdev = generate_format_blockdev($storecfg, $drive, 
> $target_file_blockdev, $target_snap);
> +
> +    #rename volume image
> +    PVE::Storage::rename_volume($storecfg, $volid, $vmid, undef, $src_snap, 
> $target_snap);
> +
> +    if($target_snap eq 'current' || $src_snap eq 'current') {
> +     #rename from|to current
> +
> +     #add backing to target
> +     if ($parent_snap) {
> +         my $parent_fmt_nodename = encode_nodename('fmt', $volid, 
> $parent_snap);

encode_nodename now lives in QemuServer::Drive, so this call doesn't work, and 
creating
a snapshot on top of another snapshot is broken as a result..

> +         $target_fmt_blockdev->{backing} = $parent_fmt_nodename;
> +     }
> +     PVE::QemuServer::Monitor::mon_cmd($vmid, 'blockdev-add', 
> %$target_fmt_blockdev);
> +
> +     #reopen the current throttlefilter nodename with the target fmt nodename
> +     my $throttle_blockdev = generate_blockdev_throttle($drive, 
> $target_fmt_blockdev->{'node-name'});
> +     PVE::QemuServer::Monitor::mon_cmd($vmid, 'blockdev-reopen', options => 
> [$throttle_blockdev]);
> +    } else {
> +        rename($src_file_blockdev->{filename}, 
> $target_file_blockdev->{filename});
> +
> +     #intermediate snapshot
> +     PVE::QemuServer::Monitor::mon_cmd($vmid, 'blockdev-add', 
> %$target_fmt_blockdev);
> +
> +     #reopen the parent node with the new target fmt backing node
> +     my $parent_file_blockdev = generate_file_blockdev($storecfg, $drive, 
> $parent_snap);
> +     my $parent_fmt_blockdev = generate_format_blockdev($storecfg, $drive, 
> $parent_file_blockdev, $parent_snap);
> +     $parent_fmt_blockdev->{backing} = $target_fmt_blockdev->{'node-name'};
> +     PVE::QemuServer::Monitor::mon_cmd($vmid, 'blockdev-reopen', options => 
> [$parent_fmt_blockdev]);
> +
> +     #change backing-file in qcow2 metadatas
> +     PVE::QemuServer::Monitor::mon_cmd($vmid, 'change-backing-file', device 
> => $deviceid, 'image-node-name' => $parent_fmt_blockdev->{'node-name'}, 
> 'backing-file' => $target_file_blockdev->{filename});
> +    }
> +
> +    # delete old file|fmt nodes
> +    # add eval as reopen is auto removing the old nodename automatically 
> only if it was created at vm start in command line argument
> +    eval { PVE::QemuServer::Monitor::mon_cmd($vmid, 'blockdev-del', 
> 'node-name' => $src_file_blockdev->{'node-name'})};
> +    eval { PVE::QemuServer::Monitor::mon_cmd($vmid, 'blockdev-del', 
> 'node-name' => $src_fmt_blockdev->{'node-name'})};
> +}


_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel

Reply via email to