Commit Graph

2131 Commits

Author SHA1 Message Date
Michael Tokarev
0be2be2c31 COPYING: stop mentioning ld_scsi
Fixes: e6bcdf5fdb "drop the LD_PRELOAD tool"
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
2024-02-05 21:19:00 +03:00
Ronnie Sahlberg
d960e6253c New version 1.20.0
Mostly various updates to the test tool

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2024-02-05 16:59:18 +10:00
Ronnie Sahlberg
bfce73325d Merge pull request #411 from folkertvanheusden/task-status
print task-status in hex
2024-01-31 12:57:00 +10:00
folkert van heusden
a51eafa90d Previously, 'task->status' was printed as decimal. In iscsi.h, the
values that are put into it are defined as hexadecimal. This is a bit
confusing (grepping through the code for 251658241 did not result in
anything while the hex variant f000001 resulted in SCSI_STATUS_ERROR).
2024-01-30 19:47:28 +01:00
folkert van heusden
abedc1848c Fix for https://github.com/sahlberg/libiscsi/issues/409
'ms->pages' was not checked for being NULL. This can happen when a
target does not return any pages.
2024-01-30 06:39:08 -08:00
Ronnie Sahlberg
0fac8df48c Merge pull request #406 from pizhenwei/improve-dump-header
Improve dump header
2023-12-01 19:49:13 +10:00
zhenwei pi
384191f57f Improve iSCSI PDU header dump
Dump iSCSI opcode firstly, then dump SCSI opcode for SCSI request.

Signed-off-by: zhenwei pi <pizhenwei@bytedance.com>
2023-12-01 16:42:12 +08:00
zhenwei pi
a6a664e8cb Abstract value_string as common utility
Originally, we use this in scsi-lowlevel.c only, this works as static
function. It also could be used to dump ISCSI opcode, so move it into
common utils.h/utils.c.

Signed-off-by: zhenwei pi <pizhenwei@bytedance.com>
2023-12-01 10:13:20 +08:00
Ronnie Sahlberg
fdd00ee801 Merge pull request #404 from pizhenwei/drain-dataout-pdu-on-timeout
Drain DATAOUT PDU on timeout
2023-11-22 14:43:22 +10:00
zhenwei pi
addb11d64c Drain DATAOUT PDU on timeout
Describe the reason again:
A WRITE16 command[w] handles R2T, and queues DATAOUT PDU m,x,y,z:

          outqueue->DATAOUT[x]->DATAOUT[y]->DATAOUT[z]...
  outqueue_current->DATAOUT[m]
         waitqueue->WRITE16[w]...

1, Once x, y, z gets released in initiator side, the target still expects the remaining
DATAOUT PDUs.
2, Once command w timeout and callback to uplayer, uplayers usually releases memory of
   iscsi task(include memory referenced by iovec.iov_base). DATAOUT[m] would access
   invalid memory iovce.iov_base.

So invoke WRITEx command callback until draining DATAOUT PDUs.

Co-developed-by: Rui Zhang <zhangrui.1203@bytedance.com>
Signed-off-by: zhenwei pi <pizhenwei@bytedance.com>
2023-11-21 16:59:40 +08:00
Ronnie Sahlberg
03e9ddc0a6 Merge pull request #403 from pizhenwei/fix-socket-error-log
Log necessary message on internal reconnect
2023-11-14 02:50:59 -05:00
zhenwei pi
3593362721 Log necessary message on internal reconnect
Once error occurs on socker read/write, libiscsi tries to reconnect
silently. Add necessary log message for this case.

Signed-off-by: zhenwei pi <pizhenwei@bytedance.com>
2023-11-14 15:39:33 +08:00
Ronnie Sahlberg
08f79ebf1d Merge pull request #402 from pizhenwei/debug-info-on-timeout
Debug info on timeout
2023-11-03 14:36:51 +10:00
zhenwei pi
4c3ac5464a Dump opcode string in iscsi_dump_pdu_header()
Now we have more friendly opcode message once error occurs:
libiscsi:1 command timed out from waitqueue [...]
libiscsi:2 PDU header: 01 c1 ... e9 88[READ16] 00 00 00 ...
                                       ^(human readable opcode string)

Signed-off-by: zhenwei pi <pizhenwei@bytedance.com>
2023-11-03 12:18:30 +08:00
zhenwei pi
283e99b322 Introduce helper function scsi_opcode_str
Convert SCSI opcode into string for trouble shooting.

Signed-off-by: zhenwei pi <pizhenwei@bytedance.com>
2023-11-03 12:17:38 +08:00
zhenwei pi
6e8497e53f Declare value-string maps as static
These value-string maps is read-only, it should be constructed once
during loading binary.

Signed-off-by: zhenwei pi <pizhenwei@bytedance.com>
2023-11-03 11:22:38 +08:00
zhenwei pi
a90520da3c Distinguish command timeout
Distinguish command timeout from outqueue or waitqueue. For example,
A command sequence:  ...NOP,READ,WRITE...

NOP OUT command has no dependence on backend media, it is expected to
response soon. Once NOP timeout in libiscsi:
a, the command is already sent to target, the target side does *not*
   response.
b, the command is still pending in libiscsi.

Separate the two cases for trouble shooting.

Signed-off-by: zhenwei pi <pizhenwei@bytedance.com>
2023-11-03 10:54:11 +08:00
Ronnie Sahlberg
c4a180fc4e Merge pull request #401 from pizhenwei/doc-iscsi-md5sum
doc: Add iscsi-md5sum
2023-10-25 13:53:59 +10:00
zhenwei pi
17fc7159b6 doc: Add iscsi-md5sum
Add document for utils/iscsi-md5sum.

Signed-off-by: zhenwei pi <pizhenwei@bytedance.com>
2023-10-25 11:31:55 +08:00
Ronnie Sahlberg
d0cc81347f Merge pull request #399 from anatoliy-glagolev/master
fixup! checking if task is in outqueue
2023-09-21 09:25:02 +10:00
Anatoliy Glagolev
de05f8ecb4 fixup! checking if task is in outqueue 2023-09-20 17:03:31 -06:00
Ronnie Sahlberg
528a3861e7 Merge pull request #398 from anatoliy-glagolev/master
checking if task is in outqueue
2023-09-21 05:56:17 +10:00
Anatoliy Glagolev
e4c4799f29 checking if task is in outqueue
Users need to check if a task is queued to send (not sent yet)
before invoking functions such as iscsi_task_mgmt_abort_task_async.
Otherwise, because task management requests are automatically
treated as "immediate", a request to abort a task is sent before
the task itself.

if (iscsi_scsi_is_task_in_outqueue(iscsi_, task_)) {
    iscsi_scsi_cancel_task(iscsi_, task_);
} else {
    iscsi_task_mgmt_abort_task_async(iscsi_, task_, AbortCb, context_);
}
2023-09-20 12:24:26 -06:00
Ronnie Sahlberg
75a46d2b2e Add add a timeout to the event_loop in sync.c
This timeout can be used to cancel async connect attempts to
a remote target.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2023-09-19 16:16:44 +10:00
Ronnie Sahlberg
a2f9ee5d78 Merge pull request #397 from pizhenwei/iscsi-discard-fix
iscsi-discard: adapt block limits
2023-08-14 12:57:23 +10:00
zhenwei pi
2794079fef iscsi-discard: adapt block limits
The blocks may exceed the block limits offered by the target,
query unmap/write zero max blocks by inquiry
SCSI_INQUIRY_PAGECODE_BLOCK_LIMITS command, than use a loop to do the
job.

Signed-off-by: zhenwei pi <pizhenwei@bytedance.com>
2023-08-08 15:07:23 +08:00
Ronnie Sahlberg
7577ec589c Merge pull request #396 from pizhenwei/iscsi-md5sum
Iscsi md5sum
2023-08-04 19:55:11 +10:00
zhenwei pi
29e46fe290 gitignore: Add utils/iscsi-md5sum
Signed-off-by: zhenwei pi <pizhenwei@bytedance.com>
2023-07-31 15:39:53 +08:00
zhenwei pi
45b274aec8 iscsi-md5sum: Add new tool
The new tool 'iscsi-md5sum' is used to calculate MD5 value of an iSCSI
target. This help users to verify data at range [LBA, Length).

For example, double-write on a RAID1 of 2 iSCSI targets, a daemon
process runs iscsi-md5sum to check data periodically.

Originally, we have to use several steps to achieve:
1, use iscsiadm to login.(root privilege required)
2, use dd(dd if=/dev/sdX of=/TMPPATH bs=4k count=LENGTH skip=LBA)
   to dump data. (root privilege required, additional disk space required)
3, use md5sum to calculate MD5 value
4, remove data.

Instead, a single command iscsi-md5sum without root privilege is enough.

Signed-off-by: zhenwei pi <pizhenwei@bytedance.com>
2023-07-31 15:29:11 +08:00
Ronnie Sahlberg
9e9a3e8198 Merge pull request #395 from pizhenwei/iscsi-discard
Iscsi discard
2023-07-22 17:06:00 +10:00
zhenwei pi
ae6909fd31 gitignore: add utils/iscsi-discard
Signed-off-by: zhenwei pi <pizhenwei@bytedance.com>
2023-07-21 18:19:51 +08:00
zhenwei pi
d631b08c19 iscsi-discard: Add new tool
The new tool 'iscsi-discard' is used to excute unmap or write zeros
on an ISCSI target. The parameters look like the command 'blkdiscard'
(from util-linux).

Signed-off-by: zhenwei pi <pizhenwei@bytedance.com>
2023-07-21 18:15:45 +08:00
zhenwei pi
6e2c677553 utils: use strtol instead of atoi
HEX format is friendly to iSCSI utils, for example:
./iscsi-inq -e 0x1 -c 0xb1 iscsi://...

atoi supports decimal only, this example does not work.
Use strtol(nptr, NULL, 0) to auto-detect format, then this works fine.

Signed-off-by: zhenwei pi <pizhenwei@bytedance.com>
2023-07-08 07:44:16 -07:00
Ronnie Sahlberg
9ca47316f4 Merge pull request #393 from pizhenwei/on-fd-dup
Add iscsi_set_fd_dup_cb
2023-06-06 16:11:30 +10:00
zhenwei pi
7bf8091013 Add iscsi_set_fd_dup_cb
libiscsi is widely used by poll driven, include libiscsi itself,
QEMU. Using poll works fine after iscsi reconnect, but it does not work
in epoll, because the epoll event has been removed during duplicating
file descriptor in kernel.

Add a new function iscsi_set_fd_dup_cb to set callback, then uplayer
gets notified after duplicating. The following codes reproduce this
issue, and test this patch by compiling flags -DISCSI_FD_DUP_CB.

static void iscsi_epoll_event(struct iscsi_context *iscsi, int epollfd, bool new)
{
	static int epoll_event;
	struct epoll_event ev = { 0 };
	int pevent = iscsi_which_events(iscsi);
	int event = 0;

	if (pevent & POLLIN)
		event |= EPOLLIN;

	if (pevent & POLLOUT)
		event |= EPOLLOUT;

	ev.events = event;
	ev.data.fd = iscsi_get_fd(iscsi);
	if (new)
		epoll_ctl(epollfd, EPOLL_CTL_ADD, ev.data.fd, &ev);
	else if (epoll_event != event) {
		epoll_ctl(epollfd, EPOLL_CTL_MOD, ev.data.fd, &ev);
	}
	epoll_event = event;
}

static void iscsi_tsk_cb(struct iscsi_context *iscsi, int status, void *command_data, void *private_data)
{
	printf("iscsi_tsk_cb status %d\n", status);
	exit(0);
}

static void iscsi_fd_dup_cb(struct iscsi_context *iscsi, void *opaque)
{
	int epollfd = *(int *)opaque;

	iscsi_epoll_event(iscsi, epollfd, true);
}

static void iscsi_on_pollout(struct iscsi_context *iscsi, struct iscsi_url *iscsi_url, int epollfd)
{
	static struct scsi_task *tsk = NULL;

	iscsi_service(iscsi, POLLOUT);
	if (!tsk) {
		tsk = iscsi_readcapacity16_task(iscsi, iscsi_url->lun, iscsi_tsk_cb, NULL);
		assert(tsk);
	}
}

int main(int argc, char *argv[])
{
	struct iscsi_context *iscsi;
	struct iscsi_url *iscsi_url;
	struct epoll_event ev, revent;
	int epollfd;

	iscsi = iscsi_create_context("dummy");
	assert(iscsi);

	iscsi_url = iscsi_parse_full_url(iscsi, argv[1]);
	assert(iscsi_url);

	iscsi_set_session_type(iscsi, ISCSI_SESSION_NORMAL);
	iscsi_set_header_digest(iscsi, ISCSI_HEADER_DIGEST_NONE_CRC32C);
	assert(!iscsi_full_connect_sync(iscsi, iscsi_url->portal, iscsi_url->lun));

	epollfd = epoll_create1(0);
	iscsi_epoll_event(iscsi, epollfd, true);

	iscsi_set_fd_dup_cb(iscsi, iscsi_fd_dup_cb, &epollfd);
	iscsi_reconnect(iscsi);

	while (epoll_wait(epollfd, &revent, 1, 100) >= 0) {
		if (revent.events & EPOLLIN)
			iscsi_service(iscsi, POLLIN);

		if (revent.events & EPOLLOUT)
			iscsi_on_pollout(iscsi, iscsi_url, epollfd);

		iscsi_epoll_event(iscsi, epollfd, false);
	}

	return 0;
}

Signed-off-by: zhenwei pi <pizhenwei@bytedance.com>
2023-06-06 13:29:52 +08:00
zhenwei pi
5233a80de4 Add /utils/iscsi-pr into .gitignore
Signed-off-by: zhenwei pi <pizhenwei@bytedance.com>
2023-05-31 06:49:59 -07:00
zhenwei pi
2b9d5bdbad iscsi-perf: Add -h/--help
Add -h/--help to show usage without "Unrecognized option".

Signed-off-by: zhenwei pi <pizhenwei@bytedance.com>
2023-05-31 06:49:59 -07:00
Li kunyu
22f7b26567 iser: Remove unnecessary 'return;'
Signed-off-by: Li kunyu <kunyu@nfschina.com>
2023-02-08 09:01:15 -08:00
Li kunyu
82846758e1 pdu: Remove temporary variables from functions
Signed-off-by: Li kunyu <kunyu@nfschina.com>
2023-01-07 13:26:54 -08:00
Ronnie Sahlberg
2f30d3acee Merge pull request #389 from likunyur/likunyu
aros_compat: Add check after malloc allocation
2022-12-14 20:15:19 +10:00
Li kunyu
c0fdc4655a connect: Add check after malloc allocation 2022-12-14 14:47:05 +08:00
Li kunyu
583211a52f aros_compat: Add check after malloc allocation 2022-12-14 11:33:19 +08:00
Bart Van Assche
be9e2d70cb ci/build.sh: Enable parallel compilation 2022-11-12 18:16:17 -08:00
Bart Van Assche
c23545c604 ci: Fix the Appveyor Linux and Windows builds 2022-11-12 18:13:26 -08:00
Bart Van Assche
3fe06e8563 ci: Add ci/install.bat
Move the MinGW package installation commands from ci/build.sh into
ci/install.sh.
2022-11-12 18:12:45 -08:00
Ronnie Sahlberg
505b2a0ab4 Merge pull request #387 from lgtm-migrator/codeql
Add CodeQL workflow for GitHub code scanning
2022-11-09 07:59:43 +10:00
LGTM Migrator
2229f42246 Add CodeQL workflow for GitHub code scanning 2022-11-08 13:08:20 +00:00
Li kunyu
6b520bee52 test-tool: remove a redundant semicolon
Signed-off-by: Li kunyu <kunyu@nfschina.com>
2022-10-08 20:34:36 -07:00
Bart Van Assche
51df0d0512 lib/scsi-lowlevel: Make the REPORT LUNS unmarshalling code more flexible
Instead of rejecting REPORT LUNS responses if the data buffer size exceeds
the LUN list size, truncate the data buffer.

Fixes: https://github.com/sahlberg/libiscsi/issues/385
2022-09-09 15:02:44 -07:00
sallyjunjun
1017435ca9 Fix segmentation fault problem.
When execute iscsi_task_mgmt_lun_reset_async function,
pdus are already removed from waitpdu list. In iscsi_service
function, this will call iscsi_process_pdu and release
pdu from waitpdu again, which cause segmentation fault.

Whether waitpud list is NULL should be checked here to avoid
the problem.

Signed-off-by: geruijun <geruijun@huawei.com>
2022-06-14 20:49:09 -07:00