diff --git a/Makefile.am b/Makefile.am index abefb53..bc1e08b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -29,5 +29,5 @@ pkgconfig_DATA = libiscsi.pc iscsi_includedir = $(includedir)/iscsi dist_iscsi_include_HEADERS = include/iscsi.h include/scsi-lowlevel.h dist_noinst_HEADERS = include/iscsi-private.h include/md5.h include/slist.h \ - include/iser-private.h include/utils.h + include/iser-private.h include/iscsi-multithreading.h include/utils.h diff --git a/examples/Makefile.am b/examples/Makefile.am index 0d39978..bc00f6c 100644 --- a/examples/Makefile.am +++ b/examples/Makefile.am @@ -3,4 +3,4 @@ AM_CFLAGS=$(WARN_CFLAGS) AM_LDFLAGS=-no-undefined LIBS=../lib/libiscsi.la -noinst_PROGRAMS = iscsiclient iscsi-dd +noinst_PROGRAMS = iscsiclient iscsi-dd iscsi-pthreads-inq diff --git a/examples/iscsi-pthreads-inq.c b/examples/iscsi-pthreads-inq.c new file mode 100644 index 0000000..64117fd --- /dev/null +++ b/examples/iscsi-pthreads-inq.c @@ -0,0 +1,343 @@ +/* + Copyright (C) 2025 by Ronnie Sahlberg + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, see . +*/ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#ifdef HAVE_POLL_H +#include +#endif + +#include +#include +#include +#include +#include +#include +#include "iscsi.h" +#include "scsi-lowlevel.h" + +const char *initiator = "iqn.2007-10.com.github:sahlberg:libiscsi:iscsi-inq"; + +void inquiry_block_limits(struct scsi_inquiry_block_limits *inq) +{ + printf("wsnz:%d\n", inq->wsnz); + printf("maximum compare and write length:%" PRIu8 "\n", inq->max_cmp); + printf("optimal transfer length granularity:%" PRIu16 "\n", inq->opt_gran); + printf("maximum transfer length:%" PRIu32 "\n", inq->max_xfer_len); + printf("optimal transfer length:%" PRIu32 "\n",inq->opt_xfer_len); + printf("maximum prefetch xdread xdwrite transfer length:%" PRIu32 "\n", inq->max_prefetch); + printf("maximum unmap lba count:%" PRIu32 "\n", inq->max_unmap); + printf("maximum unmap block descriptor count:%" PRIu32 "\n", inq->max_unmap_bdc); + printf("optimal unmap granularity:%" PRIu32 "\n", inq->opt_unmap_gran); + printf("ugavalid:%d\n", inq->ugavalid); + printf("unmap granularity alignment:%" PRIu32 "\n", inq->unmap_gran_align); + printf("maximum write same length:%" PRIu64 "\n", inq->max_ws_len); +} + +void inquiry_logical_block_provisioning(struct scsi_inquiry_logical_block_provisioning *inq) +{ + printf("Threshold Exponent:%d\n", inq->threshold_exponent); + printf("lbpu:%d\n", inq->lbpu); + printf("lbpws:%d\n", inq->lbpws); + printf("lbpws10:%d\n", inq->lbpws10); + printf("lbprz:%d\n", inq->lbprz); + printf("anc_sup:%d\n", inq->anc_sup); + printf("dp:%d\n", inq->dp); + printf("provisioning type:%d\n", inq->provisioning_type); +} + +void inquiry_block_device_characteristics(struct scsi_inquiry_block_device_characteristics *inq) +{ + printf("Medium Rotation Rate:%dRPM\n", inq->medium_rotation_rate); +} + +void inquiry_device_identification(struct scsi_inquiry_device_identification *inq) +{ + struct scsi_inquiry_device_designator *dev; + int i; + + printf("Peripheral Qualifier:%s\n", + scsi_devqualifier_to_str(inq->qualifier)); + printf("Peripheral Device Type:%s\n", + scsi_devtype_to_str(inq->device_type)); + printf("Page Code:(0x%02x) %s\n", + inq->pagecode, scsi_inquiry_pagecode_to_str(inq->pagecode)); + + for (i=0, dev = inq->designators; dev; i++, dev = dev->next) { + printf("DEVICE DESIGNATOR #%d\n", i); + if (dev->piv != 0) { + printf("Device Protocol Identifier:(%d) %s\n", dev->protocol_identifier, scsi_protocol_identifier_to_str(dev->protocol_identifier)); + } + printf("Code Set:(%d) %s\n", dev->code_set, scsi_codeset_to_str(dev->code_set)); + printf("PIV:%d\n", dev->piv); + printf("Association:(%d) %s\n", dev->association, scsi_association_to_str(dev->association)); + printf("Designator Type:(%d) %s\n", dev->designator_type, scsi_designator_type_to_str(dev->designator_type)); + printf("Designator:[%s]\n", dev->designator); + } +} + +void inquiry_unit_serial_number(struct scsi_inquiry_unit_serial_number *inq) +{ + printf("Unit Serial Number:[%s]\n", inq->usn); +} + +void inquiry_supported_pages(struct scsi_inquiry_supported_pages *inq) +{ + int i; + + for (i = 0; i < inq->num_pages; i++) { + printf("Page:0x%02x %s\n", inq->pages[i], scsi_inquiry_pagecode_to_str(inq->pages[i])); + } +} + +void inquiry_standard(struct scsi_inquiry_standard *inq) +{ + int i; + + printf("Peripheral Qualifier:%s\n", + scsi_devqualifier_to_str(inq->qualifier)); + printf("Peripheral Device Type:%s\n", + scsi_devtype_to_str(inq->device_type)); + printf("Removable:%d\n", inq->rmb); + printf("Version:%d %s\n", inq->version, scsi_version_to_str(inq->version)); + printf("NormACA:%d\n", inq->normaca); + printf("HiSup:%d\n", inq->hisup); + printf("ReponseDataFormat:%d\n", inq->response_data_format); + printf("SCCS:%d\n", inq->sccs); + printf("ACC:%d\n", inq->acc); + printf("TPGS:%d\n", inq->tpgs); + printf("3PC:%d\n", inq->threepc); + printf("Protect:%d\n", inq->protect); + printf("EncServ:%d\n", inq->encserv); + printf("MultiP:%d\n", inq->multip); + printf("SYNC:%d\n", inq->sync); + printf("CmdQue:%d\n", inq->cmdque); + printf("Vendor:%s\n", inq->vendor_identification); + printf("Product:%s\n", inq->product_identification); + printf("Revision:%s\n", inq->product_revision_level); + + for (i = 0; i < 8; i++) { + if (inq->version_descriptor[i] == 0) { + continue; + } + + printf("Version Descriptor:%04x %s\n", + inq->version_descriptor[i], + scsi_version_descriptor_to_str( + inq->version_descriptor[i])); + } +} + +void do_inquiry(struct iscsi_context *iscsi, int lun, int evpd, int pc) +{ + struct scsi_task *task; + int full_size; + void *inq; + + /* See how big this inquiry data is */ + task = iscsi_inquiry_sync(iscsi, lun, evpd, pc, 64); + if (task == NULL || task->status != SCSI_STATUS_GOOD) { + fprintf(stderr, "Inquiry command failed : %s\n", iscsi_get_error(iscsi)); + exit(10); + } + + full_size = scsi_datain_getfullsize(task); + if (full_size > task->datain.size) { + scsi_free_scsi_task(task); + + /* we need more data for the full list */ + if ((task = iscsi_inquiry_sync(iscsi, lun, evpd, pc, full_size)) == NULL) { + fprintf(stderr, "Inquiry command failed : %s\n", iscsi_get_error(iscsi)); + exit(10); + } + } + + inq = scsi_datain_unmarshall(task); + if (inq == NULL) { + fprintf(stderr, "failed to unmarshall inquiry datain blob\n"); + exit(10); + } + + if (evpd == 0) { + inquiry_standard(inq); + } else { + switch (pc) { + case SCSI_INQUIRY_PAGECODE_SUPPORTED_VPD_PAGES: + inquiry_supported_pages(inq); + break; + case SCSI_INQUIRY_PAGECODE_UNIT_SERIAL_NUMBER: + inquiry_unit_serial_number(inq); + break; + case SCSI_INQUIRY_PAGECODE_DEVICE_IDENTIFICATION: + inquiry_device_identification(inq); + break; + case SCSI_INQUIRY_PAGECODE_BLOCK_LIMITS: + inquiry_block_limits(inq); + break; + case SCSI_INQUIRY_PAGECODE_BLOCK_DEVICE_CHARACTERISTICS: + inquiry_block_device_characteristics(inq); + break; + case SCSI_INQUIRY_PAGECODE_LOGICAL_BLOCK_PROVISIONING: + inquiry_logical_block_provisioning(inq); + break; + default: + fprintf(stderr, "Usupported pagecode:0x%02x\n", pc); + } + } + scsi_free_scsi_task(task); +} + + +void print_usage(void) +{ + fprintf(stderr, "Usage: iscsi-inq [-?] [-?|--help] [--usage] [-i|--initiator-name=iqn-name]\n" + "\t\t[-e|--evpd=integer] [-c|--pagecode=integer] \n"); +} + +void print_help(void) +{ + fprintf(stderr, "Usage: iscsi-inq [OPTION...] \n"); + fprintf(stderr, " -i, --initiator-name=iqn-name Initiatorname to use\n"); + fprintf(stderr, " -e, --evpd=integer evpd\n"); + fprintf(stderr, " -c, --pagecode=integer page code\n"); + fprintf(stderr, " -d, --debug=integer debug level (0=disabled)\n"); + fprintf(stderr, "\n"); + fprintf(stderr, "Help options:\n"); + fprintf(stderr, " -?, --help Show this help message\n"); + fprintf(stderr, " --usage Display brief usage message\n"); + fprintf(stderr, "\n"); + fprintf(stderr, "iSCSI URL format : %s\n", ISCSI_URL_SYNTAX); + fprintf(stderr, "\n"); + fprintf(stderr, " is either of:\n"); + fprintf(stderr, " \"hostname\" iscsi.example\n"); + fprintf(stderr, " \"ipv4-address\" 10.1.1.27\n"); + fprintf(stderr, " \"ipv6-address\" [fce0::1]\n"); +} + +int main(int argc, char *argv[]) +{ + struct iscsi_context *iscsi; + char *url = NULL; + struct iscsi_url *iscsi_url = NULL; + int evpd = 0, pagecode = 0; + int show_help = 0, show_usage = 0, debug = 0; + int c; + + static struct option long_options[] = { + {"help", no_argument, NULL, 'h'}, + {"usage", no_argument, NULL, 'u'}, + {"debug", required_argument, NULL, 'd'}, + {"initiator-name", required_argument, NULL, 'i'}, + {"evpd", required_argument, NULL, 'e'}, + {"pagecode", required_argument, NULL, 'c'}, + {0, 0, 0, 0} + }; + int option_index; + + while ((c = getopt_long(argc, argv, "h?ud:i:e:c:", long_options, + &option_index)) != -1) { + switch (c) { + case 'h': + case '?': + show_help = 1; + break; + case 'u': + show_usage = 1; + break; + case 'd': + debug = strtol(optarg, NULL, 0); + break; + case 'i': + initiator = optarg; + break; + case 'e': + evpd = strtol(optarg, NULL, 0); + break; + case 'c': + pagecode = strtol(optarg, NULL, 0); + break; + default: + fprintf(stderr, "Unrecognized option '%c'\n\n", c); + print_help(); + exit(0); + } + } + + if (show_help != 0) { + print_help(); + exit(0); + } + + if (show_usage != 0) { + print_usage(); + exit(0); + } + + iscsi = iscsi_create_context(initiator); + if (iscsi == NULL) { + fprintf(stderr, "Failed to create context\n"); + exit(10); + } + + if (debug > 0) { + iscsi_set_log_level(iscsi, debug); + iscsi_set_log_fn(iscsi, iscsi_log_to_stderr); + } + + if (argv[optind] != NULL) { + url = strdup(argv[optind]); + } + if (url == NULL) { + fprintf(stderr, "You must specify the URL\n"); + print_usage(); + exit(10); + } + iscsi_url = iscsi_parse_full_url(iscsi, url); + + free(url); + + if (iscsi_url == NULL) { + fprintf(stderr, "Failed to parse URL: %s\n", + iscsi_get_error(iscsi)); + exit(10); + } + + iscsi_set_session_type(iscsi, ISCSI_SESSION_NORMAL); + iscsi_set_header_digest(iscsi, ISCSI_HEADER_DIGEST_NONE_CRC32C); + + if (iscsi_full_connect_sync(iscsi, iscsi_url->portal, iscsi_url->lun) != 0) { + fprintf(stderr, "Login Failed. %s\n", iscsi_get_error(iscsi)); + iscsi_destroy_url(iscsi_url); + iscsi_destroy_context(iscsi); + exit(10); + } + + if (iscsi_mt_service_thread_start(iscsi)) { + fprintf(stderr, "failed to start service thread\n"); + exit(10); + } + + do_inquiry(iscsi, iscsi_url->lun, evpd, pagecode); + iscsi_destroy_url(iscsi_url); + + iscsi_mt_service_thread_stop(iscsi); + iscsi_logout_sync(iscsi); + iscsi_destroy_context(iscsi); + return 0; +} + diff --git a/include/iscsi-private.h b/include/iscsi-private.h index 8656050..1cd0b5b 100644 --- a/include/iscsi-private.h +++ b/include/iscsi-private.h @@ -37,21 +37,14 @@ atomic_fetch_sub_explicit(&x, 1, memory_order_relaxed) #else /* HAVE_STDATOMIC_H */ #define ATOMIC_INC(rpc, x) \ - if (rpc->multithreading_enabled) { \ - nfs_mt_mutex_lock(&rpc->atomic_int_mutex); \ + iscs_mt_mutex_lock(&iscs->atomic_int_mutex); \ } \ x++; \ - if (rpc->multithreading_enabled) { \ - nfs_mt_mutex_unlock(&rpc->atomic_int_mutex); \ - } + iscsi_mt_mutex_unlock(&iscsi->atomic_int_mutex); #define ATOMIC_DEC(rpc, x) \ - if (rpc->multithreading_enabled) { \ - nfs_mt_mutex_lock(&rpc->atomic_int_mutex); \ - } \ + nfs_mt_mutex_lock(&rpc->atomic_int_mutex); \ x--; \ - if (rpc->multithreading_enabled) { \ - nfs_mt_mutex_unlock(&rpc->atomic_int_mutex); \ - } + nfs_mt_mutex_unlock(&rpc->atomic_int_mutex); #endif /* HAVE_STDATOMIC_H */ #else /* HAVE_MULTITHREADING */ /* no multithreading support, no need to protect the increment */ @@ -223,9 +216,6 @@ struct iscsi_context { libiscsi_mutex_t iscsi_mutex; libiscsi_thread_t service_thread; int poll_timeout; - //libnfs_mutex_t nfs4_open_counter_mutex; - //libnfs_mutex_t nfs4_open_call_mutex; - //struct nfs_thread_context *thread_ctx; #ifndef HAVE_STDATOMIC_H libiscsi_mutex_t atomic_int_mutex; #endif /* HAVE_STDATOMIC_H */ diff --git a/include/iscsi.h b/include/iscsi.h index 375a7d8..d9017bb 100644 --- a/include/iscsi.h +++ b/include/iscsi.h @@ -1702,6 +1702,18 @@ iscsi_set_fd_dup_cb(struct iscsi_context *iscsi, void (*cb)(struct iscsi_context *iscsi, void *opaque), void *opaque); +/* + * MULTITHREADING + */ +/* + * This function starts a separate service thread for multithreading support. + */ +EXTERN int iscsi_mt_service_thread_start(struct iscsi_context *iscsi); +/* + * Shutdown multithreading support. + */ +EXTERN void iscsi_mt_service_thread_stop(struct iscsi_context *iscsi); + #ifdef __cplusplus } #endif diff --git a/lib/libiscsi.def b/lib/libiscsi.def index 65ce2ea..18d7fe3 100644 --- a/lib/libiscsi.def +++ b/lib/libiscsi.def @@ -38,6 +38,8 @@ iscsi_modesense6_sync iscsi_modesense6_task iscsi_modesense10_sync iscsi_modesense10_task +iscsi_mt_service_thread_start +iscsi_mt_service_thread_stop iscsi_nop_out_async iscsi_parse_full_url iscsi_parse_portal_url diff --git a/lib/libiscsi.syms.in b/lib/libiscsi.syms.in index 53fb955..d100968 100644 --- a/lib/libiscsi.syms.in +++ b/lib/libiscsi.syms.in @@ -41,6 +41,8 @@ iscsi_modesense10_sync iscsi_modesense10_task iscsi_modesense6_sync iscsi_modesense6_task +iscsi_mt_service_thread_start +iscsi_mt_service_thread_stop iscsi_nop_out_async iscsi_orwrite_iov_sync iscsi_orwrite_iov_task diff --git a/lib/multithreading.c b/lib/multithreading.c index 138f391..5b57804 100644 --- a/lib/multithreading.c +++ b/lib/multithreading.c @@ -189,6 +189,7 @@ static void *iscsi_mt_service_thread(void *arg) iscsi->multithreading_enabled = 1; + /* TODO: add timeout scanning */ while (iscsi->multithreading_enabled) { pfd.fd = iscsi_get_fd(iscsi); pfd.events = iscsi_which_events(iscsi); diff --git a/lib/pdu.c b/lib/pdu.c index f61e24b..73687d7 100644 --- a/lib/pdu.c +++ b/lib/pdu.c @@ -940,7 +940,17 @@ iscsi_timeout_scan(struct iscsi_context *iscsi) int iscsi_queue_pdu(struct iscsi_context *iscsi, struct iscsi_pdu *pdu) { - return iscsi->drv->queue_pdu(iscsi, pdu); + int ret; + +#ifdef HAVE_MULTITHREADING + iscsi_mt_mutex_lock(&iscsi->iscsi_mutex); +#endif /* HAVE_MULTITHREADING */ + ret = iscsi->drv->queue_pdu(iscsi, pdu); +#ifdef HAVE_MULTITHREADING + iscsi_mt_mutex_unlock(&iscsi->iscsi_mutex); +#endif /* HAVE_MULTITHREADING */ + + return ret; } void diff --git a/lib/sync.c b/lib/sync.c index 562c44f..13013e8 100644 --- a/lib/sync.c +++ b/lib/sync.c @@ -48,6 +48,10 @@ struct iscsi_sync_state { int status; void *ptr; struct scsi_task *task; +#ifdef HAVE_MULTITHREADING + int has_sem; + libiscsi_sem_t wait_sem; +#endif /* HAVE_MULTITHREADING */ }; static void @@ -58,12 +62,21 @@ event_loop(struct iscsi_context *iscsi, struct iscsi_sync_state *state) int ret; time_t t; +#ifdef HAVE_MULTITHREADING + if(iscsi->multithreading_enabled) { + iscsi_mt_sem_wait(&state->wait_sem); + iscsi_mt_sem_destroy(&state->wait_sem); + state->has_sem = 0; + return; + } +#endif + if (iscsi->scsi_timeout) { scsi_timeout = time(NULL) + iscsi->scsi_timeout; } else { scsi_timeout = 0; } - + while (state->finished == 0) { short revents; @@ -118,6 +131,26 @@ iscsi_sync_cb(struct iscsi_context *iscsi, int status, state->status = status; state->finished = 1; +#ifdef HAVE_MULTITHREADING + if (state->has_sem) { + iscsi_mt_sem_post(&state->wait_sem); + } +#endif +} + +static void +iscsi_init_sync_state(struct iscsi_sync_state *state) +{ + memset(state, 0, sizeof(*state)); +#ifdef HAVE_MULTITHREADING + /* + * Create a semaphore and initialize it to zero. So that we + * can wait for it and immetiately block until the service thread + * has received the reply. + */ + iscsi_mt_sem_init(&state->wait_sem, 0); + state->has_sem = 1; +#endif /* HAVE_MULTITHREADING */ } int @@ -125,7 +158,7 @@ iscsi_connect_sync(struct iscsi_context *iscsi, const char *portal) { struct iscsi_sync_state state; - memset(&state, 0, sizeof(state)); + iscsi_init_sync_state(&state); if (iscsi_connect_async(iscsi, portal, iscsi_sync_cb, &state) != 0) { @@ -154,7 +187,7 @@ iscsi_full_connect_sync(struct iscsi_context *iscsi, { struct iscsi_sync_state state; - memset(&state, 0, sizeof(state)); + iscsi_init_sync_state(&state); if (iscsi_full_connect_async(iscsi, portal, lun, iscsi_sync_cb, &state) != 0) { @@ -178,7 +211,7 @@ int iscsi_login_sync(struct iscsi_context *iscsi) { struct iscsi_sync_state state; - memset(&state, 0, sizeof(state)); + iscsi_init_sync_state(&state); if (iscsi_login_async(iscsi, iscsi_sync_cb, &state) != 0) { iscsi_set_error(iscsi, "Failed to login. %s", @@ -195,7 +228,7 @@ int iscsi_logout_sync(struct iscsi_context *iscsi) { struct iscsi_sync_state state; - memset(&state, 0, sizeof(state)); + iscsi_init_sync_state(&state); if (iscsi_logout_async(iscsi, iscsi_sync_cb, &state) != 0) { iscsi_set_error(iscsi, "Failed to start logout() %s", @@ -243,7 +276,7 @@ int iscsi_reconnect_sync(struct iscsi_context *iscsi) { struct iscsi_sync_state state; - memset(&state, 0, sizeof(state)); + iscsi_init_sync_state(&state); if (iscsi_reconnect(iscsi) != 0) { iscsi_set_error(iscsi, "Failed to reconnect. %s", iscsi_get_error(iscsi)); @@ -259,7 +292,7 @@ int iscsi_force_reconnect_sync(struct iscsi_context *iscsi) { struct iscsi_sync_state state; - memset(&state, 0, sizeof(state)); + iscsi_init_sync_state(&state); if (iscsi_force_reconnect(iscsi) != 0) { iscsi_set_error(iscsi, "Failed to reconnect. %s", iscsi_get_error(iscsi)); @@ -313,7 +346,7 @@ iscsi_task_mgmt_sync(struct iscsi_context *iscsi, { struct iscsi_sync_state state; - memset(&state, 0, sizeof(state)); + iscsi_init_sync_state(&state); if (iscsi_task_mgmt_async(iscsi, lun, function, ritt, rcmdsn, @@ -396,6 +429,11 @@ scsi_sync_cb(struct iscsi_context *iscsi, int status, void *command_data, state->status = status; state->finished = 1; state->task = task; +#ifdef HAVE_MULTITHREADING + if (state->has_sem) { + iscsi_mt_sem_post(&state->wait_sem); + } +#endif } struct scsi_task * @@ -404,7 +442,7 @@ iscsi_reportluns_sync(struct iscsi_context *iscsi, int report_type, { struct iscsi_sync_state state; - memset(&state, 0, sizeof(state)); + iscsi_init_sync_state(&state); if (iscsi_reportluns_task(iscsi, report_type, alloc_len, scsi_sync_cb, &state) == NULL) { @@ -423,7 +461,7 @@ iscsi_testunitready_sync(struct iscsi_context *iscsi, int lun) { struct iscsi_sync_state state; - memset(&state, 0, sizeof(state)); + iscsi_init_sync_state(&state); if (iscsi_testunitready_task(iscsi, lun, scsi_sync_cb, &state) == NULL) { @@ -443,7 +481,7 @@ iscsi_inquiry_sync(struct iscsi_context *iscsi, int lun, int evpd, { struct iscsi_sync_state state; - memset(&state, 0, sizeof(state)); + iscsi_init_sync_state(&state); if (iscsi_inquiry_task(iscsi, lun, evpd, page_code, maxsize, scsi_sync_cb, &state) == NULL) { @@ -462,7 +500,7 @@ iscsi_read6_sync(struct iscsi_context *iscsi, int lun, uint32_t lba, { struct iscsi_sync_state state; - memset(&state, 0, sizeof(state)); + iscsi_init_sync_state(&state); if (iscsi_read6_task(iscsi, lun, lba, datalen, blocksize, scsi_sync_cb, &state) == NULL) { @@ -482,7 +520,7 @@ iscsi_read6_iov_sync(struct iscsi_context *iscsi, int lun, uint32_t lba, { struct iscsi_sync_state state; - memset(&state, 0, sizeof(state)); + iscsi_init_sync_state(&state); if (iscsi_read6_iov_task(iscsi, lun, lba, datalen, blocksize, scsi_sync_cb, &state, iov, niov) == NULL) { @@ -503,7 +541,7 @@ iscsi_read10_sync(struct iscsi_context *iscsi, int lun, uint32_t lba, { struct iscsi_sync_state state; - memset(&state, 0, sizeof(state)); + iscsi_init_sync_state(&state); if (iscsi_read10_task(iscsi, lun, lba, datalen, blocksize, rdprotect, dpo, fua, fua_nv, group_number, @@ -526,7 +564,7 @@ iscsi_read10_iov_sync(struct iscsi_context *iscsi, int lun, uint32_t lba, { struct iscsi_sync_state state; - memset(&state, 0, sizeof(state)); + iscsi_init_sync_state(&state); if (iscsi_read10_iov_task(iscsi, lun, lba, datalen, blocksize, rdprotect, dpo, fua, fua_nv, group_number, @@ -548,7 +586,7 @@ iscsi_read12_sync(struct iscsi_context *iscsi, int lun, uint32_t lba, { struct iscsi_sync_state state; - memset(&state, 0, sizeof(state)); + iscsi_init_sync_state(&state); if (iscsi_read12_task(iscsi, lun, lba, datalen, blocksize, rdprotect, dpo, fua, fua_nv, group_number, @@ -571,7 +609,7 @@ iscsi_read12_iov_sync(struct iscsi_context *iscsi, int lun, uint32_t lba, { struct iscsi_sync_state state; - memset(&state, 0, sizeof(state)); + iscsi_init_sync_state(&state); if (iscsi_read12_iov_task(iscsi, lun, lba, datalen, blocksize, rdprotect, dpo, fua, fua_nv, group_number, @@ -593,7 +631,7 @@ iscsi_read16_sync(struct iscsi_context *iscsi, int lun, uint64_t lba, { struct iscsi_sync_state state; - memset(&state, 0, sizeof(state)); + iscsi_init_sync_state(&state); if (iscsi_read16_task(iscsi, lun, lba, datalen, blocksize, rdprotect, dpo, fua, fua_nv, group_number, @@ -616,7 +654,7 @@ iscsi_read16_iov_sync(struct iscsi_context *iscsi, int lun, uint64_t lba, { struct iscsi_sync_state state; - memset(&state, 0, sizeof(state)); + iscsi_init_sync_state(&state); if (iscsi_read16_iov_task(iscsi, lun, lba, datalen, blocksize, rdprotect, dpo, fua, fua_nv, group_number, @@ -637,7 +675,7 @@ iscsi_readcapacity10_sync(struct iscsi_context *iscsi, int lun, int lba, { struct iscsi_sync_state state; - memset(&state, 0, sizeof(state)); + iscsi_init_sync_state(&state); if (iscsi_readcapacity10_task(iscsi, lun, lba, pmi, scsi_sync_cb, &state) == NULL) { @@ -656,7 +694,7 @@ iscsi_readcapacity16_sync(struct iscsi_context *iscsi, int lun) { struct iscsi_sync_state state; - memset(&state, 0, sizeof(state)); + iscsi_init_sync_state(&state); if (iscsi_readcapacity16_task(iscsi, lun, scsi_sync_cb, &state) == NULL) { @@ -677,7 +715,7 @@ iscsi_readdefectdata10_sync(struct iscsi_context *iscsi, int lun, { struct iscsi_sync_state state; - memset(&state, 0, sizeof(state)); + iscsi_init_sync_state(&state); if (iscsi_readdefectdata10_task(iscsi, lun, req_plist, req_glist, @@ -702,7 +740,7 @@ iscsi_readdefectdata12_sync(struct iscsi_context *iscsi, int lun, { struct iscsi_sync_state state; - memset(&state, 0, sizeof(state)); + iscsi_init_sync_state(&state); if (iscsi_readdefectdata12_task(iscsi, lun, req_plist, req_glist, @@ -726,7 +764,7 @@ iscsi_sanitize_sync(struct iscsi_context *iscsi, int lun, { struct iscsi_sync_state state; - memset(&state, 0, sizeof(state)); + iscsi_init_sync_state(&state); if (iscsi_sanitize_task(iscsi, lun, immed, ause, sa, param_len, data, @@ -747,7 +785,7 @@ iscsi_sanitize_block_erase_sync(struct iscsi_context *iscsi, int lun, { struct iscsi_sync_state state; - memset(&state, 0, sizeof(state)); + iscsi_init_sync_state(&state); if (iscsi_sanitize_block_erase_task(iscsi, lun, immed, ause, @@ -768,7 +806,7 @@ iscsi_sanitize_crypto_erase_sync(struct iscsi_context *iscsi, int lun, { struct iscsi_sync_state state; - memset(&state, 0, sizeof(state)); + iscsi_init_sync_state(&state); if (iscsi_sanitize_crypto_erase_task(iscsi, lun, immed, ause, @@ -789,7 +827,7 @@ iscsi_sanitize_exit_failure_mode_sync(struct iscsi_context *iscsi, int lun, { struct iscsi_sync_state state; - memset(&state, 0, sizeof(state)); + iscsi_init_sync_state(&state); if (iscsi_sanitize_exit_failure_mode_task(iscsi, lun, immed, ause, @@ -809,7 +847,7 @@ iscsi_get_lba_status_sync(struct iscsi_context *iscsi, int lun, uint64_t startin { struct iscsi_sync_state state; - memset(&state, 0, sizeof(state)); + iscsi_init_sync_state(&state); if (iscsi_get_lba_status_task(iscsi, lun, starting_lba, alloc_len, scsi_sync_cb, &state) == NULL) { @@ -829,7 +867,7 @@ iscsi_synchronizecache10_sync(struct iscsi_context *iscsi, int lun, int lba, { struct iscsi_sync_state state; - memset(&state, 0, sizeof(state)); + iscsi_init_sync_state(&state); if (iscsi_synchronizecache10_task(iscsi, lun, lba, num_blocks, syncnv, immed, @@ -851,7 +889,7 @@ iscsi_startstopunit_sync(struct iscsi_context *iscsi, int lun, { struct iscsi_sync_state state; - memset(&state, 0, sizeof(state)); + iscsi_init_sync_state(&state); if (iscsi_startstopunit_task(iscsi, lun, immed, pcm, pc, no_flush, loej, start, @@ -872,7 +910,7 @@ iscsi_preventallow_sync(struct iscsi_context *iscsi, int lun, { struct iscsi_sync_state state; - memset(&state, 0, sizeof(state)); + iscsi_init_sync_state(&state); if (iscsi_preventallow_task(iscsi, lun, prevent, scsi_sync_cb, &state) == NULL) { @@ -892,7 +930,7 @@ iscsi_synchronizecache16_sync(struct iscsi_context *iscsi, int lun, uint64_t lba { struct iscsi_sync_state state; - memset(&state, 0, sizeof(state)); + iscsi_init_sync_state(&state); if (iscsi_synchronizecache16_task(iscsi, lun, lba, num_blocks, syncnv, immed, @@ -913,7 +951,7 @@ iscsi_prefetch10_sync(struct iscsi_context *iscsi, int lun, uint32_t lba, { struct iscsi_sync_state state; - memset(&state, 0, sizeof(state)); + iscsi_init_sync_state(&state); if (iscsi_prefetch10_task(iscsi, lun, lba, num_blocks, immed, group, @@ -934,7 +972,7 @@ iscsi_prefetch16_sync(struct iscsi_context *iscsi, int lun, uint64_t lba, { struct iscsi_sync_state state; - memset(&state, 0, sizeof(state)); + iscsi_init_sync_state(&state); if (iscsi_prefetch16_task(iscsi, lun, lba, num_blocks, immed, group, @@ -956,7 +994,7 @@ iscsi_write10_sync(struct iscsi_context *iscsi, int lun, uint32_t lba, { struct iscsi_sync_state state; - memset(&state, 0, sizeof(state)); + iscsi_init_sync_state(&state); if (iscsi_write10_task(iscsi, lun, lba, data, datalen, blocksize, wrprotect, dpo, fua, fua_nv, group_number, @@ -979,7 +1017,7 @@ iscsi_write10_iov_sync(struct iscsi_context *iscsi, int lun, uint32_t lba, { struct iscsi_sync_state state; - memset(&state, 0, sizeof(state)); + iscsi_init_sync_state(&state); if (iscsi_write10_iov_task(iscsi, lun, lba, data, datalen, blocksize, wrprotect, dpo, fua, fua_nv, group_number, @@ -1001,7 +1039,7 @@ iscsi_write12_sync(struct iscsi_context *iscsi, int lun, uint32_t lba, { struct iscsi_sync_state state; - memset(&state, 0, sizeof(state)); + iscsi_init_sync_state(&state); if (iscsi_write12_task(iscsi, lun, lba, data, datalen, blocksize, wrprotect, @@ -1025,7 +1063,7 @@ iscsi_write12_iov_sync(struct iscsi_context *iscsi, int lun, uint32_t lba, { struct iscsi_sync_state state; - memset(&state, 0, sizeof(state)); + iscsi_init_sync_state(&state); if (iscsi_write12_iov_task(iscsi, lun, lba, data, datalen, blocksize, wrprotect, @@ -1048,7 +1086,7 @@ iscsi_write16_sync(struct iscsi_context *iscsi, int lun, uint64_t lba, { struct iscsi_sync_state state; - memset(&state, 0, sizeof(state)); + iscsi_init_sync_state(&state); if (iscsi_write16_task(iscsi, lun, lba, data, datalen, blocksize, wrprotect, @@ -1072,7 +1110,7 @@ iscsi_write16_iov_sync(struct iscsi_context *iscsi, int lun, uint64_t lba, { struct iscsi_sync_state state; - memset(&state, 0, sizeof(state)); + iscsi_init_sync_state(&state); if (iscsi_write16_iov_task(iscsi, lun, lba, data, datalen, blocksize, wrprotect, @@ -1095,7 +1133,7 @@ iscsi_writeatomic16_sync(struct iscsi_context *iscsi, int lun, uint64_t lba, { struct iscsi_sync_state state; - memset(&state, 0, sizeof(state)); + iscsi_init_sync_state(&state); if (iscsi_writeatomic16_task(iscsi, lun, lba, data, datalen, blocksize, wrprotect, @@ -1119,7 +1157,7 @@ iscsi_writeatomic16_iov_sync(struct iscsi_context *iscsi, int lun, uint64_t lba, { struct iscsi_sync_state state; - memset(&state, 0, sizeof(state)); + iscsi_init_sync_state(&state); if (iscsi_writeatomic16_iov_task(iscsi, lun, lba, data, datalen, blocksize, wrprotect, @@ -1142,7 +1180,7 @@ iscsi_orwrite_sync(struct iscsi_context *iscsi, int lun, uint64_t lba, { struct iscsi_sync_state state; - memset(&state, 0, sizeof(state)); + iscsi_init_sync_state(&state); if (iscsi_orwrite_task(iscsi, lun, lba, data, datalen, blocksize, wrprotect, @@ -1166,7 +1204,7 @@ iscsi_orwrite_iov_sync(struct iscsi_context *iscsi, int lun, uint64_t lba, { struct iscsi_sync_state state; - memset(&state, 0, sizeof(state)); + iscsi_init_sync_state(&state); if (iscsi_orwrite_iov_task(iscsi, lun, lba, data, datalen, blocksize, wrprotect, @@ -1189,7 +1227,7 @@ iscsi_compareandwrite_sync(struct iscsi_context *iscsi, int lun, uint64_t lba, { struct iscsi_sync_state state; - memset(&state, 0, sizeof(state)); + iscsi_init_sync_state(&state); if (iscsi_compareandwrite_task(iscsi, lun, lba, data, datalen, blocksize, wrprotect, @@ -1213,7 +1251,7 @@ iscsi_compareandwrite_iov_sync(struct iscsi_context *iscsi, int lun, uint64_t lb { struct iscsi_sync_state state; - memset(&state, 0, sizeof(state)); + iscsi_init_sync_state(&state); if (iscsi_compareandwrite_iov_task(iscsi, lun, lba, data, datalen, blocksize, wrprotect, @@ -1236,7 +1274,7 @@ iscsi_writeverify10_sync(struct iscsi_context *iscsi, int lun, uint32_t lba, { struct iscsi_sync_state state; - memset(&state, 0, sizeof(state)); + iscsi_init_sync_state(&state); if (iscsi_writeverify10_task(iscsi, lun, lba, data, datalen, blocksize, wrprotect, dpo, bytchk, group_number, @@ -1259,7 +1297,7 @@ iscsi_writeverify10_iov_sync(struct iscsi_context *iscsi, int lun, uint32_t lba, { struct iscsi_sync_state state; - memset(&state, 0, sizeof(state)); + iscsi_init_sync_state(&state); if (iscsi_writeverify10_iov_task(iscsi, lun, lba, data, datalen, blocksize, wrprotect, dpo, bytchk, group_number, @@ -1281,7 +1319,7 @@ iscsi_writeverify12_sync(struct iscsi_context *iscsi, int lun, uint32_t lba, { struct iscsi_sync_state state; - memset(&state, 0, sizeof(state)); + iscsi_init_sync_state(&state); if (iscsi_writeverify12_task(iscsi, lun, lba, data, datalen, blocksize, wrprotect, @@ -1305,7 +1343,7 @@ iscsi_writeverify12_iov_sync(struct iscsi_context *iscsi, int lun, uint32_t lba, { struct iscsi_sync_state state; - memset(&state, 0, sizeof(state)); + iscsi_init_sync_state(&state); if (iscsi_writeverify12_iov_task(iscsi, lun, lba, data, datalen, blocksize, wrprotect, @@ -1328,7 +1366,7 @@ iscsi_writeverify16_sync(struct iscsi_context *iscsi, int lun, uint64_t lba, { struct iscsi_sync_state state; - memset(&state, 0, sizeof(state)); + iscsi_init_sync_state(&state); if (iscsi_writeverify16_task(iscsi, lun, lba, data, datalen, blocksize, wrprotect, @@ -1352,7 +1390,7 @@ iscsi_writeverify16_iov_sync(struct iscsi_context *iscsi, int lun, uint64_t lba, { struct iscsi_sync_state state; - memset(&state, 0, sizeof(state)); + iscsi_init_sync_state(&state); if (iscsi_writeverify16_iov_task(iscsi, lun, lba, data, datalen, blocksize, wrprotect, @@ -1374,7 +1412,7 @@ iscsi_verify10_sync(struct iscsi_context *iscsi, int lun, unsigned char *data, u { struct iscsi_sync_state state; - memset(&state, 0, sizeof(state)); + iscsi_init_sync_state(&state); if (iscsi_verify10_task(iscsi, lun, data, datalen, lba, vprotect, dpo, bytchk, blocksize, scsi_sync_cb, &state) == NULL) { @@ -1394,7 +1432,7 @@ iscsi_verify10_iov_sync(struct iscsi_context *iscsi, int lun, unsigned char *dat { struct iscsi_sync_state state; - memset(&state, 0, sizeof(state)); + iscsi_init_sync_state(&state); if (iscsi_verify10_iov_task(iscsi, lun, data, datalen, lba, vprotect, dpo, bytchk, blocksize, scsi_sync_cb, &state, iov, niov) == NULL) { @@ -1415,7 +1453,7 @@ iscsi_verify12_sync(struct iscsi_context *iscsi, int lun, unsigned char *data, u { struct iscsi_sync_state state; - memset(&state, 0, sizeof(state)); + iscsi_init_sync_state(&state); if (iscsi_verify12_task(iscsi, lun, data, datalen, lba, vprotect, dpo, bytchk, blocksize, scsi_sync_cb, &state) == NULL) { @@ -1435,7 +1473,7 @@ iscsi_verify12_iov_sync(struct iscsi_context *iscsi, int lun, unsigned char *dat { struct iscsi_sync_state state; - memset(&state, 0, sizeof(state)); + iscsi_init_sync_state(&state); if (iscsi_verify12_iov_task(iscsi, lun, data, datalen, lba, vprotect, dpo, bytchk, blocksize, scsi_sync_cb, &state, iov, niov) == NULL) { @@ -1455,7 +1493,7 @@ iscsi_verify16_sync(struct iscsi_context *iscsi, int lun, unsigned char *data, u { struct iscsi_sync_state state; - memset(&state, 0, sizeof(state)); + iscsi_init_sync_state(&state); if (iscsi_verify16_task(iscsi, lun, data, datalen, lba, vprotect, dpo, bytchk, blocksize, scsi_sync_cb, &state) == NULL) { @@ -1475,7 +1513,7 @@ iscsi_verify16_iov_sync(struct iscsi_context *iscsi, int lun, unsigned char *dat { struct iscsi_sync_state state; - memset(&state, 0, sizeof(state)); + iscsi_init_sync_state(&state); if (iscsi_verify16_iov_task(iscsi, lun, data, datalen, lba, vprotect, dpo, bytchk, blocksize, scsi_sync_cb, &state, iov, niov) == NULL) { @@ -1497,7 +1535,7 @@ iscsi_writesame10_sync(struct iscsi_context *iscsi, int lun, uint32_t lba, { struct iscsi_sync_state state; - memset(&state, 0, sizeof(state)); + iscsi_init_sync_state(&state); if (iscsi_writesame10_task(iscsi, lun, lba, data, datalen, num_blocks, @@ -1522,7 +1560,7 @@ iscsi_writesame10_iov_sync(struct iscsi_context *iscsi, int lun, uint32_t lba, { struct iscsi_sync_state state; - memset(&state, 0, sizeof(state)); + iscsi_init_sync_state(&state); if (iscsi_writesame10_iov_task(iscsi, lun, lba, data, datalen, num_blocks, @@ -1546,7 +1584,7 @@ iscsi_writesame16_sync(struct iscsi_context *iscsi, int lun, uint64_t lba, { struct iscsi_sync_state state; - memset(&state, 0, sizeof(state)); + iscsi_init_sync_state(&state); if (iscsi_writesame16_task(iscsi, lun, lba, data, datalen, num_blocks, @@ -1571,7 +1609,7 @@ iscsi_writesame16_iov_sync(struct iscsi_context *iscsi, int lun, uint64_t lba, { struct iscsi_sync_state state; - memset(&state, 0, sizeof(state)); + iscsi_init_sync_state(&state); if (iscsi_writesame16_iov_task(iscsi, lun, lba, data, datalen, num_blocks, @@ -1593,7 +1631,7 @@ iscsi_persistent_reserve_in_sync(struct iscsi_context *iscsi, int lun, { struct iscsi_sync_state state; - memset(&state, 0, sizeof(state)); + iscsi_init_sync_state(&state); if (iscsi_persistent_reserve_in_task(iscsi, lun, sa, xferlen, scsi_sync_cb, &state) == NULL) { @@ -1613,7 +1651,7 @@ iscsi_persistent_reserve_out_sync(struct iscsi_context *iscsi, int lun, { struct iscsi_sync_state state; - memset(&state, 0, sizeof(state)); + iscsi_init_sync_state(&state); if (iscsi_persistent_reserve_out_task(iscsi, lun, sa, scope, type, param, @@ -1634,7 +1672,7 @@ iscsi_unmap_sync(struct iscsi_context *iscsi, int lun, int anchor, int group, { struct iscsi_sync_state state; - memset(&state, 0, sizeof(state)); + iscsi_init_sync_state(&state); if (iscsi_unmap_task(iscsi, lun, anchor, group, list, list_len, scsi_sync_cb, &state) == NULL) { @@ -1654,7 +1692,7 @@ iscsi_readtoc_sync(struct iscsi_context *iscsi, int lun, int msf, int format, { struct iscsi_sync_state state; - memset(&state, 0, sizeof(state)); + iscsi_init_sync_state(&state); if (iscsi_readtoc_task(iscsi, lun, msf, format, track_session, maxsize, scsi_sync_cb, &state) == NULL) { @@ -1672,7 +1710,7 @@ iscsi_reserve6_sync(struct iscsi_context *iscsi, int lun) { struct iscsi_sync_state state; - memset(&state, 0, sizeof(state)); + iscsi_init_sync_state(&state); if (iscsi_reserve6_task(iscsi, lun, scsi_sync_cb, &state) == NULL) { iscsi_set_error(iscsi, "Failed to send RESERVE6 command"); @@ -1689,7 +1727,7 @@ iscsi_release6_sync(struct iscsi_context *iscsi, int lun) { struct iscsi_sync_state state; - memset(&state, 0, sizeof(state)); + iscsi_init_sync_state(&state); if (iscsi_release6_task(iscsi, lun, scsi_sync_cb, &state) == NULL) { iscsi_set_error(iscsi, "Failed to send RELEASE6 command"); @@ -1709,7 +1747,7 @@ iscsi_report_supported_opcodes_sync(struct iscsi_context *iscsi, int lun, { struct iscsi_sync_state state; - memset(&state, 0, sizeof(state)); + iscsi_init_sync_state(&state); if (iscsi_report_supported_opcodes_task(iscsi, lun, rctd, options, opcode, sa, alloc_len, scsi_sync_cb, &state) == NULL) { iscsi_set_error(iscsi, "Failed to send MaintenanceIn:" @@ -1728,7 +1766,7 @@ iscsi_receive_copy_results_sync(struct iscsi_context *iscsi, int lun, { struct iscsi_sync_state state; - memset(&state, 0, sizeof(state)); + iscsi_init_sync_state(&state); if (iscsi_receive_copy_results_task(iscsi, lun, sa, list_id, alloc_len, scsi_sync_cb, &state) == NULL) { @@ -1748,7 +1786,7 @@ iscsi_extended_copy_sync(struct iscsi_context *iscsi, int lun, { struct iscsi_sync_state state; - memset(&state, 0, sizeof(state)); + iscsi_init_sync_state(&state); if (iscsi_extended_copy_task(iscsi, lun, param_data, scsi_sync_cb, &state) == NULL) { @@ -1768,7 +1806,7 @@ iscsi_scsi_command_sync(struct iscsi_context *iscsi, int lun, { struct iscsi_sync_state state; - memset(&state, 0, sizeof(state)); + iscsi_init_sync_state(&state); if (iscsi_scsi_command_async(iscsi, lun, task, scsi_sync_cb, data, &state) != 0) { @@ -1788,7 +1826,7 @@ iscsi_modeselect6_sync(struct iscsi_context *iscsi, int lun, { struct iscsi_sync_state state; - memset(&state, 0, sizeof(state)); + iscsi_init_sync_state(&state); if (iscsi_modeselect6_task(iscsi, lun, pf, sp, mp, scsi_sync_cb, &state) == NULL) { @@ -1808,7 +1846,7 @@ iscsi_modeselect10_sync(struct iscsi_context *iscsi, int lun, { struct iscsi_sync_state state; - memset(&state, 0, sizeof(state)); + iscsi_init_sync_state(&state); if (iscsi_modeselect10_task(iscsi, lun, pf, sp, mp, scsi_sync_cb, &state) == NULL) { @@ -1829,7 +1867,7 @@ iscsi_modesense6_sync(struct iscsi_context *iscsi, int lun, int dbd, { struct iscsi_sync_state state; - memset(&state, 0, sizeof(state)); + iscsi_init_sync_state(&state); if (iscsi_modesense6_task(iscsi, lun, dbd, pc, page_code, sub_page_code, alloc_len, scsi_sync_cb, &state) == NULL) { @@ -1850,7 +1888,7 @@ iscsi_modesense10_sync(struct iscsi_context *iscsi, int lun, int llbaa, int dbd, { struct iscsi_sync_state state; - memset(&state, 0, sizeof(state)); + iscsi_init_sync_state(&state); if (iscsi_modesense10_task(iscsi, lun, llbaa, dbd, pc, page_code, sub_page_code, alloc_len, @@ -1924,12 +1962,11 @@ iscsi_discovery_sync(struct iscsi_context *iscsi) { struct iscsi_sync_state state; - memset(&state, 0, sizeof(state)); + iscsi_init_sync_state(&state); if (iscsi_discovery_async(iscsi, iscsi_discovery_cb, &state) != 0) { iscsi_set_error(iscsi, "Failed to run discovery. %s", iscsi_get_error(iscsi)); - printf("async discovery call failed\n"); return NULL; }