bde3d612a7c090234c60e6e4578821237a5db135Simon Klinkert/*
bde3d612a7c090234c60e6e4578821237a5db135Simon Klinkert * CDDL HEADER START
bde3d612a7c090234c60e6e4578821237a5db135Simon Klinkert *
bde3d612a7c090234c60e6e4578821237a5db135Simon Klinkert * The contents of this file are subject to the terms of the
bde3d612a7c090234c60e6e4578821237a5db135Simon Klinkert * Common Development and Distribution License (the "License").
bde3d612a7c090234c60e6e4578821237a5db135Simon Klinkert * You may not use this file except in compliance with the License.
bde3d612a7c090234c60e6e4578821237a5db135Simon Klinkert *
bde3d612a7c090234c60e6e4578821237a5db135Simon Klinkert * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
bde3d612a7c090234c60e6e4578821237a5db135Simon Klinkert * or http://www.opensolaris.org/os/licensing.
bde3d612a7c090234c60e6e4578821237a5db135Simon Klinkert * See the License for the specific language governing permissions
bde3d612a7c090234c60e6e4578821237a5db135Simon Klinkert * and limitations under the License.
bde3d612a7c090234c60e6e4578821237a5db135Simon Klinkert *
bde3d612a7c090234c60e6e4578821237a5db135Simon Klinkert * When distributing Covered Code, include this CDDL HEADER in each
bde3d612a7c090234c60e6e4578821237a5db135Simon Klinkert * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
bde3d612a7c090234c60e6e4578821237a5db135Simon Klinkert * If applicable, add the following below this CDDL HEADER, with the
bde3d612a7c090234c60e6e4578821237a5db135Simon Klinkert * fields enclosed by brackets "[]" replaced with your own identifying
bde3d612a7c090234c60e6e4578821237a5db135Simon Klinkert * information: Portions Copyright [yyyy] [name of copyright owner]
bde3d612a7c090234c60e6e4578821237a5db135Simon Klinkert *
bde3d612a7c090234c60e6e4578821237a5db135Simon Klinkert * CDDL HEADER END
bde3d612a7c090234c60e6e4578821237a5db135Simon Klinkert */
bde3d612a7c090234c60e6e4578821237a5db135Simon Klinkert
bde3d612a7c090234c60e6e4578821237a5db135Simon Klinkert/*
bde3d612a7c090234c60e6e4578821237a5db135Simon Klinkert * Copyright (C) 2015 STRATO AG.
bde3d612a7c090234c60e6e4578821237a5db135Simon Klinkert */
bde3d612a7c090234c60e6e4578821237a5db135Simon Klinkert#include <stdlib.h>
bde3d612a7c090234c60e6e4578821237a5db135Simon Klinkert#include <stdio.h>
bde3d612a7c090234c60e6e4578821237a5db135Simon Klinkert#include <unistd.h>
bde3d612a7c090234c60e6e4578821237a5db135Simon Klinkert#include <sys/types.h>
bde3d612a7c090234c60e6e4578821237a5db135Simon Klinkert#include <sys/stat.h>
bde3d612a7c090234c60e6e4578821237a5db135Simon Klinkert#include <fcntl.h>
bde3d612a7c090234c60e6e4578821237a5db135Simon Klinkert#include <libzfs.h>
bde3d612a7c090234c60e6e4578821237a5db135Simon Klinkert#include <sys/resource.h>
bde3d612a7c090234c60e6e4578821237a5db135Simon Klinkert#include <errno.h>
bde3d612a7c090234c60e6e4578821237a5db135Simon Klinkert
bde3d612a7c090234c60e6e4578821237a5db135Simon Klinkert/*
bde3d612a7c090234c60e6e4578821237a5db135Simon Klinkert * Check if libzfs works with more than 255 held file handles.
bde3d612a7c090234c60e6e4578821237a5db135Simon Klinkert */
bde3d612a7c090234c60e6e4578821237a5db135Simon Klinkert/* ARGSUSED */
bde3d612a7c090234c60e6e4578821237a5db135Simon Klinkertint
bde3d612a7c090234c60e6e4578821237a5db135Simon Klinkertmain(int argc, char **argv)
bde3d612a7c090234c60e6e4578821237a5db135Simon Klinkert{
bde3d612a7c090234c60e6e4578821237a5db135Simon Klinkert int i;
bde3d612a7c090234c60e6e4578821237a5db135Simon Klinkert struct rlimit limit;
bde3d612a7c090234c60e6e4578821237a5db135Simon Klinkert libzfs_handle_t *h;
bde3d612a7c090234c60e6e4578821237a5db135Simon Klinkert
bde3d612a7c090234c60e6e4578821237a5db135Simon Klinkert limit.rlim_cur = 65535;
bde3d612a7c090234c60e6e4578821237a5db135Simon Klinkert limit.rlim_max = 65535;
bde3d612a7c090234c60e6e4578821237a5db135Simon Klinkert
bde3d612a7c090234c60e6e4578821237a5db135Simon Klinkert if (setrlimit(RLIMIT_NOFILE, &limit) != 0) {
bde3d612a7c090234c60e6e4578821237a5db135Simon Klinkert (void) printf("many_fds: setrlimit() failed with errno=%d\n",
bde3d612a7c090234c60e6e4578821237a5db135Simon Klinkert errno);
bde3d612a7c090234c60e6e4578821237a5db135Simon Klinkert exit(1);
bde3d612a7c090234c60e6e4578821237a5db135Simon Klinkert }
bde3d612a7c090234c60e6e4578821237a5db135Simon Klinkert
bde3d612a7c090234c60e6e4578821237a5db135Simon Klinkert for (i = 0; i < 255; ++i) {
bde3d612a7c090234c60e6e4578821237a5db135Simon Klinkert int fd = open("/dev/null", O_RDONLY);
bde3d612a7c090234c60e6e4578821237a5db135Simon Klinkert if (fd == -1) {
bde3d612a7c090234c60e6e4578821237a5db135Simon Klinkert (void) printf("open failed with errno=%d\n", errno);
bde3d612a7c090234c60e6e4578821237a5db135Simon Klinkert return (1);
bde3d612a7c090234c60e6e4578821237a5db135Simon Klinkert }
bde3d612a7c090234c60e6e4578821237a5db135Simon Klinkert }
bde3d612a7c090234c60e6e4578821237a5db135Simon Klinkert
bde3d612a7c090234c60e6e4578821237a5db135Simon Klinkert h = libzfs_init();
bde3d612a7c090234c60e6e4578821237a5db135Simon Klinkert
bde3d612a7c090234c60e6e4578821237a5db135Simon Klinkert if (h != NULL) {
bde3d612a7c090234c60e6e4578821237a5db135Simon Klinkert libzfs_fini(h);
bde3d612a7c090234c60e6e4578821237a5db135Simon Klinkert return (0);
bde3d612a7c090234c60e6e4578821237a5db135Simon Klinkert } else {
bde3d612a7c090234c60e6e4578821237a5db135Simon Klinkert (void) printf("many_fds: libzfs_init() failed with errno=%d\n",
bde3d612a7c090234c60e6e4578821237a5db135Simon Klinkert errno);
bde3d612a7c090234c60e6e4578821237a5db135Simon Klinkert return (1);
bde3d612a7c090234c60e6e4578821237a5db135Simon Klinkert }
bde3d612a7c090234c60e6e4578821237a5db135Simon Klinkert}