From 2e50d2bc46731639b9e37cd4214e5ae058d51532 Mon Sep 17 00:00:00 2001 From: Mike Gerdts Date: Wed, 12 Apr 2023 12:35:31 -0500 Subject: [PATCH] include: add libgen.h to stdinc.h A subsequent patch will need to use dirname(3), declared in libgen.h. Because libgen.h is a POSIX header, the SPDK build requires that it is defined in spdk/stdinc.h, not in the file that needs it. libgen.h also declares basename() which has a conflicting declaration in string.h. A small change is required in bdev_uring_read_sysfs_attr() to accommodate this. Signed-off-by: Mike Gerdts Change-Id: Ib4ded2097881668aabdfd9f1683f933ce418db2e Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/17557 Reviewed-by: Jim Harris Reviewed-by: Ben Walker Tested-by: SPDK CI Jenkins --- include/spdk/stdinc.h | 2 ++ module/bdev/uring/bdev_uring.c | 8 +++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/include/spdk/stdinc.h b/include/spdk/stdinc.h index 866632541..2490dd63d 100644 --- a/include/spdk/stdinc.h +++ b/include/spdk/stdinc.h @@ -1,6 +1,7 @@ /* SPDX-License-Identifier: BSD-3-Clause * Copyright (C) 2017 Intel Corporation. * All rights reserved. + * Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. */ /** \file @@ -39,6 +40,7 @@ extern "C" { #include #include #include +#include #include #include #include diff --git a/module/bdev/uring/bdev_uring.c b/module/bdev/uring/bdev_uring.c index 3512e01b5..c000e7b75 100644 --- a/module/bdev/uring/bdev_uring.c +++ b/module/bdev/uring/bdev_uring.c @@ -307,11 +307,17 @@ bdev_uring_read_sysfs_attr(const char *devname, const char *attr, char *str, int { char *path = NULL; char *device = NULL; + char *name; FILE *file; int ret = 0; - device = basename(devname); + name = strdup(devname); + if (name == NULL) { + return -EINVAL; + } + device = basename(name); path = spdk_sprintf_alloc("/sys/block/%s/%s", device, attr); + free(name); if (!path) { return -EINVAL; }