iscsi: Initial iscsi statistics for stgt.

This patch implements some statistics information for the iscsi.

Signed-off-by: Daniel Henrique Debonzi <debonzi@linux.vnet.ibm.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Add ua_sense_add_it_nexus function

Add function to allow setting of unit attention on the nexus_id and
logical unit provided.

Signed-off-by: Mike Anderson <andmike@linux.vnet.ibm.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Fix issue with returning full key on read.

On read reservation only 32 bits was being returned. Change to using
put_unaligned_be64 in spc_pr_read_reservation.

Signed-off-by: Mike Anderson <andmike@linux.vnet.ibm.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Fix hang issue in spc_pr_preempt

Address issue in spc_pr_preempt where the goto was leading to
endless loop. The unit attentions where not being set for
reservation released and reservation preempted cases.

Signed-off-by: Mike Anderson <andmike@linux.vnet.ibm.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Fix spc_pr_clear setting UA on wrong nexus

Fixed issue of unit attention being created for the wrong nexus. Switched
to using another sense add function.

Signed-off-by: Mike Anderson <andmike@linux.vnet.ibm.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
retry O_RDONLY again

Update bs_*_open() to try to open the backend file in read-only mode
in case the normal open in O_RDWR fails with EACCES.

If so, automatically flag this lun as read-only.

This allows files for read-only LUNS (read-only disk files and/or
cd/dvd iso extra attributes.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
tgtimg: use posix_fallocate for image creation

Use posix_fallocate() to create the disk image file instead of writing
the data. This plays nicer with the vm system.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
free target->redirect_info.callback upon iscsi target release

Added missing free() of target->redirect_info.callback upon iscsi target
release. When set, this field refers to a strdup'ed string.

Signed-off-by: Alexander Nezhinsky <alexandern@voltaire.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
tgt 1.0.10

Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
fix READ_CAPACITY_16

This fixes the 551b64ed34dbb43d6d6530a91d122c0b4d0131bd commit
regression.

Old kernels request 12 bytes for READ_CAPACITY_16. So we return
invalid data.

Reported-by: Robert Lawrence <robert@bluehost.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Tested-by: Robert Lawrence <robert@bluehost.com>
iscsi: Handle conn_close_force gracefully

Handle the conn_close() properly for forceful close of connection.

Signed-off-by: Chandra Seetharaman <sekharan@us.ibm.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
iscsi: release of the current tx task on conn_close

Fixes a bug with user-initiated disconnect that led to failures in
deleting the logical unit and target, during concurrent I/O.

Typically, the error messages were:
> tgtadm: this logical unit is still active
> tgtadm: this target is still active
(as discussed in the thread "back to forced deletion" starting with
http://lists.wpkg.org/pipermail/stgt/2010-September/004095.html)

The current tx task (conn->tx_task) was freed using the basic function
iscsi_free_task(), while all other pending tx tasks are freed differentially,
according to their type.

The current tx task also should be freed differentially, or else the task
hash table of the nexus remains non-empty and the target is declared active.

To achieve this the current tx task is added to the list of pending tx tasks
just before their release, so that it is freed according to the same policy.

Signed-off-by: Alexander Nezhinsky <alexandern@voltaire.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
tgt 1.0.11

Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
DEBUG mode in Makefile

Added DEBUG symbol for Makefile. If defined in the command line as DEBUG=1
it turns off the optimizations, makes the binary (thru the compilation flags)
to include line info and to be gdb-friendly.

Signed-off-by: Alexander Nezhinsky <alexandern@voltaire.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
iscsi: handling errors in redirect command output

Fixed handling of erroneous output from the dynamic redirect cmd.
Currently such failures don't not make their way up the call stack,
and the initiator is left in logged-in state.
This fix returns negative ret code if redir cmd processing failed,
and adds sending login target error when this happens, as the reaction
to the negative retcode.

Signed-off-by: Alexander Nezhinsky <alexandern@voltaire.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
doc: tgtadm manpage update

Add a section to the tgtadm manpage on how to set and view digests.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Added support for user-defined block size

The rationale is for using with devices (notably SSDs) that allow
formatting with sector size different from 512B. If such device
is formatted to a greater value, but tgt reports its sector size
to be 512B, all commands referencing device sectors and/or extents
will address wrong locations, some of which will be even out of
the device's capacity.

This patch follows the patch posted here:
http://lists.wpkg.org/pipermail/stgt/2009-December/003469.html
and elaborates the suggested functionality a bit further.

The default block size is maintained by sbc (block devices).
It is set to 512B. After this all block devices will report
the passed block sz value during scsi inquiries.

Block size can be set for individual luns as well using
--params blocksize=4096,...
among the parameters of new logical unit through tgtadm.

This may be used in scripts as follows:
--params blocksize=`blockdev --getss /dev/sdd`
In this case lun specific setting overrides sbc default.

Tha actual per lun is displayed through -m target -o show.

Signed-off-by: Alexander Nezhinsky <alexandern@voltaire.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
redirect callback printout in target info show

Added redirect callback printout to iscsi_target_show(), which is called
when "tgtadm --mode target --op show --tid ..." is called.
There is precedence of RedirectCallback over static redirect info
(RedirectAddress, RedirectPort, RedirectReason) when a target is checked
for redirection during iscsi login, so this precedence is retained here.

Signed-off-by: Alexander Nezhinsky <alexandern@voltaire.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
tgt 1.0.12

Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
missing "break" statement in tgt_device_create()

Adding a missing "break" statement due to a previous patch.
Thanx to: Ni-Feng Chang <zapchang@gmail.com> for noticing this.

Signed-off-by: Alexander Nezhinsky <alexandern@voltaire.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>