Sam Giraffe
2013-Sep-30 04:34 UTC
[libvirt-users] virNodeInfo returns MBytes instead of bytes
Hi, http://www.libvirt.org/html/libvirt-libvirt.html#virNodeInfo says that memory size is in kilobytes, however when I use this call I get an answer in Megabytes, see below. The hypervisor has 16 GB of RAM. $ python Python 2.6.6 (r266:84292, Jul 10 2013, 22:48:45) [GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux2 Type "help", "copyright", "credits" or "license" for more information.>>> import libvirt>>> conn=libvirt.open("qemu+ssh://xx@xx.xxx.com/system")Enter passphrase for key '/home/xx/.ssh/id_rsa':>>> hv_info=conn.getInfo()>>> hv_info['x86_64', 15919, 8, 3292, 1, 1, 4, 2] 15,919 is the number I am referencing, should that not be in bytes and not MB? 8 is the number of cores, CPU is 3.2Ghz. $ rpm -q libvirt libvirt-0.10.2-18.el6_4.14.x86_64 $ uname -a Linux xx.xxx.com 2.6.32-358.18.1.el6.x86_64 #1 SMP Wed Aug 28 17:19:38 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux Thanks
Daniel P. Berrange
2013-Sep-30 08:49 UTC
Re: [libvirt-users] virNodeInfo returns MBytes instead of bytes
On Sun, Sep 29, 2013 at 09:34:07PM -0700, Sam Giraffe wrote:> Hi, > > http://www.libvirt.org/html/libvirt-libvirt.html#virNodeInfo says that > memory size is in kilobytes, however when I use this call I get an answer > in Megabytes, see below. The hypervisor has 16 GB of RAM. > > $ python > Python 2.6.6 (r266:84292, Jul 10 2013, 22:48:45) > [GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > > >>> import libvirt > > >>> conn=libvirt.open("qemu+ssh://xx@xx.xxx.com/system") > Enter passphrase for key '/home/xx/.ssh/id_rsa': > > >>> hv_info=conn.getInfo() > > >>> hv_info > ['x86_64', 15919, 8, 3292, 1, 1, 4, 2] > > 15,919 is the number I am referencing, should that not be in bytes and not > MB?God knows why this was done, but the python binding was written to convert the KB value from the C API into MB :-( PyList_SetItem(py_retval, 1, libvirt_longWrap((long) info.memory >> 10)); For backwards compat reasons, we cannot change that default behaviour:-) We could I guess add a flag to let you request sane behaviour though eg something like conn.getInfo(memkb=True) Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
Michal Privoznik
2013-Sep-30 09:06 UTC
Re: [libvirt-users] virNodeInfo returns MBytes instead of bytes
On 30.09.2013 06:34, Sam Giraffe wrote:> Hi, > > http://www.libvirt.org/html/libvirt-libvirt.html#virNodeInfo says that > memory size is in kilobytes, however when I use this call I get an > answer in Megabytes, see below. The hypervisor has 16 GB of RAM. > > $ python > Python 2.6.6 (r266:84292, Jul 10 2013, 22:48:45) > [GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>>> import libvirt > >>>> conn=libvirt.open("qemu+ssh://xx@xx.xxx.com/system > <http://xx@xx.xxx.com/system>") > Enter passphrase for key '/home/xx/.ssh/id_rsa': > >>>> hv_info=conn.getInfo() > >>>> hv_info > ['x86_64', 15919, 8, 3292, 1, 1, 4, 2]This is the python bindings bug. From the code: http://libvirt.org/git/?p=libvirt.git;a=blob;f=python/libvirt-override.c;h=e659bae30ad01b315041e29913fb442c348ed0f6;hb=HEAD#l2846 We are shifting the mem amount left 10 times (effectively divide it by 1024). Hence you'll get MB instead of KB. Although I am not quite sure how to fix this. I see two options: 1) fix the code (possibly breaking other applications already relying on the bug) 2) document it as known bug (not consistent with C struct) Michal