]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
ublk: add helpers to check ublk_device flags
authorCaleb Sander Mateos <csander@purestorage.com>
Thu, 18 Sep 2025 01:49:40 +0000 (19:49 -0600)
committerJens Axboe <axboe@kernel.dk>
Sat, 20 Sep 2025 12:36:27 +0000 (06:36 -0600)
Introduce ublk_device analogues of the ublk_queue flag helpers:
- ublk_support_zero_copy() -> ublk_dev_support_user_copy()
- ublk_support_auto_buf_reg() -> ublk_dev_support_auto_buf_reg()
- ublk_support_user_copy() -> ublk_dev_support_user_copy()
- ublk_need_map_io() -> ublk_dev_need_map_io()
- ublk_need_req_ref() -> ublk_dev_need_req_ref()
- ublk_need_get_data() -> ublk_dev_need_get_data()

These will be used in subsequent changes to avoid accessing the
ublk_queue just for the flags, and instead use the ublk_device.

Signed-off-by: Caleb Sander Mateos <csander@purestorage.com>
Reviewed-by: Ming Lei <ming.lei@redhat.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
drivers/block/ublk_drv.c

index 4cb023d26593ae28b90829284eb7e311cf99a8bd..04b8613ce623f4e676a2f2ccb2736282db74db10 100644 (file)
@@ -662,22 +662,44 @@ static inline bool ublk_support_zero_copy(const struct ublk_queue *ubq)
        return ubq->flags & UBLK_F_SUPPORT_ZERO_COPY;
 }
 
+static inline bool ublk_dev_support_zero_copy(const struct ublk_device *ub)
+{
+       return ub->dev_info.flags & UBLK_F_SUPPORT_ZERO_COPY;
+}
+
 static inline bool ublk_support_auto_buf_reg(const struct ublk_queue *ubq)
 {
        return ubq->flags & UBLK_F_AUTO_BUF_REG;
 }
 
+static inline bool ublk_dev_support_auto_buf_reg(const struct ublk_device *ub)
+{
+       return ub->dev_info.flags & UBLK_F_AUTO_BUF_REG;
+}
+
 static inline bool ublk_support_user_copy(const struct ublk_queue *ubq)
 {
        return ubq->flags & UBLK_F_USER_COPY;
 }
 
+static inline bool ublk_dev_support_user_copy(const struct ublk_device *ub)
+{
+       return ub->dev_info.flags & UBLK_F_USER_COPY;
+}
+
 static inline bool ublk_need_map_io(const struct ublk_queue *ubq)
 {
        return !ublk_support_user_copy(ubq) && !ublk_support_zero_copy(ubq) &&
                !ublk_support_auto_buf_reg(ubq);
 }
 
+static inline bool ublk_dev_need_map_io(const struct ublk_device *ub)
+{
+       return !ublk_dev_support_user_copy(ub) &&
+              !ublk_dev_support_zero_copy(ub) &&
+              !ublk_dev_support_auto_buf_reg(ub);
+}
+
 static inline bool ublk_need_req_ref(const struct ublk_queue *ubq)
 {
        /*
@@ -695,6 +717,13 @@ static inline bool ublk_need_req_ref(const struct ublk_queue *ubq)
                ublk_support_auto_buf_reg(ubq);
 }
 
+static inline bool ublk_dev_need_req_ref(const struct ublk_device *ub)
+{
+       return ublk_dev_support_user_copy(ub) ||
+              ublk_dev_support_zero_copy(ub) ||
+              ublk_dev_support_auto_buf_reg(ub);
+}
+
 static inline void ublk_init_req_ref(const struct ublk_queue *ubq,
                struct ublk_io *io)
 {
@@ -726,6 +755,11 @@ static inline bool ublk_need_get_data(const struct ublk_queue *ubq)
        return ubq->flags & UBLK_F_NEED_GET_DATA;
 }
 
+static inline bool ublk_dev_need_get_data(const struct ublk_device *ub)
+{
+       return ub->dev_info.flags & UBLK_F_NEED_GET_DATA;
+}
+
 /* Called in slow path only, keep it noinline for trace purpose */
 static noinline struct ublk_device *ublk_get_device(struct ublk_device *ub)
 {