qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Peter Lieven <pl@kamp.de>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com, pbonzini@redhat.com, Peter Lieven <pl@kamp.de>,
	stefanha@redhat.com
Subject: [Qemu-devel] [PATCH 2/2] block/iscsi: handle failure on malloc of the allocationmap
Date: Fri, 22 Aug 2014 11:26:07 +0200	[thread overview]
Message-ID: <1408699567-6940-3-git-send-email-pl@kamp.de> (raw)
In-Reply-To: <1408699567-6940-1-git-send-email-pl@kamp.de>

Signed-off-by: Peter Lieven <pl@kamp.de>
---
 block/iscsi.c |   22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)

diff --git a/block/iscsi.c b/block/iscsi.c
index ed883c3..131357c 100644
--- a/block/iscsi.c
+++ b/block/iscsi.c
@@ -325,6 +325,19 @@ static bool is_request_lun_aligned(int64_t sector_num, int nb_sectors,
     return 1;
 }
 
+static unsigned long *iscsi_allocationmap_init(IscsiLun *iscsilun)
+{
+    unsigned long *ptr;
+    ptr = bitmap_try_new(DIV_ROUND_UP(sector_lun2qemu(iscsilun->num_blocks,
+                                                      iscsilun),
+                                      iscsilun->cluster_sectors));
+    if (ptr == NULL) {
+        error_report("iSCSI: could not initialize allocationmap. "
+                     "Out of memory.");
+    }
+    return ptr;
+}
+
 static void iscsi_allocationmap_set(IscsiLun *iscsilun, int64_t sector_num,
                                     int nb_sectors)
 {
@@ -1413,9 +1426,7 @@ static int iscsi_open(BlockDriverState *bs, QDict *options, int flags,
         iscsilun->cluster_sectors = (iscsilun->bl.opt_unmap_gran *
                                      iscsilun->block_size) >> BDRV_SECTOR_BITS;
         if (iscsilun->lbprz && !(bs->open_flags & BDRV_O_NOCACHE)) {
-            iscsilun->allocationmap =
-                bitmap_new(DIV_ROUND_UP(bs->total_sectors,
-                                        iscsilun->cluster_sectors));
+            iscsilun->allocationmap = iscsi_allocationmap_init(iscsilun);
         }
     }
 
@@ -1508,10 +1519,7 @@ static int iscsi_truncate(BlockDriverState *bs, int64_t offset)
 
     if (iscsilun->allocationmap != NULL) {
         g_free(iscsilun->allocationmap);
-        iscsilun->allocationmap =
-            bitmap_new(DIV_ROUND_UP(sector_lun2qemu(iscsilun->num_blocks,
-                                                    iscsilun),
-                                    iscsilun->cluster_sectors));
+        iscsilun->allocationmap = iscsi_allocationmap_init(iscsilun);
     }
 
     return 0;
-- 
1.7.9.5

  parent reply	other threads:[~2014-08-22  9:26 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-22  9:26 [Qemu-devel] [PATCH 0/2] introduce bitmap_try_new Peter Lieven
2014-08-22  9:26 ` [Qemu-devel] [PATCH 1/2] util: " Peter Lieven
2014-08-25 15:09   ` Eric Blake
2014-09-05 20:00     ` Peter Lieven
2014-09-05 22:17       ` Eric Blake
2014-08-22  9:26 ` Peter Lieven [this message]
2014-08-25 10:37   ` [Qemu-devel] [PATCH 2/2] block/iscsi: handle failure on malloc of the allocationmap Paolo Bonzini
2014-08-25 11:10     ` Peter Lieven
2014-08-25 11:20       ` Paolo Bonzini
2014-08-25 11:26         ` Peter Lieven
2014-08-25 11:42           ` Paolo Bonzini

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=1408699567-6940-3-git-send-email-pl@kamp.de \
    --to=pl@kamp.de \
    --cc=kwolf@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.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).