diff options
Diffstat (limited to 'include/net/sock.h')
-rw-r--r-- | include/net/sock.h | 41 |
1 files changed, 40 insertions, 1 deletions
diff --git a/include/net/sock.h b/include/net/sock.h index 4bb1ff9fd15b..07133c5e9868 100644 --- a/include/net/sock.h +++ b/include/net/sock.h | |||
@@ -218,9 +218,11 @@ struct sock { | |||
218 | #define sk_hash __sk_common.skc_hash | 218 | #define sk_hash __sk_common.skc_hash |
219 | #define sk_prot __sk_common.skc_prot | 219 | #define sk_prot __sk_common.skc_prot |
220 | #define sk_net __sk_common.skc_net | 220 | #define sk_net __sk_common.skc_net |
221 | kmemcheck_bitfield_begin(flags); | ||
221 | unsigned char sk_shutdown : 2, | 222 | unsigned char sk_shutdown : 2, |
222 | sk_no_check : 2, | 223 | sk_no_check : 2, |
223 | sk_userlocks : 4; | 224 | sk_userlocks : 4; |
225 | kmemcheck_bitfield_end(flags); | ||
224 | unsigned char sk_protocol; | 226 | unsigned char sk_protocol; |
225 | unsigned short sk_type; | 227 | unsigned short sk_type; |
226 | int sk_rcvbuf; | 228 | int sk_rcvbuf; |
@@ -1206,6 +1208,39 @@ static inline int skb_copy_to_page(struct sock *sk, char __user *from, | |||
1206 | return 0; | 1208 | return 0; |
1207 | } | 1209 | } |
1208 | 1210 | ||
1211 | /** | ||
1212 | * sk_wmem_alloc_get - returns write allocations | ||
1213 | * @sk: socket | ||
1214 | * | ||
1215 | * Returns sk_wmem_alloc minus initial offset of one | ||
1216 | */ | ||
1217 | static inline int sk_wmem_alloc_get(const struct sock *sk) | ||
1218 | { | ||
1219 | return atomic_read(&sk->sk_wmem_alloc) - 1; | ||
1220 | } | ||
1221 | |||
1222 | /** | ||
1223 | * sk_rmem_alloc_get - returns read allocations | ||
1224 | * @sk: socket | ||
1225 | * | ||
1226 | * Returns sk_rmem_alloc | ||
1227 | */ | ||
1228 | static inline int sk_rmem_alloc_get(const struct sock *sk) | ||
1229 | { | ||
1230 | return atomic_read(&sk->sk_rmem_alloc); | ||
1231 | } | ||
1232 | |||
1233 | /** | ||
1234 | * sk_has_allocations - check if allocations are outstanding | ||
1235 | * @sk: socket | ||
1236 | * | ||
1237 | * Returns true if socket has write or read allocations | ||
1238 | */ | ||
1239 | static inline int sk_has_allocations(const struct sock *sk) | ||
1240 | { | ||
1241 | return sk_wmem_alloc_get(sk) || sk_rmem_alloc_get(sk); | ||
1242 | } | ||
1243 | |||
1209 | /* | 1244 | /* |
1210 | * Queue a received datagram if it will fit. Stream and sequenced | 1245 | * Queue a received datagram if it will fit. Stream and sequenced |
1211 | * protocols can't normally use this as they need to fit buffers in | 1246 | * protocols can't normally use this as they need to fit buffers in |
@@ -1217,9 +1252,13 @@ static inline int skb_copy_to_page(struct sock *sk, char __user *from, | |||
1217 | 1252 | ||
1218 | static inline void skb_set_owner_w(struct sk_buff *skb, struct sock *sk) | 1253 | static inline void skb_set_owner_w(struct sk_buff *skb, struct sock *sk) |
1219 | { | 1254 | { |
1220 | sock_hold(sk); | ||
1221 | skb->sk = sk; | 1255 | skb->sk = sk; |
1222 | skb->destructor = sock_wfree; | 1256 | skb->destructor = sock_wfree; |
1257 | /* | ||
1258 | * We used to take a refcount on sk, but following operation | ||
1259 | * is enough to guarantee sk_free() wont free this sock until | ||
1260 | * all in-flight packets are completed | ||
1261 | */ | ||
1223 | atomic_add(skb->truesize, &sk->sk_wmem_alloc); | 1262 | atomic_add(skb->truesize, &sk->sk_wmem_alloc); |
1224 | } | 1263 | } |
1225 | 1264 | ||