From 9a4439a335c0e2c7cef69af5d950969ba5f1be75 Mon Sep 17 00:00:00 2001 From: zhenwei pi Date: Tue, 10 Mar 2020 15:50:24 +0800 Subject: [PATCH] iser: fix crash for sending pdi during reconnecting Hit the crash stack: #0 iser_initialize_headers (iser_pdu=0x7f1a3404ef50, iser_conn=0x0) at iser.c:514 #1 iscsi_iser_send_pdu (iscsi=0x7f1a3406d700, pdu=0x7f1a3404ef50) at iser.c:714 #2 0x000055e3160f0157 in iscsi_scsi_command_async (iscsi=0x7f1a3406d700, iscsi@entry=0x55e317fbcc70, lun=lun@entry=1, task=task@entry=0x7f1a34026610, cb=cb@entry=0x55e316044c10 , d=d@entry=0x7f15feeb7710, private_data=private_data@entry=0x7f15feeb77e0) at iscsi-command.c:282 #3 0x000055e3160f1616 in iscsi_write10_iov_task (iscsi=0x55e317fbcc70, lun=1, lba=lba@entry=10401896, data=data@entry=0x0, datalen=4096, blocksize=, wrprotect=0, dpo=0, fua=0, fua_nv=0, group_number=0, cb=0x55e316044c10 , private_data=0x7f15feeb77e0, iov=0x7f1a34042090, niov=1) at iscsi-command.c:1107 #4 0x000055e31604680f in iscsi_co_writev (bs=, sector_num=, nb_sectors=, iov=0x7f1a3404e380, flags=) at block/iscsi.c:640 #5 0x000055e31601e89c in bdrv_driver_pwritev (bs=bs@entry=0x55e317fb6570, offset=offset@entry=5325770752, bytes=bytes@entry=4096, qiov=qiov@entry=0x7f1a3404e380, qiov_offset=qiov_offset@entry=0, flags=flags@entry=0) at block/io.c:1220 The reason is that during async reconnection, before reconnecting call back function gets woked, we have closed the old connection, and the new connection is not ready. At the same time, up layer still sends pdu to the old iscsi context. In this patch, before reconnecting successfully, just add the pdu to waitpdu without sending. Suggested by Bart, do not show iser related log here. Signed-off-by: zhenwei pi --- lib/iser.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/iser.c b/lib/iser.c index 976ffce3..157c6431 100644 --- a/lib/iser.c +++ b/lib/iser.c @@ -711,6 +711,13 @@ iscsi_iser_send_pdu(struct iscsi_context *iscsi, struct iscsi_pdu *pdu) { iscsi_pdu_set_expstatsn(pdu, iscsi->statsn + 1); ISCSI_LIST_ADD_END(&iscsi->waitpdu, pdu); + /* because of async reconnection, before reconnecting successfully, + the argument 'iscsi' is the 'old_iscsi' with a empty connection. + */ + if (!iser_conn) { + return 0; + } + if (iser_initialize_headers(iser_pdu, iser_conn)) { iscsi_set_error(iscsi, "initialize headers Failed\n"); return -1;