Skip to content

Commit

Permalink
linux/kstat: replace existing kstat if name is reused
Browse files Browse the repository at this point in the history
Previously, if a kstat proc name already existed, the old one would be
kept. This makes it so the old one is discarded and the new one kept.

Arguably, a collision like this shouldn't ever happen, but during
import multiple vdev_t (and so vdev_queue_t, and so vdev_queue stats)
can exist at the same time for the same guid. There's no real way to
tell which is which without substantial refactoring in the import and
vdev init codepaths, whch is probably worthwhile but not for today.

Sponsored-by: Klara, Inc.
Sponsored-by: Wasabi Technology, Inc.
Signed-off-by: Rob Norris <rob.norris@klarasystems.com>
  • Loading branch information
robn committed May 16, 2024
1 parent eb6cd06 commit 6be3b93
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions module/os/linux/spl/spl-kstat.c
Original file line number Diff line number Diff line change
Expand Up @@ -666,12 +666,20 @@ kstat_proc_entry_install(kstat_proc_entry_t *kpep, mode_t mode,
}

/*
* Only one entry by this name per-module, on failure the module
* shouldn't be deleted because we know it has at least one entry.
* We can only have one entry of this name per module. If one already
* exists, replace it by first removing the proc entry, then removing
* it from the list. The kstat itself lives on; it just can't be
* inspected through the filesystem.
*/
list_for_each_entry(tmp, &module->ksm_kstat_list, kpe_list) {
if (strncmp(tmp->kpe_name, kpep->kpe_name, KSTAT_STRLEN) == 0)
goto out;
if (tmp->kpe_proc != NULL &&
strncmp(tmp->kpe_name, kpep->kpe_name, KSTAT_STRLEN) == 0) {
ASSERT3P(tmp->kpe_owner, ==, module);
remove_proc_entry(tmp->kpe_name, module->ksm_proc);
tmp->kpe_proc = NULL;
list_del_init(&tmp->kpe_list);
break;
}
}

list_add_tail(&kpep->kpe_list, &module->ksm_kstat_list);
Expand Down

0 comments on commit 6be3b93

Please sign in to comment.