2008-03-21 15:03:37 +00:00
|
|
|
/*
|
|
|
|
* Copyright IBM Corp. 2008
|
|
|
|
*
|
|
|
|
* lxc_driver.c: linux container driver functions
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* David L. Leskovec <dlesko at linux.vnet.ibm.com>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2008-04-10 07:30:52 +00:00
|
|
|
#include <fcntl.h>
|
2008-03-21 15:03:37 +00:00
|
|
|
#include <sched.h>
|
|
|
|
#include <sys/utsname.h>
|
2008-05-09 07:16:30 +00:00
|
|
|
#include <stdbool.h>
|
2008-03-21 15:03:37 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <sys/types.h>
|
2008-08-13 10:52:15 +00:00
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/un.h>
|
|
|
|
#include <sys/poll.h>
|
2008-03-21 15:03:37 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <wait.h>
|
|
|
|
|
2008-11-04 22:30:33 +00:00
|
|
|
#include "virterror_internal.h"
|
2008-11-06 16:36:07 +00:00
|
|
|
#include "logging.h"
|
2008-11-04 23:22:06 +00:00
|
|
|
#include "datatypes.h"
|
2008-03-21 15:03:37 +00:00
|
|
|
#include "lxc_conf.h"
|
2008-04-10 07:30:52 +00:00
|
|
|
#include "lxc_container.h"
|
2008-03-21 15:03:37 +00:00
|
|
|
#include "lxc_driver.h"
|
2008-06-09 22:51:32 +00:00
|
|
|
#include "memory.h"
|
2008-04-10 07:30:52 +00:00
|
|
|
#include "util.h"
|
2008-06-26 16:09:48 +00:00
|
|
|
#include "bridge.h"
|
|
|
|
#include "veth.h"
|
2008-08-13 10:52:15 +00:00
|
|
|
#include "event.h"
|
2008-10-03 16:46:01 +00:00
|
|
|
#include "cgroup.h"
|
2008-08-13 10:52:15 +00:00
|
|
|
|
2008-03-21 15:03:37 +00:00
|
|
|
|
2009-01-20 17:13:33 +00:00
|
|
|
#define VIR_FROM_THIS VIR_FROM_LXC
|
|
|
|
|
2008-03-27 09:34:06 +00:00
|
|
|
static int lxcStartup(void);
|
|
|
|
static int lxcShutdown(void);
|
2008-03-31 12:02:12 +00:00
|
|
|
static lxc_driver_t *lxc_driver = NULL;
|
2008-03-21 15:03:37 +00:00
|
|
|
|
|
|
|
/* Functions */
|
|
|
|
|
2008-12-04 21:12:41 +00:00
|
|
|
static void lxcDriverLock(lxc_driver_t *driver)
|
|
|
|
{
|
2009-01-15 19:56:05 +00:00
|
|
|
virMutexLock(&driver->lock);
|
2008-12-04 21:12:41 +00:00
|
|
|
}
|
|
|
|
static void lxcDriverUnlock(lxc_driver_t *driver)
|
|
|
|
{
|
2009-01-15 19:56:05 +00:00
|
|
|
virMutexUnlock(&driver->lock);
|
2008-12-04 21:12:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-17 11:44:51 +00:00
|
|
|
static int lxcProbe(void)
|
2008-03-21 15:03:37 +00:00
|
|
|
{
|
2008-11-17 11:44:51 +00:00
|
|
|
if (getuid() != 0 ||
|
|
|
|
lxcContainerAvailable(0) < 0)
|
|
|
|
return 0;
|
2008-08-13 10:25:34 +00:00
|
|
|
|
2008-11-17 11:44:51 +00:00
|
|
|
return 1;
|
2008-03-21 15:03:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static virDrvOpenStatus lxcOpen(virConnectPtr conn,
|
|
|
|
virConnectAuthPtr auth ATTRIBUTE_UNUSED,
|
|
|
|
int flags ATTRIBUTE_UNUSED)
|
|
|
|
{
|
2008-11-17 11:44:51 +00:00
|
|
|
if (!lxcProbe())
|
2008-03-21 15:03:37 +00:00
|
|
|
goto declineConnection;
|
|
|
|
|
2008-03-27 09:34:06 +00:00
|
|
|
if (lxc_driver == NULL)
|
|
|
|
goto declineConnection;
|
|
|
|
|
2008-03-21 15:03:37 +00:00
|
|
|
/* Verify uri was specified */
|
2008-11-17 11:44:51 +00:00
|
|
|
if (conn->uri == NULL) {
|
|
|
|
conn->uri = xmlParseURI("lxc:///");
|
|
|
|
if (!conn->uri) {
|
2009-01-29 12:10:32 +00:00
|
|
|
virReportOOMError(conn);
|
2008-11-17 11:44:51 +00:00
|
|
|
return VIR_DRV_OPEN_ERROR;
|
|
|
|
}
|
|
|
|
} else if (conn->uri->scheme == NULL ||
|
|
|
|
STRNEQ(conn->uri->scheme, "lxc")) {
|
2008-03-21 15:03:37 +00:00
|
|
|
goto declineConnection;
|
|
|
|
}
|
|
|
|
|
2008-03-27 09:34:06 +00:00
|
|
|
conn->privateData = lxc_driver;
|
2008-03-21 15:03:37 +00:00
|
|
|
|
|
|
|
return VIR_DRV_OPEN_SUCCESS;
|
|
|
|
|
|
|
|
declineConnection:
|
|
|
|
return VIR_DRV_OPEN_DECLINED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int lxcClose(virConnectPtr conn)
|
|
|
|
{
|
2008-03-27 09:34:06 +00:00
|
|
|
conn->privateData = NULL;
|
|
|
|
return 0;
|
2008-03-21 15:03:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static virDomainPtr lxcDomainLookupByID(virConnectPtr conn,
|
|
|
|
int id)
|
|
|
|
{
|
2008-12-04 21:11:41 +00:00
|
|
|
lxc_driver_t *driver = conn->privateData;
|
|
|
|
virDomainObjPtr vm;
|
|
|
|
virDomainPtr dom = NULL;
|
2008-03-21 15:03:37 +00:00
|
|
|
|
2008-12-04 21:12:41 +00:00
|
|
|
lxcDriverLock(driver);
|
2008-12-04 21:11:41 +00:00
|
|
|
vm = virDomainFindByID(&driver->domains, id);
|
2008-12-04 21:12:41 +00:00
|
|
|
lxcDriverUnlock(driver);
|
|
|
|
|
2008-03-21 15:03:37 +00:00
|
|
|
if (!vm) {
|
|
|
|
lxcError(conn, NULL, VIR_ERR_NO_DOMAIN, NULL);
|
2008-12-04 21:11:41 +00:00
|
|
|
goto cleanup;
|
2008-03-21 15:03:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
dom = virGetDomain(conn, vm->def->name, vm->def->uuid);
|
2008-12-04 21:11:41 +00:00
|
|
|
if (dom)
|
2008-03-21 15:03:37 +00:00
|
|
|
dom->id = vm->def->id;
|
|
|
|
|
2008-12-04 21:11:41 +00:00
|
|
|
cleanup:
|
2008-12-04 21:12:41 +00:00
|
|
|
if (vm)
|
|
|
|
virDomainObjUnlock(vm);
|
2008-03-21 15:03:37 +00:00
|
|
|
return dom;
|
|
|
|
}
|
|
|
|
|
|
|
|
static virDomainPtr lxcDomainLookupByUUID(virConnectPtr conn,
|
|
|
|
const unsigned char *uuid)
|
|
|
|
{
|
2008-12-04 21:11:41 +00:00
|
|
|
lxc_driver_t *driver = conn->privateData;
|
|
|
|
virDomainObjPtr vm;
|
|
|
|
virDomainPtr dom = NULL;
|
2008-03-21 15:03:37 +00:00
|
|
|
|
2008-12-04 21:12:41 +00:00
|
|
|
lxcDriverLock(driver);
|
2008-12-04 21:11:41 +00:00
|
|
|
vm = virDomainFindByUUID(&driver->domains, uuid);
|
2008-12-04 21:12:41 +00:00
|
|
|
lxcDriverUnlock(driver);
|
|
|
|
|
2008-03-21 15:03:37 +00:00
|
|
|
if (!vm) {
|
|
|
|
lxcError(conn, NULL, VIR_ERR_NO_DOMAIN, NULL);
|
2008-12-04 21:11:41 +00:00
|
|
|
goto cleanup;
|
2008-03-21 15:03:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
dom = virGetDomain(conn, vm->def->name, vm->def->uuid);
|
2008-12-04 21:11:41 +00:00
|
|
|
if (dom)
|
2008-03-21 15:03:37 +00:00
|
|
|
dom->id = vm->def->id;
|
|
|
|
|
2008-12-04 21:11:41 +00:00
|
|
|
cleanup:
|
2008-12-04 21:12:41 +00:00
|
|
|
if (vm)
|
|
|
|
virDomainObjUnlock(vm);
|
2008-03-21 15:03:37 +00:00
|
|
|
return dom;
|
|
|
|
}
|
|
|
|
|
|
|
|
static virDomainPtr lxcDomainLookupByName(virConnectPtr conn,
|
|
|
|
const char *name)
|
|
|
|
{
|
2008-12-04 21:11:41 +00:00
|
|
|
lxc_driver_t *driver = conn->privateData;
|
|
|
|
virDomainObjPtr vm;
|
|
|
|
virDomainPtr dom = NULL;
|
2008-03-21 15:03:37 +00:00
|
|
|
|
2008-12-04 21:12:41 +00:00
|
|
|
lxcDriverLock(driver);
|
2008-12-04 21:11:41 +00:00
|
|
|
vm = virDomainFindByName(&driver->domains, name);
|
2008-12-04 21:12:41 +00:00
|
|
|
lxcDriverUnlock(driver);
|
2008-03-21 15:03:37 +00:00
|
|
|
if (!vm) {
|
|
|
|
lxcError(conn, NULL, VIR_ERR_NO_DOMAIN, NULL);
|
2008-12-04 21:11:41 +00:00
|
|
|
goto cleanup;
|
2008-03-21 15:03:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
dom = virGetDomain(conn, vm->def->name, vm->def->uuid);
|
2008-12-04 21:11:41 +00:00
|
|
|
if (dom)
|
2008-03-21 15:03:37 +00:00
|
|
|
dom->id = vm->def->id;
|
|
|
|
|
2008-12-04 21:11:41 +00:00
|
|
|
cleanup:
|
2008-12-04 21:12:41 +00:00
|
|
|
if (vm)
|
|
|
|
virDomainObjUnlock(vm);
|
2008-03-21 15:03:37 +00:00
|
|
|
return dom;
|
|
|
|
}
|
|
|
|
|
2008-08-13 12:50:55 +00:00
|
|
|
static int lxcListDomains(virConnectPtr conn, int *ids, int nids) {
|
2008-12-04 21:11:41 +00:00
|
|
|
lxc_driver_t *driver = conn->privateData;
|
2008-10-10 14:20:37 +00:00
|
|
|
int got = 0, i;
|
|
|
|
|
2008-12-04 21:12:41 +00:00
|
|
|
lxcDriverLock(driver);
|
|
|
|
for (i = 0 ; i < driver->domains.count && got < nids ; i++) {
|
|
|
|
virDomainObjLock(driver->domains.objs[i]);
|
2008-10-10 14:20:37 +00:00
|
|
|
if (virDomainIsActive(driver->domains.objs[i]))
|
|
|
|
ids[got++] = driver->domains.objs[i]->def->id;
|
2008-12-04 21:12:41 +00:00
|
|
|
virDomainObjUnlock(driver->domains.objs[i]);
|
|
|
|
}
|
|
|
|
lxcDriverUnlock(driver);
|
2008-10-10 14:20:37 +00:00
|
|
|
|
2008-08-13 12:50:55 +00:00
|
|
|
return got;
|
2008-03-21 15:03:37 +00:00
|
|
|
}
|
2008-12-04 21:11:41 +00:00
|
|
|
|
2008-08-13 12:50:55 +00:00
|
|
|
static int lxcNumDomains(virConnectPtr conn) {
|
2008-12-04 21:11:41 +00:00
|
|
|
lxc_driver_t *driver = conn->privateData;
|
2008-10-10 14:20:37 +00:00
|
|
|
int n = 0, i;
|
|
|
|
|
2008-12-04 21:12:41 +00:00
|
|
|
lxcDriverLock(driver);
|
|
|
|
for (i = 0 ; i < driver->domains.count ; i++) {
|
|
|
|
virDomainObjLock(driver->domains.objs[i]);
|
2008-10-10 14:20:37 +00:00
|
|
|
if (virDomainIsActive(driver->domains.objs[i]))
|
2008-08-13 12:50:55 +00:00
|
|
|
n++;
|
2008-12-04 21:12:41 +00:00
|
|
|
virDomainObjUnlock(driver->domains.objs[i]);
|
|
|
|
}
|
|
|
|
lxcDriverUnlock(driver);
|
2008-10-10 14:20:37 +00:00
|
|
|
|
2008-08-13 12:50:55 +00:00
|
|
|
return n;
|
2008-03-21 15:03:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int lxcListDefinedDomains(virConnectPtr conn,
|
2008-08-13 12:50:55 +00:00
|
|
|
char **const names, int nnames) {
|
2008-12-04 21:11:41 +00:00
|
|
|
lxc_driver_t *driver = conn->privateData;
|
2008-08-13 12:50:55 +00:00
|
|
|
int got = 0, i;
|
2008-10-10 14:20:37 +00:00
|
|
|
|
2008-12-04 21:12:41 +00:00
|
|
|
lxcDriverLock(driver);
|
2008-10-10 14:20:37 +00:00
|
|
|
for (i = 0 ; i < driver->domains.count && got < nnames ; i++) {
|
2008-12-04 21:12:41 +00:00
|
|
|
virDomainObjLock(driver->domains.objs[i]);
|
2008-10-10 14:20:37 +00:00
|
|
|
if (!virDomainIsActive(driver->domains.objs[i])) {
|
|
|
|
if (!(names[got++] = strdup(driver->domains.objs[i]->def->name))) {
|
2009-01-29 12:10:32 +00:00
|
|
|
virReportOOMError(conn);
|
2008-12-04 21:12:41 +00:00
|
|
|
virDomainObjUnlock(driver->domains.objs[i]);
|
2008-03-21 15:03:37 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
2008-12-04 21:12:41 +00:00
|
|
|
virDomainObjUnlock(driver->domains.objs[i]);
|
2008-03-21 15:03:37 +00:00
|
|
|
}
|
2008-12-04 21:12:41 +00:00
|
|
|
lxcDriverUnlock(driver);
|
2008-10-10 14:20:37 +00:00
|
|
|
|
2008-08-13 12:50:55 +00:00
|
|
|
return got;
|
2008-03-21 15:03:37 +00:00
|
|
|
|
|
|
|
cleanup:
|
2008-08-13 12:50:55 +00:00
|
|
|
for (i = 0 ; i < got ; i++)
|
2008-06-06 11:09:57 +00:00
|
|
|
VIR_FREE(names[i]);
|
2008-12-04 21:12:41 +00:00
|
|
|
lxcDriverUnlock(driver);
|
2008-03-21 15:03:37 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-08-13 12:50:55 +00:00
|
|
|
static int lxcNumDefinedDomains(virConnectPtr conn) {
|
2008-12-04 21:11:41 +00:00
|
|
|
lxc_driver_t *driver = conn->privateData;
|
2008-10-10 14:20:37 +00:00
|
|
|
int n = 0, i;
|
|
|
|
|
2008-12-04 21:12:41 +00:00
|
|
|
lxcDriverLock(driver);
|
|
|
|
for (i = 0 ; i < driver->domains.count ; i++) {
|
|
|
|
virDomainObjLock(driver->domains.objs[i]);
|
2008-10-10 14:20:37 +00:00
|
|
|
if (!virDomainIsActive(driver->domains.objs[i]))
|
2008-08-13 12:50:55 +00:00
|
|
|
n++;
|
2008-12-04 21:12:41 +00:00
|
|
|
virDomainObjUnlock(driver->domains.objs[i]);
|
|
|
|
}
|
|
|
|
lxcDriverUnlock(driver);
|
2008-10-10 14:20:37 +00:00
|
|
|
|
2008-08-13 12:50:55 +00:00
|
|
|
return n;
|
2008-03-21 15:03:37 +00:00
|
|
|
}
|
|
|
|
|
2008-08-13 12:50:55 +00:00
|
|
|
|
|
|
|
|
2008-03-21 15:03:37 +00:00
|
|
|
static virDomainPtr lxcDomainDefine(virConnectPtr conn, const char *xml)
|
|
|
|
{
|
2008-12-04 21:11:41 +00:00
|
|
|
lxc_driver_t *driver = conn->privateData;
|
|
|
|
virDomainDefPtr def = NULL;
|
2008-12-04 21:12:41 +00:00
|
|
|
virDomainObjPtr vm = NULL;
|
2008-12-04 21:11:41 +00:00
|
|
|
virDomainPtr dom = NULL;
|
2008-03-21 15:03:37 +00:00
|
|
|
|
2008-12-04 21:12:41 +00:00
|
|
|
lxcDriverLock(driver);
|
2009-01-08 13:54:20 +00:00
|
|
|
if (!(def = virDomainDefParseString(conn, driver->caps, xml,
|
|
|
|
VIR_DOMAIN_XML_INACTIVE)))
|
2008-12-04 21:11:41 +00:00
|
|
|
goto cleanup;
|
2008-03-21 15:03:37 +00:00
|
|
|
|
2008-06-26 16:08:59 +00:00
|
|
|
if ((def->nets != NULL) && !(driver->have_netns)) {
|
|
|
|
lxcError(conn, NULL, VIR_ERR_NO_SUPPORT,
|
avoid many format string warnings
Building with --disable-nls exposed many new warnings like these:
virsh.c:4952: warning: format not a string literal and no format ...
util.c:163: warning: format not a string literal and no format arguments
All but one of the following changes add a "%s" argument before
the offending _(...) argument.
This was the only manual change:
* src/lxc_driver.c (lxcVersion): Use %s and strerror(errno)
rather than %m, to avoid a warning from gcc -Wformat-security.
Add "%s" before each warned about format-string-with-no-%-directive:
* src/domain_conf.c (virDomainHostdevSubsysUsbDefParseXML)
(virDomainDefParseString, virDomainDefParseFile):
* src/hash.c (virGetConnect, __virGetDomain, virReleaseDomain)
(__virGetNetwork, virReleaseNetwork, __virGetStoragePool)
(virReleaseStoragePool, __virGetStorageVol, virReleaseStorageVol):
* src/lxc_container.c (lxcContainerChild):
* src/lxc_driver.c (lxcDomainDefine, lxcDomainUndefine)
(lxcDomainGetInfo, lxcGetOSType, lxcDomainDumpXML)
(lxcSetupInterfaces, lxcDomainStart, lxcDomainCreateAndStart)
(lxcVersion, lxcGetSchedulerParameters):
* src/network_conf.c (virNetworkDefParseString)
(virNetworkDefParseFile):
* src/openvz_conf.c (openvzReadNetworkConf, openvzLoadDomains):
* src/openvz_driver.c (openvzDomainDefineCmd)
(openvzDomainGetInfo, openvzDomainDumpXML, openvzDomainShutdown)
(openvzDomainReboot, ADD_ARG_LIT, openvzDomainDefineXML)
(openvzDomainCreateXML, openvzDomainCreate, openvzDomainUndefine)
(openvzDomainSetAutostart, openvzDomainGetAutostart)
(openvzDomainSetVcpus):
* src/qemu_driver.c (qemudDomainBlockPeek, qemudDomainMemoryPeek):
* src/remote_internal.c (remoteDomainBlockPeek)
(remoteDomainMemoryPeek, remoteAuthPolkit):
* src/sexpr.c (sexpr_new, _string2sexpr):
* src/storage_backend_disk.c (virStorageBackendDiskMakeDataVol)
(virStorageBackendDiskCreateVol):
* src/storage_backend_fs.c
(virStorageBackendFileSystemNetFindPoolSources):
* src/storage_backend_logical.c (virStorageBackendLogicalFindLVs)
(virStorageBackendLogicalFindPoolSources):
* src/test.c (testOpenDefault, testOpenFromFile, testOpen)
(testGetDomainInfo, testDomainRestore)
(testNodeGetCellsFreeMemory):
* src/util.c (virExec):
* src/virsh.c (cmdAttachDevice, cmdDetachDevice)
(cmdAttachInterface, cmdDetachInterface, cmdAttachDisk)
(cmdDetachDisk, cmdEdit):
* src/xend_internal.c (do_connect, wr_sync, xend_op_ext)
(urlencode, xenDaemonDomainCreateXML)
(xenDaemonDomainLookupByName_ids, xenDaemonDomainLookupByID)
(xenDaemonParseSxprOS, xend_parse_sexp_desc_char)
(xenDaemonParseSxprChar, xenDaemonParseSxprDisks)
(xenDaemonParseSxpr, sexpr_to_xend_topology, sexpr_to_domain)
(xenDaemonDomainFetch, xenDaemonDomainGetAutostart)
(xenDaemonDomainSetAutostart, xenDaemonDomainMigratePerform)
(xenDaemonDomainDefineXML, xenDaemonGetSchedulerType)
(xenDaemonGetSchedulerParameters)
(xenDaemonSetSchedulerParameters, xenDaemonDomainBlockPeek)
(xenDaemonFormatSxprChr, virDomainXMLDevID):
* src/xm_internal.c (xenXMConfigCacheRefresh, xenXMDomainPinVcpu)
(xenXMDomainCreate, xenXMDomainDefineXML)
(xenXMDomainAttachDevice, xenXMDomainDetachDevice):
* src/xml.c (virXPathString, virXPathNumber, virXPathLong)
(virXPathULong, virXPathBoolean, virXPathNode, virXPathNodeSet):
* src/xs_internal.c (xenStoreOpen):
2008-10-13 16:46:28 +00:00
|
|
|
"%s", _("System lacks NETNS support"));
|
2008-12-04 21:11:41 +00:00
|
|
|
goto cleanup;
|
2008-06-26 16:08:59 +00:00
|
|
|
}
|
|
|
|
|
2008-12-04 21:11:41 +00:00
|
|
|
if (!(vm = virDomainAssignDef(conn, &driver->domains, def)))
|
|
|
|
goto cleanup;
|
|
|
|
def = NULL;
|
2008-08-20 19:42:36 +00:00
|
|
|
vm->persistent = 1;
|
2008-03-21 15:03:37 +00:00
|
|
|
|
2008-08-13 12:50:55 +00:00
|
|
|
if (virDomainSaveConfig(conn,
|
|
|
|
driver->configDir,
|
2008-08-20 19:42:36 +00:00
|
|
|
vm->newDef ? vm->newDef : vm->def) < 0) {
|
2008-08-13 12:50:55 +00:00
|
|
|
virDomainRemoveInactive(&driver->domains, vm);
|
2008-12-04 21:12:41 +00:00
|
|
|
vm = NULL;
|
2008-12-04 21:11:41 +00:00
|
|
|
goto cleanup;
|
2008-03-21 15:03:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
dom = virGetDomain(conn, vm->def->name, vm->def->uuid);
|
2008-12-04 21:11:41 +00:00
|
|
|
if (dom)
|
2008-03-21 15:03:37 +00:00
|
|
|
dom->id = vm->def->id;
|
|
|
|
|
2008-12-04 21:11:41 +00:00
|
|
|
cleanup:
|
|
|
|
virDomainDefFree(def);
|
2008-12-04 21:12:41 +00:00
|
|
|
if (vm)
|
|
|
|
virDomainObjUnlock(vm);
|
|
|
|
lxcDriverUnlock(driver);
|
2008-03-21 15:03:37 +00:00
|
|
|
return dom;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int lxcDomainUndefine(virDomainPtr dom)
|
|
|
|
{
|
2008-12-04 21:11:41 +00:00
|
|
|
lxc_driver_t *driver = dom->conn->privateData;
|
|
|
|
virDomainObjPtr vm;
|
|
|
|
int ret = -1;
|
2008-03-21 15:03:37 +00:00
|
|
|
|
2008-12-04 21:12:41 +00:00
|
|
|
lxcDriverLock(driver);
|
2008-12-04 21:11:41 +00:00
|
|
|
vm = virDomainFindByUUID(&driver->domains, dom->uuid);
|
2008-03-21 15:03:37 +00:00
|
|
|
if (!vm) {
|
|
|
|
lxcError(dom->conn, dom, VIR_ERR_INVALID_DOMAIN,
|
avoid many format string warnings
Building with --disable-nls exposed many new warnings like these:
virsh.c:4952: warning: format not a string literal and no format ...
util.c:163: warning: format not a string literal and no format arguments
All but one of the following changes add a "%s" argument before
the offending _(...) argument.
This was the only manual change:
* src/lxc_driver.c (lxcVersion): Use %s and strerror(errno)
rather than %m, to avoid a warning from gcc -Wformat-security.
Add "%s" before each warned about format-string-with-no-%-directive:
* src/domain_conf.c (virDomainHostdevSubsysUsbDefParseXML)
(virDomainDefParseString, virDomainDefParseFile):
* src/hash.c (virGetConnect, __virGetDomain, virReleaseDomain)
(__virGetNetwork, virReleaseNetwork, __virGetStoragePool)
(virReleaseStoragePool, __virGetStorageVol, virReleaseStorageVol):
* src/lxc_container.c (lxcContainerChild):
* src/lxc_driver.c (lxcDomainDefine, lxcDomainUndefine)
(lxcDomainGetInfo, lxcGetOSType, lxcDomainDumpXML)
(lxcSetupInterfaces, lxcDomainStart, lxcDomainCreateAndStart)
(lxcVersion, lxcGetSchedulerParameters):
* src/network_conf.c (virNetworkDefParseString)
(virNetworkDefParseFile):
* src/openvz_conf.c (openvzReadNetworkConf, openvzLoadDomains):
* src/openvz_driver.c (openvzDomainDefineCmd)
(openvzDomainGetInfo, openvzDomainDumpXML, openvzDomainShutdown)
(openvzDomainReboot, ADD_ARG_LIT, openvzDomainDefineXML)
(openvzDomainCreateXML, openvzDomainCreate, openvzDomainUndefine)
(openvzDomainSetAutostart, openvzDomainGetAutostart)
(openvzDomainSetVcpus):
* src/qemu_driver.c (qemudDomainBlockPeek, qemudDomainMemoryPeek):
* src/remote_internal.c (remoteDomainBlockPeek)
(remoteDomainMemoryPeek, remoteAuthPolkit):
* src/sexpr.c (sexpr_new, _string2sexpr):
* src/storage_backend_disk.c (virStorageBackendDiskMakeDataVol)
(virStorageBackendDiskCreateVol):
* src/storage_backend_fs.c
(virStorageBackendFileSystemNetFindPoolSources):
* src/storage_backend_logical.c (virStorageBackendLogicalFindLVs)
(virStorageBackendLogicalFindPoolSources):
* src/test.c (testOpenDefault, testOpenFromFile, testOpen)
(testGetDomainInfo, testDomainRestore)
(testNodeGetCellsFreeMemory):
* src/util.c (virExec):
* src/virsh.c (cmdAttachDevice, cmdDetachDevice)
(cmdAttachInterface, cmdDetachInterface, cmdAttachDisk)
(cmdDetachDisk, cmdEdit):
* src/xend_internal.c (do_connect, wr_sync, xend_op_ext)
(urlencode, xenDaemonDomainCreateXML)
(xenDaemonDomainLookupByName_ids, xenDaemonDomainLookupByID)
(xenDaemonParseSxprOS, xend_parse_sexp_desc_char)
(xenDaemonParseSxprChar, xenDaemonParseSxprDisks)
(xenDaemonParseSxpr, sexpr_to_xend_topology, sexpr_to_domain)
(xenDaemonDomainFetch, xenDaemonDomainGetAutostart)
(xenDaemonDomainSetAutostart, xenDaemonDomainMigratePerform)
(xenDaemonDomainDefineXML, xenDaemonGetSchedulerType)
(xenDaemonGetSchedulerParameters)
(xenDaemonSetSchedulerParameters, xenDaemonDomainBlockPeek)
(xenDaemonFormatSxprChr, virDomainXMLDevID):
* src/xm_internal.c (xenXMConfigCacheRefresh, xenXMDomainPinVcpu)
(xenXMDomainCreate, xenXMDomainDefineXML)
(xenXMDomainAttachDevice, xenXMDomainDetachDevice):
* src/xml.c (virXPathString, virXPathNumber, virXPathLong)
(virXPathULong, virXPathBoolean, virXPathNode, virXPathNodeSet):
* src/xs_internal.c (xenStoreOpen):
2008-10-13 16:46:28 +00:00
|
|
|
"%s", _("no domain with matching uuid"));
|
2008-12-04 21:11:41 +00:00
|
|
|
goto cleanup;
|
2008-03-21 15:03:37 +00:00
|
|
|
}
|
|
|
|
|
2008-08-13 12:50:55 +00:00
|
|
|
if (virDomainIsActive(vm)) {
|
2008-03-21 15:03:37 +00:00
|
|
|
lxcError(dom->conn, dom, VIR_ERR_INTERNAL_ERROR,
|
avoid many format string warnings
Building with --disable-nls exposed many new warnings like these:
virsh.c:4952: warning: format not a string literal and no format ...
util.c:163: warning: format not a string literal and no format arguments
All but one of the following changes add a "%s" argument before
the offending _(...) argument.
This was the only manual change:
* src/lxc_driver.c (lxcVersion): Use %s and strerror(errno)
rather than %m, to avoid a warning from gcc -Wformat-security.
Add "%s" before each warned about format-string-with-no-%-directive:
* src/domain_conf.c (virDomainHostdevSubsysUsbDefParseXML)
(virDomainDefParseString, virDomainDefParseFile):
* src/hash.c (virGetConnect, __virGetDomain, virReleaseDomain)
(__virGetNetwork, virReleaseNetwork, __virGetStoragePool)
(virReleaseStoragePool, __virGetStorageVol, virReleaseStorageVol):
* src/lxc_container.c (lxcContainerChild):
* src/lxc_driver.c (lxcDomainDefine, lxcDomainUndefine)
(lxcDomainGetInfo, lxcGetOSType, lxcDomainDumpXML)
(lxcSetupInterfaces, lxcDomainStart, lxcDomainCreateAndStart)
(lxcVersion, lxcGetSchedulerParameters):
* src/network_conf.c (virNetworkDefParseString)
(virNetworkDefParseFile):
* src/openvz_conf.c (openvzReadNetworkConf, openvzLoadDomains):
* src/openvz_driver.c (openvzDomainDefineCmd)
(openvzDomainGetInfo, openvzDomainDumpXML, openvzDomainShutdown)
(openvzDomainReboot, ADD_ARG_LIT, openvzDomainDefineXML)
(openvzDomainCreateXML, openvzDomainCreate, openvzDomainUndefine)
(openvzDomainSetAutostart, openvzDomainGetAutostart)
(openvzDomainSetVcpus):
* src/qemu_driver.c (qemudDomainBlockPeek, qemudDomainMemoryPeek):
* src/remote_internal.c (remoteDomainBlockPeek)
(remoteDomainMemoryPeek, remoteAuthPolkit):
* src/sexpr.c (sexpr_new, _string2sexpr):
* src/storage_backend_disk.c (virStorageBackendDiskMakeDataVol)
(virStorageBackendDiskCreateVol):
* src/storage_backend_fs.c
(virStorageBackendFileSystemNetFindPoolSources):
* src/storage_backend_logical.c (virStorageBackendLogicalFindLVs)
(virStorageBackendLogicalFindPoolSources):
* src/test.c (testOpenDefault, testOpenFromFile, testOpen)
(testGetDomainInfo, testDomainRestore)
(testNodeGetCellsFreeMemory):
* src/util.c (virExec):
* src/virsh.c (cmdAttachDevice, cmdDetachDevice)
(cmdAttachInterface, cmdDetachInterface, cmdAttachDisk)
(cmdDetachDisk, cmdEdit):
* src/xend_internal.c (do_connect, wr_sync, xend_op_ext)
(urlencode, xenDaemonDomainCreateXML)
(xenDaemonDomainLookupByName_ids, xenDaemonDomainLookupByID)
(xenDaemonParseSxprOS, xend_parse_sexp_desc_char)
(xenDaemonParseSxprChar, xenDaemonParseSxprDisks)
(xenDaemonParseSxpr, sexpr_to_xend_topology, sexpr_to_domain)
(xenDaemonDomainFetch, xenDaemonDomainGetAutostart)
(xenDaemonDomainSetAutostart, xenDaemonDomainMigratePerform)
(xenDaemonDomainDefineXML, xenDaemonGetSchedulerType)
(xenDaemonGetSchedulerParameters)
(xenDaemonSetSchedulerParameters, xenDaemonDomainBlockPeek)
(xenDaemonFormatSxprChr, virDomainXMLDevID):
* src/xm_internal.c (xenXMConfigCacheRefresh, xenXMDomainPinVcpu)
(xenXMDomainCreate, xenXMDomainDefineXML)
(xenXMDomainAttachDevice, xenXMDomainDetachDevice):
* src/xml.c (virXPathString, virXPathNumber, virXPathLong)
(virXPathULong, virXPathBoolean, virXPathNode, virXPathNodeSet):
* src/xs_internal.c (xenStoreOpen):
2008-10-13 16:46:28 +00:00
|
|
|
"%s", _("cannot delete active domain"));
|
2008-12-04 21:11:41 +00:00
|
|
|
goto cleanup;
|
2008-03-21 15:03:37 +00:00
|
|
|
}
|
|
|
|
|
2008-08-20 19:42:36 +00:00
|
|
|
if (!vm->persistent) {
|
|
|
|
lxcError(dom->conn, dom, VIR_ERR_INTERNAL_ERROR,
|
|
|
|
"%s", _("cannot undefine transient domain"));
|
2008-12-04 21:11:41 +00:00
|
|
|
goto cleanup;
|
2008-08-20 19:42:36 +00:00
|
|
|
}
|
2008-03-21 15:03:37 +00:00
|
|
|
|
2008-08-20 19:42:36 +00:00
|
|
|
if (virDomainDeleteConfig(dom->conn,
|
|
|
|
driver->configDir,
|
|
|
|
driver->autostartDir,
|
2008-12-04 21:11:41 +00:00
|
|
|
vm) < 0)
|
|
|
|
goto cleanup;
|
2008-03-21 15:03:37 +00:00
|
|
|
|
2008-08-13 12:50:55 +00:00
|
|
|
virDomainRemoveInactive(&driver->domains, vm);
|
2008-12-04 21:12:41 +00:00
|
|
|
vm = NULL;
|
2008-12-04 21:11:41 +00:00
|
|
|
ret = 0;
|
2008-03-21 15:03:37 +00:00
|
|
|
|
2008-12-04 21:11:41 +00:00
|
|
|
cleanup:
|
2008-12-04 21:12:41 +00:00
|
|
|
if (vm)
|
|
|
|
virDomainObjUnlock(vm);
|
|
|
|
lxcDriverUnlock(driver);
|
2008-12-04 21:11:41 +00:00
|
|
|
return ret;
|
2008-03-21 15:03:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int lxcDomainGetInfo(virDomainPtr dom,
|
|
|
|
virDomainInfoPtr info)
|
|
|
|
{
|
2008-12-04 21:11:41 +00:00
|
|
|
lxc_driver_t *driver = dom->conn->privateData;
|
|
|
|
virDomainObjPtr vm;
|
|
|
|
int ret = -1;
|
2008-03-21 15:03:37 +00:00
|
|
|
|
2008-12-04 21:12:41 +00:00
|
|
|
lxcDriverLock(driver);
|
2008-12-04 21:11:41 +00:00
|
|
|
vm = virDomainFindByUUID(&driver->domains, dom->uuid);
|
2008-12-04 21:12:41 +00:00
|
|
|
lxcDriverUnlock(driver);
|
|
|
|
|
2008-03-21 15:03:37 +00:00
|
|
|
if (!vm) {
|
|
|
|
lxcError(dom->conn, dom, VIR_ERR_INVALID_DOMAIN,
|
avoid many format string warnings
Building with --disable-nls exposed many new warnings like these:
virsh.c:4952: warning: format not a string literal and no format ...
util.c:163: warning: format not a string literal and no format arguments
All but one of the following changes add a "%s" argument before
the offending _(...) argument.
This was the only manual change:
* src/lxc_driver.c (lxcVersion): Use %s and strerror(errno)
rather than %m, to avoid a warning from gcc -Wformat-security.
Add "%s" before each warned about format-string-with-no-%-directive:
* src/domain_conf.c (virDomainHostdevSubsysUsbDefParseXML)
(virDomainDefParseString, virDomainDefParseFile):
* src/hash.c (virGetConnect, __virGetDomain, virReleaseDomain)
(__virGetNetwork, virReleaseNetwork, __virGetStoragePool)
(virReleaseStoragePool, __virGetStorageVol, virReleaseStorageVol):
* src/lxc_container.c (lxcContainerChild):
* src/lxc_driver.c (lxcDomainDefine, lxcDomainUndefine)
(lxcDomainGetInfo, lxcGetOSType, lxcDomainDumpXML)
(lxcSetupInterfaces, lxcDomainStart, lxcDomainCreateAndStart)
(lxcVersion, lxcGetSchedulerParameters):
* src/network_conf.c (virNetworkDefParseString)
(virNetworkDefParseFile):
* src/openvz_conf.c (openvzReadNetworkConf, openvzLoadDomains):
* src/openvz_driver.c (openvzDomainDefineCmd)
(openvzDomainGetInfo, openvzDomainDumpXML, openvzDomainShutdown)
(openvzDomainReboot, ADD_ARG_LIT, openvzDomainDefineXML)
(openvzDomainCreateXML, openvzDomainCreate, openvzDomainUndefine)
(openvzDomainSetAutostart, openvzDomainGetAutostart)
(openvzDomainSetVcpus):
* src/qemu_driver.c (qemudDomainBlockPeek, qemudDomainMemoryPeek):
* src/remote_internal.c (remoteDomainBlockPeek)
(remoteDomainMemoryPeek, remoteAuthPolkit):
* src/sexpr.c (sexpr_new, _string2sexpr):
* src/storage_backend_disk.c (virStorageBackendDiskMakeDataVol)
(virStorageBackendDiskCreateVol):
* src/storage_backend_fs.c
(virStorageBackendFileSystemNetFindPoolSources):
* src/storage_backend_logical.c (virStorageBackendLogicalFindLVs)
(virStorageBackendLogicalFindPoolSources):
* src/test.c (testOpenDefault, testOpenFromFile, testOpen)
(testGetDomainInfo, testDomainRestore)
(testNodeGetCellsFreeMemory):
* src/util.c (virExec):
* src/virsh.c (cmdAttachDevice, cmdDetachDevice)
(cmdAttachInterface, cmdDetachInterface, cmdAttachDisk)
(cmdDetachDisk, cmdEdit):
* src/xend_internal.c (do_connect, wr_sync, xend_op_ext)
(urlencode, xenDaemonDomainCreateXML)
(xenDaemonDomainLookupByName_ids, xenDaemonDomainLookupByID)
(xenDaemonParseSxprOS, xend_parse_sexp_desc_char)
(xenDaemonParseSxprChar, xenDaemonParseSxprDisks)
(xenDaemonParseSxpr, sexpr_to_xend_topology, sexpr_to_domain)
(xenDaemonDomainFetch, xenDaemonDomainGetAutostart)
(xenDaemonDomainSetAutostart, xenDaemonDomainMigratePerform)
(xenDaemonDomainDefineXML, xenDaemonGetSchedulerType)
(xenDaemonGetSchedulerParameters)
(xenDaemonSetSchedulerParameters, xenDaemonDomainBlockPeek)
(xenDaemonFormatSxprChr, virDomainXMLDevID):
* src/xm_internal.c (xenXMConfigCacheRefresh, xenXMDomainPinVcpu)
(xenXMDomainCreate, xenXMDomainDefineXML)
(xenXMDomainAttachDevice, xenXMDomainDetachDevice):
* src/xml.c (virXPathString, virXPathNumber, virXPathLong)
(virXPathULong, virXPathBoolean, virXPathNode, virXPathNodeSet):
* src/xs_internal.c (xenStoreOpen):
2008-10-13 16:46:28 +00:00
|
|
|
"%s", _("no domain with matching uuid"));
|
2008-12-04 21:11:41 +00:00
|
|
|
goto cleanup;
|
2008-03-21 15:03:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
info->state = vm->state;
|
|
|
|
|
2008-08-13 12:50:55 +00:00
|
|
|
if (!virDomainIsActive(vm)) {
|
2008-03-21 15:03:37 +00:00
|
|
|
info->cpuTime = 0;
|
|
|
|
} else {
|
|
|
|
info->cpuTime = 0;
|
|
|
|
}
|
|
|
|
|
2008-08-13 12:50:55 +00:00
|
|
|
info->maxMem = vm->def->maxmem;
|
|
|
|
info->memory = vm->def->memory;
|
2008-03-21 15:03:37 +00:00
|
|
|
info->nrVirtCpu = 1;
|
2008-12-04 21:11:41 +00:00
|
|
|
ret = 0;
|
2008-03-21 15:03:37 +00:00
|
|
|
|
2008-12-04 21:11:41 +00:00
|
|
|
cleanup:
|
2008-12-04 21:12:41 +00:00
|
|
|
if (vm)
|
|
|
|
virDomainObjUnlock(vm);
|
2008-12-04 21:11:41 +00:00
|
|
|
return ret;
|
2008-03-21 15:03:37 +00:00
|
|
|
}
|
|
|
|
|
2008-08-13 12:50:55 +00:00
|
|
|
static char *lxcGetOSType(virDomainPtr dom)
|
2008-03-21 15:03:37 +00:00
|
|
|
{
|
2008-12-04 21:11:41 +00:00
|
|
|
lxc_driver_t *driver = dom->conn->privateData;
|
|
|
|
virDomainObjPtr vm;
|
|
|
|
char *ret = NULL;
|
2008-08-13 12:50:55 +00:00
|
|
|
|
2008-12-04 21:12:41 +00:00
|
|
|
lxcDriverLock(driver);
|
2008-12-04 21:11:41 +00:00
|
|
|
vm = virDomainFindByUUID(&driver->domains, dom->uuid);
|
2008-12-04 21:12:41 +00:00
|
|
|
lxcDriverUnlock(driver);
|
|
|
|
|
2008-08-13 12:50:55 +00:00
|
|
|
if (!vm) {
|
|
|
|
lxcError(dom->conn, dom, VIR_ERR_INVALID_DOMAIN,
|
avoid many format string warnings
Building with --disable-nls exposed many new warnings like these:
virsh.c:4952: warning: format not a string literal and no format ...
util.c:163: warning: format not a string literal and no format arguments
All but one of the following changes add a "%s" argument before
the offending _(...) argument.
This was the only manual change:
* src/lxc_driver.c (lxcVersion): Use %s and strerror(errno)
rather than %m, to avoid a warning from gcc -Wformat-security.
Add "%s" before each warned about format-string-with-no-%-directive:
* src/domain_conf.c (virDomainHostdevSubsysUsbDefParseXML)
(virDomainDefParseString, virDomainDefParseFile):
* src/hash.c (virGetConnect, __virGetDomain, virReleaseDomain)
(__virGetNetwork, virReleaseNetwork, __virGetStoragePool)
(virReleaseStoragePool, __virGetStorageVol, virReleaseStorageVol):
* src/lxc_container.c (lxcContainerChild):
* src/lxc_driver.c (lxcDomainDefine, lxcDomainUndefine)
(lxcDomainGetInfo, lxcGetOSType, lxcDomainDumpXML)
(lxcSetupInterfaces, lxcDomainStart, lxcDomainCreateAndStart)
(lxcVersion, lxcGetSchedulerParameters):
* src/network_conf.c (virNetworkDefParseString)
(virNetworkDefParseFile):
* src/openvz_conf.c (openvzReadNetworkConf, openvzLoadDomains):
* src/openvz_driver.c (openvzDomainDefineCmd)
(openvzDomainGetInfo, openvzDomainDumpXML, openvzDomainShutdown)
(openvzDomainReboot, ADD_ARG_LIT, openvzDomainDefineXML)
(openvzDomainCreateXML, openvzDomainCreate, openvzDomainUndefine)
(openvzDomainSetAutostart, openvzDomainGetAutostart)
(openvzDomainSetVcpus):
* src/qemu_driver.c (qemudDomainBlockPeek, qemudDomainMemoryPeek):
* src/remote_internal.c (remoteDomainBlockPeek)
(remoteDomainMemoryPeek, remoteAuthPolkit):
* src/sexpr.c (sexpr_new, _string2sexpr):
* src/storage_backend_disk.c (virStorageBackendDiskMakeDataVol)
(virStorageBackendDiskCreateVol):
* src/storage_backend_fs.c
(virStorageBackendFileSystemNetFindPoolSources):
* src/storage_backend_logical.c (virStorageBackendLogicalFindLVs)
(virStorageBackendLogicalFindPoolSources):
* src/test.c (testOpenDefault, testOpenFromFile, testOpen)
(testGetDomainInfo, testDomainRestore)
(testNodeGetCellsFreeMemory):
* src/util.c (virExec):
* src/virsh.c (cmdAttachDevice, cmdDetachDevice)
(cmdAttachInterface, cmdDetachInterface, cmdAttachDisk)
(cmdDetachDisk, cmdEdit):
* src/xend_internal.c (do_connect, wr_sync, xend_op_ext)
(urlencode, xenDaemonDomainCreateXML)
(xenDaemonDomainLookupByName_ids, xenDaemonDomainLookupByID)
(xenDaemonParseSxprOS, xend_parse_sexp_desc_char)
(xenDaemonParseSxprChar, xenDaemonParseSxprDisks)
(xenDaemonParseSxpr, sexpr_to_xend_topology, sexpr_to_domain)
(xenDaemonDomainFetch, xenDaemonDomainGetAutostart)
(xenDaemonDomainSetAutostart, xenDaemonDomainMigratePerform)
(xenDaemonDomainDefineXML, xenDaemonGetSchedulerType)
(xenDaemonGetSchedulerParameters)
(xenDaemonSetSchedulerParameters, xenDaemonDomainBlockPeek)
(xenDaemonFormatSxprChr, virDomainXMLDevID):
* src/xm_internal.c (xenXMConfigCacheRefresh, xenXMDomainPinVcpu)
(xenXMDomainCreate, xenXMDomainDefineXML)
(xenXMDomainAttachDevice, xenXMDomainDetachDevice):
* src/xml.c (virXPathString, virXPathNumber, virXPathLong)
(virXPathULong, virXPathBoolean, virXPathNode, virXPathNodeSet):
* src/xs_internal.c (xenStoreOpen):
2008-10-13 16:46:28 +00:00
|
|
|
"%s", _("no domain with matching uuid"));
|
2008-12-04 21:11:41 +00:00
|
|
|
goto cleanup;
|
2008-08-13 12:50:55 +00:00
|
|
|
}
|
|
|
|
|
2008-12-04 21:11:41 +00:00
|
|
|
ret = strdup(vm->def->os.type);
|
|
|
|
|
|
|
|
cleanup:
|
2008-12-04 21:12:41 +00:00
|
|
|
if (vm)
|
|
|
|
virDomainObjUnlock(vm);
|
2008-12-04 21:11:41 +00:00
|
|
|
return ret;
|
2008-03-21 15:03:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static char *lxcDomainDumpXML(virDomainPtr dom,
|
2008-08-13 12:50:55 +00:00
|
|
|
int flags)
|
2008-03-21 15:03:37 +00:00
|
|
|
{
|
2008-12-04 21:11:41 +00:00
|
|
|
lxc_driver_t *driver = dom->conn->privateData;
|
|
|
|
virDomainObjPtr vm;
|
|
|
|
char *ret = NULL;
|
2008-03-21 15:03:37 +00:00
|
|
|
|
2008-12-04 21:12:41 +00:00
|
|
|
lxcDriverLock(driver);
|
2008-12-04 21:11:41 +00:00
|
|
|
vm = virDomainFindByUUID(&driver->domains, dom->uuid);
|
2008-12-04 21:12:41 +00:00
|
|
|
lxcDriverUnlock(driver);
|
|
|
|
|
2008-03-21 15:03:37 +00:00
|
|
|
if (!vm) {
|
|
|
|
lxcError(dom->conn, dom, VIR_ERR_INVALID_DOMAIN,
|
avoid many format string warnings
Building with --disable-nls exposed many new warnings like these:
virsh.c:4952: warning: format not a string literal and no format ...
util.c:163: warning: format not a string literal and no format arguments
All but one of the following changes add a "%s" argument before
the offending _(...) argument.
This was the only manual change:
* src/lxc_driver.c (lxcVersion): Use %s and strerror(errno)
rather than %m, to avoid a warning from gcc -Wformat-security.
Add "%s" before each warned about format-string-with-no-%-directive:
* src/domain_conf.c (virDomainHostdevSubsysUsbDefParseXML)
(virDomainDefParseString, virDomainDefParseFile):
* src/hash.c (virGetConnect, __virGetDomain, virReleaseDomain)
(__virGetNetwork, virReleaseNetwork, __virGetStoragePool)
(virReleaseStoragePool, __virGetStorageVol, virReleaseStorageVol):
* src/lxc_container.c (lxcContainerChild):
* src/lxc_driver.c (lxcDomainDefine, lxcDomainUndefine)
(lxcDomainGetInfo, lxcGetOSType, lxcDomainDumpXML)
(lxcSetupInterfaces, lxcDomainStart, lxcDomainCreateAndStart)
(lxcVersion, lxcGetSchedulerParameters):
* src/network_conf.c (virNetworkDefParseString)
(virNetworkDefParseFile):
* src/openvz_conf.c (openvzReadNetworkConf, openvzLoadDomains):
* src/openvz_driver.c (openvzDomainDefineCmd)
(openvzDomainGetInfo, openvzDomainDumpXML, openvzDomainShutdown)
(openvzDomainReboot, ADD_ARG_LIT, openvzDomainDefineXML)
(openvzDomainCreateXML, openvzDomainCreate, openvzDomainUndefine)
(openvzDomainSetAutostart, openvzDomainGetAutostart)
(openvzDomainSetVcpus):
* src/qemu_driver.c (qemudDomainBlockPeek, qemudDomainMemoryPeek):
* src/remote_internal.c (remoteDomainBlockPeek)
(remoteDomainMemoryPeek, remoteAuthPolkit):
* src/sexpr.c (sexpr_new, _string2sexpr):
* src/storage_backend_disk.c (virStorageBackendDiskMakeDataVol)
(virStorageBackendDiskCreateVol):
* src/storage_backend_fs.c
(virStorageBackendFileSystemNetFindPoolSources):
* src/storage_backend_logical.c (virStorageBackendLogicalFindLVs)
(virStorageBackendLogicalFindPoolSources):
* src/test.c (testOpenDefault, testOpenFromFile, testOpen)
(testGetDomainInfo, testDomainRestore)
(testNodeGetCellsFreeMemory):
* src/util.c (virExec):
* src/virsh.c (cmdAttachDevice, cmdDetachDevice)
(cmdAttachInterface, cmdDetachInterface, cmdAttachDisk)
(cmdDetachDisk, cmdEdit):
* src/xend_internal.c (do_connect, wr_sync, xend_op_ext)
(urlencode, xenDaemonDomainCreateXML)
(xenDaemonDomainLookupByName_ids, xenDaemonDomainLookupByID)
(xenDaemonParseSxprOS, xend_parse_sexp_desc_char)
(xenDaemonParseSxprChar, xenDaemonParseSxprDisks)
(xenDaemonParseSxpr, sexpr_to_xend_topology, sexpr_to_domain)
(xenDaemonDomainFetch, xenDaemonDomainGetAutostart)
(xenDaemonDomainSetAutostart, xenDaemonDomainMigratePerform)
(xenDaemonDomainDefineXML, xenDaemonGetSchedulerType)
(xenDaemonGetSchedulerParameters)
(xenDaemonSetSchedulerParameters, xenDaemonDomainBlockPeek)
(xenDaemonFormatSxprChr, virDomainXMLDevID):
* src/xm_internal.c (xenXMConfigCacheRefresh, xenXMDomainPinVcpu)
(xenXMDomainCreate, xenXMDomainDefineXML)
(xenXMDomainAttachDevice, xenXMDomainDetachDevice):
* src/xml.c (virXPathString, virXPathNumber, virXPathLong)
(virXPathULong, virXPathBoolean, virXPathNode, virXPathNodeSet):
* src/xs_internal.c (xenStoreOpen):
2008-10-13 16:46:28 +00:00
|
|
|
"%s", _("no domain with matching uuid"));
|
2008-12-04 21:11:41 +00:00
|
|
|
goto cleanup;
|
2008-03-21 15:03:37 +00:00
|
|
|
}
|
|
|
|
|
2008-12-04 21:11:41 +00:00
|
|
|
ret = virDomainDefFormat(dom->conn,
|
|
|
|
(flags & VIR_DOMAIN_XML_INACTIVE) &&
|
|
|
|
vm->newDef ? vm->newDef : vm->def,
|
|
|
|
flags);
|
|
|
|
|
|
|
|
cleanup:
|
2008-12-04 21:12:41 +00:00
|
|
|
if (vm)
|
|
|
|
virDomainObjUnlock(vm);
|
2008-12-04 21:11:41 +00:00
|
|
|
return ret;
|
2008-03-21 15:03:37 +00:00
|
|
|
}
|
|
|
|
|
2008-08-13 10:52:15 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* lxcVmCleanup:
|
|
|
|
* @vm: Ptr to VM to clean up
|
|
|
|
*
|
|
|
|
* waitpid() on the container process. kill and wait the tty process
|
|
|
|
* This is called by both lxcDomainDestroy and lxcSigHandler when a
|
|
|
|
* container exits.
|
|
|
|
*
|
|
|
|
* Returns 0 on success or -1 in case of error
|
|
|
|
*/
|
|
|
|
static int lxcVMCleanup(virConnectPtr conn,
|
|
|
|
lxc_driver_t *driver,
|
2008-08-13 12:50:55 +00:00
|
|
|
virDomainObjPtr vm)
|
2008-08-13 10:52:15 +00:00
|
|
|
{
|
|
|
|
int rc = -1;
|
|
|
|
int waitRc;
|
|
|
|
int childStatus = -1;
|
2008-10-03 16:46:01 +00:00
|
|
|
virCgroupPtr cgroup;
|
2008-10-10 16:08:01 +00:00
|
|
|
int i;
|
2008-08-13 10:52:15 +00:00
|
|
|
|
|
|
|
while (((waitRc = waitpid(vm->pid, &childStatus, 0)) == -1) &&
|
|
|
|
errno == EINTR)
|
|
|
|
; /* empty */
|
|
|
|
|
|
|
|
if ((waitRc != vm->pid) && (errno != ECHILD)) {
|
2009-01-20 17:13:33 +00:00
|
|
|
virReportSystemError(conn, errno,
|
|
|
|
_("waitpid failed to wait for container %d: %d"),
|
|
|
|
vm->pid, waitRc);
|
2008-08-13 10:52:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
rc = 0;
|
|
|
|
|
|
|
|
if (WIFEXITED(childStatus)) {
|
|
|
|
rc = WEXITSTATUS(childStatus);
|
|
|
|
DEBUG("container exited with rc: %d", rc);
|
|
|
|
}
|
|
|
|
|
2008-11-19 16:19:36 +00:00
|
|
|
virEventRemoveHandle(vm->monitorWatch);
|
2008-08-13 10:52:15 +00:00
|
|
|
close(vm->monitor);
|
|
|
|
|
|
|
|
virFileDeletePid(driver->stateDir, vm->def->name);
|
2008-08-20 20:55:32 +00:00
|
|
|
virDomainDeleteConfig(conn, driver->stateDir, NULL, vm);
|
2008-08-13 10:52:15 +00:00
|
|
|
|
|
|
|
vm->state = VIR_DOMAIN_SHUTOFF;
|
|
|
|
vm->pid = -1;
|
|
|
|
vm->def->id = -1;
|
|
|
|
vm->monitor = -1;
|
|
|
|
|
2008-10-10 16:08:01 +00:00
|
|
|
for (i = 0 ; i < vm->def->nnets ; i++) {
|
|
|
|
vethInterfaceUpOrDown(vm->def->nets[i]->ifname, 0);
|
|
|
|
vethDelete(vm->def->nets[i]->ifname);
|
2008-08-22 15:35:37 +00:00
|
|
|
}
|
|
|
|
|
2008-10-03 16:46:01 +00:00
|
|
|
if (virCgroupForDomain(vm->def, "lxc", &cgroup) == 0) {
|
|
|
|
virCgroupRemove(cgroup);
|
|
|
|
virCgroupFree(&cgroup);
|
|
|
|
}
|
|
|
|
|
2008-08-13 10:52:15 +00:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2008-06-26 16:09:48 +00:00
|
|
|
/**
|
|
|
|
* lxcSetupInterfaces:
|
2008-08-13 10:52:15 +00:00
|
|
|
* @def: pointer to virtual machine structure
|
2008-06-26 16:09:48 +00:00
|
|
|
*
|
|
|
|
* Sets up the container interfaces by creating the veth device pairs and
|
|
|
|
* attaching the parent end to the appropriate bridge. The container end
|
|
|
|
* will moved into the container namespace later after clone has been called.
|
|
|
|
*
|
|
|
|
* Returns 0 on success or -1 in case of error
|
|
|
|
*/
|
|
|
|
static int lxcSetupInterfaces(virConnectPtr conn,
|
2008-08-13 12:50:55 +00:00
|
|
|
virDomainDefPtr def,
|
2008-08-13 10:52:15 +00:00
|
|
|
unsigned int *nveths,
|
|
|
|
char ***veths)
|
2008-06-26 16:09:48 +00:00
|
|
|
{
|
2008-10-10 16:08:01 +00:00
|
|
|
int rc = -1, i;
|
2008-08-13 10:52:15 +00:00
|
|
|
char *bridge = NULL;
|
2008-06-26 16:09:48 +00:00
|
|
|
char parentVeth[PATH_MAX] = "";
|
|
|
|
char containerVeth[PATH_MAX] = "";
|
2008-08-13 10:52:15 +00:00
|
|
|
brControl *brctl = NULL;
|
2008-06-26 16:09:48 +00:00
|
|
|
|
2008-08-13 10:52:15 +00:00
|
|
|
if (brInit(&brctl) != 0)
|
2008-06-26 16:09:48 +00:00
|
|
|
return -1;
|
|
|
|
|
2008-10-10 16:08:01 +00:00
|
|
|
for (i = 0 ; i < def->nnets ; i++) {
|
|
|
|
switch (def->nets[i]->type) {
|
2008-08-13 12:50:55 +00:00
|
|
|
case VIR_DOMAIN_NET_TYPE_NETWORK:
|
|
|
|
{
|
|
|
|
virNetworkPtr network = virNetworkLookupByName(conn,
|
2008-10-10 16:08:01 +00:00
|
|
|
def->nets[i]->data.network.name);
|
2008-06-26 16:09:48 +00:00
|
|
|
if (!network) {
|
|
|
|
goto error_exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
bridge = virNetworkGetBridgeName(network);
|
|
|
|
|
|
|
|
virNetworkFree(network);
|
2008-08-13 12:50:55 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case VIR_DOMAIN_NET_TYPE_BRIDGE:
|
2008-10-10 16:08:01 +00:00
|
|
|
bridge = def->nets[i]->data.bridge.brname;
|
2008-08-13 12:50:55 +00:00
|
|
|
break;
|
2008-06-26 16:09:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DEBUG("bridge: %s", bridge);
|
|
|
|
if (NULL == bridge) {
|
|
|
|
lxcError(conn, NULL, VIR_ERR_INTERNAL_ERROR,
|
avoid many format string warnings
Building with --disable-nls exposed many new warnings like these:
virsh.c:4952: warning: format not a string literal and no format ...
util.c:163: warning: format not a string literal and no format arguments
All but one of the following changes add a "%s" argument before
the offending _(...) argument.
This was the only manual change:
* src/lxc_driver.c (lxcVersion): Use %s and strerror(errno)
rather than %m, to avoid a warning from gcc -Wformat-security.
Add "%s" before each warned about format-string-with-no-%-directive:
* src/domain_conf.c (virDomainHostdevSubsysUsbDefParseXML)
(virDomainDefParseString, virDomainDefParseFile):
* src/hash.c (virGetConnect, __virGetDomain, virReleaseDomain)
(__virGetNetwork, virReleaseNetwork, __virGetStoragePool)
(virReleaseStoragePool, __virGetStorageVol, virReleaseStorageVol):
* src/lxc_container.c (lxcContainerChild):
* src/lxc_driver.c (lxcDomainDefine, lxcDomainUndefine)
(lxcDomainGetInfo, lxcGetOSType, lxcDomainDumpXML)
(lxcSetupInterfaces, lxcDomainStart, lxcDomainCreateAndStart)
(lxcVersion, lxcGetSchedulerParameters):
* src/network_conf.c (virNetworkDefParseString)
(virNetworkDefParseFile):
* src/openvz_conf.c (openvzReadNetworkConf, openvzLoadDomains):
* src/openvz_driver.c (openvzDomainDefineCmd)
(openvzDomainGetInfo, openvzDomainDumpXML, openvzDomainShutdown)
(openvzDomainReboot, ADD_ARG_LIT, openvzDomainDefineXML)
(openvzDomainCreateXML, openvzDomainCreate, openvzDomainUndefine)
(openvzDomainSetAutostart, openvzDomainGetAutostart)
(openvzDomainSetVcpus):
* src/qemu_driver.c (qemudDomainBlockPeek, qemudDomainMemoryPeek):
* src/remote_internal.c (remoteDomainBlockPeek)
(remoteDomainMemoryPeek, remoteAuthPolkit):
* src/sexpr.c (sexpr_new, _string2sexpr):
* src/storage_backend_disk.c (virStorageBackendDiskMakeDataVol)
(virStorageBackendDiskCreateVol):
* src/storage_backend_fs.c
(virStorageBackendFileSystemNetFindPoolSources):
* src/storage_backend_logical.c (virStorageBackendLogicalFindLVs)
(virStorageBackendLogicalFindPoolSources):
* src/test.c (testOpenDefault, testOpenFromFile, testOpen)
(testGetDomainInfo, testDomainRestore)
(testNodeGetCellsFreeMemory):
* src/util.c (virExec):
* src/virsh.c (cmdAttachDevice, cmdDetachDevice)
(cmdAttachInterface, cmdDetachInterface, cmdAttachDisk)
(cmdDetachDisk, cmdEdit):
* src/xend_internal.c (do_connect, wr_sync, xend_op_ext)
(urlencode, xenDaemonDomainCreateXML)
(xenDaemonDomainLookupByName_ids, xenDaemonDomainLookupByID)
(xenDaemonParseSxprOS, xend_parse_sexp_desc_char)
(xenDaemonParseSxprChar, xenDaemonParseSxprDisks)
(xenDaemonParseSxpr, sexpr_to_xend_topology, sexpr_to_domain)
(xenDaemonDomainFetch, xenDaemonDomainGetAutostart)
(xenDaemonDomainSetAutostart, xenDaemonDomainMigratePerform)
(xenDaemonDomainDefineXML, xenDaemonGetSchedulerType)
(xenDaemonGetSchedulerParameters)
(xenDaemonSetSchedulerParameters, xenDaemonDomainBlockPeek)
(xenDaemonFormatSxprChr, virDomainXMLDevID):
* src/xm_internal.c (xenXMConfigCacheRefresh, xenXMDomainPinVcpu)
(xenXMDomainCreate, xenXMDomainDefineXML)
(xenXMDomainAttachDevice, xenXMDomainDetachDevice):
* src/xml.c (virXPathString, virXPathNumber, virXPathLong)
(virXPathULong, virXPathBoolean, virXPathNode, virXPathNodeSet):
* src/xs_internal.c (xenStoreOpen):
2008-10-13 16:46:28 +00:00
|
|
|
"%s", _("failed to get bridge for interface"));
|
2008-06-26 16:09:48 +00:00
|
|
|
goto error_exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
DEBUG0("calling vethCreate()");
|
2008-10-10 16:08:01 +00:00
|
|
|
if (NULL != def->nets[i]->ifname) {
|
|
|
|
strcpy(parentVeth, def->nets[i]->ifname);
|
2008-06-26 16:09:48 +00:00
|
|
|
}
|
|
|
|
DEBUG("parentVeth: %s, containerVeth: %s", parentVeth, containerVeth);
|
|
|
|
if (0 != (rc = vethCreate(parentVeth, PATH_MAX, containerVeth, PATH_MAX))) {
|
|
|
|
lxcError(conn, NULL, VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("failed to create veth device pair: %d"), rc);
|
|
|
|
goto error_exit;
|
|
|
|
}
|
2008-10-10 16:08:01 +00:00
|
|
|
if (NULL == def->nets[i]->ifname) {
|
|
|
|
def->nets[i]->ifname = strdup(parentVeth);
|
2008-06-26 16:09:48 +00:00
|
|
|
}
|
2008-08-13 10:52:15 +00:00
|
|
|
if (VIR_REALLOC_N(*veths, (*nveths)+1) < 0)
|
|
|
|
goto error_exit;
|
|
|
|
if (((*veths)[(*nveths)++] = strdup(containerVeth)) == NULL)
|
2008-06-26 16:09:48 +00:00
|
|
|
goto error_exit;
|
|
|
|
|
2008-10-10 16:08:01 +00:00
|
|
|
if (NULL == def->nets[i]->ifname) {
|
2008-08-13 10:52:15 +00:00
|
|
|
lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
avoid many format string warnings
Building with --disable-nls exposed many new warnings like these:
virsh.c:4952: warning: format not a string literal and no format ...
util.c:163: warning: format not a string literal and no format arguments
All but one of the following changes add a "%s" argument before
the offending _(...) argument.
This was the only manual change:
* src/lxc_driver.c (lxcVersion): Use %s and strerror(errno)
rather than %m, to avoid a warning from gcc -Wformat-security.
Add "%s" before each warned about format-string-with-no-%-directive:
* src/domain_conf.c (virDomainHostdevSubsysUsbDefParseXML)
(virDomainDefParseString, virDomainDefParseFile):
* src/hash.c (virGetConnect, __virGetDomain, virReleaseDomain)
(__virGetNetwork, virReleaseNetwork, __virGetStoragePool)
(virReleaseStoragePool, __virGetStorageVol, virReleaseStorageVol):
* src/lxc_container.c (lxcContainerChild):
* src/lxc_driver.c (lxcDomainDefine, lxcDomainUndefine)
(lxcDomainGetInfo, lxcGetOSType, lxcDomainDumpXML)
(lxcSetupInterfaces, lxcDomainStart, lxcDomainCreateAndStart)
(lxcVersion, lxcGetSchedulerParameters):
* src/network_conf.c (virNetworkDefParseString)
(virNetworkDefParseFile):
* src/openvz_conf.c (openvzReadNetworkConf, openvzLoadDomains):
* src/openvz_driver.c (openvzDomainDefineCmd)
(openvzDomainGetInfo, openvzDomainDumpXML, openvzDomainShutdown)
(openvzDomainReboot, ADD_ARG_LIT, openvzDomainDefineXML)
(openvzDomainCreateXML, openvzDomainCreate, openvzDomainUndefine)
(openvzDomainSetAutostart, openvzDomainGetAutostart)
(openvzDomainSetVcpus):
* src/qemu_driver.c (qemudDomainBlockPeek, qemudDomainMemoryPeek):
* src/remote_internal.c (remoteDomainBlockPeek)
(remoteDomainMemoryPeek, remoteAuthPolkit):
* src/sexpr.c (sexpr_new, _string2sexpr):
* src/storage_backend_disk.c (virStorageBackendDiskMakeDataVol)
(virStorageBackendDiskCreateVol):
* src/storage_backend_fs.c
(virStorageBackendFileSystemNetFindPoolSources):
* src/storage_backend_logical.c (virStorageBackendLogicalFindLVs)
(virStorageBackendLogicalFindPoolSources):
* src/test.c (testOpenDefault, testOpenFromFile, testOpen)
(testGetDomainInfo, testDomainRestore)
(testNodeGetCellsFreeMemory):
* src/util.c (virExec):
* src/virsh.c (cmdAttachDevice, cmdDetachDevice)
(cmdAttachInterface, cmdDetachInterface, cmdAttachDisk)
(cmdDetachDisk, cmdEdit):
* src/xend_internal.c (do_connect, wr_sync, xend_op_ext)
(urlencode, xenDaemonDomainCreateXML)
(xenDaemonDomainLookupByName_ids, xenDaemonDomainLookupByID)
(xenDaemonParseSxprOS, xend_parse_sexp_desc_char)
(xenDaemonParseSxprChar, xenDaemonParseSxprDisks)
(xenDaemonParseSxpr, sexpr_to_xend_topology, sexpr_to_domain)
(xenDaemonDomainFetch, xenDaemonDomainGetAutostart)
(xenDaemonDomainSetAutostart, xenDaemonDomainMigratePerform)
(xenDaemonDomainDefineXML, xenDaemonGetSchedulerType)
(xenDaemonGetSchedulerParameters)
(xenDaemonSetSchedulerParameters, xenDaemonDomainBlockPeek)
(xenDaemonFormatSxprChr, virDomainXMLDevID):
* src/xm_internal.c (xenXMConfigCacheRefresh, xenXMDomainPinVcpu)
(xenXMDomainCreate, xenXMDomainDefineXML)
(xenXMDomainAttachDevice, xenXMDomainDetachDevice):
* src/xml.c (virXPathString, virXPathNumber, virXPathLong)
(virXPathULong, virXPathBoolean, virXPathNode, virXPathNodeSet):
* src/xs_internal.c (xenStoreOpen):
2008-10-13 16:46:28 +00:00
|
|
|
"%s", _("failed to allocate veth names"));
|
2008-06-26 16:09:48 +00:00
|
|
|
goto error_exit;
|
|
|
|
}
|
|
|
|
|
2008-08-13 10:52:15 +00:00
|
|
|
if (0 != (rc = brAddInterface(brctl, bridge, parentVeth))) {
|
2009-01-20 17:13:33 +00:00
|
|
|
virReportSystemError(conn, rc,
|
|
|
|
_("failed to add %s device to %s"),
|
|
|
|
parentVeth, bridge);
|
2008-06-26 16:09:48 +00:00
|
|
|
goto error_exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (0 != (rc = vethInterfaceUpOrDown(parentVeth, 1))) {
|
2009-01-20 17:13:33 +00:00
|
|
|
virReportSystemError(conn, rc, "%s",
|
|
|
|
_("failed to enable parent ns veth device"));
|
2008-06-26 16:09:48 +00:00
|
|
|
goto error_exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = 0;
|
|
|
|
|
|
|
|
error_exit:
|
2008-08-13 10:52:15 +00:00
|
|
|
brShutdown(brctl);
|
2008-06-26 16:09:48 +00:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2008-04-10 07:30:52 +00:00
|
|
|
|
2008-08-13 10:52:15 +00:00
|
|
|
static int lxcMonitorClient(virConnectPtr conn,
|
|
|
|
lxc_driver_t * driver,
|
2008-08-13 12:50:55 +00:00
|
|
|
virDomainObjPtr vm)
|
2008-04-10 07:30:52 +00:00
|
|
|
{
|
2008-08-13 10:52:15 +00:00
|
|
|
char *sockpath = NULL;
|
|
|
|
int fd;
|
|
|
|
struct sockaddr_un addr;
|
2008-04-10 07:30:52 +00:00
|
|
|
|
2008-12-23 13:03:29 +00:00
|
|
|
if (virAsprintf(&sockpath, "%s/%s.sock",
|
|
|
|
driver->stateDir, vm->def->name) < 0) {
|
2009-01-29 12:10:32 +00:00
|
|
|
virReportOOMError(conn);
|
2008-08-13 10:52:15 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((fd = socket(PF_UNIX, SOCK_STREAM, 0)) < 0) {
|
2009-01-20 17:13:33 +00:00
|
|
|
virReportSystemError(conn, errno, "%s",
|
|
|
|
_("failed to create client socket"));
|
2008-08-13 10:52:15 +00:00
|
|
|
goto error;
|
2008-04-10 07:30:52 +00:00
|
|
|
}
|
|
|
|
|
2008-08-13 10:52:15 +00:00
|
|
|
memset(&addr, 0, sizeof(addr));
|
|
|
|
addr.sun_family = AF_UNIX;
|
|
|
|
strncpy(addr.sun_path, sockpath, sizeof(addr.sun_path));
|
|
|
|
|
|
|
|
if (connect(fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
|
2009-01-20 17:13:33 +00:00
|
|
|
virReportSystemError(conn, errno, "%s",
|
|
|
|
_("failed to connect to client socket"));
|
2008-08-13 10:52:15 +00:00
|
|
|
goto error;
|
2008-04-10 07:30:52 +00:00
|
|
|
}
|
|
|
|
|
2008-08-13 10:52:15 +00:00
|
|
|
VIR_FREE(sockpath);
|
|
|
|
return fd;
|
2008-04-10 07:30:52 +00:00
|
|
|
|
2008-08-13 10:52:15 +00:00
|
|
|
error:
|
|
|
|
VIR_FREE(sockpath);
|
|
|
|
if (fd != -1)
|
|
|
|
close(fd);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int lxcVmTerminate(virConnectPtr conn,
|
|
|
|
lxc_driver_t *driver,
|
2008-08-13 12:50:55 +00:00
|
|
|
virDomainObjPtr vm,
|
2008-08-13 10:52:15 +00:00
|
|
|
int signum)
|
|
|
|
{
|
|
|
|
if (signum == 0)
|
|
|
|
signum = SIGINT;
|
2008-08-13 10:14:47 +00:00
|
|
|
|
2008-08-20 20:55:32 +00:00
|
|
|
if (vm->pid <= 0) {
|
|
|
|
lxcError(conn, NULL, VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("invalid PID %d for container"), vm->pid);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2008-08-13 10:52:15 +00:00
|
|
|
if (kill(vm->pid, signum) < 0) {
|
|
|
|
if (errno != ESRCH) {
|
2009-01-20 17:13:33 +00:00
|
|
|
virReportSystemError(conn, errno,
|
|
|
|
_("failed to kill pid %d"),
|
|
|
|
vm->pid);
|
2008-08-13 10:52:15 +00:00
|
|
|
return -1;
|
2008-08-13 10:14:47 +00:00
|
|
|
}
|
2008-04-10 07:30:52 +00:00
|
|
|
}
|
|
|
|
|
2008-08-13 10:52:15 +00:00
|
|
|
vm->state = VIR_DOMAIN_SHUTDOWN;
|
2008-08-13 10:14:47 +00:00
|
|
|
|
2008-08-13 10:52:15 +00:00
|
|
|
return lxcVMCleanup(conn, driver, vm);
|
|
|
|
}
|
2008-04-10 07:30:52 +00:00
|
|
|
|
2008-11-19 16:19:36 +00:00
|
|
|
static void lxcMonitorEvent(int watch,
|
|
|
|
int fd,
|
2008-08-13 10:52:15 +00:00
|
|
|
int events ATTRIBUTE_UNUSED,
|
|
|
|
void *data)
|
|
|
|
{
|
|
|
|
lxc_driver_t *driver = data;
|
2008-10-10 14:20:37 +00:00
|
|
|
virDomainObjPtr vm = NULL;
|
|
|
|
unsigned int i;
|
2008-04-10 07:30:52 +00:00
|
|
|
|
2008-12-04 21:12:41 +00:00
|
|
|
lxcDriverLock(driver);
|
2008-10-10 14:20:37 +00:00
|
|
|
for (i = 0 ; i < driver->domains.count ; i++) {
|
2008-12-04 21:12:41 +00:00
|
|
|
virDomainObjPtr tmpvm = driver->domains.objs[i];
|
|
|
|
virDomainObjLock(tmpvm);
|
|
|
|
if (tmpvm->monitorWatch == watch) {
|
|
|
|
vm = tmpvm;
|
2008-08-13 10:52:15 +00:00
|
|
|
break;
|
2008-10-10 14:20:37 +00:00
|
|
|
}
|
2008-12-04 21:12:41 +00:00
|
|
|
virDomainObjUnlock(tmpvm);
|
2008-08-13 10:52:15 +00:00
|
|
|
}
|
|
|
|
if (!vm) {
|
2008-11-19 16:19:36 +00:00
|
|
|
virEventRemoveHandle(watch);
|
2008-12-04 21:12:41 +00:00
|
|
|
goto cleanup;
|
2008-11-19 16:19:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (vm->monitor != fd) {
|
|
|
|
virEventRemoveHandle(watch);
|
2008-12-04 21:12:41 +00:00
|
|
|
goto cleanup;
|
2008-04-10 07:30:52 +00:00
|
|
|
}
|
|
|
|
|
2008-08-13 10:52:15 +00:00
|
|
|
if (lxcVmTerminate(NULL, driver, vm, SIGINT) < 0)
|
2008-11-19 16:19:36 +00:00
|
|
|
virEventRemoveHandle(watch);
|
2008-12-04 21:12:41 +00:00
|
|
|
|
|
|
|
cleanup:
|
|
|
|
if (vm)
|
|
|
|
virDomainObjUnlock(vm);
|
|
|
|
lxcDriverUnlock(driver);
|
2008-04-10 07:30:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-08-20 20:55:32 +00:00
|
|
|
static int lxcControllerStart(virConnectPtr conn,
|
|
|
|
virDomainObjPtr vm,
|
|
|
|
int nveths,
|
|
|
|
char **veths,
|
|
|
|
int appPty,
|
|
|
|
int logfd)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int rc;
|
|
|
|
int ret = -1;
|
|
|
|
int largc = 0, larga = 0;
|
|
|
|
const char **largv = NULL;
|
|
|
|
pid_t child;
|
|
|
|
int status;
|
2008-08-27 11:42:52 +00:00
|
|
|
fd_set keepfd;
|
|
|
|
char appPtyStr[30];
|
2008-09-05 11:52:12 +00:00
|
|
|
const char *emulator;
|
|
|
|
lxc_driver_t *driver = conn->privateData;
|
2008-08-27 11:42:52 +00:00
|
|
|
|
|
|
|
FD_ZERO(&keepfd);
|
2008-08-20 20:55:32 +00:00
|
|
|
|
|
|
|
#define ADD_ARG_SPACE \
|
|
|
|
do { \
|
|
|
|
if (largc == larga) { \
|
|
|
|
larga += 10; \
|
|
|
|
if (VIR_REALLOC_N(largv, larga) < 0) \
|
|
|
|
goto no_memory; \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define ADD_ARG(thisarg) \
|
|
|
|
do { \
|
|
|
|
ADD_ARG_SPACE; \
|
|
|
|
largv[largc++] = thisarg; \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define ADD_ARG_LIT(thisarg) \
|
|
|
|
do { \
|
|
|
|
ADD_ARG_SPACE; \
|
|
|
|
if ((largv[largc++] = strdup(thisarg)) == NULL) \
|
|
|
|
goto no_memory; \
|
|
|
|
} while (0)
|
|
|
|
|
2008-08-27 11:42:52 +00:00
|
|
|
snprintf(appPtyStr, sizeof(appPtyStr), "%d", appPty);
|
|
|
|
|
2008-09-05 11:52:12 +00:00
|
|
|
emulator = vm->def->emulator;
|
|
|
|
if (!emulator)
|
|
|
|
emulator = virDomainDefDefaultEmulator(conn, vm->def, driver->caps);
|
|
|
|
if (!emulator)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
ADD_ARG_LIT(emulator);
|
2008-08-20 20:55:32 +00:00
|
|
|
ADD_ARG_LIT("--name");
|
|
|
|
ADD_ARG_LIT(vm->def->name);
|
|
|
|
ADD_ARG_LIT("--console");
|
2008-08-27 11:42:52 +00:00
|
|
|
ADD_ARG_LIT(appPtyStr);
|
2008-08-20 20:55:32 +00:00
|
|
|
ADD_ARG_LIT("--background");
|
|
|
|
|
|
|
|
for (i = 0 ; i < nveths ; i++) {
|
|
|
|
ADD_ARG_LIT("--veth");
|
|
|
|
ADD_ARG_LIT(veths[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
ADD_ARG(NULL);
|
|
|
|
|
2008-08-27 11:42:52 +00:00
|
|
|
vm->stdin_fd = -1;
|
|
|
|
FD_SET(appPty, &keepfd);
|
|
|
|
|
|
|
|
if (virExec(conn, largv, NULL, &keepfd, &child,
|
2009-01-20 16:10:20 +00:00
|
|
|
vm->stdin_fd, &logfd, &logfd,
|
2008-08-20 20:55:32 +00:00
|
|
|
VIR_EXEC_NONE) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
/* We now wait for the process to exit - the controller
|
|
|
|
* will fork() itself into the background - waiting for
|
|
|
|
* it to exit thus guarentees it has written its pidfile
|
|
|
|
*/
|
|
|
|
while ((rc = waitpid(child, &status, 0) == -1) && errno == EINTR);
|
|
|
|
if (rc == -1) {
|
2009-01-20 17:13:33 +00:00
|
|
|
virReportSystemError(conn, errno,
|
|
|
|
_("cannot wait for '%s'"),
|
|
|
|
largv[0]);
|
2008-08-20 20:55:32 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(WIFEXITED(status) && WEXITSTATUS(status) == 0)) {
|
|
|
|
lxcError(conn, NULL, VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("container '%s' unexpectedly shutdown during startup"),
|
|
|
|
largv[0]);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef ADD_ARG
|
|
|
|
#undef ADD_ARG_LIT
|
|
|
|
#undef ADD_ARG_SPACE
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
for (i = 0 ; i < largc ; i++)
|
|
|
|
VIR_FREE(largv[i]);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
no_memory:
|
2009-01-29 12:10:32 +00:00
|
|
|
virReportOOMError(conn);
|
2008-08-20 20:55:32 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-04-10 07:30:52 +00:00
|
|
|
/**
|
|
|
|
* lxcVmStart:
|
|
|
|
* @conn: pointer to connection
|
|
|
|
* @driver: pointer to driver structure
|
|
|
|
* @vm: pointer to virtual machine structure
|
|
|
|
*
|
|
|
|
* Starts a vm
|
|
|
|
*
|
|
|
|
* Returns 0 on success or -1 in case of error
|
|
|
|
*/
|
|
|
|
static int lxcVmStart(virConnectPtr conn,
|
|
|
|
lxc_driver_t * driver,
|
2008-08-13 12:50:55 +00:00
|
|
|
virDomainObjPtr vm)
|
2008-04-10 07:30:52 +00:00
|
|
|
{
|
|
|
|
int rc = -1;
|
2008-08-13 10:52:15 +00:00
|
|
|
unsigned int i;
|
|
|
|
int parentTty;
|
2008-08-13 12:50:55 +00:00
|
|
|
char *parentTtyPath = NULL;
|
2008-08-13 10:52:15 +00:00
|
|
|
char *logfile = NULL;
|
|
|
|
int logfd = -1;
|
|
|
|
unsigned int nveths = 0;
|
|
|
|
char **veths = NULL;
|
|
|
|
|
2009-01-20 17:13:33 +00:00
|
|
|
if ((rc = virFileMakePath(driver->logDir)) < 0) {
|
|
|
|
virReportSystemError(conn, rc,
|
|
|
|
_("cannot create log directory '%s'"),
|
|
|
|
driver->logDir);
|
2008-08-13 10:52:15 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2008-04-10 07:30:52 +00:00
|
|
|
|
2008-12-23 13:03:29 +00:00
|
|
|
if (virAsprintf(&logfile, "%s/%s.log",
|
|
|
|
driver->logDir, vm->def->name) < 0) {
|
2009-01-29 12:10:32 +00:00
|
|
|
virReportOOMError(conn);
|
2008-08-13 10:52:15 +00:00
|
|
|
return -1;
|
2008-04-10 07:30:52 +00:00
|
|
|
}
|
|
|
|
|
2008-08-13 10:52:15 +00:00
|
|
|
/* open parent tty */
|
2008-08-13 12:50:55 +00:00
|
|
|
if (virFileOpenTty(&parentTty, &parentTtyPath, 1) < 0) {
|
2009-01-20 17:13:33 +00:00
|
|
|
virReportSystemError(conn, errno, "%s",
|
|
|
|
_("failed to allocate tty"));
|
2008-04-10 07:30:52 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
2008-08-13 12:50:55 +00:00
|
|
|
if (vm->def->console &&
|
|
|
|
vm->def->console->type == VIR_DOMAIN_CHR_TYPE_PTY) {
|
|
|
|
VIR_FREE(vm->def->console->data.file.path);
|
|
|
|
vm->def->console->data.file.path = parentTtyPath;
|
|
|
|
} else {
|
|
|
|
VIR_FREE(parentTtyPath);
|
|
|
|
}
|
2008-04-10 07:30:52 +00:00
|
|
|
|
2008-08-13 10:52:15 +00:00
|
|
|
if (lxcSetupInterfaces(conn, vm->def, &nveths, &veths) != 0)
|
2008-06-26 16:09:48 +00:00
|
|
|
goto cleanup;
|
2008-04-10 07:30:52 +00:00
|
|
|
|
2008-08-20 20:55:32 +00:00
|
|
|
/* Persist the live configuration now we have veth & tty info */
|
|
|
|
if (virDomainSaveConfig(conn, driver->stateDir, vm->def) < 0) {
|
|
|
|
rc = -1;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2008-08-13 10:52:15 +00:00
|
|
|
if ((logfd = open(logfile, O_WRONLY | O_TRUNC | O_CREAT,
|
|
|
|
S_IRUSR|S_IWUSR)) < 0) {
|
2009-01-20 17:13:33 +00:00
|
|
|
virReportSystemError(conn, errno,
|
|
|
|
_("failed to open '%s'"),
|
|
|
|
logfile);
|
2008-06-26 16:09:48 +00:00
|
|
|
goto cleanup;
|
2008-04-10 07:30:52 +00:00
|
|
|
}
|
|
|
|
|
2008-08-20 20:55:32 +00:00
|
|
|
if (lxcControllerStart(conn,
|
|
|
|
vm,
|
|
|
|
nveths, veths,
|
|
|
|
parentTty, logfd) < 0)
|
2008-06-26 16:09:48 +00:00
|
|
|
goto cleanup;
|
2008-08-13 10:52:15 +00:00
|
|
|
|
|
|
|
/* Connect to the controller as a client *first* because
|
|
|
|
* this will block until the child has written their
|
|
|
|
* pid file out to disk */
|
|
|
|
if ((vm->monitor = lxcMonitorClient(conn, driver, vm)) < 0)
|
2008-06-26 16:09:48 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2008-08-13 10:52:15 +00:00
|
|
|
/* And get its pid */
|
|
|
|
if ((rc = virFileReadPid(driver->stateDir, vm->def->name, &vm->pid)) != 0) {
|
2009-01-20 17:13:33 +00:00
|
|
|
virReportSystemError(conn, rc,
|
|
|
|
_("Failed to read pid file %s/%s.pid"),
|
|
|
|
driver->stateDir, vm->def->name);
|
2008-08-13 10:52:15 +00:00
|
|
|
rc = -1;
|
2008-06-26 16:09:48 +00:00
|
|
|
goto cleanup;
|
2008-08-13 10:52:15 +00:00
|
|
|
}
|
2008-06-26 16:09:48 +00:00
|
|
|
|
2008-08-13 10:52:15 +00:00
|
|
|
vm->def->id = vm->pid;
|
2008-06-26 16:09:48 +00:00
|
|
|
vm->state = VIR_DOMAIN_RUNNING;
|
|
|
|
|
2008-11-19 16:19:36 +00:00
|
|
|
if ((vm->monitorWatch = virEventAddHandle(
|
|
|
|
vm->monitor,
|
|
|
|
VIR_EVENT_HANDLE_ERROR | VIR_EVENT_HANDLE_HANGUP,
|
|
|
|
lxcMonitorEvent,
|
2008-11-19 16:24:01 +00:00
|
|
|
driver, NULL)) < 0) {
|
2008-08-13 10:52:15 +00:00
|
|
|
lxcVmTerminate(conn, driver, vm, 0);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2008-06-26 16:09:48 +00:00
|
|
|
|
2008-08-13 10:52:15 +00:00
|
|
|
rc = 0;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
for (i = 0 ; i < nveths ; i++) {
|
|
|
|
if (rc != 0)
|
|
|
|
vethDelete(veths[i]);
|
|
|
|
VIR_FREE(veths[i]);
|
|
|
|
}
|
|
|
|
if (rc != 0 && vm->monitor != -1) {
|
|
|
|
close(vm->monitor);
|
|
|
|
vm->monitor = -1;
|
|
|
|
}
|
|
|
|
if (parentTty != -1)
|
|
|
|
close(parentTty);
|
|
|
|
if (logfd != -1)
|
|
|
|
close(logfd);
|
|
|
|
VIR_FREE(logfile);
|
2008-04-10 07:30:52 +00:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* lxcDomainStart:
|
|
|
|
* @dom: domain to start
|
|
|
|
*
|
|
|
|
* Looks up domain and starts it.
|
|
|
|
*
|
|
|
|
* Returns 0 on success or -1 in case of error
|
|
|
|
*/
|
|
|
|
static int lxcDomainStart(virDomainPtr dom)
|
|
|
|
{
|
2008-12-04 21:11:41 +00:00
|
|
|
lxc_driver_t *driver = dom->conn->privateData;
|
|
|
|
virDomainObjPtr vm;
|
|
|
|
int ret = -1;
|
2008-04-10 07:30:52 +00:00
|
|
|
|
2008-12-04 21:12:41 +00:00
|
|
|
lxcDriverLock(driver);
|
2008-12-04 21:11:41 +00:00
|
|
|
vm = virDomainFindByName(&driver->domains, dom->name);
|
2008-04-10 07:30:52 +00:00
|
|
|
if (!vm) {
|
2008-12-04 21:11:41 +00:00
|
|
|
lxcError(dom->conn, dom, VIR_ERR_INVALID_DOMAIN,
|
2008-11-07 16:43:58 +00:00
|
|
|
_("no domain named %s"), dom->name);
|
2008-04-10 07:30:52 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2008-08-13 12:50:55 +00:00
|
|
|
if ((vm->def->nets != NULL) && !(driver->have_netns)) {
|
2008-12-04 21:11:41 +00:00
|
|
|
lxcError(dom->conn, NULL, VIR_ERR_NO_SUPPORT,
|
avoid many format string warnings
Building with --disable-nls exposed many new warnings like these:
virsh.c:4952: warning: format not a string literal and no format ...
util.c:163: warning: format not a string literal and no format arguments
All but one of the following changes add a "%s" argument before
the offending _(...) argument.
This was the only manual change:
* src/lxc_driver.c (lxcVersion): Use %s and strerror(errno)
rather than %m, to avoid a warning from gcc -Wformat-security.
Add "%s" before each warned about format-string-with-no-%-directive:
* src/domain_conf.c (virDomainHostdevSubsysUsbDefParseXML)
(virDomainDefParseString, virDomainDefParseFile):
* src/hash.c (virGetConnect, __virGetDomain, virReleaseDomain)
(__virGetNetwork, virReleaseNetwork, __virGetStoragePool)
(virReleaseStoragePool, __virGetStorageVol, virReleaseStorageVol):
* src/lxc_container.c (lxcContainerChild):
* src/lxc_driver.c (lxcDomainDefine, lxcDomainUndefine)
(lxcDomainGetInfo, lxcGetOSType, lxcDomainDumpXML)
(lxcSetupInterfaces, lxcDomainStart, lxcDomainCreateAndStart)
(lxcVersion, lxcGetSchedulerParameters):
* src/network_conf.c (virNetworkDefParseString)
(virNetworkDefParseFile):
* src/openvz_conf.c (openvzReadNetworkConf, openvzLoadDomains):
* src/openvz_driver.c (openvzDomainDefineCmd)
(openvzDomainGetInfo, openvzDomainDumpXML, openvzDomainShutdown)
(openvzDomainReboot, ADD_ARG_LIT, openvzDomainDefineXML)
(openvzDomainCreateXML, openvzDomainCreate, openvzDomainUndefine)
(openvzDomainSetAutostart, openvzDomainGetAutostart)
(openvzDomainSetVcpus):
* src/qemu_driver.c (qemudDomainBlockPeek, qemudDomainMemoryPeek):
* src/remote_internal.c (remoteDomainBlockPeek)
(remoteDomainMemoryPeek, remoteAuthPolkit):
* src/sexpr.c (sexpr_new, _string2sexpr):
* src/storage_backend_disk.c (virStorageBackendDiskMakeDataVol)
(virStorageBackendDiskCreateVol):
* src/storage_backend_fs.c
(virStorageBackendFileSystemNetFindPoolSources):
* src/storage_backend_logical.c (virStorageBackendLogicalFindLVs)
(virStorageBackendLogicalFindPoolSources):
* src/test.c (testOpenDefault, testOpenFromFile, testOpen)
(testGetDomainInfo, testDomainRestore)
(testNodeGetCellsFreeMemory):
* src/util.c (virExec):
* src/virsh.c (cmdAttachDevice, cmdDetachDevice)
(cmdAttachInterface, cmdDetachInterface, cmdAttachDisk)
(cmdDetachDisk, cmdEdit):
* src/xend_internal.c (do_connect, wr_sync, xend_op_ext)
(urlencode, xenDaemonDomainCreateXML)
(xenDaemonDomainLookupByName_ids, xenDaemonDomainLookupByID)
(xenDaemonParseSxprOS, xend_parse_sexp_desc_char)
(xenDaemonParseSxprChar, xenDaemonParseSxprDisks)
(xenDaemonParseSxpr, sexpr_to_xend_topology, sexpr_to_domain)
(xenDaemonDomainFetch, xenDaemonDomainGetAutostart)
(xenDaemonDomainSetAutostart, xenDaemonDomainMigratePerform)
(xenDaemonDomainDefineXML, xenDaemonGetSchedulerType)
(xenDaemonGetSchedulerParameters)
(xenDaemonSetSchedulerParameters, xenDaemonDomainBlockPeek)
(xenDaemonFormatSxprChr, virDomainXMLDevID):
* src/xm_internal.c (xenXMConfigCacheRefresh, xenXMDomainPinVcpu)
(xenXMDomainCreate, xenXMDomainDefineXML)
(xenXMDomainAttachDevice, xenXMDomainDetachDevice):
* src/xml.c (virXPathString, virXPathNumber, virXPathLong)
(virXPathULong, virXPathBoolean, virXPathNode, virXPathNodeSet):
* src/xs_internal.c (xenStoreOpen):
2008-10-13 16:46:28 +00:00
|
|
|
"%s", _("System lacks NETNS support"));
|
2008-08-13 12:50:55 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2008-12-04 21:11:41 +00:00
|
|
|
ret = lxcVmStart(dom->conn, driver, vm);
|
2008-04-10 07:30:52 +00:00
|
|
|
|
|
|
|
cleanup:
|
2008-12-04 21:12:41 +00:00
|
|
|
if (vm)
|
|
|
|
virDomainObjUnlock(vm);
|
|
|
|
lxcDriverUnlock(driver);
|
2008-12-04 21:11:41 +00:00
|
|
|
return ret;
|
2008-04-10 07:30:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* lxcDomainCreateAndStart:
|
|
|
|
* @conn: pointer to connection
|
|
|
|
* @xml: XML definition of domain
|
|
|
|
* @flags: Unused
|
|
|
|
*
|
|
|
|
* Creates a domain based on xml and starts it
|
|
|
|
*
|
|
|
|
* Returns 0 on success or -1 in case of error
|
|
|
|
*/
|
|
|
|
static virDomainPtr
|
|
|
|
lxcDomainCreateAndStart(virConnectPtr conn,
|
|
|
|
const char *xml,
|
|
|
|
unsigned int flags ATTRIBUTE_UNUSED) {
|
2008-12-04 21:11:41 +00:00
|
|
|
lxc_driver_t *driver = conn->privateData;
|
2008-12-04 21:12:41 +00:00
|
|
|
virDomainObjPtr vm = NULL;
|
2008-08-13 12:50:55 +00:00
|
|
|
virDomainDefPtr def;
|
2008-04-10 07:30:52 +00:00
|
|
|
virDomainPtr dom = NULL;
|
|
|
|
|
2008-12-04 21:12:41 +00:00
|
|
|
lxcDriverLock(driver);
|
2009-01-08 13:54:20 +00:00
|
|
|
if (!(def = virDomainDefParseString(conn, driver->caps, xml,
|
|
|
|
VIR_DOMAIN_XML_INACTIVE)))
|
2008-12-04 21:11:41 +00:00
|
|
|
goto cleanup;
|
2008-04-10 07:30:52 +00:00
|
|
|
|
2008-08-13 12:50:55 +00:00
|
|
|
if ((def->nets != NULL) && !(driver->have_netns)) {
|
|
|
|
lxcError(conn, NULL, VIR_ERR_NO_SUPPORT,
|
avoid many format string warnings
Building with --disable-nls exposed many new warnings like these:
virsh.c:4952: warning: format not a string literal and no format ...
util.c:163: warning: format not a string literal and no format arguments
All but one of the following changes add a "%s" argument before
the offending _(...) argument.
This was the only manual change:
* src/lxc_driver.c (lxcVersion): Use %s and strerror(errno)
rather than %m, to avoid a warning from gcc -Wformat-security.
Add "%s" before each warned about format-string-with-no-%-directive:
* src/domain_conf.c (virDomainHostdevSubsysUsbDefParseXML)
(virDomainDefParseString, virDomainDefParseFile):
* src/hash.c (virGetConnect, __virGetDomain, virReleaseDomain)
(__virGetNetwork, virReleaseNetwork, __virGetStoragePool)
(virReleaseStoragePool, __virGetStorageVol, virReleaseStorageVol):
* src/lxc_container.c (lxcContainerChild):
* src/lxc_driver.c (lxcDomainDefine, lxcDomainUndefine)
(lxcDomainGetInfo, lxcGetOSType, lxcDomainDumpXML)
(lxcSetupInterfaces, lxcDomainStart, lxcDomainCreateAndStart)
(lxcVersion, lxcGetSchedulerParameters):
* src/network_conf.c (virNetworkDefParseString)
(virNetworkDefParseFile):
* src/openvz_conf.c (openvzReadNetworkConf, openvzLoadDomains):
* src/openvz_driver.c (openvzDomainDefineCmd)
(openvzDomainGetInfo, openvzDomainDumpXML, openvzDomainShutdown)
(openvzDomainReboot, ADD_ARG_LIT, openvzDomainDefineXML)
(openvzDomainCreateXML, openvzDomainCreate, openvzDomainUndefine)
(openvzDomainSetAutostart, openvzDomainGetAutostart)
(openvzDomainSetVcpus):
* src/qemu_driver.c (qemudDomainBlockPeek, qemudDomainMemoryPeek):
* src/remote_internal.c (remoteDomainBlockPeek)
(remoteDomainMemoryPeek, remoteAuthPolkit):
* src/sexpr.c (sexpr_new, _string2sexpr):
* src/storage_backend_disk.c (virStorageBackendDiskMakeDataVol)
(virStorageBackendDiskCreateVol):
* src/storage_backend_fs.c
(virStorageBackendFileSystemNetFindPoolSources):
* src/storage_backend_logical.c (virStorageBackendLogicalFindLVs)
(virStorageBackendLogicalFindPoolSources):
* src/test.c (testOpenDefault, testOpenFromFile, testOpen)
(testGetDomainInfo, testDomainRestore)
(testNodeGetCellsFreeMemory):
* src/util.c (virExec):
* src/virsh.c (cmdAttachDevice, cmdDetachDevice)
(cmdAttachInterface, cmdDetachInterface, cmdAttachDisk)
(cmdDetachDisk, cmdEdit):
* src/xend_internal.c (do_connect, wr_sync, xend_op_ext)
(urlencode, xenDaemonDomainCreateXML)
(xenDaemonDomainLookupByName_ids, xenDaemonDomainLookupByID)
(xenDaemonParseSxprOS, xend_parse_sexp_desc_char)
(xenDaemonParseSxprChar, xenDaemonParseSxprDisks)
(xenDaemonParseSxpr, sexpr_to_xend_topology, sexpr_to_domain)
(xenDaemonDomainFetch, xenDaemonDomainGetAutostart)
(xenDaemonDomainSetAutostart, xenDaemonDomainMigratePerform)
(xenDaemonDomainDefineXML, xenDaemonGetSchedulerType)
(xenDaemonGetSchedulerParameters)
(xenDaemonSetSchedulerParameters, xenDaemonDomainBlockPeek)
(xenDaemonFormatSxprChr, virDomainXMLDevID):
* src/xm_internal.c (xenXMConfigCacheRefresh, xenXMDomainPinVcpu)
(xenXMDomainCreate, xenXMDomainDefineXML)
(xenXMDomainAttachDevice, xenXMDomainDetachDevice):
* src/xml.c (virXPathString, virXPathNumber, virXPathLong)
(virXPathULong, virXPathBoolean, virXPathNode, virXPathNodeSet):
* src/xs_internal.c (xenStoreOpen):
2008-10-13 16:46:28 +00:00
|
|
|
"%s", _("System lacks NETNS support"));
|
2008-12-04 21:11:41 +00:00
|
|
|
goto cleanup;
|
2008-04-10 07:30:52 +00:00
|
|
|
}
|
|
|
|
|
2008-08-13 12:50:55 +00:00
|
|
|
|
2008-12-04 21:11:41 +00:00
|
|
|
if (!(vm = virDomainAssignDef(conn, &driver->domains, def)))
|
|
|
|
goto cleanup;
|
|
|
|
def = NULL;
|
2008-04-10 07:30:52 +00:00
|
|
|
|
|
|
|
if (lxcVmStart(conn, driver, vm) < 0) {
|
2008-08-13 12:50:55 +00:00
|
|
|
virDomainRemoveInactive(&driver->domains, vm);
|
2008-12-04 21:12:41 +00:00
|
|
|
vm = NULL;
|
2008-12-04 21:11:41 +00:00
|
|
|
goto cleanup;
|
2008-04-10 07:30:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
dom = virGetDomain(conn, vm->def->name, vm->def->uuid);
|
2008-12-04 21:11:41 +00:00
|
|
|
if (dom)
|
2008-04-10 07:30:52 +00:00
|
|
|
dom->id = vm->def->id;
|
|
|
|
|
2008-12-04 21:11:41 +00:00
|
|
|
cleanup:
|
|
|
|
virDomainDefFree(def);
|
2008-12-04 21:12:41 +00:00
|
|
|
if (vm)
|
|
|
|
virDomainObjUnlock(vm);
|
|
|
|
lxcDriverUnlock(driver);
|
2008-04-10 07:30:52 +00:00
|
|
|
return dom;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* lxcDomainShutdown:
|
|
|
|
* @dom: Ptr to domain to shutdown
|
|
|
|
*
|
|
|
|
* Sends SIGINT to container root process to request it to shutdown
|
|
|
|
*
|
|
|
|
* Returns 0 on success or -1 in case of error
|
|
|
|
*/
|
|
|
|
static int lxcDomainShutdown(virDomainPtr dom)
|
|
|
|
{
|
2008-12-04 21:11:41 +00:00
|
|
|
lxc_driver_t *driver = dom->conn->privateData;
|
|
|
|
virDomainObjPtr vm;
|
|
|
|
int ret = -1;
|
2008-04-10 07:30:52 +00:00
|
|
|
|
2008-12-04 21:12:41 +00:00
|
|
|
lxcDriverLock(driver);
|
2008-12-04 21:11:41 +00:00
|
|
|
vm = virDomainFindByID(&driver->domains, dom->id);
|
2008-04-10 07:30:52 +00:00
|
|
|
if (!vm) {
|
|
|
|
lxcError(dom->conn, dom, VIR_ERR_INVALID_DOMAIN,
|
|
|
|
_("no domain with id %d"), dom->id);
|
2008-12-04 21:11:41 +00:00
|
|
|
goto cleanup;
|
2008-04-10 07:30:52 +00:00
|
|
|
}
|
|
|
|
|
2008-12-04 21:11:41 +00:00
|
|
|
ret = lxcVmTerminate(dom->conn, driver, vm, 0);
|
2008-12-04 21:12:41 +00:00
|
|
|
if (!vm->persistent) {
|
|
|
|
virDomainRemoveInactive(&driver->domains, vm);
|
|
|
|
vm = NULL;
|
|
|
|
}
|
2008-12-04 21:11:41 +00:00
|
|
|
|
|
|
|
cleanup:
|
2008-12-04 21:12:41 +00:00
|
|
|
if (vm)
|
|
|
|
virDomainObjUnlock(vm);
|
|
|
|
lxcDriverUnlock(driver);
|
2008-12-04 21:11:41 +00:00
|
|
|
return ret;
|
2008-04-10 07:30:52 +00:00
|
|
|
}
|
|
|
|
|
2008-05-13 06:30:58 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* lxcDomainDestroy:
|
|
|
|
* @dom: Ptr to domain to destroy
|
|
|
|
*
|
|
|
|
* Sends SIGKILL to container root process to terminate the container
|
|
|
|
*
|
|
|
|
* Returns 0 on success or -1 in case of error
|
|
|
|
*/
|
|
|
|
static int lxcDomainDestroy(virDomainPtr dom)
|
|
|
|
{
|
2008-12-04 21:11:41 +00:00
|
|
|
lxc_driver_t *driver = dom->conn->privateData;
|
|
|
|
virDomainObjPtr vm;
|
|
|
|
int ret = -1;
|
2008-05-13 06:30:58 +00:00
|
|
|
|
2008-12-04 21:12:41 +00:00
|
|
|
lxcDriverLock(driver);
|
2008-12-04 21:11:41 +00:00
|
|
|
vm = virDomainFindByID(&driver->domains, dom->id);
|
2008-05-13 06:30:58 +00:00
|
|
|
if (!vm) {
|
|
|
|
lxcError(dom->conn, dom, VIR_ERR_INVALID_DOMAIN,
|
|
|
|
_("no domain with id %d"), dom->id);
|
2008-12-04 21:11:41 +00:00
|
|
|
goto cleanup;
|
2008-05-13 06:30:58 +00:00
|
|
|
}
|
|
|
|
|
2008-12-04 21:11:41 +00:00
|
|
|
ret = lxcVmTerminate(dom->conn, driver, vm, SIGKILL);
|
2008-12-04 21:12:41 +00:00
|
|
|
if (!vm->persistent) {
|
|
|
|
virDomainRemoveInactive(&driver->domains, vm);
|
|
|
|
vm = NULL;
|
|
|
|
}
|
2008-12-04 21:11:41 +00:00
|
|
|
|
|
|
|
cleanup:
|
2008-12-04 21:12:41 +00:00
|
|
|
if (vm)
|
|
|
|
virDomainObjUnlock(vm);
|
|
|
|
lxcDriverUnlock(driver);
|
2008-12-04 21:11:41 +00:00
|
|
|
return ret;
|
2008-04-10 07:30:52 +00:00
|
|
|
}
|
2008-03-27 09:34:06 +00:00
|
|
|
|
2008-06-26 16:05:02 +00:00
|
|
|
static int lxcCheckNetNsSupport(void)
|
|
|
|
{
|
|
|
|
const char *argv[] = {"ip", "link", "set", "lo", "netns", "-1", NULL};
|
|
|
|
int ip_rc;
|
|
|
|
|
2008-08-13 10:25:34 +00:00
|
|
|
if (virRun(NULL, argv, &ip_rc) < 0 ||
|
|
|
|
!(WIFEXITED(ip_rc) && (WEXITSTATUS(ip_rc) != 255)))
|
|
|
|
return 0;
|
2008-06-26 16:05:02 +00:00
|
|
|
|
2008-08-13 10:25:34 +00:00
|
|
|
if (lxcContainerAvailable(LXC_CONTAINER_FEATURE_NET) < 0)
|
|
|
|
return 0;
|
2008-06-26 16:05:02 +00:00
|
|
|
|
2008-08-13 10:25:34 +00:00
|
|
|
return 1;
|
2008-06-26 16:05:02 +00:00
|
|
|
}
|
|
|
|
|
2008-03-27 09:34:06 +00:00
|
|
|
static int lxcStartup(void)
|
2008-03-21 15:03:37 +00:00
|
|
|
{
|
2008-03-31 12:02:12 +00:00
|
|
|
uid_t uid = getuid();
|
2008-10-10 14:20:37 +00:00
|
|
|
unsigned int i;
|
2008-03-31 12:02:12 +00:00
|
|
|
|
|
|
|
/* Check that the user is root */
|
|
|
|
if (0 != uid) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2008-06-06 11:09:57 +00:00
|
|
|
if (VIR_ALLOC(lxc_driver) < 0) {
|
2008-03-27 09:34:06 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2009-01-15 19:56:05 +00:00
|
|
|
if (virMutexInit(&lxc_driver->lock) < 0) {
|
|
|
|
VIR_FREE(lxc_driver);
|
|
|
|
return -1;
|
|
|
|
}
|
2008-12-04 21:12:41 +00:00
|
|
|
lxcDriverLock(lxc_driver);
|
2008-03-21 15:03:37 +00:00
|
|
|
|
2008-03-27 09:34:06 +00:00
|
|
|
/* Check that this is a container enabled kernel */
|
2008-08-13 10:25:34 +00:00
|
|
|
if(lxcContainerAvailable(0) < 0)
|
2008-12-04 21:12:41 +00:00
|
|
|
goto cleanup;
|
2008-03-21 15:03:37 +00:00
|
|
|
|
2008-06-26 16:05:02 +00:00
|
|
|
lxc_driver->have_netns = lxcCheckNetNsSupport();
|
2008-03-21 15:03:37 +00:00
|
|
|
|
|
|
|
/* Call function to load lxc driver configuration information */
|
2008-12-04 21:12:41 +00:00
|
|
|
if (lxcLoadDriverConfig(lxc_driver) < 0)
|
|
|
|
goto cleanup;
|
2008-03-21 15:03:37 +00:00
|
|
|
|
2008-12-04 21:12:41 +00:00
|
|
|
if ((lxc_driver->caps = lxcCapsInit()) == NULL)
|
|
|
|
goto cleanup;
|
2008-03-21 15:03:37 +00:00
|
|
|
|
2008-08-13 12:50:55 +00:00
|
|
|
if (virDomainLoadAllConfigs(NULL,
|
|
|
|
lxc_driver->caps,
|
|
|
|
&lxc_driver->domains,
|
|
|
|
lxc_driver->configDir,
|
2008-11-17 16:52:32 +00:00
|
|
|
lxc_driver->autostartDir,
|
2008-12-04 21:12:41 +00:00
|
|
|
NULL, NULL) < 0)
|
|
|
|
goto cleanup;
|
2008-08-13 12:50:55 +00:00
|
|
|
|
2008-10-10 14:20:37 +00:00
|
|
|
for (i = 0 ; i < lxc_driver->domains.count ; i++) {
|
|
|
|
virDomainObjPtr vm = lxc_driver->domains.objs[i];
|
2008-08-20 20:55:32 +00:00
|
|
|
char *config = NULL;
|
|
|
|
virDomainDefPtr tmp;
|
2008-08-13 10:52:15 +00:00
|
|
|
int rc;
|
2008-12-04 21:12:41 +00:00
|
|
|
|
|
|
|
virDomainObjLock(vm);
|
|
|
|
if ((vm->monitor = lxcMonitorClient(NULL, lxc_driver, vm)) < 0) {
|
|
|
|
virDomainObjUnlock(vm);
|
2008-08-13 10:52:15 +00:00
|
|
|
continue;
|
2008-12-04 21:12:41 +00:00
|
|
|
}
|
2008-08-13 10:52:15 +00:00
|
|
|
|
|
|
|
/* Read pid from controller */
|
|
|
|
if ((rc = virFileReadPid(lxc_driver->stateDir, vm->def->name, &vm->pid)) != 0) {
|
|
|
|
close(vm->monitor);
|
|
|
|
vm->monitor = -1;
|
2008-12-04 21:12:41 +00:00
|
|
|
virDomainObjUnlock(vm);
|
2008-08-13 10:52:15 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2008-08-20 20:55:32 +00:00
|
|
|
if ((config = virDomainConfigFile(NULL,
|
|
|
|
lxc_driver->stateDir,
|
2008-12-04 21:12:41 +00:00
|
|
|
vm->def->name)) == NULL) {
|
|
|
|
virDomainObjUnlock(vm);
|
2008-08-20 20:55:32 +00:00
|
|
|
continue;
|
2008-12-04 21:12:41 +00:00
|
|
|
}
|
2008-08-20 20:55:32 +00:00
|
|
|
|
|
|
|
/* Try and load the live config */
|
2008-12-04 12:02:59 +00:00
|
|
|
tmp = virDomainDefParseFile(NULL, lxc_driver->caps, config, 0);
|
2008-08-20 20:55:32 +00:00
|
|
|
VIR_FREE(config);
|
|
|
|
if (tmp) {
|
|
|
|
vm->newDef = vm->def;
|
|
|
|
vm->def = tmp;
|
|
|
|
}
|
|
|
|
|
2008-08-13 10:52:15 +00:00
|
|
|
if (vm->pid != 0) {
|
|
|
|
vm->def->id = vm->pid;
|
|
|
|
vm->state = VIR_DOMAIN_RUNNING;
|
|
|
|
} else {
|
|
|
|
vm->def->id = -1;
|
|
|
|
close(vm->monitor);
|
|
|
|
vm->monitor = -1;
|
|
|
|
}
|
2008-12-04 21:12:41 +00:00
|
|
|
virDomainObjUnlock(vm);
|
2008-08-13 10:52:15 +00:00
|
|
|
}
|
|
|
|
|
2008-12-04 21:12:41 +00:00
|
|
|
lxcDriverUnlock(lxc_driver);
|
2008-03-21 15:03:37 +00:00
|
|
|
return 0;
|
|
|
|
|
2008-12-04 21:12:41 +00:00
|
|
|
cleanup:
|
|
|
|
lxcDriverUnlock(lxc_driver);
|
|
|
|
lxcShutdown();
|
|
|
|
return -1;
|
2008-03-21 15:03:37 +00:00
|
|
|
}
|
|
|
|
|
2008-03-27 09:34:06 +00:00
|
|
|
static int lxcShutdown(void)
|
2008-03-21 15:03:37 +00:00
|
|
|
{
|
2008-03-31 12:02:12 +00:00
|
|
|
if (lxc_driver == NULL)
|
2008-03-31 14:38:12 +00:00
|
|
|
return(-1);
|
2008-10-10 14:20:37 +00:00
|
|
|
|
2008-12-04 21:12:41 +00:00
|
|
|
lxcDriverLock(lxc_driver);
|
2008-10-10 14:20:37 +00:00
|
|
|
virDomainObjListFree(&lxc_driver->domains);
|
2008-12-04 21:12:41 +00:00
|
|
|
|
|
|
|
virCapabilitiesFree(lxc_driver->caps);
|
|
|
|
VIR_FREE(lxc_driver->configDir);
|
|
|
|
VIR_FREE(lxc_driver->autostartDir);
|
|
|
|
VIR_FREE(lxc_driver->stateDir);
|
|
|
|
VIR_FREE(lxc_driver->logDir);
|
|
|
|
lxcDriverUnlock(lxc_driver);
|
2009-01-15 19:56:05 +00:00
|
|
|
virMutexDestroy(&lxc_driver->lock);
|
2008-12-04 21:12:41 +00:00
|
|
|
VIR_FREE(lxc_driver);
|
2008-03-31 12:02:12 +00:00
|
|
|
lxc_driver = NULL;
|
2008-03-27 09:34:06 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2008-03-21 15:03:37 +00:00
|
|
|
|
2008-03-27 09:34:06 +00:00
|
|
|
/**
|
|
|
|
* lxcActive:
|
|
|
|
*
|
|
|
|
* Checks if the LXC daemon is active, i.e. has an active domain
|
|
|
|
*
|
|
|
|
* Returns 1 if active, 0 otherwise
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
lxcActive(void) {
|
2008-10-10 14:20:37 +00:00
|
|
|
unsigned int i;
|
2008-12-04 21:12:41 +00:00
|
|
|
int active = 0;
|
2008-08-13 12:50:55 +00:00
|
|
|
|
2008-03-31 12:02:12 +00:00
|
|
|
if (lxc_driver == NULL)
|
|
|
|
return(0);
|
2008-08-13 12:50:55 +00:00
|
|
|
|
2008-12-04 21:12:41 +00:00
|
|
|
lxcDriverLock(lxc_driver);
|
|
|
|
for (i = 0 ; i < lxc_driver->domains.count ; i++) {
|
|
|
|
virDomainObjLock(lxc_driver->domains.objs[i]);
|
2008-10-10 14:20:37 +00:00
|
|
|
if (virDomainIsActive(lxc_driver->domains.objs[i]))
|
2008-12-04 21:12:41 +00:00
|
|
|
active = 1;
|
|
|
|
virDomainObjUnlock(lxc_driver->domains.objs[i]);
|
|
|
|
}
|
|
|
|
lxcDriverUnlock(lxc_driver);
|
2008-03-27 09:34:06 +00:00
|
|
|
|
2008-12-04 21:12:41 +00:00
|
|
|
return active;
|
2008-03-21 15:03:37 +00:00
|
|
|
}
|
|
|
|
|
2008-09-03 17:21:27 +00:00
|
|
|
static int lxcVersion(virConnectPtr conn, unsigned long *version)
|
|
|
|
{
|
|
|
|
struct utsname ver;
|
|
|
|
int maj;
|
|
|
|
int min;
|
|
|
|
int rev;
|
|
|
|
|
2009-01-20 17:13:33 +00:00
|
|
|
uname(&ver);
|
2008-09-03 17:21:27 +00:00
|
|
|
|
|
|
|
if (sscanf(ver.release, "%i.%i.%i", &maj, &min, &rev) != 3) {
|
|
|
|
lxcError(conn, NULL, VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Unknown release: %s"), ver.release);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
*version = (maj * 1000 * 1000) + (min * 1000) + rev;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2008-03-27 09:34:06 +00:00
|
|
|
|
2008-10-10 09:32:27 +00:00
|
|
|
static char *lxcGetSchedulerType(virDomainPtr domain ATTRIBUTE_UNUSED,
|
|
|
|
int *nparams)
|
2008-10-08 16:28:48 +00:00
|
|
|
{
|
|
|
|
if (nparams)
|
|
|
|
*nparams = 1;
|
|
|
|
|
|
|
|
return strdup("posix");
|
|
|
|
}
|
|
|
|
|
2008-12-04 21:11:41 +00:00
|
|
|
static int lxcSetSchedulerParameters(virDomainPtr domain,
|
2008-10-08 16:28:48 +00:00
|
|
|
virSchedParameterPtr params,
|
|
|
|
int nparams)
|
|
|
|
{
|
2008-12-04 21:12:41 +00:00
|
|
|
lxc_driver_t *driver = domain->conn->privateData;
|
2008-10-08 16:28:48 +00:00
|
|
|
int i;
|
2008-12-04 21:11:41 +00:00
|
|
|
virCgroupPtr group = NULL;
|
|
|
|
virDomainObjPtr vm = NULL;
|
|
|
|
int ret = -1;
|
2008-10-08 16:28:48 +00:00
|
|
|
|
|
|
|
if (virCgroupHaveSupport() != 0)
|
2008-12-04 21:12:41 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
lxcDriverLock(driver);
|
|
|
|
vm = virDomainFindByUUID(&driver->domains, domain->uuid);
|
|
|
|
lxcDriverUnlock(driver);
|
2008-10-08 16:28:48 +00:00
|
|
|
|
2008-12-04 21:11:41 +00:00
|
|
|
if (vm == NULL) {
|
|
|
|
lxcError(NULL, domain, VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("No such domain %s"), domain->uuid);
|
|
|
|
goto cleanup;
|
2008-10-08 16:28:48 +00:00
|
|
|
}
|
|
|
|
|
2008-12-04 21:11:41 +00:00
|
|
|
if (virCgroupForDomain(vm->def, "lxc", &group) != 0)
|
|
|
|
goto cleanup;
|
2008-10-08 16:28:48 +00:00
|
|
|
|
|
|
|
for (i = 0; i < nparams; i++) {
|
|
|
|
virSchedParameterPtr param = ¶ms[i];
|
|
|
|
|
|
|
|
if (STREQ(param->field, "cpu_shares")) {
|
2008-12-04 21:11:41 +00:00
|
|
|
if (virCgroupSetCpuShares(group, params[i].value.ui) != 0)
|
|
|
|
goto cleanup;
|
2008-10-08 16:28:48 +00:00
|
|
|
} else {
|
2008-12-04 21:11:41 +00:00
|
|
|
lxcError(NULL, domain, VIR_ERR_INVALID_ARG,
|
2008-10-08 16:28:48 +00:00
|
|
|
_("Invalid parameter `%s'"), param->field);
|
2008-12-04 21:11:41 +00:00
|
|
|
goto cleanup;
|
2008-10-08 16:28:48 +00:00
|
|
|
}
|
|
|
|
}
|
2008-12-04 21:11:41 +00:00
|
|
|
ret = 0;
|
2008-10-08 16:28:48 +00:00
|
|
|
|
2008-12-04 21:11:41 +00:00
|
|
|
cleanup:
|
2008-10-08 16:28:48 +00:00
|
|
|
virCgroupFree(&group);
|
2008-12-04 21:12:41 +00:00
|
|
|
if (vm)
|
|
|
|
virDomainObjUnlock(vm);
|
2008-12-04 21:11:41 +00:00
|
|
|
return ret;
|
2008-10-08 16:28:48 +00:00
|
|
|
}
|
|
|
|
|
2008-12-04 21:11:41 +00:00
|
|
|
static int lxcGetSchedulerParameters(virDomainPtr domain,
|
2008-10-08 16:28:48 +00:00
|
|
|
virSchedParameterPtr params,
|
|
|
|
int *nparams)
|
|
|
|
{
|
2008-12-04 21:12:41 +00:00
|
|
|
lxc_driver_t *driver = domain->conn->privateData;
|
2008-12-04 21:11:41 +00:00
|
|
|
virCgroupPtr group = NULL;
|
|
|
|
virDomainObjPtr vm = NULL;
|
2008-10-24 11:20:08 +00:00
|
|
|
unsigned long val;
|
2008-12-04 21:11:41 +00:00
|
|
|
int ret = -1;
|
2008-10-08 16:28:48 +00:00
|
|
|
|
|
|
|
if (virCgroupHaveSupport() != 0)
|
2008-12-04 21:12:41 +00:00
|
|
|
return -1;
|
2008-10-08 16:28:48 +00:00
|
|
|
|
|
|
|
if ((*nparams) != 1) {
|
2008-12-04 21:11:41 +00:00
|
|
|
lxcError(NULL, domain, VIR_ERR_INVALID_ARG,
|
avoid many format string warnings
Building with --disable-nls exposed many new warnings like these:
virsh.c:4952: warning: format not a string literal and no format ...
util.c:163: warning: format not a string literal and no format arguments
All but one of the following changes add a "%s" argument before
the offending _(...) argument.
This was the only manual change:
* src/lxc_driver.c (lxcVersion): Use %s and strerror(errno)
rather than %m, to avoid a warning from gcc -Wformat-security.
Add "%s" before each warned about format-string-with-no-%-directive:
* src/domain_conf.c (virDomainHostdevSubsysUsbDefParseXML)
(virDomainDefParseString, virDomainDefParseFile):
* src/hash.c (virGetConnect, __virGetDomain, virReleaseDomain)
(__virGetNetwork, virReleaseNetwork, __virGetStoragePool)
(virReleaseStoragePool, __virGetStorageVol, virReleaseStorageVol):
* src/lxc_container.c (lxcContainerChild):
* src/lxc_driver.c (lxcDomainDefine, lxcDomainUndefine)
(lxcDomainGetInfo, lxcGetOSType, lxcDomainDumpXML)
(lxcSetupInterfaces, lxcDomainStart, lxcDomainCreateAndStart)
(lxcVersion, lxcGetSchedulerParameters):
* src/network_conf.c (virNetworkDefParseString)
(virNetworkDefParseFile):
* src/openvz_conf.c (openvzReadNetworkConf, openvzLoadDomains):
* src/openvz_driver.c (openvzDomainDefineCmd)
(openvzDomainGetInfo, openvzDomainDumpXML, openvzDomainShutdown)
(openvzDomainReboot, ADD_ARG_LIT, openvzDomainDefineXML)
(openvzDomainCreateXML, openvzDomainCreate, openvzDomainUndefine)
(openvzDomainSetAutostart, openvzDomainGetAutostart)
(openvzDomainSetVcpus):
* src/qemu_driver.c (qemudDomainBlockPeek, qemudDomainMemoryPeek):
* src/remote_internal.c (remoteDomainBlockPeek)
(remoteDomainMemoryPeek, remoteAuthPolkit):
* src/sexpr.c (sexpr_new, _string2sexpr):
* src/storage_backend_disk.c (virStorageBackendDiskMakeDataVol)
(virStorageBackendDiskCreateVol):
* src/storage_backend_fs.c
(virStorageBackendFileSystemNetFindPoolSources):
* src/storage_backend_logical.c (virStorageBackendLogicalFindLVs)
(virStorageBackendLogicalFindPoolSources):
* src/test.c (testOpenDefault, testOpenFromFile, testOpen)
(testGetDomainInfo, testDomainRestore)
(testNodeGetCellsFreeMemory):
* src/util.c (virExec):
* src/virsh.c (cmdAttachDevice, cmdDetachDevice)
(cmdAttachInterface, cmdDetachInterface, cmdAttachDisk)
(cmdDetachDisk, cmdEdit):
* src/xend_internal.c (do_connect, wr_sync, xend_op_ext)
(urlencode, xenDaemonDomainCreateXML)
(xenDaemonDomainLookupByName_ids, xenDaemonDomainLookupByID)
(xenDaemonParseSxprOS, xend_parse_sexp_desc_char)
(xenDaemonParseSxprChar, xenDaemonParseSxprDisks)
(xenDaemonParseSxpr, sexpr_to_xend_topology, sexpr_to_domain)
(xenDaemonDomainFetch, xenDaemonDomainGetAutostart)
(xenDaemonDomainSetAutostart, xenDaemonDomainMigratePerform)
(xenDaemonDomainDefineXML, xenDaemonGetSchedulerType)
(xenDaemonGetSchedulerParameters)
(xenDaemonSetSchedulerParameters, xenDaemonDomainBlockPeek)
(xenDaemonFormatSxprChr, virDomainXMLDevID):
* src/xm_internal.c (xenXMConfigCacheRefresh, xenXMDomainPinVcpu)
(xenXMDomainCreate, xenXMDomainDefineXML)
(xenXMDomainAttachDevice, xenXMDomainDetachDevice):
* src/xml.c (virXPathString, virXPathNumber, virXPathLong)
(virXPathULong, virXPathBoolean, virXPathNode, virXPathNodeSet):
* src/xs_internal.c (xenStoreOpen):
2008-10-13 16:46:28 +00:00
|
|
|
"%s", _("Invalid parameter count"));
|
2008-12-04 21:12:41 +00:00
|
|
|
return -1;
|
2008-10-08 16:28:48 +00:00
|
|
|
}
|
|
|
|
|
2008-12-04 21:12:41 +00:00
|
|
|
lxcDriverLock(driver);
|
|
|
|
vm = virDomainFindByUUID(&driver->domains, domain->uuid);
|
|
|
|
lxcDriverUnlock(driver);
|
|
|
|
|
2008-12-04 21:11:41 +00:00
|
|
|
if (vm == NULL) {
|
|
|
|
lxcError(NULL, domain, VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("No such domain %s"), domain->uuid);
|
|
|
|
goto cleanup;
|
2008-10-08 16:28:48 +00:00
|
|
|
}
|
|
|
|
|
2008-12-04 21:11:41 +00:00
|
|
|
if (virCgroupForDomain(vm->def, "lxc", &group) != 0)
|
|
|
|
goto cleanup;
|
2008-10-08 16:28:48 +00:00
|
|
|
|
2008-12-04 21:11:41 +00:00
|
|
|
if (virCgroupGetCpuShares(group, &val) != 0)
|
|
|
|
goto cleanup;
|
2008-10-24 11:20:08 +00:00
|
|
|
params[0].value.ul = val;
|
2008-10-08 16:28:48 +00:00
|
|
|
strncpy(params[0].field, "cpu_shares", sizeof(params[0].field));
|
|
|
|
params[0].type = VIR_DOMAIN_SCHED_FIELD_ULLONG;
|
|
|
|
|
2008-12-04 21:11:41 +00:00
|
|
|
ret = 0;
|
2008-10-08 16:28:48 +00:00
|
|
|
|
2008-12-04 21:11:41 +00:00
|
|
|
cleanup:
|
|
|
|
virCgroupFree(&group);
|
2008-12-04 21:12:41 +00:00
|
|
|
if (vm)
|
|
|
|
virDomainObjUnlock(vm);
|
2008-12-04 21:11:41 +00:00
|
|
|
return ret;
|
2008-10-08 16:28:48 +00:00
|
|
|
}
|
|
|
|
|
2008-03-21 15:03:37 +00:00
|
|
|
/* Function Tables */
|
|
|
|
static virDriver lxcDriver = {
|
|
|
|
VIR_DRV_LXC, /* the number virDrvNo */
|
|
|
|
"LXC", /* the name of the driver */
|
|
|
|
lxcOpen, /* open */
|
|
|
|
lxcClose, /* close */
|
|
|
|
NULL, /* supports_feature */
|
|
|
|
NULL, /* type */
|
2008-09-03 17:21:27 +00:00
|
|
|
lxcVersion, /* version */
|
2008-03-21 15:03:37 +00:00
|
|
|
NULL, /* getHostname */
|
|
|
|
NULL, /* getURI */
|
|
|
|
NULL, /* getMaxVcpus */
|
|
|
|
NULL, /* nodeGetInfo */
|
|
|
|
NULL, /* getCapabilities */
|
|
|
|
lxcListDomains, /* listDomains */
|
|
|
|
lxcNumDomains, /* numOfDomains */
|
2008-10-10 09:32:27 +00:00
|
|
|
lxcDomainCreateAndStart, /* domainCreateXML */
|
2008-03-21 15:03:37 +00:00
|
|
|
lxcDomainLookupByID, /* domainLookupByID */
|
|
|
|
lxcDomainLookupByUUID, /* domainLookupByUUID */
|
|
|
|
lxcDomainLookupByName, /* domainLookupByName */
|
|
|
|
NULL, /* domainSuspend */
|
|
|
|
NULL, /* domainResume */
|
2008-04-10 07:30:52 +00:00
|
|
|
lxcDomainShutdown, /* domainShutdown */
|
2008-03-21 15:03:37 +00:00
|
|
|
NULL, /* domainReboot */
|
2008-04-10 07:30:52 +00:00
|
|
|
lxcDomainDestroy, /* domainDestroy */
|
2008-03-21 15:03:37 +00:00
|
|
|
lxcGetOSType, /* domainGetOSType */
|
|
|
|
NULL, /* domainGetMaxMemory */
|
|
|
|
NULL, /* domainSetMaxMemory */
|
|
|
|
NULL, /* domainSetMemory */
|
|
|
|
lxcDomainGetInfo, /* domainGetInfo */
|
|
|
|
NULL, /* domainSave */
|
|
|
|
NULL, /* domainRestore */
|
|
|
|
NULL, /* domainCoreDump */
|
|
|
|
NULL, /* domainSetVcpus */
|
|
|
|
NULL, /* domainPinVcpu */
|
|
|
|
NULL, /* domainGetVcpus */
|
|
|
|
NULL, /* domainGetMaxVcpus */
|
|
|
|
lxcDomainDumpXML, /* domainDumpXML */
|
|
|
|
lxcListDefinedDomains, /* listDefinedDomains */
|
|
|
|
lxcNumDefinedDomains, /* numOfDefinedDomains */
|
2008-04-10 07:30:52 +00:00
|
|
|
lxcDomainStart, /* domainCreate */
|
2008-03-21 15:03:37 +00:00
|
|
|
lxcDomainDefine, /* domainDefineXML */
|
|
|
|
lxcDomainUndefine, /* domainUndefine */
|
|
|
|
NULL, /* domainAttachDevice */
|
|
|
|
NULL, /* domainDetachDevice */
|
|
|
|
NULL, /* domainGetAutostart */
|
|
|
|
NULL, /* domainSetAutostart */
|
2008-10-08 16:28:48 +00:00
|
|
|
lxcGetSchedulerType, /* domainGetSchedulerType */
|
|
|
|
lxcGetSchedulerParameters, /* domainGetSchedulerParameters */
|
|
|
|
lxcSetSchedulerParameters, /* domainSetSchedulerParameters */
|
2008-03-21 15:03:37 +00:00
|
|
|
NULL, /* domainMigratePrepare */
|
|
|
|
NULL, /* domainMigratePerform */
|
|
|
|
NULL, /* domainMigrateFinish */
|
|
|
|
NULL, /* domainBlockStats */
|
|
|
|
NULL, /* domainInterfaceStats */
|
2008-06-12 13:48:29 +00:00
|
|
|
NULL, /* domainBlockPeek */
|
|
|
|
NULL, /* domainMemoryPeek */
|
2008-03-21 15:03:37 +00:00
|
|
|
NULL, /* nodeGetCellsFreeMemory */
|
|
|
|
NULL, /* getFreeMemory */
|
2008-10-23 13:18:18 +00:00
|
|
|
NULL, /* domainEventRegister */
|
|
|
|
NULL, /* domainEventDeregister */
|
2008-11-14 08:42:47 +00:00
|
|
|
NULL, /* domainMigratePrepare2 */
|
|
|
|
NULL, /* domainMigrateFinish2 */
|
2008-03-21 15:03:37 +00:00
|
|
|
};
|
|
|
|
|
2008-03-27 09:34:06 +00:00
|
|
|
static virStateDriver lxcStateDriver = {
|
2008-10-06 15:40:37 +00:00
|
|
|
.initialize = lxcStartup,
|
|
|
|
.cleanup = lxcShutdown,
|
|
|
|
.active = lxcActive,
|
2008-03-27 09:34:06 +00:00
|
|
|
};
|
|
|
|
|
2008-03-21 15:03:37 +00:00
|
|
|
int lxcRegister(void)
|
|
|
|
{
|
|
|
|
virRegisterDriver(&lxcDriver);
|
2008-03-27 09:34:06 +00:00
|
|
|
virRegisterStateDriver(&lxcStateDriver);
|
2008-03-21 15:03:37 +00:00
|
|
|
return 0;
|
|
|
|
}
|