qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 0/3] linux-user: manage binfmt F flag
@ 2018-06-27 20:53 Laurent Vivier
  2018-06-27 20:53 ` [Qemu-devel] [PATCH 1/3] qemu-binfmt-conf.sh: cleanup --credential Laurent Vivier
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Laurent Vivier @ 2018-06-27 20:53 UTC (permalink / raw)
  To: qemu-devel; +Cc: Laurent Vivier, Riku Voipio

The binfmt F flag ("Fix binaries") allows to
load the interpreter binary at configuration time
and all future users are cloned from this memory copy.

This avoids to have to copy the interpreter to
the filesystem of the target we want to use.

This series introduces this new flag in qemu-binfmt-conf.sh
and another new parameter to provide a suffix to the default
qemu-CPU name to be able to use static version of qemu linux-user
provided by distros:

  qemu-binfmt-conf.sh --qemu-path /usr/bin --qemu-suffix -static \
                      --systemd m68k --credential yes --persistent yes

configures binfmt to use /usr/bin/qemu-m68k-static from the root filesystem
to interpret m68k binaries in unmodified chroots or containers/dockers.

With systemd, the interpreter is loaded when you restart the systemd-binfmt
service:

  systemctl restart systemd-binfmt.service

With that, you can execute directly a debootstrap without the --foreign
parameter.

  debootstrap --arch=m68k --variant=minbase \
              --no-check-gpg etch-m68k chroot-m68k \
              http://archive.debian.org/debian
  chroot chroot-m68k
  localhost:/# ls
  bin   dev  home    lib    mnt  proc  sbin  sys   usr
  boot  etc  initrd  media  opt  root  srv   tmp   var

Laurent Vivier (3):
  qemu-binfmt-conf.sh: cleanup --credential
  qemu-binfmt-conf.sh: add persistent (F) flags
  qemu-binfmt-conf.sh: allow to provide a suffix to the interpreter name

 scripts/qemu-binfmt-conf.sh | 64 +++++++++++++++++++++++++++++----------------
 1 file changed, 41 insertions(+), 23 deletions(-)

-- 
2.14.4

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Qemu-devel] [PATCH 1/3] qemu-binfmt-conf.sh: cleanup --credential
  2018-06-27 20:53 [Qemu-devel] [PATCH 0/3] linux-user: manage binfmt F flag Laurent Vivier
@ 2018-06-27 20:53 ` Laurent Vivier
  2018-06-27 20:53 ` [Qemu-devel] [PATCH 2/3] qemu-binfmt-conf.sh: add persistent (F) flags Laurent Vivier
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Laurent Vivier @ 2018-06-27 20:53 UTC (permalink / raw)
  To: qemu-devel; +Cc: Laurent Vivier, Riku Voipio

move credential value to its own variable to be able to manage
more flags

Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
 scripts/qemu-binfmt-conf.sh | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/scripts/qemu-binfmt-conf.sh b/scripts/qemu-binfmt-conf.sh
index d7eefda0b8..9900554608 100755
--- a/scripts/qemu-binfmt-conf.sh
+++ b/scripts/qemu-binfmt-conf.sh
@@ -241,7 +241,12 @@ qemu_check_systemd() {
 }
 
 qemu_generate_register() {
-    echo ":qemu-$cpu:M::$magic:$mask:$qemu:$FLAGS"
+    flags=""
+    if [ "$CREDENTIAL" = "yes" ] ; then
+        flags="OC"
+    fi
+
+    echo ":qemu-$cpu:M::$magic:$mask:$qemu:$flags"
 }
 
 qemu_register_interpreter() {
@@ -260,10 +265,8 @@ package qemu-$cpu
 interpreter $qemu
 magic $magic
 mask $mask
+credential $CREDENTIAL
 EOF
-    if [ "$FLAGS" = "OC" ] ; then
-        echo "credentials yes" >> "$EXPORTDIR/qemu-$cpu"
-    fi
 }
 
 qemu_set_binfmts() {
@@ -300,7 +303,7 @@ SYSTEMDDIR="/etc/binfmt.d"
 DEBIANDIR="/usr/share/binfmts"
 
 QEMU_PATH=/usr/local/bin
-FLAGS=""
+CREDENTIAL=no
 
 options=$(getopt -o ds:Q:e:hc: -l debian,systemd:,qemu-path:,exportdir:,help,credential: -- "$@")
 eval set -- "$options"
@@ -348,11 +351,7 @@ while true ; do
         ;;
     -c|--credential)
         shift
-        if [ "$1" = "yes" ] ; then
-            FLAGS="OC"
-        else
-            FLAGS=""
-        fi
+        CREDENTIAL="$1"
         ;;
     *)
         break
-- 
2.14.4

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [Qemu-devel] [PATCH 2/3] qemu-binfmt-conf.sh: add persistent (F) flags
  2018-06-27 20:53 [Qemu-devel] [PATCH 0/3] linux-user: manage binfmt F flag Laurent Vivier
  2018-06-27 20:53 ` [Qemu-devel] [PATCH 1/3] qemu-binfmt-conf.sh: cleanup --credential Laurent Vivier
@ 2018-06-27 20:53 ` Laurent Vivier
  2018-06-27 20:53 ` [Qemu-devel] [PATCH 3/3] qemu-binfmt-conf.sh: allow to provide a suffix to the interpreter name Laurent Vivier
  2018-07-02  2:37 ` [Qemu-devel] [PATCH 0/3] linux-user: manage binfmt F flag no-reply
  3 siblings, 0 replies; 5+ messages in thread
From: Laurent Vivier @ 2018-06-27 20:53 UTC (permalink / raw)
  To: qemu-devel; +Cc: Laurent Vivier, Riku Voipio

Since kernel commit 948b701a607f
(binfmt_misc: add persistent opened binary handler for containers)
kernel allows to load the interpreter at the configuration time.

In case of chroot, it allows to have the interpreter in the host root
filesystem and not to copy it to the chroot filesystem.

Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
 scripts/qemu-binfmt-conf.sh | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/scripts/qemu-binfmt-conf.sh b/scripts/qemu-binfmt-conf.sh
index 9900554608..00c9c3aa16 100755
--- a/scripts/qemu-binfmt-conf.sh
+++ b/scripts/qemu-binfmt-conf.sh
@@ -161,6 +161,7 @@ usage() {
     cat <<EOF
 Usage: qemu-binfmt-conf.sh [--qemu-path PATH][--debian][--systemd CPU]
                            [--help][--credential yes|no][--exportdir PATH]
+                           [--persistent yes|no]
 
        Configure binfmt_misc to use qemu interpreter
 
@@ -176,6 +177,9 @@ Usage: qemu-binfmt-conf.sh [--qemu-path PATH][--debian][--systemd CPU]
                      (default: $SYSTEMDDIR or $DEBIANDIR)
        --credential: if yes, credential and security tokens are
                      calculated according to the binary to interpret
+       --persistent: if yes, the interpreter is loaded when binfmt is
+                     configured and remains in memory. All future uses
+                     are cloned from the open file.
 
     To import templates with update-binfmts, use :
 
@@ -245,6 +249,9 @@ qemu_generate_register() {
     if [ "$CREDENTIAL" = "yes" ] ; then
         flags="OC"
     fi
+    if [ "$PERSISTENT" = "yes" ] ; then
+        flags="${flags}F"
+    fi
 
     echo ":qemu-$cpu:M::$magic:$mask:$qemu:$flags"
 }
@@ -304,8 +311,9 @@ DEBIANDIR="/usr/share/binfmts"
 
 QEMU_PATH=/usr/local/bin
 CREDENTIAL=no
+PERSISTENT=no
 
-options=$(getopt -o ds:Q:e:hc: -l debian,systemd:,qemu-path:,exportdir:,help,credential: -- "$@")
+options=$(getopt -o ds:Q:e:hc:p: -l debian,systemd:,qemu-path:,exportdir:,help,credential:,persistent: -- "$@")
 eval set -- "$options"
 
 while true ; do
@@ -353,6 +361,10 @@ while true ; do
         shift
         CREDENTIAL="$1"
         ;;
+    -p|--persistent)
+        shift
+        PERSISTENT="$1"
+        ;;
     *)
         break
         ;;
-- 
2.14.4

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [Qemu-devel] [PATCH 3/3] qemu-binfmt-conf.sh: allow to provide a suffix to the interpreter name
  2018-06-27 20:53 [Qemu-devel] [PATCH 0/3] linux-user: manage binfmt F flag Laurent Vivier
  2018-06-27 20:53 ` [Qemu-devel] [PATCH 1/3] qemu-binfmt-conf.sh: cleanup --credential Laurent Vivier
  2018-06-27 20:53 ` [Qemu-devel] [PATCH 2/3] qemu-binfmt-conf.sh: add persistent (F) flags Laurent Vivier
@ 2018-06-27 20:53 ` Laurent Vivier
  2018-07-02  2:37 ` [Qemu-devel] [PATCH 0/3] linux-user: manage binfmt F flag no-reply
  3 siblings, 0 replies; 5+ messages in thread
From: Laurent Vivier @ 2018-06-27 20:53 UTC (permalink / raw)
  To: qemu-devel; +Cc: Laurent Vivier, Riku Voipio

some distros provide a qemu-CPU-static binary beside the qemu-CPU one.
This change allows to use it by providing "--qemu-suffix -static" to the
script.

Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
 scripts/qemu-binfmt-conf.sh | 41 ++++++++++++++++++++++++-----------------
 1 file changed, 24 insertions(+), 17 deletions(-)

diff --git a/scripts/qemu-binfmt-conf.sh b/scripts/qemu-binfmt-conf.sh
index 00c9c3aa16..23df00ae30 100755
--- a/scripts/qemu-binfmt-conf.sh
+++ b/scripts/qemu-binfmt-conf.sh
@@ -161,25 +161,26 @@ usage() {
     cat <<EOF
 Usage: qemu-binfmt-conf.sh [--qemu-path PATH][--debian][--systemd CPU]
                            [--help][--credential yes|no][--exportdir PATH]
-                           [--persistent yes|no]
+                           [--persistent yes|no][--qemu-suffix SUFFIX]
 
        Configure binfmt_misc to use qemu interpreter
 
-       --help:       display this usage
-       --qemu-path:  set path to qemu interpreter ($QEMU_PATH)
-       --debian:     don't write into /proc,
-                     instead generate update-binfmts templates
-       --systemd:    don't write into /proc,
-                     instead generate file for systemd-binfmt.service
-                     for the given CPU. If CPU is "ALL", generate a
-                     file for all known cpus
-       --exportdir:  define where to write configuration files
-                     (default: $SYSTEMDDIR or $DEBIANDIR)
-       --credential: if yes, credential and security tokens are
-                     calculated according to the binary to interpret
-       --persistent: if yes, the interpreter is loaded when binfmt is
-                     configured and remains in memory. All future uses
-                     are cloned from the open file.
+       --help:        display this usage
+       --qemu-path:   set path to qemu interpreter ($QEMU_PATH)
+       --qemu-suffix: add a suffix to the default interpreter name
+       --debian:      don't write into /proc,
+                      instead generate update-binfmts templates
+       --systemd:     don't write into /proc,
+                      instead generate file for systemd-binfmt.service
+                      for the given CPU. If CPU is "ALL", generate a
+                      file for all known cpus
+       --exportdir:   define where to write configuration files
+                      (default: $SYSTEMDDIR or $DEBIANDIR)
+       --credential:  if yes, credential and security tokens are
+                      calculated according to the binary to interpret
+       --persistent:  if yes, the interpreter is loaded when binfmt is
+                      configured and remains in memory. All future uses
+                      are cloned from the open file.
 
     To import templates with update-binfmts, use :
 
@@ -297,6 +298,7 @@ qemu_set_binfmts() {
             qemu="$QEMU_PATH/qemu-i386"
         fi
 
+        qemu="$qemu$QEMU_SUFFIX"
         if [ "$host_family" != "$family" ] ; then
             $BINFMT_SET
         fi
@@ -312,8 +314,9 @@ DEBIANDIR="/usr/share/binfmts"
 QEMU_PATH=/usr/local/bin
 CREDENTIAL=no
 PERSISTENT=no
+QEMU_SUFFIX=""
 
-options=$(getopt -o ds:Q:e:hc:p: -l debian,systemd:,qemu-path:,exportdir:,help,credential:,persistent: -- "$@")
+options=$(getopt -o ds:Q:S:e:hc:p: -l debian,systemd:,qemu-path:,qemu-suffix:,exportdir:,help,credential:,persistent: -- "$@")
 eval set -- "$options"
 
 while true ; do
@@ -349,6 +352,10 @@ while true ; do
         shift
         QEMU_PATH="$1"
         ;;
+    -F|--qemu-suffix)
+        shift
+        QEMU_SUFFIX="$1"
+        ;;
     -e|--exportdir)
         shift
         EXPORTDIR="$1"
-- 
2.14.4

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH 0/3] linux-user: manage binfmt F flag
  2018-06-27 20:53 [Qemu-devel] [PATCH 0/3] linux-user: manage binfmt F flag Laurent Vivier
                   ` (2 preceding siblings ...)
  2018-06-27 20:53 ` [Qemu-devel] [PATCH 3/3] qemu-binfmt-conf.sh: allow to provide a suffix to the interpreter name Laurent Vivier
@ 2018-07-02  2:37 ` no-reply
  3 siblings, 0 replies; 5+ messages in thread
From: no-reply @ 2018-07-02  2:37 UTC (permalink / raw)
  To: laurent; +Cc: famz, qemu-devel, riku.voipio

Hi,

This series seems to have some coding style problems. See output below for
more information:

Type: series
Message-id: 20180627205317.10343-1-laurent@vivier.eu
Subject: [Qemu-devel] [PATCH 0/3] linux-user: manage binfmt F flag

=== TEST SCRIPT BEGIN ===
#!/bin/bash

BASE=base
n=1
total=$(git log --oneline $BASE.. | wc -l)
failed=0

git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram

commits="$(git log --format=%H --reverse $BASE..)"
for c in $commits; do
    echo "Checking PATCH $n/$total: $(git log -n 1 --format=%s $c)..."
    if ! git show $c --format=email | ./scripts/checkpatch.pl --mailback -; then
        failed=1
        echo
    fi
    n=$((n+1))
done

exit $failed
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
Switched to a new branch 'test'
38edb2d27d qemu-binfmt-conf.sh: allow to provide a suffix to the interpreter name
9a994aeb9f qemu-binfmt-conf.sh: add persistent (F) flags
9bd3bbabfb qemu-binfmt-conf.sh: cleanup --credential

=== OUTPUT BEGIN ===
Checking PATCH 1/3: qemu-binfmt-conf.sh: cleanup --credential...
Checking PATCH 2/3: qemu-binfmt-conf.sh: add persistent (F) flags...
ERROR: line over 90 characters
#55: FILE: scripts/qemu-binfmt-conf.sh:316:
+options=$(getopt -o ds:Q:e:hc:p: -l debian,systemd:,qemu-path:,exportdir:,help,credential:,persistent: -- "$@")

total: 1 errors, 0 warnings, 45 lines checked

Your patch has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.

Checking PATCH 3/3: qemu-binfmt-conf.sh: allow to provide a suffix to the interpreter name...
ERROR: line over 90 characters
#76: FILE: scripts/qemu-binfmt-conf.sh:319:
+options=$(getopt -o ds:Q:S:e:hc:p: -l debian,systemd:,qemu-path:,qemu-suffix:,exportdir:,help,credential:,persistent: -- "$@")

total: 1 errors, 0 warnings, 69 lines checked

Your patch has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.

=== OUTPUT END ===

Test command exited with code: 1


---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to patchew-devel@redhat.com

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2018-07-02  2:38 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-06-27 20:53 [Qemu-devel] [PATCH 0/3] linux-user: manage binfmt F flag Laurent Vivier
2018-06-27 20:53 ` [Qemu-devel] [PATCH 1/3] qemu-binfmt-conf.sh: cleanup --credential Laurent Vivier
2018-06-27 20:53 ` [Qemu-devel] [PATCH 2/3] qemu-binfmt-conf.sh: add persistent (F) flags Laurent Vivier
2018-06-27 20:53 ` [Qemu-devel] [PATCH 3/3] qemu-binfmt-conf.sh: allow to provide a suffix to the interpreter name Laurent Vivier
2018-07-02  2:37 ` [Qemu-devel] [PATCH 0/3] linux-user: manage binfmt F flag no-reply

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).