From nobody Mon Apr 29 23:31:06 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) client-ip=207.211.31.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1600356259; cv=none; d=zohomail.com; s=zohoarc; b=AwbfFOyayIsvadKF9U1FJg0W3U9jfgVhKh6V0pGQ50x5JRnD75uYJFpTZOl5999kpT5CRqmzaysL5sPV3MkCOdqWldGFtCT0uw5UTSsHwAmY2vJEXxreywuUW2xUUG5FyoUESnXEacyOt0274ZOAzNecYMCf+myvKesKJHPsKxg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600356259; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=qOEhJ445RSb53JF3ENVSqLo/RUywEyZ7C4nReSNez4c=; b=mNXxA0YzADLgQx7dM98mthDbT4TodxTqX15IV36WJQVKhrOTa7p9s7eyYM7nda/Lq5lY7usgQvCtF9J8oggp0rxoAugYIu86p5zhXJghH3N4ngME0/5dbUIKKwz9xbe52qCfkYSRjs/baGX/JyZnOmng6BB8bnNtH8rZHK388h0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by mx.zohomail.com with SMTPS id 1600356259225662.0989713164433; Thu, 17 Sep 2020 08:24:19 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-567-krp_PZcTNJCBF6b-2935Wg-1; Thu, 17 Sep 2020 11:24:15 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 70CB7186DD2B; Thu, 17 Sep 2020 15:24:08 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 441BA73663; Thu, 17 Sep 2020 15:24:08 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 55BD7183D040; Thu, 17 Sep 2020 15:24:07 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 08HFO5kv017763 for ; Thu, 17 Sep 2020 11:24:05 -0400 Received: by smtp.corp.redhat.com (Postfix) id D201D60CC0; Thu, 17 Sep 2020 15:24:05 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-114-29.ams2.redhat.com [10.36.114.29]) by smtp.corp.redhat.com (Postfix) with ESMTP id CB810610F2; Thu, 17 Sep 2020 15:24:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600356258; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=qOEhJ445RSb53JF3ENVSqLo/RUywEyZ7C4nReSNez4c=; b=KOaRL9BIcub+hbN8iwobldOO66JSb4QjkST9jK1vf0kTkzwOnr0bqHgK/bnWaAibD3D3AZ QvZ4iWd3107PvlUWZybTjWvFmFGwYfAbQ442aFzt6lr3mHiMQtNhPWvaC1hBEWYF/ZymrR CAgZkFc9WvhA/5XAO4E2OKgvrbYD3zk= X-MC-Unique: krp_PZcTNJCBF6b-2935Wg-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Subject: [libvirt PATCH 1/9] Jailhouse driver: first commit with skeleton code Date: Thu, 17 Sep 2020 16:23:51 +0100 Message-Id: <20200917152359.1621763-2-berrange@redhat.com> In-Reply-To: <20200917152359.1621763-1-berrange@redhat.com> References: <20200917152359.1621763-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Cc: Prakhar Bansal X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: 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 { =20 VIR_FROM_TPM =3D 70, /* Error from TPM */ VIR_FROM_BPF =3D 71, /* Error from BPF code */ - + VIR_FROM_JAILHOUSE =3D 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 62b401bd08..ca65063e79 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} =20 %define with_qemu_tcg %{with_qemu} =20 @@ -1043,6 +1044,12 @@ exit 1 %define arg_vmware -Ddriver_vmware=3Ddisabled %endif =20 +%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=3Denabled %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 . +dnl + +AC_DEFUN([LIBVIRT_DRIVER_ARG_JAILHOUSE], [ + LIBVIRT_ARG_WITH_FEATURE([JAILHOUSE], [Jailhouse], [check]) +]) + +AC_DEFUN([LIBVIRT_DRIVER_CHECK_JAILHOUSE], [ + if test "$with_jailhouse" =3D "check"; then + with_jailhouse=3D$with_linux + fi + + if test "$with_jailhouse" =3D "yes" && test "$with_linux" =3D "no"; then + AC_MSG_ERROR([The Jailhouse driver can be enabled on Linux only.]) + fi + + if test "$with_jailhouse" =3D "yes"; then + AC_DEFINE_UNQUOTED([WITH_JAILHOUSE], 1, [whether Jailhouse driver is e= nabled]) + fi + + AM_CONDITIONAL([WITH_JAILHOUSE], [test "$with_jailhouse" =3D "yes"]) +]) + +AC_DEFUN([LIBVIRT_DRIVER_RESULT_JAILHOUSE], [ + LIBVIRT_RESULT([Jailhouse], [$with_jailhouse]) +]) diff --git a/meson.build b/meson.build index 195d7cd784..f4f9ca4119 100644 --- a/meson.build +++ b/meson.build @@ -1895,6 +1895,10 @@ elif get_option('secdriver_selinux').enabled() error('You must install the libselinux development package in order to c= ompile libvirt.') endif =20 +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 7838630c1e..4f237be5dc 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -69,6 +69,7 @@ option('driver_vbox', type: 'feature', value: 'enabled', = description: 'VirtualBo option('vbox_xpcomc_dir', type: 'string', value: '', description: 'Locatio= n of directory containing VirtualBox XPCOMC library') option('driver_vmware', type: 'feature', value: 'enabled', description: 'V= Mware driver') option('driver_vz', type: 'feature', value: 'auto', description: 'Virtuozz= o driver') +option('driver_jailhouse', type: 'feature', value: 'auto', description: 'J= ailhouse driver') =20 option('secdriver_apparmor', type: 'feature', value: 'auto', description: = 'use AppArmor security driver') option('apparmor_profiles', type: 'boolean', value: false, description: 'i= nstall apparmor profiles') diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 4d296f7bcb..b764a5962d 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", ); =20 VIR_ENUM_IMPL(virDomainOS, diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index cf76f340ee..46a8a1708c 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, =20 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=3Dautomake + +JAILHOUSE_DRIVER_SOURCES =3D \ + jailhouse/jailhouse_driver.c \ + jailhouse/jailhouse_driver.h \ + $(NULL) + + +DRIVER_SOURCE_FILES +=3D $(addprefix $(srcdir)/,$(JAILHOUSE_DRIVER_SOURCES= )) + +EXTRA_DIST +=3D $(JAILHOUSE_DRIVER_SOURCES) + +if WITH_JAILHOUSE +noinst_LTLIBRARIES +=3D libvirt_driver_jailhouse.la +libvirt_la_BUILT_LIBADD +=3D libvirt_driver_jailhouse.la +libvirt_driver_jailhouse_la_CFLAGS =3D \ + -I$(srcdir)/conf \ + $(AM_CFLAGS) \ + $(NULL) +libvirt_driver_jailhouse_la_SOURCES =3D $(JAILHOUSE_DRIVER_SOURCES) +endif WITH_JAILHOUSE diff --git a/src/jailhouse/jailhouse_driver.c b/src/jailhouse/jailhouse_dri= ver.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 + * . + */ + +#include + +#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 + +#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 =3D { + .name =3D "JAILHOUSE", + .connectOpen =3D jailhouseConnectOpen, /* 6.3.0 */ + .connectClose =3D jailhouseConnectClose, /* 6.3.0 */ + .connectListDomains =3D jailhouseConnectListDomains, /* 6.3.0 */ + .connectNumOfDomains =3D jailhouseConnectNumOfDomains, /* 6.3.0 */ + .connectListAllDomains =3D jailhouseConnectListAllDomains, /* 6.3.0 */ + .domainLookupByID =3D jailhouseDomainLookupByID, /* 6.3.0 */ + .domainLookupByUUID =3D jailhouseDomainLookupByUUID, /* 6.3.0 */ + .domainLookupByName =3D jailhouseDomainLookupByName, /* 6.3.0 */ + .domainGetXMLDesc =3D jailhouseDomainGetXMLDesc, /* 6.3.0 */ + .domainCreate =3D jailhouseDomainCreate, /* 6.3.0 */ + .connectGetType =3D jailhouseConnectGetType, /* 6.3.0 */ + .connectGetHostname =3D jailhouseConnectGetHostname, /* 6.3.0 */ + .nodeGetInfo =3D jailhouseNodeGetInfo, /* 6.3.0 */ + .domainShutdown =3D jailhouseDomainShutdown, /* 6.3.0 */ + .domainDestroy =3D jailhouseDomainDestroy, /* 6.3.0 */ + .domainGetInfo =3D jailhouseDomainGetInfo, /* 6.3.0 */ + .domainGetState =3D jailhouseDomainGetState, /* 6.3.0 */ +}; + +static virConnectDriver jailhouseConnectDriver =3D { + .hypervisorDriver =3D &jailhouseHypervisorDriver, +}; + +int +jailhouseRegister(void) +{ + return virRegisterConnectDriver(&jailhouseConnectDriver, false); +} diff --git a/src/jailhouse/jailhouse_driver.h b/src/jailhouse/jailhouse_dri= ver.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 + * . + */ + +#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 =3D + autoload xfm + + let eol =3D del /[ \t]*\n/ "\n" + let value_sep =3D del /[ \t]*=3D[ \t]*/ " =3D " + let indent =3D del /[ \t]*/ "" + + let array_sep =3D del /,[ \t\n]*/ ", " + let array_start =3D del /\[[ \t\n]*/ "[ " + let array_end =3D del /\]/ "]" + + let str_val =3D del /\"/ "\"" . store /[^\"]*/ . del /\"/ "\"" + let bool_val =3D store /0|1/ + let int_val =3D store /[0-9]+/ + let str_array_element =3D [ seq "el" . str_val ] . del /[ \t\n]*/ "" + let str_array_val =3D counter "el" . array_start . ( str_array_element = . ( array_sep . str_array_element ) * ) ? . array_end + + let str_entry (kw:string) =3D [ key kw . value_sep . str_val ] + let bool_entry (kw:string) =3D [ key kw . value_sep . bool_val ] + let int_entry (kw:string) =3D [ key kw . value_sep . int_val ] + let str_array_entry (kw:string) =3D [ key kw . value_sep . str_array_va= l ] + + (* Config entry grouped by function - same order as example config *) + let log_entry =3D 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 =3D log_entry + let comment =3D [ label "#comment" . del /#[ \t]*/ "# " . store /([^ \= t\n][^\n]*)?/ . del /\n/ "\n" ] + let empty =3D [ label "#empty" . eol ] + + let record =3D indent . entry . eol + + let lns =3D ( record | comment | empty ) * + + let filter =3D incl "/etc/libvirt/jailhouse.conf" + . Util.stdexcl + + let xfm =3D 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 =3D files( + 'jailhouse_driver.c', +) + +driver_source_files +=3D jailhouse_sources +stateful_driver_source_files +=3D jailhouse_sources + +if conf.has('WITH_JAILHOUSE') + jailhouse_driver_impl =3D static_library( + 'virt_driver_jailhouse_impl', + [ + jailhouse_sources, + ], + dependencies: [ + access_dep, + src_dep, + ], + include_directories: [ + conf_inc_dir, + hypervisor_inc_dir, + ], + ) + + virt_modules +=3D { + 'name': 'virt_driver_jailhouse', + 'link_whole': [ + jailhouse_driver_impl, + ], + 'link_args': [ + libvirt_no_undefined, + ], + } + + virt_daemons +=3D { + 'name': 'virtjailhoused', + 'c_args': [ + '-DDAEMON_NAME=3D"virtjailhoused"', + '-DMODULE_NAME=3D"jailhouse"' + ], + } + + virt_conf_files +=3D files('jailhouse.conf') + virt_aug_files +=3D files('libvirtd_jailhouse.aug') + + virt_daemon_confs +=3D { + 'name': 'virtjailhoused', + } +endif diff --git a/src/libvirt.c b/src/libvirt.c index 0748eb2352..8a78cbcf3a 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" =20 #define VIR_FROM_THIS VIR_FROM_NONE @@ -271,6 +274,10 @@ virGlobalInit(void) if (hypervRegister() =3D=3D -1) goto error; #endif +#ifdef WITH_JAILHOUSE + if (jailhouseRegister() =3D=3D -1) + goto error; +#endif #ifdef WITH_REMOTE if (remoteRegister() =3D=3D -1) goto error; @@ -1045,6 +1052,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 897b5ecbca..9e2b97900e 100644 --- a/src/meson.build +++ b/src/meson.build @@ -268,6 +268,7 @@ subdir('security') subdir('storage') =20 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 0ba348e911..78976c2153 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -6843,6 +6843,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 80a7cfe0ed..560e0a1f0f 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", =20 "Perf", /* 65 */ --=20 2.26.2 From nobody Mon Apr 29 23:31:06 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1600356307; cv=none; d=zohomail.com; s=zohoarc; b=MHd4s66vziM4ik3YcpSBXjCS81xSwB93IbbYhdQ376+oWuKTSlwHOuMm1K95fUYl43475Ry0Y4jgqThb3PsLEJR8K12LU37sBsiwMuTHfbNI5QwZdeRF7ScOYy/qCYceLMID48IU6dNkMuTgXKyxEYCD0Z1nr3IHqkVm/drlJ/o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600356307; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=rdjSY/F1Mr6GEjMJIZ7Lw9uA0R1qMT+7G9zs3ZmY64E=; b=f1UInHxY52XoxqvD+NN4dKP/mheplE1Cl33L9z9mX76A/nHXBkktBaVUXBMNvOxv5tLiqJ+zH3zvWJ0QL/oy8ek0h1GcibGtuC0C3G9KHRiKJGbm5xi+cfI5sNLC7hxFp5/7tWRHlcne5fkoFIbp+OYOB6ZkOg9889MYrxFxzyg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1600356307161994.2257983701875; Thu, 17 Sep 2020 08:25:07 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-70-JvkxhRXKOOii1lsoDrGuzg-1; Thu, 17 Sep 2020 11:24:20 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 212E51008302; Thu, 17 Sep 2020 15:24:15 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id F254F55764; Thu, 17 Sep 2020 15:24:14 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id BA5DD183D047; Thu, 17 Sep 2020 15:24:14 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 08HFO7pD017775 for ; Thu, 17 Sep 2020 11:24:07 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6AB81610F2; Thu, 17 Sep 2020 15:24:07 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-114-29.ams2.redhat.com [10.36.114.29]) by smtp.corp.redhat.com (Postfix) with ESMTP id 54B1060CC0; Thu, 17 Sep 2020 15:24:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600356306; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=rdjSY/F1Mr6GEjMJIZ7Lw9uA0R1qMT+7G9zs3ZmY64E=; b=Y2hMGBqI66EopKctFLBBWiZpOf2ItORb2KfJtBrRT8kl52H0siaTOJfCniQ0G+6fvpWoco BgfVyYqIDfA8qi9BU+vdwWh7SbL2q3s/R39syX3+9MB/7SWlGxyOcKf3KFGUb9BsVNhj2R 04YWUrLGAwNwevy8iT0xxQ019HcrEuQ= X-MC-Unique: JvkxhRXKOOii1lsoDrGuzg-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Subject: [libvirt PATCH 2/9] Jailhouse driver: Implementation of ConnectOpen Date: Thu, 17 Sep 2020 16:23:52 +0100 Message-Id: <20200917152359.1621763-3-berrange@redhat.com> In-Reply-To: <20200917152359.1621763-1-berrange@redhat.com> References: <20200917152359.1621763-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Cc: Prakhar Bansal X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: 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 =3D 70, /* Error from TPM */ VIR_FROM_BPF =3D 71, /* Error from BPF code */ VIR_FROM_JAILHOUSE =3D 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 471af30b89..317db58a21 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -85,6 +85,8 @@ @SRCDIR@src/interface/interface_backend_netcf.c @SRCDIR@src/interface/interface_backend_udev.c @SRCDIR@src/internal.h +@SRCDIR@src/jailhouse/jailhouse_api.c +@SRCDIR@src/jailhouse/jailhouse_driver.c @SRCDIR@src/libvirt-domain-checkpoint.c @SRCDIR@src/libvirt-domain-snapshot.c @SRCDIR@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=3Dautomake =20 + JAILHOUSE_DRIVER_SOURCES =3D \ jailhouse/jailhouse_driver.c \ jailhouse/jailhouse_driver.h \ + jailhouse/jailhouse_api.c \ + jailhouse/jailhouse_api.h \ $(NULL) =20 =20 @@ -11,11 +14,34 @@ DRIVER_SOURCE_FILES +=3D $(addprefix $(srcdir)/,$(JAILH= OUSE_DRIVER_SOURCES)) EXTRA_DIST +=3D $(JAILHOUSE_DRIVER_SOURCES) =20 if WITH_JAILHOUSE -noinst_LTLIBRARIES +=3D libvirt_driver_jailhouse.la -libvirt_la_BUILT_LIBADD +=3D libvirt_driver_jailhouse.la -libvirt_driver_jailhouse_la_CFLAGS =3D \ + +noinst_LTLIBRARIES +=3D libvirt_driver_jailhouse_impl.la +libvirt_driver_jailhouse_la_SOURCES =3D +libvirt_driver_jailhouse_la_LIBADD =3D \ + libvirt_driver_jailhouse_impl.la \ + libvirt.la \ + $(GLIB_LIBS) \ + $(NULL) +mod_LTLIBRARIES +=3D libvirt_driver_jailhouse.la +libvirt_driver_jailhouse_la_LDFLAGS =3D $(AM_LDFLAGS_MOD_NOUNDEF) + +libvirt_driver_jailhouse_impl_la_CFLAGS =3D \ -I$(srcdir)/conf \ $(AM_CFLAGS) \ $(NULL) -libvirt_driver_jailhouse_la_SOURCES =3D $(JAILHOUSE_DRIVER_SOURCES) +libvirt_driver_jailhouse_impl_la_SOURCES =3D \ + $(JAILHOUSE_DRIVER_SOURCES) + +sbin_PROGRAMS +=3D virtjailhoused + +virtjailhoused_SOURCES =3D $(REMOTE_DAEMON_SOURCES) +nodist_virtjailhoused_SOURCES =3D $(REMOTE_DAEMON_GENERATED) +virtjailhoused_CFLAGS =3D \ + $(REMOTE_DAEMON_CFLAGS) \ + -DDAEMON_NAME=3D"\"virtjailhoused\"" \ + -DMODULE_NAME=3D"\"jailhouse\"" \ + $(NULL) +virtjailhoused_LDFLAGS =3D $(REMOTE_DAEMON_LD_FLAGS) +virtjailhoused_LDADD =3D $(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 o= n the +# system. This is a required configuration parameter for the driver. +#system_config =3D "/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 =3D "/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 + * . + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#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/ce= lls" +#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 =3D -1, len; + g_autofree char *buffer =3D NULL; + VIR_AUTOCLOSE fd =3D -1; + + if (!virFileExists(sys_conf_file_path)) + return 0; + + len =3D virFileReadAll(sys_conf_file_path, MAX_JAILHOUSE_SYS_CONFIG_FI= LE_SIZE, &buffer); + if (len < 0 || !buffer) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + "%s", _("Failed to read the system configuration fil= e")); + return -1; + } + + fd =3D openDev(); + + err =3D 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 =3D -1; + VIR_AUTOCLOSE fd =3D -1; + + fd =3D openDev(); + + err =3D 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 =3D strrchr(dirent->d_name, '.'); + + return dirent->d_name[0] !=3D '.' + && (STREQ(ext, JAILHOUSE_CELL_FILE_EXTENSION) =3D=3D 0); +} + +int +createJailhouseCells(const char *dir_path) +{ + + struct dirent **namelist; + int num_entries, ret =3D -1; + size_t i; + + if (strlen(dir_path) =3D=3D 0) + return ret; + + num_entries =3D scandir(dir_path, &namelist, cell_match, alphasort); + if (num_entries =3D=3D -1) { + if (errno =3D=3D 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 =3D 0; i < num_entries; i++) { + g_autofree char *file_path =3D g_strdup_printf("%s/%s", dir_path, = namelist[i]->d_name); + + if (createCell(file_path) !=3D 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("Cell creation failed with conf found in %s.= "), + namelist[i]->d_name); + goto fail; + } + } + + ret =3D 0; + + fail: + VIR_FREE(namelist); + return ret; +} + +int +openDev(void) +{ + int fd; + + fd =3D 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 =3D -1, len; + g_autofree char *buffer =3D NULL; + VIR_AUTOCLOSE fd =3D -1; + + if (strlen(conf_file) =3D=3D 0) + return err; + + len =3D 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 fil= e")); + return err; + } + + cell_create.config_address =3D (unsigned long) buffer; + cell_create.config_size =3D len; + + fd =3D openDev(); + + err =3D 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 =3D NULL; + g_autofree char *file_path =3D NULL; + int len =3D -1; + + file_path =3D g_strdup_printf(JAILHOUSE_CELLS "%u/%s", id, entry); + + len =3D 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 =3D *cell_info_ptr; + + /* set cell id */ + cell_info->id.id =3D id; + + /* get cell name */ + tmp =3D readSysfsCellString(id, "name"); + if (virStrncpy(cell_info->id.name, tmp, JAILHOUSE_CELL_ID_NAMELEN, JAI= LHOUSE_CELL_ID_NAMELEN) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Cell ID %s too long to be copied to the cell inf= o"), + tmp); + return -1; + } + + cell_info->id.name[JAILHOUSE_CELL_ID_NAMELEN] =3D 0; + VIR_FREE(tmp); + + /* get cell state */ + cell_info->state =3D readSysfsCellString(id, "state"); + + /* get assigned cpu list */ + cell_info->cpus_assigned_list =3D + readSysfsCellString(id, "cpus_assigned_list"); + + /* get failed cpu list */ + cell_info->cpus_failed_list =3D + 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 =3D + scandir(JAILHOUSE_CELLS, &namelist, cell_match, alphasort); + if (num_entries =3D=3D -1) { + if (errno =3D=3D 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] =3D NULL; + + for (i =3D 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 =3D -1; + VIR_AUTOCLOSE fd =3D -1; + + fd =3D openDev(); + + err =3D 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_UNUSE= D) +{ + + /* 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 + * . + */ + +#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_dri= ver.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 * . + * */ =20 #include +#include =20 +#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 +#include "virpidfile.h" =20 -#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 =3D virObjectNew(virJailhouseDriverConfigClass))) + return NULL; + + cfg->stateDir =3D g_strdup(JAILHOUSE_STATE_DIR); + + cfg->sys_config_file_path =3D g_strdup(DATADIR "/jailhouse/system.cell= "); + + cfg->cell_config_dir =3D g_strdup(DATADIR "/jailhouse/cells"); + + return cfg; +} + +static void virJailhouseDriverConfigDispose(void *obj) +{ + + virJailhouseDriverConfigPtr cfg =3D 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 =3D NULL; + + if (!virFileExists(JAILHOUSE_CONFIG_FILE)) + return 0; + + if (!(conf =3D 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) =3D=3D 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 =3D getJailhouseCellsInfo(); + + return 0; +} + +static void +jailhouseFreeDriver(virJailhouseDriverPtr driver) +{ + if (!driver) + return; + + virMutexDestroy(&driver->lock); + virObjectUnref(driver->config); + VIR_FREE(driver); +} =20 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 =3D geteuid(); + + virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); + + if (!virConnectValidateURIPath(conn->uri->path, "jailhouse", uid =3D= =3D 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 =3D jailhouse_driver; + + return VIR_DRV_OPEN_SUCCESS; } =20 +#define UNUSED(x) (void)(x) + static int jailhouseConnectClose(virConnectPtr conn) { - UNUSED(conn); + conn->privateData =3D NULL; + + return 0; +} + +static int +jailhouseStateCleanup(void) +{ + if (!jailhouse_driver) + return -1; + + if (jailhouse_driver->lockFD !=3D -1) + virPidFileRelease(jailhouse_driver->config->stateDir, + "driver", jailhouse_driver->lockFD); + + virMutexDestroy(&jailhouse_driver->lock); + + jailhouseFreeDriver(jailhouse_driver); return 0; } =20 +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 =3D NULL; + int rc; + + jailhouse_driver =3D g_new0(virJailhouseDriver, 1); + jailhouse_driver->lockFD =3D -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 =3D virJailhouseDriverConfigNew())) + goto error; + + jailhouse_driver->config =3D 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 =3D virPidFileAcquire(cfg->stateDir, + "driver", false, get= pid())) < 0) + goto error; + + if ((rc =3D jailhouseEnable(cfg->sys_config_file_path)) < 0) + goto error; + else if (rc =3D=3D 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) } =20 static int -jailhouseNodeGetInfo(virConnectPtr conn, - virNodeInfoPtr info) +jailhouseNodeGetInfo(virConnectPtr conn, virNodeInfoPtr info) { UNUSED(conn); UNUSED(info); return -1; } =20 -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, } =20 static virDomainPtr -jailhouseDomainLookupByID(virConnectPtr conn, - int id) +jailhouseDomainLookupByID(virConnectPtr conn, int id) { UNUSED(conn); UNUSED(id); @@ -116,8 +280,7 @@ jailhouseDomainLookupByID(virConnectPtr conn, } =20 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, } =20 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) } =20 static int -jailhouseDomainGetInfo(virDomainPtr domain, - virDomainInfoPtr info) +jailhouseDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info) { UNUSED(domain); UNUSED(info); @@ -167,9 +328,7 @@ jailhouseDomainGetInfo(virDomainPtr domain, =20 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, } =20 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, =20 static virHypervisorDriver jailhouseHypervisorDriver =3D { .name =3D "JAILHOUSE", - .connectOpen =3D jailhouseConnectOpen, /* 6.3.0 */ - .connectClose =3D jailhouseConnectClose, /* 6.3.0 */ - .connectListDomains =3D jailhouseConnectListDomains, /* 6.3.0 */ - .connectNumOfDomains =3D jailhouseConnectNumOfDomains, /* 6.3.0 */ - .connectListAllDomains =3D jailhouseConnectListAllDomains, /* 6.3.0 */ - .domainLookupByID =3D jailhouseDomainLookupByID, /* 6.3.0 */ - .domainLookupByUUID =3D jailhouseDomainLookupByUUID, /* 6.3.0 */ - .domainLookupByName =3D jailhouseDomainLookupByName, /* 6.3.0 */ - .domainGetXMLDesc =3D jailhouseDomainGetXMLDesc, /* 6.3.0 */ - .domainCreate =3D jailhouseDomainCreate, /* 6.3.0 */ - .connectGetType =3D jailhouseConnectGetType, /* 6.3.0 */ - .connectGetHostname =3D jailhouseConnectGetHostname, /* 6.3.0 */ - .nodeGetInfo =3D jailhouseNodeGetInfo, /* 6.3.0 */ - .domainShutdown =3D jailhouseDomainShutdown, /* 6.3.0 */ - .domainDestroy =3D jailhouseDomainDestroy, /* 6.3.0 */ - .domainGetInfo =3D jailhouseDomainGetInfo, /* 6.3.0 */ - .domainGetState =3D jailhouseDomainGetState, /* 6.3.0 */ + .connectOpen =3D jailhouseConnectOpen, /* 6.3.0 */ + .connectClose =3D jailhouseConnectClose, /* 6.3.0 */ + .connectListAllDomains =3D jailhouseConnectListAllDomains, /* 6.3.0= */ + .domainLookupByID =3D jailhouseDomainLookupByID, /* 6.3.0 */ + .domainLookupByUUID =3D jailhouseDomainLookupByUUID, /* 6.3.0 */ + .domainLookupByName =3D jailhouseDomainLookupByName, /* 6.3.0 */ + .domainGetXMLDesc =3D jailhouseDomainGetXMLDesc, /* 6.3.0 */ + .domainCreate =3D jailhouseDomainCreate, /* 6.3.0 */ + .connectGetType =3D jailhouseConnectGetType, /* 6.3.0 */ + .connectGetHostname =3D jailhouseConnectGetHostname, /* 6.3.0 */ + .nodeGetInfo =3D jailhouseNodeGetInfo, /* 6.3.0 */ + .domainShutdown =3D jailhouseDomainShutdown, /* 6.3.0 */ + .domainDestroy =3D jailhouseDomainDestroy, /* 6.3.0 */ + .domainGetInfo =3D jailhouseDomainGetInfo, /* 6.3.0 */ + .domainGetState =3D jailhouseDomainGetState, /* 6.3.0 */ }; =20 + static virConnectDriver jailhouseConnectDriver =3D { + .localOnly =3D true, + .uriSchemes =3D (const char *[]){ "jailhouse", NULL }, .hypervisorDriver =3D &jailhouseHypervisorDriver, }; =20 + +static virStateDriver jailhouseStateDriver =3D { + .name =3D "JAILHOUSE", + .stateInitialize =3D jailhouseStateInitialize, + .stateCleanup =3D 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_dri= ver.h index b0dbc8d033..8a0e111676 100644 --- a/src/jailhouse/jailhouse_driver.h +++ b/src/jailhouse/jailhouse_driver.h @@ -20,4 +20,55 @@ =20 #pragma once =20 +#include + +#include "jailhouse_api.h" + int jailhouseRegister(void); + +#define JAILHOUSE_CONFIG_FILE SYSCONFDIR "/libvirt/jailhouse/jailhouse.con= f" +#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 ro= ot */ + 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 =3D files( 'jailhouse_driver.c', + 'jailhouse_api.c', ) =20 driver_source_files +=3D jailhouse_sources diff --git a/src/libvirt.c b/src/libvirt.c index 8a78cbcf3a..0748eb2352 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" =20 #define VIR_FROM_THIS VIR_FROM_NONE @@ -274,10 +271,6 @@ virGlobalInit(void) if (hypervRegister() =3D=3D -1) goto error; #endif -#ifdef WITH_JAILHOUSE - if (jailhouseRegister() =3D=3D -1) - goto error; -#endif #ifdef WITH_REMOTE if (remoteRegister() =3D=3D -1) goto error; @@ -1052,9 +1045,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 2ac4f6cd2e..cbfdebfd7a 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_GN= UC_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 dri= vers"); if (getuid() =3D=3D 0) { priv->interfaceURI =3D "interface:///system"; --=20 2.26.2 From nobody Mon Apr 29 23:31:06 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1600356268; cv=none; d=zohomail.com; s=zohoarc; b=imoj5Rdcv3EfdL0z/Bu5YziAwS5JmlEFy1x8oiDioLX1K+TUydZkgmXPrmurdtZjcQkGbhFctJK6oackGWvIaM4NMMjIwXgql0z7gWLdM2ayuu0WziEDBBXVz0nH3KCPEnnpGQz12i6qja3Vg6gBaMUL3QQvVT4SpPKzu/poQdM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600356268; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=dBqUncYJq3Nem9df1Ye7sWxuagERFqN117v8gkDeH+I=; b=hvWRXRZ7oRDK1RrNPw+B92FkFWJCQnHJDLJ40ZU1yLB7aGvF3c3gXme9F2qmzFCeyIheQyw1KVolmIEb5gcBihAyusvNCsgH5yUZVZPKeU/8qWjdvOGWxVWv6tehN+rp5Z0YtXydecVMMoVO2L2EYVFuDHtJdodh1rHqWh10ltY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1600356268968442.8074343429438; Thu, 17 Sep 2020 08:24:28 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-16-usnSpdddN5-uvCN5MurEQw-1; Thu, 17 Sep 2020 11:24:23 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2239564098; Thu, 17 Sep 2020 15:24:18 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id F17EC73665; Thu, 17 Sep 2020 15:24:17 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id B2A71183D04C; Thu, 17 Sep 2020 15:24:17 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 08HFO8Ee017786 for ; Thu, 17 Sep 2020 11:24:08 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7DF4960CC0; Thu, 17 Sep 2020 15:24:08 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-114-29.ams2.redhat.com [10.36.114.29]) by smtp.corp.redhat.com (Postfix) with ESMTP id B6ADD610F2; Thu, 17 Sep 2020 15:24:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600356267; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=dBqUncYJq3Nem9df1Ye7sWxuagERFqN117v8gkDeH+I=; b=JROmyVxCJLu7FhKQg0CM/WrOKy48+0clPtwuPhz3e44OclgsFItmHjmgIMOkNan1fK41hg ncy5RayWOJE8xmW05sVUzZCPk7lelYj8Ah4m43SqlLKU4Tn2LxffLgA8fNDfpLdOkYVCni lGUOWMOH0uxb22F+gZjuxL9XBloo2IQ= X-MC-Unique: usnSpdddN5-uvCN5MurEQw-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Subject: [libvirt PATCH 3/9] Jailhouse driver: Implementation of ConnectGetType Date: Thu, 17 Sep 2020 16:23:53 +0100 Message-Id: <20200917152359.1621763-4-berrange@redhat.com> In-Reply-To: <20200917152359.1621763-1-berrange@redhat.com> References: <20200917152359.1621763-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Cc: Prakhar Bansal X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: 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_dri= ver.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" =20 #define VIR_FROM_THIS VIR_FROM_JAILHOUSE =20 @@ -241,16 +243,19 @@ jailhouseStateInitialize(bool privileged G_GNUC_UNUSE= D, static const char * jailhouseConnectGetType(virConnectPtr conn) { - UNUSED(conn); - return NULL; + if (virConnectGetTypeEnsureACL(conn) < 0) + return NULL; =20 + return "JAILHOUSE"; } =20 static char * jailhouseConnectGetHostname(virConnectPtr conn) { - UNUSED(conn); - return NULL; + if (virConnectGetHostnameEnsureACL(conn) < 0) + return NULL; + + return virGetHostname(); } =20 static int @@ -263,7 +268,7 @@ jailhouseNodeGetInfo(virConnectPtr conn, virNodeInfoPtr= info) =20 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; - } =20 static int @@ -350,18 +354,18 @@ static virHypervisorDriver jailhouseHypervisorDriver = =3D { .connectOpen =3D jailhouseConnectOpen, /* 6.3.0 */ .connectClose =3D jailhouseConnectClose, /* 6.3.0 */ .connectListAllDomains =3D jailhouseConnectListAllDomains, /* 6.3.0= */ - .domainLookupByID =3D jailhouseDomainLookupByID, /* 6.3.0 */ - .domainLookupByUUID =3D jailhouseDomainLookupByUUID, /* 6.3.0 */ - .domainLookupByName =3D jailhouseDomainLookupByName, /* 6.3.0 */ - .domainGetXMLDesc =3D jailhouseDomainGetXMLDesc, /* 6.3.0 */ - .domainCreate =3D jailhouseDomainCreate, /* 6.3.0 */ .connectGetType =3D jailhouseConnectGetType, /* 6.3.0 */ .connectGetHostname =3D jailhouseConnectGetHostname, /* 6.3.0 */ - .nodeGetInfo =3D jailhouseNodeGetInfo, /* 6.3.0 */ + .domainCreate =3D jailhouseDomainCreate, /* 6.3.0 */ .domainShutdown =3D jailhouseDomainShutdown, /* 6.3.0 */ .domainDestroy =3D jailhouseDomainDestroy, /* 6.3.0 */ .domainGetInfo =3D jailhouseDomainGetInfo, /* 6.3.0 */ .domainGetState =3D jailhouseDomainGetState, /* 6.3.0 */ + .domainLookupByID =3D jailhouseDomainLookupByID, /* 6.3.0 */ + .domainLookupByUUID =3D jailhouseDomainLookupByUUID, /* 6.3.0 */ + .domainLookupByName =3D jailhouseDomainLookupByName, /* 6.3.0 */ + .domainGetXMLDesc =3D jailhouseDomainGetXMLDesc, /* 6.3.0 */ + .nodeGetInfo =3D jailhouseNodeGetInfo, /* 6.3.0 */ }; =20 =20 --=20 2.26.2 From nobody Mon Apr 29 23:31:06 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) client-ip=207.211.31.81; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1600356271; cv=none; d=zohomail.com; s=zohoarc; b=imoJY8iYnMmHkOG1r1Yhmma2cT4bRSL9tWGGJHcEBHRomGBDRE79bt333qBGp2fHm3GgxqBe0RMdvnOB6weXlAmmg8tYzSs1BFNp9FQeuoKauWN1BZdiMjbmr2iNJW9u8Bp4ttb0u+PViWKgBs9Ihsw4pQr+FCYg2vXmeUpcYg8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600356271; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=RgcyuJAviLpFZCOyWmtx3X4/NJMX2LhI1dRa3U3YFIc=; b=I5kf8fnLnYPUNysBFb4wEjBNIJeTYHkelx7/j9xKHnspLnxddLLIdPtJ+Tu0thIhhpx4hodshU9f9q3lmSxYqQ8+NiEPn2iyEcPT+4C0tpKoMylL3WWUrzBQ5+IIki5rxKw6CiZGknvJKU24BxnFdirCvvAiWzgmteXsE3Jb3Jg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 1600356271660893.7841935870462; Thu, 17 Sep 2020 08:24:31 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-333-RGpO3-PZMlyX1HXzetPUMw-1; Thu, 17 Sep 2020 11:24:27 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C31FE64090; Thu, 17 Sep 2020 15:24:20 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 92C5219D7C; Thu, 17 Sep 2020 15:24:20 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 5E03D8C7D5; Thu, 17 Sep 2020 15:24:20 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 08HFO9BQ017794 for ; Thu, 17 Sep 2020 11:24:09 -0400 Received: by smtp.corp.redhat.com (Postfix) id D8983610F2; Thu, 17 Sep 2020 15:24:09 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-114-29.ams2.redhat.com [10.36.114.29]) by smtp.corp.redhat.com (Postfix) with ESMTP id CB2AA60CC0; Thu, 17 Sep 2020 15:24:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600356270; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=RgcyuJAviLpFZCOyWmtx3X4/NJMX2LhI1dRa3U3YFIc=; b=BHkqrIlICRaCHVfKxWw59O1/RSUYsCQ4chkuqeeNzh8MHBejV2fCp77PSF+nt9xIzFGINu IXnyyXN7uTUsuKM6II7KclTn3yfJyKg24XDxYtUUd5u5EhdZjnofZLoTGyG5B3Epq+yqrk y4on4xLgP6yf/L//IPeuIeD5bzzrLss= X-MC-Unique: RGpO3-PZMlyX1HXzetPUMw-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Subject: [libvirt PATCH 4/9] Jailhouse driver: Implementation of DomainCreate* callbacks Date: Thu, 17 Sep 2020 16:23:54 +0100 Message-Id: <20200917152359.1621763-5-berrange@redhat.com> In-Reply-To: <20200917152359.1621763-1-berrange@redhat.com> References: <20200917152359.1621763-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Cc: Prakhar Bansal X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Prakhar Bansal Implemented Jailhouse hypervisor APIs for cell load/start/shutdown/destroy. --- src/jailhouse/jailhouse_api.c | 100 ++++++++++++-- src/jailhouse/jailhouse_api.h | 29 +++++ src/jailhouse/jailhouse_driver.c | 217 +++++++++++++++++++++++++++++-- src/jailhouse/jailhouse_driver.h | 8 ++ 4 files changed, 335 insertions(+), 19 deletions(-) diff --git a/src/jailhouse/jailhouse_api.c b/src/jailhouse/jailhouse_api.c index cda00b50e7..783903e939 100644 --- a/src/jailhouse/jailhouse_api.c +++ b/src/jailhouse/jailhouse_api.c @@ -43,11 +43,14 @@ #define JAILHOUSE_CELLS "/sys/devices/jailhouse/ce= lls" #define MAX_JAILHOUSE_SYS_CONFIG_FILE_SIZE 1024*1024 #define MAX_JAILHOUSE_CELL_CONFIG_FILE_SIZE 1024 +#define MAX_JAILHOUSE_CELL_IMAGE_FILE_SIZE 64*1024*1024 =20 =20 #define JAILHOUSE_ENABLE _IOW(0, 0, void *) #define JAILHOUSE_DISABLE _IO(0, 1) #define JAILHOUSE_CELL_CREATE _IOW(0, 2, virJailhouseCellCreate) +#define JAILHOUSE_CELL_LOAD _IOW(0, 3, virJailhouseCellLoad) +#define JAILHOUSE_CELL_START _IOW(0, 4, virJailhouseCellId) #define JAILHOUSE_CELL_DESTROY _IOW(0, 5, virJailhouseCellId) =20 #define VIR_FROM_THIS VIR_FROM_JAILHOUSE @@ -68,8 +71,6 @@ int cell_match(const struct dirent *dirent); =20 int createCell(const char *conf_file); =20 -int destroyCell(virJailhouseCellId cell_id); - int getCellInfo(const unsigned int id, virJailhouseCellInfoPtr * cell_info); =20 @@ -254,7 +255,7 @@ readSysfsCellString(const unsigned int id, const char *= entry) } =20 int -getCellInfo(const unsigned int id, virJailhouseCellInfoPtr * cell_info_ptr) +getCellInfo(const unsigned int id, virJailhouseCellInfoPtr *cell_info_ptr) { char *tmp; =20 @@ -345,28 +346,105 @@ getJailhouseCellsInfo(void) } =20 int -destroyCell(virJailhouseCellId cell_id) +loadImagesInCell(virJailhouseCellId cell_id, char **images, int num_images) +{ + virJailhousePreloadImagePtr image; + virJailhouseCellLoadPtr cell_load; + g_autofree char *buffer =3D NULL; + unsigned int n; + int len =3D -1, err =3D -1; + VIR_AUTOCLOSE fd =3D -1; + + + if (VIR_ALLOC(cell_load) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + "%s", + _("Insufficient memory for cell load")); + return -1; + } + + + if (VIR_ALLOC_N(cell_load->image, num_images) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + "%s", + _("Insufficient memory for cell load images")); + return -1; + } + + cell_load->id =3D cell_id; + cell_load->num_preload_images =3D num_images; + + for (n =3D 0, image =3D cell_load->image; n < num_images; n++, image++)= { + len =3D virFileReadAll(images[n], MAX_JAILHOUSE_CELL_IMAGE_FILE_SI= ZE, &buffer); + if (len < 0 || !buffer) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("Failed to read the image file %s"), + images[n]); + return -1; + } + + image->source_address =3D (unsigned long)buffer; + image->size =3D len; + + // TODO(Prakhar): Add support for target address. + image->target_address =3D 0; + } + + fd =3D openDev(); + + err =3D ioctl(fd, JAILHOUSE_CELL_LOAD, cell_load); + if (err) { + virReportSystemError(errno, + _("Loading cell images for %d failed"), + cell_id.id); + return -1; + } + + return 0; +} + +int +shutdownCell(virJailhouseCellId cell_id) +{ + // Loading 0 images in the cell causes cell to shutdown. + return loadImagesInCell(cell_id, NULL, 0); +} + +int +startCell(virJailhouseCellId cell_id) { int err =3D -1; VIR_AUTOCLOSE fd =3D -1; =20 fd =3D openDev(); =20 - err =3D ioctl(fd, JAILHOUSE_CELL_DESTROY, &cell_id); - if (err) + err =3D ioctl(fd, JAILHOUSE_CELL_START, &cell_id); + if (err) { virReportSystemError(errno, - _("Destroying cell %d failed"), + _("Start cell %d failed"), cell_id.id); + return -1; + } =20 - return err; + return 0; } =20 int -destroyJailhouseCells(virJailhouseCellInfoPtr *cell_info_list G_GNUC_UNUSE= D) +destroyCell(virJailhouseCellId cell_id) { + int err =3D -1; + VIR_AUTOCLOSE fd =3D -1; + + fd =3D openDev(); =20 - /* Iterate over all cells in cell_info_list and destroy each cell */ - // TODO: Not implemented yet. + err =3D ioctl(fd, JAILHOUSE_CELL_DESTROY, &cell_id); + if (err) { + virReportSystemError(errno, + _("Destroying cell %d failed"), + cell_id.id); + + return -1; + } =20 return 0; } diff --git a/src/jailhouse/jailhouse_api.h b/src/jailhouse/jailhouse_api.h index 8362cb3d0f..ba39a4c8b7 100644 --- a/src/jailhouse/jailhouse_api.h +++ b/src/jailhouse/jailhouse_api.h @@ -48,6 +48,27 @@ struct _virJailhouseCellCreate { __u32 padding; }; =20 +typedef struct _virJailhousePreloadImage virJailhousePreloadImage; +typedef virJailhousePreloadImage *virJailhousePreloadImagePtr; + +struct _virJailhousePreloadImage { + __u64 source_address; + __u64 size; + __u64 target_address; + __u64 padding; +}; + +typedef struct _virJailhouseCellLoad virJailhouseCellLoad; +typedef virJailhouseCellLoad *virJailhouseCellLoadPtr; + +struct _virJailhouseCellLoad { + struct _virJailhouseCellId id; + __u32 num_preload_images; + __u32 padding; + struct _virJailhousePreloadImage image[]; +}; + + // Enables the Jailhouse hypervisor by reading the hypervisor system // configuration from the given file and calls the ioctl API to // enable the hypervisor. @@ -62,6 +83,14 @@ int jailhouseDisable(void); // provided in the dir_name. int createJailhouseCells(const char *dir_path); =20 +int loadImagesInCell(virJailhouseCellId cell_id, char **images, int num_im= ages); + +int startCell(virJailhouseCellId cell_id); + +int shutdownCell(virJailhouseCellId cell_id); + +int destroyCell(virJailhouseCellId cell_id); + // Destroys Jailhouse cells using the cell IDs provided in // the cell_info_list. int destroyJailhouseCells(virJailhouseCellInfoPtr *cell_info_list); diff --git a/src/jailhouse/jailhouse_driver.c b/src/jailhouse/jailhouse_dri= ver.c index 75bf41fc11..5b7bdc92d8 100644 --- a/src/jailhouse/jailhouse_driver.c +++ b/src/jailhouse/jailhouse_driver.c @@ -25,7 +25,6 @@ #include "configmake.h" #include "datatypes.h" #include "domain_conf.h" -#include "jailhouse_driver.h" #include "virtypedparam.h" #include "virerror.h" #include "virstring.h" @@ -36,6 +35,9 @@ #include "vircommand.h" #include "virpidfile.h" #include "access/viraccessapicheck.h" +#include "virdomainobjlist.h" + +#include "jailhouse_driver.h" =20 #define VIR_FROM_THIS VIR_FROM_JAILHOUSE =20 @@ -62,7 +64,6 @@ virJailhouseDriverConfigNew(void) { virJailhouseDriverConfigPtr cfg; =20 - // TODO: Check if the following has to be uncommented. if (virJailhouseConfigInitialize() < 0) return NULL; =20 @@ -135,6 +136,7 @@ jailhouseFreeDriver(virJailhouseDriverPtr driver) return; =20 virMutexDestroy(&driver->lock); + virObjectUnref(driver->domains); virObjectUnref(driver->config); VIR_FREE(driver); } @@ -207,6 +209,9 @@ jailhouseStateInitialize(bool privileged G_GNUC_UNUSED, return VIR_DRV_STATE_INIT_ERROR; } =20 + if (!(jailhouse_driver->domains =3D virDomainObjListNew())) + goto error; + if (!(cfg =3D virJailhouseDriverConfigNew())) goto error; =20 @@ -259,10 +264,11 @@ jailhouseConnectGetHostname(virConnectPtr conn) } =20 static int -jailhouseNodeGetInfo(virConnectPtr conn, virNodeInfoPtr info) +jailhouseNodeGetInfo(virConnectPtr conn, + virNodeInfoPtr nodeinfo) { UNUSED(conn); - UNUSED(info); + UNUSED(nodeinfo); return -1; } =20 @@ -300,11 +306,205 @@ jailhouseDomainLookupByUUID(virConnectPtr conn, cons= t unsigned char *uuid) return NULL; } =20 +static virDomainObjPtr +virJailhouseDomObjFromDomain(virDomainPtr domain) +{ + virDomainObjPtr cell; + virJailhouseDriverPtr driver =3D domain->conn->privateData; + char uuidstr[VIR_UUID_STRING_BUFLEN]; + + cell =3D virDomainObjListFindByUUID(driver->domains, domain->uuid); + if (!cell) { + virUUIDFormat(domain->uuid, uuidstr); + virReportError(VIR_ERR_NO_DOMAIN, + _("no domain with matching uuid '%s' (%s)"), + uuidstr, domain->name); + return NULL; + } + + return cell; +} + + + +static virJailhouseCellInfoPtr +virJailhouseFindCellByName(virJailhouseDriverPtr driver, + char* name) +{ + virJailhouseCellInfoPtr *cell =3D driver->cell_info_list; + + while (*cell) { + if (STRCASEEQ((*cell)->id.name, name)) + return *cell; + cell++; + } + + return NULL; +} + +static int +jailhouseDomainCreateWithFlags(virDomainPtr domain, + unsigned int flags) +{ + virJailhouseDriverPtr driver =3D domain->conn->privateData; + virDomainObjPtr cell; + virJailhouseCellInfoPtr cell_info; + int ret =3D -1; + + virCheckFlags(VIR_DOMAIN_NONE, -1); + + if (!domain->name) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Error while reading the domain name")); + goto cleanup; + } + + if (!domain->id) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Error while reading the domain ID")); + goto cleanup; + } + + if (!(cell =3D virJailhouseDomObjFromDomain(domain))) + goto cleanup; + + if (virDomainCreateWithFlagsEnsureACL(domain->conn, cell->def) < 0) + goto cleanup; + + if (!(cell_info =3D virJailhouseFindCellByName(driver, cell->def->name= ))) { + virReportError(VIR_ERR_NO_DOMAIN, + _("no domain with matching name %s and ID %d)"), + cell->def->name, cell->def->id); + virDomainObjListRemove(driver->domains, cell); + goto cleanup; + } + + ret =3D 0; + + cleanup: + virDomainObjEndAPI(&cell); + return ret; + +} + static int jailhouseDomainCreate(virDomainPtr domain) { - UNUSED(domain); - return -1; + return jailhouseDomainCreateWithFlags(domain, 0); +} + +static virDomainPtr +jailhouseDomainCreateXML(virConnectPtr conn, + const char *xml, + unsigned int flags) +{ + virJailhouseDriverPtr driver =3D conn->privateData; + virJailhouseCellInfoPtr cell_info; + virDomainPtr dom =3D NULL; + virDomainDefPtr def =3D NULL; + virDomainObjPtr cell =3D NULL; + virDomainDiskDefPtr disk =3D NULL; + virJailhouseCellId cell_id; + char **images =3D NULL; + int num_images =3D 0, i =3D 0; + unsigned int parse_flags =3D VIR_DOMAIN_DEF_PARSE_INACTIVE; + + if (flags & VIR_DOMAIN_START_VALIDATE) + parse_flags |=3D VIR_DOMAIN_DEF_PARSE_VALIDATE_SCHEMA; + + if ((def =3D virDomainDefParseString(xml, NULL, + NULL, parse_flags)) =3D=3D NULL) + goto cleanup; + + if ((cell =3D virDomainObjListFindByUUID(driver->domains, def->uuid))) + goto cleanup; + + if (virDomainCreateXMLEnsureACL(conn, def) < 0) + goto cleanup; + + if (!(cell_info =3D virJailhouseFindCellByName(driver, def->name))) { + virReportError(VIR_ERR_OPERATION_INVALID, + _("cell info for %s not found"), + def->name); + goto cleanup; + } + + // Assign cell Id to the domain. + def->id =3D cell_info->id.id; + + if (!(cell =3D virDomainObjListAdd(driver->domains, def, + NULL, + VIR_DOMAIN_OBJ_LIST_ADD_LIVE | + VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE, NUL= L))) + goto cleanup; + + def =3D NULL; + + if (cell->def->ndisks < 1) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Domain XML doesn't contain any disk images")); + goto cleanup; + } + + if (VIR_ALLOC_N(images, cell->def->ndisks) < 0) + goto cleanup; + + for (i =3D 0; i < cell->def->ndisks; ++i) { + images[i] =3D NULL; + + if (cell->def->disks[i]->device =3D=3D VIR_DOMAIN_DISK_DEVICE_DISK= && + virDomainDiskGetType(cell->def->disks[i]) =3D=3D VIR_STORAGE_T= YPE_FILE) { + disk =3D cell->def->disks[i]; + const char *src =3D virDomainDiskGetSource(disk); + if (!src) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("First file-based harddisk has no source"= )); + goto cleanup; + } + + images[i] =3D (char *)src; + num_images++; + } else { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("A Jailhouse doamin(cell) can ONLY have FILE = type disks")); + goto cleanup; + } + } + + // Initialize the cell_id. + cell_id.id =3D cell->def->id; + cell_id.padding =3D 0; + if (virStrncpy(cell_id.name, cell->def->name, JAILHOUSE_CELL_ID_NAMELE= N, JAILHOUSE_CELL_ID_NAMELEN) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Cell name %s length exceeded the limit"), + cell->def->name); + goto cleanup; + } + + if (loadImagesInCell(cell_id, images, num_images) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Failed to load images in the Cell %s"), + cell->def->name); + goto cleanup; + } + + VIR_DEBUG("Starting the domain..."); + + if (startCell(cell_id) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Failed to start the Cell %s"), + cell->def->name); + goto cleanup; + } + + virDomainObjSetState(cell, VIR_DOMAIN_RUNNING, VIR_DOMAIN_RUNNING_BOOT= ED); + + dom =3D virGetDomain(conn, cell->def->name, cell->def->uuid, cell->def= ->id); + + cleanup: + virDomainDefFree(def); + virDomainObjEndAPI(&cell); + return dom; } =20 static int @@ -314,7 +514,6 @@ jailhouseDomainShutdown(virDomainPtr domain) return -1; } =20 - static int jailhouseDomainDestroy(virDomainPtr domain) { @@ -356,7 +555,9 @@ static virHypervisorDriver jailhouseHypervisorDriver = =3D { .connectListAllDomains =3D jailhouseConnectListAllDomains, /* 6.3.0= */ .connectGetType =3D jailhouseConnectGetType, /* 6.3.0 */ .connectGetHostname =3D jailhouseConnectGetHostname, /* 6.3.0 */ - .domainCreate =3D jailhouseDomainCreate, /* 6.3.0 */ + .domainCreate =3D jailhouseDomainCreate, /*6.3.0 */ + .domainCreateWithFlags =3D jailhouseDomainCreateWithFlags, /* 6.3.0= */ + .domainCreateXML =3D jailhouseDomainCreateXML, /* 6.3.0 */ .domainShutdown =3D jailhouseDomainShutdown, /* 6.3.0 */ .domainDestroy =3D jailhouseDomainDestroy, /* 6.3.0 */ .domainGetInfo =3D jailhouseDomainGetInfo, /* 6.3.0 */ diff --git a/src/jailhouse/jailhouse_driver.h b/src/jailhouse/jailhouse_dri= ver.h index 8a0e111676..8fc99fe7d2 100644 --- a/src/jailhouse/jailhouse_driver.h +++ b/src/jailhouse/jailhouse_driver.h @@ -22,7 +22,9 @@ =20 #include =20 +#include "domain_event.h" #include "jailhouse_api.h" +#include "virdomainobjlist.h" =20 int jailhouseRegister(void); =20 @@ -64,6 +66,12 @@ struct _virJailhouseDriver { =20 // All the cells created during connect open on the hypervisor. virJailhouseCellInfoPtr *cell_info_list; + + // XML options for domain XMLs. + virDomainXMLOptionPtr xmlopt; + virDomainObjListPtr domains; + + virObjectEventStatePtr domainEventState; }; =20 struct _jailhouseCell { --=20 2.26.2 From nobody Mon Apr 29 23:31:06 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) client-ip=207.211.31.81; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1600356266; cv=none; d=zohomail.com; s=zohoarc; b=Qd9L5CxgSvN5dzVGUVzjlU0bzwtAYqvOCgPCyMGaaapui6s4QUIRCUjv39kW7s2R6YuYSBVmZsYZwDIBU+9tAn/KA+8zJIcs8t0/vbq46cYA18Fmr8Hxe8TypMf7w5rXgL8X85EBwUR32ICQORV+2SWb34n2d0Od8+5RWzIyFBE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600356266; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=NCZQFi2Y9KyApSRZU7ayfbPJ1vZYnN49LzcceRnWyug=; b=hkFQ/mOTghPFj1H1xGHXUf1pHi5t/acpbFx/x+I+PJBzOE+4QUFDO6RJxDbJaIsP7pcu1PdcwYyLx4EFfafAyIp12gqW1jAwEGHJvlh2Uod50wbVujhinr637Y4VWg4upmjd9ugDyJduYK9hsQVR/Ef5AQHOAdW0Mx4X8fqEXsA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 1600356266108796.3491872006872; Thu, 17 Sep 2020 08:24:26 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-199-hvJuMQnlNFWjnVQfd1031Q-1; Thu, 17 Sep 2020 11:24:21 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D1DAF8BF133; Thu, 17 Sep 2020 15:24:15 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AC28855764; Thu, 17 Sep 2020 15:24:15 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 75DC3183D048; Thu, 17 Sep 2020 15:24:15 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 08HFOEa9017829 for ; Thu, 17 Sep 2020 11:24:14 -0400 Received: by smtp.corp.redhat.com (Postfix) id 0D2AE60CC0; Thu, 17 Sep 2020 15:24:14 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-114-29.ams2.redhat.com [10.36.114.29]) by smtp.corp.redhat.com (Postfix) with ESMTP id 08B9C1F2; Thu, 17 Sep 2020 15:24:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600356265; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=NCZQFi2Y9KyApSRZU7ayfbPJ1vZYnN49LzcceRnWyug=; b=ObcblEbOf1K6NE4EmATWr69xQSmyK7H0pjCX/wZsH3ccrUByb8gpIO1BDrqiRnKmpeyX21 +3QzmIC6RAzCqz3oXfuY+KyKQ09vjvNzD1EZno2AQdRxzBhu3EC12A1ULwCvCwSQoudOcl 6/B7U242nCd7w5Koy/Yq22ezVGcNOEI= X-MC-Unique: hvJuMQnlNFWjnVQfd1031Q-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Subject: [libvirt PATCH 5/9] Jailhouse driver: Implementation of DomainInfo/State/List Date: Thu, 17 Sep 2020 16:23:55 +0100 Message-Id: <20200917152359.1621763-6-berrange@redhat.com> In-Reply-To: <20200917152359.1621763-1-berrange@redhat.com> References: <20200917152359.1621763-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Cc: Prakhar Bansal X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Prakhar Bansal --- src/jailhouse/jailhouse_driver.c | 102 +++++++++++++++++++++++++------ 1 file changed, 83 insertions(+), 19 deletions(-) diff --git a/src/jailhouse/jailhouse_driver.c b/src/jailhouse/jailhouse_dri= ver.c index 5b7bdc92d8..2bb249f996 100644 --- a/src/jailhouse/jailhouse_driver.c +++ b/src/jailhouse/jailhouse_driver.c @@ -267,19 +267,26 @@ static int jailhouseNodeGetInfo(virConnectPtr conn, virNodeInfoPtr nodeinfo) { - UNUSED(conn); - UNUSED(nodeinfo); - return -1; + if (virNodeGetInfoEnsureACL(conn) < 0) + return -1; + + return virCapabilitiesGetNodeInfo(nodeinfo); } =20 static int jailhouseConnectListAllDomains(virConnectPtr conn, - virDomainPtr **domain, unsigned int flags) + virDomainPtr **domains, + unsigned int flags) { - UNUSED(conn); - UNUSED(domain); - UNUSED(flags); - return -1; + virJailhouseDriverPtr driver =3D conn->privateData; + + virCheckFlags(VIR_CONNECT_LIST_DOMAINS_FILTERS_ALL, -1); + + if (virConnectListAllDomainsEnsureACL(conn) < 0) + return -1; + + return virDomainObjListExport(driver->domains, conn, domains, + virConnectListAllDomainsCheckACL, flags); } =20 static virDomainPtr @@ -522,30 +529,87 @@ jailhouseDomainDestroy(virDomainPtr domain) } =20 static int -jailhouseDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info) +virjailhouseGetDomainTotalCpuStats(virDomainObjPtr cell, + unsigned long long *cpustats) { - UNUSED(domain); - UNUSED(info); + // TODO(Prakhar): Not implemented yet. + UNUSED(cell); + UNUSED(cpustats); return -1; } =20 +static int +jailhouseDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info) +{ + virDomainObjPtr cell; + int ret =3D -1; + + if (!(cell =3D virJailhouseDomObjFromDomain(domain))) + goto cleanup; + + if (virDomainGetInfoEnsureACL(domain->conn, cell->def) < 0) + goto cleanup; + + if (virDomainObjIsActive(cell)) { + if (virjailhouseGetDomainTotalCpuStats(cell, &(info->cpuTime)) < 0) + goto cleanup; + } else { + info->cpuTime =3D 0; + } + + info->state =3D virDomainObjGetState(cell, NULL); + info->maxMem =3D virDomainDefGetMemoryTotal(cell->def); + info->nrVirtCpu =3D virDomainDefGetVcpus(cell->def); + ret =3D 0; + + cleanup: + virDomainObjEndAPI(&cell); + return ret; +} + static int jailhouseDomainGetState(virDomainPtr domain, int *state, int *reason, unsigned int flags) { - UNUSED(domain); - UNUSED(state); - UNUSED(reason); - UNUSED(flags); - return -1; + virDomainObjPtr cell; + int ret =3D -1; + + virCheckFlags(0, -1); + + if (!(cell =3D virJailhouseDomObjFromDomain(domain))) + goto cleanup; + + if (virDomainGetStateEnsureACL(domain->conn, cell->def) < 0) + goto cleanup; + + *state =3D virDomainObjGetState(cell, reason); + ret =3D 0; + + cleanup: + virDomainObjEndAPI(&cell); + return ret; } =20 static char * jailhouseDomainGetXMLDesc(virDomainPtr domain, unsigned int flags) { - UNUSED(domain); - UNUSED(flags); - return NULL; + virDomainObjPtr cell; + char *ret =3D NULL; + + virCheckFlags(VIR_DOMAIN_XML_COMMON_FLAGS, NULL); + + if (!(cell =3D virJailhouseDomObjFromDomain(domain))) + goto cleanup; + + if (virDomainGetXMLDescEnsureACL(domain->conn, cell->def, flags) < 0) + goto cleanup; + + ret =3D virDomainDefFormat(cell->def, NULL /* xmlopt */, + virDomainDefFormatConvertXMLFlags(flags)); + + cleanup: + virDomainObjEndAPI(&cell); + return ret; } =20 static virHypervisorDriver jailhouseHypervisorDriver =3D { --=20 2.26.2 From nobody Mon Apr 29 23:31:06 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1600356275; cv=none; d=zohomail.com; s=zohoarc; b=LLcaBEP0qEHd+5GV5+ubXSxqH3+poBZyu2gfF9q2mwZuC5KOAhqbQc47js+EsvsDvoZDPjR3NcsfUwEvk0AODboaWizvsOAlbB9tiQPRl+vFRt2VB6y8f6T3/X37FMS7r2jeoLTPWerjdNW4xVyhsyamB5hksD4iwuzp+1nzzS0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600356275; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=bD2yZ83WbeHmAfqshCaEFpL4rySNoqgjCVeQWdnT3P4=; b=VHixmeqmpc0HtrA/emOUI1uF8QZWxKpoM7tdlP8QX6U060HcupicCMNnPuLs3pcaekWUhDOHOyqJACVO0187FvLltO8jXFo54pdrcjc62DV1C7JK37B1trKeEcuqIiNJouy4V0tjT82ZHpxz8XcBrpPNy6+B1rZRc0cnE7tM8fQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1600356275961570.6163862638772; Thu, 17 Sep 2020 08:24:35 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-158-R9rF5sD_OWmO7I298J3hfA-1; Thu, 17 Sep 2020 11:24:28 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 765E180EDB0; Thu, 17 Sep 2020 15:24:23 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 516CC55766; Thu, 17 Sep 2020 15:24:23 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 1A03A183D04E; Thu, 17 Sep 2020 15:24:23 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 08HFOHw6017856 for ; Thu, 17 Sep 2020 11:24:17 -0400 Received: by smtp.corp.redhat.com (Postfix) id 552D1610F2; Thu, 17 Sep 2020 15:24:17 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-114-29.ams2.redhat.com [10.36.114.29]) by smtp.corp.redhat.com (Postfix) with ESMTP id ABA52610F3; Thu, 17 Sep 2020 15:24:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600356274; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=bD2yZ83WbeHmAfqshCaEFpL4rySNoqgjCVeQWdnT3P4=; b=BUL3eI88bqYaqEErgQfsqXYlcWlH8JJBuOqUTNMEfGgTOCwNUSTJgDoBrilsrk7Kkj9p7f 1UV/NGxTZBVvppY+crM1Kwd6cd0lbLdrw+xcz7WgGbsg3KPin7wA+dgFFFgRuz184/WqJg HU24nYfyV/v/LhEETjbR9sTapgrc5DY= X-MC-Unique: R9rF5sD_OWmO7I298J3hfA-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Subject: [libvirt PATCH 6/9] Jailhouse driver: Implementation of DomainLookup* callbacks Date: Thu, 17 Sep 2020 16:23:56 +0100 Message-Id: <20200917152359.1621763-7-berrange@redhat.com> In-Reply-To: <20200917152359.1621763-1-berrange@redhat.com> References: <20200917152359.1621763-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Cc: Prakhar Bansal X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Prakhar Bansal --- src/jailhouse/jailhouse_driver.c | 70 ++++++++++++++++++++++++++++---- 1 file changed, 61 insertions(+), 9 deletions(-) diff --git a/src/jailhouse/jailhouse_driver.c b/src/jailhouse/jailhouse_dri= ver.c index 2bb249f996..8c84a23388 100644 --- a/src/jailhouse/jailhouse_driver.c +++ b/src/jailhouse/jailhouse_driver.c @@ -292,25 +292,77 @@ jailhouseConnectListAllDomains(virConnectPtr conn, static virDomainPtr jailhouseDomainLookupByID(virConnectPtr conn, int id) { - UNUSED(conn); - UNUSED(id); - return NULL; +virJailhouseDriverPtr driver =3D conn->privateData; + virDomainObjPtr cell; + virDomainPtr dom =3D NULL; + + cell =3D virDomainObjListFindByID(driver->domains, id); + + if (!cell) { + virReportError(VIR_ERR_NO_DOMAIN, + _("No domain with matching ID '%d'"), id); + goto cleanup; + } + + if (virDomainLookupByIDEnsureACL(conn, cell->def) < 0) + goto cleanup; + + dom =3D virGetDomain(conn, cell->def->name, cell->def->uuid, cell->def= ->id); + cleanup: + virDomainObjEndAPI(&cell); + return dom; } =20 static virDomainPtr jailhouseDomainLookupByName(virConnectPtr conn, const char *name) { - UNUSED(conn); - UNUSED(name); - return NULL; + virJailhouseDriverPtr driver =3D conn->privateData; + virDomainObjPtr cell; + virDomainPtr dom =3D NULL; + + cell =3D virDomainObjListFindByName(driver->domains, name); + + if (!cell) { + virReportError(VIR_ERR_NO_DOMAIN, + _("No domain with matching name '%s'"), name); + goto cleanup; + } + + if (virDomainLookupByNameEnsureACL(conn, cell->def) < 0) + goto cleanup; + + dom =3D virGetDomain(conn, cell->def->name, cell->def->uuid, cell->def= ->id); + + cleanup: + virDomainObjEndAPI(&cell); + return dom; } =20 static virDomainPtr jailhouseDomainLookupByUUID(virConnectPtr conn, const unsigned char *uuid) { - UNUSED(conn); - UNUSED(uuid); - return NULL; + virJailhouseDriverPtr driver =3D conn->privateData; + virDomainObjPtr cell; + virDomainPtr dom =3D NULL; + + cell =3D virDomainObjListFindByUUID(driver->domains, uuid); + + if (!cell) { + char uuidstr[VIR_UUID_STRING_BUFLEN]; + virUUIDFormat(uuid, uuidstr); + virReportError(VIR_ERR_NO_DOMAIN, + _("No domain with matching UUID '%s'"), uuidstr); + goto cleanup; + } + + if (virDomainLookupByUUIDEnsureACL(conn, cell->def) < 0) + goto cleanup; + + dom =3D virGetDomain(conn, cell->def->name, cell->def->uuid, cell->def= ->id); + + cleanup: + virDomainObjEndAPI(&cell); + return dom; } =20 static virDomainObjPtr --=20 2.26.2 From nobody Mon Apr 29 23:31:06 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) client-ip=207.211.31.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1600356309; cv=none; d=zohomail.com; s=zohoarc; b=H5zVQzSZDl37as4vdtW+09jZa/eXodb97uMIYhhUi7XvKxdGaiYzBfPU58O1b8Jo0dqKUskWAhkyF3Ko087/9R8tGLJyIUZmnFaFpydBtO3WwOk69DjTGS/kl4cQ8WuzxQvxQzOmCngtl53NsqTNJ0sOuTxnc5n9kSyHrQRJKuE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600356309; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=D2rz7yH9w8X0CNpMI37pCLT+2nZ7187aj8j0mCnIKbw=; b=n+HouFp+XPYUbmKnCNEF6wTXC8y4mQ4T/Bs2IO/y6NG3PzmXovVjZOW5o7GcS4vqV2lwv4K/NwYrfxEFXeBAPjJh7u2qUEbYj/JDGh1mKVR6au2W9wKDvUc2pDvfvU1aQp8/ajXuzPrvCbCKWEKcRRKcVQAInx+N1d40SU2719g= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by mx.zohomail.com with SMTPS id 1600356309794295.629610256659; Thu, 17 Sep 2020 08:25:09 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-3-THOf3INdNwCHeD04gZN7fg-1; Thu, 17 Sep 2020 11:24:32 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1721764089; Thu, 17 Sep 2020 15:24:27 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E8A573782; Thu, 17 Sep 2020 15:24:26 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id B561A44A79; Thu, 17 Sep 2020 15:24:26 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 08HFOOE6017874 for ; Thu, 17 Sep 2020 11:24:24 -0400 Received: by smtp.corp.redhat.com (Postfix) id E36BE60CC0; Thu, 17 Sep 2020 15:24:24 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-114-29.ams2.redhat.com [10.36.114.29]) by smtp.corp.redhat.com (Postfix) with ESMTP id 203EE1F2; Thu, 17 Sep 2020 15:24:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600356308; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=D2rz7yH9w8X0CNpMI37pCLT+2nZ7187aj8j0mCnIKbw=; b=SUVlSj6M955SXIa+ScRYhF5xcEBChXwPooqOQM/1Il7vltrlZ9y6jFajJKF5IcadrZsmrD 5BSqON/ibmQdhmrGE8bDd8X4G+TSz+b+EFXc7CPHdPduBfi0EcXmOS1QWHts2qYVTjAo6Q efF1isOGSjYO+wRR7QOTPHiKsYWxtgI= X-MC-Unique: THOf3INdNwCHeD04gZN7fg-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Subject: [libvirt PATCH 7/9] Jailhouse driver: Implementation of DomainShutdown/Destroy callbacks Date: Thu, 17 Sep 2020 16:23:57 +0100 Message-Id: <20200917152359.1621763-8-berrange@redhat.com> In-Reply-To: <20200917152359.1621763-1-berrange@redhat.com> References: <20200917152359.1621763-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Cc: Prakhar Bansal X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Prakhar Bansal --- src/jailhouse/jailhouse_api.c | 8 +++ src/jailhouse/jailhouse_driver.c | 101 +++++++++++++++++++++++++++++-- 2 files changed, 104 insertions(+), 5 deletions(-) diff --git a/src/jailhouse/jailhouse_api.c b/src/jailhouse/jailhouse_api.c index 783903e939..510e2f5f66 100644 --- a/src/jailhouse/jailhouse_api.c +++ b/src/jailhouse/jailhouse_api.c @@ -71,6 +71,14 @@ int cell_match(const struct dirent *dirent); =20 int createCell(const char *conf_file); =20 +int loadImagesInCell(virJailhouseCellId cell_id, char *images, int num_ima= ges); + +int shutdownCell(virJailhouseCellId cell_id); + +int startCell(virJailhouseCellId cell_id); + +int destroyCell(virJailhouseCellId cell_id); + int getCellInfo(const unsigned int id, virJailhouseCellInfoPtr * cell_info); =20 diff --git a/src/jailhouse/jailhouse_driver.c b/src/jailhouse/jailhouse_dri= ver.c index 8c84a23388..46c7759cb8 100644 --- a/src/jailhouse/jailhouse_driver.c +++ b/src/jailhouse/jailhouse_driver.c @@ -406,8 +406,8 @@ jailhouseDomainCreateWithFlags(virDomainPtr domain, unsigned int flags) { virJailhouseDriverPtr driver =3D domain->conn->privateData; - virDomainObjPtr cell; virJailhouseCellInfoPtr cell_info; + virDomainObjPtr cell; int ret =3D -1; =20 virCheckFlags(VIR_DOMAIN_NONE, -1); @@ -566,18 +566,107 @@ jailhouseDomainCreateXML(virConnectPtr conn, return dom; } =20 +static int +jailhouseDomainShutdownFlags(virDomainPtr domain, unsigned int flags) +{ + virJailhouseDriverPtr driver =3D domain->conn->privateData; + virJailhouseCellInfoPtr cell_info; + virDomainObjPtr cell; + virJailhouseCellId cell_id; + int ret =3D -1; + + virCheckFlags(0, -1); + + if (!(cell =3D virJailhouseDomObjFromDomain(domain))) + goto cleanup; + + if (virDomainShutdownFlagsEnsureACL(domain->conn, cell->def, flags) < = 0) + goto cleanup; + + if (virDomainObjGetState(cell, NULL) !=3D VIR_DOMAIN_RUNNING) + goto cleanup; + + if (!(cell_info =3D virJailhouseFindCellByName(driver, cell->def->name= ))) { + virReportError(VIR_ERR_NO_DOMAIN, + _("no domain with matching name %s and ID %d)"), + cell->def->name, cell->def->id); + virDomainObjListRemove(driver->domains, cell); + goto cleanup; + } + + // Initialize the cell_id. + cell_id.id =3D cell->def->id; + cell_id.padding =3D 0; + if (virStrcpy(cell_id.name, cell->def->name, JAILHOUSE_CELL_ID_NAMELEN= ) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Cell name %s length exceeded the limit"), + cell->def->name); + goto cleanup; + } + + if (shutdownCell(cell_id) < 0) + goto cleanup; + + virDomainObjSetState(cell, VIR_DOMAIN_SHUTOFF, VIR_DOMAIN_SHUTOFF_SHUT= DOWN); + + ret =3D 0; + + cleanup: + virDomainObjEndAPI(&cell); + return ret; +} + static int jailhouseDomainShutdown(virDomainPtr domain) { - UNUSED(domain); - return -1; + return jailhouseDomainShutdownFlags(domain, 0); +} + +static int +jailhouseDomainDestroyFlags(virDomainPtr domain, unsigned int flags) +{ + virJailhouseDriverPtr driver =3D domain->conn->privateData; + virJailhouseCellInfoPtr cell_info; + virDomainObjPtr cell; + int ret =3D -1; + + virCheckFlags(0, -1); + + if (!(cell =3D virJailhouseDomObjFromDomain(domain))) + goto cleanup; + + if (virDomainDestroyFlagsEnsureACL(domain->conn, cell->def) < 0) + goto cleanup; + + if (virDomainObjGetState(cell, NULL) !=3D VIR_DOMAIN_SHUTOFF) { + virReportError(VIR_ERR_OPERATION_INVALID, + _("Domain %s is still running."), + cell->def->name); + goto cleanup; + } + + if (!(cell_info =3D virJailhouseFindCellByName(driver, cell->def->name= ))) { + virReportError(VIR_ERR_NO_DOMAIN, + _("no domain with matching name %s and ID %d)"), + cell->def->name, cell->def->id); + virDomainObjListRemove(driver->domains, cell); + goto cleanup; + } + + // Remove the cell from the domain list. + virDomainObjListRemove(driver->domains, cell); + + ret =3D 0; + + cleanup: + virDomainObjEndAPI(&cell); + return ret; } =20 static int jailhouseDomainDestroy(virDomainPtr domain) { - UNUSED(domain); - return -1; + return jailhouseDomainDestroyFlags(domain, 0); } =20 static int @@ -675,7 +764,9 @@ static virHypervisorDriver jailhouseHypervisorDriver = =3D { .domainCreateWithFlags =3D jailhouseDomainCreateWithFlags, /* 6.3.0= */ .domainCreateXML =3D jailhouseDomainCreateXML, /* 6.3.0 */ .domainShutdown =3D jailhouseDomainShutdown, /* 6.3.0 */ + .domainShutdownFlags =3D jailhouseDomainShutdownFlags, /* 6.3.0 */ .domainDestroy =3D jailhouseDomainDestroy, /* 6.3.0 */ + .domainDestroyFlags =3D jailhouseDomainDestroyFlags, /* 6.3.0 */ .domainGetInfo =3D jailhouseDomainGetInfo, /* 6.3.0 */ .domainGetState =3D jailhouseDomainGetState, /* 6.3.0 */ .domainLookupByID =3D jailhouseDomainLookupByID, /* 6.3.0 */ --=20 2.26.2 From nobody Mon Apr 29 23:31:06 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1600356280; cv=none; d=zohomail.com; s=zohoarc; b=TBxEmVQZOcikctmuMlxvWjAd9+eZPp12lviWaBODqmVXKrKk0F/erhh9R0JCW8JISp6RwIH5xRBbUUit6R4rtrVDann6TblmsqykVhlZOGa4y1N31vIH97gr+KVKP8tOOALa9AJWs0PzLytWvQfjgfpuSfGwsTXpUU6TupCUVaw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600356280; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=11n/G3Z9E88d5xfqbqPYIDXg+9oiNi0WBlN26VXKdoU=; b=cGM3LCA9j+/1FRf/9LVPMivmqnBNwBbExaiTs2eqG3rYyYQCfWl92IYMnVExATSvKC/wIlC73RfrmXg6cZLlrIzX70jltLZUTCiJt7Q4XKCmwpLbPmyTzrlPojfy3oYUgnugswL5UEmQqoX8menO8YRz9hlA+4/3woTDSTKicGA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 160035628004429.00879640242556; Thu, 17 Sep 2020 08:24:40 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-224-W3x2ZbI5N3ij50AZT8aqUg-1; Thu, 17 Sep 2020 11:24:34 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A19AF80EF8A; Thu, 17 Sep 2020 15:24:29 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7F29873662; Thu, 17 Sep 2020 15:24:29 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 4F2D0183D050; Thu, 17 Sep 2020 15:24:29 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 08HFOQRm017881 for ; Thu, 17 Sep 2020 11:24:26 -0400 Received: by smtp.corp.redhat.com (Postfix) id 01EC11F2; Thu, 17 Sep 2020 15:24:26 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-114-29.ams2.redhat.com [10.36.114.29]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3B1EB60CC0; Thu, 17 Sep 2020 15:24:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600356278; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=11n/G3Z9E88d5xfqbqPYIDXg+9oiNi0WBlN26VXKdoU=; b=QIkq11pgOLXGhJQqS1SB6ZVv2qkjFYOx9QWPtPHNMwayrfg7V7RZjEvkYVct8i7Xu1YYGs 71WOW+HenPAEehmAaGivi5BXB/XgURIfOxDxVhjK7cugxkXLrEe93qtrqmGIjN4KFR9FAX dbV8iyPYmGbnGhkdf0d7VvOzZF13WIE= X-MC-Unique: W3x2ZbI5N3ij50AZT8aqUg-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Subject: [libvirt PATCH 8/9] Jailhouse driver: Fixes for creation of cells, fetching cell info, disabling jailhouse hypervisor Date: Thu, 17 Sep 2020 16:23:58 +0100 Message-Id: <20200917152359.1621763-9-berrange@redhat.com> In-Reply-To: <20200917152359.1621763-1-berrange@redhat.com> References: <20200917152359.1621763-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Cc: Prakhar Bansal X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Prakhar Bansal - Added xmlopt to the Jailhouse driver - Added ACL check in ConnectOpen --- src/jailhouse/jailhouse_api.c | 48 +++++++++++++------------- src/jailhouse/jailhouse_driver.c | 58 ++++++++++++++++++++------------ 2 files changed, 61 insertions(+), 45 deletions(-) diff --git a/src/jailhouse/jailhouse_api.c b/src/jailhouse/jailhouse_api.c index 510e2f5f66..bb82b5a31e 100644 --- a/src/jailhouse/jailhouse_api.c +++ b/src/jailhouse/jailhouse_api.c @@ -69,15 +69,9 @@ char *readSysfsCellString(const unsigned int id, const c= har *entry); =20 int cell_match(const struct dirent *dirent); =20 -int createCell(const char *conf_file); - -int loadImagesInCell(virJailhouseCellId cell_id, char *images, int num_ima= ges); - -int shutdownCell(virJailhouseCellId cell_id); +int cell_match_info(const struct dirent *dirent); =20 -int startCell(virJailhouseCellId cell_id); - -int destroyCell(virJailhouseCellId cell_id); +int createCell(const char *conf_file); =20 int getCellInfo(const unsigned int id, virJailhouseCellInfoPtr * cell_info); @@ -121,25 +115,31 @@ jailhouseDisable(void) fd =3D openDev(); =20 err =3D ioctl(fd, JAILHOUSE_DISABLE); - if (err) + if (err) { virReportSystemError(errno, "%s", _("Failed to disable jailhouse: %s")); + return -1; + } =20 VIR_DEBUG("Jailhouse hypervisor is disabled"); =20 - return err; + return 0; } =20 int cell_match(const struct dirent *dirent) { char *ext =3D strrchr(dirent->d_name, '.'); - return dirent->d_name[0] !=3D '.' - && (STREQ(ext, JAILHOUSE_CELL_FILE_EXTENSION) =3D=3D 0); + && STREQ(ext, JAILHOUSE_CELL_FILE_EXTENSION); } =20 +int +cell_match_info(const struct dirent *dirent) +{ + return dirent->d_name[0] !=3D '.'; +} int createJailhouseCells(const char *dir_path) { @@ -150,7 +150,6 @@ createJailhouseCells(const char *dir_path) =20 if (strlen(dir_path) =3D=3D 0) return ret; - num_entries =3D scandir(dir_path, &namelist, cell_match, alphasort); if (num_entries =3D=3D -1) { if (errno =3D=3D ENOENT) { @@ -170,7 +169,8 @@ createJailhouseCells(const char *dir_path) for (i =3D 0; i < num_entries; i++) { g_autofree char *file_path =3D g_strdup_printf("%s/%s", dir_path, = namelist[i]->d_name); =20 - if (createCell(file_path) !=3D 0) { + + if (createCell(file_path) < 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Cell creation failed with conf found in %s.= "), namelist[i]->d_name); @@ -208,13 +208,13 @@ createCell(const char *conf_file) VIR_AUTOCLOSE fd =3D -1; =20 if (strlen(conf_file) =3D=3D 0) - return err; + return -1; =20 len =3D 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 fil= e")); - return err; + return -1; } =20 cell_create.config_address =3D (unsigned long) buffer; @@ -223,12 +223,14 @@ createCell(const char *conf_file) fd =3D openDev(); =20 err =3D ioctl(fd, JAILHOUSE_CELL_CREATE, &cell_create); - if (err) + if (err) { virReportSystemError(errno, "%s", _("Cell creation failed: %s")); + return -1; + } =20 - return err; + return 0; } =20 void @@ -243,11 +245,11 @@ cellInfoFree(virJailhouseCellInfoPtr cell_info) char * readSysfsCellString(const unsigned int id, const char *entry) { - g_autofree char *buffer =3D NULL; + char *buffer =3D NULL; g_autofree char *file_path =3D NULL; int len =3D -1; =20 - file_path =3D g_strdup_printf(JAILHOUSE_CELLS "%u/%s", id, entry); + file_path =3D g_strdup_printf(JAILHOUSE_CELLS "/%u/%s", id, entry); =20 len =3D virFileReadAll(file_path, 1024, &buffer); if (len < 0 || !buffer) { @@ -277,13 +279,12 @@ getCellInfo(const unsigned int id, virJailhouseCellIn= foPtr *cell_info_ptr) =20 /* get cell name */ tmp =3D readSysfsCellString(id, "name"); - if (virStrncpy(cell_info->id.name, tmp, JAILHOUSE_CELL_ID_NAMELEN, JAI= LHOUSE_CELL_ID_NAMELEN) < 0) { + if (virStrcpy(cell_info->id.name, tmp, JAILHOUSE_CELL_ID_NAMELEN) < 0)= { virReportError(VIR_ERR_INTERNAL_ERROR, _("Cell ID %s too long to be copied to the cell inf= o"), tmp); return -1; } - cell_info->id.name[JAILHOUSE_CELL_ID_NAMELEN] =3D 0; VIR_FREE(tmp); =20 @@ -310,8 +311,7 @@ getJailhouseCellsInfo(void) int num_entries; size_t i; =20 - num_entries =3D - scandir(JAILHOUSE_CELLS, &namelist, cell_match, alphasort); + num_entries =3D scandir(JAILHOUSE_CELLS, &namelist, cell_match_info, a= lphasort); if (num_entries =3D=3D -1) { if (errno =3D=3D ENOENT) { virReportError(VIR_ERR_INTERNAL_ERROR, diff --git a/src/jailhouse/jailhouse_driver.c b/src/jailhouse/jailhouse_dri= ver.c index 46c7759cb8..45b1f35896 100644 --- a/src/jailhouse/jailhouse_driver.c +++ b/src/jailhouse/jailhouse_driver.c @@ -122,7 +122,6 @@ jailhouseCreateAndLoadCells(virJailhouseDriverPtr drive= r) // 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 =3D getJailhouseCellsInfo(); =20 @@ -136,6 +135,7 @@ jailhouseFreeDriver(virJailhouseDriverPtr driver) return; =20 virMutexDestroy(&driver->lock); + virObjectUnref(driver->xmlopt); virObjectUnref(driver->domains); virObjectUnref(driver->config); VIR_FREE(driver); @@ -147,7 +147,6 @@ jailhouseConnectOpen(virConnectPtr conn, virConfPtr conf G_GNUC_UNUSED, unsigned int flags) { uid_t uid =3D geteuid(); - virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); =20 if (!virConnectValidateURIPath(conn->uri->path, "jailhouse", uid =3D= =3D 0)) @@ -159,8 +158,10 @@ jailhouseConnectOpen(virConnectPtr conn, return VIR_DRV_OPEN_ERROR; } =20 - conn->privateData =3D jailhouse_driver; + if (virConnectOpenEnsureACL(conn) < 0) + return VIR_DRV_OPEN_ERROR; =20 + conn->privateData =3D jailhouse_driver; return VIR_DRV_OPEN_SUCCESS; } =20 @@ -169,16 +170,19 @@ jailhouseConnectOpen(virConnectPtr conn, static int jailhouseConnectClose(virConnectPtr conn) { - conn->privateData =3D NULL; + conn->privateData =3D NULL; =20 - return 0; + return 0; } =20 static int jailhouseStateCleanup(void) { if (!jailhouse_driver) - return -1; + return -1; + + if (jailhouseDisable() < 0) + return -1; =20 if (jailhouse_driver->lockFD !=3D -1) virPidFileRelease(jailhouse_driver->config->stateDir, @@ -187,6 +191,9 @@ jailhouseStateCleanup(void) virMutexDestroy(&jailhouse_driver->lock); =20 jailhouseFreeDriver(jailhouse_driver); + + jailhouse_driver =3D NULL; + return 0; } =20 @@ -199,6 +206,9 @@ jailhouseStateInitialize(bool privileged G_GNUC_UNUSED, virJailhouseDriverConfigPtr cfg =3D NULL; int rc; =20 + if (jailhouse_driver) + return VIR_DRV_STATE_INIT_COMPLETE; + jailhouse_driver =3D g_new0(virJailhouseDriver, 1); jailhouse_driver->lockFD =3D -1; =20 @@ -220,6 +230,10 @@ jailhouseStateInitialize(bool privileged G_GNUC_UNUSED, if (jailhouseLoadConf(cfg) < 0) goto error; =20 + if (!(jailhouse_driver->xmlopt =3D virDomainXMLOptionNew(NULL, NULL, + NULL, NULL, NUL= L))) + goto error; + if (virFileMakePath(cfg->stateDir) < 0) { virReportSystemError(errno, _("Failed to create state dir %s"), cfg->stateDir); @@ -292,7 +306,7 @@ jailhouseConnectListAllDomains(virConnectPtr conn, static virDomainPtr jailhouseDomainLookupByID(virConnectPtr conn, int id) { -virJailhouseDriverPtr driver =3D conn->privateData; + virJailhouseDriverPtr driver =3D conn->privateData; virDomainObjPtr cell; virDomainPtr dom =3D NULL; =20 @@ -409,7 +423,6 @@ jailhouseDomainCreateWithFlags(virDomainPtr domain, virJailhouseCellInfoPtr cell_info; virDomainObjPtr cell; int ret =3D -1; - virCheckFlags(VIR_DOMAIN_NONE, -1); =20 if (!domain->name) { @@ -462,23 +475,23 @@ jailhouseDomainCreateXML(virConnectPtr conn, virDomainPtr dom =3D NULL; virDomainDefPtr def =3D NULL; virDomainObjPtr cell =3D NULL; - virDomainDiskDefPtr disk =3D NULL; virJailhouseCellId cell_id; char **images =3D NULL; int num_images =3D 0, i =3D 0; unsigned int parse_flags =3D VIR_DOMAIN_DEF_PARSE_INACTIVE; + bool removeInactive =3D false; =20 if (flags & VIR_DOMAIN_START_VALIDATE) parse_flags |=3D VIR_DOMAIN_DEF_PARSE_VALIDATE_SCHEMA; =20 - if ((def =3D virDomainDefParseString(xml, NULL, - NULL, parse_flags)) =3D=3D NULL) + if (!(def =3D virDomainDefParseString(xml, driver->xmlopt, + NULL, parse_flags))) goto cleanup; =20 - if ((cell =3D virDomainObjListFindByUUID(driver->domains, def->uuid))) + if (virDomainCreateXMLEnsureACL(conn, def) < 0) goto cleanup; =20 - if (virDomainCreateXMLEnsureACL(conn, def) < 0) + if ((cell =3D virDomainObjListFindByUUID(driver->domains, def->uuid))) goto cleanup; =20 if (!(cell_info =3D virJailhouseFindCellByName(driver, def->name))) { @@ -492,13 +505,13 @@ jailhouseDomainCreateXML(virConnectPtr conn, def->id =3D cell_info->id.id; =20 if (!(cell =3D virDomainObjListAdd(driver->domains, def, - NULL, - VIR_DOMAIN_OBJ_LIST_ADD_LIVE | - VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE, NUL= L))) + driver->xmlopt, 0, NULL))) goto cleanup; =20 def =3D NULL; =20 + removeInactive =3D true; + if (cell->def->ndisks < 1) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Domain XML doesn't contain any disk images")); @@ -513,7 +526,7 @@ jailhouseDomainCreateXML(virConnectPtr conn, =20 if (cell->def->disks[i]->device =3D=3D VIR_DOMAIN_DISK_DEVICE_DISK= && virDomainDiskGetType(cell->def->disks[i]) =3D=3D VIR_STORAGE_T= YPE_FILE) { - disk =3D cell->def->disks[i]; + virDomainDiskDefPtr disk =3D cell->def->disks[i]; const char *src =3D virDomainDiskGetSource(disk); if (!src) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -525,7 +538,7 @@ jailhouseDomainCreateXML(virConnectPtr conn, num_images++; } else { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("A Jailhouse doamin(cell) can ONLY have FILE = type disks")); + _("A Jailhouse domain(cell) can ONLY have FILE = type disks")); goto cleanup; } } @@ -533,7 +546,7 @@ jailhouseDomainCreateXML(virConnectPtr conn, // Initialize the cell_id. cell_id.id =3D cell->def->id; cell_id.padding =3D 0; - if (virStrncpy(cell_id.name, cell->def->name, JAILHOUSE_CELL_ID_NAMELE= N, JAILHOUSE_CELL_ID_NAMELEN) < 0) { + if (virStrcpy(cell_id.name, cell->def->name, JAILHOUSE_CELL_ID_NAMELEN= ) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Cell name %s length exceeded the limit"), cell->def->name); @@ -561,6 +574,9 @@ jailhouseDomainCreateXML(virConnectPtr conn, dom =3D virGetDomain(conn, cell->def->name, cell->def->uuid, cell->def= ->id); =20 cleanup: + if (!dom && removeInactive && !cell->persistent) + virDomainObjListRemove(driver->domains, cell); + virDomainDefFree(def); virDomainObjEndAPI(&cell); return dom; @@ -671,7 +687,7 @@ jailhouseDomainDestroy(virDomainPtr domain) =20 static int virjailhouseGetDomainTotalCpuStats(virDomainObjPtr cell, - unsigned long long *cpustats) + unsigned long long *cpustats) { // TODO(Prakhar): Not implemented yet. UNUSED(cell); @@ -721,7 +737,7 @@ jailhouseDomainGetState(virDomainPtr domain, goto cleanup; =20 if (virDomainGetStateEnsureACL(domain->conn, cell->def) < 0) - goto cleanup; + goto cleanup; =20 *state =3D virDomainObjGetState(cell, reason); ret =3D 0; --=20 2.26.2 From nobody Mon Apr 29 23:31:06 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1600356278; cv=none; d=zohomail.com; s=zohoarc; b=PXIOubMGgstermgDhz8wS4weHqXuvMA/6wPYdX7FmmAn2hfsjjrpQnkqpajn84cR3j8mlS1Ma68wrOrAzRea6ERvIyY4IAuaa7icjhFYuBO6pdng9zdy2uS2rb8/eAU85fvLFaUK0V3DooaDfIfF3cDy75h6ucn9CYscboDzZhA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600356278; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=NB9dv3wKz5Kus0z+LQGf4GWtXzutV9PHP+pJfHqcRPY=; b=CoH1GKRVhdxmL1vwm42cMxZhE3GFIjBmyfBMwi67uv2u7wBCt2qGDVrEtQZXLVj3v09d+9NlVShiFIh57EP3Gs6E4LC7cvsAIN9NLa1TBXUENdLHnMEqUlCIk+QOUoGJJjY6CBDGH5761OwsiBJ6u8xo2fWvdh2hi60RTeVuKNg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1600356278349362.49868319257916; Thu, 17 Sep 2020 08:24:38 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-256-i4cWKrPsPt2knN2pmtHnsg-1; Thu, 17 Sep 2020 11:24:33 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 128708BF149; Thu, 17 Sep 2020 15:24:28 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E245560CC0; Thu, 17 Sep 2020 15:24:27 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id ADEC9183D041; Thu, 17 Sep 2020 15:24:27 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 08HFORl5017895 for ; Thu, 17 Sep 2020 11:24:27 -0400 Received: by smtp.corp.redhat.com (Postfix) id 15F7E1F2; Thu, 17 Sep 2020 15:24:27 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-114-29.ams2.redhat.com [10.36.114.29]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7029360CC0; Thu, 17 Sep 2020 15:24:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600356277; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=NB9dv3wKz5Kus0z+LQGf4GWtXzutV9PHP+pJfHqcRPY=; b=f5VfhJga7r2SCu1B4B3P3zVNXCjIwCkU3yitqcpRbPOK/hr2y+8eL7odwgwR2wbziqzKZG qkItoWt8u/hEkRCbOf54/rIZ1ZR6geAAtNqLunXIvyf+5MbTo839Wzr+5tPJDdAJSOP9SX vYPJkAit31f4b2ZDMbNII15OWe8EADY= X-MC-Unique: i4cWKrPsPt2knN2pmtHnsg-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Subject: [libvirt PATCH 9/9] Jailhouse driver: Add events to events queue in DomainCreate/Shutdown/Destroy Date: Thu, 17 Sep 2020 16:23:59 +0100 Message-Id: <20200917152359.1621763-10-berrange@redhat.com> In-Reply-To: <20200917152359.1621763-1-berrange@redhat.com> References: <20200917152359.1621763-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Cc: Prakhar Bansal X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Prakhar Bansal --- src/jailhouse/jailhouse_driver.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/jailhouse/jailhouse_driver.c b/src/jailhouse/jailhouse_dri= ver.c index 45b1f35896..70f0f365cb 100644 --- a/src/jailhouse/jailhouse_driver.c +++ b/src/jailhouse/jailhouse_driver.c @@ -122,6 +122,7 @@ jailhouseCreateAndLoadCells(virJailhouseDriverPtr drive= r) // 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 =3D getJailhouseCellsInfo(); =20 @@ -137,6 +138,7 @@ jailhouseFreeDriver(virJailhouseDriverPtr driver) virMutexDestroy(&driver->lock); virObjectUnref(driver->xmlopt); virObjectUnref(driver->domains); + virObjectUnref(driver->domainEventState); virObjectUnref(driver->config); VIR_FREE(driver); } @@ -222,6 +224,9 @@ jailhouseStateInitialize(bool privileged G_GNUC_UNUSED, if (!(jailhouse_driver->domains =3D virDomainObjListNew())) goto error; =20 + if (!(jailhouse_driver->domainEventState =3D virObjectEventStateNew())) + goto error; + if (!(cfg =3D virJailhouseDriverConfigNew())) goto error; =20 @@ -476,6 +481,7 @@ jailhouseDomainCreateXML(virConnectPtr conn, virDomainDefPtr def =3D NULL; virDomainObjPtr cell =3D NULL; virJailhouseCellId cell_id; + virObjectEventPtr event =3D NULL; char **images =3D NULL; int num_images =3D 0, i =3D 0; unsigned int parse_flags =3D VIR_DOMAIN_DEF_PARSE_INACTIVE; @@ -573,12 +579,16 @@ jailhouseDomainCreateXML(virConnectPtr conn, =20 dom =3D virGetDomain(conn, cell->def->name, cell->def->uuid, cell->def= ->id); =20 + event =3D virDomainEventLifecycleNewFromObj(cell, + VIR_DOMAIN_EVENT_STARTED, + VIR_DOMAIN_EVENT_STARTED_BOO= TED); cleanup: if (!dom && removeInactive && !cell->persistent) virDomainObjListRemove(driver->domains, cell); =20 virDomainDefFree(def); virDomainObjEndAPI(&cell); + virObjectEventStateQueue(driver->domainEventState, event); return dom; } =20 @@ -589,6 +599,7 @@ jailhouseDomainShutdownFlags(virDomainPtr domain, unsig= ned int flags) virJailhouseCellInfoPtr cell_info; virDomainObjPtr cell; virJailhouseCellId cell_id; + virObjectEventPtr event =3D NULL; int ret =3D -1; =20 virCheckFlags(0, -1); @@ -627,8 +638,12 @@ jailhouseDomainShutdownFlags(virDomainPtr domain, unsi= gned int flags) =20 ret =3D 0; =20 + event =3D virDomainEventLifecycleNewFromObj(cell, + VIR_DOMAIN_EVENT_STOPPED, + VIR_DOMAIN_EVENT_STOPPED_SHU= TDOWN); cleanup: virDomainObjEndAPI(&cell); + virObjectEventStateQueue(driver->domainEventState, event); return ret; } =20 @@ -644,6 +659,7 @@ jailhouseDomainDestroyFlags(virDomainPtr domain, unsign= ed int flags) virJailhouseDriverPtr driver =3D domain->conn->privateData; virJailhouseCellInfoPtr cell_info; virDomainObjPtr cell; + virObjectEventPtr event =3D NULL; int ret =3D -1; =20 virCheckFlags(0, -1); @@ -674,8 +690,12 @@ jailhouseDomainDestroyFlags(virDomainPtr domain, unsig= ned int flags) =20 ret =3D 0; =20 + event =3D virDomainEventLifecycleNewFromObj(cell, + VIR_DOMAIN_EVENT_STOPPED, + VIR_DOMAIN_EVENT_STOPPED_DES= TROYED); cleanup: virDomainObjEndAPI(&cell); + virObjectEventStateQueue(driver->domainEventState, event); return ret; } =20 --=20 2.26.2