Skip to content

Commit 1f6f97f

Browse files
ahrensbehlendorf
authored andcommitted
Illumos 5116 - zpool history -i goes into infinite loop
5116 zpool history -i goes into infinite loop Reviewed by: Christopher Siden <christopher.siden@delphix.com> Reviewed by: Dan Kimmel <dan.kimmel@delphix.com> Reviewed by: George Wilson <george.wilson@delphix.com> Reviewed by: Richard Elling <richard.elling@gmail.com> Reviewed by: Boris Protopopov <boris.protopopov@me.com> Approved by: Dan McDonald <danmcd@omniti.com> References: https://www.illumos.org/issues/5116 illumos/illumos-gate@3339867 Ported by: Turbo Fredriksson <turbo@bayour.com> Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov> Closes #2715
1 parent ab2894e commit 1f6f97f

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

lib/libzfs/libzfs_pool.c

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3760,22 +3760,24 @@ zpool_history_unpack(char *buf, uint64_t bytes_read, uint64_t *leftover,
37603760
return (0);
37613761
}
37623762

3763-
#define HIS_BUF_LEN (128*1024)
3764-
37653763
/*
37663764
* Retrieve the command history of a pool.
37673765
*/
37683766
int
37693767
zpool_get_history(zpool_handle_t *zhp, nvlist_t **nvhisp)
37703768
{
3771-
char buf[HIS_BUF_LEN];
3769+
char *buf;
3770+
int buflen = 128 * 1024;
37723771
uint64_t off = 0;
37733772
nvlist_t **records = NULL;
37743773
uint_t numrecords = 0;
37753774
int err, i;
37763775

3776+
buf = malloc(buflen);
3777+
if (buf == NULL)
3778+
return (ENOMEM);
37773779
do {
3778-
uint64_t bytes_read = sizeof (buf);
3780+
uint64_t bytes_read = buflen;
37793781
uint64_t leftover;
37803782

37813783
if ((err = get_history(zhp, buf, &off, &bytes_read)) != 0)
@@ -3789,10 +3791,23 @@ zpool_get_history(zpool_handle_t *zhp, nvlist_t **nvhisp)
37893791
&leftover, &records, &numrecords)) != 0)
37903792
break;
37913793
off -= leftover;
3794+
if (leftover == bytes_read) {
3795+
/*
3796+
* no progress made, because buffer is not big enough
3797+
* to hold this record; resize and retry.
3798+
*/
3799+
buflen *= 2;
3800+
free(buf);
3801+
buf = malloc(buflen);
3802+
if (buf == NULL)
3803+
return (ENOMEM);
3804+
}
37923805

37933806
/* CONSTCOND */
37943807
} while (1);
37953808

3809+
free(buf);
3810+
37963811
if (!err) {
37973812
verify(nvlist_alloc(nvhisp, NV_UNIQUE_NAME, 0) == 0);
37983813
verify(nvlist_add_nvlist_array(*nvhisp, ZPOOL_HIST_RECORD,

0 commit comments

Comments
 (0)