aboutsummaryrefslogtreecommitdiffstats
path: root/main/mkinitfs/0001-nlplug-findfs-detect-zfs-pool.patch
blob: d7a146f6bde92eaac55112f7c7aa687ed70bab1e (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
From 76530be3c34db2e4fdbe9eefd86384ad5f2f38e2 Mon Sep 17 00:00:00 2001
From: Natanael Copa <ncopa@alpinelinux.org>
Date: Fri, 25 Jan 2019 18:15:48 +0000
Subject: [PATCH 1/2] nlplug-findfs: detect zfs pool

if search device is prefixed with ZFS= then we search for a label with
the zpool name in the zfs path. For example, if search device is
"ZFS=tank/alpine/root" then we search for device that is type
"zfs_member" and label "tank".

This makes it work better with grub which creates a boot cmdline with
ZFS=
---
 nlplug-findfs.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/nlplug-findfs.c b/nlplug-findfs.c
index e037a93..0283161 100644
--- a/nlplug-findfs.c
+++ b/nlplug-findfs.c
@@ -961,6 +961,16 @@ static void founddev(struct ueventconf *conf, int found)
 	}
 }
 
+static int is_zfs_pool(const char *path, const char *label)
+{
+	char pool_name[256];
+	char *p;
+	snprintf(pool_name, sizeof(pool_name), "%s", path);
+	if ((p = strchr(pool_name, '/')))
+		*p = '\0';
+	return strcmp(label, pool_name) == 0 ? FOUND_DEVICE : 0;
+}
+
 static int searchdev(struct uevent *ev, const char *searchdev, int scanbootmedia)
 {
 	struct ueventconf *conf = ev->conf;
@@ -981,10 +991,10 @@ static int searchdev(struct uevent *ev, const char *searchdev, int scanbootmedia
 
 	type = blkid_get_tag_value(conf->blkid_cache, "TYPE", ev->devnode);
 	uuid = blkid_get_tag_value(conf->blkid_cache, "UUID", ev->devnode);
+	label = blkid_get_tag_value(conf->blkid_cache, "LABEL", ev->devnode);
 
 	if (searchdev != NULL) {
 		if (strncmp("LABEL=", searchdev, 6) == 0) {
-			label = blkid_get_tag_value(conf->blkid_cache, "LABEL", ev->devnode);
 			if (label && strcmp(label, searchdev+6) == 0)
 				rc = FOUND_DEVICE;
 		} else if (strncmp("UUID=", searchdev, 5) == 0) {
@@ -1003,6 +1013,10 @@ static int searchdev(struct uevent *ev, const char *searchdev, int scanbootmedia
 			start_lvm2(ev->devnode);
 		} else if (strcmp("zfs_member", type) == 0) {
 			start_zpool(uuid);
+			if (searchdev != NULL && label != NULL
+			    && strncmp("ZFS=", searchdev, 4) == 0) {
+				rc = is_zfs_pool(&searchdev[4], label);
+			}
 		} else if (scanbootmedia) {
 			rc = scandev(conf, ev->devnode, type);
 		}
-- 
2.20.1