Commit Graph

1938 Commits

Author SHA1 Message Date
Bart Van Assche
3804f3c2e0 Remove the discard_const() macro
Declare dynamically allocated strings as 'char *' instead of 'const char *'.
Remove the discard_const() macro. Do not test whether or not a pointer is
NULL before calling free() because it is allowed to pass NULL to free().

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
2020-02-28 21:54:49 -08:00
Bart Van Assche
aff4b7600b Merge pull request #316 from bytedance/bugfix-iser
Fix several bugs for iser
2020-02-28 21:20:35 -08:00
zhenwei pi
b98454ae97 iser: fix resource leak during reconnect
After iser reconnects successfully, iser drive should close old
connection and release resources.

Fix resource leak in this patch, and test a lot, this patch works
fine.

Test env:
192.168.122.204: run as a software gateway
192.168.122.205: run iser target, default gateway 192.168.122.204
192.168.122.206: run QEMU as intiator, default gateway 192.168.122.204

run script on 192.168.122.204:
for i in `seq 1 100`
do
	iptables -s 192.168.122.205/32 -A FORWARD -m statistic --mode random --probability 1 -j DROP
	iptables -s 192.168.122.206/32 -A FORWARD -m statistic --mode random --probability 1 -j DROP
	sleep 30
	iptables -F
	sleep 30
done

Signed-off-by: zhenwei pi <pizhenwei@bytedance.com>
2020-02-28 18:29:41 +08:00
zhenwei pi
3ccbceb6ff lib/connect.c: fix wrong transport type for iser reconnect
A new iscsi context is created as TCP transport type, but currently
missing iscsi_init_transport to change transport to iser in
reconnecting logic, then iser could never reconnect successfully.

Use orignal transport to initialize new iscsi context.

Signed-off-by: zhenwei pi <pizhenwei@bytedance.com>
2020-02-27 22:13:08 +08:00
zhenwei pi
e114be4156 iser: fix memory leak for cm thread
If a thread is created without any attr, it works in attached mode.
It means that we need run pthread_join to relaim stack of thread.

Signed-off-by: zhenwei pi <pizhenwei@bytedance.com>
2020-02-27 10:03:46 +08:00
zhenwei pi
b4ba92094e iser: fix segfault at iser_reg_mr
Hit segfault at iser_reg_mr during attaching disk with backtrace:
 #0  0x000055ace9635b0f in iser_reg_mr (iser_conn=0x55aceca33820) at iser.c:1060
 #1  iser_connected_handler (cma_id=<optimized out>) at iser.c:1300
 #2  iser_cma_handler (event=0x7f29ef1f7950, cma_id=<optimized out>, iser_conn=0x55aceca33820) at iser.c:1326
 #3  cm_thread (arg=0x55aceca33820) at iser.c:1380
 #4  0x00007f2e2c31c4a4 in start_thread (arg=0x7f29ef1f8700) at pthread_create.c:456
 #5  0x00007f2e2c05ed0f in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:97
 (gdb) p *iser_conn->tx_desc
 Cannot access memory at address 0x20

This issue can be reproduced easily by attaching several disks of iser
protocol:
 # virsh attach-device stretch iser0.xml
 # virsh attach-device stretch iser1.xml
 ...

Initialize instances with zero to avoid random value pointer.

Signed-off-by: zhenwei pi <pizhenwei@bytedance.com>
2020-02-27 10:03:46 +08:00
zhenwei pi
d020bb003d iser: set iser cm thread proc name as "iscsi_cm_thread"
libiscsi is usually linked by QEMU, and QEMU sets thread proc name
by function. But iser cm thread is created by libiscsi privately,
QEMU can't set this thread. After attaching a iser disk, we can find
a new thread 'qemu-system-x86' in QEMU process.

With this patch, iser cm thread works with thread name
'iscsi_cm_thread'.

Signed-off-by: zhenwei pi <pizhenwei@bytedance.com>
2020-02-27 10:03:46 +08:00
zhenwei pi
e2a7fdfb36 socket: fix disconnect corner case for iser
iscsi->fd is never initialized in iser driver, so iscsi_disconnect
always does not work for iser context.

iscsi->fd is used as a member variable of TCP context, so let iscsi
TCP driver handle iscsi->fd, we just call iscsi_disconnect in
iscsi_destroy_context. Luckly, TCP driver has already handle invalid
iscsi->fd case in iscsi_tcp_disconnect.

And fix NULL pointer case for iscsi_disconnect.

Signed-off-by: zhenwei pi <pizhenwei@bytedance.com>
2020-02-27 10:02:02 +08:00
zhenwei pi
a391176a6d init: fix memory leak in iscsi_create_context
iscsi instance is allocated in iscsi_create_context, after we return
NULL, nobody could handle it anymore.

Currently we can't hit this logic, anyway we still fix this.

Signed-off-by: zhenwei pi <pizhenwei@bytedance.com>
2020-02-25 22:35:54 +08:00
Bart Van Assche
6ea30aea50 .travis.yml: Add to repository
This change makes it possible to tell Travis CI to trigger a build after
every push and every time a new merge request is submitted.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
2020-02-24 19:04:57 -08:00
Bart Van Assche
69c4783d2d test-tool: Give up if READ CAPACITY reports that the block size is zero
Since the test tool can't proceed in a meaningful way if the block size
is zero, give up if the SCSI target reports that the block size is zero.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
2020-02-23 20:11:14 -08:00
Bart Van Assche
e1978f991a lib: Fix scsi_maintenancein_datain_getfullsize()
Coverity reported dead code.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
2020-02-23 20:11:14 -08:00
Bart Van Assche
0ad5c2c648 libiscsi: Fix a format specifier
Use %lu to format unsigned long instead of %d.

This was detected by Coverity.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
2020-02-23 20:11:14 -08:00
Bart Van Assche
eeb7ebaeab Merge pull request #306 from bvanassche/master
Improve robustness of the code that restores .queue_pdu()
2020-02-23 20:09:31 -08:00
Bart Van Assche
9ad9e4b5da Merge pull request #314 from ddiss/dd_usage_and_perf
examples/iscsi-dd: add usage and performance output
2020-02-23 20:07:23 -08:00
Bart Van Assche
6ac256f095 Merge pull request #311 from iammattcoleman/master
Simplify the logic that determines when to send headers
2020-02-23 20:03:34 -08:00
Bart Van Assche
b0559fc366 Merge pull request #312 from crobinso/extern-int
test-tool: Use 'extern int' for declaring global variables in headers
2020-02-23 20:00:55 -08:00
David Disseldorp
829c6351ed examples/iscsi-dd: measure throughput
Measure the elapsed time across the copy loop and print the throughput
[bKMGT]/second.

Signed-off-by: David Disseldorp <ddiss@suse.de>
2020-02-21 19:00:02 +01:00
David Disseldorp
53471e6215 examples/iscsi-dd: print basic usage information
Add additional -h/--help parameters.

Signed-off-by: David Disseldorp <ddiss@suse.de>
2020-02-21 18:58:12 +01:00
Cole Robinson
ea89dcdbf1 test-tool: Use 'extern int' in headers
Without this, linking fails on Fedora rawhide. Example:

...
/usr/bin/ld: test_async_lu_reset_simple.o:/root/libiscsi/libiscsi.git/test-tool/iscsi-support.h:59: multiple definition of `param_list_len_err_ascqs'; iscsi-test-cu.o:/root/libiscsi/libiscsi.git/test-tool/iscsi-support.h:59: first defined here
/usr/bin/ld: test_async_lu_reset_simple.o:/root/libiscsi/libiscsi.git/test-tool/iscsi-support.h:58: multiple definition of `invalid_cdb_ascqs'; iscsi-test-cu.o:/root/libiscsi/libiscsi.git/test-tool/iscsi-support.h:58: first defined here
...

Signed-off-by: Cole Robinson <crobinso@redhat.com>
2020-02-15 18:03:11 -05:00
Matt Coleman
3b52de7c1c Simplify logic that determines when to send headers
The prior condition could be summarized as:
```
if ((first && second) || second) {
```

This will always evaluate to `second`:

```
((true && true) || true) == true
((false && true) || true) == true
((true && false) || false) == false
((false && false) || false) == false
```

Reported-by: Jeffrey Knapp <jknapp@datto.com>
2020-02-14 12:17:10 -05:00
Ronnie Sahlberg
e6bcdf5fdb drop the LD_PRELOAD tool
I don't have time to maintain it. And it is just a toy anyway.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2020-02-12 15:21:03 +10:00
Ronnie Sahlberg
148e5f69e8 remove FIXME
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2020-02-11 17:06:41 +10:00
Ronnie Sahlberg
0b7733dda3 Merge pull request #309 from yoyoyopcp/master
Fix data segment length comparison to unsigned long
2020-01-28 14:01:00 +10:00
Paul Carlisle
f2d750260a Fix data segment length comparison to unsigned long
In logic.c, data segment parameters in the text segment are converted to
signed longs.  Changing from strtol -> strtoul fixes compiler errors on
certain platforms that warn against comparing a signed long with
uint32_t using MIN.
2020-01-27 16:59:10 -08:00
Ronnie Sahlberg
72f2816ea5 Merge pull request #307 from qsqx/master
four little patches
2020-01-09 12:28:47 +10:00
wanghonghao
d200d7b862 iser: queue pdus when cmdsn exceeds maxcmdsn
A PDU is sent directly in iscsi_iser_queue_pdu even if the cmdsn of
it exceeds maxcmdsn, and it may be ignored by the target.

Signed-off-by: wanghonghao <wanghonghao@bytedance.com>
2019-12-10 14:43:39 +08:00
wanghonghao
dfbc6697ae iser: send immediate data
When ImmediateData=Yes, DataSegmentLength is set in iSCSI layer
but immediate data is not sent in the RCaP message.

Signed-off-by: wanghonghao <wanghonghao@bytedance.com>
2019-12-10 14:43:39 +08:00
wanghonghao
51391285d8 iser: remove __packed from struct iser_cm_hdr declaration
`__packed` is not defined previously, and was treated as a varible
declaration.

Signed-off-by: wanghonghao <wanghonghao@bytedance.com>
2019-12-10 14:42:38 +08:00
wanghonghao
22d7360b5e iser: fix struct iser_rx_desc
iSER header is followed by iSCSI PDU without any pad in an RCaP Message.

Signed-off-by: wanghonghao <wanghonghao@bytedance.com>
2019-12-09 13:17:55 +08:00
Bart Van Assche
cc3ddbff42 Improve robustness of the code that restores .queue_pdu()
In my tests I hit a stack overflow caused by infinite recursion of
.queue_pdu() calls, caused by .queue_pdu() not being restored in an
error path. Make the approach for restoring .queue_pdu() more robust.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
2019-11-12 18:12:27 -08:00
Ronnie Sahlberg
10599fcd4f Merge pull request #305 from bvanassche/master
Use dynamic memory allocation instead of variable-length arrays
2019-11-12 18:46:46 +10:00
Khazhismel Kumykov
2b9c928bce test-tool: avoid use-after-free on iscsi_logout_sync
iscsi_logout_sync in lu_reset_simple will still refer to wtask in the
case that we bail out due to reconnect failure.

abort_simple would sometimes refer to wtask during iscsi_logout_sync,
even if the test passed.

Signed-off-by: Khazhismel Kumykov <khazhy@google.com>
2019-11-12 18:45:08 +10:00
Bart Van Assche
9d2493248b Use dynamic memory allocation instead of variable-length arrays
Since it is easy to trigger a stack overflow with variable-length arrays,
use dynamic memory allocation instead of VLAs. Add -Wvla to the compiler
options such that no new VLAs get introduced.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
2019-11-09 13:39:34 -08:00
Ronnie Sahlberg
88f67e8cf8 Merge pull request #292 from sumitrai/TMF_OVERFLOW_DATA_SIZE_CRASH
lib/iser.c: fix overflow_data_size NULL ptr dereference
2019-11-01 07:30:19 +10:00
Ronnie Sahlberg
f6770178f9 Merge pull request #303 from bvanassche/master
Fix two recently introduced issues and improve SG_IO error reporting
2019-11-01 07:29:29 +10:00
Bart Van Assche
2bbf7b5017 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 <bvanassche@acm.org>
2019-10-31 14:16:56 -07:00
Bart Van Assche
a55f11ee68 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 <bvanassche@acm.org>
2019-10-31 14:16:56 -07:00
Bart Van Assche
30fc526c6e 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 <bvanassche@acm.org>
2019-10-31 14:16:38 -07:00
Ronnie Sahlberg
1ab84e2175 fix LGTM.com warning
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2019-09-28 17:32:29 -07:00
Ronnie Sahlberg
65c425ef82 It is a TODO not a FIXME
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2019-09-27 21:04:56 -07:00
Ronnie Sahlberg
101c1a5835 Merge pull request #301 from ddiss/iscsi_sendtargets_nop
test-tool: add iSCSI SendTargets, Nop-Out and CHAP auth tests
2019-09-27 13:32:15 -07:00
David Disseldorp
84d80878a6 test-tool: add iSCSI CHAP_A negotiation tests
The iSCSICHAP.Simple test ensures that CHAP_A comma separated lists
are correctly handled. iSCSICHAP.Invalid tests a range of invalid
CHAP_A parameters.

Signed-off-by: David Disseldorp <ddiss@suse.de>
2019-09-23 16:46:26 +02:00
David Disseldorp
e716691a45 test-tool: use CHECK_FOR_ISCSI() helper macro
This removes a large amount of boilerplate code.

Signed-off-by: David Disseldorp <ddiss@suse.de>
2019-09-22 16:40:13 +02:00
David Disseldorp
2600e538d8 test-tool: add CHECK_FOR_ISCSI() test filter macro
Skip the test if the provided iscsi_ctx is null.

Signed-off-by: David Disseldorp <ddiss@suse.de>
2019-09-22 16:40:13 +02:00
David Disseldorp
1511ddcbe4 test-tool: add simple iSCSI NOP-Out test
Send a ping with/without data and expect a valid response.

Signed-off-by: David Disseldorp <ddiss@suse.de>
2019-09-22 16:40:13 +02:00
David Disseldorp
98d383d159 test-tool: add iSCSI SendTargets.Invalid test case
This test sends a series of Text request PDUs with key-value data that
doesn't match SendTargets=All.

Signed-off-by: David Disseldorp <ddiss@suse.de>
2019-09-22 16:40:13 +02:00
David Disseldorp
955b16b3e3 test-tool: add iSCSI SendTargets.Simple test
This test currently only sends a SendTargets request via existing normal
iSCSI sessions.

Signed-off-by: David Disseldorp <ddiss@suse.de>
2019-09-22 16:07:52 +02:00
David Disseldorp
d42fcd89ce lib: use const for add_data buffers
The buffer is memcopied into the PDU. const makes it a little clearer
that the caller isn't handing over ownership.

Signed-off-by: David Disseldorp <ddiss@suse.de>
2019-09-18 13:30:04 +02:00
Ronnie Sahlberg
f36b936db1 Merge pull request #300 from ddiss/libiscsipriv
test-tool: add and link against libiscsipriv convenience library
2019-09-18 10:07:02 +10:00