From patchwork Tue Nov 1 16:07:17 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony PERARD X-Patchwork-Id: 123090 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 93C7DB6F86 for ; Wed, 2 Nov 2011 03:09:21 +1100 (EST) Received: from localhost ([::1]:39375 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RLGto-0002lv-9W for incoming@patchwork.ozlabs.org; Tue, 01 Nov 2011 12:09:16 -0400 Received: from eggs.gnu.org ([140.186.70.92]:54604) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RLGsy-0001wq-36 for qemu-devel@nongnu.org; Tue, 01 Nov 2011 12:08:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RLGsv-0004jr-Cv for qemu-devel@nongnu.org; Tue, 01 Nov 2011 12:08:23 -0400 Received: from smtp02.citrix.com ([66.165.176.63]:23018) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RLGsu-0004j5-T4 for qemu-devel@nongnu.org; Tue, 01 Nov 2011 12:08:20 -0400 X-IronPort-AV: E=Sophos;i="4.69,438,1315195200"; d="scan'208";a="168952562" Received: from ftlpmailmx02.citrite.net ([10.13.107.66]) by FTLPIPO02.CITRIX.COM with ESMTP/TLS/RC4-MD5; 01 Nov 2011 12:08:00 -0400 Received: from smtp01.ad.xensource.com (10.219.128.104) by smtprelay.citrix.com (10.13.107.66) with Microsoft SMTP Server id 8.3.137.0; Tue, 1 Nov 2011 12:07:59 -0400 Received: from perard.uk.xensource.com (dhcp-3-28.uk.xensource.com [10.80.3.28] (may be forged)) by smtp01.ad.xensource.com (8.13.1/8.13.1) with ESMTP id pA1G7YNH014577; Tue, 1 Nov 2011 09:07:57 -0700 From: Anthony PERARD To: QEMU-devel , Stefano Stabellini Date: Tue, 1 Nov 2011 16:07:17 +0000 Message-ID: <1320163646-24291-5-git-send-email-anthony.perard@citrix.com> X-Mailer: git-send-email 1.7.2.5 In-Reply-To: <1320163646-24291-1-git-send-email-anthony.perard@citrix.com> References: <1320163646-24291-1-git-send-email-anthony.perard@citrix.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 66.165.176.63 Cc: Anthony PERARD , Xen Devel Subject: [Qemu-devel] [PATCH V3 04/13] libxl: Introduce dm-version xenstore key. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org The all key is /libxl/$domid/dm-version. The /libxl/$domid dir is created with the domain and should be only accessible by the toolstack domain. The function libxl__xs_libxl_path() give this path. This come with libxl__device_model_version_running() helper function. Signed-off-by: Anthony PERARD --- tools/libxl/libxl.c | 2 ++ tools/libxl/libxl_create.c | 29 ++++++++++++++++++++++++++++- tools/libxl/libxl_internal.c | 23 +++++++++++++++++++++++ tools/libxl/libxl_internal.h | 7 +++++++ tools/libxl/libxl_xshelp.c | 9 +++++++++ 5 files changed, 69 insertions(+), 1 deletions(-) diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c index 064fbc4..22a7795 100644 --- a/tools/libxl/libxl.c +++ b/tools/libxl/libxl.c @@ -777,6 +777,8 @@ int libxl_domain_destroy(libxl_ctx *ctx, uint32_t domid, int force) if (!xs_rm(ctx->xsh, XBT_NULL, dom_path)) LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "xs_rm failed for %s", dom_path); + xs_rm(ctx->xsh, XBT_NULL, libxl__xs_libxl_path(&gc, domid)); + libxl__userdata_destroyall(&gc, domid); rc = xc_domain_destroy(ctx->xch, domid); diff --git a/tools/libxl/libxl_create.c b/tools/libxl/libxl_create.c index 68d0fc3..9506aa4 100644 --- a/tools/libxl/libxl_create.c +++ b/tools/libxl/libxl_create.c @@ -316,12 +316,14 @@ int libxl__domain_make(libxl__gc *gc, libxl_domain_create_info *info, char *rw_paths[] = { "control/shutdown", "device", "device/suspend/event-channel" , "data"}; char *ro_paths[] = { "cpu", "memory", "device", "error", "drivers", "control", "attr", "messages" }; - char *dom_path, *vm_path; + char *dom_path, *vm_path, *libxl_path; struct xs_permissions roperm[2]; struct xs_permissions rwperm[1]; + struct xs_permissions noperm[1]; xs_transaction_t t = 0; xen_domain_handle_t handle; + assert(!libxl_domid_valid_guest(*domid)); uuid_string = libxl__uuid2string(gc, info->uuid); @@ -368,6 +370,14 @@ int libxl__domain_make(libxl__gc *gc, libxl_domain_create_info *info, goto out; } + libxl_path = libxl__xs_libxl_path(gc, *domid); + if (!libxl_path) { + rc = ERROR_FAIL; + goto out; + } + noperm[0].id = 0; + noperm[0].perms = XS_PERM_NONE; + roperm[0].id = 0; roperm[0].perms = XS_PERM_NONE; roperm[1].id = *domid; @@ -386,6 +396,10 @@ retry_transaction: xs_mkdir(ctx->xsh, t, vm_path); xs_set_permissions(ctx->xsh, t, vm_path, roperm, ARRAY_SIZE(roperm)); + xs_rm(ctx->xsh, t, libxl_path); + xs_mkdir(ctx->xsh, t, libxl_path); + xs_set_permissions(ctx->xsh, t, libxl_path, noperm, ARRAY_SIZE(noperm)); + xs_write(ctx->xsh, t, libxl__sprintf(gc, "%s/vm", dom_path), vm_path, strlen(vm_path)); rc = libxl__domain_rename(gc, *domid, 0, info->name, t); if (rc) @@ -429,6 +443,17 @@ retry_transaction: return rc; } +static int store_libxl_entry(libxl__gc *gc, uint32_t domid, + libxl_device_model_info *dm_info) +{ + char *path = NULL; + + path = libxl__xs_libxl_path(gc, domid); + path = libxl__sprintf(gc, "%s/dm-version", path); + return libxl__xs_write(gc, XBT_NULL, path, libxl__strdup(gc, + libxl_device_model_version_to_string(dm_info->device_model_version))); +} + static int do_domain_create(libxl__gc *gc, libxl_domain_config *d_config, libxl_console_ready cb, void *priv, uint32_t *domid_out, int restore_fd) @@ -485,6 +510,8 @@ static int do_domain_create(libxl__gc *gc, libxl_domain_config *d_config, goto error_out; } + store_libxl_entry(gc, domid, dm_info); + for (i = 0; i < d_config->num_disks; i++) { ret = libxl_device_disk_add(ctx, domid, &d_config->disks[i]); if (ret) { diff --git a/tools/libxl/libxl_internal.c b/tools/libxl/libxl_internal.c index 3993d8e..34edaf3 100644 --- a/tools/libxl/libxl_internal.c +++ b/tools/libxl/libxl_internal.c @@ -319,6 +319,29 @@ int libxl__fd_set_cloexec(int fd) return fcntl(fd, F_SETFD, flags | FD_CLOEXEC); } +libxl_device_model_version libxl__device_model_version_running(libxl__gc *gc, + uint32_t domid) +{ + char *path = NULL; + char *dm_version = NULL; + libxl_device_model_version value; + + path = libxl__xs_libxl_path(gc, domid); + path = libxl__sprintf(gc, "%s/dm-version", path); + dm_version = libxl__xs_read(gc, XBT_NULL, path); + if (!dm_version) { + return LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL; + } + + if (libxl_device_model_version_from_string(dm_version, &value) < 0) { + libxl_ctx *ctx = libxl__gc_owner(gc); + LIBXL__LOG(ctx, LIBXL__LOG_ERROR, + "fatal: %s contain a wrong value (%s)", path, dm_version); + return -1; + } + return value; +} + /* * Local variables: * mode: C diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index 2e26ac6..942d45b 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -195,6 +195,8 @@ _hidden char **libxl__xs_directory(libxl__gc *gc, xs_transaction_t t, char *path, unsigned int *nb); /* On error: returns NULL, sets errno (no logging) */ +_hidden char *libxl__xs_libxl_path(libxl__gc *gc, uint32_t domid); + /* from xl_dom */ _hidden libxl_domain_type libxl__domain_type(libxl__gc *gc, uint32_t domid); _hidden int libxl__domain_shutdown_reason(libxl__gc *gc, uint32_t domid); @@ -554,6 +556,11 @@ _hidden void libxl__json_object_free(libxl__gc *gc, libxl__json_object *obj); _hidden libxl__json_object *libxl__json_parse(libxl__gc *gc, const char *s); + /* Based on /local/domain/$domid/dm-version xenstore key + * default is qemu xen traditional */ +_hidden libxl_device_model_version +libxl__device_model_version_running(libxl__gc *gc, uint32_t domid); + #endif /* diff --git a/tools/libxl/libxl_xshelp.c b/tools/libxl/libxl_xshelp.c index e41f962..4b09be3 100644 --- a/tools/libxl/libxl_xshelp.c +++ b/tools/libxl/libxl_xshelp.c @@ -122,6 +122,15 @@ char **libxl__xs_directory(libxl__gc *gc, xs_transaction_t t, char *path, unsign return ret; } +char *libxl__xs_libxl_path(libxl__gc *gc, uint32_t domid) +{ + libxl_ctx *ctx = libxl__gc_owner(gc); + char *s = libxl__sprintf(gc, "/libxl/%i", domid); + if (!s) + LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "cannot allocate create paths"); + return s; +} + /* * Local variables: * mode: C