qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] RFC: raw device support for block device targets
@ 2011-12-06 16:20 Alex Bligh
  2011-12-06 18:42 ` Christoph Hellwig
  2011-12-08 12:40 ` Kevin Wolf
  0 siblings, 2 replies; 7+ messages in thread
From: Alex Bligh @ 2011-12-06 16:20 UTC (permalink / raw)
  To: qemu-devel; +Cc: Alex Bligh

qemu-img convert appears to support block devices as input, but not
as output. That is irritating, as when using qemu-img convert to
convert qcow to raw on a block partition, an intermediate file has
to be used, which slows things down and pointlessly uses disk space.

The problem is that ftruncate() is being called on the output file
in order ensure it is sufficiently large, and this fails on
block devices.

I appreciate there may be other calls that fail depending on the
input file format, but these will presumably be error checked
at the time.

Is it therefore worth skipping the ftruncate() if the block device
is large enough, and at least attempting to proceed further? Something
like the following (not-even compile tested) patch?

-- 
Alex Bligh

Signed-Off-By: Alex Bligh <alex@alex.org.uk>

diff --git a/block/raw-posix.c b/block/raw-posix.c
index 2ee5d69..be9a371 100644
--- a/block/raw-posix.c
+++ b/block/raw-posix.c
@@ -573,9 +573,29 @@ static int raw_create(const char *filename, 
QEMUOptionParameter *options)
     if (fd < 0) {
         result = -errno;
     } else {
+
+        struct stat sb;
+
+        if (-1 == fstat(dest, &sb)) {
+            result = -errno;
+            goto close;
+        }
+
+        /* block devices do not support truncate. If the device is large
+           enough, then it will do */
+
+        if (S_ISBLK(sb.st_mode)) {
+            /* divide to prevent overflow */
+            if (sb.st_size / BDRV_SECTOR_SIZE < total_size)
+                result = -ENOSPC;
+            goto close;
+        }
+
         if (ftruncate(fd, total_size * BDRV_SECTOR_SIZE) != 0) {
             result = -errno;
         }
+
+    close:
         if (close(fd) != 0) {
             result = -errno;
         }

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2011-12-12 10:32 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-12-06 16:20 [Qemu-devel] RFC: raw device support for block device targets Alex Bligh
2011-12-06 18:42 ` Christoph Hellwig
2011-12-06 19:28   ` Alex Bligh
2011-12-08 12:40 ` Kevin Wolf
2011-12-11 10:45   ` Alex Bligh
2011-12-12  9:48     ` Kevin Wolf
2011-12-12 10:32       ` Alex Bligh

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).