]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
libceph: add empty check to ceph_con_get_out_msg()
authorMax Kellermann <max.kellermann@ionos.com>
Wed, 6 Aug 2025 09:48:55 +0000 (11:48 +0200)
committerIlya Dryomov <idryomov@gmail.com>
Wed, 8 Oct 2025 21:30:47 +0000 (23:30 +0200)
This moves the list_empty() checks from the two callers (v1 and v2)
into the base messenger.c library.  Now the v1/v2 specializations do
not need to know about con->out_queue; that implementation detail is
now hidden behind the ceph_con_get_out_msg() function.

[ idryomov: instead of changing prepare_write_message() to return
  a bool, move ceph_con_get_out_msg() call out to arrive to the same
  pattern as in messenger_v2.c ]

Signed-off-by: Max Kellermann <max.kellermann@ionos.com>
Reviewed-by: Viacheslav Dubeyko <Slava.Dubeyko@ibm.com>
Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
net/ceph/messenger.c
net/ceph/messenger_v1.c
net/ceph/messenger_v2.c

index 08a6a083609f967b6013d68da08bbc5505e6b0d1..878bbfe770b1ebd803e755b2b2fac9198d1d7b0a 100644 (file)
@@ -2114,7 +2114,9 @@ struct ceph_msg *ceph_con_get_out_msg(struct ceph_connection *con)
 {
        struct ceph_msg *msg;
 
-       BUG_ON(list_empty(&con->out_queue));
+       if (list_empty(&con->out_queue))
+               return NULL;
+
        msg = list_first_entry(&con->out_queue, struct ceph_msg, list_head);
        WARN_ON(msg->con != con);
 
index cc4a36ef8462bad42c1f8a90d1aabff57eff97c0..c9e002d963190a42be2e3651c654c878ee87db94 100644 (file)
@@ -191,9 +191,9 @@ static void prepare_write_message_footer(struct ceph_connection *con,
 /*
  * Prepare headers for the next outgoing message.
  */
-static void prepare_write_message(struct ceph_connection *con)
+static void prepare_write_message(struct ceph_connection *con,
+                                 struct ceph_msg *m)
 {
-       struct ceph_msg *m;
        u32 crc;
 
        con_out_kvec_reset(con);
@@ -209,8 +209,6 @@ static void prepare_write_message(struct ceph_connection *con)
                        &con->v1.out_temp_ack);
        }
 
-       m = ceph_con_get_out_msg(con);
-
        dout("prepare_write_message %p seq %lld type %d len %d+%d+%zd\n",
             m, con->out_seq, le16_to_cpu(m->hdr.type),
             le32_to_cpu(m->hdr.front_len), le32_to_cpu(m->hdr.middle_len),
@@ -1545,8 +1543,8 @@ do_next:
                        goto more;
                }
                /* is anything else pending? */
-               if (!list_empty(&con->out_queue)) {
-                       prepare_write_message(con);
+               if ((msg = ceph_con_get_out_msg(con)) != NULL) {
+                       prepare_write_message(con, msg);
                        goto more;
                }
                if (con->in_seq > con->in_seq_acked) {
index b44e936f3865e89558093a420006c24a0cbdcce6..9e39378eda003dae31b312f270a9b51d030b892a 100644 (file)
@@ -3310,8 +3310,7 @@ static int populate_out_iter(struct ceph_connection *con)
                        pr_err("prepare_keepalive2 failed: %d\n", ret);
                        return ret;
                }
-       } else if (!list_empty(&con->out_queue)) {
-               msg = ceph_con_get_out_msg(con);
+       } else if ((msg = ceph_con_get_out_msg(con)) != NULL) {
                ret = prepare_message(con, msg);
                if (ret) {
                        pr_err("prepare_message failed: %d\n", ret);