X-Git-Url: https://git.camperquake.de/gitweb.cgi?a=blobdiff_plain;f=lib%2Flibshare%2Fnfs.c;h=00ba0f621347a5b1cafb18828cf7e4be5cfcfad2;hb=5853fe790d1df58c5dd85ea52c5e165b6d43013c;hp=22e306d4370f7619466fcae141b8ab45a722a1ac;hpb=590338f63ee0db6f1fc7e6b5b23744d3944777b2;p=zfs.git diff --git a/lib/libshare/nfs.c b/lib/libshare/nfs.c index 22e306d..00ba0f6 100644 --- a/lib/libshare/nfs.c +++ b/lib/libshare/nfs.c @@ -22,6 +22,7 @@ /* * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2011 Gunnar Beutner + * Copyright (c) 2012 Cyril Plisko. All rights reserved. */ #include @@ -33,8 +34,9 @@ #include #include "libshare_impl.h" +static boolean_t nfs_available(void); + static sa_fstype_t *nfs_fstype; -static boolean_t nfs_available; /* * nfs_exportfs_temp_fd refers to a temporary copy of the output @@ -360,7 +362,7 @@ get_linux_shareopts_cb(const char *key, const char *value, void *cookie) strcmp(key, "root_squash") != 0 && strcmp(key, "no_root_squash") != 0 && strcmp(key, "all_squash") != 0 && - strcmp(key, "no_all_squash") != 0 && + strcmp(key, "no_all_squash") != 0 && strcmp(key, "fsid") != 0 && strcmp(key, "anonuid") != 0 && strcmp(key, "anongid") != 0) { return SA_SYNTAX_ERR; } @@ -407,7 +409,7 @@ nfs_enable_share(sa_share_impl_t impl_share) char *shareopts, *linux_opts; int rc; - if (!nfs_available) { + if (!nfs_available()) { return SA_SYSTEM_ERR; } @@ -480,7 +482,7 @@ nfs_disable_share_one(const char *sharepath, const char *host, static int nfs_disable_share(sa_share_impl_t impl_share) { - if (!nfs_available) { + if (!nfs_available()) { /* * The share can't possibly be active, so nothing * needs to be done to disable it. @@ -514,13 +516,13 @@ nfs_validate_shareopts(const char *shareopts) * Checks whether a share is currently active. */ static boolean_t -is_share_active(sa_share_impl_t impl_share) +nfs_is_share_active(sa_share_impl_t impl_share) { char line[512]; char *tab, *cur; FILE *nfs_exportfs_temp_fp; - if (nfs_exportfs_temp_fd < 0) + if (!nfs_available()) return B_FALSE; nfs_exportfs_temp_fp = fdopen(dup(nfs_exportfs_temp_fd), "r"); @@ -585,7 +587,8 @@ nfs_update_shareopts(sa_share_impl_t impl_share, const char *resource, boolean_t needs_reshare = B_FALSE; char *old_shareopts; - FSINFO(impl_share, nfs_fstype)->active = is_share_active(impl_share); + FSINFO(impl_share, nfs_fstype)->active = + nfs_is_share_active(impl_share); old_shareopts = FSINFO(impl_share, nfs_fstype)->shareopts; @@ -671,18 +674,27 @@ nfs_check_exportfs(void) pid = fork(); - if (pid < 0) + if (pid < 0) { + (void) close(nfs_exportfs_temp_fd); + nfs_exportfs_temp_fd = -1; return SA_SYSTEM_ERR; + } if (pid > 0) { while ((rc = waitpid(pid, &status, 0)) <= 0 && errno == EINTR) ; /* empty loop body */ - if (rc <= 0) + if (rc <= 0) { + (void) close(nfs_exportfs_temp_fd); + nfs_exportfs_temp_fd = -1; return SA_SYSTEM_ERR; + } - if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) + if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) { + (void) close(nfs_exportfs_temp_fd); + nfs_exportfs_temp_fd = -1; return SA_CONFIG_ERR; + } return SA_OK; } @@ -703,13 +715,23 @@ nfs_check_exportfs(void) exit(0); } +/* + * Provides a convenient wrapper for determing nfs availability + */ +static boolean_t +nfs_available(void) +{ + if (nfs_exportfs_temp_fd == -1) + (void) nfs_check_exportfs(); + + return (nfs_exportfs_temp_fd != -1) ? B_TRUE : B_FALSE; +} + /** * Initializes the NFS functionality of libshare. */ void libshare_nfs_init(void) { - nfs_available = (nfs_check_exportfs() == SA_OK); - nfs_fstype = register_fstype("nfs", &nfs_shareops); }