home: hub: mkinitfs

Download patch

ref: 7389119f3283687adb521aec1397f8db996207fb
parent: a24e4f153268430ca8d39aa6f239bbf656c70798
author: Natanael Copa <ncopa@alpinelinux.org>
date: Fri Jun 10 09:11:01 CDT 2016

nlplug-findfs: increase max delay

Increase timeout to 5sec if we have not found anything so we don't get
error too early.

If boot repos are found then reduce the event timeout to 250ms. If
usb_storage is found, then always add 1 second of delay in addition, to
let the usb host settle.

--- a/nlplug-findfs.c
+++ b/nlplug-findfs.c
@@ -40,6 +40,7 @@
 
 #include "arg.h"
 
+#define MAX_EVENT_TIMEOUT	5000
 #define DEFAULT_EVENT_TIMEOUT	250
 /* usb mass storage needs 1 sec to settle */
 #define USB_STORAGE_TIMEOUT	1000
@@ -204,6 +205,7 @@
 	char *bootrepos;
 	char *apkovls;
 	int timeout;
+	int usb_storage_timeout;
 	int efd;
 	unsigned running_threads;
 	pthread_t cryptsetup_tid;
@@ -682,8 +684,6 @@
 
 static int dispatch_uevent(struct uevent *ev, struct ueventconf *conf)
 {
-	static int timeout_increment = USB_STORAGE_TIMEOUT;
-
 	if (conf->subsystem_filter && ev->subsystem
 	    && strcmp(ev->subsystem, conf->subsystem_filter) != 0) {
 		dbg("subsystem '%s' filtered out (by '%s').",
@@ -701,10 +701,8 @@
 		conf->modalias_count++;
 
 		/* increase timeout so usb drives gets time to settle */
-		if (strcmp(buf, "usb_storage") == 0) {
-			conf->timeout += timeout_increment;
-			timeout_increment = 0;
-		}
+		if (strcmp(buf, "usb_storage") == 0)
+			conf->usb_storage_timeout = USB_STORAGE_TIMEOUT;
 
 	} else if (ev->devname != NULL) {
 		if (conf->program_argv[0] != NULL) {
@@ -842,6 +840,7 @@
 	size_t total_bytes = 0;
 	int found = 0;
 	int not_found_is_ok = 0;
+	int timeout = DEFAULT_EVENT_TIMEOUT;
 	char *program_argv[2] = {0,0};
 	pthread_t tid;
 	sigset_t sigchldmask;
@@ -853,7 +852,8 @@
 
 	memset(&conf, 0, sizeof(conf));
 	conf.program_argv = program_argv;
-	conf.timeout = DEFAULT_EVENT_TIMEOUT;
+	conf.timeout = MAX_EVENT_TIMEOUT;
+	conf.usb_storage_timeout = 0;
 	use_lvm = access(LVM_PATH, X_OK) == 0;
 	use_mdadm = access(MDADM_PATH, X_OK) == 0;
 
@@ -890,7 +890,7 @@
 		conf.program_argv[0] = EARGF(usage(1));
 		break;
 	case 't':
-		conf.timeout = atoi(EARGF(usage(1)));
+		timeout = atoi(EARGF(usage(1)));
 		break;
 	default:
 		usage(1);
@@ -921,7 +921,8 @@
 	conf.running_threads |= TRIGGER_THREAD;
 
 	while (1) {
-		r = poll(fds, numfds, (spawn_active(&spawnmgr) || conf.running_threads) ? -1 : conf.timeout);
+		int t = conf.timeout + conf.usb_storage_timeout;
+		r = poll(fds, numfds, (spawn_active(&spawnmgr) || conf.running_threads) ? -1 : t);
 		if (r == -1) {
 			if (errno == EINTR || errno == ERESTART)
 				continue;
@@ -928,7 +929,7 @@
 			err(1, "poll");
 		}
 		if (r == 0) {
-			dbg("exit due to timeout (%i)", conf.timeout);
+			dbg("exit due to timeout (%i)", t);
 			break;
 		}
 
@@ -977,9 +978,19 @@
 			if ((found & FOUND_DEVICE)
 			    || ((found & FOUND_BOOTREPO) &&
 				(found & FOUND_APKOVL))) {
+				/* we have found everything we need, so no
+				   no need to wait for anything new event */
 				if (conf.timeout)
 					dbg("FOUND! setting timeout to 0");
 				conf.timeout = 0;
+				conf.usb_storage_timeout= 0;
+			} else if ((found & FOUND_BOOTREPO) && conf.timeout) {
+				/* we have found boot repo, but not apkovl
+				   we reduce timeout to default timeout */
+				if (conf.timeout != timeout)
+					dbg("Setting timeout to %d",
+					    timeout);
+				conf.timeout = timeout;
 			}
 		}