Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 26 Jul 2017 16:33:58 +0000 (UTC)
From:      Alexander Motin <mav@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org
Subject:   svn commit: r321546 - stable/11/cddl/contrib/opensolaris/lib/libzfs/common
Message-ID:  <201707261633.v6QGXwpi072435@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: mav
Date: Wed Jul 26 16:33:58 2017
New Revision: 321546
URL: https://svnweb.freebsd.org/changeset/base/321546

Log:
  MFC r318819: MFV r316908: 7541 zpool import/tryimport ioctl returns ENOMEM because provided buffer is too small for config
  
  illumos/illumos-gate@8b65a70b763232c90a91f31eb2010314c02ed338
  https://github.com/illumos/illumos-gate/commit/8b65a70b763232c90a91f31eb2010314c02ed338
  
  https://www.illumos.org/issues/7541
    When calling zpool import, zpool does a few ioctls to ZFS.
    zpool allocates a buffer in userland and passes it to the kernel so that ZFS
    can copy info into it. ZFS will use it to put the nvlist that describes the
    pool configuration.
    If the allocated buffer is too small, ZFS will return ENOMEM and the call will
    have to be redone. This wastes CPU time and slows down the import process. This
    happens very often for the ZFS_IOC_POOL_TRYIMPORT call.
  
  Reviewed by: Matthew Ahrens <mahrens@delphix.com>
  Reviewed by: Dan Kimmel <dan.kimmel@delphix.com>
  Approved by: Dan McDonald <danmcd@omniti.com>
  Author: Pavel Zakharov <pavel.zakharov@delphix.com>

Modified:
  stable/11/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_impl.h
  stable/11/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_import.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_impl.h
==============================================================================
--- stable/11/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_impl.h	Wed Jul 26 16:32:17 2017	(r321545)
+++ stable/11/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_impl.h	Wed Jul 26 16:33:58 2017	(r321546)
@@ -132,6 +132,8 @@ typedef enum {
 	SHARED_SMB = 0x4
 } zfs_share_type_t;
 
+#define	CONFIG_BUF_MINSIZE	65536
+
 int zfs_error(libzfs_handle_t *, int, const char *);
 int zfs_error_fmt(libzfs_handle_t *, int, const char *, ...);
 void zfs_error_aux(libzfs_handle_t *, const char *, ...);

Modified: stable/11/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_import.c
==============================================================================
--- stable/11/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_import.c	Wed Jul 26 16:32:17 2017	(r321545)
+++ stable/11/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_import.c	Wed Jul 26 16:33:58 2017	(r321546)
@@ -21,7 +21,7 @@
 
 /*
  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
- * Copyright (c) 2012, 2015 by Delphix. All rights reserved.
+ * Copyright (c) 2012, 2016 by Delphix. All rights reserved.
  * Copyright 2015 RackTop Systems.
  * Copyright 2016 Nexenta Systems, Inc.
  */
@@ -379,13 +379,14 @@ refresh_config(libzfs_handle_t *hdl, nvlist_t *config)
 {
 	nvlist_t *nvl;
 	zfs_cmd_t zc = { 0 };
-	int err;
+	int err, dstbuf_size;
 
 	if (zcmd_write_conf_nvlist(hdl, &zc, config) != 0)
 		return (NULL);
 
-	if (zcmd_alloc_dst_nvlist(hdl, &zc,
-	    zc.zc_nvlist_conf_size * 2) != 0) {
+	dstbuf_size = MAX(CONFIG_BUF_MINSIZE, zc.zc_nvlist_conf_size * 4);
+
+	if (zcmd_alloc_dst_nvlist(hdl, &zc, dstbuf_size) != 0) {
 		zcmd_free_nvlists(&zc);
 		return (NULL);
 	}



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201707261633.v6QGXwpi072435>