summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Jones <rjones@trick.home.annexia.org>2009-06-02 14:24:16 +0100
committerRichard Jones <rjones@trick.home.annexia.org>2009-06-02 14:24:16 +0100
commitbfdc03be234d6d95f18450846433bce4f97e184c (patch)
tree09e9395c190fd74ddda85dcc2affd7ac49252bb2
parent5abae435f0cb239b70878968e040d61a6730b897 (diff)
downloadlibguestfs-bfdc03be234d6d95f18450846433bce4f97e184c.tar.gz
libguestfs-bfdc03be234d6d95f18450846433bce4f97e184c.tar.xz
libguestfs-bfdc03be234d6d95f18450846433bce4f97e184c.zip
Add 'add_drive_ro' call. Fix up documentation. Plus a couple of minor code improvements in the tests.
-rwxr-xr-xinspector/virt-inspector.pl2
-rwxr-xr-xsrc/generator.ml40
-rw-r--r--src/guestfs.c21
3 files changed, 57 insertions, 6 deletions
diff --git a/inspector/virt-inspector.pl b/inspector/virt-inspector.pl
index 4ee0e08a..6d3c472f 100755
--- a/inspector/virt-inspector.pl
+++ b/inspector/virt-inspector.pl
@@ -213,7 +213,7 @@ if (-e $ARGV[0]) {
# We've now got the list of @images, so feed them to libguestfs.
my $g = Sys::Guestfs->new ();
-$g->add_drive ($_) foreach @images;
+$g->add_drive_ro ($_) foreach @images;
$g->launch ();
$g->wait_ready ();
diff --git a/src/generator.ml b/src/generator.ml
index a80e8466..bb3744ed 100755
--- a/src/generator.ml
+++ b/src/generator.ml
@@ -374,7 +374,12 @@ for whatever operations you want to perform (ie. read access if you
just want to read the image or write access if you want to modify the
image).
-This is equivalent to the qemu parameter C<-drive file=filename>.");
+This is equivalent to the qemu parameter C<-drive file=filename>.
+
+Note that this call checks for the existence of C<filename>. This
+stops you from specifying other types of drive which are supported
+by qemu such as C<nbd:> and C<http:> URLs. To specify those, use
+the general C<guestfs_config> call instead.");
("add_cdrom", (RErr, [String "filename"]), -1, [FishAlias "cdrom"],
[],
@@ -382,7 +387,33 @@ This is equivalent to the qemu parameter C<-drive file=filename>.");
"\
This function adds a virtual CD-ROM disk image to the guest.
-This is equivalent to the qemu parameter C<-cdrom filename>.");
+This is equivalent to the qemu parameter C<-cdrom filename>.
+
+Note that this call checks for the existence of C<filename>. This
+stops you from specifying other types of drive which are supported
+by qemu such as C<nbd:> and C<http:> URLs. To specify those, use
+the general C<guestfs_config> call instead.");
+
+ ("add_drive_ro", (RErr, [String "filename"]), -1, [FishAlias "add-ro"],
+ [],
+ "add a drive in snapshot mode (read-only)",
+ "\
+This adds a drive in snapshot mode, making it effectively
+read-only.
+
+Note that writes to the device are allowed, and will be seen for
+the duration of the guestfs handle, but they are written
+to a temporary file which is discarded as soon as the guestfs
+handle is closed. We don't currently have any method to enable
+changes to be committed, although qemu can support this.
+
+This is equivalent to the qemu parameter
+C<-drive file=filename,snapshot=on>.
+
+Note that this call checks for the existence of C<filename>. This
+stops you from specifying other types of drive which are supported
+by qemu such as C<nbd:> and C<http:> URLs. To specify those, use
+the general C<guestfs_config> call instead.");
("config", (RErr, [String "qemuparam"; OptString "qemuvalue"]), -1, [],
[],
@@ -3808,7 +3839,6 @@ int main (int argc, char *argv[])
{
char c = 0;
int failed = 0;
- const char *srcdir;
const char *filename;
int fd, i;
int nr_tests, test_num = 0;
@@ -3910,8 +3940,8 @@ int main (int argc, char *argv[])
exit (1);
}
- if (guestfs_add_drive (g, \"../images/test.sqsh\") == -1) {
- printf (\"guestfs_add_drive %%s FAILED\\n\", filename);
+ if (guestfs_add_drive_ro (g, \"../images/test.sqsh\") == -1) {
+ printf (\"guestfs_add_drive_ro ../images/test.sqsh FAILED\\n\");
exit (1);
}
diff --git a/src/guestfs.c b/src/guestfs.c
index c5056d44..fea8107d 100644
--- a/src/guestfs.c
+++ b/src/guestfs.c
@@ -670,6 +670,27 @@ guestfs_add_drive (guestfs_h *g, const char *filename)
}
int
+guestfs_add_drive_ro (guestfs_h *g, const char *filename)
+{
+ size_t len = strlen (filename) + 64;
+ char buf[len];
+
+ if (strchr (filename, ',') != NULL) {
+ error (g, _("filename cannot contain ',' (comma) character"));
+ return -1;
+ }
+
+ if (access (filename, F_OK) == -1) {
+ perrorf (g, "%s", filename);
+ return -1;
+ }
+
+ snprintf (buf, len, "file=%s,snapshot=on", filename);
+
+ return guestfs_config (g, "-drive", buf);
+}
+
+int
guestfs_add_cdrom (guestfs_h *g, const char *filename)
{
if (strchr (filename, ',') != NULL) {