From owner-svn-src-all@FreeBSD.ORG Sun Sep 7 12:13:50 2014 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 9EAB4FD7; Sun, 7 Sep 2014 12:13:50 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 6FF95194C; Sun, 7 Sep 2014 12:13:50 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id s87CDork050950; Sun, 7 Sep 2014 12:13:50 GMT (envelope-from delphij@FreeBSD.org) Received: (from delphij@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id s87CDoct050949; Sun, 7 Sep 2014 12:13:50 GMT (envelope-from delphij@FreeBSD.org) Message-Id: <201409071213.s87CDoct050949@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: delphij set sender to delphij@FreeBSD.org using -f From: Xin LI Date: Sun, 7 Sep 2014 12:13:50 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-vendor@freebsd.org Subject: svn commit: r271224 - vendor/illumos/dist/lib/libzfs/common X-SVN-Group: vendor MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 07 Sep 2014 12:13:50 -0000 Author: delphij Date: Sun Sep 7 12:13:49 2014 New Revision: 271224 URL: http://svnweb.freebsd.org/changeset/base/271224 Log: 5116 zpool history -i goes into infinite loop Reviewed by: Christopher Siden Reviewed by: Dan Kimmel Reviewed by: George Wilson Reviewed by: Richard Elling Reviewed by: Boris Protopopov Approved by: Dan McDonald Author: Matthew Ahrens illumos/illumos-gate@3339867a862f63acdad71abd574d5d79e18d8579 Modified: vendor/illumos/dist/lib/libzfs/common/libzfs_pool.c Modified: vendor/illumos/dist/lib/libzfs/common/libzfs_pool.c ============================================================================== --- vendor/illumos/dist/lib/libzfs/common/libzfs_pool.c Sun Sep 7 12:07:26 2014 (r271223) +++ vendor/illumos/dist/lib/libzfs/common/libzfs_pool.c Sun Sep 7 12:13:49 2014 (r271224) @@ -3698,22 +3698,24 @@ zpool_history_unpack(char *buf, uint64_t 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) @@ -3727,10 +3729,23 @@ zpool_get_history(zpool_handle_t *zhp, n &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,