mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-07 17:28:15 +00:00
domain: Require <init> for container guests
Use capabilities to allow a driver to register a default <init> if none is specified in the XML. Openvz was already open-coding this to be /sbin/init LXC currently falls over if no init is specified, so an explicit error is an improvement IMO. (Side note: I don't think we can set a default value for LXC. If we use /sbin/init but the user doesn't specify a separate root FS for their guest, the container will rerun the host's init which can be traumatic :). For virt-install I'm thinking of defaulting to /sbin/init if a root FS has been specified, otherwise require the user to manually specify <init>)
This commit is contained in:
parent
0571c3afde
commit
34639a3f6b
@ -150,6 +150,7 @@ struct _virCaps {
|
||||
int (*privateDataXMLFormat)(virBufferPtr, void *);
|
||||
int (*privateDataXMLParse)(xmlXPathContextPtr, void *);
|
||||
bool hasWideScsiBus;
|
||||
const char *defaultInitPath;
|
||||
|
||||
virDomainXMLNamespace ns;
|
||||
};
|
||||
|
@ -5708,6 +5708,18 @@ static virDomainDefPtr virDomainDefParseXML(virCapsPtr caps,
|
||||
|
||||
if (STREQ(def->os.type, "exe")) {
|
||||
def->os.init = virXPathString("string(./os/init[1])", ctxt);
|
||||
if (!def->os.init) {
|
||||
if (caps->defaultInitPath) {
|
||||
def->os.init = strdup(caps->defaultInitPath);
|
||||
if (!def->os.init) {
|
||||
goto no_memory;
|
||||
}
|
||||
} else {
|
||||
virDomainReportError(VIR_ERR_XML_ERROR, "%s",
|
||||
_("init binary must be specified"));
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (STREQ(def->os.type, "xen") ||
|
||||
|
@ -174,8 +174,10 @@ virCapsPtr openvzCapsInit(void)
|
||||
0,
|
||||
NULL) == NULL)
|
||||
goto no_memory;
|
||||
return caps;
|
||||
|
||||
caps->defaultInitPath = "/sbin/init";
|
||||
|
||||
return caps;
|
||||
no_memory:
|
||||
virCapabilitiesFree(caps);
|
||||
return NULL;
|
||||
|
@ -857,13 +857,6 @@ openvzDomainDefineXML(virConnectPtr conn, const char *xml)
|
||||
VIR_DOMAIN_XML_INACTIVE)) == NULL)
|
||||
goto cleanup;
|
||||
|
||||
if (vmdef->os.init == NULL) {
|
||||
if (!(vmdef->os.init = strdup("/sbin/init"))) {
|
||||
virReportOOMError();
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
|
||||
vm = virDomainFindByName(&driver->domains, vmdef->name);
|
||||
if (vm) {
|
||||
openvzError(VIR_ERR_OPERATION_FAILED,
|
||||
@ -943,13 +936,6 @@ openvzDomainCreateXML(virConnectPtr conn, const char *xml,
|
||||
VIR_DOMAIN_XML_INACTIVE)) == NULL)
|
||||
goto cleanup;
|
||||
|
||||
if (vmdef->os.init == NULL) {
|
||||
if (!(vmdef->os.init = strdup("/sbin/init"))) {
|
||||
virReportOOMError();
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
|
||||
vm = virDomainFindByName(&driver->domains, vmdef->name);
|
||||
if (vm) {
|
||||
openvzError(VIR_ERR_OPERATION_FAILED,
|
||||
|
Loading…
x
Reference in New Issue
Block a user