mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2026-05-22 02:27:36 +03:00
OpenZFS 9425 - channel programs can be interrupted
Problem Statement ================= ZFS Channel program scripts currently require a timeout, so that hung or long-running scripts return a timeout error instead of causing ZFS to get wedged. This limit can currently be set up to 100 million Lua instructions. Even with a limit in place, it would be desirable to have a sys admin (support engineer) be able to cancel a script that is taking a long time. Proposed Solution ================= Make it possible to abort a channel program by sending an interrupt signal.In the underlying txg_wait_sync function, switch the cv_wait to a cv_wait_sig to catch the signal. Once a signal is encountered, the dsl_sync_task function can install a Lua hook that will get called before the Lua interpreter executes a new line of code. The dsl_sync_task can resume with a standard txg_wait_sync call and wait for the txg to complete. Meanwhile, the hook will abort the script and indicate that the channel program was canceled. The kernel returns a EINTR to indicate that the channel program run was canceled. Porting notes: Added missing return value from cv_wait_sig() Authored by: Don Brady <don.brady@delphix.com> Reviewed by: Sebastien Roy <sebastien.roy@delphix.com> Reviewed by: Serapheim Dimitropoulos <serapheim.dimitro@delphix.com> Reviewed by: Matt Ahrens <matt@delphix.com> Reviewed by: Sara Hartse <sara.hartse@delphix.com> Reviewed by: Brian Behlendorf <behlendorf1@llnl.gov> Approved by: Robert Mustacchi <rm@joyent.com> Ported-by: Don Brady <don.brady@delphix.com> Signed-off-by: Don Brady <don.brady@delphix.com> OpenZFS-issue: https://www.illumos.org/issues/9425 OpenZFS-commit: https://github.com/illumos/illumos-gate/commit/d0cb1fb926 Closes #8904
This commit is contained in:
@@ -54,7 +54,8 @@ extern void __cv_init(kcondvar_t *, char *, kcv_type_t, void *);
|
||||
extern void __cv_destroy(kcondvar_t *);
|
||||
extern void __cv_wait(kcondvar_t *, kmutex_t *);
|
||||
extern void __cv_wait_io(kcondvar_t *, kmutex_t *);
|
||||
extern void __cv_wait_sig(kcondvar_t *, kmutex_t *);
|
||||
extern int __cv_wait_io_sig(kcondvar_t *, kmutex_t *);
|
||||
extern int __cv_wait_sig(kcondvar_t *, kmutex_t *);
|
||||
extern clock_t __cv_timedwait(kcondvar_t *, kmutex_t *, clock_t);
|
||||
extern clock_t __cv_timedwait_io(kcondvar_t *, kmutex_t *, clock_t);
|
||||
extern clock_t __cv_timedwait_sig(kcondvar_t *, kmutex_t *, clock_t);
|
||||
@@ -69,6 +70,7 @@ extern void __cv_broadcast(kcondvar_t *c);
|
||||
#define cv_destroy(cvp) __cv_destroy(cvp)
|
||||
#define cv_wait(cvp, mp) __cv_wait(cvp, mp)
|
||||
#define cv_wait_io(cvp, mp) __cv_wait_io(cvp, mp)
|
||||
#define cv_wait_io_sig(cvp, mp) __cv_wait_io_sig(cvp, mp)
|
||||
#define cv_wait_sig(cvp, mp) __cv_wait_sig(cvp, mp)
|
||||
#define cv_wait_interruptible(cvp, mp) cv_wait_sig(cvp, mp)
|
||||
#define cv_timedwait(cvp, mp, t) __cv_timedwait(cvp, mp, t)
|
||||
|
||||
@@ -37,6 +37,7 @@ struct dsl_pool;
|
||||
|
||||
typedef int (dsl_checkfunc_t)(void *, dmu_tx_t *);
|
||||
typedef void (dsl_syncfunc_t)(void *, dmu_tx_t *);
|
||||
typedef void (dsl_sigfunc_t)(void *, dmu_tx_t *);
|
||||
|
||||
typedef enum zfs_space_check {
|
||||
/*
|
||||
@@ -116,6 +117,8 @@ int dsl_early_sync_task(const char *, dsl_checkfunc_t *,
|
||||
dsl_syncfunc_t *, void *, int, zfs_space_check_t);
|
||||
void dsl_early_sync_task_nowait(struct dsl_pool *, dsl_syncfunc_t *,
|
||||
void *, int, zfs_space_check_t, dmu_tx_t *);
|
||||
int dsl_sync_task_sig(const char *, dsl_checkfunc_t *, dsl_syncfunc_t *,
|
||||
dsl_sigfunc_t *, void *, int, zfs_space_check_t);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -87,6 +87,11 @@ extern void txg_kick(struct dsl_pool *dp);
|
||||
*/
|
||||
extern void txg_wait_synced(struct dsl_pool *dp, uint64_t txg);
|
||||
|
||||
/*
|
||||
* Wait as above. Returns true if the thread was signaled while waiting.
|
||||
*/
|
||||
extern boolean_t txg_wait_synced_sig(struct dsl_pool *dp, uint64_t txg);
|
||||
|
||||
/*
|
||||
* Wait until the given transaction group, or one after it, is
|
||||
* the open transaction group. Try to make this happen as soon
|
||||
|
||||
@@ -52,6 +52,12 @@ typedef struct zcp_cleanup_handler {
|
||||
list_node_t zch_node;
|
||||
} zcp_cleanup_handler_t;
|
||||
|
||||
typedef struct zcp_alloc_arg {
|
||||
boolean_t aa_must_succeed;
|
||||
int64_t aa_alloc_remaining;
|
||||
int64_t aa_alloc_limit;
|
||||
} zcp_alloc_arg_t;
|
||||
|
||||
typedef struct zcp_run_info {
|
||||
dsl_pool_t *zri_pool;
|
||||
|
||||
@@ -93,6 +99,11 @@ typedef struct zcp_run_info {
|
||||
*/
|
||||
boolean_t zri_timed_out;
|
||||
|
||||
/*
|
||||
* Channel program was canceled by user
|
||||
*/
|
||||
boolean_t zri_canceled;
|
||||
|
||||
/*
|
||||
* Boolean indicating whether or not we are running in syncing
|
||||
* context.
|
||||
@@ -104,6 +115,26 @@ typedef struct zcp_run_info {
|
||||
* triggered in the event of a fatal error.
|
||||
*/
|
||||
list_t zri_cleanup_handlers;
|
||||
|
||||
/*
|
||||
* The Lua state context of our channel program.
|
||||
*/
|
||||
lua_State *zri_state;
|
||||
|
||||
/*
|
||||
* Lua memory allocator arguments.
|
||||
*/
|
||||
zcp_alloc_arg_t *zri_allocargs;
|
||||
|
||||
/*
|
||||
* Contains output values from zcp script or error string.
|
||||
*/
|
||||
nvlist_t *zri_outnvl;
|
||||
|
||||
/*
|
||||
* The errno number returned to caller of zcp_eval().
|
||||
*/
|
||||
int zri_result;
|
||||
} zcp_run_info_t;
|
||||
|
||||
zcp_run_info_t *zcp_run_info(lua_State *);
|
||||
|
||||
@@ -307,6 +307,7 @@ typedef pthread_cond_t kcondvar_t;
|
||||
extern void cv_init(kcondvar_t *cv, char *name, int type, void *arg);
|
||||
extern void cv_destroy(kcondvar_t *cv);
|
||||
extern void cv_wait(kcondvar_t *cv, kmutex_t *mp);
|
||||
extern int cv_wait_sig(kcondvar_t *cv, kmutex_t *mp);
|
||||
extern clock_t cv_timedwait(kcondvar_t *cv, kmutex_t *mp, clock_t abstime);
|
||||
extern clock_t cv_timedwait_hires(kcondvar_t *cvp, kmutex_t *mp, hrtime_t tim,
|
||||
hrtime_t res, int flag);
|
||||
@@ -315,8 +316,8 @@ extern void cv_broadcast(kcondvar_t *cv);
|
||||
|
||||
#define cv_timedwait_io(cv, mp, at) cv_timedwait(cv, mp, at)
|
||||
#define cv_timedwait_sig(cv, mp, at) cv_timedwait(cv, mp, at)
|
||||
#define cv_wait_sig(cv, mp) cv_wait(cv, mp)
|
||||
#define cv_wait_io(cv, mp) cv_wait(cv, mp)
|
||||
#define cv_wait_io_sig(cv, mp) cv_wait_sig(cv, mp)
|
||||
#define cv_timedwait_sig_hires(cv, mp, t, r, f) \
|
||||
cv_timedwait_hires(cv, mp, t, r, f)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user