Skip to content

Commit 206245a

Browse files
committed
cleanup: move optional cleanups to c files
The cleanups helpers for addrinfo and uri depend on features which are not always available, such as network support or fabrics. Thus, these can't be part of the generic cleanup header file. Also there is also only these single users. Move them to the c files which used them. Signed-off-by: Daniel Wagner <[email protected]>
1 parent ba165f1 commit 206245a

4 files changed

Lines changed: 12 additions & 14 deletions

File tree

libnvme/src/nvme/cleanup.h

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,10 @@
33
#define __CLEANUP_H
44

55
#include <dirent.h>
6-
#include <netdb.h>
76
#include <stdio.h>
87
#include <stdlib.h>
98
#include <unistd.h>
109

11-
#include <sys/socket.h>
12-
#include <sys/types.h>
13-
1410
#include "fabrics.h"
1511

1612
#define __cleanup(fn) __attribute__((cleanup(fn)))
@@ -44,14 +40,4 @@ static inline void cleanup_fd(int *fd)
4440
}
4541
#define __cleanup_fd __cleanup(cleanup_fd)
4642

47-
static inline DEFINE_CLEANUP_FUNC(cleanup_addrinfo, struct addrinfo *, freeaddrinfo)
48-
#define __cleanup_addrinfo __cleanup(cleanup_addrinfo)
49-
50-
static inline void free_uri(struct libnvme_fabrics_uri **uri)
51-
{
52-
if (*uri)
53-
libnvmf_free_uri(*uri);
54-
}
55-
#define __cleanup_uri __cleanup(free_uri)
56-
5743
#endif

libnvme/src/nvme/fabrics.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@
4141

4242
const char *nvmf_dev = "/dev/nvme-fabrics";
4343

44+
static inline void free_uri(struct libnvme_fabrics_uri **uri)
45+
{
46+
if (*uri)
47+
libnvmf_free_uri(*uri);
48+
}
49+
#define __cleanup_uri __cleanup(free_uri)
50+
4451
/**
4552
* strchomp() - Strip trailing spaces
4653
* @str: String to strip

libnvme/src/nvme/linux.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <stdlib.h>
1717
#include <string.h>
1818
#include <unistd.h>
19+
#include <netdb.h>
1920

2021
#include <sys/ioctl.h>
2122
#include <sys/param.h>

libnvme/src/nvme/util.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,10 @@ __public const char *libnvme_strerror(int errnum)
453453
}
454454

455455
#ifdef HAVE_NETDB
456+
static inline DEFINE_CLEANUP_FUNC(cleanup_addrinfo, struct addrinfo *,
457+
freeaddrinfo)
458+
#define __cleanup_addrinfo __cleanup(cleanup_addrinfo)
459+
456460
int hostname2traddr(struct libnvme_global_ctx *ctx, const char *traddr,
457461
char **hostname)
458462
{

0 commit comments

Comments
 (0)