[et-mgmt-tools] [PATCH] Provide a common block device size utility for Solaris & Linux

Daniel P. Berrange berrange at redhat.com
Wed Dec 3 09:37:57 UTC 2008


On Tue, Dec 02, 2008 at 06:25:39PM -0800, john.levon at sun.com wrote:
> @@ -257,6 +259,18 @@ def xml_escape(str):
>      str = str.replace("<", "<")
>      str = str.replace(">", ">")
>      return str
> + 
> +def blkdev_size(path):
> +    if platform.system() == 'SunOS':
> +        return os.stat(path)[stat.ST_SIZE]
> +    else:
> +        dummy, msg = commands.getstatusoutput('fdisk -s %s' % path)
> +        # check
> +        if msg.isdigit() == False:
> +            lines = msg.splitlines()
> +            # retry eg. for the GPT disk
> +            msg = lines[len(lines)-1]
> +        return (int(msg) * 1024)


ACK, to the general idea of adding a common routine. The original Linux
impl was kind of crazy. We could get a single portable impl for all
OS by using seek(), which is how libvirt does it in its storage code.

       fd = os.open(path, O_RDONLY)
       size = os.lseek(fd, 0, SEEK_END);
       os.close(fd)
       return size


Danie
-- 
|: Red Hat, Engineering, London   -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org  -o-  http://virt-manager.org  -o-  http://ovirt.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-  F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|




More information about the et-mgmt-tools mailing list