Blame SOURCES/0056-Improve-consistency-of-debug-prints.patch

b15ea1
From d153ca75d0323eb125e525ebdf4ac5c982941d15 Mon Sep 17 00:00:00 2001
b15ea1
From: Peter Jones <pjones@redhat.com>
b15ea1
Date: Tue, 15 Oct 2019 16:26:30 -0400
b15ea1
Subject: [PATCH 56/86] Improve consistency of debug prints
b15ea1
b15ea1
This changes debug prints in a couple of ways:
b15ea1
- always calls the path we're parsing "current" in the output
b15ea1
- always use ' not " for quoting in the debug output, so tools that
b15ea1
  escape strings won't change the lenghts
b15ea1
- everything that parses "current" has a debug print after each parse
b15ea1
  attempt and before returning.
b15ea1
b15ea1
Signed-off-by: Peter Jones <pjones@redhat.com>
b15ea1
---
b15ea1
 src/dp-acpi.c         |  8 ++++----
b15ea1
 src/linux-acpi-root.c |  4 ++--
b15ea1
 src/linux-acpi.c      |  6 +++---
b15ea1
 src/linux-ata.c       | 11 +++++++----
b15ea1
 src/linux-i2o.c       | 10 +++++-----
b15ea1
 src/linux-md.c        |  4 ++--
b15ea1
 src/linux-pci-root.c  |  2 +-
b15ea1
 src/linux-pmem.c      |  5 +++--
b15ea1
 src/linux.c           | 27 +++++++++++++++++----------
b15ea1
 9 files changed, 44 insertions(+), 33 deletions(-)
b15ea1
b15ea1
diff --git a/src/dp-acpi.c b/src/dp-acpi.c
b15ea1
index 02ec70eec7a..ae4102cdf56 100644
b15ea1
--- a/src/dp-acpi.c
b15ea1
+++ b/src/dp-acpi.c
b15ea1
@@ -1,6 +1,6 @@
b15ea1
 /*
b15ea1
  * libefivar - library for the manipulation of EFI variables
b15ea1
- * Copyright 2012-2015 Red Hat, Inc.
b15ea1
+ * Copyright 2012-2019 Red Hat, Inc.
b15ea1
  *
b15ea1
  * This library is free software; you can redistribute it and/or
b15ea1
  * modify it under the terms of the GNU Lesser General Public License as
b15ea1
@@ -52,9 +52,9 @@ _format_acpi_hid_ex(unsigned char *buf, size_t size,
b15ea1
 {
b15ea1
 	ssize_t off = 0;
b15ea1
 
b15ea1
-	debug("hid:0x%08x hidstr:\"%s\"", dp->acpi_hid_ex.hid, hidstr);
b15ea1
-	debug("cid:0x%08x cidstr:\"%s\"", dp->acpi_hid_ex.cid, cidstr);
b15ea1
-	debug("uid:0x%08x uidstr:\"%s\"", dp->acpi_hid_ex.uid, uidstr);
b15ea1
+	debug("hid:0x%08x hidstr:'%s'", dp->acpi_hid_ex.hid, hidstr);
b15ea1
+	debug("cid:0x%08x cidstr:'%s'", dp->acpi_hid_ex.cid, cidstr);
b15ea1
+	debug("uid:0x%08x uidstr:'%s'", dp->acpi_hid_ex.uid, uidstr);
b15ea1
 
b15ea1
 	if (!hidstr && !cidstr && (uidstr || dp->acpi_hid_ex.uid)) {
b15ea1
 		format(buf, size, off, "AcpiExp",
b15ea1
diff --git a/src/linux-acpi-root.c b/src/linux-acpi-root.c
b15ea1
index 9154c950bb1..86693c81878 100644
b15ea1
--- a/src/linux-acpi-root.c
b15ea1
+++ b/src/linux-acpi-root.c
b15ea1
@@ -144,7 +144,7 @@ parse_acpi_root(struct device *dev, const char *path, const char *root UNUSED)
b15ea1
 			return rc;
b15ea1
 		}
b15ea1
 	}
b15ea1
-	debug("Parsed HID:0x%08x UID:0x%"PRIx64" uidstr:\"%s\" path:\"%s\"",
b15ea1
+	debug("Parsed HID:0x%08x UID:0x%"PRIx64" uidstr:'%s' path:'%s'",
b15ea1
 	      dev->acpi_root.acpi_hid, dev->acpi_root.acpi_uid,
b15ea1
 	      dev->acpi_root.acpi_uid_str,
b15ea1
 	      dev->acpi_root.acpi_cid_str);
b15ea1
@@ -162,7 +162,7 @@ dp_create_acpi_root(struct device *dev,
b15ea1
 	debug("entry buf:%p size:%zd off:%zd", buf, size, off);
b15ea1
 
b15ea1
 	if (dev->acpi_root.acpi_uid_str || dev->acpi_root.acpi_cid_str) {
b15ea1
-		debug("creating acpi_hid_ex dp hid:0x%08x uid:0x%"PRIx64" uidstr:\"%s\" cidstr:\"%s\"",
b15ea1
+		debug("creating acpi_hid_ex dp hid:0x%08x uid:0x%"PRIx64" uidstr:'%s' cidstr:'%s'",
b15ea1
 		      dev->acpi_root.acpi_hid, dev->acpi_root.acpi_uid,
b15ea1
 		      dev->acpi_root.acpi_uid_str, dev->acpi_root.acpi_cid_str);
b15ea1
 		new = efidp_make_acpi_hid_ex(buf + off, size ? size - off : 0,
b15ea1
diff --git a/src/linux-acpi.c b/src/linux-acpi.c
b15ea1
index 919f4654ae3..534573f32c1 100644
b15ea1
--- a/src/linux-acpi.c
b15ea1
+++ b/src/linux-acpi.c
b15ea1
@@ -1,6 +1,6 @@
b15ea1
 /*
b15ea1
  * libefiboot - library for the manipulation of EFI boot variables
b15ea1
- * Copyright 2012-2018 Red Hat, Inc.
b15ea1
+ * Copyright 2012-2019 Red Hat, Inc.
b15ea1
  *
b15ea1
  * This library is free software; you can redistribute it and/or
b15ea1
  * modify it under the terms of the GNU Lesser General Public License as
b15ea1
@@ -54,7 +54,7 @@ parse_acpi_hid_uid(struct device *dev, const char *fmt, ...)
b15ea1
 		if (l > 1) {
b15ea1
 			fbuf[l-1] = 0;
b15ea1
 			dev->acpi_root.acpi_cid_str = strdup(fbuf);
b15ea1
-			debug("Setting ACPI root path to \"%s\"", fbuf);
b15ea1
+			debug("Setting ACPI root path to '%s'", fbuf);
b15ea1
 		}
b15ea1
 	}
b15ea1
 
b15ea1
@@ -111,7 +111,7 @@ hid_err:
b15ea1
 			}
b15ea1
 		}
b15ea1
 	}
b15ea1
-	debug("acpi root UID:0x%"PRIx64" uidstr:\"%s\"",
b15ea1
+	debug("acpi root UID:0x%"PRIx64" uidstr:'%s'",
b15ea1
 	      dev->acpi_root.acpi_uid, dev->acpi_root.acpi_uid_str);
b15ea1
 
b15ea1
 	errno = 0;
b15ea1
diff --git a/src/linux-ata.c b/src/linux-ata.c
b15ea1
index a05a2feb8b9..a51ed5abbe0 100644
b15ea1
--- a/src/linux-ata.c
b15ea1
+++ b/src/linux-ata.c
b15ea1
@@ -60,6 +60,7 @@ is_pata(struct device *dev)
b15ea1
 static ssize_t
b15ea1
 parse_ata(struct device *dev, const char *path, const char *root UNUSED)
b15ea1
 {
b15ea1
+	const char *current = path;
b15ea1
 	uint32_t scsi_host, scsi_bus, scsi_device, scsi_target;
b15ea1
 	uint64_t scsi_lun;
b15ea1
 	int pos;
b15ea1
@@ -118,6 +119,7 @@ parse_ata(struct device *dev, const char *path, const char *root UNUSED)
b15ea1
 			      NULL, NULL, NULL);
b15ea1
 	if (pos < 0)
b15ea1
 		return -1;
b15ea1
+	current += pos;
b15ea1
 
b15ea1
 	dev->ata_info.scsi_host = scsi_host;
b15ea1
 	dev->ata_info.scsi_bus = scsi_bus;
b15ea1
@@ -125,10 +127,11 @@ parse_ata(struct device *dev, const char *path, const char *root UNUSED)
b15ea1
 	dev->ata_info.scsi_target = scsi_target;
b15ea1
 	dev->ata_info.scsi_lun = scsi_lun;
b15ea1
 
b15ea1
-	char *block = strstr(path, "/block/");
b15ea1
-	if (!block)
b15ea1
-		return -1;
b15ea1
-	return block + 1 - path;
b15ea1
+	char *block = strstr(current, "/block/");
b15ea1
+	if (block)
b15ea1
+		current += block + 1 - current;
b15ea1
+	debug("current:'%s' sz:%zd", current, current - path);
b15ea1
+	return current - path;
b15ea1
 }
b15ea1
 
b15ea1
 static ssize_t
b15ea1
diff --git a/src/linux-i2o.c b/src/linux-i2o.c
b15ea1
index ebd92aeeb53..b53f4516309 100644
b15ea1
--- a/src/linux-i2o.c
b15ea1
+++ b/src/linux-i2o.c
b15ea1
@@ -1,6 +1,6 @@
b15ea1
 /*
b15ea1
  * libefiboot - library for the manipulation of EFI boot variables
b15ea1
- * Copyright 2012-2018 Red Hat, Inc.
b15ea1
+ * Copyright 2012-2019 Red Hat, Inc.
b15ea1
  *
b15ea1
  * This library is free software; you can redistribute it and/or
b15ea1
  * modify it under the terms of the GNU Lesser General Public License as
b15ea1
@@ -33,7 +33,7 @@
b15ea1
  * ... probably doesn't work.
b15ea1
  */
b15ea1
 static ssize_t
b15ea1
-parse_i2o(struct device *dev, const char *current UNUSED, const char *root UNUSED)
b15ea1
+parse_i2o(struct device *dev, const char *current, const char *root UNUSED)
b15ea1
 {
b15ea1
 	debug("entry");
b15ea1
 	/* I2O disks can have up to 16 partitions, or 4 bits worth. */
b15ea1
@@ -47,9 +47,9 @@ parse_i2o(struct device *dev, const char *current UNUSED, const char *root UNUSE
b15ea1
 	}
b15ea1
 
b15ea1
 	char *block = strstr(current, "/block/");
b15ea1
-	if (!block)
b15ea1
-	        return -1;
b15ea1
-	return block + 1 - current;
b15ea1
+	ssize_t sz = block ? block + 1 - current : -1;
b15ea1
+	debug("current:'%s' sz:%zd", current, sz);
b15ea1
+	return sz;
b15ea1
 }
b15ea1
 
b15ea1
 enum interface_type i2o_iftypes[] = { i2o, unknown };
b15ea1
diff --git a/src/linux-md.c b/src/linux-md.c
b15ea1
index b0809f8295a..2aacb87469a 100644
b15ea1
--- a/src/linux-md.c
b15ea1
+++ b/src/linux-md.c
b15ea1
@@ -50,7 +50,7 @@ parse_md(struct device *dev, const char *current, const char *root UNUSED)
b15ea1
 	debug("searching for mdM/mdMpN");
b15ea1
 	rc = sscanf(current, "md%d/%nmd%dp%d%n",
b15ea1
 	            &md, &pos0, &tosser0, &part, &pos1);
b15ea1
-	debug("current:\"%s\" rc:%d pos0:%d pos1:%d\n", current, rc, pos0, pos1);
b15ea1
+	debug("current:'%s' rc:%d pos0:%d pos1:%d\n", current, rc, pos0, pos1);
b15ea1
 	dbgmk("         ", pos0, pos1);
b15ea1
 	/*
b15ea1
 	 * If it isn't of that form, it's not one of our partitioned md devices.
b15ea1
@@ -63,10 +63,10 @@ parse_md(struct device *dev, const char *current, const char *root UNUSED)
b15ea1
 	if (dev->part == -1)
b15ea1
 	        dev->part = part;
b15ea1
 
b15ea1
+	debug("current:'%s' sz:%d\n", current, pos1);
b15ea1
 	return pos1;
b15ea1
 }
b15ea1
 
b15ea1
-
b15ea1
 static char *
b15ea1
 make_part_name(struct device *dev)
b15ea1
 {
b15ea1
diff --git a/src/linux-pci-root.c b/src/linux-pci-root.c
b15ea1
index 8cd3849b1db..84189ffbaca 100644
b15ea1
--- a/src/linux-pci-root.c
b15ea1
+++ b/src/linux-pci-root.c
b15ea1
@@ -87,7 +87,7 @@ dp_create_pci_root(struct device *dev UNUSED,
b15ea1
 	debug("entry buf:%p size:%zd off:%zd", buf, size, off);
b15ea1
 	debug("returning 0");
b15ea1
 	if (dev->acpi_root.acpi_uid_str) {
b15ea1
-	        debug("creating acpi_hid_ex dp hid:0x%08x uid:\"%s\"",
b15ea1
+	        debug("creating acpi_hid_ex dp hid:0x%08x uid:'%s'",
b15ea1
 	              dev->acpi_root.acpi_hid,
b15ea1
 	              dev->acpi_root.acpi_uid_str);
b15ea1
 	        new = efidp_make_acpi_hid_ex(buf + off, size ? size - off : 0,
b15ea1
diff --git a/src/linux-pmem.c b/src/linux-pmem.c
b15ea1
index e5de3264d03..b9f83e12e7b 100644
b15ea1
--- a/src/linux-pmem.c
b15ea1
+++ b/src/linux-pmem.c
b15ea1
@@ -103,11 +103,12 @@ parse_pmem(struct device *dev, const char *path, const char *root UNUSED)
b15ea1
 	 *
b15ea1
 	 * 259:0 -> ../../devices/LNXSYSTM:00/LNXSYBUS:00/ACPI0012:00/ndbus0/region12/btt12.1/block/pmem12s
b15ea1
 	 */
b15ea1
+	pos0 = pos1 = -1;
b15ea1
 	rc = sscanf(current,
b15ea1
 	            "../../devices/%nLNXSYSTM:%hhx/LNXSYBUS:%hhx/ACPI%hx:%hhx/ndbus%d/region%d/btt%d.%d/%n",
b15ea1
 	            &pos0, &system, &sysbus, &pnp_id, &acpi_id, &ndbus,
b15ea1
 		    &region, &btt_region_id, &btt_id, &pos1);
b15ea1
-	debug("current:\"%s\" rc:%d pos0:%d pos1:%d", current, rc, pos0, pos1);
b15ea1
+	debug("current:'%s' rc:%d pos0:%d pos1:%d", current, rc, pos0, pos1);
b15ea1
 	dbgmk("         ", pos0, pos1);
b15ea1
 	if (rc < 8)
b15ea1
 	        return 0;
b15ea1
@@ -126,7 +127,7 @@ parse_pmem(struct device *dev, const char *path, const char *root UNUSED)
b15ea1
 	        return -1;
b15ea1
 
b15ea1
 	filebuf = NULL;
b15ea1
-	debug("nvdimm namespace is \"%s\"", namespace);
b15ea1
+	debug("nvdimm namespace is '%s'", namespace);
b15ea1
 	rc = read_sysfs_file(&filebuf, "bus/nd/devices/%s/uuid", namespace);
b15ea1
 	free(namespace);
b15ea1
 	if (rc < 0 || filebuf == NULL)
b15ea1
diff --git a/src/linux.c b/src/linux.c
b15ea1
index 1f37933f546..1051894e7bc 100644
b15ea1
--- a/src/linux.c
b15ea1
+++ b/src/linux.c
b15ea1
@@ -184,10 +184,10 @@ set_disk_and_part_name(struct device *dev)
b15ea1
 	errno = 0;
b15ea1
 	debug("dev->disk_name:%p dev->part_name:%p", dev->disk_name, dev->part_name);
b15ea1
 	debug("dev->part:%d", dev->part);
b15ea1
-	debug("ultimate:\"%s\"", ultimate ? : "");
b15ea1
-	debug("penultimate:\"%s\"", penultimate ? : "");
b15ea1
-	debug("approximate:\"%s\"", approximate ? : "");
b15ea1
-	debug("proximate:\"%s\"", proximate ? : "");
b15ea1
+	debug("ultimate:'%s'", ultimate ? : "");
b15ea1
+	debug("penultimate:'%s'", penultimate ? : "");
b15ea1
+	debug("approximate:'%s'", approximate ? : "");
b15ea1
+	debug("proximate:'%s'", proximate ? : "");
b15ea1
 
b15ea1
 	if (ultimate && penultimate &&
b15ea1
 	    ((proximate && !strcmp(proximate, "nvme")) ||
b15ea1
@@ -463,7 +463,11 @@ struct device HIDDEN
b15ea1
 	                efi_error("parsing %s failed", probe->name);
b15ea1
 	                goto err;
b15ea1
 	        } else if (pos > 0) {
b15ea1
-	                debug("%s matched %s", probe->name, current);
b15ea1
+			char match[pos+1];
b15ea1
+
b15ea1
+			strncpy(match, current, pos);
b15ea1
+			match[pos] = '\0';
b15ea1
+	                debug("%s matched '%s'", probe->name, match);
b15ea1
 	                dev->flags |= probe->flags;
b15ea1
 
b15ea1
 	                if (probe->flags & DEV_PROVIDES_HD ||
b15ea1
@@ -473,7 +477,10 @@ struct device HIDDEN
b15ea1
 
b15ea1
 	                dev->probes[n++] = dev_probes[i];
b15ea1
 	                current += pos;
b15ea1
-	                debug("current:%s", current);
b15ea1
+			if (current[0] == '\0')
b15ea1
+				debug("finished");
b15ea1
+			else
b15ea1
+				debug("current:'%s'", current);
b15ea1
 	                last_successful_probe = i;
b15ea1
 
b15ea1
 	                if (!*current || !strncmp(current, "block/", 6))
b15ea1
@@ -482,8 +489,8 @@ struct device HIDDEN
b15ea1
 	                continue;
b15ea1
 	        }
b15ea1
 
b15ea1
-	        debug("dev_probes[i+1]: %p dev->interface_type: %d\n",
b15ea1
-	              dev_probes[i+1], dev->interface_type);
b15ea1
+	        debug("dev_probes[%d]: %p dev->interface_type: %d\n",
b15ea1
+	              i+1, dev_probes[i+1], dev->interface_type);
b15ea1
 	        if (dev_probes[i+1] == NULL && dev->interface_type == unknown) {
b15ea1
 	                pos = 0;
b15ea1
 	                rc = sscanf(current, "%*[^/]/%n", &pos;;
b15ea1
@@ -499,8 +506,8 @@ slash_err:
b15ea1
 	                if (!current[pos])
b15ea1
 	                        goto slash_err;
b15ea1
 
b15ea1
-	                debug("Cannot parse device link segment \"%s\"", current);
b15ea1
-	                debug("Skipping to \"%s\"", current + pos);
b15ea1
+	                debug("Cannot parse device link segment '%s'", current);
b15ea1
+	                debug("Skipping to '%s'", current + pos);
b15ea1
 	                debug("This means we can only create abbreviated paths");
b15ea1
 	                dev->flags |= DEV_ABBREV_ONLY;
b15ea1
 	                i = last_successful_probe;
b15ea1
-- 
b15ea1
2.24.1
b15ea1