]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
block/rnbd-proto: Check and retain the NOUNMAP flag for requests
authorMd Haris Iqbal <haris.iqbal@ionos.com>
Fri, 5 Dec 2025 12:47:30 +0000 (13:47 +0100)
committerJens Axboe <axboe@kernel.dk>
Tue, 6 Jan 2026 12:28:10 +0000 (05:28 -0700)
The NOUNMAP flag is in combination with WRITE_ZEROES flag to indicate
that the upper layers wants the sectors zeroed, but does not want it to
get freed. This instruction is especially important for storage stacks
which involves a layer capable of thin provisioning.

This commit makes RNBD block device transfer and retain this NOUNMAP flag
for requests, so it can be passed onto the backend device on the server
side.

Since it is a change in the wire protocol, bump the minor version of
protocol.

Signed-off-by: Md Haris Iqbal <haris.iqbal@ionos.com>
Signed-off-by: Jack Wang <jinpu.wang@ionos.com>
Signed-off-by: Grzegorz Prajsner <grzegorz.prajsner@ionos.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
drivers/block/rnbd/rnbd-proto.h

index 5e74ae86169b0edf5a7a99b5716f4ca82e03ec45..64f1cfe9f8efbe22dae02c398947c255020db76d 100644 (file)
@@ -18,7 +18,7 @@
 #include <rdma/ib.h>
 
 #define RNBD_PROTO_VER_MAJOR 2
-#define RNBD_PROTO_VER_MINOR 1
+#define RNBD_PROTO_VER_MINOR 2
 
 /* The default port number the RTRS server is listening on. */
 #define RTRS_PORT 1234
@@ -198,6 +198,7 @@ struct rnbd_msg_io {
  * @RNBD_F_SYNC:            request is sync (sync write or read)
  * @RNBD_F_FUA:             forced unit access
  * @RNBD_F_PREFLUSH:       request for cache flush
+ * @RNBD_F_NOUNMAP:        do not free blocks when zeroing
  */
 enum rnbd_io_flags {
 
@@ -212,7 +213,8 @@ enum rnbd_io_flags {
        /* Flags */
        RNBD_F_SYNC  = 1<<(RNBD_OP_BITS + 0),
        RNBD_F_FUA   = 1<<(RNBD_OP_BITS + 1),
-       RNBD_F_PREFLUSH = 1<<(RNBD_OP_BITS + 2)
+       RNBD_F_PREFLUSH = 1<<(RNBD_OP_BITS + 2),
+       RNBD_F_NOUNMAP = 1<<(RNBD_OP_BITS + 3)
 };
 
 static inline u32 rnbd_op(u32 flags)
@@ -247,6 +249,9 @@ static inline blk_opf_t rnbd_to_bio_flags(u32 rnbd_opf)
                break;
        case RNBD_OP_WRITE_ZEROES:
                bio_opf = REQ_OP_WRITE_ZEROES;
+
+               if (rnbd_opf & RNBD_F_NOUNMAP)
+                       bio_opf |= REQ_NOUNMAP;
                break;
        default:
                WARN(1, "Unknown RNBD type: %d (flags %d)\n",
@@ -285,6 +290,9 @@ static inline u32 rq_to_rnbd_flags(struct request *rq)
                break;
        case REQ_OP_WRITE_ZEROES:
                rnbd_opf = RNBD_OP_WRITE_ZEROES;
+
+               if (rq->cmd_flags & REQ_NOUNMAP)
+                       rnbd_opf |= RNBD_F_NOUNMAP;
                break;
        case REQ_OP_FLUSH:
                rnbd_opf = RNBD_OP_FLUSH;