void * subprocess_quit_cb_data;
guestfs_launch_done_cb launch_done_cb;
void * launch_done_cb_data;
+ guestfs_close_cb close_cb;
+ void * close_cb_data;
int msg_next_serial;
};
if (g->verbose)
fprintf (stderr, "closing guestfs handle %p (state %d)\n", g, g->state);
+ /* Run user close callback before anything else. */
+ if (g->close_cb)
+ g->close_cb (g, g->close_cb_data);
+
/* Try to sync if autosync flag is set. */
if (g->autosync && g->state == READY) {
guestfs_umount_all (g);
guestfs__add_drive_ro_with_if (guestfs_h *g, const char *filename,
const char *drive_if)
{
+ size_t len = strlen (filename) + 64;
+ char buf[len];
+
if (strchr (filename, ',') != NULL) {
error (g, _("filename cannot contain ',' (comma) character"));
return -1;
return -1;
}
- if (qemu_supports (g, NULL) == -1)
- return -1;
-
- /* Only SCSI and virtio drivers support readonly mode.
- * This is only supported as a QEMU feature since 2010/01.
- */
- int supports_ro = 0;
- if ((STREQ (drive_if, "scsi") || STREQ (drive_if, "virtio")) &&
- qemu_supports (g, "readonly=on"))
- supports_ro = 1;
-
- size_t len = strlen (filename) + 100;
- char buf[len];
-
- snprintf (buf, len, "file=%s,snapshot=on,%sif=%s",
- filename,
- supports_ro ? "readonly=on," : "",
- drive_if);
+ snprintf (buf, len, "file=%s,snapshot=on,if=%s", filename, drive_if);
return guestfs__config (g, "-drive", buf);
}
static const char *kernel_name = "vmlinuz." REPO "." host_cpu;
static const char *initrd_name = "initramfs." REPO "." host_cpu ".img";
-static const char *supermin_name =
- "initramfs." REPO "." host_cpu ".supermin.img";
-static const char *supermin_hostfiles_name =
- "initramfs." REPO "." host_cpu ".supermin.hostfiles";
int
guestfs__launch (guestfs_h *g)
char unixsock[256];
struct sockaddr_un addr;
+ /* Configured? */
+ if (!g->cmdline) {
+ error (g, _("you must call guestfs_add_drive before guestfs_launch"));
+ return -1;
+ }
+
+ if (g->state != CONFIG) {
+ error (g, _("the libguestfs handle has already been launched"));
+ return -1;
+ }
+
/* Start the clock ... */
gettimeofday (&g->launch_t, NULL);
+ /* Make the temporary directory. */
#ifdef P_tmpdir
tmpdir = P_tmpdir;
#else
tmpdir = getenv ("TMPDIR") ? : tmpdir;
snprintf (dir_template, sizeof dir_template, "%s/libguestfsXXXXXX", tmpdir);
- /* Configured? */
- if (!g->cmdline) {
- error (g, _("you must call guestfs_add_drive before guestfs_launch"));
- return -1;
- }
-
- if (g->state != CONFIG) {
- error (g, _("qemu has already been launched"));
- return -1;
- }
-
- /* Make the temporary directory. */
if (!g->tmpdir) {
g->tmpdir = safe_strdup (g, dir_template);
if (mkdtemp (g->tmpdir) == NULL) {
fprintf (stderr,
"looking for supermin appliance in current directory\n");
if (dir_contains_files (".",
- supermin_name, supermin_hostfiles_name,
- "kmod.whitelist", NULL)) {
+ "supermin.d", "kmod.whitelist", NULL)) {
if (build_supermin_appliance (g, ".", &kernel, &initrd) == -1)
return -1;
break;
fprintf (stderr, "looking for supermin appliance in %s\n", pelem);
if (dir_contains_files (pelem,
- supermin_name, supermin_hostfiles_name,
- "kmod.whitelist", NULL)) {
+ "supermin.d", "kmod.whitelist", NULL)) {
if (build_supermin_appliance (g, pelem, &kernel, &initrd) == -1)
return -1;
break;
snprintf (*initrd, len+8, "%s/initrd", g->tmpdir);
snprintf (cmd, sizeof cmd,
- "PATH='%s':$PATH "
- "libguestfs-supermin-helper%s '%s' " host_cpu " " REPO " %s %s",
- path,
+ "febootstrap-supermin-helper%s "
+ "-k '%s/kmod.whitelist' "
+ "'%s/supermin.d' "
+ host_cpu " "
+ "%s %s",
g->verbose ? " --verbose" : "",
- path, *kernel, *initrd);
+ path,
+ path,
+ *kernel, *initrd);
if (g->verbose)
print_timestamped_message (g, "%s", cmd);
g->launch_done_cb_data = opaque;
}
+void
+guestfs_set_close_callback (guestfs_h *g,
+ guestfs_close_cb cb, void *opaque)
+{
+ g->close_cb = cb;
+ g->close_cb_data = opaque;
+}
+
/*----------------------------------------------------------------------*/
/* This is the code used to send and receive RPC messages and (for