efivar/SOURCES/0052-sysfs-parsing-add-some...

315 lines
12 KiB
Diff

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