Skip to contentSkip to conversation

Patches for compat drbd9 to kernel v4.10

PATCH In review Nick Wang 3 participants 15 messages Mar 7, 2017 – Mar 10, 2017 DRBD driver

lore
Share & tools
lore

Nick Wang

author
#0 lore raw

cover Patches for compat drbd9 to kernel v4.10

Patches for drbd9 compatible to kernel4.10, including drbd, drbd-kernel-compat and drbd-headers repos. Ordered as functionality, so may mix the three repos in one patch set.

block layer API and genetlink API have many changes in kernel v4.10. 93c5bdf7 and 70fd7614, bio_set_op_attrs change to inline
then obsolete by use flag directly.
dc3b17cc, use pointer to backing_dev_info in struct request_queue. 10383aea, use refcount_t for struct kref.
a07ea4d9 and 489111e5, statically initialize genetlink family.

CC Philipp Reisner <[email protected]>
CC Lars Ellenberg <[email protected]>
Signature · 1 line
1.8.5.6
author
#1 lore raw

PATCH 1/8 Remove bio_set_op_attrs

In 93c5bdf7, bio_set_op_attrs changed from define to inline. Then dropped by use flag directly. Also clean the old value for the new op and op_flags.
Use REQ_SYNC instead of WRITE_SYNC.

This patch in drbd-kernel-compat.

CC Philipp Reisner <[email protected]>
CC Lars Ellenberg <[email protected]>
---
 drbd_wrappers.h               | 13 +++++++++++--
 tests/have_bio_set_op_attrs.c | 11 +++++++++++
 2 files changed, 22 insertions(+), 2 deletions(-)
 create mode 100644 tests/have_bio_set_op_attrs.c
drbd_wrappers.h +11 -2
index 1d9289f..0489e7f 100644
@@ -719,7 +719,7 @@ static inline void blk_queue_write_cache(struct request_queue *q, bool enabled,
  * bi_opf (some kernel version) -> data packet flags -> bi_opf (other kernel version)
  */
 
-#if defined(bio_set_op_attrs)
+#ifdef COMPAT_HAVE_BIO_SET_OP_ATTRS
 /* Linux 4.8 split bio OPs and FLAGs {{{2 */
 
 #define DRBD_REQ_PREFLUSH	REQ_PREFLUSH
@@ -872,12 +872,21 @@ static inline void blk_queue_write_cache(struct request_queue *q, bool enabled,
 #define DRBD_REQ_WSAME		0
 #endif
 
+#ifdef COMPAT_HAVE_BIO_SET_OP_ATTRS
+#ifndef WRITE_FLUSH
+#define bio_set_op_attrs(bio, op, op_flags) do {        \
+	(bio)->bi_opf = op | op_flags;              \
+} while (0)
+#define WRITE_FLUSH (REQ_SYNC | DRBD_REQ_PREFLUSH)
+#endif
+#else
 #ifndef WRITE_FLUSH
 #ifndef WRITE_SYNC
 #error  FIXME WRITE_SYNC undefined??
 #endif
 #define WRITE_FLUSH       (WRITE_SYNC | DRBD_REQ_PREFLUSH)
 #endif
+#endif
 
 #ifndef REQ_NOIDLE
 /* introduced in aeb6faf (2.6.30), relevant for CFQ */
@@ -885,7 +894,7 @@ static inline void blk_queue_write_cache(struct request_queue *q, bool enabled,
 #endif
 
 
-#ifndef bio_set_op_attrs /* compat for Linux before 4.8 {{{2 */
+#ifndef COMPAT_HAVE_BIO_SET_OP_ATTRS /*compat for Linux before 4.8 {{{2 */
 
 #define bi_opf bi_rw
 
tests/have_bio_set_op_attrs.c new file +11 -0
new file mode 100644
index 0000000..6aa0781
@@ -0,0 +1,11 @@
+#include <linux/bio.h>
+
+/*
+ * bio_set_op_attrs() change to inline since 93c5bdf7 (4.10-rc1)
+ */
+void test(void)
+{
+	struct bio *bio = NULL;
+
+	bio_set_op_attrs(bio, 0, 0);
+}
Signature · 1 line
1.8.5.6
author
#2 lore raw

Re: [Drbd-dev] [Patch v0 1/8] Remove bio_set_op_attrs

Quoted 1 line
Quoted 1 line
Quoted 1 line

On 2017-3-7 at 11:27, in message

<[email protected]>, Nick Wang <[email protected]>

Quoted 3 lines · wrote:

#ifndef WRITE_FLUSH
#ifndef WRITE_SYNC
#error FIXME WRITE_SYNC undefined??

Maybe can define WRITE_SYNC to 0 in this case? #define WRITE_SYNC 0

Quoted 4 lines

#endif
#define WRITE_FLUSH (WRITE_SYNC | DRBD_REQ_PREFLUSH)
#endif
+#endif

Best regards,
Nick

author
#3 lore raw

PATCH 2/8 Adapt pointer backing_dev_info in struct request_queue

In reply to Nick Wang

In dc3b17cc, struct request_queue use pointer to backing_dev_info, so all related call should be converted.

This patch is for drbd-kernel-compat

CC Philipp Reisner <[email protected]>
CC Lars Ellenberg <[email protected]>
---
 drbd_wrappers.h                       | 5 +++++
 tests/have_pointer_backing_dev_info.c | 7 +++++++
 2 files changed, 12 insertions(+)
 create mode 100644 tests/have_pointer_backing_dev_info.c
drbd_wrappers.h +5 -0
index 0489e7f..778a6fd 100644
@@ -888,6 +888,11 @@ static inline void blk_queue_write_cache(struct request_queue *q, bool enabled,
 #endif
 #endif
 
+#ifdef COMPAT_HAVE_POINTER_BACKING_DEV_INFO
+#define bdi_rw_congested(B) bdi_rw_congested(*(B))
+#define bdi_congested(B, C) bdi_congested(*(B), C)
+#endif
+
 #ifndef REQ_NOIDLE
 /* introduced in aeb6faf (2.6.30), relevant for CFQ */
 #define REQ_NOIDLE 0
tests/have_pointer_backing_dev_info.c new file +7 -0
new file mode 100644
index 0000000..e9999ce
@@ -0,0 +1,7 @@
+#include <linux/blkdev.h>
+
+void test(void)
+{
+	struct request_queue q = {};
+	q.backing_dev_info = NULL;
+}
Signature · 1 line
1.8.5.6
#4 lore raw

Re: [Drbd-dev] [Patch v0 2/8] Adapt pointer backing_dev_info in struct request_queue

Quoted 21 lines · Nick Wang

In dc3b17cc, struct request_queue use pointer to backing_dev_info, so all related call should be converted.

This patch is for drbd-kernel-compat

CC Philipp Reisner <[email protected]>
CC Lars Ellenberg <[email protected]>
---
 drbd_wrappers.h                       | 5 +++++
 tests/have_pointer_backing_dev_info.c | 7 +++++++
 2 files changed, 12 insertions(+)
 create mode 100644 tests/have_pointer_backing_dev_info.c
drbd_wrappers.h +0 -0
index 0489e7f..778a6fd 100644

drbd_wrappers.h static inline void blk_queue_write_cache(struct request_queue *q, bool enabled, · line 895

Quoted 8 lines
drbd_wrappers.h +5 -0
@@ -888,6 +888,11 @@ static inline void blk_queue_write_cache(struct request_queue *q, bool enabled,
 #endif
 #endif
 
+#ifdef COMPAT_HAVE_POINTER_BACKING_DEV_INFO
+#define bdi_rw_congested(B) bdi_rw_congested(*(B))
+#define bdi_congested(B, C) bdi_congested(*(B), C)
+#endif
+

We do compat work the other way round. The goal is to have our out-of-tree code as close as possible to linux upstream. Otherwise we would "get stuck" at the old paradigms.

In that specific case it actually means to change drbd_debugfs.c in a way that it looks like linux upstream (basically removing the '&') and provide compat #defines for older kernels.

Regards, rck

author
#5 lore raw

PATCH 3/8 Adapt pointer backing_dev_info in struct request_queue

In reply to Nick Wang

In dc3b17cc, struct request_queue use pointer to backing_dev_info, so all related call should be converted.

CC Philipp Reisner <[email protected]>
CC Lars Ellenberg <[email protected]>
---
 drbd/drbd_main.c        | 5 +++++
 drbd/drbd_nl.c          | 9 ++++++++
 drbd/drbd_req.c         | 4 ++++
 3 files changed, 18 insertions(+)
drbd/drbd_main.c +5 -0
index b2f839e..324239b 100644
@@ -3583,8 +3583,13 @@ enum drbd_ret_code drbd_create_device(struct drbd_config_context *adm_ctx, unsig
 	/* we have no partitions. we contain only ourselves. */
 	device->this_bdev->bd_contains = device->this_bdev;
 
+#ifdef COMPAT_HAVE_POINTER_BACKING_DEV_INFO
+	q->backing_dev_info->congested_fn = drbd_congested;
+	q->backing_dev_info->congested_data = device;
+#else
 	q->backing_dev_info.congested_fn = drbd_congested;
 	q->backing_dev_info.congested_data = device;
+#endif
 
 	blk_queue_make_request(q, drbd_make_request);
 	blk_queue_write_cache(q, true, true);
drbd/drbd_nl.c +9 -0
index 22044ab..ace77c5 100644
@@ -1882,12 +1882,21 @@ static void drbd_setup_queue_param(struct drbd_device *device, struct drbd_backi
 	if (b) {
 		blk_queue_stack_limits(q, b);
 
+#ifdef COMPAT_HAVE_POINTER_BACKING_DEV_INFO
+		if (q->backing_dev_info->ra_pages != b->backing_dev_info->ra_pages) {
+			drbd_info(device, "Adjusting my ra_pages to backing device's (%lu -> %lu)\n",
+				 q->backing_dev_info->ra_pages,
+				 b->backing_dev_info->ra_pages);
+			q->backing_dev_info->ra_pages = b->backing_dev_info->ra_pages;
+		}
+#else
 		if (q->backing_dev_info.ra_pages != b->backing_dev_info.ra_pages) {
 			drbd_info(device, "Adjusting my ra_pages to backing device's (%lu -> %lu)\n",
 				 q->backing_dev_info.ra_pages,
 				 b->backing_dev_info.ra_pages);
 			q->backing_dev_info.ra_pages = b->backing_dev_info.ra_pages;
 		}
+#endif
 	}
 	fixup_discard_if_not_supported(q);
 }
drbd/drbd_req.c +4 -0
index e1e9595..d6d9dc1 100644
@@ -1155,7 +1155,11 @@ static bool remote_due_to_read_balancing(struct drbd_device *device,
 
 	switch (rbm) {
 	case RB_CONGESTED_REMOTE:
+#ifdef COMPAT_HAVE_POINTER_BACKING_DEV_INFO
+		bdi = device->ldev->backing_bdev->bd_disk->queue->backing_dev_info;
+#else
 		bdi = &device->ldev->backing_bdev->bd_disk->queue->backing_dev_info;
+#endif
 		return bdi_read_congested(bdi);
 	case RB_LEAST_PENDING:
 		return atomic_read(&device->local_cnt) >
Signature · 1 line
1.8.5.6
author
#6 lore raw

PATCH 4/8 Use refcount_t 'atomic' type to implement struct kref

In reply to Nick Wang

In 10383aea, atomic type for refcount is obsoleted, instead using refcount_t. Also convert the related call.

This patch is for drbd-kernel-compat

CC Philipp Reisner <[email protected]>
CC Lars Ellenberg <[email protected]>
---
 tests/have_refcount_inc.c | 6 ++++++
 1 file changed, 6 insertions(+)
 create mode 100644 tests/have_refcount_inc.c
tests/have_refcount_inc.c new file +6 -0
new file mode 100644
index 0000000..38373e7
@@ -0,0 +1,6 @@
+#include <linux/refcount.h>
+
+void test(refcount_t *r)
+{
+	refcount_inc(r);
+}
Signature · 1 line
1.8.5.6
author
#7 lore raw

PATCH 5/8 Use refcount_t 'atomic' type to implement structref

In reply to Nick Wang

In 10383aea, atomic type for refcount is obsoleted, instead use refcount_t. Also convert the related call.

CC Philipp Reisner <[email protected]>
CC Lars Ellenberg <[email protected]>
---
 drbd/drbd_bitmap.c      |  4 ++++
 drbd/drbd_req.c         | 12 ++++++++++++
 drbd/kref_debug.c       |  4 ++++
 3 files changed, 20 insertions(+)
drbd/drbd_bitmap.c +4 -0
index 51cfdc8..726cfae 100644
@@ -1182,7 +1182,11 @@ static int bm_rw_range(struct drbd_device *device,
 		.done = 0,
 		.flags = flags,
 		.error = 0,
+#ifdef KREF_INIT
+		.kref = KREF_INIT(2),
+#else
 		.kref = { ATOMIC_INIT(2) },
+#endif
 	};
 
 	if (!expect(device, get_ldev_if_state(device, D_ATTACHING))) {  /* put is in drbd_bm_aio_ctx_destroy() */
drbd/drbd_req.c +12 -0
index d6d9dc1..467549a 100644
@@ -124,7 +124,11 @@ void drbd_queue_peer_ack(struct drbd_resource *resource, struct drbd_request *re
 		    connection->cstate[NOW] != C_CONNECTED ||
 		    !(req->rq_state[1 + node_id] & RQ_NET_SENT))
 			continue;
+#ifdef COMPAT_HAVE_REFCOUNT_INC
+		refcount_inc(&req->kref.refcount); /* was 0, instead of kref_get() */
+#else
 		atomic_inc(&req->kref.refcount); /* was 0, instead of kref_get() */
+#endif
 		req->rq_state[1 + node_id] |= RQ_PEER_ACK;
 		if (!queued) {
 			list_add_tail(&req->tl_requests, &resource->peer_ack_list);
@@ -324,7 +328,11 @@ void drbd_req_destroy(struct kref *kref)
 	 */
 	if (destroy_next) {
 		req = destroy_next;
+#ifdef COMPAT_HAVE_REFCOUNT_INC
+		if (refcount_dec_and_test(&req->kref.refcount))
+#else
 		if (atomic_dec_and_test(&req->kref.refcount))
+#endif
 			goto tail_recursion;
 	}
 
@@ -722,7 +730,11 @@ static void mod_rq_state(struct drbd_request *req, struct bio_and_error *m,
 		/* Completion does it's own kref_put.  If we are going to
 		 * kref_sub below, we need req to be still around then. */
 		int at_least = k_put + !!c_put;
+#ifdef COMPAT_HAVE_REFCOUNT_INC
+		int refcount = refcount_read(&req->kref.refcount);
+#else
 		int refcount = atomic_read(&req->kref.refcount);
+#endif
 		if (refcount < at_least)
 			drbd_err(req->device,
 				"mod_rq_state: Logic BUG: 0: %x -> %x, %d: %x -> %x: refcount = %d, should be >= %d\n",
drbd/kref_debug.c +4 -0
index 0aa0e6e..4c50f53 100644
@@ -108,7 +108,11 @@ void print_kref_debug_info(struct seq_file *seq)
 		char obj_name[80];
 
 		debug_refs = number_of_debug_refs(debug_info);
+#ifdef COMPAT_HAVE_REFCOUNT_INC
+		refs = refcount_read(&debug_info->kref->refcount);
+#else
 		refs = atomic_read(&debug_info->kref->refcount);
+#endif
 		debug_info->class->get_object_name(debug_info, obj_name);
 
 		seq_printf(seq, "class: %s, name: %s, refs: %d, dr: %d\n",
Signature · 1 line
1.8.5.6
#8 lore raw

Re: [Drbd-dev] [Patch v0 5/8] Use refcount_t 'atomic' type to implement structref

drbd/drbd_req.c void drbd_queue_peer_ack(struct drbd_resource *resource, struct drbd_request *re · line 131

Quoted 13 lines · Nick Wang
drbd/drbd_req.c +4 -0
index d6d9dc1..467549a 100644
@@ -124,7 +124,11 @@ void drbd_queue_peer_ack(struct drbd_resource *resource, struct drbd_request *re
 		    connection->cstate[NOW] != C_CONNECTED ||
 		    !(req->rq_state[1 + node_id] & RQ_NET_SENT))
 			continue;
+#ifdef COMPAT_HAVE_REFCOUNT_INC
+		refcount_inc(&req->kref.refcount); /* was 0, instead of kref_get() */
+#else
 		atomic_inc(&req->kref.refcount); /* was 0, instead of kref_get() */
+#endif

We want to avoid #ifdef hell as much as possible in the code itself. In that case use the new refcount_inc() and if it does not exist, fall back to atomic_inc() via defining refcount_inc() to atomic_inc.

Regards, rck

author
#9 lore raw

PATCH 6/6 Statically initialize families

In reply to Nick Wang

In a07ea4d9, genetlink no longer use static family id. GENL_ID_GENERATE is removed.
In 489111e5, statically initialize the families and remove the inline functions.

This is for drbd-kernel-compat

CC Philipp Reisner <[email protected]>
CC Lars Ellenberg <[email protected]>
---
 tests/have_genl_family_in_genlmsg_multicast.c | 9 +++++++++
 tests/have_genl_id_generate.c                 | 6 ++++++
 2 files changed, 15 insertions(+)
 create mode 100644 tests/have_genl_family_in_genlmsg_multicast.c
 create mode 100644 tests/have_genl_id_generate.c
tests/have_genl_family_in_genlmsg_multicast.c new file +9 -0
new file mode 100644
index 0000000..6d44faa
@@ -0,0 +1,9 @@
+#include <net/genetlink.h>
+
+void test(void)
+{
+	struct genl_family family = { };
+	struct sk_buff *skb = NULL;
+
+	genlmsg_multicast(&family, skb, 0, 0, GFP_KERNEL);
+}
tests/have_genl_id_generate.c new file +6 -0
new file mode 100644
index 0000000..4ef0e8e
@@ -0,0 +1,6 @@
+#include <linux/genetlink.h>
+
+void test(void)
+{
+	int i = GENL_ID_GENERATE;
+}
Signature · 1 line
1.8.5.6
author
#10 lore raw

PATCH 7/8 Statically initialize families

In reply to Nick Wang

In a07ea4d9, genetlink no longer use static family id. GENL_ID_GENERATE is removed.
In 489111e5, statically initialize the families and remove the inline functions.

CC Philipp Reisner <[email protected]>
CC Lars Ellenberg <[email protected]>
---
 drbd/linux/genl_magic_func-genl_register_family_with_ops_groups.h | 4 ++++
 1 files changed, 4 insertions(+)
drbd/linux/genl_magic_func-genl_register_family_with_ops_groups.h +4 -0
index 27d8f73..cbd776e 100644
@@ -29,9 +29,13 @@ static int CONCAT_(GENL_MAGIC_FAMILY, _genl_multicast_ ## group)(	\
 
 int CONCAT_(GENL_MAGIC_FAMILY, _genl_register)(void)
 {
+#ifdef genl_register_family_with_ops_groups
 	return genl_register_family_with_ops_groups(&ZZZ_genl_family,	\
 						    ZZZ_genl_ops,	\
 						    ZZZ_genl_mcgrps);
+#else
+	return genl_register_family(&ZZZ_genl_family);
+#endif
 }
 
 void CONCAT_(GENL_MAGIC_FAMILY, _genl_unregister)(void)
Signature · 1 line
1.8.5.6
author
#11 lore raw

PATCH 8/8 Statically initialize families

In reply to Nick Wang

In a07ea4d9, genetlink no longer use static family id. GENL_ID_GENERATE is removed.
In 489111e5, statically initialize the families and remove the inline functions.

This patch is for drbd-headers.

CC Philipp Reisner <[email protected]>
CC Lars Ellenberg <[email protected]>
---
 linux/genl_magic_func.h | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
linux/genl_magic_func.h +4 -1
index d14a557..ae9b9de 100644
@@ -251,7 +251,9 @@ static struct genl_ops ZZZ_genl_ops[] __read_mostly = {
  */
 #define ZZZ_genl_family		CONCAT_(GENL_MAGIC_FAMILY, _genl_family)
 static struct genl_family ZZZ_genl_family __read_mostly = {
+#ifdef HAVE_GENL_ID_GENERATE
 	.id = GENL_ID_GENERATE,
+#endif
 	.name = __stringify(GENL_MAGIC_FAMILY),
 	.version = GENL_MAGIC_VERSION,
 #ifdef GENL_MAGIC_FAMILY_HDRSZ
@@ -275,7 +277,8 @@ static struct genl_family ZZZ_genl_family __read_mostly = {
  * genetlink: only pass array to genl_register_family_with_ops()
  * which are commits c53ed742..2a94fe48
  */
-#ifdef genl_register_family_with_ops_groups
+#if defined(genl_register_family_with_ops_groups) || \
+    defined(COMPAT_HAVE_GENL_FAMILY_IN_GENLMSG_MULTICAST)
 #include <linux/genl_magic_func-genl_register_family_with_ops_groups.h>
 #else
 #include <linux/genl_magic_func-genl_register_mc_group.h>
Signature · 1 line
1.8.5.6
maintainer
#12 lore raw
In reply to Nick Wang
Quoted 11 lines · Nick Wang

Patches for drbd9 compatible to kernel4.10, including drbd, drbd-kernel-compat and drbd-headers repos. Ordered as functionality, so may mix the three repos in one patch set.

block layer API and genetlink API have many changes in kernel v4.10. 93c5bdf7 and 70fd7614, bio_set_op_attrs change to inline
then obsolete by use flag directly.
dc3b17cc, use pointer to backing_dev_info in struct request_queue. 10383aea, use refcount_t for struct kref.
a07ea4d9 and 489111e5, statically initialize genetlink family.

Quoted 4 lines
CC Philipp Reisner <[email protected]>
CC Lars Ellenberg <[email protected]>

Thanks,
We'll find time review them "soon", I hope.

Lars

#13 lore raw
In reply to Nick Wang
Quoted 3 lines · Nick Wang

Patches for drbd9 compatible to kernel4.10, including drbd, drbd-kernel-compat and drbd-headers repos. Ordered as functionality, so may mix the three repos in one patch set.

Hi Nick,

thanks again for the time spent, it's highly appreciated.

There are some things that need to change before I can apply the series. I will answer to some patch mails (2 and 5) that exemplify how we do compat work.

It would then be great if you resend your series. If not, just let me know, then I will do the compat work.

Regards, rck

author
#14 lore raw
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

On 2017-3-9 at 18:22, in message <[email protected]>, Roland

Quoted 4 lines · Kammerer

There are some things that need to change before I can apply the series. I will answer to some patch mails (2 and 5) that exemplify how we do compat work.

Thanks for your opinion, that is much better and valuable. I do struggling
to find a better idea to compat old version and avoid too many #ifdef branches in code.

Quoted 2 lines

It would then be great if you resend your series. If not, just let me know, then I will do the compat work.

I will polish them based on your idea and resend later.

Best regards,
Nick