]> git.proxmox.com Git - mirror_zfs.git/commitdiff
Replace zpool_events_next() "block" parm w/ "flags"
authorChris Dunlap <cdunlap@llnl.gov>
Wed, 12 Feb 2014 18:30:18 +0000 (10:30 -0800)
committerBrian Behlendorf <behlendorf1@llnl.gov>
Mon, 31 Mar 2014 23:11:21 +0000 (16:11 -0700)
zpool_events_next() can be called in blocking mode by specifying a
non-zero value for the "block" parameter.  However, the design of
the ZFS Event Daemon (zed) requires additional functionality from
zpool_events_next().  Instead of adding additional arguments to the
function, it makes more sense to use flags that can be bitwise-or'd
together.

This commit replaces the zpool_events_next() int "block" parameter with
an unsigned bitwise "flags" parameter.  It also defines ZEVENT_NONE
to specify the default behavior.  Since non-blocking mode can be
specified with the existing ZEVENT_NONBLOCK flag, the default behavior
becomes blocking mode.  This, in effect, inverts the previous use
of the "block" parameter.  Existing callers of zpool_events_next()
have been modified to check for the ZEVENT_NONBLOCK flag.

Signed-off-by: Chris Dunlap <cdunlap@llnl.gov>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Issue #2

cmd/zpool/zpool_main.c
include/libzfs.h
include/sys/zfs_ioctl.h
lib/libzfs/libzfs_pool.c

index 4254f9b4d7c5a23d8ae3f777a80507316396d3d9..cc13e37393944f30afe680578db8afa1d7d7dbae 100644 (file)
@@ -49,6 +49,7 @@
 #include <sys/stat.h>
 #include <sys/fm/util.h>
 #include <sys/fm/protocol.h>
+#include <sys/zfs_ioctl.h>
 
 #include <libzfs.h>
 
@@ -5465,7 +5466,7 @@ zpool_do_events_next(ev_opts_t *opts)
 
        while (1) {
                ret = zpool_events_next(g_zfs, &nvl, &dropped,
-                   !!opts->follow, zevent_fd);
+                   (opts->follow ? ZEVENT_NONE : ZEVENT_NONBLOCK), zevent_fd);
                if (ret || nvl == NULL)
                        break;
 
index cb78f1d6293126f7c3764672f4d1f9e2b0748ed1..5bc8b03ef4b3ba507884e163ec181c4f2e79abb1 100644 (file)
@@ -408,7 +408,8 @@ extern int zpool_upgrade(zpool_handle_t *, uint64_t);
 extern int zpool_get_history(zpool_handle_t *, nvlist_t **);
 extern int zpool_history_unpack(char *, uint64_t, uint64_t *,
     nvlist_t ***, uint_t *);
-extern int zpool_events_next(libzfs_handle_t *, nvlist_t **, int *, int, int);
+extern int zpool_events_next(libzfs_handle_t *, nvlist_t **, int *, unsigned,
+    int);
 extern int zpool_events_clear(libzfs_handle_t *, int *);
 extern int zpool_events_seek(libzfs_handle_t *, uint64_t, int);
 extern void zpool_obj_to_path(zpool_handle_t *, uint64_t, uint64_t, char *,
index c63b16c78d321134844b147989bb97fa04ecde69..0ab095c1ae95b4b170a12b00fccc87f0dfefb516 100644 (file)
@@ -259,6 +259,7 @@ typedef struct zinject_record {
 #define        ZINJECT_FLUSH_ARC       0x2
 #define        ZINJECT_UNLOAD_SPA      0x4
 
+#define        ZEVENT_NONE             0x0
 #define        ZEVENT_NONBLOCK         0x1
 #define        ZEVENT_SIZE             1024
 
index 2054385b8d3527c3c0b4a9da3ca47ec32ee7481d..db1f0d7cf2be398d286edf58d718d90a22c3e801 100644 (file)
@@ -3790,11 +3790,12 @@ zpool_get_history(zpool_handle_t *zhp, nvlist_t **nvhisp)
  * no new events are available.  In either case the function returns 0 and
  * it is up to the caller to free 'nvp'.  In the case of a fatal error the
  * function will return a non-zero value.  When the function is called in
- * blocking mode it will not return until a new event is available.
+ * blocking mode (the default, unless the ZEVENT_NONBLOCK flag is passed),
+ * it will not return until a new event is available.
  */
 int
 zpool_events_next(libzfs_handle_t *hdl, nvlist_t **nvp,
-    int *dropped, int block, int zevent_fd)
+    int *dropped, unsigned flags, int zevent_fd)
 {
        zfs_cmd_t zc = {"\0"};
        int error = 0;
@@ -3803,7 +3804,7 @@ zpool_events_next(libzfs_handle_t *hdl, nvlist_t **nvp,
        *dropped = 0;
        zc.zc_cleanup_fd = zevent_fd;
 
-       if (!block)
+       if (flags & ZEVENT_NONBLOCK)
                zc.zc_guid = ZEVENT_NONBLOCK;
 
        if (zcmd_alloc_dst_nvlist(hdl, &zc, ZEVENT_SIZE) != 0)
@@ -3818,7 +3819,7 @@ retry:
                        goto out;
                case ENOENT:
                        /* Blocking error case should not occur */
-                       if (block)
+                       if (!(flags & ZEVENT_NONBLOCK))
                                error = zpool_standard_error_fmt(hdl, errno,
                                    dgettext(TEXT_DOMAIN, "cannot get event"));