hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/drivers/block/drbd/drbd_protocol.h
....@@ -57,7 +57,7 @@
5757 P_PROTOCOL_UPDATE = 0x2d, /* data sock: is used in established connections */
5858 /* 0x2e to 0x30 reserved, used in drbd 9 */
5959
60
- /* REQ_DISCARD. We used "discard" in different contexts before,
60
+ /* REQ_OP_DISCARD. We used "discard" in different contexts before,
6161 * which is why I chose TRIM here, to disambiguate. */
6262 P_TRIM = 0x31,
6363
....@@ -69,6 +69,11 @@
6969 * On a receiving side without REQ_WRITE_SAME,
7070 * we may fall back to an opencoded loop instead. */
7171 P_WSAME = 0x34,
72
+
73
+ /* 0x35 already claimed in DRBD 9 */
74
+ P_ZEROES = 0x36, /* data sock: zero-out, WRITE_ZEROES */
75
+
76
+ /* 0x40 .. 0x48 already claimed in DRBD 9 */
7277
7378 P_MAY_IGNORE = 0x100, /* Flag to test if (cmd > P_MAY_IGNORE) ... */
7479 P_MAX_OPT_CMD = 0x101,
....@@ -126,10 +131,16 @@
126131 #define DP_UNPLUG 8 /* not used anymore */
127132 #define DP_FUA 16 /* equals REQ_FUA */
128133 #define DP_FLUSH 32 /* equals REQ_PREFLUSH */
129
-#define DP_DISCARD 64 /* equals REQ_DISCARD */
134
+#define DP_DISCARD 64 /* equals REQ_OP_DISCARD */
130135 #define DP_SEND_RECEIVE_ACK 128 /* This is a proto B write request */
131136 #define DP_SEND_WRITE_ACK 256 /* This is a proto C write request */
132137 #define DP_WSAME 512 /* equiv. REQ_WRITE_SAME */
138
+#define DP_ZEROES 1024 /* equiv. REQ_OP_WRITE_ZEROES */
139
+
140
+/* possible combinations:
141
+ * REQ_OP_WRITE_ZEROES: DP_DISCARD | DP_ZEROES
142
+ * REQ_OP_WRITE_ZEROES + REQ_NOUNMAP: DP_ZEROES
143
+ */
133144
134145 struct p_data {
135146 u64 sector; /* 64 bits sector number */
....@@ -197,6 +208,42 @@
197208 */
198209 #define DRBD_FF_WSAME 4
199210
211
+/* supports REQ_OP_WRITE_ZEROES on the "wire" protocol.
212
+ *
213
+ * We used to map that to "discard" on the sending side, and if we cannot
214
+ * guarantee that discard zeroes data, the receiving side would map discard
215
+ * back to zero-out.
216
+ *
217
+ * With the introduction of REQ_OP_WRITE_ZEROES,
218
+ * we started to use that for both WRITE_ZEROES and DISCARDS,
219
+ * hoping that WRITE_ZEROES would "do what we want",
220
+ * UNMAP if possible, zero-out the rest.
221
+ *
222
+ * The example scenario is some LVM "thin" backend.
223
+ *
224
+ * While an un-allocated block on dm-thin reads as zeroes, on a dm-thin
225
+ * with "skip_block_zeroing=true", after a partial block write allocated
226
+ * that block, that same block may well map "undefined old garbage" from
227
+ * the backends on LBAs that have not yet been written to.
228
+ *
229
+ * If we cannot distinguish between zero-out and discard on the receiving
230
+ * side, to avoid "undefined old garbage" to pop up randomly at later times
231
+ * on supposedly zero-initialized blocks, we'd need to map all discards to
232
+ * zero-out on the receiving side. But that would potentially do a full
233
+ * alloc on thinly provisioned backends, even when the expectation was to
234
+ * unmap/trim/discard/de-allocate.
235
+ *
236
+ * We need to distinguish on the protocol level, whether we need to guarantee
237
+ * zeroes (and thus use zero-out, potentially doing the mentioned full-alloc),
238
+ * or if we want to put the emphasis on discard, and only do a "best effort
239
+ * zeroing" (by "discarding" blocks aligned to discard-granularity, and zeroing
240
+ * only potential unaligned head and tail clippings), to at least *try* to
241
+ * avoid "false positives" in an online-verify later, hoping that someone
242
+ * set skip_block_zeroing=false.
243
+ */
244
+#define DRBD_FF_WZEROES 8
245
+
246
+
200247 struct p_connection_features {
201248 u32 protocol_min;
202249 u32 feature_flags;
....@@ -224,7 +271,7 @@
224271 u32 resync_rate;
225272
226273 /* Since protocol version 88 and higher. */
227
- char verify_alg[0];
274
+ char verify_alg[];
228275 } __packed;
229276
230277 struct p_rs_param_89 {
....@@ -258,7 +305,7 @@
258305 u32 two_primaries;
259306
260307 /* Since protocol version 87 and higher. */
261
- char integrity_alg[0];
308
+ char integrity_alg[];
262309
263310 } __packed;
264311
....@@ -313,7 +360,7 @@
313360 u16 dds_flags; /* use enum dds_flags here. */
314361
315362 /* optional queue_limits if (agreed_features & DRBD_FF_WSAME) */
316
- struct o_qlim qlim[0];
363
+ struct o_qlim qlim[];
317364 } __packed;
318365
319366 struct p_state {
....@@ -362,7 +409,7 @@
362409 */
363410 u8 encoding;
364411
365
- u8 code[0];
412
+ u8 code[];
366413 } __packed;
367414
368415 struct p_delay_probe93 {