📄 initiator_utilities.h
字号:
/* initiator/initiator_utilities.h * * vi: set autoindent tabstop=8 shiftwidth=8 : * * This file contains auxilliary functions for iscsi initiator code that * are responsible for connecting and maintaining sessions between * initiator and target. * * Copyright (C) 2001-2004 InterOperability Lab (IOL) * University of New Hampshire (UNH) * Durham, NH 03824 * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, * USA. * * The name of IOL and/or UNH may not be used to endorse or promote * products derived from this software without specific prior * written permission.*/#ifndef _INITIATOR_UTILITIES_H#define _INITIATOR_UTILITIES_H/* keeps track of maximum number of io vector slots actually used */extern int max_iov_count;/* allocates but does not initialize a new r2t cookie for this session */struct r2t_cookie * __attribute__ ((no_instrument_function))create_r2t_cookie(struct session *this_session);/* finishes initializing an r2t cookie and adds it to end of command's * cookie list */void __attribute__ ((no_instrument_function))hookup_r2t_cookie(struct r2t_cookie *cookie, struct session *this_session, struct connection *this_connection, struct command *this_command, __u32 local_ttt);/* put a no longer used cookie structure on available list for session */void __attribute__ ((no_instrument_function))uncreate_r2t_cookie(struct r2t_cookie *cookie, struct session *this_session);/* removes cookie from this command's and this connection's cookie lists */void __attribute__ ((no_instrument_function))free_r2t_cookie(struct connection *this_connection, struct command *this_command, struct r2t_cookie *cookie);/* build a SCSI Command with write data to be sent */voidbuild_write_command(struct session *current_session, struct connection *current_connection, struct command *new_command);/* * executed only by tx thread. * the session->sess_lock MUST be held by the calling process/thread. * * Called only from ready_to_xmit(). * At the time of the call, cookie is known to be related_command's * first_cookie, it is known to be non-NULL, it is known to be at the * beginning of related_connection's order_link, and it is known to * have a positive xfer length. * * Called to build a DataOut pdu header in the "data" area of the * "related_command" if that area is currently unused (else does nothing). * The amount of data to send is controlled by the first "cookie" for * that command, but the location(s) and layout of the data in memory * are controlled by the SCpnt field in the "related_command" when * setting up the msghdr and io vector in the "related_command". * Returns number of bytes newly set up for transmission (0 if none). */intsetup_dataoutpdu(struct connection *related_connection, struct command *related_command, struct r2t_cookie *cookie);/* "prints" statistics on iov usage into buf, * returns no. of chars printed. */intprint_iovs(char *buf);voidendup_iovs(void);/* Reads an iscsi pdu header into conn->rx_buf from conn->sock. * The header length is 48 without header digests, 52 bytes with. * Uses rx_msg and rx_iov structures in "conn" to control the read. * Session lock MUST be held by the caller. * Returns header length (48 or 52) on success with session lock held, * < 0 on failure with session lock not held. */intrecv_pdu_header(struct connection *conn);/**************************************************************************** * This function is responsible for making the checks for exp_cmd_sn and * max_cmd_sn values in the received iSCSI header from the target. * Parameters: exp_cmd_sn from the PDU (in host byte order) * max_cmd_sn from the PDU (in host byte order) * cur_session, pointing to the struct session * Return value: 0, if the exp_cmd_sn and max_cmd_sn are valid * -1, if either exp_cmd_sn or max_cmd_sn is invalid. ****************************************************************************/int __attribute__ ((no_instrument_function))check_and_update_cmd_sns(__u32 exp_cmd_sn, __u32 max_cmd_sn, struct session *cur_session);/* when called, SCpnt and SCpnt->scsi_done must both be non-NULL, * and session->sess_lock must be held. */static void inline __attribute__ ((no_instrument_function))call_back_scsi_done(struct scsi_cmnd *SCpnt){/* RDR */#ifndef K26 /* scsi midlevel wants io_request_lock held during callbacks */ spin_lock(&io_request_lock);#endif /* post to SCSI midlevel that this command is completed */ (*SCpnt->scsi_done) (SCpnt);/* RDR */#ifndef K26 spin_unlock(&io_request_lock);#endif}/* Calls SCSI Mid-level's scsi_done callback with result, * (and with session lock held). * Then frees up storage allocated to old command. * Must be called with session lock held by caller. */voidfree_pending_command(struct command *old_command, struct connection *current_connection);voidalloc_inquiry_stuff(struct session *sess, __u32 lun, int size);voidfree_inquiry_stuff(struct session *sess, __u32 lun);intsend_data_ack_snack(struct connection *current_connection, struct command *related_command, __u32 increment);/* * executed only by rx thread. * process the common parts of a SCSIResponse PDU and a DataIn * PDU with the S-bit set ("phase collapse") * the current_session->sess_lock MUST be held by the calling thread. * Returns >0 on success, session lock is locked * =0 on failure, session lock is locked * <0 on failure, session lock is NOT locked */intdo_scsi_response(struct connection *current_connection, struct command *related_command, struct iscsi_targ_scsi_rsp *header, int received, __u8 * buffer);/* * executed by init_recovery thread, scsi midlevel process. * the session->sess_lock MUST be held by the calling process/thread. * Called to allocate space for a struct command and then initialize it. * Returns pointer to newly allocated and initialized command if all ok, * else NULL. */struct command *setup_command(struct scsi_cmnd * Cmnd, struct connection *conn);/* * the current_session->sess_lock MUST be held by the calling process/thread. * Called by build_session_skeleton(), free_pending_command(), * and drive_text_negotiate(). * put old command structure on end of session's free list */static inline void __attribute__ ((no_instrument_function))endup_command(struct command *old_command, struct session *current_session){ list_add_tail(&old_command->link, ¤t_session->free_commands);}/* Called to receive *size bytes of data (can be 0) into a scsi buffer * pointed to by the related_command (can be NULL), * plus over_flow_data_size bytes of data into a locally allocated * buffer. All the data is padded and checksummed as necessary. * Returns > 0 if ok, 0 on err & still hold session->sess_lock, * <0 on err and lost session->sess_lock. * ptr to local buffer is set on return if allocated else NULL * Note: if not NULL, this buffer must be freed by caller! * On entry MUST have (*size + over_flow_data_size) > 0.*/intrecv_data_in_data(struct connection *current_connection, struct command *related_command, struct iscsi_targ_scsi_data_in *data_in_header, __u32 *size, int over_flow_data_size, char **over_flow_buffer);/* Called to receive "extra" data into a locally allocated buffer * and to compute final data digest checksum on it if necessary. * Returns > 0 if ok, 0 on err & still hold session->sess_lock, * <0 on err and lost session->sess_lock. * ptr to buffer is set on return if successful else NULL * Note: if not NULL, this buffer must be freed by caller! * On entry MUST have size > 0.*/static inline int __attribute__ ((no_instrument_function))recv_local_data(struct connection *current_connection, struct command *related_command, __u32 size, char **over_flow_buffer){ __u32 dummy_size = 0; return recv_data_in_data(current_connection, related_command, NULL, &dummy_size, size, over_flow_buffer);}/* Called to ignore "extra" data by reading it into a locally allocated * buffer and then throwing it away. * Compute final data digest checksum on it if necessary. * Returns > 0 if ok, 0 on err & still hold session->sess_lock, * <0 on err and lost session->sess_lock. * On entry MUST have size > 0.*/static inline int __attribute__ ((no_instrument_function))recv_ignore_data(struct connection *current_connection, __u32 size){ int retval; __u32 dummy_size = 0; char *over_flow_buffer = NULL; retval = recv_data_in_data(current_connection, NULL, NULL, &dummy_size, size, &over_flow_buffer); if (over_flow_buffer) my_kfree((void **) &over_flow_buffer, "local buf"); return retval;}/* here to attach cmnds to the list after they have been properly * filled in. The reason we needed to be a bit careful is that other * portions of the driver might be attempting to traverse the list * at the same time that we are here so we don't want to attach an * invalid entry. Therefore, the session lock must be held by * the calling process/thread. */void attach_pending_command(struct command *new_command, struct connection *current_connection, int need_itt);#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -