svn commit: r355725 - in head/sys: kern sys
John Baldwin
jhb at FreeBSD.org
Fri Dec 13 19:26:05 UTC 2019
Author: jhb
Date: Fri Dec 13 19:26:04 2019
New Revision: 355725
URL: https://svnweb.freebsd.org/changeset/base/355725
Log:
Use callout(9) instead of deprecated timeout(9) for fail points.
Allocate the callout structure on-demand from
fail_point_use_timeout_path() since most fail points do not use
timeouts.
Reviewed by: markj (earlier version), cem
Differential Revision: https://reviews.freebsd.org/D22599
Modified:
head/sys/kern/kern_fail.c
head/sys/sys/fail.h
Modified: head/sys/kern/kern_fail.c
==============================================================================
--- head/sys/kern/kern_fail.c Fri Dec 13 19:21:58 2019 (r355724)
+++ head/sys/kern/kern_fail.c Fri Dec 13 19:26:04 2019 (r355725)
@@ -403,6 +403,8 @@ fail_point_drain(struct fail_point *fp, int expected_r
wakeup(FP_PAUSE_CHANNEL(fp));
tsleep(&fp, PWAIT, "fail_point_drain", hz / 100);
}
+ if (fp->fp_callout)
+ callout_drain(fp->fp_callout);
fail_point_swap_settings(fp, entries);
}
@@ -442,8 +444,8 @@ fail_point_sleep(struct fail_point *fp, int msecs,
if (fp->fp_pre_sleep_fn)
fp->fp_pre_sleep_fn(fp->fp_pre_sleep_arg);
- timeout(fp->fp_post_sleep_fn, fp->fp_post_sleep_arg,
- timo);
+ callout_reset(fp->fp_callout, timo,
+ fp->fp_post_sleep_fn, fp->fp_post_sleep_arg);
*pret = FAIL_POINT_RC_QUEUED;
}
}
@@ -493,6 +495,20 @@ fail_point_init(struct fail_point *fp, const char *fmt
fp->fp_post_sleep_arg = NULL;
}
+void
+fail_point_alloc_callout(struct fail_point *fp)
+{
+
+ /**
+ * This assumes that calls to fail_point_use_timeout_path()
+ * will not race.
+ */
+ if (fp->fp_callout != NULL)
+ return;
+ fp->fp_callout = fp_malloc(sizeof(*fp->fp_callout), M_WAITOK);
+ callout_init(fp->fp_callout, CALLOUT_MPSAFE);
+}
+
/**
* Free the resources held by a fail_point, and wake any paused threads.
* Thou shalt not allow threads to hit this fail point after you enter this
@@ -510,6 +526,10 @@ fail_point_destroy(struct fail_point *fp)
fp->fp_name = NULL;
}
fp->fp_flags = 0;
+ if (fp->fp_callout) {
+ fp_free(fp->fp_callout);
+ fp->fp_callout = NULL;
+ }
sx_xlock(&sx_fp_set);
fail_point_garbage_collect();
Modified: head/sys/sys/fail.h
==============================================================================
--- head/sys/sys/fail.h Fri Dec 13 19:21:58 2019 (r355724)
+++ head/sys/sys/fail.h Fri Dec 13 19:26:04 2019 (r355725)
@@ -84,6 +84,8 @@ struct fail_point {
void (*fp_post_sleep_fn)(void *);
/**< Arg for fp_post_sleep_fn */
void *fp_post_sleep_arg;
+
+ struct callout *fp_callout;
};
#define FAIL_POINT_DYNAMIC_NAME 0x01 /**< Must free name on destroy */
@@ -149,9 +151,12 @@ fail_point_sleep_set_post_arg(struct fail_point *fp, v
{
fp->fp_post_sleep_arg = sleep_arg;
}
+
+void fail_point_alloc_callout(struct fail_point *);
+
/**
* If the FAIL_POINT_USE_TIMEOUT flag is set on a failpoint, then
- * FAIL_POINT_SLEEP will result in a call to timeout instead of
+ * FAIL_POINT_SLEEP will result in a call to callout_reset instead of
* msleep. Note that if you sleep while this flag is set, you must
* set fp_post_sleep_fn or an error will occur upon waking.
*/
@@ -163,9 +168,10 @@ fail_point_use_timeout_path(struct fail_point *fp, boo
(post_sleep_fn == NULL && fp->fp_post_sleep_fn != NULL),
("Setting fp to use timeout, but not setting post_sleep_fn\n"));
- if (use_timeout)
+ if (use_timeout) {
+ fail_point_alloc_callout(fp);
fp->fp_flags |= FAIL_POINT_USE_TIMEOUT_PATH;
- else
+ } else
fp->fp_flags &= ~FAIL_POINT_USE_TIMEOUT_PATH;
if (post_sleep_fn != NULL)
More information about the svn-src-all
mailing list