Bug 1015689 - 'usage' attribute defaults to bytes when mounting ram disk in lxc... documented as kb default
'usage' attribute defaults to bytes when mounting ram disk in lxc... document...
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: libvirt (Show other bugs)
Unspecified Unspecified
unspecified Severity unspecified
: rc
: ---
Assigned To: Ján Tomko
Virtualization Bugs
Depends On:
  Show dependency treegraph
Reported: 2013-10-04 16:55 EDT by David Vossel
Modified: 2015-08-24 02:35 EDT (History)
7 users (show)

See Also:
Fixed In Version: libvirt-1.1.1-9.el7
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2014-06-13 06:47:35 EDT
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

  None (edit)
Description David Vossel 2013-10-04 16:55:26 EDT
Description of problem:


The resource on the host that is being accessed in the guest. The name attribute must be used with type='template', and the dir attribute must be used with type='mount'. The usage attribute is used with type='ram' to set the memory limit in KB."

    <filesystem type='ram'>
        <source usage='393216'/>
        <target dir='/dev/shm'/>

Putting the above config in my lxc xml config results in /dev/shm being allocated only 384kb, not 384mb.  Based on the documentation I would expect 384mb

Version-Release number of selected component (if applicable):

yum list installed | grep libvirt
fence-virtd-libvirt.x86_64             0.3.0-13.el7                    @r7      
libvirt.x86_64                         1.1.1-6.el7                     @r7      
libvirt-client.x86_64                  1.1.1-6.el7                     @r7      
libvirt-daemon.x86_64                  1.1.1-6.el7                     @r7      
libvirt-daemon-config-network.x86_64   1.1.1-6.el7                     @r7      
libvirt-daemon-config-nwfilter.x86_64  1.1.1-6.el7                     @r7      
libvirt-daemon-driver-interface.x86_64 1.1.1-6.el7                     @r7      
libvirt-daemon-driver-lxc.x86_64       1.1.1-6.el7                     @r7      
libvirt-daemon-driver-network.x86_64   1.1.1-6.el7                     @r7      
libvirt-daemon-driver-nodedev.x86_64   1.1.1-6.el7                     @r7      
libvirt-daemon-driver-nwfilter.x86_64  1.1.1-6.el7                     @r7      
libvirt-daemon-driver-qemu.x86_64      1.1.1-6.el7                     @r7      
libvirt-daemon-driver-secret.x86_64    1.1.1-6.el7                     @r7      
libvirt-daemon-driver-storage.x86_64   1.1.1-6.el7                     @r7 

How reproducible:

Define a in-memory filesystem in the lxc config.
    <filesystem type='ram'>
        <source usage='393216'/>
        <target dir='/dev/shm'/>

Within the live lxc domain, execute 'df', you'll see /dev/shm only has 384kb allocated instead of 384mb.
Comment 2 Eric Blake 2013-10-08 13:55:37 EDT
We must match the existing documentation.  Consistency with all other memory-related parameters, which are also output in k, says that the bug is in treating the value as bytes when it should be handled in k.  The first attempt at a patch:
doesn't seem right to me, as it tries to reject XML that was previously output by older libvirt, which is not backwards-compatible.
Comment 3 Ján Tomko 2013-10-09 09:22:21 EDT
Another upstream patch attempted:

Missing units default to KiB, and XML generated by older libvirt is parsed correctly.

Both of them also fix the bug of libvirt not being able to parse the units in its own generated XML correctly.
Comment 4 Ján Tomko 2013-10-09 11:46:54 EDT
The third version of the patch has been pushed upstream:

commit 3f029fb5319b9dc9cc2fbf8d1ba4505ee9e4b1e3
Author:     Ján Tomko <jtomko@redhat.com>
AuthorDate: 2013-10-09 14:17:13 +0200
Commit:     Ján Tomko <jtomko@redhat.com>
CommitDate: 2013-10-09 17:44:45 +0200

    LXC: Fix handling of RAM filesystem size units
    Since 76b644c when the support for RAM filesystems was introduced,
    libvirt accepted the following XML:
    <source usage='1024' unit='KiB'/>
    This was parsed correctly and internally stored in bytes, but it
    was formatted as (with an extra 's'):
    <source usage='1024' units='KiB'/>
    When read again, this was treated as if the units were missing,
    meaning libvirt was unable to parse its own XML correctly.
    The usage attribute was documented as being in KiB, but it was not
    scaled if the unit was missing. Transient domains still worked,
    because this was balanced by an extra 'k' in the mount options.
    This patch:
    Changes the parser to use 'units' instead of 'unit', as the latter
    was never documented (fixing persistent domains) and some programs
    (libvirt-glib, libvirt-sandbox) already parse the 'units' attribute.
    Removes the extra 'k' from the tmpfs mount options, which is needed
    because now we parse our own XML correctly.
    Changes the default input unit to KiB to match documentation, fixing:

git describe: v1.1.3-77-g3f029fb
Comment 7 Luwen Su 2013-10-18 03:37:29 EDT
Verify with

1.Prepare the lxc xml

<domain type='lxc'>
  <memory unit='KiB'>1048576</memory>
  <currentMemory unit='KiB'>1048576</currentMemory>
  <vcpu placement='static'>1</vcpu>
    <type arch='x86_64'>exe</type>
  <clock offset='utc'/>
    <filesystem type='ram' accessmode='passthrough'>
      <source usage='10240' units='KiB'/>
      <target dir='/mnt/mississippi'/>
    <filesystem type='ram' accessmode='passthrough'>
      <source usage='1024' units='KiB'/>
      <target dir='/mnt/antananarivo'/>
    <filesystem type='ram' accessmode='passthrough'>
      <source usage='4' units='KiB'/>
      <target dir='/mnt/ouagadougou'/>
    <filesystem type='ram' accessmode='passthrough'>
      <source usage='393216' units='KiB'/>
      <target dir='/dev/shm'/>
    <interface type='network'>
      <mac address='00:16:3e:87:67:8c'/>
      <source network='default'/>
    <console type='pty'>
      <target type='lxc' port='0'/>

#virsh -c lxc:/// start test

#virt-sandbox-service connect test
sh-4.2# df
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/sda1       41153856 2131960  36908360   6% /
tmpfs              10240       0     10240   0% /mnt/mississippi
tmpfs               1024       0      1024   0% /mnt/antananarivo
tmpfs                  4       0         4   0% /mnt/ouagadougou
tmpfs             393216       0    393216   0% /dev/shm

If omits the units attribute , or change the unit to B , MiB , it will auto-complete and scaler properly , so Set VERIFIED
Comment 8 Ludek Smid 2014-06-13 06:47:35 EDT
This request was resolved in Red Hat Enterprise Linux 7.0.

Contact your manager or support representative in case you have further questions about the request.

Note You need to log in before you can comment on or make changes to this bug.