Line data Source code
1 47 : GQuark bd_nvme_error_quark (void) {
2 47 : return g_quark_from_static_string ("g-bd-nvme-error-quark");
3 : }
4 :
5 : /**
6 : * BDNVMEControllerInfo:
7 : * @pci_vendor_id: The PCI Vendor ID.
8 : * @pci_subsys_vendor_id: The PCI Subsystem Vendor ID.
9 : * @ctrl_id: Controller ID, the NVM subsystem unique controller identifier associated with the controller.
10 : * @fguid: FRU GUID, a 128-bit value that is globally unique for a given Field Replaceable Unit.
11 : * @model_number: The model number.
12 : * @serial_number: The serial number.
13 : * @firmware_ver: The currently active firmware revision.
14 : * @nvme_ver: The NVM Express base specification that the controller implementation supports or %NULL when not reported by the device.
15 : * @features: features and capabilities present for this controller, see #BDNVMEControllerFeature.
16 : * @controller_type: The controller type.
17 : * @selftest_ext_time: Extended Device Self-test Time, if #BD_NVME_CTRL_FEAT_SELFTEST is supported then this field
18 : * indicates the nominal amount of time in one minute units that the controller takes
19 : * to complete an extended device self-test operation when in power state 0.
20 : * @hmb_pref_size: Host Memory Buffer Preferred Size indicates the preferred size that the host
21 : * is requested to allocate for the Host Memory Buffer feature in bytes.
22 : * @hmb_min_size: Host Memory Buffer Minimum Size indicates the minimum size that the host
23 : * is requested to allocate for the Host Memory Buffer feature in bytes.
24 : * @size_total: Total NVM Capacity in the NVM subsystem in bytes.
25 : * @size_unalloc: Unallocated NVM Capacity in the NVM subsystem in bytes.
26 : * @num_namespaces: Maximum Number of Allowed Namespaces supported by the NVM subsystem.
27 : * @subsysnqn: NVM Subsystem NVMe Qualified Name, UTF-8 null terminated string.
28 : */
29 : /**
30 : * bd_nvme_controller_info_free: (skip)
31 : * @info: (nullable): %BDNVMEControllerInfo to free
32 : *
33 : * Frees @info.
34 : */
35 2 : void bd_nvme_controller_info_free (BDNVMEControllerInfo *info) {
36 2 : if (info == NULL)
37 0 : return;
38 :
39 2 : g_free (info->fguid);
40 2 : g_free (info->subsysnqn);
41 2 : g_free (info->model_number);
42 2 : g_free (info->serial_number);
43 2 : g_free (info->firmware_ver);
44 2 : g_free (info->nvme_ver);
45 2 : g_free (info);
46 : }
47 :
48 : /**
49 : * bd_nvme_controller_info_copy: (skip)
50 : * @info: (nullable): %BDNVMEControllerInfo to copy
51 : *
52 : * Creates a new copy of @info.
53 : */
54 0 : BDNVMEControllerInfo * bd_nvme_controller_info_copy (BDNVMEControllerInfo *info) {
55 : BDNVMEControllerInfo *new_info;
56 :
57 0 : if (info == NULL)
58 0 : return NULL;
59 :
60 0 : new_info = g_new0 (BDNVMEControllerInfo, 1);
61 0 : memcpy (new_info, info, sizeof (BDNVMEControllerInfo));
62 0 : new_info->fguid = g_strdup (info->fguid);
63 0 : new_info->subsysnqn = g_strdup (info->subsysnqn);
64 0 : new_info->model_number = g_strdup (info->model_number);
65 0 : new_info->serial_number = g_strdup (info->serial_number);
66 0 : new_info->firmware_ver = g_strdup (info->firmware_ver);
67 0 : new_info->nvme_ver = g_strdup (info->nvme_ver);
68 :
69 0 : return new_info;
70 : }
71 :
72 71 : GType bd_nvme_controller_info_get_type () {
73 : static GType type = 0;
74 :
75 71 : if (G_UNLIKELY (type == 0)) {
76 1 : type = g_boxed_type_register_static ("BDNVMEControllerInfo",
77 : (GBoxedCopyFunc) bd_nvme_controller_info_copy,
78 : (GBoxedFreeFunc) bd_nvme_controller_info_free);
79 : }
80 71 : return type;
81 : }
82 :
83 : /**
84 : * BDNVMELBAFormat:
85 : * Namespace LBA Format Data Structure.
86 : * @data_size: LBA data size (i.e. a sector size) in bytes.
87 : * @metadata_size: metadata size in bytes or `0` in case of no metadata support.
88 : * @relative_performance: Relative Performance index, see #BDNVMELBAFormatRelativePerformance.
89 : */
90 : /**
91 : * bd_nvme_lba_format_free: (skip)
92 : * @fmt: (nullable): %BDNVMELBAFormat to free
93 : *
94 : * Frees @fmt.
95 : */
96 5 : void bd_nvme_lba_format_free (BDNVMELBAFormat *fmt) {
97 5 : g_free (fmt);
98 5 : }
99 :
100 : /**
101 : * bd_nvme_lba_format_copy: (skip)
102 : * @fmt: (nullable): %BDNVMELBAFormat to copy
103 : *
104 : * Creates a new copy of @fmt.
105 : */
106 4 : BDNVMELBAFormat * bd_nvme_lba_format_copy (BDNVMELBAFormat *fmt) {
107 : BDNVMELBAFormat *new_fmt;
108 :
109 4 : if (fmt == NULL)
110 0 : return NULL;
111 :
112 4 : new_fmt = g_new0 (BDNVMELBAFormat, 1);
113 4 : new_fmt->data_size = fmt->data_size;
114 4 : new_fmt->metadata_size = fmt->metadata_size;
115 4 : new_fmt->relative_performance = fmt->relative_performance;
116 :
117 4 : return new_fmt;
118 : }
119 :
120 9 : GType bd_nvme_lba_format_get_type () {
121 : static GType type = 0;
122 :
123 9 : if (G_UNLIKELY (type == 0)) {
124 1 : type = g_boxed_type_register_static ("BDNVMELBAFormat",
125 : (GBoxedCopyFunc) bd_nvme_lba_format_copy,
126 : (GBoxedFreeFunc) bd_nvme_lba_format_free);
127 : }
128 9 : return type;
129 : }
130 :
131 : /**
132 : * BDNVMENamespaceInfo:
133 : * @nsid: The Namespace Identifier (NSID).
134 : * @eui64: IEEE Extended Unique Identifier: a 64-bit IEEE Extended Unique Identifier (EUI-64)
135 : * that is globally unique and assigned to the namespace when the namespace is created.
136 : * Remains fixed throughout the life of the namespace and is preserved across namespace
137 : * and controller operations.
138 : * @nguid: Namespace Globally Unique Identifier: a 128-bit value that is globally unique and
139 : * assigned to the namespace when the namespace is created. Remains fixed throughout
140 : * the life of the namespace and is preserved across namespace and controller operations.
141 : * @uuid: Namespace 128-bit Universally Unique Identifier (UUID) as specified in RFC 4122.
142 : * @nsize: Namespace Size: total size of the namespace in logical blocks. The number of logical blocks
143 : * is based on the formatted LBA size (see @current_lba_format).
144 : * @ncap: Namespace Capacity: maximum number of logical blocks that may be allocated in the namespace
145 : * at any point in time. The number of logical blocks is based on the formatted LBA size (see @current_lba_format).
146 : * @nuse: Namespace Utilization: current number of logical blocks allocated in the namespace.
147 : * This field is smaller than or equal to the Namespace Capacity. The number of logical
148 : * blocks is based on the formatted LBA size (see @current_lba_format).
149 : * @features: features and capabilities present for this namespace, see #BDNVMENamespaceFeature.
150 : * @format_progress_remaining: The percentage value remaining of a format operation in progress.
151 : * @write_protected: %TRUE if the namespace is currently write protected and all write access to the namespace shall fail.
152 : * @lba_formats: (array zero-terminated=1): A list of supported LBA Formats.
153 : * @current_lba_format: A LBA Format currently used for the namespace. Contains zeroes in case of
154 : * an invalid or no supported LBA Format reported.
155 : */
156 : /**
157 : * bd_nvme_namespace_info_free: (skip)
158 : * @info: (nullable): %BDNVMENamespaceInfo to free
159 : *
160 : * Frees @info.
161 : */
162 1 : void bd_nvme_namespace_info_free (BDNVMENamespaceInfo *info) {
163 : BDNVMELBAFormat **lba_formats;
164 :
165 1 : if (info == NULL)
166 0 : return;
167 :
168 1 : g_free (info->eui64);
169 1 : g_free (info->uuid);
170 1 : g_free (info->nguid);
171 :
172 2 : for (lba_formats = info->lba_formats; lba_formats && *lba_formats; lba_formats++)
173 1 : bd_nvme_lba_format_free (*lba_formats);
174 1 : g_free (info->lba_formats);
175 1 : g_free (info);
176 : }
177 :
178 : /**
179 : * bd_nvme_namespace_info_copy: (skip)
180 : * @info: (nullable): %BDNVMENamespaceInfo to copy
181 : *
182 : * Creates a new copy of @info.
183 : */
184 0 : BDNVMENamespaceInfo * bd_nvme_namespace_info_copy (BDNVMENamespaceInfo *info) {
185 : BDNVMENamespaceInfo *new_info;
186 : BDNVMELBAFormat **lba_formats;
187 : GPtrArray *ptr_array;
188 :
189 0 : if (info == NULL)
190 0 : return NULL;
191 :
192 0 : new_info = g_new0 (BDNVMENamespaceInfo, 1);
193 0 : memcpy (new_info, info, sizeof (BDNVMENamespaceInfo));
194 0 : new_info->eui64 = g_strdup (info->eui64);
195 0 : new_info->uuid = g_strdup (info->uuid);
196 0 : new_info->nguid = g_strdup (info->nguid);
197 :
198 0 : ptr_array = g_ptr_array_new ();
199 0 : for (lba_formats = info->lba_formats; lba_formats && *lba_formats; lba_formats++)
200 0 : g_ptr_array_add (ptr_array, bd_nvme_lba_format_copy (*lba_formats));
201 0 : g_ptr_array_add (ptr_array, NULL);
202 0 : new_info->lba_formats = (BDNVMELBAFormat **) g_ptr_array_free (ptr_array, FALSE);
203 :
204 0 : return new_info;
205 : }
206 :
207 20 : GType bd_nvme_namespace_info_get_type () {
208 : static GType type = 0;
209 :
210 20 : if (G_UNLIKELY (type == 0)) {
211 1 : type = g_boxed_type_register_static ("BDNVMENamespaceInfo",
212 : (GBoxedCopyFunc) bd_nvme_namespace_info_copy,
213 : (GBoxedFreeFunc) bd_nvme_namespace_info_free);
214 : }
215 20 : return type;
216 : }
217 :
218 : /**
219 : * BDNVMESmartLog:
220 : * @critical_warning: critical warnings for the state of the controller, see #BDNVMESmartCriticalWarning.
221 : * @avail_spare: Available Spare: a normalized percentage (0% to 100%) of the remaining spare capacity available.
222 : * @spare_thresh: Available Spare Threshold: a normalized percentage (0% to 100%) of the available spare threshold.
223 : * @percent_used: Percentage Used: a vendor specific estimate of the percentage drive life used based on the
224 : * actual usage and the manufacturer's prediction. A value of 100 indicates that the estimated
225 : * endurance has been consumed, but may not indicate an NVM subsystem failure.
226 : * The value is allowed to exceed 100.
227 : * @total_data_read: An estimated calculation of total data read in bytes based on calculation of data
228 : * units read from the host. A value of 0 indicates that the number of Data Units Read
229 : * is not reported.
230 : * @total_data_written: An estimated calculation of total data written in bytes based on calculation
231 : * of data units written by the host. A value of 0 indicates that the number
232 : * of Data Units Written is not reported.
233 : * @ctrl_busy_time: Amount of time the controller is busy with I/O commands, reported in minutes.
234 : * @power_cycles: The number of power cycles.
235 : * @power_on_hours: The number of power-on hours, excluding a non-operational power state.
236 : * @unsafe_shutdowns: The number of unsafe shutdowns as a result of a Shutdown Notification not received prior to loss of power.
237 : * @media_errors: Media and Data Integrity Errors: the number of occurrences where the controller detected
238 : * an unrecovered data integrity error (e.g. uncorrectable ECC, CRC checksum failure, or LBA tag mismatch).
239 : * @num_err_log_entries: Number of Error Information Log Entries: the number of Error Information log
240 : * entries over the life of the controller.
241 : * @temperature: Composite Temperature: temperature in Kelvins that represents the current composite
242 : * temperature of the controller and associated namespaces or 0 when not applicable.
243 : * @temp_sensors: Temperature Sensor 1-8: array of the current temperature reported by temperature sensors
244 : * 1-8 in Kelvins or 0 when the particular sensor is not available.
245 : * @wctemp: Warning Composite Temperature Threshold (WCTEMP): indicates the minimum Composite Temperature (@temperature)
246 : * value that indicates an overheating condition during which controller operation continues.
247 : * A value of 0 indicates that no warning temperature threshold value is reported by the controller.
248 : * @cctemp: Critical Composite Temperature Threshold (CCTEMP): indicates the minimum Composite Temperature (@temperature)
249 : * value that indicates a critical overheating condition (e.g., may prevent continued normal operation,
250 : * possibility of data loss, automatic device shutdown, extreme performance throttling, or permanent damage).
251 : * A value of 0 indicates that no critical temperature threshold value is reported by the controller.
252 : * @warning_temp_time: Warning Composite Temperature Time: the amount of time in minutes that the Composite Temperature (@temperature)
253 : * is greater than or equal to the Warning Composite Temperature Threshold (@wctemp) and less than the
254 : * Critical Composite Temperature Threshold (@cctemp).
255 : * @critical_temp_time: Critical Composite Temperature Time: the amount of time in minutes that the Composite Temperature (@temperature)
256 : * is greater than or equal to the Critical Composite Temperature Threshold (@cctemp).
257 : */
258 : /**
259 : * bd_nvme_smart_log_free: (skip)
260 : * @log: (nullable): %BDNVMESmartLog to free
261 : *
262 : * Frees @log.
263 : */
264 1 : void bd_nvme_smart_log_free (BDNVMESmartLog *log) {
265 1 : g_free (log);
266 1 : }
267 :
268 : /**
269 : * bd_nvme_smart_log_copy: (skip)
270 : * @log: (nullable): %BDNVMESmartLog to copy
271 : *
272 : * Creates a new copy of @log.
273 : */
274 0 : BDNVMESmartLog * bd_nvme_smart_log_copy (BDNVMESmartLog *log) {
275 : BDNVMESmartLog *new_log;
276 :
277 0 : if (log == NULL)
278 0 : return NULL;
279 :
280 0 : new_log = g_new0 (BDNVMESmartLog, 1);
281 0 : memcpy (new_log, log, sizeof (BDNVMESmartLog));
282 :
283 0 : return new_log;
284 : }
285 :
286 23 : GType bd_nvme_smart_log_get_type () {
287 : static GType type = 0;
288 :
289 23 : if (G_UNLIKELY (type == 0)) {
290 1 : type = g_boxed_type_register_static ("BDNVMESmartLog",
291 : (GBoxedCopyFunc) bd_nvme_smart_log_copy,
292 : (GBoxedFreeFunc) bd_nvme_smart_log_free);
293 : }
294 23 : return type;
295 : }
296 :
297 : /**
298 : * BDNVMEErrorLogEntry:
299 : * @error_count: internal error counter, a unique identifier for the error.
300 : * @command_id: the Command Identifier of the command that the error is associated with or `0xffff` if the error is not specific to a particular command.
301 : * @command_specific: Command Specific Information specific to @command_id.
302 : * @command_status: the Status code for the command that completed.
303 : * @command_error: translated command error in the BD_NVME_ERROR domain or %NULL in case @command_status indicates success.
304 : * @lba: the first LBA that experienced the error condition.
305 : * @nsid: the NSID of the namespace that the error is associated with.
306 : * @transport_type: type of the transport associated with the error.
307 : */
308 : /**
309 : * bd_nvme_error_log_entry_free: (skip)
310 : * @entry: (nullable): %BDNVMEErrorLogEntry to free
311 : *
312 : * Frees @entry.
313 : */
314 0 : void bd_nvme_error_log_entry_free (BDNVMEErrorLogEntry *entry) {
315 0 : if (entry == NULL)
316 0 : return;
317 :
318 0 : if (entry->command_error)
319 0 : g_error_free (entry->command_error);
320 0 : g_free (entry);
321 : }
322 :
323 : /**
324 : * bd_nvme_error_log_entry_copy: (skip)
325 : * @entry: (nullable): %BDNVMEErrorLogEntry to copy
326 : *
327 : * Creates a new copy of @entry.
328 : */
329 0 : BDNVMEErrorLogEntry * bd_nvme_error_log_entry_copy (BDNVMEErrorLogEntry *entry) {
330 : BDNVMEErrorLogEntry *new_entry;
331 :
332 0 : if (entry == NULL)
333 0 : return NULL;
334 :
335 0 : new_entry = g_new0 (BDNVMEErrorLogEntry, 1);
336 0 : memcpy (new_entry, entry, sizeof (BDNVMEErrorLogEntry));
337 0 : if (entry->command_error)
338 0 : new_entry->command_error = g_error_copy (entry->command_error);
339 :
340 0 : return new_entry;
341 : }
342 :
343 3 : GType bd_nvme_error_log_entry_get_type () {
344 : static GType type = 0;
345 :
346 3 : if (G_UNLIKELY (type == 0)) {
347 1 : type = g_boxed_type_register_static ("BDNVMEErrorLogEntry",
348 : (GBoxedCopyFunc) bd_nvme_error_log_entry_copy,
349 : (GBoxedFreeFunc) bd_nvme_error_log_entry_free);
350 : }
351 3 : return type;
352 : }
353 :
354 : /**
355 : * BDNVMESelfTestLogEntry:
356 : * @result: Result of the device self-test operation.
357 : * @action: The Self-test Code value (action) that was specified in the Device Self-test command that started this device self-test operation.
358 : * @segment: Segment number where the first self-test failure occurred. Valid only when @result is set to #BD_NVME_SELF_TEST_RESULT_KNOWN_SEG_FAIL.
359 : * @power_on_hours: Number of power-on hours at the time the device self-test operation was completed or aborted. Does not include time that the controller was powered and in a low power state condition.
360 : * @nsid: Namespace ID that the Failing LBA occurred on.
361 : * @failing_lba: LBA of the logical block that caused the test to fail. If the device encountered more than one failed logical block during the test, then this field only indicates one of those failed logical blocks.
362 : * @status_code_error: Translated NVMe Command Status Code representing additional information related to errors or conditions.
363 : */
364 : /**
365 : * bd_nvme_self_test_log_entry_free: (skip)
366 : * @entry: (nullable): %BDNVMESelfTestLogEntry to free
367 : *
368 : * Frees @entry.
369 : */
370 0 : void bd_nvme_self_test_log_entry_free (BDNVMESelfTestLogEntry *entry) {
371 0 : if (entry == NULL)
372 0 : return;
373 :
374 0 : if (entry->status_code_error)
375 0 : g_error_free (entry->status_code_error);
376 0 : g_free (entry);
377 : }
378 :
379 : /**
380 : * bd_nvme_self_test_log_entry_copy: (skip)
381 : * @entry: (nullable): %BDNVMESelfTestLogEntry to copy
382 : *
383 : * Creates a new copy of @entry.
384 : */
385 0 : BDNVMESelfTestLogEntry * bd_nvme_self_test_log_entry_copy (BDNVMESelfTestLogEntry *entry) {
386 : BDNVMESelfTestLogEntry *new_entry;
387 :
388 0 : if (entry == NULL)
389 0 : return NULL;
390 :
391 0 : new_entry = g_new0 (BDNVMESelfTestLogEntry, 1);
392 0 : memcpy (new_entry, entry, sizeof (BDNVMESelfTestLogEntry));
393 0 : if (entry->status_code_error)
394 0 : new_entry->status_code_error = g_error_copy (entry->status_code_error);
395 :
396 0 : return new_entry;
397 : }
398 :
399 2 : GType bd_nvme_self_test_log_entry_get_type () {
400 : static GType type = 0;
401 :
402 2 : if (G_UNLIKELY (type == 0)) {
403 1 : type = g_boxed_type_register_static ("BDNVMESelfTestLogEntry",
404 : (GBoxedCopyFunc) bd_nvme_self_test_log_entry_copy,
405 : (GBoxedFreeFunc) bd_nvme_self_test_log_entry_free);
406 : }
407 2 : return type;
408 : }
409 :
410 : /**
411 : * BDNVMESelfTestLog:
412 : * @current_operation: Current running device self-test operation. There's no corresponding record in @entries for a device self-test operation that is in progress.
413 : * @current_operation_completion: Percentage of the currently running device self-test operation. Only valid when @current_operation is other than #BD_NVME_SELF_TEST_ACTION_NOT_RUNNING.
414 : * @entries: (array zero-terminated=1): Self-test log entries for the last 20 operations, sorted from newest (first element) to oldest.
415 : */
416 : /**
417 : * bd_nvme_self_test_log_free: (skip)
418 : * @log: (nullable): %BDNVMESelfTestLog to free
419 : *
420 : * Frees @log.
421 : */
422 0 : void bd_nvme_self_test_log_free (BDNVMESelfTestLog *log) {
423 : BDNVMESelfTestLogEntry **entries;
424 :
425 0 : if (log == NULL)
426 0 : return;
427 :
428 0 : for (entries = log->entries; entries && *entries; entries++)
429 0 : bd_nvme_self_test_log_entry_free (*entries);
430 0 : g_free (log->entries);
431 0 : g_free (log);
432 : }
433 :
434 : /**
435 : * bd_nvme_self_test_log_copy: (skip)
436 : * @log: (nullable): %BDNVMESelfTestLog to copy
437 : *
438 : * Creates a new copy of @log.
439 : */
440 0 : BDNVMESelfTestLog * bd_nvme_self_test_log_copy (BDNVMESelfTestLog *log) {
441 : BDNVMESelfTestLog *new_log;
442 : BDNVMESelfTestLogEntry **entries;
443 : GPtrArray *ptr_array;
444 :
445 0 : if (log == NULL)
446 0 : return NULL;
447 :
448 0 : new_log = g_new0 (BDNVMESelfTestLog, 1);
449 0 : memcpy (new_log, log, sizeof (BDNVMESelfTestLog));
450 :
451 0 : ptr_array = g_ptr_array_new ();
452 0 : for (entries = log->entries; entries && *entries; entries++)
453 0 : g_ptr_array_add (ptr_array, bd_nvme_self_test_log_entry_copy (*entries));
454 0 : g_ptr_array_add (ptr_array, NULL);
455 0 : new_log->entries = (BDNVMESelfTestLogEntry **) g_ptr_array_free (ptr_array, FALSE);
456 :
457 0 : return new_log;
458 : }
459 :
460 3 : GType bd_nvme_self_test_log_get_type () {
461 : static GType type = 0;
462 :
463 3 : if (G_UNLIKELY (type == 0)) {
464 1 : type = g_boxed_type_register_static ("BDNVMESelfTestLog",
465 : (GBoxedCopyFunc) bd_nvme_self_test_log_copy,
466 : (GBoxedFreeFunc) bd_nvme_self_test_log_free);
467 : }
468 3 : return type;
469 : }
470 :
471 : /**
472 : * BDNVMESanitizeLog:
473 : * @sanitize_progress: The percentage complete of the sanitize operation.
474 : * @sanitize_status: The status of the most recent sanitize operation.
475 : * @global_data_erased: Indicates that no user data has been written either since the drive was manufactured and
476 : * has never been sanitized or since the most recent successful sanitize operation.
477 : * @overwrite_passes: Number of completed passes if the most recent sanitize operation was an Overwrite.
478 : * @time_for_overwrite: Estimated time in seconds needed to complete an Overwrite sanitize operation with 16 passes in the background.
479 : * A value of -1 means that no time estimate is reported. A value of 0 means that the operation is expected
480 : * to be completed in the background when the Sanitize command is completed.
481 : * @time_for_block_erase: Estimated time in seconds needed to complete a Block Erase sanitize operation in the background.
482 : * A value of -1 means that no time estimate is reported. A value of 0 means that the operation is expected
483 : * to be completed in the background when the Sanitize command is completed.
484 : * @time_for_crypto_erase: Estimated time in seconds needed to complete a Crypto Erase sanitize operation in the background.
485 : * A value of -1 means that no time estimate is reported. A value of 0 means that the operation is expected
486 : * to be completed in the background when the Sanitize command is completed.
487 : * @time_for_overwrite_nd: Estimated time in seconds needed to complete an Overwrite sanitize operation and the associated
488 : * additional media modification in the background when the No-Deallocate After Sanitize or
489 : * the No-Deallocate Modifies Media After Sanitize features have been requested.
490 : * @time_for_block_erase_nd: Estimated time in seconds needed to complete a Block Erase sanitize operation and the associated
491 : * additional media modification in the background when the No-Deallocate After Sanitize or
492 : * the No-Deallocate Modifies Media After Sanitize features have been requested.
493 : * @time_for_crypto_erase_nd: Estimated time in seconds needed to complete a Crypto Erase sanitize operation and the associated
494 : * additional media modification in the background when the No-Deallocate After Sanitize or
495 : * the No-Deallocate Modifies Media After Sanitize features have been requested.
496 : */
497 : /**
498 : * bd_nvme_sanitize_log_free: (skip)
499 : * @log: (nullable): %BDNVMESanitizeLog to free
500 : *
501 : * Frees @log.
502 : */
503 0 : void bd_nvme_sanitize_log_free (BDNVMESanitizeLog *log) {
504 0 : if (log == NULL)
505 0 : return;
506 :
507 0 : g_free (log);
508 : }
509 :
510 : /**
511 : * bd_nvme_sanitize_log_copy: (skip)
512 : * @log: (nullable): %BDNVMESanitizeLog to copy
513 : *
514 : * Creates a new copy of @log.
515 : */
516 0 : BDNVMESanitizeLog * bd_nvme_sanitize_log_copy (BDNVMESanitizeLog *log) {
517 : BDNVMESanitizeLog *new_log;
518 :
519 0 : if (log == NULL)
520 0 : return NULL;
521 :
522 0 : new_log = g_new0 (BDNVMESanitizeLog, 1);
523 0 : memcpy (new_log, log, sizeof (BDNVMESanitizeLog));
524 :
525 0 : return new_log;
526 : }
527 :
528 3 : GType bd_nvme_sanitize_log_get_type () {
529 : static GType type = 0;
530 :
531 3 : if (G_UNLIKELY (type == 0)) {
532 1 : type = g_boxed_type_register_static ("BDNVMESanitizeLog",
533 : (GBoxedCopyFunc) bd_nvme_sanitize_log_copy,
534 : (GBoxedFreeFunc) bd_nvme_sanitize_log_free);
535 : }
536 3 : return type;
537 : }
538 :
539 0 : static gboolean bd_nvme_is_tech_avail_stub (BDNVMETech tech G_GNUC_UNUSED, G_GNUC_UNUSED guint64 mode G_GNUC_UNUSED, GError **error) {
540 0 : bd_utils_log_format (BD_UTILS_LOG_CRIT, "The function 'bd_nvme_is_tech_avail' called, but not implemented!");
541 0 : g_set_error (error, BD_INIT_ERROR, BD_INIT_ERROR_NOT_IMPLEMENTED,
542 : "The function 'bd_nvme_is_tech_avail' called, but not implemented!");
543 0 : return FALSE;
544 : }
545 :
546 : static gboolean (*_bd_nvme_is_tech_avail) (BDNVMETech tech, G_GNUC_UNUSED guint64 mode, GError **error) = bd_nvme_is_tech_avail_stub;
547 :
548 : /**
549 : * bd_nvme_is_tech_avail:
550 : * @tech: the queried tech
551 : * @mode: a bit mask of queried modes of operation (#BDNVMETechMode) for @tech
552 : * @error: (out) (nullable): place to store error (details about why the @tech-@mode combination is not available)
553 : *
554 : * Returns: whether the @tech-@mode combination is available -- supported by the
555 : * plugin implementation and having all the runtime dependencies available
556 : */
557 2 : gboolean bd_nvme_is_tech_avail (BDNVMETech tech, G_GNUC_UNUSED guint64 mode, GError **error) {
558 2 : return _bd_nvme_is_tech_avail (tech, mode, error);
559 : }
560 :
561 :
562 0 : static const gchar * bd_nvme_self_test_result_to_string_stub (BDNVMESelfTestResult result G_GNUC_UNUSED, GError **error) {
563 0 : bd_utils_log_format (BD_UTILS_LOG_CRIT, "The function 'bd_nvme_self_test_result_to_string' called, but not implemented!");
564 0 : g_set_error (error, BD_INIT_ERROR, BD_INIT_ERROR_NOT_IMPLEMENTED,
565 : "The function 'bd_nvme_self_test_result_to_string' called, but not implemented!");
566 0 : return NULL;
567 : }
568 :
569 : static const gchar * (*_bd_nvme_self_test_result_to_string) (BDNVMESelfTestResult result, GError **error) = bd_nvme_self_test_result_to_string_stub;
570 :
571 : /**
572 : * bd_nvme_self_test_result_to_string:
573 : * @result: A %BDNVMESelfTestResult.
574 : * @error: (out) (optional): place to store error (if any)
575 : *
576 : * Returns: (transfer none): A string representation of @result for use as an identifier string
577 : * or %NULL when the code is unknown.
578 : */
579 10 : const gchar * bd_nvme_self_test_result_to_string (BDNVMESelfTestResult result, GError **error) {
580 10 : return _bd_nvme_self_test_result_to_string (result, error);
581 : }
582 :
583 :
584 0 : static BDNVMEControllerInfo * bd_nvme_get_controller_info_stub (const gchar *device G_GNUC_UNUSED, GError **error) {
585 0 : bd_utils_log_format (BD_UTILS_LOG_CRIT, "The function 'bd_nvme_get_controller_info' called, but not implemented!");
586 0 : g_set_error (error, BD_INIT_ERROR, BD_INIT_ERROR_NOT_IMPLEMENTED,
587 : "The function 'bd_nvme_get_controller_info' called, but not implemented!");
588 0 : return NULL;
589 : }
590 :
591 : static BDNVMEControllerInfo * (*_bd_nvme_get_controller_info) (const gchar *device, GError **error) = bd_nvme_get_controller_info_stub;
592 :
593 : /**
594 : * bd_nvme_get_controller_info:
595 : * @device: a NVMe controller device (e.g. `/dev/nvme0`)
596 : * @error: (out) (nullable): place to store error (if any)
597 : *
598 : * Retrieves information about the NVMe controller (the Identify Controller command)
599 : * as specified by the @device block device path.
600 : *
601 : * Returns: (transfer full): information about given controller or %NULL in case of an error (with @error set).
602 : *
603 : * Tech category: %BD_NVME_TECH_NVME-%BD_NVME_TECH_MODE_INFO
604 : */
605 3 : BDNVMEControllerInfo * bd_nvme_get_controller_info (const gchar *device, GError **error) {
606 3 : return _bd_nvme_get_controller_info (device, error);
607 : }
608 :
609 :
610 0 : static BDNVMENamespaceInfo * bd_nvme_get_namespace_info_stub (const gchar *device G_GNUC_UNUSED, GError **error) {
611 0 : bd_utils_log_format (BD_UTILS_LOG_CRIT, "The function 'bd_nvme_get_namespace_info' called, but not implemented!");
612 0 : g_set_error (error, BD_INIT_ERROR, BD_INIT_ERROR_NOT_IMPLEMENTED,
613 : "The function 'bd_nvme_get_namespace_info' called, but not implemented!");
614 0 : return NULL;
615 : }
616 :
617 : static BDNVMENamespaceInfo * (*_bd_nvme_get_namespace_info) (const gchar *device, GError **error) = bd_nvme_get_namespace_info_stub;
618 :
619 : /**
620 : * bd_nvme_get_namespace_info:
621 : * @device: a NVMe namespace device (e.g. `/dev/nvme0n1`)
622 : * @error: (out) (nullable): place to store error (if any)
623 : *
624 : * Retrieves information about the NVMe namespace (the Identify Namespace command)
625 : * as specified by the @device block device path.
626 : *
627 : * Returns: (transfer full): information about given namespace or %NULL in case of an error (with @error set).
628 : *
629 : * Tech category: %BD_NVME_TECH_NVME-%BD_NVME_TECH_MODE_INFO
630 : */
631 3 : BDNVMENamespaceInfo * bd_nvme_get_namespace_info (const gchar *device, GError **error) {
632 3 : return _bd_nvme_get_namespace_info (device, error);
633 : }
634 :
635 :
636 0 : static BDNVMESmartLog * bd_nvme_get_smart_log_stub (const gchar *device G_GNUC_UNUSED, GError **error) {
637 0 : bd_utils_log_format (BD_UTILS_LOG_CRIT, "The function 'bd_nvme_get_smart_log' called, but not implemented!");
638 0 : g_set_error (error, BD_INIT_ERROR, BD_INIT_ERROR_NOT_IMPLEMENTED,
639 : "The function 'bd_nvme_get_smart_log' called, but not implemented!");
640 0 : return NULL;
641 : }
642 :
643 : static BDNVMESmartLog * (*_bd_nvme_get_smart_log) (const gchar *device, GError **error) = bd_nvme_get_smart_log_stub;
644 :
645 : /**
646 : * bd_nvme_get_smart_log:
647 : * @device: a NVMe controller device (e.g. `/dev/nvme0`)
648 : * @error: (out) (nullable): place to store error (if any)
649 : *
650 : * Retrieves drive SMART and general health information (Log Identifier `02h`).
651 : * The information provided is over the life of the controller and is retained across power cycles.
652 : *
653 : * Returns: (transfer full): health log data or %NULL in case of an error (with @error set).
654 : *
655 : * Tech category: %BD_NVME_TECH_NVME-%BD_NVME_TECH_MODE_INFO
656 : */
657 2 : BDNVMESmartLog * bd_nvme_get_smart_log (const gchar *device, GError **error) {
658 2 : return _bd_nvme_get_smart_log (device, error);
659 : }
660 :
661 :
662 0 : static BDNVMEErrorLogEntry ** bd_nvme_get_error_log_entries_stub (const gchar *device G_GNUC_UNUSED, GError **error) {
663 0 : bd_utils_log_format (BD_UTILS_LOG_CRIT, "The function 'bd_nvme_get_error_log_entries' called, but not implemented!");
664 0 : g_set_error (error, BD_INIT_ERROR, BD_INIT_ERROR_NOT_IMPLEMENTED,
665 : "The function 'bd_nvme_get_error_log_entries' called, but not implemented!");
666 0 : return NULL;
667 : }
668 :
669 : static BDNVMEErrorLogEntry ** (*_bd_nvme_get_error_log_entries) (const gchar *device, GError **error) = bd_nvme_get_error_log_entries_stub;
670 :
671 : /**
672 : * bd_nvme_get_error_log_entries:
673 : * @device: a NVMe controller device (e.g. `/dev/nvme0`)
674 : * @error: (out) (nullable): place to store error (if any)
675 : *
676 : * Retrieves Error Information Log (Log Identifier `01h`) entries, used to describe
677 : * extended error information for a command that completed with error or to report
678 : * an error that is not specific to a particular command. This log is global to the
679 : * controller. The ordering of the entries is based on the time when the error
680 : * occurred, with the most recent error being returned as the first log entry.
681 : * As the number of entries is typically limited by the drive implementation, only
682 : * most recent entries are provided.
683 : *
684 : * Returns: (transfer full) (array zero-terminated=1): null-terminated list
685 : * of error entries or %NULL in case of an error (with @error set).
686 : *
687 : * Tech category: %BD_NVME_TECH_NVME-%BD_NVME_TECH_MODE_INFO
688 : */
689 2 : BDNVMEErrorLogEntry ** bd_nvme_get_error_log_entries (const gchar *device, GError **error) {
690 2 : return _bd_nvme_get_error_log_entries (device, error);
691 : }
692 :
693 :
694 0 : static BDNVMESelfTestLog * bd_nvme_get_self_test_log_stub (const gchar *device G_GNUC_UNUSED, GError **error) {
695 0 : bd_utils_log_format (BD_UTILS_LOG_CRIT, "The function 'bd_nvme_get_self_test_log' called, but not implemented!");
696 0 : g_set_error (error, BD_INIT_ERROR, BD_INIT_ERROR_NOT_IMPLEMENTED,
697 : "The function 'bd_nvme_get_self_test_log' called, but not implemented!");
698 0 : return NULL;
699 : }
700 :
701 : static BDNVMESelfTestLog * (*_bd_nvme_get_self_test_log) (const gchar *device, GError **error) = bd_nvme_get_self_test_log_stub;
702 :
703 : /**
704 : * bd_nvme_get_self_test_log:
705 : * @device: a NVMe controller device (e.g. `/dev/nvme0`)
706 : * @error: (out) (nullable): place to store error (if any)
707 : *
708 : * Retrieves drive self-test log (Log Identifier `06h`). Provides the status of a self-test operation
709 : * in progress and the percentage complete of that operation, along with the results of the last
710 : * 20 device self-test operations.
711 : *
712 : * Returns: (transfer full): self-test log data or %NULL in case of an error (with @error set).
713 : *
714 : * Tech category: %BD_NVME_TECH_NVME-%BD_NVME_TECH_MODE_INFO
715 : */
716 2 : BDNVMESelfTestLog * bd_nvme_get_self_test_log (const gchar *device, GError **error) {
717 2 : return _bd_nvme_get_self_test_log (device, error);
718 : }
719 :
720 :
721 0 : static BDNVMESanitizeLog * bd_nvme_get_sanitize_log_stub (const gchar *device G_GNUC_UNUSED, GError **error) {
722 0 : bd_utils_log_format (BD_UTILS_LOG_CRIT, "The function 'bd_nvme_get_sanitize_log' called, but not implemented!");
723 0 : g_set_error (error, BD_INIT_ERROR, BD_INIT_ERROR_NOT_IMPLEMENTED,
724 : "The function 'bd_nvme_get_sanitize_log' called, but not implemented!");
725 0 : return NULL;
726 : }
727 :
728 : static BDNVMESanitizeLog * (*_bd_nvme_get_sanitize_log) (const gchar *device, GError **error) = bd_nvme_get_sanitize_log_stub;
729 :
730 : /**
731 : * bd_nvme_get_sanitize_log:
732 : * @device: a NVMe controller device (e.g. `/dev/nvme0`)
733 : * @error: (out) (nullable): place to store error (if any)
734 : *
735 : * Retrieves the drive sanitize status log (Log Identifier `81h`) that includes information
736 : * about the most recent sanitize operation and the sanitize operation time estimates.
737 : *
738 : * As advised in the NVMe specification whitepaper the host should limit polling
739 : * to retrieve progress of a running sanitize operations (e.g. to at most once every
740 : * several minutes) to avoid interfering with the progress of the sanitize operation itself.
741 : *
742 : * Returns: (transfer full): sanitize log data or %NULL in case of an error (with @error set).
743 : *
744 : * Tech category: %BD_NVME_TECH_NVME-%BD_NVME_TECH_MODE_INFO
745 : */
746 3 : BDNVMESanitizeLog * bd_nvme_get_sanitize_log (const gchar *device, GError **error) {
747 3 : return _bd_nvme_get_sanitize_log (device, error);
748 : }
749 :
750 :
751 0 : static gboolean bd_nvme_device_self_test_stub (const gchar *device G_GNUC_UNUSED, BDNVMESelfTestAction action G_GNUC_UNUSED, GError **error) {
752 0 : bd_utils_log_format (BD_UTILS_LOG_CRIT, "The function 'bd_nvme_device_self_test' called, but not implemented!");
753 0 : g_set_error (error, BD_INIT_ERROR, BD_INIT_ERROR_NOT_IMPLEMENTED,
754 : "The function 'bd_nvme_device_self_test' called, but not implemented!");
755 0 : return FALSE;
756 : }
757 :
758 : static gboolean (*_bd_nvme_device_self_test) (const gchar *device, BDNVMESelfTestAction action, GError **error) = bd_nvme_device_self_test_stub;
759 :
760 : /**
761 : * bd_nvme_device_self_test:
762 : * @device: a NVMe controller or namespace device (e.g. `/dev/nvme0`)
763 : * @action: self-test action to take.
764 : * @error: (out) (nullable): place to store error (if any)
765 : *
766 : * Initiates or aborts the Device Self-test operation on the controller or a namespace,
767 : * distinguished by the @device path specified. In case a controller device
768 : * is specified then the self-test operation would include all active namespaces.
769 : *
770 : * To abort a running operation, pass #BD_NVME_SELF_TEST_ACTION_ABORT as @action.
771 : * To retrieve progress of a current running operation, check the self-test log using
772 : * bd_nvme_get_self_test_log().
773 : *
774 : * Returns: %TRUE if the device self-test command was issued successfully,
775 : * %FALSE otherwise with @error set.
776 : *
777 : * Tech category: %BD_NVME_TECH_NVME-%BD_NVME_TECH_MODE_MANAGE
778 : */
779 11 : gboolean bd_nvme_device_self_test (const gchar *device, BDNVMESelfTestAction action, GError **error) {
780 11 : return _bd_nvme_device_self_test (device, action, error);
781 : }
782 :
783 :
784 0 : static gboolean bd_nvme_format_stub (const gchar *device G_GNUC_UNUSED, guint16 lba_data_size G_GNUC_UNUSED, guint16 metadata_size G_GNUC_UNUSED, BDNVMEFormatSecureErase secure_erase G_GNUC_UNUSED, GError **error) {
785 0 : bd_utils_log_format (BD_UTILS_LOG_CRIT, "The function 'bd_nvme_format' called, but not implemented!");
786 0 : g_set_error (error, BD_INIT_ERROR, BD_INIT_ERROR_NOT_IMPLEMENTED,
787 : "The function 'bd_nvme_format' called, but not implemented!");
788 0 : return FALSE;
789 : }
790 :
791 : static gboolean (*_bd_nvme_format) (const gchar *device, guint16 lba_data_size, guint16 metadata_size, BDNVMEFormatSecureErase secure_erase, GError **error) = bd_nvme_format_stub;
792 :
793 : /**
794 : * bd_nvme_format:
795 : * @device: NVMe namespace or controller device to format (e.g. `/dev/nvme0n1`)
796 : * @lba_data_size: desired LBA data size (i.e. a sector size) in bytes or `0` to keep current. See #BDNVMELBAFormat and bd_nvme_get_namespace_info().
797 : * @metadata_size: desired metadata size in bytes or `0` for default. See #BDNVMELBAFormat and bd_nvme_get_namespace_info().
798 : * @secure_erase: optional secure erase action to take.
799 : * @error: (out) (nullable): place to store error (if any)
800 : *
801 : * Performs low level format of the NVM media, destroying all data and metadata for either
802 : * a specific namespace or all attached namespaces to the controller. Use this command
803 : * to change LBA sector size. Optional secure erase method can be specified as well.
804 : *
805 : * Supported LBA data sizes for a given namespace can be listed using the bd_nvme_get_namespace_info()
806 : * call. In case of a special value `0` the current LBA format for a given namespace will be
807 : * retained. When called on a controller device the first namespace is used as a reference.
808 : *
809 : * Note that the NVMe controller may define a Format NVM attribute indicating that the format
810 : * operation would apply to all namespaces and a format (excluding secure erase) of any
811 : * namespace results in a format of all namespaces in the NVM subsystem. In such case and
812 : * when @device is a namespace block device the #BD_NVME_ERROR_WOULD_FORMAT_ALL_NS error
813 : * is returned to prevent further damage. This is then supposed to be handled by the caller
814 : * and bd_nvme_format() is supposed to be called on a controller device instead.
815 : *
816 : * This call blocks until the format operation has finished. To retrieve progress
817 : * of a current running operation, check the namespace info using bd_nvme_get_namespace_info().
818 : *
819 : * Returns: %TRUE if the format command finished successfully, %FALSE otherwise with @error set.
820 : *
821 : * Tech category: %BD_NVME_TECH_NVME-%BD_NVME_TECH_MODE_MANAGE
822 : */
823 5 : gboolean bd_nvme_format (const gchar *device, guint16 lba_data_size, guint16 metadata_size, BDNVMEFormatSecureErase secure_erase, GError **error) {
824 5 : return _bd_nvme_format (device, lba_data_size, metadata_size, secure_erase, error);
825 : }
826 :
827 :
828 0 : static gboolean bd_nvme_sanitize_stub (const gchar *device G_GNUC_UNUSED, BDNVMESanitizeAction action G_GNUC_UNUSED, gboolean no_dealloc G_GNUC_UNUSED, gint overwrite_pass_count G_GNUC_UNUSED, guint32 overwrite_pattern G_GNUC_UNUSED, gboolean overwrite_invert_pattern G_GNUC_UNUSED, GError **error) {
829 0 : bd_utils_log_format (BD_UTILS_LOG_CRIT, "The function 'bd_nvme_sanitize' called, but not implemented!");
830 0 : g_set_error (error, BD_INIT_ERROR, BD_INIT_ERROR_NOT_IMPLEMENTED,
831 : "The function 'bd_nvme_sanitize' called, but not implemented!");
832 0 : return FALSE;
833 : }
834 :
835 : static gboolean (*_bd_nvme_sanitize) (const gchar *device, BDNVMESanitizeAction action, gboolean no_dealloc, gint overwrite_pass_count, guint32 overwrite_pattern, gboolean overwrite_invert_pattern, GError **error) = bd_nvme_sanitize_stub;
836 :
837 : /**
838 : * bd_nvme_sanitize:
839 : * @device: NVMe namespace or controller device to format (e.g. `/dev/nvme0n1`)
840 : * @action: the sanitize action to perform.
841 : * @no_dealloc: instruct the controller to not deallocate the affected media area.
842 : * @overwrite_pass_count: number of overwrite passes [1-15] or 0 for the default (16 passes).
843 : * @overwrite_pattern: a 32-bit pattern used for the Overwrite sanitize operation.
844 : * @overwrite_invert_pattern: invert the overwrite pattern between passes.
845 : * @error: (out) (nullable): place to store error (if any)
846 : *
847 : * Starts a sanitize operation or recovers from a previously failed sanitize operation.
848 : * By definition, a sanitize operation alters all user data in the NVM subsystem such
849 : * that recovery of any previous user data from any cache, the non-volatile media,
850 : * or any Controller Memory Buffer is not possible. The scope of a sanitize operation
851 : * is all locations in the NVM subsystem that are able to contain user data, including
852 : * caches, Persistent Memory Regions, and unallocated or deallocated areas of the media.
853 : *
854 : * Once started, a sanitize operation is not able to be aborted and continues after
855 : * a Controller Level Reset including across power cycles. Once the sanitize operation
856 : * has run the media affected may not be immediately ready for use unless additional
857 : * media modification mechanism is run. This is often vendor specific and also depends
858 : * on the sanitize method (@action) used. Callers to this sanitize operation should
859 : * set @no_dealloc to %TRUE for the added convenience.
860 : *
861 : * The controller also ignores Critical Warning(s) in the SMART / Health Information
862 : * log page (e.g., read only mode) and attempts to complete the sanitize operation requested.
863 : *
864 : * This call returns immediately and the actual sanitize operation is performed
865 : * in the background. Use bd_nvme_get_sanitize_log() to retrieve status and progress
866 : * of a running sanitize operation. In case a sanitize operation fails the controller
867 : * may restrict its operation until a subsequent sanitize operation is started
868 : * (i.e. retried) or an #BD_NVME_SANITIZE_ACTION_EXIT_FAILURE action is used
869 : * to acknowledge the failure explicitly.
870 : *
871 : * The @overwrite_pass_count, @overwrite_pattern and @overwrite_invert_pattern
872 : * arguments are only valid when @action is #BD_NVME_SANITIZE_ACTION_OVERWRITE.
873 : *
874 : * The sanitize operation is set to run under the Allow Unrestricted Sanitize Exit
875 : * mode.
876 : *
877 : * Returns: %TRUE if the format command finished successfully, %FALSE otherwise with @error set.
878 : *
879 : * Tech category: %BD_NVME_TECH_NVME-%BD_NVME_TECH_MODE_MANAGE
880 : */
881 9 : gboolean bd_nvme_sanitize (const gchar *device, BDNVMESanitizeAction action, gboolean no_dealloc, gint overwrite_pass_count, guint32 overwrite_pattern, gboolean overwrite_invert_pattern, GError **error) {
882 9 : return _bd_nvme_sanitize (device, action, no_dealloc, overwrite_pass_count, overwrite_pattern, overwrite_invert_pattern, error);
883 : }
884 :
885 :
886 0 : static gchar * bd_nvme_get_host_nqn_stub (GError **error) {
887 0 : bd_utils_log_format (BD_UTILS_LOG_CRIT, "The function 'bd_nvme_get_host_nqn' called, but not implemented!");
888 0 : g_set_error (error, BD_INIT_ERROR, BD_INIT_ERROR_NOT_IMPLEMENTED,
889 : "The function 'bd_nvme_get_host_nqn' called, but not implemented!");
890 0 : return NULL;
891 : }
892 :
893 : static gchar * (*_bd_nvme_get_host_nqn) (GError **error) = bd_nvme_get_host_nqn_stub;
894 :
895 : /**
896 : * bd_nvme_get_host_nqn:
897 : * @error: (out) (nullable): Place to store error (if any).
898 : *
899 : * Reads the Host NQN (NVM Qualified Name) value from the global `/etc/nvme/hostnqn`
900 : * file. An empty string is an indication that no Host NQN has been set.
901 : *
902 : * Returns: (transfer full): the Host NQN string or an empty string if none set.
903 : *
904 : * Tech category: %BD_NVME_TECH_FABRICS-%BD_NVME_TECH_MODE_INITIATOR
905 : */
906 2 : gchar * bd_nvme_get_host_nqn (GError **error) {
907 2 : return _bd_nvme_get_host_nqn (error);
908 : }
909 :
910 :
911 0 : static gchar * bd_nvme_generate_host_nqn_stub (GError **error) {
912 0 : bd_utils_log_format (BD_UTILS_LOG_CRIT, "The function 'bd_nvme_generate_host_nqn' called, but not implemented!");
913 0 : g_set_error (error, BD_INIT_ERROR, BD_INIT_ERROR_NOT_IMPLEMENTED,
914 : "The function 'bd_nvme_generate_host_nqn' called, but not implemented!");
915 0 : return NULL;
916 : }
917 :
918 : static gchar * (*_bd_nvme_generate_host_nqn) (GError **error) = bd_nvme_generate_host_nqn_stub;
919 :
920 : /**
921 : * bd_nvme_generate_host_nqn:
922 : * @error: (out) (nullable): Place to store error (if any).
923 : *
924 : * Compute new Host NQN (NVM Qualified Name) value for the current system. This
925 : * takes in account various system identifiers (DMI, device tree) with the goal
926 : * of a stable unique identifier whenever feasible.
927 : *
928 : * Returns: (transfer full): the Host NQN string or %NULL with @error set.
929 : *
930 : * Tech category: %BD_NVME_TECH_FABRICS-%BD_NVME_TECH_MODE_INITIATOR
931 : */
932 2 : gchar * bd_nvme_generate_host_nqn (GError **error) {
933 2 : return _bd_nvme_generate_host_nqn (error);
934 : }
935 :
936 :
937 0 : static gchar * bd_nvme_get_host_id_stub (GError **error) {
938 0 : bd_utils_log_format (BD_UTILS_LOG_CRIT, "The function 'bd_nvme_get_host_id' called, but not implemented!");
939 0 : g_set_error (error, BD_INIT_ERROR, BD_INIT_ERROR_NOT_IMPLEMENTED,
940 : "The function 'bd_nvme_get_host_id' called, but not implemented!");
941 0 : return NULL;
942 : }
943 :
944 : static gchar * (*_bd_nvme_get_host_id) (GError **error) = bd_nvme_get_host_id_stub;
945 :
946 : /**
947 : * bd_nvme_get_host_id:
948 : * @error: (out) (nullable): Place to store error (if any).
949 : *
950 : * Reads the Host ID value from the global `/etc/nvme/hostid` file. An empty
951 : * string is an indication that no Host ID has been set.
952 : *
953 : * Returns: (transfer full): the Host ID string or an empty string if none set.
954 : *
955 : * Tech category: %BD_NVME_TECH_FABRICS-%BD_NVME_TECH_MODE_INITIATOR
956 : */
957 2 : gchar * bd_nvme_get_host_id (GError **error) {
958 2 : return _bd_nvme_get_host_id (error);
959 : }
960 :
961 :
962 0 : static gboolean bd_nvme_set_host_nqn_stub (const gchar *host_nqn G_GNUC_UNUSED, GError **error) {
963 0 : bd_utils_log_format (BD_UTILS_LOG_CRIT, "The function 'bd_nvme_set_host_nqn' called, but not implemented!");
964 0 : g_set_error (error, BD_INIT_ERROR, BD_INIT_ERROR_NOT_IMPLEMENTED,
965 : "The function 'bd_nvme_set_host_nqn' called, but not implemented!");
966 0 : return FALSE;
967 : }
968 :
969 : static gboolean (*_bd_nvme_set_host_nqn) (const gchar *host_nqn, GError **error) = bd_nvme_set_host_nqn_stub;
970 :
971 : /**
972 : * bd_nvme_set_host_nqn:
973 : * @host_nqn: The Host NVM Qualified Name.
974 : * @error: (out) (nullable): Place to store error (if any).
975 : *
976 : * Writes the Host NQN (NVM Qualified Name) value to the system `/etc/nvme/hostnqn` file.
977 : * No validation of the string is performed.
978 : *
979 : * Returns: %TRUE if the value was set successfully or %FALSE otherwise with @error set.
980 : *
981 : * Tech category: %BD_NVME_TECH_FABRICS-%BD_NVME_TECH_MODE_INITIATOR
982 : */
983 1 : gboolean bd_nvme_set_host_nqn (const gchar *host_nqn, GError **error) {
984 1 : return _bd_nvme_set_host_nqn (host_nqn, error);
985 : }
986 :
987 :
988 0 : static gboolean bd_nvme_set_host_id_stub (const gchar *host_id G_GNUC_UNUSED, GError **error) {
989 0 : bd_utils_log_format (BD_UTILS_LOG_CRIT, "The function 'bd_nvme_set_host_id' called, but not implemented!");
990 0 : g_set_error (error, BD_INIT_ERROR, BD_INIT_ERROR_NOT_IMPLEMENTED,
991 : "The function 'bd_nvme_set_host_id' called, but not implemented!");
992 0 : return FALSE;
993 : }
994 :
995 : static gboolean (*_bd_nvme_set_host_id) (const gchar *host_id, GError **error) = bd_nvme_set_host_id_stub;
996 :
997 : /**
998 : * bd_nvme_set_host_id:
999 : * @host_id: The Host ID.
1000 : * @error: (out) (nullable): Place to store error (if any).
1001 : *
1002 : * Writes the Host ID value to the system `/etc/nvme/hostid` file.
1003 : * No validation of the string is performed.
1004 : *
1005 : * Returns: %TRUE if the value was set successfully or %FALSE otherwise with @error set.
1006 : *
1007 : * Tech category: %BD_NVME_TECH_FABRICS-%BD_NVME_TECH_MODE_INITIATOR
1008 : */
1009 1 : gboolean bd_nvme_set_host_id (const gchar *host_id, GError **error) {
1010 1 : return _bd_nvme_set_host_id (host_id, error);
1011 : }
1012 :
1013 :
1014 0 : static gboolean bd_nvme_connect_stub (const gchar *subsysnqn G_GNUC_UNUSED, const gchar *transport G_GNUC_UNUSED, const gchar *transport_addr G_GNUC_UNUSED, const gchar *transport_svcid G_GNUC_UNUSED, const gchar *host_traddr G_GNUC_UNUSED, const gchar *host_iface G_GNUC_UNUSED, const gchar *host_nqn G_GNUC_UNUSED, const gchar *host_id G_GNUC_UNUSED, const BDExtraArg **extra G_GNUC_UNUSED, GError **error) {
1015 0 : bd_utils_log_format (BD_UTILS_LOG_CRIT, "The function 'bd_nvme_connect' called, but not implemented!");
1016 0 : g_set_error (error, BD_INIT_ERROR, BD_INIT_ERROR_NOT_IMPLEMENTED,
1017 : "The function 'bd_nvme_connect' called, but not implemented!");
1018 0 : return FALSE;
1019 : }
1020 :
1021 : static gboolean (*_bd_nvme_connect) (const gchar *subsysnqn, const gchar *transport, const gchar *transport_addr, const gchar *transport_svcid, const gchar *host_traddr, const gchar *host_iface, const gchar *host_nqn, const gchar *host_id, const BDExtraArg **extra, GError **error) = bd_nvme_connect_stub;
1022 :
1023 : /**
1024 : * bd_nvme_connect:
1025 : * @subsysnqn: The name for the NVMe subsystem to connect to.
1026 : * @transport: The network fabric used for a NVMe-over-Fabrics network.
1027 : * @transport_addr: (nullable): The network address of the Controller. For transports using IP addressing (e.g. `rdma`) this should be an IP-based address.
1028 : * @transport_svcid: (nullable): The transport service ID. For transports using IP addressing (e.g. `tcp`, `rdma`) this field is the port number. The default port number for the `tcp` and `rdma` transports is `4420` and `8009` respectively when the well-known Discovery NQN is specified.
1029 : * @host_traddr: (nullable): The network address used on the host to connect to the Controller. For TCP, this sets the source address on the socket.
1030 : * @host_iface: (nullable): The network interface used on the host to connect to the Controller (e.g. IP `eth1`, `enp2s0`). This forces the connection to be made on a specific interface instead of letting the system decide.
1031 : * @host_nqn: (nullable): Overrides the default Host NQN that identifies the NVMe Host. If this option is %NULL, the default is read from `/etc/nvme/hostnqn` first.
1032 : * If that does not exist, the autogenerated NQN value from the NVMe Host kernel module is used next. The Host NQN uniquely identifies the NVMe Host.
1033 : * @host_id: (nullable): User-defined host UUID or %NULL to use default (as defined in `/etc/nvme/hostid`)
1034 : * @extra: (nullable) (array zero-terminated=1): Additional arguments.
1035 : * @error: (out) (nullable): Place to store error (if any).
1036 : *
1037 : * Creates a transport connection to a remote system (specified by @transport_addr and @transport_svcid)
1038 : * and creates a NVMe over Fabrics controller for the NVMe subsystem specified by the @subsysnqn option.
1039 : *
1040 : * Valid values for @transport include:
1041 : * - `"rdma"`: An rdma network (RoCE, iWARP, Infiniband, basic rdma, etc.)
1042 : * - `"fc"`: A Fibre Channel network.
1043 : * - `"tcp"`: A TCP/IP network.
1044 : * - `"loop"`: A NVMe over Fabrics target on the local host.
1045 : *
1046 : * In addition to the primary options it's possible to supply @extra arguments:
1047 : * - `"config"`: Use the specified JSON configuration file instead of the default file (see below) or
1048 : * specify `"none"` to avoid reading any configuration file.
1049 : * - `"dhchap_key"`: NVMe In-band authentication secret in ASCII format as described
1050 : * in the NVMe 2.0 specification. When not specified, the secret is by default read
1051 : * from `/etc/nvme/hostkey`. In case that file does not exist no in-band authentication
1052 : * is attempted.
1053 : * - `"dhchap_ctrl_key"`: NVMe In-band authentication controller secret for bi-directional authentication.
1054 : * When not specified, no bi-directional authentication is attempted.
1055 : * - `"nr_io_queues"`: The number of I/O queues.
1056 : * - `"nr_write_queues"`: Number of additional queues that will be used for write I/O.
1057 : * - `"nr_poll_queues"`: Number of additional queues that will be used for polling latency sensitive I/O.
1058 : * - `"queue_size"`: Number of elements in the I/O queues.
1059 : * - `"keep_alive_tmo"`: The keep alive timeout (in seconds).
1060 : * - `"reconnect_delay"`: The delay (in seconds) before reconnect is attempted after a connect loss.
1061 : * - `"ctrl_loss_tmo"`: The controller loss timeout period (in seconds). A special value of `-1` will cause reconnecting forever.
1062 : * - `"fast_io_fail_tmo"`: Fast I/O Fail timeout (in seconds).
1063 : * - `"tos"`: Type of service.
1064 : * - `"duplicate_connect"`: Allow duplicated connections between same transport host and subsystem port. Boolean value.
1065 : * - `"disable_sqflow"`: Disables SQ flow control to omit head doorbell update for submission queues when sending nvme completions. Boolean value.
1066 : * - `"hdr_digest"`: Generates/verifies header digest (TCP). Boolean value.
1067 : * - `"data_digest"`: Generates/verifies data digest (TCP). Boolean value.
1068 : * - `"tls"`: Enable TLS encryption (TCP). Boolean value.
1069 : * - `"hostsymname"`: TP8010: NVMe host symbolic name.
1070 : * - `"keyring"`: Keyring to store and lookup keys. String value.
1071 : * - `"tls_key"`: TLS PSK for the connection. String value.
1072 : *
1073 : * Boolean values can be expressed by "0"/"1", "on"/"off" or "True"/"False" case-insensitive
1074 : * strings. Failed numerical or boolean string conversions will result in the option being ignored.
1075 : *
1076 : * By default additional options are read from the default configuration file `/etc/nvme/config.json`.
1077 : * This follows the default behaviour of `nvme-cli`. Use the @extra `"config"` argument
1078 : * to either specify a different config file or disable use of it. The JSON configuration
1079 : * file format is documented in [https://raw.githubusercontent.com/linux-nvme/libnvme/master/doc/config-schema.json](https://raw.githubusercontent.com/linux-nvme/libnvme/master/doc/config-schema.json).
1080 : * As a rule @extra key names are kept consistent with the JSON config file schema.
1081 : * Any @extra option generally overrides particular option specified in a configuration file.
1082 : *
1083 : * Returns: %TRUE if the subsystem was connected successfully, %FALSE otherwise with @error set.
1084 : *
1085 : * Tech category: %BD_NVME_TECH_FABRICS-%BD_NVME_TECH_MODE_INITIATOR
1086 : */
1087 14 : gboolean bd_nvme_connect (const gchar *subsysnqn, const gchar *transport, const gchar *transport_addr, const gchar *transport_svcid, const gchar *host_traddr, const gchar *host_iface, const gchar *host_nqn, const gchar *host_id, const BDExtraArg **extra, GError **error) {
1088 14 : return _bd_nvme_connect (subsysnqn, transport, transport_addr, transport_svcid, host_traddr, host_iface, host_nqn, host_id, extra, error);
1089 : }
1090 :
1091 :
1092 0 : static gboolean bd_nvme_disconnect_stub (const gchar *subsysnqn G_GNUC_UNUSED, GError **error) {
1093 0 : bd_utils_log_format (BD_UTILS_LOG_CRIT, "The function 'bd_nvme_disconnect' called, but not implemented!");
1094 0 : g_set_error (error, BD_INIT_ERROR, BD_INIT_ERROR_NOT_IMPLEMENTED,
1095 : "The function 'bd_nvme_disconnect' called, but not implemented!");
1096 0 : return FALSE;
1097 : }
1098 :
1099 : static gboolean (*_bd_nvme_disconnect) (const gchar *subsysnqn, GError **error) = bd_nvme_disconnect_stub;
1100 :
1101 : /**
1102 : * bd_nvme_disconnect:
1103 : * @subsysnqn: The name of the NVMe subsystem to disconnect.
1104 : * @error: (out) (nullable): Place to store error (if any).
1105 : *
1106 : * Disconnects and removes one or more existing NVMe over Fabrics controllers.
1107 : * This may disconnect multiple controllers with matching @subsysnqn and %TRUE
1108 : * is only returned when all controllers were disconnected successfully.
1109 : *
1110 : * Returns: %TRUE if all matching controllers were disconnected successfully, %FALSE with @error
1111 : * set in case of a disconnect error or when no matching controllers were found.
1112 : *
1113 : * Tech category: %BD_NVME_TECH_FABRICS-%BD_NVME_TECH_MODE_INITIATOR
1114 : */
1115 10 : gboolean bd_nvme_disconnect (const gchar *subsysnqn, GError **error) {
1116 10 : return _bd_nvme_disconnect (subsysnqn, error);
1117 : }
1118 :
1119 :
1120 0 : static gboolean bd_nvme_disconnect_by_path_stub (const gchar *path G_GNUC_UNUSED, GError **error) {
1121 0 : bd_utils_log_format (BD_UTILS_LOG_CRIT, "The function 'bd_nvme_disconnect_by_path' called, but not implemented!");
1122 0 : g_set_error (error, BD_INIT_ERROR, BD_INIT_ERROR_NOT_IMPLEMENTED,
1123 : "The function 'bd_nvme_disconnect_by_path' called, but not implemented!");
1124 0 : return FALSE;
1125 : }
1126 :
1127 : static gboolean (*_bd_nvme_disconnect_by_path) (const gchar *path, GError **error) = bd_nvme_disconnect_by_path_stub;
1128 :
1129 : /**
1130 : * bd_nvme_disconnect_by_path:
1131 : * @path: NVMe controller device to disconnect (e.g. `/dev/nvme0`).
1132 : * @error: (out) (nullable): Place to store error (if any).
1133 : *
1134 : * Disconnects and removes a NVMe over Fabrics controller represented
1135 : * by a block device path.
1136 : *
1137 : * Returns: %TRUE if the controller was disconnected successfully,
1138 : * %FALSE otherwise with @error set.
1139 : *
1140 : * Tech category: %BD_NVME_TECH_FABRICS-%BD_NVME_TECH_MODE_INITIATOR
1141 : */
1142 3 : gboolean bd_nvme_disconnect_by_path (const gchar *path, GError **error) {
1143 3 : return _bd_nvme_disconnect_by_path (path, error);
1144 : }
1145 :
1146 :
1147 0 : static gchar ** bd_nvme_find_ctrls_for_ns_stub (const gchar *ns_sysfs_path G_GNUC_UNUSED, const gchar *subsysnqn G_GNUC_UNUSED, const gchar *host_nqn G_GNUC_UNUSED, const gchar *host_id G_GNUC_UNUSED, GError **error) {
1148 0 : bd_utils_log_format (BD_UTILS_LOG_CRIT, "The function 'bd_nvme_find_ctrls_for_ns' called, but not implemented!");
1149 0 : g_set_error (error, BD_INIT_ERROR, BD_INIT_ERROR_NOT_IMPLEMENTED,
1150 : "The function 'bd_nvme_find_ctrls_for_ns' called, but not implemented!");
1151 0 : return NULL;
1152 : }
1153 :
1154 : static gchar ** (*_bd_nvme_find_ctrls_for_ns) (const gchar *ns_sysfs_path, const gchar *subsysnqn, const gchar *host_nqn, const gchar *host_id, GError **error) = bd_nvme_find_ctrls_for_ns_stub;
1155 :
1156 : /**
1157 : * bd_nvme_find_ctrls_for_ns:
1158 : * @ns_sysfs_path: NVMe namespace device file.
1159 : * @subsysnqn: (nullable): Limit matching to the specified subsystem NQN.
1160 : * @host_nqn: (nullable): Limit matching to the specified host NQN.
1161 : * @host_id: (nullable): Limit matching to the specified host ID.
1162 : * @error: (out) (nullable): Place to store error (if any).
1163 : *
1164 : * A convenient utility function to look up all controllers associated
1165 : * with a NVMe subsystem the specified namespace is part of.
1166 : *
1167 : * Returns: (transfer full) (array zero-terminated=1): list of controller sysfs paths
1168 : * or %NULL in case of an error (with @error set).
1169 : *
1170 : * Tech category: %BD_NVME_TECH_FABRICS-%BD_NVME_TECH_MODE_INITIATOR
1171 : */
1172 27 : gchar ** bd_nvme_find_ctrls_for_ns (const gchar *ns_sysfs_path, const gchar *subsysnqn, const gchar *host_nqn, const gchar *host_id, GError **error) {
1173 27 : return _bd_nvme_find_ctrls_for_ns (ns_sysfs_path, subsysnqn, host_nqn, host_id, error);
1174 : }
1175 :
1176 :
1177 3 : static gpointer load_nvme_from_plugin(const gchar *so_name) {
1178 3 : void *handle = NULL;
1179 3 : char *error = NULL;
1180 3 : gboolean (*init_fn) (void) = NULL;
1181 :
1182 3 : handle = dlopen(so_name, RTLD_LAZY);
1183 3 : if (!handle) {
1184 0 : bd_utils_log_format (BD_UTILS_LOG_WARNING, "failed to load module nvme: %s", dlerror());
1185 0 : return NULL;
1186 : }
1187 :
1188 3 : dlerror();
1189 3 : * (void**) (&init_fn) = dlsym(handle, "bd_nvme_init");
1190 3 : if ((error = dlerror()) != NULL)
1191 0 : bd_utils_log_format (BD_UTILS_LOG_DEBUG, "failed to load the init() function for nvme: %s", error);
1192 : /* coverity[dead_error_condition] */
1193 3 : if (init_fn && !init_fn()) {
1194 0 : dlclose(handle);
1195 0 : return NULL;
1196 : }
1197 3 : init_fn = NULL;
1198 :
1199 3 : dlerror();
1200 3 : * (void**) (&_bd_nvme_is_tech_avail) = dlsym(handle, "bd_nvme_is_tech_avail");
1201 3 : if ((error = dlerror()) != NULL)
1202 0 : bd_utils_log_format (BD_UTILS_LOG_WARNING, "failed to load bd_nvme_is_tech_avail: %s", error);
1203 :
1204 3 : dlerror();
1205 3 : * (void**) (&_bd_nvme_self_test_result_to_string) = dlsym(handle, "bd_nvme_self_test_result_to_string");
1206 3 : if ((error = dlerror()) != NULL)
1207 0 : bd_utils_log_format (BD_UTILS_LOG_WARNING, "failed to load bd_nvme_self_test_result_to_string: %s", error);
1208 :
1209 3 : dlerror();
1210 3 : * (void**) (&_bd_nvme_get_controller_info) = dlsym(handle, "bd_nvme_get_controller_info");
1211 3 : if ((error = dlerror()) != NULL)
1212 0 : bd_utils_log_format (BD_UTILS_LOG_WARNING, "failed to load bd_nvme_get_controller_info: %s", error);
1213 :
1214 3 : dlerror();
1215 3 : * (void**) (&_bd_nvme_get_namespace_info) = dlsym(handle, "bd_nvme_get_namespace_info");
1216 3 : if ((error = dlerror()) != NULL)
1217 0 : bd_utils_log_format (BD_UTILS_LOG_WARNING, "failed to load bd_nvme_get_namespace_info: %s", error);
1218 :
1219 3 : dlerror();
1220 3 : * (void**) (&_bd_nvme_get_smart_log) = dlsym(handle, "bd_nvme_get_smart_log");
1221 3 : if ((error = dlerror()) != NULL)
1222 0 : bd_utils_log_format (BD_UTILS_LOG_WARNING, "failed to load bd_nvme_get_smart_log: %s", error);
1223 :
1224 3 : dlerror();
1225 3 : * (void**) (&_bd_nvme_get_error_log_entries) = dlsym(handle, "bd_nvme_get_error_log_entries");
1226 3 : if ((error = dlerror()) != NULL)
1227 0 : bd_utils_log_format (BD_UTILS_LOG_WARNING, "failed to load bd_nvme_get_error_log_entries: %s", error);
1228 :
1229 3 : dlerror();
1230 3 : * (void**) (&_bd_nvme_get_self_test_log) = dlsym(handle, "bd_nvme_get_self_test_log");
1231 3 : if ((error = dlerror()) != NULL)
1232 0 : bd_utils_log_format (BD_UTILS_LOG_WARNING, "failed to load bd_nvme_get_self_test_log: %s", error);
1233 :
1234 3 : dlerror();
1235 3 : * (void**) (&_bd_nvme_get_sanitize_log) = dlsym(handle, "bd_nvme_get_sanitize_log");
1236 3 : if ((error = dlerror()) != NULL)
1237 0 : bd_utils_log_format (BD_UTILS_LOG_WARNING, "failed to load bd_nvme_get_sanitize_log: %s", error);
1238 :
1239 3 : dlerror();
1240 3 : * (void**) (&_bd_nvme_device_self_test) = dlsym(handle, "bd_nvme_device_self_test");
1241 3 : if ((error = dlerror()) != NULL)
1242 0 : bd_utils_log_format (BD_UTILS_LOG_WARNING, "failed to load bd_nvme_device_self_test: %s", error);
1243 :
1244 3 : dlerror();
1245 3 : * (void**) (&_bd_nvme_format) = dlsym(handle, "bd_nvme_format");
1246 3 : if ((error = dlerror()) != NULL)
1247 0 : bd_utils_log_format (BD_UTILS_LOG_WARNING, "failed to load bd_nvme_format: %s", error);
1248 :
1249 3 : dlerror();
1250 3 : * (void**) (&_bd_nvme_sanitize) = dlsym(handle, "bd_nvme_sanitize");
1251 3 : if ((error = dlerror()) != NULL)
1252 0 : bd_utils_log_format (BD_UTILS_LOG_WARNING, "failed to load bd_nvme_sanitize: %s", error);
1253 :
1254 3 : dlerror();
1255 3 : * (void**) (&_bd_nvme_get_host_nqn) = dlsym(handle, "bd_nvme_get_host_nqn");
1256 3 : if ((error = dlerror()) != NULL)
1257 0 : bd_utils_log_format (BD_UTILS_LOG_WARNING, "failed to load bd_nvme_get_host_nqn: %s", error);
1258 :
1259 3 : dlerror();
1260 3 : * (void**) (&_bd_nvme_generate_host_nqn) = dlsym(handle, "bd_nvme_generate_host_nqn");
1261 3 : if ((error = dlerror()) != NULL)
1262 0 : bd_utils_log_format (BD_UTILS_LOG_WARNING, "failed to load bd_nvme_generate_host_nqn: %s", error);
1263 :
1264 3 : dlerror();
1265 3 : * (void**) (&_bd_nvme_get_host_id) = dlsym(handle, "bd_nvme_get_host_id");
1266 3 : if ((error = dlerror()) != NULL)
1267 0 : bd_utils_log_format (BD_UTILS_LOG_WARNING, "failed to load bd_nvme_get_host_id: %s", error);
1268 :
1269 3 : dlerror();
1270 3 : * (void**) (&_bd_nvme_set_host_nqn) = dlsym(handle, "bd_nvme_set_host_nqn");
1271 3 : if ((error = dlerror()) != NULL)
1272 0 : bd_utils_log_format (BD_UTILS_LOG_WARNING, "failed to load bd_nvme_set_host_nqn: %s", error);
1273 :
1274 3 : dlerror();
1275 3 : * (void**) (&_bd_nvme_set_host_id) = dlsym(handle, "bd_nvme_set_host_id");
1276 3 : if ((error = dlerror()) != NULL)
1277 0 : bd_utils_log_format (BD_UTILS_LOG_WARNING, "failed to load bd_nvme_set_host_id: %s", error);
1278 :
1279 3 : dlerror();
1280 3 : * (void**) (&_bd_nvme_connect) = dlsym(handle, "bd_nvme_connect");
1281 3 : if ((error = dlerror()) != NULL)
1282 0 : bd_utils_log_format (BD_UTILS_LOG_WARNING, "failed to load bd_nvme_connect: %s", error);
1283 :
1284 3 : dlerror();
1285 3 : * (void**) (&_bd_nvme_disconnect) = dlsym(handle, "bd_nvme_disconnect");
1286 3 : if ((error = dlerror()) != NULL)
1287 0 : bd_utils_log_format (BD_UTILS_LOG_WARNING, "failed to load bd_nvme_disconnect: %s", error);
1288 :
1289 3 : dlerror();
1290 3 : * (void**) (&_bd_nvme_disconnect_by_path) = dlsym(handle, "bd_nvme_disconnect_by_path");
1291 3 : if ((error = dlerror()) != NULL)
1292 0 : bd_utils_log_format (BD_UTILS_LOG_WARNING, "failed to load bd_nvme_disconnect_by_path: %s", error);
1293 :
1294 3 : dlerror();
1295 3 : * (void**) (&_bd_nvme_find_ctrls_for_ns) = dlsym(handle, "bd_nvme_find_ctrls_for_ns");
1296 3 : if ((error = dlerror()) != NULL)
1297 0 : bd_utils_log_format (BD_UTILS_LOG_WARNING, "failed to load bd_nvme_find_ctrls_for_ns: %s", error);
1298 :
1299 3 : return handle;
1300 : }
1301 :
1302 3 : static gboolean unload_nvme (gpointer handle) {
1303 3 : char *error = NULL;
1304 3 : gboolean (*close_fn) (void) = NULL;
1305 :
1306 3 : _bd_nvme_is_tech_avail = bd_nvme_is_tech_avail_stub;
1307 3 : _bd_nvme_self_test_result_to_string = bd_nvme_self_test_result_to_string_stub;
1308 3 : _bd_nvme_get_controller_info = bd_nvme_get_controller_info_stub;
1309 3 : _bd_nvme_get_namespace_info = bd_nvme_get_namespace_info_stub;
1310 3 : _bd_nvme_get_smart_log = bd_nvme_get_smart_log_stub;
1311 3 : _bd_nvme_get_error_log_entries = bd_nvme_get_error_log_entries_stub;
1312 3 : _bd_nvme_get_self_test_log = bd_nvme_get_self_test_log_stub;
1313 3 : _bd_nvme_get_sanitize_log = bd_nvme_get_sanitize_log_stub;
1314 3 : _bd_nvme_device_self_test = bd_nvme_device_self_test_stub;
1315 3 : _bd_nvme_format = bd_nvme_format_stub;
1316 3 : _bd_nvme_sanitize = bd_nvme_sanitize_stub;
1317 3 : _bd_nvme_get_host_nqn = bd_nvme_get_host_nqn_stub;
1318 3 : _bd_nvme_generate_host_nqn = bd_nvme_generate_host_nqn_stub;
1319 3 : _bd_nvme_get_host_id = bd_nvme_get_host_id_stub;
1320 3 : _bd_nvme_set_host_nqn = bd_nvme_set_host_nqn_stub;
1321 3 : _bd_nvme_set_host_id = bd_nvme_set_host_id_stub;
1322 3 : _bd_nvme_connect = bd_nvme_connect_stub;
1323 3 : _bd_nvme_disconnect = bd_nvme_disconnect_stub;
1324 3 : _bd_nvme_disconnect_by_path = bd_nvme_disconnect_by_path_stub;
1325 3 : _bd_nvme_find_ctrls_for_ns = bd_nvme_find_ctrls_for_ns_stub;
1326 :
1327 3 : dlerror();
1328 3 : * (void**) (&close_fn) = dlsym(handle, "bd_nvme_close");
1329 3 : if (((error = dlerror()) != NULL) || !close_fn)
1330 0 : bd_utils_log_format (BD_UTILS_LOG_DEBUG, "failed to load the close_plugin() function for nvme: %s", error);
1331 : /* coverity[dead_error_condition] */
1332 3 : if (close_fn) {
1333 3 : close_fn();
1334 : }
1335 :
1336 3 : return dlclose(handle) == 0;
1337 : }
1338 :
|