"qemu-img convert" tries to create the destination image by calling it's
->create function. host_devices do not currently have one, since host
devices are not created like normal images are. A reasonable analog of
create for host devices is verifying that they have the appropriate
properties.
This patch adds that verification.
It also fixes a typo that caused qemu-img to print the wrong device type
in the error message informing the user that the destination device did
not support creation.
Signed-off-by: Nolan Leake <nolan <at> sigbus.net>
Index: block-raw-posix.c
===================================================================
--- block-raw-posix.c (revision 6718)
+++ block-raw-posix.c (working copy)
@@ -1132,6 +1132,32 @@
return ioctl(s->fd, req, buf);
}
+
+static int hdev_create(const char *filename, int64_t total_size,
+ const char *backing_file, int flags)
+{
+ int fd;
+ int ret = 0;
+ struct stat stat_buf;
+
+ if (flags || backing_file)
+ return -ENOTSUP;
+
+ fd = open(filename, O_WRONLY | O_BINARY);
+ if (fd < 0)
+ return -EIO;
+
+ if (fstat(fd, &stat_buf) < 0)
+ ret = -EIO;
+ else if (!S_ISBLK(stat_buf.st_mode))
+ ret = -EIO;
+ else if (lseek(fd, 0, SEEK_END) < total_size * 512)
+ ret = -ENOSPC;
+
+ close(fd);
+ return ret;
+}