lib/create.c: Fix check after BLKDISCARD

We didn't correctly check for an error from the ioctl.  Thus when
using a raw block device you would often see a bogus warning in
debugging output.

Related: https://issues.redhat.com/browse/MTV-2441
This commit is contained in:
Richard W.M. Jones
2025-05-01 09:10:52 +01:00
parent 9b32056061
commit 59bad26898

View File

@@ -119,7 +119,7 @@ disk_create_raw_block (guestfs_h *g, const char *filename)
if (ioctl (fd, BLKGETSIZE64, &size) == 0) {
range[0] = 0;
range[1] = size;
if (ioctl (fd, BLKDISCARD, range) == 0)
if (ioctl (fd, BLKDISCARD, range) == -1)
debug (g, "disk_create: %s: BLKDISCARD failed on this device: %m",
filename);
}