diff --git a/lib/libzfs/Makefile.am b/lib/libzfs/Makefile.am index 0827d52a47..332094469c 100644 --- a/lib/libzfs/Makefile.am +++ b/lib/libzfs/Makefile.am @@ -41,7 +41,6 @@ if BUILD_LINUX USER_C += \ os/linux/libzfs_mount_os.c \ os/linux/libzfs_pool_os.c \ - os/linux/libzfs_sendrecv_os.c \ os/linux/libzfs_util_os.c endif diff --git a/lib/libzfs/libzfs_impl.h b/lib/libzfs/libzfs_impl.h index cf8d0d4e67..6a18f6c328 100644 --- a/lib/libzfs/libzfs_impl.h +++ b/lib/libzfs/libzfs_impl.h @@ -257,7 +257,6 @@ extern int libzfs_load_module(void); extern int zpool_relabel_disk(libzfs_handle_t *hdl, const char *path, const char *msg); extern int find_shares_object(differ_info_t *di); -extern void libzfs_set_pipe_max(int infd); extern void zfs_commit_proto(const zfs_share_proto_t *); #ifdef __cplusplus diff --git a/lib/libzfs/libzfs_sendrecv.c b/lib/libzfs/libzfs_sendrecv.c index 91f595ac51..4e491fd3be 100644 --- a/lib/libzfs/libzfs_sendrecv.c +++ b/lib/libzfs/libzfs_sendrecv.c @@ -5243,13 +5243,6 @@ zfs_receive(libzfs_handle_t *hdl, const char *tosnap, nvlist_t *props, return (-2); } - /* - * It is not uncommon for gigabytes to be processed in zfs receive. - * Speculatively increase the buffer size if supported by the platform. - */ - if (S_ISFIFO(sb.st_mode)) - libzfs_set_pipe_max(infd); - if (props) { err = nvlist_lookup_string(props, "origin", &originsnap); if (err && err != ENOENT) diff --git a/lib/libzfs/os/freebsd/libzfs_compat.c b/lib/libzfs/os/freebsd/libzfs_compat.c index ce2dcef009..f5be2b90bb 100644 --- a/lib/libzfs/os/freebsd/libzfs_compat.c +++ b/lib/libzfs/os/freebsd/libzfs_compat.c @@ -38,12 +38,6 @@ #define ZFS_KMOD "openzfs" #endif -void -libzfs_set_pipe_max(int infd) -{ - /* FreeBSD automatically resizes */ - (void) infd; -} static int execvPe(const char *name, const char *path, char * const *argv, diff --git a/lib/libzfs/os/linux/libzfs_sendrecv_os.c b/lib/libzfs/os/linux/libzfs_sendrecv_os.c deleted file mode 100644 index 593c38ec62..0000000000 --- a/lib/libzfs/os/linux/libzfs_sendrecv_os.c +++ /dev/null @@ -1,52 +0,0 @@ -/* - * CDDL HEADER START - * - * The contents of this file are subject to the terms of the - * Common Development and Distribution License (the "License"). - * You may not use this file except in compliance with the License. - * - * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE - * or http://www.opensolaris.org/os/licensing. - * See the License for the specific language governing permissions - * and limitations under the License. - * - * When distributing Covered Code, include this CDDL HEADER in each - * file and include the License file at usr/src/OPENSOLARIS.LICENSE. - * If applicable, add the following below this CDDL HEADER, with the - * fields enclosed by brackets "[]" replaced with your own identifying - * information: Portions Copyright [yyyy] [name of copyright owner] - * - * CDDL HEADER END - */ - - -#include - -#include "../../libzfs_impl.h" - -#ifndef F_SETPIPE_SZ -#define F_SETPIPE_SZ (F_SETLEASE + 7) -#endif /* F_SETPIPE_SZ */ - -#ifndef F_GETPIPE_SZ -#define F_GETPIPE_SZ (F_GETLEASE + 7) -#endif /* F_GETPIPE_SZ */ - -void -libzfs_set_pipe_max(int infd) -{ - FILE *procf = fopen("/proc/sys/fs/pipe-max-size", "re"); - - if (procf != NULL) { - unsigned long max_psize; - long cur_psize; - if (fscanf(procf, "%lu", &max_psize) > 0) { - cur_psize = fcntl(infd, F_GETPIPE_SZ); - if (cur_psize > 0 && - max_psize > (unsigned long) cur_psize) - fcntl(infd, F_SETPIPE_SZ, - max_psize); - } - fclose(procf); - } -} diff --git a/lib/libzfs_core/libzfs_core.c b/lib/libzfs_core/libzfs_core.c index 99652bc4a0..f7561241af 100644 --- a/lib/libzfs_core/libzfs_core.c +++ b/lib/libzfs_core/libzfs_core.c @@ -586,6 +586,30 @@ lzc_get_holds(const char *snapname, nvlist_t **holdsp) return (lzc_ioctl(ZFS_IOC_GET_HOLDS, snapname, NULL, holdsp)); } +static void +max_pipe_buffer(int infd) +{ +#if __linux__ + FILE *procf = fopen("/proc/sys/fs/pipe-max-size", "re"); + + if (procf != NULL) { + unsigned long max_psize; + long cur_psize; + if (fscanf(procf, "%lu", &max_psize) > 0) { + cur_psize = fcntl(infd, F_GETPIPE_SZ); + if (cur_psize > 0 && + max_psize > (unsigned long) cur_psize) + fcntl(infd, F_SETPIPE_SZ, + max_psize); + } + fclose(procf); + } +#else + /* FreeBSD automatically resizes */ + (void) infd; +#endif +} + /* * Generate a zfs send stream for the specified snapshot and write it to * the specified file descriptor. @@ -811,6 +835,16 @@ recv_impl(const char *snapname, nvlist_t *recvdprops, nvlist_t *localprops, *slashp = '\0'; } + /* + * It is not uncommon for gigabytes to be processed by zfs receive. + * Speculatively increase the buffer size if supported by the platform. + */ + struct stat sb; + if (fstat(input_fd, &sb) == -1) + return (errno); + if (S_ISFIFO(sb.st_mode)) + max_pipe_buffer(input_fd); + /* * The begin_record is normally a non-byteswapped BEGIN record. * For resumable streams it may be set to any non-byteswapped