Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions fabrics.c
Original file line number Diff line number Diff line change
Expand Up @@ -479,8 +479,8 @@ int fabrics_discovery(const char *desc, int argc, char **argv, bool connect)
char *config_file = PATH_NVMF_CONFIG;
char *context = NULL;
nvme_print_flags_t flags;
_cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL;
_cleanup_nvmf_context_ struct libnvmf_context *fctx = NULL;
__cleanup_nvme_global_ctx struct libnvme_global_ctx *ctx = NULL;
__cleanup_nvmf_context struct libnvmf_context *fctx = NULL;
int ret;
struct libnvme_fabrics_config cfg;
struct nvmf_args fa = { .subsysnqn = NVME_DISC_SUBSYS_NAME };
Expand Down Expand Up @@ -587,13 +587,13 @@ int fabrics_discovery(const char *desc, int argc, char **argv, bool connect)

int fabrics_connect(const char *desc, int argc, char **argv)
{
_cleanup_free_ char *hnqn = NULL;
_cleanup_free_ char *hid = NULL;
__cleanup_free char *hnqn = NULL;
__cleanup_free char *hid = NULL;
char *config_file = NULL;
char *context = NULL;
_cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL;
_cleanup_nvmf_context_ struct libnvmf_context *fctx = NULL;
_cleanup_nvme_ctrl_ libnvme_ctrl_t c = NULL;
__cleanup_nvme_global_ctx struct libnvme_global_ctx *ctx = NULL;
__cleanup_nvmf_context struct libnvmf_context *fctx = NULL;
__cleanup_nvme_ctrl libnvme_ctrl_t c = NULL;
int ret;
nvme_print_flags_t flags;
struct libnvme_fabrics_config cfg = { 0 };
Expand Down Expand Up @@ -736,7 +736,7 @@ static void nvmf_disconnect_nqn(struct libnvme_global_ctx *ctx, char *nqn)
int fabrics_disconnect(const char *desc, int argc, char **argv)
{
const char *device = "nvme device handle";
_cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL;
__cleanup_nvme_global_ctx struct libnvme_global_ctx *ctx = NULL;
libnvme_ctrl_t c;
char *p;
int ret;
Expand Down Expand Up @@ -820,7 +820,7 @@ int fabrics_disconnect(const char *desc, int argc, char **argv)

int fabrics_disconnect_all(const char *desc, int argc, char **argv)
{
_cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL;
__cleanup_nvme_global_ctx struct libnvme_global_ctx *ctx = NULL;
libnvme_host_t h;
libnvme_subsystem_t s;
libnvme_ctrl_t c;
Expand Down Expand Up @@ -887,7 +887,7 @@ int fabrics_disconnect_all(const char *desc, int argc, char **argv)
int fabrics_config(const char *desc, int argc, char **argv)
{
bool scan_tree = false, modify_config = false, update_config = false;
_cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL;
__cleanup_nvme_global_ctx struct libnvme_global_ctx *ctx = NULL;
char *config_file = PATH_NVMF_CONFIG;
struct libnvme_fabrics_config cfg;
struct nvmf_args fa = { };
Expand Down Expand Up @@ -931,7 +931,7 @@ int fabrics_config(const char *desc, int argc, char **argv)
}

if (modify_config) {
_cleanup_nvmf_context_ struct libnvmf_context *fctx = NULL;
__cleanup_nvmf_context struct libnvmf_context *fctx = NULL;

if (!fa.subsysnqn) {
fprintf(stderr,
Expand All @@ -958,7 +958,7 @@ int fabrics_config(const char *desc, int argc, char **argv)
}

if (update_config) {
_cleanup_fd_ int fd = -1;
__cleanup_fd int fd = -1;

fd = open(config_file, O_RDONLY, 0);
if (fd != -1)
Expand Down Expand Up @@ -998,7 +998,7 @@ static int dim_operation(libnvme_ctrl_t c, enum nvmf_dim_tas tas, const char *na

int fabrics_dim(const char *desc, int argc, char **argv)
{
_cleanup_nvme_global_ctx_ struct libnvme_global_ctx *ctx = NULL;
__cleanup_nvme_global_ctx struct libnvme_global_ctx *ctx = NULL;
enum nvmf_dim_tas tas;
libnvme_ctrl_t c;
char *p;
Expand Down
14 changes: 7 additions & 7 deletions libnvme/src/nvme/cleanup.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

#include "fabrics.h"

#define __cleanup__(fn) __attribute__((cleanup(fn)))
#define __cleanup(fn) __attribute__((cleanup(fn)))

#define DECLARE_CLEANUP_FUNC(name, type) \
void name(type *__p)
Expand All @@ -29,29 +29,29 @@ static inline void freep(void *p)
{
free(*(void **)p);
}
#define _cleanup_free_ __cleanup__(freep)
#define __cleanup_free __cleanup(freep)

static inline DEFINE_CLEANUP_FUNC(cleanup_file, FILE *, fclose)
#define _cleanup_file_ __cleanup__(cleanup_file)
#define __cleanup_file __cleanup(cleanup_file)

static inline DEFINE_CLEANUP_FUNC(cleanup_dir, DIR *, closedir)
#define _cleanup_dir_ __cleanup__(cleanup_dir)
#define __cleanup_dir __cleanup(cleanup_dir)

static inline void cleanup_fd(int *fd)
{
if (*fd >= 0)
close(*fd);
}
#define _cleanup_fd_ __cleanup__(cleanup_fd)
#define __cleanup_fd __cleanup(cleanup_fd)

static inline DEFINE_CLEANUP_FUNC(cleanup_addrinfo, struct addrinfo *, freeaddrinfo)
#define _cleanup_addrinfo_ __cleanup__(cleanup_addrinfo)
#define __cleanup_addrinfo __cleanup(cleanup_addrinfo)

static inline void free_uri(struct libnvme_fabrics_uri **uri)
{
if (*uri)
libnvmf_free_uri(*uri);
}
#define _cleanup_uri_ __cleanup__(free_uri)
#define __cleanup_uri __cleanup(free_uri)

#endif
10 changes: 5 additions & 5 deletions libnvme/src/nvme/cmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ __public int libnvme_get_uuid_list(struct libnvme_transport_handle *hdl,
__public int libnvme_get_telemetry_max(struct libnvme_transport_handle *hdl,
enum nvme_telemetry_da *da, size_t *data_tx)
{
_cleanup_free_ struct nvme_id_ctrl *id_ctrl = NULL;
__cleanup_free struct nvme_id_ctrl *id_ctrl = NULL;
struct libnvme_passthru_cmd cmd;
int err;

Expand Down Expand Up @@ -354,7 +354,7 @@ __public int libnvme_get_telemetry_log(struct libnvme_transport_handle *hdl, boo
static const __u32 xfer = NVME_LOG_TELEM_BLOCK_SIZE;
struct nvme_telemetry_log *telem;
struct libnvme_passthru_cmd cmd;
_cleanup_free_ void *log = NULL;
__cleanup_free void *log = NULL;
void *tmp;
int err;
size_t dalb;
Expand Down Expand Up @@ -477,7 +477,7 @@ __public int libnvme_get_new_host_telemetry(struct libnvme_transport_handle *hdl
int libnvme_get_lba_status_log(struct libnvme_transport_handle *hdl, bool rae,
struct nvme_lba_status_log **log)
{
_cleanup_free_ struct nvme_lba_status_log *buf = NULL;
__cleanup_free struct nvme_lba_status_log *buf = NULL;
struct libnvme_passthru_cmd cmd;
__u32 size;
void *tmp;
Expand Down Expand Up @@ -532,7 +532,7 @@ __public size_t libnvme_get_ana_log_len_from_id_ctrl(const struct nvme_id_ctrl *

__public int libnvme_get_ana_log_len(struct libnvme_transport_handle *hdl, size_t *analen)
{
_cleanup_free_ struct nvme_id_ctrl *ctrl = NULL;
__cleanup_free struct nvme_id_ctrl *ctrl = NULL;
struct libnvme_passthru_cmd cmd;
int ret;

Expand All @@ -552,7 +552,7 @@ __public int libnvme_get_ana_log_len(struct libnvme_transport_handle *hdl, size_
__public int libnvme_get_logical_block_size(struct libnvme_transport_handle *hdl,
__u32 nsid, int *blksize)
{
_cleanup_free_ struct nvme_id_ns *ns = NULL;
__cleanup_free struct nvme_id_ns *ns = NULL;
struct libnvme_passthru_cmd cmd;
__u8 flbas;
int ret;
Expand Down
42 changes: 21 additions & 21 deletions libnvme/src/nvme/fabrics.c
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,8 @@ __public int libnvmf_context_set_crypto(struct libnvmf_context *fctx,
return 0;

if (!strncmp(tls_key, "pin:", 4)) {
_cleanup_free_ unsigned char *raw_secret = NULL;
_cleanup_free_ char *encoded_key = NULL;
__cleanup_free unsigned char *raw_secret = NULL;
__cleanup_free char *encoded_key = NULL;
int key_len = 32;

err = libnvme_create_raw_secret(fctx->ctx, tls_key,
Expand Down Expand Up @@ -629,7 +629,7 @@ static int inet6_pton(struct libnvme_global_ctx *ctx, const char *src, uint16_t
if (strlen(src) > INET6_ADDRSTRLEN)
return -EINVAL;

_cleanup_free_ char *tmp = strdup(src);
__cleanup_free char *tmp = strdup(src);
if (!tmp) {
libnvme_msg(ctx, LOG_ERR, "cannot copy: %s\n", src);
return -ENOMEM;
Expand Down Expand Up @@ -862,7 +862,7 @@ static int build_options(libnvme_host_t h, libnvme_ctrl_t c, char **argstr)
static int __nvmf_supported_options(struct libnvme_global_ctx *ctx)
{
char buf[0x1000], *options, *p, *v;
_cleanup_fd_ int fd = -1;
__cleanup_fd int fd = -1;
ssize_t len;

if (ctx->options)
Expand Down Expand Up @@ -949,7 +949,7 @@ static int __nvmf_supported_options(struct libnvme_global_ctx *ctx)

static int __nvmf_add_ctrl(struct libnvme_global_ctx *ctx, const char *argstr)
{
_cleanup_fd_ int fd = -1;
__cleanup_fd int fd = -1;
int ret, len = strlen(argstr);
char buf[0x1000], *options, *p;

Expand Down Expand Up @@ -1039,7 +1039,7 @@ __public int libnvmf_add_ctrl(libnvme_host_t h, libnvme_ctrl_t c,
{
libnvme_subsystem_t s;
const char *root_app, *app;
_cleanup_free_ char *argstr = NULL;
__cleanup_free char *argstr = NULL;
int ret;

/* highest prio have configs from command line */
Expand Down Expand Up @@ -1132,7 +1132,7 @@ __public int libnvmf_add_ctrl(libnvme_host_t h, libnvme_ctrl_t c,

__public int libnvmf_connect_ctrl(libnvme_ctrl_t c)
{
_cleanup_free_ char *argstr = NULL;
__cleanup_free char *argstr = NULL;
int ret;

ret = build_options(c->s->h, c, &argstr);
Expand Down Expand Up @@ -1578,7 +1578,7 @@ static int nvmf_dim(libnvme_ctrl_t c, enum nvmf_dim_tas tas, __u8 trtype,
__u32 *result)
{
struct libnvme_global_ctx *ctx = c->s && c->s->h ? c->s->h->ctx : NULL;
_cleanup_free_ struct nvmf_dim_data *dim = NULL;
__cleanup_free struct nvmf_dim_data *dim = NULL;
struct libnvme_transport_handle *hdl = libnvme_ctrl_get_transport_handle(c);
struct libnvme_passthru_cmd cmd;
struct nvmf_ext_die *die;
Expand Down Expand Up @@ -1709,7 +1709,7 @@ static const char *dctype_str[] = {
*/
static int nvme_fetch_cntrltype_dctype_from_id(libnvme_ctrl_t c)
{
_cleanup_free_ struct nvme_id_ctrl *id = NULL;
__cleanup_free struct nvme_id_ctrl *id = NULL;
int ret;

id = __libnvme_alloc(sizeof(*id));
Expand Down Expand Up @@ -1789,10 +1789,10 @@ static char *unescape_uri(const char *str, int len)
__public int libnvme_parse_uri(const char *str, struct libnvme_fabrics_uri **urip)
{
struct libnvme_fabrics_uri *uri;
_cleanup_free_ char *scheme = NULL;
_cleanup_free_ char *authority = NULL;
_cleanup_free_ char *path = NULL;
_cleanup_free_ char *h = NULL;
__cleanup_free char *scheme = NULL;
__cleanup_free char *authority = NULL;
__cleanup_free char *path = NULL;
__cleanup_free char *h = NULL;
const char *host;
int i;

Expand Down Expand Up @@ -1918,8 +1918,8 @@ static libnvme_ctrl_t lookup_ctrl(libnvme_host_t h, struct libnvmf_context *fctx
static int lookup_host(struct libnvme_global_ctx *ctx,
struct libnvmf_context *fctx, struct libnvme_host **host)
{
_cleanup_free_ char *hnqn = NULL;
_cleanup_free_ char *hid = NULL;
__cleanup_free char *hnqn = NULL;
__cleanup_free char *hid = NULL;
struct libnvme_host *h;
int err;

Expand Down Expand Up @@ -1998,7 +1998,7 @@ static int _nvmf_discovery(struct libnvme_global_ctx *ctx,
struct libnvmf_context *fctx, bool connect,
struct libnvme_ctrl *c)
{
_cleanup_free_ struct nvmf_discovery_log *log = NULL;
__cleanup_free struct nvmf_discovery_log *log = NULL;
libnvme_subsystem_t s = libnvme_ctrl_get_subsystem(c);
libnvme_host_t h = libnvme_subsystem_get_host(s);
uint64_t numrec;
Expand Down Expand Up @@ -2188,7 +2188,7 @@ static int nvmf_create_discovery_ctrl(struct libnvme_global_ctx *ctx,
struct libnvme_fabrics_config *cfg,
struct libnvme_ctrl **ctrl)
{
_cleanup_free_ struct nvme_id_ctrl *id = NULL;
__cleanup_free struct nvme_id_ctrl *id = NULL;
struct libnvme_ctrl *c;
int ret;

Expand Down Expand Up @@ -2487,8 +2487,8 @@ __public int libnvmf_discovery_config_file(struct libnvme_global_ctx *ctx,
__public int libnvmf_config_modify(struct libnvme_global_ctx *ctx,
struct libnvmf_context *fctx)
{
_cleanup_free_ char *hnqn = NULL;
_cleanup_free_ char *hid = NULL;
__cleanup_free char *hnqn = NULL;
__cleanup_free char *hid = NULL;
struct libnvme_host *h;
struct libnvme_subsystem *s;
struct libnvme_ctrl *c;
Expand Down Expand Up @@ -2895,8 +2895,8 @@ __public int libnvmf_discovery_nbft(struct libnvme_global_ctx *ctx,

/* Discovery Descriptor List */
for (dd = entry->nbft->discovery_list; dd && *dd; dd++) {
_cleanup_uri_ struct libnvme_fabrics_uri *uri = NULL;
_cleanup_free_ char *trsvcid = NULL;
__cleanup_uri struct libnvme_fabrics_uri *uri = NULL;
__cleanup_free char *trsvcid = NULL;
struct libnvmf_context nfctx = *fctx;
bool persistent = false;
bool linked = false;
Expand Down
6 changes: 3 additions & 3 deletions libnvme/src/nvme/json.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,16 +191,16 @@ static void json_parse_host(struct libnvme_global_ctx *ctx, struct json_object *
}

static DEFINE_CLEANUP_FUNC(cleanup_tokener, json_tokener *, json_tokener_free)
#define _cleanup_tokener_ __cleanup__(cleanup_tokener)
#define __cleanup_tokener __cleanup(cleanup_tokener)

static struct json_object *parse_json(struct libnvme_global_ctx *ctx, int fd)
{
char buf[JSON_FILE_BUF_SIZE];
struct json_object *obj;
char *str = NULL;
_cleanup_tokener_ json_tokener *tok = NULL;
__cleanup_tokener json_tokener *tok = NULL;
int ret;
_cleanup_free_ void *ptr = NULL;
__cleanup_free void *ptr = NULL;
int len = 0;

while ((ret = read(fd, buf, JSON_FILE_BUF_SIZE)) > 0) {
Expand Down
2 changes: 1 addition & 1 deletion libnvme/src/nvme/lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ static int __nvme_transport_handle_open_direct(
struct libnvme_transport_handle *hdl, const char *devname)
{
struct libnvme_passthru_cmd dummy = { 0 };
_cleanup_free_ char *path = NULL;
__cleanup_free char *path = NULL;
char *name;
int ret, id, ns;
bool c = true;
Expand Down
Loading
Loading