From 449705dbef3008f1cf69ea59276bd07720e4beb2 Mon Sep 17 00:00:00 2001 From: Simon Klinkert Date: Wed, 11 Mar 2015 11:02:08 +0100 Subject: OpenZFS 5704 - libzfs can only handle 255 file descriptors Authored by: Simon Klinkert Reviewed by: Josef 'Jeff' Sipek Reviewed by: John Kennedy Approved by: Richard Lowe Reviewed-by: Brian Behlendorf Reviewed by: Ned Bass Reviewed-by: Chunwei Chen Ported-by: George Melikov OpenZFS-issue: https://www.illumos.org/issues/5704 OpenZFS-commit: https://github.com/openzfs/openzfs/commit/bde3d61 Closes #5767 --- configure.ac | 1 + tests/runfiles/linux.run | 3 + tests/zfs-tests/tests/functional/Makefile.am | 1 + tests/zfs-tests/tests/functional/libzfs/.gitignore | 1 + .../zfs-tests/tests/functional/libzfs/Makefile.am | 24 +++++++ .../zfs-tests/tests/functional/libzfs/cleanup.ksh | 34 ++++++++++ tests/zfs-tests/tests/functional/libzfs/many_fds.c | 73 ++++++++++++++++++++++ tests/zfs-tests/tests/functional/libzfs/setup.ksh | 35 +++++++++++ 8 files changed, 172 insertions(+) create mode 100644 tests/zfs-tests/tests/functional/libzfs/.gitignore create mode 100644 tests/zfs-tests/tests/functional/libzfs/Makefile.am create mode 100755 tests/zfs-tests/tests/functional/libzfs/cleanup.ksh create mode 100644 tests/zfs-tests/tests/functional/libzfs/many_fds.c create mode 100755 tests/zfs-tests/tests/functional/libzfs/setup.ksh diff --git a/configure.ac b/configure.ac index 20a67dc4f..60416f6ae 100644 --- a/configure.ac +++ b/configure.ac @@ -246,6 +246,7 @@ AC_CONFIG_FILES([ tests/zfs-tests/tests/functional/large_files/Makefile tests/zfs-tests/tests/functional/largest_pool/Makefile tests/zfs-tests/tests/functional/link_count/Makefile + tests/zfs-tests/tests/functional/libzfs/Makefile tests/zfs-tests/tests/functional/migration/Makefile tests/zfs-tests/tests/functional/mmap/Makefile tests/zfs-tests/tests/functional/mount/Makefile diff --git a/tests/runfiles/linux.run b/tests/runfiles/linux.run index ec42b8e40..dfc2c5a66 100644 --- a/tests/runfiles/linux.run +++ b/tests/runfiles/linux.run @@ -666,3 +666,6 @@ tests = ['zvol_cli_001_pos', 'zvol_cli_002_pos', 'zvol_cli_003_neg'] #[tests/functional/zvol/zvol_swap] #tests = ['zvol_swap_001_pos', 'zvol_swap_002_pos', 'zvol_swap_003_pos', # 'zvol_swap_004_pos', 'zvol_swap_005_pos', 'zvol_swap_006_pos'] + +[tests/functional/libzfs] +tests = ['many_fds'] diff --git a/tests/zfs-tests/tests/functional/Makefile.am b/tests/zfs-tests/tests/functional/Makefile.am index b974e5930..b59df35ba 100644 --- a/tests/zfs-tests/tests/functional/Makefile.am +++ b/tests/zfs-tests/tests/functional/Makefile.am @@ -23,6 +23,7 @@ SUBDIRS = \ inuse \ large_files \ largest_pool \ + libzfs \ link_count \ migration \ mmap \ diff --git a/tests/zfs-tests/tests/functional/libzfs/.gitignore b/tests/zfs-tests/tests/functional/libzfs/.gitignore new file mode 100644 index 000000000..ed21ddbc9 --- /dev/null +++ b/tests/zfs-tests/tests/functional/libzfs/.gitignore @@ -0,0 +1 @@ +/many_fds diff --git a/tests/zfs-tests/tests/functional/libzfs/Makefile.am b/tests/zfs-tests/tests/functional/libzfs/Makefile.am new file mode 100644 index 000000000..811f09452 --- /dev/null +++ b/tests/zfs-tests/tests/functional/libzfs/Makefile.am @@ -0,0 +1,24 @@ +include $(top_srcdir)/config/Rules.am + +pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/libzfs + +pkgexecdir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/libzfs + +dist_pkgdata_SCRIPTS = \ + cleanup.ksh \ + setup.ksh + +DEFAULT_INCLUDES += \ + -I$(top_srcdir)/include \ + -I$(top_srcdir)/lib/libspl/include + +many_fds_LDADD = \ + $(top_builddir)/lib/libnvpair/libnvpair.la \ + $(top_builddir)/lib/libuutil/libuutil.la \ + $(top_builddir)/lib/libzpool/libzpool.la \ + $(top_builddir)/lib/libzfs/libzfs.la \ + $(top_builddir)/lib/libzfs_core/libzfs_core.la + +pkgexec_PROGRAMS = many_fds +many_fds_SOURCES = many_fds.c + diff --git a/tests/zfs-tests/tests/functional/libzfs/cleanup.ksh b/tests/zfs-tests/tests/functional/libzfs/cleanup.ksh new file mode 100755 index 000000000..3166bd6ec --- /dev/null +++ b/tests/zfs-tests/tests/functional/libzfs/cleanup.ksh @@ -0,0 +1,34 @@ +#!/bin/ksh -p +# +# 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 +# + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# + +# +# Copyright (c) 2013 by Delphix. All rights reserved. +# + +. $STF_SUITE/include/libtest.shlib + +default_cleanup diff --git a/tests/zfs-tests/tests/functional/libzfs/many_fds.c b/tests/zfs-tests/tests/functional/libzfs/many_fds.c new file mode 100644 index 000000000..e09ed60ee --- /dev/null +++ b/tests/zfs-tests/tests/functional/libzfs/many_fds.c @@ -0,0 +1,73 @@ +/* + * 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 + */ + +/* + * Copyright (C) 2015 STRATO AG. + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* + * Check if libzfs works with more than 255 held file handles. + */ +/* ARGSUSED */ +int +main(int argc, char **argv) +{ + int i; + struct rlimit limit; + libzfs_handle_t *h; + + limit.rlim_cur = 65535; + limit.rlim_max = 65535; + + if (setrlimit(RLIMIT_NOFILE, &limit) != 0) { + (void) printf("many_fds: setrlimit() failed with errno=%d\n", + errno); + exit(1); + } + + for (i = 0; i < 255; ++i) { + int fd = open("/dev/null", O_RDONLY); + if (fd == -1) { + (void) printf("open failed with errno=%d\n", errno); + return (1); + } + } + + h = libzfs_init(); + + if (h != NULL) { + libzfs_fini(h); + return (0); + } else { + (void) printf("many_fds: libzfs_init() failed with errno=%d\n", + errno); + return (1); + } +} diff --git a/tests/zfs-tests/tests/functional/libzfs/setup.ksh b/tests/zfs-tests/tests/functional/libzfs/setup.ksh new file mode 100755 index 000000000..fc5cec306 --- /dev/null +++ b/tests/zfs-tests/tests/functional/libzfs/setup.ksh @@ -0,0 +1,35 @@ +#!/bin/ksh -p +# +# 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 +# + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# + +# +# Copyright (c) 2013 by Delphix. All rights reserved. +# + +. $STF_SUITE/include/libtest.shlib + +DISK=${DISKS%% *} +default_setup $DISK -- cgit v1.2.3