From aa1b1fa34f6ae9be060b209d7cd2f3b4a3e610de Mon Sep 17 00:00:00 2001 From: Zach Brown Date: Wed, 6 Jan 2021 09:20:14 -0800 Subject: [PATCH] Add util.h for kernel helpers Add a little header for inline convenience functions. Signed-off-by: Zach Brown --- kmod/src/util.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 kmod/src/util.h diff --git a/kmod/src/util.h b/kmod/src/util.h new file mode 100644 index 00000000..20d9db79 --- /dev/null +++ b/kmod/src/util.h @@ -0,0 +1,20 @@ +#ifndef _SCOUTFS_UTIL_H_ +#define _SCOUTFS_UTIL_H_ + +/* + * Little utility helpers that probably belong upstream. + */ + +static inline void down_write_two(struct rw_semaphore *a, + struct rw_semaphore *b) +{ + BUG_ON(a == b); + + if (a > b) + swap(a, b); + + down_write(a); + down_write_nested(b, SINGLE_DEPTH_NESTING); +} + +#endif