diff options
author | Brian Behlendorf <[email protected]> | 2013-11-22 14:52:16 -0800 |
---|---|---|
committer | Brian Behlendorf <[email protected]> | 2014-03-31 16:10:57 -0700 |
commit | 75e3ff58feda2d836c4546c5dc2e98fcd2d1a67b (patch) | |
tree | 56f18f143be48ff4b4d06f93ddc730e77cd9a2f6 /module/zfs/fm.c | |
parent | a2f1945ee3ce8eba02ef54168c72f3be8f2cebdc (diff) |
Add zpool_events_seek() functionality
The ZFS_IOC_EVENTS_SEEK ioctl was added to allow user space callers
to seek around the zevent file descriptor by EID. When a specific
EID is passed and it exists the cursor will be positioned there.
If the EID is no longer cached by the kernel ENOENT is returned.
The caller may also pass ZEVENT_SEEK_START or ZEVENT_SEEK_END to seek
to those respective locations.
Signed-off-by: Brian Behlendorf <[email protected]>
Signed-off-by: Chris Dunlap <[email protected]>
Issue #2
Diffstat (limited to 'module/zfs/fm.c')
-rw-r--r-- | module/zfs/fm.c | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/module/zfs/fm.c b/module/zfs/fm.c index fe9223ff8..246b3d2cf 100644 --- a/module/zfs/fm.c +++ b/module/zfs/fm.c @@ -664,6 +664,67 @@ out: return (error); } +/* + * The caller may seek to a specific EID by passing that EID. If the EID + * is still available in the posted list of events the cursor is positioned + * there. Otherwise ENOENT is returned and the cursor is not moved. + * + * There are two reserved EIDs which may be passed and will never fail. + * ZEVENT_SEEK_START positions the cursor at the start of the list, and + * ZEVENT_SEEK_END positions the cursor at the end of the list. + */ +int +zfs_zevent_seek(zfs_zevent_t *ze, uint64_t eid) +{ + zevent_t *ev; + int error = 0; + + mutex_enter(&zevent_lock); + + if (eid == ZEVENT_SEEK_START) { + if (ze->ze_zevent) + list_remove(&ze->ze_zevent->ev_ze_list, ze); + + ze->ze_zevent = NULL; + goto out; + } + + if (eid == ZEVENT_SEEK_END) { + if (ze->ze_zevent) + list_remove(&ze->ze_zevent->ev_ze_list, ze); + + ev = list_head(&zevent_list); + if (ev) { + ze->ze_zevent = ev; + list_insert_head(&ev->ev_ze_list, ze); + } else { + ze->ze_zevent = NULL; + } + + goto out; + } + + for (ev = list_tail(&zevent_list); ev != NULL; + ev = list_prev(&zevent_list, ev)) { + if (ev->ev_eid == eid) { + if (ze->ze_zevent) + list_remove(&ze->ze_zevent->ev_ze_list, ze); + + ze->ze_zevent = ev; + list_insert_head(&ev->ev_ze_list, ze); + break; + } + } + + if (ev == NULL) + error = ENOENT; + +out: + mutex_exit(&zevent_lock); + + return (error); +} + void zfs_zevent_init(zfs_zevent_t **zep) { |