2012-08-01 23:05:43

by Hauke Mehrtens

[permalink] [raw]
Subject: [PATCH 1/3] compat: add seq_hlist_next and seq_hlist_start_head

These functions are copied from the kernel and are needed by
net/bluetooth/af_bluetooth.c

Signed-off-by: Hauke Mehrtens <[email protected]>
---
compat/compat-2.6.34.c | 55 +++++++++++++++++++++++++++++++++++++++++
include/linux/compat-2.6.34.h | 6 +++++
2 files changed, 61 insertions(+)

diff --git a/compat/compat-2.6.34.c b/compat/compat-2.6.34.c
index b905a26..80a6107 100644
--- a/compat/compat-2.6.34.c
+++ b/compat/compat-2.6.34.c
@@ -28,3 +28,58 @@ int sdio_set_host_pm_flags(struct sdio_func *func, mmc_pm_flag_t flags)
{
return -EINVAL;
}
+
+/**
+ * seq_hlist_start - start an iteration of a hlist
+ * @head: the head of the hlist
+ * @pos: the start position of the sequence
+ *
+ * Called at seq_file->op->start().
+ */
+struct hlist_node *seq_hlist_start(struct hlist_head *head, loff_t pos)
+{
+ struct hlist_node *node;
+
+ hlist_for_each(node, head)
+ if (pos-- == 0)
+ return node;
+ return NULL;
+}
+
+/**
+ * seq_hlist_start_head - start an iteration of a hlist
+ * @head: the head of the hlist
+ * @pos: the start position of the sequence
+ *
+ * Called at seq_file->op->start(). Call this function if you want to
+ * print a header at the top of the output.
+ */
+struct hlist_node *seq_hlist_start_head(struct hlist_head *head, loff_t pos)
+{
+ if (!pos)
+ return SEQ_START_TOKEN;
+
+ return seq_hlist_start(head, pos - 1);
+}
+EXPORT_SYMBOL(seq_hlist_start_head);
+
+/**
+ * seq_hlist_next - move to the next position of the hlist
+ * @v: the current iterator
+ * @head: the head of the hlist
+ * @ppos: the current position
+ *
+ * Called at seq_file->op->next().
+ */
+struct hlist_node *seq_hlist_next(void *v, struct hlist_head *head,
+ loff_t *ppos)
+{
+ struct hlist_node *node = v;
+
+ ++*ppos;
+ if (v == SEQ_START_TOKEN)
+ return head->first;
+ else
+ return node->next;
+}
+EXPORT_SYMBOL(seq_hlist_next);
diff --git a/include/linux/compat-2.6.34.h b/include/linux/compat-2.6.34.h
index b5a40e2..39bc13b 100644
--- a/include/linux/compat-2.6.34.h
+++ b/include/linux/compat-2.6.34.h
@@ -319,6 +319,12 @@ static inline int lockdep_rtnl_is_held(void)
}
#endif /* #ifdef CONFIG_PROVE_LOCKING */

+extern struct hlist_node *seq_hlist_start_head(struct hlist_head *head,
+ loff_t pos);
+
+extern struct hlist_node *seq_hlist_next(void *v, struct hlist_head *head,
+ loff_t *ppos);
+
#else /* Kernels >= 2.6.34 */

static inline void init_compat_mmc_pm_flags(void)
--
1.7.9.5



2012-08-01 23:05:53

by Hauke Mehrtens

[permalink] [raw]
Subject: [PATCH 3/3] compat: add sk_wmem_alloc_get and sk_has_allocations

These functions are copied from the kernel.

Signed-off-by: Hauke Mehrtens <[email protected]>
---
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 25db973..347ae26 100644
--- a/include/linux/compat-2.6.31.h
+++ b/include/linux/compat-2.6.31.h
@@ -11,6 +11,7 @@
#include <net/dst.h>
#include <net/genetlink.h>
#include <linux/ethtool.h>
+#include <net/sock.h>

/*
* 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)) */

--
1.7.9.5


2012-08-06 17:50:50

by Luis R. Rodriguez

[permalink] [raw]
Subject: Re: [PATCH 3/3] compat: add sk_wmem_alloc_get and sk_has_allocations

On Wed, Aug 1, 2012 at 4:05 PM, Hauke Mehrtens <[email protected]> wrote:
> These functions are copied from the kernel.
>
> Signed-off-by: Hauke Mehrtens <[email protected]>

Thanks, applied all 3 and pushed!

Luis

2012-08-01 23:05:40

by Hauke Mehrtens

[permalink] [raw]
Subject: [PATCH 2/3] compat: add sk_entry

This function is copied from the kernel.

Signed-off-by: Hauke Mehrtens <[email protected]>
---
include/linux/compat-2.6.34.h | 6 ++++++
1 file changed, 6 insertions(+)

diff --git a/include/linux/compat-2.6.34.h b/include/linux/compat-2.6.34.h
index 39bc13b..b8b48c0 100644
--- a/include/linux/compat-2.6.34.h
+++ b/include/linux/compat-2.6.34.h
@@ -8,6 +8,7 @@
#include <linux/netdevice.h>
#include <linux/usb.h>
#include <linux/mmc/sdio_func.h>
+#include <net/sock.h>

/*
* Backports da68c4eb25
@@ -325,6 +326,11 @@ extern struct hlist_node *seq_hlist_start_head(struct hlist_head *head,
extern struct hlist_node *seq_hlist_next(void *v, struct hlist_head *head,
loff_t *ppos);

+static inline struct sock *sk_entry(const struct hlist_node *node)
+{
+ return hlist_entry(node, struct sock, sk_node);
+}
+
#else /* Kernels >= 2.6.34 */

static inline void init_compat_mmc_pm_flags(void)
--
1.7.9.5