-
Notifications
You must be signed in to change notification settings - Fork 710
Expand file tree
/
Copy pathlib.h
More file actions
265 lines (242 loc) · 8.99 KB
/
lib.h
File metadata and controls
265 lines (242 loc) · 8.99 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
/* SPDX-License-Identifier: LGPL-2.1-or-later */
/*
* This file is part of libnvme.
* Copyright (c) 2020 Western Digital Corporation or its affiliates.
*
* Authors: Keith Busch <[email protected]>
* Chaitanya Kulkarni <[email protected]>
*/
#pragma once
#include <stdbool.h>
#include <stdio.h>
#include <nvme/lib-compat.h>
#include <nvme/lib-types.h>
enum libnvme_log_level {
LIBNVME_LOG_ERR = 0,
LIBNVME_LOG_WARN = 1,
LIBNVME_LOG_INFO = 2,
LIBNVME_LOG_DEBUG = 3,
};
#define LIBNVME_DEFAULT_LOGLEVEL LIBNVME_LOG_WARN
/**
* libnvme_create_global_ctx() - Initialize global context object
* @fp: File descriptor for logging messages
* @log_level: Logging level to use
*
* Return: Initialized &struct libnvme_global_ctx object
*/
struct libnvme_global_ctx *libnvme_create_global_ctx(FILE *fp, int log_level);
/**
* libnvme_free_global_ctx() - Free global context object
* @ctx: &struct libnvme_global_ctx object
*
* Free an &struct libnvme_global_ctx object and all attached objects
*/
void libnvme_free_global_ctx(struct libnvme_global_ctx *ctx);
/**
* libnvme_set_logging_level() - Set current logging level
* @ctx: struct libnvme_global_ctx object
* @log_level: Logging level to set
* @log_pid: Boolean to enable logging of the PID
* @log_tstamp: Boolean to enable logging of the timestamp
*
* Sets the current logging level for the global context.
*/
void libnvme_set_logging_level(struct libnvme_global_ctx *ctx, int log_level,
bool log_pid, bool log_tstamp);
/**
* libnvme_get_logging_level() - Get current logging level
* @ctx: struct libnvme_global_ctx object
* @log_pid: Pointer to store a current value of logging of
* the PID flag at (optional).
* @log_tstamp: Pointer to store a current value of logging of
* the timestamp flag at (optional).
*
* Retrieves current values of logging variables.
*
* Return: current log level value or LIBNVME_DEFAULT_LOGLEVEL if not initialized.
*/
int libnvme_get_logging_level(struct libnvme_global_ctx *ctx, bool *log_pid,
bool *log_tstamp);
/**
* libnvme_open() - Open an nvme controller or namespace device
* @ctx: struct libnvme_global_ctx object
* @name: The basename of the device to open
* @hdl: Transport handle to return
*
* This will look for the handle in /dev/ and validate the name and filetype
* match linux conventions.
*
* Return: 0 on success or negative error code otherwise
*/
int libnvme_open(struct libnvme_global_ctx *ctx, const char *name,
struct libnvme_transport_handle **hdl);
/**
* libnvme_close() - Close transport handle
* @hdl: Transport handle
*/
void libnvme_close(struct libnvme_transport_handle *hdl);
/**
* libnvme_transport_handle_get_fd - Return file descriptor from
* the transport handle
* @hdl: Transport handle
*
* If the device handle is for a ioctl based device,
* libnvme_transport_handle_get_fd will return a valid file descriptor.
*
* Return: File descriptor for an IOCTL based transport handle,
* otherwise LIBNVME_INVALID_FD.
*/
libnvme_fd_t libnvme_transport_handle_get_fd(struct libnvme_transport_handle *hdl);
/**
* libnvme_transport_handle_get_name - Return name of the device
* transport handle
* @hdl: Transport handle
*
* Return: Device file name, otherwise -1.
*/
const char *libnvme_transport_handle_get_name(
struct libnvme_transport_handle *hdl);
/**
* libnvme_transport_handle_is_ctrl - Check if transport handle is a
* controller device
* @hdl: Transport handle
*
* Return: Return true if transport handle is a controller device,
* otherwise false.
*/
bool libnvme_transport_handle_is_ctrl(struct libnvme_transport_handle *hdl);
/**
* libnvme_transport_handle_is_direct - Check if transport handle is using IOCTL
* interface
* @hdl: Transport handle
*
* Return: Return true if transport handle is using IOCTL interface,
* otherwise false.
*/
bool libnvme_transport_handle_is_direct(struct libnvme_transport_handle *hdl);
/**
* libnvme_transport_handle_is_mi - Check if transport handle is a using MI
* interface
* @hdl: Transport handle
*
* Return: Return true if transport handle is using MI interface,
* otherwise false.
*/
bool libnvme_transport_handle_is_mi(struct libnvme_transport_handle *hdl);
/**
* libnvme_transport_handle_is_ns - Check if transport handle is a
* namespace device
* @hdl: Transport handle
*
* Return: Return true if transport handle is a namespace device,
* otherwise false.
*/
bool libnvme_transport_handle_is_ns(struct libnvme_transport_handle *hdl);
/**
* libnvme_transport_handle_set_submit_entry() - Install a submit-entry callback
* @hdl: Transport handle to configure
* @submit_entry: Callback invoked immediately before a passthrough command is
* submitted. The function receives the command about to be issued
* and may return an opaque pointer representing per-command
* context. This pointer is later passed unmodified to the
* submit-exit callback. Implementations typically use this hook
* for logging, tracing, or allocating per-command state.
*
* Installs a user-defined callback that is invoked at the moment a passthrough
* command enters the NVMe submission path. Passing NULL removes any previously
* installed callback.
*
* Return: None.
*/
void libnvme_transport_handle_set_submit_entry(
struct libnvme_transport_handle *hdl,
void *(*submit_entry)(struct libnvme_transport_handle *hdl,
struct libnvme_passthru_cmd *cmd));
/**
* libnvme_transport_handle_set_submit_exit() - Install a submit-exit callback
* @hdl: Transport handle to configure
* @submit_exit: Callback invoked after a passthrough command completes. The
* function receives the command, the completion status @err
* (0 for success, a negative errno, or an NVMe status value), and
* the @user_data pointer returned earlier by the submit-entry
* callback. Implementations typically use this hook for logging,
* tracing, or freeing per-command state.
*
* Installs a callback that is invoked when a passthrough command leaves the
* NVMe submission path. Passing NULL removes any previously installed callback.
*
* Return: None.
*/
void libnvme_transport_handle_set_submit_exit(
struct libnvme_transport_handle *hdl,
void (*submit_exit)(struct libnvme_transport_handle *hdl,
struct libnvme_passthru_cmd *cmd,
int err, void *user_data));
/**
* libnvme_transport_handle_set_decide_retry() - Install a retry-decision
* callback
* @hdl: Transport handle to configure
* @decide_retry: Callback used to determine whether a passthrough command
* should be retried after an error. The function is called with
* the command that failed and the error code returned by the
* kernel or device. The callback should return true if the
* submission path should retry the command, or false if the
* error is final.
*
* Installs a user-provided callback to control retry behavior for
* passthrough commands issued through @hdl. This allows transports or
* higher-level logic to implement custom retry policies, such as retrying on
* transient conditions like -EAGAIN or device-specific status codes.
*
* Passing NULL clears any previously installed callback and reverts to the
* default behavior (no retries).
*
* Return: None.
*/
void libnvme_transport_handle_set_decide_retry(
struct libnvme_transport_handle *hdl,
bool (*decide_retry)(struct libnvme_transport_handle *hdl,
struct libnvme_passthru_cmd *cmd, int err));
/**
* libnvme_transport_handle_set_timeout() - Set the default command timeout
* @hdl: Transport handle to configure
* @timeout_ms: Timeout in milliseconds. A value of 0 means use the kernel
* default (NVME_DEFAULT_IOCTL_TIMEOUT).
*
* Sets a default timeout that is applied to every passthrough command
* submitted through @hdl when the command's own timeout_ms field is 0.
* Commands that set a non-zero timeout_ms override this default.
*/
void libnvme_transport_handle_set_timeout(struct libnvme_transport_handle *hdl,
__u32 timeout_ms);
/**
* libnvme_set_probe_enabled() - enable/disable the probe for new MI endpoints
* @ctx: &struct libnvme_global_ctx object
* @enabled: whether to probe new endpoints
*
* Controls whether newly-created endpoints are probed for quirks on creation.
* Defaults to enabled, which results in some initial messaging with the
* endpoint to determine model-specific details.
*/
void libnvme_set_probe_enabled(struct libnvme_global_ctx *ctx, bool enabled);
/**
* libnvme_set_dry_run() - Set global dry run state
* @ctx: struct libnvme_global_ctx object
* @enable: Enable/disable dry run state
*
* When dry_run is enabled, any IOCTL commands send via the passthru
* interface won't be executed.
*/
void libnvme_set_dry_run(struct libnvme_global_ctx *ctx, bool enable);
/**
* libnvme_set_ioctl_probing() - Enable/disable 64-bit IOCTL probing
* @ctx: struct libnvme_global_ctx object
* @enable: Enable/disable 64-bit IOCTL probing
*
* When IOCTL probing is enabled, a 64-bit IOCTL command is issued to
* figure out if the passthru interface supports it.
*
* IOCTL probing is enabled per default.
*/
void libnvme_set_ioctl_probing(struct libnvme_global_ctx *ctx, bool enable);