]> git.proxmox.com Git - mirror_qemu.git/commitdiff
nbd-server: do not exit on failed memory allocation
authorPaolo Bonzini <pbonzini@redhat.com>
Thu, 7 Jan 2016 13:34:13 +0000 (14:34 +0100)
committerPaolo Bonzini <pbonzini@redhat.com>
Fri, 15 Jan 2016 17:58:02 +0000 (18:58 +0100)
The amount of memory allocated in nbd_co_receive_request is driven by the
NBD client (possibly a virtual machine).  Parallel I/O can cause the
server to allocate a large amount of memory; check for failures and
return ENOMEM in that case.

Cc: qemu-block@nongnu.org
Reviewed-by: Max Reitz <mreitz@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
block/block-backend.c
include/sysemu/block-backend.h
nbd/server.c

index f41d326b3c4eb3a5067de6793c120a81c02eef0f..e81375955f38f6d8e65712378c959d1492cb446e 100644 (file)
@@ -1033,6 +1033,11 @@ void blk_set_guest_block_size(BlockBackend *blk, int align)
     blk->guest_block_size = align;
 }
 
+void *blk_try_blockalign(BlockBackend *blk, size_t size)
+{
+    return qemu_try_blockalign(blk ? blk->bs : NULL, size);
+}
+
 void *blk_blockalign(BlockBackend *blk, size_t size)
 {
     return qemu_blockalign(blk ? blk->bs : NULL, size);
index dc244760a13696d61140ff201b525dd71d30e93e..1568554e3e12ff98f048572637642519752be256 100644 (file)
@@ -148,6 +148,7 @@ int blk_get_flags(BlockBackend *blk);
 int blk_get_max_transfer_length(BlockBackend *blk);
 int blk_get_max_iov(BlockBackend *blk);
 void blk_set_guest_block_size(BlockBackend *blk, int align);
+void *blk_try_blockalign(BlockBackend *blk, size_t size);
 void *blk_blockalign(BlockBackend *blk, size_t size);
 bool blk_op_is_blocked(BlockBackend *blk, BlockOpType op, Error **errp);
 void blk_op_unblock(BlockBackend *blk, BlockOpType op, Error *reason);
index c41af0debe9d6aa5bf53ada78c28ef34bb63f6d6..eead339a2cb9d008bc4d8f716a396013b5fb3a49 100644 (file)
@@ -836,7 +836,11 @@ static ssize_t nbd_co_receive_request(NBDRequest *req, struct nbd_request *reque
             goto out;
         }
 
-        req->data = blk_blockalign(client->exp->blk, request->len);
+        req->data = blk_try_blockalign(client->exp->blk, request->len);
+        if (req->data == NULL) {
+            rc = -ENOMEM;
+            goto out;
+        }
     }
     if (command == NBD_CMD_WRITE) {
         TRACE("Reading %u byte(s)", request->len);