File: iscsi.h

package info (click to toggle)
libiscsi 1.20.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,080 kB
  • sloc: ansic: 40,928; xml: 749; sh: 689; makefile: 352
file content (1668 lines) | stat: -rw-r--r-- 62,435 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
/*
   Copyright (C) 2010 by Ronnie Sahlberg <ronniesahlberg@gmail.com>

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU Lesser General Public License as published by
   the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public License
   along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __iscsi_h__
#define __iscsi_h__

#include <stdint.h>
#include <sys/types.h>

#if defined(_WIN32)
#define EXTERN __declspec( dllexport )
#else
#define EXTERN
#endif

#ifdef __cplusplus
extern "C" {
#endif


struct iscsi_context;
struct sockaddr;
struct scsi_iovec;

/* API VERSION */
#define LIBISCSI_API_VERSION (20170105)

/* FEATURES */
#define LIBISCSI_FEATURE_IOVECTOR (1)
#define LIBISCSI_FEATURE_NOP_COUNTER (1)
#define LIBISCSI_FEATURE_ISER (1)

#define MAX_STRING_SIZE (255)

/*
 * Syntax for normal and portal/discovery URLs.
 */
#define ISCSI_URL_SYNTAX "\"iscsi://[<username>[%<password>]@]" \
  "<host>[:<port>]/<target-iqn>/<lun>\""
#define ISCSI_PORTAL_URL_SYNTAX "\"iscsi://[<username>[%<password>]@]" \
  "<host>[:<port>]\""

enum iscsi_transport_type {
	TCP_TRANSPORT = 0,
	ISER_TRANSPORT = 1
};

EXTERN void iscsi_set_cache_allocations(struct iscsi_context *iscsi, int ca);

/*
 * The following three functions are used to integrate libiscsi in an event
 * system.
 */
/*
 * Returns the file descriptor that libiscsi uses.
 */
EXTERN int iscsi_get_fd(struct iscsi_context *iscsi);
/*
 * Returns which events that we need to poll for for the iscsi file descriptor.
 *
 * This function can return 0 which means that there are no events to
 * poll for at this time. In that case the application should wait some time
 * before calling iscsi_which_events() again. This could for example happen
 * if we fail to reconnect the TCP session during an automatic session
 * reconnect.
 * When this function returns 0, the application should wait >=100ms
 * before trying again.
 */
EXTERN int iscsi_which_events(struct iscsi_context *iscsi);
/*
 * Called to process the events when events become available for the iscsi
 * file descriptor.
 */
EXTERN int iscsi_service(struct iscsi_context *iscsi, int revents);
/*
 * How many commands are in flight.
 */
EXTERN int iscsi_queue_length(struct iscsi_context *iscsi);
/*
 * How many commands are queued for dispatch.
 */
EXTERN int iscsi_out_queue_length(struct iscsi_context *iscsi);


/************************************************************
 * Timeout Handling.
 * Libiscsi does not use or interface with any system timers.
 * Instead all timeout processing in libiscsi is done as part
 * of the iscsi_service() processing.
 *
 * This means that if you use the timeout function below you must
 * device your application to call out to iscsi_service() at regular
 * intervals.
 * An easy way to do this is calling iscsi_service(iscsi, 0), i.e.
 * by passing 0 as the revents arguments once every second or so.
 ************************************************************/

/*
 * Set the timeout in seconds after which a task/pdu will timeout.
 * This timeout applies to SCSI task PDUs as well as normal iSCSI
 * PDUs such as login/task management/logout/...
 *
 * Each PDU is assigned its timeout value upon creation and can not be
 * changed afterwards. I.e. When you change the default timeout, it will
 * only affect any commands that are issued in the future but will not
 * affect the timeouts for any commands already in flight.
 *
 * The recommended usecase is to set to a default value for all PDUs
 * and only change the default temporarily when a specific task needs
 * a different timeout.
 *
 * // Set default to 5 seconds for all commands at beginning of program.
 * iscsi_set_timeout(iscsi, 5);
 *
 * ...
 * // SANITIZE command will take long so set it to no tiemout.
 * iscsi_set_timeout(iscsi, 0);
 * iscsi_sanitize_task(iscsi, ...
 * iscsi_set_timeout(iscsi, <set back to original value>);
 * ...
 *
 *
 * Default is 0 == no timeout.
 */
EXTERN int iscsi_set_timeout(struct iscsi_context *iscsi, int timeout);

/*
 * To set tcp keepalive for the session.
 * Only options supported by given platform (if any) are set.
 */
EXTERN int iscsi_set_tcp_keepalive(struct iscsi_context *iscsi, int idle, int count, int interval);

struct iscsi_url {
       char portal[MAX_STRING_SIZE + 1];
       char target[MAX_STRING_SIZE + 1];
       char user[MAX_STRING_SIZE + 1];
       char passwd[MAX_STRING_SIZE + 1];
       char target_user[MAX_STRING_SIZE + 1];
       char target_passwd[MAX_STRING_SIZE + 1];
       int lun;
       struct iscsi_context *iscsi;
       enum iscsi_transport_type transport;
};

/*
 * This function is used to set the desired mode for immediate data.
 * This can be set on a context before it has been logged in to the target
 * and controls how the initiator will try to negotiate the immediate data.
 *
 * Default is for libiscsi to try to negotiate ISCSI_IMMEDIATE_DATA_YES
 */
enum iscsi_immediate_data {
	ISCSI_IMMEDIATE_DATA_NO  = 0,
	ISCSI_IMMEDIATE_DATA_YES = 1
};
EXTERN int iscsi_set_immediate_data(struct iscsi_context *iscsi, enum iscsi_immediate_data immediate_data);

/*
 * This function is used to set the desired mode for initial_r2t
 * This can be set on a context before it has been logged in to the target
 * and controls how the initiator will try to negotiate the initial r2t.
 *
 * Default is for libiscsi to try to negotiate ISCSI_INITIAL_R2T_NO
 */
enum iscsi_initial_r2t {
	ISCSI_INITIAL_R2T_NO  = 0,
	ISCSI_INITIAL_R2T_YES = 1
};
EXTERN int
iscsi_set_initial_r2t(struct iscsi_context *iscsi, enum iscsi_initial_r2t initial_r2t);


/*
 * This function is used to parse an iSCSI URL into a iscsi_url structure.
 * iSCSI URL format :
 * iscsi://[<username>[%<password>]@]<host>[:<port>]/<target-iqn>/<lun>
 *
 * Target names are url encoded with '%' as a special character.
 * Example:
 * "iqn.ronnie.test%3A1234" will be translated to "iqn.ronnie.test:1234"
 *
 * Function will return a pointer to an iscsi url structure if successful,
 * or it will return NULL and set iscsi_get_error() accordingly if there was a problem
 * with the URL.
 *
 * CHAP username/password can also be provided via environment variables
 * LIBISCSI_CHAP_USERNAME=ronnie
 * LIBISCSI_CHAP_PASSWORD=password
 *
 * The returned structure is freed by calling iscsi_destroy_url()
 */
EXTERN struct iscsi_url *iscsi_parse_full_url(struct iscsi_context *iscsi, const char *url);
EXTERN void iscsi_destroy_url(struct iscsi_url *iscsi_url);

/*
 * This function is used to parse an iSCSI Portal URL into a iscsi_url structure.
 * iSCSI Portal URL format :
 * iscsi://[<username>[%<password>]@]<host>[:<port>]
 *
 * iSCSI Portal URL is used when describing a discovery session, where the target-iqn and the
 * lun is not yet known.
 *
 * Function will return a pointer to an iscsi url structure if successful,
 * or it will return NULL and set iscsi_get_error() accordingly if there was a problem
 * with the URL.
 *
 * CHAP username/password can also be provided via environment variables
 * LIBISCSI_CHAP_USERNAME=ronnie
 * LIBISCSI_CHAP_PASSWORD=password
 *
 * The returned structure is freed by calling iscsi_destroy_url()
 */
EXTERN struct iscsi_url *
iscsi_parse_portal_url(struct iscsi_context *iscsi, const char *url);

/*
 * This function returns a description of the last encountered error.
 */
EXTERN const char *iscsi_get_error(struct iscsi_context *iscsi);

/*
 * Create a context for an ISCSI session.
 * Initiator_name is the iqn name we want to identify to the target as.
 *
 * Returns:
 *  non-NULL: success
 *  NULL: error
 */
EXTERN struct iscsi_context *iscsi_create_context(const char *initiator_name);

/*
 * Destroy an existing ISCSI context and tear down any existing connection.
 * Callbacks for any command in flight will be invoked with
 * SCSI_STATUS_CANCELLED.
 *
 * Returns:
 *  0: success
 * <0: error
 */
EXTERN int iscsi_destroy_context(struct iscsi_context *iscsi);

/*
 * Sets and initializes the transport type for a context.
 * TCP_TRANSPORT is the default and is available on all platforms.
 * ISER_TRANSPORT is conditionally supported on Linux where available.
 *
 * Returns:
 *  0: success
 * <0: error
 */
EXTERN int iscsi_init_transport(struct iscsi_context *iscsi,
                                enum iscsi_transport_type transport);

/*
 * Set an optional alias name to identify with when connecting to the target
 *
 * Returns:
 *  0: success
 * <0: error
 */
EXTERN int iscsi_set_alias(struct iscsi_context *iscsi, const char *alias);


/*
 * Set the iqn name of the taqget to login to.
 * The target name must be set before a normal-login can be initiated.
 * Only discovery-logins are possible without setting the target iqn name.
 *
 * Returns:
 *  0: success
 * <0: error
 */
EXTERN int iscsi_set_targetname(struct iscsi_context *iscsi, const char *targetname);

/*
 * This function returns any target address supplied in a login response when
 * the target has moved.
 */
EXTERN const char *iscsi_get_target_address(struct iscsi_context *iscsi);

/* Type of iscsi sessions. Discovery sessions are used to query for what
 * targets exist behind the portal connected to. Normal sessions are used to
 * log in and do I/O to the SCSI LUNs
 */
enum iscsi_session_type {
	ISCSI_SESSION_DISCOVERY = 1,
	ISCSI_SESSION_NORMAL    = 2
};
/*
 * Set the session type for a scsi context.
 * Session type can only be set/changed before the context
 * is logged in to the target.
 *
 * Returns:
 *  0: success
 * <0: error
 */
EXTERN int iscsi_set_session_type(struct iscsi_context *iscsi,
			   enum iscsi_session_type session_type);


/*
 * Types of header digest we support. Default is NONE
 */
enum iscsi_header_digest {
	ISCSI_HEADER_DIGEST_NONE        = 0,
	ISCSI_HEADER_DIGEST_NONE_CRC32C = 1,
	ISCSI_HEADER_DIGEST_CRC32C_NONE = 2,
	ISCSI_HEADER_DIGEST_CRC32C      = 3,
	ISCSI_HEADER_DIGEST_LAST        = ISCSI_HEADER_DIGEST_CRC32C
};

/*
 * Set the desired header digest for a scsi context.
 * Header digest can only be set/changed before the context
 * is logged in to the target.
 *
 * Returns:
 *  0: success
 * <0: error
 */
EXTERN int iscsi_set_header_digest(struct iscsi_context *iscsi,
			    enum iscsi_header_digest header_digest);

/*
 * Specify the username and password to use for chap authentication
 */
EXTERN int iscsi_set_initiator_username_pwd(struct iscsi_context *iscsi,
    					    const char *user,
					    const char *passwd);
/*
 * Specify the username and password to use for target chap authentication.
 * Target/bidirectional CHAP is only supported if you also have normal
 * CHAP authentication.
 * You must configure CHAP first using iscsi_set_initiator_username_pwd()
`* before you can set up target authentication.
 */
EXTERN int iscsi_set_target_username_pwd(struct iscsi_context *iscsi,
					 const char *user,
					 const char *passwd);

/*
 * check if the context is logged in or not
 */
EXTERN int iscsi_is_logged_in(struct iscsi_context *iscsi);


enum scsi_status {
	SCSI_STATUS_GOOD                 = 0,
	SCSI_STATUS_CHECK_CONDITION      = 2,
	SCSI_STATUS_CONDITION_MET        = 4,
	SCSI_STATUS_BUSY                 = 8,
	SCSI_STATUS_RESERVATION_CONFLICT = 0x18,
	SCSI_STATUS_TASK_SET_FULL        = 0x28,
	SCSI_STATUS_ACA_ACTIVE           = 0x30,
	SCSI_STATUS_TASK_ABORTED         = 0x40,
	SCSI_STATUS_REDIRECT             = 0x101,
	SCSI_STATUS_CANCELLED            = 0x0f000000,
	SCSI_STATUS_ERROR                = 0x0f000001,
	SCSI_STATUS_TIMEOUT              = 0x0f000002
};


/*
 * Generic callback for completion of iscsi_*_async().
 * command_data depends on status.
 */
typedef void (*iscsi_command_cb)(struct iscsi_context *iscsi, int status,
				 void *command_data, void *private_data);



/*
 * Asynchronous call to connect a TCP connection to the target-host/port
 *
 * Returns:
 *  0 if the call was initiated and a connection will be attempted. Result of
 * the connection will be reported through the callback function.
 * <0 if there was an error. The callback function will not be invoked.
 *
 * This command is unique in that the callback can be invoked twice.
 *
 * Callback parameters :
 * status can be either of :
 *    SCSI_STATUS_GOOD     : Connection was successful. Command_data is NULL.
 *                           In this case the callback will be invoked a
 *                           second time once the connection is torn down.
 *
 *    SCSI_STATUS_ERROR    : Either failed to establish the connection, or
 *                           an already established connection has failed
 *                           with an error.
 *
 * The callback will NOT be invoked if the session is explicitely torn down
 * through a call to iscsi_disconnect() or iscsi_destroy_context().
 */
EXTERN int iscsi_connect_async(struct iscsi_context *iscsi, const char *portal,
			iscsi_command_cb cb, void *private_data);

/*
 * Synchronous call to connect a TCP connection to the target-host/port
 *
 * Returns:
 *  0 if connected successfully.
 * <0 if there was an error.
 *
 */
EXTERN int iscsi_connect_sync(struct iscsi_context *iscsi, const char *portal);


/*
 * Asynchronous call to connect a lun
 * This function will connect to the portal, login, and verify that the lun
 * is available.
 *
 * Returns:
 *  0 if the call was initiated and a connection will be attempted. Result
 *    of the connection will be reported through the callback function.
 * <0 if there was an error. The callback function will not be invoked.
 *
 * This command is unique in that the callback can be invoked twice.
 *
 * Callback parameters :
 * status can be either of :
 *    SCSI_STATUS_GOOD     : Connection was successful. Command_data is NULL.
 *                           In this case the callback will be invoked a
 *                           second time once the connection is torn down.
 *
 *    SCSI_STATUS_ERROR    : Either failed to establish the connection, or
 *                           an already established connection has failed
 *                           with an error.
 *
 * The callback will NOT be invoked if the session is explicitely torn down
 * through a call to iscsi_disconnect() or iscsi_destroy_context().
 */
EXTERN int iscsi_full_connect_async(struct iscsi_context *iscsi, const char *portal,
			     int lun, iscsi_command_cb cb, void *private_data);

/*
 * Synchronous call to connect a lun
 * This function will connect to the portal, login, and verify that the lun
 * is available.
 *
 * Returns:
 *  0 if the cconnect was successful.
 * <0 if there was an error.
 */
EXTERN int iscsi_full_connect_sync(struct iscsi_context *iscsi, const char *portal,
			    int lun);

/*
 * Disconnect a connection to a target.
 * You can not disconnect while being logged in to a target.
 *
 * Returns:
 *  0 disconnect was successful
 * <0 error
 */
EXTERN int iscsi_disconnect(struct iscsi_context *iscsi);

/*
 * Disconnect a connection to a target and try to reconnect (async version).
 * This call returns immediately and the reconnect is processed in the
 * background. Commands send to this connection will be queued and not
 * processed until we have successfully reconnected.
 *
 * Returns:
 *  0 reconnect was successful
 * <0 error
 */
EXTERN int iscsi_reconnect(struct iscsi_context *iscsi);

/*
 * Disconnect a connection to a target and try to reconnect (sync version).
 * This call will block until the connection is reestablished.
 *
 * Returns:
 *  0 reconnect was successful
 * <0 error
 */
EXTERN int iscsi_reconnect_sync(struct iscsi_context *iscsi);

/*
 * Disconnect a connection to a target and try to reconnect (async version).
 * This call returns immediately and the reconnect is processed in the
 * background. Commands send to this connection will be queued and not
 * processed until we have successfully reconnected.
 *
 * This will re-start connection (to the configured original portal) even if a
 * pending reconnection is already underway, which may be useful if the current
 * connection is not progressing.  It does not over-ride any existing re-try
 * backoff or max retries state.
 *
 * Returns:
 *  0 reconnect was successful
 * <0 error
 */
EXTERN int iscsi_force_reconnect(struct iscsi_context *iscsi);

/*
 * Disconnect a connection to a target and try to force reconnection (sync
 * version). This call will block until the connection is reestablished.
 *
 * Returns:
 *  0 reconnect was successful
 * <0 error
 */
EXTERN int iscsi_force_reconnect_sync(struct iscsi_context *iscsi);

/*
 * Asynchronous call to perform an ISCSI login.
 *
 * Returns:
 *  0 if the call was initiated and a login will be attempted. Result of the
 *    login will be reported through the callback function.
 * <0 if there was an error. The callback function will not be invoked.
 *
 * Callback parameters :
 * status can be either of :
 *    SCSI_STATUS_GOOD     : login was successful. Command_data is always
 *                           NULL.
 *    SCSI_STATUS_CANCELLED: login was aborted. Command_data is NULL.
 *    SCSI_STATUS_ERROR    : login failed. Command_data is NULL.
 */
EXTERN int iscsi_login_async(struct iscsi_context *iscsi, iscsi_command_cb cb,
		      void *private_data);

/*
 * Synchronous call to perform an ISCSI login.
 *
 * Returns:
 *  0 if the login was successful
 * <0 if there was an error.
 */
EXTERN int iscsi_login_sync(struct iscsi_context *iscsi);


/*
 * Asynchronous call to perform an ISCSI logout.
 *
 * Returns:
 *  0 if the call was initiated and a logout will be attempted. Result of the
 *    logout will be reported through the callback function.
 * <0 if there was an error. The callback function will not be invoked.
 *
 * Callback parameters :
 * status can be either of :
 *    SCSI_STATUS_GOOD     : logout was successful. Command_data is always
 *                           NULL.
 *    SCSI_STATUS_CANCELLED: logout was aborted. Command_data is NULL.
 */
EXTERN int iscsi_logout_async(struct iscsi_context *iscsi, iscsi_command_cb cb,
		       void *private_data);

/*
 * Synchronous call to perform an ISCSI logout.
 *
 * Returns:
 *  0 if the logout was successful
 * <0 if there was an error.
 */
EXTERN int iscsi_logout_sync(struct iscsi_context *iscsi);


struct iscsi_target_portal {
       struct iscsi_target_portal *next;
       char *portal;
};

struct iscsi_discovery_address {
       struct iscsi_discovery_address *next;
       char *target_name;
       struct iscsi_target_portal *portals;
};

/*
 * Asynchronous call to perform an ISCSI discovery.
 *
 * discoveries can only be done on connected and logged in discovery sessions.
 *
 * Returns:
 *  0 if the call was initiated and a discovery  will be attempted. Result
 *    will be reported through the callback function.
 * <0 if there was an error. The callback function will not be invoked.
 *
 * Callback parameters :
 * status can be either of :
 *    SCSI_STATUS_GOOD     : Discovery was successful. Command_data is a
 *                           pointer to a iscsi_discovery_address list of
 *                           structures.
 *                           This list of structures is only valid for the
 *                           duration of the callback and all data will be
 *                           freed once the callback returns.
 *    SCSI_STATUS_CANCELLED : Discovery was aborted. Command_data is NULL.
 */
EXTERN int iscsi_discovery_async(struct iscsi_context *iscsi, iscsi_command_cb cb,
			  void *private_data);

/*
 * Synchronous call to perform an ISCSI discovery.
 *
 * discoveries can only be done on connected and logged in discovery sessions.
 *
 * Returns:
 *  NULL if there was an error.
 *  struct iscsi_discovery_address* if the discovery was successfull.
 *    The data returned must be released by calling iscsi_free_discovery_data.
 */
EXTERN struct iscsi_discovery_address *iscsi_discovery_sync(
        struct iscsi_context *iscsi);

/* Free the discovery data structures returned by iscsi_discovery_sync
 */
EXTERN void iscsi_free_discovery_data(struct iscsi_context *iscsi,
                                      struct iscsi_discovery_address *da);

/*
 * Asynchronous call to perform an ISCSI NOP-OUT call
 *
 * Returns:
 *  0 if the call was initiated and a nop-out will be attempted. Result will
 *    be reported through the callback function.
 * <0 if there was an error. The callback function will not be invoked.
 *
 * Callback parameters :
 * status can be either of :
 *    SCSI_STATUS_GOOD     : NOP-OUT was successful and the server responded
 *                           with a NOP-IN callback_data is a iscsi_data
 *                           structure containing the data returned from
 *                           the server.
 *    SCSI_STATUS_CANCELLED : Discovery was aborted. Command_data is NULL.
 * 
 * The callback may be NULL if you only want to let libiscsi count the in-flight
 * NOPs.
 */
EXTERN int iscsi_nop_out_async(struct iscsi_context *iscsi, iscsi_command_cb cb,
			unsigned char *data, int len, void *private_data);


/* read out the number of consecutive nop outs that did not receive an answer */
EXTERN int iscsi_get_nops_in_flight(struct iscsi_context *iscsi);

struct scsi_task;
struct scsi_sense;

enum iscsi_task_mgmt_funcs {
     ISCSI_TM_ABORT_TASK        = 0x01,
     ISCSI_TM_ABORT_TASK_SET    = 0x02,
     ISCSI_TM_CLEAR_ACA         = 0x03,
     ISCSI_TM_CLEAR_TASK_SET    = 0x04,
     ISCSI_TM_LUN_RESET         = 0x05,
     ISCSI_TM_TARGET_WARM_RESET = 0x06,
     ISCSI_TM_TARGET_COLD_RESET = 0x07,
     ISCSI_TM_TASK_REASSIGN     = 0x08
};

enum iscsi_task_mgmt_response {
	ISCSI_TMR_FUNC_COMPLETE				= 0x0,
	ISCSI_TMR_TASK_DOES_NOT_EXIST			= 0x1,
	ISCSI_TMR_LUN_DOES_NOT_EXIST			= 0x2,
	ISCSI_TMR_TASK_STILL_ALLEGIANT			= 0x3,
	ISCSI_TMR_TASK_ALLEGIANCE_REASS_NOT_SUPPORTED	= 0x4,
	ISCSI_TMR_TMF_NOT_SUPPORTED			= 0x5,
	ISCSI_TMR_FUNC_AUTH_FAILED			= 0x6,
	ISCSI_TMR_FUNC_REJECTED				= 0xFF
};

/*
 * Asynchronous call for task management
 *
 * Returns:
 *  0 if the call was initiated and the task mgmt function will be invoked.
 *    The result will be reported through the callback function.
 * <0 if there was an error. The callback function will not be invoked.
 *
 * Callback parameters :
 * status can be either of :
 *    SCSI_STATUS_GOOD     : Connection was successful. Command_data is a pointer to uint32_t
 *                           containing the response code as per RFC3720/10.6.1
 *
 *    SCSI_STATUS_ERROR     : Error.
 *
 * The callback will NOT be invoked if the session is explicitely torn down
 * through a call to iscsi_disconnect() or iscsi_destroy_context().
 *
 * abort_task will also cancel the scsi task. The callback for the scsi task will be invoked with
 *            SCSI_STATUS_CANCELLED
 * abort_task_set, lun_reset, target_warn_reset, target_cold_reset will cancel all tasks. The callback for
 *            all tasks will be invoked with SCSI_STATUS_CANCELLED
 */
EXTERN int
iscsi_task_mgmt_async(struct iscsi_context *iscsi,
		      int lun, enum iscsi_task_mgmt_funcs function,
		      uint32_t ritt, uint32_t rcmdscn,
		      iscsi_command_cb cb, void *private_data);

EXTERN int
iscsi_task_mgmt_abort_task_async(struct iscsi_context *iscsi,
		      struct scsi_task *task,
		      iscsi_command_cb cb, void *private_data);
EXTERN int
iscsi_task_mgmt_abort_task_set_async(struct iscsi_context *iscsi,
		      uint32_t lun,
		      iscsi_command_cb cb, void *private_data);
EXTERN int
iscsi_task_mgmt_lun_reset_async(struct iscsi_context *iscsi,
		      uint32_t lun,
		      iscsi_command_cb cb, void *private_data);
EXTERN int
iscsi_task_mgmt_target_warm_reset_async(struct iscsi_context *iscsi,
		      iscsi_command_cb cb, void *private_data);
EXTERN int
iscsi_task_mgmt_target_cold_reset_async(struct iscsi_context *iscsi,
		      iscsi_command_cb cb, void *private_data);



/*
 * Synchronous calls for task management
 *
 * Returns:
 *  0 success.
 * <0 error.
 */
EXTERN int
iscsi_task_mgmt_sync(struct iscsi_context *iscsi,
		     int lun, enum iscsi_task_mgmt_funcs function,
		     uint32_t ritt, uint32_t rcmdscn);

EXTERN int
iscsi_task_mgmt_abort_task_sync(struct iscsi_context *iscsi, struct scsi_task *task);

EXTERN int
iscsi_task_mgmt_abort_task_set_sync(struct iscsi_context *iscsi, uint32_t lun);

EXTERN int
iscsi_task_mgmt_lun_reset_sync(struct iscsi_context *iscsi, uint32_t lun);

EXTERN int
iscsi_task_mgmt_target_warm_reset_sync(struct iscsi_context *iscsi);

EXTERN int
iscsi_task_mgmt_target_cold_reset_sync(struct iscsi_context *iscsi);




/* These are the possible status values for the callbacks for scsi commands.
 * The content of command_data depends on the status type.
 *
 * status :
 *   SCSI_STATUS_GOOD the scsi command completed successfullt on the target.
 *   If this scsi command returns DATA-IN, that data is stored in an scsi_task
 *   structure returned in the command_data parameter. This buffer will be
 *   automatically freed once the callback returns.
 *
 *   SCSI_STATUS_CHECK_CONDITION the scsi command failed with a scsi sense.
 *   Command_data contains a struct scsi_task. When the callback returns,
 *   this buffer will automatically become freed.
 *
 *   SCSI_STATUS_CANCELLED the scsi command was aborted. Command_data is
 *   NULL.
 *
 *   SCSI_STATUS_ERROR the command failed. Command_data is NULL.
 */

struct iscsi_data {
       size_t size;
       unsigned char *data;
};


/*
 * These functions will set the ISID type and value.
 * By default, contexts will automatically be assigned a 'random'
 * type and value on creation, but this can be overridden
 * by an appplication using these functions.
 *
 * Setting the ISID can only be done before loggin in to the target.
 */
EXTERN int
iscsi_set_isid_oui(struct iscsi_context *iscsi, uint32_t oui, uint32_t qualifier);
EXTERN int
iscsi_set_isid_en(struct iscsi_context *iscsi, uint32_t en, uint32_t qualifier);
EXTERN int
iscsi_set_isid_random(struct iscsi_context *iscsi, uint32_t rnd, uint32_t qualifier);
EXTERN int
iscsi_set_isid_reserved(struct iscsi_context *iscsi);


struct scsi_mode_page;



/*
 * The scsi commands use/return a scsi_task structure when invoked
 * and also through the callback.
 *
 * You must release this structure when you are finished with the task
 * by calling scsi_free_scsi_task().
 * Most of the time this means you should call this function before returning
 * from the callback.
 */

EXTERN int iscsi_scsi_command_async(struct iscsi_context *iscsi, int lun,
			     struct scsi_task *task, iscsi_command_cb cb,
			     struct iscsi_data *data, void *private_data);

/*
 * Async commands for SCSI
 *
 * These async functions return a scsi_task structure, or NULL if the command failed.
 * This structure can be used by task management functions to abort the task or a whole task set.
 */
EXTERN struct scsi_task *
iscsi_reportluns_task(struct iscsi_context *iscsi, int report_type,
			   int alloc_len, iscsi_command_cb cb,
			   void *private_data);
EXTERN struct scsi_task *
iscsi_testunitready_task(struct iscsi_context *iscsi, int lun,
			      iscsi_command_cb cb, void *private_data);
EXTERN struct scsi_task *
iscsi_inquiry_task(struct iscsi_context *iscsi, int lun, int evpd,
			int page_code, int maxsize, iscsi_command_cb cb,
			void *private_data);
EXTERN struct scsi_task *
iscsi_readcapacity10_task(struct iscsi_context *iscsi, int lun, int lba,
			       int pmi, iscsi_command_cb cb,
			       void *private_data);
EXTERN struct scsi_task *
iscsi_readcapacity16_task(struct iscsi_context *iscsi, int lun,
			  iscsi_command_cb cb,
			  void *private_data);
EXTERN struct scsi_task *
iscsi_readdefectdata10_task(struct iscsi_context *iscsi, int lun,
                            int req_plist, int req_glist,
                            int defect_list_format, uint16_t alloc_len,
                            iscsi_command_cb cb, void *private_data);
EXTERN struct scsi_task *
iscsi_readdefectdata12_task(struct iscsi_context *iscsi, int lun,
                            int req_plist, int req_glist,
                            int defect_list_format,
                            uint32_t address_descriptor_index,
                            uint32_t alloc_len,
                            iscsi_command_cb cb, void *private_data);
EXTERN struct scsi_task *
iscsi_sanitize_task(struct iscsi_context *iscsi, int lun,
		    int immed, int ause, int sa, int param_len,
		    struct iscsi_data *data,
		    iscsi_command_cb cb, void *private_data);
EXTERN struct scsi_task *
iscsi_sanitize_block_erase_task(struct iscsi_context *iscsi, int lun,
			       int immed, int ause,
			       iscsi_command_cb cb, void *private_data);
EXTERN struct scsi_task *
iscsi_sanitize_crypto_erase_task(struct iscsi_context *iscsi, int lun,
				 int immed, int ause,
				 iscsi_command_cb cb, void *private_data);
EXTERN struct scsi_task *
iscsi_sanitize_exit_failure_mode_task(struct iscsi_context *iscsi, int lun,
				      int immed, int ause,
				      iscsi_command_cb cb, void *private_data);
EXTERN struct scsi_task *
iscsi_get_lba_status_task(struct iscsi_context *iscsi, int lun,
			  uint64_t starting_lba, uint32_t alloc_len,
			  iscsi_command_cb cb,
			  void *private_data);
EXTERN struct scsi_task *
iscsi_synchronizecache10_task(struct iscsi_context *iscsi, int lun,
				   int lba, int num_blocks, int syncnv,
				   int immed, iscsi_command_cb cb,
				   void *private_data);
EXTERN struct scsi_task *
iscsi_synchronizecache16_task(struct iscsi_context *iscsi, int lun,
				   uint64_t lba, uint32_t num_blocks, int syncnv,
				   int immed, iscsi_command_cb cb,
				   void *private_data);
EXTERN struct scsi_task *
iscsi_prefetch10_task(struct iscsi_context *iscsi, int lun,
		      uint32_t lba, int num_blocks,
		      int immed, int group,
		      iscsi_command_cb cb, void *private_data);
EXTERN struct scsi_task *
iscsi_prefetch16_task(struct iscsi_context *iscsi, int lun,
		      uint64_t lba, int num_blocks,
		      int immed, int group,
		      iscsi_command_cb cb, void *private_data);
EXTERN struct scsi_task *
iscsi_read6_task(struct iscsi_context *iscsi, int lun, uint32_t lba,
		       uint32_t datalen, int blocksize, iscsi_command_cb cb,
		       void *private_data);
EXTERN struct scsi_task *
iscsi_read6_iov_task(struct iscsi_context *iscsi, int lun, uint32_t lba,
		       uint32_t datalen, int blocksize, iscsi_command_cb cb,
		       void *private_data, struct scsi_iovec *iov, int niov);
EXTERN struct scsi_task *
iscsi_read10_task(struct iscsi_context *iscsi, int lun, uint32_t lba,
		  uint32_t datalen, int blocksize,
		  int rdprotect, int dpo, int fua, int fua_nv, int group_number,
		  iscsi_command_cb cb, void *private_data);
EXTERN struct scsi_task *
iscsi_read10_iov_task(struct iscsi_context *iscsi, int lun, uint32_t lba,
		  uint32_t datalen, int blocksize,
		  int rdprotect, int dpo, int fua, int fua_nv, int group_number,
		  iscsi_command_cb cb, void *private_data, struct scsi_iovec *iov, int niov);
EXTERN struct scsi_task *
iscsi_write10_task(struct iscsi_context *iscsi, int lun, uint32_t lba,
		   unsigned char *data, uint32_t datalen, int blocksize,
		   int wrprotect, int dpo, int fua, int fua_nv, int group_number,
		   iscsi_command_cb cb, void *private_data);
EXTERN struct scsi_task *
iscsi_write10_iov_task(struct iscsi_context *iscsi, int lun, uint32_t lba,
		   unsigned char *data, uint32_t datalen, int blocksize,
		   int wrprotect, int dpo, int fua, int fua_nv, int group_number,
		   iscsi_command_cb cb, void *private_data, struct scsi_iovec *iov, int niov);
EXTERN struct scsi_task *
iscsi_writeverify10_task(struct iscsi_context *iscsi, int lun, uint32_t lba,
		   unsigned char *data, uint32_t datalen, int blocksize,
		   int wrprotect, int dpo, int bytchk, int group_number,
		   iscsi_command_cb cb, void *private_data);
EXTERN struct scsi_task *
iscsi_writeverify10_iov_task(struct iscsi_context *iscsi, int lun, uint32_t lba,
		   unsigned char *data, uint32_t datalen, int blocksize,
		   int wrprotect, int dpo, int bytchk, int group_number,
		   iscsi_command_cb cb, void *private_data, struct scsi_iovec *iov, int niov);
EXTERN struct scsi_task *
iscsi_read12_task(struct iscsi_context *iscsi, int lun, uint32_t lba,
		   uint32_t datalen, int blocksize,
		   int rdprotect, int dpo, int fua, int fua_nv, int group_number,
		   iscsi_command_cb cb, void *private_data);
EXTERN struct scsi_task *
iscsi_read12_iov_task(struct iscsi_context *iscsi, int lun, uint32_t lba,
		   uint32_t datalen, int blocksize,
		   int rdprotect, int dpo, int fua, int fua_nv, int group_number,
		   iscsi_command_cb cb, void *private_data, struct scsi_iovec *iov, int niov);
EXTERN struct scsi_task *
iscsi_write12_task(struct iscsi_context *iscsi, int lun, uint32_t lba,
		   unsigned char *data, uint32_t datalen, int blocksize,
		   int wrprotect, int dpo, int fua, int fua_nv, int group_number,
		   iscsi_command_cb cb, void *private_data);
EXTERN struct scsi_task *
iscsi_write12_iov_task(struct iscsi_context *iscsi, int lun, uint32_t lba,
		   unsigned char *data, uint32_t datalen, int blocksize,
		   int wrprotect, int dpo, int fua, int fua_nv, int group_number,
		   iscsi_command_cb cb, void *private_data, struct scsi_iovec *iov, int niov);
EXTERN struct scsi_task *
iscsi_writeverify12_task(struct iscsi_context *iscsi, int lun, uint32_t lba,
		   unsigned char *data, uint32_t datalen, int blocksize,
		   int wrprotect, int dpo, int bytchk, int group_number,
		   iscsi_command_cb cb, void *private_data);
EXTERN struct scsi_task *
iscsi_writeverify12_iov_task(struct iscsi_context *iscsi, int lun, uint32_t lba,
		   unsigned char *data, uint32_t datalen, int blocksize,
		   int wrprotect, int dpo, int bytchk, int group_number,
		   iscsi_command_cb cb, void *private_data, struct scsi_iovec *iov, int niov);
EXTERN struct scsi_task *
iscsi_read16_task(struct iscsi_context *iscsi, int lun, uint64_t lba,
		   uint32_t datalen, int blocksize,
		   int rdprotect, int dpo, int fua, int fua_nv, int group_number,
		   iscsi_command_cb cb, void *private_data);
EXTERN struct scsi_task *
iscsi_read16_iov_task(struct iscsi_context *iscsi, int lun, uint64_t lba,
		   uint32_t datalen, int blocksize,
		   int rdprotect, int dpo, int fua, int fua_nv, int group_number,
		   iscsi_command_cb cb, void *private_data, struct scsi_iovec *iov, int niov);
EXTERN struct scsi_task *
iscsi_write16_task(struct iscsi_context *iscsi, int lun, uint64_t lba,
		   unsigned char *data, uint32_t datalen, int blocksize,
		   int wrprotect, int dpo, int fua, int fua_nv, int group_number,
		   iscsi_command_cb cb, void *private_data);
EXTERN struct scsi_task *
iscsi_write16_iov_task(struct iscsi_context *iscsi, int lun, uint64_t lba,
		   unsigned char *data, uint32_t datalen, int blocksize,
		   int wrprotect, int dpo, int fua, int fua_nv, int group_number,
		   iscsi_command_cb cb, void *private_data, struct scsi_iovec *iov, int niov);
EXTERN struct scsi_task *
iscsi_writeatomic16_task(struct iscsi_context *iscsi, int lun, uint64_t lba,
			 unsigned char *data, uint32_t datalen, int blocksize,
			 int wrprotect, int dpo, int fua, int group_number,
		   iscsi_command_cb cb, void *private_data);
EXTERN struct scsi_task *
iscsi_writeatomic16_iov_task(struct iscsi_context *iscsi, int lun, uint64_t lba,
			     unsigned char *data, uint32_t datalen, int blocksize,
			     int wrprotect, int dpo, int fua, int group_number,
			     iscsi_command_cb cb, void *private_data,
			     struct scsi_iovec *iov, int niov);
EXTERN struct scsi_task *
iscsi_orwrite_task(struct iscsi_context *iscsi, int lun, uint64_t lba,
		   unsigned char *data, uint32_t datalen, int blocksize,
		   int wrprotect, int dpo, int fua, int fua_nv, int group_number,
		   iscsi_command_cb cb, void *private_data);
EXTERN struct scsi_task *
iscsi_orwrite_iov_task(struct iscsi_context *iscsi, int lun, uint64_t lba,
		       unsigned char *data, uint32_t datalen, int blocksize,
		       int wrprotect, int dpo, int fua, int fua_nv, int group_number,
		       iscsi_command_cb cb, void *private_data, struct scsi_iovec *iov, int niov);
EXTERN struct scsi_task *
iscsi_startstopunit_task(struct iscsi_context *iscsi, int lun,
			 int immed, int pcm, int pc,
			 int no_flush, int loej, int start,
			 iscsi_command_cb cb, void *private_data);
EXTERN struct scsi_task *
iscsi_preventallow_task(struct iscsi_context *iscsi, int lun,
			int prevent,
			iscsi_command_cb cb, void *private_data);
EXTERN struct scsi_task *
iscsi_compareandwrite_task(struct iscsi_context *iscsi, int lun, uint64_t lba,
		   unsigned char *data, uint32_t datalen, int blocksize,
		   int wrprotect, int dpo, int fua, int fua_nv, int group_number,
		   iscsi_command_cb cb, void *private_data);
EXTERN struct scsi_task *
iscsi_compareandwrite_iov_task(struct iscsi_context *iscsi, int lun, uint64_t lba,
			       unsigned char *data, uint32_t datalen, int blocksize,
			       int wrprotect, int dpo, int fua, int fua_nv, int group_number,
			       iscsi_command_cb cb, void *private_data, struct scsi_iovec *iov, int niov);
EXTERN struct scsi_task *
iscsi_writeverify16_task(struct iscsi_context *iscsi, int lun, uint64_t lba,
		   unsigned char *data, uint32_t datalen, int blocksize,
		   int wrprotect, int dpo, int bytchk, int group_number,
		   iscsi_command_cb cb, void *private_data);
EXTERN struct scsi_task *
iscsi_writeverify16_iov_task(struct iscsi_context *iscsi, int lun, uint64_t lba,
		   unsigned char *data, uint32_t datalen, int blocksize,
		   int wrprotect, int dpo, int bytchk, int group_number,
		   iscsi_command_cb cb, void *private_data, struct scsi_iovec *iov, int niov);
EXTERN struct scsi_task *
iscsi_verify10_task(struct iscsi_context *iscsi, int lun,
		    unsigned char *data, uint32_t datalen, uint32_t lba,
		    int vprotect, int dpo, int bytchk,
		    int blocksize, iscsi_command_cb cb,
		    void *private_data);
EXTERN struct scsi_task *
iscsi_verify10_iov_task(struct iscsi_context *iscsi, int lun,
			unsigned char *data, uint32_t datalen, uint32_t lba,
			int vprotect, int dpo, int bytchk,
			int blocksize, iscsi_command_cb cb,
			void *private_data, struct scsi_iovec *iov, int niov);
EXTERN struct scsi_task *
iscsi_verify12_task(struct iscsi_context *iscsi, int lun,
		    unsigned char *data, uint32_t datalen, uint32_t lba,
		    int vprotect, int dpo, int bytchk,
		    int blocksize, iscsi_command_cb cb,
		    void *private_data);
EXTERN struct scsi_task *
iscsi_verify12_iov_task(struct iscsi_context *iscsi, int lun,
			unsigned char *data, uint32_t datalen, uint32_t lba,
			int vprotect, int dpo, int bytchk,
			int blocksize, iscsi_command_cb cb,
			void *private_data, struct scsi_iovec *iov, int niov);
EXTERN struct scsi_task *
iscsi_verify16_task(struct iscsi_context *iscsi, int lun,
		    unsigned char *data, uint32_t datalen, uint64_t lba,
		    int vprotect, int dpo, int bytchk,
		    int blocksize, iscsi_command_cb cb,
		    void *private_data);
EXTERN struct scsi_task *
iscsi_verify16_iov_task(struct iscsi_context *iscsi, int lun,
			unsigned char *data, uint32_t datalen, uint64_t lba,
			int vprotect, int dpo, int bytchk,
			int blocksize, iscsi_command_cb cb,
			void *private_data, struct scsi_iovec *iov, int niov);
EXTERN struct scsi_task *
iscsi_writesame10_task(struct iscsi_context *iscsi, int lun, uint32_t lba,
		       unsigned char *data, uint32_t datalen,
		       uint16_t num_blocks,
		       int anchor, int unmap, int wrprotect, int group,
		       iscsi_command_cb cb, void *private_data);
EXTERN struct scsi_task *
iscsi_writesame10_iov_task(struct iscsi_context *iscsi, int lun, uint32_t lba,
			   unsigned char *data, uint32_t datalen,
			   uint16_t num_blocks,
			   int anchor, int unmap, int wrprotect, int group,
			   iscsi_command_cb cb, void *private_data,
			   struct scsi_iovec *iov, int niov);
EXTERN struct scsi_task *
iscsi_writesame16_task(struct iscsi_context *iscsi, int lun, uint64_t lba,
		       unsigned char *data, uint32_t datalen,
		       uint32_t num_blocks,
		       int anchor, int unmap, int wrprotect, int group,
		       iscsi_command_cb cb, void *private_data);
EXTERN struct scsi_task *
iscsi_writesame16_iov_task(struct iscsi_context *iscsi, int lun, uint64_t lba,
			   unsigned char *data, uint32_t datalen,
			   uint32_t num_blocks,
			   int anchor, int unmap, int wrprotect, int group,
			   iscsi_command_cb cb, void *private_data,
			   struct scsi_iovec *iov, int niov);
EXTERN struct scsi_task *
iscsi_modeselect6_task(struct iscsi_context *iscsi, int lun,
		       int pf, int sp, struct scsi_mode_page *mp,
		       iscsi_command_cb cb, void *private_data);
EXTERN struct scsi_task *
iscsi_modeselect10_task(struct iscsi_context *iscsi, int lun,
			int pf, int sp, struct scsi_mode_page *mp,
			iscsi_command_cb cb, void *private_data);
EXTERN struct scsi_task *
iscsi_modesense6_task(struct iscsi_context *iscsi, int lun, int dbd,
			   int pc, int page_code, int sub_page_code,
			   unsigned char alloc_len, iscsi_command_cb cb,
			   void *private_data);
EXTERN struct scsi_task *
iscsi_modesense10_task(struct iscsi_context *iscsi, int lun, int llbaa, int dbd,
			   int pc, int page_code, int sub_page_code,
			   unsigned char alloc_len, iscsi_command_cb cb,
			   void *private_data);

struct unmap_list {
       uint64_t	  lba;
       uint32_t	  num;
};

EXTERN struct scsi_task *
iscsi_persistent_reserve_in_task(struct iscsi_context *iscsi, int lun,
				 int sa, uint16_t xferlen,
				 iscsi_command_cb cb, void *private_data);

EXTERN struct scsi_task *
iscsi_persistent_reserve_out_task(struct iscsi_context *iscsi, int lun,
				  int sa, int scope, int type, void *params,
				  iscsi_command_cb cb, void *private_data);

EXTERN struct scsi_task *
iscsi_unmap_task(struct iscsi_context *iscsi, int lun, int anchor, int group,
		 struct unmap_list *list, int list_len,
		 iscsi_command_cb cb, void *private_data);

EXTERN struct scsi_task *
iscsi_readtoc_task(struct iscsi_context *iscsi, int lun, int msf, int format,
		   int track_session, int maxsize,
		   iscsi_command_cb cb, void *private_data);

EXTERN struct scsi_task *
iscsi_reserve6_task(struct iscsi_context *iscsi, int lun,
		    iscsi_command_cb cb, void *private_data);

EXTERN struct scsi_task *
iscsi_release6_task(struct iscsi_context *iscsi, int lun,
		    iscsi_command_cb cb, void *private_data);

EXTERN struct scsi_task *
iscsi_report_supported_opcodes_task(struct iscsi_context *iscsi, int lun,
				    int rctd, int options,
				    int opcode, int sa,
				    uint32_t alloc_len,
				    iscsi_command_cb cb, void *private_data);

EXTERN struct scsi_task *
iscsi_receive_copy_results_task(struct iscsi_context *iscsi, int lun,
				int sa, int list_id, int alloc_len,
				iscsi_command_cb cb, void *private_data);

EXTERN struct scsi_task *
iscsi_extended_copy_task(struct iscsi_context *iscsi, int lun,
			 struct iscsi_data *param_data,
			 iscsi_command_cb cb, void *private_data);

/*
 * Sync commands for SCSI
 */
EXTERN struct scsi_task *
iscsi_scsi_command_sync(struct iscsi_context *iscsi, int lun,
			struct scsi_task *task, struct iscsi_data *data);

EXTERN struct scsi_task *
iscsi_modeselect6_sync(struct iscsi_context *iscsi, int lun,
		       int pf, int sp, struct scsi_mode_page *mp);

EXTERN struct scsi_task *
iscsi_modeselect10_sync(struct iscsi_context *iscsi, int lun,
			int pf, int sp, struct scsi_mode_page *mp);

EXTERN struct scsi_task *
iscsi_modesense6_sync(struct iscsi_context *iscsi, int lun, int dbd,
		      int pc, int page_code, int sub_page_code,
		      unsigned char alloc_len);

EXTERN struct scsi_task *
iscsi_modesense10_sync(struct iscsi_context *iscsi, int lun, int llbaa, int dbd,
		      int pc, int page_code, int sub_page_code,
		      unsigned char alloc_len);

EXTERN struct scsi_task *
iscsi_reportluns_sync(struct iscsi_context *iscsi, int report_type,
		      int alloc_len);

EXTERN struct scsi_task *
iscsi_testunitready_sync(struct iscsi_context *iscsi, int lun);

EXTERN struct scsi_task *
iscsi_inquiry_sync(struct iscsi_context *iscsi, int lun, int evpd,
		   int page_code, int maxsize);

EXTERN struct scsi_task *
iscsi_read6_sync(struct iscsi_context *iscsi, int lun, uint32_t lba,
		  uint32_t datalen, int blocksize);

EXTERN struct scsi_task *
iscsi_read6_iov_sync(struct iscsi_context *iscsi, int lun, uint32_t lba,
		     uint32_t datalen, int blocksize,
		     struct scsi_iovec *iov, int niov);

EXTERN struct scsi_task *
iscsi_read10_sync(struct iscsi_context *iscsi, int lun, uint32_t lba,
		  uint32_t datalen, int blocksize,
		  int rdprotect, int dpo, int fua, int fua_nv, int group_number);

EXTERN struct scsi_task *
iscsi_read10_iov_sync(struct iscsi_context *iscsi, int lun, uint32_t lba,
		      uint32_t datalen, int blocksize,
		      int rdprotect, int dpo, int fua, int fua_nv, int group_number,
		      struct scsi_iovec *iov, int niov);

EXTERN struct scsi_task *
iscsi_write10_sync(struct iscsi_context *iscsi, int lun, uint32_t lba,
		   unsigned char *data, uint32_t datalen, int blocksize,
		   int wrprotect, int dpo, int fua, int fua_nv, int group_number);

EXTERN struct scsi_task *
iscsi_write10_iov_sync(struct iscsi_context *iscsi, int lun, uint32_t lba,
			unsigned char *data, uint32_t datalen, int blocksize,
			int wrprotect, int dpo, int fua, int fua_nv, int group_number,
			struct scsi_iovec *iov, int niov);
EXTERN struct scsi_task *
iscsi_writeverify10_sync(struct iscsi_context *iscsi, int lun, uint32_t lba,
		   unsigned char *data, uint32_t datalen, int blocksize,
		   int wrprotect, int dpo, int bytchk, int group_number);

EXTERN struct scsi_task *
iscsi_writeverify10_iov_sync(struct iscsi_context *iscsi, int lun, uint32_t lba,
			     unsigned char *data, uint32_t datalen, int blocksize,
			     int wrprotect, int dpo, int bytchk, int group_number,
			     struct scsi_iovec *iov, int niov);

EXTERN struct scsi_task *
iscsi_read12_sync(struct iscsi_context *iscsi, int lun, uint32_t lba,
		  uint32_t datalen, int blocksize,
		  int rdprotect, int dpo, int fua, int fua_nv, int group_number);

EXTERN struct scsi_task *
iscsi_read12_iov_sync(struct iscsi_context *iscsi, int lun, uint32_t lba,
		      uint32_t datalen, int blocksize,
		      int rdprotect, int dpo, int fua, int fua_nv, int group_number,
		      struct scsi_iovec *iov, int niov);

EXTERN struct scsi_task *
iscsi_write12_sync(struct iscsi_context *iscsi, int lun, uint32_t lba,
		   unsigned char *data, uint32_t datalen, int blocksize,
		   int wrprotect, int dpo, int fua, int fua_nv, int group_number);

EXTERN struct scsi_task *
iscsi_write12_iov_sync(struct iscsi_context *iscsi, int lun, uint32_t lba,
		       unsigned char *data, uint32_t datalen, int blocksize,
		       int wrprotect, int dpo, int fua, int fua_nv, int group_number,
		       struct scsi_iovec *iov, int niov);

EXTERN struct scsi_task *
iscsi_writeverify12_sync(struct iscsi_context *iscsi, int lun, uint32_t lba,
		   unsigned char *data, uint32_t datalen, int blocksize,
		   int wrprotect, int dpo, int bytchk, int group_number);

EXTERN struct scsi_task *
iscsi_writeverify12_iov_sync(struct iscsi_context *iscsi, int lun, uint32_t lba,
			     unsigned char *data, uint32_t datalen, int blocksize,
			     int wrprotect, int dpo, int bytchk, int group_number,
			     struct scsi_iovec *iov, int niov);

EXTERN struct scsi_task *
iscsi_read16_sync(struct iscsi_context *iscsi, int lun, uint64_t lba,
		  uint32_t datalen, int blocksize,
		  int rdprotect, int dpo, int fua, int fua_nv, int group_number);

EXTERN struct scsi_task *
iscsi_read16_iov_sync(struct iscsi_context *iscsi, int lun, uint64_t lba,
		      uint32_t datalen, int blocksize,
		      int rdprotect, int dpo, int fua, int fua_nv, int group_number,
		      struct scsi_iovec *iov, int niov);

EXTERN struct scsi_task *
iscsi_write16_sync(struct iscsi_context *iscsi, int lun, uint64_t lba,
		   unsigned char *data, uint32_t datalen, int blocksize,
		   int wrprotect, int dpo, int fua, int fua_nv, int group_number);

EXTERN struct scsi_task *
iscsi_write16_iov_sync(struct iscsi_context *iscsi, int lun, uint64_t lba,
		       unsigned char *data, uint32_t datalen, int blocksize,
		       int wrprotect, int dpo, int fua, int fua_nv, int group_number,
		       struct scsi_iovec *iov, int niov);

EXTERN struct scsi_task *
iscsi_writeatomic16_sync(struct iscsi_context *iscsi, int lun, uint64_t lba,
			 unsigned char *data, uint32_t datalen, int blocksize,
			 int wrprotect, int dpo, int fua, int group_number);

EXTERN struct scsi_task *
iscsi_writeatomic16_iov_sync(struct iscsi_context *iscsi, int lun, uint64_t lba,
			     unsigned char *data, uint32_t datalen, int blocksize,
			     int wrprotect, int dpo, int fua, int group_number,
			     struct scsi_iovec *iov, int niov);

EXTERN struct scsi_task *
iscsi_orwrite_sync(struct iscsi_context *iscsi, int lun, uint64_t lba,
		   unsigned char *data, uint32_t datalen, int blocksize,
		   int wrprotect, int dpo, int fua, int fua_nv, int group_number);

EXTERN struct scsi_task *
iscsi_orwrite_iov_sync(struct iscsi_context *iscsi, int lun, uint64_t lba,
		       unsigned char *data, uint32_t datalen, int blocksize,
		       int wrprotect, int dpo, int fua, int fua_nv, int group_number,
		       struct scsi_iovec *iov, int niov);

EXTERN struct scsi_task *
iscsi_startstopunit_sync(struct iscsi_context *iscsi, int lun,
			 int immed, int pcm, int pc,
			 int no_flush, int loej, int start);

EXTERN struct scsi_task *
iscsi_preventallow_sync(struct iscsi_context *iscsi, int lun,
			int prevent);

EXTERN struct scsi_task *
iscsi_compareandwrite_sync(struct iscsi_context *iscsi, int lun, uint64_t lba,
		   unsigned char *data, uint32_t datalen, int blocksize,
		   int wrprotect, int dpo, int fua, int fua_nv, int group_number);

EXTERN struct scsi_task *
iscsi_compareandwrite_iov_sync(struct iscsi_context *iscsi, int lun, uint64_t lba,
			       unsigned char *data, uint32_t datalen, int blocksize,
			       int wrprotect, int dpo, int fua, int fua_nv, int group_number,
			       struct scsi_iovec *iov, int niov);

EXTERN struct scsi_task *
iscsi_writeverify16_sync(struct iscsi_context *iscsi, int lun, uint64_t lba,
		   unsigned char *data, uint32_t datalen, int blocksize,
		   int wrprotect, int dpo, int bytchk, int group_number);

EXTERN struct scsi_task *
iscsi_writeverify16_iov_sync(struct iscsi_context *iscsi, int lun, uint64_t lba,
			     unsigned char *data, uint32_t datalen, int blocksize,
			     int wrprotect, int dpo, int bytchk, int group_number,
			     struct scsi_iovec *iov, int niov);

EXTERN struct scsi_task *
iscsi_readcapacity10_sync(struct iscsi_context *iscsi, int lun, int lba,
			  int pmi);

EXTERN struct scsi_task *
iscsi_readcapacity16_sync(struct iscsi_context *iscsi, int lun);

EXTERN struct scsi_task *
iscsi_readdefectdata10_sync(struct iscsi_context *iscsi, int lun,
                            int req_plist, int req_glist,
                            int defect_list_format, uint16_t alloc_len);

EXTERN struct scsi_task *
iscsi_readdefectdata12_sync(struct iscsi_context *iscsi, int lun,
                            int req_plist, int req_glist,
                            int defect_list_format,
                            uint32_t address_descriptor_index,
                            uint32_t alloc_len);
EXTERN struct scsi_task *
iscsi_get_lba_status_sync(struct iscsi_context *iscsi, int lun, uint64_t starting_lba, uint32_t alloc_len);

EXTERN struct scsi_task *
iscsi_sanitize_sync(struct iscsi_context *iscsi, int lun,
		    int immed, int ause, int sa, int param_len,
		    struct iscsi_data *data);
EXTERN struct scsi_task *
iscsi_sanitize_block_erase_sync(struct iscsi_context *iscsi, int lun,
		    int immed, int ause);
EXTERN struct scsi_task *
iscsi_sanitize_crypto_erase_sync(struct iscsi_context *iscsi, int lun,
		    int immed, int ause);
EXTERN struct scsi_task *
iscsi_sanitize_exit_failure_mode_sync(struct iscsi_context *iscsi, int lun,
		    int immed, int ause);
EXTERN struct scsi_task *
iscsi_synchronizecache10_sync(struct iscsi_context *iscsi, int lun, int lba,
			      int num_blocks, int syncnv, int immed);

EXTERN struct scsi_task *
iscsi_synchronizecache16_sync(struct iscsi_context *iscsi, int lun, uint64_t lba,
			      uint32_t num_blocks, int syncnv, int immed);

EXTERN struct scsi_task *
iscsi_prefetch10_sync(struct iscsi_context *iscsi, int lun, uint32_t lba,
		      int num_blocks, int immed, int group);

EXTERN struct scsi_task *
iscsi_prefetch16_sync(struct iscsi_context *iscsi, int lun, uint64_t lba,
		      int num_blocks, int immed, int group);

EXTERN struct scsi_task *
iscsi_verify10_sync(struct iscsi_context *iscsi, int lun,
		    unsigned char *data, uint32_t datalen, uint32_t lba,
		    int vprotect, int dpo, int bytchk,
		    int blocksize);

EXTERN struct scsi_task *
iscsi_verify10_iov_sync(struct iscsi_context *iscsi, int lun,
			unsigned char *data, uint32_t datalen, uint32_t lba,
			int vprotect, int dpo, int bytchk,
			int blocksize, struct scsi_iovec *iov, int niov);

EXTERN struct scsi_task *
iscsi_verify12_sync(struct iscsi_context *iscsi, int lun,
		    unsigned char *data, uint32_t datalen, uint32_t lba,
		    int vprotect, int dpo, int bytchk,
		    int blocksize);

EXTERN struct scsi_task *
iscsi_verify12_iov_sync(struct iscsi_context *iscsi, int lun,
			unsigned char *data, uint32_t datalen, uint32_t lba,
			int vprotect, int dpo, int bytchk,
			int blocksize, struct scsi_iovec *iov, int niov);

EXTERN struct scsi_task *
iscsi_verify16_sync(struct iscsi_context *iscsi, int lun,
		    unsigned char *data, uint32_t datalen, uint64_t lba,
		    int vprotect, int dpo, int bytchk,
		    int blocksize);

EXTERN struct scsi_task *
iscsi_verify16_iov_sync(struct iscsi_context *iscsi, int lun,
			unsigned char *data, uint32_t datalen, uint64_t lba,
			int vprotect, int dpo, int bytchk,
			int blocksize, struct scsi_iovec *iov, int niov);

EXTERN struct scsi_task *
iscsi_writesame10_sync(struct iscsi_context *iscsi, int lun, uint32_t lba,
		       unsigned char *data, uint32_t datalen,
		       uint16_t num_blocks,
		       int anchor, int unmap, int wrprotect, int group);

EXTERN struct scsi_task *
iscsi_writesame10_iov_sync(struct iscsi_context *iscsi, int lun, uint32_t lba,
			   unsigned char *data, uint32_t datalen,
			   uint16_t num_blocks,
			   int anchor, int unmap, int wrprotect, int group,
			   struct scsi_iovec *iov, int niov);

EXTERN struct scsi_task *
iscsi_writesame16_sync(struct iscsi_context *iscsi, int lun, uint64_t lba,
		       unsigned char *data, uint32_t datalen,
		       uint32_t num_blocks,
		       int anchor, int unmap, int wrprotect, int group);

EXTERN struct scsi_task *
iscsi_writesame16_iov_sync(struct iscsi_context *iscsi, int lun, uint64_t lba,
			   unsigned char *data, uint32_t datalen,
			   uint32_t num_blocks,
			   int anchor, int unmap, int wrprotect, int group,
			   struct scsi_iovec *iov, int niov);

EXTERN struct scsi_task *
iscsi_persistent_reserve_in_sync(struct iscsi_context *iscsi, int lun,
				 int sa, uint16_t xferlen);

EXTERN struct scsi_task *
iscsi_persistent_reserve_out_sync(struct iscsi_context *iscsi, int lun,
				  int sa, int scope, int type, void *params);

EXTERN struct scsi_task *
iscsi_unmap_sync(struct iscsi_context *iscsi, int lun, int anchor, int group,
		 struct unmap_list *list, int list_len);

EXTERN struct scsi_task *
iscsi_readtoc_sync(struct iscsi_context *iscsi, int lun, int msf,
		   int format, int track_session, int maxsize);

EXTERN struct scsi_task *
iscsi_reserve6_sync(struct iscsi_context *iscsi, int lun);

EXTERN struct scsi_task *
iscsi_release6_sync(struct iscsi_context *iscsi, int lun);

EXTERN struct scsi_task *
iscsi_report_supported_opcodes_sync(struct iscsi_context *iscsi, int lun,
				    int rctd, int options,
				    int opcode, int sa,
				    uint32_t alloc_len);

EXTERN struct scsi_task *
iscsi_extended_copy_sync(struct iscsi_context *iscsi, int lun,
			 struct iscsi_data *param_data);

EXTERN struct scsi_task *
iscsi_receive_copy_results_sync(struct iscsi_context *iscsi, int lun,
				int sa, int list_id, int alloc_len);

/*
 * These functions are used when the application wants to specify its own buffers to read the data
 * from the DATA-IN PDUs into, or write the data to DATA-OUT PDUs from.
 * The main use is for SCSI READ10/12/16 WRITE10/12/16 operations to have them read/write directly from
 * the applications buffer, avoiding coying the data.
 *
 * This also supports reading into a vector of buffers by calling this function multiple times.
 * The individual buffers will be filled in the same order as they were created.
 *
 * Example READ10:
 *     task = iscsi_read10_task(    ( 2 512byte blocks into two buffers)
 *     scsi_task_add_data_in_buffer(task, first_buffer, 512
 *     scsi_task_add_data_in_buffer(task, second_buffer, 512
 *
 *
 * If you use this function you can not use task->datain in the READ callback.
 * task->datain.size will be 0 and
 * task->datain.data will be NULL
 *
 * Example WRITE10: (write 2 blocks)
 *     static struct scsi_iovec iov[2];
 *
 *     task = iscsi_write10_task(iscsi, lun, 0, NULL, 512, 512, 0, 0, 0, 0, 0, callback, private_data);
 *     iov[0].iov_base = first_buffer;
 *     iov[0].iov_len  = 512;
 *     iov[1].iov_base = second_buffer;
 *     iov[1].iov_len  = 512;
 *     scsi_task_set_iov_out(task, &iov[0], 2);
 */
EXTERN int scsi_task_add_data_in_buffer(struct scsi_task *task, int len, unsigned char *buf);
EXTERN int scsi_task_add_data_out_buffer(struct scsi_task *task, int len, unsigned char *buf);

struct scsi_iovec;
EXTERN void scsi_task_set_iov_out(struct scsi_task *task, struct scsi_iovec *iov, int niov);
EXTERN void scsi_task_set_iov_in(struct scsi_task *task, struct scsi_iovec *iov, int niov);

EXTERN int scsi_task_get_status(struct scsi_task *task, struct scsi_sense *sense);

/*
 * This function returns 1 if the task is queued for send (for example, the task has been created
 * with an asynchronous request and has not been put on the wire right away due to the socket
 * or the ISCSI session state); otherwise returns 0.
 */
EXTERN int iscsi_scsi_is_task_in_outqueue(struct iscsi_context *iscsi, struct scsi_task *task);

/*
 * This function is used when you want to cancel a scsi task.
 * The callback for the task will immediately be invoked with SCSI_STATUS_CANCELLED.
 * The cancellation is only local in libiscsi. If the task is already in-flight
 * this call will not cancel the task at the target.
 * To cancel the task also a the target you need to call the task management functions.
 */
EXTERN int
iscsi_scsi_cancel_task(struct iscsi_context *iscsi,
		       struct scsi_task *task);

/*
 * This function is used when you want to cancel all scsi tasks.
 * The callback for the tasks will immediately be invoked with SCSI_STATUS_CANCELLED.
 * The cancellation is only local in libiscsi. If the tasks are already in-flight
 * this call will not cancel the tasks at the target.
 * To cancel the tasks also a the target you need to call the task management functions.
 */
EXTERN void
iscsi_scsi_cancel_all_tasks(struct iscsi_context *iscsi);

/*
 * This function is to set the debugging level where level is
 *
 * 0  = disabled (default)
 * 1  = errors only
 * 2  = connection related info
 * 3  = user set variables
 * 4  = function calls
 * 5  = ...
 * 10 = everything
 */
EXTERN void
iscsi_set_log_level(struct iscsi_context *iscsi, int level);

typedef void (*iscsi_log_fn)(int level, const char *mesage);

/* Set the logging function to use */
EXTERN void iscsi_set_log_fn(struct iscsi_context *iscsi, iscsi_log_fn fn);

/* predefined log function that just writes to stderr */
EXTERN void iscsi_log_to_stderr(int level, const char *message);

/*
 * This function is to set the TCP_USER_TIMEOUT option. It has to be called after iscsi
 * context creation. The value given in ms is then applied each time a new socket is created.
 */
EXTERN void
iscsi_set_tcp_user_timeout(struct iscsi_context *iscsi, int timeout_ms);

/*
 * This function is to set the TCP_KEEPIDLE option. It has to be called after iscsi
 * context creation.
 */
EXTERN void
iscsi_set_tcp_keepidle(struct iscsi_context *iscsi, int value);

/*
 * This function is to set the TCP_KEEPCNT option. It has to be called after iscsi
 * context creation.
 */
EXTERN void
iscsi_set_tcp_keepcnt(struct iscsi_context *iscsi, int value);

/*
 * This function is to set the TCP_KEEPINTVL option. It has to be called after iscsi
 * context creation.
 */
EXTERN void
iscsi_set_tcp_keepintvl(struct iscsi_context *iscsi, int value);

/*
 * This function is to set the TCP_SYNCNT option. It has to be called after iscsi
 * context creation.
 */
EXTERN void
iscsi_set_tcp_syncnt(struct iscsi_context *iscsi, int value);

/*
 * This function is to set the interface that outbound connections for this socket are bound to.
 * You max specify more than one interface here separated by comma.
 */
EXTERN void
iscsi_set_bind_interfaces(struct iscsi_context *iscsi, char * interfaces);

/*
 * This function is to disable auto reconnect logic.
 *
 *  0 - Disable this feature (auto reconnect)
 *  1 - Enable this feature (no auto reconnect)
 */
EXTERN void
iscsi_set_noautoreconnect(struct iscsi_context *iscsi, int state);


/* This function is to set if we should retry a failed reconnect
   
   count is defined as follows:
    -1 -> retry forever (default)
    0  -> never retry
    n  -> retry n times
*/
EXTERN void
iscsi_set_reconnect_max_retries(struct iscsi_context *iscsi, int count);

/* Set to true to have libiscsi use TESTUNITREADY and consume any/all
   UnitAttentions that may have triggered in the target.
 */
EXTERN void
iscsi_set_no_ua_on_reconnect(struct iscsi_context *iscsi, int state);

/* Set callback on iscsi file descriptor on duplicating */
EXTERN void
iscsi_set_fd_dup_cb(struct iscsi_context *iscsi,
		    void (*cb)(struct iscsi_context *iscsi, void *opaque),
		    void *opaque);

#ifdef __cplusplus
}
#endif

#endif /* __iscsi_h__ */