From: Richard Jones Date: Tue, 2 Jun 2009 13:24:16 +0000 (+0100) Subject: Add 'add_drive_ro' call. Fix up documentation. Plus a couple of minor code improvemen... X-Git-Tag: 1.0.38~2 X-Git-Url: http://git.annexia.org/?a=commitdiff_plain;h=bfdc03be234d6d95f18450846433bce4f97e184c;p=libguestfs.git Add 'add_drive_ro' call. Fix up documentation. Plus a couple of minor code improvements in the tests. --- diff --git a/inspector/virt-inspector.pl b/inspector/virt-inspector.pl index 4ee0e08..6d3c472 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 a80e846..bb3744e 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. This +stops you from specifying other types of drive which are supported +by qemu such as C and C URLs. To specify those, use +the general C 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. This +stops you from specifying other types of drive which are supported +by qemu such as C and C URLs. To specify those, use +the general C 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. This +stops you from specifying other types of drive which are supported +by qemu such as C and C URLs. To specify those, use +the general C 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 c5056d4..fea8107 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) {