Patches for compat drbd9 to kernel v4.10
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.
Signature · 1 line
1.8.5.6
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.
--- 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
@@ -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
@@ -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
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
#ifndefWRITE_SYNC
#error FIXMEWRITE_SYNCundefined??
Maybe can define WRITE_SYNC to 0 in this case? #define WRITE_SYNC 0
Quoted 4 lines
#endif
#defineWRITE_FLUSH(WRITE_SYNC|DRBD_REQ_PREFLUSH)
#endif
+#endif
Best regards,
Nick
PATCH 2/8 Adapt pointer backing_dev_info in struct request_queue
In reply to Nick WangIn dc3b17cc, struct request_queue use pointer to backing_dev_info, so all related call should be converted.
This patch is for drbd-kernel-compat
--- 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
@@ -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
@@ -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
Re: [Drbd-dev] [Patch v0 2/8] Adapt pointer backing_dev_info in struct request_queue
Quoted 21 lines · Nick Wang
In
dc3b17cc, structrequest_queueuse pointer tobacking_dev_info, so all related call should be converted.This patch is for drbd-kernel-compat
Signed-off-by Nick Wang <[email protected]>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.cdrbd_wrappers.h +0
-0
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
PATCH 3/8 Adapt pointer backing_dev_info in struct request_queue
In reply to Nick WangIn dc3b17cc, struct request_queue use pointer to backing_dev_info, so all related call should be converted.
--- 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
@@ -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
@@ -1882,12 +1882,21 @@ static void drbd_setup_queue_param(struct drbd_device *device, struct drbd_backiif (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
@@ -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
PATCH 4/8 Use refcount_t 'atomic' type to implement struct kref
In reply to Nick WangIn 10383aea, atomic type for refcount is obsoleted, instead using refcount_t. Also convert the related call.
This patch is for drbd-kernel-compat
--- 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
@@ -0,0 +1,6 @@ +#include <linux/refcount.h> + +void test (refcount_t *r) +{ +refcount_inc (r); +}
Signature · 1 line
1.8.5.6
PATCH 5/8 Use refcount_t 'atomic' type to implement structref
In reply to Nick WangIn 10383aea, atomic type for refcount is obsoleted, instead use refcount_t. Also convert the related call.
--- 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
@@ -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
@@ -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
@@ -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
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@@ -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
PATCH 6/6 Statically initialize families
In reply to Nick WangIn 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
--- 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
@@ -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
@@ -0,0 +1,6 @@ +#include <linux/genetlink.h> + +void test (void ) +{ +int i =GENL_ID_GENERATE ; +}
Signature · 1 line
1.8.5.6
PATCH 7/8 Statically initialize families
In reply to Nick WangIn a07ea4d9, genetlink no longer use static family id. GENL_ID_GENERATE is removed.
In 489111e5, statically initialize the families and remove the inline functions.
--- 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
@@ -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_groupsreturn 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
PATCH 8/8 Statically initialize families
In reply to Nick WangIn 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.
--- linux/genl_magic_func.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
linux/genl_magic_func.h +4 -1
@@ -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
Lars Ellenberg
maintainerQuoted 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.
93c5bdf7and70fd7614,bio_set_op_attrschange to inline
then obsolete by use flag directly.dc3b17cc, use pointer tobacking_dev_infoin structrequest_queue.10383aea, userefcount_tfor struct kref.a07ea4d9and489111e5, statically initialize genetlink family.
Quoted 4 lines
Signed-off-by Nick Wang <[email protected]>CC Philipp Reisner <[email protected]>CC Lars Ellenberg <[email protected]>
Thanks,
We'll find time review them "soon", I hope.
Lars
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
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