[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[PATCH] Include journal size in ext3/ext4 existing size value.



For ext3 and ext4 filesystems, add the journal size to the value we get
from statvfs() and use that total for the existing size of the
filesystem.  Existing size is meant to be the amount of space occupied
by the filesystem on the volume, for journaled filesystems that means
there is a disconnect between what we get from statvfs() and how much
space the filesystem consumes on the volume.
---
 storage/formats/fs.py |   37 +++++++++++++++++++++++++++++++++++++
 1 files changed, 37 insertions(+), 0 deletions(-)

diff --git a/storage/formats/fs.py b/storage/formats/fs.py
index 4527a03..6330825 100644
--- a/storage/formats/fs.py
+++ b/storage/formats/fs.py
@@ -126,11 +126,13 @@ class FS(DeviceFormat):
     _labelfs = ""                        # labeling utility
     _fsck = ""                           # fs check utility
     _migratefs = ""                      # fs migration utility
+    _infofs = ""                         # fs info utility
     _defaultFormatOptions = []           # default options passed to mkfs
     _defaultMountOptions = ["defaults"]  # default options passed to mount
     _defaultLabelOptions = []
     _defaultCheckOptions = []
     _defaultMigrateOptions = []
+    _defaultInfoOptions = []
     _migrationTarget = None
     lostAndFoundContext = None
 
@@ -610,6 +612,11 @@ class FS(DeviceFormat):
         return self._migratefs
 
     @property
+    def infofsProg(self):
+        """ Program used to display filesystem information. """
+        return self._infofs
+
+    @property
     def migrationTarget(self):
         return self._migrationTarget
 
@@ -767,6 +774,8 @@ class Ext2FS(FS):
     _migrationTarget = "ext3"
     _migratefs = "tune2fs"
     _defaultMigrateOptions = ["-j"]
+    _infofs = "dumpe2fs"
+    _defaultInfoOptions = ["-h"]
 
     def doMigrate(self, intf=None):
         FS.doMigrate(self, intf=intf)
@@ -837,6 +846,34 @@ class Ext3FS(Ext2FS):
     _modules = ["ext3"]
     _defaultMigrateOptions = ["-O", "extents"]
 
+    def _getExistingSize(self):
+        """ Determine the size of this filesystem.  Filesystem must
+            exist.  Adds in the size of the filesystem journal.
+        """
+        size = Ext2FS._getExistingSize(self)
+        val = 0
+        conv = 1
+
+        buf = iutil.execWithCapture(self.infofsProg, self._defaultInfoOptions,
+                                    stderr="/dev/tty5")
+        for line in buf.splitlines():
+            if line.startswith("Journal size:"):
+                val = line.split()[-1]
+
+                if val.endswith('M'):
+                    val = long(val.split('M')[0])
+                    break
+                elif val.endswith('k'):
+                    val = long(val.split('k')[0])
+                    conv = 1024.0
+                    break
+
+        size *= conv
+        size += val
+        size /= conv
+
+        return size
+
     @property
     def migratable(self):
         """ Can filesystems of this type be migrated? """
-- 
1.6.2.2


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]