Commit Graph

488 Commits

Author SHA1 Message Date
Bart Van Assche
d77765548f libiscsi: Also parse residual if SCSI status != GOOD
This change is needed for the test_write*_residuals tests.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
2014-08-04 16:03:49 -07:00
Ronnie Sahlberg
f0ebbdc203 Merge pull request #128 from plieven/revert_iovector
socket: rename max_read parameter to count in iscsi_iovector_readv_write...
2014-07-14 06:24:05 -07:00
Peter Lieven
53e38dff7d socket: rename max_read parameter to count in iscsi_iovector_readv_writev
Signed-off-by: Peter Lieven <pl@kamp.de>
2014-07-14 15:05:19 +02:00
Ronnie Sahlberg
a0d09ca9de Merge pull request #127 from plieven/revert_iovector
Revert "Rewrite and simplify iscsi_iovector_readv_writev"
2014-07-14 05:56:12 -07:00
Peter Lieven
59e4a07129 Revert "Rewrite and simplify iscsi_iovector_readv_writev"
Since writing headers and payload in a single iov has never been
implementend and after thinking about it several times seems to
be very hairy I would like to revert this change since
the original implementation is in O(1) while the changed one
is in O(n). This results in a complexity of O(n^2) instead of
O(n) for the whole send operation.

This reverts commit 06eab264f6.
2014-07-14 08:05:32 +02:00
Peter Lieven
4b3f4b5822 iscsi_which_events: do not set POLLOUT if context is corked
if the socket is corked we otherwise set POLLOUT and then
do not sent. Depending on the event loop implementation this
can result in a busy wait.

Signed-off-by: Peter Lieven <pl@kamp.de>
2014-07-14 08:02:24 +02:00
Ronnie Sahlberg
ada1fc2008 Merge pull request #123 from plieven/asyncv3
add support for async messages
2014-07-13 16:46:27 -07:00
Paolo Bonzini
ce0723320c libiscsi: fix dangling pointer for outqueue_current
The outqueue_current PDU might also be in waitpdu if it does not have
ISCSI_PDU_DELETE_WHEN_SENT.  outqueue_current is freed after the
waitpdu list (for reconnect or defer_reconnect), or sometimes not
considered at all (for cancel), and this can cause a dangling pointer.

Keep outqueue_current up to date when a PDU is freed.  A bit hacky,
but it avoids touching code all over the place.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2014-06-17 14:59:50 +02:00
Peter Lieven
4e129d385c pdu: fix statsn and factor out sn comparision
Signed-off-by: Peter Lieven <pl@kamp.de>
2014-06-17 14:58:38 +02:00
Peter Lieven
52c6b0d397 pdu: check callback on iscsi_process_reject
if the rejected packet is a NOP-Out it is legal
that it has no callback. In this case we end
up in a segfault.

Signed-off-by: Peter Lieven <pl@kamp.de>
2014-06-17 14:57:52 +02:00
Peter Lieven
e6894fd73a iscsi-command: do not fail commands while reconnect is pending
Signed-off-by: Peter Lieven <pl@kamp.de>
2014-06-17 14:56:57 +02:00
Peter Lieven
f14f3ef6fe pdu: handle async events 2,3,4
Signed-off-by: Peter Lieven <pl@kamp.de>
2014-06-17 14:56:43 +02:00
Peter Lieven
21e02c2078 pdu: catch rejected packets while target waits for logout
after a target has send the async target requests logout event it may
reject each request with a waiting for logout reason. Catch these
rejects if an outstanding request and the logout event overlap.

Signed-off-by: Peter Lieven <pl@kamp.de>
2014-06-17 14:54:05 +02:00
Peter Lieven
81921e3762 pdu: handle async target requests logout events
Signed-off-by: Peter Lieven <pl@kamp.de>
2014-06-17 14:52:27 +02:00
Peter Lieven
98bbeab664 pdu: introduce ISCSI_PDU_URGENT_DELIVERY
Signed-off-by: Peter Lieven <pl@kamp.de>
2014-06-17 14:50:41 +02:00
Peter Lieven
344b21d37d logout: allow additional PDU flags to be passed internally
Signed-off-by: Peter Lieven <pl@kamp.de>
2014-06-17 14:43:54 +02:00
Peter Lieven
e940f95769 logout: cork socket after logout has been sent
Signed-off-by: Peter Lieven <pl@kamp.de>
2014-06-17 14:42:21 +02:00
Peter Lieven
99585b6996 pdu: introduce ISCSI_PDU_CORK_WHEN_SENT
Signed-off-by: Peter Lieven <pl@kamp.de>
2014-06-17 14:42:08 +02:00
Peter Lieven
5d55d32adb socket: do not stop sending for immediate PDUs
Signed-off-by: Peter Lieven <pl@kamp.de>
2014-06-17 14:42:00 +02:00
Paolo Bonzini
267343dca5 bump ABI version again
1.10 and 1.11 both introduced incompatible changes to the
libiscsi ABI.  Please do not do that, and feel free to Cc
me on any patch that touches include/.  In the meanwhile,
bump the soname of the library.  I suggest releasing 1.11.1
with this change for distros.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2014-06-10 13:38:46 +02:00
Michael Tokarev
d7ab603ba0 format string cast ptrdiff on 32bit arch (#747262)
Cast ptrdiff (diff between two pointers) to long to fix printfs.
This fixes FTBFS on 32bit architectures.

Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
2014-05-07 06:49:02 -07:00
Ronnie Sahlberg
717b95cb8a slist.h: rename SLIST_ to ISCSI_LIST_ to avoid clash on *BSD
Rename the macros for managing the linked lists from SLIST_* to ISCSI_LIST_*
to avoid a clash on *BSD which already have other macros SLIST_*

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2014-05-07 06:44:19 -07:00
Ronnie Sahlberg
fe669580ee New version 1.11.0
This version contains changes for:
 - Fix memory leaks in persistent reserve out.
 - Fix various leaks in the testsuite.
 - Add additional READ16 tests
 - Better logging when reconnect fails.
 - Discovery and Login fixes.
 - Various fixes found by coverity.
 - WRITESAME test updates.
 - Add XML oputput support for the testsuite.
and various other things.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2014-04-19 12:06:45 -07:00
Ronnie Sahlberg
24601a36ee MAKEFILE.AM cleanups 2014-03-22 18:21:27 -07:00
Ronnie Sahlberg
65d3597c1b AUTOTOOLS: Create Makefile.am for lib 2014-03-22 13:10:15 -07:00
Ronnie Sahlberg
354f00fd4f Discovery: Create a list of portals for each discovered target.
Some targets return multiple TargetAddress for individual targets.
Create a linked list of addresses for each target instead of
failing the discovery process when this happens.
2014-01-15 19:37:40 -08:00
Michael Tokarev
120b308741 Spelling fixes: Dont => Don't
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
2013-12-16 18:19:24 -08:00
Paolo Bonzini
34b93c4cfd fix CHAP authentication
Empty discovery and login packets are legal, and have the same behavior
as packets with a single NUL in them.  Introduced by commit 94d73fc
(Merge pull request #83 from bonzini/coverity, 2013-11-05).

Reported-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2013-12-12 17:06:06 +01:00
Ronnie Sahlberg
78e49f1427 Coding style update 2013-11-05 17:59:55 -08:00
Ronnie Sahlberg
e59c336450 Use <ptr> == NULL instead of !<ptr> 2013-11-05 17:53:10 -08:00
Paolo Bonzini
87ee645621 check for a target being there before processing TargetAddress
Otherwise we access a NULL pointer.  RFC3270 appendix D confirms
that TargetName must always come before TargetAddress.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2013-11-05 15:38:38 +01:00
Paolo Bonzini
bfde497565 rework login and discovery code to avoid strlen beyond end of data
Checking for the presence of the NUL character should be done
without accessing beyond the PDU datain.  Use memchr instead
of strlen, and compute the length only if a NUL character is
actually there.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2013-11-05 14:32:34 +01:00
Paolo Bonzini
bb0e59055a handle bad iscsi->fd in iscsi_service
Just do nothing if the file descriptor is invalid.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2013-11-05 14:31:16 +01:00
Paolo Bonzini
fce94c81a3 do not test arrays against NULL
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2013-11-05 14:24:56 +01:00
Paolo Bonzini
dbaa0b4ea6 exit after malloc failure when allocating sense data blob
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2013-11-05 14:24:56 +01:00
Paolo Bonzini
1acce4a948 log failures (typically malloc) of iscsi_create_context during reconnect
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2013-11-05 14:24:56 +01:00
Paolo Bonzini
c3e8d0c945 reconnect: do not initialize iscsi to old_iscsi, use old_iscsi if appropriate
Makes it clearer that logging has to be done on the existing context,
since the "iscsi" pointer will not survive iscsi_reconnect.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2013-11-05 14:24:56 +01:00
Bart Van Assche
3fdc3f2327 lib: Fix a memory leak in scsi_cdb_persistent_reserve_out()
If scsi_cdb_persistent_reserve_out() succeeds a call to
scsi_free_scsi_task() won't free any memory allocated with scsi_malloc()
in this function because the memset() call in this function overwrites
the task->mem pointer. Move the memset() call up such that it doesn't
clear task->mem. This makes it possible for the caller of this function
to free the memory allocated by this function by calling
scsi_free_scsi_task(). Merge the error handling code such that the code
for freeing memory only occurs once.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
2013-10-23 05:33:07 -07:00
Bart Van Assche
afa076b537 lib: Make scsi_free_scsi_task() accept a NULL task pointer
Several cleanup paths can be simplified if it is allowed to pass a
NULL pointer to scsi_free_scsi_task(). Hence modify this function
such that it returns immediately if passed a NULL task pointer.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
2013-10-23 05:32:21 -07:00
Ronnie Sahlberg
ccacae482f Merge branch 'master' of github.com:sahlberg/libiscsi 2013-10-14 06:16:31 -07:00
Edward Tomasz Napierala
dd1ca33094 Freebsd build fixes. 2013-10-13 15:35:00 +02:00
Ronnie Sahlberg
fe72f69dfd We dont need _snprintf_s since we have a compatibility function for windows 2013-10-05 21:05:42 -07:00
Ronnie Sahlberg
305d6e1644 Get rid of a lot of WIN32 ifdefs by providing a compatibility function instead 2013-10-05 17:23:46 -07:00
Ronnie Sahlberg
eec84c2805 Add PowerOnOccured as a sense code we allow and ignore during connect 2013-10-05 17:06:21 -07:00
Ronnie Sahlberg
d7b7c7727a Fix win32 so it works again 2013-10-05 15:34:56 -07:00
Ronnie Sahlberg
27b82512d5 Remove 'inline'. Some compilers do not support it. 2013-10-05 13:50:55 -07:00
Ronnie Sahlberg
1828481ba2 Portability fixes. Declare variables at the start of a scope only. 2013-10-05 13:48:00 -07:00
Ronnie Sahlberg
720e426c92 Always declare variables at the start of a new scope. 2013-10-05 13:43:10 -07:00
Bart Van Assche
4653cd8df4 iscsi_reconnect: Fix a use-after-free
This patch fixes the following Valgrind complaint:

Invalid read of size 4
   at 0x524A858: iscsi_reconnect (connect.c:378)
   by 0x5258794: iscsi_service (socket.c:707)
   by 0x52599C4: event_loop (sync.c:67)
   by 0x525AFD7: iscsi_reserve6_sync (sync.c:1096)
   by 0x40A40A: reserve6 (iscsi-support.c:3291)
   by 0x422C95: test_reserve6_target_warm_reset (test_reserve6_target_warm_reset.c:39)
   by 0x503B05F: ??? (in /usr/lib/libcunit.so.1.0.1)
   by 0x503B375: ??? (in /usr/lib/libcunit.so.1.0.1)
   by 0x503B69F: CU_run_all_tests (in /usr/lib/libcunit.so.1.0.1)
   by 0x403171: main (iscsi-test-cu.c:1258)
 Address 0x6443958 is 3,032 bytes inside a block of size 4,120 free'd
   at 0x4C2B83A: free (vg_replace_malloc.c:468)
   by 0x524A846: iscsi_reconnect (connect.c:374)
   by 0x5258794: iscsi_service (socket.c:707)
   by 0x52599C4: event_loop (sync.c:67)
   by 0x525AFD7: iscsi_reserve6_sync (sync.c:1096)
   by 0x40A40A: reserve6 (iscsi-support.c:3291)
   by 0x422C95: test_reserve6_target_warm_reset (test_reserve6_target_warm_reset.c:39)
   by 0x503B05F: ??? (in /usr/lib/libcunit.so.1.0.1)
   by 0x503B375: ??? (in /usr/lib/libcunit.so.1.0.1)
   by 0x503B69F: CU_run_all_tests (in /usr/lib/libcunit.so.1.0.1)
   by 0x403171: main (iscsi-test-cu.c:1258)

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
2013-10-01 06:24:07 -07:00
Ronnie Sahlberg
766d92221c Reconnect: recalculate the header digest when we re-queue after a reconnect 2013-09-26 18:26:29 -07:00