[PATCH] fix vm schizencephaly when heartbeat stoped
by Yilu Lin
>From e28cb2a03a670e4c0e7641f68f9d9f3accb00ae0 Mon Sep 17 00:00:00 2001
From: Yilu Lin <linyilu(a)huawei.com>
Date: Tue, 4 Aug 2020 02:42:00 -0400
Subject: [PATCH] fix vm schizencephaly when heartbeat stoped
Signed-off-by: Yilu Lin <linyilu(a)huawei.com>
If keepalive messages lost in finish step, vm maybe schizencephaly.
Shutdown src vm for protection.
---
src/qemu/qemu_migration.c | 22 ++++++++++++++++++++--
1 file changed, 20 insertions(+), 2 deletions(-)
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index 2c7bf34..b8296ba 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -4136,6 +4136,8 @@ qemuMigrationSrcPerformPeer2Peer3(virQEMUDriverPtr driver,
int cookieoutlen = 0;
int ret = -1;
virErrorPtr orig_err = NULL;
+ virErrorPtr finish_err = NULL;
+ bool living = true;
bool cancelled = true;
virStreamPtr st = NULL;
unsigned long destflags;
@@ -4394,7 +4396,16 @@ qemuMigrationSrcPerformPeer2Peer3(virQEMUDriverPtr driver,
* The lock manager plugins should take care of
* safety in this scenario.
*/
- cancelled = ddomain == NULL;
+ if (!cancelled && !ddomain)
+ finish_err = virSaveLastError();
+
+ if (finish_err && finish_err->message &&
+ strstr(finish_err->message, "received hangup / error event on socket")) {
+ living = false;
+ VIR_ERROR(_("keepalive messages lost in finish step, shutdown src vm for protection"));
+ } else {
+ cancelled = ddomain == NULL;
+ }
/* If finish3 set an error, and we don't have an earlier
* one we need to preserve it in case confirm3 overwrites
@@ -4427,10 +4438,17 @@ qemuMigrationSrcPerformPeer2Peer3(virQEMUDriverPtr driver,
virObjectUnref(ddomain);
ret = 0;
} else {
- ret = -1;
+ if (!living)
+ ret = 0;
+ else
+ ret = -1;
}
virObjectUnref(st);
+ if (finish_err) {
+ virSetError(finish_err);
+ virFreeError(finish_err);
+ }
virErrorRestore(&orig_err);
VIR_FREE(uri_out);
--
2.19.1
4 years, 2 months
[libvirt PATCH 0/3] AUTHORS: Convert to reStructuredText
by Andrea Bolognani
Plus some other adjustments.
Andrea Bolognani (3):
AUTHORS: Convert to reStructuredText
AUTHORS: Some small tweaks
AUTHORS: Remove Emacs file variables
AUTHORS.in | 103 -----------------------------------
AUTHORS.rst.in | 99 +++++++++++++++++++++++++++++++++
libvirt.spec.in | 2 +-
meson.build | 4 +-
scripts/meson-gen-authors.py | 2 +-
5 files changed, 103 insertions(+), 107 deletions(-)
delete mode 100644 AUTHORS.in
create mode 100644 AUTHORS.rst.in
--
2.26.2
4 years, 2 months
[PATCH] build-aux: use GNU sed for syntax-check on FreeBSD
by Roman Bogorodskiy
BSD sed(1) and GNU sed(1) syntax are not compatible, and as
syntax-check.mk uses the GNU flavor, set SED variable to
'gsed' by default.
Signed-off-by: Roman Bogorodskiy <bogorodskiy(a)gmail.com>
---
build-aux/syntax-check.mk | 8 ++++++++
1 file changed, 8 insertions(+)
I'm not sure if this requires a more comprehensive solution.
I have mixed feeling about this. If we try to just use gsed like in this
patch, it'll fail because we don't require gsed to be installed.
OTOH, an alternative solution like checking for gsed in meson.build,
and probably even generation of some files with variables to be sourced
by .mk files feels like too much of a hassle, esp. in this context.
diff --git a/build-aux/syntax-check.mk b/build-aux/syntax-check.mk
index 6eb59cf90e..bbfcb63152 100644
--- a/build-aux/syntax-check.mk
+++ b/build-aux/syntax-check.mk
@@ -28,7 +28,15 @@ ME := build-aux/syntax-check.mk
# ignoring the module description.
AWK ?= awk
GREP ?= grep
+# FreeBSD (and probably some other OSes too) ships own version of sed(1), not
+# compatible with the GNU sed. GNU sed is available as gsed(1), so use this
+# instead
+UNAME := $(shell uname)
+ifeq ($(UNAME),FreeBSD)
+SED ?= gsed
+else
SED ?= sed
+endif
# Helper variables.
_empty =
--
2.27.0
4 years, 2 months
[libvirt PATCH v2] Adds e1000e/vmxnet3 Vnet_hdr suuport
by Patrick Magauran
Changes from Original:
Moved Comparison to qemuInterfaceIsVnetCompatModel in qemu_interface.c per the recommendation of Daniel Berrangé
-----
Libvirt bases its decision about whether to apply the vnet_hdr flag to the tap interface on whether or not the selected model is VirtIO. Originally, VirtIO was the only model to support the vnet_hdr in QEMU; however, the e1000e & vmxnet3 adapters also support it(seemingly from introduction based on commits). This passes the whole packet to the host, reducing emulation overhead and improving performance.
Signed-off-by: Patrick Magauran <patmagauran.j(a)gmail.com>
---
src/qemu/qemu_interface.c | 15 +++++++++++----
src/qemu/qemu_interface.h | 1 +
2 files changed, 12 insertions(+), 4 deletions(-)
diff --git a/src/qemu/qemu_interface.c b/src/qemu/qemu_interface.c
index ffec992596..229bb299aa 100644
--- a/src/qemu/qemu_interface.c
+++ b/src/qemu/qemu_interface.c
@@ -230,6 +230,13 @@ qemuInterfaceStopDevices(virDomainDefPtr def)
return 0;
}
+bool qemuInterfaceIsVnetCompatModel(const virDomainNetDef *net)
+{
+ return (virDomainNetIsVirtioModel(net) ||
+ net->model == VIR_DOMAIN_NET_MODEL_E1000E ||
+ net->model == VIR_DOMAIN_NET_MODEL_VMXNET3);
+}
+
/**
* qemuInterfaceDirectConnect:
@@ -255,7 +262,7 @@ qemuInterfaceDirectConnect(virDomainDefPtr def,
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
unsigned int macvlan_create_flags = VIR_NETDEV_MACVLAN_CREATE_WITH_TAP;
- if (virDomainNetIsVirtioModel(net))
+ if (qemuInterfaceIsVnetCompatModel(net))
macvlan_create_flags |= VIR_NETDEV_MACVLAN_VNET_HDR;
if (virNetDevMacVLanCreateWithVPortProfile(net->ifname,
@@ -417,7 +424,7 @@ qemuInterfaceEthernetConnect(virDomainDefPtr def,
}
}
- if (virDomainNetIsVirtioModel(net))
+ if (qemuInterfaceIsVnetCompatModel(net))
tap_create_flags |= VIR_NETDEV_TAP_CREATE_VNET_HDR;
if (net->managed_tap == VIR_TRISTATE_BOOL_NO) {
@@ -436,7 +443,7 @@ qemuInterfaceEthernetConnect(virDomainDefPtr def,
if (virNetDevMacVLanTapOpen(net->ifname, tapfd, tapfdSize) < 0)
goto cleanup;
if (virNetDevMacVLanTapSetup(tapfd, tapfdSize,
- virDomainNetIsVirtioModel(net)) < 0) {
+ qemuInterfaceIsVnetCompatModel(net)) < 0) {
goto cleanup;
}
} else {
@@ -559,7 +566,7 @@ qemuInterfaceBridgeConnect(virDomainDefPtr def,
template_ifname = true;
}
- if (virDomainNetIsVirtioModel(net))
+ if (qemuInterfaceIsVnetCompatModel(net))
tap_create_flags |= VIR_NETDEV_TAP_CREATE_VNET_HDR;
if (driver->privileged) {
diff --git a/src/qemu/qemu_interface.h b/src/qemu/qemu_interface.h
index 0464b903d7..9e3f61e8e0 100644
--- a/src/qemu/qemu_interface.h
+++ b/src/qemu/qemu_interface.h
@@ -58,3 +58,4 @@ int qemuInterfaceOpenVhostNet(virDomainDefPtr def,
qemuSlirpPtr qemuInterfacePrepareSlirp(virQEMUDriverPtr driver,
virDomainNetDefPtr net);
+bool qemuInterfaceIsVnetCompatModel(const virDomainNetDef *net);
--
2.26.2
4 years, 2 months
[GSoC PATCH 3/9] Jailhouse driver: Implementation of ConnectGetType
by Prakhar Bansal
---
src/jailhouse/jailhouse_driver.c | 28 ++++++++++++++++------------
1 file changed, 16 insertions(+), 12 deletions(-)
diff --git a/src/jailhouse/jailhouse_driver.c b/src/jailhouse/jailhouse_driver.c
index ac9da4c85d..75bf41fc11 100644
--- a/src/jailhouse/jailhouse_driver.c
+++ b/src/jailhouse/jailhouse_driver.c
@@ -32,8 +32,10 @@
#include "viralloc.h"
#include "virfile.h"
#include "virlog.h"
+#include "virutil.h"
#include "vircommand.h"
#include "virpidfile.h"
+#include "access/viraccessapicheck.h"
#define VIR_FROM_THIS VIR_FROM_JAILHOUSE
@@ -241,16 +243,19 @@ jailhouseStateInitialize(bool privileged G_GNUC_UNUSED,
static const char *
jailhouseConnectGetType(virConnectPtr conn)
{
- UNUSED(conn);
- return NULL;
+ if (virConnectGetTypeEnsureACL(conn) < 0)
+ return NULL;
+ return "JAILHOUSE";
}
static char *
jailhouseConnectGetHostname(virConnectPtr conn)
{
- UNUSED(conn);
- return NULL;
+ if (virConnectGetHostnameEnsureACL(conn) < 0)
+ return NULL;
+
+ return virGetHostname();
}
static int
@@ -263,7 +268,7 @@ jailhouseNodeGetInfo(virConnectPtr conn, virNodeInfoPtr info)
static int
jailhouseConnectListAllDomains(virConnectPtr conn,
- virDomainPtr ** domain, unsigned int flags)
+ virDomainPtr **domain, unsigned int flags)
{
UNUSED(conn);
UNUSED(domain);
@@ -300,7 +305,6 @@ jailhouseDomainCreate(virDomainPtr domain)
{
UNUSED(domain);
return -1;
-
}
static int
@@ -350,18 +354,18 @@ static virHypervisorDriver jailhouseHypervisorDriver = {
.connectOpen = jailhouseConnectOpen, /* 6.3.0 */
.connectClose = jailhouseConnectClose, /* 6.3.0 */
.connectListAllDomains = jailhouseConnectListAllDomains, /* 6.3.0 */
- .domainLookupByID = jailhouseDomainLookupByID, /* 6.3.0 */
- .domainLookupByUUID = jailhouseDomainLookupByUUID, /* 6.3.0 */
- .domainLookupByName = jailhouseDomainLookupByName, /* 6.3.0 */
- .domainGetXMLDesc = jailhouseDomainGetXMLDesc, /* 6.3.0 */
- .domainCreate = jailhouseDomainCreate, /* 6.3.0 */
.connectGetType = jailhouseConnectGetType, /* 6.3.0 */
.connectGetHostname = jailhouseConnectGetHostname, /* 6.3.0 */
- .nodeGetInfo = jailhouseNodeGetInfo, /* 6.3.0 */
+ .domainCreate = jailhouseDomainCreate, /* 6.3.0 */
.domainShutdown = jailhouseDomainShutdown, /* 6.3.0 */
.domainDestroy = jailhouseDomainDestroy, /* 6.3.0 */
.domainGetInfo = jailhouseDomainGetInfo, /* 6.3.0 */
.domainGetState = jailhouseDomainGetState, /* 6.3.0 */
+ .domainLookupByID = jailhouseDomainLookupByID, /* 6.3.0 */
+ .domainLookupByUUID = jailhouseDomainLookupByUUID, /* 6.3.0 */
+ .domainLookupByName = jailhouseDomainLookupByName, /* 6.3.0 */
+ .domainGetXMLDesc = jailhouseDomainGetXMLDesc, /* 6.3.0 */
+ .nodeGetInfo = jailhouseNodeGetInfo, /* 6.3.0 */
};
--
2.17.1
4 years, 2 months
[GSoC PATCH 2/9] Jailhouse driver: Implementation of ConnectOpen
by Prakhar Bansal
---
include/libvirt/virterror.h | 1 +
po/POTFILES.in | 2 +
src/jailhouse/Makefile.inc.am | 34 ++-
src/jailhouse/jailhouse.conf | 10 +
src/jailhouse/jailhouse_api.c | 372 ++++++++++++++++++++++++++++
src/jailhouse/jailhouse_api.h | 74 ++++++
src/jailhouse/jailhouse_driver.c | 302 +++++++++++++++++-----
src/jailhouse/jailhouse_driver.h | 51 ++++
src/jailhouse/meson.build | 1 +
src/libvirt.c | 10 -
src/remote/remote_daemon.c | 4 +
src/remote/remote_daemon_dispatch.c | 3 +-
12 files changed, 783 insertions(+), 81 deletions(-)
create mode 100644 src/jailhouse/jailhouse.conf
create mode 100644 src/jailhouse/jailhouse_api.c
create mode 100644 src/jailhouse/jailhouse_api.h
diff --git a/include/libvirt/virterror.h b/include/libvirt/virterror.h
index 97f2ac16d8..9f1bca2684 100644
--- a/include/libvirt/virterror.h
+++ b/include/libvirt/virterror.h
@@ -137,6 +137,7 @@ typedef enum {
VIR_FROM_TPM = 70, /* Error from TPM */
VIR_FROM_BPF = 71, /* Error from BPF code */
VIR_FROM_JAILHOUSE = 72, /* Error from Jailhouse driver */
+
# ifdef VIR_ENUM_SENTINELS
VIR_ERR_DOMAIN_LAST
# endif
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 3d6c20c55f..a94285817f 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -85,6 +85,8 @@
@SRCDIR(a)src/interface/interface_backend_netcf.c
@SRCDIR(a)src/interface/interface_backend_udev.c
@SRCDIR(a)src/internal.h
+@SRCDIR(a)src/jailhouse/jailhouse_api.c
+@SRCDIR(a)src/jailhouse/jailhouse_driver.c
@SRCDIR(a)src/libvirt-domain-checkpoint.c
@SRCDIR(a)src/libvirt-domain-snapshot.c
@SRCDIR(a)src/libvirt-domain.c
diff --git a/src/jailhouse/Makefile.inc.am b/src/jailhouse/Makefile.inc.am
index 02822b2ea1..324c3b1b16 100644
--- a/src/jailhouse/Makefile.inc.am
+++ b/src/jailhouse/Makefile.inc.am
@@ -1,8 +1,11 @@
# vim: filetype=automake
+
JAILHOUSE_DRIVER_SOURCES = \
jailhouse/jailhouse_driver.c \
jailhouse/jailhouse_driver.h \
+ jailhouse/jailhouse_api.c \
+ jailhouse/jailhouse_api.h \
$(NULL)
@@ -11,11 +14,34 @@ DRIVER_SOURCE_FILES += $(addprefix
$(srcdir)/,$(JAILHOUSE_DRIVER_SOURCES))
EXTRA_DIST += $(JAILHOUSE_DRIVER_SOURCES)
if WITH_JAILHOUSE
-noinst_LTLIBRARIES += libvirt_driver_jailhouse.la
-libvirt_la_BUILT_LIBADD += libvirt_driver_jailhouse.la
-libvirt_driver_jailhouse_la_CFLAGS = \
+
+noinst_LTLIBRARIES += libvirt_driver_jailhouse_impl.la
+libvirt_driver_jailhouse_la_SOURCES =
+libvirt_driver_jailhouse_la_LIBADD = \
+ libvirt_driver_jailhouse_impl.la \
+ libvirt.la \
+ $(GLIB_LIBS) \
+ $(NULL)
+mod_LTLIBRARIES += libvirt_driver_jailhouse.la
+libvirt_driver_jailhouse_la_LDFLAGS = $(AM_LDFLAGS_MOD_NOUNDEF)
+
+libvirt_driver_jailhouse_impl_la_CFLAGS = \
-I$(srcdir)/conf \
$(AM_CFLAGS) \
$(NULL)
-libvirt_driver_jailhouse_la_SOURCES = $(JAILHOUSE_DRIVER_SOURCES)
+libvirt_driver_jailhouse_impl_la_SOURCES = \
+ $(JAILHOUSE_DRIVER_SOURCES)
+
+sbin_PROGRAMS += virtjailhoused
+
+virtjailhoused_SOURCES = $(REMOTE_DAEMON_SOURCES)
+nodist_virtjailhoused_SOURCES = $(REMOTE_DAEMON_GENERATED)
+virtjailhoused_CFLAGS = \
+ $(REMOTE_DAEMON_CFLAGS) \
+ -DDAEMON_NAME="\"virtjailhoused\"" \
+ -DMODULE_NAME="\"jailhouse\"" \
+ $(NULL)
+virtjailhoused_LDFLAGS = $(REMOTE_DAEMON_LD_FLAGS)
+virtjailhoused_LDADD = $(REMOTE_DAEMON_LD_ADD)
+
endif WITH_JAILHOUSE
diff --git a/src/jailhouse/jailhouse.conf b/src/jailhouse/jailhouse.conf
new file mode 100644
index 0000000000..587068b9d0
--- /dev/null
+++ b/src/jailhouse/jailhouse.conf
@@ -0,0 +1,10 @@
+# Configuration for the Jailhouse driver.
+
+# Jailhouse system configuration file to enable the Jailhouse hypervisor
on the
+# system. This is a required configuration parameter for the driver.
+#system_config = "/etc/libvirt/jailhouse/qemu-x86.cell"
+
+# Specify a directory which contains all the non-root cell configurations
which
+# should be created by the driver at the startup. This is optional. Default
+# value of "/etc/libvirt/jailhouse/cells/" will be used if left empty.
+#non_root_cells_dir = "/etc/libvirt/jailhouse/cells/"
diff --git a/src/jailhouse/jailhouse_api.c b/src/jailhouse/jailhouse_api.c
new file mode 100644
index 0000000000..cda00b50e7
--- /dev/null
+++ b/src/jailhouse/jailhouse_api.c
@@ -0,0 +1,372 @@
+/*
+ * jailhouse_api.c: Jailhouse API
+ *
+ * Copyright (C) 2020 Prakhar Bansal
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include <config.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <dirent.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/ioctl.h>
+#include <sys/stat.h>
+#include <linux/types.h>
+
+#include "viralloc.h"
+#include "virerror.h"
+#include "virfile.h"
+#include "virlog.h"
+#include "virstring.h"
+#include "jailhouse_api.h"
+
+#define JAILHOUSE_DEVICE "/dev/jailhouse"
+#define JAILHOUSE_CELLS
"/sys/devices/jailhouse/cells"
+#define MAX_JAILHOUSE_SYS_CONFIG_FILE_SIZE 1024*1024
+#define MAX_JAILHOUSE_CELL_CONFIG_FILE_SIZE 1024
+
+
+#define JAILHOUSE_ENABLE _IOW(0, 0, void *)
+#define JAILHOUSE_DISABLE _IO(0, 1)
+#define JAILHOUSE_CELL_CREATE _IOW(0, 2, virJailhouseCellCreate)
+#define JAILHOUSE_CELL_DESTROY _IOW(0, 5, virJailhouseCellId)
+
+#define VIR_FROM_THIS VIR_FROM_JAILHOUSE
+
+VIR_LOG_INIT("jailhouse.jailhouse_api");
+
+#define JAILHOUSE_CELL_FILE_EXTENSION ".cell"
+
+/* Forward declarations */
+
+/* Open the Jailhouse device for ioctl APIs */
+int openDev(void);
+
+/* Reads cell's property given by 'entry' using sysfs API */
+char *readSysfsCellString(const unsigned int id, const char *entry);
+
+int cell_match(const struct dirent *dirent);
+
+int createCell(const char *conf_file);
+
+int destroyCell(virJailhouseCellId cell_id);
+
+int getCellInfo(const unsigned int id,
+ virJailhouseCellInfoPtr * cell_info);
+
+int
+jailhouseEnable(const char *sys_conf_file_path)
+{
+ int err = -1, len;
+ g_autofree char *buffer = NULL;
+ VIR_AUTOCLOSE fd = -1;
+
+ if (!virFileExists(sys_conf_file_path))
+ return 0;
+
+ len = virFileReadAll(sys_conf_file_path,
MAX_JAILHOUSE_SYS_CONFIG_FILE_SIZE, &buffer);
+ if (len < 0 || !buffer) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ "%s", _("Failed to read the system configuration
file"));
+ return -1;
+ }
+
+ fd = openDev();
+
+ err = ioctl(fd, JAILHOUSE_ENABLE, buffer);
+ if (err) {
+ virReportSystemError(errno, "%s", _("Failed to enable jailhouse"));
+ return err;
+ }
+
+ VIR_DEBUG("Jailhouse hypervisor is enabled");
+
+ return 1;
+}
+
+int
+jailhouseDisable(void)
+{
+ int err = -1;
+ VIR_AUTOCLOSE fd = -1;
+
+ fd = openDev();
+
+ err = ioctl(fd, JAILHOUSE_DISABLE);
+ if (err)
+ virReportSystemError(errno,
+ "%s",
+ _("Failed to disable jailhouse: %s"));
+
+ VIR_DEBUG("Jailhouse hypervisor is disabled");
+
+ return err;
+}
+
+int
+cell_match(const struct dirent *dirent)
+{
+ char *ext = strrchr(dirent->d_name, '.');
+
+ return dirent->d_name[0] != '.'
+ && (STREQ(ext, JAILHOUSE_CELL_FILE_EXTENSION) == 0);
+}
+
+int
+createJailhouseCells(const char *dir_path)
+{
+
+ struct dirent **namelist;
+ int num_entries, ret = -1;
+ size_t i;
+
+ if (strlen(dir_path) == 0)
+ return ret;
+
+ num_entries = scandir(dir_path, &namelist, cell_match, alphasort);
+ if (num_entries == -1) {
+ if (errno == ENOENT) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("No cells found in %s, scandir failed."),
+ dir_path);
+ goto fail;
+ }
+
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("Error reading cell configurations in %s."),
+ dir_path);
+ goto fail;
+ }
+
+
+ for (i = 0; i < num_entries; i++) {
+ g_autofree char *file_path = g_strdup_printf("%s/%s", dir_path,
namelist[i]->d_name);
+
+ if (createCell(file_path) != 0) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("Cell creation failed with conf found in
%s."),
+ namelist[i]->d_name);
+ goto fail;
+ }
+ }
+
+ ret = 0;
+
+ fail:
+ VIR_FREE(namelist);
+ return ret;
+}
+
+int
+openDev(void)
+{
+ int fd;
+
+ fd = open(JAILHOUSE_DEVICE, O_RDWR);
+ if (fd < 0) {
+ virReportSystemError(errno,
+ _("Error opening jailhouse device %s"),
+ JAILHOUSE_DEVICE);
+ }
+ return fd;
+}
+
+int
+createCell(const char *conf_file)
+{
+ virJailhouseCellCreate cell_create;
+ int err = -1, len;
+ g_autofree char *buffer = NULL;
+ VIR_AUTOCLOSE fd = -1;
+
+ if (strlen(conf_file) == 0)
+ return err;
+
+ len = virFileReadAll(conf_file, MAX_JAILHOUSE_CELL_CONFIG_FILE_SIZE,
&buffer);
+ if (len < 0 || !buffer) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ "%s", _("Failed to read the system configuration
file"));
+ return err;
+ }
+
+ cell_create.config_address = (unsigned long) buffer;
+ cell_create.config_size = len;
+
+ fd = openDev();
+
+ err = ioctl(fd, JAILHOUSE_CELL_CREATE, &cell_create);
+ if (err)
+ virReportSystemError(errno,
+ "%s",
+ _("Cell creation failed: %s"));
+
+ return err;
+}
+
+void
+cellInfoFree(virJailhouseCellInfoPtr cell_info)
+{
+ VIR_FREE(cell_info->state);
+ VIR_FREE(cell_info->cpus_assigned_list);
+ VIR_FREE(cell_info->cpus_failed_list);
+ VIR_FREE(cell_info);
+}
+
+char *
+readSysfsCellString(const unsigned int id, const char *entry)
+{
+ g_autofree char *buffer = NULL;
+ g_autofree char *file_path = NULL;
+ int len = -1;
+
+ file_path = g_strdup_printf(JAILHOUSE_CELLS "%u/%s", id, entry);
+
+ len = virFileReadAll(file_path, 1024, &buffer);
+ if (len < 0 || !buffer) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Error reading cell(%u) %s from %s failed"),
+ id, entry, file_path);
+ return NULL;
+ }
+
+ virTrimSpaces(buffer, NULL);
+
+ return buffer;
+}
+
+int
+getCellInfo(const unsigned int id, virJailhouseCellInfoPtr * cell_info_ptr)
+{
+ char *tmp;
+
+ if (VIR_ALLOC(*cell_info_ptr) < 0)
+ return -1;
+
+ virJailhouseCellInfoPtr cell_info = *cell_info_ptr;
+
+ /* set cell id */
+ cell_info->id.id = id;
+
+ /* get cell name */
+ tmp = readSysfsCellString(id, "name");
+ if (virStrncpy(cell_info->id.name, tmp, JAILHOUSE_CELL_ID_NAMELEN,
JAILHOUSE_CELL_ID_NAMELEN) < 0) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Cell ID %s too long to be copied to the cell
info"),
+ tmp);
+ return -1;
+ }
+
+ cell_info->id.name[JAILHOUSE_CELL_ID_NAMELEN] = 0;
+ VIR_FREE(tmp);
+
+ /* get cell state */
+ cell_info->state = readSysfsCellString(id, "state");
+
+ /* get assigned cpu list */
+ cell_info->cpus_assigned_list =
+ readSysfsCellString(id, "cpus_assigned_list");
+
+ /* get failed cpu list */
+ cell_info->cpus_failed_list =
+ readSysfsCellString(id, "cpus_failed_list");
+
+ return 0;
+}
+
+virJailhouseCellInfoPtr *
+getJailhouseCellsInfo(void)
+{
+ struct dirent **namelist;
+ virJailhouseCellInfoPtr *cell_info_list;
+ unsigned int id;
+ int num_entries;
+ size_t i;
+
+ num_entries =
+ scandir(JAILHOUSE_CELLS, &namelist, cell_match, alphasort);
+ if (num_entries == -1) {
+ if (errno == ENOENT) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("No cells found in %s, scandir failed."),
+ JAILHOUSE_CELLS);
+ return NULL;
+ }
+
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Error reading cell IDs in %s."),
+ JAILHOUSE_CELLS);
+ return NULL;
+ }
+
+ /* Allocate memory for 1 more than num_entries and make the last entry
NULL. */
+ if (VIR_ALLOC_N(cell_info_list, num_entries + 1) < 0) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ "%s",
+ _("Insufficient memory for cells info list"));
+ }
+
+ /* Set the last entry to NULL. */
+ cell_info_list[num_entries] = NULL;
+
+ for (i = 0; i < num_entries; i++) {
+ if (virStrToLong_ui(namelist[i]->d_name, NULL, 10, &id) < 0) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Cell ID %s could not be converted to a
long"),
+ namelist[i]->d_name);
+ continue;
+ }
+
+ /* get the cell's information(name, state etc.) using sysfs */
+ getCellInfo(id, &cell_info_list[i]);
+ VIR_FREE(namelist[i]);
+ }
+
+ VIR_FREE(namelist);
+ return cell_info_list;
+}
+
+int
+destroyCell(virJailhouseCellId cell_id)
+{
+ int err = -1;
+ VIR_AUTOCLOSE fd = -1;
+
+ fd = openDev();
+
+ err = ioctl(fd, JAILHOUSE_CELL_DESTROY, &cell_id);
+ if (err)
+ virReportSystemError(errno,
+ _("Destroying cell %d failed"),
+ cell_id.id);
+
+ return err;
+}
+
+int
+destroyJailhouseCells(virJailhouseCellInfoPtr *cell_info_list
G_GNUC_UNUSED)
+{
+
+ /* Iterate over all cells in cell_info_list and destroy each cell */
+ // TODO: Not implemented yet.
+
+ return 0;
+}
diff --git a/src/jailhouse/jailhouse_api.h b/src/jailhouse/jailhouse_api.h
new file mode 100644
index 0000000000..8362cb3d0f
--- /dev/null
+++ b/src/jailhouse/jailhouse_api.h
@@ -0,0 +1,74 @@
+/*
+ * jailhouse_api.h: Jailhouse hypervisor API implementation
+ *
+ * Copyright (C) 2020 Prakhar Bansal
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see
+ * <http://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+
+#define JAILHOUSE_CELL_ID_NAMELEN 31
+
+typedef struct _virJailhouseCellId virJailhouseCellId;
+
+struct _virJailhouseCellId {
+ __s32 id;
+ __u32 padding;
+ char name[JAILHOUSE_CELL_ID_NAMELEN + 1];
+};
+
+typedef struct _virJailhouseCellInfo virJailhouseCellInfo;
+typedef virJailhouseCellInfo *virJailhouseCellInfoPtr;
+
+struct _virJailhouseCellInfo {
+ struct _virJailhouseCellId id;
+ char *state;
+ char *cpus_assigned_list;
+ char *cpus_failed_list;
+};
+
+typedef struct _virJailhouseCellCreate virJailhouseCellCreate;
+
+struct _virJailhouseCellCreate {
+ __u64 config_address;
+ __u32 config_size;
+ __u32 padding;
+};
+
+// Enables the Jailhouse hypervisor by reading the hypervisor system
+// configuration from the given file and calls the ioctl API to
+// enable the hypervisor.
+int jailhouseEnable(const char *sys_conf_file_path);
+
+// Disables the Jailhouse hypervisor.
+int jailhouseDisable(void);
+
+/* Cell API methods */
+
+// Creates Jailhouse cells using the cells configurations
+// provided in the dir_name.
+int createJailhouseCells(const char *dir_path);
+
+// Destroys Jailhouse cells using the cell IDs provided in
+// the cell_info_list.
+int destroyJailhouseCells(virJailhouseCellInfoPtr *cell_info_list);
+
+// Returns cell's information in a null-terminated array of
+// virJailhouseCellInfoPtr for all the Jailhouse cells.
+virJailhouseCellInfoPtr *getJailhouseCellsInfo(void);
+
+// Free the cell info object.
+void cellInfoFree(virJailhouseCellInfoPtr cell_info);
diff --git a/src/jailhouse/jailhouse_driver.c
b/src/jailhouse/jailhouse_driver.c
index 0175ba771b..ac9da4c85d 100644
--- a/src/jailhouse/jailhouse_driver.c
+++ b/src/jailhouse/jailhouse_driver.c
@@ -16,43 +16,228 @@
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see
* <http://www.gnu.org/licenses/>.
+ *
*/
#include <config.h>
+#include <string.h>
+#include "configmake.h"
+#include "datatypes.h"
+#include "domain_conf.h"
#include "jailhouse_driver.h"
#include "virtypedparam.h"
#include "virerror.h"
#include "virstring.h"
#include "viralloc.h"
-#include "domain_conf.h"
#include "virfile.h"
-#include "datatypes.h"
+#include "virlog.h"
#include "vircommand.h"
-#include <string.h>
+#include "virpidfile.h"
-#define UNUSED(x) (void)(x)
+#define VIR_FROM_THIS VIR_FROM_JAILHOUSE
+
+VIR_LOG_INIT("jailhouse.jailhouse_driver");
+
+static virClassPtr virJailhouseDriverConfigClass;
+static void virJailhouseDriverConfigDispose(void *obj);
+
+static virJailhouseDriverPtr jailhouse_driver;
+
+static int virJailhouseConfigOnceInit(void)
+{
+ if (!VIR_CLASS_NEW(virJailhouseDriverConfig, virClassForObject()))
+ return -1;
+
+ return 0;
+}
+
+VIR_ONCE_GLOBAL_INIT(virJailhouseConfig);
+
+
+static virJailhouseDriverConfigPtr
+virJailhouseDriverConfigNew(void)
+{
+ virJailhouseDriverConfigPtr cfg;
+
+ // TODO: Check if the following has to be uncommented.
+ if (virJailhouseConfigInitialize() < 0)
+ return NULL;
+
+ if (!(cfg = virObjectNew(virJailhouseDriverConfigClass)))
+ return NULL;
+
+ cfg->stateDir = g_strdup(JAILHOUSE_STATE_DIR);
+
+ cfg->sys_config_file_path = g_strdup(DATADIR "/jailhouse/system.cell");
+
+ cfg->cell_config_dir = g_strdup(DATADIR "/jailhouse/cells");
+
+ return cfg;
+}
+
+static void virJailhouseDriverConfigDispose(void *obj)
+{
+
+ virJailhouseDriverConfigPtr cfg = obj;
+
+ VIR_FREE(cfg->stateDir);
+ VIR_FREE(cfg->sys_config_file_path);
+ VIR_FREE(cfg->cell_config_dir);
+}
+
+static int
+jailhouseLoadConf(virJailhouseDriverConfigPtr config)
+{
+ g_autoptr(virConf) conf = NULL;
+
+ if (!virFileExists(JAILHOUSE_CONFIG_FILE))
+ return 0;
+
+ if (!(conf = virConfReadFile(JAILHOUSE_CONFIG_FILE, 0)))
+ return -1;
+
+ if (virConfGetValueString(conf, "system_config",
+ &config->sys_config_file_path) < 0)
+ return -1;
+
+ if (virConfGetValueString(conf, "non_root_cells_dir",
+ &config->cell_config_dir) < 0)
+ return -1;
+
+ return 1;
+}
+
+static int
+jailhouseCreateAndLoadCells(virJailhouseDriverPtr driver)
+{
+ if (!driver->config ||
+ !driver->config->cell_config_dir ||
+ strlen(driver->config->cell_config_dir) == 0)
+ return -1;
+
+ // Create all cells in the hypervisor.
+ if (createJailhouseCells(driver->config->cell_config_dir) < 0)
+ return -1;
+
+ // Get all cells created above.
+ driver->cell_info_list = getJailhouseCellsInfo();
+
+ return 0;
+}
+
+static void
+jailhouseFreeDriver(virJailhouseDriverPtr driver)
+{
+ if (!driver)
+ return;
+
+ virMutexDestroy(&driver->lock);
+ virObjectUnref(driver->config);
+ VIR_FREE(driver);
+}
static virDrvOpenStatus
jailhouseConnectOpen(virConnectPtr conn,
- virConnectAuthPtr auth,
- virConfPtr conf,
- unsigned int flags)
+ virConnectAuthPtr auth G_GNUC_UNUSED,
+ virConfPtr conf G_GNUC_UNUSED, unsigned int flags)
{
- UNUSED(conn);
- UNUSED(auth);
- UNUSED(conf);
- UNUSED(flags);
- return 0;
+ uid_t uid = geteuid();
+
+ virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR);
+
+ if (!virConnectValidateURIPath(conn->uri->path, "jailhouse", uid == 0))
+ return VIR_DRV_OPEN_ERROR;
+
+ if (!jailhouse_driver) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("Jailhouse driver state is not initialized."));
+ return VIR_DRV_OPEN_ERROR;
+ }
+
+ conn->privateData = jailhouse_driver;
+
+ return VIR_DRV_OPEN_SUCCESS;
}
+#define UNUSED(x) (void)(x)
+
static int
jailhouseConnectClose(virConnectPtr conn)
{
- UNUSED(conn);
+ conn->privateData = NULL;
+
+ return 0;
+}
+
+static int
+jailhouseStateCleanup(void)
+{
+ if (!jailhouse_driver)
+ return -1;
+
+ if (jailhouse_driver->lockFD != -1)
+ virPidFileRelease(jailhouse_driver->config->stateDir,
+ "driver", jailhouse_driver->lockFD);
+
+ virMutexDestroy(&jailhouse_driver->lock);
+
+ jailhouseFreeDriver(jailhouse_driver);
return 0;
}
+static int
+jailhouseStateInitialize(bool privileged G_GNUC_UNUSED,
+ const char *root G_GNUC_UNUSED,
+ virStateInhibitCallback callback G_GNUC_UNUSED,
+ void *opaque G_GNUC_UNUSED)
+{
+ virJailhouseDriverConfigPtr cfg = NULL;
+ int rc;
+
+ jailhouse_driver = g_new0(virJailhouseDriver, 1);
+ jailhouse_driver->lockFD = -1;
+
+ if (virMutexInit(&jailhouse_driver->lock) < 0) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("cannot initialize mutex"));
+ VIR_FREE(jailhouse_driver);
+ return VIR_DRV_STATE_INIT_ERROR;
+ }
+
+ if (!(cfg = virJailhouseDriverConfigNew()))
+ goto error;
+
+ jailhouse_driver->config = cfg;
+
+ if (jailhouseLoadConf(cfg) < 0)
+ goto error;
+
+ if (virFileMakePath(cfg->stateDir) < 0) {
+ virReportSystemError(errno, _("Failed to create state dir %s"),
+ cfg->stateDir);
+ goto error;
+ }
+
+ if ((jailhouse_driver->lockFD = virPidFileAcquire(cfg->stateDir,
+ "driver", false,
getpid())) < 0)
+ goto error;
+
+ if ((rc = jailhouseEnable(cfg->sys_config_file_path)) < 0)
+ goto error;
+ else if (rc == 0)
+ return VIR_DRV_STATE_INIT_SKIPPED;
+
+ if (jailhouseCreateAndLoadCells(jailhouse_driver) < 0)
+ goto error;
+
+ return VIR_DRV_STATE_INIT_COMPLETE;
+
+ error:
+ jailhouseStateCleanup();
+ return VIR_DRV_STATE_INIT_ERROR;
+
+}
static const char *
jailhouseConnectGetType(virConnectPtr conn)
{
@@ -69,36 +254,16 @@ jailhouseConnectGetHostname(virConnectPtr conn)
}
static int
-jailhouseNodeGetInfo(virConnectPtr conn,
- virNodeInfoPtr info)
+jailhouseNodeGetInfo(virConnectPtr conn, virNodeInfoPtr info)
{
UNUSED(conn);
UNUSED(info);
return -1;
}
-static int
-jailhouseConnectListDomains(virConnectPtr conn,
- int *ids,
- int maxids)
-{
- UNUSED(conn);
- UNUSED(ids);
- UNUSED(maxids);
- return -1;
-}
-
-static int
-jailhouseConnectNumOfDomains(virConnectPtr conn)
-{
- UNUSED(conn);
- return -1;
-}
-
static int
jailhouseConnectListAllDomains(virConnectPtr conn,
- virDomainPtr **domain,
- unsigned int flags)
+ virDomainPtr ** domain, unsigned int flags)
{
UNUSED(conn);
UNUSED(domain);
@@ -107,8 +272,7 @@ jailhouseConnectListAllDomains(virConnectPtr conn,
}
static virDomainPtr
-jailhouseDomainLookupByID(virConnectPtr conn,
- int id)
+jailhouseDomainLookupByID(virConnectPtr conn, int id)
{
UNUSED(conn);
UNUSED(id);
@@ -116,8 +280,7 @@ jailhouseDomainLookupByID(virConnectPtr conn,
}
static virDomainPtr
-jailhouseDomainLookupByName(virConnectPtr conn,
- const char *name)
+jailhouseDomainLookupByName(virConnectPtr conn, const char *name)
{
UNUSED(conn);
UNUSED(name);
@@ -125,8 +288,7 @@ jailhouseDomainLookupByName(virConnectPtr conn,
}
static virDomainPtr
-jailhouseDomainLookupByUUID(virConnectPtr conn,
- const unsigned char *uuid)
+jailhouseDomainLookupByUUID(virConnectPtr conn, const unsigned char *uuid)
{
UNUSED(conn);
UNUSED(uuid);
@@ -157,8 +319,7 @@ jailhouseDomainDestroy(virDomainPtr domain)
}
static int
-jailhouseDomainGetInfo(virDomainPtr domain,
- virDomainInfoPtr info)
+jailhouseDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info)
{
UNUSED(domain);
UNUSED(info);
@@ -167,9 +328,7 @@ jailhouseDomainGetInfo(virDomainPtr domain,
static int
jailhouseDomainGetState(virDomainPtr domain,
- int *state,
- int *reason,
- unsigned int flags)
+ int *state, int *reason, unsigned int flags)
{
UNUSED(domain);
UNUSED(state);
@@ -179,8 +338,7 @@ jailhouseDomainGetState(virDomainPtr domain,
}
static char *
-jailhouseDomainGetXMLDesc(virDomainPtr domain,
- unsigned int flags)
+jailhouseDomainGetXMLDesc(virDomainPtr domain, unsigned int flags)
{
UNUSED(domain);
UNUSED(flags);
@@ -189,31 +347,43 @@ jailhouseDomainGetXMLDesc(virDomainPtr domain,
static virHypervisorDriver jailhouseHypervisorDriver = {
.name = "JAILHOUSE",
- .connectOpen = jailhouseConnectOpen, /* 6.3.0 */
- .connectClose = jailhouseConnectClose, /* 6.3.0 */
- .connectListDomains = jailhouseConnectListDomains, /* 6.3.0 */
- .connectNumOfDomains = jailhouseConnectNumOfDomains, /* 6.3.0 */
- .connectListAllDomains = jailhouseConnectListAllDomains, /* 6.3.0 */
- .domainLookupByID = jailhouseDomainLookupByID, /* 6.3.0 */
- .domainLookupByUUID = jailhouseDomainLookupByUUID, /* 6.3.0 */
- .domainLookupByName = jailhouseDomainLookupByName, /* 6.3.0 */
- .domainGetXMLDesc = jailhouseDomainGetXMLDesc, /* 6.3.0 */
- .domainCreate = jailhouseDomainCreate, /* 6.3.0 */
- .connectGetType = jailhouseConnectGetType, /* 6.3.0 */
- .connectGetHostname = jailhouseConnectGetHostname, /* 6.3.0 */
- .nodeGetInfo = jailhouseNodeGetInfo, /* 6.3.0 */
- .domainShutdown = jailhouseDomainShutdown, /* 6.3.0 */
- .domainDestroy = jailhouseDomainDestroy, /* 6.3.0 */
- .domainGetInfo = jailhouseDomainGetInfo, /* 6.3.0 */
- .domainGetState = jailhouseDomainGetState, /* 6.3.0 */
+ .connectOpen = jailhouseConnectOpen, /* 6.3.0 */
+ .connectClose = jailhouseConnectClose, /* 6.3.0 */
+ .connectListAllDomains = jailhouseConnectListAllDomains, /* 6.3.0 */
+ .domainLookupByID = jailhouseDomainLookupByID, /* 6.3.0 */
+ .domainLookupByUUID = jailhouseDomainLookupByUUID, /* 6.3.0 */
+ .domainLookupByName = jailhouseDomainLookupByName, /* 6.3.0 */
+ .domainGetXMLDesc = jailhouseDomainGetXMLDesc, /* 6.3.0 */
+ .domainCreate = jailhouseDomainCreate, /* 6.3.0 */
+ .connectGetType = jailhouseConnectGetType, /* 6.3.0 */
+ .connectGetHostname = jailhouseConnectGetHostname, /* 6.3.0 */
+ .nodeGetInfo = jailhouseNodeGetInfo, /* 6.3.0 */
+ .domainShutdown = jailhouseDomainShutdown, /* 6.3.0 */
+ .domainDestroy = jailhouseDomainDestroy, /* 6.3.0 */
+ .domainGetInfo = jailhouseDomainGetInfo, /* 6.3.0 */
+ .domainGetState = jailhouseDomainGetState, /* 6.3.0 */
};
+
static virConnectDriver jailhouseConnectDriver = {
+ .localOnly = true,
+ .uriSchemes = (const char *[]){ "jailhouse", NULL },
.hypervisorDriver = &jailhouseHypervisorDriver,
};
+
+static virStateDriver jailhouseStateDriver = {
+ .name = "JAILHOUSE",
+ .stateInitialize = jailhouseStateInitialize,
+ .stateCleanup = jailhouseStateCleanup,
+};
+
int
jailhouseRegister(void)
{
- return virRegisterConnectDriver(&jailhouseConnectDriver, false);
+ if (virRegisterConnectDriver(&jailhouseConnectDriver, false) < 0)
+ return -1;
+ if (virRegisterStateDriver(&jailhouseStateDriver) < 0)
+ return -1;
+ return 0;
}
diff --git a/src/jailhouse/jailhouse_driver.h
b/src/jailhouse/jailhouse_driver.h
index b0dbc8d033..8a0e111676 100644
--- a/src/jailhouse/jailhouse_driver.h
+++ b/src/jailhouse/jailhouse_driver.h
@@ -20,4 +20,55 @@
#pragma once
+#include <linux/types.h>
+
+#include "jailhouse_api.h"
+
int jailhouseRegister(void);
+
+#define JAILHOUSE_CONFIG_FILE SYSCONFDIR
"/libvirt/jailhouse/jailhouse.conf"
+#define JAILHOUSE_STATE_DIR RUNSTATEDIR "/libvirt/jailhouse"
+
+#define JAILHOUSE_DEV "/dev/jailhouse"
+
+#define JAILHOUSE_SYSFS_DEV "/sys/devices/jailhouse/"
+
+typedef struct _virJailhouseDriver virJailhouseDriver;
+typedef virJailhouseDriver *virJailhouseDriverPtr;
+
+typedef struct _virJailhouseDriverConfig virJailhouseDriverConfig;
+typedef virJailhouseDriverConfig *virJailhouseDriverConfigPtr;
+
+struct _virJailhouseDriverConfig {
+ virObject parent;
+
+ char *stateDir;
+
+ // File path of the jailhouse system configuration
+ // for jailhouse enable/disable.
+ char *sys_config_file_path;
+
+ // Config directory where all jailhouse cell configurations
+ // are stored.
+ char *cell_config_dir;
+};
+
+struct _virJailhouseDriver {
+ virMutex lock;
+
+ // Jailhouse configuration read from the jailhouse.conf
+ virJailhouseDriverConfigPtr config;
+
+ /* pid file FD, ensures two copies of the driver can't use the same
root */
+ int lockFD;
+
+ // All the cells created during connect open on the hypervisor.
+ virJailhouseCellInfoPtr *cell_info_list;
+};
+
+struct _jailhouseCell {
+ __s32 id;
+ char *state;
+ char *cpus_assigned_list;
+ char *cpus_failed_list;
+};
diff --git a/src/jailhouse/meson.build b/src/jailhouse/meson.build
index 45ceeecca3..a706985169 100644
--- a/src/jailhouse/meson.build
+++ b/src/jailhouse/meson.build
@@ -1,5 +1,6 @@
jailhouse_sources = files(
'jailhouse_driver.c',
+ 'jailhouse_api.c',
)
driver_source_files += jailhouse_sources
diff --git a/src/libvirt.c b/src/libvirt.c
index 59b75c6f7b..b2d0ba3d23 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -75,9 +75,6 @@
#ifdef WITH_BHYVE
# include "bhyve/bhyve_driver.h"
#endif
-#ifdef WITH_JAILHOUSE
-# include "jailhouse/jailhouse_driver.h"
-#endif
#include "access/viraccessmanager.h"
#define VIR_FROM_THIS VIR_FROM_NONE
@@ -274,10 +271,6 @@ virGlobalInit(void)
if (hypervRegister() == -1)
goto error;
#endif
-#ifdef WITH_JAILHOUSE
- if (jailhouseRegister() == -1)
- goto error;
-#endif
#ifdef WITH_REMOTE
if (remoteRegister() == -1)
goto error;
@@ -1010,9 +1003,6 @@ virConnectOpenInternal(const char *name,
#endif
#ifndef WITH_VZ
STRCASEEQ(ret->uri->scheme, "parallels") ||
-#endif
-#ifndef WITH_JAILHOUSE
- STRCASEEQ(ret->uri->scheme, "jailhouse") ||
#endif
false)) {
virReportErrorHelper(VIR_FROM_NONE, VIR_ERR_CONFIG_UNSUPPORTED,
diff --git a/src/remote/remote_daemon.c b/src/remote/remote_daemon.c
index 1aa9bfc0d2..9d1b208a38 100644
--- a/src/remote/remote_daemon.c
+++ b/src/remote/remote_daemon.c
@@ -145,6 +145,10 @@ static int daemonInitialize(void)
if (virDriverLoadModule("interface", "interfaceRegister", false) < 0)
return -1;
# endif
+# ifdef WITH_JAILHOUSE
+ if (virDriverLoadModule("jailhouse", "jailhouseRegister", false) < 0)
+ return -1;
+# endif
# ifdef WITH_SECRETS
if (virDriverLoadModule("secret", "secretRegister", false) < 0)
return -1;
diff --git a/src/remote/remote_daemon_dispatch.c
b/src/remote/remote_daemon_dispatch.c
index 53d17a8f4a..06d8fe6098 100644
--- a/src/remote/remote_daemon_dispatch.c
+++ b/src/remote/remote_daemon_dispatch.c
@@ -2115,7 +2115,8 @@ remoteDispatchConnectOpen(virNetServerPtr server
G_GNUC_UNUSED,
STREQ(type, "VBOX") ||
STREQ(type, "bhyve") ||
STREQ(type, "vz") ||
- STREQ(type, "Parallels")) {
+ STREQ(type, "Parallels") ||
+ STREQ(type, "JAILHOUSE")) {
VIR_DEBUG("Hypervisor driver found, setting URIs for secondary
drivers");
if (getuid() == 0) {
priv->interfaceURI = "interface:///system";
--
2.17.1
4 years, 2 months
[GSoC PATCH 1/9] Jailhouse driver: first commit with skeleton code
by Prakhar Bansal
---
include/libvirt/virterror.h | 2 +-
libvirt.spec.in | 7 +
m4/virt-driver-jailhouse.m4 | 42 +++++
meson.build | 4 +
meson_options.txt | 1 +
src/conf/domain_conf.c | 1 +
src/conf/domain_conf.h | 1 +
src/jailhouse/Makefile.inc.am | 21 +++
src/jailhouse/jailhouse_driver.c | 219 +++++++++++++++++++++++++++
src/jailhouse/jailhouse_driver.h | 23 +++
src/jailhouse/libvirtd_jailhouse.aug | 43 ++++++
src/jailhouse/meson.build | 48 ++++++
src/libvirt.c | 10 ++
src/meson.build | 1 +
src/qemu/qemu_command.c | 1 +
src/util/virerror.c | 1 +
16 files changed, 424 insertions(+), 1 deletion(-)
create mode 100644 m4/virt-driver-jailhouse.m4
create mode 100644 src/jailhouse/Makefile.inc.am
create mode 100644 src/jailhouse/jailhouse_driver.c
create mode 100644 src/jailhouse/jailhouse_driver.h
create mode 100644 src/jailhouse/libvirtd_jailhouse.aug
create mode 100644 src/jailhouse/meson.build
diff --git a/include/libvirt/virterror.h b/include/libvirt/virterror.h
index 0f1c32283d..97f2ac16d8 100644
--- a/include/libvirt/virterror.h
+++ b/include/libvirt/virterror.h
@@ -136,7 +136,7 @@ typedef enum {
VIR_FROM_TPM = 70, /* Error from TPM */
VIR_FROM_BPF = 71, /* Error from BPF code */
-
+ VIR_FROM_JAILHOUSE = 72, /* Error from Jailhouse driver */
# ifdef VIR_ENUM_SENTINELS
VIR_ERR_DOMAIN_LAST
# endif
diff --git a/libvirt.spec.in b/libvirt.spec.in
index bb74443484..074410eaa1 100644
--- a/libvirt.spec.in
+++ b/libvirt.spec.in
@@ -17,6 +17,7 @@
%define with_lxc 0%{!?_without_lxc:1}
%define with_libxl 0%{!?_without_libxl:1}
%define with_vbox 0%{!?_without_vbox:1}
+%define with_jailhouse 0%{!?_without_jailhouse:1}
%define with_qemu_tcg %{with_qemu}
@@ -1045,6 +1046,12 @@ exit 1
%define arg_vmware -Ddriver_vmware=disabled
%endif
+%if %{with_jailhouse}
+ %define arg_jailhouse --with-jailhouse
+%else
+ %define arg_jailhouse --without-jailhouse
+%endif
+
%if %{with_storage_rbd}
%define arg_storage_rbd -Dstorage_rbd=enabled
%else
diff --git a/m4/virt-driver-jailhouse.m4 b/m4/virt-driver-jailhouse.m4
new file mode 100644
index 0000000000..9008c6ce30
--- /dev/null
+++ b/m4/virt-driver-jailhouse.m4
@@ -0,0 +1,42 @@
+dnl The Jailhouse driver
+dnl
+dnl Copyright (C) 2016 Red Hat, Inc.
+dnl
+dnl This library is free software; you can redistribute it and/or
+dnl modify it under the terms of the GNU Lesser General Public
+dnl License as published by the Free Software Foundation; either
+dnl version 2.1 of the License, or (at your option) any later version.
+dnl
+dnl This library is distributed in the hope that it will be useful,
+dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
+dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+dnl Lesser General Public License for more details.
+dnl
+dnl You should have received a copy of the GNU Lesser General Public
+dnl License along with this library. If not, see
+dnl <http://www.gnu.org/licenses/>.
+dnl
+
+AC_DEFUN([LIBVIRT_DRIVER_ARG_JAILHOUSE], [
+ LIBVIRT_ARG_WITH_FEATURE([JAILHOUSE], [Jailhouse], [check])
+])
+
+AC_DEFUN([LIBVIRT_DRIVER_CHECK_JAILHOUSE], [
+ if test "$with_jailhouse" = "check"; then
+ with_jailhouse=$with_linux
+ fi
+
+ if test "$with_jailhouse" = "yes" && test "$with_linux" = "no"; then
+ AC_MSG_ERROR([The Jailhouse driver can be enabled on Linux only.])
+ fi
+
+ if test "$with_jailhouse" = "yes"; then
+ AC_DEFINE_UNQUOTED([WITH_JAILHOUSE], 1, [whether Jailhouse driver is
enabled])
+ fi
+
+ AM_CONDITIONAL([WITH_JAILHOUSE], [test "$with_jailhouse" = "yes"])
+])
+
+AC_DEFUN([LIBVIRT_DRIVER_RESULT_JAILHOUSE], [
+ LIBVIRT_RESULT([Jailhouse], [$with_jailhouse])
+])
diff --git a/meson.build b/meson.build
index dabd4196e6..d0f31f916b 100644
--- a/meson.build
+++ b/meson.build
@@ -1889,6 +1889,10 @@ elif get_option('secdriver_selinux').enabled()
error('You must install the libselinux development package in order to
compile libvirt.')
endif
+if get_option('driver_jailhouse').enabled()
+ conf.set('WITH_JAILHOUSE', 1)
+endif
+
if conf.has('WITH_QEMU') or conf.has('WITH_LXC') or
conf.has('WITH_NETWORK')
conf.set('WITH_BRIDGE', 1)
endif
diff --git a/meson_options.txt b/meson_options.txt
index 79554c3186..c1f2b51427 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -68,6 +68,7 @@ option('driver_vbox', type: 'feature', value: 'enabled',
description: 'VirtualBo
option('vbox_xpcomc_dir', type: 'string', value: '', description:
'Location of directory containing VirtualBox XPCOMC library')
option('driver_vmware', type: 'feature', value: 'enabled', description:
'VMware driver')
option('driver_vz', type: 'feature', value: 'auto', description:
'Virtuozzo driver')
+option('driver_jailhouse', type: 'feature', value: 'auto', description:
'Jailhouse driver')
option('secdriver_apparmor', type: 'feature', value: 'auto', description:
'use AppArmor security driver')
option('apparmor_profiles', type: 'boolean', value: false, description:
'install apparmor profiles')
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 5d3ae8bb28..cb946d5e87 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -130,6 +130,7 @@ VIR_ENUM_IMPL(virDomainVirt,
"parallels",
"bhyve",
"vz",
+ "jailhouse",
);
VIR_ENUM_IMPL(virDomainOS,
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 8a0f26f5c0..cc51547bc2 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -139,6 +139,7 @@ typedef enum {
VIR_DOMAIN_VIRT_PARALLELS,
VIR_DOMAIN_VIRT_BHYVE,
VIR_DOMAIN_VIRT_VZ,
+ VIR_DOMAIN_VIRT_JAILHOUSE,
VIR_DOMAIN_VIRT_LAST
} virDomainVirtType;
diff --git a/src/jailhouse/Makefile.inc.am b/src/jailhouse/Makefile.inc.am
new file mode 100644
index 0000000000..02822b2ea1
--- /dev/null
+++ b/src/jailhouse/Makefile.inc.am
@@ -0,0 +1,21 @@
+# vim: filetype=automake
+
+JAILHOUSE_DRIVER_SOURCES = \
+ jailhouse/jailhouse_driver.c \
+ jailhouse/jailhouse_driver.h \
+ $(NULL)
+
+
+DRIVER_SOURCE_FILES += $(addprefix $(srcdir)/,$(JAILHOUSE_DRIVER_SOURCES))
+
+EXTRA_DIST += $(JAILHOUSE_DRIVER_SOURCES)
+
+if WITH_JAILHOUSE
+noinst_LTLIBRARIES += libvirt_driver_jailhouse.la
+libvirt_la_BUILT_LIBADD += libvirt_driver_jailhouse.la
+libvirt_driver_jailhouse_la_CFLAGS = \
+ -I$(srcdir)/conf \
+ $(AM_CFLAGS) \
+ $(NULL)
+libvirt_driver_jailhouse_la_SOURCES = $(JAILHOUSE_DRIVER_SOURCES)
+endif WITH_JAILHOUSE
diff --git a/src/jailhouse/jailhouse_driver.c
b/src/jailhouse/jailhouse_driver.c
new file mode 100644
index 0000000000..0175ba771b
--- /dev/null
+++ b/src/jailhouse/jailhouse_driver.c
@@ -0,0 +1,219 @@
+/*
+ * jailhouse_driver.c: Implementation of driver for Jailhouse hypervisor
+ *
+ * Copyright (C) 2020 Prakhar Bansal
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see
+ * <http://www.gnu.org/licenses/>.
+ */
+
+#include <config.h>
+
+#include "jailhouse_driver.h"
+#include "virtypedparam.h"
+#include "virerror.h"
+#include "virstring.h"
+#include "viralloc.h"
+#include "domain_conf.h"
+#include "virfile.h"
+#include "datatypes.h"
+#include "vircommand.h"
+#include <string.h>
+
+#define UNUSED(x) (void)(x)
+
+static virDrvOpenStatus
+jailhouseConnectOpen(virConnectPtr conn,
+ virConnectAuthPtr auth,
+ virConfPtr conf,
+ unsigned int flags)
+{
+ UNUSED(conn);
+ UNUSED(auth);
+ UNUSED(conf);
+ UNUSED(flags);
+ return 0;
+}
+
+static int
+jailhouseConnectClose(virConnectPtr conn)
+{
+ UNUSED(conn);
+ return 0;
+}
+
+static const char *
+jailhouseConnectGetType(virConnectPtr conn)
+{
+ UNUSED(conn);
+ return NULL;
+
+}
+
+static char *
+jailhouseConnectGetHostname(virConnectPtr conn)
+{
+ UNUSED(conn);
+ return NULL;
+}
+
+static int
+jailhouseNodeGetInfo(virConnectPtr conn,
+ virNodeInfoPtr info)
+{
+ UNUSED(conn);
+ UNUSED(info);
+ return -1;
+}
+
+static int
+jailhouseConnectListDomains(virConnectPtr conn,
+ int *ids,
+ int maxids)
+{
+ UNUSED(conn);
+ UNUSED(ids);
+ UNUSED(maxids);
+ return -1;
+}
+
+static int
+jailhouseConnectNumOfDomains(virConnectPtr conn)
+{
+ UNUSED(conn);
+ return -1;
+}
+
+static int
+jailhouseConnectListAllDomains(virConnectPtr conn,
+ virDomainPtr **domain,
+ unsigned int flags)
+{
+ UNUSED(conn);
+ UNUSED(domain);
+ UNUSED(flags);
+ return -1;
+}
+
+static virDomainPtr
+jailhouseDomainLookupByID(virConnectPtr conn,
+ int id)
+{
+ UNUSED(conn);
+ UNUSED(id);
+ return NULL;
+}
+
+static virDomainPtr
+jailhouseDomainLookupByName(virConnectPtr conn,
+ const char *name)
+{
+ UNUSED(conn);
+ UNUSED(name);
+ return NULL;
+}
+
+static virDomainPtr
+jailhouseDomainLookupByUUID(virConnectPtr conn,
+ const unsigned char *uuid)
+{
+ UNUSED(conn);
+ UNUSED(uuid);
+ return NULL;
+}
+
+static int
+jailhouseDomainCreate(virDomainPtr domain)
+{
+ UNUSED(domain);
+ return -1;
+
+}
+
+static int
+jailhouseDomainShutdown(virDomainPtr domain)
+{
+ UNUSED(domain);
+ return -1;
+}
+
+
+static int
+jailhouseDomainDestroy(virDomainPtr domain)
+{
+ UNUSED(domain);
+ return -1;
+}
+
+static int
+jailhouseDomainGetInfo(virDomainPtr domain,
+ virDomainInfoPtr info)
+{
+ UNUSED(domain);
+ UNUSED(info);
+ return -1;
+}
+
+static int
+jailhouseDomainGetState(virDomainPtr domain,
+ int *state,
+ int *reason,
+ unsigned int flags)
+{
+ UNUSED(domain);
+ UNUSED(state);
+ UNUSED(reason);
+ UNUSED(flags);
+ return -1;
+}
+
+static char *
+jailhouseDomainGetXMLDesc(virDomainPtr domain,
+ unsigned int flags)
+{
+ UNUSED(domain);
+ UNUSED(flags);
+ return NULL;
+}
+
+static virHypervisorDriver jailhouseHypervisorDriver = {
+ .name = "JAILHOUSE",
+ .connectOpen = jailhouseConnectOpen, /* 6.3.0 */
+ .connectClose = jailhouseConnectClose, /* 6.3.0 */
+ .connectListDomains = jailhouseConnectListDomains, /* 6.3.0 */
+ .connectNumOfDomains = jailhouseConnectNumOfDomains, /* 6.3.0 */
+ .connectListAllDomains = jailhouseConnectListAllDomains, /* 6.3.0 */
+ .domainLookupByID = jailhouseDomainLookupByID, /* 6.3.0 */
+ .domainLookupByUUID = jailhouseDomainLookupByUUID, /* 6.3.0 */
+ .domainLookupByName = jailhouseDomainLookupByName, /* 6.3.0 */
+ .domainGetXMLDesc = jailhouseDomainGetXMLDesc, /* 6.3.0 */
+ .domainCreate = jailhouseDomainCreate, /* 6.3.0 */
+ .connectGetType = jailhouseConnectGetType, /* 6.3.0 */
+ .connectGetHostname = jailhouseConnectGetHostname, /* 6.3.0 */
+ .nodeGetInfo = jailhouseNodeGetInfo, /* 6.3.0 */
+ .domainShutdown = jailhouseDomainShutdown, /* 6.3.0 */
+ .domainDestroy = jailhouseDomainDestroy, /* 6.3.0 */
+ .domainGetInfo = jailhouseDomainGetInfo, /* 6.3.0 */
+ .domainGetState = jailhouseDomainGetState, /* 6.3.0 */
+};
+
+static virConnectDriver jailhouseConnectDriver = {
+ .hypervisorDriver = &jailhouseHypervisorDriver,
+};
+
+int
+jailhouseRegister(void)
+{
+ return virRegisterConnectDriver(&jailhouseConnectDriver, false);
+}
diff --git a/src/jailhouse/jailhouse_driver.h
b/src/jailhouse/jailhouse_driver.h
new file mode 100644
index 0000000000..b0dbc8d033
--- /dev/null
+++ b/src/jailhouse/jailhouse_driver.h
@@ -0,0 +1,23 @@
+/*
+ * jailhouse_driver.h: Libvirt driver for Jailhouse hypervisor
+ *
+ * Copyright (C) 2020 Prakhar Bansal
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see
+ * <http://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+
+int jailhouseRegister(void);
diff --git a/src/jailhouse/libvirtd_jailhouse.aug
b/src/jailhouse/libvirtd_jailhouse.aug
new file mode 100644
index 0000000000..96a186eae2
--- /dev/null
+++ b/src/jailhouse/libvirtd_jailhouse.aug
@@ -0,0 +1,43 @@
+(* /etc/libvirt/jailhouse.conf *)
+
+module Libvirtd_jailhouse =
+ autoload xfm
+
+ let eol = del /[ \t]*\n/ "\n"
+ let value_sep = del /[ \t]*=[ \t]*/ " = "
+ let indent = del /[ \t]*/ ""
+
+ let array_sep = del /,[ \t\n]*/ ", "
+ let array_start = del /\[[ \t\n]*/ "[ "
+ let array_end = del /\]/ "]"
+
+ let str_val = del /\"/ "\"" . store /[^\"]*/ . del /\"/ "\""
+ let bool_val = store /0|1/
+ let int_val = store /[0-9]+/
+ let str_array_element = [ seq "el" . str_val ] . del /[ \t\n]*/ ""
+ let str_array_val = counter "el" . array_start . ( str_array_element .
( array_sep . str_array_element ) * ) ? . array_end
+
+ let str_entry (kw:string) = [ key kw . value_sep . str_val ]
+ let bool_entry (kw:string) = [ key kw . value_sep . bool_val ]
+ let int_entry (kw:string) = [ key kw . value_sep . int_val ]
+ let str_array_entry (kw:string) = [ key kw . value_sep . str_array_val ]
+
+ (* Config entry grouped by function - same order as example config *)
+ let log_entry = bool_entry "log_with_libvirtd"
+ | str_entry "security_driver"
+ | bool_entry "security_default_confined"
+ | bool_entry "security_require_confined"
+
+ (* Each entry in the config is one of the following three ... *)
+ let entry = log_entry
+ let comment = [ label "#comment" . del /#[ \t]*/ "# " . store /([^
\t\n][^\n]*)?/ . del /\n/ "\n" ]
+ let empty = [ label "#empty" . eol ]
+
+ let record = indent . entry . eol
+
+ let lns = ( record | comment | empty ) *
+
+ let filter = incl "/etc/libvirt/jailhouse.conf"
+ . Util.stdexcl
+
+ let xfm = transform lns filter
diff --git a/src/jailhouse/meson.build b/src/jailhouse/meson.build
new file mode 100644
index 0000000000..45ceeecca3
--- /dev/null
+++ b/src/jailhouse/meson.build
@@ -0,0 +1,48 @@
+jailhouse_sources = files(
+ 'jailhouse_driver.c',
+)
+
+driver_source_files += jailhouse_sources
+stateful_driver_source_files += jailhouse_sources
+
+if conf.has('WITH_JAILHOUSE')
+ jailhouse_driver_impl = static_library(
+ 'virt_driver_jailhouse_impl',
+ [
+ jailhouse_sources,
+ ],
+ dependencies: [
+ access_dep,
+ src_dep,
+ ],
+ include_directories: [
+ conf_inc_dir,
+ hypervisor_inc_dir,
+ ],
+ )
+
+ virt_modules += {
+ 'name': 'virt_driver_jailhouse',
+ 'link_whole': [
+ jailhouse_driver_impl,
+ ],
+ 'link_args': [
+ libvirt_no_undefined,
+ ],
+ }
+
+ virt_daemons += {
+ 'name': 'virtjailhoused',
+ 'c_args': [
+ '-DDAEMON_NAME="virtjailhoused"',
+ '-DMODULE_NAME="jailhouse"'
+ ],
+ }
+
+ virt_conf_files += files('jailhouse.conf')
+ virt_aug_files += files('libvirtd_jailhouse.aug')
+
+ virt_daemon_confs += {
+ 'name': 'virtjailhoused',
+ }
+endif
diff --git a/src/libvirt.c b/src/libvirt.c
index b2d0ba3d23..59b75c6f7b 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -75,6 +75,9 @@
#ifdef WITH_BHYVE
# include "bhyve/bhyve_driver.h"
#endif
+#ifdef WITH_JAILHOUSE
+# include "jailhouse/jailhouse_driver.h"
+#endif
#include "access/viraccessmanager.h"
#define VIR_FROM_THIS VIR_FROM_NONE
@@ -271,6 +274,10 @@ virGlobalInit(void)
if (hypervRegister() == -1)
goto error;
#endif
+#ifdef WITH_JAILHOUSE
+ if (jailhouseRegister() == -1)
+ goto error;
+#endif
#ifdef WITH_REMOTE
if (remoteRegister() == -1)
goto error;
@@ -1003,6 +1010,9 @@ virConnectOpenInternal(const char *name,
#endif
#ifndef WITH_VZ
STRCASEEQ(ret->uri->scheme, "parallels") ||
+#endif
+#ifndef WITH_JAILHOUSE
+ STRCASEEQ(ret->uri->scheme, "jailhouse") ||
#endif
false)) {
virReportErrorHelper(VIR_FROM_NONE, VIR_ERR_CONFIG_UNSUPPORTED,
diff --git a/src/meson.build b/src/meson.build
index 5d8deaf548..7188dc623e 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -268,6 +268,7 @@ subdir('security')
subdir('storage')
subdir('bhyve')
+subdir('jailhouse')
subdir('esx')
subdir('hyperv')
subdir('libxl')
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 6798febf8d..f750270230 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -6819,6 +6819,7 @@ qemuBuildMachineCommandLine(virCommandPtr cmd,
case VIR_DOMAIN_VIRT_PHYP:
case VIR_DOMAIN_VIRT_PARALLELS:
case VIR_DOMAIN_VIRT_BHYVE:
+ case VIR_DOMAIN_VIRT_JAILHOUSE:
case VIR_DOMAIN_VIRT_VZ:
case VIR_DOMAIN_VIRT_NONE:
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
diff --git a/src/util/virerror.c b/src/util/virerror.c
index 507a29f50f..8caf24a5f2 100644
--- a/src/util/virerror.c
+++ b/src/util/virerror.c
@@ -134,6 +134,7 @@ VIR_ENUM_IMPL(virErrorDomain,
"Thread jobs",
"Admin Interface",
"Log Manager",
+ "Jailhouse Driver",
"Xen XL Config",
"Perf", /* 65 */
--
2.17.1
4 years, 2 months
[question] cpumap: why 'mpx' removed from Cooperlake model?
by Wangxin (Alexander)
Hi, Jiri
I just compared the cpu features between the 'x86_Cooperlake.xml ' and 'x86_Cascadelake-Server.xml',
the feature 'mpx' seems removed from the Cooperlake model. Is there a reason?
And what rules do we follow to add or remove CPU features?
Regards,
Xin
4 years, 2 months
[PATCH] NVRAM: check NVRAM file size and recover from template
by Hao Wang
From: Hao Wang <wanghao232(a)huawei.com>
Subject: [PATCH] NVRAM: check NVRAM file size and recover from template
A corrupted nvram file (e.g. caused by last unsuccessful creation due to
insufficient memory) can lead to boot or migration failure.
Check the size of the existed nvram file when qemuPrepareNVRAM, and re-create
if the existed one is unhealthy.
Signed-off-by: Hao Wang <wanghao232(a)huawei.com>
---
src/qemu/qemu_process.c | 54 ++++++++++++++++++++++++++++++++++++++++-
1 file changed, 53 insertions(+), 1 deletion(-)
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 126fabf5ef..42060bb36c 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -4376,6 +4376,48 @@ qemuProcessUpdateCPU(virQEMUDriverPtr driver,
}
+static bool
+qemuIsNvramFileHealthy(virQEMUDriverConfigPtr cfg,
+ virDomainLoaderDefPtr loader)
+{
+ const char *masterNvramPath;
+ off_t nvramSize;
+ off_t masterSize;
+
+ masterNvramPath = loader->templt;
+ if (!loader->templt) {
+ size_t i;
+ for (i = 0; i < cfg->nfirmwares; i++) {
+ if (STREQ(cfg->firmwares[i]->name, loader->path)) {
+ masterNvramPath = cfg->firmwares[i]->nvram;
+ break;
+ }
+ }
+ }
+
+ if (!masterNvramPath) {
+ VIR_WARN("no nvram template is found; assume the nvram file is healthy");
+ return true;
+ }
+
+ if ((nvramSize = virFileLength(loader->nvram, -1)) < 0 ||
+ (masterSize = virFileLength(masterNvramPath, -1)) < 0) {
+ virReportSystemError(errno,
+ _("unable to get the size of '%s' or '%s'"),
+ loader->nvram, masterNvramPath);
+ return false;
+ }
+
+ if (nvramSize != masterSize) {
+ VIR_WARN("the size(%zd) of the nvram file is not equal to that of the template %s",
+ nvramSize, masterNvramPath);
+ return false;
+ }
+
+ return true;
+}
+
+
static int
qemuPrepareNVRAM(virQEMUDriverConfigPtr cfg,
virDomainObjPtr vm)
@@ -4388,9 +4430,19 @@ qemuPrepareNVRAM(virQEMUDriverConfigPtr cfg,
const char *master_nvram_path;
ssize_t r;
- if (!loader || !loader->nvram || virFileExists(loader->nvram))
+ if (!loader || !loader->nvram)
return 0;
+ if (virFileExists(loader->nvram)) {
+ if (qemuIsNvramFileHealthy(cfg, loader))
+ return 0;
+
+ ignore_value(virFileRemove(loader->nvram, -1, -1));
+ VIR_WARN("the nvram file %s exists but may be corrupted! "
+ "Remove it and try to copy a new one from template.",
+ loader->nvram);
+ }
+
master_nvram_path = loader->templt;
if (!loader->templt) {
size_t i;
--
2.23.0
4 years, 2 months
[GSoC PATCH 3/9] Jailhouse driver: Implementation of ConnectGetType
by Prakhar Bansal
---
src/jailhouse/jailhouse_driver.c | 28 ++++++++++++++++------------
1 file changed, 16 insertions(+), 12 deletions(-)
diff --git a/src/jailhouse/jailhouse_driver.c b/src/jailhouse/jailhouse_driver.c
index ac9da4c85d..75bf41fc11 100644
--- a/src/jailhouse/jailhouse_driver.c
+++ b/src/jailhouse/jailhouse_driver.c
@@ -32,8 +32,10 @@
#include "viralloc.h"
#include "virfile.h"
#include "virlog.h"
+#include "virutil.h"
#include "vircommand.h"
#include "virpidfile.h"
+#include "access/viraccessapicheck.h"
#define VIR_FROM_THIS VIR_FROM_JAILHOUSE
@@ -241,16 +243,19 @@ jailhouseStateInitialize(bool privileged G_GNUC_UNUSED,
static const char *
jailhouseConnectGetType(virConnectPtr conn)
{
- UNUSED(conn);
- return NULL;
+ if (virConnectGetTypeEnsureACL(conn) < 0)
+ return NULL;
+ return "JAILHOUSE";
}
static char *
jailhouseConnectGetHostname(virConnectPtr conn)
{
- UNUSED(conn);
- return NULL;
+ if (virConnectGetHostnameEnsureACL(conn) < 0)
+ return NULL;
+
+ return virGetHostname();
}
static int
@@ -263,7 +268,7 @@ jailhouseNodeGetInfo(virConnectPtr conn, virNodeInfoPtr info)
static int
jailhouseConnectListAllDomains(virConnectPtr conn,
- virDomainPtr ** domain, unsigned int flags)
+ virDomainPtr **domain, unsigned int flags)
{
UNUSED(conn);
UNUSED(domain);
@@ -300,7 +305,6 @@ jailhouseDomainCreate(virDomainPtr domain)
{
UNUSED(domain);
return -1;
-
}
static int
@@ -350,18 +354,18 @@ static virHypervisorDriver jailhouseHypervisorDriver = {
.connectOpen = jailhouseConnectOpen, /* 6.3.0 */
.connectClose = jailhouseConnectClose, /* 6.3.0 */
.connectListAllDomains = jailhouseConnectListAllDomains, /* 6.3.0 */
- .domainLookupByID = jailhouseDomainLookupByID, /* 6.3.0 */
- .domainLookupByUUID = jailhouseDomainLookupByUUID, /* 6.3.0 */
- .domainLookupByName = jailhouseDomainLookupByName, /* 6.3.0 */
- .domainGetXMLDesc = jailhouseDomainGetXMLDesc, /* 6.3.0 */
- .domainCreate = jailhouseDomainCreate, /* 6.3.0 */
.connectGetType = jailhouseConnectGetType, /* 6.3.0 */
.connectGetHostname = jailhouseConnectGetHostname, /* 6.3.0 */
- .nodeGetInfo = jailhouseNodeGetInfo, /* 6.3.0 */
+ .domainCreate = jailhouseDomainCreate, /* 6.3.0 */
.domainShutdown = jailhouseDomainShutdown, /* 6.3.0 */
.domainDestroy = jailhouseDomainDestroy, /* 6.3.0 */
.domainGetInfo = jailhouseDomainGetInfo, /* 6.3.0 */
.domainGetState = jailhouseDomainGetState, /* 6.3.0 */
+ .domainLookupByID = jailhouseDomainLookupByID, /* 6.3.0 */
+ .domainLookupByUUID = jailhouseDomainLookupByUUID, /* 6.3.0 */
+ .domainLookupByName = jailhouseDomainLookupByName, /* 6.3.0 */
+ .domainGetXMLDesc = jailhouseDomainGetXMLDesc, /* 6.3.0 */
+ .nodeGetInfo = jailhouseNodeGetInfo, /* 6.3.0 */
};
--
2.17.1
4 years, 2 months