Re: Detach disk from VM - virsh (working) vs. PHP (not working)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 8/1/19 10:12 AM, Jan Horak wrote:
Hi all,

i created a script in PHP for create a virtual server with two QCOW2 discs … one is our system for installation and second is target system.

After successfully instalation (create a blank Debian system, prepare all files and grub partitions) i need a restart virtual without a installation disk.

If i use Virsh:

detach-disk --domain debian-test2 --persistent --target vda
reset debian-test2

everything works well.

If i use a PHP, there is „complicated“ way and „simple“ way:

1, complicated:

libvirt_domain_destroy($domain);
libvirt_domain_undefine($domain);

$xml = domain_create_xml($name,$uuid,$memory,$cpu,$vnc,$mac);
$domain = libvirt_domain_define_xml($server->conn, $xml);
libvirt_domain_disk_add($domain, "/users/".$name.".img", "vdb", "virtio", "qcow2", NULL);
libvirt_domain_create($domain);

(or instead libvirt_domain_disk_add i can define disk directly in XML)

But in this case, the server will not boot (GRUB error)

Question is, how GRUB refers to the disk where kernel is to be found. Also, I suspect it is not GRUB that is complaining, but SeaBIOS which hasn't found any bootable device. It's only an assumption becasue I don't know how domain_create_xml() works - it's not a libvirt-php function. There are two possibilities here:

1) make sure domain_create_xml() sets boot devices
2) construct disk XML yourself, and put "<boot order='N'/>" into it


2, simple:

libvirt_domain_disk_remove($domain,“vda“);
libvirt_domain_reboot($domain);

The problem of this solution is thats not working. The remove disk is failing with error „Unable attach disk“ - i looks to source code, and yes, there is a mystake with „attach“/„detach“, but main problem i see in log from libvirt:

Oh, that's only typo in the error message. In fact the detach API is called. And it fails.


Aug  1 02:57:05 ry libvirtd[19051]: missing source information for device vda

I try to put source detail to xml in source of PHP module

libvirt-domain.c:

   822	    if (asprintf(&newXml,
   823	                 "    <disk type='file' device='disk'>\n"
   824	                 "      <target dev='%s'/>\n"
   825	                 "    </disk>", dev) < 0) {
   826	        set_error("Out of memory" TSRMLS_CC);
   827	        goto error;
   828	    }

but my attempts was unsuccesfull (i’m not C programmer).

Yes, this minimalistic XML is not good as detach API requires full device XML. I'll fix this soon.


Questions:

A, why complicated way is not working and system dont want boot (GRUB error) if virsh works fine
B, why libvirt_domain_disk_remove is not work ? I use libvirt and libvirt-php latest from git.

I've pushed fixes here:


Please give it a try.

Michal

_______________________________________________
libvirt-users mailing list
libvirt-users@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvirt-users




[Index of Archives]     [Virt Tools]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [KDE Users]

  Powered by Linux