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.

Glance:

diff --git a/glance/store/filesystem.py b/glance/store/filesystem.py
index 6f028b7..b5ba775 100644
--- a/glance/store/filesystem.py
+++ b/glance/store/filesystem.py
@@ -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(glance.store.base.Store):

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

Nova:

diff --git a/nova/image/glance.py b/nova/image/glance.py
index 97a60cb..10b3a76 100644
--- a/nova/image/glance.py
+++ b/nova/image/glance.py
@@ -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:
             _reraise_translated_image_exception(image_id)

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

         base_image_meta = self._translate_from_glance(image_meta)
         return base_image_meta