Skip to content

Commit

Permalink
5116 zpool history -i goes into infinite loop
Browse files Browse the repository at this point in the history
Reviewed by: Christopher Siden <[email protected]>
Reviewed by: Dan Kimmel <[email protected]>
Reviewed by: George Wilson <[email protected]>
Reviewed by: Richard Elling <[email protected]>
Reviewed by: Boris Protopopov <[email protected]>
Approved by: Dan McDonald <[email protected]>
  • Loading branch information
ahrens authored and Christopher Siden committed Sep 5, 2014
1 parent e503a68 commit 3339867
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions usr/src/lib/libzfs/common/libzfs_pool.c
Original file line number Diff line number Diff line change
Expand Up @@ -3698,22 +3698,24 @@ zpool_history_unpack(char *buf, uint64_t bytes_read, uint64_t *leftover,
return (0);
}

#define HIS_BUF_LEN (128*1024)

/*
* Retrieve the command history of a pool.
*/
int
zpool_get_history(zpool_handle_t *zhp, nvlist_t **nvhisp)
{
char buf[HIS_BUF_LEN];
char *buf;
int buflen = 128 * 1024;
uint64_t off = 0;
nvlist_t **records = NULL;
uint_t numrecords = 0;
int err, i;

buf = malloc(buflen);
if (buf == NULL)
return (ENOMEM);
do {
uint64_t bytes_read = sizeof (buf);
uint64_t bytes_read = buflen;
uint64_t leftover;

if ((err = get_history(zhp, buf, &off, &bytes_read)) != 0)
Expand All @@ -3727,10 +3729,23 @@ zpool_get_history(zpool_handle_t *zhp, nvlist_t **nvhisp)
&leftover, &records, &numrecords)) != 0)
break;
off -= leftover;
if (leftover == bytes_read) {
/*
* no progress made, because buffer is not big enough
* to hold this record; resize and retry.
*/
buflen *= 2;
free(buf);
buf = malloc(buflen);
if (buf == NULL)
return (ENOMEM);
}

/* CONSTCOND */
} while (1);

free(buf);

if (!err) {
verify(nvlist_alloc(nvhisp, NV_UNIQUE_NAME, 0) == 0);
verify(nvlist_add_nvlist_array(*nvhisp, ZPOOL_HIST_RECORD,
Expand Down

0 comments on commit 3339867

Please sign in to comment.