diff options
author | Richard W.M. Jones <rjones@redhat.com> | 2009-06-30 11:16:22 +0100 |
---|---|---|
committer | Richard W.M. Jones <rjones@redhat.com> | 2009-06-30 13:10:44 +0100 |
commit | 3d15f7e652340777514ff30c3cfc560a90b612ec (patch) | |
tree | 7ded6427f608f60153e0852577b1e93628b2c5b4 | |
parent | 284797c1561e5e089986027d469bd16ee1a983df (diff) | |
download | libguestfs-3d15f7e652340777514ff30c3cfc560a90b612ec.tar.gz libguestfs-3d15f7e652340777514ff30c3cfc560a90b612ec.tar.xz libguestfs-3d15f7e652340777514ff30c3cfc560a90b612ec.zip |
Add 'set_memsize'/'get_memsize' calls.
Allow the qemu memory size to be specified either by API
calls or by setting the LIBGUESTFS_MEMSIZE environment
variable.
-rw-r--r-- | TODO | 5 | ||||
-rwxr-xr-x | src/generator.ml | 29 | ||||
-rw-r--r-- | src/guestfs.c | 44 |
3 files changed, 62 insertions, 16 deletions
@@ -160,11 +160,6 @@ Allow swap space from the guest to be used. Is it a good idea? ---------------------------------------------------------------------- -Allow memsize to be configured (ie. guestfs_set_memsize etc) -Also have an environment variable (LIBGUESTFS_MEMSIZE). - ----------------------------------------------------------------------- - Need a way to query a binary or library file for its architecture. Using objdump or readelf? What about non-ELF files (eg. Windows, BSD). diff --git a/src/generator.ml b/src/generator.ml index da18ccff..13c1cfae 100755 --- a/src/generator.ml +++ b/src/generator.ml @@ -598,6 +598,35 @@ actions using the low-level API. For more information on states, see L<guestfs(3)>."); + ("set_memsize", (RErr, [Int "memsize"]), -1, [FishAlias "memsize"], + [], + "set memory allocated to the qemu subprocess", + "\ +This sets the memory size in megabytes allocated to the +qemu subprocess. This only has any effect if called before +C<guestfs_launch>. + +You can also change this by setting the environment +variable C<LIBGUESTFS_MEMSIZE> before the handle is +created. + +For more information on the architecture of libguestfs, +see L<guestfs(3)>."); + + ("get_memsize", (RInt "memsize", []), -1, [], + [], + "get memory allocated to the qemu subprocess", + "\ +This gets the memory size in megabytes allocated to the +qemu subprocess. + +If C<guestfs_set_memsize> was not called +on this handle, and if C<LIBGUESTFS_MEMSIZE> was not set, +then this returns the compiled-in default value for memsize. + +For more information on the architecture of libguestfs, +see L<guestfs(3)>."); + ] (* daemon_functions are any functions which cause some action diff --git a/src/guestfs.c b/src/guestfs.c index 016d8035..5743a071 100644 --- a/src/guestfs.c +++ b/src/guestfs.c @@ -174,6 +174,8 @@ struct guestfs_h char *qemu; /* Qemu binary. */ char *append; /* Append to kernel command line. */ + int memsize; /* Size of RAM (megabytes). */ + char *last_error; /* Callbacks. */ @@ -246,6 +248,22 @@ guestfs_create (void) if (!g->append) goto error; } + /* Choose a suitable memory size. Previously we tried to choose + * a minimal memory size, but this isn't really necessary since + * recent QEMU and KVM don't do anything nasty like locking + * memory into core any more. Thus we can safely choose a + * large, generous amount of memory, and it'll just get swapped + * on smaller systems. + */ + str = getenv ("LIBGUESTFS_MEMSIZE"); + if (str) { + if (sscanf (str, "%d", &g->memsize) != 1 || g->memsize <= 256) { + fprintf (stderr, "libguestfs: non-numeric or too small value for LIBGUESTFS_MEMSIZE\n"); + goto error; + } + } else + g->memsize = 500; + g->main_loop = guestfs_get_default_main_loop (); /* Start with large serial numbers so they are easy to spot @@ -597,6 +615,19 @@ guestfs_get_append (guestfs_h *g) return g->append; } +int +guestfs_set_memsize (guestfs_h *g, int memsize) +{ + g->memsize = memsize; + return 0; +} + +int +guestfs_get_memsize (guestfs_h *g) +{ + return g->memsize; +} + /* Add a string to the current command line. */ static void incr_cmdline_size (guestfs_h *g) @@ -763,7 +794,7 @@ int guestfs_launch (guestfs_h *g) { static const char *dir_template = "/tmp/libguestfsXXXXXX"; - int r, i, pmore, memsize; + int r, i, pmore; size_t len; int wfd[2], rfd[2]; int tries; @@ -882,15 +913,6 @@ guestfs_launch (guestfs_h *g) goto cleanup0; } - /* Choose a suitable memory size. Previously we tried to choose - * a minimal memory size, but this isn't really necessary since - * recent QEMU and KVM don't do anything nasty like locking - * memory into core any more. Thus we can safely choose a - * large, generous amount of memory, and it'll just get swapped - * on smaller systems. - */ - memsize = 500; - /* Get qemu help text and version. */ if (test_qemu (g) == -1) goto cleanup0; @@ -936,7 +958,7 @@ guestfs_launch (guestfs_h *g) g->verbose ? " guestfs_verbose=1" : "", g->append ? " " : "", g->append ? g->append : ""); - snprintf (memsize_str, sizeof memsize_str, "%d", memsize); + snprintf (memsize_str, sizeof memsize_str, "%d", g->memsize); add_cmdline (g, "-m"); add_cmdline (g, memsize_str); |