From owner-svn-src-head@freebsd.org Sun Dec 2 23:12:17 2018 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 53F0E130CD34; Sun, 2 Dec 2018 23:12:17 +0000 (UTC) (envelope-from imp@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id EFC7782F6A; Sun, 2 Dec 2018 23:12:16 +0000 (UTC) (envelope-from imp@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id D169859EF; Sun, 2 Dec 2018 23:12:16 +0000 (UTC) (envelope-from imp@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id wB2NCGcE036943; Sun, 2 Dec 2018 23:12:16 GMT (envelope-from imp@FreeBSD.org) Received: (from imp@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id wB2NCGFF036940; Sun, 2 Dec 2018 23:12:16 GMT (envelope-from imp@FreeBSD.org) Message-Id: <201812022312.wB2NCGFF036940@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: imp set sender to imp@FreeBSD.org using -f From: Warner Losh Date: Sun, 2 Dec 2018 23:12:16 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r341408 - head/sbin/nvmecontrol X-SVN-Group: head X-SVN-Commit-Author: imp X-SVN-Commit-Paths: head/sbin/nvmecontrol X-SVN-Commit-Revision: 341408 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: EFC7782F6A X-Spamd-Result: default: False [-0.03 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_SHORT(-0.11)[-0.108,0]; NEURAL_SPAM_LONG(0.05)[0.050,0]; NEURAL_SPAM_MEDIUM(0.03)[0.029,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US] X-Rspamd-Server: mx1.freebsd.org X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 02 Dec 2018 23:12:17 -0000 Author: imp Date: Sun Dec 2 23:12:16 2018 New Revision: 341408 URL: https://svnweb.freebsd.org/changeset/base/341408 Log: Make logpage functions a linker set. Move logpage function def to header. Convert all the logpage_function elements to elements of the linker set. Leave them all in logpage.c for the moment. Sponsored by: Netflix Differential Revision: https://reviews.freebsd.org/D18403 Modified: head/sbin/nvmecontrol/logpage.c head/sbin/nvmecontrol/nvmecontrol.h Modified: head/sbin/nvmecontrol/logpage.c ============================================================================== --- head/sbin/nvmecontrol/logpage.c Sun Dec 2 23:10:55 2018 (r341407) +++ head/sbin/nvmecontrol/logpage.c Sun Dec 2 23:12:16 2018 (r341408) @@ -48,14 +48,14 @@ __FBSDID("$FreeBSD$"); #include "nvmecontrol.h" +SET_DECLARE(logpage, struct logpage_function); + #define LOGPAGE_USAGE \ " nvmecontrol logpage <-p page_id> [-b] [-v vendor] [-x] \n" \ #define DEFAULT_SIZE (4096) #define MAX_FW_SLOTS (7) -typedef void (*print_fn_t)(const struct nvme_controller_data *cdata, void *buf, uint32_t size); - struct kv_name { uint32_t key; @@ -853,39 +853,40 @@ print_hgst_info_log(const struct nvme_controller_data * Make sure you keep all the pages of one vendor together so -v help * lists all the vendors pages. */ -static struct logpage_function { - uint8_t log_page; - const char *vendor; - const char *name; - print_fn_t print_fn; - size_t size; -} logfuncs[] = { - {NVME_LOG_ERROR, NULL, "Drive Error Log", - print_log_error, 0}, - {NVME_LOG_HEALTH_INFORMATION, NULL, "Health/SMART Data", - print_log_health, sizeof(struct nvme_health_information_page)}, - {NVME_LOG_FIRMWARE_SLOT, NULL, "Firmware Information", - print_log_firmware, sizeof(struct nvme_firmware_page)}, - {HGST_INFO_LOG, "hgst", "Detailed Health/SMART", - print_hgst_info_log, DEFAULT_SIZE}, - {HGST_INFO_LOG, "wdc", "Detailed Health/SMART", - print_hgst_info_log, DEFAULT_SIZE}, - {HGST_INFO_LOG, "wds", "Detailed Health/SMART", - print_hgst_info_log, DEFAULT_SIZE}, - {INTEL_LOG_TEMP_STATS, "intel", "Temperature Stats", - print_intel_temp_stats, sizeof(struct intel_log_temp_stats)}, - {INTEL_LOG_READ_LAT_LOG, "intel", "Read Latencies", - print_intel_read_lat_log, DEFAULT_SIZE}, - {INTEL_LOG_WRITE_LAT_LOG, "intel", "Write Latencies", - print_intel_write_lat_log, DEFAULT_SIZE}, - {INTEL_LOG_ADD_SMART, "intel", "Extra Health/SMART Data", - print_intel_add_smart, DEFAULT_SIZE}, - {INTEL_LOG_ADD_SMART, "samsung", "Extra Health/SMART Data", - print_intel_add_smart, DEFAULT_SIZE}, +NVME_LOGPAGE(error, + NVME_LOG_ERROR, NULL, "Drive Error Log", + print_log_error, 0); +NVME_LOGPAGE(health, + NVME_LOG_HEALTH_INFORMATION, NULL, "Health/SMART Data", + print_log_health, sizeof(struct nvme_health_information_page)); +NVME_LOGPAGE(fw, + NVME_LOG_FIRMWARE_SLOT, NULL, "Firmware Information", + print_log_firmware, sizeof(struct nvme_firmware_page)); +NVME_LOGPAGE(hgst_info, + HGST_INFO_LOG, "hgst", "Detailed Health/SMART", + print_hgst_info_log, DEFAULT_SIZE); +NVME_LOGPAGE(wdc_info, + HGST_INFO_LOG, "wdc", "Detailed Health/SMART", + print_hgst_info_log, DEFAULT_SIZE); +NVME_LOGPAGE(wds_info, + HGST_INFO_LOG, "wds", "Detailed Health/SMART", + print_hgst_info_log, DEFAULT_SIZE); +NVME_LOGPAGE(intel_temp, + INTEL_LOG_TEMP_STATS, "intel", "Temperature Stats", + print_intel_temp_stats, sizeof(struct intel_log_temp_stats)); +NVME_LOGPAGE(intel_rlat, + INTEL_LOG_READ_LAT_LOG, "intel", "Read Latencies", + print_intel_read_lat_log, DEFAULT_SIZE); +NVME_LOGPAGE(intel_wlat, + INTEL_LOG_WRITE_LAT_LOG, "intel", "Write Latencies", + print_intel_write_lat_log, DEFAULT_SIZE); +NVME_LOGPAGE(intel_smart, + INTEL_LOG_ADD_SMART, "intel", "Extra Health/SMART Data", + print_intel_add_smart, DEFAULT_SIZE); +NVME_LOGPAGE(samsung_smart, + INTEL_LOG_ADD_SMART, "samsung", "Extra Health/SMART Data", + print_intel_add_smart, DEFAULT_SIZE); - {0, NULL, NULL, NULL, 0}, -}; - static void logpage_usage(void) { @@ -897,15 +898,15 @@ logpage_usage(void) static void logpage_help(void) { - struct logpage_function *f; + struct logpage_function **f; const char *v; fprintf(stderr, "\n"); fprintf(stderr, "%-8s %-10s %s\n", "Page", "Vendor","Page Name"); fprintf(stderr, "-------- ---------- ----------\n"); - for (f = logfuncs; f->log_page > 0; f++) { - v = f->vendor == NULL ? "-" : f->vendor; - fprintf(stderr, "0x%02x %-10s %s\n", f->log_page, v, f->name); + for (f = SET_BEGIN(logpage); f < SET_LIMIT(logpage); f++) { + v = (*f)->vendor == NULL ? "-" : (*f)->vendor; + fprintf(stderr, "0x%02x %-10s %s\n", (*f)->log_page, v, (*f)->name); } exit(1); @@ -923,7 +924,7 @@ logpage(int argc, char *argv[]) uint32_t nsid, size; void *buf; const char *vendor = NULL; - struct logpage_function *f; + struct logpage_function **f; struct nvme_controller_data cdata; print_fn_t print_fn; uint8_t ns_smart; @@ -1009,14 +1010,14 @@ logpage(int argc, char *argv[]) * the page is vendor specific, don't match the print function * unless the vendors match. */ - for (f = logfuncs; f->log_page > 0; f++) { - if (f->vendor != NULL && vendor != NULL && - strcmp(f->vendor, vendor) != 0) + for (f = SET_BEGIN(logpage); f < SET_LIMIT(logpage); f++) { + if ((*f)->vendor != NULL && vendor != NULL && + strcmp((*f)->vendor, vendor) != 0) continue; - if (log_page != f->log_page) + if (log_page != (*f)->log_page) continue; - print_fn = f->print_fn; - size = f->size; + print_fn = (*f)->print_fn; + size = (*f)->size; break; } } Modified: head/sbin/nvmecontrol/nvmecontrol.h ============================================================================== --- head/sbin/nvmecontrol/nvmecontrol.h Sun Dec 2 23:10:55 2018 (r341407) +++ head/sbin/nvmecontrol/nvmecontrol.h Sun Dec 2 23:12:16 2018 (r341408) @@ -48,6 +48,27 @@ struct nvme_function { { .name = #nam, .fn = function, .usage = usage_str }; \ NVME_CMDSET(set, function ## _nvme_cmd) +typedef void (*print_fn_t)(const struct nvme_controller_data *cdata, void *buf, uint32_t size); + +struct logpage_function { + uint8_t log_page; + const char *vendor; + const char *name; + print_fn_t print_fn; + size_t size; +}; + +#define NVME_LOGPAGESET(sym) DATA_SET(logpage, sym) +#define NVME_LOGPAGE(unique, lp, vend, nam, fn, sz) \ + static struct logpage_function unique ## _lpf = { \ + .log_page = lp, \ + .vendor = vend, \ + .name = nam, \ + .print_fn = fn, \ + .size = sz, \ + } ; \ + NVME_LOGPAGESET(unique ## _lpf) + #define NVME_CTRLR_PREFIX "nvme" #define NVME_NS_PREFIX "ns"