diff mbox series

[fstools,v2] partname: Correct fstools_partname_fallback_scan comparison

Message ID 20230126061815.3146071-1-computersforpeace@gmail.com
State Accepted
Headers show
Series [fstools,v2] partname: Correct fstools_partname_fallback_scan comparison | expand

Commit Message

Brian Norris Jan. 26, 2023, 6:18 a.m. UTC
Commit 1ea5855e980c ("partname: Introduce fstools_partname_fallback_scan
option") had two problems:

1. The strcmp() aborted when the param *matched* 1; we wanted the
   inverse
2. It was too aggressive about skipping the fallback behavior. For
   devices that had no root= parameter, they would always attempt the
   fallback scan.

Fix both of those.

Fixes: 1ea5855e980c ("partname: Introduce fstools_partname_fallback_scan option")
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
---

Changes in v2:
 * Also restore the pre-1ea5855e980c fallback behavior when no root= is
   provided

 libfstools/partname.c | 33 ++++++++++++++++++++-------------
 1 file changed, 20 insertions(+), 13 deletions(-)

Comments

Brian Norris Feb. 3, 2023, 6:27 p.m. UTC | #1
Hi Ansuel (or others),

On Wed, Jan 25, 2023 at 10:18 PM Brian Norris
<computersforpeace@gmail.com> wrote:
>
> Commit 1ea5855e980c ("partname: Introduce fstools_partname_fallback_scan
> option") had two problems:
>
> 1. The strcmp() aborted when the param *matched* 1; we wanted the
>    inverse
> 2. It was too aggressive about skipping the fallback behavior. For
>    devices that had no root= parameter, they would always attempt the
>    fallback scan.
>
> Fix both of those.
>
> Fixes: 1ea5855e980c ("partname: Introduce fstools_partname_fallback_scan option")
> Signed-off-by: Brian Norris <computersforpeace@gmail.com>

Would you be able to look at this soon? Your emergency fix broke
multiple things, and I'd like to get TP-Link OnHub back in shape so
others can rely on snapshot builds.

Thanks,
Brian
diff mbox series

Patch

diff --git a/libfstools/partname.c b/libfstools/partname.c
index f42322a49d5b..004b249a7fdb 100644
--- a/libfstools/partname.c
+++ b/libfstools/partname.c
@@ -121,6 +121,8 @@  static struct volume *partname_volume_find(char *name)
 	char *rootdev = NULL, *devname, *tmp;
 	int j;
 	bool found = false;
+	bool allow_fallback = false;
+	bool has_root = false;
 	glob_t gl;
 
 	if (get_var_from_file("/proc/cmdline", "fstools_ignore_partname", rootparam, sizeof(rootparam))) {
@@ -128,24 +130,29 @@  static struct volume *partname_volume_find(char *name)
 			return NULL;
 	}
 
-	if (get_var_from_file("/proc/cmdline", "root", rootparam, sizeof(rootparam)) && rootparam[0] == '/') {
+	/*
+	 * Some device may contains a GPT partition named rootfs_data that may not be suitable.
+	 * To save from regression with old implementation that doesn't use fstools_ignore_partname to
+	 * explicitly say that that partname scan should be ignored, make explicit that scanning each
+	 * partition should be done by providing fstools_partname_fallback_scan=1 and skip partname scan
+	 * in every other case.
+	 */
+	if (get_var_from_file("/proc/cmdline", "fstools_partname_fallback_scan", rootparam, sizeof(rootparam))) {
+		if (!strcmp("1", rootparam))
+			allow_fallback = true;
+	}
+
+	if (get_var_from_file("/proc/cmdline", "root", rootparam, sizeof(rootparam)))
+		has_root = true;
+
+	if (has_root && rootparam[0] == '/') {
 		rootdev = rootdevname(rootparam);
 		/* find partition on same device as rootfs */
 		snprintf(ueventgstr, sizeof(ueventgstr), "%s/%s/*/uevent", block_dir_name, rootdev);
 	} else {
-		/*
-		 * Some device may contains a GPT partition named rootfs_data that may not be suitable.
-		 * To save from regression with old implementation that doesn't use fstools_ignore_partname to
-		 * explicitly say that that parname scan should be ignored, make explicit that scanning each
-		 * partition should be done by providing fstools_partname_fallback_scan=1 and skip partname scan
-		 * in every other case.
-		 */
-		if (!get_var_from_file("/proc/cmdline", "fstools_partname_fallback_scan", rootparam, sizeof(rootparam)))
+		/* For compatibility, devices with root= params must explicitly opt into this fallback. */
+		if (has_root && !allow_fallback)
 			return NULL;
-
-		if (!strcmp("1", rootparam))
-			return NULL;
-
 		/* no useful 'root=' kernel cmdline parameter, find on any block device */
 		snprintf(ueventgstr, sizeof(ueventgstr), "%s/*/uevent", block_dir_name);
 	}