summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeremy Katz <katzj@redhat.com>2003-11-14 21:29:10 +0000
committerJeremy Katz <katzj@redhat.com>2003-11-14 21:29:10 +0000
commit9a778ced3d3a06f22879dd4b71d264e09a370b0b (patch)
tree2f7112ea4e31d08d9394274136ac737a3cbc224d
parent7b7ad890423bf12fe2c5c4d3b706ca79e162a7a2 (diff)
downloadanaconda-9a778ced3d3a06f22879dd4b71d264e09a370b0b.tar.gz
anaconda-9a778ced3d3a06f22879dd4b71d264e09a370b0b.tar.xz
anaconda-9a778ced3d3a06f22879dd4b71d264e09a370b0b.zip
let's start on 2.6...
try to write some module loading code modules are .ko, not .o
-rw-r--r--loader2/Makefile4
-rw-r--r--loader2/loader.c2
-rw-r--r--loader2/modstubs.c113
-rw-r--r--loader2/modstubs.h4
-rwxr-xr-xscripts/mk-images29
5 files changed, 87 insertions, 65 deletions
diff --git a/loader2/Makefile b/loader2/Makefile
index 399536338..ccc7946b1 100644
--- a/loader2/Makefile
+++ b/loader2/Makefile
@@ -12,7 +12,6 @@ BTERMLIB = -lbterm -lbogl
WLITELIB = -lwlite
ISYSLIB = ../isys/libisys.a
GUNZIP = -lz
-MODULELINKAGE :=-lmodutils -lmodutilutil -lmodutilobj
BINS = loader
@@ -119,8 +118,7 @@ loader-net.o: loader.c
loader: loader.o $(OBJS) $(NETOBJS)
$(CC) -g $(STATIC) -o $@ $^ -lpopt \
- $(HWLIBS) $(ISYSLIB) \
- $(MODULELINKAGE) $(GUNZIP) \
+ $(HWLIBS) $(ISYSLIB) $(GUNZIP) \
-lpump -lresolv $(NEWTLIB) $(SLANGLIB) $(BTERMLIB) $(WLITELIB)
clean:
diff --git a/loader2/loader.c b/loader2/loader.c
index a066e0a27..dd9355645 100644
--- a/loader2/loader.c
+++ b/loader2/loader.c
@@ -1082,7 +1082,7 @@ int main(int argc, char ** argv) {
if (!strcmp(argv[0] + strlen(argv[0]) - 8, "modprobe"))
return ourInsmodCommand(argc, argv);
if (!strcmp(argv[0] + strlen(argv[0]) - 5, "rmmod"))
- return combined_insmod_main(argc, argv);
+ return ourRmmodCommand(argc, argv);
if (!testing && !access("/var/run/loader.run", R_OK)) {
printf(_("loader has already been run. Starting shell."));
diff --git a/loader2/modstubs.c b/loader2/modstubs.c
index e783ced94..8114897b2 100644
--- a/loader2/modstubs.c
+++ b/loader2/modstubs.c
@@ -20,30 +20,72 @@
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
+#include <errno.h>
#include <stdlib.h>
#include <sys/utsname.h>
#include <sys/wait.h>
+#include "log.h"
#include "modstubs.h"
#include "modules.h"
#include "../isys/cpio.h"
#include "../isys/stubs.h"
+extern long init_module(void *, unsigned long, const char *);
+extern long delete_module(const char *, unsigned int);
+
static int usage() {
fprintf(stderr, "usage: insmod [-p <path>] <module>.o\n");
return 1;
}
+static int rmmod_usage() {
+ fprintf(stderr, "usage: rmmod <module>\n");
+ return 1;
+}
+
+static char * extractModule(char * file, char * ballPath, int version,
+ int *rmObj) {
+ gzFile fd;
+ char finalName[100], fullName[100];
+ char * chptr = NULL;
+
+ if (access(file, R_OK)) {
+ /* it might be having a ball */
+ fd = gunzip_open(ballPath);
+ if (!fd) {
+ free(ballPath);
+ return NULL;
+ }
+
+ chptr = strrchr(file, '/');
+ if (chptr) file = chptr + 1;
+ sprintf(finalName, "/tmp/%s", file);
+
+ /* XXX: leak */
+ sprintf(fullName, "%s/%s", getModuleLocation(version), file);
+
+ if (installCpioFile(fd, fullName, finalName, 0)) {
+ free(ballPath);
+ return NULL;
+ }
+
+ *rmObj = 1;
+ file = finalName;
+ }
+
+ return file;
+}
+
int ourInsmodCommand(int argc, char ** argv) {
char * file;
- char finalName[100];
- char * chptr;
- gzFile fd;
int rc, rmObj = 0;
char * ballPath = NULL;
- char fullName[100];
int version = 1;
+ int fd;
+ char * modbuf = NULL;
+ struct stat sb;
if (argc < 2) {
return usage();
@@ -68,53 +110,47 @@ int ourInsmodCommand(int argc, char ** argv) {
ballPath = strdup("/modules/modules.cgz");
}
- file = argv[1];
+ file = extractModule(argv[1], ballPath, version, &rmObj);
+ free(ballPath);
- if (access(file, R_OK)) {
- /* it might be having a ball */
- fd = gunzip_open(ballPath);
- if (!fd) {
- free(ballPath);
- return 1;
- }
-
- chptr = strrchr(file, '/');
- if (chptr) file = chptr + 1;
- sprintf(finalName, "/tmp/%s", file);
-
- /* XXX: leak */
- sprintf(fullName, "%s/%s", getModuleLocation(version), file);
-
- if (installCpioFile(fd, fullName, finalName, 0)) {
- free(ballPath);
- return 1;
- }
-
- rmObj = 1;
- file = finalName;
+ if (stat(file, &sb) == -1) {
+ logMessage("unable to stat file %s: %s", file, strerror(errno));
+ return 1;
}
- free(ballPath);
-
- argv[0] = "insmod";
- argv[1] = file;
+ fd = open(file, O_RDONLY);
+ if (fd < 0) {
+ logMessage("unable to open file %s: %s", file, strerror(errno));
+ return 1;
+ }
- rc = combined_insmod_main(argc, argv);
-
- if (rmObj) unlink(file);
+ modbuf = malloc(sb.st_size);
+ if (read(fd, modbuf, sb.st_size) < sb.st_size) {
+ logMessage("error reading file %s: %s", file, strerror(errno));
+ return 1;
+ }
+ rc = init_module(file, sb.st_size, "");
+ if (rc != 0)
+ logMessage("failed to insert module (%d)", errno);
return rc;
}
+int ourRmmodCommand(int argc, char ** argv) {
+ if (argc < 2) {
+ return rmmod_usage();
+ }
+
+ return rmmod(argv[2]);
+}
+
int rmmod(char * modName) {
pid_t child;
int status;
- char * argv[] = { "/bin/rmmod", modName, NULL };
- int argc = 2;
int rc = 0;
if ((child = fork()) == 0) {
- exit(combined_insmod_main(argc, argv));
+ exit(delete_module(modName, O_NONBLOCK|O_EXCL));
}
waitpid(child, &status, 0);
@@ -158,8 +194,7 @@ int insmod(char * modName, char * path, char ** args) {
argc += count;
if ((child = fork()) == 0) {
- execv("/bin/loader", argv);
- exit(1);
+ exit(ourInsmodCommand(argc, argv));
}
waitpid(child, &status, 0);
diff --git a/loader2/modstubs.h b/loader2/modstubs.h
index 0ea68bd12..cd80b600d 100644
--- a/loader2/modstubs.h
+++ b/loader2/modstubs.h
@@ -2,10 +2,8 @@
#define H_MODSTUBS
int ourInsmodCommand(int argc, char ** argv);
+int ourRmmodCommand(int argc, char ** argv);
int rmmod(char * modName);
int insmod(char * modName, char * path, char ** args);
-/* hack */
-int combined_insmod_main(int argc, char ** argv);
-
#endif
diff --git a/scripts/mk-images b/scripts/mk-images
index 9bef8a32c..993ce7859 100755
--- a/scripts/mk-images
+++ b/scripts/mk-images
@@ -165,7 +165,7 @@ findmodule () {
find $KERNELROOT/lib/modules/ > $CACHE
fi
- grep "/$1\.o" $CACHE
+ grep "/$1\.ko" $CACHE
}
rundepmod () {
@@ -202,7 +202,7 @@ rundepmod () {
# So we use an ugly hack. :-(
PARIDE="aten bpck bpck6 comm dstr epat epia fit2 fit3 friq frpw kbic ktti on20 on26"
- cat $final.foo | $FILTERMODDEPS | sed -e 's/\.o//g' \
+ cat $final.foo | $FILTERMODDEPS | sed -e 's/\.ko//g' \
-e 's/: parport$/: parport_pc/g' \
-e 's/^\(parport_pc: parport\)_pc$/\1/' \
-e "s/^pcd:.*/pcd: $PARIDE/" > $final
@@ -214,7 +214,7 @@ getmoddeps () {
final=$2
for mod in $what ; do
- mod=$(echo $mod | sed 's/\.o */|^/g;s/\.o$//;s/.*\///')
+ mod=$(echo $mod | sed 's/\.ko */|^/g;s/\.ko$//;s/.*\///')
egrep $mod $MODDEPS >> $final.foo
done
mv $final.foo $final
@@ -330,21 +330,16 @@ makemoduleball() {
pushd $MMB_DIR/modules > /dev/null
- GZIPPED=$(find . -name '*.o.gz')
- if [ -n "$GZIPPED" ]; then
- echo $GZIPPED | xargs gunzip
- fi
-
$MODLIST --modinfo-file $MODINFO --ignore-missing --modinfo \
$MMB_MODULESET > ../$MMB_MODINFO
- getmoddeps "$(find . -name *.o)" ../modules.dep
+ getmoddeps "$(find . -name *.ko)" ../modules.dep
# create the pcitable
- $TRIMPCITABLE $(find . -name *.o -exec basename {} \;) < $PCITABLE > ../pcitable
+ $TRIMPCITABLE $(find . -name *.ko -exec basename {} \;) < $PCITABLE > ../pcitable
# create the modules.pcimap
- $TRIMMODMAP $PCITABLE $(find . -name *.o -exec basename {} \;) < $MODMAPS > ../modules.pcimap
+ $TRIMMODMAP $PCITABLE $(find . -name *.ko -exec basename {} \;) < $MODMAPS > ../modules.pcimap
if [ -n "$MMB_DD" ]; then
echo $MMB_DD > $MMB_DIR/rhdd
@@ -369,7 +364,7 @@ makemainmodules() {
if [ "$BUILDARCH" = "s390" -o "$BUILDARCH" = "s390x" ]; then
mkdir -p $KERNELROOT/lib/modules/misc
- find $KERNELROOT/lib/modules/*/kernel/drivers/s390/ -name "*.o" \
+ find $KERNELROOT/lib/modules/*/kernel/drivers/s390/ -name "*.ko" \
-exec cp -f {} $KERNELROOT/lib/modules/misc \;
fi
makemoduleball $extraargs $FULLMODPATH "$modlist"
@@ -739,7 +734,7 @@ makeinstimage () {
(cd $INSTIMGTEMPLATE; find . | cpio --quiet -p $tmpdir)
if [ "$BUILDARCH" = "s390" -o "$BUILDARCH" = "s390x" ]; then
mkdir -p $KERNELROOT/lib/modules/misc
- find $KERNELROOT/lib/modules/*/kernel/drivers/s390/ -name "*.o" \
+ find $KERNELROOT/lib/modules/*/kernel/drivers/s390/ -name "*.ko" \
-exec cp -f {} $KERNELROOT/lib/modules/misc \;
fi
makemoduleball $tmpdir/modules "$modlist"
@@ -937,14 +932,10 @@ for KERNELARCH in $arches; do
if [ -f $KERNELROOT/etc/pcmcia/config ]; then
# This gets everything mentioned in /etc/pcmcia/config. We probably
# want to do some module-info stuff here too
- PCMCIAMODULES=$((perl -e 'while (<>) { s/^.*class.*(network|scsi|ide).*module +"// || next; s/[" ]//g; s/,/\n/g; print }' $KERNELROOT/etc/pcmcia/config | sed 's/\.o//g') | sort -u)
+ PCMCIAMODULES=$((perl -e 'while (<>) { s/^.*class.*(network|scsi|ide).*module +"// || next; s/[" ]//g; s/,/\n/g; print }' $KERNELROOT/etc/pcmcia/config | sed 's/\.ko//g') | sort -u)
fi
- GZIPPED=$(find $KERNELROOT/lib/modules/$version -name "*.o.gz")
- if [ -n "$GZIPPED" ]; then
- echo $GZIPPED |xargs gunzip
- fi
- allmods=$(find $KERNELROOT/lib/modules/$version -name *.o)
+ allmods=$(find $KERNELROOT/lib/modules/$version -name *.ko)
rundepmod "$allmods" $MODDEPS
rm -f $MODDEPS.foo