TESTS: Fix READ6 test

Commit 45a3752d163a2348918690084405293c62f5eebb skips all tests from
read-at-eol onwards when the LUN is large. Fix this by only skipping the
read-at-eol tests in this scenario.

Signed-off-by: Sitsofe Wheeler <sitsofe@yahoo.com>
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>
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>
test tool, RESERVE(6) tests: Avoid leaking 'iscsi2'

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
test tool, WRITESAME(16) UNMAP test: Avoid leaking 'buf' if a precondition fails

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
test tool: Fix a memory leak in testunitready_clear_ua()

Avoid leaking 'task' if task->status != SCSI_STATUS_GOOD.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
test tool: Fix a memory leak in test_preventallow_logout.c

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
test tool: Fix a memory leak in test-tool/test_reserve6_logout.c

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
test tool: Fix memory leaks in test setup and teardown functions

Free read_write_buf and task after each test. Free iscsi2 after
each PGR test when using CUnit version 2. Note: CUnit version 1
doesn't support test setup and teardown functions.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
test tool: Fix a memory leak in test_reserve6_lun_reset.c

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Add two additional READ16-beyond-eol tests

This helps testing SCSI target implementations that represent the
byte offset from the start of the device as a signed or unsigned
64-bit integer.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
test-tool/0184_writesame10_0blocks.c: Include WSNZ bit in test

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Merge pull request #82 from plieven/master

introduce LIBISCSI_API_VERSION
Merge pull request #77 from sitsofe/read6

TESTS: Fix READ6 test
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>
log failures (typically malloc) of iscsi_create_context during reconnect

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
exit after malloc failure when allocating sense data blob

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
do not test arrays against NULL

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
handle bad iscsi->fd in iscsi_service

Just do nothing if the file descriptor is invalid.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
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>