From 30fc526c6ee76c2fd9c724c95223a13c9d021edd Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Thu, 31 Oct 2019 12:53:30 -0700 Subject: [PATCH 1/3] Link with -lpthread if iSER is enabled This patch fixes the following linker error: /usr/bin/ld: ../lib/.libs/libiscsipriv.a(libiscsipriv_la-iser.o): undefined reference to symbol 'sem_post@@GLIBC_2.2.5' /usr/bin/ld: //lib/x86_64-linux-gnu/libpthread.so.0: error adding symbols: DSO missing from command line Signed-off-by: Bart Van Assche --- lib/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Makefile.am b/lib/Makefile.am index 7161ed2..4a8a916 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -17,7 +17,7 @@ libiscsipriv_la_SOURCES += iser.c endif if HAVE_LINUX_ISER -libiscsipriv_la_LDFLAGS = -libverbs -lrdmacm +libiscsipriv_la_LDFLAGS = -libverbs -lrdmacm -lpthread endif libiscsipriv_la_CPPFLAGS = -I${srcdir}/../include -I$(srcdir)/include \ From a55f11ee6874fe3e216227b49632f8ad5d2516f4 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Thu, 31 Oct 2019 13:10:05 -0700 Subject: [PATCH 2/3] Improve iser_rx_desc alignment Align iscsi_header[] and data[] on an 8-byte boundary instead of on a 4-byte boundary. With this patch applied pahole produces the following output: struct iser_rx_desc { struct iser_hdr iser_header; /* 0 28 */ char pad1[4]; /* 28 4 */ char iscsi_header[48]; /* 32 48 */ /* --- cacheline 1 boundary (64 bytes) was 16 bytes ago --- */ char data[128]; /* 80 128 */ /* --- cacheline 3 boundary (192 bytes) was 16 bytes ago --- */ struct ibv_sge rx_sg; /* 208 16 */ struct ibv_mr * hdr_mr; /* 224 8 */ char pad2[24]; /* 232 24 */ /* size: 256, cachelines: 4, members: 7 */ }; Additionally, this patch fixes the following build errors: iser.c: In function 'iser_alloc_rx_descriptors': iser.c:916:11: error: taking address of packed member of 'struct iser_rx_desc' may result in an unaligned pointer value [-Werror=address-of-packed-member] 916 | rx_sg = &rx_desc->rx_sg; | ^~~~~~~~~~~~~~~ iser.c: In function 'iser_post_recvm': iser.c:955:20: error: taking address of packed member of 'struct iser_rx_desc' may result in an unaligned pointer value [-Werror=address-of-packed-member] 955 | rx_wr->sg_list = &rx_desc->rx_sg; | ^~~~~~~~~~~~~~~ Signed-off-by: Bart Van Assche --- include/iser-private.h | 9 ++++----- include/scsi-lowlevel.h | 4 ++++ 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/include/iser-private.h b/include/iser-private.h index 73749cb..ff38793 100644 --- a/include/iser-private.h +++ b/include/iser-private.h @@ -85,9 +85,6 @@ enum data_dir{ #define ISER_MIN_POSTED_RX (ISER_DEF_XMIT_CMDS_MAX >> 2) -#define ISER_RX_PAD_SIZE (256 - (ISER_RX_PAYLOAD_SIZE + \ - sizeof(struct ibv_mr*) + sizeof(struct ibv_sge))) - /** * struct iser_hdr - iSER header * @@ -121,13 +118,15 @@ struct iser_hdr { struct iser_rx_desc { struct iser_hdr iser_header; + char pad1[4]; char iscsi_header[ISCSI_RAW_HEADER_SIZE]; char data[ISER_RECV_DATA_SEG_LEN]; struct ibv_sge rx_sg; struct ibv_mr *hdr_mr; - char pad[ISER_RX_PAD_SIZE]; -} __attribute__((packed)); + char pad2[24]; +}; +static_assert(sizeof(struct iser_rx_desc) == 256, "iser_rx_desc size != 256"); /** * struct iser_tx_desc - iSER TX descriptor (for send wr_id) diff --git a/include/scsi-lowlevel.h b/include/scsi-lowlevel.h index f5fd037..bedefd8 100644 --- a/include/scsi-lowlevel.h +++ b/include/scsi-lowlevel.h @@ -30,6 +30,10 @@ extern "C" { #endif +#ifndef static_assert +#define static_assert(e, m) extern char unused_array[1 - 2 * !(e)] +#endif + #define SCSI_CDB_MAX_SIZE 16 enum scsi_opcode { From 2bbf7b5017c3549c64d8805ea2e3944f2648da70 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Thu, 31 Oct 2019 12:50:00 -0700 Subject: [PATCH 3/3] test-tool: If SG_IO fails, report why it failed See also https://github.com/sahlberg/libiscsi/issues/302. Signed-off-by: Bart Van Assche --- test-tool/iscsi-support.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test-tool/iscsi-support.c b/test-tool/iscsi-support.c index 169d2b0..9bec9e1 100644 --- a/test-tool/iscsi-support.c +++ b/test-tool/iscsi-support.c @@ -370,10 +370,14 @@ static struct scsi_task *send_scsi_command(struct scsi_device *sdev, struct scsi io_hdr.timeout = 5000; if(ioctl(sdev->sgio_fd, SG_IO, &io_hdr) < 0){ + int err = errno; + if (sdev->error_str != NULL) { free(discard_const(sdev->error_str)); } - sdev->error_str = strdup("SG_IO ioctl failed"); + if (asprintf(&sdev->error_str, "SG_IO ioctl failed: %s", + strerror(err)) < 0) + sdev->error_str = NULL; return NULL; }