direct-io.hg

changeset 12393:2511ac1f1e21

Parsing 'df' output is extremely non-portable. Replace with a direct statvfs().

Signed-off-by: John Levon <john.levon@sun.com>
author john.levon@sun.com
date Thu Nov 09 15:03:51 2006 -0800 (2006-11-09)
parents ad7b60a1db8c
children 5b97dafc7448
files tools/python/xen/xend/XendStorageRepository.py
line diff
     1.1 --- a/tools/python/xen/xend/XendStorageRepository.py	Mon Nov 13 16:19:38 2006 +0000
     1.2 +++ b/tools/python/xen/xend/XendStorageRepository.py	Thu Nov 09 15:03:51 2006 -0800
     1.3 @@ -31,10 +31,8 @@ XEND_STORAGE_MAX_IGNORE = -1
     1.4  XEND_STORAGE_DIR = "/var/lib/xend/storage/"
     1.5  XEND_STORAGE_QCOW_FILENAME = "%s.qcow"
     1.6  XEND_STORAGE_VDICFG_FILENAME = "%s.vdi.xml"
     1.7 -DF_COMMAND = "df -lPk"
     1.8  QCOW_CREATE_COMMAND = "/usr/sbin/qcow-create %d %s"
     1.9  
    1.10 -KB = 1024
    1.11  MB = 1024 *1024
    1.12  
    1.13  class DeviceInvalidError(Exception):
    1.14 @@ -151,23 +149,6 @@ class XendStorageRepository:
    1.15          finally:
    1.16              self.lock.release()
    1.17  
    1.18 -    def _get_df(self):
    1.19 -        """Returns the output of 'df' in a dictionary where the keys
    1.20 -        are the Linux device numbers, and the values are it's corresponding
    1.21 -        free space in bytes
    1.22 -
    1.23 -        @rtype: dictionary
    1.24 -        """
    1.25 -        df = commands.getoutput(DF_COMMAND)
    1.26 -        devnum_free = {}
    1.27 -        for line in df.split('\n')[1:]:
    1.28 -            words = line.split()
    1.29 -            mount_point = words[-1]
    1.30 -            dev_no = os.stat(mount_point).st_dev
    1.31 -            free_kb = int(words[3])
    1.32 -            devnum_free[dev_no] = free_kb * KB
    1.33 -        return devnum_free
    1.34 -
    1.35      def _get_free_space(self):
    1.36          """Returns the amount of free space in bytes available in the storage
    1.37          partition. Note that this may not be used if the storage repository
    1.38 @@ -175,12 +156,8 @@ class XendStorageRepository:
    1.39  
    1.40          @rtype: int
    1.41          """
    1.42 -        df = self._get_df()
    1.43 -        devnum = os.stat(self.storage_dir).st_dev
    1.44 -        if df.has_key(devnum):
    1.45 -            return df[devnum]
    1.46 -        raise DeviceInvalidError("Device not found for storage path: %s" %
    1.47 -                                 self.storage_dir)
    1.48 +        stfs = os.statvfs(self.storage_dir)
    1.49 +        return stfs.f_bavail * stfs.f_frsize
    1.50  
    1.51      def _has_space_available_for(self, size_bytes):
    1.52          """Returns whether there is enough space for an image in the