diff options
author | Richard Jones <rjones@redhat.com> | 2010-03-16 21:50:13 +0000 |
---|---|---|
committer | Richard Jones <rjones@redhat.com> | 2010-03-16 21:50:13 +0000 |
commit | 676462684e05dd8341dd695762dd99a87d8ec022 (patch) | |
tree | bf1e674da820e27c1a4b512bd719fa1323506679 /src/guestfs.c | |
parent | 5442f45aea522a728fa5b06396d4f08d8506d7de (diff) | |
download | libguestfs-676462684e05dd8341dd695762dd99a87d8ec022.tar.gz libguestfs-676462684e05dd8341dd695762dd99a87d8ec022.tar.xz libguestfs-676462684e05dd8341dd695762dd99a87d8ec022.zip |
add_drive_ro adds readonly=on option if available.
Change the add_drive_ro call so it adds the readonly=on option
if qemu supports that.
This just means that qemu will not try to open the drive with
O_RDWR, and should not otherwise change the behaviour of qemu or
libguestfs. (In particular, writes to the read-only drive are
still permitted, and are just discarded when the handle is closed).
However it should alleviate RHBZ#571714 where udev was deciding
to incorrectly relabel a device because we had opened the device
for writing (even though we didn't actually write to it).
Diffstat (limited to 'src/guestfs.c')
-rw-r--r-- | src/guestfs.c | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/src/guestfs.c b/src/guestfs.c index af60699d..02d5fdbf 100644 --- a/src/guestfs.c +++ b/src/guestfs.c @@ -792,9 +792,6 @@ int 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; @@ -805,7 +802,24 @@ guestfs__add_drive_ro_with_if (guestfs_h *g, const char *filename, return -1; } - snprintf (buf, len, "file=%s,snapshot=on,if=%s", filename, drive_if); + 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); return guestfs__config (g, "-drive", buf); } |