FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Redhat > Fedora/Linux Management Tools

 
 
LinkBack Thread Tools
 
Old 12-03-2008, 08:37 AM
"Daniel P. Berrange"
 
Default Provide a common block device size utility for Solaris & Linux

On Tue, Dec 02, 2008 at 06:25:39PM -0800, john.levon@sun.com wrote:
> @@ -257,6 +259,18 @@ def xml_escape(str):
> str = str.replace("<", "&lt;")
> str = str.replace(">", "&gt;")
> 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 :|

_______________________________________________
et-mgmt-tools mailing list
et-mgmt-tools@redhat.com
https://www.redhat.com/mailman/listinfo/et-mgmt-tools
 
Old 12-04-2008, 02:24 AM
John Levon
 
Default Provide a common block device size utility for Solaris & Linux

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

_______________________________________________
et-mgmt-tools mailing list
et-mgmt-tools@redhat.com
https://www.redhat.com/mailman/listinfo/et-mgmt-tools
 
Old 12-04-2008, 09:40 AM
"Daniel P. Berrange"
 
Default Provide a common block device size utility for Solaris & Linux

On Thu, Dec 04, 2008 at 03:24:16AM +0000, John Levon wrote:
> 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?

Because stat() returns 0 for the size of block devices on many UNIX
including Linux.

# perl -e 'use File::stat; my $f = stat("/dev/sda1"); printf "%d
", $f->size'
0

# perl -e 'use POSIX; my $f = POSIX:pen("/dev/sda1", O_RDONLY); printf "%d
", (POSIX::lseek $f, 0, 2)'
106896384

Daniel
--
|: 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 :|

_______________________________________________
et-mgmt-tools mailing list
et-mgmt-tools@redhat.com
https://www.redhat.com/mailman/listinfo/et-mgmt-tools
 

Thread Tools




All times are GMT. The time now is 12:40 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org