There are 3 compute node with Debian 10. Each node is used as hypervisor based on QEMU/KVM.
Libvirt0:amd64 5.0.0-4+deb10u1
Libguestfs0:amd 1:1.40.2-2
I create Virtual Machines with disks on GlusterFS volume.
<disk type='network' device='disk'>
<driver name='qemu' type='qcow2' cache='none' io='threads' discard='unmap'/>
<source protocol='gluster' name='TEST/TEST1'>
<host name='localhost' port='24007'/>
</source>
<target dev='vda' bus='virtio'/>
<iotune>
<read_bytes_sec>157286400</read_bytes_sec>
<write_bytes_sec>104857600</write_bytes_sec>
<read_iops_sec>40000</read_iops_sec>
<write_iops_sec>25000</write_iops_sec>
</iotune>
<alias name='virtio-disk0'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x09' function='0x0'/>
</disk>
I would like to work with guest image by libguestfs.
Using guestfish (all rights!):
><fs> add TEST/TEST1 protocol:gluster server:localhost:24007
><fs> run
><fs> list-filesystems
/dev/sda1: ext4
/dev/sda5: swap
The using libguestfs library (C++) results in error "No operating system found" My code:
#include <iostream>
#include <libvirt/libvirt.h>
#include <libguestfs/guestfs.h>
void main()
{
auto handle_ = guestfs_create();
if (!handle_) {
std::cout << "Connection failed" << std::endl;
return;
}
auto protocol = "gluster";
auto host = "localhost:24007";
auto name = "TEST/TEST1";
const char* server[2] = { host.c_str(), NULL };
auto res = guestfs_add_drive_opts(handle_, name,
GUESTFS_ADD_DRIVE_OPTS_FORMAT, "raw",
GUESTFS_ADD_DRIVE_OPTS_READONLY, 1,
GUESTFS_ADD_DRIVE_OPTS_PROTOCOL, protocol,
GUESTFS_ADD_DRIVE_OPTS_SERVER, server,
-1);
if (res < 0) {
std::cout << "Add drive failed" << std::endl;
return;
}
if (guestfs_launch(handle_) < 0) {
std::cout << "Launch failed" << std::endl;
return;
}
auto filesystems = guestfs_list_filesystems(handle_);
if (!filesystems) {
std::cout << "Failsystem failed" << std::endl;
return;
}
if (!filesystems[0]) {
std::cout << "No failsystem found" << std::endl;
return;
}
auto i = 0;
while (true) {
if (!filesystems[i]) {
std::cout << "No more fs" << std::endl;
break;
}
std::cout << "filesystem: " << filesystems[i] << " -- " << filesystems[i + 1] << std::endl;
i += 2;
}
auto roots_ = guestfs_inspect_os(handle_);
if (!roots_) {
std::cout << "Couldn't get root" << std::endl;
return;
}
if (!roots_[0]) {
std::cout << "No operating system found" << std::endl;
return;
}
}
How should I use libguetfs library to attach virtual michine disk correctly?
In this case VM disk format is qcow2. Be default parameter GUESTFS_ADD_DRIVE_OPTS_FORMAT is "qcow", so using guestfish there arn't any errors. In C++ code you should set GUESTFS_ADD_DRIVE_OPTS_FORMAT in appropriate value.