Re: [GSoC PATCH 1/9] Jailhouse driver: first commit with skeleton code

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On a Monday in 2020, Prakhar Bansal wrote:
---
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/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

m4/virt-driver-jailhouse.m4 is not needed anymore, after the switch to
Meson

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>

This should not be needed if you include internal.h,
which should be included transitively by the includes above.

+
+#define UNUSED(x) (void)(x)
+

We have G_GNUC_UNUSED, that can be used like:

+jailhouseConnectOpen(virConnectPtr conn G_GNUC_UNUSED,
+                     virConnectAuthPtr auth,
+                     virConfPtr conf,
+                     unsigned int flags)

however, there is no need to include all these functions in the first
patch (see below)

+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",

Why is this all uppercase? From the cover letter it seems "Jailhouse" is
the preferred spelling.

+    .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 */

Apart from connectOpen and connectClose, there is no need to list all
the functions upfront. If you don't initialize them, the caller will
check whether a particular driver implements it or not before calling
it:
virDomainLookupByID(virConnectPtr conn, int id)
  ...

    if (conn->driver->domainLookupByID) {
        virDomainPtr ret;
        ret = conn->driver->domainLookupByID(conn, id);
        if (!ret)
            goto error;
        return ret;
    }


+};
+
+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
+

#include "internal.h"
please

+int jailhouseRegister(void);

Jano

Attachment: signature.asc
Description: PGP signature


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux