Commit Graph

286 Commits

Author SHA1 Message Date
Ronnie Sahlberg
6eb523af64 Merge pull request #45 from plieven/nest-scsi_cbdata
ISCSI_PDU nest iscsi_scsi_cbdata
2012-11-29 06:36:06 -08:00
Peter Lieven
562dd46833 PDU avoid incrementing itt to 0xffffffff
This patch avoid incrementing itt to 0xffffffff which is
a reserved value for immediate pdus. Avoid incrementing
it to 0xfffffff to avoid unexpected behaviour.

Signed-off-by: Peter Lieven <pl@kamp.de>
2012-11-28 10:58:33 +01:00
Peter Lieven
cd09c0f17d PDU use serial32 arithmetic for cmdsn, maxcmdsn and expcmdsn.
RFC3720 says that cmdsn comparison must be done using
serial32 arithmetic. This will definetly avoid a deadlock
if cmdsn wraps from 2^32-1 to 0.

Signed-off-by: Peter Lieven <pl@kamp.de>
2012-11-28 10:37:28 +01:00
Ronnie Sahlberg
700d363a88 Create a wrapper function for when we add pdus to the out queue
so that we can add them so that they are send in increasing itt order.
2012-11-27 20:26:13 -08:00
Peter Lieven
d9f0464232 ISCSI_PDU nest iscsi_scsi_cbdata
We can simply next the iscsi_scsi_cbdata in the iscsi_pdu struct
since it is only used inside the iscsi_pdu.

This saves one malloc for each pdu.

Signed-off-by: Peter Lieven <pl@kamp.de>
2012-11-27 11:48:53 +01:00
Ronnie Sahlberg
9f741ad2e3 Remove the iscsi data alloc_size field.
Avoiding to realloc data over and over should rather be handled with something
similar to iovectors instead.
2012-11-25 19:22:37 -08:00
Ronnie Sahlberg
bb755104e5 Remove iscsi_allocate_pdu_with_itt_flags_size()
We dont need this anymore.
2012-11-25 19:11:51 -08:00
Ronnie Sahlberg
7b1c0a19bb Remove iscsi_allocate_pdu_size. This is not use any more. 2012-11-25 19:02:34 -08:00
Ronnie Sahlberg
4237d8c257 Remove 'nidata' from the iscsi pdu structure. We dont use it any more. 2012-11-25 19:01:26 -08:00
Ronnie Sahlberg
cbfb086d40 Update the documentation for read/write iovectors 2012-11-25 18:56:33 -08:00
Ronnie Sahlberg
3ac9fdcbff Change iscsi_scsi_command_async() to use iovectors for writes.
Change iscsi_scsi_command_async() to write data-out using iovectors
attached to the scsi task structure instead of copying the data into
the buffer holding the header.
Still allow passing the data via an argument to the funtcion so that the
ABI does not change but then just conver the data to an iovector.

Update the write_to_socket functions to know about the iovectors and write them
as part of the pdu.

Convert write10_task to use iovectors.

This will allow 'zero-copy' writes through libiscsi.
However, as 'zero-copy writes does mean that we do more send() calls into
the kernel this may degrade performance for very small i/o.

A scsi write will not take at least 2 send() calls.
One send call for the iscsi header structure and a second send call for the
payload data.
This will be more expensive than the old memcpy() of payload data plus one send() call since the send() will be a lot more expensive than memcpy() of a small amount of data.
2012-11-25 18:17:51 -08:00
Ronnie Sahlberg
beed0809a5 Fix indentation 2012-11-25 14:12:33 -08:00
Bernhard Kohl
7e4b33dd31 scsi-lowlevel: make scsi_get_uint16/32() global and add scsi_set_uint16/32()
This is a preparation to use the (un)marshalling functions anywhere
in the library.

Signed-off-by: Bernhard Kohl <bernhard.kohl@gmx.net>
2012-11-23 16:46:03 -08:00
Peter Lieven
e7cc6dc1ca SCSI add support for POSIX compatible iovectos
This patch defines an scsi_iovec struct which is guaranteed
to be POSIX compatible. It furthermore adds support for
in+out iovectors for bi-directional operations
Signed-off-by: Peter Lieven <pl@kamp.de>
2012-11-23 15:43:00 +01:00
Peter Lieven
55f76cfb0c SCSI add support for iovectors
If an application passes buffers to libiscsi for reading they are
currently added to a linked list one by one. This leads to a malloc
for each buffer object plus O(n) walks trough the list to add
the buffer to then end of the list. Additionally the buffer read
routine takes up to O(n) iterations to find the right buffer
for a request.

This patch introduces an scsi_iovector struct to pass buffers to
an scsi task. Adding a new buffer is in O(1) and finding the
right buffer to also. Malloc requirements are in O(log(n)).

Additionally the scsi_iovector struct is itended to be binary
compatible to an QEMUIOVector allowing to pass this structure
directly to the library.

Initial tests have been made booting an Ubuntu LTS 12.04.1
Desktop server up to the login prompt. The following observations
have been made with regards to scsi_malloc calls:

original implementation:	~11.500 mallocs
using iovector instead of list:	~ 7.500 mallocs
passing the iovector directly:        0 mallocs

To enable this feature in qemu for testing the following patch might
be used:

diff --git a/block/iscsi.c b/block/iscsi.c
index a6a819d..2809c15 100644
--- a/block/iscsi.c
+++ b/block/iscsi.c
@@ -390,11 +390,16 @@ iscsi_aio_readv(BlockDriverState *bs, int64_t sector_num,
         return NULL;
     }

+#if defined(LIBISCSI_FEATURE_IOVECTOR)
+    assert(sizeof(struct QEMUIOVector) == sizeof(struct scsi_iovector));
+    scsi_iovector_assign(acb->task, (struct scsi_iovector*) acb->qiov);
+#else
     for (i = 0; i < acb->qiov->niov; i++) {
         scsi_task_add_data_in_buffer(acb->task,
                 acb->qiov->iov[i].iov_len,
                 acb->qiov->iov[i].iov_base);
     }
+#endif

     iscsi_set_events(iscsilun);

---
Signed-off-by: Peter Lieven <pl@kamp.de>
2012-11-21 17:02:59 +01:00
Ronnie Sahlberg
4a973e9a4e SCSI: Pass the expected opcode to scsi_cdb_unmarshall()
Pass the opcode we expect to the unmarshalling function so it can do a basic
check that we are trying to unmarshalling the right kind of cdb.
2012-11-20 19:16:42 -08:00
Ronnie Sahlberg
890471c8cc Add support to unmarshall a CDB into a structure and update iscsi-dd
Add two new helper functions scsi_get_uint32() and scsi_get_uint16()
2012-11-20 19:00:55 -08:00
Arne Redlich
5194d13e73 scsi-lowlevel: remove scsi_maintenancein_params and finally scsi_task->params too
Signed-off-by: Arne Redlich <arne.redlich@googlemail.com>
2012-11-18 23:28:32 +01:00
Arne Redlich
8baa843d73 scsi-lowlevel: remove scsi_readtoc_params and fix READ TOC format field
Set the format field in the READ TOC CDB (lower nibble of byte 2).

Signed-off-by: Arne Redlich <arne.redlich@googlemail.com>
2012-11-18 23:16:45 +01:00
Arne Redlich
551298adfb scsi-lowlevel: remove scsi_serviceactionin_params and plug potential memleaks
Signed-off-by: Arne Redlich <arne.redlich@googlemail.com>
2012-11-18 22:57:59 +01:00
Arne Redlich
fa158865d2 scsi-lowlevel: remove scsi_modesense6_params
Signed-off-by: Arne Redlich <arne.redlich@googlemail.com>
2012-11-18 22:47:14 +01:00
Arne Redlich
5f414317dc scsi-lowlevel: remove scsi_inquiry_params and refactor INQUIRY data-in unmarshalling
Split the INQUIRY data-in unmarshalling into smaller chunks, fixing some
potential memory leaks along the way.

Signed-off-by: Arne Redlich <arne.redlich@googlemail.com>
2012-11-18 22:46:04 +01:00
Arne Redlich
b5a9ba6159 scsi-lowlevel: remove scsi_readcapacity10_params
Signed-off-by: Arne Redlich <arne.redlich@googlemail.com>
2012-11-18 22:04:57 +01:00
Arne Redlich
188505a72d scsi-lowlevel: remove scsi_verify16_params
Signed-off-by: Arne Redlich <arne.redlich@googlemail.com>
2012-11-18 21:59:42 +01:00
Arne Redlich
de67d86e64 scsi-lowlevel: remove scsi_verify12_params
Signed-off-by: Arne Redlich <arne.redlich@googlemail.com>
2012-11-18 21:58:30 +01:00
Arne Redlich
10fd2f560b scsi-lowlevel: remove scsi_verify10_params
Signed-off-by: Arne Redlich <arne.redlich@googlemail.com>
2012-11-18 21:57:00 +01:00
Arne Redlich
1dbdd04795 scsi-lowlevel: remove scsi_writeverify16_params
Signed-off-by: Arne Redlich <arne.redlich@googlemail.com>
2012-11-18 21:55:01 +01:00
Arne Redlich
a262d07c4b scsi-lowlevel: remove scsi_writeverify12_params
Signed-off-by: Arne Redlich <arne.redlich@googlemail.com>
2012-11-18 21:53:44 +01:00
Arne Redlich
fff2527cda scsi-lowlevel: remove scsi_writeverify10_params
Signed-off-by: Arne Redlich <arne.redlich@googlemail.com>
2012-11-18 21:52:34 +01:00
Arne Redlich
8169c3e280 scsi-lowlevel: remove scsi_compareandwrite_params
Signed-off-by: Arne Redlich <arne.redlich@googlemail.com>
2012-11-18 21:51:10 +01:00
Arne Redlich
9f7f7f1e0d scsi-lowlevel: remove scsi_orwrite_params
Signed-off-by: Arne Redlich <arne.redlich@googlemail.com>
2012-11-18 21:48:17 +01:00
Arne Redlich
8f513c23f5 scsi-lowlevel: remove scsi_preventallow_params
Signed-off-by: Arne Redlich <arne.redlich@googlemail.com>
2012-11-18 21:46:52 +01:00
Arne Redlich
a02cd53cfc scsi-lowlevel: remove scsi_startstopunit_params
Signed-off-by: Arne Redlich <arne.redlich@googlemail.com>
2012-11-18 21:45:02 +01:00
Arne Redlich
3ec1a2147f scsi-lowlevel: remove scsi_write16_params
Signed-off-by: Arne Redlich <arne.redlich@googlemail.com>
2012-11-18 21:43:15 +01:00
Arne Redlich
f95d86f762 scsi-lowlevel: remove scsi_write12_params
Signed-off-by: Arne Redlich <arne.redlich@googlemail.com>
2012-11-18 21:41:53 +01:00
Arne Redlich
1ca5f447fc scsi-lowlevel: remove scsi_write10_params
Signed-off-by: Arne Redlich <arne.redlich@googlemail.com>
2012-11-18 21:40:27 +01:00
Arne Redlich
daed6117c8 scsi-lowlevel: remove scsi_read16_params
Signed-off-by: Arne Redlich <arne.redlich@googlemail.com>
2012-11-18 21:38:35 +01:00
Arne Redlich
17eff2d8d9 scsi-lowlevel: remove scsi_read12_params
Signed-off-by: Arne Redlich <arne.redlich@googlemail.com>
2012-11-18 21:37:05 +01:00
Arne Redlich
f955449ecc scsi-lowlevel: remove scsi_read10_params
Signed-off-by: Arne Redlich <arne.redlich@googlemail.com>
2012-11-18 21:35:37 +01:00
Arne Redlich
d95e811ccf scsi-lowlevel: remove scsi_read6_params
Signed-off-by: Arne Redlich <arne.redlich@googlemail.com>
2012-11-18 21:34:08 +01:00
Arne Redlich
76aa2693c4 scsi-lowlevel: remove scsi_reportluns_params
Signed-off-by: Arne Redlich <arne.redlich@googlemail.com>
2012-11-18 21:31:11 +01:00
Arne Redlich
44cb5d60c5 iscsi.h: include <sys/types.h> as iscsi_data gained a size_t member
Signed-off-by: Arne Redlich <arne.redlich@googlemail.com>
2012-11-18 00:36:28 +01:00
Peter Lieven
b1374b42ed Rename scsi-command.c to iscsi-command.c 2012-11-12 16:12:29 +01:00
Peter Lieven
8cb369b87f Merge remote-tracking branch 'upstream-git/master'
Conflicts:
	include/iscsi-private.h
	include/iscsi.h
	lib/connect.c
	lib/init.c
	lib/scsi-lowlevel.c
2012-11-12 16:02:57 +01:00
Peter Lieven
5e1d011270 SCSI-LOWLEVEL revert changes to scsi-lowlevel
The memory tracking code reports memory allocated by iscsi_allocate_pdu_with_itt_flags_size() as lost.
This memory is allocated by the iscsi part of libiscsi, but later freed by the lowlevel scsi part. We
will fix this later by introducing an iscsi_task object.
2012-11-12 15:43:29 +01:00
Ronnie Sahlberg
a5b8224f4e Dont include iscsi headers from the scsi implementation in scsi-lowlevel.c 2012-11-11 09:49:49 -08:00
Ronnie Sahlberg
3b05e9996f Move cancel_task and cancel_all_tasks from scsi-lowlevel.c to scsi-command.c
These two functions belong in the iscsi layer, not the scsi layer so move them
out from scsi-lowlevel.c so that we can start turning scsi-lowlevel.c to a pure
scsi layer and remove all dependencies to iscsi from it.
2012-11-11 09:44:11 -08:00
Ronnie Sahlberg
4de36794f2 Make scsi_allocated_memory private to scsi-lowlevel and remove the ptr pointer
Change the list-head structure for in-task scsi memory allocations to
be private to scsi-lowlevel since is is never accessed from anyehwere else and
it is private to this function.
Remove the pointer to the user data in the list head and replace it with a zero length buffer at the end of the header.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2012-11-11 08:07:26 -08:00
Peter Lieven
144026a7bd RECONNECT allow a consecutive reconnect only every 5 seconds
In case there is an error condition e.g. out of memory. We are heavily
disconnecting and reconnecting without any limit. This patch
adds a 5 seconds period that has to go by between 2 reconnects.
2012-11-08 16:56:44 +01:00
Ronnie Sahlberg
50e7c682bb Add a logging subsystem and change all DPRINTF to ISCSI_LOG
Add a mechanism where we can set a logging subsystem that libiscsi can use.
Create an example 'log to stderr' that utilities can use for convenience.
2012-11-07 06:34:38 -08:00