svn commit: r341658 - head/sbin/nvmecontrol

Warner Losh imp at FreeBSD.org
Thu Dec 6 22:58:45 UTC 2018


Author: imp
Date: Thu Dec  6 22:58:42 2018
New Revision: 341658
URL: https://svnweb.freebsd.org/changeset/base/341658

Log:
  Const poison the command interface
  
  Make the pointers we pass into the commands const, also make the
  linker set mirrors const.
  
  Suggested by: cem@
  Sponsored by: Netflix
  Differential Revision: https://reviews.freebsd.org/D18459

Modified:
  head/sbin/nvmecontrol/devlist.c
  head/sbin/nvmecontrol/firmware.c
  head/sbin/nvmecontrol/format.c
  head/sbin/nvmecontrol/identify.c
  head/sbin/nvmecontrol/logpage.c
  head/sbin/nvmecontrol/ns.c
  head/sbin/nvmecontrol/nvmecontrol.c
  head/sbin/nvmecontrol/nvmecontrol.h
  head/sbin/nvmecontrol/perftest.c
  head/sbin/nvmecontrol/power.c
  head/sbin/nvmecontrol/reset.c
  head/sbin/nvmecontrol/wdc.c

Modified: head/sbin/nvmecontrol/devlist.c
==============================================================================
--- head/sbin/nvmecontrol/devlist.c	Thu Dec  6 22:58:26 2018	(r341657)
+++ head/sbin/nvmecontrol/devlist.c	Thu Dec  6 22:58:42 2018	(r341658)
@@ -60,7 +60,7 @@ ns_get_sector_size(struct nvme_namespace_data *nsdata)
 }
 
 static void
-devlist(struct nvme_function *nf, int argc, char *argv[])
+devlist(const struct nvme_function *nf, int argc, char *argv[])
 {
 	struct nvme_controller_data	cdata;
 	struct nvme_namespace_data	nsdata;

Modified: head/sbin/nvmecontrol/firmware.c
==============================================================================
--- head/sbin/nvmecontrol/firmware.c	Thu Dec  6 22:58:26 2018	(r341657)
+++ head/sbin/nvmecontrol/firmware.c	Thu Dec  6 22:58:42 2018	(r341658)
@@ -174,7 +174,7 @@ activate_firmware(int fd, int slot, int activate_actio
 }
 
 static void
-firmware(struct nvme_function *nf, int argc, char *argv[])
+firmware(const struct nvme_function *nf, int argc, char *argv[])
 {
 	int				fd = -1, slot = 0;
 	int				a_flag, s_flag, f_flag;

Modified: head/sbin/nvmecontrol/format.c
==============================================================================
--- head/sbin/nvmecontrol/format.c	Thu Dec  6 22:58:26 2018	(r341657)
+++ head/sbin/nvmecontrol/format.c	Thu Dec  6 22:58:42 2018	(r341658)
@@ -47,7 +47,7 @@ __FBSDID("$FreeBSD$");
 	"format [-f fmt] [-m mset] [-p pi] [-l pil] [-E] [-C] <controller id|namespace id>\n"
 
 static void
-format(struct nvme_function *nf, int argc, char *argv[])
+format(const struct nvme_function *nf, int argc, char *argv[])
 {
 	struct nvme_controller_data	cd;
 	struct nvme_namespace_data	nsd;

Modified: head/sbin/nvmecontrol/identify.c
==============================================================================
--- head/sbin/nvmecontrol/identify.c	Thu Dec  6 22:58:26 2018	(r341657)
+++ head/sbin/nvmecontrol/identify.c	Thu Dec  6 22:58:42 2018	(r341658)
@@ -150,7 +150,7 @@ print_namespace(struct nvme_namespace_data *nsdata)
 }
 
 static void
-identify_ctrlr(struct nvme_function *nf, int argc, char *argv[])
+identify_ctrlr(const struct nvme_function *nf, int argc, char *argv[])
 {
 	struct nvme_controller_data	cdata;
 	int				ch, fd, hexflag = 0, hexlength;
@@ -197,7 +197,7 @@ identify_ctrlr(struct nvme_function *nf, int argc, cha
 }
 
 static void
-identify_ns(struct nvme_function *nf,int argc, char *argv[])
+identify_ns(const struct nvme_function *nf,int argc, char *argv[])
 {
 	struct nvme_namespace_data	nsdata;
 	char				path[64];
@@ -261,7 +261,7 @@ identify_ns(struct nvme_function *nf,int argc, char *a
 }
 
 static void
-identify(struct nvme_function *nf, int argc, char *argv[])
+identify(const struct nvme_function *nf, int argc, char *argv[])
 {
 	char	*target;
 

Modified: head/sbin/nvmecontrol/logpage.c
==============================================================================
--- head/sbin/nvmecontrol/logpage.c	Thu Dec  6 22:58:26 2018	(r341657)
+++ head/sbin/nvmecontrol/logpage.c	Thu Dec  6 22:58:42 2018	(r341658)
@@ -326,7 +326,7 @@ NVME_LOGPAGE(fw,
 static void
 logpage_help(void)
 {
-	struct logpage_function		**f;
+	const struct logpage_function	* const *f;
 	const char 			*v;
 
 	fprintf(stderr, "\n");
@@ -341,7 +341,7 @@ logpage_help(void)
 }
 
 static void
-logpage(struct nvme_function *nf, int argc, char *argv[])
+logpage(const struct nvme_function *nf, int argc, char *argv[])
 {
 	int				fd;
 	int				log_page = 0, pageflag = false;
@@ -352,7 +352,7 @@ logpage(struct nvme_function *nf, int argc, char *argv
 	uint32_t			nsid, size;
 	void				*buf;
 	const char			*vendor = NULL;
-	struct logpage_function		**f;
+	const struct logpage_function	* const *f;
 	struct nvme_controller_data	cdata;
 	print_fn_t			print_fn;
 	uint8_t				ns_smart;

Modified: head/sbin/nvmecontrol/ns.c
==============================================================================
--- head/sbin/nvmecontrol/ns.c	Thu Dec  6 22:58:26 2018	(r341657)
+++ head/sbin/nvmecontrol/ns.c	Thu Dec  6 22:58:42 2018	(r341658)
@@ -60,10 +60,10 @@ NVME_CMD_DECLARE(ns, struct nvme_function);
 #define NSDETACH_USAGE							\
 	"ns detach -n nsid [-c ctrlrid] nvmeN\n"
 
-void nscreate(struct nvme_function *nf, int argc, char *argv[]);
-void nsdelete(struct nvme_function *nf, int argc, char *argv[]);
-void nsattach(struct nvme_function *nf, int argc, char *argv[]);
-void nsdetach(struct nvme_function *nf, int argc, char *argv[]);
+static void nscreate(const struct nvme_function *nf, int argc, char *argv[]);
+static void nsdelete(const struct nvme_function *nf, int argc, char *argv[]);
+static void nsattach(const struct nvme_function *nf, int argc, char *argv[]);
+static void nsdetach(const struct nvme_function *nf, int argc, char *argv[]);
 
 NVME_COMMAND(ns, create, nscreate, NSCREATE_USAGE);
 NVME_COMMAND(ns, delete, nsdelete, NSDELETE_USAGE);
@@ -109,8 +109,8 @@ get_res_str(uint16_t res)
  * 0x16 = Namespace ID  unavailable (number namespaces exceeded)
  * 0xb = Thin Provisioning Not supported
  */
-void
-nscreate(struct nvme_function *nf, int argc, char *argv[])
+static void
+nscreate(const struct nvme_function *nf, int argc, char *argv[])
 {
 	struct nvme_pt_command	pt;
 	struct nvme_controller_data cd;
@@ -204,8 +204,8 @@ nscreate(struct nvme_function *nf, int argc, char *arg
 	exit(0);
 }
 
-void
-nsdelete(struct nvme_function *nf, int argc, char *argv[])
+static void
+nsdelete(const struct nvme_function *nf, int argc, char *argv[])
 {
 	struct nvme_pt_command	pt;
 	struct nvme_controller_data cd;
@@ -271,8 +271,8 @@ nsdelete(struct nvme_function *nf, int argc, char *arg
  *
  * 0x2 Invalid Field can occur if ctrlrid d.n.e in system.
  */
-void
-nsattach(struct nvme_function *nf, int argc, char *argv[])
+static void
+nsattach(const struct nvme_function *nf, int argc, char *argv[])
 {
 	struct nvme_pt_command	pt;
 	struct nvme_controller_data cd;
@@ -350,8 +350,8 @@ nsattach(struct nvme_function *nf, int argc, char *arg
 	exit(0);
 }
 
-void
-nsdetach(struct nvme_function *nf, int argc, char *argv[])
+static void
+nsdetach(const struct nvme_function *nf, int argc, char *argv[])
 {
 	struct nvme_pt_command	pt;
 	struct nvme_controller_data cd;
@@ -437,7 +437,7 @@ nsdetach(struct nvme_function *nf, int argc, char *arg
 }
 
 static void
-ns(struct nvme_function *nf __unused, int argc, char *argv[])
+ns(const struct nvme_function *nf __unused, int argc, char *argv[])
 {
 
 	DISPATCH(argc, argv, ns);

Modified: head/sbin/nvmecontrol/nvmecontrol.c
==============================================================================
--- head/sbin/nvmecontrol/nvmecontrol.c	Thu Dec  6 22:58:26 2018	(r341657)
+++ head/sbin/nvmecontrol/nvmecontrol.c	Thu Dec  6 22:58:42 2018	(r341658)
@@ -75,7 +75,7 @@ print_usage(const struct nvme_function *f)
 }
 
 static void
-gen_usage_set(struct nvme_function **f, struct nvme_function **flimit)
+gen_usage_set(const struct nvme_function * const *f, const struct nvme_function * const *flimit)
 {
 
 	fprintf(stderr, "usage:\n");
@@ -96,10 +96,10 @@ usage(const struct nvme_function *f)
 }
 
 void
-dispatch_set(int argc, char *argv[], struct nvme_function **tbl,
-    struct nvme_function **tbl_limit)
+dispatch_set(int argc, char *argv[], const struct nvme_function * const *tbl,
+    const struct nvme_function * const *tbl_limit)
 {
-	struct nvme_function **f = tbl;
+	const struct nvme_function * const *f = tbl;
 
 	if (argv[1] == NULL) {
 		gen_usage_set(tbl, tbl_limit);

Modified: head/sbin/nvmecontrol/nvmecontrol.h
==============================================================================
--- head/sbin/nvmecontrol/nvmecontrol.h	Thu Dec  6 22:58:26 2018	(r341657)
+++ head/sbin/nvmecontrol/nvmecontrol.h	Thu Dec  6 22:58:42 2018	(r341658)
@@ -35,7 +35,7 @@
 #include <dev/nvme/nvme.h>
 
 struct nvme_function;
-typedef void (*nvme_fn_t)(struct nvme_function *nf, int argc, char *argv[]);
+typedef void (*nvme_fn_t)(const struct nvme_function *nf, int argc, char *argv[]);
 
 struct nvme_function {
 	const char	*name;
@@ -96,8 +96,8 @@ struct set_concat {
 void set_concat_add(struct set_concat *m, void *begin, void *end);
 #define SET_CONCAT_DEF(set, t) 							\
 static struct set_concat set ## _concat;					\
-static inline t **set ## _begin() { return ((t **)set ## _concat.begin); }	\
-static inline t **set ## _limit() { return ((t **)set ## _concat.limit); }	\
+static inline const t * const *set ## _begin() { return ((const t * const *)set ## _concat.begin); }	\
+static inline const t * const *set ## _limit() { return ((const t * const *)set ## _concat.limit); }	\
 void add_to_ ## set(t **b, t **e)						\
 {										\
 	set_concat_add(&set ## _concat, b, e);					\
@@ -120,11 +120,13 @@ void read_logpage(int fd, uint8_t log_page, uint32_t n
 void print_temp(uint16_t t);
 
 void usage(const struct nvme_function *f);
-void dispatch_set(int argc, char *argv[], struct nvme_function **tbl,
-    struct nvme_function **tbl_limit);
+void dispatch_set(int argc, char *argv[], const struct nvme_function * const *tbl,
+    const struct nvme_function * const *tbl_limit);
 
-#define DISPATCH(argc, argv, set)	\
-	dispatch_set(argc, argv, NVME_CMD_BEGIN(set), NVME_CMD_LIMIT(set))
+#define DISPATCH(argc, argv, set)					\
+	dispatch_set(argc, argv,					\
+	    (const struct nvme_function * const *)NVME_CMD_BEGIN(set),	\
+	    (const struct nvme_function * const *)NVME_CMD_LIMIT(set))	\
 
 /* Utility Routines */
 /*

Modified: head/sbin/nvmecontrol/perftest.c
==============================================================================
--- head/sbin/nvmecontrol/perftest.c	Thu Dec  6 22:58:26 2018	(r341657)
+++ head/sbin/nvmecontrol/perftest.c	Thu Dec  6 22:58:42 2018	(r341658)
@@ -75,7 +75,7 @@ print_perftest(struct nvme_io_test *io_test, bool pert
 }
 
 static void
-perftest(struct nvme_function *nf, int argc, char *argv[])
+perftest(const struct nvme_function *nf, int argc, char *argv[])
 {
 	struct nvme_io_test		io_test;
 	int				fd;

Modified: head/sbin/nvmecontrol/power.c
==============================================================================
--- head/sbin/nvmecontrol/power.c	Thu Dec  6 22:58:26 2018	(r341657)
+++ head/sbin/nvmecontrol/power.c	Thu Dec  6 22:58:42 2018	(r341658)
@@ -129,7 +129,7 @@ power_show(int fd)
 }
 
 static void
-power(struct nvme_function *nf, int argc, char *argv[])
+power(const struct nvme_function *nf, int argc, char *argv[])
 {
 	struct nvme_controller_data	cdata;
 	int				ch, listflag = 0, powerflag = 0, power_val = 0, fd;

Modified: head/sbin/nvmecontrol/reset.c
==============================================================================
--- head/sbin/nvmecontrol/reset.c	Thu Dec  6 22:58:26 2018	(r341657)
+++ head/sbin/nvmecontrol/reset.c	Thu Dec  6 22:58:42 2018	(r341658)
@@ -45,7 +45,7 @@ __FBSDID("$FreeBSD$");
 	"reset <controller id>\n"
 
 static void
-reset(struct nvme_function *nf, int argc, char *argv[])
+reset(const struct nvme_function *nf, int argc, char *argv[])
 {
 	int	ch, fd;
 

Modified: head/sbin/nvmecontrol/wdc.c
==============================================================================
--- head/sbin/nvmecontrol/wdc.c	Thu Dec  6 22:58:26 2018	(r341657)
+++ head/sbin/nvmecontrol/wdc.c	Thu Dec  6 22:58:42 2018	(r341658)
@@ -52,7 +52,7 @@ NVME_CMD_DECLARE(wdc, struct nvme_function);
 #define WDC_NVME_CAP_DIAG_OPCODE	0xe6
 #define WDC_NVME_CAP_DIAG_CMD		0x0000
 
-static void wdc_cap_diag(struct nvme_function *nf, int argc, char *argv[]);
+static void wdc_cap_diag(const struct nvme_function *nf, int argc, char *argv[]);
 
 #define WDC_CAP_DIAG_USAGE	"wdc cap-diag [-o path-template]\n"
 
@@ -154,7 +154,7 @@ wdc_do_dump(int fd, char *tmpl, const char *suffix, ui
 }
 
 static void
-wdc_cap_diag(struct nvme_function *nf, int argc, char *argv[])
+wdc_cap_diag(const struct nvme_function *nf, int argc, char *argv[])
 {
 	char path_tmpl[MAXPATHLEN];
 	int ch, fd;
@@ -183,7 +183,7 @@ wdc_cap_diag(struct nvme_function *nf, int argc, char 
 }
 
 static void
-wdc(struct nvme_function *nf __unused, int argc, char *argv[])
+wdc(const struct nvme_function *nf __unused, int argc, char *argv[])
 {
 
 	DISPATCH(argc, argv, wdc);


More information about the svn-src-all mailing list