Update the kstat dataset_name when renaming a zvol

Add a dataset_kstats_rename function, and call it when renaming
a zvol on FreeBSD and Linux.

Reviewed-by: Alexander Motin <mav@FreeBSD.org>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Alan Somers <asomers@gmail.com>
Sponsored-by: Axcient
Closes #15482
Closes #15486
This commit is contained in:
Alan Somers 2023-11-07 12:34:50 -07:00 committed by GitHub
parent 9ce567c6ff
commit e36ff84c33
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 0 deletions

View File

@ -71,6 +71,7 @@ typedef struct dataset_kstats {
int dataset_kstats_create(dataset_kstats_t *, objset_t *); int dataset_kstats_create(dataset_kstats_t *, objset_t *);
void dataset_kstats_destroy(dataset_kstats_t *); void dataset_kstats_destroy(dataset_kstats_t *);
void dataset_kstats_rename(dataset_kstats_t *dk, const char *);
void dataset_kstats_update_write_kstats(dataset_kstats_t *, int64_t); void dataset_kstats_update_write_kstats(dataset_kstats_t *, int64_t);
void dataset_kstats_update_read_kstats(dataset_kstats_t *, int64_t); void dataset_kstats_update_read_kstats(dataset_kstats_t *, int64_t);

View File

@ -1319,6 +1319,7 @@ zvol_os_rename_minor(zvol_state_t *zv, const char *newname)
} }
} }
strlcpy(zv->zv_name, newname, sizeof (zv->zv_name)); strlcpy(zv->zv_name, newname, sizeof (zv->zv_name));
dataset_kstats_rename(&zv->zv_kstat, newname);
} }
/* /*

View File

@ -1528,6 +1528,8 @@ zvol_os_rename_minor(zvol_state_t *zv, const char *newname)
*/ */
set_disk_ro(zv->zv_zso->zvo_disk, !readonly); set_disk_ro(zv->zv_zso->zvo_disk, !readonly);
set_disk_ro(zv->zv_zso->zvo_disk, readonly); set_disk_ro(zv->zv_zso->zvo_disk, readonly);
dataset_kstats_rename(&zv->zv_kstat, newname);
} }
void void

View File

@ -198,6 +198,18 @@ dataset_kstats_destroy(dataset_kstats_t *dk)
zil_sums_fini(&dk->dk_zil_sums); zil_sums_fini(&dk->dk_zil_sums);
} }
void
dataset_kstats_rename(dataset_kstats_t *dk, const char *name)
{
dataset_kstat_values_t *dkv = dk->dk_kstats->ks_data;
char *ds_name;
ds_name = KSTAT_NAMED_STR_PTR(&dkv->dkv_ds_name);
ASSERT3S(ds_name, !=, NULL);
(void) strlcpy(ds_name, name,
KSTAT_NAMED_STR_BUFLEN(&dkv->dkv_ds_name));
}
void void
dataset_kstats_update_write_kstats(dataset_kstats_t *dk, dataset_kstats_update_write_kstats(dataset_kstats_t *dk,
int64_t nwritten) int64_t nwritten)