mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2026-05-22 10:37:35 +03:00
Fix zpool history unbounded memory usage
In original implementation, zpool history will read the whole history before printing anything, causing memory usage goes unbounded. We fix this by breaking it into read-print iterations. Reviewed-by: Tom Caputi <tcaputi@datto.com> Reviewed-by: Matt Ahrens <matt@delphix.com> Reviewed-by: Igor Kozhukhov <igor@dilos.org> Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Signed-off-by: Chunwei Chen <david.chen@nutanix.com> Closes #9516
This commit is contained in:
committed by
Brian Behlendorf
parent
e35704647e
commit
7125a109dc
+28
-16
@@ -8518,24 +8518,12 @@ typedef struct hist_cbdata {
|
||||
boolean_t internal;
|
||||
} hist_cbdata_t;
|
||||
|
||||
/*
|
||||
* Print out the command history for a specific pool.
|
||||
*/
|
||||
static int
|
||||
get_history_one(zpool_handle_t *zhp, void *data)
|
||||
static void
|
||||
print_history_records(nvlist_t *nvhis, hist_cbdata_t *cb)
|
||||
{
|
||||
nvlist_t *nvhis;
|
||||
nvlist_t **records;
|
||||
uint_t numrecords;
|
||||
int ret, i;
|
||||
hist_cbdata_t *cb = (hist_cbdata_t *)data;
|
||||
|
||||
cb->first = B_FALSE;
|
||||
|
||||
(void) printf(gettext("History for '%s':\n"), zpool_get_name(zhp));
|
||||
|
||||
if ((ret = zpool_get_history(zhp, &nvhis)) != 0)
|
||||
return (ret);
|
||||
int i;
|
||||
|
||||
verify(nvlist_lookup_nvlist_array(nvhis, ZPOOL_HIST_RECORD,
|
||||
&records, &numrecords) == 0);
|
||||
@@ -8639,8 +8627,32 @@ get_history_one(zpool_handle_t *zhp, void *data)
|
||||
(void) printf("]");
|
||||
(void) printf("\n");
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Print out the command history for a specific pool.
|
||||
*/
|
||||
static int
|
||||
get_history_one(zpool_handle_t *zhp, void *data)
|
||||
{
|
||||
nvlist_t *nvhis;
|
||||
int ret;
|
||||
hist_cbdata_t *cb = (hist_cbdata_t *)data;
|
||||
uint64_t off = 0;
|
||||
boolean_t eof = B_FALSE;
|
||||
|
||||
cb->first = B_FALSE;
|
||||
|
||||
(void) printf(gettext("History for '%s':\n"), zpool_get_name(zhp));
|
||||
|
||||
while (!eof) {
|
||||
if ((ret = zpool_get_history(zhp, &nvhis, &off, &eof)) != 0)
|
||||
return (ret);
|
||||
|
||||
print_history_records(nvhis, cb);
|
||||
nvlist_free(nvhis);
|
||||
}
|
||||
(void) printf("\n");
|
||||
nvlist_free(nvhis);
|
||||
|
||||
return (ret);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user