xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Ian Campbell <ian.campbell@citrix.com>
To: xen-devel@lists.xensource.com
Cc: Ian Campbell <ian.campbell@citrix.com>
Subject: [PATCH 16 of 26] libxl: implement destroy for libxl_file_reference builtin type
Date: Mon, 16 Aug 2010 15:33:40 +0100	[thread overview]
Message-ID: <d91c2cef85ea93062cdb.1281969220@localhost.localdomain> (raw)
In-Reply-To: <patchbomb.1281969204@localhost.localdomain>

# HG changeset patch
# User Ian Campbell <ian.campbell@citrix.com>
# Date 1281969065 -3600
# Node ID d91c2cef85ea93062cdbd23c81e4990567c0ba25
# Parent  4c0e7313a88fc4219f37cf48177a1c807ca4d22b
libxl: implement destroy for libxl_file_reference builtin type

As well as freeing data any file mappings need to be torn down so
implement an explicit destroy function.

Also the map and unmap function are internal to libxl so make that so.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>

diff -r 4c0e7313a88f -r d91c2cef85ea tools/libxl/libxl.c
--- a/tools/libxl/libxl.c	Mon Aug 16 15:31:05 2010 +0100
+++ b/tools/libxl/libxl.c	Mon Aug 16 15:31:05 2010 +0100
@@ -23,7 +23,6 @@
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <sys/select.h>
-#include <sys/mman.h>
 #include <sys/wait.h>
 #include <sys/time.h>
 #include <signal.h>
@@ -341,9 +340,9 @@ int libxl_domain_build(libxl_ctx *ctx, l
     }
     ret = build_post(ctx, domid, info, state, vments, localents);
 out:
-    libxl_file_reference_unmap(ctx, &info->kernel);
+    libxl__file_reference_unmap(&info->kernel);
     if (!info->hvm)
-	    libxl_file_reference_unmap(ctx, &info->u.pv.ramdisk);
+	    libxl__file_reference_unmap(&info->u.pv.ramdisk);
 
     libxl_free_all(&gc);
     return ret;
@@ -406,9 +405,9 @@ int libxl_domain_restore(libxl_ctx *ctx,
     }
 
 out:
-    libxl_file_reference_unmap(ctx, &info->kernel);
+    libxl__file_reference_unmap(&info->kernel);
     if (!info->hvm)
-	    libxl_file_reference_unmap(ctx, &info->u.pv.ramdisk);
+	    libxl__file_reference_unmap(&info->u.pv.ramdisk);
 
     esave = errno;
 
@@ -3371,47 +3370,8 @@ int libxl_tmem_freeable(libxl_ctx *ctx)
     return rc;
 }
 
-int libxl_file_reference_map(libxl_ctx *ctx, libxl_file_reference *f)
+void libxl_file_reference_destroy(libxl_file_reference *f)
 {
-	struct stat st_buf;
-	int ret, fd;
-	void *data;
-
-	if (f->mapped)
-		return 0;
-
-	fd = open(f->path, O_RDONLY);
-	if (f < 0)
-		return ERROR_FAIL;
-
-	ret = fstat(fd, &st_buf);
-	if (ret < 0)
-		goto out;
-
-	ret = -1;
-	data = mmap(NULL, st_buf.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
-	if (data == NULL)
-		goto out;
-
-	f->mapped = 1;
-	f->data = data;
-	f->size = st_buf.st_size;
-
-	ret = 0;
-out:
-	close(fd);
-
-	return ret == 0 ? 0 : ERROR_FAIL;
+    libxl__file_reference_unmap(f);
+    free(f->path);
 }
-
-int libxl_file_reference_unmap(libxl_ctx *ctx, libxl_file_reference *f)
-{
-	int ret;
-
-	if (!f->mapped)
-		return 0;
-
-	ret = munmap(f->data, f->size);
-
-	return ret == 0 ? 0 : ERROR_FAIL;
-}
diff -r 4c0e7313a88f -r d91c2cef85ea tools/libxl/libxl.h
--- a/tools/libxl/libxl.h	Mon Aug 16 15:31:05 2010 +0100
+++ b/tools/libxl/libxl.h	Mon Aug 16 15:31:05 2010 +0100
@@ -142,10 +142,8 @@ typedef uint8_t libxl_mac[6];
 typedef uint8_t libxl_mac[6];
 
 typedef char **libxl_string_list;
-void libxl_string_list_destroy(libxl_string_list sl);
 
 typedef char **libxl_key_value_list;
-void libxl_key_value_list_destroy(libxl_key_value_list kvl);
 
 typedef uint64_t *libxl_cpumap;
 
@@ -235,8 +233,10 @@ int libxl_domain_destroy(libxl_ctx *ctx,
 int libxl_domain_destroy(libxl_ctx *ctx, uint32_t domid, int force);
 int libxl_domain_preserve(libxl_ctx *ctx, uint32_t domid, libxl_domain_create_info *info, const char *name_suffix, libxl_uuid new_uuid);
 
-int libxl_file_reference_map(libxl_ctx *ctx, libxl_file_reference *f);
-int libxl_file_reference_unmap(libxl_ctx *ctx, libxl_file_reference *f);
+/* destructors for builtin data types */
+void libxl_string_list_destroy(libxl_string_list sl);
+void libxl_key_value_list_destroy(libxl_key_value_list kvl);
+void libxl_file_reference_destroy(libxl_file_reference *f);
 
 /*
  * Run the configured bootloader for a PV domain and update
diff -r 4c0e7313a88f -r d91c2cef85ea tools/libxl/libxl_bootloader.c
--- a/tools/libxl/libxl_bootloader.c	Mon Aug 16 15:31:05 2010 +0100
+++ b/tools/libxl/libxl_bootloader.c	Mon Aug 16 15:31:05 2010 +0100
@@ -279,12 +279,12 @@ static void parse_bootloader_result(libx
         if (strncmp("kernel ", o, strlen("kernel ")) == 0) {
             free(info->kernel.path);
             info->kernel.path = strdup(o + strlen("kernel "));
-            libxl_file_reference_map(ctx, &info->kernel);
+            libxl__file_reference_map(&info->kernel);
             unlink(info->kernel.path);
         } else if (strncmp("ramdisk ", o, strlen("ramdisk ")) == 0) {
             free(info->u.pv.ramdisk.path);
             info->u.pv.ramdisk.path = strdup(o + strlen("ramdisk "));
-            libxl_file_reference_map(ctx, &info->u.pv.ramdisk);
+            libxl__file_reference_map(&info->u.pv.ramdisk);
             unlink(info->u.pv.ramdisk.path);
         } else if (strncmp("args ", o, strlen("args ")) == 0) {
             free(info->u.pv.cmdline);
diff -r 4c0e7313a88f -r d91c2cef85ea tools/libxl/libxl_internal.c
--- a/tools/libxl/libxl_internal.c	Mon Aug 16 15:31:05 2010 +0100
+++ b/tools/libxl/libxl_internal.c	Mon Aug 16 15:31:05 2010 +0100
@@ -18,6 +18,12 @@
 #include <stdio.h>
 #include <stdarg.h>
 #include <string.h>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <sys/mman.h>
+#include <unistd.h>
 
 #include "libxl.h"
 #include "libxl_internal.h"
@@ -185,3 +191,48 @@ char *libxl_abs_path(libxl_gc *gc, char 
     return libxl_sprintf(gc, "%s/%s", path, s);
 }
 
+
+int libxl__file_reference_map(libxl_file_reference *f)
+{
+	struct stat st_buf;
+	int ret, fd;
+	void *data;
+
+	if (f->mapped)
+		return 0;
+
+	fd = open(f->path, O_RDONLY);
+	if (f < 0)
+		return ERROR_FAIL;
+
+	ret = fstat(fd, &st_buf);
+	if (ret < 0)
+		goto out;
+
+	ret = -1;
+	data = mmap(NULL, st_buf.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
+	if (data == NULL)
+		goto out;
+
+	f->mapped = 1;
+	f->data = data;
+	f->size = st_buf.st_size;
+
+	ret = 0;
+out:
+	close(fd);
+
+	return ret == 0 ? 0 : ERROR_FAIL;
+}
+
+int libxl__file_reference_unmap(libxl_file_reference *f)
+{
+	int ret;
+
+	if (!f->mapped)
+		return 0;
+
+	ret = munmap(f->data, f->size);
+
+	return ret == 0 ? 0 : ERROR_FAIL;
+}
diff -r 4c0e7313a88f -r d91c2cef85ea tools/libxl/libxl_internal.h
--- a/tools/libxl/libxl_internal.h	Mon Aug 16 15:31:05 2010 +0100
+++ b/tools/libxl/libxl_internal.h	Mon Aug 16 15:31:05 2010 +0100
@@ -253,4 +253,7 @@ struct libxl__xen_console_reader {
     unsigned int index;
 };
 
+_hidden int libxl__file_reference_map(libxl_file_reference *f);
+_hidden int libxl__file_reference_unmap(libxl_file_reference *f);
+
 #endif
diff -r 4c0e7313a88f -r d91c2cef85ea tools/libxl/libxltypes.idl
--- a/tools/libxl/libxltypes.idl	Mon Aug 16 15:31:05 2010 +0100
+++ b/tools/libxl/libxltypes.idl	Mon Aug 16 15:31:05 2010 +0100
@@ -85,7 +85,7 @@ mapped is true then the actual file may 
 mapped is true then the actual file may already be unlinked."""),
     ("mapped", integer),
     ("data", void),
-    ("size", size_t)])
+    ("size", size_t)], autogenerate_destructor=False)
 
 libxl_domain_build_info = Struct("domain_build_info",[
     ("max_vcpus",       integer),

  parent reply	other threads:[~2010-08-16 14:33 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-16 14:33 [PATCH 00 of 26] libxl: autogenerate type definitions and destructor functions Ian Campbell
2010-08-16 14:33 ` [PATCH 01 of 26] xl: use the regular implicit rules to build the xl .o files Ian Campbell
2010-08-16 14:33 ` [PATCH 02 of 26] libxl: define specific types for string list and key, value list Ian Campbell
2010-08-16 14:33 ` [PATCH 03 of 26] libxl: move various enum and #defines above datastructure definitions Ian Campbell
2010-08-16 14:33 ` [PATCH 04 of 26] libxl: add specific type for cpumap Ian Campbell
2010-08-16 14:33 ` [PATCH 05 of 26] libxl: add specific type for hwcaps Ian Campbell
2010-08-16 14:33 ` [PATCH 06 of 26] libxl: make libxl_console_reader type opaque to users of libxl Ian Campbell
2010-08-16 14:33 ` [PATCH 07 of 26] lbixl: make libxl_device_model_starting " Ian Campbell
2010-08-16 14:33 ` [PATCH 08 of 26] libxl: ensure result of libxl_poolid_to_name is always dynamically allocated Ian Campbell
2010-08-16 14:33 ` [PATCH 09 of 26] libxl: move type definitions into _libxl_types.h Ian Campbell
2010-08-16 14:33 ` [PATCH 10 of 26] libxl: tweak formatting/whitespace of _libxl_types.h Ian Campbell
2010-08-16 14:33 ` [PATCH 11 of 26] libxl: autogenerate _libxl_types.h Ian Campbell
2010-08-17 11:53   ` Stefano Stabellini
2010-08-17 12:20     ` Ian Campbell
2010-08-16 14:33 ` [PATCH 12 of 26] libxl: generate destructors for each libxl defined type Ian Campbell
2010-08-16 14:33 ` [PATCH 13 of 26] libxl: libxl_device_console.build_state is const Ian Campbell
2010-08-16 14:33 ` [PATCH 14 of 26] libxl: build info bootloader{, _args} are not const Ian Campbell
2010-08-16 14:33 ` [PATCH 15 of 26] libxl: do not generate a destructor for data types which do not require one Ian Campbell
2010-08-16 14:33 ` Ian Campbell [this message]
2010-08-16 14:33 ` [PATCH 17 of 26] xl: free the libxl types contained in struct domain_config Ian Campbell
2010-08-16 14:33 ` [PATCH 18 of 26] libxl: use libxl_version_info_destroy instead of hand-coded do_free_version_info Ian Campbell
2010-08-16 14:33 ` [PATCH 19 of 26] xl: destroy device model info after creation Ian Campbell
2010-08-16 14:33 ` [PATCH 20 of 26] xl: free all data on exit from the domain monitor daemon Ian Campbell
2010-08-17 12:27   ` Stefano Stabellini
2010-08-17 12:33     ` Ian Campbell
2010-08-17 15:11       ` Ian Jackson
2010-08-17 15:12         ` Ian Campbell
2010-08-16 14:33 ` [PATCH 21 of 26] libxl/xl: use libxl_diskinfo_destroy and libxl_device_disk_destroy Ian Campbell
2010-08-16 14:33 ` [PATCH 22 of 26] libxl/xl: Use libxl_device_nic_destroy and libxl_nicinfo_destroy Ian Campbell
2010-08-16 14:33 ` [PATCH 23 of 26] libxl/xl: Use libxl_vcpuinfo_destroy Ian Campbell
2010-08-16 14:33 ` [PATCH 24 of 26] xl: use libxl_device_pci_destroy Ian Campbell
2010-08-16 14:33 ` [PATCH 25 of 26] libxl: do not GC data returned to the caller by libxl_device_disk_getinfo Ian Campbell
2010-08-16 14:33 ` [PATCH 26 of 26] libxl: xs_read accepts NULL for *len parameter Ian Campbell
2010-08-17 12:14 ` [PATCH 00 of 26] libxl: autogenerate type definitions and destructor functions Gianni Tedesco
2010-08-17 12:25   ` Ian Campbell
2010-08-17 12:24     ` Gianni Tedesco
2010-08-17 12:34   ` Stefano Stabellini
2010-08-17 12:37     ` Ian Campbell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d91c2cef85ea93062cdb.1281969220@localhost.localdomain \
    --to=ian.campbell@citrix.com \
    --cc=xen-devel@lists.xensource.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).