Commit Graph

1956 Commits

Author SHA1 Message Date
Bart Van Assche
0bbd90e0de Merge pull request #321 from ddiss/xcopy_type_a0_sds
test: XCOPY type 0x0A segment descriptor support
2020-03-18 11:52:52 -07:00
David Disseldorp
a89583aec3 test/xcopy_simple: add XCOPY test with 0x0A segment descriptor
Check for 0x0A descriptor support via SCSI_COPY_RESULTS_OP_PARAMS. If
supported, perform a 0x0A type XCOPY using target's
maximum_segment_length (or 256M if larger).

Signed-off-by: David Disseldorp <ddiss@suse.de>
2020-03-18 18:59:43 +01:00
David Disseldorp
c8992f45b1 test: add support for 0x0A type XCOPY segment descriptors
Type 0x0A segment descriptors provide a 32-bit wide number-of-bytes
field, allowing for much larger copy offloads with a single segment
descriptor.

Signed-off-by: David Disseldorp <ddiss@suse.de>
2020-03-18 18:59:34 +01:00
David Disseldorp
385c6e8ae9 test/xcopy_simple: zero destination range before copy
Signed-off-by: David Disseldorp <ddiss@suse.de>
2020-03-18 18:59:34 +01:00
zhenwei pi
46e978ce97 iser: fix hang in rdma_destroy_id
Hit iser hang in rdma_destroy_id with trace:
 #0  pthread_cond_wait@@GLIBC_2.3.2 () at ../sysdeps/unix/sysv/linux/x86_64/pthread_cond_wait.S:185
 #1  0x00007f96ecbbcbb3 in rdma_destroy_id () from /usr/lib/librdmacm.so.1
 #2  0x00005632027311d4 in iser_conn_release (iser_conn=iser_conn@entry=0x7f96d4027440) at iser.c:261
 #3  0x0000563202731428 in iscsi_iser_connect (iscsi=0x563205206c70, sa=<optimized out>, ai_family=<optimized out>)
     at iser.c:1516
 #4  0x000056320273dd3c in iscsi_connect_async (iscsi=iscsi@entry=0x563205206c70,
     portal=portal@entry=0x563205207084 "210.32.124.205:3260", cb=cb@entry=0x56320272b220 <iscsi_connect_cb>,
     private_data=private_data@entry=0x7f96d4008b00) at socket.c:389
 #5  0x000056320272b325 in iscsi_full_connect_async (iscsi=0x563205206c70,
     portal=0x563205207084 "210.32.124.205:3260", lun=1, cb=cb@entry=0x56320272aef0 <iscsi_reconnect_cb>,
     private_data=private_data@entry=0x0) at connect.c:230
 #6  0x000056320272b711 in iscsi_reconnect (iscsi=<optimized out>) at connect.c:473
 #7  0x00005632026810a8 in iscsi_timed_check_events (opaque=0x563205206ae0) at block/iscsi.c:387

Currently use pthread_cancel to kill cmthread forcefully, cmthread may
exits without rdma_ack_cm_event, then unacknowledged event will be
remained in librdmacm. rdma_destroy_id hangs until uplayer ack all
the cm event.

Since destroying qp, cm thread will handle DISCONNECTED event, and
exits by itself. Joining cm thread to wait cm thread to exit
gracefully.

Signed-off-by: zhenwei pi <pizhenwei@bytedance.com>
2020-03-17 20:31:46 -07:00
zhenwei pi
dcf95f9780 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 <iscsi_co_generic_cb>,
     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=<optimized out>, wrprotect=0, dpo=0, fua=0, fua_nv=0,
     group_number=0, cb=0x55e316044c10 <iscsi_co_generic_cb>, private_data=0x7f15feeb77e0, iov=0x7f1a34042090,
     niov=1) at iscsi-command.c:1107
 #4  0x000055e31604680f in iscsi_co_writev (bs=<optimized out>, sector_num=<optimized out>,
     nb_sectors=<optimized out>, iov=0x7f1a3404e380, flags=<optimized out>) 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 <pizhenwei@bytedance.com>
[ bvanassche: reformatted patch ]
2020-03-17 20:27:49 -07:00
Bart Van Assche
37fb15e8eb Merge pull request #320 from ddiss/xcopy_type_a0_sds_prep
test/xcopy: minor clean up and refactoring
2020-03-17 17:13:48 -07:00
David Disseldorp
da7c1c4b0a test: use spec defined XCOPY segment descriptor lengths
The SPC4r37 specification defines XCOPY Segment Descriptor lengths for
each SD type. The spec defined SD lengths don't account for the four SD
header bytes. To make it easier to match the spec to the implementation,
use the spec defined lengths in get_desc_len() with a four byte SD
header addition.

Signed-off-by: David Disseldorp <ddiss@suse.de>
2020-03-18 00:49:36 +01:00
David Disseldorp
8dbf6e51e2 test: use scsi_set_uintX marshalling helpers for XCOPY
Signed-off-by: David Disseldorp <ddiss@suse.de>
2020-03-18 00:49:36 +01:00
Bart Van Assche
65caf10cab iser: Remove a superfluous pointer check
Checking whether a pointer is NULL after it has been dereferenced is not
useful. This was detected by Coverity.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
2020-03-07 12:37:51 -08:00
Bart Van Assche
bac94c18b8 libiscsi: Reduce the size of struct iscsi_context
Reduce the size of struct iscsi_context by reordering the members of this
data structure. Additionally, change the rdma_ack_timeout value from
'unsigned char' into 'uint8_t' to make it clear that this variable
represents an integer.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
2020-03-07 12:37:51 -08:00
zhenwei pi
6ed1ffb7b2 iser: support rdma ack timeout optimization
Since 2c1619edef61a03cb516efaa81750784c3071d10 for linux kernel and
55843c4ab8f559679d28c559cc4d681836be769b for rdma-core, rdma cma
supports RDMA_OPTION_ID_ACK_TIMEOUT. It's useful for RDMA out of
sequence case. Because this feature is added recently, we have to
check this in autogen.sh before building source code.

Depend on production enviroument, tunning rdma ack timeout could get
the best performance. Suggested by Bart and Ronnie, instead of using
a fixed timeout value, add two methods to set rdma ack timeout value.
1, add URL variable 'LIBISCSI_RDMA_ACK_TIMEOUT'. This could works
for a specified connection.
2, add env argument 'LIBISCSI_RDMA_ACK_TIMEOUT'. This works as a
common setting for all the connection of a process.

Test under different packet loss rate and different ack timeout, run
fio (iodepth=1) in a guest os, I got this result:
latency under packet loss rate 0.00001:
	timeout 19: avg 170.22, pct99.9 215
	timeout 10: avg 160.08, pct99.9 215
	timeout 8 : avg 146.39, pct99.9 177
	timeout 7 : avg 148.37, pct99.9 211

latency under packet loss rate 0.0001:
	timeout 19: avg 949.23, pct99.9 306
	timeout 10: avg 818.53, pct99.9 378
	timeout 8 : avg 615.84, pct99.9 189
	timeout 7 : avg 618.89, pct99.9 310

Base on this test report, setting ack timeout to 8(1048.576 usec) is
a good choice in my test enviroument.

Signed-off-by: zhenwei pi <pizhenwei@bytedance.com>
2020-03-07 12:37:46 -08:00
Bart Van Assche
e051995303 Merge pull request #315 from ddiss/dd_clock_gettime
examples/iscsi-dd: check for clock_gettime() errors
2020-03-05 20:34:24 -08:00
David Disseldorp
8ae813bae9 examples/iscsi-dd: check for clock_gettime() errors
Only dump performance details if we have valid start and end times.

Signed-off-by: David Disseldorp <ddiss@suse.de>
2020-03-04 15:49:20 +01:00
Bart Van Assche
fbadb25da7 Merge pull request #318 from neutronsharc/pr
specify number of blocks in write_same command
2020-03-03 18:18:44 -08:00
shawn
dfff7e9d16 specify number of blocks in write_same command
If "number of blocks" is 0, write_same will not erase the LBA range and
read-verify will fail.
2020-03-03 17:31:50 -08:00
Bart Van Assche
66e5af9422 configure.ac: Add -Wcast-qual
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
2020-02-28 21:54:49 -08:00
Bart Van Assche
529350eab1 Do not cast away constness
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
2020-02-28 21:54:49 -08:00
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