From bde3d612a7c090234c60e6e4578821237a5db135 Mon Sep 17 00:00:00 2001 From: Simon Klinkert Date: Wed, 11 Mar 2015 11:02:08 +0100 Subject: [PATCH] 5704 libzfs can only handle 255 file descriptors Reviewed by: Josef 'Jeff' Sipek Reviewed by: John Kennedy Approved by: Richard Lowe --- usr/src/lib/libzfs/common/libzfs_util.c | 4 +- usr/src/pkg/manifests/system-test-zfstest.mf | 2 + usr/src/test/zfs-tests/runfiles/delphix.run | 5 ++ usr/src/test/zfs-tests/runfiles/omnios.run | 5 ++ usr/src/test/zfs-tests/runfiles/openindiana.run | 5 ++ usr/src/test/zfs-tests/tests/functional/Makefile | 1 + .../zfs-tests/tests/functional/libzfs/Makefile | 60 ++++++++++++++++++ .../zfs-tests/tests/functional/libzfs/many_fds.c | 73 ++++++++++++++++++++++ 8 files changed, 153 insertions(+), 2 deletions(-) create mode 100644 usr/src/test/zfs-tests/tests/functional/libzfs/Makefile create mode 100644 usr/src/test/zfs-tests/tests/functional/libzfs/many_fds.c diff --git a/usr/src/lib/libzfs/common/libzfs_util.c b/usr/src/lib/libzfs/common/libzfs_util.c index 414d74ee20..7652f6756f 100644 --- a/usr/src/lib/libzfs/common/libzfs_util.c +++ b/usr/src/lib/libzfs/common/libzfs_util.c @@ -624,13 +624,13 @@ libzfs_init(void) return (NULL); } - if ((hdl->libzfs_mnttab = fopen(MNTTAB, "r")) == NULL) { + if ((hdl->libzfs_mnttab = fopen(MNTTAB, "rF")) == NULL) { (void) close(hdl->libzfs_fd); free(hdl); return (NULL); } - hdl->libzfs_sharetab = fopen("/etc/dfs/sharetab", "r"); + hdl->libzfs_sharetab = fopen("/etc/dfs/sharetab", "rF"); if (libzfs_core_init() != 0) { (void) close(hdl->libzfs_fd); diff --git a/usr/src/pkg/manifests/system-test-zfstest.mf b/usr/src/pkg/manifests/system-test-zfstest.mf index 10f8d357df..b3a8c55353 100644 --- a/usr/src/pkg/manifests/system-test-zfstest.mf +++ b/usr/src/pkg/manifests/system-test-zfstest.mf @@ -101,6 +101,7 @@ dir path=opt/zfs-tests/tests/functional/interop dir path=opt/zfs-tests/tests/functional/inuse dir path=opt/zfs-tests/tests/functional/large_files dir path=opt/zfs-tests/tests/functional/largest_pool +dir path=opt/zfs-tests/tests/functional/libzfs dir path=opt/zfs-tests/tests/functional/link_count dir path=opt/zfs-tests/tests/functional/mdb dir path=opt/zfs-tests/tests/functional/migration @@ -1775,6 +1776,7 @@ file path=opt/zfs-tests/tests/functional/largest_pool/largest_pool.cfg \ mode=0555 file path=opt/zfs-tests/tests/functional/largest_pool/largest_pool_001_pos \ mode=0555 +file path=opt/zfs-tests/tests/functional/libzfs/many_fds mode=0555 file path=opt/zfs-tests/tests/functional/link_count/cleanup mode=0555 file path=opt/zfs-tests/tests/functional/link_count/link_count_001 mode=0555 file path=opt/zfs-tests/tests/functional/link_count/setup mode=0555 diff --git a/usr/src/test/zfs-tests/runfiles/delphix.run b/usr/src/test/zfs-tests/runfiles/delphix.run index eef8eef38b..61dd469c66 100644 --- a/usr/src/test/zfs-tests/runfiles/delphix.run +++ b/usr/src/test/zfs-tests/runfiles/delphix.run @@ -524,3 +524,8 @@ tests = ['zvol_misc_001_neg', 'zvol_misc_002_pos', 'zvol_misc_003_neg', [/opt/zfs-tests/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'] + +[/opt/zfs-tests/tests/functional/libzfs] +tests = ['many_fds'] +pre = +post = diff --git a/usr/src/test/zfs-tests/runfiles/omnios.run b/usr/src/test/zfs-tests/runfiles/omnios.run index a4a3184ebe..474365fcd0 100644 --- a/usr/src/test/zfs-tests/runfiles/omnios.run +++ b/usr/src/test/zfs-tests/runfiles/omnios.run @@ -524,3 +524,8 @@ tests = ['zvol_misc_001_neg', 'zvol_misc_002_pos', 'zvol_misc_003_neg', [/opt/zfs-tests/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'] + +[/opt/zfs-tests/tests/functional/libzfs] +tests = ['many_fds'] +pre = +post = diff --git a/usr/src/test/zfs-tests/runfiles/openindiana.run b/usr/src/test/zfs-tests/runfiles/openindiana.run index a4a3184ebe..474365fcd0 100644 --- a/usr/src/test/zfs-tests/runfiles/openindiana.run +++ b/usr/src/test/zfs-tests/runfiles/openindiana.run @@ -524,3 +524,8 @@ tests = ['zvol_misc_001_neg', 'zvol_misc_002_pos', 'zvol_misc_003_neg', [/opt/zfs-tests/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'] + +[/opt/zfs-tests/tests/functional/libzfs] +tests = ['many_fds'] +pre = +post = diff --git a/usr/src/test/zfs-tests/tests/functional/Makefile b/usr/src/test/zfs-tests/tests/functional/Makefile index 39df901840..6248d0d42e 100644 --- a/usr/src/test/zfs-tests/tests/functional/Makefile +++ b/usr/src/test/zfs-tests/tests/functional/Makefile @@ -38,6 +38,7 @@ SUBDIRS = acl \ inuse \ large_files \ largest_pool \ + libzfs \ link_count \ mdb \ migration \ diff --git a/usr/src/test/zfs-tests/tests/functional/libzfs/Makefile b/usr/src/test/zfs-tests/tests/functional/libzfs/Makefile new file mode 100644 index 0000000000..b26af8631f --- /dev/null +++ b/usr/src/test/zfs-tests/tests/functional/libzfs/Makefile @@ -0,0 +1,60 @@ +# +# This file and its contents are supplied under the terms of the +# Common Development and Distribution License ("CDDL"), version 1.0. +# You may only use this file in accordance with the terms of version +# 1.0 of the CDDL. +# +# A full copy of the text of the CDDL should have accompanied this +# source. A copy of the CDDL is also available via the Internet at +# http://www.illumos.org/license/CDDL. +# +# +# Copyright (C) 2015 STRATO AG. All rights reserved. +# + +include $(SRC)/Makefile.master + +ROOTOPTPKG = $(ROOT)/opt/zfs-tests +TESTDIR = $(ROOTOPTPKG)/tests/functional/libzfs +PROG = many_fds +SCRIPTS = + +include $(SRC)/cmd/Makefile.cmd +include $(SRC)/test/Makefile.com + +OBJS = $(PROG:%=%.o) +SRCS = $(OBJS:%.o=%.c) +LDLIBS += -lzfs + +CMDS = $(PROG:%=$(TESTDIR)/%) $(SCRIPTS:%=$(TESTDIR)/%) +$(CMDS) := FILEMODE = 0555 + +all: $(PROG) + +$(PROG): $(OBJS) + $(LINK.c) $(OBJS) -o $@ $(LDLIBS) + $(POST_PROCESS) + +%.o: ../%.c + $(COMPILE.c) $< + +install: all $(CMDS) + +lint: lint_SRCS + +clobber: clean + -$(RM) $(PROG) + +clean: + -$(RM) $(OBJS) + +$(CMDS): $(TESTDIR) $(PROG) + +$(TESTDIR): + $(INS.dir) + +$(TESTDIR)/%: % + $(INS.file) + +$(TESTDIR)/%: %.ksh + $(INS.rename) diff --git a/usr/src/test/zfs-tests/tests/functional/libzfs/many_fds.c b/usr/src/test/zfs-tests/tests/functional/libzfs/many_fds.c new file mode 100644 index 0000000000..e09ed60eef --- /dev/null +++ b/usr/src/test/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); + } +} -- 2.11.4.GIT