iscsi: Fix leak of task->data

Steps to reproduce: In initiator, dd to the volume and bring the initiator
interface up and down repeatedly. Valgrind of tgtd confirms the leak and
the fix.

If a connection is terminated while tasks are not yet fully received,
task->data will have been allocated but not referred to by a cmd in-
or out-buffer, which happens in iscsi_target_cmd_queue only after the
entire command is received. When freeing tasks for a closed connection,
ensure task->data is freed if it isn't already freed by the pointer
having been copied to scmd in or out buffer.

It might be nicer set task->data to NULL when its reference is copied,
and then we could unconditionally call free() on it in iscsi_free_task,
but task->data is referred to in many other places in iscsid.c. Maybe
those places should refer to the in/out buffers instead?

Reported-by: Tomoaki Nishimura <t-nishimura@hf.jp.nec.com>
Signed-off-by: Andy Grover <agrover@redhat.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
iscsi: Enable more iscsi local params

This patch is restructuring  step done in order to configuring local parameters for tgtd through tgtadm.
Local parameters in this context are parameters that are not negotiated with the initiator.

Currently there is one such parameter i.e. ISCSI_PARAM_MAX_XMIT_DLENGTH and we want to add more e.g. max commands.

This patch aims to standardize the adding and handling of such local parameters by moving them to the end of the list.
A new enumeration was named ISCSI_PARAM_FIRST_LOCAL was added.
Explicit tests done against ISCSI_PARAM_MAX_XMIT_DLENGTH in order not to send a prameter's value to the initiator
were modified to check if the parameter's index is greater or equal to ISCSI_PARAM_FIRST_LOCAL
(where the index of ISCSI_PARAM_MAX_XMIT_DLENGTH is the one of the "first local").

Signed-off-by: Shlomo Pongratz <shlomop@mellanox.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
iscsi: Add MaxQueueCmd iscsi local parameter

Make iscsi max queue commannd configurable. This parameter is local
like "MaxXmitDataSegmentLength" i.e. it is not sent to the
initiator. The dynamic range of the parmater is [1..512] and the
default value is 128, to keep backward compatibility. The following
tgtadm command should be used in order to modify it for a certain
target

$ tgtadm --op update --mode target --tid <target-id> --name=MaxQueueCmd --value=<new-value>

Note that the new value will be applicable only to new sessions. So in
that respect, after modifying the value, if the new value need to be
used the initiator needs to logout and login again.

Signed-off-by: Shlomo Pongratz <shlomop@mellanox.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Fix double-free and add comment in iscsi_free_task

This patch fixes my previous patch to not crash due to double-free,
and also adds a comment.

Signed-off-by: Andy Grover <agrover@redhat.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Add bash-completion

Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Include bash-completion into RPM package

Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Include bash-completion into DEB package

Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
iser: Don't wait until iser_ib_init to init list_heads

iser_ib_init exits before initializing list heads if no IB present. This
will cause assert to fire.

see https://bugzilla.redhat.com/show_bug.cgi?id=995750

Signed-off-by: Andy Grover <agrover@redhat.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
iser: Don't release IB resources if were not allocated

The lld exit function is being called even if the lld was not
initialized.  Added a check if IB resources were allocated before
trying to release.

Signed-off-by: Roi Dayan <roid@mellanox.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Fix possible segfault on logicalunit update

When updating logicalunit with tgtdadm without any params
tgtd will segfault when calling strncmp on NULL.
The call to strsep later is ok and will return NULL.

To reproduce create a target with a lun and run:
tgtadm -m logicalunit -o update --tid 1 --lun 1

Signed-off-by: Roi Dayan <roid@mellanox.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
tgt 1.0.39

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