2008-03-21 15:03:37 +00:00
|
|
|
/*
|
|
|
|
* Copyright IBM Corp. 2008
|
|
|
|
*
|
|
|
|
* lxc_conf.c: config functions for managing linux containers
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* includes */
|
|
|
|
#include <config.h>
|
|
|
|
|
2008-08-13 12:50:55 +00:00
|
|
|
#include <sys/utsname.h>
|
2008-03-21 15:03:37 +00:00
|
|
|
|
|
|
|
#include "lxc_conf.h"
|
|
|
|
|
|
|
|
/* debug macros */
|
|
|
|
#define DEBUG(fmt,...) VIR_DEBUG(__FILE__, fmt, __VA_ARGS__)
|
|
|
|
#define DEBUG0(msg) VIR_DEBUG(__FILE__, "%s", msg)
|
|
|
|
|
|
|
|
/* Functions */
|
|
|
|
void lxcError(virConnectPtr conn, virDomainPtr dom, int code,
|
|
|
|
const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list args;
|
2008-08-13 12:50:55 +00:00
|
|
|
char errorMessage[1024];
|
2008-03-21 15:03:37 +00:00
|
|
|
const char *codeErrorMessage;
|
|
|
|
|
|
|
|
if (fmt) {
|
|
|
|
va_start(args, fmt);
|
2008-08-13 12:50:55 +00:00
|
|
|
vsnprintf(errorMessage, sizeof(errorMessage)-1, fmt, args);
|
2008-03-21 15:03:37 +00:00
|
|
|
va_end(args);
|
|
|
|
} else {
|
|
|
|
errorMessage[0] = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
codeErrorMessage = __virErrorMsg(code, fmt);
|
|
|
|
__virRaiseError(conn, dom, NULL, VIR_FROM_LXC, code, VIR_ERR_ERROR,
|
|
|
|
codeErrorMessage, errorMessage, NULL, 0, 0,
|
|
|
|
codeErrorMessage, errorMessage);
|
|
|
|
}
|
|
|
|
|
2008-08-13 12:50:55 +00:00
|
|
|
virCapsPtr lxcCapsInit(void)
|
2008-03-21 15:03:37 +00:00
|
|
|
{
|
2008-08-13 12:50:55 +00:00
|
|
|
struct utsname utsname;
|
|
|
|
virCapsPtr caps;
|
|
|
|
virCapsGuestPtr guest;
|
2008-06-05 06:03:00 +00:00
|
|
|
|
2008-08-13 12:50:55 +00:00
|
|
|
uname(&utsname);
|
2008-06-05 06:03:00 +00:00
|
|
|
|
2008-08-13 12:50:55 +00:00
|
|
|
if ((caps = virCapabilitiesNew(utsname.machine,
|
|
|
|
0, 0)) == NULL)
|
|
|
|
goto no_memory;
|
2008-03-21 15:03:37 +00:00
|
|
|
|
2008-08-13 12:50:55 +00:00
|
|
|
if ((guest = virCapabilitiesAddGuest(caps,
|
|
|
|
"exe",
|
|
|
|
utsname.machine,
|
|
|
|
sizeof(int) == 4 ? 32 : 8,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
0,
|
|
|
|
NULL)) == NULL)
|
|
|
|
goto no_memory;
|
2008-03-21 15:03:37 +00:00
|
|
|
|
2008-08-13 12:50:55 +00:00
|
|
|
if (virCapabilitiesAddGuestDomain(guest,
|
|
|
|
"lxc",
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
0,
|
|
|
|
NULL) == NULL)
|
|
|
|
goto no_memory;
|
|
|
|
return caps;
|
2008-03-21 15:03:37 +00:00
|
|
|
|
2008-08-13 12:50:55 +00:00
|
|
|
no_memory:
|
|
|
|
virCapabilitiesFree(caps);
|
2008-03-21 15:03:37 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2008-03-27 09:34:06 +00:00
|
|
|
int lxcLoadDriverConfig(lxc_driver_t *driver)
|
2008-03-21 15:03:37 +00:00
|
|
|
{
|
|
|
|
/* Set the container configuration directory */
|
2008-08-13 10:52:15 +00:00
|
|
|
if ((driver->configDir = strdup(SYSCONF_DIR "/libvirt/lxc")) == NULL)
|
|
|
|
goto no_memory;
|
|
|
|
if ((driver->stateDir = strdup(LOCAL_STATE_DIR "/run/libvirt/lxc")) == NULL)
|
|
|
|
goto no_memory;
|
|
|
|
if ((driver->logDir = strdup(LOCAL_STATE_DIR "/log/libvirt/lxc")) == NULL)
|
|
|
|
goto no_memory;
|
2008-06-05 06:03:00 +00:00
|
|
|
|
2008-03-21 15:03:37 +00:00
|
|
|
return 0;
|
2008-08-13 10:52:15 +00:00
|
|
|
|
|
|
|
no_memory:
|
|
|
|
lxcError(NULL, NULL, VIR_ERR_NO_MEMORY, "configDir");
|
|
|
|
return -1;
|
2008-03-21 15:03:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|