qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com, sitsofe@yahoo.com, qemu-block@nongnu.org,
	mreitz@redhat.com
Subject: [Qemu-devel] [PATCH 2/2] nbd: do not exit on failed memory allocation
Date: Thu,  7 Jan 2016 14:44:26 +0100	[thread overview]
Message-ID: <1452174266-11594-3-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1452174266-11594-1-git-send-email-pbonzini@redhat.com>

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.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 block/block-backend.c          | 5 +++++
 include/sysemu/block-backend.h | 1 +
 nbd.c                          | 6 +++++-
 3 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/block/block-backend.c b/block/block-backend.c
index f41d326..e813759 100644
--- a/block/block-backend.c
+++ b/block/block-backend.c
@@ -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);
diff --git a/include/sysemu/block-backend.h b/include/sysemu/block-backend.h
index dc24476..1568554 100644
--- a/include/sysemu/block-backend.h
+++ b/include/sysemu/block-backend.h
@@ -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);
diff --git a/nbd.c b/nbd.c
index e395a16..7dc58a9 100644
--- a/nbd.c
+++ b/nbd.c
@@ -1245,7 +1245,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);
-- 
2.5.0

  parent reply	other threads:[~2016-01-07 13:44 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-07 13:44 [Qemu-devel] [PATCH 0/2] nbd: changes around allocating buffers for requests Paolo Bonzini
2016-01-07 13:44 ` [Qemu-devel] [PATCH 1/2] nbd: do not check request length except for reads and writes Paolo Bonzini
2016-01-07 21:17   ` Max Reitz
2016-01-07 13:44 ` Paolo Bonzini [this message]
2016-01-07 21:25   ` [Qemu-devel] [PATCH 2/2] nbd: do not exit on failed memory allocation Max Reitz
2016-02-08 14:56 ` [Qemu-devel] [Qemu-block] [PATCH 0/2] nbd: changes around allocating buffers for requests Stefan Hajnoczi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1452174266-11594-3-git-send-email-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=sitsofe@yahoo.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).