Skip to contentSkip to conversation

block: avoid creating too large iovecs in multiwrite_merge

PATCH Applied Christoph Hellwig 2 participants 3 messages Jan 26, 2010 – Feb 1, 2010

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 block: avoid creating too large iovecs in multiwrite_merge

If we go over the maximum number of iovecs support by syscall we get back EINVAL from the kernel which translate to I/O errors for the guest.

Add a MAX_IOV defintion for platforms that don't have it. For now we use the same 1024 define that's used on Linux and various other platforms, but until the windows block backend implements some kind of vectored I/O it doesn't matter.

block.c +4 -0
Index: qemu/block.c
===================================================================
@@ -1689,6 +1689,10 @@ static int multiwrite_merge(BlockDriverS
             merge = bs->drv->bdrv_merge_requests(bs, &reqs[outidx], &reqs[i]);
         }
 
+        if (reqs[outidx].qiov->niov + reqs[i].qiov->niov + 1 > IOV_MAX) {
+            merge = 0;
+        }
+
         if (merge) {
             size_t size;
             QEMUIOVector *qiov = qemu_mallocz(sizeof(*qiov));
qemu-common.h +4 -0
Index: qemu/qemu-common.h
===================================================================
@@ -54,6 +54,10 @@ struct iovec {
     void *iov_base;
     size_t iov_len;
 };
+/*
+ * Use the same value as Linux for now.
+ */
+#define IOV_MAX		1024
 #else
 #include <sys/uio.h>
 #endif
#1 lore raw
Quoted 10 lines · Christoph Hellwig

If we go over the maximum number of iovecs support by syscall we get back EINVAL from the kernel which translate to I/O errors for the guest.

Add a MAX_IOV defintion for platforms that don't have it. For now we use the same 1024 define that's used on Linux and various other platforms, but until the windows block backend implements some kind of vectored I/O it doesn't matter.

Applied. Thanks.

Regards,

Anthony Liguori

Quoted 34 lines

Index: qemu/block.c
===================================================================

block.c +4 -0
@@ -1689,6 +1689,10 @@ static int multiwrite_merge(BlockDriverS
              merge = bs->drv->bdrv_merge_requests(bs,&reqs[outidx],&reqs[i]);
          }
 
+        if (reqs[outidx].qiov->niov + reqs[i].qiov->niov + 1>  IOV_MAX) {
+            merge = 0;
+        }
+
          if (merge) {
              size_t size;
              QEMUIOVector *qiov = qemu_mallocz(sizeof(*qiov));

Index: qemu/qemu-common.h
===================================================================

qemu-common.h +4 -0
@@ -54,6 +54,10 @@ struct iovec {
      void *iov_base;
      size_t iov_len;
  };
+/*
+ * Use the same value as Linux for now.
+ */
+#define IOV_MAX		1024
  #else
  #include<sys/uio.h>
  #endif
#2 lore raw
Quoted 9 lines · Anthony Liguori
Quoted 8 lines · Christoph Hellwig

If we go over the maximum number of iovecs support by syscall we get back EINVAL from the kernel which translate to I/O errors for the guest.

Add a MAX_IOV defintion for platforms that don't have it. For now we use the same 1024 define that's used on Linux and various other platforms, but until the windows block backend implements some kind of vectored I/O it doesn't matter.

Quoted 4 lines
Quoted 2 lines

Applied. Thanks.

Can you also add it to the 0.12-stable series? There's tons of bug reports from users seeing this regression in qemu-0.12.