File s390-tools-sles11-zfcpdump-initrd of Package s390-tools

Description: zfcpdump: Allow zfcpdump to work in more initrds.
Symptom:     Kernel modules are not loaded and e2fsck is not found.
             The dump process fails.
Problem:     For some initrds, the required kernel modules are not built-in
             and e2fsck is located under /bin instead of /sbin.
Solution:    Load kernel modules and look for /bin/e2fsck.
---
 zfcpdump_v2/zfcpdump.c |   42 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)

Index: s390-tools-sles11/zfcpdump_v2/zfcpdump.c
===================================================================
--- s390-tools-sles11.orig/zfcpdump_v2/zfcpdump.c
+++ s390-tools-sles11/zfcpdump_v2/zfcpdump.c
@@ -33,6 +33,8 @@
 #endif
 
 static struct globals g;
+static char *module_list[] = {"zfcp", "sd_mod", "ext2", "ext3", "zcore_mod",
+			      NULL};
 
 /*
  * parse one kernel parameter in the form keyword=value
@@ -301,6 +303,7 @@ static int mount_dump_device(void)
 		PRINT_PERR("fork failed\n");
 		return -1;
 	} else if (pid == 0) {
+		execl("/bin/e2fsck", "e2fsck", dump_part, "-y", NULL);
 		execl("/sbin/e2fsck", "e2fsck", dump_part, "-y", NULL);
 		exit(1);
 	} else {
@@ -913,6 +916,41 @@ failed_close_fmap:
 }
 
 /*
+ * Load a kernel module
+ */
+static int modprobe(const char *module)
+{
+	pid_t pid;
+
+	pid = fork();
+	if (pid < 0) {
+		PRINT_PERR("fork failed\n");
+		return -1;
+	} else if (pid == 0) {
+		execl("/bin/modprobe", "modprobe", module, "-q", NULL);
+		execl("/sbin/modprobe", "modprobe", module, "-q", NULL);
+		exit(1);
+	} else {
+		waitpid(pid, NULL, 0);
+	}
+	return 0;
+}
+
+/*
+ * Load all required kernel modules
+ */
+static int load_modules(void)
+{
+	int i;
+
+	for (i = 0; module_list[i]; i++) {
+		if (modprobe(module_list[i]))
+			return -1;
+	}
+	return 0;
+}
+
+/*
  * main routine of the zfcp_dumper
  */
 int main(int argc, char *argv[])
@@ -960,6 +998,10 @@ int main(int argc, char *argv[])
 		PRINT_ERR("Could not parse parmline\n");
 		goto fail;
 	}
+	if (load_modules()) {
+		PRINT_ERR("Module load failed\n");
+		goto fail;
+	}
 	if (enable_zfcp_device()) {
 		PRINT_ERR("Could not enable dump device\n");
 		goto fail;
openSUSE Build Service is sponsored by