From 9ac7db8cb1e8a95671e2b1543566378bc4e2fc9a Mon Sep 17 00:00:00 2001 From: Will Woods Date: Mon, 27 Jun 2011 14:46:47 -0400 Subject: [PATCH] Add TreeBuilder.generate_module_data() for depmod/module-info generate_module_data() runs depmod for each kernel module in the install root, then generates the (anaconda-specific) module-info files. --- share/runtime-cleanup.tmpl | 2 +- share/runtime-postinstall.tmpl | 7 ------- src/pylorax/__init__.py | 4 ++++ src/pylorax/treebuilder.py | 30 ++++++++++++++++++++++++++++++ 4 files changed, 35 insertions(+), 8 deletions(-) diff --git a/share/runtime-cleanup.tmpl b/share/runtime-cleanup.tmpl index ee6b92c6..d5d90c7b 100644 --- a/share/runtime-cleanup.tmpl +++ b/share/runtime-cleanup.tmpl @@ -76,7 +76,7 @@ arch/x86/kvm %for kmodpath in removekmods: remove /modules/*/kernel/${kmodpath} %endfor -## FIXME: run depmod, generate module-info +remove /modules/*/{build,source,*.map} ## Clean up systemd removefrom ConsoleKit /lib/systemd/* diff --git a/share/runtime-postinstall.tmpl b/share/runtime-postinstall.tmpl index 562d3649..bda3d422 100644 --- a/share/runtime-postinstall.tmpl +++ b/share/runtime-postinstall.tmpl @@ -96,10 +96,3 @@ symlink ../firmware lib/firmware ## create_depmod_conf() append etc/depmod.d/dd.conf "search updates built-in" - -## TODO: cleanup_kernel_modules(), then depmod -## TODO: depmod -a -F ${root}/boot/System.map-${kver} -b ${root} ${kver} -%for moddir in glob("modules/*"): - remove ${moddir}/*.map ${moddir}/build ${moddir}/source - ## FIXME: generate magical anaconda 'module-info' files -%endfor diff --git a/src/pylorax/__init__.py b/src/pylorax/__init__.py index ec2d9bcb..f1af4e6c 100644 --- a/src/pylorax/__init__.py +++ b/src/pylorax/__init__.py @@ -183,6 +183,7 @@ class Lorax(BaseLoraxClass): logger.debug("product data: %s" % product) templatedir = self.conf.get("lorax", "sharedir") + # NOTE: rb.root = ybo.conf.installroot (== self.inroot) rb = RuntimeBuilder(product=self.product, arch=self.arch, yum=ybo, templatedir=templatedir) @@ -228,6 +229,9 @@ class Lorax(BaseLoraxClass): inroot=installroot, outroot=self.outputdir, runtime=runtime, templatedir=templatedir) + logger.info("generating kernel module metadata") + treebuilder.generate_module_data() + logger.info("rebuilding initramfs images") treebuilder.rebuild_initrds(add_args=["--xz"]) diff --git a/src/pylorax/treebuilder.py b/src/pylorax/treebuilder.py index 09374c82..2e8b6b05 100644 --- a/src/pylorax/treebuilder.py +++ b/src/pylorax/treebuilder.py @@ -64,6 +64,28 @@ def findkernels(root="/", kdir="boot"): return kernels +def generate_module_info(moddir, outfile=None): + logger.info("reading module data in %s", moddir) + def module_desc(mod): + return check_output(["modinfo", "-F", "description", mod]).strip() + def read_module_set(name): + return set(l.strip() for l in open(join(moddir,name)) if ".ko" in l) + modsets = {'scsi':read_module_set("modules.block"), + 'eth':read_module_set("modules.networking")} + + modinfo = list() + for root, dirs, files in os.walk(moddir): + for modtype, modset in modsets.items(): + for mod in modset.intersection(files): # modules in this dir + (name, ext) = os.path.splitext(mod) # foo.ko -> (foo, .ko) + desc = module_desc(join(root,mod)) or "%s driver" % name + modinfo.append(dict(name=name, type=modtype, desc=desc)) + + out = open(outfile or join(moddir,"module-info"), "w") + logger.info("writing %s", out.name) + for mod in sorted(modinfo, key=lambda m: m.get('name')): + out.write('{name}\n\t{type}\n\t"{desc:.65}"\n'.format(**mod)) + def brace_expand(s): if not ('{' in s and ',' in s and '}' in s): yield s @@ -179,6 +201,14 @@ class TreeBuilder(object): self.treeinfo_data = runner.results.treeinfo self.implantisomd5() + def generate_module_data(self): + inroot = self.vars.inroot + for kernel in self.kernels: + kver = kernel.version + ksyms = joinpaths(inroot, "boot/System.map-%s" % kver) + check_call(["depmod", "-a", "-F", ksyms, "-b", inroot, kver]) + generate_module_info(joinpaths(inroot, "modules", kver)) + def rebuild_initrds(self, add_args=[], backup=""): '''Rebuild all the initrds in the tree. If backup is specified, each initrd will be renamed with backup as a suffix before rebuilding.