[lxc-devel] Iozone test faild in LXC

Han Yuejuan-B42073 B42073 at freescale.com
Thu Nov 22 06:59:26 UTC 2012


Hello all,

Issue:  It is not successful to do iozone test in Linux Containers.

Test context:
       Hardware :P4080 -> gerald: rev 3.0, ddr=8g (FSL Powerpc)
       software: sdk_1.3 rc2
Question:
       When do -i 0 -i 1 (write/rewrite,read/re-read) test:
       The memory size of host is 8G , so the maximum file size of setting can be 2*8g when doing iozone test in LXC ?
       if not, the maximum file size will be ? and what is the relationship of setted maximum file size in LXC with host memory size ?or any other factors that impact iozone
       test of lxc?

Look forward to your answer! Thanks a lot!

Detail information as below:
       In LXC:
            Configuration of  LXC rootfs (using busybox template)
                     1.Creating device files into container rootfs
                             In fun of install_busybox() add:
                              # device zero
                                  mknod zero c 1 5
                                  chmod 666 zero

                            # hdd
                                 mknod sdb b 8 0
                                 mknod sdb1 b 8 1
                                chmod 666 sdb
                                chmod 666 sdb1
                    2. Include instruction set for LXC : insert "/$rootfs/usr/bin" into install_busybox()
                                install_busybox()
                                {
                                     rootfs=$1
                                      name=$2
                                      res=0
                                      tree="\
                                     $rootfs/selinux \
                                      $rootfs/usr/bin  \
                                      ......}

                    3. Set mount entry of LXC : insert "/usr/bin" into copy_configure()
                                copy_configure()
                               {
                                        libdirs="\
                                         /lib \
                                         /usr/bin \
                                          ......
                                       for dir in $libdirs; do
                                        if [ -d $dir ]; then
                                           echo "lxc.mount.entry=$dir $rootfs$dir none ro,bind 0 0" >> $path/config
                                        fi
                                        done
                                    ......}
               Create lxc :
                              lxc-create -n ctx1 -t busybox -f /usr/share/doc/lxc/examples/lxc-no-netns.conf
                               lxc-start -n ctx1
               Iozone test cmd  in LXC :
                              iozone -Rab /mnt/sdb1/result1.xls -i 0 -i 1 -f /mnt/sdb1/test -n 32M -g 16384M -r 64k
                                 root at ctx1:/# iozone -Rab /mnt/sdb1/result1.xls -i 0 -i 1 -f /mnt/sdb1/test -n 32M -g 16384M -r 64k
                                                             iozone -Rab /mnt/sdb1/result1.xls -i 0 -i 1 -f /mnt/sdb1/test -n 32M -g 16384M -r 64k
                                 Iozone: Performance Test of File I/O
                               Version $Revision: 3.263 $
                                 Compiled for 32 bit mode.
                                 uild: linux-powerpc

                                  Excel chart generation enabled
                                Auto Mode
                               Using minimum file size of 32768 kilobytes.
                              Using maximum file size of 16777216 kilobytes.
                               Record Size 64 KB
                              Command line used: iozone -Rab /mnt/sdb1/result1.xls -i 0 -i 1 -f /mnt/sdb1/test -n 32M -g 16384M -r 64k
                              Output is in Kbytes/sec
                           Time Resolution = 0.000001 seconds.
                          Processor cache line size set to 32 bytes.
                               File stride size set to 17 * record size.
                                                            random  random    bkwd  record  stride
                                                         KB  reclen   write rewrite    read    reread    read   write    read rewrite    read   fwrite frewrite   fread  freread
                                                         32768      64  490172  977157  1201181  1214717
                                                        65536      64  493178  955101  1208728  1215113
                                                        131072      64    8908   20254  1212673  1215599
                                                        262144      64    6486   12719  1212478  1215329
                                                        524288        64    6493   11205  1217592  1219668
                                                        1048576      64    5626   10302  1216230  1218040
                                                         2097152      64
                                                      Error writing block 29644, fd= 3

                                                    iozone: interrupted

     It is normal to do iozone test in host :

    part of  log info:
     root at p4080ds:~# iozone -Rab /mnt/sdb1/result2.xls -i 0 -i 1 -f /mnt/sdb1/test -n 32M -g 16384M -r 64k
    Iozone: Performance Test of File I/O
         Version $Revision: 3.263 $
        Compiled for 32 bit mode.
        Build: linux-powerpc

    Excel chart generation enabled
    Auto Mode
    Using minimum file size of 32768 kilobytes.
    Using maximum file size of 16777216 kilobytes.
    Record Size 64 KB
    Command line used: iozone -Rab /mnt/sdb1/result2.xls -i 0 -i 1 -f /mnt/sdb1/test -n 32M -g 16384M -r 64k
    Output is in Kbytes/sec
    Time Resolution = 0.000001 seconds.
    Processor cache size set to 1024 Kbytes.
    Processor cache line size set to 32 bytes.
    File stride size set to 17 * record size.
                                                            random  random    bkwd  record  stride
              KB  reclen   write rewrite    read    reread    read   write    read rewrite    read   fwrite frewrite   fread  freread
           32768      64  420950  978033  1207407  1225800
           65536      64  500316  971208  1220048  1229522
          131072      64  170862  184546  1225121  1230135
          262144      64   81217   96077  1227869  1229931
          524288      64   66387   75088  1224423  1227892
         1048576      64   59394   68065  1226510  1227980
         2097152      64   56872   64417  1227611  1230297
         4194304      64   55253   62806  1226647  1227713
         8388608      64   54556   61921    65851    65912
        16777216      64   53933   61459    64280    64327

iozone test complete.

Best Regards,
Yuejuan.



________________________________________
From: lxc-devel-request at lists.sourceforge.net [lxc-devel-request at lists.sourceforge.net]
Sent: Wednesday, November 21, 2012 5:04 PM
To: lxc-devel at lists.sourceforge.net
Subject: Lxc-devel Digest, Vol 51, Issue 13

Send Lxc-devel mailing list submissions to
lxc-devel at lists.sourceforge.net

To subscribe or unsubscribe via the World Wide Web, visit
https://lists.sourceforge.net/lists/listinfo/lxc-devel
or, via email, send a message with subject or body 'help' to
lxc-devel-request at lists.sourceforge.net

You can reach the person managing the list at
lxc-devel-owner at lists.sourceforge.net

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Lxc-devel digest..."


Today's Topics:

1. Re: using posix shell instead of bash (Serge Hallyn)
2. [PATCH] lxc-create: use posix shell instead of bash
(Natanael Copa)
3. Re: [PATCH] lxc-create: use posix shell instead of bash
(Serge Hallyn)
4. Re: [PATCH] lxc-create: use posix shell instead of bash
(St?phane Graber)
5. [PATCH] Rewrite lxc-ls in python (St?phane Graber)


----------------------------------------------------------------------

Message: 1
Date: Fri, 16 Nov 2012 08:02:35 -0600
From: Serge Hallyn <serge.hallyn at canonical.com>
Subject: Re: [lxc-devel] using posix shell instead of bash
To: Natanael Copa <ncopa at alpinelinux.org>
Cc: Lxc development list <lxc-devel at lists.sourceforge.net>
Message-ID: <20121116140235.GA17455 at sergelap>
Content-Type: text/plain; charset=us-ascii

Quoting Natanael Copa (ncopa at alpinelinux.org):
> On Wed, 14 Nov 2012 09:54:58 -0600
> Serge Hallyn <serge.hallyn at canonical.com> wrote:
>
> > Successful runs of
> > https://code.launchpad.net/~serge-hallyn/+junk/lxc-test with your
> > patches will also be reassuring.
>
> This is causing problems for me:
>
> if dist[0] != "Ubuntu":
> print >>sys.stderr, "This test suite does not yet support %s" % (dist[0])
> sys.exit(1)

Oh yeah, good point, that's worth updating :)



------------------------------

Message: 2
Date: Fri, 16 Nov 2012 17:01:55 +0100
From: Natanael Copa <ncopa at alpinelinux.org>
Subject: [lxc-devel] [PATCH] lxc-create: use posix shell instead of
bash
To: lxc-devel at lists.sourceforge.net
Message-ID: <1353081715-31771-1-git-send-email-ncopa at alpinelinux.org>

- use '[ -x /path/prog ]' instead of 'type /path/prog'
- avoid getopt --longoptions
- add \ at after && and || when those are at end of line
- make sure condition expands to empty string if variable is empty

Signed-off-by: Natanael Copa <ncopa at alpinelinux.org>
---
I have tested it with 'lxc-create -t debian ...' with busybox as /bin/sh

src/lxc/lxc-create.in | 70 +++++++++++++++++++++++++++++----------------------
1 file changed, 40 insertions(+), 30 deletions(-)

diff --git a/src/lxc/lxc-create.in b/src/lxc/lxc-create.in
index 101e489..e8056e9 100644
--- a/src/lxc/lxc-create.in
+++ b/src/lxc/lxc-create.in
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh

#
# lxc: linux Container library
@@ -54,16 +54,26 @@ help() {
echo " $(basename $0) -t ubuntu -h" >&2
exit 0
fi
- type ${templatedir}/lxc-$lxc_template 2>/dev/null
- if [ $? -eq 0 ]; then
+ if [ -x ${templatedir}/lxc-$lxc_template ]; then
echo >&2
echo "Template-specific options (TEMPLATE_OPTIONS):" >&2
${templatedir}/lxc-$lxc_template -h
fi
}

-shortoptions='hn:f:t:B:'
-longoptions='help,name:,config:,template:,backingstore:,fstype:,dir:,lvname:,vgname:,fssize:'
+usage_err() {
+ [ -n "$1" ] && echo "$1" >&2
+ usage
+ exit 1
+}
+
+optarg_check() {
+ local opt="$1" optarg="$2"
+ if [ -z "$optarg" ]; then
+ usage_err "option '$opt' requires an argument"
+ fi
+}
+
lxc_path=@LXCPATH@
bindir=@BINDIR@
templatedir=@LXCTEMPLATEDIR@
@@ -73,68 +83,69 @@ fssize=500M
vgname=lxc
custom_rootfs=""

-getopt=$(getopt -o $shortoptions --longoptions $longoptions -- "$@")
-if [ $? != 0 ]; then
- usage
- exit 1;
-fi
-
-eval set -- "$getopt"
-
-while true; do
- case "$1" in
+while [ $# -gt 0 ]; do
+ local opt="$1"
+ shift
+ case "$opt" in
-h|--help)
help
exit 1
;;
-n|--name)
- shift
+ optarg_check $opt "$1"
lxc_name=$1
shift
;;
-f|--config)
- shift
+ optarg_check $opt "$1"
lxc_config=$1
shift
;;
-t|--template)
- shift
+ optarg_check $opt "$1"
lxc_template=$1
shift
;;
-B|--backingstore)
- shift
+ optarg_check $opt "$1"
backingstore=$1
shift
;;
--dir)
- shift
+ optarg_check $opt "$1"
custom_rootfs=$1
shift
;;
--lvname)
- shift
+ optarg_check $opt "$1"
lvname=$1
shift
;;
--vgname)
- shift
+ optarg_check $opt "$1"
vgname=$1
shift
;;
--fstype)
- shift
+ optarg_check $opt "$1"
fstype=$1
shift
;;
--fssize)
- shift
+ optarg_check $opt "$1"
fssize=$1
shift
;;
--)
shift
break;;
+ -?)
+ usage_err "unknown option '$opt'"
+ ;;
+ -*)
+ # split opts -abc into -a -b -c
+ set -- $(echo "${opt#-}" | sed 's/\(.\)/ -\1/g') "$@"
+ ;;
*)
usage
exit 1
@@ -200,7 +211,7 @@ rootfs="$lxc_path/$lxc_name/rootfs"

if [ "$backingstore" = "_unset" -o "$backingstore" = "btrfs" ]; then
# if no backing store was given, then see if btrfs would work
- if which btrfs >/dev/null 2>&1 &&
+ if which btrfs >/dev/null 2>&1 && \
btrfs filesystem df "$lxc_path/" >/dev/null 2>&1; then
backingstore="btrfs"
else
@@ -246,10 +257,10 @@ elif [ "$backingstore" = "btrfs" ]; then
fi

cleanup() {
- if [ $backingstore = "lvm" ]; then
+ if [ "$backingstore" = "lvm" ]; then
umount $rootfs
lvremove -f $rootdev
- elif [ $backingstore = "btrfs" ]; then
+ elif [ "$backingstore" = "btrfs" ]; then
btrfs subvolume delete "$rootfs"
fi
${bindir}/lxc-destroy -n $lxc_name
@@ -299,8 +310,7 @@ if [ ! -z $lxc_template ]; then
template_path=${templatedir}/lxc-$lxc_template
fi

- type $template_path 2>/dev/null
- if [ $? -ne 0 ]; then
+ if ! [ -x "$template_path" ]; then
echo "$(basename $0): unknown template '$lxc_template'" >&2
cleanup
fi
@@ -314,7 +324,7 @@ if [ ! -z $lxc_template ]; then
echo "'$lxc_template' template installed"
fi

-if [ $backingstore = "lvm" ]; then
+if [ "$backingstore" = "lvm" ]; then
echo "Unmounting LVM"
umount $rootfs

--
1.8.0




------------------------------

Message: 3
Date: Mon, 19 Nov 2012 10:36:46 -0600
From: Serge Hallyn <serge.hallyn at canonical.com>
Subject: Re: [lxc-devel] [PATCH] lxc-create: use posix shell instead
of bash
To: Natanael Copa <ncopa at alpinelinux.org>
Cc: lxc-devel at lists.sourceforge.net
Message-ID: <20121119163646.GA32083 at serge-ThinkPad-X130e>
Content-Type: text/plain; charset=us-ascii

Quoting Natanael Copa (ncopa at alpinelinux.org):
> - use '[ -x /path/prog ]' instead of 'type /path/prog'
> - avoid getopt --longoptions
> - add \ at after && and || when those are at end of line
> - make sure condition expands to empty string if variable is empty
>

looks good to me, thanks.

Acked-by: Serge E. Hallyn <serge.hallyn at ubuntu.com>

> Signed-off-by: Natanael Copa <ncopa at alpinelinux.org>
> ---
> I have tested it with 'lxc-create -t debian ...' with busybox as /bin/sh
>
> src/lxc/lxc-create.in | 70 +++++++++++++++++++++++++++++----------------------
> 1 file changed, 40 insertions(+), 30 deletions(-)
>
> diff --git a/src/lxc/lxc-create.in b/src/lxc/lxc-create.in
> index 101e489..e8056e9 100644
> --- a/src/lxc/lxc-create.in
> +++ b/src/lxc/lxc-create.in
> @@ -1,4 +1,4 @@
> -#!/bin/bash
> +#!/bin/sh
>
> #
> # lxc: linux Container library
> @@ -54,16 +54,26 @@ help() {
> echo " $(basename $0) -t ubuntu -h" >&2
> exit 0
> fi
> - type ${templatedir}/lxc-$lxc_template 2>/dev/null
> - if [ $? -eq 0 ]; then
> + if [ -x ${templatedir}/lxc-$lxc_template ]; then
> echo >&2
> echo "Template-specific options (TEMPLATE_OPTIONS):" >&2
> ${templatedir}/lxc-$lxc_template -h
> fi
> }
>
> -shortoptions='hn:f:t:B:'
> -longoptions='help,name:,config:,template:,backingstore:,fstype:,dir:,lvname:,vgname:,fssize:'
> +usage_err() {
> + [ -n "$1" ] && echo "$1" >&2
> + usage
> + exit 1
> +}
> +
> +optarg_check() {
> + local opt="$1" optarg="$2"
> + if [ -z "$optarg" ]; then
> + usage_err "option '$opt' requires an argument"
> + fi
> +}
> +
> lxc_path=@LXCPATH@
> bindir=@BINDIR@
> templatedir=@LXCTEMPLATEDIR@
> @@ -73,68 +83,69 @@ fssize=500M
> vgname=lxc
> custom_rootfs=""
>
> -getopt=$(getopt -o $shortoptions --longoptions $longoptions -- "$@")
> -if [ $? != 0 ]; then
> - usage
> - exit 1;
> -fi
> -
> -eval set -- "$getopt"
> -
> -while true; do
> - case "$1" in
> +while [ $# -gt 0 ]; do
> + local opt="$1"
> + shift
> + case "$opt" in
> -h|--help)
> help
> exit 1
> ;;
> -n|--name)
> - shift
> + optarg_check $opt "$1"
> lxc_name=$1
> shift
> ;;
> -f|--config)
> - shift
> + optarg_check $opt "$1"
> lxc_config=$1
> shift
> ;;
> -t|--template)
> - shift
> + optarg_check $opt "$1"
> lxc_template=$1
> shift
> ;;
> -B|--backingstore)
> - shift
> + optarg_check $opt "$1"
> backingstore=$1
> shift
> ;;
> --dir)
> - shift
> + optarg_check $opt "$1"
> custom_rootfs=$1
> shift
> ;;
> --lvname)
> - shift
> + optarg_check $opt "$1"
> lvname=$1
> shift
> ;;
> --vgname)
> - shift
> + optarg_check $opt "$1"
> vgname=$1
> shift
> ;;
> --fstype)
> - shift
> + optarg_check $opt "$1"
> fstype=$1
> shift
> ;;
> --fssize)
> - shift
> + optarg_check $opt "$1"
> fssize=$1
> shift
> ;;
> --)
> shift
> break;;
> + -?)
> + usage_err "unknown option '$opt'"
> + ;;
> + -*)
> + # split opts -abc into -a -b -c
> + set -- $(echo "${opt#-}" | sed 's/\(.\)/ -\1/g') "$@"
> + ;;
> *)
> usage
> exit 1
> @@ -200,7 +211,7 @@ rootfs="$lxc_path/$lxc_name/rootfs"
>
> if [ "$backingstore" = "_unset" -o "$backingstore" = "btrfs" ]; then
> # if no backing store was given, then see if btrfs would work
> - if which btrfs >/dev/null 2>&1 &&
> + if which btrfs >/dev/null 2>&1 && \
> btrfs filesystem df "$lxc_path/" >/dev/null 2>&1; then
> backingstore="btrfs"
> else
> @@ -246,10 +257,10 @@ elif [ "$backingstore" = "btrfs" ]; then
> fi
>
> cleanup() {
> - if [ $backingstore = "lvm" ]; then
> + if [ "$backingstore" = "lvm" ]; then
> umount $rootfs
> lvremove -f $rootdev
> - elif [ $backingstore = "btrfs" ]; then
> + elif [ "$backingstore" = "btrfs" ]; then
> btrfs subvolume delete "$rootfs"
> fi
> ${bindir}/lxc-destroy -n $lxc_name
> @@ -299,8 +310,7 @@ if [ ! -z $lxc_template ]; then
> template_path=${templatedir}/lxc-$lxc_template
> fi
>
> - type $template_path 2>/dev/null
> - if [ $? -ne 0 ]; then
> + if ! [ -x "$template_path" ]; then
> echo "$(basename $0): unknown template '$lxc_template'" >&2
> cleanup
> fi
> @@ -314,7 +324,7 @@ if [ ! -z $lxc_template ]; then
> echo "'$lxc_template' template installed"
> fi
>
> -if [ $backingstore = "lvm" ]; then
> +if [ "$backingstore" = "lvm" ]; then
> echo "Unmounting LVM"
> umount $rootfs
>
> --
> 1.8.0
>
>
> ------------------------------------------------------------------------------
> Monitor your physical, virtual and cloud infrastructure from a single
> web console. Get in-depth insight into apps, servers, databases, vmware,
> SAP, cloud infrastructure, etc. Download 30-day Free Trial.
> Pricing starts from $795 for 25 servers or applications!
> http://p.sf.net/sfu/zoho_dev2dev_nov
> _______________________________________________
> Lxc-devel mailing list
> Lxc-devel at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/lxc-devel



------------------------------

Message: 4
Date: Wed, 21 Nov 2012 14:36:36 -0500
From: St?phane Graber <stgraber at ubuntu.com>
Subject: Re: [lxc-devel] [PATCH] lxc-create: use posix shell instead
of bash
To: lxc-devel at lists.sourceforge.net
Message-ID: <50AD2D44.3080903 at ubuntu.com>
Content-Type: text/plain; charset="iso-8859-1"

On 11/19/2012 11:36 AM, Serge Hallyn wrote:
> Quoting Natanael Copa (ncopa at alpinelinux.org):
>> - use '[ -x /path/prog ]' instead of 'type /path/prog'
>> - avoid getopt --longoptions
>> - add \ at after && and || when those are at end of line
>> - make sure condition expands to empty string if variable is empty
>>
>
> looks good to me, thanks.
>
> Acked-by: Serge E. Hallyn <serge.hallyn at ubuntu.com>

Acked-by: St?phane Graber <stgraber at ubuntu.com>

And pushed to staging. Thanks!

>
>> Signed-off-by: Natanael Copa <ncopa at alpinelinux.org>
>> ---
>> I have tested it with 'lxc-create -t debian ...' with busybox as /bin/sh
>>
>> src/lxc/lxc-create.in | 70 +++++++++++++++++++++++++++++----------------------
>> 1 file changed, 40 insertions(+), 30 deletions(-)
>>
>> diff --git a/src/lxc/lxc-create.in b/src/lxc/lxc-create.in
>> index 101e489..e8056e9 100644
>> --- a/src/lxc/lxc-create.in
>> +++ b/src/lxc/lxc-create.in
>> @@ -1,4 +1,4 @@
>> -#!/bin/bash
>> +#!/bin/sh
>>
>> #
>> # lxc: linux Container library
>> @@ -54,16 +54,26 @@ help() {
>> echo " $(basename $0) -t ubuntu -h" >&2
>> exit 0
>> fi
>> - type ${templatedir}/lxc-$lxc_template 2>/dev/null
>> - if [ $? -eq 0 ]; then
>> + if [ -x ${templatedir}/lxc-$lxc_template ]; then
>> echo >&2
>> echo "Template-specific options (TEMPLATE_OPTIONS):" >&2
>> ${templatedir}/lxc-$lxc_template -h
>> fi
>> }
>>
>> -shortoptions='hn:f:t:B:'
>> -longoptions='help,name:,config:,template:,backingstore:,fstype:,dir:,lvname:,vgname:,fssize:'
>> +usage_err() {
>> + [ -n "$1" ] && echo "$1" >&2
>> + usage
>> + exit 1
>> +}
>> +
>> +optarg_check() {
>> + local opt="$1" optarg="$2"
>> + if [ -z "$optarg" ]; then
>> + usage_err "option '$opt' requires an argument"
>> + fi
>> +}
>> +
>> lxc_path=@LXCPATH@
>> bindir=@BINDIR@
>> templatedir=@LXCTEMPLATEDIR@
>> @@ -73,68 +83,69 @@ fssize=500M
>> vgname=lxc
>> custom_rootfs=""
>>
>> -getopt=$(getopt -o $shortoptions --longoptions $longoptions -- "$@")
>> -if [ $? != 0 ]; then
>> - usage
>> - exit 1;
>> -fi
>> -
>> -eval set -- "$getopt"
>> -
>> -while true; do
>> - case "$1" in
>> +while [ $# -gt 0 ]; do
>> + local opt="$1"
>> + shift
>> + case "$opt" in
>> -h|--help)
>> help
>> exit 1
>> ;;
>> -n|--name)
>> - shift
>> + optarg_check $opt "$1"
>> lxc_name=$1
>> shift
>> ;;
>> -f|--config)
>> - shift
>> + optarg_check $opt "$1"
>> lxc_config=$1
>> shift
>> ;;
>> -t|--template)
>> - shift
>> + optarg_check $opt "$1"
>> lxc_template=$1
>> shift
>> ;;
>> -B|--backingstore)
>> - shift
>> + optarg_check $opt "$1"
>> backingstore=$1
>> shift
>> ;;
>> --dir)
>> - shift
>> + optarg_check $opt "$1"
>> custom_rootfs=$1
>> shift
>> ;;
>> --lvname)
>> - shift
>> + optarg_check $opt "$1"
>> lvname=$1
>> shift
>> ;;
>> --vgname)
>> - shift
>> + optarg_check $opt "$1"
>> vgname=$1
>> shift
>> ;;
>> --fstype)
>> - shift
>> + optarg_check $opt "$1"
>> fstype=$1
>> shift
>> ;;
>> --fssize)
>> - shift
>> + optarg_check $opt "$1"
>> fssize=$1
>> shift
>> ;;
>> --)
>> shift
>> break;;
>> + -?)
>> + usage_err "unknown option '$opt'"
>> + ;;
>> + -*)
>> + # split opts -abc into -a -b -c
>> + set -- $(echo "${opt#-}" | sed 's/\(.\)/ -\1/g') "$@"
>> + ;;
>> *)
>> usage
>> exit 1
>> @@ -200,7 +211,7 @@ rootfs="$lxc_path/$lxc_name/rootfs"
>>
>> if [ "$backingstore" = "_unset" -o "$backingstore" = "btrfs" ]; then
>> # if no backing store was given, then see if btrfs would work
>> - if which btrfs >/dev/null 2>&1 &&
>> + if which btrfs >/dev/null 2>&1 && \
>> btrfs filesystem df "$lxc_path/" >/dev/null 2>&1; then
>> backingstore="btrfs"
>> else
>> @@ -246,10 +257,10 @@ elif [ "$backingstore" = "btrfs" ]; then
>> fi
>>
>> cleanup() {
>> - if [ $backingstore = "lvm" ]; then
>> + if [ "$backingstore" = "lvm" ]; then
>> umount $rootfs
>> lvremove -f $rootdev
>> - elif [ $backingstore = "btrfs" ]; then
>> + elif [ "$backingstore" = "btrfs" ]; then
>> btrfs subvolume delete "$rootfs"
>> fi
>> ${bindir}/lxc-destroy -n $lxc_name
>> @@ -299,8 +310,7 @@ if [ ! -z $lxc_template ]; then
>> template_path=${templatedir}/lxc-$lxc_template
>> fi
>>
>> - type $template_path 2>/dev/null
>> - if [ $? -ne 0 ]; then
>> + if ! [ -x "$template_path" ]; then
>> echo "$(basename $0): unknown template '$lxc_template'" >&2
>> cleanup
>> fi
>> @@ -314,7 +324,7 @@ if [ ! -z $lxc_template ]; then
>> echo "'$lxc_template' template installed"
>> fi
>>
>> -if [ $backingstore = "lvm" ]; then
>> +if [ "$backingstore" = "lvm" ]; then
>> echo "Unmounting LVM"
>> umount $rootfs
>>
>> --
>> 1.8.0
>>
>>
>> ------------------------------------------------------------------------------
>> Monitor your physical, virtual and cloud infrastructure from a single
>> web console. Get in-depth insight into apps, servers, databases, vmware,
>> SAP, cloud infrastructure, etc. Download 30-day Free Trial.
>> Pricing starts from $795 for 25 servers or applications!
>> http://p.sf.net/sfu/zoho_dev2dev_nov
>> _______________________________________________
>> Lxc-devel mailing list
>> Lxc-devel at lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/lxc-devel
>
> ------------------------------------------------------------------------------
> Monitor your physical, virtual and cloud infrastructure from a single
> web console. Get in-depth insight into apps, servers, databases, vmware,
> SAP, cloud infrastructure, etc. Download 30-day Free Trial.
> Pricing starts from $795 for 25 servers or applications!
> http://p.sf.net/sfu/zoho_dev2dev_nov
> _______________________________________________
> Lxc-devel mailing list
> Lxc-devel at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/lxc-devel
>


--
St?phane Graber



--
St?phane Graber
Ubuntu developer
http://www.ubuntu.com

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 899 bytes
Desc: OpenPGP digital signature

------------------------------

Message: 5
Date: Wed, 21 Nov 2012 18:04:03 -0500
From: St?phane Graber <stgraber at ubuntu.com>
Subject: [lxc-devel] [PATCH] Rewrite lxc-ls in python
To: Lxc development list <lxc-devel at lists.sourceforge.net>
Message-ID: <50AD5DE3.5020900 at ubuntu.com>
Content-Type: text/plain; charset="iso-8859-1"

This rewrite is mostly compatible with the shell version.
--active and -1 still work and behave as they used to.

This adds --running, --stopped and --frozen as state filters.

A new "fancy" view is also implemented (can be used with --fancy) and
will show containers in a column-based interface with the following fields:
- name
- state
- ipv4
- ipv6
- pid of init

Signed-off-by: St?phane Graber <stgraber at ubuntu.com>
---
.gitignore | 1 -
configure.ac | 1 -
doc/lxc-ls.sgml.in | 150 ++++++++++++++++++++++-----------
src/lxc/Makefile.am | 2 +-
src/lxc/lxc-ls | 236
++++++++++++++++++++++++++++++++++++++++++++++++++++
src/lxc/lxc-ls.in | 94 ---------------------
6 files changed, 340 insertions(+), 144 deletions(-)
create mode 100644 src/lxc/lxc-ls
delete mode 100644 src/lxc/lxc-ls.in

diff --git a/.gitignore b/.gitignore
index d5b07e3..398e4fc 100644
--- a/.gitignore
+++ b/.gitignore
@@ -50,7 +50,6 @@ src/lxc/lxc-freeze
src/lxc/lxc-info
src/lxc/lxc-init
src/lxc/lxc-kill
-src/lxc/lxc-ls
src/lxc/lxc-monitor
src/lxc/lxc-netstat
src/lxc/lxc-ps
diff --git a/configure.ac b/configure.ac
index b6fa365..5f0cc0b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -257,7 +257,6 @@ AC_CONFIG_FILES([
src/Makefile
src/lxc/Makefile
src/lxc/lxc-ps
- src/lxc/lxc-ls
src/lxc/lxc-netstat
src/lxc/lxc-checkconfig
src/lxc/lxc-setcap
diff --git a/doc/lxc-ls.sgml.in b/doc/lxc-ls.sgml.in
index f5f6573..138908d 100644
--- a/doc/lxc-ls.sgml.in
+++ b/doc/lxc-ls.sgml.in
@@ -49,8 +49,14 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston,
MA 02111-1307 USA
<refsynopsisdiv>
<cmdsynopsis>
<command>lxc-ls</command>
+ <arg choice="opt">-1</arg>
<arg choice="opt">--active</arg>
- <arg choice="opt">ls option</arg>
+ <arg choice="opt">--frozen</arg>
+ <arg choice="opt">--running</arg>
+ <arg choice="opt">--stopped</arg>
+ <arg choice="opt">--fancy</arg>
+ <arg choice="opt">--fancy-format</arg>
+ <arg choice="opt">filter</arg>
</cmdsynopsis>
</refsynopsisdiv>
@@ -65,77 +71,127 @@ Foundation, Inc., 59 Temple Place, Suite 330,
Boston, MA 02111-1307 USA
<refsect1>
<title>Options</title>
<variablelist>
+ <varlistentry>
+ <term>
+ <option><optional>-1</optional></option>
+ </term>
+ <listitem>
+ <para>
+ Show one entry per line. (default when /dev/stdout isn't a tty)
+ </para>
+ </listitem>
+ </varlistentry>
<varlistentry>
- <term>
- <option><optional>--active</optional></option>
- </term>
- <listitem>
- <para>
- List active containers.
- </para>
- </listitem>
+ <term>
+ <option><optional>--active</optional></option>
+ </term>
+ <listitem>
+ <para>
+ List only active containers (same as --frozen --running).
+ </para>
+ </listitem>
</varlistentry>
<varlistentry>
- <term>
- <option><optional>ls options</optional></option>
- </term>
- <listitem>
- <para>
- The option passed to <command>lxc-ls</command> are the
- same as the <command>ls</command> command.
- </para>
- </listitem>
+ <term>
+ <option><optional>--frozen</optional></option>
+ </term>
+ <listitem>
+ <para>
+ List only frozen containers.
+ </para>
+ </listitem>
</varlistentry>
- </variablelist>
+ <varlistentry>
+ <term>
+ <option><optional>--running</optional></option>
+ </term>
+ <listitem>
+ <para>
+ List only running containers.
+ </para>
+ </listitem>
+ </varlistentry>
- </refsect1>
+ <varlistentry>
+ <term>
+ <option><optional>--stopped</optional></option>
+ </term>
+ <listitem>
+ <para>
+ List only stopped containers.
+ </para>
+ </listitem>
+ </varlistentry>
- <refsect1>
- <title>Examples</title>
- <variablelist>
<varlistentry>
- <term>lxc-ls -l</term>
- <listitem>
- <para>
- list all the container and their permissions.
- </para>
- </listitem>
+ <term>
+ <option><optional>--fancy</optional></option>
+ </term>
+ <listitem>
+ <para>
+ Use a fancy, column-based output.
+ </para>
+ </listitem>
</varlistentry>
<varlistentry>
- <term>lxc-ls --active -1</term>
- <listitem>
- <para>
- list active containers and display the list in one column.
- </para>
- </listitem>
+ <term>
+ <option><optional>--fancy-format</optional></option>
+ </term>
+ <listitem>
+ <para>
+ Comma separate list of column to show in the fancy output.
+ Valid values are: name, state, ipv4, ipv6 and pid
+ Default is: name,state,ipv4,ipv6
+ </para>
+ </listitem>
</varlistentry>
+ <varlistentry>
+ <term>
+ <option><optional>filter</optional></option>
+ </term>
+ <listitem>
+ <para>
+ The filter passed to <command>lxc-ls</command> will be
+ applied to the container name. The format is a regular
expression.
+ </para>
+ </listitem>
+ </varlistentry>
</variablelist>
</refsect1>
<refsect1>
- <title>See Also</title>
-
- <simpara> - <citerefentry>
- <refentrytitle>ls</refentrytitle>
- <manvolnum>1</manvolnum>
- </citerefentry>,
- </simpara>
+ <title>Examples</title>
+ <variablelist>
+ <varlistentry>
+ <term>lxc-ls --fancy</term>
+ <listitem>
+ <para>
+ list all the containers, listing one per line along with its
+ name, state, ipv4 and ipv6 addresses.
+ </para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>lxc-ls --active -1</term>
+ <listitem>
+ <para>
+ list active containers and display the list in one column.
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
</refsect1>
- &seealso;
-
<refsect1>
<title>Author</title>
- <para>Daniel Lezcano <email>daniel.lezcano at free.fr</email></para>
+ <para>St?phane Graber <email>stgraber at ubuntu.com</email></para>
</refsect1>
-
</refentry>
<!-- Keep this comment at the end of the file
diff --git a/src/lxc/Makefile.am b/src/lxc/Makefile.am
index 7d86ad6..9219ba6 100644
--- a/src/lxc/Makefile.am
+++ b/src/lxc/Makefile.am
@@ -87,7 +87,6 @@ liblxc_so_LDADD = -lutil $(CAP_LIBS) $(APPARMOR_LIBS)
$(SECCOMP_LIBS) -lrt
bin_SCRIPTS = \
lxc-ps \
lxc-netstat \
- lxc-ls \
lxc-checkconfig \
lxc-setcap \
lxc-setuid \
@@ -98,6 +97,7 @@ bin_SCRIPTS = \
lxc-destroy
if ENABLE_PYTHON
+ bin_SCRIPTS += lxc-ls
bin_SCRIPTS += lxc-start-ephemeral
endif
diff --git a/src/lxc/lxc-ls b/src/lxc/lxc-ls
new file mode 100644
index 0000000..8a1d1ed
--- /dev/null
+++ b/src/lxc/lxc-ls
@@ -0,0 +1,236 @@
+#!/usr/bin/python3
+#
+# lxc-ls: List containers
+#
+# This python implementation is based on the work done in the original
+# shell implementation done by Serge Hallyn in Ubuntu (and other
contributors)
+#
+# (C) Copyright Canonical Ltd. 2012
+#
+# Authors:
+# St?phane Graber <stgraber at ubuntu.com>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+
+# NOTE: To remove once the API is stabilized
+import warnings
+warnings.filterwarnings("ignore", "The python-lxc API isn't yet stable")
+
+import argparse
+import gettext
+import lxc
+import re
+import sys
+
+_ = gettext.gettext
+gettext.textdomain("lxc-ls")
+
+
+# Functions used later on
+def batch(iterable, cols=1):
+ import math
+
+ length = len(iterable)
+ lines = math.ceil(length / cols)
+
+ for line in range(lines):
+ fields = []
+ for col in range(cols):
+ index = line + (col * lines)
+ if index < length:
+ fields.append(iterable[index])
+ yield fields
+
+
+def getTerminalSize():
+ import os
+ env = os.environ
+
+ def ioctl_GWINSZ(fd):
+ try:
+ import fcntl
+ import termios
+ import struct
+ cr = struct.unpack('hh', fcntl.ioctl(fd, termios.TIOCGWINSZ,
+ '1234'))
+ return cr
+ except:
+ return
+
+ cr = ioctl_GWINSZ(0) or ioctl_GWINSZ(1) or ioctl_GWINSZ(2)
+ if not cr:
+ try:
+ fd = os.open(os.ctermid(), os.O_RDONLY)
+ cr = ioctl_GWINSZ(fd)
+ os.close(fd)
+ except:
+ pass
+
+ if not cr:
+ cr = (env.get('LINES', 25), env.get('COLUMNS', 80))
+
+ return int(cr[1]), int(cr[0])
+
+# Begin parsing the command line
+parser = argparse.ArgumentParser(description=_("LXC: List containers"),
+
formatter_class=argparse.RawTextHelpFormatter)
+
+parser.add_argument("-1", dest="one", action="store_true",
+ help=_("list one container per line (default when
piped)"))
+
+parser.add_argument("--active", action="store_true",
+ help=_("list only active containers "
+ "(same as --running --frozen)"))
+
+parser.add_argument("--frozen", dest="state", action="append_const",
+ const="FROZEN", help=_("list only frozen containers"))
+
+parser.add_argument("--running", dest="state", action="append_const",
+ const="RUNNING", help=_("list only running
containers"))
+
+parser.add_argument("--stopped", dest="state", action="append_const",
+ const="STOPPED", help=_("list only stopped
containers"))
+
+parser.add_argument("--fancy", action="store_true",
+ help=_("use fancy output"))
+
+parser.add_argument("--fancy-format", type=str,
default="name,state,ipv4,ipv6",
+ help=_("comma separated list of fields to show"))
+
+parser.add_argument("filter", metavar='FILTER', type=str, nargs="?",
+ help=_("regexp to be applied on the container list"))
+
+args = parser.parse_args()
+
+# --active is the same as --running --frozen
+if args.active:
+ if not args.state:
+ args.state = []
+ args.state += ["RUNNING", "FROZEN"]
+
+# If the output is piped, default to --one
+if not sys.stdout.isatty():
+ args.one = True
+
+# Turn args.fancy_format into a list
+args.fancy_format = args.fancy_format.strip().split(",")
+
+# List of containers, stored as dictionaries
+containers = []
+for container in lxc.list_containers(as_object=True):
+ # Filter by status
+ if args.state and container.state not in args.state:
+ continue
+
+ # Apply filter
+ if args.filter and not re.match(args.filter, container.name):
+ continue
+
+ entry = {}
+ entry['name'] = container.name
+
+ # Nothing more is needed if we're not printing some fancy output
+ if not args.fancy:
+ containers.append(entry)
+ continue
+
+ # Some extra field we may want
+ if 'state' in args.fancy_format:
+ entry['state'] = container.state
+ if 'pid' in args.fancy_format:
+ entry['pid'] = "-"
+ if container.init_pid != -1:
+ entry['pid'] = str(container.init_pid)
+
+ # Get the IPs
+ for protocol in ('ipv4', 'ipv6'):
+ if protocol in args.fancy_format:
+ entry[protocol] = "-"
+ ips = container.get_ips(protocol=protocol, timeout=1)
+ if ips:
+ entry[protocol] = ", ".join(ips)
+
+ containers.append(entry)
+
+
+# Print the list
+## Standard list with one entry per line
+if not args.fancy and args.one:
+ for container in sorted(containers,
+ key=lambda container: container['name']):
+ print(container['name'])
+ sys.exit(0)
+
+## Standard list with multiple entries per line
+if not args.fancy and not args.one:
+ # Get the longest name and extra simple list
+ field_maxlength = 0
+ container_names = []
+ for container in containers:
+ if len(container['name']) > field_maxlength:
+ field_maxlength = len(container['name'])
+ container_names.append(container['name'])
+
+ # Figure out how many we can put per line
+ width = getTerminalSize()[0]
+
+ entries = int(width / (field_maxlength + 2))
+ if entries == 0:
+ entries = 1
+
+ for line in batch(sorted(container_names), entries):
+ line_format = ""
+ for index in range(len(line)):
+ line_format += "{line[%s]:%s}" % (index, field_maxlength + 2)
+
+ print(line_format.format(line=line))
+
+## Fancy listing
+if args.fancy:
+ field_maxlength = {}
+
+ # Get the maximum length per field
+ for field in args.fancy_format:
+ field_maxlength[field] = len(field)
+
+ for container in containers:
+ for field in args.fancy_format:
+ if len(container[field]) > field_maxlength[field]:
+ field_maxlength[field] = len(container[field])
+
+ # Generate the line format string based on the maximum length and
+ # a 2 character padding
+ line_format = ""
+ index = 0
+ for field in args.fancy_format:
+ line_format += "{fields[%s]:%s}" % (index,
field_maxlength[field] + 2)
+ index += 1
+
+ # Get the line length minus the padding of the last field
+ line_length = -2
+ for field in field_maxlength:
+ line_length += field_maxlength[field] + 2
+
+ # Print header
+ print(line_format.format(fields=[header.upper()
+ for header in args.fancy_format]))
+ print("-" * line_length)
+
+ # Print the entries
+ for container in sorted(containers,
+ key=lambda container: container['name']):
+ fields = [container[field] for field in args.fancy_format]
+ print(line_format.format(fields=fields))
diff --git a/src/lxc/lxc-ls.in b/src/lxc/lxc-ls.in
deleted file mode 100644
index f26572d..0000000
--- a/src/lxc/lxc-ls.in
+++ /dev/null
@@ -1,94 +0,0 @@
-#!/bin/bash
-
-#
-# lxc: linux Container library
-
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# Lesser General Public License for more details.
-
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-lxc_path=@LXCPATH@
-
-usage()
-{
- echo "usage: $(basename $0) [--active] [--] [LS_OPTIONS...]" >&2
-}
-
-help() {
- usage
- echo >&2
- echo "List containers existing on the system." >&2
- echo >&2
- echo " --active list active containers" >&2
- echo " LS_OPTIONS ls command options (see \`ls --help')" >&2
-}
-
-get_parent_cgroup()
-{
- local hierarchies hierarchy fields subsystems init_cgroup mountpoint
-
- parent_cgroup=""
-
- # Obtain a list of hierarchies that contain one or more subsystems
- hierarchies=$(tail -n +2 /proc/cgroups | cut -f 2)
-
- # Iterate through the list until a suitable hierarchy is found
- for hierarchy in $hierarchies; do
- # Obtain information about the init process in the hierarchy
- fields=$(grep -E "^$hierarchy:" /proc/1/cgroup | head -n 1)
- if [ -z "$fields" ]; then continue; fi
- fields=${fields#*:}
-
- # Get a comma-separated list of the hierarchy's subsystems
- subsystems=${fields%:*}
-
- # Get the cgroup of the init process in the hierarchy
- init_cgroup=${fields#*:}
-
- # Get the filesystem mountpoint of the hierarchy
- mountpoint=$(grep -E "^[^ ]+ [^ ]+ cgroup ([^ ]+,)?$subsystems(,[^
]+)? " /proc/self/mounts | cut -d ' ' -f 2)
- if [ -z "$mountpoint" ]; then continue; fi
-
- # Return the absolute path to the containers' parent cgroup
- # (do not append '/lxc' if the hierarchy contains the 'ns' subsystem)
- if [[ ",$subsystems," == *,ns,* ]]; then
- parent_cgroup="${mountpoint}${init_cgroup%/}"
- else
- parent_cgroup="${mountpoint}${init_cgroup%/}/lxc"
- fi
- break
- done
-}
-
-directory=$(readlink -f "$lxc_path")
-
-for i in "$@"; do
- case $i in
- --help)
- help; exit;;
- --active)
- get_parent_cgroup; directory="$parent_cgroup"; shift;;
- --)
- shift; break;;
- *)
- break;;
- esac
-done
-
-containers=""
-if [ ! -z "$directory" ]; then
- containers=$(find $directory -mindepth 1 -maxdepth 1 -type d -printf
"%f\n" 2>/dev/null)
-fi
-
-cd "$directory"
-ls -d $@ -- $containers
--
1.8.0


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 899 bytes
Desc: OpenPGP digital signature

------------------------------

------------------------------------------------------------------------------
Monitor your physical, virtual and cloud infrastructure from a single
web console. Get in-depth insight into apps, servers, databases, vmware,
SAP, cloud infrastructure, etc. Download 30-day Free Trial.
Pricing starts from $795 for 25 servers or applications!
http://p.sf.net/sfu/zoho_dev2dev_nov

------------------------------

_______________________________________________
Lxc-devel mailing list
Lxc-devel at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


End of Lxc-devel Digest, Vol 51, Issue 13
*****************************************

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20121122/c120d4f3/attachment.html>


More information about the lxc-devel mailing list