aboutsummaryrefslogtreecommitdiffstats
path: root/main/mkinitfs/0001-nlplug-findfs-increase-max-delay.patch
blob: e341103137b68322d0d596086c5aa939eb36d7d0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
From 7389119f3283687adb521aec1397f8db996207fb Mon Sep 17 00:00:00 2001
From: Natanael Copa <ncopa@alpinelinux.org>
Date: Fri, 10 Jun 2016 14:11:01 +0000
Subject: [PATCH] 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.
---
 nlplug-findfs.c | 31 +++++++++++++++++++++----------
 1 file changed, 21 insertions(+), 10 deletions(-)

diff --git a/nlplug-findfs.c b/nlplug-findfs.c
index b11b7b8..7a3a136 100644
--- 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 @@ struct ueventconf {
 	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 searchdev(struct uevent *ev, const char *searchdev, char *bootrepos,
 
 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 @@ static int dispatch_uevent(struct uevent *ev, struct ueventconf *conf)
 		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 @@ int main(int argc, char *argv[])
 	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 @@ int main(int argc, char *argv[])
 
 	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 @@ int main(int argc, char *argv[])
 		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,14 +921,15 @@ int main(int argc, char *argv[])
 	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;
 			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 @@ int main(int argc, char *argv[])
 			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;
 			}
 		}
 
-- 
2.8.4