Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 12 Aug 2019 19:44:28 +0000 (UTC)
From:      Alexander Motin <mav@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org
Subject:   svn commit: r350952 - in stable/12: sbin/nvmecontrol sys/dev/nvme
Message-ID:  <201908121944.x7CJiSEK096493@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: mav
Date: Mon Aug 12 19:44:28 2019
New Revision: 350952
URL: https://svnweb.freebsd.org/changeset/base/350952

Log:
  MFC r350599, r350609: Add `nvmecontrol resv` to handle NVMe reservations.
  
  NVMe reservations are quite alike to SCSI persistent reservations and
  can be used in clustered setups with shared multiport storage.
  
  Relnotes:	yes

Added:
  stable/12/sbin/nvmecontrol/resv.c
     - copied, changed from r350599, head/sbin/nvmecontrol/resv.c
Modified:
  stable/12/sbin/nvmecontrol/Makefile
  stable/12/sbin/nvmecontrol/nvmecontrol.8
  stable/12/sbin/nvmecontrol/sanitize.c
  stable/12/sys/dev/nvme/nvme.h
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/sbin/nvmecontrol/Makefile
==============================================================================
--- stable/12/sbin/nvmecontrol/Makefile	Mon Aug 12 19:43:25 2019	(r350951)
+++ stable/12/sbin/nvmecontrol/Makefile	Mon Aug 12 19:44:28 2019	(r350952)
@@ -4,7 +4,7 @@ PACKAGE=runtime
 PROG=	nvmecontrol
 SRCS=	comnd.c nvmecontrol.c
 SRCS+=	devlist.c firmware.c format.c identify.c logpage.c ns.c nsid.c
-SRCS+=	perftest.c power.c reset.c sanitize.c
+SRCS+=	perftest.c power.c reset.c resv.c sanitize.c
 #SRCS+=	passthru.c
 SRCS+=	identify_ext.c nvme_util.c nc_util.c
 MAN=	nvmecontrol.8

Modified: stable/12/sbin/nvmecontrol/nvmecontrol.8
==============================================================================
--- stable/12/sbin/nvmecontrol/nvmecontrol.8	Mon Aug 12 19:43:25 2019	(r350951)
+++ stable/12/sbin/nvmecontrol/nvmecontrol.8	Mon Aug 12 19:44:28 2019	(r350952)
@@ -34,7 +34,7 @@
 .\"
 .\" $FreeBSD$
 .\"
-.Dd August 3, 2019
+.Dd August 5, 2019
 .Dt NVMECONTROL 8
 .Os
 .Sh NAME
@@ -121,6 +121,33 @@
 .Aq device id
 .Aq namespace id
 .Nm
+.Ic resv acquire
+.Aq Fl c Ar crkey
+.Op Fl p Ar prkey
+.Aq Fl t Ar rtype
+.Aq Fl a Ar racqa
+.Aq namespace id
+.Nm
+.Ic resv register
+.Op Fl c Ar crkey
+.Aq Fl k Ar nrkey
+.Aq Fl r Ar rrega
+.Op Fl i Ar iekey
+.Op Fl p Ar cptpl
+.Aq namespace id
+.Nm
+.Ic resv release
+.Aq Fl c Ar crkey
+.Aq Fl t Ar rtype
+.Aq Fl a Ar rrela
+.Aq namespace id
+.Nm
+.Ic resv report
+.Op Fl e
+.Op Fl v
+.Op Fl x
+.Aq namespace id
+.Nm
 .Ic firmware
 .Op Fl s Ar slot
 .Op Fl f Ar path_to_firmware
@@ -140,9 +167,9 @@
 .Ic sanitize
 .Aq Fl a Ar sanact
 .Op Fl c Ar owpass
+.Op Fl d
 .Op Fl p Ar ovrpat
 .Op Fl r
-.Op Fl D
 .Op Fl I
 .Op Fl U
 .Aq device id
@@ -223,6 +250,96 @@ will set Retain Asynchronous Event.
 Various namespace management commands.
 If namespace management is supported by device, allow list, create and delete
 namespaces, list, attach and detach controllers to namespaces.
+.Ss resv acquire
+Acquire or preempt namespace reservation, using specified parameters:
+.Bl -tag -width 6n
+.It Fl a
+Acquire action:
+.Bl -tag -compact -width 6n
+.It Dv 0
+Acquire
+.It Dv 1
+Preempt
+.It Dv 2
+Preempt and abort
+.El
+.It Fl c
+Current reservation key.
+.It Fl p
+Preempt reservation key.
+.It Fl t
+Reservation type:
+.Bl -tag -compact -width 6n
+.It Dv 1
+Write Exclusive
+.It Dv 2
+Exclusive Access
+.It Dv 3
+Write Exclusive - Registrants Only
+.It Dv 4
+Exclusive Access - Registrants Only
+.It Dv 5
+Write Exclusive - All Registrants
+.It Dv 6
+Exclusive Access - All Registrants
+.El
+.El
+.Ss resv register
+Register, unregister or replace reservation key, using specified parameters:
+.Bl -tag -width 6n
+.It Fl c
+Current reservation key.
+.It Fl k
+New reservation key.
+.It Fl r
+Register action:
+.Bl -tag -compact -width 6n
+.It Dv 0
+Register
+.It Dv 1
+Unregister
+.It Dv 2
+Replace
+.El
+.It Fl i
+Ignore Existing Key
+.It Fl p
+Change Persist Through Power Loss State:
+.Bl -tag -compact -width 6n
+.It Dv 0
+No change to PTPL state
+.It Dv 2
+Set PTPL state to ‘0’.
+Reservations are released and registrants are cleared on a power on.
+.It Dv 3
+Set PTPL state to ‘1’.
+Reservations and registrants persist across a power loss.
+.El
+.El
+.Ss resv release
+Release or clear reservation, using specified parameters:
+.Bl -tag -width 6n
+.It Fl c
+Current reservation key.
+.It Fl t
+Reservation type.
+.It Fl a
+Release action:
+.Bl -tag -compact -width 6n
+.It Dv 0
+Release
+.It Dv 1
+Clean
+.El
+.El
+.Ss resv report
+Print reservation status, using specified parameters:
+.Bl -tag -width 6n
+.It Fl x
+Print reservation status in hex.
+.It Fl e
+Use Extended Data Structure.
+.El
 .Ss format
 Format either specified namespace, or all namespaces of specified controller,
 using specified parameters:
@@ -281,7 +398,7 @@ The number of passes when performing an
 operation.
 Valid values are between 1 and 16.
 The default is 1.
-.It Fl D
+.It Fl d
 No Deallocate After Sanitize.
 .It Fl I
 When performing an

Copied and modified: stable/12/sbin/nvmecontrol/resv.c (from r350599, head/sbin/nvmecontrol/resv.c)
==============================================================================
--- head/sbin/nvmecontrol/resv.c	Mon Aug  5 17:36:00 2019	(r350599, copy source)
+++ stable/12/sbin/nvmecontrol/resv.c	Mon Aug 12 19:44:28 2019	(r350952)
@@ -351,7 +351,7 @@ resvreport(const struct cmd *f, int argc, char *argv[]
 	struct nvme_pt_command	pt;
 	struct nvme_resv_status	*s;
 	struct nvme_resv_status_ext *e;
-	uint8_t		data[4096];
+	uint8_t		data[4096] __aligned(4);
 	int		fd;
 	u_int		i, n;
 	uint32_t	nsid;

Modified: stable/12/sbin/nvmecontrol/sanitize.c
==============================================================================
--- stable/12/sbin/nvmecontrol/sanitize.c	Mon Aug 12 19:43:25 2019	(r350951)
+++ stable/12/sbin/nvmecontrol/sanitize.c	Mon Aug 12 19:44:28 2019	(r350952)
@@ -71,7 +71,7 @@ static const struct opts sanitize_opts[] = {
 #define OPT(l, s, t, opt, addr, desc) { l, s, t, &opt.addr, desc }
 	OPT("ause", 'U', arg_none, opt, ause,
 	    "Allow Unrestricted Sanitize Exit"),
-	OPT("ndas", 'D', arg_none, opt, ndas,
+	OPT("ndas", 'd', arg_none, opt, ndas,
 	    "No Deallocate After Sanitize"),
 	OPT("oipbp", 'I', arg_none, opt, oipbp,
 	    "Overwrite Invert Pattern Between Passes"),

Modified: stable/12/sys/dev/nvme/nvme.h
==============================================================================
--- stable/12/sys/dev/nvme/nvme.h	Mon Aug 12 19:43:25 2019	(r350951)
+++ stable/12/sys/dev/nvme/nvme.h	Mon Aug 12 19:44:28 2019	(r350952)
@@ -1401,6 +1401,56 @@ struct intel_log_temp_stats
 
 _Static_assert(sizeof(struct intel_log_temp_stats) == 13 * 8, "bad size for intel_log_temp_stats");
 
+struct nvme_resv_reg_ctrlr
+{
+	uint16_t		ctrlr_id;	/* Controller ID */
+	uint8_t			rcsts;		/* Reservation Status */
+	uint8_t			reserved3[5];
+	uint64_t		hostid;		/* Host Identifier */
+	uint64_t		rkey;		/* Reservation Key */
+} __packed __aligned(4);
+
+_Static_assert(sizeof(struct nvme_resv_reg_ctrlr) == 24, "bad size for nvme_resv_reg_ctrlr");
+
+struct nvme_resv_reg_ctrlr_ext
+{
+	uint16_t		ctrlr_id;	/* Controller ID */
+	uint8_t			rcsts;		/* Reservation Status */
+	uint8_t			reserved3[5];
+	uint64_t		rkey;		/* Reservation Key */
+	uint64_t		hostid[2];	/* Host Identifier */
+	uint8_t			reserved32[32];
+} __packed __aligned(4);
+
+_Static_assert(sizeof(struct nvme_resv_reg_ctrlr_ext) == 64, "bad size for nvme_resv_reg_ctrlr_ext");
+
+struct nvme_resv_status
+{
+	uint32_t		gen;		/* Generation */
+	uint8_t			rtype;		/* Reservation Type */
+	uint8_t			regctl[2];	/* Number of Registered Controllers */
+	uint8_t			reserved7[2];
+	uint8_t			ptpls;		/* Persist Through Power Loss State */
+	uint8_t			reserved10[14];
+	struct nvme_resv_reg_ctrlr	ctrlr[0];
+} __packed __aligned(4);
+
+_Static_assert(sizeof(struct nvme_resv_status) == 24, "bad size for nvme_resv_status");
+
+struct nvme_resv_status_ext
+{
+	uint32_t		gen;		/* Generation */
+	uint8_t			rtype;		/* Reservation Type */
+	uint8_t			regctl[2];	/* Number of Registered Controllers */
+	uint8_t			reserved7[2];
+	uint8_t			ptpls;		/* Persist Through Power Loss State */
+	uint8_t			reserved10[14];
+	uint8_t			reserved24[40];
+	struct nvme_resv_reg_ctrlr_ext	ctrlr[0];
+} __packed __aligned(4);
+
+_Static_assert(sizeof(struct nvme_resv_status_ext) == 64, "bad size for nvme_resv_status_ext");
+
 #define NVME_TEST_MAX_THREADS	128
 
 struct nvme_io_test {
@@ -1859,6 +1909,36 @@ void	intel_log_temp_stats_swapbytes(struct intel_log_t
 	s->max_oper_temp = le64toh(s->max_oper_temp);
 	s->min_oper_temp = le64toh(s->min_oper_temp);
 	s->est_offset = le64toh(s->est_offset);
+}
+
+static inline
+void	nvme_resv_status_swapbytes(struct nvme_resv_status *s, size_t size)
+{
+	u_int i, n;
+
+	s->gen = le32toh(s->gen);
+	n = (s->regctl[1] << 8) | s->regctl[0];
+	n = MIN(n, (size - sizeof(s)) / sizeof(s->ctrlr[0]));
+	for (i = 0; i < n; i++) {
+		s->ctrlr[i].ctrlr_id = le16toh(s->ctrlr[i].ctrlr_id);
+		s->ctrlr[i].hostid = le64toh(s->ctrlr[i].hostid);
+		s->ctrlr[i].rkey = le64toh(s->ctrlr[i].rkey);
+	}
+}
+
+static inline
+void	nvme_resv_status_ext_swapbytes(struct nvme_resv_status_ext *s, size_t size)
+{
+	u_int i, n;
+
+	s->gen = le32toh(s->gen);
+	n = (s->regctl[1] << 8) | s->regctl[0];
+	n = MIN(n, (size - sizeof(s)) / sizeof(s->ctrlr[0]));
+	for (i = 0; i < n; i++) {
+		s->ctrlr[i].ctrlr_id = le16toh(s->ctrlr[i].ctrlr_id);
+		s->ctrlr[i].rkey = le64toh(s->ctrlr[i].rkey);
+		nvme_le128toh((void *)s->ctrlr[i].hostid);
+	}
 }
 
 #endif /* __NVME_H__ */



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201908121944.x7CJiSEK096493>