Comment 4 for bug 810493

Lothar Gesslein (lgesslein) wrote :

I've written patches to scratch our own itch that make glance write raw sparse files to disk and that make nova-compute write raw sparse files to disk. They do not change the transport format, so all zeros still go uncompressed over the network. Obviously this needs some more work to make it an configuration option and maybe someone has a faster way to check for all-zeros blocks.


diff --git a/glance/store/ b/glance/store/
index 6f028b7..b5ba775 100644
--- a/glance/store/
+++ b/glance/store/
@@ -24,6 +24,7 @@ import hashlib
 import logging
 import os
 import urlparse
+import re

 from glance.common import cfg
 from glance.common import exception
@@ -197,13 +198,18 @@ class Store(

         checksum = hashlib.md5()
         bytes_written = 0
+ CHECK_RE = re.compile('^[0]*$')
             with open(filepath, 'wb') as f:
                 for buf in utils.chunkreadable(image_file,
                     bytes_written += len(buf)
- f.write(buf)
+ if CHECK_RE.match(buf.encode("hex")):
+ f.truncate()
+ else:
+ f.write(buf)
         except IOError as e:
             if e.errno in [errno.EFBIG, errno.ENOSPC]:
                 raise exception.StorageFull()


diff --git a/nova/image/ b/nova/image/
index 97a60cb..10b3a76 100644
--- a/nova/image/
+++ b/nova/image/
@@ -26,6 +26,7 @@ import random
 import sys
 import time
 import urlparse
+import re

 from glance.common import exception as glance_exception

@@ -262,8 +263,13 @@ class GlanceImageService(object):
         except Exception:

+ CHECK_RE = re.compile('^[0]*$')
         for chunk in image_chunks:
- data.write(chunk)
+ if CHECK_RE.match(chunk.encode("hex")):
+ data.truncate()
+ else:
+ data.write(chunk)

         base_image_meta = self._translate_from_glance(image_meta)
         return base_image_meta