Make the cow file size equal to the original media
authorNikos Skalkotos <skalkoto@grnet.gr>
Fri, 24 Aug 2012 09:48:18 +0000 (12:48 +0300)
committerNikos Skalkotos <skalkoto@grnet.gr>
Fri, 24 Aug 2012 09:48:18 +0000 (12:48 +0300)
The size of the cow file was hardcoded to 1G. This was buggy, because
for a big image, the resize operation could fill up the cow file and
fail.

image_creator/disk.py

index 7e3b166..c367efd 100644 (file)
@@ -114,12 +114,12 @@ class Disk(object):
 
         # Take a snapshot and return it to the user
         self.out.output("Snapshotting media source...", False)
-        size = blockdev('--getsize', sourcedev)
+        size = blockdev('--getsz', sourcedev)
         cowfd, cow = tempfile.mkstemp()
         os.close(cowfd)
         self._add_cleanup(os.unlink, cow)
-        # Create 1G cow sparse file
-        dd('if=/dev/null', 'of=%s' % cow, 'bs=1k', 'seek=%d' % (1024 * 1024))
+        # Create cow sparse file
+        dd('if=/dev/null', 'of=%s' % cow, 'bs=512', 'seek=%d' % int(size))
         cowdev = self._losetup(cow)
 
         snapshot = uuid.uuid4().hex