From 868e5de06655ed389871847f7adb66843f792b25 Mon Sep 17 00:00:00 2001 From: Brian Behlendorf Date: Fri, 21 May 2010 10:47:59 -0700 Subject: [PATCH] Add linux-user-util topic branch. This topic branch contains required changes to the user space utilities to allow them to integrate cleanly with Linux. --- .topdeps | 4 +--- .topmsg | 18 +++--------------- cmd/zdb/zdb.c | 4 ++-- cmd/zfs/zfs_main.c | 22 ++++++++++------------ cmd/zinject/zinject.c | 23 ++++++++++------------- cmd/zpool/zpool_main.c | 16 +++++++--------- lib/libzfs/libzfs_sendrecv.c | 1 + lib/libzfs/libzfs_util.c | 7 +++++++ 8 files changed, 41 insertions(+), 54 deletions(-) diff --git a/.topdeps b/.topdeps index 607c231780..7f16cbcdd5 100644 --- a/.topdeps +++ b/.topdeps @@ -1,3 +1 @@ -gcc-branch -fix-branch -feature-branch +zfs-branch diff --git a/.topmsg b/.topmsg index 03967cdff5..e37e8f4bfc 100644 --- a/.topmsg +++ b/.topmsg @@ -1,19 +1,7 @@ From: Brian Behlendorf -Subject: [PATCH] zfs branch +Subject: [PATCH] linux user util -Merged result of all changes which are relevant to both Solaris -and Linux builds of the ZFS code. These are changes where there -is a reasonable chance they will be accepted upstream. - -Additionally, since this is effectively the root of the linux -ZFS tree the core linux build system is added here. This -includes autogen.sh, configure.ac, m4 macros, some scripts/*, -and makefiles for all the core ZFS components. Linux-only -features which require tweaks to the build system should appear -on the relevant topic branches. All autotools products which -result from autogen.sh are commited to the linux-configure-branch. - -This branch also contains the META, ChangeLog, AUTHORS, TODO, -and README, files. +This topic branch contains required changes to the user space +utilities to allow them to integrate cleanly with Linux. Signed-off-by: Brian Behlendorf diff --git a/cmd/zdb/zdb.c b/cmd/zdb/zdb.c index ce84349586..dd1cb70da2 100644 --- a/cmd/zdb/zdb.c +++ b/cmd/zdb/zdb.c @@ -2394,8 +2394,8 @@ main(int argc, char **argv) } kernel_init(FREAD); - g_zfs = libzfs_init(); - ASSERT(g_zfs != NULL); + if ((g_zfs = libzfs_init()) == NULL) + return (1); for (c = 0; c < 256; c++) { if (dump_all && c != 'l' && c != 'R') diff --git a/cmd/zfs/zfs_main.c b/cmd/zfs/zfs_main.c index 91b85ed6b8..fafc0a87fe 100644 --- a/cmd/zfs/zfs_main.c +++ b/cmd/zfs/zfs_main.c @@ -4035,17 +4035,6 @@ main(int argc, char **argv) opterr = 0; - if ((g_zfs = libzfs_init()) == NULL) { - (void) fprintf(stderr, gettext("internal error: failed to " - "initialize ZFS library\n")); - return (1); - } - - zpool_set_history_str("zfs", argc, argv, history_str); - verify(zpool_stage_history(g_zfs, history_str) == 0); - - libzfs_print_on_error(g_zfs, B_TRUE); - if ((mnttab_file = fopen(MNTTAB, "r")) == NULL) { (void) fprintf(stderr, gettext("internal error: unable to " "open %s\n"), MNTTAB); @@ -4087,9 +4076,18 @@ main(int argc, char **argv) /* * Special case '-?' */ - if (strcmp(cmdname, "-?") == 0) + if ((strcmp(cmdname, "-?") == 0) || + (strcmp(cmdname, "--help") == 0)) usage(B_TRUE); + if ((g_zfs = libzfs_init()) == NULL) + return (1); + + zpool_set_history_str("zfs", argc, argv, history_str); + verify(zpool_stage_history(g_zfs, history_str) == 0); + + libzfs_print_on_error(g_zfs, B_TRUE); + /* * 'volinit' and 'volfini' do not appear in the usage message, * so we have to special case them here. diff --git a/cmd/zinject/zinject.c b/cmd/zinject/zinject.c index 09c377ef8d..1be9899bb4 100644 --- a/cmd/zinject/zinject.c +++ b/cmd/zinject/zinject.c @@ -486,19 +486,6 @@ main(int argc, char **argv) int ret; int flags = 0; - if ((g_zfs = libzfs_init()) == NULL) { - (void) fprintf(stderr, "internal error: failed to " - "initialize ZFS library\n"); - return (1); - } - - libzfs_print_on_error(g_zfs, B_TRUE); - - if ((zfs_fd = open(ZFS_DEV, O_RDWR)) < 0) { - (void) fprintf(stderr, "failed to open ZFS device\n"); - return (1); - } - if (argc == 1) { /* * No arguments. Print the available handlers. If there are no @@ -612,6 +599,16 @@ main(int argc, char **argv) argc -= optind; argv += optind; + if ((g_zfs = libzfs_init()) == NULL) + return (1); + + libzfs_print_on_error(g_zfs, B_TRUE); + + if ((zfs_fd = open(ZFS_DEV, O_RDWR)) < 0) { + (void) fprintf(stderr, "failed to open ZFS device\n"); + return (1); + } + if (cancel != NULL) { /* * '-c' is invalid with any other options. diff --git a/cmd/zpool/zpool_main.c b/cmd/zpool/zpool_main.c index 3cdc269b08..2cdd4087b1 100644 --- a/cmd/zpool/zpool_main.c +++ b/cmd/zpool/zpool_main.c @@ -3921,14 +3921,6 @@ main(int argc, char **argv) (void) setlocale(LC_ALL, ""); (void) textdomain(TEXT_DOMAIN); - if ((g_zfs = libzfs_init()) == NULL) { - (void) fprintf(stderr, gettext("internal error: failed to " - "initialize ZFS library\n")); - return (1); - } - - libzfs_print_on_error(g_zfs, B_TRUE); - opterr = 0; /* @@ -3944,9 +3936,15 @@ main(int argc, char **argv) /* * Special case '-?' */ - if (strcmp(cmdname, "-?") == 0) + if ((strcmp(cmdname, "-?") == 0) || + strcmp(cmdname, "--help") == 0) usage(B_TRUE); + if ((g_zfs = libzfs_init()) == NULL) + return (1); + + libzfs_print_on_error(g_zfs, B_TRUE); + zpool_set_history_str("zpool", argc, argv, history_str); verify(zpool_stage_history(g_zfs, history_str) == 0); diff --git a/lib/libzfs/libzfs_sendrecv.c b/lib/libzfs/libzfs_sendrecv.c index be5b3949f7..eb799901d6 100644 --- a/lib/libzfs/libzfs_sendrecv.c +++ b/lib/libzfs/libzfs_sendrecv.c @@ -39,6 +39,7 @@ #include #include #include +#include #include #include diff --git a/lib/libzfs/libzfs_util.c b/lib/libzfs/libzfs_util.c index 8d0c47e301..2059fdab61 100644 --- a/lib/libzfs/libzfs_util.c +++ b/lib/libzfs/libzfs_util.c @@ -578,6 +578,13 @@ libzfs_init(void) } if ((hdl->libzfs_fd = open(ZFS_DEV, O_RDWR)) < 0) { + (void) fprintf(stderr, gettext("Unable to open %s: %s.\n"), + ZFS_DEV, strerror(errno)); + if (errno == ENOENT) + (void) fprintf(stderr, + gettext("Verify the ZFS module stack is " + "loaded by running '/sbin/modprobe zfs'.\n")); + free(hdl); return (NULL); }