From 1414c3fa8e12604a35e2c299dcac13830a419aaf Mon Sep 17 00:00:00 2001 From: Edward Hope-Morley Date: Mon, 19 Aug 2013 14:22:11 +0100 Subject: [PATCH] Add rbd store support for zero size image If glanceclient does not provide image size to RBD store add() it will create a zero-size image and fail when writing to it. If provided with zero size we now work out the size of each chunk being written and resize the rbd image prior to each write. This will be much slower than if new the image size on create but it will at least work. There is a corresponding glanceclient fix to ensure content-length is set if known by the glanceclient, see bug 1220197 Change-Id: I014c4b71c77c92b9876786d1ba438cdb90f83233 Fixes: bug #1213880 --- glance/store/rbd.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/glance/store/rbd.py b/glance/store/rbd.py index 4d2649f9f5..9cb63d3b59 100644 --- a/glance/store/rbd.py +++ b/glance/store/rbd.py @@ -305,7 +305,13 @@ class Store(glance.store.base.Store): fsid = conn.get_fsid() with conn.open_ioctx(self.pool) as ioctx: order = int(math.log(self.chunk_size, 2)) - LOG.debug('creating image %s with order %d', image_name, order) + LOG.debug('creating image %s with order %d and size %d', + image_name, order, image_size) + if image_size == 0: + LOG.warning(_("since image size is zero we will be doing " + "resize-before-write for each chunk which " + "will be considerably slower than normal")) + try: loc = self._create_image(fsid, ioctx, image_name, image_size, order) @@ -318,6 +324,17 @@ class Store(glance.store.base.Store): chunks = utils.chunkreadable(image_file, self.chunk_size) for chunk in chunks: + # If the image size provided is zero we need to do + # a resize for the amount we are writing. This will + # be slower so setting a higher chunk size may + # speed things up a bit. + if image_size == 0: + length = offset + len(chunk) + LOG.debug(_("resizing image to %s KiB") % + (length / 1024)) + image.resize(length) + LOG.debug(_("writing chunk at offset %s") % + (offset)) offset += image.write(chunk, offset) checksum.update(chunk) if loc.snapshot: