----------------------------------------------------------------------
-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).
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
char *qemu; /* Qemu binary. */
char *append; /* Append to kernel command line. */
+ int memsize; /* Size of RAM (megabytes). */
+
char *last_error;
/* Callbacks. */
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
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)
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;
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;
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);