]> www.infradead.org Git - users/sagi/libnvme.git/commitdiff
minor updates
authorKeith Busch <kbusch@kernel.org>
Fri, 29 May 2020 16:33:42 +0000 (09:33 -0700)
committerKeith Busch <kbusch@kernel.org>
Fri, 29 May 2020 16:33:42 +0000 (09:33 -0700)
A collection of updates including:

  Naming consistency improvements

  Namespace descriptor attributes added to namespace elements

  Doc updates to use more consise descriptions

Signed-off-by: Keith Busch <kbusch@kernel.org>
src/nvme/ioctl.c
src/nvme/ioctl.h
src/nvme/tree.c
src/nvme/tree.h
src/nvme/types.h
test/Makefile
test/test.c

index 28aee2d3cf8369d29f4a2175db6e787bdbe4f1b1..2c3a12163de24e6a18df47b699dcb4a464262d80 100644 (file)
@@ -1645,8 +1645,8 @@ int nvme_dsm(int fd, __u32 nsid, __u32 attrs, __u16 nr_ranges,
        return nvme_submit_io_passthru(fd, &cmd, NULL);
 }
 
-int nvme_resv_acquire(int fd, __u32 nsid, enum nvme_reservation_rtype rtype,
-                     enum nvme_reservation_racqa racqa, bool iekey,
+int nvme_resv_acquire(int fd, __u32 nsid, enum nvme_resv_rtype rtype,
+                     enum nvme_resv_racqa racqa, bool iekey,
                      __u64 crkey, __u64 nrkey)
 {
        __le64 payload[2] = { cpu_to_le64(crkey), cpu_to_le64(nrkey) };
@@ -1663,8 +1663,8 @@ int nvme_resv_acquire(int fd, __u32 nsid, enum nvme_reservation_rtype rtype,
        return nvme_submit_io_passthru(fd, &cmd, NULL);
 }
 
-int nvme_resv_register(int fd, __u32 nsid, enum nvme_reservation_rrega rrega,
-                      enum nvme_reservation_cptpl cptpl, bool iekey,
+int nvme_resv_register(int fd, __u32 nsid, enum nvme_resv_rrega rrega,
+                      enum nvme_resv_cptpl cptpl, bool iekey,
                       __u64 crkey, __u64 nrkey)
 {
        __le64 payload[2] = { cpu_to_le64(crkey), cpu_to_le64(nrkey) };
@@ -1681,8 +1681,8 @@ int nvme_resv_register(int fd, __u32 nsid, enum nvme_reservation_rrega rrega,
        return nvme_submit_io_passthru(fd, &cmd, NULL);
 }
 
-int nvme_resv_release(int fd, __u32 nsid, enum nvme_reservation_rtype rtype,
-                     enum nvme_reservation_rrela rrela, bool iekey,
+int nvme_resv_release(int fd, __u32 nsid, enum nvme_resv_rtype rtype,
+                     enum nvme_resv_rrela rrela, bool iekey,
                      __u64 crkey)
 {
        __le64 payload[1] = { cpu_to_le64(crkey) };
@@ -1700,7 +1700,7 @@ int nvme_resv_release(int fd, __u32 nsid, enum nvme_reservation_rtype rtype,
 }
 
 int nvme_resv_report(int fd, __u32 nsid, bool eds, __u32 len,
-                    struct nvme_reservation_status *report)
+                    struct nvme_resv_status *report)
 {
        struct nvme_passthru_cmd cmd = {
                .opcode         = nvme_cmd_resv_report,
index 445468b042723d82d1bea9aabe29c62760064c20..77ad9a3631a25105ba3f7624701f00819cb4cca5 100644 (file)
@@ -939,9 +939,9 @@ int nvme_identify_nvmset_list(int fd, __u16 nvmsetid,
 /**
  * nvme_identify_primary_ctrl() - Retrieve NVMe Primary Controller
  *                               identification
- * &fd:
- * @cntid:
- * @cap:
+ * @fd:                File descriptor of nvme device
+ * @cntid:     Return controllers starting at this identifier
+ * @cap:       User space destination buffer address to transfer the data
  *
  * See &struct nvme_primary_ctrl_cap for the defintion of the returned structure, @cap.
  *
@@ -1006,10 +1006,11 @@ int nvme_identify_uuid(int fd, struct nvme_id_uuid_list *list);
 
 /**
  * nvme_get_log() - NVMe Admin Get Log command
- * @fd:          File descriptor of nvme device
- * @lid:  Log page identifier, see &enum nvme_cmd_get_log_lid for known values
- * @nsid:  Namespace identifier, if applicable
- * @lpo:   Log page offset for partial log transfers
+ * @fd:                File descriptor of nvme device
+ * @lid:       Log page identifier, see &enum nvme_cmd_get_log_lid for known
+ *             values
+ * @nsid:      Namespace identifier, if applicable
+ * @lpo:       Log page offset for partial log transfers
  * @lsp:   Log specific field
  * @lsi:   Endurance group information
  * @rae:   Retain asynchronous events
@@ -1030,8 +1031,8 @@ int nvme_get_log(int fd, enum nvme_cmd_get_log_lid lid, __u32 nsid, __u64 lpo,
  * @rae:       Retain asynchronous events
  * @err_log:   Array of error logs of size 'entries'
  *
- * This log page is used to describe extended error information for a command
- * that completed with error, or may report an error that is not specific to a
+ * This log page describes extended error information for a command that
+ * completed with error, or may report an error that is not specific to a
  * particular command.
  *
  * Return: The nvme command status if a response was received (see
@@ -1047,12 +1048,12 @@ int nvme_get_log_error(int fd, unsigned nr_entries, bool rae,
  * @rae:       Retain asynchronous events
  * @smart_log: User address to store the smart log
  *
- * This log page is used to provide SMART and general health information. The
- * information provided is over the life of the controller and is retained
- * across power cycles. To request the controller log page, the namespace
- * identifier specified is FFFFFFFFh. The controller may also support
- * requesting the log page on a per namespace basis, as indicated by bit 0 of
- * the LPA field in the Identify Controller data structure.
+ * This log page provides SMART and general health information. The information
+ * provided is over the life of the controller and is retained across power
+ * cycles. To request the controller log page, the namespace identifier
+ * specified is FFFFFFFFh. The controller may also support requesting the log
+ * page on a per namespace basis, as indicated by bit 0 of the LPA field in the
+ * Identify Controller data structure.
  *
  * Return: The nvme command status if a response was received (see
  * &enum nvme_status_field) or -1 with errno set otherwise.
@@ -1065,9 +1066,9 @@ int nvme_get_log_smart(int fd, __u32 nsid, bool rae, struct nvme_smart_log *log)
  * @rae:       Retain asynchronous events
  * @fw_log:    User address to store the log page
  *
- * This log page is used to describe the firmware revision stored in each
- * firmware slot supported. The firmware revision is indicated as an ASCII
- * string. The log page also indicates the active slot number.
+ * This log page describes the firmware revision stored in each firmware slot
+ * supported. The firmware revision is indicated as an ASCII string. The log
+ * page also indicates the active slot number.
  *
  * Return: The nvme command status if a response was received (see
  * &enum nvme_status_field) or -1 with errno set otherwise.
@@ -1080,9 +1081,9 @@ int nvme_get_log_fw_slot(int fd, bool rae, struct nvme_firmware_slot *log);
  * @rae:       Retain asynchronous events
  * @ns_list:   User address to store the log page
  *
- * This log page is used to describe namespaces attached to this controller
- * that have changed since the last time the namespace was identified, been
- * added, or deleted.
+ * This log page describes namespaces attached to this controller that have
+ * changed since the last time the namespace was identified, been added, or
+ * deleted.
  *
  * Return: The nvme command status if a response was received (see
  * &enum nvme_status_field) or -1 with errno set otherwise.
@@ -1094,8 +1095,8 @@ int nvme_get_log_changed_ns_list(int fd, bool rae, struct nvme_ns_list *log);
  * @fd:                File descriptor of nvme device
  * @effects_log:User address to store the effects log
  *
- * This log page is used to describe the commands that the controller supports
- * and the effects of those commands on the state of the NVM subsystem.
+ * This log page describes the commands that the controller supports and the
+ * effects of those commands on the state of the NVM subsystem.
  *
  * Return: The nvme command status if a response was received (see
  * &enum nvme_status_field) or -1 with errno set otherwise.
@@ -1108,8 +1109,8 @@ int nvme_get_log_cmd_effects(int fd, struct nvme_cmd_effects_log *log);
  * @nsid:      Namespace ID being tested
  * @log:       Userspace address of the log payload
  *
- * The log page is used to indicate the status of an in progress self test and
- * the percent complete of that operation, and the results of the previous 20
+ * The log page indicates the status of an in progress self test and the
+ * percent complete of that operation, and the results of the previous 20
  * self-test operations.
  *
  * Return: The nvme command status if a response was received (see
@@ -1272,8 +1273,8 @@ int nvme_get_log_reservation(int fd, bool rae,
  * @rae:       Retain asynchronous events
  * @log:       User address to store the sanitize log
  *
- * The Sanitize Status log page is used to report sanitize operation time
- * estimates and information about the most recent sanitize operation.
+ * The Sanitize Status log page reports sanitize operation time estimates and
+ * information about the most recent sanitize operation.
  *
  * Return: The nvme command status if a response was received (see
  * &enum nvme_status_field) or -1 with errno set otherwise.
@@ -1338,7 +1339,6 @@ int nvme_set_features_power_mgmt(int fd, __u8 ps, __u8 wh, bool save,
 int nvme_set_features_lba_range(int fd, __u32 nsid, __u32 nr_ranges, bool save,
                                struct nvme_lba_range_type *data, __u32 *result);
 
-
 /**
  * enum nvme_feat_tmpthresh_thsel -
  */
@@ -1372,7 +1372,6 @@ int nvme_set_features_temp_thresh(int fd, __u16 tmpth, __u8 tmpsel,
 int nvme_set_features_err_recovery(int fd, __u32 nsid, __u16 tler,
                                   bool dulbe, bool save, __u32 *result);
 
-
 /**
  * nvme_set_features_volatile_wc() -
  * @fd:                File descriptor of nvme device
@@ -1409,7 +1408,6 @@ int nvme_set_features_irq_coalesce(int fd, __u8 thr, __u8 time,
 int nvme_set_features_irq_config(int fd, __u16 iv, bool cd, bool save,
                                 __u32 *result);
 
-
 /**
  * nvme_set_features_write_atomic() -
  * @fd:                File descriptor of nvme device
@@ -1454,7 +1452,6 @@ enum nvme_features_async_event_config_flags {
 int nvme_set_features_async_event(int fd, __u32 events, bool save,
                                  __u32 *result);
 
-
 /**
  * nvme_set_features_auto_pst() -
  * @fd:                File descriptor of nvme device
@@ -1479,7 +1476,6 @@ int nvme_set_features_auto_pst(int fd, bool apste, bool save,
  */
 int nvme_set_features_timestamp(int fd, bool save, __u64 timestamp);
 
-
 /**
  * nvme_set_features_hctm() -
  * @fd:                File descriptor of nvme device
@@ -1494,6 +1490,12 @@ int nvme_set_features_hctm(int fd, __u16 tmt2, __u16 tmt1, bool save,
 
 /**
  * nvme_set_features_nopsc() -
+ * @fd:                File descriptor of nvme device
+ * @save:      Save value across power states
+ * @result:    The command completion result from CQE dword0
+ *
+ * Return: The nvme command status if a response was received (see
+ * &enum nvme_status_field) or -1 with errno set otherwise.
  */
 int nvme_set_features_nopsc(int fd, bool noppme, bool save, __u32 *result);
 
@@ -1542,7 +1544,6 @@ enum nvme_feat_plm_window_select {
 int nvme_set_features_plm_window(int fd, enum nvme_feat_plm_window_select sel,
                                 __u16 nvmsetid, bool save, __u32 *result);
 
-
 /**
  * nvme_set_features_lba_sts_interval() -
  * @fd:                File descriptor of nvme device
@@ -1555,11 +1556,11 @@ int nvme_set_features_plm_window(int fd, enum nvme_feat_plm_window_select sel,
 int nvme_set_features_lba_sts_interval(int fd, __u16 lsiri, __u16 lsipi,
                                       bool save, __u32 *result);
 
-
 /**
  * nvme_set_features_host_behavior() -
  * @fd:                File descriptor of nvme device
  * @save:      Save value across power states
+ * @data:      
  *
  * Return: The nvme command status if a response was received (see
  * &enum nvme_status_field) or -1 with errno set otherwise.
@@ -1570,6 +1571,7 @@ int nvme_set_features_host_behavior(int fd, bool save,
 /**
  * nvme_set_features_sanitize() -
  * @fd:                File descriptor of nvme device
+ * @nodrm:     
  * @save:      Save value across power states
  * @result:    The command completion result from CQE dword0
  *
@@ -1595,6 +1597,7 @@ int nvme_set_features_endurance_evt_cfg(int fd, __u16 endgid, __u8 egwarn,
 /**
  * nvme_set_features_sw_progress() -
  * @fd:                File descriptor of nvme device
+ * @pbslc:     
  * @save:      Save value across power states
  * @result:    The command completion result from CQE dword0
  *
@@ -1608,6 +1611,7 @@ int nvme_set_features_sw_progress(int fd, __u8 pbslc, bool save,
 /**
  * nvme_set_features_host_id() -
  * @fd:                File descriptor of nvme device
+ * @exhid:     
  * @save:      Save value across power states
  * @result:    The command completion result from CQE dword0
  *
@@ -1628,6 +1632,7 @@ enum nvme_feat_resv_notify_flags {
 /**
  * nvme_set_features_resv_mask() -
  * @fd:                File descriptor of nvme device
+ * @mask:      
  * @save:      Save value across power states
  * @result:    The command completion result from CQE dword0
  *
@@ -1639,6 +1644,7 @@ int nvme_set_features_resv_mask(int fd, __u32 mask, bool save, __u32 *result);
 /**
  * nvme_set_features_resv_persist() -
  * @fd:                File descriptor of nvme device
+ * @ptpl:      
  * @save:      Save value across power states
  * @result:    The command completion result from CQE dword0
  *
@@ -1664,6 +1670,7 @@ enum nvme_feat_nswpcfg_state {
 /**
  * nvme_set_features_write_protect() -
  * @fd:                File descriptor of nvme device
+ * @stat:      
  * @save:      Save value across power states
  * @result:    The command completion result from CQE dword0
  *
@@ -2054,10 +2061,10 @@ int nvme_get_features_write_protect(int fd, __u32 nsid,
  * @timeout:   Set to override default timeout to this value in milliseconds;
  *             useful for long running formats. 0 will use system default.
  *
- * The Format NVM command is used to low level format the NVM media. This
- * command is used by the host to change the LBA data size and/or metadata
- * size. A low level format may destroy all data and metadata associated with
- * all namespaces or only the specific namespace associated with the command
+ * The Format NVM command low level formats the NVM media. This command is used
+ * by the host to change the LBA data size and/or metadata size. A low level
+ * format may destroy all data and metadata associated with all namespaces or
+ * only the specific namespace associated with the command
  *
  * Return: The nvme command status if a response was received (see
  * &enum nvme_status_field) or -1 with errno set otherwise.
@@ -2142,9 +2149,9 @@ int nvme_ns_detach_ctrls(int fd, __u32 nsid, struct nvme_ctrl_list *ctrlist);
  * @data_len:  Length of data in this command in bytes
  * @data:      Userspace address of the firmware data
  *
- * The Firmware Image Download command is used to download all or a portion of
- * an image for a future update to the controller. The Firmware Image Download
- * command downloads a new image (in whole or in part) to the controller.
+ * The Firmware Image Download command downloads all or a portion of an image
+ * for a future update to the controller. The Firmware Image Download command
+ * downloads a new image (in whole or in part) to the controller.
  *
  * The image may be constructed of multiple pieces that are individually
  * downloaded with separate Firmware Image Download commands. Each Firmware
@@ -2167,8 +2174,7 @@ int nvme_fw_download(int fd, __u32 offset, __u32 data_len, void *data);
  * @action:    Action to use for the firmware image, see &enum nvme_fw_commit_ca
  * @bpid:      Set to true to select the boot partition id
  *
- * The Firmware Commit command is used to modify the firmware image or Boot
- * Partitions.
+ * The Firmware Commit command modifies the firmware image or Boot Partitions.
  *
  * Return: The nvme command status if a response was received (see
  * &enum nvme_status_field) or -1 with errno set otherwise. The command
@@ -2191,7 +2197,7 @@ int nvme_fw_commit(int fd, __u8 slot, enum nvme_fw_commit_ca action, bool bpid);
  * @data:      Security data payload to send
  * @result:    The command completion result from CQE dword0
  *
- * The Security Send command is used to transfer security protocol data to the
+ * The Security Send command transfers security protocol data to the
  * controller. The data structure transferred to the controller as part of this
  * command contains security protocol specific commands to be performed by the
  * controller. The data structure transferred may also contain data or
@@ -2261,8 +2267,8 @@ int nvme_get_lba_status(int fd, __u32 nsid, __u64 slba, __u32 mndw, __u16 rl,
  * @result:    If successful, the CQE dword0 value
  *
  * Directives is a mechanism to enable host and NVM subsystem or controller
- * information exchange. The Directive Send command is used to transfer data
- * related to a specific Directive Type from the host to the controller.
+ * information exchange. The Directive Send command transfers data related to a
+ * specific Directive Type from the host to the controller.
  *
  * See the NVMe specification for more information.
  *
@@ -2431,11 +2437,11 @@ int nvme_get_property(int fd, int offset, __u64 *value);
  * recovery of any previous user data from any cache, the non-volatile media,
  * or any Controller Memory Buffer is not possible.
  *
- * The Sanitize command is used to start a sanitize operation or to recover
- * from a previously failed sanitize operation. The sanitize operation types
- * that may be supported are Block Erase, Crypto Erase, and Overwrite. All
- * sanitize operations are processed in the background, i.e., completion of the
- * sanitize command does not indicate completion of the sanitize operation.
+ * The Sanitize command starts a sanitize operation or to recover from a
+ * previously failed sanitize operation. The sanitize operation types that may
+ * be supported are Block Erase, Crypto Erase, and Overwrite. All sanitize
+ * operations are processed in the background, i.e., completion of the sanitize
+ * command does not indicate completion of the sanitize operation.
  *
  * Return: The nvme command status if a response was received (see
  * &enum nvme_status_field) or -1 with errno set otherwise.
@@ -2449,12 +2455,12 @@ int nvme_sanitize_nvm(int fd, enum nvme_sanitize_sanact sanact, bool ause,
  * @nsid:      Namespace ID to test
  * @stc:       Self test code, see &enum nvme_dst_stc
  *
- * The Device Self-test command is used to start a device self-test operation
- * or abort a device self-test operation. A device self-test operation is a
- * diagnostic testing sequence that tests the integrity and functionality of
- * the controller and may include testing of the media associated with
- * namespaces. The controller may return a response to this command immediately
- * while running the self-test in the background.
+ * The Device Self-test command starts a device self-test operation or abort a
+ * device self-test operation. A device self-test operation is a diagnostic
+ * testing sequence that tests the integrity and functionality of the
+ * controller and may include testing of the media associated with namespaces.
+ * The controller may return a response to this command immediately while
+ * running the self-test in the background.
  *
  * Set the 'nsid' field to 0 to not include namepsaces in the test. Set to
  * 0xffffffff to test all namespaces. All other values tests a specific
@@ -2524,8 +2530,8 @@ enum nvme_io_opcode {
  * @fd:                File descriptor of nvme device
  * @nsid:      Namespace identifier
  *
- * The Flush command is used to request that the contents of volatile write
- * cache be made non-volatile.
+ * The Flush command requests that the contents of volatile write cache be made
+ * non-volatile.
  *
  * Return: The nvme command status if a response was received (see
  * &enum nvme_status_field) or -1 with errno set otherwise.
@@ -2695,10 +2701,10 @@ int nvme_compare(int fd, __u32 nsid, __u64 slba, __u16 nlb, __u16 control,
  *             only if the namespace is formatted to use end-to-end protection
  *             information.
  *
- * The Write Zeroes command is used to set a range of logical blocks to zero.
- * After successful completion of this command, the value returned by
- * subsequent reads of logical blocks in this range shall be all bytes cleared
- * to 0h until a write occurs to this LBA range.
+ * The Write Zeroes command sets a range of logical blocks to zero.  After
+ * successful completion of this command, the value returned by subsequent
+ * reads of logical blocks in this range shall be all bytes cleared to 0h until
+ * a write occurs to this LBA range.
  *
  * Return: The nvme command status if a response was received (see
  * &enum nvme_status_field) or -1 with errno set otherwise.
@@ -2713,11 +2719,10 @@ int nvme_write_zeros(int fd, __u32 nsid, __u64 slba, __u16 nlb, __u16 control,
  * @slba:      Starting logical block
  * @nlb:       Number of logical blocks to invalidate (0's based value)
  *
- * The Write Uncorrectable command is used to mark a range of logical blocks as
- * invalid. When the specified logical block(s) are read after this operation,
- * a failure is returned with Unrecovered Read Error status. To clear the
- * invalid logical block status, a write operation on those logical blocks is
- * required.
+ * The Write Uncorrectable command marks a range of logical blocks as invalid.
+ * When the specified logical block(s) are read after this operation, a failure
+ * is returned with Unrecovered Read Error status. To clear the invalid logical
+ * block status, a write operation on those logical blocks is required.
  *
  * Return: The nvme command status if a response was received (see
  * &enum nvme_status_field) or -1 with errno set otherwise.
@@ -2784,7 +2789,7 @@ int nvme_dsm(int fd, __u32 nsid, __u32 attrs, __u16 nr_ranges,
             struct nvme_dsm_range *dsm);
 
 /**
- * enum nvme_reservation_rtype -
+ * enum nvme_resv_rtype -
  * @NVME_RESERVATION_RTYPE_WE:
  * @NVME_RESERVATION_RTYPE_EA:
  * @NVME_RESERVATION_RTYPE_WERO:
@@ -2792,7 +2797,7 @@ int nvme_dsm(int fd, __u32 nsid, __u32 attrs, __u16 nr_ranges,
  * @NVME_RESERVATION_RTYPE_WEAR:
  * @NVME_RESERVATION_RTYPE_EAAR:
  */
-enum nvme_reservation_rtype {
+enum nvme_resv_rtype {
        NVME_RESERVATION_RTYPE_WE       = 1,
        NVME_RESERVATION_RTYPE_EA       = 2,
        NVME_RESERVATION_RTYPE_WERO     = 3,
@@ -2802,12 +2807,12 @@ enum nvme_reservation_rtype {
 };
 
 /**
- * enum nvme_reservation_racqa -
+ * enum nvme_resv_racqa -
  * @NVME_RESERVATION_RACQA_ACQUIRE:
  * @NVME_RESERVATION_RACQA_PREEMPT:
  * @NVME_RESERVATION_RACQA_PREEMPT_AND_ABORT:
  */
-enum nvme_reservation_racqa {
+enum nvme_resv_racqa {
        NVME_RESERVATION_RACQA_ACQUIRE                  = 0,
        NVME_RESERVATION_RACQA_PREEMPT                  = 1,
        NVME_RESERVATION_RACQA_PREEMPT_AND_ABORT        = 2,
@@ -2817,43 +2822,43 @@ enum nvme_reservation_racqa {
  * nvme_resv_acquire() - Send an nvme reservation acquire
  * @fd:                File descriptor of nvme device
  * @nsid:      Namespace identifier
- * @rtype:     The type of reservation to be create, see &enum nvme_reservation_rtype
- * @racqa:     The action that is performed by the command, see &enum nvme_reservation_racqa
+ * @rtype:     The type of reservation to be create, see &enum nvme_resv_rtype
+ * @racqa:     The action that is performed by the command, see &enum nvme_resv_racqa
  * @iekey:     Set to ignore the existing key
  * @crkey:     The current reservation key associated with the host
  * @nrkey:     The reservation key to be unregistered from the namespace if
  *             the action is preempt
  *
- * The Reservation Acquire command is used to acquire a reservation on a
- * namespace, preempt a reservation held on a namespace, and abort a
- * reservation held on a namespace.
+ * The Reservation Acquire command acquires a reservation on a namespace,
+ * preempt a reservation held on a namespace, and abort a reservation held on a
+ * namespace.
  *
  * Return: The nvme command status if a response was received (see
  * &enum nvme_status_field) or -1 with errno set otherwise.
  */
-int nvme_resv_acquire(int fd, __u32 nsid, enum nvme_reservation_rtype rtype,
-                     enum nvme_reservation_racqa racqa, bool iekey,
+int nvme_resv_acquire(int fd, __u32 nsid, enum nvme_resv_rtype rtype,
+                     enum nvme_resv_racqa racqa, bool iekey,
                      __u64 crkey, __u64 nrkey);
 
 /**
- * enum nvme_reservation_rrega -
+ * enum nvme_resv_rrega -
  * @NVME_RESERVATION_RREGA_REGISTER_KEY:
  * @NVME_RESERVATION_RREGA_UNREGISTER_KEY:
  * @NVME_RESERVATION_RREGA_REPLACE_KEY:
  */
-enum nvme_reservation_rrega {
+enum nvme_resv_rrega {
        NVME_RESERVATION_RREGA_REGISTER_KEY             = 0,
        NVME_RESERVATION_RREGA_UNREGISTER_KEY           = 1,
        NVME_RESERVATION_RREGA_REPLACE_KEY              = 2,
 };
 
 /**
- * enum nvme_reservation_cptpl -
+ * enum nvme_resv_cptpl -
  * @NVME_RESERVATION_CPTPL_NO_CHANGE:
  * @NVME_RESERVATION_CPTPL_CLEAR:
  * @NVME_RESERVATION_CPTPL_PERSIST:
  */
-enum nvme_reservation_cptpl {
+enum nvme_resv_cptpl {
        NVME_RESERVATION_CPTPL_NO_CHANGE                = 0,
        NVME_RESERVATION_CPTPL_CLEAR                    = 2,
        NVME_RESERVATION_CPTPL_PERSIST                  = 3,
@@ -2863,29 +2868,29 @@ enum nvme_reservation_cptpl {
  * nvme_resv_register() - Send an nvme reservation register
  * @fd:                File descriptor of nvme device
  * @nsid:      Namespace identifier
- * @rrega:     The registration action, see &enum nvme_reservation_rrega
- * @cptpl:     Change persist through power loss, see &enum nvme_reservation_cptpl
+ * @rrega:     The registration action, see &enum nvme_resv_rrega
+ * @cptpl:     Change persist through power loss, see &enum nvme_resv_cptpl
  * @iekey:     Set to ignore the existing key
  * @crkey:     The current reservation key associated with the host
  * @nrkey:     The new reservation key to be register if action is register or
  *             replace
  *
- * The Reservation Register command is used to register, unregister, or replace
- * reservation key.
+ * The Reservation Register command registers, unregisters, or replaces a
+ * reservation key.
  *
  * Return: The nvme command status if a response was received (see
  * &enum nvme_status_field) or -1 with errno set otherwise.
  */
-int nvme_resv_register(int fd, __u32 nsid, enum nvme_reservation_rrega rrega,
-                      enum nvme_reservation_cptpl cptpl, bool iekey,
+int nvme_resv_register(int fd, __u32 nsid, enum nvme_resv_rrega rrega,
+                      enum nvme_resv_cptpl cptpl, bool iekey,
                       __u64 crkey, __u64 nrkey);
 
 /**
- * enum nvme_reservation_rrela -
+ * enum nvme_resv_rrela -
  * @NVME_RESERVATION_RRELA_RELEASE:
  * @NVME_RESERVATION_RRELA_CLEAR:
  */
-enum nvme_reservation_rrela {
+enum nvme_resv_rrela {
        NVME_RESERVATION_RRELA_RELEASE                  = 0,
        NVME_RESERVATION_RRELA_CLEAR                    = 1
 };
@@ -2894,16 +2899,16 @@ enum nvme_reservation_rrela {
  * nvme_resv_release() - Send an nvme reservation release
  * @fd:                File descriptor of nvme device
  * @nsid:      Namespace identifier
- * @rtype:     The type of reservation to be create, see &enum nvme_reservation_rtype
- * @rrela:     Reservation releast action, see &enum  nvme_reservation_rrela
+ * @rtype:     The type of reservation to be create, see &enum nvme_resv_rtype
+ * @rrela:     Reservation releast action, see &enum nvme_resv_rrela
  * @iekey:     Set to ignore the existing key
  * @crkey:     The current reservation key to release
  *
  * Return: The nvme command status if a response was received (see
  * &enum nvme_status_field) or -1 with errno set otherwise.
  */
-int nvme_resv_release(int fd, __u32 nsid, enum nvme_reservation_rtype rtype,
-                     enum nvme_reservation_rrela rrela, bool iekey,
+int nvme_resv_release(int fd, __u32 nsid, enum nvme_resv_rtype rtype,
+                     enum nvme_resv_rrela rrela, bool iekey,
                      __u64 crkey);
 
 /**
@@ -2922,5 +2927,5 @@ int nvme_resv_release(int fd, __u32 nsid, enum nvme_reservation_rtype rtype,
  * &enum nvme_status_field) or -1 with errno set otherwise.
  */
 int nvme_resv_report(int fd, __u32 nsid, bool eds, __u32 len,
-                    struct nvme_reservation_status *report);
+                    struct nvme_resv_status *report);
 #endif /* _LIBNVME_IOCTL_H */
index d850aa73cf3ae8b7a00ab1aae436261872460cdc..620b74d8b5ce4699b625057d7e151160bec9cc56 100644 (file)
@@ -18,6 +18,8 @@
 
 #include <ccan/list/list.h>
 
+#include <uuid/uuid.h>
+
 #include "ioctl.h"
 #include "filters.h"
 #include "tree.h"
@@ -48,15 +50,19 @@ struct nvme_ns {
        struct nvme_ctrl *c;
 
        int fd;
+       int nsid;
        char *name;
        char *sysfs_dir;
-       int nsid;
 
        int lba_shift;
        int lba_size;
        int meta_size;
        uint64_t lba_count;
        uint64_t lba_util;
+
+       uint8_t eui64[8];
+       uint8_t nguid[16];
+       uuid_t  uuid;
 };
 
 struct nvme_ctrl {
@@ -357,7 +363,7 @@ void nvme_free_path(struct nvme_path *p)
 
 static void nvme_subsystem_set_path_ns(nvme_subsystem_t s, nvme_path_t p)
 {
-       char n_name[32] = { };
+       char n_name[32] = { };
        int i, c, nsid, ret;
        nvme_ns_t n;
 
@@ -720,11 +726,31 @@ uint64_t nvme_ns_get_lba_util(nvme_ns_t n)
        return n->lba_util;
 }
 
+const uint8_t *nvme_ns_get_eui64(nvme_ns_t n)
+{
+       return n->eui64;
+}
+
+const uint8_t *nvme_ns_get_nguid(nvme_ns_t n)
+{
+       return n->nguid;
+}
+
+void nvme_ns_get_uuid(nvme_ns_t n, uuid_t out)
+{
+       uuid_copy(out, n->uuid);
+}
+
 int nvme_ns_identify(nvme_ns_t n, struct nvme_id_ns *ns)
 {
        return nvme_identify_ns(nvme_ns_get_fd(n), nvme_ns_get_nsid(n), ns);
 }
 
+int nvme_ns_identify_descs(nvme_ns_t n, struct nvme_ns_id_desc *descs)
+{
+       return nvme_identify_ns_descs(nvme_ns_get_fd(n), nvme_ns_get_nsid(n), descs);
+}
+
 int nvme_ns_verify(nvme_ns_t n, off_t offset, size_t count)
 {
        __u64 slba;
@@ -802,9 +828,38 @@ int nvme_ns_flush(nvme_ns_t n)
        return nvme_flush(nvme_ns_get_fd(n), nvme_ns_get_nsid(n));
 }
 
+static void nvme_ns_parse_descriptors(struct nvme_ns *n,
+                                     struct nvme_ns_id_desc *descs)
+{
+       void *d = descs;
+       int i, len;
+
+       for (i = 0; i < NVME_IDENTIFY_DATA_SIZE; i += len) {
+               struct nvme_ns_id_desc *desc = d + i;
+
+               if (!desc->nidl)
+                       break;
+               len = desc->nidl + sizeof(*desc);
+
+               switch (desc->nidt) {
+               case NVME_NIDT_EUI64:
+                       memcpy(n->eui64, desc->nid, sizeof(n->eui64));
+                       break;
+               case NVME_NIDT_NGUID:
+                       memcpy(n->nguid, desc->nid, sizeof(n->nguid));
+                       break;
+               case NVME_NIDT_UUID:
+                       memcpy(n->uuid, desc->nid, sizeof(n->uuid));
+                       break;
+               }
+       }
+}
+
 static void nvme_ns_init(struct nvme_ns *n)
 {
-       struct nvme_id_ns ns = { 0 };
+       struct nvme_id_ns ns = { };
+       uint8_t buffer[NVME_IDENTIFY_DATA_SIZE] = { };
+       struct nvme_ns_id_desc *descs = (void *)buffer;
 
        if (nvme_ns_identify(n, &ns) != 0)
                return;
@@ -813,8 +868,10 @@ static void nvme_ns_init(struct nvme_ns *n)
        n->lba_size = 1 << n->lba_shift;
        n->lba_count = le64_to_cpu(ns.nsze);
        n->lba_util = le64_to_cpu(ns.nuse);
-}
 
+       if (!nvme_ns_identify_descs(n, descs))
+               nvme_ns_parse_descriptors(n, descs);
+}
 
 nvme_ns_t nvme_ns_open(char *name)
 {
index 6cce9224472664dad35d6d86f425fdf52401e875..b8e66fc4d7f59a3efc69af6fa549325ab512c4b5 100644 (file)
@@ -15,6 +15,8 @@
 
 #include <sys/types.h>
 
+#include <uuid/uuid.h>
+
 #include "ioctl.h"
 #include "util.h"
 
@@ -262,6 +264,31 @@ uint64_t nvme_ns_get_lba_count(nvme_ns_t n);
  */
 uint64_t nvme_ns_get_lba_util(nvme_ns_t n);
 
+/**
+ * nvme_ns_get_eui64() -
+ * @n:
+ *
+ * Returns a pointer to the 64-bit eui
+ */
+const uint8_t *nvme_ns_get_eui64(nvme_ns_t n);
+
+/**
+ * nvme_ns_get_nguid() -
+ * @n:
+ *
+ * Returns a pointer to the 128-bit nguid
+ */
+const uint8_t *nvme_ns_get_nguid(nvme_ns_t n);
+
+/**
+ * nvme_ns_get_uuid() -
+ * @n:
+ * @out:
+ *
+ * Copies the namespace's uuid to the destination buffer
+ */
+void nvme_ns_get_uuid(nvme_ns_t n, uuid_t out);
+
 /**
  * nvme_ns_get_sysfs_dir() -
  * @n:
@@ -374,6 +401,15 @@ int nvme_ns_flush(nvme_ns_t n);
  */
 int nvme_ns_identify(nvme_ns_t n, struct nvme_id_ns *ns);
 
+/**
+ * nvme_ns_identify_descs() -
+ * @n:
+ * @descs:
+ *
+ * Return: 
+ */
+int nvme_ns_identify_descs(nvme_ns_t n, struct nvme_ns_id_desc *descs);
+
 /**
  * nvme_path_get_name() -
  * @p:
index b10737c961db22f90a286ca102c7ddda86d55ea8..31fe5faccfcbb1b062f89bad8522d290e03511bf 100644 (file)
 #define __force
 #endif
 
+/**
+ * NVME_GET() - extract field from complex value
+ * @name: The name of the sub-field within an nvme value
+ * @value: The original value of a complex field
+ *
+ * By convention, this library defines _SHIFT and _MASK such that mask can be
+ * applied after the shift to isolate a specific set of bits that decode to a
+ * sub-field.
+ *
+ * Returns: The 'name' field from 'value'
+ */
+#define NVME_GET(name, value) \
+       (((value) >> NVME_##name##_SHIFT) & NVME_##name##_MASK)
+
 /**
  * cpu_to_le16() -
  * @x: 16-bit CPU value to turn to little endian.
@@ -82,11 +96,11 @@ static inline uint64_t le64_to_cpu(__le64 x)
  *                             namespaces
  * @NVME_NSID_NONE:            The invalid namespace id, for when the nsid
  *                             parameter is not used in a command
- * @NVME_UUID_NONE:            Use to omit the uuid command parameter
- * @NVME_CNTLID_NONE:          Use to omit the cntlid command parameter
- * @NVME_NVMSETID_NONE:        Use to omit the nvmsetid command parameter
- * @NVME_LOG_LSP_NONE:         Use to omit the log lsp command parameter
- * @NVME_LOG_LSI_NONE:         Use to omit the log lsi command parameter
+ * @NVME_UUID_NONE:            Use to omit a uuid command parameter
+ * @NVME_CNTLID_NONE:          Use to omit a cntlid command parameter
+ * @NVME_NVMSETID_NONE:        Use to omit a nvmsetid command parameter
+ * @NVME_LOG_LSP_NONE:         Use to omit a log lsp command parameter
+ * @NVME_LOG_LSI_NONE:         Use to omit a log lsi command parameter
  * @NVME_IDENTIFY_DATA_SIZE:   The transfer size for nvme identify commands
  * @NVME_ID_NVMSET_LIST_MAX:   The largest possible nvmset index in identify
  *                             nvmeset
@@ -105,9 +119,9 @@ static inline uint64_t le64_to_cpu(__le64 x)
  * @NVME_LOG_TELEM_BLOCK_SIZE: Specification defined size of Telemetry Data Blocks
  * @NVME_DSM_MAX_RANGES:       The largest possible range index in a data-set
  *                             management command
- * @NVME_NQN_LENGTH:           Max length for NVMe Qualified Name.
- * @NVMF_TRADDR_SIZE:
- * @NVMF_TSAS_SIZE:
+ * @NVME_NQN_LENGTH:           Max length for NVMe Qualified Name
+ * @NVMF_TRADDR_SIZE:          Max Transport Address size
+ * @NVMF_TSAS_SIZE:            Max Transport Specific Address Subtype size
  */
 enum nvme_constants {
        NVME_NSID_ALL                   = 0xffffffff,
@@ -131,8 +145,6 @@ enum nvme_constants {
        NVME_NQN_LENGTH                 = 256,
        NVMF_TRADDR_SIZE                = 256,
        NVMF_TSAS_SIZE                  = 256,
-       NVME_NIDT_EUI64_LEN             = 8,
-       NVME_NIDT_NGUID_LEN             = 16,
 };
 
 /**
@@ -233,8 +245,7 @@ static inline __u64 nvme_mmio_read64(void *addr)
         return le32_to_cpu(*p) | ((uint64_t)le32_to_cpu(*(p + 1)) << 32);
 }
 
-#define NVME_REG_VALUE(name, value) \
-       (((value) >> NVME_##name##_SHIFT) & NVME_##name##_MASK)
+#define NVME_REG_VALUE(name, value) NVME_GET(name, value)
 
 enum nvme_cap {
        NVME_CAP_MQES_SHIFT             = 0,
@@ -1894,27 +1905,32 @@ enum nvme_ns_id_desc_nidt {
        NVME_NIDT_UUID          = 3,
 };
 
+enum nvme_ns_id_desc_nidt_lens {
+       NVME_NIDT_EUI64_LEN             = 8,
+       NVME_NIDT_NGUID_LEN             = 16,
+       NVME_NIDT_UUID_LEN              = 16,
+};
+
 /**
  * struct nvme_nvmset_attr - NVM Set Attributes Entry
- * @id:                            NVM Set Identifier
- * @endurance_group_id:            Endurance Group Identifier
- * @random_4k_read_typical: Random 4 KiB Read Typical indicates the typical
- *                         time to complete a 4 KiB random read in 100
- *                         nanosecond units when the NVM Set is in a
- *                         Predictable Latency Mode Deterministic Window and
- *                         there is 1 outstanding command per NVM Set.
- * @opt_write_size:
- * @total_nvmset_cap:
- * @unalloc_nvmset_cap:
+ * @nvmsetid:  NVM Set Identifier
+ * @endgid:    Endurance Group Identifier
+ * @rr4kt:     Random 4 KiB Read Typical indicates the typical
+ *             time to complete a 4 KiB random read in 100 nanosecond units
+ *             when the NVM Set is in a Predictable Latency Mode Deterministic
+ *             Window and there is 1 outstanding command per NVM Set.
+ * @ows:       Optimal Write Size
+ * @tnvmsetcap:        Total NVM Set Capacity
+ * @unvmsetcap:        Unallocated NVM Set Capacity
  */
 struct nvme_nvmset_attr {
-       __le16                  id;
-       __le16                  endurance_group_id;
+       __le16                  nvmsetid;
+       __le16                  endgid;
        __u8                    rsvd4[4];
-       __le32                  random_4k_read_typical;
-       __le32                  opt_write_size;
-       __u8                    total_nvmset_cap[16];
-       __u8                    unalloc_nvmset_cap[16];
+       __le32                  rr4kt;
+       __le32                  ows;
+       __u8                    tnvmsetcap[16];
+       __u8                    unvmsetcap[16];
        __u8                    rsvd48[80];
 };
 
@@ -1931,12 +1947,12 @@ struct nvme_id_nvmset_list {
 
 /**
  * struct nvme_id_ns_granularity_desc -
- * @namespace_size_granularity:
- * @namespace_capacity_granularity:
+ * @nszegran:
+ * @ncapgran:
  */
 struct nvme_id_ns_granularity_desc {
-       __le64                  namespace_size_granularity;
-       __le64                  namespace_capacity_granularity;
+       __le64                  nszegran;
+       __le64                  ncapgran;
 };
 
 /**
@@ -2706,15 +2722,17 @@ struct nvme_sanitize_log_page {
  * @NVME_SANITIZE_SSTAT_STATUS_ND_COMPLETE_SUCCESS:
  */
 enum nvme_sanitize_sstat {
+       NVME_SANITIZE_SSTAT_STATUS_SHIFT                = 0,
        NVME_SANITIZE_SSTAT_STATUS_MASK                 = 0x7,
        NVME_SANITIZE_SSTAT_STATUS_NEVER_SANITIZED      = 0,
        NVME_SANITIZE_SSTAT_STATUS_COMPLETE_SUCCESS     = 1,
        NVME_SANITIZE_SSTAT_STATUS_IN_PROGESS           = 2,
        NVME_SANITIZE_SSTAT_STATUS_COMPLETED_FAILED     = 3,
        NVME_SANITIZE_SSTAT_STATUS_ND_COMPLETE_SUCCESS  = 4,
-       NVME_SANITIZE_SSTAT_COMPLETED_PASSES_MASK       = 0xf8,
        NVME_SANITIZE_SSTAT_COMPLETED_PASSES_SHIFT      = 3,
-       NVME_SANITIZE_SSTAT_GLOBAL_DATA_ERASED          = 1 << 8,
+       NVME_SANITIZE_SSTAT_COMPLETED_PASSES_MASK       = 0x1f,
+       NVME_SANITIZE_SSTAT_GLOBAL_DATA_ERASED_SHIFT    = 8,
+       NVME_SANITIZE_SSTAT_GLOBAL_DATA_ERASED_MASK     = 0x1,
 };
 
 /**
@@ -2756,10 +2774,10 @@ struct nvme_feat_auto_pst {
  * enum nvme_apst_entry -
  */
 enum nvme_apst_entry {
-       NVME_APST_ENTRY_ITPS_MASK = 0xf8,
        NVME_APST_ENTRY_ITPS_SHIFT = 3,
-       NVME_APST_ENTRY_ITPT_MASK = 0xffffff00,
        NVME_APST_ENTRY_ITPT_SHIFT = 8,
+       NVME_APST_ENTRY_ITPS_MASK = 0x1f,
+       NVME_APST_ENTRY_ITPT_MASK = 0xffffff,
 };
 
 /**
@@ -2896,7 +2914,7 @@ struct nvme_registered_ctrl_ext {
 };
 
 /**
- * struct nvme_reservation_status -{
+ * struct nvme_resv_status -{
  * @gen:
  * @rtype:
  * @regctl:
@@ -2904,7 +2922,7 @@ struct nvme_registered_ctrl_ext {
  * @regctl_eds:
  * @regctl_ds:
  */
-struct nvme_reservation_status {
+struct nvme_resv_status {
        __le32  gen;
        __u8    rtype;
        __u8    regctl[2];
index b5541aaf10b3bef940c910b41e093712d8d29fdc..77669219461ef5ad85a4727ef3d7dd2caf7ee1fa 100644 (file)
@@ -1,5 +1,5 @@
 CFLAGS ?= -g -O2
-override CFLAGS += -Wall -D_GNU_SOURCE -L../src/ -I../src/
+override CFLAGS += -Wall -D_GNU_SOURCE -L../src/ -I../src/ -luuid
 
 include ../Makefile.quiet
 
index 8992554531ad27bea2fbc9a6603b4961d20a9ce1..79919e170befa9c496cc30f0e9101db0a6936097 100644 (file)
@@ -277,7 +277,7 @@ static int test_namespace(nvme_ns_t n)
                printf("  ERROR: Identify allocated ns:%x\n", ret);
        ret = nvme_identify_ns_descs(fd, nsid,  &descs);
        if (!ret)
-               printf("  Identify NS Descriptorss\n");
+               printf("  Identify NS Descriptors\n");
        else
                printf("  ERROR: Identify NS Descriptors:%x\n", ret);
        ret = nvme_get_features_write_protect(fd, nsid,
@@ -289,6 +289,14 @@ static int test_namespace(nvme_ns_t n)
        return 0;
 }
 
+static void print_hex(const uint8_t *x, int len)
+{
+       int i;
+
+       for (i = 0; i < len; i++)
+               printf("%02x", x[i]);
+}
+
 int main()
 {
        nvme_root_t r;
@@ -338,10 +346,21 @@ int main()
                                nvme_ctrl_get_address(c),
                                nvme_ctrl_get_state(c));
 
-                       nvme_ctrl_for_each_ns(c, n)
+                       nvme_ctrl_for_each_ns(c, n) {
+                               char uuid_str[40];
+                               uuid_t uuid;
+
                                printf("   `- %s lba size:%d lba max:%lu\n",
                                        nvme_ns_get_name(n), nvme_ns_get_lba_size(n),
                                        nvme_ns_get_lba_count(n));
+                               printf("      eui:");
+                               print_hex(nvme_ns_get_eui64(n), 8);
+                               printf(" nguid:");
+                               print_hex(nvme_ns_get_nguid(n), 16);
+                               nvme_ns_get_uuid(n, uuid);
+                               uuid_unparse_lower(uuid, uuid_str);
+                               printf(" uuid:%s\n", uuid_str);
+                       }
 
                        nvme_ctrl_for_each_path(c, p)
                                printf("   `- %s %s\n", nvme_path_get_name(p),