2007-07-17 13:27:26 +00:00
|
|
|
/*
|
|
|
|
* openvz_conf.c: config functions for managing OpenVZ VEs
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006, 2007 Binary Karma
|
|
|
|
* Copyright (C) 2006 Shuveb Hussain
|
2007-09-03 15:37:07 +00:00
|
|
|
* Copyright (C) 2007 Anoop Joe Cyriac
|
2007-07-17 13:27:26 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*
|
2008-02-05 19:27:37 +00:00
|
|
|
* Authors:
|
2007-09-03 15:37:07 +00:00
|
|
|
* Shuveb Hussain <shuveb@binarykarma.com>
|
|
|
|
* Anoop Joe Cyriac <anoop@binarykarma.com>
|
|
|
|
*
|
2007-07-17 13:27:26 +00:00
|
|
|
*/
|
|
|
|
|
2008-01-29 18:15:54 +00:00
|
|
|
#include <config.h>
|
2007-12-05 21:40:15 +00:00
|
|
|
|
2007-07-17 13:27:26 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <dirent.h>
|
|
|
|
#include <strings.h>
|
|
|
|
#include <time.h>
|
2007-09-03 15:37:07 +00:00
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <errno.h>
|
2008-06-12 13:48:29 +00:00
|
|
|
#include <string.h>
|
2008-09-05 14:10:58 +00:00
|
|
|
#include <sys/utsname.h>
|
2008-10-24 11:32:48 +00:00
|
|
|
#include <sys/wait.h>
|
2007-07-17 13:27:26 +00:00
|
|
|
|
2008-11-04 22:30:33 +00:00
|
|
|
#include "virterror_internal.h"
|
2007-09-03 15:37:07 +00:00
|
|
|
#include "openvz_conf.h"
|
2007-07-17 13:27:26 +00:00
|
|
|
#include "uuid.h"
|
|
|
|
#include "buf.h"
|
2008-06-06 11:09:57 +00:00
|
|
|
#include "memory.h"
|
2008-07-21 13:34:19 +00:00
|
|
|
#include "util.h"
|
2008-11-24 19:34:21 +00:00
|
|
|
#include "nodeinfo.h"
|
2007-07-17 13:27:26 +00:00
|
|
|
|
2009-01-29 12:10:32 +00:00
|
|
|
#define VIR_FROM_THIS VIR_FROM_OPENVZ
|
|
|
|
|
2007-09-03 15:37:07 +00:00
|
|
|
static char *openvzLocateConfDir(void);
|
|
|
|
static int openvzGetVPSUUID(int vpsid, char *uuidstr);
|
2008-11-12 16:35:47 +00:00
|
|
|
static int openvzLocateConfFile(int vpsid, char *conffile, int maxlen, const char *ext);
|
2008-09-05 14:10:58 +00:00
|
|
|
static int openvzAssignUUIDs(void);
|
2007-07-17 13:27:26 +00:00
|
|
|
|
2007-09-03 15:37:07 +00:00
|
|
|
int
|
2007-09-03 16:30:00 +00:00
|
|
|
strtoI(const char *str)
|
2007-09-03 15:37:07 +00:00
|
|
|
{
|
|
|
|
int val;
|
|
|
|
|
2008-07-21 13:34:19 +00:00
|
|
|
if (virStrToLong_i(str, NULL, 10, &val) < 0)
|
|
|
|
return 0 ;
|
2007-07-17 13:27:26 +00:00
|
|
|
|
2007-09-03 15:37:07 +00:00
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
2008-10-24 11:32:48 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
openvzExtractVersionInfo(const char *cmd, int *retversion)
|
|
|
|
{
|
|
|
|
const char *const vzarg[] = { cmd, "--help", NULL };
|
|
|
|
const char *const vzenv[] = { "LC_ALL=C", NULL };
|
|
|
|
pid_t child;
|
|
|
|
int newstdout = -1;
|
|
|
|
int ret = -1, status;
|
|
|
|
unsigned int major, minor, micro;
|
|
|
|
unsigned int version;
|
|
|
|
|
|
|
|
if (retversion)
|
|
|
|
*retversion = 0;
|
|
|
|
|
|
|
|
if (virExec(NULL, vzarg, vzenv, NULL,
|
|
|
|
&child, -1, &newstdout, NULL, VIR_EXEC_NONE) < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
char *help = NULL;
|
2008-11-10 12:08:19 +00:00
|
|
|
int len = virFileReadLimFD(newstdout, 4096, &help);
|
2008-10-24 11:32:48 +00:00
|
|
|
if (len < 0)
|
|
|
|
goto cleanup2;
|
|
|
|
|
|
|
|
if (sscanf(help, "vzctl version %u.%u.%u",
|
|
|
|
&major, &minor, µ) != 3) {
|
|
|
|
goto cleanup2;
|
|
|
|
}
|
|
|
|
|
|
|
|
version = (major * 1000 * 1000) + (minor * 1000) + micro;
|
|
|
|
|
|
|
|
if (retversion)
|
|
|
|
*retversion = version;
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
cleanup2:
|
|
|
|
VIR_FREE(help);
|
|
|
|
if (close(newstdout) < 0)
|
|
|
|
ret = -1;
|
|
|
|
|
|
|
|
rewait:
|
|
|
|
if (waitpid(child, &status, 0) != child) {
|
|
|
|
if (errno == EINTR)
|
|
|
|
goto rewait;
|
|
|
|
ret = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int openvzExtractVersion(virConnectPtr conn,
|
|
|
|
struct openvz_driver *driver)
|
|
|
|
{
|
|
|
|
if (driver->version > 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (openvzExtractVersionInfo(VZCTL, &driver->version) < 0) {
|
|
|
|
openvzError(conn, VIR_ERR_INTERNAL_ERROR,
|
2009-06-03 12:13:52 +00:00
|
|
|
"%s", _("Could not extract vzctl version"));
|
2008-10-24 11:32:48 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-09-05 14:10:58 +00:00
|
|
|
virCapsPtr openvzCapsInit(void)
|
|
|
|
{
|
|
|
|
struct utsname utsname;
|
|
|
|
virCapsPtr caps;
|
|
|
|
virCapsGuestPtr guest;
|
|
|
|
|
|
|
|
uname(&utsname);
|
|
|
|
|
|
|
|
if ((caps = virCapabilitiesNew(utsname.machine,
|
|
|
|
0, 0)) == NULL)
|
|
|
|
goto no_memory;
|
|
|
|
|
make NUMA-initialization code more portable and more robust
qemudCapsInitNUMA and umlCapsInitNUMA were identical, so this change
factors them into a new function, virCapsInitNUMA, and puts it in
nodeinfo.c.
In addition to factoring out the duplicates, this change also
adjusts that function definition (along with its macros) so
that it works with Fedora 9's numactl version 1, and makes it
so the code will work even if someone builds the kernel with
CONFIG_NR_CPUS > 4096.
Finally, also perform this NUMA initialization for the lxc
and openvz drivers.
* src/nodeinfo.c: Include <stdint.h>, <numa.h> and "memory.h".
(virCapsInitNUMA): Rename from qemudCapsInitNUMA and umlCapsInitNUMA.
(NUMA_MAX_N_CPUS): Define depending on NUMA API version.
(n_bits, MASK_CPU_ISSET): Define, adjust, use uint64 rather than long.
* src/nodeinfo.h: Include "capabilities.h".
(virCapsInitNUMA): Declare it.
* examples/domain-events/events-c/Makefile.am:
* src/Makefile.am: Add $(NUMACTL_CFLAGS) and $(NUMACTL_LIBS) to various
compile/link-related variables.
* src/qemu_conf.c: Include "nodeinfo.h".
(qemudCapsInitNUMA): Remove duplicate code. Adjust caller.
* src/uml_conf.c (umlCapsInitNUMA): Likewise.
Include "nodeinfo.h".
* src/lxc_conf.c: Include "nodeinfo.h".
(lxcCapsInit): Perform NUMA initialization here, too.
* src/openvz_conf.c (openvzCapsInit): And here.
Include "nodeinfo.h".
* src/libvirt_sym.version.in: Add virCapsInitNUMA so that libvirtd
can link to this function.
2008-12-21 18:55:09 +00:00
|
|
|
if (virCapsInitNUMA(caps) < 0)
|
|
|
|
goto no_memory;
|
|
|
|
|
2008-11-12 16:35:47 +00:00
|
|
|
virCapabilitiesSetMacPrefix(caps, (unsigned char[]){ 0x52, 0x54, 0x00 });
|
|
|
|
|
2008-09-05 14:10:58 +00:00
|
|
|
if ((guest = virCapabilitiesAddGuest(caps,
|
|
|
|
"exe",
|
|
|
|
utsname.machine,
|
|
|
|
sizeof(int) == 4 ? 32 : 8,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
0,
|
|
|
|
NULL)) == NULL)
|
|
|
|
goto no_memory;
|
|
|
|
|
|
|
|
if (virCapabilitiesAddGuestDomain(guest,
|
|
|
|
"openvz",
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
0,
|
|
|
|
NULL) == NULL)
|
|
|
|
goto no_memory;
|
|
|
|
return caps;
|
|
|
|
|
|
|
|
no_memory:
|
|
|
|
virCapabilitiesFree(caps);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-10 16:08:01 +00:00
|
|
|
static int
|
|
|
|
openvzReadNetworkConf(virConnectPtr conn,
|
|
|
|
virDomainDefPtr def,
|
|
|
|
int veid) {
|
2008-09-22 15:21:44 +00:00
|
|
|
int ret;
|
2008-10-10 16:08:01 +00:00
|
|
|
virDomainNetDefPtr net;
|
2008-09-22 15:21:44 +00:00
|
|
|
char temp[4096];
|
|
|
|
char *token, *saveptr = NULL;
|
|
|
|
|
|
|
|
/*parse routing network configuration*
|
|
|
|
* Sample from config:
|
|
|
|
* IP_ADDRESS="1.1.1.1 1.1.1.2"
|
|
|
|
* splited IPs by space
|
|
|
|
*/
|
2009-03-24 10:59:13 +00:00
|
|
|
ret = openvzReadVPSConfigParam(veid, "IP_ADDRESS", temp, sizeof(temp));
|
2008-09-22 15:21:44 +00:00
|
|
|
if (ret < 0) {
|
|
|
|
openvzError(conn, VIR_ERR_INTERNAL_ERROR,
|
2009-06-03 12:13:52 +00:00
|
|
|
_("Could not read 'IP_ADDRESS' from config for container %d"),
|
2008-09-22 15:21:44 +00:00
|
|
|
veid);
|
|
|
|
goto error;
|
|
|
|
} else if (ret > 0) {
|
|
|
|
token = strtok_r(temp, " ", &saveptr);
|
|
|
|
while (token != NULL) {
|
2008-10-10 16:08:01 +00:00
|
|
|
if (VIR_ALLOC(net) < 0)
|
2008-09-22 15:21:44 +00:00
|
|
|
goto no_memory;
|
|
|
|
|
|
|
|
net->type = VIR_DOMAIN_NET_TYPE_ETHERNET;
|
|
|
|
net->data.ethernet.ipaddr = strdup(token);
|
|
|
|
|
|
|
|
if (net->data.ethernet.ipaddr == NULL)
|
|
|
|
goto no_memory;
|
|
|
|
|
2008-10-10 16:08:01 +00:00
|
|
|
if (VIR_REALLOC_N(def->nets, def->nnets + 1) < 0)
|
|
|
|
goto no_memory;
|
|
|
|
def->nets[def->nnets++] = net;
|
|
|
|
net = NULL;
|
|
|
|
|
2008-09-22 15:21:44 +00:00
|
|
|
token = strtok_r(NULL, " ", &saveptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*parse bridge devices*/
|
|
|
|
/*Sample from config:
|
|
|
|
*NETIF="ifname=eth10,mac=00:18:51:C1:05:EE,host_ifname=veth105.10,host_mac=00:18:51:8F:D9:F3"
|
|
|
|
*devices splited by ';'
|
|
|
|
*/
|
2009-03-24 10:59:13 +00:00
|
|
|
ret = openvzReadVPSConfigParam(veid, "NETIF", temp, sizeof(temp));
|
2008-09-22 15:21:44 +00:00
|
|
|
if (ret < 0) {
|
|
|
|
openvzError(conn, VIR_ERR_INTERNAL_ERROR,
|
2009-06-03 12:13:52 +00:00
|
|
|
_("Could not read 'NETIF' from config for container %d"),
|
2008-09-22 15:21:44 +00:00
|
|
|
veid);
|
|
|
|
goto error;
|
|
|
|
} else if (ret > 0) {
|
|
|
|
token = strtok_r(temp, ";", &saveptr);
|
|
|
|
while (token != NULL) {
|
|
|
|
/*add new device to list*/
|
2008-10-10 16:08:01 +00:00
|
|
|
if (VIR_ALLOC(net) < 0)
|
2008-09-22 15:21:44 +00:00
|
|
|
goto no_memory;
|
|
|
|
|
|
|
|
net->type = VIR_DOMAIN_NET_TYPE_BRIDGE;
|
|
|
|
|
|
|
|
char *p = token, *next = token;
|
|
|
|
char cpy_temp[32];
|
|
|
|
int len;
|
|
|
|
|
|
|
|
/*parse string*/
|
|
|
|
do {
|
|
|
|
while (*next != '\0' && *next != ',') next++;
|
|
|
|
if (STRPREFIX(p, "ifname=")) {
|
|
|
|
p += 7;
|
2008-11-12 16:35:47 +00:00
|
|
|
/* skip in libvirt */
|
|
|
|
} else if (STRPREFIX(p, "host_ifname=")) {
|
|
|
|
p += 12;
|
2008-09-22 15:21:44 +00:00
|
|
|
len = next - p;
|
|
|
|
if (len > 16) {
|
|
|
|
openvzError(conn, 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", _("Too long network device name"));
|
2008-09-22 15:21:44 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2008-11-12 16:35:47 +00:00
|
|
|
if (VIR_ALLOC_N(net->ifname, len+1) < 0)
|
|
|
|
goto no_memory;
|
|
|
|
|
|
|
|
strncpy(net->ifname, p, len);
|
|
|
|
net->ifname[len] = '\0';
|
|
|
|
} else if (STRPREFIX(p, "bridge=")) {
|
|
|
|
p += 7;
|
|
|
|
len = next - p;
|
|
|
|
if (len > 16) {
|
|
|
|
openvzError(conn, VIR_ERR_INTERNAL_ERROR,
|
|
|
|
"%s", _("Too long bridge device name"));
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2008-09-22 15:21:44 +00:00
|
|
|
if (VIR_ALLOC_N(net->data.bridge.brname, len+1) < 0)
|
|
|
|
goto no_memory;
|
|
|
|
|
|
|
|
strncpy(net->data.bridge.brname, p, len);
|
|
|
|
net->data.bridge.brname[len] = '\0';
|
|
|
|
} else if (STRPREFIX(p, "mac=")) {
|
|
|
|
p += 4;
|
|
|
|
len = next - p;
|
|
|
|
if (len != 17) { //should be 17
|
|
|
|
openvzError(conn, 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", _("Wrong length MAC address"));
|
2008-09-22 15:21:44 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
strncpy(cpy_temp, p, len);
|
|
|
|
cpy_temp[len] = '\0';
|
2008-11-12 16:35:47 +00:00
|
|
|
if (virParseMacAddr(cpy_temp, net->mac) < 0) {
|
2008-09-22 15:21:44 +00:00
|
|
|
openvzError(conn, 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", _("Wrong MAC address"));
|
2008-09-22 15:21:44 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
p = ++next;
|
|
|
|
} while (p < token + strlen(token));
|
|
|
|
|
2008-10-10 16:08:01 +00:00
|
|
|
if (VIR_REALLOC_N(def->nets, def->nnets + 1) < 0)
|
|
|
|
goto no_memory;
|
|
|
|
def->nets[def->nnets++] = net;
|
|
|
|
net = NULL;
|
|
|
|
|
2008-09-22 15:21:44 +00:00
|
|
|
token = strtok_r(NULL, ";", &saveptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-10 16:08:01 +00:00
|
|
|
return 0;
|
2008-09-22 15:21:44 +00:00
|
|
|
no_memory:
|
2009-01-29 12:10:32 +00:00
|
|
|
virReportOOMError(conn);
|
2008-09-22 15:21:44 +00:00
|
|
|
error:
|
|
|
|
virDomainNetDefFree(net);
|
2008-10-10 16:08:01 +00:00
|
|
|
return -1;
|
2008-09-22 15:21:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-03-24 10:59:13 +00:00
|
|
|
/* utility function to replace 'from' by 'to' in 'str' */
|
|
|
|
static char*
|
|
|
|
openvz_replace(const char* str,
|
|
|
|
const char* from,
|
|
|
|
const char* to) {
|
|
|
|
const char* offset = NULL;
|
|
|
|
const char* str_start = str;
|
|
|
|
int to_len = strlen(to);
|
|
|
|
int from_len = strlen(from);
|
|
|
|
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
|
|
|
|
|
|
|
if(!from)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
while((offset = strstr(str_start, from)))
|
|
|
|
{
|
|
|
|
virBufferAdd(&buf, str_start, offset-str_start);
|
|
|
|
virBufferAdd(&buf, to, to_len);
|
|
|
|
str_start = offset + from_len;
|
|
|
|
}
|
|
|
|
|
|
|
|
virBufferAdd(&buf, str_start, strlen(str_start));
|
|
|
|
|
|
|
|
if(virBufferError(&buf))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return virBufferContentAndReset(&buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-10 12:08:19 +00:00
|
|
|
static int
|
|
|
|
openvzReadFSConf(virConnectPtr conn,
|
|
|
|
virDomainDefPtr def,
|
|
|
|
int veid) {
|
|
|
|
int ret;
|
|
|
|
virDomainFSDefPtr fs = NULL;
|
2009-03-24 10:59:13 +00:00
|
|
|
char* veid_str = NULL;
|
|
|
|
char temp[100];
|
2008-11-10 12:08:19 +00:00
|
|
|
|
2009-03-24 10:59:13 +00:00
|
|
|
ret = openvzReadVPSConfigParam(veid, "OSTEMPLATE", temp, sizeof(temp));
|
2008-11-10 12:08:19 +00:00
|
|
|
if (ret < 0) {
|
|
|
|
openvzError(conn, VIR_ERR_INTERNAL_ERROR,
|
2009-06-03 12:13:52 +00:00
|
|
|
_("Could not read 'OSTEMPLATE' from config for container %d"),
|
2008-11-10 12:08:19 +00:00
|
|
|
veid);
|
|
|
|
goto error;
|
|
|
|
} else if (ret > 0) {
|
|
|
|
if (VIR_ALLOC(fs) < 0)
|
|
|
|
goto no_memory;
|
|
|
|
|
|
|
|
fs->type = VIR_DOMAIN_FS_TYPE_TEMPLATE;
|
|
|
|
fs->src = strdup(temp);
|
2009-03-24 10:59:13 +00:00
|
|
|
} else {
|
|
|
|
/* OSTEMPLATE was not found, VE was booted from a private dir directly */
|
|
|
|
ret = openvzReadVPSConfigParam(veid, "VE_PRIVATE", temp, sizeof(temp));
|
|
|
|
if (ret <= 0) {
|
|
|
|
openvzError(conn, VIR_ERR_INTERNAL_ERROR,
|
2009-06-03 12:13:52 +00:00
|
|
|
_("Could not read 'VE_PRIVATE' from config for container %d"),
|
2009-03-24 10:59:13 +00:00
|
|
|
veid);
|
|
|
|
goto error;
|
|
|
|
}
|
2008-11-10 12:08:19 +00:00
|
|
|
|
2009-03-24 10:59:13 +00:00
|
|
|
if (VIR_ALLOC(fs) < 0)
|
2008-11-10 12:08:19 +00:00
|
|
|
goto no_memory;
|
|
|
|
|
2009-03-24 10:59:13 +00:00
|
|
|
if(virAsprintf(&veid_str, "%d", veid) < 0)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
fs->type = VIR_DOMAIN_FS_TYPE_MOUNT;
|
|
|
|
fs->src = openvz_replace(temp, "$VEID", veid_str);
|
2008-11-10 12:08:19 +00:00
|
|
|
|
2009-03-24 10:59:13 +00:00
|
|
|
VIR_FREE(veid_str);
|
2008-11-10 12:08:19 +00:00
|
|
|
}
|
|
|
|
|
2009-03-24 10:59:13 +00:00
|
|
|
fs->dst = strdup("/");
|
|
|
|
|
|
|
|
if (fs->src == NULL || fs->dst == NULL)
|
|
|
|
goto no_memory;
|
|
|
|
|
|
|
|
if (VIR_REALLOC_N(def->fss, def->nfss + 1) < 0)
|
|
|
|
goto no_memory;
|
|
|
|
def->fss[def->nfss++] = fs;
|
|
|
|
fs = NULL;
|
|
|
|
|
2008-11-10 12:08:19 +00:00
|
|
|
return 0;
|
|
|
|
no_memory:
|
2009-01-29 12:10:32 +00:00
|
|
|
virReportOOMError(conn);
|
2008-11-10 12:08:19 +00:00
|
|
|
error:
|
|
|
|
virDomainFSDefFree(fs);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-03 15:37:07 +00:00
|
|
|
/* Free all memory associated with a openvz_driver structure */
|
|
|
|
void
|
|
|
|
openvzFreeDriver(struct openvz_driver *driver)
|
|
|
|
{
|
|
|
|
if (!driver)
|
|
|
|
return;
|
2008-09-05 15:00:14 +00:00
|
|
|
|
2008-10-10 14:20:37 +00:00
|
|
|
virDomainObjListFree(&driver->domains);
|
2008-09-05 14:10:58 +00:00
|
|
|
virCapabilitiesFree(driver->caps);
|
2008-09-05 15:00:14 +00:00
|
|
|
}
|
2008-07-28 14:06:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2008-09-05 14:10:58 +00:00
|
|
|
int openvzLoadDomains(struct openvz_driver *driver) {
|
2007-07-17 13:27:26 +00:00
|
|
|
FILE *fp;
|
|
|
|
int veid, ret;
|
|
|
|
char status[16];
|
2007-07-19 16:22:40 +00:00
|
|
|
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
2008-10-10 14:20:37 +00:00
|
|
|
virDomainObjPtr dom = NULL;
|
2008-09-05 14:10:58 +00:00
|
|
|
char temp[50];
|
2008-02-05 19:27:37 +00:00
|
|
|
|
2008-09-05 14:10:58 +00:00
|
|
|
if (openvzAssignUUIDs() < 0)
|
|
|
|
return -1;
|
2007-07-17 13:27:26 +00:00
|
|
|
|
2008-09-05 14:10:58 +00:00
|
|
|
if ((fp = popen(VZLIST " -a -ovpsid,status -H 2>/dev/null", "r")) == NULL) {
|
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
|
|
|
openvzError(NULL, VIR_ERR_INTERNAL_ERROR, "%s", _("popen failed"));
|
2008-09-05 14:10:58 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
while(!feof(fp)) {
|
2007-09-03 16:30:00 +00:00
|
|
|
if (fscanf(fp, "%d %s\n", &veid, status) != 2) {
|
2008-08-27 11:21:01 +00:00
|
|
|
if (feof(fp))
|
|
|
|
break;
|
2008-09-05 15:00:14 +00:00
|
|
|
|
2008-09-05 14:10:58 +00:00
|
|
|
openvzError(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 parse vzlist output"));
|
2008-09-05 14:10:58 +00:00
|
|
|
goto cleanup;
|
2007-07-17 13:27:26 +00:00
|
|
|
}
|
2008-09-05 15:00:14 +00:00
|
|
|
|
2009-01-15 19:56:05 +00:00
|
|
|
if (VIR_ALLOC(dom) < 0)
|
2008-09-05 14:10:58 +00:00
|
|
|
goto no_memory;
|
2008-09-05 15:00:14 +00:00
|
|
|
|
2009-01-15 19:56:05 +00:00
|
|
|
if (virMutexInit(&dom->lock) < 0) {
|
|
|
|
openvzError(NULL, VIR_ERR_INTERNAL_ERROR,
|
|
|
|
"%s", _("cannot initialize mutex"));
|
|
|
|
VIR_FREE(dom);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (VIR_ALLOC(dom->def) < 0)
|
|
|
|
goto no_memory;
|
2008-12-17 21:13:19 +00:00
|
|
|
|
2008-09-05 14:10:58 +00:00
|
|
|
if (STREQ(status, "stopped"))
|
|
|
|
dom->state = VIR_DOMAIN_SHUTOFF;
|
|
|
|
else
|
|
|
|
dom->state = VIR_DOMAIN_RUNNING;
|
2008-09-05 15:00:14 +00:00
|
|
|
|
2008-09-05 14:10:58 +00:00
|
|
|
dom->pid = veid;
|
|
|
|
dom->def->id = dom->state == VIR_DOMAIN_SHUTOFF ? -1 : veid;
|
2008-09-05 15:00:14 +00:00
|
|
|
|
2008-12-23 13:03:29 +00:00
|
|
|
if (virAsprintf(&dom->def->name, "%i", veid) < 0)
|
2008-09-05 14:10:58 +00:00
|
|
|
goto no_memory;
|
2008-09-05 15:00:14 +00:00
|
|
|
|
2007-07-17 13:27:26 +00:00
|
|
|
openvzGetVPSUUID(veid, uuidstr);
|
2008-09-05 14:10:58 +00:00
|
|
|
ret = virUUIDParse(uuidstr, dom->def->uuid);
|
2008-09-05 15:00:14 +00:00
|
|
|
|
2008-09-05 14:10:58 +00:00
|
|
|
if (ret == -1) {
|
|
|
|
openvzError(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", _("UUID in config file malformed"));
|
2008-09-05 14:10:58 +00:00
|
|
|
goto cleanup;
|
2007-07-17 13:27:26 +00:00
|
|
|
}
|
2008-09-05 15:00:14 +00:00
|
|
|
|
2008-09-05 14:10:58 +00:00
|
|
|
if (!(dom->def->os.type = strdup("exe")))
|
|
|
|
goto no_memory;
|
|
|
|
if (!(dom->def->os.init = strdup("/sbin/init")))
|
|
|
|
goto no_memory;
|
2007-07-17 13:27:26 +00:00
|
|
|
|
2009-03-24 10:59:13 +00:00
|
|
|
ret = openvzReadVPSConfigParam(veid, "CPUS", temp, sizeof(temp));
|
2008-08-20 13:44:03 +00:00
|
|
|
if (ret < 0) {
|
2008-09-05 14:10:58 +00:00
|
|
|
openvzError(NULL, VIR_ERR_INTERNAL_ERROR,
|
2009-06-03 12:13:52 +00:00
|
|
|
_("Could not read config for container %d"),
|
2008-09-05 14:10:58 +00:00
|
|
|
veid);
|
|
|
|
goto cleanup;
|
2008-08-20 13:44:03 +00:00
|
|
|
} else if (ret > 0) {
|
2008-09-05 14:10:58 +00:00
|
|
|
dom->def->vcpus = strtoI(temp);
|
2008-08-20 13:44:03 +00:00
|
|
|
}
|
|
|
|
|
2008-11-24 19:34:21 +00:00
|
|
|
if (ret == 0 || dom->def->vcpus == 0)
|
|
|
|
dom->def->vcpus = openvzGetNodeCPUs();
|
|
|
|
|
2008-09-05 14:10:58 +00:00
|
|
|
/* XXX load rest of VM config data .... */
|
2008-09-05 15:00:14 +00:00
|
|
|
|
2008-10-10 16:08:01 +00:00
|
|
|
openvzReadNetworkConf(NULL, dom->def, veid);
|
2008-11-10 12:08:19 +00:00
|
|
|
openvzReadFSConf(NULL, dom->def, veid);
|
2008-09-22 15:21:44 +00:00
|
|
|
|
2008-10-10 14:20:37 +00:00
|
|
|
if (VIR_REALLOC_N(driver->domains.objs,
|
|
|
|
driver->domains.count + 1) < 0)
|
|
|
|
goto no_memory;
|
|
|
|
|
|
|
|
driver->domains.objs[driver->domains.count++] = dom;
|
|
|
|
dom = NULL;
|
2007-09-03 16:30:00 +00:00
|
|
|
}
|
2008-09-05 15:00:14 +00:00
|
|
|
|
2008-09-05 14:10:58 +00:00
|
|
|
fclose(fp);
|
2008-09-05 15:00:14 +00:00
|
|
|
|
2008-09-05 14:10:58 +00:00
|
|
|
return 0;
|
2008-09-05 15:00:14 +00:00
|
|
|
|
2008-09-05 14:10:58 +00:00
|
|
|
no_memory:
|
2009-01-29 12:10:32 +00:00
|
|
|
virReportOOMError(NULL);
|
2008-09-05 15:00:14 +00:00
|
|
|
|
2008-09-05 14:10:58 +00:00
|
|
|
cleanup:
|
|
|
|
fclose(fp);
|
|
|
|
virDomainObjFree(dom);
|
|
|
|
return -1;
|
2007-07-17 13:27:26 +00:00
|
|
|
}
|
|
|
|
|
2008-11-24 19:34:21 +00:00
|
|
|
unsigned int
|
|
|
|
openvzGetNodeCPUs(void)
|
|
|
|
{
|
|
|
|
virNodeInfo nodeinfo;
|
|
|
|
|
|
|
|
if (virNodeInfoPopulate(NULL, &nodeinfo) < 0) {
|
|
|
|
openvzError(NULL, VIR_ERR_INTERNAL_ERROR,
|
2009-06-03 12:13:52 +00:00
|
|
|
"%s", _("Could not read nodeinfo"));
|
2008-11-24 19:34:21 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nodeinfo.cpus;
|
|
|
|
}
|
2008-11-12 16:35:47 +00:00
|
|
|
|
2009-03-24 10:59:13 +00:00
|
|
|
static int
|
|
|
|
openvzWriteConfigParam(const char * conf_file, const char *param, const char *value)
|
2008-11-12 16:35:47 +00:00
|
|
|
{
|
2009-03-24 10:59:13 +00:00
|
|
|
char * temp_file = NULL;
|
|
|
|
int fd = -1, temp_fd = -1;
|
2008-11-12 16:35:47 +00:00
|
|
|
char line[PATH_MAX] ;
|
|
|
|
|
2009-03-24 10:59:13 +00:00
|
|
|
if (virAsprintf(&temp_file, "%s.tmp", conf_file)<0)
|
2008-11-12 16:35:47 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
fd = open(conf_file, O_RDONLY);
|
|
|
|
if (fd == -1)
|
2009-03-24 10:59:13 +00:00
|
|
|
goto error;
|
2008-11-12 16:35:47 +00:00
|
|
|
temp_fd = open(temp_file, O_WRONLY | O_CREAT | O_TRUNC, 0644);
|
|
|
|
if (temp_fd == -1) {
|
|
|
|
close(fd);
|
2009-03-24 10:59:13 +00:00
|
|
|
goto error;
|
2008-11-12 16:35:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
while(1) {
|
|
|
|
if (openvz_readline(fd, line, sizeof(line)) <= 0)
|
|
|
|
break;
|
|
|
|
|
2008-11-17 09:55:59 +00:00
|
|
|
if (!(STRPREFIX(line, param) && line[strlen(param)] == '=')) {
|
2008-11-12 16:35:47 +00:00
|
|
|
if (safewrite(temp_fd, line, strlen(line)) !=
|
|
|
|
strlen(line))
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (safewrite(temp_fd, param, strlen(param)) < 0 ||
|
|
|
|
safewrite(temp_fd, "=\"", 2) < 0 ||
|
|
|
|
safewrite(temp_fd, value, strlen(value)) < 0 ||
|
|
|
|
safewrite(temp_fd, "\"\n", 2) < 0)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
if (close(fd) < 0)
|
|
|
|
goto error;
|
|
|
|
fd = -1;
|
|
|
|
if (close(temp_fd) < 0)
|
|
|
|
goto error;
|
|
|
|
temp_fd = -1;
|
|
|
|
|
|
|
|
if (rename(temp_file, conf_file) < 0)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
error:
|
|
|
|
if (fd != -1)
|
|
|
|
close(fd);
|
|
|
|
if (temp_fd != -1)
|
|
|
|
close(temp_fd);
|
2009-03-24 10:59:13 +00:00
|
|
|
if(temp_file)
|
|
|
|
unlink(temp_file);
|
|
|
|
VIR_FREE(temp_file);
|
2008-11-12 16:35:47 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2008-07-10 07:52:14 +00:00
|
|
|
int
|
2009-03-24 10:59:13 +00:00
|
|
|
openvzWriteVPSConfigParam(int vpsid, const char *param, const char *value)
|
|
|
|
{
|
|
|
|
char conf_file[PATH_MAX];
|
|
|
|
|
|
|
|
if (openvzLocateConfFile(vpsid, conf_file, PATH_MAX, "conf")<0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return openvzWriteConfigParam(conf_file, param, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
openvzReadConfigParam(const char * conf_file ,const char * param, char *value, int maxlen)
|
2008-07-10 07:52:14 +00:00
|
|
|
{
|
|
|
|
char line[PATH_MAX] ;
|
|
|
|
int ret, found = 0;
|
|
|
|
int fd ;
|
|
|
|
char * sf, * token;
|
|
|
|
char *saveptr = NULL;
|
|
|
|
|
|
|
|
value[0] = 0;
|
|
|
|
|
|
|
|
fd = open(conf_file, O_RDONLY);
|
2008-07-10 12:21:09 +00:00
|
|
|
if (fd == -1)
|
2008-07-10 07:52:14 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
while(1) {
|
|
|
|
ret = openvz_readline(fd, line, sizeof(line));
|
|
|
|
if(ret <= 0)
|
|
|
|
break;
|
|
|
|
saveptr = NULL;
|
2008-07-10 12:21:09 +00:00
|
|
|
if (STREQLEN(line, param, strlen(param))) {
|
2008-07-10 07:52:14 +00:00
|
|
|
sf = line;
|
|
|
|
sf += strlen(param);
|
2008-09-08 12:45:29 +00:00
|
|
|
if (sf[0] == '=' && sf[1] != '\0' ) {
|
|
|
|
sf ++;
|
|
|
|
if ((token = strtok_r(sf,"\"\t\n", &saveptr)) != NULL) {
|
|
|
|
strncpy(value, token, maxlen) ;
|
|
|
|
value[maxlen-1] = '\0';
|
|
|
|
found = 1;
|
|
|
|
}
|
2008-07-10 07:52:14 +00:00
|
|
|
}
|
2008-07-10 12:21:09 +00:00
|
|
|
}
|
2008-07-10 07:52:14 +00:00
|
|
|
}
|
|
|
|
close(fd);
|
|
|
|
|
|
|
|
if (ret == 0 && found)
|
|
|
|
ret = 1;
|
|
|
|
|
|
|
|
return ret ;
|
|
|
|
}
|
|
|
|
|
2009-03-24 10:59:13 +00:00
|
|
|
/*
|
|
|
|
* Read parameter from container config
|
|
|
|
* sample: 133, "OSTEMPLATE", value, 1024
|
|
|
|
* return: -1 - error
|
|
|
|
* 0 - don't found
|
|
|
|
* 1 - OK
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
openvzReadVPSConfigParam(int vpsid ,const char * param, char *value, int maxlen)
|
|
|
|
{
|
|
|
|
char conf_file[PATH_MAX] ;
|
|
|
|
|
|
|
|
if (openvzLocateConfFile(vpsid, conf_file, PATH_MAX, "conf")<0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return openvzReadConfigParam(conf_file, param, value, maxlen);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
openvz_copyfile(char* from_path, char* to_path)
|
|
|
|
{
|
|
|
|
char line[PATH_MAX];
|
|
|
|
int fd, copy_fd;
|
|
|
|
int bytes_read;
|
|
|
|
|
|
|
|
fd = open(from_path, O_RDONLY);
|
|
|
|
if (fd == -1)
|
|
|
|
return -1;
|
|
|
|
copy_fd = open(to_path, O_WRONLY | O_CREAT | O_TRUNC, 0644);
|
|
|
|
if (copy_fd == -1) {
|
|
|
|
close(fd);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
while(1) {
|
|
|
|
if (openvz_readline(fd, line, sizeof(line)) <= 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
bytes_read = strlen(line);
|
|
|
|
if (safewrite(copy_fd, line, bytes_read) != bytes_read)
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (close(fd) < 0)
|
|
|
|
goto error;
|
|
|
|
fd = -1;
|
|
|
|
if (close(copy_fd) < 0)
|
|
|
|
goto error;
|
|
|
|
copy_fd = -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
error:
|
|
|
|
if (fd != -1)
|
|
|
|
close(fd);
|
|
|
|
if (copy_fd != -1)
|
|
|
|
close(copy_fd);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copy the default config to the VE conf file
|
|
|
|
* return: -1 - error
|
|
|
|
* 0 - OK
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
openvzCopyDefaultConfig(int vpsid)
|
|
|
|
{
|
|
|
|
char * confdir = NULL;
|
|
|
|
char * default_conf_file = NULL;
|
|
|
|
char configfile_value[PATH_MAX];
|
|
|
|
char conf_file[PATH_MAX];
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
if(openvzReadConfigParam(VZ_CONF_FILE, "CONFIGFILE", configfile_value, PATH_MAX) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
confdir = openvzLocateConfDir();
|
|
|
|
if (confdir == NULL)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virAsprintf(&default_conf_file, "%s/ve-%s.conf-sample", confdir, configfile_value) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (openvzLocateConfFile(vpsid, conf_file, PATH_MAX, "conf")<0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (openvz_copyfile(default_conf_file, conf_file)<0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
cleanup:
|
|
|
|
VIR_FREE(confdir);
|
|
|
|
VIR_FREE(default_conf_file);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-07-11 08:56:16 +00:00
|
|
|
/* Locate config file of container
|
|
|
|
* return -1 - error
|
|
|
|
* 0 - OK
|
|
|
|
*/
|
|
|
|
static int
|
2008-11-12 16:35:47 +00:00
|
|
|
openvzLocateConfFile(int vpsid, char *conffile, int maxlen, const char *ext)
|
2008-07-11 08:56:16 +00:00
|
|
|
{
|
|
|
|
char * confdir;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
confdir = openvzLocateConfDir();
|
|
|
|
if (confdir == NULL)
|
|
|
|
return -1;
|
|
|
|
|
2008-11-12 16:35:47 +00:00
|
|
|
if (snprintf(conffile, maxlen, "%s/%d.%s",
|
|
|
|
confdir, vpsid, ext ? ext : "conf") >= maxlen)
|
2008-07-11 08:56:16 +00:00
|
|
|
ret = -1;
|
|
|
|
|
|
|
|
VIR_FREE(confdir);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-02-05 19:27:37 +00:00
|
|
|
static char
|
2007-07-19 16:22:40 +00:00
|
|
|
*openvzLocateConfDir(void)
|
2007-07-17 13:27:26 +00:00
|
|
|
{
|
|
|
|
const char *conf_dir_list[] = {"/etc/vz/conf", "/usr/local/etc/conf", NULL};
|
|
|
|
int i=0;
|
|
|
|
|
|
|
|
while(conf_dir_list[i]) {
|
|
|
|
if(!access(conf_dir_list[i], F_OK))
|
2008-04-10 16:54:54 +00:00
|
|
|
return strdup(conf_dir_list[i]);
|
2007-07-17 13:27:26 +00:00
|
|
|
i ++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Richard Steven's classic readline() function */
|
2008-02-05 19:27:37 +00:00
|
|
|
int
|
2007-07-19 16:22:40 +00:00
|
|
|
openvz_readline(int fd, char *ptr, int maxlen)
|
2007-07-17 13:27:26 +00:00
|
|
|
{
|
|
|
|
int n, rc;
|
|
|
|
char c;
|
|
|
|
|
|
|
|
for(n = 1; n < maxlen; n ++) {
|
|
|
|
if( (rc = read(fd, &c, 1)) == 1) {
|
|
|
|
*ptr++ = c;
|
|
|
|
if(c == '\n')
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if(rc == 0) {
|
|
|
|
if(n == 1)
|
|
|
|
return 0; /* EOF condition */
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return -1; /* error */
|
|
|
|
}
|
|
|
|
*ptr = 0;
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2008-02-05 19:27:37 +00:00
|
|
|
static int
|
2007-09-03 15:37:07 +00:00
|
|
|
openvzGetVPSUUID(int vpsid, char *uuidstr)
|
2007-07-17 13:27:26 +00:00
|
|
|
{
|
|
|
|
char conf_file[PATH_MAX];
|
|
|
|
char line[1024];
|
2007-09-03 15:37:07 +00:00
|
|
|
char uuidbuf[1024];
|
2007-07-17 13:27:26 +00:00
|
|
|
char iden[1024];
|
|
|
|
int fd, ret;
|
|
|
|
|
2008-11-12 16:35:47 +00:00
|
|
|
if (openvzLocateConfFile(vpsid, conf_file, PATH_MAX, "conf")<0)
|
2008-07-11 08:56:16 +00:00
|
|
|
return -1;
|
2007-07-17 13:27:26 +00:00
|
|
|
|
2008-07-11 08:56:16 +00:00
|
|
|
fd = open(conf_file, O_RDONLY);
|
2007-07-17 13:27:26 +00:00
|
|
|
if(fd == -1)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
while(1) {
|
|
|
|
ret = openvz_readline(fd, line, sizeof(line));
|
|
|
|
if(ret == -1)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if(ret == 0) { /* EoF, UUID was not found */
|
2007-09-03 15:37:07 +00:00
|
|
|
uuidstr[0] = 0;
|
2007-07-17 13:27:26 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-09-03 15:37:07 +00:00
|
|
|
sscanf(line, "%s %s\n", iden, uuidbuf);
|
2008-05-14 19:51:24 +00:00
|
|
|
if(STREQ(iden, "#UUID:")) {
|
2007-09-03 15:37:07 +00:00
|
|
|
strncpy(uuidstr, uuidbuf, VIR_UUID_STRING_BUFLEN);
|
2007-07-17 13:27:26 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-07-10 07:52:14 +00:00
|
|
|
close(fd);
|
|
|
|
|
2007-07-17 13:27:26 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Do actual checking for UUID presence in conf file,
|
|
|
|
* assign if not present.
|
|
|
|
*/
|
2008-08-05 10:53:05 +00:00
|
|
|
int
|
|
|
|
openvzSetDefinedUUID(int vpsid, unsigned char *uuid)
|
2007-07-17 13:27:26 +00:00
|
|
|
{
|
|
|
|
char conf_file[PATH_MAX];
|
2007-08-09 20:19:12 +00:00
|
|
|
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
2008-08-05 10:53:05 +00:00
|
|
|
|
|
|
|
if (uuid == NULL)
|
|
|
|
return -1;
|
2007-07-17 13:27:26 +00:00
|
|
|
|
2008-11-12 16:35:47 +00:00
|
|
|
if (openvzLocateConfFile(vpsid, conf_file, PATH_MAX, "conf")<0)
|
2008-07-11 08:56:16 +00:00
|
|
|
return -1;
|
2007-07-17 13:27:26 +00:00
|
|
|
|
2008-02-21 18:48:06 +00:00
|
|
|
if (openvzGetVPSUUID(vpsid, uuidstr))
|
2007-07-17 13:27:26 +00:00
|
|
|
return -1;
|
|
|
|
|
2008-02-21 18:48:06 +00:00
|
|
|
if (uuidstr[0] == 0) {
|
2008-04-10 16:54:54 +00:00
|
|
|
FILE *fp = fopen(conf_file, "a"); /* append */
|
|
|
|
if (fp == NULL)
|
|
|
|
return -1;
|
2007-07-17 13:27:26 +00:00
|
|
|
|
2007-08-09 20:19:12 +00:00
|
|
|
virUUIDFormat(uuid, uuidstr);
|
|
|
|
|
2008-04-10 16:54:54 +00:00
|
|
|
/* Record failure if fprintf or fclose fails,
|
|
|
|
and be careful always to close the stream. */
|
|
|
|
if ((fprintf(fp, "\n#UUID: %s\n", uuidstr) < 0)
|
|
|
|
+ (fclose(fp) == EOF))
|
|
|
|
return -1;
|
2007-07-17 13:27:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-08-05 10:53:05 +00:00
|
|
|
static int
|
|
|
|
openvzSetUUID(int vpsid){
|
|
|
|
unsigned char uuid[VIR_UUID_BUFLEN];
|
|
|
|
|
|
|
|
virUUIDGenerate(uuid);
|
|
|
|
|
|
|
|
return openvzSetDefinedUUID(vpsid, uuid);
|
|
|
|
}
|
|
|
|
|
2007-07-17 13:27:26 +00:00
|
|
|
/*
|
|
|
|
* Scan VPS config files and see if they have a UUID.
|
|
|
|
* If not, assign one. Just append one to the config
|
|
|
|
* file as comment so that the OpenVZ tools ignore it.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2008-09-05 14:10:58 +00:00
|
|
|
static int openvzAssignUUIDs(void)
|
2007-07-17 13:27:26 +00:00
|
|
|
{
|
|
|
|
DIR *dp;
|
|
|
|
struct dirent *dent;
|
|
|
|
char *conf_dir;
|
|
|
|
int vpsid, res;
|
|
|
|
char ext[8];
|
|
|
|
|
|
|
|
conf_dir = openvzLocateConfDir();
|
2008-02-21 18:22:45 +00:00
|
|
|
if (conf_dir == NULL)
|
|
|
|
return -1;
|
2007-07-17 13:27:26 +00:00
|
|
|
|
|
|
|
dp = opendir(conf_dir);
|
|
|
|
if(dp == NULL) {
|
2008-06-06 11:09:57 +00:00
|
|
|
VIR_FREE(conf_dir);
|
2007-07-17 13:27:26 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
while((dent = readdir(dp))) {
|
|
|
|
res = sscanf(dent->d_name, "%d.%5s", &vpsid, ext);
|
2008-05-14 19:51:24 +00:00
|
|
|
if(!(res == 2 && STREQ(ext, "conf")))
|
2007-07-17 13:27:26 +00:00
|
|
|
continue;
|
|
|
|
if(vpsid > 0) /* '0.conf' belongs to the host, ignore it */
|
|
|
|
openvzSetUUID(vpsid);
|
|
|
|
}
|
|
|
|
closedir(dp);
|
2008-06-06 11:09:57 +00:00
|
|
|
VIR_FREE(conf_dir);
|
2007-07-17 13:27:26 +00:00
|
|
|
return 0;
|
|
|
|
}
|