Hi!

Here's a rebased version with the pointed out problems fixed.
Please apply, the difference in speed is drastic on most systems.

-- 
ᛊᚨᚾᛁᛏᚣ᛫ᛁᛊ᛫ᚠᛟᚱ᛫ᚦᛖ᛫ᚹᛖᚨᚲ
>From 5cd826ac5d94f5994bfe824c1c01520763c159c7 Mon Sep 17 00:00:00 2001
From: Adam Borowski <kilob...@angband.pl>
Date: Mon, 16 Sep 2013 22:46:56 +0200
Subject: [PATCH] eatmydata support [Adrian von Bidder]

Fixes from #606158 included.

Among them is a hard-dependency on eatmydata to solve a corner case
when eatmydata is requested but available only inside the chroot.
This could be done differently if you want to trim dependencies,
but I'm unsure it's worth the effort.
---
 debian/control                      |  1 +
 pbuilder                            |  2 +-
 pbuilder-buildpackage-funcs         |  2 +-
 pbuilder-checkparams                | 14 ++++++++++++++
 pbuilder-createbuildenv             | 12 ++++++++++++
 pbuilder-modules                    |  6 ++++++
 pbuilder-satisfydepends-checkparams |  4 ++++
 pbuilder.8                          |  6 +++++-
 pdebuild-checkparams                |  4 ++++
 pdebuild-internal                   |  8 ++++++++
 10 files changed, 56 insertions(+), 3 deletions(-)

diff --git a/debian/control b/debian/control
index f4a1f94..291c299 100644
--- a/debian/control
+++ b/debian/control
@@ -25,6 +25,7 @@ Depends: coreutils (>= 4.5.8-1),
          dpkg-dev,
          debianutils (>= 1.13.1),
          wget,
+         eatmydata,
          ${misc:Depends}
 Recommends: fakeroot,
             sudo,
diff --git a/pbuilder b/pbuilder
index d816183..4bfee48 100755
--- a/pbuilder
+++ b/pbuilder
@@ -69,7 +69,7 @@ File extracted to: $BUILDPLACE
 "
 	fi
 	executehooks "F"
-	(${CHROOTEXEC} bin/bash -c 'exec -a -bash bin/bash')
+	(${CHROOTEXEC} /bin/bash -c 'exec -a -bash bin/bash')
 	RET=$?
 
 	save_aptcache
diff --git a/pbuilder-buildpackage-funcs b/pbuilder-buildpackage-funcs
index 3083f03..98d6de1 100644
--- a/pbuilder-buildpackage-funcs
+++ b/pbuilder-buildpackage-funcs
@@ -50,7 +50,7 @@ function checkbuilddep () {
     fi
     # install extra packages to the chroot
     if [ -n "$EXTRAPACKAGES" ]; then 
-	$CHROOTEXEC usr/bin/apt-get -q -y "${APTGETOPT[@]}" install ${EXTRAPACKAGES}
+	$CHROOTEXEC /usr/bin/apt-get -q -y "${APTGETOPT[@]}" install ${EXTRAPACKAGES}
     fi
 }
 
diff --git a/pbuilder-checkparams b/pbuilder-checkparams
index 3cdc48e..d8547fc 100755
--- a/pbuilder-checkparams
+++ b/pbuilder-checkparams
@@ -231,6 +231,10 @@ while [ -n "$1" ]; do
 	    OUTPUTFILE[${#OUTPUTFILE[@]}]="$2";
 	    shift; shift; 
 	    ;;
+        --no-eatmydata)
+            EATMYDATA="no"
+	    shift;
+            ;;
 
 	## internal options.
 	--internal-chrootexec)
@@ -321,6 +325,16 @@ fi
 # sort BINDMOUNTS to ensure that deeper directories are mounted last
 BINDMOUNTS="$(for i in $BINDMOUNTS; do echo $i; done | sort -u)"
 
+pbuilder_old_LD_PRELOAD="$LD_PRELOAD"
+# enable eatmydata if available and not disabled
+if [ -f "/usr/lib/libeatmydata/libeatmydata.so" -a "$EATMYDATA" != "no" ]; then
+    if [ -z "$LD_PRELOAD" ]; then
+        export LD_PRELOAD="/usr/lib/libeatmydata/libeatmydata.so"
+    else
+        export LD_PRELOAD="$LD_PRELOAD:/usr/lib/libeatmydata/libeatmydata.so"
+    fi
+fi
+
 if [ "$ALLOWUNTRUSTED" = "yes" ]; then
     PBUILDERSATISFYDEPENDSOPT[${#PBUILDERSATISFYDEPENDSOPT[@]}]='--allow-untrusted'
     # Also duplicated in pbuilder-satisfydepends-checkparams!
diff --git a/pbuilder-createbuildenv b/pbuilder-createbuildenv
index 8362b1c..40057f4 100755
--- a/pbuilder-createbuildenv
+++ b/pbuilder-createbuildenv
@@ -89,6 +89,12 @@ mkdir -p "$BUILDPLACE/tmp/buildd"
 copy_local_configuration
 installaptlines
 add_additional_aptkeyrings
+
+# Can't use eatmydata while it is not yet installed in the chroot
+if echo "$LD_PRELOAD" | grep -q libeatmydata.so; then
+    LD_PRELOAD="$pbuilder_old_LD_PRELOAD"
+fi
+
 executehooks "G"
 
 log "I: Refreshing the base.tgz "
@@ -112,6 +118,12 @@ else
     EXTRAPACKAGES="$EXTRAPACKAGES ccache-"
 fi
 
+if [ "$EATMYDATA" != "no" ]; then
+    EXTRAPACKAGES="$EXTRAPACKAGES eatmydata"
+else
+    EXTRAPACKAGES="$EXTRAPACKAGES eatmydata-"
+fi
+
 if [ -n "$REMOVEPACKAGES" ]; then
     # FIXME this wont work if the packages have some reverse dependencies;
     # apt-get can also remove package, either with apt-get remove or purge, or
diff --git a/pbuilder-modules b/pbuilder-modules
index 055d611..db4b5e5 100644
--- a/pbuilder-modules
+++ b/pbuilder-modules
@@ -468,6 +468,12 @@ function extractbuildplace () {
 
     mountproc
     mkdir -p "$BUILDPLACE/tmp/buildd"
+
+    # if available inside the chroot and if not disabled, use eatmydata:
+    if [ -f "$BUILDPLACE/usr/lib/libeatmydata/libeatmydata.so" \
+            -a "$EATMYDATA" != "no" ]; then
+        CHROOTEXEC="$CHROOTEXEC eatmydata "
+    fi
 }
 
 function echobacktime () {
diff --git a/pbuilder-satisfydepends-checkparams b/pbuilder-satisfydepends-checkparams
index 24a601f..2df9717 100755
--- a/pbuilder-satisfydepends-checkparams
+++ b/pbuilder-satisfydepends-checkparams
@@ -44,6 +44,10 @@ while [ -n "$1" ]; do
 		echo '--chroot specified after --internal-chrootexec' >&2
 		exit 1
 	    fi
+            if [ -f "$CHROOT/usr/lib/libeatmydata/libeatmydata.so" \
+                    -a "$EATMYDATA" != "no" ]; then
+                CHROOTEXEC="$CHROOTEXEC eatmydata "
+            fi
 	    shift; shift
 	    ;;
 	--internal-chrootexec)
diff --git a/pbuilder.8 b/pbuilder.8
index a2f37c3..64c6ec6 100644
--- a/pbuilder.8
+++ b/pbuilder.8
@@ -417,8 +417,12 @@ This is useful when you keep a aptcache directory for each distribution
 and want to keep the size of the aptcache down.
 
 .TP
-.BI "\-\-help"
+.BI "\-\-no\-eatmydata"
+Do not use eatmydata.  Eatmydata is used by default if installed (on the host
+system when creating the base.tgz or in the base.tgz for all other operations.)
 
+.TP
+.BI "\-\-help"
 Show a brief help message.
 
 .SH "MORE SPECIFIC OPTIONS"
diff --git a/pdebuild-checkparams b/pdebuild-checkparams
index b6ba0ed..f49002c 100644
--- a/pdebuild-checkparams
+++ b/pdebuild-checkparams
@@ -99,6 +99,10 @@ while [ -n "$1" ]; do
 	    PDEBUILD_PBUILDER="$2"
 	    shift; shift;
 	    ;;
+        --no-eatmydata)
+            EATMYDATA="no"
+	    shift;
+            ;;
 	--help)
 	    showhelp
 	    ;;
diff --git a/pdebuild-internal b/pdebuild-internal
index 0c4fb99..79c330a 100644
--- a/pdebuild-internal
+++ b/pdebuild-internal
@@ -89,6 +89,14 @@ BUILDPLACE=/
 # chroot command will just chroot to /, which will effectively chdir
 # to / and nothing else.
 CHROOTEXEC="chroot $BUILDPLACE "
+# if not explicitly disabled and if available: enable eatmydata
+if [ -f "/usr/lib/libeatmydata/libeatmydata.so" -a "$EATMYDATA" != "no" ]; then
+    if [ -z "$LD_PRELOAD" ]; then
+        export LD_PRELOAD="/usr/lib/libeatmydata/libeatmydata.so"
+    else
+        export LD_PRELOAD="$LD_PRELOAD:/usr/lib/libeatmydata/libeatmydata.so"
+    fi
+fi
 # make HOOKDIR contain something if there is a hook, to fool HOOKDIR
 # check inside pbuilder-runhooks that there is HOOKDIR
 # configuration. We don't call loadhooks or unloadhooks ourselves,
-- 
1.8.4.rc3

Reply via email to