WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] [PATCH] fix xend not to parse `df`

To: xen-devel@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-devel] [PATCH] fix xend not to parse `df`
From: John Levon <levon@xxxxxxxxxxxxxxxxx>
Date: Thu, 9 Nov 2006 23:06:55 +0000
Delivery-date: Thu, 09 Nov 2006 15:07:11 -0800
Envelope-to: www-data@xxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Mutt/1.5.9i
# HG changeset patch
# User john.levon@xxxxxxx
# Date 1163113431 28800
# Node ID 348c6ec90131ddfe893029fa01dc133bbc77a3ae
# Parent  d6902275432c8570835d0e962ac7991fcd2c070a
Parsing 'df' output is extremely non-portable. Replace with a direct statvfs().

Signed-off-by: John Levon <john.levon@xxxxxxx>

diff --git a/tools/python/xen/xend/XendStorageRepository.py 
b/tools/python/xen/xend/XendStorageRepository.py
--- a/tools/python/xen/xend/XendStorageRepository.py
+++ b/tools/python/xen/xend/XendStorageRepository.py
@@ -31,10 +31,8 @@ XEND_STORAGE_DIR = "/var/lib/xend/storag
 XEND_STORAGE_DIR = "/var/lib/xend/storage/"
 XEND_STORAGE_QCOW_FILENAME = "%s.qcow"
 XEND_STORAGE_VDICFG_FILENAME = "%s.vdi.xml"
-DF_COMMAND = "df -lPk"
 QCOW_CREATE_COMMAND = "/usr/sbin/qcow-create %d %s"
 
-KB = 1024
 MB = 1024 *1024
 
 class DeviceInvalidError(Exception):
@@ -151,23 +149,6 @@ class XendStorageRepository:
         finally:
             self.lock.release()
 
-    def _get_df(self):
-        """Returns the output of 'df' in a dictionary where the keys
-        are the Linux device numbers, and the values are it's corresponding
-        free space in bytes
-
-        @rtype: dictionary
-        """
-        df = commands.getoutput(DF_COMMAND)
-        devnum_free = {}
-        for line in df.split('\n')[1:]:
-            words = line.split()
-            mount_point = words[-1]
-            dev_no = os.stat(mount_point).st_dev
-            free_kb = int(words[3])
-            devnum_free[dev_no] = free_kb * KB
-        return devnum_free
-
     def _get_free_space(self):
         """Returns the amount of free space in bytes available in the storage
         partition. Note that this may not be used if the storage repository
@@ -175,12 +156,8 @@ class XendStorageRepository:
 
         @rtype: int
         """
-        df = self._get_df()
-        devnum = os.stat(self.storage_dir).st_dev
-        if df.has_key(devnum):
-            return df[devnum]
-        raise DeviceInvalidError("Device not found for storage path: %s" %
-                                 self.storage_dir)
+        stfs = os.statvfs(self.storage_dir)
+        return stfs.f_bavail * stfs.f_frsize
 
     def _has_space_available_for(self, size_bytes):
         """Returns whether there is enough space for an image in the

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel

<Prev in Thread] Current Thread [Next in Thread>