[v2,2/2] net/mlx5: enhance log file path

Message ID 20250321132750.4237-2-ming.1.yang@nokia-sbell.com (mailing list archive)
State New
Delegated to: Raslan Darawsheh
Headers
Series [v2,1/2] net/mlx5: enhance socket file path |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/intel-Functional success Functional PASS
ci/github-robot: build success github build: passed
ci/iol-abi-testing success Testing PASS
ci/iol-compile-amd64-testing warning Testing issues
ci/iol-sample-apps-testing success Testing PASS
ci/iol-unit-arm64-testing success Testing PASS
ci/iol-compile-arm64-testing success Testing PASS
ci/iol-mellanox-Functional success Functional Testing PASS
ci/iol-unit-amd64-testing fail Testing issues

Commit Message

Yang Ming March 21, 2025, 1:27 p.m. UTC
The directory /var/log may not be writable in a container's
read-only mode. To address this issue, use the DPDK runtime
directory as an alternative when /var/log is not writable.

Cc: bingz@nvidia.com
Cc: dsosnowski@nvidia.com
Cc: stephen@networkplumber.org
Cc: julien.meunier@nokia.com

Signed-off-by: Yang Ming <ming.1.yang@nokia-sbell.com>
---
 drivers/net/mlx5/mlx5_rxtx.c | 33 ++++++++++++++++++++++++---------
 1 file changed, 24 insertions(+), 9 deletions(-)
  

Comments

Yang Ming April 10, 2025, 7:53 a.m. UTC | #1
On 2025/3/21 21:27, Yang Ming wrote:
> The directory /var/log may not be writable in a container's
> read-only mode. To address this issue, use the DPDK runtime
> directory as an alternative when /var/log is not writable.
>
> Cc: bingz@nvidia.com
> Cc: dsosnowski@nvidia.com
> Cc: stephen@networkplumber.org
> Cc: julien.meunier@nokia.com
>
> Signed-off-by: Yang Ming <ming.1.yang@nokia-sbell.com>
> ---
>   drivers/net/mlx5/mlx5_rxtx.c | 33 ++++++++++++++++++++++++---------
>   1 file changed, 24 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/net/mlx5/mlx5_rxtx.c b/drivers/net/mlx5/mlx5_rxtx.c
> index 9c075f6a56..9e63d38524 100644
> --- a/drivers/net/mlx5/mlx5_rxtx.c
> +++ b/drivers/net/mlx5/mlx5_rxtx.c
> @@ -6,12 +6,14 @@
>   #include <stdint.h>
>   #include <string.h>
>   #include <stdlib.h>
> +#include <unistd.h>
>   
>   #include <rte_mbuf.h>
>   #include <rte_mempool.h>
>   #include <rte_prefetch.h>
>   #include <rte_common.h>
>   #include <rte_branch_prediction.h>
> +#include <rte_eal.h>
>   #include <rte_ether.h>
>   #include <rte_cycles.h>
>   #include <rte_flow.h>
> @@ -411,20 +413,33 @@ 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+");
> -	if (!fd) {
> -		DRV_LOG(WARNING, "cannot open %s for debug dump", path);
> -		MKSTR(path2, "./%s", fname);
> +	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(WARNING, "cannot open %s for debug dump", path);
> +		else
> +			DRV_LOG(INFO, "New debug dump in file %s", path);
> +	} else {
> +		MKSTR(path2, "%s/%s", rte_eal_get_runtime_dir(), fname);
>   		fd = fopen(path2, "a+");
> +		if (!fd)
> +			DRV_LOG(WARNING, "cannot open %s for debug dump", path2);
> +		else
> +			DRV_LOG(INFO, "New debug dump in file %s", path2);
> +	}
> +
> +	if (!fd) {
> +		MKSTR(path3, "./%s", fname);
> +		fd = fopen(path3, "a+");
>   		if (!fd) {
> -			DRV_LOG(ERR, "cannot open %s for debug dump", path2);
> +			DRV_LOG(ERR, "cannot open %s for debug dump", path3);
>   			return;
> +		} else {
> +			DRV_LOG(INFO, "New debug dump in file %s", path3);
>   		}
> -		DRV_LOG(INFO, "New debug dump in file %s", path2);
> -	} else {
> -		DRV_LOG(INFO, "New debug dump in file %s", path);
>   	}
> +
>   	if (hex_title)
>   		rte_hexdump(fd, hex_title, buf, hex_len);
>   	else
Hi Experts,

is there any chance to review and accept this patch?

Brs,

Yang Ming
  

Patch

diff --git a/drivers/net/mlx5/mlx5_rxtx.c b/drivers/net/mlx5/mlx5_rxtx.c
index 9c075f6a56..9e63d38524 100644
--- a/drivers/net/mlx5/mlx5_rxtx.c
+++ b/drivers/net/mlx5/mlx5_rxtx.c
@@ -6,12 +6,14 @@ 
 #include <stdint.h>
 #include <string.h>
 #include <stdlib.h>
+#include <unistd.h>
 
 #include <rte_mbuf.h>
 #include <rte_mempool.h>
 #include <rte_prefetch.h>
 #include <rte_common.h>
 #include <rte_branch_prediction.h>
+#include <rte_eal.h>
 #include <rte_ether.h>
 #include <rte_cycles.h>
 #include <rte_flow.h>
@@ -411,20 +413,33 @@  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+");
-	if (!fd) {
-		DRV_LOG(WARNING, "cannot open %s for debug dump", path);
-		MKSTR(path2, "./%s", fname);
+	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(WARNING, "cannot open %s for debug dump", path);
+		else
+			DRV_LOG(INFO, "New debug dump in file %s", path);
+	} else {
+		MKSTR(path2, "%s/%s", rte_eal_get_runtime_dir(), fname);
 		fd = fopen(path2, "a+");
+		if (!fd)
+			DRV_LOG(WARNING, "cannot open %s for debug dump", path2);
+		else
+			DRV_LOG(INFO, "New debug dump in file %s", path2);
+	}
+
+	if (!fd) {
+		MKSTR(path3, "./%s", fname);
+		fd = fopen(path3, "a+");
 		if (!fd) {
-			DRV_LOG(ERR, "cannot open %s for debug dump", path2);
+			DRV_LOG(ERR, "cannot open %s for debug dump", path3);
 			return;
+		} else {
+			DRV_LOG(INFO, "New debug dump in file %s", path3);
 		}
-		DRV_LOG(INFO, "New debug dump in file %s", path2);
-	} else {
-		DRV_LOG(INFO, "New debug dump in file %s", path);
 	}
+
 	if (hex_title)
 		rte_hexdump(fd, hex_title, buf, hex_len);
 	else