Skip to content

Commit

Permalink
Allow larger SPA names in stats
Browse files Browse the repository at this point in the history
Signed-off-by: gaurkuma <[email protected]>
  • Loading branch information
gaurntnx committed Aug 9, 2017
1 parent 1e1c398 commit 38e7855
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 23 deletions.
7 changes: 4 additions & 3 deletions lib/libspl/include/sys/kstat.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ typedef int kid_t; /* unique kstat id */
* kcid = ioctl(kd, KSTAT_IOC_WRITE, kstat_t *);
*/

#define KSTAT_STRLEN 31 /* 30 chars + NULL; must be 16 * n - 1 */
#define KSTAT_STRLEN 31 /* 30 chars + NULL; must be 16 * n-1 */
#define KSTAT_MOD_STRLEN 255 /* Support large pool name */

/*
* The generic kstat header
Expand All @@ -72,7 +73,7 @@ typedef struct kstat {
hrtime_t ks_crtime; /* creation time (from gethrtime()) */
struct kstat *ks_next; /* kstat chain linkage */
kid_t ks_kid; /* unique kstat ID */
char ks_module[KSTAT_STRLEN]; /* provider module name */
char ks_module[KSTAT_MOD_STRLEN]; /* provider module name */
uchar_t ks_resv; /* reserved, currently just padding */
int ks_instance; /* provider module's instance */
char ks_name[KSTAT_STRLEN]; /* kstat name */
Expand Down Expand Up @@ -103,7 +104,7 @@ typedef struct kstat32 {
hrtime_t ks_crtime;
caddr32_t ks_next; /* struct kstat pointer */
kid32_t ks_kid;
char ks_module[KSTAT_STRLEN];
char ks_module[KSTAT_MOD_STRLEN];
uint8_t ks_resv;
int32_t ks_instance;
char ks_name[KSTAT_STRLEN];
Expand Down
35 changes: 15 additions & 20 deletions module/zfs/spa_stats.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ static void
spa_read_history_init(spa_t *spa)
{
spa_stats_history_t *ssh = &spa->spa_stats.read_history;
char name[KSTAT_STRLEN];
kstat_t *ksp;

mutex_init(&ssh->lock, NULL, MUTEX_DEFAULT, NULL);
Expand All @@ -153,9 +152,7 @@ spa_read_history_init(spa_t *spa)
ssh->size = 0;
ssh->private = NULL;

(void) snprintf(name, KSTAT_STRLEN, "zfs/%s", spa_name(spa));

ksp = kstat_create(name, 0, "reads", "misc",
ksp = kstat_create("", 0, "reads", "misc",
KSTAT_TYPE_RAW, 0, KSTAT_FLAG_VIRTUAL);
ssh->kstat = ksp;

Expand All @@ -164,6 +161,8 @@ spa_read_history_init(spa_t *spa)
ksp->ks_data = NULL;
ksp->ks_private = spa;
ksp->ks_update = spa_read_history_update;
(void) snprintf(ksp->ks_module, KSTAT_MOD_STRLEN,
"zfs/%s", spa_name(spa));
kstat_set_raw_ops(ksp, spa_read_history_headers,
spa_read_history_data, spa_read_history_addr);
kstat_install(ksp);
Expand Down Expand Up @@ -365,7 +364,6 @@ static void
spa_txg_history_init(spa_t *spa)
{
spa_stats_history_t *ssh = &spa->spa_stats.txg_history;
char name[KSTAT_STRLEN];
kstat_t *ksp;

mutex_init(&ssh->lock, NULL, MUTEX_DEFAULT, NULL);
Expand All @@ -376,9 +374,7 @@ spa_txg_history_init(spa_t *spa)
ssh->size = 0;
ssh->private = NULL;

(void) snprintf(name, KSTAT_STRLEN, "zfs/%s", spa_name(spa));

ksp = kstat_create(name, 0, "txgs", "misc",
ksp = kstat_create("", 0, "txgs", "misc",
KSTAT_TYPE_RAW, 0, KSTAT_FLAG_VIRTUAL);
ssh->kstat = ksp;

Expand All @@ -387,6 +383,8 @@ spa_txg_history_init(spa_t *spa)
ksp->ks_data = NULL;
ksp->ks_private = spa;
ksp->ks_update = spa_txg_history_update;
(void) snprintf(ksp->ks_module, KSTAT_MOD_STRLEN,
"zfs/%s", spa_name(spa));
kstat_set_raw_ops(ksp, spa_txg_history_headers,
spa_txg_history_data, spa_txg_history_addr);
kstat_install(ksp);
Expand Down Expand Up @@ -598,7 +596,6 @@ static void
spa_tx_assign_init(spa_t *spa)
{
spa_stats_history_t *ssh = &spa->spa_stats.tx_assign_histogram;
char name[KSTAT_STRLEN];
kstat_named_t *ks;
kstat_t *ksp;
int i;
Expand All @@ -609,8 +606,6 @@ spa_tx_assign_init(spa_t *spa)
ssh->size = ssh->count * sizeof (kstat_named_t);
ssh->private = kmem_alloc(ssh->size, KM_SLEEP);

(void) snprintf(name, KSTAT_STRLEN, "zfs/%s", spa_name(spa));

for (i = 0; i < ssh->count; i++) {
ks = &((kstat_named_t *)ssh->private)[i];
ks->data_type = KSTAT_DATA_UINT64;
Expand All @@ -619,7 +614,7 @@ spa_tx_assign_init(spa_t *spa)
(u_longlong_t)1 << i);
}

ksp = kstat_create(name, 0, "dmu_tx_assign", "misc",
ksp = kstat_create("", 0, "dmu_tx_assign", "misc",
KSTAT_TYPE_NAMED, 0, KSTAT_FLAG_VIRTUAL);
ssh->kstat = ksp;

Expand All @@ -629,6 +624,8 @@ spa_tx_assign_init(spa_t *spa)
ksp->ks_ndata = ssh->count;
ksp->ks_data_size = ssh->size;
ksp->ks_private = spa;
(void) snprintf(ksp->ks_module, KSTAT_MOD_STRLEN,
"zfs/%s", spa_name(spa));
ksp->ks_update = spa_tx_assign_update;
kstat_install(ksp);
}
Expand Down Expand Up @@ -678,20 +675,19 @@ static void
spa_io_history_init(spa_t *spa)
{
spa_stats_history_t *ssh = &spa->spa_stats.io_history;
char name[KSTAT_STRLEN];
kstat_t *ksp;

mutex_init(&ssh->lock, NULL, MUTEX_DEFAULT, NULL);

(void) snprintf(name, KSTAT_STRLEN, "zfs/%s", spa_name(spa));

ksp = kstat_create(name, 0, "io", "disk", KSTAT_TYPE_IO, 1, 0);
ksp = kstat_create("", 0, "io", "disk", KSTAT_TYPE_IO, 1, 0);
ssh->kstat = ksp;

if (ksp) {
ksp->ks_lock = &ssh->lock;
ksp->ks_private = spa;
ksp->ks_update = spa_io_history_update;
(void) snprintf(ksp->ks_module, KSTAT_MOD_STRLEN,
"zfs/%s", spa_name(spa));
kstat_install(ksp);
}
}
Expand Down Expand Up @@ -806,7 +802,6 @@ static void
spa_mmp_history_init(spa_t *spa)
{
spa_stats_history_t *ssh = &spa->spa_stats.mmp_history;
char name[KSTAT_STRLEN];
kstat_t *ksp;

mutex_init(&ssh->lock, NULL, MUTEX_DEFAULT, NULL);
Expand All @@ -817,9 +812,7 @@ spa_mmp_history_init(spa_t *spa)
ssh->size = 0;
ssh->private = NULL;

(void) snprintf(name, KSTAT_STRLEN, "zfs/%s", spa_name(spa));

ksp = kstat_create(name, 0, "multihost", "misc",
ksp = kstat_create("", 0, "multihost", "misc",
KSTAT_TYPE_RAW, 0, KSTAT_FLAG_VIRTUAL);
ssh->kstat = ksp;

Expand All @@ -828,6 +821,8 @@ spa_mmp_history_init(spa_t *spa)
ksp->ks_data = NULL;
ksp->ks_private = spa;
ksp->ks_update = spa_mmp_history_update;
(void) snprintf(ksp->ks_module, KSTAT_MOD_STRLEN,
"zfs/%s", spa_name(spa));
kstat_set_raw_ops(ksp, spa_mmp_history_headers,
spa_mmp_history_data, spa_mmp_history_addr);
kstat_install(ksp);
Expand Down

0 comments on commit 38e7855

Please sign in to comment.