rpms/module-init-tools/devel module-init-tools-dump_modversions.patch, NONE, 1.1 module-init-tools-weak_updates.patch, NONE, 1.1 weak-modules, NONE, 1.1

fedora-cvs-commits at redhat.com fedora-cvs-commits at redhat.com
Wed Jun 14 12:06:04 UTC 2006


Author: harald

Update of /cvs/dist/rpms/module-init-tools/devel
In directory cvs.devel.redhat.com:/tmp/cvs-serv8686

Added Files:
	module-init-tools-dump_modversions.patch 
	module-init-tools-weak_updates.patch weak-modules 
Log Message:


module-init-tools-dump_modversions.patch:
 modprobe.c |   71 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 71 insertions(+)

--- NEW FILE module-init-tools-dump_modversions.patch ---
--- module-init-tools-3.3-pre1/modprobe.c.dump	2006-06-14 12:14:03.000000000 +0200
+++ module-init-tools-3.3-pre1/modprobe.c	2006-06-14 12:15:46.000000000 +0200
@@ -976,6 +976,67 @@
 	goto remove_rest;
 }
 
+struct modver32_info
+{
+       uint32_t crc;
+       char name[64 - sizeof(uint32_t)];
+};
+
+struct modver64_info
+{
+       uint64_t crc;
+       char name[64 - sizeof(uint64_t)];
+};
+
+const char *skip_dot(const char *str)
+{
+       /* For our purposes, .foo matches foo.  PPC64 needs this. */
+       if (str && str[0] == '.')
+               return str + 1;
+       return str;
+}
+
+void dump_modversions(const char *filename, errfn_t error)
+{
+       unsigned long size, secsize;
+       void *file = grab_file(filename, &size);
+       struct modver32_info *info32;
+       struct modver64_info *info64;
+       int n;
+
+       if (!file) {
+               error("%s: %s\n", filename, strerror(errno));
+               return;
+       }
+       switch (elf_ident(file, size)) {
+       case ELFCLASS32:
+               info32 = get_section32(file, size, "__versions", &secsize);
+               if (!info32)
+                       return;  /* Does not seem to be a kernel module */
+               if (secsize % sizeof(struct modver32_info))
+                       error("Wrong section size in %s\n", filename);
+               for (n = 0; n < secsize / sizeof(struct modver32_info); n++)
+                       printf("0x%08lx\t%s\n", (unsigned long)
+                              info32[n].crc, skip_dot(info32[n].name));
+               break;
+
+       case ELFCLASS64:
+               info64 = get_section64(file, size, "__versions", &secsize);
+               if (!info64)
+                       return;  /* Does not seem to be a kernel module */
+               if (secsize % sizeof(struct modver64_info))
+                       error("Wrong section size in %s\n", filename);
+               for (n = 0; n < secsize / sizeof(struct modver64_info); n++)
+                       printf("0x%08llx\t%s\n", (unsigned long long)
+                              info64[n].crc, skip_dot(info64[n].name));
+               break;
+
+       default:
+               error("%s: ELF class not recognized\n", filename);
+       }
+}
+
+
 /* Does path contain directory(s) subpath? */
 static int type_matches(const char *path, const char *subpath)
 {
@@ -1384,6 +1445,7 @@
 				   { "set-version", 1, NULL, 'S' },
 				   { "show-depends", 0, NULL, 'D' },
 				   { "first-time", 0, NULL, 3 },
+				   { "dump-modversions", 0, NULL, 4 },
 				   { "use-blacklist", 0, NULL, 'b' },
 				   { NULL, 0, NULL, 0 } };
 
@@ -1421,6 +1483,7 @@
 	int strip_modversion = 0;
 	int ignore_proc = 0;
 	int first_time = 0;
+	int dump_modver = 0;
 	int use_blacklist = 0;
 	unsigned int i, num_modules;
 	char *type = NULL;
@@ -1537,6 +1600,9 @@
 		case 3:
 			first_time = 1;
 			break;
+		case 4:
+			dump_modver = 1;
+			break;
 		default:
 			print_usage(argv[0]);
 		}
@@ -1602,6 +1668,11 @@
 		LIST_HEAD(list);
 		char *modulearg = argv[optind + i];
 
+		if (dump_modver) {
+			dump_modversions(modulearg, error);
+			continue;
+		}
+
 		/* Convert name we are looking for */
 		underscores(modulearg);
 

module-init-tools-weak_updates.patch:
 depmod.c |   23 +++++++++++++++++++++--
 1 files changed, 21 insertions(+), 2 deletions(-)

--- NEW FILE module-init-tools-weak_updates.patch ---
--- module-init-tools-3.3-pre1/depmod.c.weak	2006-06-14 12:16:08.000000000 +0200
+++ module-init-tools-3.3-pre1/depmod.c	2006-06-14 12:16:08.000000000 +0200
@@ -474,10 +474,26 @@
 				      const char *filename,
 				      struct module *next);
 
+static int is_weak_update(const char *dirname)
+{
+	char *p;
+
+	p = strstr(dirname, "weak-updates");
+	if (!p)
+		return 0;
+	return (p[strlen("weak-updates")] == '/' ||
+		p[strlen("weak-updates")] == '\0');
+}
+
 static int is_update(const char *dirname)
 {
 	char *p;
 
+	/* If it's a weak_update then we don't want to match on updates/"
+         */
+	if (is_weak_update(dirname))
+		return 0;
+
 	p = strstr(dirname, "updates");
 	if (!p)
 		return 0;
@@ -545,8 +561,11 @@
 			char subdir[strlen(dirname) + 1
 				   + strlen(dirent->d_name) + 1];
 			sprintf(subdir, "%s/%s", dirname, dirent->d_name);
-			/* Don't follow links, eg. build/ */
-			if (readlink(subdir, &dummy, 1) < 0) {
+			/* Don't follow links, eg. build/ (except under
+			 * extra/ to allow for weak-updates symlinks)
+                         */
+			if ((readlink(subdir, &dummy, 1) < 0) ||
+			    is_weak_update(subdir)) {
 				sub = opendir(subdir);
 				if (sub) {
 					next = grab_dir(subdir, sub, next,


--- NEW FILE weak-modules ---
#! /bin/bash

# weak-modules - derived from weak-updates by Andreas Gruenbacher

unset LANG LC_ALL LC_COLLATE

# Check if MODULE is compatible with kernel release KREL.
module_is_compatible() {
    declare module=$1 krel=$2 module_krel=$(krel_of_module "$module")

    if [ ! -e "$tmpdir/all-symvers-$krel-$module_krel" ]; then
        # Symbols exported by the "new" kernel
        if [ ! -e $tmpdir/symvers-$krel ]; then
            if [ -e /boot/symvers-$krel.gz ]; then
                zcat /boot/symvers-$krel.gz \
                | sed -r -ne 's:^0x0*([0-9a-f]+\t[0-9a-zA-Z_]+)\t.*:\1:p'
            fi > $tmpdir/symvers-$krel
        fi

        # Symbols that other add-on modules of the "old" kernel export
        # (and that this module may require)
        if [ ! -e "$tmpdir/extra-symvers-$module_krel" ]; then
            if [ -e /lib/modules/$module_krel/extra ]; then
                find /lib/modules/$module_krel/extra -name '*.ko' \
                | xargs nm \
                | sed -nre 's:^0*([0-9a-f]+) A __crc_(.*):\1 \2:p'
            fi > $tmpdir/extra-symvers-$module_krel
        fi

        sort -u $tmpdir/symvers-$krel $tmpdir/extra-symvers-$module_krel \
        > "$tmpdir/all-symvers-$krel-$module_krel"
    fi

    # If the module does not have modversions enabled, $tmpdir/modvers
    # will be empty.
    /sbin/modprobe --dump-modversions "$module" \
    | sed -r -e 's:^0x0*([0-9a-f]+\t.*):\1:' \
    | sort -u \
    > $tmpdir/modvers

    # Only include lines of the second file in the output that don't
    # match lines in the first file. (The default separator is
    # <space>, so we are matching the whole line.)
    join -j 1 -v 2 $tmpdir/all-symvers-$krel-$module_krel \
                   $tmpdir/modvers > $tmpdir/join

    if [ ! -s $tmpdir/modvers ]; then
        echo "Warning: Module ${module##*/} from kernel $module_krel has no" \
             "modversions, so it cannot be reused for kernel $krel" >&2
    elif [ -s $tmpdir/join ]; then
        [ -n "$verbose" ] &&
        echo "Module ${module##*/} from kernel $module_krel is not compatible" \
             "with kernel $krel in symbols:" $(sed -e 's:.* ::' $tmpdir/join)
    else
        [ -n "$verbose" ] &&
        echo "Module ${module##*/} from kernel $module_krel is compatible" \
             "with kernel $krel"
        return 0
    fi
    return 1
}

# Compute the kernel release of a module.
krel_of_module() {
    declare module=$1
    /sbin/modinfo -F vermagic "$module" | awk '{print $1}'
}

# Read a list of modules from standard input, convert the filenames into
# absolute names, and compute the kernel release of each module.
read_modules_list() {
    local IFS=$'\n'
    modules=($(cat))

    for ((n = 0; n < ${#modules[@]}; n++)); do
        if [ ${modules[n]:0:1} != '/' ]; then
            modules[n]="$PWD/${modules[n]}"
        fi
        if [ -f "${modules[n]}" ]; then
            module_krels[n]=$(krel_of_module ${modules[n]})
        else
            # Try to extract the kernel release from the path
            set -- "${modules[n]#/lib/modules/}"
            module_krels[n]=${1%%/*}
        fi
    done
}

doit() {
    [ -n "$verbose" ] && echo "$@"
    [ -n "$dry_run" ] || "$@"
}

usage() {
    echo "Usage: ${0##*/} [options] {--add-modules|--remove-modules}"
    echo "${0##*/} [options] {--add-kernel|--remove-kernel} {kernel-release}"
    cat <<'EOF'
--add-modules
        Add a list of modules read from standard input. Create
        symlinks in compatible kernel's weak-updates/ directory.
        The list of modules is read from standard input.

--remove-modules
        Remove compatibility symlinks from weak-updates/ directories
        for a list of modules.  The list of modules is read from
        standard input.

--add-kernel
        Add compatibility symlinks for all compatible modules to the
        specified or running kernel.

--remove-kernel
        Remove all compatibility symlinks for the specified or current
        kernel.

--verbose
        Print the commands executed.

-dry-run
        Do not create/remove any files.
EOF
    exit $1
}

[ -e /etc/sysconfig/kernel ] && source /etc/sysconfig/kernel

unset ${!changed_modules_*} ${!changed_initrd_*}

module_has_changed() {
    declare module=$1 krel=$2

    module=${module%.ko}
    module=${module##*/}

    eval "changed_modules_${krel//[^a-zA-Z0-9]/_}=$krel"
    case " $INITRD_MODULES " in
    *" $module "*)
        eval "changed_initrd_${krel//[^a-zA-Z0-9]/_}=$krel"
        ;;
    esac
}

options=`getopt -o h --long help,add-modules,remove-modules \
                     --long add-kernel,remove-kernel,dry-run,verbose -- "$@"`

[ $? -eq 0 ] || usage 1

eval set -- "$options"

while :; do
    case "$1" in
    --add-modules)
        add_modules=1
        ;;
    --remove-modules)
        remove_modules=1
        ;;
    --add-kernel)
        add_kernel=1
        ;;
    --remove-kernel)
        remove_kernel=1
        ;;
    --dry-run)
        dry_run=1
        ;;
    --verbose)
        verbose=1
        ;;
    -h|--help)
        usage 0
        ;;
    --)
        shift
        break
        ;;
    esac
    shift
done

if [ "$add_modules$remove_modules$add_kernel$remove_kernel" != 1 ]; then
    usage 1
fi
if [ -n "$add_kernel" -o -n "$remove_kernel" ]; then
    [ $# -gt 1 ] && usage 1
else
    [ $# -ne 0 ] && usage 1
fi

tmpdir=$(mktemp -td ${0##*/}.XXXXXX)
trap "rm -rf $tmpdir" EXIT
trap "rm -rf $tmpdir" INT

if [ -n "$add_modules" ]; then
    read_modules_list || exit 1
    if [ ${#modules[@]} -gt 0 ]; then
        for krel in $(ls /lib/modules/); do
            [ -e "/boot/symvers-$krel.gz" ] || continue
            for ((n = 0; n < ${#modules[@]}; n++)); do
                module="${modules[n]}"
                module_krel="${module_krels[n]}"
                case "$module" in
                /lib/modules/$krel/*)
                    continue ;;
                esac
                subpath="${module#/lib/modules/$module_krel/extra}"
                weak_module="/lib/modules/$krel/weak-updates/${subpath#/}"
                if [ -r "$weak_module" ]; then
                    weak_krel=$(krel_of_module "$weak_module")
                    if [ "$weak_krel" != "$module_krel" ] &&
                       [ "$(printf "%s\n" "$weak_krel" "$module_krel" \
                            | /usr/lib/rpm/redhat/rpmsort | head -n 1)" = \
                         "$module_krel" ]; then
                        # Keep modules from more recent kernels.
                        [ -n "$verbose" ] && echo \
"Keeping module ${module##*/} from kernel $weak_krel for kernel $krel"
                        continue
                    fi
                fi
                if module_is_compatible $module $krel; then
                    doit mkdir -p $(dirname $weak_module)
                    doit ln -sf $module $weak_module
                    module_has_changed $module $krel
                fi
            done
        done
    fi
elif [ -n "$remove_modules" ]; then
    read_modules_list || exit 1
    if [ ${#modules[@]} -gt 0 ]; then
        krels=($(ls /lib/modules/ | /usr/lib/rpm/redhat/rpmsort -r))
        for krel in "${krels[@]}"; do
            [ -e "/boot/symvers-$krel.gz" ] || continue
            for ((n = 0; n < ${#modules[@]}; n++)); do
                module="${modules[n]}"
                module_krel="${module_krels[n]}"
                subpath="${module#/lib/modules/$module_krel/extra}"
                weak_module="/lib/modules/$krel/weak-updates/${subpath#/}"
		if [ "$module" == "`readlink $weak_module`" ]; then
                    [ -n "$verbose" ] && echo \
"Removing compatible module ${module##*/} from kernel $krel"
                    doit rm -f "$weak_module"
                    for krel2 in "${krels[@]}"; do
                        [ -e "/boot/symvers-$krel2.gz" ] || continue
                        module="/lib/modules/$krel2/extra/$subpath"
                        [ -e "$module" ] || continue
                        if module_is_compatible "$module" "$krel2"; then
                            [ -n "$verbose" ] && echo \
"Adding compatible module ${module##*/} from kernel $krel2 instead"
                            doit ln -s "$module" "$weak_module"
                            break
                        fi
                    done
                    doit rmdir --parents --ignore-fail-on-non-empty \
                               "$(dirname "$weak_module")"
                    module_has_changed $module $krel
                fi
            done
        done
    fi
elif [ -n "$add_kernel" ]; then
    add_krel=${1:-$(uname -r)}
    if [ ! -e "/boot/symvers-$add_krel.gz" ]; then
        echo "Symvers dump file /boot/symvers-$add_krel.gz" \
             "not found" >&2
        exit 1
    fi
    for krel in $(ls /lib/modules/ | /usr/lib/rpm/redhat/rpmsort -r); do
        [ "$add_krel" = "$krel" ] && continue
        [ -d /lib/modules/$krel/extra ] || continue
        for module in $(find /lib/modules/$krel/extra -name '*.ko'); do
            subpath="${module#/lib/modules/$krel/extra}"
            weak_module="/lib/modules/$add_krel/weak-updates/${subpath#/}"
            [ -e "$weak_module" ] && continue
            if module_is_compatible $module $add_krel; then
                doit mkdir -p $(dirname $weak_module)
                doit ln -sf $module $weak_module
            fi
        done
    done
elif [ -n "$remove_kernel" ]; then
    remove_krel=${1:-$(uname -r)}
    weak_modules="/lib/modules/$remove_krel/weak-updates"
    doit rm -rf "$weak_modules"
fi

for krel in ${!changed_modules_*}; do
    krel=${!krel}
    [ -e "/boot/System.map-$krel" ] || continue
    /sbin/depmod -ae -F /boot/System.map-$krel $krel
done

for krel in ${!changed_initrd_*}; do
    krel=${!krel}
    [ -e "/boot/System.map-$krel" ] || continue

    image=
    for x in vmlinuz image vmlinux linux bzImage; do
        if [ -f "/boot/$x-$krel" ]; then
            image="$x"
            break
        fi
    done
    if [ -n "$image" ]; then
        /sbin/mkinitrd -k "/boot/$image-$krel" -i "/boot/initrd-$krel"
    fi
done




More information about the fedora-cvs-commits mailing list