Skip to content

Commit 6140f1d

Browse files
MaxKellermannidryomov
authored andcommitted
libceph: add empty check to ceph_con_get_out_msg()
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 <[email protected]> Reviewed-by: Viacheslav Dubeyko <[email protected]> Signed-off-by: Ilya Dryomov <[email protected]>
1 parent 7399212 commit 6140f1d

File tree

3 files changed

+8
-9
lines changed

3 files changed

+8
-9
lines changed

net/ceph/messenger.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2114,7 +2114,9 @@ struct ceph_msg *ceph_con_get_out_msg(struct ceph_connection *con)
21142114
{
21152115
struct ceph_msg *msg;
21162116

2117-
BUG_ON(list_empty(&con->out_queue));
2117+
if (list_empty(&con->out_queue))
2118+
return NULL;
2119+
21182120
msg = list_first_entry(&con->out_queue, struct ceph_msg, list_head);
21192121
WARN_ON(msg->con != con);
21202122

net/ceph/messenger_v1.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,9 @@ static void prepare_write_message_footer(struct ceph_connection *con,
191191
/*
192192
* Prepare headers for the next outgoing message.
193193
*/
194-
static void prepare_write_message(struct ceph_connection *con)
194+
static void prepare_write_message(struct ceph_connection *con,
195+
struct ceph_msg *m)
195196
{
196-
struct ceph_msg *m;
197197
u32 crc;
198198

199199
con_out_kvec_reset(con);
@@ -209,8 +209,6 @@ static void prepare_write_message(struct ceph_connection *con)
209209
&con->v1.out_temp_ack);
210210
}
211211

212-
m = ceph_con_get_out_msg(con);
213-
214212
dout("prepare_write_message %p seq %lld type %d len %d+%d+%zd\n",
215213
m, con->out_seq, le16_to_cpu(m->hdr.type),
216214
le32_to_cpu(m->hdr.front_len), le32_to_cpu(m->hdr.middle_len),
@@ -1545,8 +1543,8 @@ int ceph_con_v1_try_write(struct ceph_connection *con)
15451543
goto more;
15461544
}
15471545
/* is anything else pending? */
1548-
if (!list_empty(&con->out_queue)) {
1549-
prepare_write_message(con);
1546+
if ((msg = ceph_con_get_out_msg(con)) != NULL) {
1547+
prepare_write_message(con, msg);
15501548
goto more;
15511549
}
15521550
if (con->in_seq > con->in_seq_acked) {

net/ceph/messenger_v2.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3310,8 +3310,7 @@ static int populate_out_iter(struct ceph_connection *con)
33103310
pr_err("prepare_keepalive2 failed: %d\n", ret);
33113311
return ret;
33123312
}
3313-
} else if (!list_empty(&con->out_queue)) {
3314-
msg = ceph_con_get_out_msg(con);
3313+
} else if ((msg = ceph_con_get_out_msg(con)) != NULL) {
33153314
ret = prepare_message(con, msg);
33163315
if (ret) {
33173316
pr_err("prepare_message failed: %d\n", ret);

0 commit comments

Comments
 (0)