Blame SOURCES/0052-sysfs-parsing-add-some-more-debugging-output.patch

4e0e09
From f1d09655cbc47a738410b601ac1f7ddde2d72b26 Mon Sep 17 00:00:00 2001
4e0e09
From: Peter Jones <pjones@redhat.com>
4e0e09
Date: Wed, 2 Oct 2019 16:59:14 -0400
4e0e09
Subject: [PATCH 52/63] sysfs parsing: add some more debugging output
4e0e09
4e0e09
This adds highlights under the things we've found when searching, like:
4e0e09
4e0e09
linux-pci.c:66 parse_pci(): searching for 0000:00:00.0/
4e0e09
linux-pci.c:69 parse_pci(): current:'0000:00:1d.4/0000:6e:00.0/nvme/nvme0/nvme0n1' rc:4 pos0:0 pos1:13
4e0e09
linux-pci.c:70 parse_pci():          ^^^^^^^^^^^^^
4e0e09
4e0e09
Signed-off-by: Peter Jones <pjones@redhat.com>
4e0e09
---
4e0e09
 src/linux-acpi-root.c |  3 +++
4e0e09
 src/linux-emmc.c      |  1 +
4e0e09
 src/linux-md.c        |  1 +
4e0e09
 src/linux-nvme.c      |  1 +
4e0e09
 src/linux-pci-root.c  |  2 ++
4e0e09
 src/linux-pci.c       |  1 +
4e0e09
 src/linux-pmem.c      |  2 ++
4e0e09
 src/linux-sata.c      |  4 ++++
4e0e09
 src/linux-scsi.c      |  8 ++++++++
4e0e09
 src/linux-soc-root.c  |  2 ++
4e0e09
 src/linux-virtblk.c   |  1 +
4e0e09
 src/util.h            | 35 +++++++++++++++++++++++++++++++++++
4e0e09
 12 files changed, 61 insertions(+)
4e0e09
4e0e09
diff --git a/src/linux-acpi-root.c b/src/linux-acpi-root.c
4e0e09
index f48d4be9ac6..5ed4d7f5b86 100644
4e0e09
--- a/src/linux-acpi-root.c
4e0e09
+++ b/src/linux-acpi-root.c
4e0e09
@@ -63,6 +63,7 @@ parse_acpi_root(struct device *dev, const char *current, const char *root UNUSED
4e0e09
 	 */
4e0e09
 	rc = sscanf(devpart, "../../devices/platform/%n", &pos;;
4e0e09
 	debug("devpart:\"%s\" rc:%d pos:%d", devpart, rc, pos);
4e0e09
+	dbgmk("         ", pos);
4e0e09
 	if (rc != 0 || pos < 1)
4e0e09
 		return 0;
4e0e09
 	devpart += pos;
4e0e09
@@ -97,6 +98,7 @@ parse_acpi_root(struct device *dev, const char *current, const char *root UNUSED
4e0e09
 
4e0e09
 	pos -= 4;
4e0e09
 	debug("devpart:\"%s\" rc:%d pos:%d", devpart, rc, pos);
4e0e09
+	dbgmk("         ", pos);
4e0e09
 	acpi_header = strndupa(devpart, pos);
4e0e09
 	if (!acpi_header)
4e0e09
 		return 0;
4e0e09
@@ -114,6 +116,7 @@ parse_acpi_root(struct device *dev, const char *current, const char *root UNUSED
4e0e09
 	}
4e0e09
 	debug("devpart:\"%s\" parsed:%04hx:%02hhx pos:%d rc:%d",
4e0e09
 	      devpart, pad0, pad1, pos, rc);
4e0e09
+	dbgmk("         ", pos);
4e0e09
 
4e0e09
 	devpart += pos;
4e0e09
 
4e0e09
diff --git a/src/linux-emmc.c b/src/linux-emmc.c
4e0e09
index 8af316a1723..59ef8e7524d 100644
4e0e09
--- a/src/linux-emmc.c
4e0e09
+++ b/src/linux-emmc.c
4e0e09
@@ -58,6 +58,7 @@ parse_emmc(struct device *dev, const char *current, const char *root UNUSED)
4e0e09
 	            &tosser0, &tosser1, &tosser2, &slot_id,
4e0e09
 	            &pos0, &tosser3, &partition, &pos1);
4e0e09
 	debug("current:\"%s\" rc:%d pos0:%d pos1:%d\n", current, rc, pos0, pos1);
4e0e09
+	dbgmk("         ", pos0, pos1);
4e0e09
 	/*
4e0e09
 	 * If it isn't of that form, it's not one of our emmc devices.
4e0e09
 	 */
4e0e09
diff --git a/src/linux-md.c b/src/linux-md.c
4e0e09
index 3d5975d8195..1d7bd3195c0 100644
4e0e09
--- a/src/linux-md.c
4e0e09
+++ b/src/linux-md.c
4e0e09
@@ -51,6 +51,7 @@ parse_md(struct device *dev, const char *current, const char *root UNUSED)
4e0e09
 	rc = sscanf(current, "md%d/%nmd%dp%d%n",
4e0e09
 	            &md, &pos0, &tosser0, &part, &pos1);
4e0e09
 	debug("current:\"%s\" rc:%d pos0:%d pos1:%d\n", current, rc, pos0, pos1);
4e0e09
+	dbgmk("         ", pos0, pos1);
4e0e09
 	/*
4e0e09
 	 * If it isn't of that form, it's not one of our partitioned md devices.
4e0e09
 	 */
4e0e09
diff --git a/src/linux-nvme.c b/src/linux-nvme.c
4e0e09
index e6e42c7a3fc..0b4eae74f79 100644
4e0e09
--- a/src/linux-nvme.c
4e0e09
+++ b/src/linux-nvme.c
4e0e09
@@ -62,6 +62,7 @@ parse_nvme(struct device *dev, const char *current, const char *root UNUSED)
4e0e09
 	            &tosser0, &ctrl_id, &ns_id, &pos0,
4e0e09
 	            &tosser1, &tosser2, &partition, &pos1);
4e0e09
 	debug("current:\"%s\" rc:%d pos0:%d pos1:%d\n", current, rc, pos0, pos1);
4e0e09
+	dbgmk("         ", pos0, pos1);
4e0e09
 	/*
4e0e09
 	 * If it isn't of that form, it's not one of our nvme devices.
4e0e09
 	 */
4e0e09
diff --git a/src/linux-pci-root.c b/src/linux-pci-root.c
4e0e09
index ede9321395c..c84b639cbfe 100644
4e0e09
--- a/src/linux-pci-root.c
4e0e09
+++ b/src/linux-pci-root.c
4e0e09
@@ -57,6 +57,8 @@ parse_pci_root(struct device *dev, const char *current, const char *root UNUSED)
4e0e09
 	 *    ^d   ^p
4e0e09
 	 */
4e0e09
 	rc = sscanf(devpart, "../../devices/pci%hx:%hhx/%n", &root_domain, &root_bus, &pos;;
4e0e09
+	debug("current:\"%s\" rc:%d pos:%d", devpart, rc, pos);
4e0e09
+	dbgmk("         ", pos);
4e0e09
 	/*
4e0e09
 	 * If we can't find that, it's not a PCI device.
4e0e09
 	 */
4e0e09
diff --git a/src/linux-pci.c b/src/linux-pci.c
4e0e09
index 4c715df3d6e..0de330db628 100644
4e0e09
--- a/src/linux-pci.c
4e0e09
+++ b/src/linux-pci.c
4e0e09
@@ -68,6 +68,7 @@ parse_pci(struct device *dev, const char *current, const char *root)
4e0e09
 	        rc = sscanf(devpart, "%hx:%hhx:%hhx.%hhx/%n",
4e0e09
 	                    &domain, &bus, &device, &function, &pos;;
4e0e09
 	        debug("current:\"%s\" rc:%d pos:%d", devpart, rc, pos);
4e0e09
+		dbgmk("         ", pos);
4e0e09
 	        if (rc != 4)
4e0e09
 	                break;
4e0e09
 	        devpart += pos;
4e0e09
diff --git a/src/linux-pmem.c b/src/linux-pmem.c
4e0e09
index 099ac8aef8c..18eb7dce5e3 100644
4e0e09
--- a/src/linux-pmem.c
4e0e09
+++ b/src/linux-pmem.c
4e0e09
@@ -105,6 +105,8 @@ parse_pmem(struct device *dev, const char *current, const char *root UNUSED)
4e0e09
 	            "../../devices/LNXSYSTM:%hhx/LNXSYBUS:%hhx/ACPI%hx:%hhx/ndbus%d/region%d/btt%d.%d/%n",
4e0e09
 	            &system, &sysbus, &pnp_id, &acpi_id, &ndbus, &region,
4e0e09
 	            &btt_region_id, &btt_id, &pos;;
4e0e09
+	debug("current:\"%s\" rc:%d pos:%d", current, rc, pos);
4e0e09
+	dbgmk("         ", pos);
4e0e09
 	if (rc < 8)
4e0e09
 	        return 0;
4e0e09
 
4e0e09
diff --git a/src/linux-sata.c b/src/linux-sata.c
4e0e09
index ee285d84a76..b0caa3fa401 100644
4e0e09
--- a/src/linux-sata.c
4e0e09
+++ b/src/linux-sata.c
4e0e09
@@ -162,6 +162,7 @@ parse_sata(struct device *dev, const char *devlink, const char *root UNUSED)
4e0e09
 	debug("searching for ata1/");
4e0e09
 	rc = sscanf(current, "ata%"PRIu32"/%n", &print_id, &pos;;
4e0e09
 	debug("current:\"%s\" rc:%d pos:%d\n", current, rc, pos);
4e0e09
+	dbgmk("         ", pos);
4e0e09
 	/*
4e0e09
 	 * If we don't find this one, it isn't an ata device, so return 0 not
4e0e09
 	 * error.  Later errors mean it is an ata device, but we can't parse
4e0e09
@@ -175,6 +176,7 @@ parse_sata(struct device *dev, const char *devlink, const char *root UNUSED)
4e0e09
 	debug("searching for host0/");
4e0e09
 	rc = sscanf(current, "host%"PRIu32"/%n", &scsi_bus, &pos;;
4e0e09
 	debug("current:\"%s\" rc:%d pos:%d\n", current, rc, pos);
4e0e09
+	dbgmk("         ", pos);
4e0e09
 	if (rc != 1)
4e0e09
 	        return -1;
4e0e09
 	current += pos;
4e0e09
@@ -184,6 +186,7 @@ parse_sata(struct device *dev, const char *devlink, const char *root UNUSED)
4e0e09
 	rc = sscanf(current, "target%"PRIu32":%"PRIu32":%"PRIu64"/%n",
4e0e09
 	            &scsi_device, &scsi_target, &scsi_lun, &pos;;
4e0e09
 	debug("current:\"%s\" rc:%d pos:%d\n", current, rc, pos);
4e0e09
+	dbgmk("         ", pos);
4e0e09
 	if (rc != 3)
4e0e09
 	        return -1;
4e0e09
 	current += pos;
4e0e09
@@ -193,6 +196,7 @@ parse_sata(struct device *dev, const char *devlink, const char *root UNUSED)
4e0e09
 	rc = sscanf(current, "%"PRIu32":%"PRIu32":%"PRIu32":%"PRIu64"/%n",
4e0e09
 	            &tosser0, &tosser1, &tosser2, &tosser3, &pos;;
4e0e09
 	debug("current:\"%s\" rc:%d pos:%d\n", current, rc, pos);
4e0e09
+	dbgmk("         ", pos);
4e0e09
 	if (rc != 4)
4e0e09
 	        return -1;
4e0e09
 	current += pos;
4e0e09
diff --git a/src/linux-scsi.c b/src/linux-scsi.c
4e0e09
index 90a85836b1c..96fde7e15fa 100644
4e0e09
--- a/src/linux-scsi.c
4e0e09
+++ b/src/linux-scsi.c
4e0e09
@@ -101,6 +101,7 @@ parse_scsi_link(const char *current, uint32_t *scsi_host,
4e0e09
 	debug("searching for host4/");
4e0e09
 	rc = sscanf(current, "host%d/%n", scsi_host, &pos0);
4e0e09
 	debug("current:\"%s\" rc:%d pos0:%d\n", current+sz, rc, pos0);
4e0e09
+	dbgmk("         ", pos0);
4e0e09
 	if (rc != 1)
4e0e09
 	        return -1;
4e0e09
 	sz += pos0;
4e0e09
@@ -118,6 +119,7 @@ parse_scsi_link(const char *current, uint32_t *scsi_host,
4e0e09
 	rc = sscanf(current+sz, "port-%d:%d%n:%d%n", &tosser0,
4e0e09
 	            &tosser1, &pos0, &tosser2, &pos1);
4e0e09
 	debug("current:\"%s\" rc:%d pos0:%d pos1:%d\n", current+sz, rc, pos0, pos1);
4e0e09
+	dbgmk("         ", pos0, pos1);
4e0e09
 	if (rc == 2 || rc == 3) {
4e0e09
 	        sz += pos0;
4e0e09
 	        pos0 = 0;
4e0e09
@@ -143,6 +145,7 @@ parse_scsi_link(const char *current, uint32_t *scsi_host,
4e0e09
 	        debug("searching for expander-4:0/");
4e0e09
 	        rc = sscanf(current+sz, "expander-%d:%d/%n", &tosser0, &tosser1, &pos0);
4e0e09
 	        debug("current:\"%s\" rc:%d pos0:%d\n", current+sz, rc, pos0);
4e0e09
+		dbgmk("         ", pos0);
4e0e09
 	        if (rc == 2) {
4e0e09
 	                if (!remote_target_id) {
4e0e09
 	                        efi_error("Device is PHY is a remote target, but remote_target_id is NULL");
4e0e09
@@ -158,6 +161,7 @@ parse_scsi_link(const char *current, uint32_t *scsi_host,
4e0e09
 	                debug("searching for port-2:0:2/");
4e0e09
 	                rc = sscanf(current+sz, "port-%d:%d:%d/%n", &tosser0, &tosser1, &tosser2, &pos0);
4e0e09
 	                debug("current:\"%s\" rc:%d pos0:%d\n", current+sz, rc, pos0);
4e0e09
+			dbgmk("         ", pos0);
4e0e09
 	                if (rc != 3) {
4e0e09
 	                        efi_error("Couldn't parse port expander port string");
4e0e09
 	                        return -1;
4e0e09
@@ -182,6 +186,7 @@ parse_scsi_link(const char *current, uint32_t *scsi_host,
4e0e09
 	        rc = sscanf(current + sz + pos0, ":%d%n", &tosser2, &pos1);
4e0e09
 	        if (rc != 0 && rc != 1)
4e0e09
 	                return -1;
4e0e09
+		dbgmk("         ", pos0, pos0+pos1);
4e0e09
 	        if (remote_port_id && rc == 1)
4e0e09
 	                *remote_port_id = tosser2;
4e0e09
 	        if (local_port_id && rc == 0)
4e0e09
@@ -203,6 +208,7 @@ parse_scsi_link(const char *current, uint32_t *scsi_host,
4e0e09
 	rc = sscanf(current + sz, "target%d:%d:%"PRIu64"/%n", &tosser0, &tosser1,
4e0e09
 	            &tosser3, &pos0);
4e0e09
 	debug("current:\"%s\" rc:%d pos0:%d\n", current+sz, rc, pos0);
4e0e09
+	dbgmk("         ", pos0);
4e0e09
 	if (rc != 3)
4e0e09
 	        return -1;
4e0e09
 	sz += pos0;
4e0e09
@@ -215,6 +221,7 @@ parse_scsi_link(const char *current, uint32_t *scsi_host,
4e0e09
 	rc = sscanf(current + sz, "%d:%d:%d:%"PRIu64"/%n",
4e0e09
 	            scsi_bus, scsi_device, scsi_target, scsi_lun, &pos0);
4e0e09
 	debug("current:\"%s\" rc:%d pos0:%d\n", current+sz, rc, pos0);
4e0e09
+	dbgmk("         ", pos0);
4e0e09
 	if (rc != 4)
4e0e09
 	        return -1;
4e0e09
 	sz += pos0;
4e0e09
@@ -242,6 +249,7 @@ parse_scsi(struct device *dev, const char *current, const char *root UNUSED)
4e0e09
 	            &dev->scsi_info.scsi_lun,
4e0e09
 	            &pos;;
4e0e09
 	debug("current:\"%s\" rc:%d pos:%d\n", dev->device, rc, pos);
4e0e09
+	dbgmk("         ", pos);
4e0e09
 	if (rc != 4)
4e0e09
 	        return 0;
4e0e09
 
4e0e09
diff --git a/src/linux-soc-root.c b/src/linux-soc-root.c
4e0e09
index 27633d69c97..c932670ef15 100644
4e0e09
--- a/src/linux-soc-root.c
4e0e09
+++ b/src/linux-soc-root.c
4e0e09
@@ -49,6 +49,8 @@ parse_soc_root(struct device *dev UNUSED, const char *current, const char *root
4e0e09
 	rc = sscanf(devpart, "../../devices/platform/soc/%*[^/]/%n", &pos;;
4e0e09
 	if (rc != 0)
4e0e09
 	        return 0;
4e0e09
+	debug("current:\"%s\" rc:%d pos:%d", current, rc, pos);
4e0e09
+	dbgmk("         ", pos);
4e0e09
 	devpart += pos;
4e0e09
 	debug("new position is \"%s\"", devpart);
4e0e09
 
4e0e09
diff --git a/src/linux-virtblk.c b/src/linux-virtblk.c
4e0e09
index 891c262fe05..7517db55555 100644
4e0e09
--- a/src/linux-virtblk.c
4e0e09
+++ b/src/linux-virtblk.c
4e0e09
@@ -56,6 +56,7 @@ parse_virtblk(struct device *dev, const char *current, const char *root UNUSED)
4e0e09
 	debug("searching for virtio0/");
4e0e09
 	rc = sscanf(current, "virtio%x/%n", &tosser, &pos;;
4e0e09
 	debug("current:\"%s\" rc:%d pos:%d\n", current, rc, pos);
4e0e09
+	dbgmk("         ", pos);
4e0e09
 	/*
4e0e09
 	 * If we couldn't find virtioX/ then it isn't a virtio device.
4e0e09
 	 */
4e0e09
diff --git a/src/util.h b/src/util.h
4e0e09
index 3f68d812700..845989bbfe9 100644
4e0e09
--- a/src/util.h
4e0e09
+++ b/src/util.h
4e0e09
@@ -284,6 +284,40 @@ swizzle_guid_to_uuid(efi_guid_t *guid)
4e0e09
 	u16[1] = __builtin_bswap16(u16[1]);
4e0e09
 }
4e0e09
 
4e0e09
+static inline void UNUSED
4e0e09
+debug_markers_(const char * const file, int line,
4e0e09
+	       const char * const func, int level,
4e0e09
+	       const char * const prefix, ...)
4e0e09
+{
4e0e09
+	FILE *logfile;
4e0e09
+	va_list ap;
4e0e09
+	int pos;
4e0e09
+	int n = 0;
4e0e09
+	bool on = false;
4e0e09
+
4e0e09
+	va_start(ap, prefix);
4e0e09
+	for (n = 0, pos = va_arg(ap, int); pos >= 0; pos = va_arg(ap, int), n++)
4e0e09
+		;
4e0e09
+	va_end(ap);
4e0e09
+	if (n < 2)
4e0e09
+		return;
4e0e09
+	n = 0;
4e0e09
+
4e0e09
+	efi_set_loglevel(level);
4e0e09
+	logfile = efi_get_logfile();
4e0e09
+	fprintf(logfile, "%s:%d %s(): %s", file, line, func, prefix ? prefix : "");
4e0e09
+	va_start(ap, prefix);
4e0e09
+	while ((pos = va_arg(ap, int)) >= 0) {
4e0e09
+		for (; n <= pos; n++) {
4e0e09
+			if (n == pos)
4e0e09
+				on = !on;
4e0e09
+			fprintf(logfile, "%c", on ? '^' : ' ');
4e0e09
+		}
4e0e09
+	}
4e0e09
+	fprintf(logfile, "\n");
4e0e09
+	va_end(ap);
4e0e09
+}
4e0e09
+
4e0e09
 #define log_(file, line, func, level, fmt, args...)			\
4e0e09
 	({								\
4e0e09
 		efi_set_loglevel(level);				\
4e0e09
@@ -312,6 +346,7 @@ swizzle_guid_to_uuid(efi_guid_t *guid)
4e0e09
 	})
4e0e09
 #define log_hex(level, buf, size) log_hex_(__FILE__, __LINE__, __func__, level, buf, size)
4e0e09
 #define debug_hex(buf, size) log_hex(LOG_DEBUG, buf, size)
4e0e09
+#define dbgmk(prefix, args...) debug_markers_(__FILE__, __LINE__, __func__, LOG_DEBUG, prefix, ## args, -1)
4e0e09
 
4e0e09
 #endif /* EFIVAR_UTIL_H */
4e0e09
 
4e0e09
-- 
4e0e09
2.26.2
4e0e09