Bug 152945 - sys-kernel/genkernel: fix unionfs support
Bug#: 152945 Product:  Gentoo Hosted Projects Version: unspecified Platform: All
OS/Version: Linux Status: RESOLVED Severity: normal Priority: P2
Resolution: FIXED Assigned To: genkernel@gentoo.org Reported By: lxnay@lxnaydesign.net
Component: genkernel
URL:  http://www.archlinux.org/packages/10670/
Summary: sys-kernel/genkernel: fix unionfs support
Keywords:  InSVN
Status Whiteboard: 
Opened: 2006-10-26 23:31 0000
Description:   Opened: 2006-10-26 23:31 0000
I have fixed unionfs support (--unionfs-dev) in genkernel. 2.6.18 kernel and
latest unionfs >1.3 support is there, to get this one working I had to use a
well-tested unionfs devel snapshot (thanks Arch Linux).
Genkernel patch (against 3.4.4) attached.

------- Comment #1 From Fabio Erculiani 2006-10-26 23:33:04 0000 -------
Created an attachment (id=100566) [details]
fixed unionfs compilation

------- Comment #2 From Fabio Erculiani 2006-10-26 23:36:51 0000 -------
Created an attachment (id=100567) [details]
fixed unionfs compilation

------- Comment #3 From Chris Gianelloni (RETIRED) 2006-10-27 09:46:25 0000 -------
This doesn't really "fix" it, which is why I haven't applied anything like this
yet.  The problem is that you need certain unionfs versions for certain
kernels, which causes all kinds of hell to break loose.  Since genkernel is
supposed to be a generic kernel builder, it cannot be limited to a specific
kernel version.  Basically, we need a smarter unionfs build system for
genkernel, or it needs to be stripped entirely and rethought.

------- Comment #4 From Fabio Erculiani 2006-10-27 11:46:40 0000 -------
yes but at least include those changes. I think that they are safe and needed
to test unionfs+genkernel progresses.

Please do not remove unionfs code in genkernel, it would be a shame, just keep
that disabled so I can re-enable and fix the things that do not work ;)

If you want, I could maintain that stuff.

------- Comment #5 From Dan Casimiro 2006-10-29 05:45:52 0000 -------
Created an attachment (id=100706) [details]
unionfs helper functions

You can use a hash table to choose the correct unionfs version based on the
kernel. This attachment implements the hash table logic. It will set
UNIONFS_VERSION to the correct version, given the value in ${KV}.

To use these functions, change gen_compile.sh to source the file. Then, add:
+               get_unionfs_version
+               # subsitute source tarball here.
+               # the user can override this functionality by changing
+               # ${UNIONFS_SRCTAR} in /etc/genkernel.conf. genkernel can
+               # print a warning if the two versions do not match.
+               UNIONFS_SRCTAR=${UNIONFS_SRCTAR/UNIONFS_VER/${UNIONFS_VERSION}}

inside of compile_unionfs_modules.  The genkernel ebuild will have to download
the different versions of unionfs.  Also, this idea can be extended to invoke 
different versions of compile_unionfs_modules, if the versions differ enough.

------- Comment #6 From Fabio Erculiani 2006-10-29 07:16:04 0000 -------
great :)
yes there are some small differences from unionfs 1.3 and the current svn. You
can see the workaround to compile unionfs utils inside my patch.

------- Comment #7 From Dan Casimiro 2006-11-22 17:10:39 0000 -------
Created an attachment (id=102580) [details]
Use callbacks to build the correct unionfs based on the current kernel

This patch implements the complete callback system.  I have tested it with a
2.6.15 kernel and a 2.6.17 kernel. It may or may not work with different
variants. It does not support 2.4.x kernels. The patch requires a small change
to genkernel.conf.  The difference is included in the patch.  Look for the
section named "sample_unionfs_genkernel.conf."

Most of the interesting stuff is added into a new file named
gen_unionfs_helper.sh. gen_compile.sh has been changed to call into the new
file. I think that this patch is at least a start.

------- Comment #8 From Fabio Erculiani 2006-11-22 22:36:07 0000 -------
2.6.17???
Does it work with 2.6.18 kernels and a 2.6.18-aware unionfs?
There have been some changes in the unionfs sources lately.

------- Comment #9 From Dan Casimiro 2006-11-23 06:05:59 0000 -------
I have not tested with a 2.6.18 kernel.  I didn't have a 2.6.18 kernel around,
but the patch does have the hooks for unionfs version 1.4. Currently, those
hooks just call the version 1.3 entry points.  Look for
"compile_unionfs_modules_1_4()" and "compile_unionfs_utils_1_4()" in
gen_unionfs_helpers.sh.

------- Comment #10 From Dan Casimiro 2006-11-23 06:20:13 0000 -------
(In reply to comment #9)
> I have not tested with a 2.6.18 kernel.  I didn't have a 2.6.18 kernel around,
> but the patch does have the hooks for unionfs version 1.4. Currently, those
> hooks just call the version 1.3 entry points.  Look for
> "compile_unionfs_modules_1_4()" and "compile_unionfs_utils_1_4()" in
> gen_unionfs_helpers.sh.
> 
Update: I just tested it and it works without any changes.

------- Comment #11 From Fabio Erculiani 2006-11-29 05:38:59 0000 -------
Ok Dan, I am going to test that ASAP.

Chris? any hint? Is there anything that we could do to get unionfs back into
genkernel? You could even add a USE flag on the genkernel ebuild that enables
this "experimental" unionfs support.

------- Comment #12 From Fabio Erculiani 2006-12-26 00:58:22 0000 -------
I've tested your patch, in few words:
- unnecessarily complex
- buggy
- needs constant updates to keep in sync with new unionfs releases

------- Comment #13 From Dan Casimiro 2006-12-26 06:47:34 0000 -------
(In reply to comment #12)
> I've tested your patch, in few words:
> - unnecessarily complex

What are your suggestions to make it simpler?

> - buggy

What bugs did you encounter?  I did notice that the include line was relative
to a path on my computer, but I have not experienced any other problems.

> - needs constant updates to keep in sync with new unionfs releases
> 

Conceptually, it only needs to be updated when unionfs changes the compilation
steps. It is possible to make the script use a default callback when the
version number is unrecognized. Also, the script does not really need callbacks
for each unionfs version; it was just easier to prototype that way.

I am going to upload a new version of the patch and a modified ebuild that
patches the official genkernel release. The ebuild worked well enough to build
a customized livecd with catalyst.

------- Comment #14 From Dan Casimiro 2006-12-26 06:53:17 0000 -------
Created an attachment (id=104749) [details]
compressed version of patch

This is a compressed version of the patch, with the relative include bug fixed.
The naming scheme is used by the ebuild that is also attached.

------- Comment #15 From Dan Casimiro 2006-12-26 06:54:45 0000 -------
Created an attachment (id=104750) [details]
A modified ebuild

This ebuild patches the official genkernel. It also downloads all of the
different unionfs tarballs.

------- Comment #16 From Fabio Erculiani 2006-12-26 08:01:39 0000 -------
Sorry, I like your efforts but I technically disagree with your solution:

- unnecessarily complex:
a) there aren't enough comments and the ones that are there are not fully
comprehensible
b) functions' names are not self-explanatory
c) the structure of your version detection system is too complex me thinks
d) I still prefer to just fix the actual genkernel's scripts and then think
about the rest

- buggy:
a) on the sabayon overlay I have uploaded a brand new version of unionfs that
should work with 2.6.19 (needs testing), using that package with genkernel on a
2.6.19-gentoo-r2 kernel simply does not work out of the box

- needs constant updates to keep in sync with new unionfs releases
a) we need to write code that continue to work with minimal human intervention.

Let's keep the discussion open :)

One thing is clear, we both want to see genkernel fixed.

------- Comment #17 From Luca 2007-01-04 09:37:17 0000 -------
Chris has fixed a xkb bug in genkernel 3.4.6:
http://bugs.gentoo.org/show_bug.cgi?id=146714

Do you know if 3.4.6 will support unionfs for kernel 2.6.18 ?

------- Comment #18 From Chris Gianelloni (RETIRED) 2007-01-04 10:17:46 0000 -------
No, it doesn't.

As I said, I have *zero* plans on updating the unionfs support until a good,
elegant solution is created for the fact that upstream unionfs sucks for
supporting multiple kernels.

Don't expect to see me working on a solution for this, at all.  I'd just assume
remove unionfs support entirely until a solution that doesn't suck is found.

------- Comment #19 From Fabio Erculiani 2007-01-04 11:46:38 0000 -------
Thanks god I already forked livecd-tools, so I won't mind forking that too
someday :-). I need unionfs or at least the new aufs, that's the matter :P

------- Comment #20 From Chris Gianelloni (RETIRED) 2007-01-04 14:04:17 0000 -------
Please keep your off-topic comments elsewhere.  This is a bug report, not a
forum.

------- Comment #21 From Chris Gianelloni (RETIRED) 2007-02-12 17:05:50 0000 -------
OK.  I've added Fabio's patch, after some slight modification.  It isn't what I
would call the most elegant solution, but it'll allow me to specify a
known-working unionfs with a known-working kernel version for release.

------- Comment #22 From Fabio Erculiani 2007-02-12 18:14:52 0000 -------
Chris, if you want, I worked out a patch that supports unionfs-utils only. In
this case, you'll have to use an in-kernel unionfs "driver". Atm, unionfs 2.0
included in akpm tree does not support addition/removal of branches but I've
ported unionfs 1.5 to it, you can see it on sabayon-sources into the sabayon
overlay, along with the updated genkernel.

------- Comment #23 From Chris Gianelloni (RETIRED) 2007-02-12 19:32:36 0000 -------
Funny enough, I was actually thinking of something similar.  We would build the
utilities within genkernel, but require the modules to be built externally,
such as via a callback (or built-in to the kernel).  I'm not completely sold on
the idea, though, as it means yet another thing that adds requirements to the
host system for compiling a kernel.  Anyway, that's something for another bug
in another time.

------- Comment #24 From Fabio Erculiani 2007-02-13 17:46:26 0000 -------
Created an attachment (id=110079) [details]
Unionfs support for genkernel 3.4.6 with PROPER branches management

Newer unionfs-utils does not support branches indexes (0,1,2) but we must
provide the complete name. This patch add unionfs-utils support to genkernel.
unionfs module must be included in the kernel.

------- Comment #25 From Fabio Erculiani 2007-02-13 17:47:28 0000 -------
Created an attachment (id=110081) [details]
genkernel-3.4.6-r4 ebuild with unionfs-utils support

------- Comment #26 From Chris Gianelloni (RETIRED) 2007-02-13 19:56:25 0000 -------
Umm... why are you adding more junk to this bug?

------- Comment #27 From Fabio Erculiani 2007-02-14 06:35:31 0000 -------
because I'm sure that you are interested in fixing the unionctl thing at least.
Please note that you WON'T be able to use "--after 0" ANYMORE!.

------- Comment #28 From Chris Gianelloni (RETIRED) 2007-02-14 15:08:05 0000 -------
Ehh... I'm not concerned with switching to the in-kernel unionfs code support
just yet.  For now, I'm sticking with building our own modules, since I'm
looking at what *Gentoo* supports first.  The 3.4.7 release of genkernel will
be using the http://bugs.gentoo.org/attachment.cgi?id=100706 patch.  Perhaps
after that, we can revisit unionfs support in general for another genkernel
release (likely 3.5.x)...

------- Comment #29 From Fabio Erculiani 2007-02-14 16:03:49 0000 -------
I know but read the patch.
Please apply this:
diff -Nurp genkernel-3.4.6.orig/generic/initrd.scripts
genkernel-3.4.6/generic/initrd.scripts
--- genkernel-3.4.6.orig/generic/initrd.scripts 2007-02-13 16:03:22.000000000
+0100
+++ genkernel-3.4.6/generic/initrd.scripts      2007-02-13 16:02:11.000000000
+0100
@@ -147,10 +147,12 @@ mount_sysfs() {
 # $2 = path to data directory
 #
 union_insert_dir() {
-   /sbin/unionctl $1 --add --after 0 --mode ro $2
+   # detect branch 0 because newer unionfs doesn't support "0,1,2"
+   BRANCH_0="/"$(/sbin/unionctl $1 --list | cut -d/ -f2- | cut -d'(' -f1)
+   /sbin/unionctl $1 --add --after $BRANCH_0 --mode ro $2
    if [ $? = '0' ]
    then
-       good_msg "Addition of $2 to $1 successful"
+       good_msg "Addition of $2 to $1 after branch $BRANCH_0 successful"
    fi
 }

it does not break anything and will always work. read the unionctl manual.

------- Comment #30 From Chris Gianelloni (RETIRED) 2007-02-14 21:57:17 0000 -------
Fixed in 3.4.7_pre3