Merge pull request #106 from jpoimboe/kpatch-install-initrd

kpatch: install patch modules to initrd
This commit is contained in:
Seth Jennings 2014-04-07 11:02:30 -05:00
commit f3a4275ed8
5 changed files with 104 additions and 1 deletions

View File

@ -1,6 +1,6 @@
include Makefile.inc include Makefile.inc
SUBDIRS = kpatch-build kpatch kmod man SUBDIRS = kpatch-build kpatch kmod man contrib
BUILD_DIRS = $(SUBDIRS:%=build-%) BUILD_DIRS = $(SUBDIRS:%=build-%)
INSTALL_DIRS = $(SUBDIRS:%=install-%) INSTALL_DIRS = $(SUBDIRS:%=install-%)
UNINSTALL_DIRS = $(SUBDIRS:%=uninstall-%) UNINSTALL_DIRS = $(SUBDIRS:%=uninstall-%)

14
contrib/Makefile Normal file
View File

@ -0,0 +1,14 @@
include ../Makefile.inc
DRACUTDIR=/usr/lib/dracut/modules.d/99kpatch
all:
install: all
$(INSTALL) -d $(DRACUTDIR)
$(INSTALL) module-setup.sh kpatch-apply-all.sh $(DRACUTDIR)
uninstall:
$(RM) $(DRACUTDIR)
clean:

10
contrib/kpatch-apply-all.sh Executable file
View File

@ -0,0 +1,10 @@
#!/bin/bash
# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
# ex: ts=8 sw=4 sts=4 et filetype=sh
#
# Licensed under the GPLv2
#
# Copyright 2014 Red Hat, Inc.
# Josh Poimboeuf <jpoimboe@redhat.com>
kpatch apply --all

48
contrib/module-setup.sh Executable file
View File

@ -0,0 +1,48 @@
#!/bin/bash
# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
# ex: ts=8 sw=4 sts=4 et filetype=sh
#
# Licensed under the GPLv2
#
# Copyright 2014 Red Hat, Inc.
# Josh Poimboeuf <jpoimboe@redhat.com>
# called by dracut
check() {
if [[ -e /var/lib/kpatch/$kernel ]] || [[ -e /usr/lib/kpatch/$kernel ]]; then
return 0
else
return 1
fi
}
# called by dracut
install() {
# install kpatch script
inst_any -d /usr/sbin/kpatch /usr/local/sbin/kpatch /usr/sbin/kpatch
# install insmod (needed by kpatch script)
inst_symlink /usr/sbin/insmod
# install core module
inst_any -d /usr/lib/modules/$kernel/kpatch/kpatch.ko /usr/local/lib/modules/$kernel/kpatch/kpatch.ko /usr/lib/modules/$kernel/kpatch/kpatch.ko
# install patch modules
if [[ -e /var/lib/kpatch/$kernel ]]; then
inst_dir /var/lib/kpatch/$kernel
for i in /var/lib/kpatch/$kernel/*; do
[[ -e $i ]] || continue
inst "$i"
done
fi
if [[ -e /usr/lib/kpatch/$kernel ]]; then
inst_dir /usr/lib/kpatch/$kernel
for i in /usr/lib/kpatch/$kernel/*; do
[[ -e $i ]] || continue
inst "$i"
done
fi
# install hook script
inst_hook pre-udev 00 "$moddir/kpatch-apply-all.sh"
}

View File

@ -69,11 +69,32 @@ find_module () {
__find_module "${arg}" __find_module "${arg}"
} }
find_core_module() {
COREMOD="/usr/local/lib/modules/$(uname -r)/kpatch/kpatch.ko"
[[ -f "$COREMOD" ]] && return
COREMOD="/usr/lib/modules/$(uname -r)/kpatch/kpatch.ko"
[[ -f "$COREMOD" ]] && return
return 1
}
core_module_loaded () {
grep -q "T kpatch_register" /proc/kallsyms
}
load_module () { load_module () {
if ! core_module_loaded; then
find_core_module || die "can't find core module"
echo "loading core module: $COREMOD"
/usr/sbin/insmod "$COREMOD" || die "failed to load core module"
fi
echo "loading patch module: $1"
/usr/sbin/insmod "$1" /usr/sbin/insmod "$1"
} }
unload_module () { unload_module () {
echo "unloading patch module: $1"
/usr/sbin/rmmod "$(basename $1)" /usr/sbin/rmmod "$(basename $1)"
} }
@ -118,15 +139,25 @@ case "$1" in
PATCH="$2" PATCH="$2"
[[ -e "$PATCH" ]] || die "$PATCH doesn't exist" [[ -e "$PATCH" ]] || die "$PATCH doesn't exist"
[[ ${PATCH: -3} == ".ko" ]] || die "$PATCH isn't a .ko file" [[ ${PATCH: -3} == ".ko" ]] || die "$PATCH isn't a .ko file"
echo "installing $PATCH to $USERDIR"
mkdir -p "$USERDIR" || die "failed to create install directory" mkdir -p "$USERDIR" || die "failed to create install directory"
cp -f "$PATCH" "$USERDIR" || die "failed to install patch $PATCH" cp -f "$PATCH" "$USERDIR" || die "failed to install patch $PATCH"
echo "installing $PATCH to initramfs"
dracut -f || die "dracut failed"
;; ;;
"uninstall") "uninstall")
[[ "$#" -ne 2 ]] && usage [[ "$#" -ne 2 ]] && usage
PATCH="$2" PATCH="$2"
find_module "$PATCH" || die "$PATCH is not installed" find_module "$PATCH" || die "$PATCH is not installed"
echo "uninstalling $PATCH from $USERDIR"
rm -f "$USERDIR/$(basename $MODULE)" || die "failed to uninstall patch $PATCH" rm -f "$USERDIR/$(basename $MODULE)" || die "failed to uninstall patch $PATCH"
echo "uninstalling $PATCH from initramfs"
dracut -f || die "dracut failed"
;; ;;
"list") "list")