2008-08-13 10:25:34 +00:00
|
|
|
/*
|
2016-05-13 17:20:54 +00:00
|
|
|
* Copyright (C) 2010-2016 Red Hat, Inc.
|
2011-03-09 03:13:18 +00:00
|
|
|
* Copyright IBM Corp. 2008
|
2008-08-13 10:25:34 +00:00
|
|
|
*
|
|
|
|
* lxc_controller.c: linux container process controller
|
|
|
|
*
|
|
|
|
* 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
|
2012-09-20 22:30:55 +00:00
|
|
|
* License along with this library. If not, see
|
2012-07-21 10:06:23 +00:00
|
|
|
* <http://www.gnu.org/licenses/>.
|
2008-08-13 10:25:34 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include <sys/epoll.h>
|
2008-08-13 10:52:15 +00:00
|
|
|
#include <sys/wait.h>
|
|
|
|
#include <sys/socket.h>
|
2016-04-14 13:11:45 +00:00
|
|
|
|
|
|
|
#ifdef MAJOR_IN_MKDEV
|
|
|
|
# include <sys/mkdev.h>
|
|
|
|
#elif MAJOR_IN_SYSMACROS
|
|
|
|
# include <sys/sysmacros.h>
|
|
|
|
#endif
|
|
|
|
|
Make sure sys/types.h is included after sys/sysmacros.h
In the latest glibc, major() and minor() functions are marked as
deprecated (glibc commit dbab6577):
CC util/libvirt_util_la-vircgroup.lo
util/vircgroup.c: In function 'virCgroupGetBlockDevString':
util/vircgroup.c:768:5: error: '__major_from_sys_types' is deprecated:
In the GNU C Library, `major' is defined by <sys/sysmacros.h>.
For historical compatibility, it is currently defined by
<sys/types.h> as well, but we plan to remove this soon.
To use `major', include <sys/sysmacros.h> directly.
If you did not intend to use a system-defined macro `major',
you should #undef it after including <sys/types.h>.
[-Werror=deprecated-declarations]
if (virAsprintf(&ret, "%d:%d ", major(sb.st_rdev), minor(sb.st_rdev)) < 0)
^~
In file included from /usr/include/features.h:397:0,
from /usr/include/bits/libc-header-start.h:33,
from /usr/include/stdio.h:28,
from ../gnulib/lib/stdio.h:43,
from util/vircgroup.c:26:
/usr/include/sys/sysmacros.h:87:1: note: declared here
__SYSMACROS_DEFINE_MAJOR (__SYSMACROS_FST_IMPL_TEMPL)
^
Moreover, in the glibc commit, there's suggestion to keep
ordering of including of header files as implemented here.
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2016-09-06 12:20:04 +00:00
|
|
|
#include <sys/types.h>
|
2008-08-20 20:55:32 +00:00
|
|
|
#include <sys/un.h>
|
2011-02-23 17:17:53 +00:00
|
|
|
#include <sys/personality.h>
|
2008-08-13 10:25:34 +00:00
|
|
|
#include <unistd.h>
|
2011-02-22 17:35:06 +00:00
|
|
|
#include <errno.h>
|
2008-08-13 10:52:15 +00:00
|
|
|
#include <fcntl.h>
|
|
|
|
#include <signal.h>
|
2008-08-20 20:55:32 +00:00
|
|
|
#include <getopt.h>
|
2009-04-22 14:26:50 +00:00
|
|
|
#include <sys/mount.h>
|
2011-10-19 01:39:57 +00:00
|
|
|
#include <grp.h>
|
|
|
|
#include <sys/stat.h>
|
Initialize random generator in lxc controller
The lxc contoller eventually makes use of virRandomBits(), which was
segfaulting since virRandomInitialize() is never invoked.
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff554d560 in random_r () from /lib64/libc.so.6
(gdb) bt
0 0x00007ffff554d560 in random_r () from /lib64/libc.so.6
1 0x0000000000469eaa in virRandomBits (nbits=32) at util/virrandom.c:80
2 0x000000000045bf69 in virHashCreateFull (size=256,
dataFree=0x4aa2a2 <hashDataFree>, keyCode=0x45bd40 <virHashStrCode>,
keyEqual=0x45bdad <virHashStrEqual>, keyCopy=0x45bdfa <virHashStrCopy>,
keyFree=0x45be37 <virHashStrFree>) at util/virhash.c:134
3 0x000000000045c069 in virHashCreate (size=0, dataFree=0x4aa2a2 <hashDataFree>)
at util/virhash.c:164
4 0x00000000004aa562 in virNWFilterHashTableCreate (n=0)
at conf/nwfilter_params.c:686
5 0x00000000004aa95b in virNWFilterParseParamAttributes (cur=0x711d30)
at conf/nwfilter_params.c:793
6 0x0000000000481a7f in virDomainNetDefParseXML (caps=0x702c90, node=0x7116b0,
ctxt=0x7101b0, bootMap=0x0, flags=0) at conf/domain_conf.c:4589
7 0x000000000048cc36 in virDomainDefParseXML (caps=0x702c90, xml=0x710040,
root=0x7103b0, ctxt=0x7101b0, expectedVirtTypes=16, flags=0)
at conf/domain_conf.c:8658
8 0x000000000048f011 in virDomainDefParseNode (caps=0x702c90, xml=0x710040,
root=0x7103b0, expectedVirtTypes=16, flags=0) at conf/domain_conf.c:9360
9 0x000000000048ee30 in virDomainDefParse (xmlStr=0x0,
filename=0x702ae0 "/var/run/libvirt/lxc/x.xml", caps=0x702c90,
expectedVirtTypes=16, flags=0) at conf/domain_conf.c:9310
10 0x000000000048ef00 in virDomainDefParseFile (caps=0x702c90,
filename=0x702ae0 "/var/run/libvirt/lxc/x.xml", expectedVirtTypes=16, flags=0)
at conf/domain_conf.c:9332
11 0x0000000000425053 in main (argc=5, argv=0x7fffffffe2b8)
at lxc/lxc_controller.c:1773
2012-06-21 05:28:09 +00:00
|
|
|
#include <time.h>
|
2008-08-13 10:25:34 +00:00
|
|
|
|
2012-09-20 14:17:56 +00:00
|
|
|
#if WITH_CAPNG
|
2010-03-09 18:22:22 +00:00
|
|
|
# include <cap-ng.h>
|
2009-06-29 17:09:42 +00:00
|
|
|
#endif
|
|
|
|
|
2012-12-13 18:21:53 +00:00
|
|
|
#include "virerror.h"
|
2012-12-12 17:59:27 +00:00
|
|
|
#include "virlog.h"
|
2008-08-13 10:25:34 +00:00
|
|
|
|
|
|
|
#include "lxc_conf.h"
|
2008-08-13 10:52:15 +00:00
|
|
|
#include "lxc_container.h"
|
2012-07-13 11:21:27 +00:00
|
|
|
#include "lxc_cgroup.h"
|
2012-12-21 13:19:54 +00:00
|
|
|
#include "lxc_monitor_protocol.h"
|
2012-11-14 09:39:04 +00:00
|
|
|
#include "lxc_fuse.h"
|
2011-11-02 16:03:09 +00:00
|
|
|
#include "virnetdev.h"
|
|
|
|
#include "virnetdevveth.h"
|
2012-12-12 18:06:53 +00:00
|
|
|
#include "viralloc.h"
|
2011-07-19 18:32:58 +00:00
|
|
|
#include "virfile.h"
|
2011-08-05 13:13:12 +00:00
|
|
|
#include "virpidfile.h"
|
2012-12-12 16:27:01 +00:00
|
|
|
#include "vircommand.h"
|
2016-04-13 17:53:02 +00:00
|
|
|
#include "virhostcpu.h"
|
Initialize random generator in lxc controller
The lxc contoller eventually makes use of virRandomBits(), which was
segfaulting since virRandomInitialize() is never invoked.
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff554d560 in random_r () from /lib64/libc.so.6
(gdb) bt
0 0x00007ffff554d560 in random_r () from /lib64/libc.so.6
1 0x0000000000469eaa in virRandomBits (nbits=32) at util/virrandom.c:80
2 0x000000000045bf69 in virHashCreateFull (size=256,
dataFree=0x4aa2a2 <hashDataFree>, keyCode=0x45bd40 <virHashStrCode>,
keyEqual=0x45bdad <virHashStrEqual>, keyCopy=0x45bdfa <virHashStrCopy>,
keyFree=0x45be37 <virHashStrFree>) at util/virhash.c:134
3 0x000000000045c069 in virHashCreate (size=0, dataFree=0x4aa2a2 <hashDataFree>)
at util/virhash.c:164
4 0x00000000004aa562 in virNWFilterHashTableCreate (n=0)
at conf/nwfilter_params.c:686
5 0x00000000004aa95b in virNWFilterParseParamAttributes (cur=0x711d30)
at conf/nwfilter_params.c:793
6 0x0000000000481a7f in virDomainNetDefParseXML (caps=0x702c90, node=0x7116b0,
ctxt=0x7101b0, bootMap=0x0, flags=0) at conf/domain_conf.c:4589
7 0x000000000048cc36 in virDomainDefParseXML (caps=0x702c90, xml=0x710040,
root=0x7103b0, ctxt=0x7101b0, expectedVirtTypes=16, flags=0)
at conf/domain_conf.c:8658
8 0x000000000048f011 in virDomainDefParseNode (caps=0x702c90, xml=0x710040,
root=0x7103b0, expectedVirtTypes=16, flags=0) at conf/domain_conf.c:9360
9 0x000000000048ee30 in virDomainDefParse (xmlStr=0x0,
filename=0x702ae0 "/var/run/libvirt/lxc/x.xml", caps=0x702c90,
expectedVirtTypes=16, flags=0) at conf/domain_conf.c:9310
10 0x000000000048ef00 in virDomainDefParseFile (caps=0x702c90,
filename=0x702ae0 "/var/run/libvirt/lxc/x.xml", expectedVirtTypes=16, flags=0)
at conf/domain_conf.c:9332
11 0x0000000000425053 in main (argc=5, argv=0x7fffffffe2b8)
at lxc/lxc_controller.c:1773
2012-06-21 05:28:09 +00:00
|
|
|
#include "virrandom.h"
|
2012-09-24 17:10:37 +00:00
|
|
|
#include "virprocess.h"
|
2013-03-18 09:04:02 +00:00
|
|
|
#include "virnuma.h"
|
2013-10-11 14:57:31 +00:00
|
|
|
#include "virdbus.h"
|
2015-03-16 14:02:41 +00:00
|
|
|
#include "rpc/virnetdaemon.h"
|
2013-04-03 10:36:23 +00:00
|
|
|
#include "virstring.h"
|
2016-04-12 22:29:52 +00:00
|
|
|
#include "virgettext.h"
|
2008-08-13 10:25:34 +00:00
|
|
|
|
2009-01-20 17:13:33 +00:00
|
|
|
#define VIR_FROM_THIS VIR_FROM_LXC
|
|
|
|
|
2014-02-28 12:16:17 +00:00
|
|
|
VIR_LOG_INIT("lxc.lxc_controller");
|
|
|
|
|
2012-07-03 11:42:53 +00:00
|
|
|
typedef struct _virLXCControllerConsole virLXCControllerConsole;
|
|
|
|
typedef virLXCControllerConsole *virLXCControllerConsolePtr;
|
|
|
|
struct _virLXCControllerConsole {
|
|
|
|
int hostWatch;
|
|
|
|
int hostFd; /* PTY FD in the host OS */
|
|
|
|
bool hostClosed;
|
|
|
|
int hostEpoll;
|
|
|
|
|
|
|
|
int contWatch;
|
|
|
|
int contFd; /* PTY FD in the container */
|
|
|
|
bool contClosed;
|
|
|
|
int contEpoll;
|
|
|
|
|
|
|
|
int epollWatch;
|
|
|
|
int epollFd; /* epoll FD for dealing with EOF */
|
|
|
|
|
|
|
|
size_t fromHostLen;
|
|
|
|
char fromHostBuf[1024];
|
|
|
|
size_t fromContLen;
|
|
|
|
char fromContBuf[1024];
|
2012-11-16 09:11:23 +00:00
|
|
|
|
2015-03-16 14:02:41 +00:00
|
|
|
virNetDaemonPtr daemon;
|
2012-07-03 11:42:53 +00:00
|
|
|
};
|
|
|
|
|
2012-07-03 10:54:09 +00:00
|
|
|
typedef struct _virLXCController virLXCController;
|
|
|
|
typedef virLXCController *virLXCControllerPtr;
|
|
|
|
struct _virLXCController {
|
|
|
|
char *name;
|
2015-01-16 16:39:57 +00:00
|
|
|
virDomainObjPtr vm;
|
2012-07-03 10:54:09 +00:00
|
|
|
virDomainDefPtr def;
|
2012-07-03 11:06:38 +00:00
|
|
|
|
2012-07-03 12:16:48 +00:00
|
|
|
int handshakeFd;
|
|
|
|
|
2012-07-03 11:12:59 +00:00
|
|
|
pid_t initpid;
|
|
|
|
|
2015-05-26 16:29:27 +00:00
|
|
|
size_t nnbdpids;
|
|
|
|
pid_t *nbdpids;
|
|
|
|
|
2012-07-03 11:06:38 +00:00
|
|
|
size_t nveths;
|
|
|
|
char **veths;
|
2012-07-03 11:42:53 +00:00
|
|
|
|
2015-01-16 16:58:39 +00:00
|
|
|
size_t nnicindexes;
|
|
|
|
int *nicindexes;
|
|
|
|
|
2013-07-09 17:15:45 +00:00
|
|
|
size_t npassFDs;
|
|
|
|
int *passFDs;
|
|
|
|
|
2015-08-20 13:46:17 +00:00
|
|
|
int *nsFDs;
|
|
|
|
|
2012-07-03 11:42:53 +00:00
|
|
|
size_t nconsoles;
|
|
|
|
virLXCControllerConsolePtr consoles;
|
2012-07-03 13:02:33 +00:00
|
|
|
char *devptmx;
|
2012-07-03 12:49:19 +00:00
|
|
|
|
|
|
|
size_t nloopDevs;
|
|
|
|
int *loopDevFds;
|
2012-07-03 12:59:36 +00:00
|
|
|
|
|
|
|
virSecurityManagerPtr securityManager;
|
2012-07-03 13:40:45 +00:00
|
|
|
|
2015-03-16 14:02:41 +00:00
|
|
|
virNetDaemonPtr daemon;
|
2012-11-20 17:49:25 +00:00
|
|
|
bool firstClient;
|
2012-07-17 14:54:08 +00:00
|
|
|
virNetServerClientPtr client;
|
|
|
|
virNetServerProgramPtr prog;
|
|
|
|
bool inShutdown;
|
|
|
|
int timerShutdown;
|
2012-11-14 09:39:04 +00:00
|
|
|
|
2013-07-22 15:36:06 +00:00
|
|
|
virCgroupPtr cgroup;
|
|
|
|
|
2012-11-14 09:39:04 +00:00
|
|
|
virLXCFusePtr fuse;
|
2012-07-03 10:54:09 +00:00
|
|
|
};
|
|
|
|
|
2012-07-17 14:54:08 +00:00
|
|
|
#include "lxc_controller_dispatch.h"
|
|
|
|
|
2012-07-03 10:54:09 +00:00
|
|
|
static void virLXCControllerFree(virLXCControllerPtr ctrl);
|
2012-11-20 17:49:25 +00:00
|
|
|
static int virLXCControllerEventSendInit(virLXCControllerPtr ctrl,
|
|
|
|
pid_t initpid);
|
2012-07-03 10:54:09 +00:00
|
|
|
|
2012-07-17 14:54:08 +00:00
|
|
|
static void virLXCControllerQuitTimer(int timer ATTRIBUTE_UNUSED, void *opaque)
|
|
|
|
{
|
|
|
|
virLXCControllerPtr ctrl = opaque;
|
|
|
|
|
|
|
|
VIR_DEBUG("Triggering event loop quit");
|
2015-03-16 14:02:41 +00:00
|
|
|
virNetDaemonQuit(ctrl->daemon);
|
2012-07-17 14:54:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-07-03 10:54:09 +00:00
|
|
|
static virLXCControllerPtr virLXCControllerNew(const char *name)
|
|
|
|
{
|
|
|
|
virLXCControllerPtr ctrl = NULL;
|
|
|
|
virCapsPtr caps = NULL;
|
2013-03-31 18:03:42 +00:00
|
|
|
virDomainXMLOptionPtr xmlopt = NULL;
|
2012-07-03 10:54:09 +00:00
|
|
|
char *configFile = NULL;
|
|
|
|
|
2013-07-04 10:11:37 +00:00
|
|
|
if (VIR_ALLOC(ctrl) < 0)
|
2013-05-03 12:43:39 +00:00
|
|
|
goto error;
|
2012-07-03 10:54:09 +00:00
|
|
|
|
2012-07-17 14:54:08 +00:00
|
|
|
ctrl->timerShutdown = -1;
|
2012-11-20 17:49:25 +00:00
|
|
|
ctrl->firstClient = true;
|
2012-07-17 14:54:08 +00:00
|
|
|
|
2013-05-03 12:43:39 +00:00
|
|
|
if (VIR_STRDUP(ctrl->name, name) < 0)
|
|
|
|
goto error;
|
2012-07-03 10:54:09 +00:00
|
|
|
|
2013-07-15 09:43:10 +00:00
|
|
|
if (!(caps = virLXCDriverCapsInit(NULL)))
|
2012-07-03 10:54:09 +00:00
|
|
|
goto error;
|
|
|
|
|
2013-03-31 18:03:42 +00:00
|
|
|
if (!(xmlopt = lxcDomainXMLConfInit()))
|
2013-03-05 15:17:24 +00:00
|
|
|
goto error;
|
|
|
|
|
2012-07-03 10:54:09 +00:00
|
|
|
if ((configFile = virDomainConfigFile(LXC_STATE_DIR,
|
|
|
|
ctrl->name)) == NULL)
|
|
|
|
goto error;
|
|
|
|
|
2015-01-16 16:39:57 +00:00
|
|
|
if ((ctrl->vm = virDomainObjParseFile(configFile,
|
|
|
|
caps, xmlopt,
|
|
|
|
0)) == NULL)
|
2012-07-03 10:54:09 +00:00
|
|
|
goto error;
|
2015-01-16 16:39:57 +00:00
|
|
|
ctrl->def = ctrl->vm->def;
|
2012-07-03 10:54:09 +00:00
|
|
|
|
2012-07-17 14:54:08 +00:00
|
|
|
if ((ctrl->timerShutdown = virEventAddTimeout(-1,
|
|
|
|
virLXCControllerQuitTimer, ctrl,
|
|
|
|
NULL)) < 0)
|
|
|
|
goto error;
|
|
|
|
|
2014-03-25 06:49:26 +00:00
|
|
|
cleanup:
|
2012-07-03 10:54:09 +00:00
|
|
|
VIR_FREE(configFile);
|
2013-02-01 12:26:18 +00:00
|
|
|
virObjectUnref(caps);
|
2013-03-31 18:03:42 +00:00
|
|
|
virObjectUnref(xmlopt);
|
2012-07-03 10:54:09 +00:00
|
|
|
return ctrl;
|
|
|
|
|
2014-03-25 06:49:26 +00:00
|
|
|
error:
|
2012-07-03 10:54:09 +00:00
|
|
|
virLXCControllerFree(ctrl);
|
|
|
|
ctrl = NULL;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2012-07-03 11:12:59 +00:00
|
|
|
|
2013-03-15 15:07:13 +00:00
|
|
|
static int virLXCControllerCloseLoopDevices(virLXCControllerPtr ctrl)
|
2012-07-03 12:49:19 +00:00
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
|
2013-05-21 08:03:33 +00:00
|
|
|
for (i = 0; i < ctrl->nloopDevs; i++)
|
2013-03-15 15:07:13 +00:00
|
|
|
VIR_FORCE_CLOSE(ctrl->loopDevFds[i]);
|
2012-07-03 12:49:19 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-07-03 11:12:59 +00:00
|
|
|
static void virLXCControllerStopInit(virLXCControllerPtr ctrl)
|
|
|
|
{
|
|
|
|
if (ctrl->initpid == 0)
|
|
|
|
return;
|
|
|
|
|
2013-03-15 15:07:13 +00:00
|
|
|
virLXCControllerCloseLoopDevices(ctrl);
|
2012-09-24 16:59:31 +00:00
|
|
|
virProcessAbort(ctrl->initpid);
|
2012-07-03 11:12:59 +00:00
|
|
|
ctrl->initpid = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-07-03 11:42:53 +00:00
|
|
|
static void virLXCControllerConsoleClose(virLXCControllerConsolePtr console)
|
|
|
|
{
|
|
|
|
if (console->hostWatch != -1)
|
|
|
|
virEventRemoveHandle(console->hostWatch);
|
|
|
|
VIR_FORCE_CLOSE(console->hostFd);
|
|
|
|
|
|
|
|
if (console->contWatch != -1)
|
|
|
|
virEventRemoveHandle(console->contWatch);
|
|
|
|
VIR_FORCE_CLOSE(console->contFd);
|
|
|
|
|
|
|
|
if (console->epollWatch != -1)
|
|
|
|
virEventRemoveHandle(console->epollWatch);
|
|
|
|
VIR_FORCE_CLOSE(console->epollFd);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-11-14 09:39:04 +00:00
|
|
|
static void
|
|
|
|
virLXCControllerFreeFuse(virLXCControllerPtr ctrl)
|
|
|
|
{
|
|
|
|
return lxcFreeFuse(&ctrl->fuse);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-07-03 10:54:09 +00:00
|
|
|
static void virLXCControllerFree(virLXCControllerPtr ctrl)
|
|
|
|
{
|
2012-07-03 11:06:38 +00:00
|
|
|
size_t i;
|
|
|
|
|
2012-07-03 10:54:09 +00:00
|
|
|
if (!ctrl)
|
|
|
|
return;
|
|
|
|
|
2012-07-03 11:12:59 +00:00
|
|
|
virLXCControllerStopInit(ctrl);
|
|
|
|
|
2013-02-05 17:54:55 +00:00
|
|
|
virObjectUnref(ctrl->securityManager);
|
2012-07-03 12:59:36 +00:00
|
|
|
|
2013-05-21 08:03:33 +00:00
|
|
|
for (i = 0; i < ctrl->nveths; i++)
|
2012-07-03 11:06:38 +00:00
|
|
|
VIR_FREE(ctrl->veths[i]);
|
|
|
|
VIR_FREE(ctrl->veths);
|
2015-01-16 16:58:39 +00:00
|
|
|
VIR_FREE(ctrl->nicindexes);
|
2012-07-03 11:06:38 +00:00
|
|
|
|
2013-07-09 17:15:45 +00:00
|
|
|
for (i = 0; i < ctrl->npassFDs; i++)
|
|
|
|
VIR_FORCE_CLOSE(ctrl->passFDs[i]);
|
|
|
|
VIR_FREE(ctrl->passFDs);
|
|
|
|
|
2013-05-21 08:03:33 +00:00
|
|
|
for (i = 0; i < ctrl->nconsoles; i++)
|
2012-07-03 11:42:53 +00:00
|
|
|
virLXCControllerConsoleClose(&(ctrl->consoles[i]));
|
|
|
|
VIR_FREE(ctrl->consoles);
|
|
|
|
|
2012-07-03 13:02:33 +00:00
|
|
|
VIR_FREE(ctrl->devptmx);
|
|
|
|
|
2018-03-26 22:21:59 +00:00
|
|
|
virDomainObjEndAPI(&ctrl->vm);
|
2012-07-03 10:54:09 +00:00
|
|
|
VIR_FREE(ctrl->name);
|
|
|
|
|
2012-07-17 14:54:08 +00:00
|
|
|
if (ctrl->timerShutdown != -1)
|
|
|
|
virEventRemoveTimeout(ctrl->timerShutdown);
|
|
|
|
|
2015-03-16 14:02:41 +00:00
|
|
|
virObjectUnref(ctrl->daemon);
|
2012-11-14 09:39:04 +00:00
|
|
|
virLXCControllerFreeFuse(ctrl);
|
2012-07-03 13:40:45 +00:00
|
|
|
|
2015-05-26 16:29:27 +00:00
|
|
|
VIR_FREE(ctrl->nbdpids);
|
|
|
|
|
2015-08-20 13:46:17 +00:00
|
|
|
VIR_FREE(ctrl->nsFDs);
|
2013-07-22 15:36:06 +00:00
|
|
|
virCgroupFree(&ctrl->cgroup);
|
|
|
|
|
2013-03-04 20:47:37 +00:00
|
|
|
/* This must always be the last thing to be closed */
|
|
|
|
VIR_FORCE_CLOSE(ctrl->handshakeFd);
|
2012-07-03 10:54:09 +00:00
|
|
|
VIR_FREE(ctrl);
|
|
|
|
}
|
|
|
|
|
2012-07-03 11:06:38 +00:00
|
|
|
|
2012-07-03 11:42:53 +00:00
|
|
|
static int virLXCControllerAddConsole(virLXCControllerPtr ctrl,
|
|
|
|
int hostFd)
|
|
|
|
{
|
2013-07-04 10:11:37 +00:00
|
|
|
if (VIR_EXPAND_N(ctrl->consoles, ctrl->nconsoles, 1) < 0)
|
2012-07-03 11:42:53 +00:00
|
|
|
return -1;
|
2015-03-16 14:02:41 +00:00
|
|
|
ctrl->consoles[ctrl->nconsoles-1].daemon = ctrl->daemon;
|
2012-07-03 11:42:53 +00:00
|
|
|
ctrl->consoles[ctrl->nconsoles-1].hostFd = hostFd;
|
|
|
|
ctrl->consoles[ctrl->nconsoles-1].hostWatch = -1;
|
|
|
|
|
|
|
|
ctrl->consoles[ctrl->nconsoles-1].contFd = -1;
|
|
|
|
ctrl->consoles[ctrl->nconsoles-1].contWatch = -1;
|
|
|
|
|
|
|
|
ctrl->consoles[ctrl->nconsoles-1].epollFd = -1;
|
|
|
|
ctrl->consoles[ctrl->nconsoles-1].epollWatch = -1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int virLXCControllerConsoleSetNonblocking(virLXCControllerConsolePtr console)
|
|
|
|
{
|
|
|
|
if (virSetBlocking(console->hostFd, false) < 0 ||
|
|
|
|
virSetBlocking(console->contFd, false) < 0) {
|
|
|
|
virReportSystemError(errno, "%s",
|
|
|
|
_("Unable to set console file descriptor non-blocking"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-07-03 12:16:48 +00:00
|
|
|
static int virLXCControllerDaemonHandshake(virLXCControllerPtr ctrl)
|
|
|
|
{
|
|
|
|
if (lxcContainerSendContinue(ctrl->handshakeFd) < 0) {
|
|
|
|
virReportSystemError(errno, "%s",
|
|
|
|
_("error sending continue signal to daemon"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
VIR_FORCE_CLOSE(ctrl->handshakeFd);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-07-03 11:06:38 +00:00
|
|
|
static int virLXCControllerValidateNICs(virLXCControllerPtr ctrl)
|
|
|
|
{
|
|
|
|
if (ctrl->def->nnets != ctrl->nveths) {
|
2012-07-13 12:59:51 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
2012-09-26 15:12:28 +00:00
|
|
|
_("expecting %zu veths, but got %zu"),
|
2012-07-13 12:59:51 +00:00
|
|
|
ctrl->def->nnets, ctrl->nveths);
|
2012-07-03 11:06:38 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-01-16 16:58:39 +00:00
|
|
|
static int virLXCControllerGetNICIndexes(virLXCControllerPtr ctrl)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
VIR_DEBUG("Getting nic indexes");
|
|
|
|
for (i = 0; i < ctrl->def->nnets; i++) {
|
|
|
|
int nicindex = -1;
|
|
|
|
switch (ctrl->def->nets[i]->type) {
|
|
|
|
case VIR_DOMAIN_NET_TYPE_BRIDGE:
|
|
|
|
case VIR_DOMAIN_NET_TYPE_NETWORK:
|
2016-05-13 17:20:54 +00:00
|
|
|
case VIR_DOMAIN_NET_TYPE_ETHERNET:
|
2015-01-16 16:58:39 +00:00
|
|
|
if (ctrl->def->nets[i]->ifname == NULL)
|
|
|
|
continue;
|
|
|
|
if (virNetDevGetIndex(ctrl->def->nets[i]->ifname,
|
|
|
|
&nicindex) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
if (VIR_EXPAND_N(ctrl->nicindexes,
|
|
|
|
ctrl->nnicindexes,
|
|
|
|
1) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
VIR_DEBUG("Index %d for %s", nicindex,
|
|
|
|
ctrl->def->nets[i]->ifname);
|
|
|
|
ctrl->nicindexes[ctrl->nnicindexes-1] = nicindex;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VIR_DOMAIN_NET_TYPE_USER:
|
|
|
|
case VIR_DOMAIN_NET_TYPE_VHOSTUSER:
|
|
|
|
case VIR_DOMAIN_NET_TYPE_SERVER:
|
|
|
|
case VIR_DOMAIN_NET_TYPE_CLIENT:
|
|
|
|
case VIR_DOMAIN_NET_TYPE_MCAST:
|
2015-08-29 20:19:10 +00:00
|
|
|
case VIR_DOMAIN_NET_TYPE_UDP:
|
2015-01-16 16:58:39 +00:00
|
|
|
case VIR_DOMAIN_NET_TYPE_INTERNAL:
|
|
|
|
case VIR_DOMAIN_NET_TYPE_DIRECT:
|
|
|
|
case VIR_DOMAIN_NET_TYPE_HOSTDEV:
|
2018-02-14 09:43:59 +00:00
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
|
|
|
_("Unsupported net type %s"),
|
|
|
|
virDomainNetTypeToString(ctrl->def->nets[i]->type));
|
|
|
|
goto cleanup;
|
|
|
|
case VIR_DOMAIN_NET_TYPE_LAST:
|
2015-01-16 16:58:39 +00:00
|
|
|
default:
|
2018-02-14 09:43:59 +00:00
|
|
|
virReportEnumRangeError(virDomainNetType, ctrl->def->nets[i]->type);
|
|
|
|
goto cleanup;
|
2015-01-16 16:58:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
cleanup:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-07-03 11:42:53 +00:00
|
|
|
static int virLXCControllerValidateConsoles(virLXCControllerPtr ctrl)
|
|
|
|
{
|
|
|
|
if (ctrl->def->nconsoles != ctrl->nconsoles) {
|
2012-07-13 12:59:51 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
2012-09-26 15:12:28 +00:00
|
|
|
_("expecting %zu consoles, but got %zu tty file handlers"),
|
2012-07-13 12:59:51 +00:00
|
|
|
ctrl->def->nconsoles, ctrl->nconsoles);
|
2012-07-03 11:42:53 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-04 18:09:23 +00:00
|
|
|
static int virLXCControllerSetupLoopDeviceFS(virDomainFSDefPtr fs)
|
2011-08-04 09:13:02 +00:00
|
|
|
{
|
2012-07-03 14:06:27 +00:00
|
|
|
int lofd;
|
2011-08-04 09:13:02 +00:00
|
|
|
char *loname = NULL;
|
|
|
|
|
2016-07-14 13:52:38 +00:00
|
|
|
if ((lofd = virFileLoopDeviceAssociate(fs->src->path, &loname)) < 0)
|
2011-08-04 09:13:02 +00:00
|
|
|
return -1;
|
|
|
|
|
2013-10-08 15:36:26 +00:00
|
|
|
VIR_DEBUG("Changing fs %s to use type=block for dev %s",
|
2016-07-14 13:52:38 +00:00
|
|
|
fs->src->path, loname);
|
2011-08-04 09:13:02 +00:00
|
|
|
/*
|
|
|
|
* We now change it into a block device type, so that
|
|
|
|
* the rest of container setup 'just works'
|
|
|
|
*/
|
|
|
|
fs->type = VIR_DOMAIN_FS_TYPE_BLOCK;
|
2016-07-14 13:52:38 +00:00
|
|
|
VIR_FREE(fs->src->path);
|
|
|
|
fs->src->path = loname;
|
2011-08-04 09:13:02 +00:00
|
|
|
loname = NULL;
|
|
|
|
|
|
|
|
return lofd;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-04 18:09:23 +00:00
|
|
|
static int virLXCControllerSetupLoopDeviceDisk(virDomainDiskDefPtr disk)
|
|
|
|
{
|
|
|
|
int lofd;
|
|
|
|
char *loname = NULL;
|
2014-03-17 20:49:05 +00:00
|
|
|
const char *src = virDomainDiskGetSource(disk);
|
2014-03-25 17:09:05 +00:00
|
|
|
int ret = -1;
|
2013-03-04 18:09:23 +00:00
|
|
|
|
2014-03-17 20:49:05 +00:00
|
|
|
if ((lofd = virFileLoopDeviceAssociate(src, &loname)) < 0)
|
2013-03-04 18:09:23 +00:00
|
|
|
return -1;
|
|
|
|
|
2013-10-08 15:36:26 +00:00
|
|
|
VIR_DEBUG("Changing disk %s to use type=block for dev %s",
|
2014-03-17 20:49:05 +00:00
|
|
|
src, loname);
|
2013-10-08 15:36:26 +00:00
|
|
|
|
2013-03-04 18:09:23 +00:00
|
|
|
/*
|
|
|
|
* We now change it into a block device type, so that
|
|
|
|
* the rest of container setup 'just works'
|
|
|
|
*/
|
conf: move host disk type to util/
A continuation of the migration of disk details to virstoragefile.
This patch moves a single enum, but converting the name has quite
a bit of fallout.
* src/conf/domain_conf.h (virDomainDiskType): Move...
* src/util/virstoragefile.h (virStorageType): ...and rename.
* src/bhyve/bhyve_command.c (bhyveBuildDiskArgStr)
(virBhyveProcessBuildLoadCmd): Update clients.
* src/conf/domain_conf.c (virDomainDiskSourceDefParse)
(virDomainDiskDefParseXML, virDomainDiskSourceDefFormatInternal)
(virDomainDiskDefFormat, virDomainDiskGetActualType)
(virDomainDiskDefForeachPath, virDomainDiskSourceIsBlockType):
Likewise.
* src/conf/snapshot_conf.h (_virDomainSnapshotDiskDef): Likewise.
* src/conf/snapshot_conf.c (virDomainSnapshotDiskDefParseXML)
(virDomainSnapshotAlignDisks, virDomainSnapshotDiskDefFormat):
Likewise.
* src/esx/esx_driver.c (esxAutodetectSCSIControllerModel)
(esxDomainDefineXML): Likewise.
* src/locking/domain_lock.c (virDomainLockManagerAddDisk):
Likewise.
* src/lxc/lxc_controller.c
(virLXCControllerSetupLoopDeviceDisk)
(virLXCControllerSetupNBDDeviceDisk)
(virLXCControllerSetupLoopDevices, virLXCControllerSetupDisk):
Likewise.
* src/parallels/parallels_driver.c (parallelsGetHddInfo):
Likewise.
* src/phyp/phyp_driver.c (phypDiskType): Likewise.
* src/qemu/qemu_command.c (qemuGetDriveSourceString)
(qemuDomainDiskGetSourceString, qemuBuildDriveStr)
(qemuBuildCommandLine, qemuParseCommandLineDisk)
(qemuParseCommandLine): Likewise.
* src/qemu/qemu_conf.c (qemuCheckSharedDevice)
(qemuTranslateDiskSourcePool)
(qemuTranslateSnapshotDiskSourcePool): Likewise.
* src/qemu/qemu_domain.c (qemuDomainDeviceDefPostParse)
(qemuDomainDetermineDiskChain): Likewise.
* src/qemu/qemu_driver.c (qemuDomainGetBlockInfo)
(qemuDomainSnapshotPrepareDiskExternalBackingInactive)
(qemuDomainSnapshotPrepareDiskExternalBackingActive)
(qemuDomainSnapshotPrepareDiskExternalOverlayActive)
(qemuDomainSnapshotPrepareDiskExternalOverlayInactive)
(qemuDomainSnapshotPrepareDiskInternal)
(qemuDomainSnapshotPrepare)
(qemuDomainSnapshotCreateSingleDiskActive): Likewise.
* src/qemu/qemu_hotplug.c (qemuDomainChangeEjectableMedia):
Likewise.
* src/qemu/qemu_migration.c (qemuMigrationIsSafe): Likewise.
* src/security/security_apparmor.c
(AppArmorRestoreSecurityImageLabel)
(AppArmorSetSecurityImageLabel): Likewise.
* src/security/security_dac.c (virSecurityDACSetSecurityImageLabel)
(virSecurityDACRestoreSecurityImageLabelInt)
(virSecurityDACSetSecurityAllLabel): Likewise.
* src/security/security_selinux.c
(virSecuritySELinuxRestoreSecurityImageLabelInt)
(virSecuritySELinuxSetSecurityImageLabel)
(virSecuritySELinuxSetSecurityAllLabel): Likewise.
* src/storage/storage_backend.c (virStorageFileBackendForType):
Likewise.
* src/storage/storage_backend_fs.c (virStorageFileBackendFile)
(virStorageFileBackendBlock): Likewise.
* src/storage/storage_backend_gluster.c
(virStorageFileBackendGluster): Likewise.
* src/vbox/vbox_tmpl.c (vboxDomainGetXMLDesc, vboxAttachDrives)
(vboxDomainAttachDeviceImpl, vboxDomainDetachDevice): Likewise.
* src/vmware/vmware_conf.c (vmwareVmxPath): Likewise.
* src/vmx/vmx.c (virVMXParseDisk, virVMXFormatDisk)
(virVMXFormatFloppy): Likewise.
* src/xenxs/xen_sxpr.c (xenParseSxprDisks, xenParseSxpr)
(xenFormatSxprDisk): Likewise.
* src/xenxs/xen_xm.c (xenParseXM, xenFormatXMDisk): Likewise.
* tests/securityselinuxlabeltest.c (testSELinuxLoadDef):
Likewise.
* src/libvirt_private.syms (domain_conf.h): Move symbols...
(virstoragefile.h): ...as appropriate.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-03-27 21:57:49 +00:00
|
|
|
virDomainDiskSetType(disk, VIR_STORAGE_TYPE_BLOCK);
|
2014-03-25 17:09:05 +00:00
|
|
|
if (virDomainDiskSetSource(disk, loname) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
cleanup:
|
2014-03-17 20:49:05 +00:00
|
|
|
VIR_FREE(loname);
|
2014-03-25 17:09:05 +00:00
|
|
|
if (ret < 0)
|
2015-05-12 12:40:34 +00:00
|
|
|
VIR_FORCE_CLOSE(lofd);
|
2013-03-04 18:09:23 +00:00
|
|
|
|
|
|
|
return lofd;
|
2014-03-25 17:09:05 +00:00
|
|
|
|
2013-03-04 18:09:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-22 14:06:18 +00:00
|
|
|
static int virLXCControllerSetupNBDDeviceFS(virDomainFSDefPtr fs)
|
|
|
|
{
|
|
|
|
char *dev;
|
|
|
|
|
|
|
|
if (fs->format <= VIR_STORAGE_FILE_NONE) {
|
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
|
|
|
_("An explicit disk format must be specified"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2016-07-14 13:52:38 +00:00
|
|
|
if (virFileNBDDeviceAssociate(fs->src->path,
|
2013-04-22 14:06:18 +00:00
|
|
|
fs->format,
|
|
|
|
fs->readonly,
|
|
|
|
&dev) < 0)
|
|
|
|
return -1;
|
|
|
|
|
2013-10-08 15:36:26 +00:00
|
|
|
VIR_DEBUG("Changing fs %s to use type=block for dev %s",
|
2016-07-14 13:52:38 +00:00
|
|
|
fs->src->path, dev);
|
2013-04-22 14:06:18 +00:00
|
|
|
/*
|
|
|
|
* We now change it into a block device type, so that
|
|
|
|
* the rest of container setup 'just works'
|
|
|
|
*/
|
2013-10-08 15:36:49 +00:00
|
|
|
fs->type = VIR_DOMAIN_FS_TYPE_BLOCK;
|
2016-07-14 13:52:38 +00:00
|
|
|
VIR_FREE(fs->src->path);
|
|
|
|
fs->src->path = dev;
|
2013-04-22 14:06:18 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int virLXCControllerSetupNBDDeviceDisk(virDomainDiskDefPtr disk)
|
|
|
|
{
|
|
|
|
char *dev;
|
2014-03-17 20:49:05 +00:00
|
|
|
const char *src = virDomainDiskGetSource(disk);
|
|
|
|
int format = virDomainDiskGetFormat(disk);
|
2013-04-22 14:06:18 +00:00
|
|
|
|
2014-03-17 20:49:05 +00:00
|
|
|
if (format <= VIR_STORAGE_FILE_NONE) {
|
2013-04-22 14:06:18 +00:00
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
|
|
|
_("An explicit disk format must be specified"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-03-17 20:49:05 +00:00
|
|
|
if (virFileNBDDeviceAssociate(src,
|
|
|
|
format,
|
2014-06-24 13:15:55 +00:00
|
|
|
disk->src->readonly,
|
2013-04-22 14:06:18 +00:00
|
|
|
&dev) < 0)
|
|
|
|
return -1;
|
|
|
|
|
2013-10-08 15:36:26 +00:00
|
|
|
VIR_DEBUG("Changing disk %s to use type=block for dev %s",
|
2014-03-17 20:49:05 +00:00
|
|
|
src, dev);
|
2013-04-22 14:06:18 +00:00
|
|
|
/*
|
|
|
|
* We now change it into a block device type, so that
|
|
|
|
* the rest of container setup 'just works'
|
|
|
|
*/
|
conf: move host disk type to util/
A continuation of the migration of disk details to virstoragefile.
This patch moves a single enum, but converting the name has quite
a bit of fallout.
* src/conf/domain_conf.h (virDomainDiskType): Move...
* src/util/virstoragefile.h (virStorageType): ...and rename.
* src/bhyve/bhyve_command.c (bhyveBuildDiskArgStr)
(virBhyveProcessBuildLoadCmd): Update clients.
* src/conf/domain_conf.c (virDomainDiskSourceDefParse)
(virDomainDiskDefParseXML, virDomainDiskSourceDefFormatInternal)
(virDomainDiskDefFormat, virDomainDiskGetActualType)
(virDomainDiskDefForeachPath, virDomainDiskSourceIsBlockType):
Likewise.
* src/conf/snapshot_conf.h (_virDomainSnapshotDiskDef): Likewise.
* src/conf/snapshot_conf.c (virDomainSnapshotDiskDefParseXML)
(virDomainSnapshotAlignDisks, virDomainSnapshotDiskDefFormat):
Likewise.
* src/esx/esx_driver.c (esxAutodetectSCSIControllerModel)
(esxDomainDefineXML): Likewise.
* src/locking/domain_lock.c (virDomainLockManagerAddDisk):
Likewise.
* src/lxc/lxc_controller.c
(virLXCControllerSetupLoopDeviceDisk)
(virLXCControllerSetupNBDDeviceDisk)
(virLXCControllerSetupLoopDevices, virLXCControllerSetupDisk):
Likewise.
* src/parallels/parallels_driver.c (parallelsGetHddInfo):
Likewise.
* src/phyp/phyp_driver.c (phypDiskType): Likewise.
* src/qemu/qemu_command.c (qemuGetDriveSourceString)
(qemuDomainDiskGetSourceString, qemuBuildDriveStr)
(qemuBuildCommandLine, qemuParseCommandLineDisk)
(qemuParseCommandLine): Likewise.
* src/qemu/qemu_conf.c (qemuCheckSharedDevice)
(qemuTranslateDiskSourcePool)
(qemuTranslateSnapshotDiskSourcePool): Likewise.
* src/qemu/qemu_domain.c (qemuDomainDeviceDefPostParse)
(qemuDomainDetermineDiskChain): Likewise.
* src/qemu/qemu_driver.c (qemuDomainGetBlockInfo)
(qemuDomainSnapshotPrepareDiskExternalBackingInactive)
(qemuDomainSnapshotPrepareDiskExternalBackingActive)
(qemuDomainSnapshotPrepareDiskExternalOverlayActive)
(qemuDomainSnapshotPrepareDiskExternalOverlayInactive)
(qemuDomainSnapshotPrepareDiskInternal)
(qemuDomainSnapshotPrepare)
(qemuDomainSnapshotCreateSingleDiskActive): Likewise.
* src/qemu/qemu_hotplug.c (qemuDomainChangeEjectableMedia):
Likewise.
* src/qemu/qemu_migration.c (qemuMigrationIsSafe): Likewise.
* src/security/security_apparmor.c
(AppArmorRestoreSecurityImageLabel)
(AppArmorSetSecurityImageLabel): Likewise.
* src/security/security_dac.c (virSecurityDACSetSecurityImageLabel)
(virSecurityDACRestoreSecurityImageLabelInt)
(virSecurityDACSetSecurityAllLabel): Likewise.
* src/security/security_selinux.c
(virSecuritySELinuxRestoreSecurityImageLabelInt)
(virSecuritySELinuxSetSecurityImageLabel)
(virSecuritySELinuxSetSecurityAllLabel): Likewise.
* src/storage/storage_backend.c (virStorageFileBackendForType):
Likewise.
* src/storage/storage_backend_fs.c (virStorageFileBackendFile)
(virStorageFileBackendBlock): Likewise.
* src/storage/storage_backend_gluster.c
(virStorageFileBackendGluster): Likewise.
* src/vbox/vbox_tmpl.c (vboxDomainGetXMLDesc, vboxAttachDrives)
(vboxDomainAttachDeviceImpl, vboxDomainDetachDevice): Likewise.
* src/vmware/vmware_conf.c (vmwareVmxPath): Likewise.
* src/vmx/vmx.c (virVMXParseDisk, virVMXFormatDisk)
(virVMXFormatFloppy): Likewise.
* src/xenxs/xen_sxpr.c (xenParseSxprDisks, xenParseSxpr)
(xenFormatSxprDisk): Likewise.
* src/xenxs/xen_xm.c (xenParseXM, xenFormatXMDisk): Likewise.
* tests/securityselinuxlabeltest.c (testSELinuxLoadDef):
Likewise.
* src/libvirt_private.syms (domain_conf.h): Move symbols...
(virstoragefile.h): ...as appropriate.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-03-27 21:57:49 +00:00
|
|
|
virDomainDiskSetType(disk, VIR_STORAGE_TYPE_BLOCK);
|
2014-03-17 20:49:05 +00:00
|
|
|
if (virDomainDiskSetSource(disk, dev) < 0) {
|
|
|
|
VIR_FREE(dev);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
VIR_FREE(dev);
|
2013-04-22 14:06:18 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-05-26 16:29:27 +00:00
|
|
|
static int virLXCControllerAppendNBDPids(virLXCControllerPtr ctrl,
|
|
|
|
const char *dev)
|
|
|
|
{
|
|
|
|
char *pidpath = NULL;
|
2015-07-15 07:58:18 +00:00
|
|
|
pid_t *pids = NULL;
|
|
|
|
size_t npids = 0;
|
2015-05-26 16:29:27 +00:00
|
|
|
size_t i;
|
|
|
|
int ret = -1;
|
2015-07-15 08:13:21 +00:00
|
|
|
size_t loops = 0;
|
2015-05-26 16:29:27 +00:00
|
|
|
pid_t pid;
|
|
|
|
|
|
|
|
if (!STRPREFIX(dev, "/dev/") ||
|
|
|
|
virAsprintf(&pidpath, "/sys/devices/virtual/block/%s/pid", dev + 5) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2015-07-15 08:13:21 +00:00
|
|
|
/* Wait for the pid file to appear */
|
|
|
|
while (!virFileExists(pidpath)) {
|
|
|
|
/* wait for 100ms before checking again, but don't do it for ever */
|
|
|
|
if (errno == ENOENT && loops < 10) {
|
|
|
|
usleep(100 * 1000);
|
|
|
|
loops++;
|
|
|
|
} else {
|
|
|
|
virReportSystemError(errno,
|
|
|
|
_("Cannot check NBD device %s pid"),
|
|
|
|
dev + 5);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-26 16:29:27 +00:00
|
|
|
if (virPidFileReadPath(pidpath, &pid) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virProcessGetPids(pid, &npids, &pids) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
for (i = 0; i < npids; i++) {
|
|
|
|
if (VIR_APPEND_ELEMENT(ctrl->nbdpids, ctrl->nnbdpids, pids[i]) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
VIR_FREE(pids);
|
|
|
|
VIR_FREE(pidpath);
|
|
|
|
return ret;
|
|
|
|
}
|
2013-04-22 14:06:18 +00:00
|
|
|
|
2012-07-03 12:49:19 +00:00
|
|
|
static int virLXCControllerSetupLoopDevices(virLXCControllerPtr ctrl)
|
2011-08-04 09:13:02 +00:00
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
int ret = -1;
|
|
|
|
|
2013-07-09 13:24:10 +00:00
|
|
|
VIR_DEBUG("Setting up loop devices for filesystems");
|
|
|
|
|
2013-05-21 08:03:33 +00:00
|
|
|
for (i = 0; i < ctrl->def->nfss; i++) {
|
2013-03-04 18:02:42 +00:00
|
|
|
virDomainFSDefPtr fs = ctrl->def->fss[i];
|
2011-08-04 09:13:02 +00:00
|
|
|
int fd;
|
|
|
|
|
2013-03-04 18:02:42 +00:00
|
|
|
if (fs->type != VIR_DOMAIN_FS_TYPE_FILE)
|
2011-08-04 09:13:02 +00:00
|
|
|
continue;
|
|
|
|
|
2013-07-09 13:23:06 +00:00
|
|
|
if (fs->fsdriver == VIR_DOMAIN_FS_DRIVER_TYPE_DEFAULT) {
|
|
|
|
if (fs->format == VIR_STORAGE_FILE_RAW ||
|
|
|
|
fs->format == VIR_STORAGE_FILE_NONE)
|
|
|
|
fs->fsdriver = VIR_DOMAIN_FS_DRIVER_TYPE_LOOP;
|
|
|
|
else
|
|
|
|
fs->fsdriver = VIR_DOMAIN_FS_DRIVER_TYPE_NBD;
|
|
|
|
}
|
|
|
|
|
2013-04-22 14:06:15 +00:00
|
|
|
if (fs->fsdriver == VIR_DOMAIN_FS_DRIVER_TYPE_LOOP) {
|
|
|
|
if (fs->format != VIR_STORAGE_FILE_RAW &&
|
|
|
|
fs->format != VIR_STORAGE_FILE_NONE) {
|
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
|
|
|
_("fs format %s is not supported"),
|
|
|
|
virStorageFileFormatTypeToString(fs->format));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
fd = virLXCControllerSetupLoopDeviceFS(fs);
|
|
|
|
if (fd < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
VIR_DEBUG("Saving loop fd %d", fd);
|
|
|
|
if (VIR_EXPAND_N(ctrl->loopDevFds, ctrl->nloopDevs, 1) < 0) {
|
|
|
|
VIR_FORCE_CLOSE(fd);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
ctrl->loopDevFds[ctrl->nloopDevs - 1] = fd;
|
2013-04-22 14:06:18 +00:00
|
|
|
} else if (fs->fsdriver == VIR_DOMAIN_FS_DRIVER_TYPE_NBD) {
|
|
|
|
if (virLXCControllerSetupNBDDeviceFS(fs) < 0)
|
|
|
|
goto cleanup;
|
2015-05-26 16:29:27 +00:00
|
|
|
|
|
|
|
/* The NBD device will be cleaned up while the cgroup will end.
|
|
|
|
* For this we need to remember the qemu-nbd pid and add it to
|
|
|
|
* the cgroup*/
|
2016-07-14 13:52:38 +00:00
|
|
|
if (virLXCControllerAppendNBDPids(ctrl, fs->src->path) < 0)
|
2015-05-26 16:29:27 +00:00
|
|
|
goto cleanup;
|
2013-04-22 14:06:15 +00:00
|
|
|
} else {
|
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
|
|
|
_("fs driver %s is not supported"),
|
2014-05-14 19:48:15 +00:00
|
|
|
virDomainFSDriverTypeToString(fs->fsdriver));
|
2013-07-09 13:24:10 +00:00
|
|
|
goto cleanup;
|
2011-08-04 09:13:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-09 13:24:10 +00:00
|
|
|
VIR_DEBUG("Setting up loop devices for disks");
|
|
|
|
|
2013-05-21 08:03:33 +00:00
|
|
|
for (i = 0; i < ctrl->def->ndisks; i++) {
|
2013-03-04 18:09:23 +00:00
|
|
|
virDomainDiskDefPtr disk = ctrl->def->disks[i];
|
|
|
|
int fd;
|
2014-03-17 20:49:05 +00:00
|
|
|
const char *driver = virDomainDiskGetDriver(disk);
|
|
|
|
int format = virDomainDiskGetFormat(disk);
|
2013-03-04 18:09:23 +00:00
|
|
|
|
conf: move host disk type to util/
A continuation of the migration of disk details to virstoragefile.
This patch moves a single enum, but converting the name has quite
a bit of fallout.
* src/conf/domain_conf.h (virDomainDiskType): Move...
* src/util/virstoragefile.h (virStorageType): ...and rename.
* src/bhyve/bhyve_command.c (bhyveBuildDiskArgStr)
(virBhyveProcessBuildLoadCmd): Update clients.
* src/conf/domain_conf.c (virDomainDiskSourceDefParse)
(virDomainDiskDefParseXML, virDomainDiskSourceDefFormatInternal)
(virDomainDiskDefFormat, virDomainDiskGetActualType)
(virDomainDiskDefForeachPath, virDomainDiskSourceIsBlockType):
Likewise.
* src/conf/snapshot_conf.h (_virDomainSnapshotDiskDef): Likewise.
* src/conf/snapshot_conf.c (virDomainSnapshotDiskDefParseXML)
(virDomainSnapshotAlignDisks, virDomainSnapshotDiskDefFormat):
Likewise.
* src/esx/esx_driver.c (esxAutodetectSCSIControllerModel)
(esxDomainDefineXML): Likewise.
* src/locking/domain_lock.c (virDomainLockManagerAddDisk):
Likewise.
* src/lxc/lxc_controller.c
(virLXCControllerSetupLoopDeviceDisk)
(virLXCControllerSetupNBDDeviceDisk)
(virLXCControllerSetupLoopDevices, virLXCControllerSetupDisk):
Likewise.
* src/parallels/parallels_driver.c (parallelsGetHddInfo):
Likewise.
* src/phyp/phyp_driver.c (phypDiskType): Likewise.
* src/qemu/qemu_command.c (qemuGetDriveSourceString)
(qemuDomainDiskGetSourceString, qemuBuildDriveStr)
(qemuBuildCommandLine, qemuParseCommandLineDisk)
(qemuParseCommandLine): Likewise.
* src/qemu/qemu_conf.c (qemuCheckSharedDevice)
(qemuTranslateDiskSourcePool)
(qemuTranslateSnapshotDiskSourcePool): Likewise.
* src/qemu/qemu_domain.c (qemuDomainDeviceDefPostParse)
(qemuDomainDetermineDiskChain): Likewise.
* src/qemu/qemu_driver.c (qemuDomainGetBlockInfo)
(qemuDomainSnapshotPrepareDiskExternalBackingInactive)
(qemuDomainSnapshotPrepareDiskExternalBackingActive)
(qemuDomainSnapshotPrepareDiskExternalOverlayActive)
(qemuDomainSnapshotPrepareDiskExternalOverlayInactive)
(qemuDomainSnapshotPrepareDiskInternal)
(qemuDomainSnapshotPrepare)
(qemuDomainSnapshotCreateSingleDiskActive): Likewise.
* src/qemu/qemu_hotplug.c (qemuDomainChangeEjectableMedia):
Likewise.
* src/qemu/qemu_migration.c (qemuMigrationIsSafe): Likewise.
* src/security/security_apparmor.c
(AppArmorRestoreSecurityImageLabel)
(AppArmorSetSecurityImageLabel): Likewise.
* src/security/security_dac.c (virSecurityDACSetSecurityImageLabel)
(virSecurityDACRestoreSecurityImageLabelInt)
(virSecurityDACSetSecurityAllLabel): Likewise.
* src/security/security_selinux.c
(virSecuritySELinuxRestoreSecurityImageLabelInt)
(virSecuritySELinuxSetSecurityImageLabel)
(virSecuritySELinuxSetSecurityAllLabel): Likewise.
* src/storage/storage_backend.c (virStorageFileBackendForType):
Likewise.
* src/storage/storage_backend_fs.c (virStorageFileBackendFile)
(virStorageFileBackendBlock): Likewise.
* src/storage/storage_backend_gluster.c
(virStorageFileBackendGluster): Likewise.
* src/vbox/vbox_tmpl.c (vboxDomainGetXMLDesc, vboxAttachDrives)
(vboxDomainAttachDeviceImpl, vboxDomainDetachDevice): Likewise.
* src/vmware/vmware_conf.c (vmwareVmxPath): Likewise.
* src/vmx/vmx.c (virVMXParseDisk, virVMXFormatDisk)
(virVMXFormatFloppy): Likewise.
* src/xenxs/xen_sxpr.c (xenParseSxprDisks, xenParseSxpr)
(xenFormatSxprDisk): Likewise.
* src/xenxs/xen_xm.c (xenParseXM, xenFormatXMDisk): Likewise.
* tests/securityselinuxlabeltest.c (testSELinuxLoadDef):
Likewise.
* src/libvirt_private.syms (domain_conf.h): Move symbols...
(virstoragefile.h): ...as appropriate.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-03-27 21:57:49 +00:00
|
|
|
if (virDomainDiskGetType(disk) != VIR_STORAGE_TYPE_FILE)
|
2013-03-04 18:09:23 +00:00
|
|
|
continue;
|
|
|
|
|
2013-04-22 14:06:18 +00:00
|
|
|
/* If no driverName is set, we prefer 'loop' for
|
|
|
|
* dealing with raw or undefined formats, otherwise
|
|
|
|
* we use 'nbd'.
|
|
|
|
*/
|
2014-03-17 20:49:05 +00:00
|
|
|
if (STREQ_NULLABLE(driver, "loop") ||
|
|
|
|
(!driver &&
|
|
|
|
(format == VIR_STORAGE_FILE_RAW ||
|
|
|
|
format == VIR_STORAGE_FILE_NONE))) {
|
|
|
|
if (format != VIR_STORAGE_FILE_RAW &&
|
|
|
|
format != VIR_STORAGE_FILE_NONE) {
|
2013-03-04 18:09:23 +00:00
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
2013-04-22 14:06:15 +00:00
|
|
|
_("disk format %s is not supported"),
|
2014-03-17 20:49:05 +00:00
|
|
|
virStorageFileFormatTypeToString(format));
|
2013-03-04 18:09:23 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2013-04-22 14:06:15 +00:00
|
|
|
/* We treat 'none' as meaning 'raw' since we
|
|
|
|
* don't want to go into the auto-probing
|
|
|
|
* business for security reasons
|
|
|
|
*/
|
2013-03-04 18:09:23 +00:00
|
|
|
fd = virLXCControllerSetupLoopDeviceDisk(disk);
|
|
|
|
if (fd < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2013-04-22 14:06:15 +00:00
|
|
|
VIR_DEBUG("Saving loop fd %d", fd);
|
|
|
|
if (VIR_EXPAND_N(ctrl->loopDevFds, ctrl->nloopDevs, 1) < 0) {
|
|
|
|
VIR_FORCE_CLOSE(fd);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
ctrl->loopDevFds[ctrl->nloopDevs - 1] = fd;
|
2014-03-17 20:49:05 +00:00
|
|
|
} else if (!driver || STREQ(driver, "nbd")) {
|
2013-04-22 14:06:18 +00:00
|
|
|
if (disk->cachemode != VIR_DOMAIN_DISK_CACHE_DEFAULT &&
|
|
|
|
disk->cachemode != VIR_DOMAIN_DISK_CACHE_DISABLE) {
|
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
|
|
|
_("Disk cache mode %s is not supported"),
|
|
|
|
virDomainDiskCacheTypeToString(disk->cachemode));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
if (virLXCControllerSetupNBDDeviceDisk(disk) < 0)
|
|
|
|
goto cleanup;
|
2015-05-26 16:29:27 +00:00
|
|
|
|
|
|
|
/* The NBD device will be cleaned up while the cgroup will end.
|
|
|
|
* For this we need to remember the qemu-nbd pid and add it to
|
|
|
|
* the cgroup*/
|
|
|
|
if (virLXCControllerAppendNBDPids(ctrl, virDomainDiskGetSource(disk)) < 0)
|
|
|
|
goto cleanup;
|
2013-04-22 14:06:15 +00:00
|
|
|
} else {
|
2013-03-04 18:09:23 +00:00
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
2013-04-22 14:06:15 +00:00
|
|
|
_("disk driver %s is not supported"),
|
2014-03-17 20:49:05 +00:00
|
|
|
driver);
|
2013-07-09 13:24:10 +00:00
|
|
|
goto cleanup;
|
2013-03-04 18:09:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-04 09:13:02 +00:00
|
|
|
VIR_DEBUG("Setup all loop devices");
|
|
|
|
ret = 0;
|
|
|
|
|
2014-03-25 06:49:26 +00:00
|
|
|
cleanup:
|
2011-08-04 09:13:02 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-11-10 11:54:53 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* To be run while still single threaded
|
|
|
|
*/
|
2012-07-03 13:53:59 +00:00
|
|
|
static int virLXCControllerSetupCpuAffinity(virLXCControllerPtr ctrl)
|
2011-11-10 11:54:53 +00:00
|
|
|
{
|
2012-09-14 07:47:01 +00:00
|
|
|
int hostcpus, maxcpu = CPU_SETSIZE;
|
|
|
|
virBitmapPtr cpumap, cpumapToSet;
|
2011-11-10 11:54:53 +00:00
|
|
|
|
|
|
|
VIR_DEBUG("Setting CPU affinity");
|
|
|
|
|
|
|
|
/* setaffinity fails if you set bits for CPUs which
|
|
|
|
* aren't present, so we have to limit ourselves */
|
2016-04-13 17:16:16 +00:00
|
|
|
if ((hostcpus = virHostCPUGetCount()) < 0)
|
2012-11-13 12:54:37 +00:00
|
|
|
return -1;
|
|
|
|
|
2011-11-10 11:54:53 +00:00
|
|
|
if (maxcpu > hostcpus)
|
|
|
|
maxcpu = hostcpus;
|
|
|
|
|
2012-09-14 07:46:59 +00:00
|
|
|
cpumap = virBitmapNew(maxcpu);
|
|
|
|
if (!cpumap)
|
2011-11-10 11:54:53 +00:00
|
|
|
return -1;
|
|
|
|
|
2012-09-14 07:47:01 +00:00
|
|
|
cpumapToSet = cpumap;
|
|
|
|
|
2012-07-03 13:53:59 +00:00
|
|
|
if (ctrl->def->cpumask) {
|
2012-09-14 07:47:01 +00:00
|
|
|
cpumapToSet = ctrl->def->cpumask;
|
2011-11-10 11:54:53 +00:00
|
|
|
} else {
|
|
|
|
/* You may think this is redundant, but we can't assume libvirtd
|
|
|
|
* itself is running on all pCPUs, so we need to explicitly set
|
|
|
|
* the spawned LXC instance to all pCPUs if no map is given in
|
|
|
|
* its config file */
|
2012-09-14 07:46:59 +00:00
|
|
|
virBitmapSetAll(cpumap);
|
2011-11-10 11:54:53 +00:00
|
|
|
}
|
|
|
|
|
2012-09-14 07:46:59 +00:00
|
|
|
/* We are presuming we are running between fork/exec of LXC
|
2011-11-10 11:54:53 +00:00
|
|
|
* so use '0' to indicate our own process ID. No threads are
|
|
|
|
* running at this point
|
|
|
|
*/
|
2012-12-13 14:58:41 +00:00
|
|
|
if (virProcessSetAffinity(0 /* Self */, cpumapToSet) < 0) {
|
2012-09-14 07:46:59 +00:00
|
|
|
virBitmapFree(cpumap);
|
2011-11-10 11:54:53 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2012-09-14 07:46:59 +00:00
|
|
|
virBitmapFree(cpumap);
|
2011-11-10 11:54:53 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-18 09:04:02 +00:00
|
|
|
static int virLXCControllerGetNumadAdvice(virLXCControllerPtr ctrl,
|
|
|
|
virBitmapPtr *mask)
|
|
|
|
{
|
|
|
|
virBitmapPtr nodemask = NULL;
|
2013-03-22 11:44:00 +00:00
|
|
|
char *nodeset = NULL;
|
2013-03-18 09:04:02 +00:00
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
/* Get the advisory nodeset from numad if 'placement' of
|
|
|
|
* either <vcpu> or <numatune> is 'auto'.
|
|
|
|
*/
|
2014-06-09 13:00:22 +00:00
|
|
|
if (virDomainDefNeedsPlacementAdvice(ctrl->def)) {
|
2015-10-22 12:59:03 +00:00
|
|
|
nodeset = virNumaGetAutoPlacementAdvice(virDomainDefGetVcpus(ctrl->def),
|
2013-03-18 09:04:02 +00:00
|
|
|
ctrl->def->mem.cur_balloon);
|
|
|
|
if (!nodeset)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
VIR_DEBUG("Nodeset returned from numad: %s", nodeset);
|
|
|
|
|
2016-06-17 12:56:45 +00:00
|
|
|
if (virBitmapParse(nodeset, &nodemask, VIR_DOMAIN_CPUMASK_LEN) < 0)
|
2013-03-18 09:04:02 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
*mask = nodemask;
|
|
|
|
|
2014-03-25 06:49:26 +00:00
|
|
|
cleanup:
|
2013-03-18 09:04:02 +00:00
|
|
|
VIR_FREE(nodeset);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-11-10 12:38:24 +00:00
|
|
|
/**
|
2012-07-03 13:53:59 +00:00
|
|
|
* virLXCControllerSetupResourceLimits
|
|
|
|
* @ctrl: the controller state
|
2011-11-10 12:38:24 +00:00
|
|
|
*
|
2015-01-16 16:23:45 +00:00
|
|
|
* Sets up the non-cgroup based resource limits that need
|
|
|
|
* to be inherited by the child process across clone()/exec().
|
|
|
|
* The cgroup limits are setup later
|
2011-11-10 12:38:24 +00:00
|
|
|
*
|
|
|
|
* Returns 0 on success or -1 in case of error
|
|
|
|
*/
|
2013-07-22 15:36:06 +00:00
|
|
|
static int virLXCControllerSetupResourceLimits(virLXCControllerPtr ctrl)
|
2011-11-10 12:38:24 +00:00
|
|
|
{
|
2014-11-06 11:16:54 +00:00
|
|
|
virBitmapPtr auto_nodeset = NULL;
|
2013-03-18 09:04:02 +00:00
|
|
|
int ret = -1;
|
2014-11-06 11:16:54 +00:00
|
|
|
virBitmapPtr nodeset = NULL;
|
|
|
|
virDomainNumatuneMemMode mode;
|
|
|
|
|
2015-05-19 09:55:26 +00:00
|
|
|
if (virDomainNumatuneGetMode(ctrl->def->numa, -1, &mode) == 0) {
|
|
|
|
if (mode == VIR_DOMAIN_NUMATUNE_MEM_STRICT &&
|
|
|
|
virCgroupControllerAvailable(VIR_CGROUP_CONTROLLER_CPUSET)) {
|
|
|
|
/* Use virNuma* API iff necessary. Once set and child is exec()-ed,
|
|
|
|
* there's no way for us to change it. Rely on cgroups (if available
|
|
|
|
* and enabled in the config) rather than virNuma*. */
|
|
|
|
VIR_DEBUG("Relying on CGroups for memory binding");
|
|
|
|
} else {
|
2014-11-06 11:16:54 +00:00
|
|
|
|
2015-05-19 09:55:26 +00:00
|
|
|
VIR_DEBUG("Setting up process resource limits");
|
2013-03-18 09:04:02 +00:00
|
|
|
|
2015-05-19 09:55:26 +00:00
|
|
|
if (virLXCControllerGetNumadAdvice(ctrl, &auto_nodeset) < 0)
|
|
|
|
goto cleanup;
|
2015-03-27 10:44:55 +00:00
|
|
|
|
2015-05-19 09:55:26 +00:00
|
|
|
nodeset = virDomainNumatuneGetNodeset(ctrl->def->numa, auto_nodeset, -1);
|
2015-03-27 10:44:55 +00:00
|
|
|
|
2015-05-19 09:55:26 +00:00
|
|
|
if (virNumaSetupMemoryPolicy(mode, nodeset) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2015-03-27 10:44:55 +00:00
|
|
|
}
|
2011-11-10 12:38:24 +00:00
|
|
|
|
2012-07-03 13:53:59 +00:00
|
|
|
if (virLXCControllerSetupCpuAffinity(ctrl) < 0)
|
2013-03-18 09:04:02 +00:00
|
|
|
goto cleanup;
|
2011-11-10 12:38:24 +00:00
|
|
|
|
2015-01-16 16:23:45 +00:00
|
|
|
ret = 0;
|
|
|
|
cleanup:
|
|
|
|
virBitmapFree(auto_nodeset);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Creates the cgroup and sets up the various limits associated
|
|
|
|
* with it
|
|
|
|
*/
|
|
|
|
static int virLXCControllerSetupCgroupLimits(virLXCControllerPtr ctrl)
|
|
|
|
{
|
|
|
|
virBitmapPtr auto_nodeset = NULL;
|
|
|
|
int ret = -1;
|
|
|
|
virBitmapPtr nodeset = NULL;
|
2015-05-26 16:29:27 +00:00
|
|
|
size_t i;
|
2015-01-16 16:23:45 +00:00
|
|
|
|
|
|
|
VIR_DEBUG("Setting up cgroup resource limits");
|
|
|
|
|
|
|
|
if (virLXCControllerGetNumadAdvice(ctrl, &auto_nodeset) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2015-02-11 13:54:59 +00:00
|
|
|
nodeset = virDomainNumatuneGetNodeset(ctrl->def->numa, auto_nodeset, -1);
|
2015-01-16 16:23:45 +00:00
|
|
|
|
|
|
|
if (!(ctrl->cgroup = virLXCCgroupCreate(ctrl->def,
|
2015-01-16 16:58:39 +00:00
|
|
|
ctrl->initpid,
|
|
|
|
ctrl->nnicindexes,
|
|
|
|
ctrl->nicindexes)))
|
2015-01-16 16:23:45 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2017-01-05 15:26:00 +00:00
|
|
|
if (virCgroupAddMachineTask(ctrl->cgroup, getpid()) < 0)
|
2015-01-16 16:23:45 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2015-05-26 16:29:27 +00:00
|
|
|
/* Add all qemu-nbd tasks to the cgroup */
|
|
|
|
for (i = 0; i < ctrl->nnbdpids; i++) {
|
2017-01-05 15:26:00 +00:00
|
|
|
if (virCgroupAddMachineTask(ctrl->cgroup, ctrl->nbdpids[i]) < 0)
|
2015-05-26 16:29:27 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2014-11-06 11:16:54 +00:00
|
|
|
if (virLXCCgroupSetup(ctrl->def, ctrl->cgroup, nodeset) < 0)
|
2013-03-18 09:04:02 +00:00
|
|
|
goto cleanup;
|
2011-11-10 12:38:24 +00:00
|
|
|
|
2013-03-18 09:04:02 +00:00
|
|
|
ret = 0;
|
2014-03-25 06:49:26 +00:00
|
|
|
cleanup:
|
2014-11-06 11:16:54 +00:00
|
|
|
virBitmapFree(auto_nodeset);
|
2013-03-18 09:04:02 +00:00
|
|
|
return ret;
|
2008-10-03 16:46:01 +00:00
|
|
|
}
|
|
|
|
|
2008-12-23 13:03:29 +00:00
|
|
|
|
2012-07-17 14:54:08 +00:00
|
|
|
static void virLXCControllerClientCloseHook(virNetServerClientPtr client)
|
|
|
|
{
|
|
|
|
virLXCControllerPtr ctrl = virNetServerClientGetPrivateData(client);
|
|
|
|
|
|
|
|
VIR_DEBUG("Client %p has closed", client);
|
|
|
|
if (ctrl->client == client)
|
|
|
|
ctrl->client = NULL;
|
|
|
|
if (ctrl->inShutdown) {
|
|
|
|
VIR_DEBUG("Arm timer to quit event loop");
|
|
|
|
virEventUpdateTimeout(ctrl->timerShutdown, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-09 11:31:34 +00:00
|
|
|
static void virLXCControllerClientPrivateFree(void *data)
|
|
|
|
{
|
2012-11-22 16:45:39 +00:00
|
|
|
virLXCControllerPtr ctrl = data;
|
|
|
|
VIR_DEBUG("Got private data free %p", ctrl);
|
2012-08-09 11:31:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void *virLXCControllerClientPrivateNew(virNetServerClientPtr client,
|
|
|
|
void *opaque)
|
2012-07-03 14:25:30 +00:00
|
|
|
{
|
|
|
|
virLXCControllerPtr ctrl = opaque;
|
2012-08-09 11:31:34 +00:00
|
|
|
|
2012-07-17 14:54:08 +00:00
|
|
|
virNetServerClientSetCloseHook(client, virLXCControllerClientCloseHook);
|
|
|
|
VIR_DEBUG("Got new client %p", client);
|
|
|
|
ctrl->client = client;
|
2012-11-20 17:49:25 +00:00
|
|
|
|
|
|
|
if (ctrl->initpid && ctrl->firstClient)
|
|
|
|
virLXCControllerEventSendInit(ctrl, ctrl->initpid);
|
|
|
|
ctrl->firstClient = false;
|
|
|
|
|
2012-11-22 16:45:39 +00:00
|
|
|
return ctrl;
|
2008-08-20 20:55:32 +00:00
|
|
|
}
|
|
|
|
|
2012-07-03 14:25:30 +00:00
|
|
|
|
|
|
|
static int virLXCControllerSetupServer(virLXCControllerPtr ctrl)
|
2008-08-20 20:55:32 +00:00
|
|
|
{
|
2015-03-16 14:02:41 +00:00
|
|
|
virNetServerPtr srv = NULL;
|
2012-07-03 14:25:30 +00:00
|
|
|
virNetServerServicePtr svc = NULL;
|
|
|
|
char *sockpath;
|
2008-08-20 20:55:32 +00:00
|
|
|
|
2012-07-03 14:25:30 +00:00
|
|
|
if (virAsprintf(&sockpath, "%s/%s.sock",
|
2013-07-04 10:11:37 +00:00
|
|
|
LXC_STATE_DIR, ctrl->name) < 0)
|
2012-07-03 14:25:30 +00:00
|
|
|
return -1;
|
2008-08-20 20:55:32 +00:00
|
|
|
|
2016-04-13 18:54:40 +00:00
|
|
|
if (!(srv = virNetServerNew("LXC", 1,
|
2016-03-01 14:34:15 +00:00
|
|
|
0, 0, 0, 1,
|
2015-07-20 12:51:24 +00:00
|
|
|
0, -1, 0,
|
2015-03-16 14:02:41 +00:00
|
|
|
NULL,
|
|
|
|
virLXCControllerClientPrivateNew,
|
|
|
|
NULL,
|
|
|
|
virLXCControllerClientPrivateFree,
|
|
|
|
ctrl)))
|
2009-08-03 12:37:44 +00:00
|
|
|
goto error;
|
2008-08-20 20:55:32 +00:00
|
|
|
|
2014-01-08 03:03:01 +00:00
|
|
|
if (virSecurityManagerSetSocketLabel(ctrl->securityManager, ctrl->def) < 0)
|
|
|
|
goto error;
|
|
|
|
|
2012-07-03 14:25:30 +00:00
|
|
|
if (!(svc = virNetServerServiceNewUNIX(sockpath,
|
|
|
|
0700,
|
|
|
|
0,
|
|
|
|
0,
|
2013-01-08 21:02:05 +00:00
|
|
|
#if WITH_GNUTLS
|
2013-01-07 14:54:18 +00:00
|
|
|
NULL,
|
|
|
|
#endif
|
2012-07-03 14:25:30 +00:00
|
|
|
false,
|
2013-07-25 12:45:38 +00:00
|
|
|
0,
|
2013-01-07 14:54:18 +00:00
|
|
|
5)))
|
2008-08-20 20:55:32 +00:00
|
|
|
goto error;
|
2012-07-03 14:25:30 +00:00
|
|
|
|
2014-01-08 03:03:01 +00:00
|
|
|
if (virSecurityManagerClearSocketLabel(ctrl->securityManager, ctrl->def) < 0)
|
|
|
|
goto error;
|
|
|
|
|
2015-03-16 14:02:41 +00:00
|
|
|
if (virNetServerAddService(srv, svc, NULL) < 0)
|
2008-08-20 20:55:32 +00:00
|
|
|
goto error;
|
2012-07-11 13:35:52 +00:00
|
|
|
virObjectUnref(svc);
|
2012-07-03 14:25:30 +00:00
|
|
|
svc = NULL;
|
2008-08-20 20:55:32 +00:00
|
|
|
|
2013-03-13 19:19:22 +00:00
|
|
|
if (!(ctrl->prog = virNetServerProgramNew(VIR_LXC_MONITOR_PROGRAM,
|
|
|
|
VIR_LXC_MONITOR_PROGRAM_VERSION,
|
|
|
|
virLXCMonitorProcs,
|
|
|
|
virLXCMonitorNProcs)))
|
2012-07-17 14:54:08 +00:00
|
|
|
goto error;
|
|
|
|
|
2015-03-16 14:02:41 +00:00
|
|
|
if (!(ctrl->daemon = virNetDaemonNew()) ||
|
2016-03-01 14:40:31 +00:00
|
|
|
virNetDaemonAddServer(ctrl->daemon, srv) < 0)
|
2015-03-16 14:02:41 +00:00
|
|
|
goto error;
|
|
|
|
|
|
|
|
virNetDaemonUpdateServices(ctrl->daemon, true);
|
2012-07-03 14:25:30 +00:00
|
|
|
VIR_FREE(sockpath);
|
|
|
|
return 0;
|
2008-08-20 20:55:32 +00:00
|
|
|
|
2014-03-25 06:49:26 +00:00
|
|
|
error:
|
2012-07-03 14:25:30 +00:00
|
|
|
VIR_FREE(sockpath);
|
2015-03-16 14:02:41 +00:00
|
|
|
virObjectUnref(srv);
|
|
|
|
virObjectUnref(ctrl->daemon);
|
|
|
|
ctrl->daemon = NULL;
|
2012-07-11 13:35:52 +00:00
|
|
|
virObjectUnref(svc);
|
2008-08-20 20:55:32 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2008-08-13 10:25:34 +00:00
|
|
|
|
2009-06-29 17:09:42 +00:00
|
|
|
|
|
|
|
static int lxcControllerClearCapabilities(void)
|
|
|
|
{
|
2012-09-20 14:17:56 +00:00
|
|
|
#if WITH_CAPNG
|
2009-06-29 17:09:42 +00:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
capng_clear(CAPNG_SELECT_BOTH);
|
|
|
|
|
|
|
|
if ((ret = capng_apply(CAPNG_SELECT_BOTH)) < 0) {
|
2012-07-13 12:59:51 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("failed to apply capabilities: %d"), ret);
|
2009-06-29 17:09:42 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
#else
|
2011-05-09 09:24:09 +00:00
|
|
|
VIR_WARN("libcap-ng support not compiled in, unable to clear capabilities");
|
2009-06-29 17:09:42 +00:00
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-10-28 18:38:04 +00:00
|
|
|
static bool wantReboot;
|
2014-03-25 14:54:44 +00:00
|
|
|
static virMutex lock = VIR_MUTEX_INITIALIZER;
|
2011-10-19 15:22:24 +00:00
|
|
|
|
|
|
|
|
2015-06-16 12:59:33 +00:00
|
|
|
static void virLXCControllerSignalChildIO(virNetDaemonPtr dmn,
|
2012-07-03 14:25:30 +00:00
|
|
|
siginfo_t *info ATTRIBUTE_UNUSED,
|
2012-07-03 11:12:59 +00:00
|
|
|
void *opaque)
|
2011-02-22 17:35:06 +00:00
|
|
|
{
|
2012-07-03 11:12:59 +00:00
|
|
|
virLXCControllerPtr ctrl = opaque;
|
2012-07-03 14:25:30 +00:00
|
|
|
int ret;
|
2012-07-23 11:25:37 +00:00
|
|
|
int status;
|
2011-10-19 15:22:24 +00:00
|
|
|
|
2012-07-23 11:25:37 +00:00
|
|
|
ret = waitpid(-1, &status, WNOHANG);
|
2018-04-25 12:42:34 +00:00
|
|
|
VIR_DEBUG("Got sig child %d vs %lld", ret, (long long)ctrl->initpid);
|
2012-07-09 13:55:31 +00:00
|
|
|
if (ret == ctrl->initpid) {
|
2015-06-16 12:59:33 +00:00
|
|
|
virNetDaemonQuit(dmn);
|
2012-07-09 13:55:31 +00:00
|
|
|
virMutexLock(&lock);
|
2012-07-23 11:25:37 +00:00
|
|
|
if (WIFSIGNALED(status) &&
|
2013-11-01 16:24:30 +00:00
|
|
|
WTERMSIG(status) == SIGHUP) {
|
|
|
|
VIR_DEBUG("Status indicates reboot");
|
2012-07-23 11:25:37 +00:00
|
|
|
wantReboot = true;
|
2013-11-01 16:24:30 +00:00
|
|
|
}
|
2012-07-09 13:55:31 +00:00
|
|
|
virMutexUnlock(&lock);
|
|
|
|
}
|
2011-10-19 15:22:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-07-03 11:42:53 +00:00
|
|
|
static void virLXCControllerConsoleUpdateWatch(virLXCControllerConsolePtr console)
|
2011-10-19 15:22:24 +00:00
|
|
|
{
|
|
|
|
int hostEvents = 0;
|
|
|
|
int contEvents = 0;
|
|
|
|
|
2013-11-01 16:24:30 +00:00
|
|
|
/* If host console is open, then we can look to read/write */
|
|
|
|
if (!console->hostClosed) {
|
2011-10-19 15:22:24 +00:00
|
|
|
if (console->fromHostLen < sizeof(console->fromHostBuf))
|
|
|
|
hostEvents |= VIR_EVENT_HANDLE_READABLE;
|
|
|
|
if (console->fromContLen)
|
|
|
|
hostEvents |= VIR_EVENT_HANDLE_WRITABLE;
|
|
|
|
}
|
2013-11-01 16:24:30 +00:00
|
|
|
|
|
|
|
/* If cont console is open, then we can look to read/write */
|
|
|
|
if (!console->contClosed) {
|
2011-10-19 15:22:24 +00:00
|
|
|
if (console->fromContLen < sizeof(console->fromContBuf))
|
|
|
|
contEvents |= VIR_EVENT_HANDLE_READABLE;
|
|
|
|
if (console->fromHostLen)
|
|
|
|
contEvents |= VIR_EVENT_HANDLE_WRITABLE;
|
|
|
|
}
|
|
|
|
|
2013-11-01 16:24:30 +00:00
|
|
|
VIR_DEBUG("Container watch=%d, events=%d closed=%d; host watch=%d events=%d closed=%d",
|
|
|
|
console->contWatch, contEvents, console->contClosed,
|
|
|
|
console->hostWatch, hostEvents, console->hostClosed);
|
2011-10-19 15:22:24 +00:00
|
|
|
virEventUpdateHandle(console->contWatch, contEvents);
|
|
|
|
virEventUpdateHandle(console->hostWatch, hostEvents);
|
2011-02-22 17:35:06 +00:00
|
|
|
|
2012-01-12 17:03:03 +00:00
|
|
|
if (console->hostClosed) {
|
2013-11-01 16:24:30 +00:00
|
|
|
/* Must setup an epoll to detect when host becomes accessible again */
|
2012-01-12 17:03:03 +00:00
|
|
|
int events = EPOLLIN | EPOLLET;
|
2013-11-01 16:24:30 +00:00
|
|
|
if (console->fromContLen)
|
2012-01-12 17:03:03 +00:00
|
|
|
events |= EPOLLOUT;
|
|
|
|
|
|
|
|
if (events != console->hostEpoll) {
|
|
|
|
struct epoll_event event;
|
|
|
|
int action = EPOLL_CTL_ADD;
|
|
|
|
if (console->hostEpoll)
|
|
|
|
action = EPOLL_CTL_MOD;
|
|
|
|
|
|
|
|
VIR_DEBUG("newHostEvents=%x oldHostEvents=%x", events, console->hostEpoll);
|
|
|
|
|
|
|
|
event.events = events;
|
|
|
|
event.data.fd = console->hostFd;
|
|
|
|
if (epoll_ctl(console->epollFd, action, console->hostFd, &event) < 0) {
|
|
|
|
VIR_DEBUG(":fail");
|
|
|
|
virReportSystemError(errno, "%s",
|
|
|
|
_("Unable to add epoll fd"));
|
2015-03-16 14:02:41 +00:00
|
|
|
virNetDaemonQuit(console->daemon);
|
2012-01-12 17:03:03 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
console->hostEpoll = events;
|
|
|
|
VIR_DEBUG("newHostEvents=%x oldHostEvents=%x", events, console->hostEpoll);
|
|
|
|
}
|
|
|
|
} else if (console->hostEpoll) {
|
|
|
|
VIR_DEBUG("Stop epoll oldContEvents=%x", console->hostEpoll);
|
|
|
|
if (epoll_ctl(console->epollFd, EPOLL_CTL_DEL, console->hostFd, NULL) < 0) {
|
|
|
|
virReportSystemError(errno, "%s",
|
|
|
|
_("Unable to remove epoll fd"));
|
2012-11-16 09:11:23 +00:00
|
|
|
VIR_DEBUG(":fail");
|
2015-03-16 14:02:41 +00:00
|
|
|
virNetDaemonQuit(console->daemon);
|
2012-01-12 17:03:03 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
console->hostEpoll = 0;
|
|
|
|
}
|
2011-10-19 15:22:24 +00:00
|
|
|
|
2012-01-12 17:03:03 +00:00
|
|
|
if (console->contClosed) {
|
2013-11-01 16:24:30 +00:00
|
|
|
/* Must setup an epoll to detect when guest becomes accessible again */
|
2012-01-12 17:03:03 +00:00
|
|
|
int events = EPOLLIN | EPOLLET;
|
2013-11-01 16:24:30 +00:00
|
|
|
if (console->fromHostLen)
|
2012-01-12 17:03:03 +00:00
|
|
|
events |= EPOLLOUT;
|
|
|
|
|
|
|
|
if (events != console->contEpoll) {
|
|
|
|
struct epoll_event event;
|
|
|
|
int action = EPOLL_CTL_ADD;
|
|
|
|
if (console->contEpoll)
|
|
|
|
action = EPOLL_CTL_MOD;
|
|
|
|
|
|
|
|
VIR_DEBUG("newContEvents=%x oldContEvents=%x", events, console->contEpoll);
|
|
|
|
|
|
|
|
event.events = events;
|
|
|
|
event.data.fd = console->contFd;
|
|
|
|
if (epoll_ctl(console->epollFd, action, console->contFd, &event) < 0) {
|
|
|
|
virReportSystemError(errno, "%s",
|
|
|
|
_("Unable to add epoll fd"));
|
|
|
|
VIR_DEBUG(":fail");
|
2015-03-16 14:02:41 +00:00
|
|
|
virNetDaemonQuit(console->daemon);
|
2012-01-12 17:03:03 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
console->contEpoll = events;
|
|
|
|
VIR_DEBUG("newHostEvents=%x oldHostEvents=%x", events, console->contEpoll);
|
|
|
|
}
|
|
|
|
} else if (console->contEpoll) {
|
|
|
|
VIR_DEBUG("Stop epoll oldContEvents=%x", console->contEpoll);
|
|
|
|
if (epoll_ctl(console->epollFd, EPOLL_CTL_DEL, console->contFd, NULL) < 0) {
|
|
|
|
virReportSystemError(errno, "%s",
|
|
|
|
_("Unable to remove epoll fd"));
|
2012-11-16 09:11:23 +00:00
|
|
|
VIR_DEBUG(":fail");
|
2015-03-16 14:02:41 +00:00
|
|
|
virNetDaemonQuit(console->daemon);
|
2012-01-12 17:03:03 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
console->contEpoll = 0;
|
|
|
|
}
|
2014-03-25 06:49:26 +00:00
|
|
|
cleanup:
|
2012-01-12 17:03:03 +00:00
|
|
|
return;
|
|
|
|
}
|
2011-10-19 15:22:24 +00:00
|
|
|
|
|
|
|
|
2012-07-03 11:42:53 +00:00
|
|
|
static void virLXCControllerConsoleEPoll(int watch, int fd, int events, void *opaque)
|
2011-10-19 15:22:24 +00:00
|
|
|
{
|
2012-07-03 11:42:53 +00:00
|
|
|
virLXCControllerConsolePtr console = opaque;
|
2011-10-19 15:22:24 +00:00
|
|
|
|
2012-01-12 17:03:03 +00:00
|
|
|
virMutexLock(&lock);
|
|
|
|
VIR_DEBUG("IO event watch=%d fd=%d events=%d fromHost=%zu fromcont=%zu",
|
|
|
|
watch, fd, events,
|
|
|
|
console->fromHostLen,
|
|
|
|
console->fromContLen);
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
struct epoll_event event;
|
|
|
|
int ret;
|
|
|
|
ret = epoll_wait(console->epollFd, &event, 1, 0);
|
2011-10-19 15:22:24 +00:00
|
|
|
if (ret < 0) {
|
2012-04-27 18:39:17 +00:00
|
|
|
if (errno == EINTR)
|
2011-10-19 15:22:24 +00:00
|
|
|
continue;
|
|
|
|
virReportSystemError(errno, "%s",
|
|
|
|
_("Unable to wait on epoll"));
|
2015-03-16 14:02:41 +00:00
|
|
|
virNetDaemonQuit(console->daemon);
|
2011-10-19 15:22:24 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2012-01-12 17:03:03 +00:00
|
|
|
if (ret == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
VIR_DEBUG("fd=%d hostFd=%d contFd=%d hostEpoll=%x contEpoll=%x",
|
|
|
|
event.data.fd, console->hostFd, console->contFd,
|
|
|
|
console->hostEpoll, console->contEpoll);
|
|
|
|
|
2011-10-19 15:22:24 +00:00
|
|
|
/* If we get HUP+dead PID, we just re-enable the main loop
|
|
|
|
* which will see the PID has died and exit */
|
2013-11-01 16:24:30 +00:00
|
|
|
if ((event.events & (EPOLLIN|EPOLLOUT))) {
|
2012-01-12 17:03:03 +00:00
|
|
|
if (event.data.fd == console->hostFd) {
|
|
|
|
console->hostClosed = false;
|
2011-10-19 15:22:24 +00:00
|
|
|
} else {
|
2012-01-12 17:03:03 +00:00
|
|
|
console->contClosed = false;
|
2011-10-19 15:22:24 +00:00
|
|
|
}
|
2012-07-03 11:42:53 +00:00
|
|
|
virLXCControllerConsoleUpdateWatch(console);
|
2011-10-19 15:22:24 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-25 06:49:26 +00:00
|
|
|
cleanup:
|
2012-01-12 17:03:03 +00:00
|
|
|
virMutexUnlock(&lock);
|
2011-10-19 15:22:24 +00:00
|
|
|
}
|
|
|
|
|
2012-07-03 11:42:53 +00:00
|
|
|
static void virLXCControllerConsoleIO(int watch, int fd, int events, void *opaque)
|
2011-10-19 15:22:24 +00:00
|
|
|
{
|
2012-07-03 11:42:53 +00:00
|
|
|
virLXCControllerConsolePtr console = opaque;
|
2011-10-19 15:22:24 +00:00
|
|
|
|
|
|
|
virMutexLock(&lock);
|
2012-01-12 17:03:03 +00:00
|
|
|
VIR_DEBUG("IO event watch=%d fd=%d events=%d fromHost=%zu fromcont=%zu",
|
|
|
|
watch, fd, events,
|
|
|
|
console->fromHostLen,
|
|
|
|
console->fromContLen);
|
2011-10-19 15:22:24 +00:00
|
|
|
if (events & VIR_EVENT_HANDLE_READABLE) {
|
|
|
|
char *buf;
|
|
|
|
size_t *len;
|
|
|
|
size_t avail;
|
|
|
|
ssize_t done;
|
|
|
|
if (watch == console->hostWatch) {
|
|
|
|
buf = console->fromHostBuf;
|
|
|
|
len = &console->fromHostLen;
|
|
|
|
avail = sizeof(console->fromHostBuf) - *len;
|
|
|
|
} else {
|
|
|
|
buf = console->fromContBuf;
|
|
|
|
len = &console->fromContLen;
|
|
|
|
avail = sizeof(console->fromContBuf) - *len;
|
|
|
|
}
|
2015-05-12 12:40:34 +00:00
|
|
|
reread:
|
2011-10-19 15:22:24 +00:00
|
|
|
done = read(fd, buf + *len, avail);
|
|
|
|
if (done == -1 && errno == EINTR)
|
|
|
|
goto reread;
|
|
|
|
if (done == -1 && errno != EAGAIN) {
|
|
|
|
virReportSystemError(errno, "%s",
|
|
|
|
_("Unable to read container pty"));
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
if (done > 0) {
|
|
|
|
*len += done;
|
|
|
|
} else {
|
|
|
|
VIR_DEBUG("Read fd %d done %d errno %d", fd, (int)done, errno);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (events & VIR_EVENT_HANDLE_WRITABLE) {
|
|
|
|
char *buf;
|
|
|
|
size_t *len;
|
|
|
|
ssize_t done;
|
|
|
|
if (watch == console->hostWatch) {
|
|
|
|
buf = console->fromContBuf;
|
|
|
|
len = &console->fromContLen;
|
|
|
|
} else {
|
|
|
|
buf = console->fromHostBuf;
|
|
|
|
len = &console->fromHostLen;
|
|
|
|
}
|
|
|
|
|
2015-05-12 12:40:34 +00:00
|
|
|
rewrite:
|
2011-10-19 15:22:24 +00:00
|
|
|
done = write(fd, buf, *len);
|
|
|
|
if (done == -1 && errno == EINTR)
|
|
|
|
goto rewrite;
|
|
|
|
if (done == -1 && errno != EAGAIN) {
|
|
|
|
virReportSystemError(errno, "%s",
|
|
|
|
_("Unable to write to container pty"));
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
if (done > 0) {
|
|
|
|
memmove(buf, buf + done, (*len - done));
|
|
|
|
*len -= done;
|
|
|
|
} else {
|
|
|
|
VIR_DEBUG("Write fd %d done %d errno %d", fd, (int)done, errno);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (events & VIR_EVENT_HANDLE_HANGUP) {
|
|
|
|
if (watch == console->hostWatch) {
|
|
|
|
console->hostClosed = true;
|
|
|
|
} else {
|
|
|
|
console->contClosed = true;
|
|
|
|
}
|
|
|
|
VIR_DEBUG("Got EOF on %d %d", watch, fd);
|
|
|
|
}
|
|
|
|
|
2012-07-03 11:42:53 +00:00
|
|
|
virLXCControllerConsoleUpdateWatch(console);
|
2011-10-19 15:22:24 +00:00
|
|
|
virMutexUnlock(&lock);
|
|
|
|
return;
|
|
|
|
|
2014-03-25 06:49:26 +00:00
|
|
|
error:
|
2011-10-19 15:22:24 +00:00
|
|
|
virEventRemoveHandle(console->contWatch);
|
|
|
|
virEventRemoveHandle(console->hostWatch);
|
|
|
|
console->contWatch = console->hostWatch = -1;
|
2015-03-16 14:02:41 +00:00
|
|
|
virNetDaemonQuit(console->daemon);
|
2011-10-19 15:22:24 +00:00
|
|
|
virMutexUnlock(&lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-08-13 10:25:34 +00:00
|
|
|
/**
|
2009-11-05 12:35:13 +00:00
|
|
|
* lxcControllerMain
|
2011-10-19 15:22:24 +00:00
|
|
|
* @serverFd: server socket fd to accept client requests
|
|
|
|
* @clientFd: initial client which is the libvirtd daemon
|
2008-08-13 10:25:34 +00:00
|
|
|
*
|
2011-10-19 15:22:24 +00:00
|
|
|
* Processes I/O on consoles and the monitor
|
2008-08-13 10:25:34 +00:00
|
|
|
*
|
|
|
|
* Returns 0 on success or -1 in case of error
|
|
|
|
*/
|
2012-07-03 13:40:45 +00:00
|
|
|
static int virLXCControllerMain(virLXCControllerPtr ctrl)
|
2008-08-13 10:25:34 +00:00
|
|
|
{
|
2011-10-19 15:22:24 +00:00
|
|
|
virErrorPtr err;
|
2008-08-13 10:25:34 +00:00
|
|
|
int rc = -1;
|
2011-10-20 08:44:31 +00:00
|
|
|
size_t i;
|
2011-10-19 15:22:24 +00:00
|
|
|
|
2015-03-16 14:02:41 +00:00
|
|
|
if (virNetDaemonAddSignalHandler(ctrl->daemon,
|
2012-07-03 14:25:30 +00:00
|
|
|
SIGCHLD,
|
|
|
|
virLXCControllerSignalChildIO,
|
|
|
|
ctrl) < 0)
|
2008-08-13 10:25:34 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2011-10-19 15:22:24 +00:00
|
|
|
virResetLastError();
|
|
|
|
|
2013-05-21 08:03:33 +00:00
|
|
|
for (i = 0; i < ctrl->nconsoles; i++) {
|
2012-07-03 11:42:53 +00:00
|
|
|
if ((ctrl->consoles[i].epollFd = epoll_create1(EPOLL_CLOEXEC)) < 0) {
|
2012-01-12 17:03:03 +00:00
|
|
|
virReportSystemError(errno, "%s",
|
|
|
|
_("Unable to create epoll fd"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2012-07-03 11:42:53 +00:00
|
|
|
if ((ctrl->consoles[i].epollWatch = virEventAddHandle(ctrl->consoles[i].epollFd,
|
|
|
|
VIR_EVENT_HANDLE_READABLE,
|
|
|
|
virLXCControllerConsoleEPoll,
|
|
|
|
&(ctrl->consoles[i]),
|
|
|
|
NULL)) < 0) {
|
2012-07-13 12:59:51 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Unable to watch epoll FD"));
|
2012-01-12 17:03:03 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2012-07-03 11:42:53 +00:00
|
|
|
if ((ctrl->consoles[i].hostWatch = virEventAddHandle(ctrl->consoles[i].hostFd,
|
|
|
|
VIR_EVENT_HANDLE_READABLE,
|
|
|
|
virLXCControllerConsoleIO,
|
|
|
|
&(ctrl->consoles[i]),
|
|
|
|
NULL)) < 0) {
|
2012-07-13 12:59:51 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Unable to watch host console PTY"));
|
2011-10-20 08:44:31 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2012-07-03 11:42:53 +00:00
|
|
|
if ((ctrl->consoles[i].contWatch = virEventAddHandle(ctrl->consoles[i].contFd,
|
|
|
|
VIR_EVENT_HANDLE_READABLE,
|
|
|
|
virLXCControllerConsoleIO,
|
|
|
|
&(ctrl->consoles[i]),
|
|
|
|
NULL)) < 0) {
|
2012-07-13 12:59:51 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Unable to watch host console PTY"));
|
2011-10-20 08:44:31 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
2011-10-19 15:22:24 +00:00
|
|
|
}
|
2008-08-13 10:25:34 +00:00
|
|
|
|
2015-03-16 14:02:41 +00:00
|
|
|
virNetDaemonRun(ctrl->daemon);
|
2008-08-13 10:25:34 +00:00
|
|
|
|
2011-10-19 15:22:24 +00:00
|
|
|
err = virGetLastError();
|
|
|
|
if (!err || err->code == VIR_ERR_OK)
|
2012-07-23 11:25:37 +00:00
|
|
|
rc = wantReboot ? 1 : 0;
|
2008-08-13 10:25:34 +00:00
|
|
|
|
2014-03-25 06:49:26 +00:00
|
|
|
cleanup:
|
2013-05-21 08:03:33 +00:00
|
|
|
for (i = 0; i < ctrl->nconsoles; i++)
|
2012-07-03 11:42:53 +00:00
|
|
|
virLXCControllerConsoleClose(&(ctrl->consoles[i]));
|
2012-01-12 17:03:03 +00:00
|
|
|
|
2008-08-13 10:25:34 +00:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2014-07-28 20:59:17 +00:00
|
|
|
static unsigned int
|
|
|
|
virLXCControllerLookupUsernsMap(virDomainIdMapEntryPtr map,
|
|
|
|
int num,
|
|
|
|
unsigned int src)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
for (i = 0; i < num; i++) {
|
|
|
|
if (src > map[i].start && src < map[i].start + map[i].count)
|
|
|
|
return map[i].target + (src - map[i].start);
|
|
|
|
}
|
|
|
|
|
|
|
|
return src;
|
|
|
|
}
|
2008-08-13 10:52:15 +00:00
|
|
|
|
2013-06-07 07:12:21 +00:00
|
|
|
static int
|
|
|
|
virLXCControllerSetupUsernsMap(virDomainIdMapEntryPtr map,
|
|
|
|
int num,
|
|
|
|
char *path)
|
|
|
|
{
|
|
|
|
virBuffer map_value = VIR_BUFFER_INITIALIZER;
|
Convert 'int i' to 'size_t i' in src/lxc/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t i;
|
|
|
|
int ret = -1;
|
2013-06-07 07:12:21 +00:00
|
|
|
|
|
|
|
for (i = 0; i < num; i++)
|
|
|
|
virBufferAsprintf(&map_value, "%u %u %u\n",
|
|
|
|
map[i].start, map[i].target, map[i].count);
|
|
|
|
|
2014-06-27 08:40:15 +00:00
|
|
|
if (virBufferCheckError(&map_value) < 0)
|
|
|
|
goto cleanup;
|
2013-06-07 07:12:21 +00:00
|
|
|
|
2013-07-01 16:42:25 +00:00
|
|
|
VIR_DEBUG("Set '%s' to '%s'", path, virBufferCurrentContent(&map_value));
|
|
|
|
|
2013-06-07 07:12:21 +00:00
|
|
|
if (virFileWriteStr(path, virBufferCurrentContent(&map_value), 0) < 0) {
|
|
|
|
virReportSystemError(errno, _("unable write to %s"), path);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
2014-03-25 06:49:26 +00:00
|
|
|
cleanup:
|
2013-06-07 07:12:21 +00:00
|
|
|
virBufferFreeAndReset(&map_value);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virLXCControllerSetupUserns
|
|
|
|
*
|
|
|
|
* Set proc files for user namespace
|
|
|
|
*
|
|
|
|
* Returns 0 on success or -1 in case of error
|
|
|
|
*/
|
|
|
|
static int virLXCControllerSetupUserns(virLXCControllerPtr ctrl)
|
|
|
|
{
|
|
|
|
char *uid_map = NULL;
|
|
|
|
char *gid_map = NULL;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
/* User namespace is disabled for container */
|
2015-01-16 17:20:48 +00:00
|
|
|
if (ctrl->def->idmap.nuidmap == 0) {
|
|
|
|
VIR_DEBUG("No uid map, skipping userns setup");
|
2013-06-07 07:12:21 +00:00
|
|
|
return 0;
|
2015-01-16 17:20:48 +00:00
|
|
|
}
|
2013-06-07 07:12:21 +00:00
|
|
|
|
2015-01-16 17:20:48 +00:00
|
|
|
VIR_DEBUG("Setting up userns maps");
|
2013-06-07 07:12:21 +00:00
|
|
|
if (virAsprintf(&uid_map, "/proc/%d/uid_map", ctrl->initpid) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virLXCControllerSetupUsernsMap(ctrl->def->idmap.uidmap,
|
|
|
|
ctrl->def->idmap.nuidmap,
|
|
|
|
uid_map) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virAsprintf(&gid_map, "/proc/%d/gid_map", ctrl->initpid) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virLXCControllerSetupUsernsMap(ctrl->def->idmap.gidmap,
|
|
|
|
ctrl->def->idmap.ngidmap,
|
|
|
|
gid_map) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
ret = 0;
|
2014-03-25 06:49:26 +00:00
|
|
|
cleanup:
|
2013-06-07 07:12:21 +00:00
|
|
|
VIR_FREE(uid_map);
|
|
|
|
VIR_FREE(gid_map);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-06-07 07:12:22 +00:00
|
|
|
static int virLXCControllerSetupDev(virLXCControllerPtr ctrl)
|
|
|
|
{
|
|
|
|
char *mount_options = NULL;
|
|
|
|
char *opts = NULL;
|
|
|
|
char *dev = NULL;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
VIR_DEBUG("Setting up /dev/ for container");
|
|
|
|
|
|
|
|
mount_options = virSecurityManagerGetMountOptions(ctrl->securityManager,
|
|
|
|
ctrl->def);
|
|
|
|
|
|
|
|
if (virAsprintf(&dev, "/%s/%s.dev",
|
2013-07-04 10:11:37 +00:00
|
|
|
LXC_STATE_DIR, ctrl->def->name) < 0)
|
2013-06-07 07:12:22 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* tmpfs is limited to 64kb, since we only have device nodes in there
|
|
|
|
* and don't want to DOS the entire OS RAM usage
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (virAsprintf(&opts,
|
2013-07-04 10:11:37 +00:00
|
|
|
"mode=755,size=65536%s", mount_options) < 0)
|
2013-06-07 07:12:22 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2016-11-10 15:17:48 +00:00
|
|
|
if (virFileSetupDev(dev, opts) < 0)
|
2013-06-07 07:12:22 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2013-07-16 02:00:02 +00:00
|
|
|
if (lxcContainerChown(ctrl->def, dev) < 0)
|
2013-06-07 07:12:24 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2013-06-07 07:12:22 +00:00
|
|
|
ret = 0;
|
2014-03-25 06:49:26 +00:00
|
|
|
cleanup:
|
2013-06-07 07:12:22 +00:00
|
|
|
VIR_FREE(opts);
|
|
|
|
VIR_FREE(mount_options);
|
|
|
|
VIR_FREE(dev);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int virLXCControllerPopulateDevices(virLXCControllerPtr ctrl)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
int ret = -1;
|
|
|
|
char *path = NULL;
|
|
|
|
const struct {
|
|
|
|
int maj;
|
|
|
|
int min;
|
|
|
|
mode_t mode;
|
|
|
|
const char *path;
|
|
|
|
} devs[] = {
|
|
|
|
{ LXC_DEV_MAJ_MEMORY, LXC_DEV_MIN_NULL, 0666, "/null" },
|
|
|
|
{ LXC_DEV_MAJ_MEMORY, LXC_DEV_MIN_ZERO, 0666, "/zero" },
|
|
|
|
{ LXC_DEV_MAJ_MEMORY, LXC_DEV_MIN_FULL, 0666, "/full" },
|
|
|
|
{ LXC_DEV_MAJ_MEMORY, LXC_DEV_MIN_RANDOM, 0666, "/random" },
|
|
|
|
{ LXC_DEV_MAJ_MEMORY, LXC_DEV_MIN_URANDOM, 0666, "/urandom" },
|
2013-07-09 10:05:14 +00:00
|
|
|
{ LXC_DEV_MAJ_TTY, LXC_DEV_MIN_TTY, 0666, "/tty" },
|
2013-06-07 07:12:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
if (virLXCControllerSetupDev(ctrl) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
/* Populate /dev/ with a few important bits */
|
|
|
|
for (i = 0; i < ARRAY_CARDINALITY(devs); i++) {
|
|
|
|
if (virAsprintf(&path, "/%s/%s.dev/%s",
|
2013-07-04 10:11:37 +00:00
|
|
|
LXC_STATE_DIR, ctrl->def->name, devs[i].path) < 0)
|
2013-06-07 07:12:22 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
dev_t dev = makedev(devs[i].maj, devs[i].min);
|
|
|
|
if (mknod(path, S_IFCHR, dev) < 0 ||
|
|
|
|
chmod(path, devs[i].mode)) {
|
|
|
|
virReportSystemError(errno,
|
|
|
|
_("Failed to make device %s"),
|
|
|
|
path);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2013-06-07 07:12:25 +00:00
|
|
|
|
2013-07-16 02:00:02 +00:00
|
|
|
if (lxcContainerChown(ctrl->def, path) < 0)
|
2013-06-07 07:12:25 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2013-06-07 07:12:22 +00:00
|
|
|
VIR_FREE(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
2014-03-25 06:49:26 +00:00
|
|
|
cleanup:
|
2013-06-07 07:12:22 +00:00
|
|
|
VIR_FREE(path);
|
|
|
|
return ret;
|
|
|
|
}
|
2013-06-07 07:12:21 +00:00
|
|
|
|
2008-08-13 10:52:15 +00:00
|
|
|
|
2013-07-16 02:00:04 +00:00
|
|
|
static int
|
|
|
|
virLXCControllerSetupHostdevSubsysUSB(virDomainDefPtr vmDef,
|
|
|
|
virDomainHostdevDefPtr def,
|
|
|
|
virSecurityManagerPtr securityDriver)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
char *src = NULL;
|
|
|
|
char *dstdir = NULL;
|
|
|
|
char *dstfile = NULL;
|
|
|
|
char *vroot = NULL;
|
|
|
|
struct stat sb;
|
|
|
|
mode_t mode;
|
2014-07-03 19:43:05 +00:00
|
|
|
virDomainHostdevSubsysUSBPtr usbsrc = &def->source.subsys.u.usb;
|
2013-07-16 02:00:04 +00:00
|
|
|
|
|
|
|
if (virAsprintf(&src, USB_DEVFS "/%03d/%03d",
|
2014-07-03 19:43:05 +00:00
|
|
|
usbsrc->bus, usbsrc->device) < 0)
|
2013-07-16 02:00:04 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virAsprintf(&vroot, "/%s/%s.dev/bus/usb/",
|
|
|
|
LXC_STATE_DIR, vmDef->name) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2014-07-03 19:43:05 +00:00
|
|
|
if (virAsprintf(&dstdir, "%s/%03d/", vroot, usbsrc->bus) < 0)
|
2013-07-16 02:00:04 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2014-07-03 19:43:05 +00:00
|
|
|
if (virAsprintf(&dstfile, "%s/%03d", dstdir, usbsrc->device) < 0)
|
2013-07-16 02:00:04 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (stat(src, &sb) < 0) {
|
|
|
|
virReportSystemError(errno,
|
|
|
|
_("Unable to access %s"), src);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!S_ISCHR(sb.st_mode)) {
|
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
|
|
|
_("USB source %s was not a character device"),
|
|
|
|
src);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
mode = 0700 | S_IFCHR;
|
|
|
|
|
|
|
|
if (virFileMakePath(dstdir) < 0) {
|
|
|
|
virReportSystemError(errno,
|
|
|
|
_("Unable to create %s"), dstdir);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
VIR_DEBUG("Creating dev %s (%d,%d)",
|
|
|
|
dstfile, major(sb.st_rdev), minor(sb.st_rdev));
|
|
|
|
if (mknod(dstfile, mode, sb.st_rdev) < 0) {
|
|
|
|
virReportSystemError(errno,
|
|
|
|
_("Unable to create device %s"),
|
|
|
|
dstfile);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2013-07-16 02:00:05 +00:00
|
|
|
if (lxcContainerChown(vmDef, dstfile) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2013-07-16 02:00:04 +00:00
|
|
|
if (virSecurityManagerSetHostdevLabel(securityDriver,
|
|
|
|
vmDef, def, vroot) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
2014-03-25 06:49:26 +00:00
|
|
|
cleanup:
|
2013-07-16 02:00:04 +00:00
|
|
|
VIR_FREE(src);
|
|
|
|
VIR_FREE(dstfile);
|
|
|
|
VIR_FREE(dstdir);
|
|
|
|
VIR_FREE(vroot);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
virLXCControllerSetupHostdevCapsStorage(virDomainDefPtr vmDef,
|
|
|
|
virDomainHostdevDefPtr def,
|
|
|
|
virSecurityManagerPtr securityDriver)
|
|
|
|
{
|
|
|
|
char *dst = NULL;
|
|
|
|
char *path = NULL;
|
|
|
|
int len = 0;
|
|
|
|
int ret = -1;
|
|
|
|
struct stat sb;
|
|
|
|
mode_t mode;
|
|
|
|
char *dev = def->source.caps.u.storage.block;
|
|
|
|
|
|
|
|
if (dev == NULL) {
|
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
|
|
|
_("Missing storage host block path"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (VIR_STRDUP(path, dev) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
while (*(path + len) == '/')
|
|
|
|
len++;
|
|
|
|
|
|
|
|
if (virAsprintf(&dst, "/%s/%s.dev/%s",
|
|
|
|
LXC_STATE_DIR, vmDef->name,
|
|
|
|
strchr(path + len, '/')) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (stat(dev, &sb) < 0) {
|
|
|
|
virReportSystemError(errno,
|
|
|
|
_("Unable to access %s"),
|
|
|
|
dev);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!S_ISBLK(sb.st_mode)) {
|
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
|
|
|
_("Storage source %s must be a block device"),
|
|
|
|
dev);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lxcContainerSetupHostdevCapsMakePath(dst) < 0) {
|
|
|
|
virReportError(errno,
|
|
|
|
_("Failed to create directory for device %s"),
|
|
|
|
dev);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
mode = 0700 | S_IFBLK;
|
|
|
|
|
|
|
|
VIR_DEBUG("Creating dev %s (%d,%d)", dst,
|
|
|
|
major(sb.st_rdev), minor(sb.st_rdev));
|
|
|
|
if (mknod(dst, mode, sb.st_rdev) < 0) {
|
|
|
|
virReportSystemError(errno,
|
|
|
|
_("Unable to create device %s"),
|
|
|
|
dst);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2013-07-16 02:00:05 +00:00
|
|
|
if (lxcContainerChown(vmDef, dst) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2013-07-16 02:00:04 +00:00
|
|
|
def->source.caps.u.storage.block = dst;
|
|
|
|
if (virSecurityManagerSetHostdevLabel(securityDriver, vmDef, def, NULL) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
2014-03-25 06:49:26 +00:00
|
|
|
cleanup:
|
2013-07-16 02:00:04 +00:00
|
|
|
def->source.caps.u.storage.block = dev;
|
|
|
|
VIR_FREE(dst);
|
|
|
|
VIR_FREE(path);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
virLXCControllerSetupHostdevCapsMisc(virDomainDefPtr vmDef,
|
|
|
|
virDomainHostdevDefPtr def,
|
|
|
|
virSecurityManagerPtr securityDriver)
|
|
|
|
{
|
|
|
|
char *dst = NULL;
|
|
|
|
char *path = NULL;
|
|
|
|
int len = 0;
|
|
|
|
int ret = -1;
|
|
|
|
struct stat sb;
|
|
|
|
mode_t mode;
|
|
|
|
char *dev = def->source.caps.u.misc.chardev;
|
|
|
|
|
|
|
|
if (dev == NULL) {
|
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
|
|
|
_("Missing storage host block path"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (VIR_STRDUP(path, dev) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
while (*(path + len) == '/')
|
|
|
|
len++;
|
|
|
|
|
|
|
|
if (virAsprintf(&dst, "/%s/%s.dev/%s",
|
|
|
|
LXC_STATE_DIR, vmDef->name,
|
|
|
|
strchr(path + len, '/')) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (stat(dev, &sb) < 0) {
|
|
|
|
virReportSystemError(errno,
|
|
|
|
_("Unable to access %s"),
|
|
|
|
dev);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!S_ISCHR(sb.st_mode)) {
|
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
|
|
|
_("Storage source %s must be a character device"),
|
|
|
|
dev);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lxcContainerSetupHostdevCapsMakePath(dst) < 0) {
|
|
|
|
virReportError(errno,
|
|
|
|
_("Failed to create directory for device %s"),
|
|
|
|
dst);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
mode = 0700 | S_IFCHR;
|
|
|
|
|
|
|
|
VIR_DEBUG("Creating dev %s (%d,%d)", dst,
|
|
|
|
major(sb.st_rdev), minor(sb.st_rdev));
|
|
|
|
if (mknod(dst, mode, sb.st_rdev) < 0) {
|
|
|
|
virReportSystemError(errno,
|
|
|
|
_("Unable to create device %s"),
|
|
|
|
dev);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2013-07-16 02:00:05 +00:00
|
|
|
if (lxcContainerChown(vmDef, dst) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2013-07-16 02:00:04 +00:00
|
|
|
def->source.caps.u.misc.chardev = dst;
|
|
|
|
if (virSecurityManagerSetHostdevLabel(securityDriver, vmDef, def, NULL) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
2014-03-25 06:49:26 +00:00
|
|
|
cleanup:
|
2013-07-16 02:00:04 +00:00
|
|
|
def->source.caps.u.misc.chardev = dev;
|
|
|
|
VIR_FREE(dst);
|
|
|
|
VIR_FREE(path);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
virLXCControllerSetupHostdevSubsys(virDomainDefPtr vmDef,
|
|
|
|
virDomainHostdevDefPtr def,
|
|
|
|
virSecurityManagerPtr securityDriver)
|
|
|
|
{
|
|
|
|
switch (def->source.subsys.type) {
|
|
|
|
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB:
|
|
|
|
return virLXCControllerSetupHostdevSubsysUSB(vmDef,
|
|
|
|
def,
|
|
|
|
securityDriver);
|
|
|
|
|
|
|
|
default:
|
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
|
|
|
_("Unsupported host device mode %s"),
|
|
|
|
virDomainHostdevSubsysTypeToString(def->source.subsys.type));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
virLXCControllerSetupHostdevCaps(virDomainDefPtr vmDef,
|
|
|
|
virDomainHostdevDefPtr def,
|
|
|
|
virSecurityManagerPtr securityDriver)
|
|
|
|
{
|
|
|
|
switch (def->source.subsys.type) {
|
|
|
|
case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_STORAGE:
|
|
|
|
return virLXCControllerSetupHostdevCapsStorage(vmDef,
|
|
|
|
def,
|
|
|
|
securityDriver);
|
|
|
|
|
|
|
|
case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_MISC:
|
|
|
|
return virLXCControllerSetupHostdevCapsMisc(vmDef,
|
|
|
|
def,
|
|
|
|
securityDriver);
|
|
|
|
|
|
|
|
case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_NET:
|
2017-04-27 06:47:19 +00:00
|
|
|
return 0; /* case is handled in virLXCControllerMoveInterfaces */
|
2013-07-16 02:00:04 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
|
|
|
_("Unsupported host device mode %s"),
|
|
|
|
virDomainHostdevCapsTypeToString(def->source.subsys.type));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
virLXCControllerSetupAllHostdevs(virLXCControllerPtr ctrl)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
virDomainDefPtr vmDef = ctrl->def;
|
|
|
|
virSecurityManagerPtr securityDriver = ctrl->securityManager;
|
|
|
|
VIR_DEBUG("Setting up hostdevs");
|
|
|
|
|
|
|
|
for (i = 0; i < vmDef->nhostdevs; i++) {
|
|
|
|
virDomainHostdevDefPtr def = vmDef->hostdevs[i];
|
|
|
|
switch (def->mode) {
|
|
|
|
case VIR_DOMAIN_HOSTDEV_MODE_SUBSYS:
|
|
|
|
if (virLXCControllerSetupHostdevSubsys(vmDef,
|
|
|
|
def,
|
|
|
|
securityDriver) < 0)
|
|
|
|
return -1;
|
|
|
|
break;
|
|
|
|
case VIR_DOMAIN_HOSTDEV_MODE_CAPABILITIES:
|
|
|
|
if (virLXCControllerSetupHostdevCaps(vmDef,
|
|
|
|
def,
|
|
|
|
securityDriver) < 0)
|
|
|
|
return -1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
|
|
|
_("Unsupported host device mode %s"),
|
|
|
|
virDomainHostdevModeTypeToString(def->mode));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
VIR_DEBUG("Setup all hostdevs");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-07-16 02:00:00 +00:00
|
|
|
static int virLXCControllerSetupDisk(virLXCControllerPtr ctrl,
|
|
|
|
virDomainDiskDefPtr def,
|
|
|
|
virSecurityManagerPtr securityDriver)
|
|
|
|
{
|
|
|
|
char *dst = NULL;
|
|
|
|
int ret = -1;
|
|
|
|
struct stat sb;
|
|
|
|
mode_t mode;
|
2014-05-21 23:13:12 +00:00
|
|
|
char *tmpsrc = def->src->path;
|
2013-07-16 02:00:00 +00:00
|
|
|
|
conf: move host disk type to util/
A continuation of the migration of disk details to virstoragefile.
This patch moves a single enum, but converting the name has quite
a bit of fallout.
* src/conf/domain_conf.h (virDomainDiskType): Move...
* src/util/virstoragefile.h (virStorageType): ...and rename.
* src/bhyve/bhyve_command.c (bhyveBuildDiskArgStr)
(virBhyveProcessBuildLoadCmd): Update clients.
* src/conf/domain_conf.c (virDomainDiskSourceDefParse)
(virDomainDiskDefParseXML, virDomainDiskSourceDefFormatInternal)
(virDomainDiskDefFormat, virDomainDiskGetActualType)
(virDomainDiskDefForeachPath, virDomainDiskSourceIsBlockType):
Likewise.
* src/conf/snapshot_conf.h (_virDomainSnapshotDiskDef): Likewise.
* src/conf/snapshot_conf.c (virDomainSnapshotDiskDefParseXML)
(virDomainSnapshotAlignDisks, virDomainSnapshotDiskDefFormat):
Likewise.
* src/esx/esx_driver.c (esxAutodetectSCSIControllerModel)
(esxDomainDefineXML): Likewise.
* src/locking/domain_lock.c (virDomainLockManagerAddDisk):
Likewise.
* src/lxc/lxc_controller.c
(virLXCControllerSetupLoopDeviceDisk)
(virLXCControllerSetupNBDDeviceDisk)
(virLXCControllerSetupLoopDevices, virLXCControllerSetupDisk):
Likewise.
* src/parallels/parallels_driver.c (parallelsGetHddInfo):
Likewise.
* src/phyp/phyp_driver.c (phypDiskType): Likewise.
* src/qemu/qemu_command.c (qemuGetDriveSourceString)
(qemuDomainDiskGetSourceString, qemuBuildDriveStr)
(qemuBuildCommandLine, qemuParseCommandLineDisk)
(qemuParseCommandLine): Likewise.
* src/qemu/qemu_conf.c (qemuCheckSharedDevice)
(qemuTranslateDiskSourcePool)
(qemuTranslateSnapshotDiskSourcePool): Likewise.
* src/qemu/qemu_domain.c (qemuDomainDeviceDefPostParse)
(qemuDomainDetermineDiskChain): Likewise.
* src/qemu/qemu_driver.c (qemuDomainGetBlockInfo)
(qemuDomainSnapshotPrepareDiskExternalBackingInactive)
(qemuDomainSnapshotPrepareDiskExternalBackingActive)
(qemuDomainSnapshotPrepareDiskExternalOverlayActive)
(qemuDomainSnapshotPrepareDiskExternalOverlayInactive)
(qemuDomainSnapshotPrepareDiskInternal)
(qemuDomainSnapshotPrepare)
(qemuDomainSnapshotCreateSingleDiskActive): Likewise.
* src/qemu/qemu_hotplug.c (qemuDomainChangeEjectableMedia):
Likewise.
* src/qemu/qemu_migration.c (qemuMigrationIsSafe): Likewise.
* src/security/security_apparmor.c
(AppArmorRestoreSecurityImageLabel)
(AppArmorSetSecurityImageLabel): Likewise.
* src/security/security_dac.c (virSecurityDACSetSecurityImageLabel)
(virSecurityDACRestoreSecurityImageLabelInt)
(virSecurityDACSetSecurityAllLabel): Likewise.
* src/security/security_selinux.c
(virSecuritySELinuxRestoreSecurityImageLabelInt)
(virSecuritySELinuxSetSecurityImageLabel)
(virSecuritySELinuxSetSecurityAllLabel): Likewise.
* src/storage/storage_backend.c (virStorageFileBackendForType):
Likewise.
* src/storage/storage_backend_fs.c (virStorageFileBackendFile)
(virStorageFileBackendBlock): Likewise.
* src/storage/storage_backend_gluster.c
(virStorageFileBackendGluster): Likewise.
* src/vbox/vbox_tmpl.c (vboxDomainGetXMLDesc, vboxAttachDrives)
(vboxDomainAttachDeviceImpl, vboxDomainDetachDevice): Likewise.
* src/vmware/vmware_conf.c (vmwareVmxPath): Likewise.
* src/vmx/vmx.c (virVMXParseDisk, virVMXFormatDisk)
(virVMXFormatFloppy): Likewise.
* src/xenxs/xen_sxpr.c (xenParseSxprDisks, xenParseSxpr)
(xenFormatSxprDisk): Likewise.
* src/xenxs/xen_xm.c (xenParseXM, xenFormatXMDisk): Likewise.
* tests/securityselinuxlabeltest.c (testSELinuxLoadDef):
Likewise.
* src/libvirt_private.syms (domain_conf.h): Move symbols...
(virstoragefile.h): ...as appropriate.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-03-27 21:57:49 +00:00
|
|
|
if (virDomainDiskGetType(def) != VIR_STORAGE_TYPE_BLOCK) {
|
2013-07-16 02:00:00 +00:00
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
|
|
|
_("Can't setup disk for non-block device"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2014-03-17 20:49:05 +00:00
|
|
|
if (!tmpsrc) {
|
2013-07-16 02:00:00 +00:00
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
|
|
|
_("Can't setup disk without media"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virAsprintf(&dst, "/%s/%s.dev/%s",
|
|
|
|
LXC_STATE_DIR, ctrl->def->name, def->dst) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2014-05-21 23:13:12 +00:00
|
|
|
if (stat(def->src->path, &sb) < 0) {
|
2013-07-16 02:00:00 +00:00
|
|
|
virReportSystemError(errno,
|
2014-03-17 20:49:05 +00:00
|
|
|
_("Unable to access %s"), tmpsrc);
|
2013-07-16 02:00:00 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!S_ISCHR(sb.st_mode) && !S_ISBLK(sb.st_mode)) {
|
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
|
|
|
_("Disk source %s must be a character/block device"),
|
2014-03-17 20:49:05 +00:00
|
|
|
tmpsrc);
|
2013-07-16 02:00:00 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
mode = 0700;
|
|
|
|
if (S_ISCHR(sb.st_mode))
|
|
|
|
mode |= S_IFCHR;
|
|
|
|
else
|
|
|
|
mode |= S_IFBLK;
|
|
|
|
|
|
|
|
/* Yes, the device name we're creating may not
|
|
|
|
* actually correspond to the major:minor number
|
|
|
|
* we're using, but we've no other option at this
|
|
|
|
* time. Just have to hope that containerized apps
|
|
|
|
* don't get upset that the major:minor is different
|
|
|
|
* to that normally implied by the device name
|
|
|
|
*/
|
|
|
|
VIR_DEBUG("Creating dev %s (%d,%d) from %s",
|
2014-03-17 20:49:05 +00:00
|
|
|
dst, major(sb.st_rdev), minor(sb.st_rdev), tmpsrc);
|
2013-07-16 02:00:00 +00:00
|
|
|
if (mknod(dst, mode, sb.st_rdev) < 0) {
|
|
|
|
virReportSystemError(errno,
|
|
|
|
_("Unable to create device %s"),
|
|
|
|
dst);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2013-07-16 02:00:02 +00:00
|
|
|
if (lxcContainerChown(ctrl->def, dst) < 0)
|
2013-07-16 02:00:01 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2013-07-16 02:00:00 +00:00
|
|
|
/* Labelling normally operates on src, but we need
|
2013-09-26 21:40:34 +00:00
|
|
|
* to actually label the dst here, so hack the config */
|
2014-05-21 23:13:12 +00:00
|
|
|
def->src->path = dst;
|
2014-06-18 12:46:27 +00:00
|
|
|
if (virSecurityManagerSetDiskLabel(securityDriver, ctrl->def, def) < 0)
|
2013-07-16 02:00:00 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
2014-03-25 06:49:26 +00:00
|
|
|
cleanup:
|
2014-05-21 23:13:12 +00:00
|
|
|
def->src->path = tmpsrc;
|
2013-07-16 02:00:00 +00:00
|
|
|
VIR_FREE(dst);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int virLXCControllerSetupAllDisks(virLXCControllerPtr ctrl)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
VIR_DEBUG("Setting up disks");
|
|
|
|
|
|
|
|
for (i = 0; i < ctrl->def->ndisks; i++) {
|
|
|
|
if (virLXCControllerSetupDisk(ctrl, ctrl->def->disks[i],
|
|
|
|
ctrl->securityManager) < 0)
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
VIR_DEBUG("Setup all disks");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-08-13 10:52:15 +00:00
|
|
|
/**
|
2012-07-03 11:06:38 +00:00
|
|
|
* virLXCControllerMoveInterfaces
|
2008-08-13 10:52:15 +00:00
|
|
|
* @nveths: number of interfaces
|
|
|
|
* @veths: interface names
|
|
|
|
* @container: pid of container
|
|
|
|
*
|
|
|
|
* Moves network interfaces into a container's namespace
|
|
|
|
*
|
|
|
|
* Returns 0 on success or -1 in case of error
|
|
|
|
*/
|
2012-07-03 11:12:59 +00:00
|
|
|
static int virLXCControllerMoveInterfaces(virLXCControllerPtr ctrl)
|
2008-08-13 10:52:15 +00:00
|
|
|
{
|
2012-07-03 11:06:38 +00:00
|
|
|
size_t i;
|
2013-04-05 12:26:40 +00:00
|
|
|
virDomainDefPtr def = ctrl->def;
|
2012-07-03 11:06:38 +00:00
|
|
|
|
2013-05-21 08:03:33 +00:00
|
|
|
for (i = 0; i < ctrl->nveths; i++) {
|
2012-07-03 11:12:59 +00:00
|
|
|
if (virNetDevSetNamespace(ctrl->veths[i], ctrl->initpid) < 0)
|
2008-08-13 10:52:15 +00:00
|
|
|
return -1;
|
2012-07-03 11:06:38 +00:00
|
|
|
}
|
2008-08-13 10:52:15 +00:00
|
|
|
|
2013-04-05 12:26:40 +00:00
|
|
|
for (i = 0; i < def->nhostdevs; i ++) {
|
|
|
|
virDomainHostdevDefPtr hdev = def->hostdevs[i];
|
|
|
|
|
|
|
|
if (hdev->mode != VIR_DOMAIN_HOSTDEV_MODE_CAPABILITIES)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
virDomainHostdevCaps hdcaps = hdev->source.caps;
|
|
|
|
|
|
|
|
if (hdcaps.type != VIR_DOMAIN_HOSTDEV_CAPS_TYPE_NET)
|
2015-05-12 12:40:34 +00:00
|
|
|
continue;
|
2013-04-05 12:26:40 +00:00
|
|
|
|
2016-06-06 19:44:15 +00:00
|
|
|
if (virNetDevSetNamespace(hdcaps.u.net.ifname, ctrl->initpid) < 0)
|
2013-04-05 12:26:40 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2008-08-13 10:52:15 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2012-07-03 11:06:38 +00:00
|
|
|
* virLXCControllerDeleteInterfaces:
|
|
|
|
* @ctrl: the LXC controller
|
2008-08-13 10:52:15 +00:00
|
|
|
*
|
|
|
|
* Cleans up the container interfaces by deleting the veth device pairs.
|
|
|
|
*
|
|
|
|
* Returns 0 on success or -1 in case of error
|
|
|
|
*/
|
2012-07-03 11:06:38 +00:00
|
|
|
static int virLXCControllerDeleteInterfaces(virLXCControllerPtr ctrl)
|
2008-08-13 10:52:15 +00:00
|
|
|
{
|
2012-07-03 11:06:38 +00:00
|
|
|
size_t i;
|
|
|
|
int ret = 0;
|
2008-08-13 10:52:15 +00:00
|
|
|
|
2013-05-21 08:03:33 +00:00
|
|
|
for (i = 0; i < ctrl->nveths; i++) {
|
2012-07-03 11:06:38 +00:00
|
|
|
if (virNetDevVethDelete(ctrl->veths[i]) < 0)
|
|
|
|
ret = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2008-08-13 10:52:15 +00:00
|
|
|
}
|
|
|
|
|
2012-07-03 11:06:38 +00:00
|
|
|
|
2011-02-23 17:17:53 +00:00
|
|
|
static int lxcSetPersonality(virDomainDefPtr def)
|
|
|
|
{
|
2012-12-10 22:28:09 +00:00
|
|
|
virArch altArch;
|
2011-02-23 17:17:53 +00:00
|
|
|
|
2015-01-16 17:20:48 +00:00
|
|
|
VIR_DEBUG("Checking for 32-bit personality");
|
2012-12-10 22:28:09 +00:00
|
|
|
altArch = lxcContainerGetAlt32bitArch(virArchFromHost());
|
2011-02-23 17:17:53 +00:00
|
|
|
if (altArch &&
|
2012-12-10 22:28:09 +00:00
|
|
|
(def->os.arch == altArch)) {
|
2015-01-16 17:20:48 +00:00
|
|
|
VIR_DEBUG("Setting personality to %s",
|
|
|
|
virArchToString(altArch));
|
2011-02-23 17:17:53 +00:00
|
|
|
if (personality(PER_LINUX32) < 0) {
|
|
|
|
virReportSystemError(errno, _("Unable to request personality for %s on %s"),
|
2012-12-10 22:28:09 +00:00
|
|
|
virArchToString(altArch),
|
|
|
|
virArchToString(virArchFromHost()));
|
2011-02-23 17:17:53 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-04-22 14:26:50 +00:00
|
|
|
#ifndef MS_REC
|
2010-03-09 18:22:22 +00:00
|
|
|
# define MS_REC 16384
|
2009-04-22 14:26:50 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef MS_SLAVE
|
2010-03-09 18:22:22 +00:00
|
|
|
# define MS_SLAVE (1<<19)
|
2009-04-22 14:26:50 +00:00
|
|
|
#endif
|
2008-08-13 10:52:15 +00:00
|
|
|
|
2011-10-19 01:39:57 +00:00
|
|
|
/* Create a private tty using the private devpts at PTMX, returning
|
|
|
|
* the master in *TTYMASTER and the name of the slave, _from the
|
|
|
|
* perspective of the guest after remounting file systems_, in
|
|
|
|
* *TTYNAME. Heavily borrowed from glibc, but doesn't require that
|
|
|
|
* devpts == "/dev/pts" */
|
|
|
|
static int
|
2013-06-07 07:12:23 +00:00
|
|
|
lxcCreateTty(virLXCControllerPtr ctrl, int *ttymaster,
|
|
|
|
char **ttyName, char **ttyHostPath)
|
2011-10-19 01:39:57 +00:00
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
int ptyno;
|
|
|
|
int unlock = 0;
|
|
|
|
|
2013-06-07 07:12:23 +00:00
|
|
|
if ((*ttymaster = open(ctrl->devptmx, O_RDWR|O_NOCTTY|O_NONBLOCK)) < 0)
|
2011-10-19 01:39:57 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (ioctl(*ttymaster, TIOCSPTLCK, &unlock) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (ioctl(*ttymaster, TIOCGPTN, &ptyno) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
/* If mount() succeeded at honoring newinstance, then the kernel
|
|
|
|
* was new enough to also honor the mode=0620,gid=5 options, which
|
|
|
|
* guarantee that the new pty already has correct permissions; so
|
|
|
|
* while glibc has to fstat(), fchmod(), and fchown() for older
|
|
|
|
* kernels, we can skip those steps. ptyno shouldn't currently be
|
|
|
|
* anything other than 0, but let's play it safe. */
|
2013-06-07 07:12:23 +00:00
|
|
|
if ((virAsprintf(ttyName, "/dev/pts/%d", ptyno) < 0) ||
|
|
|
|
(virAsprintf(ttyHostPath, "/%s/%s.devpts/%d", LXC_STATE_DIR,
|
2015-05-12 12:40:34 +00:00
|
|
|
ctrl->def->name, ptyno) < 0)) {
|
2011-10-19 01:39:57 +00:00
|
|
|
errno = ENOMEM;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
2014-03-25 06:49:26 +00:00
|
|
|
cleanup:
|
2011-10-19 01:39:57 +00:00
|
|
|
if (ret != 0) {
|
|
|
|
VIR_FORCE_CLOSE(*ttymaster);
|
|
|
|
VIR_FREE(*ttyName);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-07-03 13:02:33 +00:00
|
|
|
|
2013-01-07 18:14:34 +00:00
|
|
|
static int
|
|
|
|
virLXCControllerSetupPrivateNS(void)
|
|
|
|
{
|
2013-05-20 10:12:19 +00:00
|
|
|
/*
|
|
|
|
* If doing a chroot style setup, we need to prepare
|
|
|
|
* a private /dev/pts for the child now, which they
|
|
|
|
* will later move into position.
|
|
|
|
*
|
|
|
|
* This is complex because 'virsh console' needs to
|
|
|
|
* use /dev/pts from the host OS, and the guest OS
|
|
|
|
* needs to use /dev/pts from the guest.
|
|
|
|
*
|
|
|
|
* This means that we (libvirt_lxc) need to see and
|
|
|
|
* use both /dev/pts instances. We're running in the
|
|
|
|
* host OS context though and don't want to expose
|
|
|
|
* the guest OS /dev/pts there.
|
|
|
|
*
|
|
|
|
* Thus we call unshare(CLONE_NS) so that we can see
|
|
|
|
* the guest's new /dev/pts, without it becoming
|
|
|
|
* visible to the host OS. We also put the root FS
|
|
|
|
* into slave mode, just in case it was currently
|
|
|
|
* marked as shared
|
|
|
|
*/
|
|
|
|
|
2016-11-10 13:55:48 +00:00
|
|
|
return virProcessSetupPrivateMountNS();
|
2013-01-07 18:14:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-08-13 10:52:15 +00:00
|
|
|
static int
|
2012-07-03 13:02:33 +00:00
|
|
|
virLXCControllerSetupDevPTS(virLXCControllerPtr ctrl)
|
2008-08-13 10:52:15 +00:00
|
|
|
{
|
2012-05-11 10:02:50 +00:00
|
|
|
char *mount_options = NULL;
|
2012-11-14 15:39:48 +00:00
|
|
|
char *opts = NULL;
|
2012-07-03 13:02:33 +00:00
|
|
|
char *devpts = NULL;
|
|
|
|
int ret = -1;
|
2014-07-28 20:59:17 +00:00
|
|
|
gid_t ptsgid = 5;
|
2008-08-13 10:52:15 +00:00
|
|
|
|
2012-07-03 13:02:33 +00:00
|
|
|
VIR_DEBUG("Setting up private /dev/pts");
|
2010-03-04 11:15:42 +00:00
|
|
|
|
2012-07-03 13:02:33 +00:00
|
|
|
mount_options = virSecurityManagerGetMountOptions(ctrl->securityManager,
|
|
|
|
ctrl->def);
|
2011-06-02 18:25:25 +00:00
|
|
|
|
2013-03-22 13:54:12 +00:00
|
|
|
if (virAsprintf(&devpts, "%s/%s.devpts",
|
|
|
|
LXC_STATE_DIR, ctrl->def->name) < 0 ||
|
|
|
|
virAsprintf(&ctrl->devptmx, "%s/%s.devpts/ptmx",
|
2013-07-04 10:11:37 +00:00
|
|
|
LXC_STATE_DIR, ctrl->def->name) < 0)
|
2012-07-03 13:02:33 +00:00
|
|
|
goto cleanup;
|
2009-04-22 14:26:50 +00:00
|
|
|
|
2012-07-03 13:02:33 +00:00
|
|
|
if (virFileMakePath(devpts) < 0) {
|
|
|
|
virReportSystemError(errno,
|
|
|
|
_("Failed to make path %s"),
|
|
|
|
devpts);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2009-04-22 14:26:50 +00:00
|
|
|
|
2014-07-28 20:59:17 +00:00
|
|
|
if (ctrl->def->idmap.ngidmap)
|
|
|
|
ptsgid = virLXCControllerLookupUsernsMap(ctrl->def->idmap.gidmap,
|
|
|
|
ctrl->def->idmap.ngidmap,
|
|
|
|
ptsgid);
|
|
|
|
|
2012-07-03 13:02:33 +00:00
|
|
|
/* XXX should we support gid=X for X!=5 for distros which use
|
|
|
|
* a different gid for tty? */
|
2014-07-28 20:59:17 +00:00
|
|
|
if (virAsprintf(&opts, "newinstance,ptmxmode=0666,mode=0620,gid=%u%s",
|
|
|
|
ptsgid, (mount_options ? mount_options : "")) < 0)
|
2012-07-03 13:02:33 +00:00
|
|
|
goto cleanup;
|
2012-01-25 14:12:54 +00:00
|
|
|
|
2017-09-25 10:43:33 +00:00
|
|
|
VIR_DEBUG("Mount devpts on %s type=tmpfs flags=0x%x, opts=%s",
|
2012-07-03 13:02:33 +00:00
|
|
|
devpts, MS_NOSUID, opts);
|
|
|
|
if (mount("devpts", devpts, "devpts", MS_NOSUID, opts) < 0) {
|
|
|
|
virReportSystemError(errno,
|
|
|
|
_("Failed to mount devpts on %s"),
|
|
|
|
devpts);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2009-04-22 14:26:50 +00:00
|
|
|
|
2012-07-03 13:02:33 +00:00
|
|
|
if (access(ctrl->devptmx, R_OK) < 0) {
|
2013-03-28 17:30:25 +00:00
|
|
|
virReportSystemError(ENOSYS, "%s",
|
|
|
|
_("Kernel does not support private devpts"));
|
|
|
|
goto cleanup;
|
2009-04-22 14:26:50 +00:00
|
|
|
}
|
|
|
|
|
2013-07-16 02:00:02 +00:00
|
|
|
if ((lxcContainerChown(ctrl->def, ctrl->devptmx) < 0) ||
|
|
|
|
(lxcContainerChown(ctrl->def, devpts) < 0))
|
2015-05-12 12:40:34 +00:00
|
|
|
goto cleanup;
|
2013-06-07 07:12:26 +00:00
|
|
|
|
2012-07-03 13:02:33 +00:00
|
|
|
ret = 0;
|
|
|
|
|
2014-03-25 06:49:26 +00:00
|
|
|
cleanup:
|
2012-07-03 13:02:33 +00:00
|
|
|
VIR_FREE(opts);
|
|
|
|
VIR_FREE(devpts);
|
2013-05-20 10:12:18 +00:00
|
|
|
VIR_FREE(mount_options);
|
2012-07-03 13:02:33 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-11-14 09:39:04 +00:00
|
|
|
static int
|
|
|
|
virLXCControllerSetupFuse(virLXCControllerPtr ctrl)
|
|
|
|
{
|
|
|
|
return lxcSetupFuse(&ctrl->fuse, ctrl->def);
|
|
|
|
}
|
|
|
|
|
2013-11-15 16:15:59 +00:00
|
|
|
static int
|
|
|
|
virLXCControllerStartFuse(virLXCControllerPtr ctrl)
|
|
|
|
{
|
|
|
|
return lxcStartFuse(ctrl->fuse);
|
|
|
|
}
|
|
|
|
|
2012-07-03 13:02:33 +00:00
|
|
|
static int
|
|
|
|
virLXCControllerSetupConsoles(virLXCControllerPtr ctrl,
|
|
|
|
char **containerTTYPaths)
|
|
|
|
{
|
|
|
|
size_t i;
|
2013-06-07 07:12:23 +00:00
|
|
|
int ret = -1;
|
|
|
|
char *ttyHostPath = NULL;
|
2012-07-03 13:02:33 +00:00
|
|
|
|
2013-05-21 08:03:33 +00:00
|
|
|
for (i = 0; i < ctrl->nconsoles; i++) {
|
2013-03-28 17:30:25 +00:00
|
|
|
VIR_DEBUG("Opening tty on private %s", ctrl->devptmx);
|
2013-06-07 07:12:23 +00:00
|
|
|
if (lxcCreateTty(ctrl,
|
2013-03-28 17:30:25 +00:00
|
|
|
&ctrl->consoles[i].contFd,
|
2013-06-07 07:12:23 +00:00
|
|
|
&containerTTYPaths[i], &ttyHostPath) < 0) {
|
2013-03-28 17:30:25 +00:00
|
|
|
virReportSystemError(errno, "%s",
|
2015-05-12 12:40:34 +00:00
|
|
|
_("Failed to allocate tty"));
|
2013-06-07 07:12:23 +00:00
|
|
|
goto cleanup;
|
2011-10-20 08:44:31 +00:00
|
|
|
}
|
2013-06-07 07:12:23 +00:00
|
|
|
|
|
|
|
/* Change the owner of tty device to the root user of container */
|
2013-07-16 02:00:02 +00:00
|
|
|
if (lxcContainerChown(ctrl->def, ttyHostPath) < 0)
|
2013-06-07 07:12:23 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
VIR_FREE(ttyHostPath);
|
2011-10-20 08:44:31 +00:00
|
|
|
}
|
2013-06-07 07:12:23 +00:00
|
|
|
|
|
|
|
ret = 0;
|
2014-03-25 06:49:26 +00:00
|
|
|
cleanup:
|
2013-06-07 07:12:23 +00:00
|
|
|
VIR_FREE(ttyHostPath);
|
|
|
|
return ret;
|
2012-07-03 13:02:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-07-17 14:54:08 +00:00
|
|
|
static void
|
|
|
|
virLXCControllerEventSend(virLXCControllerPtr ctrl,
|
|
|
|
int procnr,
|
|
|
|
xdrproc_t proc,
|
|
|
|
void *data)
|
|
|
|
{
|
|
|
|
virNetMessagePtr msg;
|
|
|
|
|
2012-11-20 17:49:25 +00:00
|
|
|
if (!ctrl->client) {
|
2013-09-27 05:43:24 +00:00
|
|
|
VIR_WARN("Dropping event %d because libvirtd is not connected", procnr);
|
2012-07-17 14:54:08 +00:00
|
|
|
return;
|
2012-11-20 17:49:25 +00:00
|
|
|
}
|
2012-07-17 14:54:08 +00:00
|
|
|
|
|
|
|
VIR_DEBUG("Send event %d client=%p", procnr, ctrl->client);
|
|
|
|
if (!(msg = virNetMessageNew(false)))
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
msg->header.prog = virNetServerProgramGetID(ctrl->prog);
|
|
|
|
msg->header.vers = virNetServerProgramGetVersion(ctrl->prog);
|
|
|
|
msg->header.proc = procnr;
|
|
|
|
msg->header.type = VIR_NET_MESSAGE;
|
|
|
|
msg->header.serial = 1;
|
|
|
|
msg->header.status = VIR_NET_OK;
|
|
|
|
|
|
|
|
if (virNetMessageEncodeHeader(msg) < 0)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
if (virNetMessageEncodePayload(msg, proc, data) < 0)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
VIR_DEBUG("Queue event %d %zu", procnr, msg->bufferLength);
|
2018-02-26 11:13:50 +00:00
|
|
|
if (virNetServerClientSendMessage(ctrl->client, msg) < 0)
|
|
|
|
goto error;
|
2012-07-17 14:54:08 +00:00
|
|
|
|
|
|
|
xdr_free(proc, data);
|
|
|
|
return;
|
|
|
|
|
2014-03-25 06:49:26 +00:00
|
|
|
error:
|
2012-07-17 14:54:08 +00:00
|
|
|
virNetMessageFree(msg);
|
|
|
|
xdr_free(proc, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
virLXCControllerEventSendExit(virLXCControllerPtr ctrl,
|
|
|
|
int exitstatus)
|
|
|
|
{
|
2013-03-13 19:19:22 +00:00
|
|
|
virLXCMonitorExitEventMsg msg;
|
2012-07-17 14:54:08 +00:00
|
|
|
|
2012-11-22 16:45:39 +00:00
|
|
|
VIR_DEBUG("Exit status %d (client=%p)", exitstatus, ctrl->client);
|
2012-07-17 14:54:08 +00:00
|
|
|
memset(&msg, 0, sizeof(msg));
|
|
|
|
switch (exitstatus) {
|
|
|
|
case 0:
|
2013-03-13 19:19:22 +00:00
|
|
|
msg.status = VIR_LXC_MONITOR_EXIT_STATUS_SHUTDOWN;
|
2012-07-17 14:54:08 +00:00
|
|
|
break;
|
2012-07-23 11:25:37 +00:00
|
|
|
case 1:
|
2013-03-13 19:19:22 +00:00
|
|
|
msg.status = VIR_LXC_MONITOR_EXIT_STATUS_REBOOT;
|
2012-07-23 11:25:37 +00:00
|
|
|
break;
|
2012-07-17 14:54:08 +00:00
|
|
|
default:
|
2013-03-13 19:19:22 +00:00
|
|
|
msg.status = VIR_LXC_MONITOR_EXIT_STATUS_ERROR;
|
2012-07-17 14:54:08 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
virLXCControllerEventSend(ctrl,
|
2013-03-13 19:19:22 +00:00
|
|
|
VIR_LXC_MONITOR_PROC_EXIT_EVENT,
|
|
|
|
(xdrproc_t)xdr_virLXCMonitorExitEventMsg,
|
2012-07-17 14:54:08 +00:00
|
|
|
(void*)&msg);
|
|
|
|
|
|
|
|
if (ctrl->client) {
|
|
|
|
VIR_DEBUG("Waiting for client to complete dispatch");
|
|
|
|
ctrl->inShutdown = true;
|
|
|
|
virNetServerClientDelayedClose(ctrl->client);
|
2015-03-16 14:02:41 +00:00
|
|
|
virNetDaemonRun(ctrl->daemon);
|
2012-07-17 14:54:08 +00:00
|
|
|
}
|
|
|
|
VIR_DEBUG("Client has gone away");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-11-20 17:49:25 +00:00
|
|
|
static int
|
|
|
|
virLXCControllerEventSendInit(virLXCControllerPtr ctrl,
|
|
|
|
pid_t initpid)
|
|
|
|
{
|
2013-03-13 19:19:22 +00:00
|
|
|
virLXCMonitorInitEventMsg msg;
|
2012-11-20 17:49:25 +00:00
|
|
|
|
2018-04-25 12:42:34 +00:00
|
|
|
VIR_DEBUG("Init pid %lld", (long long)initpid);
|
2012-11-20 17:49:25 +00:00
|
|
|
memset(&msg, 0, sizeof(msg));
|
|
|
|
msg.initpid = initpid;
|
|
|
|
|
|
|
|
virLXCControllerEventSend(ctrl,
|
2013-03-13 19:19:22 +00:00
|
|
|
VIR_LXC_MONITOR_PROC_INIT_EVENT,
|
|
|
|
(xdrproc_t)xdr_virLXCMonitorInitEventMsg,
|
2012-11-20 17:49:25 +00:00
|
|
|
(void*)&msg);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-07-03 13:02:33 +00:00
|
|
|
static int
|
2012-07-03 13:40:45 +00:00
|
|
|
virLXCControllerRun(virLXCControllerPtr ctrl)
|
2012-07-03 13:02:33 +00:00
|
|
|
{
|
|
|
|
int rc = -1;
|
|
|
|
int control[2] = { -1, -1};
|
|
|
|
int containerhandshake[2] = { -1, -1 };
|
|
|
|
char **containerTTYPaths = NULL;
|
|
|
|
size_t i;
|
|
|
|
|
2013-07-04 10:11:37 +00:00
|
|
|
if (VIR_ALLOC_N(containerTTYPaths, ctrl->nconsoles) < 0)
|
2012-07-03 13:02:33 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (socketpair(PF_UNIX, SOCK_STREAM, 0, control) < 0) {
|
|
|
|
virReportSystemError(errno, "%s",
|
|
|
|
_("sockpair failed"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (socketpair(PF_UNIX, SOCK_STREAM, 0, containerhandshake) < 0) {
|
|
|
|
virReportSystemError(errno, "%s",
|
|
|
|
_("socketpair failed"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2013-01-07 18:14:34 +00:00
|
|
|
if (virLXCControllerSetupPrivateNS() < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2012-07-03 13:02:33 +00:00
|
|
|
if (virLXCControllerSetupLoopDevices(ctrl) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2013-07-22 15:36:06 +00:00
|
|
|
if (virLXCControllerSetupResourceLimits(ctrl) < 0)
|
2012-07-03 13:02:33 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virLXCControllerSetupDevPTS(ctrl) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2013-06-07 07:12:22 +00:00
|
|
|
if (virLXCControllerPopulateDevices(ctrl) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2013-07-16 02:00:00 +00:00
|
|
|
if (virLXCControllerSetupAllDisks(ctrl) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2013-07-16 02:00:04 +00:00
|
|
|
if (virLXCControllerSetupAllHostdevs(ctrl) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2012-11-14 09:39:04 +00:00
|
|
|
if (virLXCControllerSetupFuse(ctrl) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2012-07-03 13:02:33 +00:00
|
|
|
if (virLXCControllerSetupConsoles(ctrl, containerTTYPaths) < 0)
|
|
|
|
goto cleanup;
|
2011-10-20 08:44:31 +00:00
|
|
|
|
2012-07-03 10:54:09 +00:00
|
|
|
if (lxcSetPersonality(ctrl->def) < 0)
|
2011-02-23 17:17:53 +00:00
|
|
|
goto cleanup;
|
2009-04-22 14:26:50 +00:00
|
|
|
|
2012-07-03 11:12:59 +00:00
|
|
|
if ((ctrl->initpid = lxcContainerStart(ctrl->def,
|
2012-07-03 12:59:36 +00:00
|
|
|
ctrl->securityManager,
|
2012-07-03 11:12:59 +00:00
|
|
|
ctrl->nveths,
|
|
|
|
ctrl->veths,
|
2013-07-09 17:15:45 +00:00
|
|
|
ctrl->npassFDs,
|
|
|
|
ctrl->passFDs,
|
2012-07-03 11:12:59 +00:00
|
|
|
control[1],
|
|
|
|
containerhandshake[1],
|
2015-08-20 13:46:17 +00:00
|
|
|
ctrl->nsFDs,
|
2013-07-09 17:15:45 +00:00
|
|
|
ctrl->nconsoles,
|
|
|
|
containerTTYPaths)) < 0)
|
2008-08-13 10:52:15 +00:00
|
|
|
goto cleanup;
|
2010-11-09 20:48:48 +00:00
|
|
|
VIR_FORCE_CLOSE(control[1]);
|
2011-06-02 15:52:32 +00:00
|
|
|
VIR_FORCE_CLOSE(containerhandshake[1]);
|
2008-08-13 10:52:15 +00:00
|
|
|
|
2013-07-09 17:15:45 +00:00
|
|
|
for (i = 0; i < ctrl->npassFDs; i++)
|
|
|
|
VIR_FORCE_CLOSE(ctrl->passFDs[i]);
|
|
|
|
|
2015-08-20 13:46:17 +00:00
|
|
|
if (ctrl->nsFDs)
|
|
|
|
for (i = 0; i < VIR_LXC_DOMAIN_NAMESPACE_LAST; i++)
|
|
|
|
VIR_FORCE_CLOSE(ctrl->nsFDs[i]);
|
|
|
|
|
2015-01-16 16:23:45 +00:00
|
|
|
if (virLXCControllerSetupCgroupLimits(ctrl) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2013-06-07 07:12:21 +00:00
|
|
|
if (virLXCControllerSetupUserns(ctrl) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2012-07-03 11:12:59 +00:00
|
|
|
if (virLXCControllerMoveInterfaces(ctrl) < 0)
|
2008-08-13 10:52:15 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2013-11-15 16:15:59 +00:00
|
|
|
if (virLXCControllerStartFuse(ctrl) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2011-06-02 15:18:14 +00:00
|
|
|
if (lxcContainerSendContinue(control[0]) < 0) {
|
|
|
|
virReportSystemError(errno, "%s",
|
|
|
|
_("Unable to send container continue message"));
|
2008-08-13 10:52:15 +00:00
|
|
|
goto cleanup;
|
2011-06-02 15:18:14 +00:00
|
|
|
}
|
2008-08-13 10:52:15 +00:00
|
|
|
|
2011-06-02 15:52:32 +00:00
|
|
|
if (lxcContainerWaitForContinue(containerhandshake[0]) < 0) {
|
|
|
|
virReportSystemError(errno, "%s",
|
|
|
|
_("error receiving signal from container"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2011-08-04 09:13:02 +00:00
|
|
|
/* ...and reduce our privileges */
|
2009-06-29 17:09:42 +00:00
|
|
|
if (lxcControllerClearCapabilities() < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2013-05-21 08:03:33 +00:00
|
|
|
for (i = 0; i < ctrl->nconsoles; i++)
|
2012-07-03 11:42:53 +00:00
|
|
|
if (virLXCControllerConsoleSetNonblocking(&(ctrl->consoles[i])) < 0)
|
2011-10-20 08:44:31 +00:00
|
|
|
goto cleanup;
|
2011-10-19 15:22:24 +00:00
|
|
|
|
2016-07-19 14:23:25 +00:00
|
|
|
if (virLXCControllerDaemonHandshake(ctrl) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2013-10-11 14:57:31 +00:00
|
|
|
/* We must not hold open a dbus connection for life
|
|
|
|
* of LXC instance, since dbus-daemon is limited to
|
|
|
|
* only a few 100 connections by default
|
|
|
|
*/
|
|
|
|
virDBusCloseSystemBus();
|
|
|
|
|
2012-07-03 13:40:45 +00:00
|
|
|
rc = virLXCControllerMain(ctrl);
|
2008-08-13 10:52:15 +00:00
|
|
|
|
2012-07-17 14:54:08 +00:00
|
|
|
virLXCControllerEventSendExit(ctrl, rc);
|
|
|
|
|
2014-03-25 06:49:26 +00:00
|
|
|
cleanup:
|
2010-11-09 20:48:48 +00:00
|
|
|
VIR_FORCE_CLOSE(control[0]);
|
|
|
|
VIR_FORCE_CLOSE(control[1]);
|
2011-06-02 15:52:32 +00:00
|
|
|
VIR_FORCE_CLOSE(containerhandshake[0]);
|
|
|
|
VIR_FORCE_CLOSE(containerhandshake[1]);
|
2008-08-13 10:52:15 +00:00
|
|
|
|
2013-05-21 08:03:33 +00:00
|
|
|
for (i = 0; i < ctrl->nconsoles; i++)
|
2012-07-03 11:42:53 +00:00
|
|
|
VIR_FREE(containerTTYPaths[i]);
|
|
|
|
VIR_FREE(containerTTYPaths);
|
2011-10-27 07:18:00 +00:00
|
|
|
|
2012-07-03 11:12:59 +00:00
|
|
|
virLXCControllerStopInit(ctrl);
|
2011-10-21 17:09:23 +00:00
|
|
|
|
2008-08-13 10:52:15 +00:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-08-20 20:55:32 +00:00
|
|
|
int main(int argc, char *argv[])
|
2008-08-13 10:52:15 +00:00
|
|
|
{
|
|
|
|
pid_t pid;
|
2013-10-11 16:28:31 +00:00
|
|
|
int rc = -1;
|
2014-01-07 14:42:44 +00:00
|
|
|
const char *name = NULL;
|
2012-07-03 11:06:38 +00:00
|
|
|
size_t nveths = 0;
|
2008-08-20 20:55:32 +00:00
|
|
|
char **veths = NULL;
|
2015-08-20 13:46:17 +00:00
|
|
|
int ns_fd[VIR_LXC_DOMAIN_NAMESPACE_LAST];
|
2012-07-03 12:16:48 +00:00
|
|
|
int handshakeFd = -1;
|
2013-05-24 10:14:02 +00:00
|
|
|
bool bg = false;
|
2009-02-03 13:08:59 +00:00
|
|
|
const struct option options[] = {
|
2008-08-20 20:55:32 +00:00
|
|
|
{ "background", 0, NULL, 'b' },
|
|
|
|
{ "name", 1, NULL, 'n' },
|
|
|
|
{ "veth", 1, NULL, 'v' },
|
|
|
|
{ "console", 1, NULL, 'c' },
|
2013-07-09 17:15:45 +00:00
|
|
|
{ "passfd", 1, NULL, 'p' },
|
2011-06-01 22:17:00 +00:00
|
|
|
{ "handshakefd", 1, NULL, 's' },
|
2012-01-25 14:12:53 +00:00
|
|
|
{ "security", 1, NULL, 'S' },
|
2015-08-20 13:46:17 +00:00
|
|
|
{ "share-net", 1, NULL, 'N' },
|
|
|
|
{ "share-ipc", 1, NULL, 'I' },
|
|
|
|
{ "share-uts", 1, NULL, 'U' },
|
2008-08-20 20:55:32 +00:00
|
|
|
{ "help", 0, NULL, 'h' },
|
|
|
|
{ 0, 0, 0, 0 },
|
|
|
|
};
|
2011-10-20 08:44:31 +00:00
|
|
|
int *ttyFDs = NULL;
|
|
|
|
size_t nttyFDs = 0;
|
2013-07-09 17:15:45 +00:00
|
|
|
int *passFDs = NULL;
|
|
|
|
size_t npassFDs = 0;
|
2012-07-03 10:54:09 +00:00
|
|
|
virLXCControllerPtr ctrl = NULL;
|
2012-07-03 11:42:53 +00:00
|
|
|
size_t i;
|
2012-07-03 12:59:36 +00:00
|
|
|
const char *securityDriver = "none";
|
2008-08-13 10:52:15 +00:00
|
|
|
|
2015-08-20 13:46:17 +00:00
|
|
|
for (i = 0; i < VIR_LXC_DOMAIN_NAMESPACE_LAST; i++)
|
|
|
|
ns_fd[i] = -1;
|
|
|
|
|
2016-04-12 22:29:52 +00:00
|
|
|
if (virGettextInitialize() < 0 ||
|
2013-10-08 13:35:01 +00:00
|
|
|
virThreadInitialize() < 0 ||
|
|
|
|
virErrorInitialize() < 0) {
|
2010-11-16 19:01:37 +00:00
|
|
|
fprintf(stderr, _("%s: initialization failed\n"), argv[0]);
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
2012-05-01 09:47:53 +00:00
|
|
|
/* Initialize logging */
|
|
|
|
virLogSetFromEnv();
|
|
|
|
|
2008-08-20 20:55:32 +00:00
|
|
|
while (1) {
|
|
|
|
int c;
|
2008-08-13 10:52:15 +00:00
|
|
|
|
2015-08-20 13:46:17 +00:00
|
|
|
c = getopt_long(argc, argv, "dn:v:p:m:c:s:h:S:N:I:U:",
|
2015-05-12 12:40:34 +00:00
|
|
|
options, NULL);
|
2008-08-20 20:55:32 +00:00
|
|
|
|
|
|
|
if (c == -1)
|
|
|
|
break;
|
|
|
|
|
|
|
|
switch (c) {
|
|
|
|
case 'b':
|
2013-05-24 10:14:02 +00:00
|
|
|
bg = true;
|
2008-08-20 20:55:32 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'n':
|
2014-01-07 14:42:44 +00:00
|
|
|
name = optarg;
|
2008-08-20 20:55:32 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'v':
|
2013-07-04 10:11:37 +00:00
|
|
|
if (VIR_REALLOC_N(veths, nveths+1) < 0)
|
2008-08-20 20:55:32 +00:00
|
|
|
goto cleanup;
|
2013-05-03 12:43:39 +00:00
|
|
|
if (VIR_STRDUP(veths[nveths++], optarg) < 0)
|
2008-08-20 20:55:32 +00:00
|
|
|
goto cleanup;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'c':
|
2013-07-04 10:11:37 +00:00
|
|
|
if (VIR_REALLOC_N(ttyFDs, nttyFDs + 1) < 0)
|
2011-10-20 08:44:31 +00:00
|
|
|
goto cleanup;
|
|
|
|
if (virStrToLong_i(optarg, NULL, 10, &ttyFDs[nttyFDs++]) < 0) {
|
2008-08-20 20:55:32 +00:00
|
|
|
fprintf(stderr, "malformed --console argument '%s'", optarg);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2013-07-09 17:15:45 +00:00
|
|
|
case 'p':
|
|
|
|
if (VIR_REALLOC_N(passFDs, npassFDs + 1) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
if (virStrToLong_i(optarg, NULL, 10, &passFDs[npassFDs++]) < 0) {
|
|
|
|
fprintf(stderr, "malformed --passfd argument '%s'", optarg);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2011-06-01 22:17:00 +00:00
|
|
|
case 's':
|
2012-07-03 12:16:48 +00:00
|
|
|
if (virStrToLong_i(optarg, NULL, 10, &handshakeFd) < 0) {
|
2011-06-01 22:17:00 +00:00
|
|
|
fprintf(stderr, "malformed --handshakefd argument '%s'",
|
|
|
|
optarg);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2015-08-20 13:46:17 +00:00
|
|
|
case 'N':
|
|
|
|
if (virStrToLong_i(optarg, NULL, 10, &ns_fd[VIR_LXC_DOMAIN_NAMESPACE_SHARENET]) < 0) {
|
|
|
|
fprintf(stderr, "malformed --share-net argument '%s'",
|
|
|
|
optarg);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'I':
|
|
|
|
if (virStrToLong_i(optarg, NULL, 10, &ns_fd[VIR_LXC_DOMAIN_NAMESPACE_SHAREIPC]) < 0) {
|
|
|
|
fprintf(stderr, "malformed --share-ipc argument '%s'",
|
|
|
|
optarg);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'U':
|
|
|
|
if (virStrToLong_i(optarg, NULL, 10, &ns_fd[VIR_LXC_DOMAIN_NAMESPACE_SHAREUTS]) < 0) {
|
|
|
|
fprintf(stderr, "malformed --share-uts argument '%s'",
|
|
|
|
optarg);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2012-01-25 14:12:53 +00:00
|
|
|
case 'S':
|
2012-07-03 12:59:36 +00:00
|
|
|
securityDriver = optarg;
|
2012-01-25 14:12:53 +00:00
|
|
|
break;
|
|
|
|
|
2008-08-20 20:55:32 +00:00
|
|
|
case 'h':
|
|
|
|
case '?':
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
fprintf(stderr, "syntax: %s [OPTIONS]\n", argv[0]);
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
fprintf(stderr, "Options\n");
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
fprintf(stderr, " -b, --background\n");
|
|
|
|
fprintf(stderr, " -n NAME, --name NAME\n");
|
|
|
|
fprintf(stderr, " -c FD, --console FD\n");
|
|
|
|
fprintf(stderr, " -v VETH, --veth VETH\n");
|
2011-06-01 22:17:00 +00:00
|
|
|
fprintf(stderr, " -s FD, --handshakefd FD\n");
|
2012-01-25 14:12:53 +00:00
|
|
|
fprintf(stderr, " -S NAME, --security NAME\n");
|
2015-08-20 13:46:17 +00:00
|
|
|
fprintf(stderr, " -N FD, --share-net FD\n");
|
|
|
|
fprintf(stderr, " -I FD, --share-ipc FD\n");
|
|
|
|
fprintf(stderr, " -U FD, --share-uts FD\n");
|
2008-08-20 20:55:32 +00:00
|
|
|
fprintf(stderr, " -h, --help\n");
|
|
|
|
fprintf(stderr, "\n");
|
2015-08-27 00:21:54 +00:00
|
|
|
rc = 0;
|
2008-08-20 20:55:32 +00:00
|
|
|
goto cleanup;
|
2008-08-13 10:52:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-20 20:55:32 +00:00
|
|
|
if (name == NULL) {
|
|
|
|
fprintf(stderr, "%s: missing --name argument for configuration\n", argv[0]);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2012-07-03 12:16:48 +00:00
|
|
|
if (handshakeFd < 0) {
|
2014-01-07 14:51:13 +00:00
|
|
|
fprintf(stderr, "%s: missing --handshakefd argument for container PTY\n",
|
2011-06-01 22:17:00 +00:00
|
|
|
argv[0]);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2013-10-09 11:13:45 +00:00
|
|
|
if (geteuid() != 0) {
|
2008-08-20 20:55:32 +00:00
|
|
|
fprintf(stderr, "%s: must be run as the 'root' user\n", argv[0]);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2008-08-13 10:52:15 +00:00
|
|
|
|
2011-10-19 15:22:24 +00:00
|
|
|
virEventRegisterDefaultImpl();
|
2013-10-11 14:57:31 +00:00
|
|
|
|
|
|
|
virDBusSetSharedBus(false);
|
2011-10-19 15:22:24 +00:00
|
|
|
|
2012-07-03 10:54:09 +00:00
|
|
|
if (!(ctrl = virLXCControllerNew(name)))
|
2008-08-20 20:55:32 +00:00
|
|
|
goto cleanup;
|
2008-08-13 10:52:15 +00:00
|
|
|
|
2012-07-03 12:16:48 +00:00
|
|
|
ctrl->handshakeFd = handshakeFd;
|
|
|
|
|
2012-07-03 12:59:36 +00:00
|
|
|
if (!(ctrl->securityManager = virSecurityManagerNew(securityDriver,
|
2015-10-06 15:01:48 +00:00
|
|
|
LXC_DRIVER_NAME, 0)))
|
2012-07-03 12:59:36 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2012-11-26 14:17:58 +00:00
|
|
|
if (ctrl->def->seclabels) {
|
|
|
|
VIR_DEBUG("Security model %s type %s label %s imagelabel %s",
|
|
|
|
NULLSTR(ctrl->def->seclabels[0]->model),
|
|
|
|
virDomainSeclabelTypeToString(ctrl->def->seclabels[0]->type),
|
|
|
|
NULLSTR(ctrl->def->seclabels[0]->label),
|
|
|
|
NULLSTR(ctrl->def->seclabels[0]->imagelabel));
|
|
|
|
} else {
|
|
|
|
VIR_DEBUG("Security model not initialized");
|
|
|
|
}
|
2012-05-01 09:47:53 +00:00
|
|
|
|
2012-07-03 11:06:38 +00:00
|
|
|
ctrl->veths = veths;
|
|
|
|
ctrl->nveths = nveths;
|
|
|
|
|
2013-07-09 17:15:45 +00:00
|
|
|
ctrl->passFDs = passFDs;
|
|
|
|
ctrl->npassFDs = npassFDs;
|
|
|
|
|
2015-08-20 13:46:17 +00:00
|
|
|
for (i = 0; i < VIR_LXC_DOMAIN_NAMESPACE_LAST; i++) {
|
|
|
|
if (ns_fd[i] != -1) {
|
|
|
|
if (!ctrl->nsFDs) {/*allocate only once */
|
|
|
|
size_t j = 0;
|
|
|
|
if (VIR_ALLOC_N(ctrl->nsFDs, VIR_LXC_DOMAIN_NAMESPACE_LAST) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
for (j = 0; j < VIR_LXC_DOMAIN_NAMESPACE_LAST; j++)
|
|
|
|
ctrl->nsFDs[j] = -1;
|
|
|
|
}
|
|
|
|
ctrl->nsFDs[i] = ns_fd[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-21 08:03:33 +00:00
|
|
|
for (i = 0; i < nttyFDs; i++) {
|
2012-07-03 11:42:53 +00:00
|
|
|
if (virLXCControllerAddConsole(ctrl, ttyFDs[i]) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
ttyFDs[i] = -1;
|
|
|
|
}
|
|
|
|
|
2012-07-03 11:06:38 +00:00
|
|
|
if (virLXCControllerValidateNICs(ctrl) < 0)
|
2008-08-20 20:55:32 +00:00
|
|
|
goto cleanup;
|
2008-08-13 10:52:15 +00:00
|
|
|
|
2015-01-16 16:58:39 +00:00
|
|
|
if (virLXCControllerGetNICIndexes(ctrl) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2012-07-03 11:42:53 +00:00
|
|
|
if (virLXCControllerValidateConsoles(ctrl) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2012-07-03 14:25:30 +00:00
|
|
|
if (virLXCControllerSetupServer(ctrl) < 0)
|
2008-08-20 20:55:32 +00:00
|
|
|
goto cleanup;
|
2008-08-13 10:52:15 +00:00
|
|
|
|
2008-08-20 20:55:32 +00:00
|
|
|
if (bg) {
|
|
|
|
if ((pid = fork()) < 0)
|
|
|
|
goto cleanup;
|
2008-08-13 10:52:15 +00:00
|
|
|
|
2008-08-20 20:55:32 +00:00
|
|
|
if (pid > 0) {
|
2011-08-05 13:13:12 +00:00
|
|
|
if ((rc = virPidFileWrite(LXC_STATE_DIR, name, pid)) < 0) {
|
2011-07-25 18:11:38 +00:00
|
|
|
virReportSystemError(-rc,
|
2009-01-20 17:13:33 +00:00
|
|
|
_("Unable to write pid file '%s/%s.pid'"),
|
|
|
|
LXC_STATE_DIR, name);
|
2008-08-20 20:55:32 +00:00
|
|
|
_exit(1);
|
|
|
|
}
|
2008-08-13 10:52:15 +00:00
|
|
|
|
2008-08-20 20:55:32 +00:00
|
|
|
/* First child now exits, allowing original caller
|
|
|
|
* (ie libvirtd's LXC driver to complete their
|
|
|
|
* waitpid & continue */
|
|
|
|
_exit(0);
|
2008-08-13 10:52:15 +00:00
|
|
|
}
|
|
|
|
|
2013-04-19 20:18:14 +00:00
|
|
|
/* Don't hold on to any cwd we inherit from libvirtd either */
|
2008-08-20 20:55:32 +00:00
|
|
|
if (chdir("/") < 0) {
|
2010-02-04 20:02:58 +00:00
|
|
|
virReportSystemError(errno, "%s",
|
2009-01-20 17:13:33 +00:00
|
|
|
_("Unable to change to root dir"));
|
2008-08-20 20:55:32 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (setsid() < 0) {
|
2010-02-04 20:02:58 +00:00
|
|
|
virReportSystemError(errno, "%s",
|
2009-01-20 17:13:33 +00:00
|
|
|
_("Unable to become session leader"));
|
2008-08-20 20:55:32 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
2008-08-13 10:52:15 +00:00
|
|
|
|
2012-07-03 13:40:45 +00:00
|
|
|
rc = virLXCControllerRun(ctrl);
|
2008-08-13 10:52:15 +00:00
|
|
|
|
2014-03-25 06:49:26 +00:00
|
|
|
cleanup:
|
2013-03-04 20:47:37 +00:00
|
|
|
if (rc < 0) {
|
2016-05-19 19:10:19 +00:00
|
|
|
fprintf(stderr,
|
|
|
|
_("Failure in libvirt_lxc startup: %s\n"),
|
|
|
|
virGetLastErrorMessage());
|
2013-03-04 20:47:37 +00:00
|
|
|
}
|
|
|
|
|
2012-07-03 10:54:09 +00:00
|
|
|
virPidFileDelete(LXC_STATE_DIR, name);
|
2012-11-26 11:13:56 +00:00
|
|
|
if (ctrl)
|
|
|
|
virLXCControllerDeleteInterfaces(ctrl);
|
2013-05-21 08:03:33 +00:00
|
|
|
for (i = 0; i < nttyFDs; i++)
|
2012-07-03 11:42:53 +00:00
|
|
|
VIR_FORCE_CLOSE(ttyFDs[i]);
|
|
|
|
VIR_FREE(ttyFDs);
|
2013-07-09 17:15:45 +00:00
|
|
|
for (i = 0; i < npassFDs; i++)
|
|
|
|
VIR_FORCE_CLOSE(passFDs[i]);
|
|
|
|
VIR_FREE(passFDs);
|
2012-07-03 11:42:53 +00:00
|
|
|
|
2012-07-03 10:54:09 +00:00
|
|
|
virLXCControllerFree(ctrl);
|
2008-08-20 20:55:32 +00:00
|
|
|
|
2012-07-17 14:54:08 +00:00
|
|
|
return rc < 0? EXIT_FAILURE : EXIT_SUCCESS;
|
2008-08-20 20:55:32 +00:00
|
|
|
}
|