NAME

App::FuguVM::Disk - the qcow2 disk of a virtual machine

SYNOPSIS

use App::FuguVM::Disk;

my $disk = App::FuguVM::Disk->new($state_dir);

$disk->create('default', '8G');
$disk->create('default', undef, $base_image);   # an overlay

my $info = $disk->info('default');
my $base = $disk->backing_file('default');

DESCRIPTION

The module wraps qemu-img(1). Every invocation goes through Fugu::Process, which runs a list and never a shell, so no path needs quoting.

A disk lives at <state_dir>/<name>/disk.qcow2.

METHODS

new, path

new takes the directory that holds every VM's disk.

create

$disk->create($name, $size, $backing_image)

Create the disk. The size may be undef for an overlay, which then inherits the virtual size of its backing image. Every backing image is a qcow2: a cached base image or a snapshot.

The method returns the path unchanged when the file already exists. Thus a caller that replaces a disk with an overlay unlinks it first.

info

Return the qemu-img(1) report as a hash reference, or undef.

The inspection asks for shared access. A running QEMU holds an exclusive lock, and without shared access the query would fail on exactly the VMs whose backing chain a caller most needs to resolve. If cache clear could not see the backing file of a running VM, it would remove the base from under it.

backing_file

Return the absolute path of the image that backs the disk, or undef when the disk is standalone.

qemu-img(1) reports the reference even when the file it names is gone. Thus a caller can diagnose a broken chain instead of meeting an opaque failure at boot.

check, repair

check returns { status, output, path }, where the status is ok or corrupted. repair runs the repair pass and returns 1 or 0.

SEE ALSO

qemu-img(1), Fugu::Process, App::FuguVM::DiskCache, App::FuguVM::Guest

AUTHOR

Dick Olsson <hi@senzilla.io>