summaryrefslogtreecommitdiffstats
path: root/usr.bin
diff options
context:
space:
mode:
authorbapt <bapt@FreeBSD.org>2018-01-07 10:29:15 +0000
committerbapt <bapt@FreeBSD.org>2018-01-07 10:29:15 +0000
commit70f47ab42c3654ed2e73a9ae46d8b47f7723b938 (patch)
treeda935deab5151ae325e7ba73cf0f49f03d3f8174 /usr.bin
parentf0b3f761c7280baa1c9e2fa7e3e76088a3eada51 (diff)
downloadFreeBSD-src-70f47ab42c3654ed2e73a9ae46d8b47f7723b938.zip
FreeBSD-src-70f47ab42c3654ed2e73a9ae46d8b47f7723b938.tar.gz
MFC r326769:
Remove hard coded number of lun definition The number of lun exposed is now exposed via sysctl by the kernel. Use that number in ctlstat instead of the hardcoded version Add a backward compatibility in case the sysctl(2) request fails. This also allows ctlstat -l 1118 to actually work when having more than 1024 luns. Reviewed by: avg, manu (both before the backward compatibility addition) Approved by: avg, manu (both before the backward compatibility addition) Sponsored by: Gandi.net Differential Revision: https://reviews.freebsd.org/D13446
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/ctlstat/ctlstat.c28
1 files changed, 17 insertions, 11 deletions
diff --git a/usr.bin/ctlstat/ctlstat.c b/usr.bin/ctlstat/ctlstat.c
index d90c071..70c1f7a 100644
--- a/usr.bin/ctlstat/ctlstat.c
+++ b/usr.bin/ctlstat/ctlstat.c
@@ -72,12 +72,7 @@ __FBSDID("$FreeBSD$");
*/
#define CTL_STAT_NUM_ITEMS 256
-/*
- * The default number of LUN selection bits we allocate. This is large
- * because we don't currently increase it if the user specifies a LUN
- * number of 1024 or larger.
- */
-#define CTL_STAT_BITS 1024L
+static int ctl_stat_bits;
static const char *ctlstat_opts = "Cc:Ddhjl:n:p:tw:";
static const char *ctlstat_usage = "Usage: ctlstat [-CDdjht] [-l lunnum]"
@@ -125,7 +120,7 @@ struct ctlstat_context {
struct ctl_cpu_stats cur_cpu, prev_cpu;
uint64_t cur_total_jiffies, prev_total_jiffies;
uint64_t cur_idle, prev_idle;
- bitstr_t bit_decl(item_mask, CTL_STAT_BITS);
+ bitstr_t *item_mask;
int cur_items, prev_items;
int cur_alloc, prev_alloc;
int numdevs;
@@ -429,7 +424,7 @@ ctlstat_standard(struct ctlstat_context *ctx) {
(F_TIMEVAL(ctx) != 0) ? " " : "");
n = 3;
} else {
- for (i = n = 0; i < min(CTL_STAT_BITS,
+ for (i = n = 0; i < min(ctl_stat_bits,
ctx->cur_items); i++) {
int item;
@@ -537,7 +532,7 @@ ctlstat_standard(struct ctlstat_context *ctx) {
dmas_per_sec[i], mbsec[i]);
}
} else {
- for (i = n = 0; i < min(CTL_STAT_BITS, ctx->cur_items); i++) {
+ for (i = n = 0; i < min(ctl_stat_bits, ctx->cur_items); i++) {
long double mbsec, kb_per_transfer;
long double transfers_per_sec;
long double ms_per_transfer;
@@ -580,6 +575,7 @@ main(int argc, char **argv)
int c;
int count, waittime;
int fd, retval;
+ size_t size;
struct ctlstat_context ctx;
struct ctl_io_stats *tmp_stats;
@@ -594,6 +590,16 @@ main(int argc, char **argv)
ctx.flags |= CTLSTAT_FLAG_FIRST_RUN;
ctx.flags |= CTLSTAT_FLAG_HEADER;
+ size = sizeof(ctl_stat_bits);
+ if (sysctlbyname("kern.cam.ctl.max_luns", &ctl_stat_bits, &size, NULL,
+ 0) == -1) {
+ /* Backward compatibility for where the sysctl wasn't exposed */
+ ctl_stat_bits = 1024;
+ }
+ ctx.item_mask = bit_alloc(ctl_stat_bits);
+ if (ctx.item_mask == NULL)
+ err(1, "bit_alloc() failed");
+
while ((c = getopt(argc, argv, ctlstat_opts)) != -1) {
switch (c) {
case 'C':
@@ -620,7 +626,7 @@ main(int argc, char **argv)
int cur_lun;
cur_lun = atoi(optarg);
- if (cur_lun > CTL_STAT_BITS)
+ if (cur_lun > ctl_stat_bits)
errx(1, "Invalid LUN number %d", cur_lun);
if (!F_MASK(&ctx))
@@ -639,7 +645,7 @@ main(int argc, char **argv)
int cur_port;
cur_port = atoi(optarg);
- if (cur_port > CTL_STAT_BITS)
+ if (cur_port > ctl_stat_bits)
errx(1, "Invalid port number %d", cur_port);
if (!F_MASK(&ctx))
OpenPOWER on IntegriCloud