|
|
022f11 |
From eaffd8105fcd164616aad47cea2b2bf56686acfa Mon Sep 17 00:00:00 2001
|
|
|
022f11 |
From: "Richard W.M. Jones" <rjones@redhat.com>
|
|
|
022f11 |
Date: Fri, 19 Jul 2013 14:09:56 +0100
|
|
|
022f11 |
Subject: [PATCH] New API: add-drive-scratch.
|
|
|
022f11 |
|
|
|
022f11 |
This adds a temporary scratch drive to the handle.
|
|
|
022f11 |
|
|
|
022f11 |
(cherry picked from commit 1b11a83d5248511abbf86775601eb6e25a36c1ee)
|
|
|
022f11 |
---
|
|
|
022f11 |
generator/actions.ml | 15 +++++++++++++++
|
|
|
022f11 |
gobject/Makefile.inc | 2 ++
|
|
|
022f11 |
po/POTFILES | 1 +
|
|
|
022f11 |
src/drives.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
022f11 |
4 files changed, 71 insertions(+)
|
|
|
022f11 |
|
|
|
022f11 |
diff --git a/generator/actions.ml b/generator/actions.ml
|
|
|
022f11 |
index d30aec8..eb09aa7 100644
|
|
|
022f11 |
--- a/generator/actions.ml
|
|
|
022f11 |
+++ b/generator/actions.ml
|
|
|
022f11 |
@@ -2954,6 +2954,21 @@ it is set to the empty string (but never C<NULL>)." };
|
|
|
022f11 |
longdesc = "\
|
|
|
022f11 |
Get the program name. See C<guestfs_set_program>." };
|
|
|
022f11 |
|
|
|
022f11 |
+ { defaults with
|
|
|
022f11 |
+ name = "add_drive_scratch";
|
|
|
022f11 |
+ style = RErr, [Int64 "size"], [OString "name"; OString "label"];
|
|
|
022f11 |
+ blocking = false;
|
|
|
022f11 |
+ fish_alias = ["scratch"];
|
|
|
022f11 |
+ shortdesc = "add a temporary scratch drive";
|
|
|
022f11 |
+ longdesc = "\
|
|
|
022f11 |
+This command adds a temporary scratch drive to the handle. The
|
|
|
022f11 |
+C<size> parameter is the virtual size (in bytes). The scratch
|
|
|
022f11 |
+drive is blank initially (all reads return zeroes until you start
|
|
|
022f11 |
+writing to it). The drive is deleted when the handle is closed.
|
|
|
022f11 |
+
|
|
|
022f11 |
+The optional arguments C<name> and C<label> are passed through to
|
|
|
022f11 |
+C<guestfs_add_drive>." };
|
|
|
022f11 |
+
|
|
|
022f11 |
]
|
|
|
022f11 |
|
|
|
022f11 |
(* daemon_functions are any functions which cause some action
|
|
|
022f11 |
diff --git a/gobject/Makefile.inc b/gobject/Makefile.inc
|
|
|
022f11 |
index 69f7215..17da527 100644
|
|
|
022f11 |
--- a/gobject/Makefile.inc
|
|
|
022f11 |
+++ b/gobject/Makefile.inc
|
|
|
022f11 |
@@ -51,6 +51,7 @@ guestfs_gobject_headers= \
|
|
|
022f11 |
include/guestfs-gobject/optargs-inspect_get_icon.h \
|
|
|
022f11 |
include/guestfs-gobject/optargs-mount_local.h \
|
|
|
022f11 |
include/guestfs-gobject/optargs-umount_local.h \
|
|
|
022f11 |
+ include/guestfs-gobject/optargs-add_drive_scratch.h \
|
|
|
022f11 |
include/guestfs-gobject/optargs-is_file.h \
|
|
|
022f11 |
include/guestfs-gobject/optargs-is_dir.h \
|
|
|
022f11 |
include/guestfs-gobject/optargs-umount.h \
|
|
|
022f11 |
@@ -123,6 +124,7 @@ guestfs_gobject_sources= \
|
|
|
022f11 |
src/optargs-inspect_get_icon.c \
|
|
|
022f11 |
src/optargs-mount_local.c \
|
|
|
022f11 |
src/optargs-umount_local.c \
|
|
|
022f11 |
+ src/optargs-add_drive_scratch.c \
|
|
|
022f11 |
src/optargs-is_file.c \
|
|
|
022f11 |
src/optargs-is_dir.c \
|
|
|
022f11 |
src/optargs-umount.c \
|
|
|
022f11 |
diff --git a/po/POTFILES b/po/POTFILES
|
|
|
022f11 |
index bc4be6f..e2e63a2 100644
|
|
|
022f11 |
--- a/po/POTFILES
|
|
|
022f11 |
+++ b/po/POTFILES
|
|
|
022f11 |
@@ -150,6 +150,7 @@ fuse/guestunmount.c
|
|
|
022f11 |
fuse/test-guestunmount-fd.c
|
|
|
022f11 |
gobject/src/optargs-add_domain.c
|
|
|
022f11 |
gobject/src/optargs-add_drive.c
|
|
|
022f11 |
+gobject/src/optargs-add_drive_scratch.c
|
|
|
022f11 |
gobject/src/optargs-btrfs_filesystem_resize.c
|
|
|
022f11 |
gobject/src/optargs-btrfs_fsck.c
|
|
|
022f11 |
gobject/src/optargs-compress_device_out.c
|
|
|
022f11 |
diff --git a/src/drives.c b/src/drives.c
|
|
|
022f11 |
index df6f7e0..3854961 100644
|
|
|
022f11 |
--- a/src/drives.c
|
|
|
022f11 |
+++ b/src/drives.c
|
|
|
022f11 |
@@ -33,6 +33,7 @@
|
|
|
022f11 |
#include <netdb.h>
|
|
|
022f11 |
#include <arpa/inet.h>
|
|
|
022f11 |
#include <assert.h>
|
|
|
022f11 |
+#include <sys/types.h>
|
|
|
022f11 |
|
|
|
022f11 |
#include <pcre.h>
|
|
|
022f11 |
|
|
|
022f11 |
@@ -1072,6 +1073,58 @@ guestfs__add_drive_ro_with_if (guestfs_h *g, const char *filename,
|
|
|
022f11 |
}
|
|
|
022f11 |
|
|
|
022f11 |
int
|
|
|
022f11 |
+guestfs__add_drive_scratch (guestfs_h *g, int64_t size,
|
|
|
022f11 |
+ const struct guestfs_add_drive_scratch_argv *optargs)
|
|
|
022f11 |
+{
|
|
|
022f11 |
+ struct guestfs_add_drive_opts_argv add_drive_optargs;
|
|
|
022f11 |
+ CLEANUP_FREE char *filename = NULL;
|
|
|
022f11 |
+ int fd;
|
|
|
022f11 |
+
|
|
|
022f11 |
+ /* Some parameters we always set. */
|
|
|
022f11 |
+ add_drive_optargs.bitmask = GUESTFS_ADD_DRIVE_OPTS_FORMAT_BITMASK;
|
|
|
022f11 |
+ add_drive_optargs.format = "raw";
|
|
|
022f11 |
+
|
|
|
022f11 |
+ /* Copy the optional arguments through to guestfs_add_drive_opts. */
|
|
|
022f11 |
+ if (optargs->bitmask & GUESTFS_ADD_DRIVE_SCRATCH_NAME_BITMASK) {
|
|
|
022f11 |
+ add_drive_optargs.bitmask |= GUESTFS_ADD_DRIVE_OPTS_NAME_BITMASK;
|
|
|
022f11 |
+ add_drive_optargs.name = optargs->name;
|
|
|
022f11 |
+ }
|
|
|
022f11 |
+ if (optargs->bitmask & GUESTFS_ADD_DRIVE_SCRATCH_LABEL_BITMASK) {
|
|
|
022f11 |
+ add_drive_optargs.bitmask |= GUESTFS_ADD_DRIVE_OPTS_LABEL_BITMASK;
|
|
|
022f11 |
+ add_drive_optargs.label = optargs->label;
|
|
|
022f11 |
+ }
|
|
|
022f11 |
+
|
|
|
022f11 |
+ /* Create the temporary file. We don't have to worry about cleanup
|
|
|
022f11 |
+ * because everything in g->tmpdir is 'rm -rf'd when the handle is
|
|
|
022f11 |
+ * closed.
|
|
|
022f11 |
+ */
|
|
|
022f11 |
+ if (guestfs___lazy_make_tmpdir (g) == -1)
|
|
|
022f11 |
+ return -1;
|
|
|
022f11 |
+ filename = safe_asprintf (g, "%s/scratch.%d", g->tmpdir, ++g->unique);
|
|
|
022f11 |
+
|
|
|
022f11 |
+ /* Create a raw format temporary disk. */
|
|
|
022f11 |
+ fd = open (filename, O_WRONLY|O_CREAT|O_TRUNC|O_NOCTTY|O_CLOEXEC, 0600);
|
|
|
022f11 |
+ if (fd == -1) {
|
|
|
022f11 |
+ perrorf (g, "open: %s", filename);
|
|
|
022f11 |
+ return -1;
|
|
|
022f11 |
+ }
|
|
|
022f11 |
+
|
|
|
022f11 |
+ if (ftruncate (fd, size) == -1) {
|
|
|
022f11 |
+ perrorf (g, "ftruncate: %s", filename);
|
|
|
022f11 |
+ close (fd);
|
|
|
022f11 |
+ return -1;
|
|
|
022f11 |
+ }
|
|
|
022f11 |
+
|
|
|
022f11 |
+ if (close (fd) == -1) {
|
|
|
022f11 |
+ perrorf (g, "close: %s", filename);
|
|
|
022f11 |
+ return -1;
|
|
|
022f11 |
+ }
|
|
|
022f11 |
+
|
|
|
022f11 |
+ /* Call guestfs_add_drive_opts to add the drive. */
|
|
|
022f11 |
+ return guestfs_add_drive_opts_argv (g, filename, &add_drive_optargs);
|
|
|
022f11 |
+}
|
|
|
022f11 |
+
|
|
|
022f11 |
+int
|
|
|
022f11 |
guestfs__add_cdrom (guestfs_h *g, const char *filename)
|
|
|
022f11 |
{
|
|
|
022f11 |
if (strchr (filename, ':') != NULL) {
|
|
|
022f11 |
--
|
|
|
022f11 |
1.8.3.1
|
|
|
022f11 |
|