----- Original Message -----
From: "David Lehman" <dlehman(a)redhat.com>
To: anaconda-patches(a)lists.fedorahosted.org
Sent: Monday, November 17, 2014 2:36:04 PM
Subject: [PATCH 1/5] Run fsck before obtaining minimum filesystem size. (#1162215)
resize2fs -P now requires an e2fsck -f first. The lack of a real minimum
size left us with no useful minInstanceSize and allowed users to attempt
a shrink down to any size, which led to failures.
If we have a currentSize, set the default minInstanceSize to that so
that a failure to obtain a true minInstanceSize from the fs tools
precludes shrinking the filesystem.
---
blivet/formats/fs.py | 28 +++++++++++++++++++++-------
1 file changed, 21 insertions(+), 7 deletions(-)
diff --git a/blivet/formats/fs.py b/blivet/formats/fs.py
index 0c6184d..9c75d2a 100644
--- a/blivet/formats/fs.py
+++ b/blivet/formats/fs.py
@@ -117,7 +117,12 @@ class FS(DeviceFormat):
if flags.installer_mode:
# if you want current/min size you have to call updateSizeInfo
- self.updateSizeInfo()
+ try:
+ self.updateSizeInfo()
+ except FSError:
+ log.warning("%s filesystem on %s needs repair", self.type,
+ self.device)
+ self._resizable = False
self._targetSize = self._size
@@ -220,8 +225,16 @@ class FS(DeviceFormat):
if not self.exists:
return
- info = self._getFSInfo()
- self._size = self._getExistingSize(info=info)
+ try:
+ self.doCheck()
This call here is for the benefit of resize2fs _only_? That is
ntfsresize -m does not require an fsck call beforehand, but this
is just done for uniformity?
This is an informational question as minSize is one of the tasks
that I'm working on, actually currently, because it was one of the trickier
to think about.
+ except FSError:
+ raise
+ finally:
+ # try to gather current size info anyway
+ info = self._getFSInfo()
+ self._size = self._getExistingSize(info=info)
+ self._minSize = self._size # default to current size
+
self._getMinSize(info=info) # force calculation of minimum size
def _getMinSize(self, info=None):
@@ -432,13 +445,12 @@ class FS(DeviceFormat):
if not self.device == "tmpfs" and not os.path.exists(self.device):
raise FSResizeError("device does not exist", self.device)
- self.doCheck()
-
# The first minimum size can be incorrect if the fs was not
# properly unmounted. After doCheck the minimum size will be correct
# so run the check one last time and bump up the size if it was too
# small.
self._minInstanceSize = Size(0)
+ self.updateSizeInfo()
if self.targetSize < self.minSize:
self.targetSize = self.minSize
log.info("Minimum size changed, setting targetSize on %s to %s",
@@ -937,6 +949,7 @@ class Ext2FS(FS):
# get minimum size according to resize2fs
buf = util.capture_output([self.resizefsProg,
"-P", self.device])
==== start
+ _size = None
for line in buf.splitlines():
# line will look like:
# Estimated minimum size of the filesystem: 1148649
@@ -946,13 +959,14 @@ class Ext2FS(FS):
minSize = minSize.strip()
if not minSize:
break
- size = Size(long(minSize) * blockSize)
+ _size = Size(long(minSize) * blockSize)
break
- if size is None:
+ if not _size:
log.warning("failed to get minimum size for %s filesystem "
"on %s", self.mountType, self.device)
==== end
While I've been working on min size I've also restructured the block above to be a
little bit clearer, something like this:
numBlocks = None
for line in buf.splitlines():
(text, _sep, value) = line.partition(":")
if "minimum size of the filesystem" not in text:
continue
try:
numBlocks = int(value.strip())
break
except ValueError:
break
if numBlocks is None:
raise <appropriate error>
else:
size = Size(blockSize) * numBlocks
orig_size = size
etc.
The advantages are that the variable numBlocks accurately describes the value it holds and
does not change its
meaning in the middle of the loop from number of blocks to total size
and that it's more robust to parsing errors, i.e., if it somehow gets for numBlocks a
string that does
not convert to an int.
else:
+ size = _size
orig_size = size
log.debug("size=%s, current=%s", size, self.currentSize)
size = min(size * Decimal('1.1'), size + 500,
self.currentSize)
--
1.9.3
_______________________________________________
anaconda-patches mailing list
anaconda-patches(a)lists.fedorahosted.org
https://lists.fedorahosted.org/mailman/listinfo/anaconda-patches
- mulhern