[Libvir] Updated Solaris dom0 patch (part 1)

I've broken this patch up into a few pieces to make it more reviewable and tried to address the comments from the previous patch (Jun 15th'ish if your looking). Here is first part... tested on today's CVS bits on a FC7 dom0 (LD_PRELOAD=src/.libs/libvirt.so src/.libs/virsh) One note, it looks like you still need a xend change on FC7 before the no kernel/bootloader option works. It looks like it's close though.. works fine with them of course. More details... [root@fedora solaris]# cat guest.py name = "solaris" vcpus = 1 memory = "512" #bootloader = "/usr/bin/pygrub" #kernel = "/platform/i86xpv/kernel/unix" #ramdisk = "/platform/i86pc/boot_archive" extra = "-k" root = "/dev/dsk/c0d0s0" disk = ['file:/export/guests/solaris/disk.img,0,w'] vif = ['bridge=xenbr0'] on_shutdown = "destroy" on_reboot = "restart" on_crash = "destroy" [root@fedora solaris]# xm list -l solaris (domain (on_crash destroy) (uuid 72f9b45e-4be9-bf1f-a500-3707b9c3922c) (bootloader_args ) (vcpus 1) (name solaris) (on_poweroff destroy) (on_reboot restart) (bootloader ) (maxmem 512) (memory 512) (shadow_memory 0) (cpu_weight 256) (cpu_cap 0) (features ) (on_xend_start ignore) (on_xend_stop ignore) (image (linux (kernel ) (args 'root=/dev/dsk/c0d0s0 -k'))) (status 0) (device (vif (bridge xenbr0) (uuid 9a8d5a2f-0a70-3a1f-fed0-fd2459e63733))) (device (vbd (uuid a6ba2241-1019-151e-6dd7-28638d3e17b7) (bootable 1) (driver paravirtualised) (dev 0) (uname file:/export/guests/solaris/disk.img) (mode w) ) ) ) [root@fedora solaris]# virsh # start solaris Domain solaris started virsh # dominfo solaris Id: 5 Name: solaris UUID: 72f9b45e-4be9-bf1f-a500-3707b9c3922c OS Type: linux State: no state CPU(s): 1 CPU time: 2.1s Max memory: 524288 kB Used memory: 524288 kB virsh # console solaris libvir: Xen Daemon error : internal error domain information incomplete, missing kernel & bootloader domain.xml:25: parser error : Opening and ending tag mismatch: os line 4 and domain </domain> ^ domain.xml:26: parser error : Premature end of data in tag domain line 1 ^ virsh # quit [root@fedora solaris]# xm console solaris Loading kmdb... SunOS Release 5.11 Version matrix-devel-build 32-bit Copyright 1983-2007 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms. WARNING: Found xen v3.1.0-rc7-2934.fc7 but need xen v3.0.4-1-xvm WARNING: The kernel may not function correctly Hostname: unknown Reading ZFS config: done. Sep 28 18:48:53 unknown ntpdate[419]: no server suitable for synchronization found unknown console login: root Password: Last login: Fri Sep 28 18:45:46 on console Sep 28 18:50:30 unknown login: ROOT LOGIN /dev/console Sun Microsystems Inc. SunOS 5.11 matrix-devel-build October 2007 bfu'ed from /net/girltalk/export/xvm/matrix-devel/archives/i386/nightly-nd on 2007-09-28 Sun Microsystems Inc. SunOS 5.11 xen-nv66-2007-06-24 October 2007 # poweroff Sep 28 18:50:33 unknown poweroff: initiated by root on /dev/console [root@fedora solaris]# Thanks, MRJ --- Solaris dom0 support diff --git a/src/xen_internal.c b/src/xen_internal.c --- a/src/xen_internal.c +++ b/src/xen_internal.c @@ -56,9 +56,10 @@ typedef struct v0_hypercall_struct { unsigned long op; unsigned long arg[5]; } v0_hypercall_t; + +#ifdef __linux__ #define XEN_V0_IOCTL_HYPERCALL_CMD \ _IOC(_IOC_NONE, 'P', 0, sizeof(v0_hypercall_t)) - /* the new one */ typedef struct v1_hypercall_struct { @@ -67,8 +68,12 @@ typedef struct v1_hypercall_struct } v1_hypercall_t; #define XEN_V1_IOCTL_HYPERCALL_CMD \ _IOC(_IOC_NONE, 'P', 0, sizeof(v1_hypercall_t)) - typedef v1_hypercall_t hypercall_t; +#elif define(__sun__) +typedef privcmd_hypercall_t hypercall_t; +#else +#error "unsupported platform" +#endif #ifndef __HYPERVISOR_sysctl #define __HYPERVISOR_sysctl 35 @@ -314,6 +319,26 @@ typedef union xen_getschedulerid xen_get dominfo.v2.handle : \ dominfo.v2d5.handle)) + +static int +lock_pages(void *addr, size_t len) +{ +#ifdef __linux__ + return (mlock(addr, len)); +#elif define(__sun) + return (0); +#endif +} + +static int +unlock_pages(void *addr, size_t len) +{ +#ifdef __linux__ + return (munlock(addr, len)); +#elif define(__sun) + return (0); +#endif +} struct xen_v0_getdomaininfolistop { @@ -616,7 +641,17 @@ typedef struct xen_op_v2_dom xen_op_v2_d #include "xen_unified.h" #include "xen_internal.h" -#define XEN_HYPERVISOR_SOCKET "/proc/xen/privcmd" +#ifdef __linux__ +#define XEN_HYPERVISOR_SOCKET "/proc/xen/privcmd" +#define HYPERVISOR_CAPABILITIES "/sys/hypervisor/properties/capabilities" +#define CPUINFO "/proc/cpuinfo" +#elif define(__sun__) +#define XEN_HYPERVISOR_SOCKET "/dev/xen/privcmd" +#define HYPERVISOR_CAPABILITIES "" +#define CPUINFO "/dev/cpu/self/cpuid" +#else +#error "unsupported platform" +#endif #ifndef PROXY static const char * xenHypervisorGetType(virConnectPtr conn); @@ -773,7 +808,7 @@ xenHypervisorDoV0Op(int handle, xen_op_v hc.op = __HYPERVISOR_dom0_op; hc.arg[0] = (unsigned long) op; - if (mlock(op, sizeof(dom0_op_t)) < 0) { + if (lock_pages(op, sizeof(dom0_op_t)) < 0) { virXenError(VIR_ERR_XEN_CALL, " locking", sizeof(*op)); return (-1); } @@ -783,7 +818,7 @@ xenHypervisorDoV0Op(int handle, xen_op_v virXenError(VIR_ERR_XEN_CALL, " ioctl ", xen_ioctl_hypercall_cmd); } - if (munlock(op, sizeof(dom0_op_t)) < 0) { + if (unlock_pages(op, sizeof(dom0_op_t)) < 0) { virXenError(VIR_ERR_XEN_CALL, " releasing", sizeof(*op)); ret = -1; } @@ -814,7 +849,7 @@ xenHypervisorDoV1Op(int handle, xen_op_v hc.op = __HYPERVISOR_dom0_op; hc.arg[0] = (unsigned long) op; - if (mlock(op, sizeof(dom0_op_t)) < 0) { + if (lock_pages(op, sizeof(dom0_op_t)) < 0) { virXenError(VIR_ERR_XEN_CALL, " locking", sizeof(*op)); return (-1); } @@ -824,7 +859,7 @@ xenHypervisorDoV1Op(int handle, xen_op_v virXenError(VIR_ERR_XEN_CALL, " ioctl ", xen_ioctl_hypercall_cmd); } - if (munlock(op, sizeof(dom0_op_t)) < 0) { + if (unlock_pages(op, sizeof(dom0_op_t)) < 0) { virXenError(VIR_ERR_XEN_CALL, " releasing", sizeof(*op)); ret = -1; } @@ -856,7 +891,7 @@ xenHypervisorDoV2Sys(int handle, xen_op_ hc.op = __HYPERVISOR_sysctl; hc.arg[0] = (unsigned long) op; - if (mlock(op, sizeof(dom0_op_t)) < 0) { + if (lock_pages(op, sizeof(dom0_op_t)) < 0) { virXenError(VIR_ERR_XEN_CALL, " locking", sizeof(*op)); return (-1); } @@ -866,7 +901,7 @@ xenHypervisorDoV2Sys(int handle, xen_op_ virXenError(VIR_ERR_XEN_CALL, " sys ioctl ", xen_ioctl_hypercall_cmd); } - if (munlock(op, sizeof(dom0_op_t)) < 0) { + if (unlock_pages(op, sizeof(dom0_op_t)) < 0) { virXenError(VIR_ERR_XEN_CALL, " releasing", sizeof(*op)); ret = -1; } @@ -898,7 +933,7 @@ xenHypervisorDoV2Dom(int handle, xen_op_ hc.op = __HYPERVISOR_domctl; hc.arg[0] = (unsigned long) op; - if (mlock(op, sizeof(dom0_op_t)) < 0) { + if (lock_pages(op, sizeof(dom0_op_t)) < 0) { virXenError(VIR_ERR_XEN_CALL, " locking", sizeof(*op)); return (-1); } @@ -908,7 +943,7 @@ xenHypervisorDoV2Dom(int handle, xen_op_ virXenError(VIR_ERR_XEN_CALL, " ioctl ", xen_ioctl_hypercall_cmd); } - if (munlock(op, sizeof(dom0_op_t)) < 0) { + if (unlock_pages(op, sizeof(dom0_op_t)) < 0) { virXenError(VIR_ERR_XEN_CALL, " releasing", sizeof(*op)); ret = -1; } @@ -936,7 +971,7 @@ virXen_getdomaininfolist(int handle, int { int ret = -1; - if (mlock(XEN_GETDOMAININFOLIST_DATA(dominfos), + if (lock_pages(XEN_GETDOMAININFOLIST_DATA(dominfos), XEN_GETDOMAININFO_SIZE * maxids) < 0) { virXenError(VIR_ERR_XEN_CALL, " locking", XEN_GETDOMAININFO_SIZE * maxids); @@ -992,7 +1027,7 @@ virXen_getdomaininfolist(int handle, int if (ret == 0) ret = op.u.getdomaininfolist.num_domains; } - if (munlock(XEN_GETDOMAININFOLIST_DATA(dominfos), + if (unlock_pages(XEN_GETDOMAININFOLIST_DATA(dominfos), XEN_GETDOMAININFO_SIZE * maxids) < 0) { virXenError(VIR_ERR_XEN_CALL, " release", XEN_GETDOMAININFO_SIZE * maxids); @@ -1679,7 +1714,7 @@ virXen_setvcpumap(int handle, int id, un if (hypervisor_version > 1) { xen_op_v2_dom op; - if (mlock(cpumap, maplen) < 0) { + if (lock_pages(cpumap, maplen) < 0) { virXenError(VIR_ERR_XEN_CALL, " locking", maplen); return (-1); } @@ -1697,7 +1732,7 @@ virXen_setvcpumap(int handle, int id, un } ret = xenHypervisorDoV2Dom(handle, &op); - if (munlock(cpumap, maplen) < 0) { + if (unlock_pages(cpumap, maplen) < 0) { virXenError(VIR_ERR_XEN_CALL, " release", maplen); ret = -1; } @@ -1794,7 +1829,7 @@ virXen_getvcpusinfo(int handle, int id, ipt->cpu = op.u.getvcpuinfod5.online ? (int)op.u.getvcpuinfod5.cpu : -1; } if ((cpumap != NULL) && (maplen > 0)) { - if (mlock(cpumap, maplen) < 0) { + if (lock_pages(cpumap, maplen) < 0) { virXenError(VIR_ERR_XEN_CALL, " locking", maplen); return (-1); } @@ -1812,7 +1847,7 @@ virXen_getvcpusinfo(int handle, int id, op.u.getvcpumapd5.cpumap.nr_cpus = maplen * 8; } ret = xenHypervisorDoV2Dom(handle, &op); - if (munlock(cpumap, maplen) < 0) { + if (unlock_pages(cpumap, maplen) < 0) { virXenError(VIR_ERR_XEN_CALL, " release", maplen); ret = -1; } @@ -1963,6 +1998,7 @@ xenHypervisorInit(void) goto detect_v2; } +#ifndef __sun__ /* * check if the old hypercall are actually working */ @@ -1980,6 +2016,7 @@ xenHypervisorInit(void) hypervisor_version = 0; goto done; } +#endif /* * we faild to make any hypercall diff --git a/src/xend_internal.c b/src/xend_internal.c --- a/src/xend_internal.c +++ b/src/xend_internal.c @@ -1280,9 +1280,7 @@ xend_parse_sexp_desc_os(virConnectPtr xe virBufferVSprintf(buf, " <type>hvm</type>\n"); tmp = sexpr_node(node, "domain/image/hvm/kernel"); if (tmp == NULL && !bootloader) { - virXendError(xend, VIR_ERR_INTERNAL_ERROR, - _("domain information incomplete, missing kernel & bootloader")); - return(-1); + virBufferVSprintf(buf, " <!-- use the default bootloader -->\n"); } if (tmp) virBufferVSprintf(buf, " <loader>%s</loader>\n", tmp); @@ -1311,9 +1309,7 @@ xend_parse_sexp_desc_os(virConnectPtr xe virBufferVSprintf(buf, " <type>linux</type>\n"); tmp = sexpr_node(node, "domain/image/linux/kernel"); if (tmp == NULL && !bootloader) { - virXendError(xend, VIR_ERR_INTERNAL_ERROR, - _("domain information incomplete, missing kernel & bootloader")); - return(-1); + virBufferVSprintf(buf, " <!-- use the default bootloader -->\n"); } if (tmp) virBufferVSprintf(buf, " <kernel>%s</kernel>\n", tmp); diff --git a/src/xml.c b/src/xml.c --- a/src/xml.c +++ b/src/xml.c @@ -703,10 +703,7 @@ virDomainParseXMLOSDescPV(virConnectPtr return (-1); } virBufferAdd(buf, "(image (linux ", 14); - if (kernel == NULL) { - virXMLError(conn, VIR_ERR_NO_KERNEL, NULL, 0); - return (-1); - } else { + if (kernel != NULL) { virBufferVSprintf(buf, "(kernel '%s')", (const char *) kernel); } if (initrd != NULL) diff --git a/src/xs_internal.c b/src/xs_internal.c --- a/src/xs_internal.c +++ b/src/xs_internal.c @@ -31,7 +31,13 @@ #include "xs_internal.h" #include "xen_internal.h" /* for xenHypervisorCheckID */ +#ifdef __linux__ #define XEN_HYPERVISOR_SOCKET "/proc/xen/privcmd" +#elif define(__sun__) +#define XEN_HYPERVISOR_SOCKET "/dev/xen/privcmd" +#else +#error "unsupported platform" +#endif #ifndef PROXY static char *xenStoreDomainGetOSType(virDomainPtr domain);

On Fri, Sep 28, 2007 at 03:03:15PM -0400, Mark Johnson wrote:
I've broken this patch up into a few pieces to make it more reviewable and tried to address the comments from the previous patch (Jun 15th'ish if your looking).
Here is first part...
tested on today's CVS bits on a FC7 dom0 (LD_PRELOAD=src/.libs/libvirt.so src/.libs/virsh)
One note, it looks like you still need a xend change on FC7 before the no kernel/bootloader option works. It looks like it's close though.. works fine with them of course.
More details...
[root@fedora solaris]# cat guest.py name = "solaris" vcpus = 1 memory = "512"
#bootloader = "/usr/bin/pygrub" #kernel = "/platform/i86xpv/kernel/unix" #ramdisk = "/platform/i86pc/boot_archive" extra = "-k"
root = "/dev/dsk/c0d0s0" disk = ['file:/export/guests/solaris/disk.img,0,w']
Oooh, that's interesting. Can you explain a little about Solaris paravirt disk naming, since it doesn't use xvdN/hdN/sdN style config ? Does the HVM disk naming still use the named devs ? Also one other question. There is a config option builder='linux' Which is never used on Linux since 'linux' is the default. Do you change the default on Solaris, or dooes the existing 'linux' builder work just fine with Solaris DomU images ? I guess the latter, since the SEXPR you have below is using 'linux'.
[root@fedora solaris]# xm list -l solaris (domain (on_crash destroy) (uuid 72f9b45e-4be9-bf1f-a500-3707b9c3922c) (bootloader_args ) (vcpus 1) (name solaris) (on_poweroff destroy) (on_reboot restart) (bootloader )
Since I notice it has the bootloader bit in the SEXPR, I'm thinking I'll tweak our XML generation so it at least includes an empty <bootloade/> since there may be tools using libvirt which expect at least one of <os> or <bootloader> and using an empty tag may keep them happier. eg, it'd probably avoid this problem...
virsh # console solaris libvir: Xen Daemon error : internal error domain information incomplete, missing kernel & bootloader domain.xml:25: parser error : Opening and ending tag mismatch: os line 4 and domain </domain> ^ domain.xml:26: parser error : Premature end of data in tag domain line 1
Though obviously your patch fixes that too. Dan. -- |=- Red Hat, Engineering, Emerging Technologies, Boston. +1 978 392 2496 -=| |=- Perl modules: http://search.cpan.org/~danberr/ -=| |=- Projects: http://freshmeat.net/~danielpb/ -=| |=- GnuPG: 7D3B9505 F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 -=|

On Fri, Sep 28, 2007 at 03:03:15PM -0400, Mark Johnson wrote:
I've broken this patch up into a few pieces to make it more reviewable and tried to address the comments from the previous patch (Jun 15th'ish if your looking).
Here is first part...
I've comitted this minus the changes to xml.c & xend_internal.c for the bootloader. The use case for those should be addressed by the other patch I posted - let me know if there turn out to be any issues with it. Regards, Dan. -- |=- Red Hat, Engineering, Emerging Technologies, Boston. +1 978 392 2496 -=| |=- Perl modules: http://search.cpan.org/~danberr/ -=| |=- Projects: http://freshmeat.net/~danielpb/ -=| |=- GnuPG: 7D3B9505 F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 -=|
participants (2)
-
Daniel P. Berrange
-
Mark Johnson