Skip to contentSkip to conversation

Patches for compat drbd9 to kernel v4.10

PATCH New Nick Wang 1 participant 9 messages Mar 13, 2017 DRBD driver

lore
Share & tools
lore

Nick Wang

author
#0 lore raw

cover Patches for compat drbd9 to kernel v4.10

Changelog of v1 compare to v0:
patch1: Remove the "error FIXME WRITE_SYNC undefined", since
for the new kernels without WRITE_SYNC, can savely ignore it.
patch2 and patch3: Remove the wrapper of bdi_congested in v1,
by removing the '&' directly.
patch4 and patch5: Use a warpper of refcount_* function,
fallback to atomic_ when kernel not support.

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 Lars Ellenberg <[email protected]>
CC Roland Kammerer <[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.

CC Lars Ellenberg <[email protected]>
CC Roland Kammerer <[email protected]>
---
 drbd_wrappers.h               | 15 ++++++++++++---
 tests/have_bio_set_op_attrs.c | 11 +++++++++++
 2 files changed, 23 insertions(+), 3 deletions(-)
 create mode 100644 tests/have_bio_set_op_attrs.c
drbd_wrappers.h +12 -3
index 1d9289f..1e35aec 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??
+#define WRITE_FLUSH       DRBD_REQ_PREFLUSH
 #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

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.

CC Lars Ellenberg <[email protected]>
CC Roland Kammerer <[email protected]>
---
 tests/have_pointer_backing_dev_info.c | 7 +++++++
 1 file changed, 7 insertions(+)
 create mode 100644 tests/have_pointer_backing_dev_info.c
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
author
#3 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 Lars Ellenberg <[email protected]>
CC Roland Kammerer <[email protected]>
---
 drbd/drbd_debugfs.c     |  4 ++++
 drbd/drbd_main.c        |  9 +++++++++
 drbd/drbd_nl.c          | 13 +++++++++++++
 drbd/drbd_req.c         |  4 ++++
 4 files changed, 30 insertions(+)
drbd/drbd_debugfs.c +4 -0
index 96c78fb..0bf2c96 100644
@@ -1431,7 +1431,11 @@ static int peer_device_proc_drbd_show(struct seq_file *m, void *ignored)
 	rcu_read_lock();
 	{
 		/* reset device->congestion_reason */
+#ifdef COMPAT_HAVE_POINTER_BACKING_DEV_INFO
+		bdi_rw_congested(device->rq_queue->backing_dev_info);
+#else
 		bdi_rw_congested(&device->rq_queue->backing_dev_info);
+#endif
 
 		nc = rcu_dereference(peer_device->connection->transport.net_conf);
 		wp = nc ? nc->wire_protocol - DRBD_PROT_A + 'A' : ' ';
drbd/drbd_main.c +9 -0
index b2f839e..40c65ee 100644
@@ -3009,7 +3009,11 @@ static int drbd_congested(void *congested_data, int bdi_bits)
 
 	if (get_ldev(device)) {
 		q = bdev_get_queue(device->ldev->backing_bdev);
+#ifdef COMPAT_HAVE_POINTER_BACKING_DEV_INFO
+		r = bdi_congested(q->backing_dev_info, bdi_bits);
+#else
 		r = bdi_congested(&q->backing_dev_info, bdi_bits);
+#endif
 		put_ldev(device);
 	}
 
@@ -3583,8 +3587,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 +13 -0
index 22044ab..41a59a8 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);
 }
@@ -4601,7 +4610,11 @@ static void device_to_statistics(struct device_statistics *s,
 		s->dev_disk_flags = md->flags;
 		q = bdev_get_queue(device->ldev->backing_bdev);
 		s->dev_lower_blocked =
+#ifdef COMPAT_HAVE_POINTER_BACKING_DEV_INFO
+			bdi_congested(q->backing_dev_info,
+#else
 			bdi_congested(&q->backing_dev_info,
+#endif
 				      (1 << WB_async_congested) |
 				      (1 << WB_sync_congested));
 		put_ldev(device);
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
#4 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.

CC Lars Ellenberg <[email protected]>
CC Roland Kammerer <[email protected]>
---
 drbd_wrappers.h           | 5 +++++
 tests/have_refcount_inc.c | 6 ++++++
 2 files changed, 11 insertions(+)
 create mode 100644 tests/have_refcount_inc.c
drbd_wrappers.h +5 -0
index 1e35aec..cf17d84 100644
@@ -893,6 +893,11 @@ static inline void blk_queue_write_cache(struct request_queue *q, bool enabled,
 #define REQ_NOIDLE 0
 #endif
 
+#ifndef COMPAT_HAVE_REFCOUNT_INC
+#define refcount_inc(R) atomic_inc(R)
+#define refcount_read(R) atomic_read(R)
+#define refcount_dec_and_test(R) atomic_dec_and_test(R)
+#endif
 
 #ifndef COMPAT_HAVE_BIO_SET_OP_ATTRS /*compat for Linux before 4.8 {{{2 */
 
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
#5 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 Lars Ellenberg <[email protected]>
CC Roland Kammerer <[email protected]>
---
 drbd/drbd_bitmap.c | 4 ++++
 drbd/drbd_req.c    | 6 +++---
 drbd/kref_debug.c  | 2 +-
 3 files changed, 8 insertions(+), 4 deletions(-)
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 +3 -3
index d6d9dc1..b433a12 100644
@@ -124,7 +124,7 @@ 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;
-		atomic_inc(&req->kref.refcount); /* was 0, instead of kref_get() */
+		refcount_inc(&req->kref.refcount); /* was 0, instead of kref_get() */
 		req->rq_state[1 + node_id] |= RQ_PEER_ACK;
 		if (!queued) {
 			list_add_tail(&req->tl_requests, &resource->peer_ack_list);
@@ -324,7 +324,7 @@ void drbd_req_destroy(struct kref *kref)
 	 */
 	if (destroy_next) {
 		req = destroy_next;
-		if (atomic_dec_and_test(&req->kref.refcount))
+		if (refcount_dec_and_test(&req->kref.refcount))
 			goto tail_recursion;
 	}
 
@@ -722,7 +722,7 @@ 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;
-		int refcount = atomic_read(&req->kref.refcount);
+		int refcount = refcount_read(&req->kref.refcount);
 		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 +1 -1
index 0aa0e6e..a77cc35 100644
@@ -108,7 +108,7 @@ void print_kref_debug_info(struct seq_file *seq)
 		char obj_name[80];
 
 		debug_refs = number_of_debug_refs(debug_info);
-		refs = atomic_read(&debug_info->kref->refcount);
+		refs = refcount_read(&debug_info->kref->refcount);
 		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
author
#6 lore raw

PATCH 6/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 Lars Ellenberg <[email protected]>
CC Roland Kammerer <[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
#7 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 Lars Ellenberg <[email protected]>
CC Roland Kammerer <[email protected]>
---
 drbd/linux/genl_magic_func-genl_register_family_with_ops_groups.h | 4 ++++
 1 file 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
#8 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.

CC Lars Ellenberg <[email protected]>
CC Roland Kammerer <[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