summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xfish/test-a.sh16
-rw-r--r--generator/generator_actions.ml6
-rw-r--r--perl/t/070-optargs.t2
-rw-r--r--python/t/060-optargs.py2
-rw-r--r--python/t/rhbz811650.py10
-rw-r--r--src/launch.c19
6 files changed, 45 insertions, 10 deletions
diff --git a/fish/test-a.sh b/fish/test-a.sh
index 20cc5cd8..4a607907 100755
--- a/fish/test-a.sh
+++ b/fish/test-a.sh
@@ -21,25 +21,29 @@
set -e
rm -f test.out
+rm -f test1.img
-./guestfish -x -a /dev/null </dev/null >test.out 2>&1
+./guestfish sparse test1.img 100M
+
+./guestfish -x -a test1.img </dev/null >test.out 2>&1
! grep -sq 'add_drive.*format' test.out
-./guestfish -x --format=qcow2 -a /dev/null </dev/null >test.out 2>&1
+./guestfish -x --format=qcow2 -a test1.img </dev/null >test.out 2>&1
grep -sq 'add_drive.*format:qcow2' test.out
-./guestfish -x --ro --format=qcow2 -a /dev/null </dev/null >test.out 2>&1
+./guestfish -x --ro --format=qcow2 -a test1.img </dev/null >test.out 2>&1
grep -sq 'add_drive.*readonly:true.*format:qcow2' test.out
-./guestfish -x --format -a /dev/null </dev/null >test.out 2>&1
+./guestfish -x --format -a test1.img </dev/null >test.out 2>&1
! grep -sq 'add_drive.*format' test.out
-./guestfish -x -a /dev/null --format=qcow2 </dev/null >test.out 2>&1
+./guestfish -x -a test1.img --format=qcow2 </dev/null >test.out 2>&1
! grep -sq 'add_drive.*format' test.out
-rm -f test.out
+rm test.out
+rm test1.img
diff --git a/generator/generator_actions.ml b/generator/generator_actions.ml
index f249991e..3c8f5976 100644
--- a/generator/generator_actions.ml
+++ b/generator/generator_actions.ml
@@ -1075,7 +1075,11 @@ deprecated C<guestfs_add_drive_with_if> call (q.v.)
The name the drive had in the original guest, e.g. /dev/sdb. This is used as a
hint to the guest inspection process if it is available.
-=back");
+=back
+
+C<filename> can have the special value C</dev/null>, which means
+to add a null (zero length) raw format device. You can add C</dev/null>
+multiple times.");
("inspect_get_windows_systemroot", (RString "systemroot", [Device "root"], []), -1, [],
[],
diff --git a/perl/t/070-optargs.t b/perl/t/070-optargs.t
index 273a7fa7..978db920 100644
--- a/perl/t/070-optargs.t
+++ b/perl/t/070-optargs.t
@@ -30,5 +30,5 @@ ok (1);
$h->add_drive_opts ("/dev/null", readonly => 1);
ok (1);
-$h->add_drive_opts ("/dev/null", format => "qcow2", readonly => 0);
+$h->add_drive_opts ("/dev/null", format => "raw", readonly => 0);
ok (1);
diff --git a/python/t/060-optargs.py b/python/t/060-optargs.py
index 75ea06f3..be28a3ce 100644
--- a/python/t/060-optargs.py
+++ b/python/t/060-optargs.py
@@ -21,5 +21,5 @@ import guestfs
g = guestfs.GuestFS()
g.add_drive_opts ("/dev/null")
g.add_drive_opts ("/dev/null", readonly = 1)
-g.add_drive_opts ("/dev/null", iface = "virtio", format = "qcow2")
+g.add_drive_opts ("/dev/null", iface = "virtio", format = "raw")
g.close ()
diff --git a/python/t/rhbz811650.py b/python/t/rhbz811650.py
index 84daf0fe..cf01673f 100644
--- a/python/t/rhbz811650.py
+++ b/python/t/rhbz811650.py
@@ -15,11 +15,17 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+import os
import guestfs
+f = open ("test.img", "w")
+f.truncate (500 * 1024 * 1024)
+f.close ()
+
g = guestfs.GuestFS ()
-g.add_drive_opts ("/dev/null", format="qcow2");
+# Deliberate error: the disk format is supposed to be raw.
+g.add_drive_opts ("test.img", format="qcow2");
# Because error() wasn't being called, guestfs_last_error would return
# NULL, causing a segfault in the Python bindings (RHBZ#811650).
@@ -27,3 +33,5 @@ try:
g.launch ()
except:
pass
+
+os.unlink ("test.img")
diff --git a/src/launch.c b/src/launch.c
index 72eca511..cd785014 100644
--- a/src/launch.c
+++ b/src/launch.c
@@ -347,6 +347,7 @@ guestfs__add_drive_opts (guestfs_h *g, const char *filename,
char *iface;
char *name;
int use_cache_off;
+ int is_null;
if (strchr (filename, ':') != NULL) {
error (g, _("filename cannot contain ':' (colon) character. "
@@ -374,6 +375,24 @@ guestfs__add_drive_opts (guestfs_h *g, const char *filename,
goto err_out;
}
+ /* Traditionally you have been able to use /dev/null as a filename,
+ * as many times as you like. Treat this as a special case, because
+ * old versions of qemu have some problems.
+ */
+ is_null = STREQ (filename, "/dev/null");
+ if (is_null) {
+ if (format && STRNEQ (format, "raw")) {
+ error (g, _("for device '/dev/null', format must be 'raw'"));
+ goto err_out;
+ }
+ /* Ancient KVM (RHEL 5) cannot handle the case where we try to add
+ * a snapshot on top of /dev/null. Modern qemu can handle it OK,
+ * but the device size is still 0, so it shouldn't matter whether
+ * or not this is readonly.
+ */
+ readonly = 0;
+ }
+
/* For writable files, see if we can use cache=off. This also
* checks for the existence of the file. For readonly we have
* to do the check explicitly.