ioemu: Get guest uuid from xenstore
PATCH 1/1 ioemu: Get guest uuid from xenstore
xenstore_get_guess_uuid() retrieves the guest uuid by using a sysctl hypercall through libxc now, but when we use the ioemu-stubdom, the hcall is not allowed to be invoked.
This patch makes ioemu get the guest uuid from xenstore, instead of using libxc.
Regards,
-----------------------
Yosuke Iwamatsu
NEC Corporation
xenstore.c +40 -29
@@ -247,47 +247,58 @@ static void xenstore_get_backend_path(char **backend, const char *devtype,free (frontend_doublecheck); } -const char *xenstore_get_guest_uuid (void ) { -#ifdef CONFIG_STUBDOM -return 0 ; -#else - -static char *already_computed; +const char *xenstore_get_guest_uuid (void ) +{ +static char *already_computed =NULL ; -xc_domaininfo_t info; -int xch =-1 , r, i; -char *p; +char *domain_path =NULL , *vm_path =NULL , *vm_value =NULL , *p =NULL ; +unsigned int len;if (already_computed)return already_computed; - xch =xc_interface_open (); -if (xch ==-1 ) { -fprintf (logfile,"cannot get uuid - xc_interface_open() failed: %s\n" , -strerror (errno)); +if (xsh ==NULL ) +return NULL ; + + domain_path =xs_get_domain_path (xsh, domid); +if (domain_path ==NULL ) { +fprintf (logfile,"xs_get_domain_path() error. domid %d.\n" , domid); goto out; } - r =xc_domain_getinfolist (xch, domid,1 , &info); -if (r !=1 ) { -fprintf (logfile,"cannot get uuid - xc_domain_getinfolist() failed:" -" %s\n" ,strerror (errno)); + +if (pasprintf (&vm_path,"%s/vm" , domain_path) ==-1 ) { +fprintf (logfile,"xenstore_get_guest_uuid(): out of memory.\n" ); goto out; } - already_computed =malloc (37 ); -for (i =0 , p = already_computed; i <16 ; i++, p +=2 ) { -if (i==4 || i==6 || i==8 || i==10 ) - *p++ ='-' ; -sprintf (p,"%02x" , info.handle[i]); + vm_value =xs_read (xsh,XBT_NULL , vm_path, &len); +if (vm_value ==NULL ) { +fprintf (logfile,"xs_read(): uuid get error. %s.\n" , vm_path); + goto out; } -close (xch); -return already_computed; + +if (strtok (vm_value,"/" ) ==NULL ) { +fprintf (logfile,"failed to parse guest uuid\n" ); + goto out; + } + p =strtok (NULL ,"/" ); +if (p ==NULL ) { +fprintf (logfile,"failed to parse guest uuid\n" ); + goto out; + } + +if (pasprintf (&already_computed,"%s" , p) ==-1 ) { +fprintf (logfile,"xenstore_get_guest_uuid(): out of memory.\n" ); + goto out; + } + +fprintf (logfile,"Guest uuid = %s\n" , already_computed); out: -if (xch !=-1 ) -close (xch); - -return 0 ; -#endif +free (domain_path); +free (vm_path); +free (vm_value); + +return already_computed; }#define DIRECT_PCI_STR_LEN 160
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Yosuke Iwamatsu writes ("[Xen-devel] [PATCH] ioemu: Get guest uuid from xenstore"):
Quoted 5 lines
xenstore_get_guess_uuid()retrieves the guest uuid by using a sysctl hypercall through libxc now, but when we use the ioemu-stubdom, the hcall is not allowed to be invoked.
This patch makes ioemu get the guest uuid from xenstore, instead of using libxc.
I don't think this patch is safe. /local/domain/<domid>/vm is owned by (and thus writeable by) the domain in question. We need a trustworthy copy of this information.
Ian.
Quoted 3 lines · Ian Jackson
I don't think this patch is safe. /local/domain/<domid>/vm is owned by (and thus writeable by) the domain in question. We need a trustworthy copy of this information.
Perhaps worth checking with a xenstore-ls -p, or a xenstore-write attempt within a domU, but the vm node should be owned by dom0 and read-only by the domU. The recent xenstore permissions fixes should ensure that.
So the patch should be safe and if it's not it's a xend bug that needs fixing.
-- Keir
PATCH 1/1 ioemu: Get guest uuid from xenstore
Quoted 6 lines · Keir Fraser
Quoted 3 lines · Ian Jackson
I don't think this patch is safe. /local/domain/<domid>/vm is owned by (and thus writeable by) the domain in question. We need a trustworthy copy of this information.
Quoted 6 lines
Perhaps worth checking with a xenstore-ls -p, or a xenstore-write attempt within a domU, but the vm node should be owned by dom0 and read-only by the domU. The recent xenstore permissions fixes should ensure that.
So the patch should be safe and if it's not it's a xend bug that needs fixing.
I checked with 'xenstore-ls -p' on my system and could confirm that the permission of /local/domain/<domid>/vm was set properly (owned by dom0 and set read-only by domU), apparently since cs 18933.
Thanks,
Yosuke
Yosuke Iwamatsu writes ("[Xen-devel] [PATCH] ioemu: Get guest uuid from xenstore"):
Quoted 4 lines
Quoted 3 lines · Keir Fraser
Perhaps worth checking with a xenstore-ls -p, or a xenstore-write attempt within a domU, but the vm node should be owned by dom0 and read-only by the domU. The recent xenstore permissions fixes should ensure that.
I looked with xenstore-ls -p but perhaps my test box is out of date. I'll update it and see what it does then ...
Ian.
PATCH 1/1 ioemu: Get guest uuid from xenstore
Quoted 9 lines · Ian Jackson
Yosuke Iwamatsu writes ("[Xen-devel] [PATCH] ioemu: Get guest uuid from xenstore"):
Quoted 4 lines
Quoted 3 lines · Keir Fraser
Perhaps worth checking with a xenstore-ls -p, or a xenstore-write attempt within a domU, but the vm node should be owned by dom0 and read-only by the domU. The recent xenstore permissions fixes should ensure that.
I looked with xenstore-ls -p but perhaps my test box is out of date. I'll update it and see what it does then ...
Any progress on this?
Please note that there is a real problem with the current implementation (xenstore_get_guest_uuid() returns NULL in stub-dom mode) that sometime the ioemu-domain crashes while running a Linux HVM domain, So we should fix it somehow.
Thank you,
Yosuke
Yosuke Iwamatsu writes ("[Xen-devel] [PATCH] ioemu: Get guest uuid from xenstore"):
Quoted 3 lines
Quoted 2 lines · Ian Jackson
I looked with xenstore-ls -p but perhaps my test box is out of date. I'll update it and see what it does then ...
... what it did was break utterly and after I'd fixed it I'm afraid I forgot about your patch. I've checked now and it's fine so I have applied your patch.
Thanks for the reminder.
Ian.