Annotation of embedaddon/istgt/src/istgt_proto.h, revision 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_PROTO_H
! 29: #define ISTGT_PROTO_H
! 30:
! 31: #ifdef HAVE_CONFIG_H
! 32: #include "config.h"
! 33: #endif
! 34:
! 35: #ifdef USE_ATOMIC
! 36: #ifdef HAVE_SYS_TYPES_H
! 37: #include <sys/types.h>
! 38: #endif
! 39: #ifdef HAVE_MACHINE_ATOMIC_H
! 40: #include <machine/atomic.h>
! 41: #endif
! 42: #ifdef HAVE_SYS_ATOMIC_H
! 43: #include <sys/atomic.h>
! 44: #endif
! 45: #endif /* USE_ATOMIC */
! 46:
! 47: #include <stdint.h>
! 48: #include <signal.h>
! 49: #include <sys/socket.h>
! 50: #ifdef HAVE_UUID_H
! 51: #include <uuid.h>
! 52: #endif
! 53: #include "istgt.h"
! 54: #include "istgt_iscsi.h"
! 55: #include "istgt_lu.h"
! 56:
! 57: /* istgt_iscsi.c */
! 58: int istgt_chap_get_authinfo(ISTGT_CHAP_AUTH *auth, const char *authfile, const char *authuser, int ag_tag);
! 59: int istgt_iscsi_transfer_out(CONN_Ptr conn, ISTGT_LU_CMD_Ptr lu_cmd, uint8_t *data, int alloc_len, int transfer_len);
! 60: int istgt_create_sess(ISTGT_Ptr istgt, CONN_Ptr conn, ISTGT_LU_Ptr lu);
! 61: int istgt_create_conn(ISTGT_Ptr istgt, PORTAL_Ptr portal, int sock, struct sockaddr *sa, socklen_t salen);
! 62: void istgt_lock_gconns(void);
! 63: void istgt_unlock_gconns(void);
! 64: int istgt_get_gnconns(void);
! 65: CONN_Ptr istgt_get_gconn(int idx);
! 66: int istgt_get_active_conns(void);
! 67: CONN_Ptr istgt_find_conn(const char *initiator_port, const char *target_name, uint16_t tsih);
! 68: int istgt_iscsi_init(ISTGT_Ptr istgt);
! 69: int istgt_iscsi_shutdown(ISTGT_Ptr istgt);
! 70: int istgt_iscsi_copy_pdu(ISCSI_PDU_Ptr dst_pdu, ISCSI_PDU_Ptr src_pdu);
! 71:
! 72: /* istgt_lu.c */
! 73: int istgt_lu_allow_netmask(const char *netmask, const char *addr);
! 74: int istgt_lu_access(CONN_Ptr conn, ISTGT_LU_Ptr lu, const char *iqn, const char *addr);
! 75: int istgt_lu_visible(ISTGT_Ptr istgt, ISTGT_LU_Ptr lu, const char *iqn, int pg_tag);
! 76: int istgt_lu_sendtargets(CONN_Ptr conn, const char *iiqn, const char *iaddr, const char *tiqn, uint8_t *data, int alloc_len, int data_len);
! 77: ISTGT_LU_Ptr istgt_lu_find_target(ISTGT_Ptr istgt, const char *target_name);
! 78: uint16_t istgt_lu_allocate_tsih(ISTGT_LU_Ptr lu, const char *initiator_port, int tag);
! 79: void istgt_lu_free_tsih(ISTGT_LU_Ptr lu, uint16_t tsih, char *initiator_port);
! 80: char *istgt_lu_get_media_flags_string(int flags, char *buf, size_t len);
! 81: uint64_t istgt_lu_get_devsize(const char *file);
! 82: uint64_t istgt_lu_get_filesize(const char *file);
! 83: uint64_t istgt_lu_parse_size(const char *size);
! 84: int istgt_lu_parse_media_flags(const char *flags);
! 85: uint64_t istgt_lu_parse_media_size(const char *file, const char *size, int *flags);
! 86: PORTAL *istgt_lu_find_portalgroup(ISTGT_Ptr istgt, int tag);
! 87: INITIATOR_GROUP *istgt_lu_find_initiatorgroup(ISTGT_Ptr istgt, int tag);
! 88: int istgt_lu_init(ISTGT_Ptr istgt);
! 89: int istgt_lu_set_all_state(ISTGT_Ptr istgt, ISTGT_STATE state);
! 90: int istgt_lu_create_threads(ISTGT_Ptr istgt);
! 91: int istgt_lu_shutdown(ISTGT_Ptr istgt);
! 92: int istgt_lu_islun2lun(uint64_t islun);
! 93: uint64_t istgt_lu_lun2islun(int lun, int maxlun);
! 94: int istgt_lu_reset(ISTGT_LU_Ptr lu, uint64_t lun);
! 95: int istgt_lu_execute(CONN_Ptr conn, ISTGT_LU_CMD_Ptr lu_cmd);
! 96: int istgt_lu_create_task(CONN_Ptr conn, ISTGT_LU_CMD_Ptr lu_cmd, ISTGT_LU_TASK_Ptr lu_task, int lun);
! 97: int istgt_lu_destroy_task(ISTGT_LU_TASK_Ptr lu_task);
! 98: int istgt_lu_clear_task_IT(CONN_Ptr conn, ISTGT_LU_Ptr lu);
! 99: int istgt_lu_clear_task_ITL(CONN_Ptr conn, ISTGT_LU_Ptr lu, uint64_t lun);
! 100: int istgt_lu_clear_task_ITLQ(CONN_Ptr conn, ISTGT_LU_Ptr lu, uint64_t lun, uint32_t CmdSN);
! 101: int istgt_lu_clear_all_task(ISTGT_LU_Ptr lu, uint64_t lun);
! 102:
! 103: /* istgt_lu_ctl.c */
! 104: int istgt_create_uctl(ISTGT_Ptr istgt, PORTAL_Ptr portal, int sock, struct sockaddr *sa, socklen_t salen);
! 105: int istgt_init_uctl(ISTGT_Ptr istgt);
! 106:
! 107: /* istgt_lu_disk.c */
! 108: struct istgt_lu_disk_t;
! 109: void istgt_scsi_dump_cdb(uint8_t *cdb);
! 110: void istgt_strcpy_pad(uint8_t *dst, size_t size, const char *src, int pad);
! 111: #ifdef HAVE_UUID_H
! 112: uint64_t istgt_uuid2uint64(uuid_t *uuid);
! 113: #endif /* HAVE_UUID_H */
! 114: uint64_t istgt_get_lui(const char *name, int lun);
! 115: uint64_t istgt_get_rkey(const char *initiator_name, uint64_t lui);
! 116: int istgt_lu_set_lid(uint8_t *buf, uint64_t vid);
! 117: int istgt_lu_set_id(uint8_t *buf, uint64_t vid);
! 118: int istgt_lu_set_extid(uint8_t *buf, uint64_t vid, uint64_t vide);
! 119: int istgt_lu_scsi_build_sense_data(uint8_t *data, int sk, int asc, int ascq);
! 120: int istgt_lu_scsi_build_sense_data2(uint8_t *data, int sk, int asc, int ascq);
! 121: int istgt_lu_disk_init(ISTGT_Ptr istgt, ISTGT_LU_Ptr lu);
! 122: int istgt_lu_disk_shutdown(ISTGT_Ptr istgt, ISTGT_LU_Ptr lu);
! 123: int istgt_lu_disk_reset(ISTGT_LU_Ptr lu, int lun);
! 124: int istgt_lu_disk_execute(CONN_Ptr conn, ISTGT_LU_CMD_Ptr lu_cmd);
! 125: int istgt_lu_disk_queue_clear_IT(CONN_Ptr conn, ISTGT_LU_Ptr lu);
! 126: int istgt_lu_disk_queue_clear_ITL(CONN_Ptr conn, ISTGT_LU_Ptr lu, int lun);
! 127: int istgt_lu_disk_queue_clear_ITLQ(CONN_Ptr conn, ISTGT_LU_Ptr lu, int lun, uint32_t CmdSN);
! 128: int istgt_lu_disk_queue_clear_all(ISTGT_LU_Ptr lu, int lun);
! 129: int istgt_lu_disk_queue(CONN_Ptr conn, ISTGT_LU_CMD_Ptr lu_cmd);
! 130: int istgt_lu_disk_queue_count(ISTGT_LU_Ptr lu, int *lun);
! 131: int istgt_lu_disk_queue_start(ISTGT_LU_Ptr lu, int lun);
! 132: void istgt_lu_disk_aio_done(siginfo_t *info);
! 133:
! 134: /* istgt_lu_dvd.c */
! 135: struct istgt_lu_dvd_t;
! 136: int istgt_lu_dvd_media_present(struct istgt_lu_dvd_t *spec);
! 137: int istgt_lu_dvd_media_lock(struct istgt_lu_dvd_t *spec);
! 138: int istgt_lu_dvd_load_media(struct istgt_lu_dvd_t *spec);
! 139: int istgt_lu_dvd_unload_media(struct istgt_lu_dvd_t *spec);
! 140: int istgt_lu_dvd_change_media(struct istgt_lu_dvd_t *spec, char *type, char *flags, char *file, char *size);
! 141: int istgt_lu_dvd_init(ISTGT_Ptr istgt, ISTGT_LU_Ptr lu);
! 142: int istgt_lu_dvd_shutdown(ISTGT_Ptr istgt, ISTGT_LU_Ptr lu);
! 143: int istgt_lu_dvd_reset(ISTGT_LU_Ptr lu, int lun);
! 144: int istgt_lu_dvd_execute(CONN_Ptr conn, ISTGT_LU_CMD_Ptr lu_cmd);
! 145:
! 146: /* istgt_lu_tape.c */
! 147: struct istgt_lu_tape_t;
! 148: int istgt_lu_tape_media_present(struct istgt_lu_tape_t *spec);
! 149: int istgt_lu_tape_media_lock(struct istgt_lu_tape_t *spec);
! 150: int istgt_lu_tape_load_media(struct istgt_lu_tape_t *spec);
! 151: int istgt_lu_tape_unload_media(struct istgt_lu_tape_t *spec);
! 152: int istgt_lu_tape_change_media(struct istgt_lu_tape_t *spec, char *type, char *flags, char *file, char *size);
! 153: int istgt_lu_tape_init(ISTGT_Ptr istgt, ISTGT_LU_Ptr lu);
! 154: int istgt_lu_tape_shutdown(ISTGT_Ptr istgt, ISTGT_LU_Ptr lu);
! 155: int istgt_lu_tape_reset(ISTGT_LU_Ptr lu, int lun);
! 156: int istgt_lu_tape_execute(CONN_Ptr conn, ISTGT_LU_CMD_Ptr lu_cmd);
! 157:
! 158: /* istgt_lu_pass.c */
! 159: int istgt_lu_pass_init(ISTGT_Ptr istgt, ISTGT_LU_Ptr lu);
! 160: int istgt_lu_pass_shutdown(ISTGT_Ptr istgt, ISTGT_LU_Ptr lu);
! 161: int istgt_lu_pass_reset(ISTGT_LU_Ptr lu, int lun);
! 162: int istgt_lu_pass_execute(CONN_Ptr conn, ISTGT_LU_CMD_Ptr lu_cmd);
! 163:
! 164: #ifdef USE_ATOMIC
! 165: static inline int
! 166: istgt_lu_get_state(ISTGT_LU_Ptr lu)
! 167: {
! 168: ISTGT_STATE state;
! 169: #if defined HAVE_ATOMIC_LOAD_ACQ_INT
! 170: state = atomic_load_acq_int((unsigned int *)&lu->state);
! 171: #elif defined HAVE_ATOMIC_OR_UINT_NV
! 172: state = (int)atomic_or_uint_nv((unsigned int *)&lu->state, 0);
! 173: #else
! 174: #error "no atomic operation"
! 175: #endif
! 176: return state;
! 177: }
! 178: static inline void
! 179: istgt_lu_set_state(ISTGT_LU_Ptr lu, ISTGT_STATE state)
! 180: {
! 181: #if defined HAVE_ATOMIC_STORE_REL_INT
! 182: atomic_store_rel_int((unsigned int *)&lu->state, state);
! 183: #elif defined HAVE_ATOMIC_SWAP_UINT
! 184: (void)atomic_swap_uint((unsigned int *)&lu->state, state);
! 185: #if defined HAVE_MEMBAR_PRODUCER
! 186: membar_producer();
! 187: #endif
! 188: #else
! 189: #error "no atomic operation"
! 190: #endif
! 191: }
! 192: #else
! 193: static inline int
! 194: istgt_lu_get_state(ISTGT_LU_Ptr lu)
! 195: {
! 196: ISTGT_STATE state;
! 197: MTX_LOCK(&lu->state_mutex);
! 198: state = lu->state;
! 199: MTX_UNLOCK(&lu->state_mutex);
! 200: return state;
! 201: }
! 202:
! 203: static inline void
! 204: istgt_lu_set_state(ISTGT_LU_Ptr lu, ISTGT_STATE state)
! 205: {
! 206: MTX_LOCK(&lu->state_mutex);
! 207: lu->state = state;
! 208: MTX_UNLOCK(&lu->state_mutex);
! 209: }
! 210: #endif /* USE_ATOMIC */
! 211:
! 212: #endif /* ISTGT_PROTO_H */
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>