From: Yang Ming <mosesyyoung@gmail.com>
To: dev@dpdk.org
Subject: [PATCH v3 2/2] net/mlx5: improve debug dump file path handling
Date: Fri, 29 Aug 2025 22:49:53 +0800 [thread overview]
Message-ID: <20250829144954.2576-2-mosesyyoung@gmail.com> (raw)
In-Reply-To: <20250829144954.2576-1-mosesyyoung@gmail.com>
The current implementation always tries to open debug dump files
under /var/log, which may not be writable in containerized or
restricted environments (e.g. when the filesystem is mounted as
read-only).
This patch introduces an OS-specific helper function
mlx5_os_debug_dump_file_open() to unify the logic:
* On Linux:
1. Try /var/log if it is writable (kept for backward
compatibility).
2. Fallback to the DPDK runtime directory.
3. Finally, use the current working directory.
* On Windows:
1. Use the DPDK runtime directory.
2. Fallback to the current working directory.
This preserves the previous directory preference while ensuring
debug dumps can still be written in restricted environments such
as containers. The structure of the open logic is kept unchanged
so that test cases and expected logs remain valid.
Signed-off-by: Yang Ming <mosesyyoung@gmail.com>
---
drivers/net/mlx5/linux/mlx5_os.c | 44 ++++++++++++++++++++++++++++++
drivers/net/mlx5/mlx5.h | 1 +
drivers/net/mlx5/mlx5_rxtx.c | 16 ++---------
drivers/net/mlx5/windows/mlx5_os.c | 30 ++++++++++++++++++++
4 files changed, 78 insertions(+), 13 deletions(-)
diff --git a/drivers/net/mlx5/linux/mlx5_os.c b/drivers/net/mlx5/linux/mlx5_os.c
index 696a3e12c7..fdb2102cd5 100644
--- a/drivers/net/mlx5/linux/mlx5_os.c
+++ b/drivers/net/mlx5/linux/mlx5_os.c
@@ -3020,6 +3020,50 @@ mlx5_os_net_cleanup(void)
mlx5_pmd_socket_uninit();
}
+/* Default system log directory on Linux. */
+#define MLX5_SYSTEM_LOG_DIR "/var/log"
+
+/*
+ * Open a debug dump file on Linux.
+ *
+ * The function attempts to create/open the file in the following order:
+ * 1. /var/log (if writable),
+ * 2. EAL runtime directory,
+ * 3. current working directory ("./").
+ */
+FILE *
+mlx5_os_debug_dump_file_open(const char *fname)
+{
+ FILE *fd = NULL;
+
+ if (access(MLX5_SYSTEM_LOG_DIR, W_OK) == 0) {
+ MKSTR(path, "%s/%s", MLX5_SYSTEM_LOG_DIR, fname);
+ fd = fopen(path, "a+");
+ if (fd) {
+ DRV_LOG(INFO, "New debug dump in file %s", path);
+ return fd;
+ }
+ DRV_LOG(WARNING, "cannot open %s for debug dump", path);
+ }
+
+ MKSTR(path2, "%s/%s", rte_eal_get_runtime_dir(), fname);
+ fd = fopen(path2, "a+");
+ if (fd) {
+ DRV_LOG(INFO, "New debug dump in file %s", path2);
+ return fd;
+ }
+ DRV_LOG(WARNING, "cannot open %s for debug dump", path2);
+
+ MKSTR(path3, "./%s", fname);
+ fd = fopen(path3, "a+");
+ if (fd)
+ DRV_LOG(INFO, "New debug dump in file %s", path3);
+ else
+ DRV_LOG(ERR, "cannot open %s for debug dump", path3);
+
+ return fd;
+}
+
/**
* Install shared asynchronous device events handler.
* This function is implemented to support event sharing
diff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h
index c08894cd03..fc7ac08039 100644
--- a/drivers/net/mlx5/mlx5.h
+++ b/drivers/net/mlx5/mlx5.h
@@ -2597,6 +2597,7 @@ int mlx5_os_capabilities_prepare(struct mlx5_dev_ctx_shared *sh);
void mlx5_os_free_shared_dr(struct mlx5_priv *priv);
int mlx5_os_net_probe(struct mlx5_common_device *cdev,
struct mlx5_kvargs_ctrl *mkvlist);
+FILE *mlx5_os_debug_dump_file_open(const char *name);
void mlx5_os_dev_shared_handler_install(struct mlx5_dev_ctx_shared *sh);
void mlx5_os_dev_shared_handler_uninstall(struct mlx5_dev_ctx_shared *sh);
void mlx5_os_mac_addr_remove(struct rte_eth_dev *dev, uint32_t index);
diff --git a/drivers/net/mlx5/mlx5_rxtx.c b/drivers/net/mlx5/mlx5_rxtx.c
index 82c5481ad7..b35365ffd3 100644
--- a/drivers/net/mlx5/mlx5_rxtx.c
+++ b/drivers/net/mlx5/mlx5_rxtx.c
@@ -391,7 +391,6 @@ mlx5_set_swp_types_table(void)
}
}
-#define MLX5_SYSTEM_LOG_DIR "/var/log"
/**
* Dump debug information to log file.
*
@@ -411,20 +410,11 @@ mlx5_dump_debug_information(const char *fname, const char *hex_title,
{
FILE *fd;
- MKSTR(path, "%s/%s", MLX5_SYSTEM_LOG_DIR, fname);
- fd = fopen(path, "a+");
+ fd = mlx5_os_debug_dump_file_open(fname);
if (!fd) {
- DRV_LOG(WARNING, "cannot open %s for debug dump", path);
- MKSTR(path2, "./%s", fname);
- fd = fopen(path2, "a+");
- if (!fd) {
- DRV_LOG(ERR, "cannot open %s for debug dump", path2);
- return;
- }
- DRV_LOG(INFO, "New debug dump in file %s", path2);
- } else {
- DRV_LOG(INFO, "New debug dump in file %s", path);
+ return;
}
+
if (hex_title)
rte_hexdump(fd, hex_title, buf, hex_len);
else
diff --git a/drivers/net/mlx5/windows/mlx5_os.c b/drivers/net/mlx5/windows/mlx5_os.c
index d583730066..734b71e3f7 100644
--- a/drivers/net/mlx5/windows/mlx5_os.c
+++ b/drivers/net/mlx5/windows/mlx5_os.c
@@ -629,6 +629,36 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev,
return NULL;
}
+/*
+ * Open a debug dump file on Windows.
+ *
+ * The function attempts to create/open the file in the following order:
+ * 1. EAL runtime directory,
+ * 2. current working directory ("./").
+ */
+FILE *
+mlx5_os_debug_dump_file_open(const char *fname)
+{
+ FILE *fd = NULL;
+
+ MKSTR(path, "%s/%s", rte_eal_get_runtime_dir(), fname);
+ fd = fopen(path, "a+");
+ if (fd) {
+ DRV_LOG(INFO, "New debug dump in file %s", path);
+ return fd;
+ }
+ DRV_LOG(WARNING, "cannot open %s for debug dump", path);
+
+ MKSTR(path2, "./%s", fname);
+ fd = fopen(path2, "a+");
+ if (fd)
+ DRV_LOG(INFO, "New debug dump in file %s", path2);
+ else
+ DRV_LOG(ERR, "cannot open %s for debug dump", path2);
+
+ return fd;
+}
+
/**
* This function should share events between multiple ports of single IB
* device. Currently it has no support under Windows.
--
2.49.0.windows.1
next prev parent reply other threads:[~2025-08-29 14:50 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-13 9:24 [PATCH 1/2] net/mlx5: improve socket file path Yang Ming
2024-12-13 9:24 ` [PATCH 2/2] net/mlx5: improve log " Yang Ming
2025-03-04 6:23 ` Bing Zhao
2025-03-05 3:20 ` Yang Ming
2025-03-10 14:59 ` Stephen Hemminger
2025-03-12 2:32 ` [External] " Yang Ming
2025-03-17 16:05 ` Bing Zhao
2025-03-21 9:48 ` Ming 1. Yang (NSB)
2024-12-13 17:12 ` [PATCH 1/2] net/mlx5: improve socket " Stephen Hemminger
2024-12-13 17:16 ` Bruce Richardson
2025-01-03 2:51 ` Yang Ming
2025-03-12 2:55 ` Yang Ming
2025-03-14 11:48 ` Dariusz Sosnowski
2025-03-21 13:27 ` [PATCH v2 1/2] net/mlx5: enhance " Yang Ming
2025-03-21 13:27 ` [PATCH v2 2/2] net/mlx5: enhance log " Yang Ming
2025-04-10 7:53 ` Yang Ming
2025-05-12 10:12 ` Moses Young
2025-06-04 6:54 ` Maayan Kashani
2025-06-26 13:06 ` Dariusz Sosnowski
2025-07-20 8:57 ` Moses Young
2025-06-26 12:48 ` [PATCH v2 1/2] net/mlx5: enhance socket " Dariusz Sosnowski
2025-08-29 14:49 ` [PATCH v3 1/2] net/mlx5: improve socket file path handling Yang Ming
2025-08-29 14:49 ` Yang Ming [this message]
2025-08-29 19:57 ` Stephen Hemminger
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250829144954.2576-2-mosesyyoung@gmail.com \
--to=mosesyyoung@gmail.com \
--cc=dev@dpdk.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).