[Fedora-livecd-list] 4 commits - imgcreate/creator.py imgcreate/fs.py
Jeremy Katz
katzj at fedoraproject.org
Mon Jul 6 18:44:40 UTC 2009
imgcreate/creator.py | 2 -
imgcreate/fs.py | 62 +++++++++++++++++++++++++++------------------------
2 files changed, 35 insertions(+), 29 deletions(-)
New commits:
commit 6a3849d072b142f6c5c5bba07dd6521a1ef0c03a
Author: Jeremy Katz <katzj at redhat.com>
Date: Mon Jul 6 14:29:30 2009 -0400
Store a copy of the filesystem image before resize
Save a copy of an e2image before we do the resize so that if it
fails, people can have something to provide via bugzilla
diff --git a/imgcreate/fs.py b/imgcreate/fs.py
index c19e8a0..c536de3 100644
--- a/imgcreate/fs.py
+++ b/imgcreate/fs.py
@@ -25,6 +25,7 @@ import subprocess
import random
import string
import logging
+import tempfile
from imgcreate.errors import *
@@ -56,6 +57,9 @@ def resize2fs(fs, size = None, minimal = False):
raise RuntimeError("Must specify either a size or minimal for resize!")
e2fsck(fs)
+ (fd, saved_image) = tempfile.mkstemp("", "resize-image-", "/tmp")
+ os.close(fd)
+ subprocess.call(["/sbin/e2image", "-r", fs, saved_image])
dev_null = os.open("/dev/null", os.O_WRONLY)
args = ["/sbin/resize2fs", fs]
@@ -72,7 +76,8 @@ def resize2fs(fs, size = None, minimal = False):
return ret
if e2fsck(fs) != 0:
- raise CreatorError("fsck after resize returned an error!")
+ raise CreatorError("fsck after resize returned an error! image to debug at %s" %(saved_image,))
+ os.unlink(saved_image)
return 0
def e2fsck(fs):
commit 44c17e8655e2787d3bb2fdc5ab32be18526ce284
Author: Jeremy Katz <katzj at redhat.com>
Date: Mon Jul 6 14:26:43 2009 -0400
Consolidate calls to fsck
We always want to fsck before/after resizing, so just do it in
the resize method rather than having it scattered everywhere.
diff --git a/imgcreate/fs.py b/imgcreate/fs.py
index 567376a..c19e8a0 100644
--- a/imgcreate/fs.py
+++ b/imgcreate/fs.py
@@ -54,6 +54,9 @@ def resize2fs(fs, size = None, minimal = False):
raise RuntimeError("Can't specify both minimal and a size for resize!")
if not minimal and size is None:
raise RuntimeError("Must specify either a size or minimal for resize!")
+
+ e2fsck(fs)
+
dev_null = os.open("/dev/null", os.O_WRONLY)
args = ["/sbin/resize2fs", fs]
if minimal:
@@ -61,9 +64,21 @@ def resize2fs(fs, size = None, minimal = False):
else:
args.append("%sK" %(size / 1024,))
try:
- return subprocess.call(args, stdout = dev_null, stderr = dev_null)
+ ret = subprocess.call(args, stdout = dev_null, stderr = dev_null)
finally:
os.close(dev_null)
+
+ if ret != 0:
+ return ret
+
+ if e2fsck(fs) != 0:
+ raise CreatorError("fsck after resize returned an error!")
+ return 0
+
+def e2fsck(fs):
+ logging.debug("Checking filesystem %s" % fs)
+ rc = subprocess.call(["/sbin/e2fsck", "-f", "-y", fs])
+ return rc
class BindChrootMount:
"""Represents a bind mount of a directory into a chroot."""
@@ -402,11 +417,7 @@ class ExtDiskMount(DiskMount):
if size > current_size:
self.disk.expand(size)
- self.__fsck()
-
resize2fs(self.disk.lofile, size)
-
- self.__fsck()
return size
def __create(self):
@@ -426,8 +437,7 @@ class ExtDiskMount(DiskMount):
DiskMount.mount(self)
def __fsck(self):
- logging.debug("Checking filesystem %s" % self.disk.lofile)
- rc = subprocess.call(["/sbin/e2fsck", "-f", "-y", self.disk.lofile])
+ return e2fsck(self.disk.lofile)
return rc
def __get_size_from_filesystem(self):
@@ -449,12 +459,8 @@ class ExtDiskMount(DiskMount):
return int(parse_field(out, "Block count")) * self.blocksize
def __resize_to_minimal(self):
- self.__fsck()
resize2fs(self.disk.lofile, minimal = True)
- min = self.__get_size_from_filesystem()
- if self.__fsck() != 0:
- raise CreatorError("fsck returned an error!")
- return min
+ return self.__get_size_from_filesystem()
def resparse(self, size = None):
self.cleanup()
commit 1e5e6019a058c6acde0b4cb85a21cac4d7b66a60
Author: Jeremy Katz <katzj at redhat.com>
Date: Mon Jul 6 13:49:14 2009 -0400
Use resize2fs -M instead of binary search
esandeen got a "resize to minimal size" option added to resize2fs,
so we should use it rather than our bisecting down to a minimal
size. And maybe then we'll hit fewer resize2fs bugs.
diff --git a/imgcreate/fs.py b/imgcreate/fs.py
index 65f16e4..567376a 100644
--- a/imgcreate/fs.py
+++ b/imgcreate/fs.py
@@ -49,11 +49,19 @@ def mksquashfs(in_img, out_img):
raise SquashfsError("'%s' exited with error (%d)" %
(string.join(args, " "), ret))
-def resize2fs(fs, size):
+def resize2fs(fs, size = None, minimal = False):
+ if minimal and size is not None:
+ raise RuntimeError("Can't specify both minimal and a size for resize!")
+ if not minimal and size is None:
+ raise RuntimeError("Must specify either a size or minimal for resize!")
dev_null = os.open("/dev/null", os.O_WRONLY)
+ args = ["/sbin/resize2fs", fs]
+ if minimal:
+ args.append("-M")
+ else:
+ args.append("%sK" %(size / 1024,))
try:
- return subprocess.call(["/sbin/resize2fs", fs, "%sK" % (size / 1024,)],
- stdout = dev_null, stderr = dev_null)
+ return subprocess.call(args, stdout = dev_null, stderr = dev_null)
finally:
os.close(dev_null)
@@ -442,24 +450,11 @@ class ExtDiskMount(DiskMount):
def __resize_to_minimal(self):
self.__fsck()
-
- #
- # Use a binary search to find the minimal size
- # we can resize the image to
- #
- bot = 0
- top = self.__get_size_from_filesystem()
- while top != (bot + 1):
- t = bot + ((top - bot) / 2)
-
- if not resize2fs(self.disk.lofile, t):
- top = t
- else:
- bot = t
-
+ resize2fs(self.disk.lofile, minimal = True)
+ min = self.__get_size_from_filesystem()
if self.__fsck() != 0:
raise CreatorError("fsck returned an error!")
- return top
+ return min
def resparse(self, size = None):
self.cleanup()
commit 0b0d40f7bdfc05c3220f44eec9bbb37bd8475587
Author: Jeremy Katz <katzj at redhat.com>
Date: Mon Jun 29 10:58:42 2009 -0400
Don't error out with SELinux disabled on the host (#508402)
diff --git a/imgcreate/creator.py b/imgcreate/creator.py
index 1f8971f..910c778 100644
--- a/imgcreate/creator.py
+++ b/imgcreate/creator.py
@@ -433,7 +433,7 @@ class ImageCreator(object):
def __getbooleans(self):
booleans = []
- if not kickstart.selinux_enabled(self.ks):
+ if not kickstart.selinux_enabled(self.ks) or not os.path.exists("/selinux/enforce"):
return booleans
for i in selinux.security_get_boolean_names()[1]:
on = selinux.security_get_boolean_active(i)
More information about the livecd
mailing list