Annotation of embedaddon/istgt/src/istgt_lu.h, revision 1.1.1.1

1.1       misho       1: /*
                      2:  * Copyright (C) 2008-2011 Daisuke Aoyama <aoyama@peach.ne.jp>.
                      3:  * All rights reserved.
                      4:  *
                      5:  * Redistribution and use in source and binary forms, with or without
                      6:  * modification, are permitted provided that the following conditions
                      7:  * are met:
                      8:  * 1. Redistributions of source code must retain the above copyright
                      9:  *    notice, this list of conditions and the following disclaimer.
                     10:  * 2. Redistributions in binary form must reproduce the above copyright
                     11:  *    notice, this list of conditions and the following disclaimer in the
                     12:  *    documentation and/or other materials provided with the distribution.
                     13:  *
                     14:  * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
                     15:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     16:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     17:  * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
                     18:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     19:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     20:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     21:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     22:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     23:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     24:  * SUCH DAMAGE.
                     25:  *
                     26:  */
                     27: 
                     28: #ifndef ISTGT_LU_H
                     29: #define ISTGT_LU_H
                     30: 
                     31: #include <pthread.h>
                     32: #include <time.h>
                     33: #include "istgt.h"
                     34: 
                     35: #define MAX_LU_LUN 16
                     36: #define MAX_LU_LUN_SLOT 8
                     37: #define MAX_LU_TSIH 256
                     38: #define MAX_LU_MAP 256
                     39: #define MAX_LU_SERIAL_STRING 32
                     40: #define MAX_LU_RESERVE 256
                     41: #define MAX_LU_RESERVE_IPT 256
                     42: #define MAX_LU_QUEUE_DEPTH 256
                     43: 
                     44: #define USE_LU_TAPE_DLT8000
                     45: 
                     46: #define DEFAULT_LU_BLOCKLEN 512
                     47: #define DEFAULT_LU_BLOCKLEN_DISK DEFAULT_LU_BLOCKLEN
                     48: #define DEFAULT_LU_BLOCKLEN_DVD 2048
                     49: #define DEFAULT_LU_BLOCKLEN_TAPE DEFAULT_LU_BLOCKLEN
                     50: #define DEFAULT_LU_QUEUE_DEPTH 32
                     51: #define DEFAULT_LU_ROTATIONRATE 7200   /* 7200 rpm */
                     52: #define DEFAULT_LU_FORMFACTOR 0x02     /* 3.5 inch */
                     53: 
                     54: #if defined (__FreeBSD__)
                     55: #define DEFAULT_LU_VENDOR "FreeBSD"
                     56: #elif defined (__NetBSD__)
                     57: #define DEFAULT_LU_VENDOR "NetBSD"
                     58: #elif defined (__OpenBSD__)
                     59: #define DEFAULT_LU_VENDOR "OpenBSD"
                     60: #else
                     61: //#define DEFAULT_LU_VENDOR "PEACHNW"
                     62: #define DEFAULT_LU_VENDOR "FreeBSD"
                     63: #endif
                     64: 
                     65: #define DEFAULT_LU_VENDOR_DISK DEFAULT_LU_VENDOR
                     66: #define DEFAULT_LU_VENDOR_DVD  DEFAULT_LU_VENDOR
                     67: #ifndef USE_LU_TAPE_DLT8000
                     68: #define DEFAULT_LU_VENDOR_TAPE DEFAULT_LU_VENDOR
                     69: #else
                     70: #define DEFAULT_LU_VENDOR_TAPE "QUANTUM"
                     71: #endif /* !USE_LU_TAPE_DLT8000 */
                     72: #define DEFAULT_LU_PRODUCT      "iSCSI UNIT"
                     73: #define DEFAULT_LU_PRODUCT_DISK "iSCSI DISK"
                     74: #define DEFAULT_LU_PRODUCT_DVD  "iSCSI DVD"
                     75: #ifndef USE_LU_TAPE_DLT8000
                     76: #define DEFAULT_LU_PRODUCT_TAPE "iSCSI TAPE"
                     77: #else
                     78: #define DEFAULT_LU_PRODUCT_TAPE "DLT8000"
                     79: #endif /* !USE_LU_TAPE_DLT8000 */
                     80: #define DEFAULT_LU_REVISION "0001"
                     81: #define DEFAULT_LU_REVISION_DISK DEFAULT_LU_REVISION
                     82: #define DEFAULT_LU_REVISION_DVD  DEFAULT_LU_REVISION
                     83: #ifndef USE_LU_TAPE_DLT8000
                     84: #define DEFAULT_LU_REVISION_TAPE DEFAULT_LU_REVISION
                     85: #else
                     86: #define DEFAULT_LU_REVISION_TAPE "C001"
                     87: #endif /* !USE_LU_TAPE_DLT8000 */
                     88: #define MAX_INQUIRY_SERIAL 16
                     89: 
                     90: #define ISTGT_LU_WORK_BLOCK_SIZE (1ULL * 1024ULL * 1024ULL)
                     91: #define ISTGT_LU_MAX_WRITE_CACHE_SIZE (8ULL * 1024ULL * 1024ULL)
                     92: #define ISTGT_LU_MEDIA_SIZE_MIN (1ULL * 1024ULL * 1024ULL)
                     93: #define ISTGT_LU_MEDIA_EXTEND_UNIT (256ULL * 1024ULL * 1024ULL)
                     94: #define ISTGT_LU_1GB (1ULL * 1024ULL * 1024ULL * 1024ULL)
                     95: #define ISTGT_LU_1MB (1ULL * 1024ULL * 1024ULL)
                     96: 
                     97: typedef enum {
                     98:        ISTGT_LU_FLAG_MEDIA_READONLY = 0x00000001,
                     99:        ISTGT_LU_FLAG_MEDIA_AUTOSIZE = 0x00000002,
                    100:        ISTGT_LU_FLAG_MEDIA_EXTEND   = 0x00000010,
                    101:        ISTGT_LU_FLAG_MEDIA_DYNAMIC  = 0x00000020,
                    102: } ISTGT_LU_FLAG;
                    103: 
                    104: typedef enum {
                    105:        ISTGT_LU_TYPE_NONE = 0,
                    106:        ISTGT_LU_TYPE_PASS = 1,
                    107:        ISTGT_LU_TYPE_DISK = 2,
                    108:        ISTGT_LU_TYPE_DVD = 3,
                    109:        ISTGT_LU_TYPE_TAPE = 4,
                    110: } ISTGT_LU_TYPE;
                    111: 
                    112: typedef enum {
                    113:        ISTGT_LU_LUN_TYPE_NONE = 0,
                    114:        ISTGT_LU_LUN_TYPE_DEVICE = 1,
                    115:        ISTGT_LU_LUN_TYPE_STORAGE = 2,
                    116:        ISTGT_LU_LUN_TYPE_REMOVABLE = 3,
                    117:        ISTGT_LU_LUN_TYPE_SLOT = 4,
                    118: } ISTGT_LU_LUN_TYPE;
                    119: 
                    120: typedef struct istgt_lu_device_t {
                    121:        char *file;
                    122: } ISTGT_LU_DEVICE;
                    123: 
                    124: typedef struct istgt_lu_storage_t {
                    125:        int fd;
                    126:        char *file;
                    127:        uint64_t size;
                    128: } ISTGT_LU_STORAGE;
                    129: 
                    130: typedef struct istgt_lu_removable_t {
                    131:        int type;
                    132:        int id;
                    133:        int flags;
                    134:        int fd;
                    135:        char *file;
                    136:        uint64_t size;
                    137: } ISTGT_LU_REMOVABLE;
                    138: 
                    139: typedef struct istgt_lu_slot_t {
                    140:        int maxslot;
                    141:        int present[MAX_LU_LUN_SLOT];
                    142:        int flags[MAX_LU_LUN_SLOT];
                    143:        char *file[MAX_LU_LUN_SLOT];
                    144:        uint64_t size[MAX_LU_LUN_SLOT];
                    145: } ISTGT_LU_SLOT;
                    146: 
                    147: typedef struct istgt_lu_lun_t {
                    148:        int type;
                    149:        union {
                    150:                ISTGT_LU_DEVICE device;
                    151:                ISTGT_LU_STORAGE storage;
                    152:                ISTGT_LU_REMOVABLE removable;
                    153:                ISTGT_LU_SLOT slot;
                    154:        } u;
                    155:        int rotationrate;
                    156:        int formfactor;
                    157:        int readcache;
                    158:        int writecache;
                    159:        char *serial;
                    160:        void *spec;
                    161: } ISTGT_LU_LUN;
                    162: typedef ISTGT_LU_LUN *ISTGT_LU_LUN_Ptr;
                    163: 
                    164: typedef struct istgt_lu_tsih_t {
                    165:        int tag;
                    166:        uint16_t tsih;
                    167:        char *initiator_port;
                    168: } ISTGT_LU_TSIH;
                    169: 
                    170: typedef enum {
                    171:        AAS_ACTIVE_OPTIMIZED = 0x00,
                    172:        AAS_ACTIVE_NON_OPTIMIZED = 0x01,
                    173:        AAS_STANDBY = 0x02,
                    174:        AAS_UNAVAILABLE = 0x03,
                    175:        AAS_TRANSITIONING = 0x0F,
                    176: 
                    177:        AAS_STATUS_NO = 0x0000,
                    178:        AAS_STATUS_STPG = 0x0100,
                    179:        AAS_STATUS_IMPLICIT = 0x0200,
                    180: } ISTGT_LU_AAS;
                    181: 
                    182: typedef struct istgt_lu_map_t {
                    183:        int pg_tag;
                    184:        int pg_aas;
                    185:        int ig_tag;
                    186: } ISTGT_LU_MAP;
                    187: 
                    188: typedef struct istgt_lu_t {
                    189:        int num;
                    190:        char *name;
                    191:        char *alias;
                    192: 
                    193:        char *inq_vendor;
                    194:        char *inq_product;
                    195:        char *inq_revision;
                    196:        char *inq_serial;
                    197: 
                    198:        ISTGT_Ptr istgt;
                    199:        ISTGT_STATE state;
                    200:        pthread_mutex_t mutex;
                    201:        pthread_mutex_t state_mutex;
                    202:        pthread_mutex_t queue_mutex;
                    203:        pthread_cond_t queue_cond;
                    204:        pthread_t thread;
                    205: 
                    206:        uint16_t last_tsih;
                    207: 
                    208:        int no_auth_chap;
                    209:        int auth_chap;
                    210:        int auth_chap_mutual;
                    211:        int auth_group;
                    212:        int header_digest;
                    213:        int data_digest;
                    214: 
                    215:        int MaxOutstandingR2T;
                    216:        int DefaultTime2Wait;
                    217:        int DefaultTime2Retain;
                    218:        int FirstBurstLength;
                    219:        int MaxBurstLength;
                    220:        int MaxRecvDataSegmentLength;
                    221:        int InitialR2T;
                    222:        int ImmediateData;
                    223:        int DataPDUInOrder;
                    224:        int DataSequenceInOrder;
                    225:        int ErrorRecoveryLevel;
                    226: 
                    227:        int type;
                    228:        int online;
                    229:        int readonly;
                    230:        int blocklen;
                    231:        int queue_depth;
                    232: 
                    233:        int maxlun;
                    234:        ISTGT_LU_LUN lun[MAX_LU_LUN];
                    235:        int maxtsih;
                    236:        ISTGT_LU_TSIH tsih[MAX_LU_TSIH];
                    237:        int maxmap;
                    238:        ISTGT_LU_MAP map[MAX_LU_MAP];
                    239: } ISTGT_LU;
                    240: typedef ISTGT_LU *ISTGT_LU_Ptr;
                    241: 
                    242: typedef struct istgt_lu_cmd_t {
                    243:        struct iscsi_pdu_t *pdu;
                    244:        ISTGT_LU_Ptr lu;
                    245: 
                    246:        int I_bit;
                    247:        int F_bit;
                    248:        int R_bit;
                    249:        int W_bit;
                    250:        int Attr_bit;
                    251:        uint64_t lun;
                    252:        uint32_t task_tag;
                    253:        uint32_t transfer_len;
                    254:        uint32_t CmdSN;
                    255:        uint8_t *cdb;
                    256: 
                    257:        uint8_t *iobuf;
                    258:        int iobufsize;
                    259:        uint8_t *data;
                    260:        int data_len;
                    261:        int alloc_len;
                    262: 
                    263:        int status;
                    264:        uint8_t *sense_data;
                    265:        int sense_data_len;
                    266:        int sense_alloc_len;
                    267: } ISTGT_LU_CMD;
                    268: typedef ISTGT_LU_CMD *ISTGT_LU_CMD_Ptr;
                    269: 
                    270: enum {
                    271:        ISTGT_LU_TASK_RESULT_IMMEDIATE = 0,
                    272:        ISTGT_LU_TASK_RESULT_QUEUE_OK = 1,
                    273:        ISTGT_LU_TASK_RESULT_QUEUE_FULL = 2,
                    274: } ISTGT_LU_TASK_RESULT;
                    275: 
                    276: enum {
                    277:        ISTGT_LU_TASK_RESPONSE = 0,
                    278:        ISTGT_LU_TASK_REQPDU = 1,
                    279: } ISTGT_LU_TASK_TYPE;
                    280: 
                    281: typedef struct istgt_lu_task_t {
                    282:        int type;
                    283: 
                    284:        struct istgt_conn_t *conn;
                    285:        char initiator_name[MAX_INITIATOR_NAME];
                    286:        char initiator_port[MAX_INITIATOR_NAME];
                    287:        ISTGT_LU_CMD lu_cmd;
                    288:        int lun;
                    289:        pthread_t thread;
                    290:        int use_cond;
                    291:        pthread_mutex_t trans_mutex;
                    292:        pthread_cond_t trans_cond;
                    293:        pthread_cond_t exec_cond;
                    294: 
                    295:        time_t create_time;
                    296:        int condwait;
                    297: 
                    298:        int dup_iobuf;
                    299:        uint8_t *iobuf;
                    300:        uint8_t *data;
                    301:        uint8_t *sense_data;
                    302: 
                    303:        int offset;
                    304:        int req_execute;
                    305:        int req_transfer_out;
                    306:        int error;
                    307:        int abort;
                    308:        int execute;
                    309:        int complete;
                    310:        int lock;
                    311: } ISTGT_LU_TASK;
                    312: typedef ISTGT_LU_TASK *ISTGT_LU_TASK_Ptr;
                    313: 
                    314: #endif /* ISTGT_LU_H */

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>