The old 'xm' driver does not currently implement the autostart feature for domains managed via /etc/xen. This patche addresses that limitation by making it create the symlinks in /etc/xen/auto as expected by the existing 'xendomains' init script for autostart. Daniel diff -r dddbb717add4 src/xen_unified.c --- a/src/xen_unified.c Mon Nov 24 10:45:05 2008 -0500 +++ b/src/xen_unified.c Mon Nov 24 11:00:24 2008 -0500 @@ -1159,13 +1159,16 @@ xenUnifiedDomainGetAutostart (virDomainP xenUnifiedDomainGetAutostart (virDomainPtr dom, int *autostart) { GET_PRIVATE(dom->conn); - int i; - - for (i = 0; i < XEN_UNIFIED_NR_DRIVERS; ++i) - if (priv->opened[i] && drivers[i]->domainGetAutostart && - drivers[i]->domainGetAutostart (dom, autostart) == 0) - return 0; - + + if (priv->xendConfigVersion < 3) { + if (priv->opened[XEN_UNIFIED_XM_OFFSET]) + return xenXMDomainGetAutostart(dom, autostart); + } else { + if (priv->opened[XEN_UNIFIED_XEND_OFFSET]) + return xenDaemonDomainGetAutostart(dom, autostart); + } + + xenUnifiedError (dom->conn, VIR_ERR_NO_SUPPORT, __FUNCTION__); return -1; } @@ -1173,13 +1176,16 @@ xenUnifiedDomainSetAutostart (virDomainP xenUnifiedDomainSetAutostart (virDomainPtr dom, int autostart) { GET_PRIVATE(dom->conn); - int i; - - for (i = 0; i < XEN_UNIFIED_NR_DRIVERS; ++i) - if (priv->opened[i] && drivers[i]->domainSetAutostart && - drivers[i]->domainSetAutostart (dom, autostart) == 0) - return 0; - + + if (priv->xendConfigVersion < 3) { + if (priv->opened[XEN_UNIFIED_XM_OFFSET]) + return xenXMDomainSetAutostart(dom, autostart); + } else { + if (priv->opened[XEN_UNIFIED_XEND_OFFSET]) + return xenDaemonDomainSetAutostart(dom, autostart); + } + + xenUnifiedError (dom->conn, VIR_ERR_NO_SUPPORT, __FUNCTION__); return -1; } diff -r dddbb717add4 src/xm_internal.c --- a/src/xm_internal.c Mon Nov 24 10:45:05 2008 -0500 +++ b/src/xm_internal.c Mon Nov 24 11:02:16 2008 -0500 @@ -2669,3 +2669,84 @@ xenXMDomainBlockPeek (virDomainPtr dom, return -1; } + +static char *xenXMAutostartLinkName(virDomainPtr dom) +{ + char *ret; + if (asprintf(&ret, "/etc/xen/auto/%s", dom->name) < 0) + return NULL; + return ret; +} + +static char *xenXMDomainConfigName(virDomainPtr dom) +{ + char *ret; + if (asprintf(&ret, "/etc/xen/%s", dom->name) < 0) + return NULL; + return ret; +} + +int xenXMDomainGetAutostart(virDomainPtr dom, int *autostart) +{ + char *linkname = xenXMAutostartLinkName(dom); + char *config = xenXMDomainConfigName(dom); + int ret = -1; + + if (!linkname || !config) { + xenXMError(dom->conn, VIR_ERR_NO_MEMORY, NULL); + goto cleanup; + } + + *autostart = virFileLinkPointsTo(linkname, config); + if (*autostart < 0) { + xenXMError(dom->conn, VIR_ERR_INTERNAL_ERROR, + _("failed to check autostart link %s: %s"), + linkname, strerror(errno)); + goto cleanup; + } + + ret = 0; + +cleanup: + VIR_FREE(linkname); + VIR_FREE(config); + return ret; +} + + +int xenXMDomainSetAutostart(virDomainPtr dom, int autostart) +{ + char *linkname = xenXMAutostartLinkName(dom); + char *config = xenXMDomainConfigName(dom); + int ret = -1; + + if (!linkname || !config) { + xenXMError(dom->conn, VIR_ERR_NO_MEMORY, NULL); + goto cleanup; + } + + if (autostart) { + if (symlink(config, linkname) < 0 && + errno != EEXIST) { + xenXMError(dom->conn, VIR_ERR_INTERNAL_ERROR, + "failed to create link %s: %s", + linkname, strerror(errno)); + goto cleanup; + } + } else { + if (unlink(linkname) < 0 && + errno != ENOENT) { + xenXMError(dom->conn, VIR_ERR_INTERNAL_ERROR, + "failed to remove link %s: %s", + linkname, strerror(errno)); + goto cleanup; + } + } + ret = 0; + +cleanup: + VIR_FREE(linkname); + VIR_FREE(config); + + return ret; +} diff -r dddbb717add4 src/xm_internal.h --- a/src/xm_internal.h Mon Nov 24 10:45:05 2008 -0500 +++ b/src/xm_internal.h Mon Nov 24 10:59:24 2008 -0500 @@ -65,4 +65,7 @@ virDomainDefPtr xenXMDomainConfigParse(v int xenXMDomainBlockPeek (virDomainPtr dom, const char *path, unsigned long long offset, size_t size, void *buffer); +int xenXMDomainGetAutostart(virDomainPtr dom, int *autostart); +int xenXMDomainSetAutostart(virDomainPtr dom, int autostart); + #endif -- |: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :| -- Libvir-list mailing list Libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list