[libvirt] [PATCH] LXC: Fix the output units of ram filesystem size

Eric Blake eblake at redhat.com
Tue Oct 8 17:43:12 UTC 2013


On 10/08/2013 11:28 AM, Ján Tomko wrote:
> Commit 76b644c added support for adding RAM filesystems to LXC
> domains, with a syntax of:
> <source usage='10' unit='MiB'/>
> where default unit would be KiB per documentation, however the
> XML parser treated sizes without units as bytes.
> 
> When formatting the XML, this was divided by 1024, but the KiB units
> were put inside the 'units' attribute, as opposed to the 'unit'
> attribute the parser looks for.
> 
> The code generating the mount options assumed the size in the domain
> definition to be in KiB, despite it being parsed as B. This worked
> as long as exaclty one re-format of the XML happened (for domains that
> were just created).
> 
> Change the XML output to bytes and fix the documentation.

We still have libvirt in the wild that outputs bogus units= in the XML;
that should still pass the RelaxNG grammar even if it is otherwise ignored.

>          <code>name</code> attribute must be used with
>          <code>type='template'</code>, and the <code>dir</code> attribute must
>          be used with <code>type='mount'</code>. The <code>usage</code> attribute
> -        is used with <code>type='ram'</code> to set the memory limit in KB.
> +        is used with <code>type='ram'</code> to set the memory limit in bytes.

If the RelaxNG is fixed to parse the broken output, then this could
document that <code>units</code> is ignored.

> +++ b/src/conf/domain_conf.c
> @@ -14764,8 +14764,8 @@ virDomainFSDefFormat(virBufferPtr buf,
>          break;
>  
>      case VIR_DOMAIN_FS_TYPE_RAM:
> -        virBufferAsprintf(buf, "      <source usage='%lld' units='KiB'/>\n",
> -                          def->usage / 1024);
> +        virBufferAsprintf(buf, "      <source usage='%lld' unit='B'/>\n",
> +                          def->usage);

Wait.  This says older libvirt was outputting k, not bytes.  If that's
true, then we MUST continue to output k.

>          break;
>      }
>  
> diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c
> index b1f429c..7c722cc 100644
> --- a/src/lxc/lxc_container.c
> +++ b/src/lxc/lxc_container.c
> @@ -1428,7 +1428,7 @@ static int lxcContainerMountFSTmpfs(virDomainFSDefPtr fs,
>      VIR_DEBUG("usage=%lld sec=%s", fs->usage, sec_mount_options);
>  
>      if (virAsprintf(&data,
> -                    "size=%lldk%s", fs->usage, sec_mount_options) < 0)
> +                    "size=%lld%s", fs->usage, sec_mount_options) < 0)

I'm also not convince on this change - if the XML contains k by default,
then we must continue to pass k to the mount command.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 621 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20131008/e832a54c/attachment-0001.sig>


More information about the libvir-list mailing list