Index: src/libvirt.c =================================================================== RCS file: /data/cvs/libvirt/src/libvirt.c,v retrieving revision 1.29 diff -u -r1.29 libvirt.c --- src/libvirt.c 14 Jun 2006 13:03:04 -0000 1.29 +++ src/libvirt.c 14 Jun 2006 13:27:24 -0000 @@ -880,28 +880,33 @@ int virDomainDestroy(virDomainPtr domain) { - int ret; + int ret = -1, i; + virConnectPtr conn; if (!VIR_IS_CONNECTED_DOMAIN(domain)) { virLibDomainError(domain, VIR_ERR_INVALID_DOMAIN, __FUNCTION__); return (-1); } - /* - * try first with the xend method - */ - ret = xenDaemonDomainDestroy(domain); - if (ret == 0) { - virDomainFree(domain); - return (0); - } - - ret = xenHypervisorDestroyDomain(domain); - if (ret < 0) + conn = domain->conn; + if (domain->conn->flags & VIR_CONNECT_RO) return (-1); - virDomainFree(domain); - return (0); + /* Go though the driver registered entry points */ + for (i = 0;i < conn->nb_drivers;i++) { + if ((conn->drivers[i] != NULL) && + (conn->drivers[i]->domainDestroy != NULL)) { + if (conn->drivers[i]->domainDestroy(domain) == 0) + ret = 0; + } + } + + if (ret != 0) { + virLibConnError(conn, VIR_ERR_CALL_FAILED, __FUNCTION__); + return (ret); + } + + return (ret); } /** @@ -940,20 +945,33 @@ int virDomainSuspend(virDomainPtr domain) { - int ret; + int ret = -1, i; + virConnectPtr conn; if (!VIR_IS_CONNECTED_DOMAIN(domain)) { virLibDomainError(domain, VIR_ERR_INVALID_DOMAIN, __FUNCTION__); return (-1); } - /* first try though the Xen daemon */ - ret = xenDaemonDomainSuspend(domain); - if (ret == 0) - return (0); + conn = domain->conn; + if (domain->conn->flags & VIR_CONNECT_RO) + return (-1); + + /* Go though the driver registered entry points */ + for (i = 0;i < conn->nb_drivers;i++) { + if ((conn->drivers[i] != NULL) && + (conn->drivers[i]->domainSuspend != NULL)) { + if (conn->drivers[i]->domainSuspend(domain) == 0) + ret = 0; + } + } + + if (ret != 0) { + virLibConnError(conn, VIR_ERR_CALL_FAILED, __FUNCTION__); + return (ret); + } - /* then try a direct hypervisor access */ - return (xenHypervisorPauseDomain(domain)); + return (ret); } /** @@ -969,20 +987,33 @@ int virDomainResume(virDomainPtr domain) { - int ret; + int ret = -1, i; + virConnectPtr conn; if (!VIR_IS_CONNECTED_DOMAIN(domain)) { virLibDomainError(domain, VIR_ERR_INVALID_DOMAIN, __FUNCTION__); return (-1); } - /* first try though the Xen daemon */ - ret = xenDaemonDomainResume(domain); - if (ret == 0) - return (0); + conn = domain->conn; + if (domain->conn->flags & VIR_CONNECT_RO) + return (-1); - /* then try a direct hypervisor access */ - return (xenHypervisorResumeDomain(domain)); + /* Go though the driver registered entry points */ + for (i = 0;i < conn->nb_drivers;i++) { + if ((conn->drivers[i] != NULL) && + (conn->drivers[i]->domainResume != NULL)) { + if (conn->drivers[i]->domainResume(domain) == 0) + ret = 0; + } + } + + if (ret != 0) { + virLibConnError(conn, VIR_ERR_CALL_FAILED, __FUNCTION__); + return (ret); + } + + return (ret); } /** @@ -1099,30 +1130,32 @@ int virDomainShutdown(virDomainPtr domain) { - int ret; + int ret = -1, i; + virConnectPtr conn; if (!VIR_IS_CONNECTED_DOMAIN(domain)) { virLibDomainError(domain, VIR_ERR_INVALID_DOMAIN, __FUNCTION__); return (-1); } - /* - * try first with the xend daemon - */ - ret = xenDaemonDomainShutdown(domain); - if (ret == 0) { - domain->flags |= DOMAIN_IS_SHUTDOWN; - return (0); - } + conn = domain->conn; + if (domain->conn->flags & VIR_CONNECT_RO) + return (-1); - /* - * this is very hackish, the domU kernel probes for a special - * node in the xenstore and launch the shutdown command if found. - */ - ret = xenDaemonDomainShutdown(domain); - if (ret == 0) { - domain->flags |= DOMAIN_IS_SHUTDOWN; + /* Go though the driver registered entry points */ + for (i = 0;i < conn->nb_drivers;i++) { + if ((conn->drivers[i] != NULL) && + (conn->drivers[i]->domainShutdown != NULL)) { + if (conn->drivers[i]->domainShutdown(domain) == 0) + ret = 0; + } } + + if (ret != 0) { + virLibConnError(conn, VIR_ERR_CALL_FAILED, __FUNCTION__); + return (ret); + } + return (ret); } @@ -1140,30 +1173,32 @@ int virDomainReboot(virDomainPtr domain, unsigned int flags) { - int ret; + int ret = -1, i; + virConnectPtr conn; if (!VIR_IS_CONNECTED_DOMAIN(domain)) { virLibDomainError(domain, VIR_ERR_INVALID_DOMAIN, __FUNCTION__); return (-1); } - /* - * try first with the xend daemon - */ - ret = xenDaemonDomainReboot(domain, flags); - if (ret == 0) { - domain->flags |= DOMAIN_IS_SHUTDOWN; - return (0); - } + conn = domain->conn; + if (domain->conn->flags & VIR_CONNECT_RO) + return (-1); - /* - * this is very hackish, the domU kernel probes for a special - * node in the xenstore and launch the shutdown command if found. - */ - ret = xenDaemonDomainReboot(domain, flags); - if (ret == 0) { - domain->flags |= DOMAIN_IS_SHUTDOWN; + /* Go though the driver registered entry points */ + for (i = 0;i < conn->nb_drivers;i++) { + if ((conn->drivers[i] != NULL) && + (conn->drivers[i]->domainReboot != NULL)) { + if (conn->drivers[i]->domainReboot(domain, flags) == 0) + ret = 0; + } } + + if (ret != 0) { + virLibConnError(conn, VIR_ERR_CALL_FAILED, __FUNCTION__); + return (ret); + } + return (ret); }