From owner-svn-src-all@freebsd.org Fri Feb 22 15:15:37 2019 Return-Path: Delivered-To: svn-src-all@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 5BC2C14EF53C; Fri, 22 Feb 2019 15:15:37 +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.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id F3A8570E37; Fri, 22 Feb 2019 15:15:36 +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 E7449715A; Fri, 22 Feb 2019 15:15:36 +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 x1MFFa9r036711; Fri, 22 Feb 2019 15:15:36 GMT (envelope-from imp@FreeBSD.org) Received: (from imp@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x1MFFahU036709; Fri, 22 Feb 2019 15:15:36 GMT (envelope-from imp@FreeBSD.org) Message-Id: <201902221515.x1MFFahU036709@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: imp set sender to imp@FreeBSD.org using -f From: Warner Losh Date: Fri, 22 Feb 2019 15:15:36 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r344469 - head/sbin/nvmecontrol X-SVN-Group: head X-SVN-Commit-Author: imp X-SVN-Commit-Paths: head/sbin/nvmecontrol X-SVN-Commit-Revision: 344469 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: F3A8570E37 X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.96 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.999,0]; NEURAL_HAM_SHORT(-0.96)[-0.957,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US]; NEURAL_HAM_LONG(-1.00)[-0.999,0] X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 22 Feb 2019 15:15:37 -0000 Author: imp Date: Fri Feb 22 15:15:36 2019 New Revision: 344469 URL: https://svnweb.freebsd.org/changeset/base/344469 Log: Rework logpage extensibility. Move from using a linker set to a constructor function that's called. This simplifies the code and is slightly more obvious. We now keep a list of page decoders rather than having an array we managed before. Commands will move to something similar in the future. Reviewed by: jhb@ Differential Revision: https://reviews.freebsd.org/D19275 Modified: head/sbin/nvmecontrol/logpage.c head/sbin/nvmecontrol/nvmecontrol.c head/sbin/nvmecontrol/nvmecontrol.h Modified: head/sbin/nvmecontrol/logpage.c ============================================================================== --- head/sbin/nvmecontrol/logpage.c Fri Feb 22 14:59:40 2019 (r344468) +++ head/sbin/nvmecontrol/logpage.c Fri Feb 22 15:15:36 2019 (r344469) @@ -53,8 +53,15 @@ __FBSDID("$FreeBSD$"); #define MAX_FW_SLOTS (7) -SET_CONCAT_DEF(logpage, struct logpage_function); +static SLIST_HEAD(,logpage_function) logpages; +void +logpage_register(struct logpage_function *p) +{ + + SLIST_INSERT_HEAD(&logpages, p, link); +} + const char * kv_lookup(const struct kv_name *kv, size_t kv_count, uint32_t key) { @@ -326,15 +333,15 @@ NVME_LOGPAGE(fw, static void logpage_help(void) { - const struct logpage_function * const *f; + const 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 = logpage_begin(); f < logpage_limit(); f++) { - v = (*f)->vendor == NULL ? "-" : (*f)->vendor; - fprintf(stderr, "0x%02x %-10s %s\n", (*f)->log_page, v, (*f)->name); + SLIST_FOREACH(f, &logpages, link) { + v = f->vendor == NULL ? "-" : f->vendor; + fprintf(stderr, "0x%02x %-10s %s\n", f->log_page, v, f->name); } exit(1); @@ -352,7 +359,7 @@ logpage(const struct nvme_function *nf, int argc, char uint32_t nsid, size; void *buf; const char *vendor = NULL; - const struct logpage_function * const *f; + const struct logpage_function *f; struct nvme_controller_data cdata; print_fn_t print_fn; uint8_t ns_smart; @@ -438,14 +445,14 @@ logpage(const struct nvme_function *nf, int argc, char * the page is vendor specific, don't match the print function * unless the vendors match. */ - for (f = logpage_begin(); f < logpage_limit(); f++) { - if ((*f)->vendor != NULL && vendor != NULL && - strcmp((*f)->vendor, vendor) != 0) + SLIST_FOREACH(f, &logpages, link) { + 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.c ============================================================================== --- head/sbin/nvmecontrol/nvmecontrol.c Fri Feb 22 14:59:40 2019 (r344468) +++ head/sbin/nvmecontrol/nvmecontrol.c Fri Feb 22 15:15:36 2019 (r344469) @@ -312,19 +312,17 @@ load_dir(const char *dir) warnx("Can't load %s: %s", path, dlerror()); else { /* - * Add in the top (for cli commands) and logpage (for - * logpage parsing) linker sets. We have to do this by - * hand because linker sets aren't automatically merged. + * Add in the top (for cli commands)linker sets. We have + * to do this by hand because linker sets aren't + * automatically merged. */ void *begin, *limit; + begin = dlsym(h, "__start_set_top"); limit = dlsym(h, "__stop_set_top"); if (begin) add_to_top(begin, limit); - begin = dlsym(h, "__start_set_logpage"); - limit = dlsym(h, "__stop_set_logpage"); - if (begin) - add_to_logpage(begin, limit); + /* log pages use constructors so are done on load */ } free(path); path = NULL; @@ -337,7 +335,6 @@ main(int argc, char *argv[]) { add_to_top(NVME_CMD_BEGIN(top), NVME_CMD_LIMIT(top)); - add_to_logpage(NVME_LOGPAGE_BEGIN, NVME_LOGPAGE_LIMIT); load_dir("/lib/nvmecontrol"); load_dir("/usr/local/lib/nvmecontrol"); Modified: head/sbin/nvmecontrol/nvmecontrol.h ============================================================================== --- head/sbin/nvmecontrol/nvmecontrol.h Fri Feb 22 14:59:40 2019 (r344468) +++ head/sbin/nvmecontrol/nvmecontrol.h Fri Feb 22 15:15:36 2019 (r344469) @@ -32,6 +32,7 @@ #define __NVMECONTROL_H__ #include +#include #include struct nvme_function; @@ -56,6 +57,7 @@ struct nvme_function { typedef void (*print_fn_t)(const struct nvme_controller_data *cdata, void *buf, uint32_t size); struct logpage_function { + SLIST_ENTRY(logpage_function) link; uint8_t log_page; const char *vendor; const char *name; @@ -64,7 +66,6 @@ struct logpage_function { }; -#define NVME_LOGPAGESET(sym) DATA_SET(NVME_SETNAME(logpage), sym) #define NVME_LOGPAGE(unique, lp, vend, nam, fn, sz) \ static struct logpage_function unique ## _lpf = { \ .log_page = lp, \ @@ -73,10 +74,8 @@ struct logpage_function { .print_fn = fn, \ .size = sz, \ } ; \ - NVME_LOGPAGESET(unique ## _lpf) -#define NVME_LOGPAGE_BEGIN SET_BEGIN(NVME_SETNAME(logpage)) -#define NVME_LOGPAGE_LIMIT SET_LIMIT(NVME_SETNAME(logpage)) -#define NVME_LOGPAGE_DECLARE(t) SET_DECLARE(NVME_SETNAME(logpage), t) + static void logpage_reg_##unique(void) __attribute__((constructor)); \ + static void logpage_reg_##unique(void) { logpage_register(&unique##_lpf); } #define DEFAULT_SIZE (4096) struct kv_name { @@ -87,7 +86,7 @@ struct kv_name { const char *kv_lookup(const struct kv_name *kv, size_t kv_count, uint32_t key); NVME_CMD_DECLARE(top, struct nvme_function); -NVME_LOGPAGE_DECLARE(struct logpage_function); +void logpage_register(struct logpage_function *p); struct set_concat { void **begin; @@ -105,7 +104,6 @@ void add_to_ ## set(t **b, t **e) \ #define SET_CONCAT_DECL(set, t) \ void add_to_ ## set(t **b, t **e) SET_CONCAT_DECL(top, struct nvme_function); -SET_CONCAT_DECL(logpage, struct logpage_function); #define NVME_CTRLR_PREFIX "nvme" #define NVME_NS_PREFIX "ns"