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