summaryrefslogtreecommitdiff
path: root/usr/src/lib/libzfs/common/libzfs_util.c
diff options
context:
space:
mode:
authoreschrock <none@none>2006-03-03 20:08:16 -0800
committereschrock <none@none>2006-03-03 20:08:16 -0800
commitea8dc4b6d2251b437950c0056bc626b311c73c27 (patch)
tree69cc1808568f2ef8fd1e21c61e186ba452ea64da /usr/src/lib/libzfs/common/libzfs_util.c
parent5c18afbc96a46bc3a9e6f3667512daa374d6cd79 (diff)
downloadillumos-joyent-ea8dc4b6d2251b437950c0056bc626b311c73c27.tar.gz
PSARC 2006/077 zpool clear
PSARC 2006/139 FMA for ZFS 6284889 arc should replace the znode cache 6333006 DMU & DSL should not panic upon I/O error 6333092 concurrent reads to a file not scaling with number of readers 6338081 ZFS/FMA phase 1 6338386 need persistent error log 6341326 i/o error causes arc buf hash table corruption 6341639 zfs backup/restore should compute/verify checksum of backup stream 6348002 out of space due to changing properties 6354724 inaccurate error message from zfs restore 6354872 dmu_sync() blows predictive accounting 6355416 zpool scrubbing consumes all memory, system hung 6363995 df should only load libzfs when it encounters a ZFS filesystem 6366320 zfs backup/restore doesn't like signals 6368892 mount -m support needed for legacy mounts 6368902 boot archive fstat support needed for ZFS Mountroot 6369424 BFU complains when bfu'ing a ZFS root filesystem 6374062 mountroot support needed for ZFS 6376356 dirtying dbuf obj=43 lvl=0 blkid=0 but not tx_held 6378391 unused members of dmu_objset_stats_t 6378392 clean up zfs_cmd_t structure 6378685 buf_init should allocate its hash table more carefully 6378976 ziltest should be a first class citizen 6381086 zdb segfaults if there is a spa deferred-free bplist 6381203 deadlock due to i/o while assigning (tc_lock held) 6381209 freed space is not immediately available 6381344 'zpool clear' 6381345 FAULTED devices should really be UNAVAIL 6381346 import should mark devices as persistently unavailable 6383272 recursive mutex_enter() during log replay with zfs root 6386326 origin property is not displayed 6386354 libzfs does too much in its _init section, calls exit(1) 6386624 zpool should not complain about non-existent devices from libdiskmgt 6386910 spa needs to be i/o error hardened 6387735 need a mechanism to inject faults into ZFS 6387736 internal ZFS utilities should be placed in an ON-private package 6389928 libzfs should ship a lint library 6390609 malformed vdev config panics on zpool_create() 6390677 version number checking makes upgrades challenging 6390713 ztest hangs in zil_suspend() 6391873 metadata compression should be turned back on 6392113 ztest sometimes reports leaked blocks because ZIL isn't resilvered 6393004 minor memory leak in unique_insert()
Diffstat (limited to 'usr/src/lib/libzfs/common/libzfs_util.c')
-rw-r--r--usr/src/lib/libzfs/common/libzfs_util.c61
1 files changed, 42 insertions, 19 deletions
diff --git a/usr/src/lib/libzfs/common/libzfs_util.c b/usr/src/lib/libzfs/common/libzfs_util.c
index d164c4585d..c7f7528491 100644
--- a/usr/src/lib/libzfs/common/libzfs_util.c
+++ b/usr/src/lib/libzfs/common/libzfs_util.c
@@ -2,9 +2,8 @@
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License"). You may not use this file except in compliance
- * with the License.
+ * 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.
@@ -20,7 +19,7 @@
* CDDL HEADER END
*/
/*
- * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -44,7 +43,10 @@
#include "libzfs_impl.h"
-int zfs_fd;
+static int zfs_fd = -1;
+static FILE *mnttab_file;
+static FILE *sharetab_file;
+static int sharetab_opened;
void (*error_func)(const char *, va_list);
@@ -144,34 +146,55 @@ zfs_strdup(const char *str)
}
/*
- * Initialize the library. Sets the command name used when reporting errors.
- * This command name is used to prefix all error messages appropriately.
- * Also opens /dev/zfs and dies if it cannot be opened.
+ * Utility functions around common used files - /dev/zfs, /etc/mnttab, and
+ * /etc/dfs/sharetab.
*/
-#pragma init(zfs_init)
-void
-zfs_init(void)
+int
+zfs_ioctl(int cmd, zfs_cmd_t *zc)
{
- if ((zfs_fd = open(ZFS_DEV, O_RDWR)) < 0)
- zfs_fatal(dgettext(TEXT_DOMAIN,
- "internal error: cannot open zfs device"));
+ if (zfs_fd == -1 &&
+ (zfs_fd = open(ZFS_DEV, O_RDWR)) < 0)
+ zfs_fatal(dgettext(TEXT_DOMAIN, "internal error: unable to "
+ "open ZFS device\n"), MNTTAB);
- if ((mnttab_file = fopen(MNTTAB, "r")) == NULL)
+ return (ioctl(zfs_fd, cmd, zc));
+}
+
+FILE *
+zfs_mnttab(void)
+{
+ if (mnttab_file == NULL &&
+ (mnttab_file = fopen(MNTTAB, "r")) == NULL)
zfs_fatal(dgettext(TEXT_DOMAIN, "internal error: unable to "
"open %s\n"), MNTTAB);
- sharetab_file = fopen("/etc/dfs/sharetab", "r");
+ return (mnttab_file);
+}
+
+FILE *
+zfs_sharetab(void)
+{
+ if (sharetab_opened)
+ return (sharetab_file);
+
+ sharetab_opened = TRUE;
+ return (sharetab_file = fopen("/etc/dfs/sharetab", "r"));
}
/*
- * Cleanup function for library. Simply close the file descriptors that we
- * opened as part of libzfs_init().
+ * Cleanup function for library. Close any file descriptors that were
+ * opened as part of the above functions.
*/
#pragma fini(zfs_fini)
void
zfs_fini(void)
{
- (void) close(zfs_fd);
+ if (zfs_fd != -1)
+ (void) close(zfs_fd);
+ if (sharetab_file)
+ (void) fclose(sharetab_file);
+ if (mnttab_file)
+ (void) fclose(mnttab_file);
}
/*