Accepting request 1233480 from network:ha-clustering:Factory

OBS-URL: https://build.opensuse.org/request/show/1233480
OBS-URL: https://build.opensuse.org/package/show/openSUSE:Factory/drbd?expand=0&rev=114
This commit is contained in:
Ana Guerrero 2024-12-29 10:56:44 +00:00 committed by Git OBS Bridge
commit 06370a1980
39 changed files with 153 additions and 2343 deletions

View File

@ -0,0 +1,81 @@
From d64ebe7eb7df8c622b20bca38f3d7f4c7bb033c9 Mon Sep 17 00:00:00 2001
From: "zhengbing.huang" <zhengbing.huang@easystack.cn>
Date: Sun, 15 Dec 2024 14:50:56 +0800
Subject: [PATCH] drbd: Fix memory leak
In the output of kmemleak, we have the followe backtrace:
unreferenced object 0xffff8885b57cda80 (size 64):
comm "drbd_r_testimg4", pid 37104, jiffies 4494192827 (age 127162.843s)
hex dump (first 32 bytes):
31 20 6f 66 20 32 20 6e 6f 64 65 73 20 76 69 73 1 of 2 nodes vis
69 62 6c 65 2c 20 6e 65 65 64 20 32 20 66 6f 72 ible, need 2 for
backtrace:
[<000000006d641d68>] __kmalloc_track_caller+0x15c/0x270
[<000000006a7ffbcf>] kvasprintf+0xa7/0x120
[<000000002d2f15b3>] drbd_state_err+0xa9/0x190 [drbd]
[<000000006aa2f3df>] __is_valid_soft_transition+0xe99/0xec0 [drbd]
[<0000000009d68cc7>] try_state_change+0x4f0/0x840 [drbd]
[<00000000d5640f06>] ___end_state_change+0x140/0x12a0 [drbd]
[<000000009f4b8d71>] __end_state_change+0xa1/0x130 [drbd]
[<000000001c6de1a7>] change_connection_state+0x5ee/0xbd0 [drbd]
[<00000000ce4408d6>] process_twopc+0x1d3e/0x2ce0 [drbd]
[<00000000df3af6e8>] receive_twopc+0x17b/0x2b0 [drbd]
[<000000009701f919>] drbd_receiver+0x311/0x6e0 [drbd]
[<0000000092c4aeb1>] drbd_thread_setup+0x19d/0x430 [drbd]
[<0000000098e316ab>] kthread+0x19c/0x1c0
[<000000004c72b3a8>] ret_from_fork+0x1f/0x40
This is a memory leak.
In drbd_state_err() function, if resource->state_change_err_str is a null pointer,
the err_str will not be free.
And _drbd_state_err() has same issues.
So, if err_str has not put to up layer, free it in current function.
Signed-off-by: zhengbing.huang <zhengbing.huang@easystack.cn>
Signed-off-by: Joel Colledge <joel.colledge@linbit.com>
---
drbd/drbd_state.c | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/drbd/drbd_state.c b/drbd/drbd_state.c
index f498eaa60396..0e693c8e3af0 100644
--- a/drbd/drbd_state.c
+++ b/drbd/drbd_state.c
@@ -1557,10 +1557,13 @@ static __printf(2, 3) void _drbd_state_err(struct change_context *context, const
va_end(args);
if (!err_str)
return;
- if (context->err_str)
- *context->err_str = err_str;
if (context->flags & CS_VERBOSE)
drbd_err(resource, "%s\n", err_str);
+
+ if (context->err_str)
+ *context->err_str = err_str;
+ else
+ kfree(err_str);
}
static __printf(2, 3) void drbd_state_err(struct drbd_resource *resource, const char *fmt, ...)
@@ -1573,10 +1576,13 @@ static __printf(2, 3) void drbd_state_err(struct drbd_resource *resource, const
va_end(args);
if (!err_str)
return;
- if (resource->state_change_err_str)
- *resource->state_change_err_str = err_str;
if (resource->state_change_flags & CS_VERBOSE)
drbd_err(resource, "%s\n", err_str);
+
+ if (resource->state_change_err_str)
+ *resource->state_change_err_str = err_str;
+ else
+ kfree(err_str);
}
static enum drbd_state_rv __is_valid_soft_transition(struct drbd_resource *resource)
--
2.43.0

View File

@ -1,119 +0,0 @@
From aab03bfc73a62f95011316545a5c0fbb4817741b Mon Sep 17 00:00:00 2001
From: Lars Ellenberg <lars.ellenberg@linbit.com>
Date: Wed, 14 Aug 2024 11:49:42 +0200
Subject: [PATCH 01/32] drbd: properly rate-limit resync progress reports
A peer_device in "paused" sync would have flooded the "drbd events2"
generic netlink broadcast with "resync progress reports",
if it cleared significant out-of-sync bits,
as is the case with application writes,
or several peers syncing from the same sync source
and having a "paused sync" replication state between themselves.
If you have "many" such resources, this storm may even overflow receive buffers.
At most one progress report every three seconds should be enough,
and is what was intended.
Use a new "last progress report time stamp" to throttle
advancing resync progress marks and progress report broadcasts.
---
drbd/drbd_actlog.c | 35 +++++++++++++++++++++++------------
drbd/drbd_int.h | 1 +
drbd/drbd_receiver.c | 1 +
drbd/drbd_state.c | 2 ++
4 files changed, 27 insertions(+), 12 deletions(-)
diff --git a/drbd/drbd_actlog.c b/drbd/drbd_actlog.c
index b96560843878..646dcb29e1d9 100644
--- a/drbd/drbd_actlog.c
+++ b/drbd/drbd_actlog.c
@@ -1020,19 +1020,30 @@ static bool update_rs_extent(struct drbd_peer_device *peer_device,
void drbd_advance_rs_marks(struct drbd_peer_device *peer_device, unsigned long still_to_go)
{
- unsigned long now = jiffies;
- unsigned long last = peer_device->rs_mark_time[peer_device->rs_last_mark];
- int next = (peer_device->rs_last_mark + 1) % DRBD_SYNC_MARKS;
- if (time_after_eq(now, last + DRBD_SYNC_MARK_STEP)) {
- if (peer_device->rs_mark_left[peer_device->rs_last_mark] != still_to_go &&
- peer_device->repl_state[NOW] != L_PAUSED_SYNC_T &&
- peer_device->repl_state[NOW] != L_PAUSED_SYNC_S) {
- peer_device->rs_mark_time[next] = now;
- peer_device->rs_mark_left[next] = still_to_go;
- peer_device->rs_last_mark = next;
- }
- drbd_peer_device_post_work(peer_device, RS_PROGRESS);
+ unsigned long now;
+ int next;
+
+ /* report progress and advance marks only if we made progress */
+ if (peer_device->rs_mark_left[peer_device->rs_last_mark] == still_to_go)
+ return;
+
+ /* report progress and advance marks at most once every DRBD_SYNC_MARK_STEP (3 seconds) */
+ now = jiffies;
+ if (!time_after_eq(now, peer_device->rs_last_progress_report_ts + DRBD_SYNC_MARK_STEP))
+ return;
+
+ /* Do not advance marks if we are "paused" */
+ if (peer_device->repl_state[NOW] != L_PAUSED_SYNC_T &&
+ peer_device->repl_state[NOW] != L_PAUSED_SYNC_S) {
+ next = (peer_device->rs_last_mark + 1) % DRBD_SYNC_MARKS;
+ peer_device->rs_mark_time[next] = now;
+ peer_device->rs_mark_left[next] = still_to_go;
+ peer_device->rs_last_mark = next;
}
+
+ /* But still report progress even if paused. */
+ peer_device->rs_last_progress_report_ts = now;
+ drbd_peer_device_post_work(peer_device, RS_PROGRESS);
}
/* It is called lazy update, so don't do write-out too often. */
diff --git a/drbd/drbd_int.h b/drbd/drbd_int.h
index 49bd7b0c407c..c18407899f59 100644
--- a/drbd/drbd_int.h
+++ b/drbd/drbd_int.h
@@ -1285,6 +1285,7 @@ struct drbd_peer_device {
unsigned long rs_paused;
/* skipped because csum was equal [unit BM_BLOCK_SIZE] */
unsigned long rs_same_csum;
+ unsigned long rs_last_progress_report_ts;
#define DRBD_SYNC_MARKS 8
#define DRBD_SYNC_MARK_STEP (3*HZ)
/* block not up-to-date at mark [unit BM_BLOCK_SIZE] */
diff --git a/drbd/drbd_receiver.c b/drbd/drbd_receiver.c
index 19634f6423bd..ee54cf3ac116 100644
--- a/drbd/drbd_receiver.c
+++ b/drbd/drbd_receiver.c
@@ -3409,6 +3409,7 @@ static int receive_DataRequest(struct drbd_connection *connection, struct packet
peer_device->ov_skipped = 0;
peer_device->rs_total = ov_left;
peer_device->rs_last_writeout = now;
+ peer_device->rs_last_progress_report_ts = now;
for (i = 0; i < DRBD_SYNC_MARKS; i++) {
peer_device->rs_mark_left[i] = ov_left;
peer_device->rs_mark_time[i] = now;
diff --git a/drbd/drbd_state.c b/drbd/drbd_state.c
index be1de8f0653b..44f55ee5c939 100644
--- a/drbd/drbd_state.c
+++ b/drbd/drbd_state.c
@@ -2483,6 +2483,7 @@ static void initialize_resync_progress_marks(struct drbd_peer_device *peer_devic
unsigned long now = jiffies;
int i;
+ peer_device->rs_last_progress_report_ts = now;
for (i = 0; i < DRBD_SYNC_MARKS; i++) {
peer_device->rs_mark_left[i] = tw;
peer_device->rs_mark_time[i] = now;
@@ -2730,6 +2731,7 @@ static void finish_state_change(struct drbd_resource *resource, const char *tag)
peer_device->ov_last_skipped_size = 0;
peer_device->ov_last_skipped_start = 0;
peer_device->rs_last_writeout = now;
+ peer_device->rs_last_progress_report_ts = now;
for (i = 0; i < DRBD_SYNC_MARKS; i++) {
peer_device->rs_mark_left[i] = peer_device->rs_total;
peer_device->rs_mark_time[i] = now;
--
2.35.3

View File

@ -1,60 +0,0 @@
From f6613104a37c1d43cb50fd619afccba370db47a0 Mon Sep 17 00:00:00 2001
From: Joel Colledge <joel.colledge@linbit.com>
Date: Tue, 20 Aug 2024 12:28:09 +0100
Subject: [PATCH 02/32] drbd: inherit history UUIDs from sync source when
resync finishes
This prevents unexpected "unrelated data" or "split-brain" situations
from occurring later. For example with nodes A, B and C:
* A diskless, B, C with disk, all connected, on UUID X
* Down B
* Write on C, new UUID Y generated
* Add disk on A, resyncs from C
* Down C
* Up B, connects to A, should resync from A
Without this change, "unrelated data" or "split-brain" occurs between A
and B.
Node A has current UUID Y, but knows nothing about X.
Node B has current UUID X, but knows nothing about Y.
This scenario is also possible with "quorum majority".
Fix this by adding the history and bitmap UUIDs from the sync source
into the history on the sync target when a resync finishes. In the above
scenario, this adds the UUID X into the history on A and so has the
effect that a full sync from A to B occurs in the final step.
---
drbd/drbd_main.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/drbd/drbd_main.c b/drbd/drbd_main.c
index 7968be7c4c3f..862438885f35 100644
--- a/drbd/drbd_main.c
+++ b/drbd/drbd_main.c
@@ -5030,11 +5030,22 @@ u64 drbd_uuid_resync_finished(struct drbd_peer_device *peer_device) __must_hold(
{
struct drbd_device *device = peer_device->device;
unsigned long flags;
+ int i;
u64 ss_nz_bm; /* sync_source has non zero bitmap for. expressed as nodemask */
u64 pwcu; /* peers with current uuid */
u64 newer;
spin_lock_irqsave(&device->ldev->md.uuid_lock, flags);
+ // Inherit history from the sync source
+ for (i = 0; i < ARRAY_SIZE(peer_device->history_uuids); i++)
+ _drbd_uuid_push_history(device, peer_device->history_uuids[i] & ~UUID_PRIMARY);
+
+ // Inherit history in bitmap UUIDs from the sync source
+ for (i = 0; i < DRBD_PEERS_MAX; i++)
+ if (peer_device->bitmap_uuids[i] != -1)
+ _drbd_uuid_push_history(device,
+ peer_device->bitmap_uuids[i] & ~UUID_PRIMARY);
+
ss_nz_bm = __test_bitmap_slots_of_peer(peer_device);
pwcu = peers_with_current_uuid(device, peer_device->current_uuid);
--
2.35.3

View File

@ -1,36 +0,0 @@
From d6f2b71109f6a589fbc3d5c571c840a6bd142943 Mon Sep 17 00:00:00 2001
From: Lars Ellenberg <lars.ellenberg@linbit.com>
Date: Thu, 22 Aug 2024 16:05:25 +0200
Subject: [PATCH 03/32] build,compat: fix line offset in annotation pragmas
pointing to patched sources
I forgot to update the "new position" by the two output pragma lines
for each non-context to context line transition per chunk.
Offsets would accumultate within the chunk, but reset with the next chunk.
Pragmas pointing into the "patched" file would be off by two lines
(per such transition within a chunk), pointing to some line 2 (4,6,8) lines
above the actual offending line.
Noticed during recent compat work when the backward compat cocci rules
where still incomplete.
---
.../annotate-diff-with-original-file-position-pragmas.pl | 1 +
1 file changed, 1 insertion(+)
diff --git a/drbd/drbd-kernel-compat/annotate-diff-with-original-file-position-pragmas.pl b/drbd/drbd-kernel-compat/annotate-diff-with-original-file-position-pragmas.pl
index c28265e6dd9d..de95689a6ef0 100644
--- a/drbd/drbd-kernel-compat/annotate-diff-with-original-file-position-pragmas.pl
+++ b/drbd/drbd-kernel-compat/annotate-diff-with-original-file-position-pragmas.pl
@@ -91,6 +91,7 @@ m{^--- (?:\./)?(\S+)$} and do {
$chunk .= qq{+# $. "$patch_name"\n};
$chunk .= qq{+# $o_pos "$ABS_NAME"\n};
$n_count += 2;
+ $n_pos += 2;
$extra_ncount += 2;
$file_line_context_points_to_orig = 1;
$state = ' ';
--
2.35.3

View File

@ -1,57 +0,0 @@
From 2f464b8e8235efe2c5d972cf8054dcc2010b100e Mon Sep 17 00:00:00 2001
From: Philipp Reisner <philipp.reisner@linbit.com>
Date: Wed, 14 Aug 2024 17:42:44 +0200
Subject: [PATCH 04/32] drbd: fix exposed_uuid going backward
When a diskless node in the primary role creates a new current UUID,
it sends it all its UpToDate peers and sets it as its own exposed
UUID. If there is only one UpToDate node in the secondary role and it
sends its current UUID to the diskless primary at about the same time,
then with the following state change, through the function
ensure_expose_data_uuid(), the diskless primary sets its exposed_uuid
back to the previous one.
Avoid this problem by not accepting a current_uuid update from a peer
when I am primary (authoritative), and I have told the peer the latest
update, and that peer is already on that latest (authoritative) value.
---
drbd/drbd_main.c | 1 +
drbd/drbd_receiver.c | 10 +++++++++-
2 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/drbd/drbd_main.c b/drbd/drbd_main.c
index 862438885f35..bc3283b045c9 100644
--- a/drbd/drbd_main.c
+++ b/drbd/drbd_main.c
@@ -1484,6 +1484,7 @@ int drbd_send_current_uuid(struct drbd_peer_device *peer_device, u64 current_uui
if (!p)
return -EIO;
+ peer_device->comm_current_uuid = current_uuid;
p->uuid = cpu_to_be64(current_uuid);
p->weak_nodes = cpu_to_be64(weak_nodes);
return drbd_send_command(peer_device, P_CURRENT_UUID, DATA_STREAM);
diff --git a/drbd/drbd_receiver.c b/drbd/drbd_receiver.c
index ee54cf3ac116..985fac8e69b3 100644
--- a/drbd/drbd_receiver.c
+++ b/drbd/drbd_receiver.c
@@ -5815,7 +5815,15 @@ static int receive_uuids110(struct drbd_connection *connection, struct packet_in
peer_md = device->ldev->md.peers;
spin_lock_irq(&device->ldev->md.uuid_lock);
}
- peer_device->current_uuid = be64_to_cpu(p->current_uuid);
+
+ if (device->resource->role[NOW] != R_PRIMARY ||
+ device->disk_state[NOW] != D_DISKLESS ||
+ (peer_device->current_uuid & ~UUID_PRIMARY) !=
+ (device->exposed_data_uuid & ~UUID_PRIMARY) ||
+ (peer_device->comm_current_uuid & ~UUID_PRIMARY) !=
+ (device->exposed_data_uuid & ~UUID_PRIMARY))
+ peer_device->current_uuid = be64_to_cpu(p->current_uuid);
+
peer_device->dirty_bits = be64_to_cpu(p->dirty_bits);
peer_device->uuid_flags = be64_to_cpu(p->uuid_flags);
if (peer_device->uuid_flags & UUID_FLAG_HAS_UNALLOC) {
--
2.35.3

View File

@ -1,39 +0,0 @@
From c7384276634be7c5b49ef0b8d7fa064927a207f8 Mon Sep 17 00:00:00 2001
From: Philipp Reisner <philipp.reisner@linbit.com>
Date: Wed, 14 Aug 2024 19:42:40 +0200
Subject: [PATCH 05/32] drbd: Proper locking around new_current_uuid on a
diskless
Like the current UUID of a diskful node, changing the exposed_uuid of
a diskless node needs to be serialized with the UUID exchange when
establishing new connections.
---
drbd/drbd_main.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/drbd/drbd_main.c b/drbd/drbd_main.c
index bc3283b045c9..2792b9896271 100644
--- a/drbd/drbd_main.c
+++ b/drbd/drbd_main.c
@@ -4827,7 +4827,10 @@ void drbd_uuid_new_current(struct drbd_device *device, bool forced)
current_uuid |= UUID_PRIMARY;
else
current_uuid &= ~UUID_PRIMARY;
+
+ down_write(&device->uuid_sem);
drbd_uuid_set_exposed(device, current_uuid, false);
+ downgrade_write(&device->uuid_sem);
drbd_info(device, "sending new current UUID: %016llX\n", current_uuid);
weak_nodes = drbd_weak_nodes_device(device);
@@ -4837,6 +4840,7 @@ void drbd_uuid_new_current(struct drbd_device *device, bool forced)
peer_device->current_uuid = current_uuid;
}
}
+ up_read(&device->uuid_sem);
}
}
--
2.35.3

View File

@ -1,43 +0,0 @@
From 18795749745baa4b8b37cb56eb12a57a7bd55da7 Mon Sep 17 00:00:00 2001
From: Roland Kammerer <roland.kammerer@linbit.com>
Date: Tue, 27 Aug 2024 09:08:31 +0200
Subject: [PATCH 06/32] build: CycloneDX: fix bom-ref, add purl
---
Makefile | 4 ++--
drbd-kmod.cdx.json.in | 1 +
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/Makefile b/Makefile
index 83a2ed8a42f7..3f58568cc138 100644
--- a/Makefile
+++ b/Makefile
@@ -238,11 +238,11 @@ drbd-kmod_rhel.spdx drbd-kmod_sles.spdx:
# only call this wrapper from drbd-kmod.cdx.json
.PHONY: cdx-sub
cdx-sub:
- cat $(CDX_FILE).in | jq --args '.metadata.timestamp = "$(CDX_DATE)" | .metadata.component.version = "$(FDIST_VERSION)" | .metadata.component."bom-ref" = "https://github.com/LINBIT/drbd/releases/tag/drbd-$(FDIST_VERSION)"' > $(CDX_FILE)
+ cat $(CDX_FILE).in | jq --args '.metadata.timestamp = "$(CDX_DATE)" | .metadata.component.version = "$(FDIST_VERSION)" | .metadata.component."bom-ref" = "$(PURL)" | .metadata.component.purl = "$(PURL)"' > $(CDX_FILE)
.PHONY: drbd-kmod.cdx.json
drbd-kmod.cdx.json:
- $(MAKE) -s cdx-sub CDX_DATE="$$(date --utc +%FT%TZ)" CDX_FILE="$@"
+ $(MAKE) -s cdx-sub CDX_DATE="$$(date --utc +%FT%TZ)" PURL="pkg:github/LINBIT/drbd@drbd-$(FDIST_VERSION)" CDX_FILE="$@"
! grep -q __PLACEHOLDER__ $@
# update of .filelist is forced:
diff --git a/drbd-kmod.cdx.json.in b/drbd-kmod.cdx.json.in
index f7a4c4a46aa6..ab4e05a43187 100644
--- a/drbd-kmod.cdx.json.in
+++ b/drbd-kmod.cdx.json.in
@@ -18,6 +18,7 @@
"name": "kmod-drbd",
"version": "__PLACEHOLDER__",
"bom-ref": "__PLACEHOLDER__",
+ "purl": "__PLACEHOLDER__",
"licenses": [
{
"licenses": {
--
2.35.3

View File

@ -1,51 +0,0 @@
From c4dd27cc69b99e13d4117fa348f968cf2199db6b Mon Sep 17 00:00:00 2001
From: Philipp Reisner <philipp.reisner@linbit.com>
Date: Wed, 28 Aug 2024 18:43:31 +0200
Subject: [PATCH 07/32] build: Another update to the spdx files
Some enterprise customers require these files to contain a
"PackageCopyrightText" tag. Apart from that they require the
SPDX in JSON format. That will come in another commit.
---
Makefile | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/Makefile b/Makefile
index 3f58568cc138..80c20d24ab54 100644
--- a/Makefile
+++ b/Makefile
@@ -205,6 +205,8 @@ PackageSupplier: Organization: LINBIT HA-Solutions GmbH
PackageDownloadLocation: https://github.com/LINBIT/drbd
FilesAnalyzed: false
PackageLicenseDeclared: GPL-2.0-only
+PackageCopyrightText: <text>2001-2008, LINBIT Information Technologies GmbH
+2008-$(SPDX_YEAR), LINBIT HA-Solutions GmbH</text>
Relationship: SPDXRef-DOCUMENT DESCRIBES SPDXRef-Package-$(SPDX_PKG_NAME)
endef
@@ -219,6 +221,7 @@ drbd-kmod_rhel.spdx drbd-kmod_sles.spdx:
SPDX_DATE="$$(date --utc +%FT%TZ)"; \
SPDX_UUID="$$(cat /proc/sys/kernel/random/uuid)"; \
SPDX_VERSION="$(REL_VERSION)"; \
+ SPDX_YEAR="$$(date --utc +%Y)"; \
case "$@" in \
drbd-kmod_rhel.spdx) SPDX_PKG_NAME=kmod-drbd;; \
drbd-kmod_sles.spdx) SPDX_PKG_NAME=drbd-kmp-default;; \
@@ -228,11 +231,13 @@ drbd-kmod_rhel.spdx drbd-kmod_sles.spdx:
test -n "$$SPDX_DATE"; \
test -n "$$SPDX_UUID"; \
test -n "$$SPDX_VERSION"; \
+ test -n "$$SPDX_YEAR"; \
$(MAKE) spdx-file SPDX_UUID="$$SPDX_UUID" \
SPDX_DATE="$$SPDX_DATE" \
SPDX_FILE_TMP="$@.tmp" \
SPDX_PKG_NAME="$$SPDX_PKG_NAME" \
- SPDX_VERSION="$$SPDX_VERSION"; \
+ SPDX_VERSION="$$SPDX_VERSION" \
+ SPDX_YEAR="$$SPDX_YEAR"; \
mv $@.tmp $@; )
# only call this wrapper from drbd-kmod.cdx.json
--
2.35.3

View File

@ -1,235 +0,0 @@
From ca3589743378a7750b9e6a8e19b904d57986cce4 Mon Sep 17 00:00:00 2001
From: Lars Ellenberg <lars.ellenberg@linbit.com>
Date: Wed, 28 Aug 2024 20:00:36 +0200
Subject: [PATCH 08/32] build: generate spdx.json, not "tag value" format
Generates .spdx.json files in SPDX-json format instead of tag/value.
This appears to be more machine friendly.
Use jq with "null" input and \(env.<environment-variable-name>) string interpolation in templates.
Move all this to a new ./sbom/ subdirectory.
---
Makefile | 74 ++-----------------
sbom/Makefile | 24 ++++++
.../drbd-kmod.cdx.json.in | 8 +-
sbom/drbd-kmod.spdx.json.in | 32 ++++++++
4 files changed, 68 insertions(+), 70 deletions(-)
create mode 100644 sbom/Makefile
rename drbd-kmod.cdx.json.in => sbom/drbd-kmod.cdx.json.in (84%)
create mode 100644 sbom/drbd-kmod.spdx.json.in
diff --git a/Makefile b/Makefile
index 80c20d24ab54..37ffcd777d09 100644
--- a/Makefile
+++ b/Makefile
@@ -92,6 +92,8 @@ ifndef FDIST_VERSION
FDIST_VERSION := $(DIST_VERSION)
endif
+export REL_VERSION FDIST_VERSION
+
all: module tools
.PHONY: all tools module
@@ -189,76 +191,15 @@ drbd/.drbd_git_revision: FORCE
@echo >&2 "Need a git checkout to regenerate $@"; test -s $@
endif
-export define SPDX_TEMPLATE
-SPDXVersion: SPDX-2.3
-DataLicense: CC0-1.0
-SPDXID: SPDXRef-DOCUMENT
-DocumentName: drbd kernel module SBOM (software bill of materials)
-DocumentNamespace: https://linbit.org/spdx-docs/drbd-kmod-$(SPDX_VERSION)-$(SPDX_UUID)
-Creator: Person: Philipp Reisner (philipp.reisner@linbit.com)
-Created: $(SPDX_DATE)
-
-PackageName: $(SPDX_PKG_NAME)
-SPDXID: SPDXRef-Package-$(SPDX_PKG_NAME)
-PackageVersion: $(SPDX_VERSION)
-PackageSupplier: Organization: LINBIT HA-Solutions GmbH
-PackageDownloadLocation: https://github.com/LINBIT/drbd
-FilesAnalyzed: false
-PackageLicenseDeclared: GPL-2.0-only
-PackageCopyrightText: <text>2001-2008, LINBIT Information Technologies GmbH
-2008-$(SPDX_YEAR), LINBIT HA-Solutions GmbH</text>
-Relationship: SPDXRef-DOCUMENT DESCRIBES SPDXRef-Package-$(SPDX_PKG_NAME)
-endef
-
-# only call this wrapper from drbd-kmod_{sles,rhel}.spdx
-.PHONY: spdx-file
-spdx-file:
- @echo "$$SPDX_TEMPLATE" > $(SPDX_FILE_TMP)
-
-.PHONY: drbd-kmod_rhel.spdx drbd-kmod_sles.spdx
-drbd-kmod_rhel.spdx drbd-kmod_sles.spdx:
- @set -e; ( truncate -s0 $@.tmp; \
- SPDX_DATE="$$(date --utc +%FT%TZ)"; \
- SPDX_UUID="$$(cat /proc/sys/kernel/random/uuid)"; \
- SPDX_VERSION="$(REL_VERSION)"; \
- SPDX_YEAR="$$(date --utc +%Y)"; \
- case "$@" in \
- drbd-kmod_rhel.spdx) SPDX_PKG_NAME=kmod-drbd;; \
- drbd-kmod_sles.spdx) SPDX_PKG_NAME=drbd-kmp-default;; \
- *) false;; \
- esac; \
- test -n "$$SPDX_TEMPLATE"; \
- test -n "$$SPDX_DATE"; \
- test -n "$$SPDX_UUID"; \
- test -n "$$SPDX_VERSION"; \
- test -n "$$SPDX_YEAR"; \
- $(MAKE) spdx-file SPDX_UUID="$$SPDX_UUID" \
- SPDX_DATE="$$SPDX_DATE" \
- SPDX_FILE_TMP="$@.tmp" \
- SPDX_PKG_NAME="$$SPDX_PKG_NAME" \
- SPDX_VERSION="$$SPDX_VERSION" \
- SPDX_YEAR="$$SPDX_YEAR"; \
- mv $@.tmp $@; )
-
-# only call this wrapper from drbd-kmod.cdx.json
-.PHONY: cdx-sub
-cdx-sub:
- cat $(CDX_FILE).in | jq --args '.metadata.timestamp = "$(CDX_DATE)" | .metadata.component.version = "$(FDIST_VERSION)" | .metadata.component."bom-ref" = "$(PURL)" | .metadata.component.purl = "$(PURL)"' > $(CDX_FILE)
-
-.PHONY: drbd-kmod.cdx.json
-drbd-kmod.cdx.json:
- $(MAKE) -s cdx-sub CDX_DATE="$$(date --utc +%FT%TZ)" PURL="pkg:github/LINBIT/drbd@drbd-$(FDIST_VERSION)" CDX_FILE="$@"
- ! grep -q __PLACEHOLDER__ $@
-
# update of .filelist is forced:
.fdist_version: FORCE
@test -s $@ && test "$$(cat $@)" = "$(FDIST_VERSION)" || echo "$(FDIST_VERSION)" > $@
.filelist: .fdist_version FORCE
@$(GIT) ls-files --recurse -- ':!:.git*' $(if $(PRESERVE_DEBIAN),,':!:debian') > $@.new
+ @test -s $@.new # assert there is something in .filelist.new now
@mkdir -p drbd/drbd-kernel-compat/cocci_cache/
@find drbd/drbd-kernel-compat/cocci_cache/ -type f -not -path '*/\.*' >> $@.new
- @test -s $@.new # assert there is something in .filelist.new now
@mv $@.new $@
@echo "./.filelist updated."
@@ -273,9 +214,10 @@ drbd-kmod.cdx.json:
comma := ,
backslash_comma := \,
escape_comma = $(subst $(comma),$(backslash_comma),$(1))
-tgz-extra-files := \
- .fdist_version drbd/.drbd_git_revision .filelist \
- drbd-kmod_rhel.spdx drbd-kmod_sles.spdx drbd-kmod.cdx.json
+tgz-extra-files := .fdist_version drbd/.drbd_git_revision .filelist
+tgz-extra-files += sbom/drbd-kmod_rhel.spdx.json
+tgz-extra-files += sbom/drbd-kmod_sles.spdx.json
+tgz-extra-files += sbom/drbd-kmod.cdx.json
tgz:
test -s .filelist # .filelist must be present
test -n "$(FDIST_VERSION)" # FDIST_VERSION must be known
@@ -318,7 +260,7 @@ debrelease:
tarball:
$(MAKE) distclean
$(MAKE) check-submods check_all_committed drbd/.drbd_git_revision
- $(MAKE) drbd-kmod_rhel.spdx drbd-kmod_sles.spdx drbd-kmod.cdx.json
+ $(MAKE) -C sbom drbd-kmod_rhel.spdx.json drbd-kmod_sles.spdx.json drbd-kmod.cdx.json
$(MAKE) .filelist
$(MAKE) tgz
diff --git a/sbom/Makefile b/sbom/Makefile
new file mode 100644
index 000000000000..757f57e4db60
--- /dev/null
+++ b/sbom/Makefile
@@ -0,0 +1,24 @@
+
+# we inherit some variables from our "parent" Makefile
+THIS_MAKEFILE := $(lastword $(MAKEFILE_LIST))
+$(foreach v,REL_VERSION FDIST_VERSION,$(if $($(v)),,$(error "Do not use this Makefile ($(THIS_MAKEFILE)) directly! ($(v) missing))))
+
+all: drbd-kmod.cdx.json drbd-kmod_rhel.spdx.json drbd-kmod_sles.spdx.json
+
+export SPDX_VERSION SPDX_DATE SPDX_YEAR SPDX_UUID SPDX_PKG_NAME
+SPDX_VERSION:=$(REL_VERSION)
+SPDX_DATE:=$(shell date --utc +%FT%TZ)
+SPDX_YEAR:=$(firstword $(subst -, ,$(SPDX_DATE)))
+drbd-kmod_rhel.spdx.json drbd-kmod_sles.spdx.json: SPDX_UUID:=$(shell cat /proc/sys/kernel/random/uuid)
+drbd-kmod_rhel.spdx.json: SPDX_PKG_NAME:=kmod-drbd
+drbd-kmod_sles.spdx.json: SPDX_PKG_NAME:=drbd-kmp-default
+drbd-kmod_rhel.spdx.json drbd-kmod_sles.spdx.json: FORCE
+ @rm -f $@; jq -n -f drbd-kmod.spdx.json.in > $@.tmp && mv $@.tmp $@
+
+# uses:
+# SPDX_DATE from above and FDIST_VERSION from parent Makefile
+drbd-kmod.cdx.json: FORCE
+ @rm -f $@; jq -n -f drbd-kmod.cdx.json.in > $@.tmp && mv $@.tmp $@
+
+.PHONY: FORCE
+FORCE:
diff --git a/drbd-kmod.cdx.json.in b/sbom/drbd-kmod.cdx.json.in
similarity index 84%
rename from drbd-kmod.cdx.json.in
rename to sbom/drbd-kmod.cdx.json.in
index ab4e05a43187..99858e8b9b43 100644
--- a/drbd-kmod.cdx.json.in
+++ b/sbom/drbd-kmod.cdx.json.in
@@ -2,7 +2,7 @@
"bomFormat": "CycloneDX",
"specVersion": "1.5",
"metadata": {
- "timestamp": "__PLACEHOLDER__",
+ "timestamp": "\(env.SPDX_DATE)",
"authors": [
{
"name": "Philipp Reisner",
@@ -16,9 +16,9 @@
"component": {
"type": "application",
"name": "kmod-drbd",
- "version": "__PLACEHOLDER__",
- "bom-ref": "__PLACEHOLDER__",
- "purl": "__PLACEHOLDER__",
+ "version": "\(env.FDIST_VERSION)",
+ "bom-ref": "pkg:github/LINBIT/drbd@drbd-\(env.FDIST_VERSION)",
+ "purl": "pkg:github/LINBIT/drbd@drbd-\(env.FDIST_VERSION)",
"licenses": [
{
"licenses": {
diff --git a/sbom/drbd-kmod.spdx.json.in b/sbom/drbd-kmod.spdx.json.in
new file mode 100644
index 000000000000..07c1003f8834
--- /dev/null
+++ b/sbom/drbd-kmod.spdx.json.in
@@ -0,0 +1,32 @@
+{
+ "SPDXID": "SPDXRef-DOCUMENT",
+ "spdxVersion": "SPDX-2.3",
+ "creationInfo": {
+ "created": "\(env.SPDX_DATE)",
+ "creators": [
+ "Person: Philipp Reisner (philipp.reisner@linbit.com)"
+ ]
+ },
+ "name": "drbd kernel module SBOM (software bill of materials)",
+ "dataLicense": "CC0-1.0",
+ "documentNamespace": "https://linbit.org/spdx-docs/drbd-kmod-\(env.SPDX_VERSION)-\(env.SPDX_UUID)",
+ "packages": [
+ {
+ "SPDXID": "SPDXRef-Package-\(env.SPDX_PKG_NAME)",
+ "copyrightText": "2001-2008, LINBIT Information Technologies GmbH\n2008-\(env.SPDX_YEAR), LINBIT HA-Solutions GmbH",
+ "downloadLocation": "https://github.com/LINBIT/drbd",
+ "filesAnalyzed": false,
+ "licenseDeclared": "GPL-2.0-only",
+ "name": "\(env.SPDX_PKG_NAME)",
+ "supplier": "Organization: LINBIT HA-Solutions GmbH",
+ "versionInfo": "\(env.SPDX_VERSION)"
+ }
+ ],
+ "relationships": [
+ {
+ "spdxElementId": "SPDXRef-DOCUMENT",
+ "relationshipType": "DESCRIBES",
+ "relatedSpdxElement": "SPDXRef-Package-\(env.SPDX_PKG_NAME)"
+ }
+ ]
+}
--
2.35.3

View File

@ -1,49 +0,0 @@
From 98325293e7d64ffae0e5e70620c5040ab0c76179 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Christoph=20B=C3=B6hmwalder?=
<christoph.boehmwalder@linbit.com>
Date: Tue, 13 Aug 2024 12:23:52 +0200
Subject: [PATCH 09/32] compat: fix gen_patch_names for bdev_file_open_by_path
---
drbd/drbd-kernel-compat/gen_patch_names.c | 12 +++++-------
1 file changed, 5 insertions(+), 7 deletions(-)
diff --git a/drbd/drbd-kernel-compat/gen_patch_names.c b/drbd/drbd-kernel-compat/gen_patch_names.c
index a9781bbd04e5..7549ee39afb7 100644
--- a/drbd/drbd-kernel-compat/gen_patch_names.c
+++ b/drbd/drbd-kernel-compat/gen_patch_names.c
@@ -564,14 +564,17 @@ int main(int argc, char **argv)
patch(1, "__bio_add_page", true, false,
COMPAT_HAVE___BIO_ADD_PAGE, "present");
+ /* blkdev_put is oldest, then bdev_open_by_path, then bdev_file_open_by_path */
patch(1, "bdev_file_open_by_path", true, false,
COMPAT_HAVE_BDEV_FILE_OPEN_BY_PATH, "present");
-
#if !defined(COMPAT_HAVE_BDEV_FILE_OPEN_BY_PATH)
+ /* middle ground: bdev_open_by_path */
patch(1, "bdev_open_by_path", true, false,
COMPAT_HAVE_BDEV_OPEN_BY_PATH, "present");
-
# if !defined(COMPAT_HAVE_BDEV_OPEN_BY_PATH)
+ /* old: blkdev_get_by_* and blkdev_put */
+ patch(1, "blkdev_put", true, false,
+ COMPAT_BLKDEV_PUT_HAS_HOLDER, "has_holder");
patch(1, "blkdev_get_by_path", true, false,
COMPAT_BLKDEV_GET_BY_PATH_HAS_HOLDER_OPS, "has_holder_ops");
# endif
@@ -586,11 +589,6 @@ int main(int argc, char **argv)
patch(1, "blk_mode_t", true, false,
COMPAT_HAVE_BLK_MODE_T, "present");
-#if !defined(COMPAT_HAVE_BDEV_OPEN_BY_PATH)
- patch(1, "blkdev_put", true, false,
- COMPAT_BLKDEV_PUT_HAS_HOLDER, "has_holder");
-#endif
-
patch(1, "genl_info_userhdr", true, false,
COMPAT_HAVE_GENL_INFO_USERHDR, "present");
--
2.35.3

View File

@ -1,35 +0,0 @@
From f6078aa51ed5b776eb2f646553872d576c404c60 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Christoph=20B=C3=B6hmwalder?=
<christoph.boehmwalder@linbit.com>
Date: Tue, 13 Aug 2024 12:40:27 +0200
Subject: [PATCH 10/32] compat: fix nla_nest_start_noflag test
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
GCC complains:
returning struct nlattr * from a function with return type int makes
integer from pointer without a cast
Return the proper type from this function.
---
drbd/drbd-kernel-compat/tests/have_nla_nest_start_noflag.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drbd/drbd-kernel-compat/tests/have_nla_nest_start_noflag.c b/drbd/drbd-kernel-compat/tests/have_nla_nest_start_noflag.c
index 1d8037c397c5..62ab06c563b7 100644
--- a/drbd/drbd-kernel-compat/tests/have_nla_nest_start_noflag.c
+++ b/drbd/drbd-kernel-compat/tests/have_nla_nest_start_noflag.c
@@ -1,7 +1,7 @@
/* {"version": "5.1-rc7", "commit": "ae0be8de9a53cda3505865c11826d8ff0640237c", "comment": "nla_nest_start was renamed to _noflag, and the original version became a wrapper adding a flag", "author": "Michal Kubecek <mkubecek@suse.cz>", "date": "Fri Apr 26 11:13:06 2019 +0200"} */
#include <net/netlink.h>
-int dummy(struct sk_buff *skb, int attrtype)
+static struct nlattr *dummy(struct sk_buff *skb, int attrtype)
{
return nla_nest_start_noflag(skb, attrtype);
}
--
2.35.3

View File

@ -1,29 +0,0 @@
From 32b84f7b4d071312e5e812eab6b26e4aad2899e4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Christoph=20B=C3=B6hmwalder?=
<christoph.boehmwalder@linbit.com>
Date: Mon, 19 Aug 2024 16:19:47 +0200
Subject: [PATCH 11/32] compat: fix blk_alloc_disk rule
---
drbd/drbd-kernel-compat/gen_patch_names.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drbd/drbd-kernel-compat/gen_patch_names.c b/drbd/drbd-kernel-compat/gen_patch_names.c
index 7549ee39afb7..c21a43b39488 100644
--- a/drbd/drbd-kernel-compat/gen_patch_names.c
+++ b/drbd/drbd-kernel-compat/gen_patch_names.c
@@ -155,9 +155,10 @@ int main(int argc, char **argv)
patch(1, "blk_alloc_disk", true, false,
COMPAT_BLK_ALLOC_DISK_TAKES_QUEUE_LIMITS, "takes_queue_limits");
-
+#if !defined(COMPAT_BLK_ALLOC_DISK_TAKES_QUEUE_LIMITS)
patch(1, "blk_alloc_disk", true, false,
COMPAT_HAVE_BLK_ALLOC_DISK, "present");
+#endif
/*******************************************************************************/
/*
--
2.35.3

View File

@ -1,29 +0,0 @@
From 392743b95ab0aaff13d5c91eaaab5ae24388384f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Christoph=20B=C3=B6hmwalder?=
<christoph.boehmwalder@linbit.com>
Date: Tue, 13 Aug 2024 12:29:35 +0200
Subject: [PATCH 12/32] drbd: remove const from function return type
Linux 6.10 enables some compiler flag that errors out with:
error: type qualifiers ignored on function return type
---
drbd/drbd_receiver.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drbd/drbd_receiver.c b/drbd/drbd_receiver.c
index 985fac8e69b3..1b9f80de6f41 100644
--- a/drbd/drbd_receiver.c
+++ b/drbd/drbd_receiver.c
@@ -272,7 +272,7 @@ static const char *drbd_sync_rule_str(enum sync_rule rule)
return sync_rule_names[rule];
}
-static const struct sync_descriptor strategy_descriptor(enum sync_strategy strategy)
+static struct sync_descriptor strategy_descriptor(enum sync_strategy strategy)
{
if (strategy < 0 || strategy > ARRAY_SIZE(sync_descriptors)) {
WARN_ON(true);
--
2.35.3

View File

@ -1,39 +0,0 @@
From 3672388dc75cbcdb5f3821b5f4354b55333004f5 Mon Sep 17 00:00:00 2001
From: Christoph Hellwig <hch@lst.de>
Date: Wed, 6 Mar 2024 15:03:30 +0100
Subject: [PATCH 13/32] drbd: don't set max_write_zeroes_sectors in
decide_on_discard_support
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
fixup_write_zeroes always overrides the max_write_zeroes_sectors value
a little further down the callchain, so don't bother to setup a limit
in decide_on_discard_support.
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Philipp Reisner <philipp.reisner@linbit.com>
Reviewed-by: Lars Ellenberg <lars.ellenberg@linbit.com>
Tested-by: Christoph Böhmwalder <christoph.boehmwalder@linbit.com>
Link: https://lore.kernel.org/r/20240306140332.623759-6-philipp.reisner@linbit.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Christoph Böhmwalder <christoph.boehmwalder@linbit.com>
---
drbd/drbd_nl.c | 1 -
1 file changed, 1 deletion(-)
diff --git a/drbd/drbd_nl.c b/drbd/drbd_nl.c
index ef315e02f437..a0c3534d8996 100644
--- a/drbd/drbd_nl.c
+++ b/drbd/drbd_nl.c
@@ -2070,7 +2070,6 @@ static void decide_on_discard_support(struct drbd_device *device,
blk_queue_discard_granularity(q, 512);
max_discard_sectors = drbd_max_discard_sectors(device->resource);
blk_queue_max_discard_sectors(q, max_discard_sectors);
- blk_queue_max_write_zeroes_sectors(q, max_discard_sectors);
return;
not_supported:
--
2.35.3

View File

@ -1,73 +0,0 @@
From 78d5d462c2bdac350921c114caca588c606d7c0b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Christoph=20B=C3=B6hmwalder?=
<christoph.boehmwalder@linbit.com>
Date: Mon, 1 Jul 2024 17:56:08 +0200
Subject: [PATCH 14/32] drbd: split out a drbd_discard_supported helper
Add a helper to check if discard is supported for a given connection /
backing device combination.
Similar idea to upstream kernel commit 5eaee6e9c8f9
("drbd: split out a drbd_discard_supported helper"), but also get rid of
the goto.
---
drbd/drbd_nl.c | 29 ++++++++++++++++++-----------
1 file changed, 18 insertions(+), 11 deletions(-)
diff --git a/drbd/drbd_nl.c b/drbd/drbd_nl.c
index a0c3534d8996..e3f508cd0421 100644
--- a/drbd/drbd_nl.c
+++ b/drbd/drbd_nl.c
@@ -2044,19 +2044,31 @@ static unsigned int drbd_max_discard_sectors(struct drbd_resource *resource)
return s;
}
-static void decide_on_discard_support(struct drbd_device *device,
+static bool drbd_discard_supported(struct drbd_device *device,
struct drbd_backing_dev *bdev)
{
- struct request_queue *q = device->rq_queue;
- unsigned int max_discard_sectors;
-
if (bdev && !bdev_max_discard_sectors(bdev->backing_bdev))
- goto not_supported;
+ return false;
if (!(common_connection_features(device->resource) & DRBD_FF_TRIM)) {
drbd_info(device,
"peer DRBD too old, does not support TRIM: disabling discards\n");
- goto not_supported;
+ return false;
+ }
+
+ return true;
+}
+
+static void decide_on_discard_support(struct drbd_device *device,
+ struct drbd_backing_dev *bdev)
+{
+ struct request_queue *q = device->rq_queue;
+ unsigned int max_discard_sectors;
+
+ if (!drbd_discard_supported(device, bdev)) {
+ blk_queue_discard_granularity(q, 0);
+ blk_queue_max_discard_sectors(q, 0);
+ return;
}
/*
@@ -2070,11 +2082,6 @@ static void decide_on_discard_support(struct drbd_device *device,
blk_queue_discard_granularity(q, 512);
max_discard_sectors = drbd_max_discard_sectors(device->resource);
blk_queue_max_discard_sectors(q, max_discard_sectors);
- return;
-
-not_supported:
- blk_queue_discard_granularity(q, 0);
- blk_queue_max_discard_sectors(q, 0);
}
static void fixup_write_zeroes(struct drbd_device *device, struct request_queue *q)
--
2.35.3

View File

@ -1,194 +0,0 @@
From 5931286cb71114c0f34e51fc7f357dceec139ca1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Christoph=20B=C3=B6hmwalder?=
<christoph.boehmwalder@linbit.com>
Date: Tue, 13 Aug 2024 12:26:02 +0200
Subject: [PATCH 15/32] drbd: atomically update queue limits in
drbd_reconsider_queue_parameters
Switch drbd_reconsider_queue_parameters to set up the queue parameters
in an on-stack queue_limits structure and apply the limits atomically.
Remove various helpers that have become so trivial that they can be
folded into drbd_reconsider_queue_parameters.
Same idea as upstream kernel commit e6dfe748f09e ("drbd: atomically
update queue limits in drbd_reconsider_queue_parameters"), but with some
adaptations to DRBD 9.
---
drbd/drbd_nl.c | 136 ++++++++++++++++++++++---------------------------
1 file changed, 60 insertions(+), 76 deletions(-)
diff --git a/drbd/drbd_nl.c b/drbd/drbd_nl.c
index e3f508cd0421..7193ba0c77e3 100644
--- a/drbd/drbd_nl.c
+++ b/drbd/drbd_nl.c
@@ -2018,11 +2018,6 @@ static u32 common_connection_features(struct drbd_resource *resource)
return features;
}
-static void blk_queue_discard_granularity(struct request_queue *q, unsigned int granularity)
-{
- q->limits.discard_granularity = granularity;
-}
-
static unsigned int drbd_max_discard_sectors(struct drbd_resource *resource)
{
struct drbd_connection *connection;
@@ -2059,73 +2054,20 @@ static bool drbd_discard_supported(struct drbd_device *device,
return true;
}
-static void decide_on_discard_support(struct drbd_device *device,
- struct drbd_backing_dev *bdev)
-{
- struct request_queue *q = device->rq_queue;
- unsigned int max_discard_sectors;
-
- if (!drbd_discard_supported(device, bdev)) {
- blk_queue_discard_granularity(q, 0);
- blk_queue_max_discard_sectors(q, 0);
- return;
- }
-
- /*
- * We don't care for the granularity, really.
- *
- * Stacking limits below should fix it for the local device. Whether or
- * not it is a suitable granularity on the remote device is not our
- * problem, really. If you care, you need to use devices with similar
- * topology on all peers.
- */
- blk_queue_discard_granularity(q, 512);
- max_discard_sectors = drbd_max_discard_sectors(device->resource);
- blk_queue_max_discard_sectors(q, max_discard_sectors);
-}
-
-static void fixup_write_zeroes(struct drbd_device *device, struct request_queue *q)
-{
- /* Fixup max_write_zeroes_sectors after blk_stack_limits():
- * if we can handle "zeroes" efficiently on the protocol,
- * we want to do that, even if our backend does not announce
- * max_write_zeroes_sectors itself. */
-
- /* If all peers announce WZEROES support, use it. Otherwise, rather
- * send explicit zeroes than rely on some discard-zeroes-data magic. */
- if (common_connection_features(device->resource) & DRBD_FF_WZEROES)
- q->limits.max_write_zeroes_sectors = DRBD_MAX_BBIO_SECTORS;
- else
- q->limits.max_write_zeroes_sectors = 0;
-}
-
-static void fixup_discard_support(struct drbd_device *device, struct request_queue *q)
-{
- unsigned int max_discard = device->rq_queue->limits.max_discard_sectors;
- unsigned int discard_granularity = device->rq_queue->limits.discard_granularity >> SECTOR_SHIFT;
-
- if (discard_granularity > max_discard) {
- blk_queue_discard_granularity(q, 0);
- blk_queue_max_discard_sectors(q, 0);
- }
-}
-
-void drbd_reconsider_queue_parameters(struct drbd_device *device, struct drbd_backing_dev *bdev)
+static void get_common_queue_limits(struct queue_limits *common_limits,
+ struct drbd_device *device)
{
- struct request_queue * const q = device->rq_queue;
- struct queue_limits common_limits = { 0 }; /* sizeof(struct queue_limits) ~ 110 bytes */
- struct queue_limits peer_limits = { 0 };
struct drbd_peer_device *peer_device;
- struct request_queue *b = NULL;
+ struct queue_limits peer_limits = { 0 };
- blk_set_stacking_limits(&common_limits);
+ blk_set_stacking_limits(common_limits);
/* This is the workaround for "bio would need to, but cannot, be split" */
- common_limits.seg_boundary_mask = PAGE_SIZE - 1;
- common_limits.max_hw_sectors = device->device_conf.max_bio_size >> SECTOR_SHIFT;
- common_limits.max_sectors = device->device_conf.max_bio_size >> SECTOR_SHIFT;
- common_limits.physical_block_size = device->device_conf.block_size;
- common_limits.logical_block_size = device->device_conf.block_size;
- common_limits.io_min = device->device_conf.block_size;
+ common_limits->seg_boundary_mask = PAGE_SIZE - 1;
+ common_limits->max_hw_sectors = device->device_conf.max_bio_size >> SECTOR_SHIFT;
+ common_limits->max_sectors = device->device_conf.max_bio_size >> SECTOR_SHIFT;
+ common_limits->physical_block_size = device->device_conf.block_size;
+ common_limits->logical_block_size = device->device_conf.block_size;
+ common_limits->io_min = device->device_conf.block_size;
rcu_read_lock();
for_each_peer_device_rcu(peer_device, device) {
@@ -2140,21 +2082,63 @@ void drbd_reconsider_queue_parameters(struct drbd_device *device, struct drbd_ba
peer_limits.io_opt = peer_device->q_limits.io_opt;
peer_limits.max_hw_sectors = peer_device->q_limits.max_bio_size >> SECTOR_SHIFT;
peer_limits.max_sectors = peer_device->q_limits.max_bio_size >> SECTOR_SHIFT;
- blk_stack_limits(&common_limits, &peer_limits, 0);
+ blk_stack_limits(common_limits, &peer_limits, 0);
}
rcu_read_unlock();
+}
+
+void drbd_reconsider_queue_parameters(struct drbd_device *device, struct drbd_backing_dev *bdev)
+{
+ struct request_queue * const q = device->rq_queue;
+ struct queue_limits lim;
+ struct request_queue *b = NULL;
+
+ lim = queue_limits_start_update(q);
+ get_common_queue_limits(&lim, device);
+
+ /*
+ * We don't care for the granularity, really.
+ * Stacking limits below should fix it for the local device. Whether or
+ * not it is a suitable granularity on the remote device is not our
+ * problem, really. If you care, you need to use devices with similar
+ * topology on all peers.
+ */
+ if (drbd_discard_supported(device, bdev)) {
+ lim.discard_granularity = 512;
+ lim.max_hw_discard_sectors = drbd_max_discard_sectors(device->resource);
+ } else {
+ lim.discard_granularity = 0;
+ lim.max_hw_discard_sectors = 0;
+ }
if (bdev) {
b = bdev->backing_bdev->bd_disk->queue;
- blk_stack_limits(&common_limits, &b->limits, 0);
- disk_update_readahead(device->vdisk);
+ blk_stack_limits(&lim, &b->limits, 0);
+ }
+
+ /*
+ * If we can handle "zeroes" efficiently on the protocol,
+ * we want to do that, even if our backend does not announce
+ * max_write_zeroes_sectors itself.
+ */
+ if (common_connection_features(device->resource) & DRBD_FF_WZEROES)
+ lim.max_write_zeroes_sectors = DRBD_MAX_BBIO_SECTORS;
+ else
+ lim.max_write_zeroes_sectors = 0;
+
+ if ((lim.discard_granularity >> SECTOR_SHIFT) >
+ lim.max_hw_discard_sectors) {
+ /*
+ * discard_granularity is the smallest supported unit of a
+ * discard. If that is larger than the maximum supported discard
+ * size, we need to disable discards altogether.
+ */
+ lim.discard_granularity = 0;
+ lim.max_hw_discard_sectors = 0;
}
- q->limits = common_limits;
- blk_queue_max_hw_sectors(q, common_limits.max_hw_sectors);
- decide_on_discard_support(device, bdev);
- fixup_write_zeroes(device, q);
- fixup_discard_support(device, q);
+ if (queue_limits_commit_update(q, &lim))
+ drbd_err(device, "setting new queue limits failed\n");
}
/* Make sure IO is suspended before calling this function(). */
--
2.35.3

View File

@ -1,71 +0,0 @@
From fef08ee4fac426f5dfbec124bd2bd58fbd390cb2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Christoph=20B=C3=B6hmwalder?=
<christoph.boehmwalder@linbit.com>
Date: Thu, 22 Aug 2024 12:09:42 +0200
Subject: [PATCH 16/32] compat: test and patch for queue_limits_start_update
---
...ueue_limits_start_update__no_present.cocci | 20 +++++++++++++++++++
drbd/drbd-kernel-compat/gen_patch_names.c | 3 +++
.../tests/have_queue_limits_start_update.c | 8 ++++++++
3 files changed, 31 insertions(+)
create mode 100644 drbd/drbd-kernel-compat/cocci/queue_limits_start_update__no_present.cocci
create mode 100644 drbd/drbd-kernel-compat/tests/have_queue_limits_start_update.c
diff --git a/drbd/drbd-kernel-compat/cocci/queue_limits_start_update__no_present.cocci b/drbd/drbd-kernel-compat/cocci/queue_limits_start_update__no_present.cocci
new file mode 100644
index 000000000000..4e34f5887181
--- /dev/null
+++ b/drbd/drbd-kernel-compat/cocci/queue_limits_start_update__no_present.cocci
@@ -0,0 +1,20 @@
+@@
+identifier lim;
+identifier q;
+identifier device;
+identifier bdev;
+@@
+void drbd_reconsider_queue_parameters(struct drbd_device *device, struct drbd_backing_dev *bdev)
+{
+...
+ lim =
+- queue_limits_start_update(q);
++ q->limits;
+...
+- if (queue_limits_commit_update(q, &lim)) { ... }
++ blk_queue_max_hw_sectors(q, lim.max_hw_sectors);
++ q->limits = lim;
++ if (bdev)
++ disk_update_readahead(device->vdisk);
+...
+}
diff --git a/drbd/drbd-kernel-compat/gen_patch_names.c b/drbd/drbd-kernel-compat/gen_patch_names.c
index c21a43b39488..13aec5c8bd5f 100644
--- a/drbd/drbd-kernel-compat/gen_patch_names.c
+++ b/drbd/drbd-kernel-compat/gen_patch_names.c
@@ -393,6 +393,9 @@ int main(int argc, char **argv)
COMPAT_HAVE_WB_CONGESTED_ENUM, "present");
#endif
+ patch(1, "queue_limits_start_update", true, false,
+ COMPAT_HAVE_QUEUE_LIMITS_START_UPDATE, "present");
+
patch(1, "disk_update_readahead", true, false,
COMPAT_HAVE_DISK_UPDATE_READAHEAD, "present");
diff --git a/drbd/drbd-kernel-compat/tests/have_queue_limits_start_update.c b/drbd/drbd-kernel-compat/tests/have_queue_limits_start_update.c
new file mode 100644
index 000000000000..a867d1675218
--- /dev/null
+++ b/drbd/drbd-kernel-compat/tests/have_queue_limits_start_update.c
@@ -0,0 +1,8 @@
+/* { "version": "v6.9-rc1", "commit": "d690cb8ae14bd377d422b7905b6959c7e7a45b95", "comment": "block: add an API to atomically update queue limits", "author": "Christoph Hellwig <hch@lst.de>", "date": "Tue Feb 13 08:34:14 2024 +0100" } */
+
+#include <linux/blkdev.h>
+
+static struct queue_limits foo(struct request_queue *q)
+{
+ return queue_limits_start_update(q);
+}
--
2.35.3

View File

@ -1,54 +0,0 @@
From 4352ece8e85da43090be171276a0d45d83c55a00 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Christoph=20B=C3=B6hmwalder?=
<christoph.boehmwalder@linbit.com>
Date: Thu, 22 Aug 2024 12:25:39 +0200
Subject: [PATCH 17/32] compat: specify which essential change was not made
---
drbd/drbd-kernel-compat/cocci/bdi_congested__yes_present.cocci | 2 +-
drbd/drbd-kernel-compat/cocci/bio_op_shift__yes_present.cocci | 2 +-
.../cocci/blk_queue_max_write_same_sectors__yes_present.cocci | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/drbd/drbd-kernel-compat/cocci/bdi_congested__yes_present.cocci b/drbd/drbd-kernel-compat/cocci/bdi_congested__yes_present.cocci
index 8a0260321ab5..fdf6afc8355f 100644
--- a/drbd/drbd-kernel-compat/cocci/bdi_congested__yes_present.cocci
+++ b/drbd/drbd-kernel-compat/cocci/bdi_congested__yes_present.cocci
@@ -21,7 +21,7 @@ struct device_statistics *s;
@ script:python depends on !(add_bdi_read_congested_congested_remote && add_bdi_read_congested_device_to_statistics) @
@@
import sys
-print('ERROR: A rule making an essential change was not executed!', file=sys.stderr)
+print('ERROR: A rule making an essential change was not executed! (bdi_read_congested)', file=sys.stderr)
print('ERROR: This would not show up as a compiler error, but would still break DRBD.', file=sys.stderr)
print('ERROR: Check bdi_congested__yes_present.cocci', file=sys.stderr)
print('ERROR: As a precaution, the build will be aborted here.', file=sys.stderr)
diff --git a/drbd/drbd-kernel-compat/cocci/bio_op_shift__yes_present.cocci b/drbd/drbd-kernel-compat/cocci/bio_op_shift__yes_present.cocci
index cc02f5b91c2e..3225291f7dbd 100644
--- a/drbd/drbd-kernel-compat/cocci/bio_op_shift__yes_present.cocci
+++ b/drbd/drbd-kernel-compat/cocci/bio_op_shift__yes_present.cocci
@@ -57,7 +57,7 @@ combine_opf(wire_flags_to_bio_op(dpf),
@ script:python depends on !combine_wire_flags @
@@
import sys
-print('ERROR: A rule making an essential change was not executed!', file=sys.stderr)
+print('ERROR: A rule making an essential change was not executed! (combine_opf)', file=sys.stderr)
print('ERROR: This would not show up as a compiler error, but would still break DRBD.', file=sys.stderr)
print('ERROR: As a precaution, the build will be aborted here.', file=sys.stderr)
sys.exit(1)
diff --git a/drbd/drbd-kernel-compat/cocci/blk_queue_max_write_same_sectors__yes_present.cocci b/drbd/drbd-kernel-compat/cocci/blk_queue_max_write_same_sectors__yes_present.cocci
index 8eb4eef7dfd5..9202ee9c2dc4 100644
--- a/drbd/drbd-kernel-compat/cocci/blk_queue_max_write_same_sectors__yes_present.cocci
+++ b/drbd/drbd-kernel-compat/cocci/blk_queue_max_write_same_sectors__yes_present.cocci
@@ -7,7 +7,7 @@ blk_queue_max_hw_sectors(q, ...);
@ script:python depends on !add_blk_queue_max_write_same_sectors @
@@
import sys
-print('ERROR: A rule making an essential change was not executed!', file=sys.stderr)
+print('ERROR: A rule making an essential change was not executed! (blk_queue_max_write_same_sectors)', file=sys.stderr)
print('ERROR: This would not show up as a compiler error, but would still break DRBD.', file=sys.stderr)
print('ERROR: Check blk_queue_max_write_same_sectors_yes_present.cocci', file=sys.stderr)
print('ERROR: As a precaution, the build will be aborted here.', file=sys.stderr)
--
2.35.3

View File

@ -1,57 +0,0 @@
From b340c96d60065f08397d14360e7f045005c587e8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Christoph=20B=C3=B6hmwalder?=
<christoph.boehmwalder@linbit.com>
Date: Fri, 23 Aug 2024 12:30:45 +0200
Subject: [PATCH 18/32] gen_patch_names: reorder blk_mode_t
And match against bdev_file_open_by_path.
---
drbd/drbd-kernel-compat/cocci/blk_mode_t__no_present.cocci | 7 +------
drbd/drbd-kernel-compat/gen_patch_names.c | 6 +++---
2 files changed, 4 insertions(+), 9 deletions(-)
diff --git a/drbd/drbd-kernel-compat/cocci/blk_mode_t__no_present.cocci b/drbd/drbd-kernel-compat/cocci/blk_mode_t__no_present.cocci
index d1312a093ffe..cde4430478e5 100644
--- a/drbd/drbd-kernel-compat/cocci/blk_mode_t__no_present.cocci
+++ b/drbd/drbd-kernel-compat/cocci/blk_mode_t__no_present.cocci
@@ -22,12 +22,7 @@ identifier mode;
@@
// special case: bdev_open_by_path takes a blk_mode_t, so convert that too. I can't seem to get
// coccinelle to match the "READ | WRITE" condition generically, so just hard code it.
-// NOTE: we use blkdev_get_by_path instead of bdev_open_by_path in some compat cases, so support that too.
-(
-bdev_open_by_path
-|
-blkdev_get_by_path
-)
+bdev_file_open_by_path
(...,
- BLK_OPEN_READ | BLK_OPEN_WRITE
+ FMODE_READ | FMODE_WRITE
diff --git a/drbd/drbd-kernel-compat/gen_patch_names.c b/drbd/drbd-kernel-compat/gen_patch_names.c
index 13aec5c8bd5f..6f62ea5827b7 100644
--- a/drbd/drbd-kernel-compat/gen_patch_names.c
+++ b/drbd/drbd-kernel-compat/gen_patch_names.c
@@ -568,6 +568,9 @@ int main(int argc, char **argv)
patch(1, "__bio_add_page", true, false,
COMPAT_HAVE___BIO_ADD_PAGE, "present");
+ patch(1, "blk_mode_t", true, false,
+ COMPAT_HAVE_BLK_MODE_T, "present");
+
/* blkdev_put is oldest, then bdev_open_by_path, then bdev_file_open_by_path */
patch(1, "bdev_file_open_by_path", true, false,
COMPAT_HAVE_BDEV_FILE_OPEN_BY_PATH, "present");
@@ -590,9 +593,6 @@ int main(int argc, char **argv)
patch(1, "block_device_operations_release", true, false,
COMPAT_BLOCK_DEVICE_OPERATIONS_RELEASE_TAKES_SINGLE_ARGUMENT, "takes_single_argument");
- patch(1, "blk_mode_t", true, false,
- COMPAT_HAVE_BLK_MODE_T, "present");
-
patch(1, "genl_info_userhdr", true, false,
COMPAT_HAVE_GENL_INFO_USERHDR, "present");
--
2.35.3

View File

@ -1,38 +0,0 @@
From 37edd6c75cccba9b151e8b834c83832ae0382484 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Christoph=20B=C3=B6hmwalder?=
<christoph.boehmwalder@linbit.com>
Date: Thu, 29 Aug 2024 13:27:31 +0200
Subject: [PATCH 19/32] compat: fix blk_queue_update_readahead patch
Did not match anymore
---
.../cocci/blk_queue_update_readahead__no_present.cocci | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/drbd/drbd-kernel-compat/cocci/blk_queue_update_readahead__no_present.cocci b/drbd/drbd-kernel-compat/cocci/blk_queue_update_readahead__no_present.cocci
index ed62a3426ad6..2e78f626261d 100644
--- a/drbd/drbd-kernel-compat/cocci/blk_queue_update_readahead__no_present.cocci
+++ b/drbd/drbd-kernel-compat/cocci/blk_queue_update_readahead__no_present.cocci
@@ -1,8 +1,10 @@
@@
-expression e;
-struct request_queue *q, b;
+identifier q, b;
@@
-blk_stack_limits(e, &b->limits, 0);
+struct request_queue *q;
+...
+struct request_queue *b;
+<...
- blk_queue_update_readahead(q);
+ if (q->backing_dev_info->ra_pages !=
+ b->backing_dev_info->ra_pages) {
@@ -12,3 +14,4 @@ blk_stack_limits(e, &b->limits, 0);
+ q->backing_dev_info->ra_pages =
+ b->backing_dev_info->ra_pages;
+ }
+...>
\ No newline at end of file
--
2.35.3

View File

@ -1,57 +0,0 @@
From f2a779276e7b0918c8592da8254a044c291f1778 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Christoph=20B=C3=B6hmwalder?=
<christoph.boehmwalder@linbit.com>
Date: Thu, 29 Aug 2024 16:15:27 +0200
Subject: [PATCH 20/32] compat: test and patch for
que_limits->max_hw_discard_sectors
---
.../queue_limits__no_has_max_hw_discard_sectors.cocci | 5 +++++
drbd/drbd-kernel-compat/gen_patch_names.c | 3 +++
.../tests/queue_limits_has_max_hw_discard_sectors.c | 8 ++++++++
3 files changed, 16 insertions(+)
create mode 100644 drbd/drbd-kernel-compat/cocci/queue_limits__no_has_max_hw_discard_sectors.cocci
create mode 100644 drbd/drbd-kernel-compat/tests/queue_limits_has_max_hw_discard_sectors.c
diff --git a/drbd/drbd-kernel-compat/cocci/queue_limits__no_has_max_hw_discard_sectors.cocci b/drbd/drbd-kernel-compat/cocci/queue_limits__no_has_max_hw_discard_sectors.cocci
new file mode 100644
index 000000000000..bf96b80a003d
--- /dev/null
+++ b/drbd/drbd-kernel-compat/cocci/queue_limits__no_has_max_hw_discard_sectors.cocci
@@ -0,0 +1,5 @@
+@@
+struct queue_limits lim;
+@@
+- lim.max_hw_discard_sectors
++ lim.max_discard_sectors
diff --git a/drbd/drbd-kernel-compat/gen_patch_names.c b/drbd/drbd-kernel-compat/gen_patch_names.c
index 6f62ea5827b7..5abc32725daf 100644
--- a/drbd/drbd-kernel-compat/gen_patch_names.c
+++ b/drbd/drbd-kernel-compat/gen_patch_names.c
@@ -296,6 +296,9 @@ int main(int argc, char **argv)
patch(1, "write_zeroes", true, false,
COMPAT_HAVE_REQ_OP_WRITE_ZEROES, "capable");
+ patch(1, "queue_limits", true, false,
+ COMPAT_QUEUE_LIMITS_HAS_MAX_HW_DISCARD_SECTORS, "has_max_hw_discard_sectors");
+
patch(1, "bio_bi_opf", true, false,
COMPAT_HAVE_BIO_BI_OPF, "present");
diff --git a/drbd/drbd-kernel-compat/tests/queue_limits_has_max_hw_discard_sectors.c b/drbd/drbd-kernel-compat/tests/queue_limits_has_max_hw_discard_sectors.c
new file mode 100644
index 000000000000..5dcf9c48667b
--- /dev/null
+++ b/drbd/drbd-kernel-compat/tests/queue_limits_has_max_hw_discard_sectors.c
@@ -0,0 +1,8 @@
+/* { "version": "v6.9-rc1", "commit": "4f563a64732dabb2677c7d1232a8f714a18b41b3", "comment": "lim.max_hw_discard_sectors was added", "author": "Christoph Hellwig <hch@lst.de>", "date": "Tue Feb 13 08:34:16 2024 +0100" } */
+
+#include <linux/blkdev.h>
+
+int foo(struct queue_limits *lim)
+{
+ return lim->max_hw_discard_sectors;
+}
--
2.35.3

View File

@ -1,26 +0,0 @@
From 4578726d3b0e5b7c699659c1ecd26194060e7be7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Christoph=20B=C3=B6hmwalder?=
<christoph.boehmwalder@linbit.com>
Date: Thu, 29 Aug 2024 16:15:47 +0200
Subject: [PATCH 21/32] compat: fixup write_zeroes__no_capable
We now access the field directly instead of using this helper
---
drbd/drbd-kernel-compat/cocci/write_zeroes__no_capable.cocci | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drbd/drbd-kernel-compat/cocci/write_zeroes__no_capable.cocci b/drbd/drbd-kernel-compat/cocci/write_zeroes__no_capable.cocci
index 4fa6d9e249d7..2b060e2abd16 100644
--- a/drbd/drbd-kernel-compat/cocci/write_zeroes__no_capable.cocci
+++ b/drbd/drbd-kernel-compat/cocci/write_zeroes__no_capable.cocci
@@ -30,5 +30,6 @@ expression e;
+WARN_ON_ONCE(e); /* WRITE_ZEROES not supported on this kernel */
@@
+struct queue_limits lim;
@@
-- blk_queue_max_write_zeroes_sectors(...);
+- lim.max_write_zeroes_sectors = ...;
--
2.35.3

View File

@ -1,77 +0,0 @@
From ce06250eb289e98bf97940104c92751282704783 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Christoph=20B=C3=B6hmwalder?=
<christoph.boehmwalder@linbit.com>
Date: Wed, 4 Sep 2024 19:05:06 +0200
Subject: [PATCH 22/32] compat: fixup queue_flag_discard__yes_present
blk_queue_discard_granularity does not exist anymore, just use the field
in queue_limits.
Match directly do drbd_reconsider_queue_parameters instead of trying to
guess the right function.
---
.../queue_flag_discard__yes_present.cocci | 30 ++++++-------------
1 file changed, 9 insertions(+), 21 deletions(-)
diff --git a/drbd/drbd-kernel-compat/cocci/queue_flag_discard__yes_present.cocci b/drbd/drbd-kernel-compat/cocci/queue_flag_discard__yes_present.cocci
index cc28c3d02d82..e0ecc697b10a 100644
--- a/drbd/drbd-kernel-compat/cocci/queue_flag_discard__yes_present.cocci
+++ b/drbd/drbd-kernel-compat/cocci/queue_flag_discard__yes_present.cocci
@@ -1,27 +1,19 @@
@@
-struct request_queue *q;
-@@
-(
-q->limits.max_discard_sectors = 0;
-+ blk_queue_flag_clear(QUEUE_FLAG_DISCARD, q);
-|
-q->limits.max_discard_sectors = ...;
-+ blk_queue_flag_set(QUEUE_FLAG_DISCARD, q);
-)
-
-@@
-struct request_queue *q;
+struct queue_limits lim;
+identifier q;
@@
+struct request_queue *q = device->rq_queue;
+...
(
-blk_queue_discard_granularity(q, 0);
+lim.max_hw_discard_sectors = 0;
+ blk_queue_flag_clear(QUEUE_FLAG_DISCARD, q);
|
-blk_queue_discard_granularity(q, 512);
+lim.max_hw_discard_sectors = ...;
+ blk_queue_flag_set(QUEUE_FLAG_DISCARD, q);
)
@@
-identifier q, device, fn;
+identifier q, device;
@@
+static void fixup_discard_if_not_supported(struct request_queue *q)
+{
@@ -31,18 +23,14 @@ identifier q, device, fn;
+ * */
+ if (!blk_queue_discard(q)) {
+ blk_queue_max_discard_sectors(q, 0);
-+ blk_queue_discard_granularity(q, 0);
++ q->limits.discard_granularity = 0;
+ }
+}
-fn (struct drbd_device *device, ...)
+void drbd_reconsider_queue_parameters(struct drbd_device *device, ...)
{
...
struct request_queue *q = device->rq_queue;
...
-decide_on_discard_support(...);
-<+...
-blk_stack_limits(...);
-...+>
+ fixup_discard_if_not_supported(q);
}
--
2.35.3

View File

@ -1,53 +0,0 @@
From ac4e2f85066d2da306ec0e3fed8db4e945be6f6d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Christoph=20B=C3=B6hmwalder?=
<christoph.boehmwalder@linbit.com>
Date: Thu, 5 Sep 2024 13:03:07 +0200
Subject: [PATCH 23/32] drbd: move flags to queue_limits
Roughly equivalent to the following commits from upstream Linux:
1122c0c1 block: move cache control settings out of queue->flags
bd4a633b block: move the nonrot flag to queue_limits
1a02f3a7 block: move the stable_writes flag to queue_limits
---
drbd/drbd_main.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/drbd/drbd_main.c b/drbd/drbd_main.c
index 2792b9896271..407b0a1d1773 100644
--- a/drbd/drbd_main.c
+++ b/drbd/drbd_main.c
@@ -3886,6 +3886,11 @@ enum drbd_ret_code drbd_create_device(struct drbd_config_context *adm_ctx, unsig
int vnr = adm_ctx->volume;
enum drbd_ret_code err = ERR_NOMEM;
bool locked = false;
+ struct queue_limits lim = {
+ .features = BLK_FEAT_WRITE_CACHE | BLK_FEAT_FUA |
+ BLK_FEAT_ROTATIONAL |
+ BLK_FEAT_STABLE_WRITES,
+ };
lockdep_assert_held(&resource->conf_update);
@@ -3948,7 +3953,7 @@ enum drbd_ret_code drbd_create_device(struct drbd_config_context *adm_ctx, unsig
init_rwsem(&device->uuid_sem);
- disk = blk_alloc_disk(NULL, NUMA_NO_NODE);
+ disk = blk_alloc_disk(&lim, NUMA_NO_NODE);
if (IS_ERR(disk)) {
err = PTR_ERR(disk);
goto out_no_disk;
@@ -3967,9 +3972,6 @@ enum drbd_ret_code drbd_create_device(struct drbd_config_context *adm_ctx, unsig
sprintf(disk->disk_name, "drbd%d", minor);
disk->private_data = device;
- blk_queue_flag_set(QUEUE_FLAG_STABLE_WRITES, disk->queue);
- blk_queue_write_cache(disk->queue, true, true);
-
device->md_io.page = alloc_page(GFP_KERNEL);
if (!device->md_io.page)
goto out_no_io_page;
--
2.35.3

View File

@ -1,191 +0,0 @@
From 3c18af1a3e8d67833e3ea8a2d38408501c9ee6be Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Christoph=20B=C3=B6hmwalder?=
<christoph.boehmwalder@linbit.com>
Date: Thu, 5 Sep 2024 13:05:59 +0200
Subject: [PATCH 24/32] compat: test and patch for queue_limits.features
And fixup compat patches that rely on blk_queue_write_cache being there.
Match to disk->private_data = ... instead.
---
.../blk_queue_make_request__yes_present.cocci | 3 ++-
.../blk_queue_merge_bvec__yes_present.cocci | 21 +++++++++++-----
.../cocci/congested_fn__yes_present.cocci | 3 ++-
.../queue_limits_features__no_present.cocci | 25 +++++++++++++++++++
drbd/drbd-kernel-compat/gen_patch_names.c | 15 ++++++-----
.../tests/queue_limits_has_features.c | 8 ++++++
6 files changed, 61 insertions(+), 14 deletions(-)
create mode 100644 drbd/drbd-kernel-compat/cocci/queue_limits_features__no_present.cocci
create mode 100644 drbd/drbd-kernel-compat/tests/queue_limits_has_features.c
diff --git a/drbd/drbd-kernel-compat/cocci/blk_queue_make_request__yes_present.cocci b/drbd/drbd-kernel-compat/cocci/blk_queue_make_request__yes_present.cocci
index 63c65d21cb32..665e10cbaa1a 100644
--- a/drbd/drbd-kernel-compat/cocci/blk_queue_make_request__yes_present.cocci
+++ b/drbd/drbd-kernel-compat/cocci/blk_queue_make_request__yes_present.cocci
@@ -5,12 +5,13 @@ identifier make_request_fn;
+ blk_alloc_queue(GFP_KERNEL)
@@
+struct gendisk *disk;
identifier rm_blk_alloc_queue.make_request_fn;
@@
drbd_create_device(...)
{
...
+ disk->private_data = ...;
+ blk_queue_make_request(q, make_request_fn);
- blk_queue_write_cache(...);
...
}
diff --git a/drbd/drbd-kernel-compat/cocci/blk_queue_merge_bvec__yes_present.cocci b/drbd/drbd-kernel-compat/cocci/blk_queue_merge_bvec__yes_present.cocci
index d4c0d85810e8..bedb09f8b375 100644
--- a/drbd/drbd-kernel-compat/cocci/blk_queue_merge_bvec__yes_present.cocci
+++ b/drbd/drbd-kernel-compat/cocci/blk_queue_merge_bvec__yes_present.cocci
@@ -1,10 +1,10 @@
-@@
+@ add_drbd_merge_bvec_definition @
identifier ws;
@@
+extern int drbd_merge_bvec(struct request_queue *, struct bvec_merge_data *, struct bio_vec *);
extern void do_submit(struct work_struct *ws);
-@@
+@ add_drbd_merge_bvec @
@@
+/* This is called by bio_add_page().
+ *
@@ -44,9 +44,10 @@ extern void do_submit(struct work_struct *ws);
do_submit(...)
{ ... }
-@@
+@ add_blk_queue_merge_bvec @
symbol true;
identifier q, resource, dev;
+struct gendisk *disk;
@@
drbd_create_device(...)
{
@@ -68,9 +69,17 @@ struct request_queue *q;
// also want to store it in queuedata for the compat.
dev->rq_queue = q;
+ q->queuedata = dev;
-<...
-blk_queue_write_cache(q, true, true);
+...
+disk->private_data = ...;
+ blk_queue_merge_bvec(q, drbd_merge_bvec);
-...>
+...
}
+@ script:python depends on !(add_drbd_merge_bvec_definition && add_drbd_merge_bvec && add_blk_queue_merge_bvec) @
+@@
+import sys
+print('ERROR: A rule making an essential change was not executed! (blk_queue_merge_bvec)', file=sys.stderr)
+print('ERROR: This would not show up as a compiler error, but would still break DRBD.', file=sys.stderr)
+print('ERROR: As a precaution, the build will be aborted here.', file=sys.stderr)
+sys.exit(1)
+
diff --git a/drbd/drbd-kernel-compat/cocci/congested_fn__yes_present.cocci b/drbd/drbd-kernel-compat/cocci/congested_fn__yes_present.cocci
index d0b55c3dffbf..a697311af6bd 100644
--- a/drbd/drbd-kernel-compat/cocci/congested_fn__yes_present.cocci
+++ b/drbd/drbd-kernel-compat/cocci/congested_fn__yes_present.cocci
@@ -63,14 +63,15 @@ drbd_cleanup(...)
@@
identifier dev;
+struct gendisk *disk;
@@
drbd_create_device(...)
{
...
struct drbd_device *dev;
...
+ disk->private_data = ...;
+ q->backing_dev_info->congested_fn = drbd_congested;
+ q->backing_dev_info->congested_data = dev;
- blk_queue_write_cache(...);
...
}
diff --git a/drbd/drbd-kernel-compat/cocci/queue_limits_features__no_present.cocci b/drbd/drbd-kernel-compat/cocci/queue_limits_features__no_present.cocci
new file mode 100644
index 000000000000..b9017351302b
--- /dev/null
+++ b/drbd/drbd-kernel-compat/cocci/queue_limits_features__no_present.cocci
@@ -0,0 +1,25 @@
+// NOTE this actually encompasses three patches:
+// 1122c0c1 block: move cache control settings out of queue->flags
+// bd4a633b block: move the nonrot flag to queue_limits
+// 1a02f3a7 block: move the stable_writes flag to queue_limits
+//
+// They add "BLK_FEAT_WRITE_CACHE | BLK_FEAT_FUA", "BLK_FEAT_ROTATIONAL", and
+// "BLK_FEAT_STABLE_WRITES", respectively.
+// Since these commits are all from the same series, just patch them together.
+@@
+expression e;
+struct gendisk *disk;
+identifier lim;
+@@
+-struct queue_limits lim = {
+- .features = e,
+-};
+...
+blk_alloc_disk(
+- &lim
++ NULL
+ , ...)
+...
+disk->private_data = ...;
++ blk_queue_flag_set(QUEUE_FLAG_STABLE_WRITES, disk->queue);
++ blk_queue_write_cache(disk->queue, true, true);
diff --git a/drbd/drbd-kernel-compat/gen_patch_names.c b/drbd/drbd-kernel-compat/gen_patch_names.c
index 5abc32725daf..cc3bad2d84e4 100644
--- a/drbd/drbd-kernel-compat/gen_patch_names.c
+++ b/drbd/drbd-kernel-compat/gen_patch_names.c
@@ -153,6 +153,9 @@ int main(int argc, char **argv)
patch(1, "blk_cleanup_disk", false, true,
COMPAT_HAVE_BLK_CLEANUP_DISK, "present");
+ patch(1, "queue_limits_features", true, false,
+ COMPAT_QUEUE_LIMITS_HAS_FEATURES, "present");
+
patch(1, "blk_alloc_disk", true, false,
COMPAT_BLK_ALLOC_DISK_TAKES_QUEUE_LIMITS, "takes_queue_limits");
#if !defined(COMPAT_BLK_ALLOC_DISK_TAKES_QUEUE_LIMITS)
@@ -267,13 +270,13 @@ int main(int argc, char **argv)
patch(1, "security_netlink_recv", false, true,
COMPAT_HAVE_SECURITY_NETLINK_RECV, "present");
-#if defined(COMPAT_HAVE_QUEUE_FLAG_STABLE_WRITES)
- /* in versions >=5.9, there is QUEUE_FLAG_STABLE_WRITES */
-#else
- /* for <5.9 but >=3.9, fall back to BDI_CAP_STABLE_WRITES */
+ /*
+ * >= 6.10: BLK_FEAT_STABLE_WRITES
+ * 5.9-6.10: QUEUE_FLAG_STABLE_WRITES
+ * <5.9: BDI_CAP_STABLE_WRITES
+ */
patch(1, "queue_flag_stable_writes", true, false,
- NO, "present");
-#endif
+ COMPAT_HAVE_QUEUE_FLAG_STABLE_WRITES, "present");
patch(1, "queue_flag_discard", false, true,
COMPAT_HAVE_QUEUE_FLAG_DISCARD, "present");
diff --git a/drbd/drbd-kernel-compat/tests/queue_limits_has_features.c b/drbd/drbd-kernel-compat/tests/queue_limits_has_features.c
new file mode 100644
index 000000000000..e566a34bdda6
--- /dev/null
+++ b/drbd/drbd-kernel-compat/tests/queue_limits_has_features.c
@@ -0,0 +1,8 @@
+/* { "version": "v6.10", "commit": "1122c0c1cc71f740fa4d5f14f239194e06a1d5e7", "comment": "features field was introduced", "author": "Christoph Hellwig <hch@lst.de>", "date": "Mon Jun 17 08:04:40 2024 +0200" } */
+
+#include <linux/blkdev.h>
+
+unsigned int foo(struct queue_limits lim)
+{
+ return lim.features;
+}
--
2.35.3

View File

@ -1,47 +0,0 @@
From 85afbf893a6c7cd55e04407731e52d495b6f228f Mon Sep 17 00:00:00 2001
From: Kees Cook <keescook@chromium.org>
Date: Fri, 15 Sep 2023 13:03:16 -0700
Subject: [PATCH 25/32] drbd: Annotate struct fifo_buffer with __counted_by
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Prepare for the coming implementation by GCC and Clang of the __counted_by
attribute. Flexible array members annotated with __counted_by can have
their accesses bounds-checked at run-time checking via CONFIG_UBSAN_BOUNDS
(for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
functions).
As found with Coccinelle[1], add __counted_by for struct fifo_buffer.
[1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci
Cc: Philipp Reisner <philipp.reisner@linbit.com>
Cc: Lars Ellenberg <lars.ellenberg@linbit.com>
Cc: Christoph Böhmwalder <christoph.boehmwalder@linbit.com>
Cc: Jens Axboe <axboe@kernel.dk>
Cc: drbd-dev@lists.linbit.com
Cc: linux-block@vger.kernel.org
Reviewed-by: "Gustavo A. R. Silva" <gustavoars@kernel.org>
Link: https://lore.kernel.org/r/20230915200316.never.707-kees@kernel.org
Signed-off-by: Kees Cook <keescook@chromium.org>
---
drbd/drbd_int.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drbd/drbd_int.h b/drbd/drbd_int.h
index c18407899f59..182593257c6a 100644
--- a/drbd/drbd_int.h
+++ b/drbd/drbd_int.h
@@ -746,7 +746,7 @@ struct fifo_buffer {
unsigned int head_index;
unsigned int size;
int total; /* sum of all values */
- int values[];
+ int values[] __counted_by(size);
};
extern struct fifo_buffer *fifo_alloc(unsigned int fifo_size);
--
2.35.3

View File

@ -1,94 +0,0 @@
From 3a1d6d3e2bd0e1506995e316b183cef8abc0034b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Christoph=20B=C3=B6hmwalder?=
<christoph.boehmwalder@linbit.com>
Date: Fri, 6 Sep 2024 11:14:43 +0200
Subject: [PATCH 26/32] compat: test and patch for __counted_by
Unfortunately, the "attribute name" variable type only works with very
recent coccinelle versions (>=1.1.1). So add a hint about that in the
README.
---
README.md | 9 ++++-----
.../cocci/counted_by__no_present.cocci | 12 ++++++++++++
drbd/drbd-kernel-compat/gen_patch_names.c | 3 +++
drbd/drbd-kernel-compat/tests/have_counted_by.c | 8 ++++++++
4 files changed, 27 insertions(+), 5 deletions(-)
create mode 100644 drbd/drbd-kernel-compat/cocci/counted_by__no_present.cocci
create mode 100644 drbd/drbd-kernel-compat/tests/have_counted_by.c
diff --git a/README.md b/README.md
index ec513d19438e..b63286db0113 100644
--- a/README.md
+++ b/README.md
@@ -38,7 +38,7 @@ Since version 9.0.20, DRBD has been using a kernel backwards compatibility syste
based on [Coccinelle](https://github.com/coccinelle/coccinelle) semantic patches.
While this has many advantages, it also makes it a little harder for "casual"
developers to build DRBD from the git sources. The problem is that we require a
-very recent version of `spatch` (at least 1.0.8 at time of writing), and most
+very recent version of `spatch` (at least 1.1.1 at time of writing), and most
distributions only have relatively old versions in their repositories.
## From git
@@ -48,10 +48,9 @@ For users wishing to build DRBD from its git sources, here are a few options:
chances are you won't even have to use any of the compat features, which
means you won't require compatibility patches and in turn don't need spatch
installed.
-2. On Ubuntu 18.04 and newer, use a recent spatch version from the
- [Coccinelle PPA](https://launchpad.net/~npalix/+archive/ubuntu/coccinelle).
- This provides (at time of writing) version 1.0.8, which is recent enough to
- build DRBD.
+2. Fedora >=39 packages Coccinelle 1.1.1, which is recent enough to build DRBD. **Warning**: while
+ Ubuntu also ships Coccinelle with supposedly the same version number (1.1.1), this version
+ is *not* able to build DRBD.
3. Build and install spatch from source. This will also give you a version that
is recent enough to build DRBD.
diff --git a/drbd/drbd-kernel-compat/cocci/counted_by__no_present.cocci b/drbd/drbd-kernel-compat/cocci/counted_by__no_present.cocci
new file mode 100644
index 000000000000..40db31bece0c
--- /dev/null
+++ b/drbd/drbd-kernel-compat/cocci/counted_by__no_present.cocci
@@ -0,0 +1,12 @@
+@@
+type T;
+identifier s, x;
+attribute name __counted_by;
+@@
+struct s {
+...
+ T x
+- __counted_by(...)
+ ;
+...
+};
diff --git a/drbd/drbd-kernel-compat/gen_patch_names.c b/drbd/drbd-kernel-compat/gen_patch_names.c
index cc3bad2d84e4..72c1e25512ea 100644
--- a/drbd/drbd-kernel-compat/gen_patch_names.c
+++ b/drbd/drbd-kernel-compat/gen_patch_names.c
@@ -605,6 +605,9 @@ int main(int argc, char **argv)
patch(1, "need_recalc_sigpending", false, true,
COMPAT_NEED_RECALC_SIGPENDING, "need");
+ patch(1, "counted_by", true, false,
+ COMPAT_HAVE_COUNTED_BY, "present");
+
/* #define BLKDEV_ISSUE_ZEROOUT_EXPORTED */
/* #define BLKDEV_ZERO_NOUNMAP */
diff --git a/drbd/drbd-kernel-compat/tests/have_counted_by.c b/drbd/drbd-kernel-compat/tests/have_counted_by.c
new file mode 100644
index 000000000000..07fac32aad16
--- /dev/null
+++ b/drbd/drbd-kernel-compat/tests/have_counted_by.c
@@ -0,0 +1,8 @@
+/* { "version": "v6.4", "commit": "dd06e72e68bcb4070ef211be100d2896e236c8fb", "comment": "add __counted_by macro", "author": "Kees Cook <keescook@chromium.org>", "date": "Wed May 17 12:08:44 2023 -0700" } */
+
+#include <linux/compiler_attributes.h>
+
+struct foo {
+ int a;
+ int b[] __counted_by(a);
+};
--
2.35.3

View File

@ -1,100 +0,0 @@
From fa5329fb2c7e089cbe712acecb2c75ba8887754e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Christoph=20B=C3=B6hmwalder?=
<christoph.boehmwalder@linbit.com>
Date: Fri, 6 Sep 2024 15:16:49 +0200
Subject: [PATCH 27/32] drbd: fix function cast warnings in state machine
Equivalent to upstream commit fe0b1e9a ("drbd: fix function cast
warnings in state machine").
---
drbd/drbd_state.c | 16 ++++++++++------
drbd/drbd_state_change.h | 8 ++++----
2 files changed, 14 insertions(+), 10 deletions(-)
diff --git a/drbd/drbd_state.c b/drbd/drbd_state.c
index 44f55ee5c939..100e32ba037f 100644
--- a/drbd/drbd_state.c
+++ b/drbd/drbd_state.c
@@ -3212,10 +3212,11 @@ static union drbd_state state_change_word(struct drbd_state_change *state_change
int notify_resource_state_change(struct sk_buff *skb,
unsigned int seq,
- struct drbd_state_change *state_change,
+ void *state_change,
enum drbd_notification_type type)
{
- struct drbd_resource_state_change *resource_state_change = state_change->resource;
+ struct drbd_resource_state_change *resource_state_change =
+ ((struct drbd_state_change *)state_change)->resource;
struct drbd_resource *resource = resource_state_change->resource;
struct resource_info resource_info = {
.res_role = resource_state_change->role[NEW],
@@ -3232,9 +3233,10 @@ int notify_resource_state_change(struct sk_buff *skb,
int notify_connection_state_change(struct sk_buff *skb,
unsigned int seq,
- struct drbd_connection_state_change *connection_state_change,
+ void *state_change,
enum drbd_notification_type type)
{
+ struct drbd_connection_state_change *connection_state_change = state_change;
struct drbd_connection *connection = connection_state_change->connection;
struct connection_info connection_info = {
.conn_connection_state = connection_state_change->cstate[NEW],
@@ -3246,9 +3248,10 @@ int notify_connection_state_change(struct sk_buff *skb,
int notify_device_state_change(struct sk_buff *skb,
unsigned int seq,
- struct drbd_device_state_change *device_state_change,
+ void *state_change,
enum drbd_notification_type type)
{
+ struct drbd_device_state_change *device_state_change = state_change;
struct drbd_device *device = device_state_change->device;
struct device_info device_info;
device_state_change_to_info(&device_info, device_state_change);
@@ -3258,10 +3261,11 @@ int notify_device_state_change(struct sk_buff *skb,
int notify_peer_device_state_change(struct sk_buff *skb,
unsigned int seq,
- struct drbd_peer_device_state_change *state_change,
+ void *state_change,
enum drbd_notification_type type)
{
- struct drbd_peer_device *peer_device = state_change->peer_device;
+ struct drbd_peer_device_state_change *peer_device_state_change = state_change;
+ struct drbd_peer_device *peer_device = peer_device_state_change->peer_device;
struct peer_device_info peer_device_info;
peer_device_state_change_to_info(&peer_device_info, state_change);
diff --git a/drbd/drbd_state_change.h b/drbd/drbd_state_change.h
index 3dc8616dedd4..40687d40b222 100644
--- a/drbd/drbd_state_change.h
+++ b/drbd/drbd_state_change.h
@@ -69,19 +69,19 @@ extern void forget_state_change(struct drbd_state_change *);
extern int notify_resource_state_change(struct sk_buff *,
unsigned int,
- struct drbd_state_change *,
+ void *,
enum drbd_notification_type type);
extern int notify_connection_state_change(struct sk_buff *,
unsigned int,
- struct drbd_connection_state_change *,
+ void *,
enum drbd_notification_type type);
extern int notify_device_state_change(struct sk_buff *,
unsigned int,
- struct drbd_device_state_change *,
+ void *,
enum drbd_notification_type type);
extern int notify_peer_device_state_change(struct sk_buff *,
unsigned int,
- struct drbd_peer_device_state_change *,
+ void *,
enum drbd_notification_type type);
#endif /* DRBD_STATE_CHANGE_H */
--
2.35.3

View File

@ -1,61 +0,0 @@
From 11e96ecc0575eb0d6d4e29caaffb70d1e299908d Mon Sep 17 00:00:00 2001
From: Simon Horman <horms@kernel.org>
Date: Tue, 23 Jul 2024 10:41:52 +0100
Subject: [PATCH 28/32] Add missing documentation of peer_device parameter to
Kernel doc.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
These parameters were added in commit 8164dd6c8ae1 ("drbd: Add peer
device parameter to whole-bitmap I/O handlers")
Flagged by W=1 builds.
Signed-off-by: Simon Horman <horms@kernel.org>
Link: https://lore.kernel.org/r/20240723-drbd-doc-v1-1-a04d9b7a9688@kernel.org
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Christoph Böhmwalder <christoph.boehmwalder@linbit.com>
---
drbd/drbd_main.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/drbd/drbd_main.c b/drbd/drbd_main.c
index 407b0a1d1773..a216b725e66c 100644
--- a/drbd/drbd_main.c
+++ b/drbd/drbd_main.c
@@ -5356,6 +5356,7 @@ int drbd_bmio_set_all_n_write(struct drbd_device *device,
/**
* drbd_bmio_set_n_write() - io_fn for drbd_queue_bitmap_io() or drbd_bitmap_io()
* @device: DRBD device.
+ * @peer_device: Peer DRBD device.
*
* Sets all bits in the bitmap towards one peer and writes the whole bitmap to stable storage.
*/
@@ -5408,6 +5409,7 @@ int drbd_bmio_set_allocated_n_write(struct drbd_device *device,
/**
* drbd_bmio_clear_all_n_write() - io_fn for drbd_queue_bitmap_io() or drbd_bitmap_io()
* @device: DRBD device.
+ * @peer_device: Peer DRBD device.
*
* Clears all bits in the bitmap and writes the whole bitmap to stable storage.
*/
@@ -5474,6 +5476,7 @@ void drbd_queue_pending_bitmap_work(struct drbd_device *device)
* @io_fn: IO callback to be called when bitmap IO is possible
* @done: callback to be called after the bitmap IO was performed
* @why: Descriptive text of the reason for doing the IO
+ * @peer_device: Peer DRBD device.
*
* While IO on the bitmap happens we freeze application IO thus we ensure
* that drbd_set_out_of_sync() can not be called. This function MAY ONLY be
@@ -5549,6 +5552,7 @@ void drbd_queue_bitmap_io(struct drbd_device *device,
* @device: DRBD device.
* @io_fn: IO callback to be called when bitmap IO is possible
* @why: Descriptive text of the reason for doing the IO
+ * @peer_device: Peer DRBD device.
*
* freezes application IO while that the actual IO operations runs. This
* functions MAY NOT be called from sender context.
--
2.35.3

View File

@ -1,42 +0,0 @@
From 9fe2be655a793d2f9425b96e53a7e1e7feec067e Mon Sep 17 00:00:00 2001
From: Joel Colledge <joel.colledge@linbit.com>
Date: Wed, 18 Sep 2024 15:08:55 +0200
Subject: [PATCH 30/32] drbd: kref_put() path when kernel_accept() fails
We need to put the reference that dtt_wait_connect_cond() gets.
This is an unusual situation. The function dtt_wait_connect_cond() only
returns a path when pending_accepts is positive or there is a socket in
the path->sockets list. So if the code reaches the kernel_accept() call,
we expect it to succeed. However, it has been observed to fail, so we
need to handle that case cleanly.
Without the kref_put(), it is impossible to rmmod drbd.
For any error other than -EAGAIN, the error is be passed up and is
logged by conn_connect(). However, when -EAGAIN is returned,
dtt_connect() continues trying to connect and the error from
kernel_accept() leaves no traces in the logs.
---
drbd/drbd_transport_tcp.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drbd/drbd_transport_tcp.c b/drbd/drbd_transport_tcp.c
index df144fcb4522..d59f68d83c58 100644
--- a/drbd/drbd_transport_tcp.c
+++ b/drbd/drbd_transport_tcp.c
@@ -625,8 +625,10 @@ retry:
s_estab = NULL;
err = kernel_accept(listener->s_listen, &s_estab, O_NONBLOCK);
- if (err < 0)
+ if (err < 0) {
+ kref_put(&path->path.kref, drbd_destroy_path);
return err;
+ }
/* The established socket inherits the sk_state_change callback
from the listening socket. */
--
2.35.3

View File

@ -1,29 +0,0 @@
From 903779df9a65ac04814afb1530423914bdfe305c Mon Sep 17 00:00:00 2001
From: Lars Ellenberg <lars.ellenberg@linbit.com>
Date: Sun, 6 Oct 2024 01:14:19 +0200
Subject: [PATCH 31/32] build: fix typo in Makefile.spatch
The variable name should be cached_compat_h, compat_h does not exist.
Noticed when built with `make -j`:
Because of the empty prerequisites, sometimes make would try to build
kernelrelease.txt before the directory was created.
---
drbd/Makefile.spatch | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drbd/Makefile.spatch b/drbd/Makefile.spatch
index bbcf10dc0603..a5cc774c18b5 100644
--- a/drbd/Makefile.spatch
+++ b/drbd/Makefile.spatch
@@ -42,7 +42,7 @@ cached_compat_patch := $(cache_dir)/compat.patch
# Remember which kernel releases this supposedly works for.
# If KERNELRELEASE is not known, will add an empty line (at most once).
-$(cache_dir)/kernelrelease.txt: $(compat_h) FORCE
+$(cache_dir)/kernelrelease.txt: $(cached_compat_h) FORCE
$(Q)set -e; \
grep -sqxFe "$(KERNELRELEASE)" $@ < /dev/null || \
echo $(KERNELRELEASE) >> $@;
--
2.35.3

View File

@ -1,90 +0,0 @@
From 13ada1be201eb14ff8295a17194de8db5cdccd7f Mon Sep 17 00:00:00 2001
From: Lars Ellenberg <lars.ellenberg@linbit.com>
Date: Wed, 2 Oct 2024 14:34:02 +0200
Subject: [PATCH 32/32] drbd: open: do not delay open() if already Primary
Since 48376549f (drbd: When a remote state change is active to not touch the open_counts, 2017-10-30)
if a remote state change is pending when someone tries to open() a DRBD volume,
we wait, interruptible, for "auto-promote-timeout",
until that state change is finalized (committed or aborted),
or give up with EAGAIN if the auto-promote timeout is reached.
auto-promote-timeout by default is much smaller than twopc-timeout,
so we may get spurious open() failures.
This could be mitigated with auto-promote-timeout > twopc-timeout.
But we can just ignore the pending state change,
if changing the open_cnt won't make a difference:
if we are already Primary, or we already have openers anyways.
If
- we have some remote state change pending,
- and we are not Primary already,
- and we do not have any openers, or this is an open with write intent,
we reject NDELAY openers immediately.
Normal openers wait for the state change to be finalized
(or give up after auto-promote-timeout).
We do not need to wait if:
- there is no remote state change pending,
- or we are already Primary anyways,
- or we are Secondary, this is a read-only open, and we have openers already.
Note: we may still want to immediately reject NDELAY open if
there is a remote state change pending, even if we have an
open count != 0. These are typically short lived openers
triggered via udev. If they overlap (new open comes in
before previous close), these may still accumulate enough
time to mess with state changes.
For now, I decide to allow them.
---
drbd/drbd_main.c | 22 ++++++++++++++++++++--
1 file changed, 20 insertions(+), 2 deletions(-)
diff --git a/drbd/drbd_main.c b/drbd/drbd_main.c
index a216b725e66c..258be3b9c10d 100644
--- a/drbd/drbd_main.c
+++ b/drbd/drbd_main.c
@@ -2583,10 +2583,21 @@ enum ioc_rv {
IOC_ABORT = 2,
};
+/* If we are in the middle of a cluster wide state change, we don't want
+ * to change (open_cnt == 0), as that then could cause a failure to commit
+ * some already promised peer auto-promote locally.
+ * So we wait until the pending remote_state_change is finalized,
+ * or give up when the timeout is reached.
+ *
+ * But we don't want to fail an open on a Primary just because it happens
+ * during some unrelated remote state change.
+ * If we are already Primary, or already have an open count != 0,
+ * we don't need to wait, it won't change anything.
+ */
static enum ioc_rv inc_open_count(struct drbd_device *device, blk_mode_t mode)
{
struct drbd_resource *resource = device->resource;
- enum ioc_rv r = mode & BLK_OPEN_NDELAY ? IOC_ABORT : IOC_SLEEP;
+ enum ioc_rv r;
if (test_bit(DOWN_IN_PROGRESS, &resource->flags))
return IOC_ABORT;
@@ -2594,7 +2605,14 @@ static enum ioc_rv inc_open_count(struct drbd_device *device, blk_mode_t mode)
read_lock_irq(&resource->state_rwlock);
if (test_bit(UNREGISTERED, &device->flags))
r = IOC_ABORT;
- else if (!resource->remote_state_change) {
+ else if (resource->remote_state_change &&
+ resource->role[NOW] != R_PRIMARY &&
+ (device->open_cnt == 0 || mode & BLK_OPEN_WRITE)) {
+ if (mode & BLK_OPEN_NDELAY)
+ r = IOC_ABORT;
+ else
+ r = IOC_SLEEP;
+ } else {
r = IOC_OK;
device->open_cnt++;
if (mode & BLK_OPEN_WRITE)
--
2.35.3

View File

@ -1,92 +0,0 @@
Oct 11, 2024. by heming.zhao@suse.com
This patch includes the following 4 changes for passing the build on v6.11.0.
-------------
for 'queue_flag_stable_writes__no_present', modifying
drbd-kernel-compat/cocci/queue_flag_stable_writes__no_present.cocci
upstream kernel:
commit 1a02f3a73f8c670eddeb44bf52a75ae7f67cfc11
Author: Christoph Hellwig <hch@lst.de>
Date: Mon Jun 17 08:04:44 2024 +0200
block: move the stable_writes flag to queue_limits
-------------
for 'disk_update_readahead__no_present', modifying
drbd-kernel-compat/cocci/disk_update_readahead__no_present.cocci
upstream kernel:
commit 73781b3b81e76583708a652c853d54d03dce031d
Author: Christoph Hellwig <hch@lst.de>
Date: Wed Jun 26 16:26:27 2024 +0200
block: remove disk_update_readahead
--------------
for 'blk_queue_update_readahead__no_present', modifying
'drbd-kernel-compat/gen_patch_names.c', which bypasses the
testing of COMPAT_HAVE_BLK_QUEUE_UPDATE_READAHEAD.
---------------
for 'blk_queue_write_cache__no_present__yes_flush', modifying
drbd-kernel-compat/tests/have_blk_queue_write_cache.c
upstream kernel:
commit 62e35f942231e372f8e465d8484de66a60221226
Author: Christoph Hellwig <hch@lst.de>
Date: Thu Jun 27 13:14:03 2024 +0200
block: pass a gendisk to the queue_sysfs_entry methods
---------------
diff -Nupr a/drbd/drbd-kernel-compat/cocci/disk_update_readahead__no_present.cocci b/drbd/drbd-kernel-compat/cocci/disk_update_readahead__no_present.cocci
--- a/drbd/drbd-kernel-compat/cocci/disk_update_readahead__no_present.cocci 2024-10-11 09:23:43.340688884 +0800
+++ b/drbd/drbd-kernel-compat/cocci/disk_update_readahead__no_present.cocci 2024-10-11 09:27:53.755206413 +0800
@@ -6,5 +6,5 @@ type T;
T q = dev->rq_queue;
<...
- disk_update_readahead(dev->vdisk);
-+ blk_queue_update_readahead(q);
++ blk_apply_bdi_limits(dev->vdisk->bdi, &dev->vdisk->queue->limits);
...>
diff -Nupr a/drbd/drbd-kernel-compat/cocci/queue_flag_stable_writes__no_present.cocci b/drbd/drbd-kernel-compat/cocci/queue_flag_stable_writes__no_present.cocci
--- a/drbd/drbd-kernel-compat/cocci/queue_flag_stable_writes__no_present.cocci 2024-10-11 09:23:25.420604140 +0800
+++ b/drbd/drbd-kernel-compat/cocci/queue_flag_stable_writes__no_present.cocci 2024-10-11 09:28:33.265393250 +0800
@@ -2,4 +2,4 @@
expression q;
@@
- blk_queue_flag_set(QUEUE_FLAG_STABLE_WRITES, q);
-+ q->backing_dev_info->capabilities |= BDI_CAP_STABLE_WRITES;
++ q->limits.features |= BLK_FEAT_STABLE_WRITES;
diff -Nupr a/drbd/drbd-kernel-compat/gen_patch_names.c b/drbd/drbd-kernel-compat/gen_patch_names.c
--- a/drbd/drbd-kernel-compat/gen_patch_names.c 2024-10-11 09:24:54.021023132 +0800
+++ b/drbd/drbd-kernel-compat/gen_patch_names.c 2024-10-11 09:26:48.508231197 +0800
@@ -405,6 +405,7 @@ int main(int argc, char **argv)
patch(1, "disk_update_readahead", true, false,
COMPAT_HAVE_DISK_UPDATE_READAHEAD, "present");
+#if 0
#if !defined(COMPAT_HAVE_DISK_UPDATE_READAHEAD)
/* disk_update_readahead is the "new version" of
* blk_queue_update_readahead. we only need to consider compat
@@ -412,6 +413,7 @@ int main(int argc, char **argv)
patch(1, "blk_queue_update_readahead", true, false,
COMPAT_HAVE_BLK_QUEUE_UPDATE_READAHEAD, "present");
#endif
+#endif
patch(1, "struct_gendisk", true, false,
COMPAT_STRUCT_GENDISK_HAS_BACKING_DEV_INFO, "has_backing_dev_info");
diff -Nupr a/drbd/drbd-kernel-compat/tests/have_blk_queue_write_cache.c b/drbd/drbd-kernel-compat/tests/have_blk_queue_write_cache.c
--- a/drbd/drbd-kernel-compat/tests/have_blk_queue_write_cache.c 2024-10-11 09:25:57.557990258 +0800
+++ b/drbd/drbd-kernel-compat/tests/have_blk_queue_write_cache.c 2024-10-11 09:27:17.571701979 +0800
@@ -2,5 +2,5 @@
void dummy(struct request_queue *q, bool enabled, bool fua)
{
- blk_queue_write_cache(q, enabled, fua);
+ blk_queue_write_cache(q);
}

View File

@ -1,37 +0,0 @@
From 80673af5c0cebaeedc1260248466cfd8b268aa0c Mon Sep 17 00:00:00 2001
From: Su Yue <glass.su@suse.com>
Date: Tue, 12 Nov 2024 10:14:17 +0800
Subject: [PATCH] boo1233222_fix_drbd_build_error_against_kernel_v6.11.6
This patch fixes build error due to kernel ABI change introduced
in v6.11.6 by
commit 56440d7ec28d60f8da3bfa09062b3368ff9b16db
Author: Eric Dumazet <edumazet@google.com>
Date: Fri Oct 11 17:12:17 2024 +0000
genetlink: hold RCU in genlmsg_mcast()
After the commit, genlmsg_multicast_allns is called without parameter flags.
Signed-off-by: Su Yue <glass.su@suse.com>
---
.../genl_magic_func-genl_register_family_with_ops_groups.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drbd/drbd-headers/linux/genl_magic_func-genl_register_family_with_ops_groups.h b/drbd/drbd-headers/linux/genl_magic_func-genl_register_family_with_ops_groups.h
index b7adc480247e..733cbc788f7f 100644
--- a/drbd/drbd-headers/linux/genl_magic_func-genl_register_family_with_ops_groups.h
+++ b/drbd/drbd-headers/linux/genl_magic_func-genl_register_family_with_ops_groups.h
@@ -19,7 +19,7 @@ static int CONCAT_(GENL_MAGIC_FAMILY, _genl_multicast_ ## group)( \
unsigned int group_id = \
CONCAT_(GENL_MAGIC_FAMILY, _group_ ## group); \
return genlmsg_multicast_allns(&ZZZ_genl_family, skb, 0, \
- group_id, flags); \
+ group_id); \
}
#include GENL_MAGIC_INCLUDE_FILE
--
2.47.0

View File

@ -1,3 +0,0 @@
version https://git-lfs.github.com/spec/v1
oid sha256:4a0af3560d6d133f8062d4284dd6a2be8614388bbacd140a0978232fd163c533
size 1427992

3
drbd-9.1.23.tar.gz Normal file
View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:27273c96d68d6399bdc0f9a21581c4ebe67fb387206e55f8727d05595baf1cae
size 1481356

View File

@ -1,3 +1,69 @@
-------------------------------------------------------------------
Fri Dec 11 02:35:00 UTC 2024 - Heming Zhao <heming.zhao@suse.com>
- Update DRBD version from 9.1.22 to 9.1.23 (boo#1234849)
* Changelog from Linbit:
9.1.23 (api:genl2/proto:86-101,118-121/transport:18)
--------
* Fix a corner case that can happen when DRBD establishes multiple
connections in parallel, which could lead one connection to end up in
an inconsistent replication state of WFBitMapT/Established
* Fix a corner case in which a reconciliation resync ends up in
WFBitMapT/Established
* Restrict protocol compatibility to the most recent 8.4 and 9.0 releases
* Fix a corner case causing a module ref leak on drbd_transport_tcp;
if it hits, you can not rmmod it
* rate-limit resync progress while resync is paused
* resync-target inherits history UUIDs when resync finishes,
this can prevent unexpected "unrelared data" events later
* Updated compatibility code for Linux 6.11 and 6.12
* remove patches which already included in the new version:
0001-drbd-properly-rate-limit-resync-progress-reports.patch
0002-drbd-inherit-history-UUIDs-from-sync-source-when-res.patch
0003-build-compat-fix-line-offset-in-annotation-pragmas-p.patch
0004-drbd-fix-exposed_uuid-going-backward.patch
0005-drbd-Proper-locking-around-new_current_uuid-on-a-dis.patch
0006-build-CycloneDX-fix-bom-ref-add-purl.patch
0007-build-Another-update-to-the-spdx-files.patch
0008-build-generate-spdx.json-not-tag-value-format.patch
0009-compat-fix-gen_patch_names-for-bdev_file_open_by_pat.patch
0010-compat-fix-nla_nest_start_noflag-test.patch
0011-compat-fix-blk_alloc_disk-rule.patch
0012-drbd-remove-const-from-function-return-type.patch
0013-drbd-don-t-set-max_write_zeroes_sectors-in-decide_on.patch
0014-drbd-split-out-a-drbd_discard_supported-helper.patch
0015-drbd-atomically-update-queue-limits-in-drbd_reconsid.patch
0016-compat-test-and-patch-for-queue_limits_start_update.patch
0017-compat-specify-which-essential-change-was-not-made.patch
0018-gen_patch_names-reorder-blk_mode_t.patch
0019-compat-fix-blk_queue_update_readahead-patch.patch
0020-compat-test-and-patch-for-que_limits-max_hw_discard_.patch
0021-compat-fixup-write_zeroes__no_capable.patch
0022-compat-fixup-queue_flag_discard__yes_present.patch
0023-drbd-move-flags-to-queue_limits.patch
0024-compat-test-and-patch-for-queue_limits.features.patch
0025-drbd-Annotate-struct-fifo_buffer-with-__counted_by.patch
0026-compat-test-and-patch-for-__counted_by.patch
0027-drbd-fix-function-cast-warnings-in-state-machine.patch
0028-Add-missing-documentation-of-peer_device-parameter-t.patch
0030-drbd-kref_put-path-when-kernel_accept-fails.patch
0031-build-fix-typo-in-Makefile.spatch.patch
0032-drbd-open-do-not-delay-open-if-already-Primary.patch
* removed patch which is not needed anymore:
boo1231290_fix_drbd_build_error_against_kernel_v6.11.0.patch
boo1233222_fix_drbd_build_error_against_kernel_v6.11.6.patch
* update:
drbd_git_revision
drbd.spec
* add upstream patches to align commit d64ebe7eb7df:
0001-drbd-Fix-memory-leak.patch
-------------------------------------------------------------------
Mon Nov 11 12:23:17 UTC 2024 - Glass Su <glass.su@suse.com>

View File

@ -24,7 +24,7 @@
%endif
%endif
Name: drbd
Version: 9.1.22
Version: 9.1.23
Release: 0
Summary: Linux driver for the "Distributed Replicated Block Device"
License: GPL-2.0-or-later
@ -36,44 +36,11 @@ Source3: drbd_git_revision
########################
# upstream patch
Patch0001: 0001-drbd-properly-rate-limit-resync-progress-reports.patch
Patch0002: 0002-drbd-inherit-history-UUIDs-from-sync-source-when-res.patch
Patch0003: 0003-build-compat-fix-line-offset-in-annotation-pragmas-p.patch
Patch0004: 0004-drbd-fix-exposed_uuid-going-backward.patch
Patch0005: 0005-drbd-Proper-locking-around-new_current_uuid-on-a-dis.patch
Patch0006: 0006-build-CycloneDX-fix-bom-ref-add-purl.patch
Patch0007: 0007-build-Another-update-to-the-spdx-files.patch
Patch0008: 0008-build-generate-spdx.json-not-tag-value-format.patch
Patch0009: 0009-compat-fix-gen_patch_names-for-bdev_file_open_by_pat.patch
Patch0010: 0010-compat-fix-nla_nest_start_noflag-test.patch
Patch0011: 0011-compat-fix-blk_alloc_disk-rule.patch
Patch0012: 0012-drbd-remove-const-from-function-return-type.patch
Patch0013: 0013-drbd-don-t-set-max_write_zeroes_sectors-in-decide_on.patch
Patch0014: 0014-drbd-split-out-a-drbd_discard_supported-helper.patch
Patch0015: 0015-drbd-atomically-update-queue-limits-in-drbd_reconsid.patch
Patch0016: 0016-compat-test-and-patch-for-queue_limits_start_update.patch
Patch0017: 0017-compat-specify-which-essential-change-was-not-made.patch
Patch0018: 0018-gen_patch_names-reorder-blk_mode_t.patch
Patch0019: 0019-compat-fix-blk_queue_update_readahead-patch.patch
Patch0020: 0020-compat-test-and-patch-for-que_limits-max_hw_discard_.patch
Patch0021: 0021-compat-fixup-write_zeroes__no_capable.patch
Patch0022: 0022-compat-fixup-queue_flag_discard__yes_present.patch
Patch0023: 0023-drbd-move-flags-to-queue_limits.patch
Patch0024: 0024-compat-test-and-patch-for-queue_limits.features.patch
Patch0025: 0025-drbd-Annotate-struct-fifo_buffer-with-__counted_by.patch
Patch0026: 0026-compat-test-and-patch-for-__counted_by.patch
Patch0027: 0027-drbd-fix-function-cast-warnings-in-state-machine.patch
Patch0028: 0028-Add-missing-documentation-of-peer_device-parameter-t.patch
# 0029-ci-update-build-helpers.patch is fedora special, we ignore it.
Patch0029: 0030-drbd-kref_put-path-when-kernel_accept-fails.patch
Patch0030: 0031-build-fix-typo-in-Makefile.spatch.patch
Patch0031: 0032-drbd-open-do-not-delay-open-if-already-Primary.patch
Patch0001: 0001-drbd-Fix-memory-leak.patch
# suse special patch
Patch1001: bsc-1025089_fix-resync-finished-with-syncs-have-bits-set.patch
Patch1002: suse-coccinelle.patch
Patch1003: boo1231290_fix_drbd_build_error_against_kernel_v6.11.0.patch
Patch1004: boo1233222_fix_drbd_build_error_against_kernel_v6.11.6.patch
########################
#https://github.com/openSUSE/rpmlint-checks/blob/master/KMPPolicyCheck.py

View File

@ -1 +1 @@
GIT-hash: 13ada1be201eb14ff8295a17194de8db5cdccd7f
GIT-hash: d64ebe7eb7df8c622b20bca38f3d7f4c7bb033c9