From 656d3e6e6b3bfc014b0610031f7e3b0a53da6eb8 Mon Sep 17 00:00:00 2001 From: Hauke Mehrtens Date: Thu, 2 Aug 2012 01:05:24 +0200 Subject: [PATCH] compat: add sk_wmem_alloc_get and sk_has_allocations These functions are copied from the kernel. Signed-off-by: Hauke Mehrtens Signed-off-by: Luis R. Rodriguez --- include/linux/compat-2.6.31.h | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/include/linux/compat-2.6.31.h b/include/linux/compat-2.6.31.h index 25db973dff99..347ae26d14be 100644 --- a/include/linux/compat-2.6.31.h +++ b/include/linux/compat-2.6.31.h @@ -11,6 +11,7 @@ #include #include #include +#include /* * These macros allow us to backport rfkill without any @@ -215,6 +216,39 @@ extern long long atomic64_add_return(long long a, atomic64_t *v); #endif +/** + * sk_rmem_alloc_get - returns read allocations + * @sk: socket + * + * Returns sk_rmem_alloc + */ +static inline int sk_rmem_alloc_get(const struct sock *sk) +{ + return atomic_read(&sk->sk_rmem_alloc); +} + +/** + * sk_wmem_alloc_get - returns write allocations + * @sk: socket + * + * Returns sk_wmem_alloc minus initial offset of one + */ +static inline int sk_wmem_alloc_get(const struct sock *sk) +{ + return atomic_read(&sk->sk_wmem_alloc) - 1; +} + +/** + * sk_has_allocations - check if allocations are outstanding + * @sk: socket + * + * Returns true if socket has write or read allocations + */ +static inline bool sk_has_allocations(const struct sock *sk) +{ + return sk_wmem_alloc_get(sk) || sk_rmem_alloc_get(sk); +} + #endif /* (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,31)) */ -- 2.30.2