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

John Levon levon at movementarian.org
Thu Dec 4 03:24:16 UTC 2008


On Wed, Dec 03, 2008 at 09:37:57AM +0000, Daniel P. Berrange wrote:

> > +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.

Quite honestly, I wasn't entirely sure why you're using fdisk. But if
you don't need to, why use lseek() when os.stat() does the job?

regards
john




More information about the et-mgmt-tools mailing list