-
Notifications
You must be signed in to change notification settings - Fork 656
/
libnvme-wrap.c
73 lines (62 loc) · 1.87 KB
/
libnvme-wrap.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* This file is part of nvme-cli
*
* Copyright (c) 2022 Daniel Wagner, SUSE
*/
#include <dlfcn.h>
#include <errno.h>
#include <stdlib.h>
#include <libnvme.h>
#include "nvme-print.h"
#define PROTO(args...) args
#define ARGS(args...) args
#define VOID_FN(name, proto, args) \
void __attribute__((weak)) name(proto) \
{ \
void (*fn)(proto); \
fn = dlsym(RTLD_NEXT, #name); \
if (!fn) { \
nvme_show_error("libnvme function " #name " not found");\
exit(EXIT_FAILURE); \
} \
fn(args); \
}
#define FN(name, rtype, proto, args, defret) \
rtype __attribute__((weak)) name(proto) \
{ \
rtype (*fn)(proto); \
fn = dlsym(RTLD_NEXT, #name); \
if (fn) \
return fn(args); \
return defret; \
}
FN(nvme_get_version,
const char *, PROTO(enum nvme_version type),
ARGS(type), "n/a")
VOID_FN(nvme_init_copy_range_f1,
PROTO(struct nvme_copy_range_f1 *copy, __u16 *nlbs,
__u64 *slbas, __u64 *eilbrts, __u32 *elbatms,
__u32 *elbats, __u16 nr),
ARGS(copy, nlbs, slbas, eilbrts, elbatms, elbats, nr))
VOID_FN(nvme_init_copy_range_f2,
PROTO(struct nvme_copy_range_f2 *copy, __u32 *snsids,
__u16 *nlbs, __u64 *slbas, __u16 *sopts, __u32 *eilbrts,
__u32 *elbatms, __u32 *elbats, __u16 nr),
ARGS(copy, snsids, nlbs, slbas, sopts, eilbrts, elbatms, elbats, nr))
VOID_FN(nvme_init_copy_range_f3,
PROTO(struct nvme_copy_range_f3 *copy, __u32 *snsids,
__u16 *nlbs, __u64 *slbas, __u16 *sopts, __u64 *eilbrts,
__u32 *elbatms, __u32 *elbats, __u16 nr),
ARGS(copy, snsids, nlbs, slbas, sopts, eilbrts, elbatms, elbats, nr))
FN(nvme_get_feature_length2,
int,
PROTO(int fid, __u32 cdw11, enum nvme_data_tfr dir,
__u32 *len),
ARGS(fid, cdw11, dir, len),
-EEXIST)
FN(nvme_ctrl_is_persistent,
bool,
PROTO(nvme_ctrl_t c),
ARGS(c),
false)