⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 iscsi_client.c

📁 一个iSCSI协议实现源代码
💻 C
📖 第 1 页 / 共 4 页
字号:
                        /* Not sure what to do with the status other than print it out if its not good */                        // printk ("iscsi_client - iscsi_client_dispatch() - RX READ_DATA\n");                        if ((hdr.scsi_rsp.status & STATUS_MASK) != GOOD) {                                printk ("iscsi_client - bad status recieve in READ_DATA: %d\n",                                         hdr.scsi_rsp.status & STATUS_MASK);                        }                        if ((hdr.scsi_read.buf_offset + bytes_to_read) > s->current_command->request_bufflen) {                                printk ("iscsi_client - buffer cannot handle request in READ_DATA\n"                                        "               ignoring data!\n");				/* Can't do converging reads if we are doing scatter/gather... FIXME */				while (bytes_to_read) {					if ((bytes_read = iscsi_read (c->sock, scratch_pad, bytes_to_read)) == -1) {						break;					}					bytes_to_read -= bytes_read;				}                        }                                                if ((sg_cnt = s->current_command->use_sg) == 0) {                                int current_read;                                while (bytes_to_read){                                        if ((current_read = iscsi_read (c->sock,                                                                       s->current_command->request_buffer +                                                                       + hdr.scsi_read.buf_offset +                                                                      bytes_read,                                                                       bytes_to_read)) == -1) {                                        }                                        bytes_read += current_read;                                        bytes_to_read -= current_read;                                }                        } else {                                // printk ("iscsi_client - iscsi_client_dispatch() USING sg for cmd buf %p\n", s->current_command->request_buffer);                                sg_lst = s->current_command->request_buffer;                                sg_off = 0;                                /* first find where we should start reading into */                                do {                                        if (hdr.scsi_read.buf_offset < (sg_off += sg_lst->length)) {                                                break;                                        }                                                                        } while (sg_lst++, sg_cnt--);                                /* now sg_lst should point to the element we want to start reading into                                 * and sg_cnt should tell us how many we have left                                  */                                ASSERT (sg_off > hdr.scsi_read.buf_offset);                                ASSERT (sg_off - sg_lst->length <= hdr.scsi_read.buf_offset);                                ASSERT (sg_cnt > 0);                                                                sg_off = hdr.scsi_read.buf_offset - (sg_off - sg_lst->length);                                                                ASSERT (sg_off < sg_lst->length);                                /* This may be a fragmented read so do outside the loop */                                if (bytes_to_read <= sg_lst->length - sg_off) {                                        iscsi_read (c->sock, sg_lst->address + sg_off, bytes_to_read);                                } else {                                        bytes_to_read -= iscsi_read (c->sock, sg_lst->address + sg_off, sg_lst->length - sg_off);                                        do {                                                sg_lst++;                                                sg_cnt--;                                                                                        ASSERT (sg_cnt > 0);                                                if (bytes_to_read <= sg_lst->length) {                                                        bytes_to_read -= iscsi_read (c->sock, sg_lst->address, bytes_to_read);                                                } else {                                                        bytes_to_read -= iscsi_read (c->sock, sg_lst->address, sg_lst->length);                                                }                                        } while (bytes_to_read);                                }                        }                        return 0;                        break;                                        case ISCSI_OP_LOGOUT_RSP:                                                /* just close the socket for now, this is bad */                        sock_release(c->sock);                        printk ("iscsi_client - LOGOUT_RSP RECIEVED\n");                        return 0;                        break;                                        case ISCSI_OP_R2T:                                                // printk ("iscsi_client - iscsi_client_dispatch() - RX R2T\n");                        if (bytes_to_read != 0) {                                printk ("iscsi_client - Leftover bytes in"                                        " R2T %d\n", bytes_to_read);                                while (bytes_to_read) {                                        if ((bytes_read = iscsi_read (c->sock, scratch_pad, bytes_to_read)) == -1) {                                                break;                                        }                                        bytes_to_read -= bytes_read;                                }                        }                                                 memset (&rsp, 0, ISCSI_HDR_SIZE);                        rsp.op = ISCSI_OP_WRITE_DATA;                        rsp.scsi_write.F_reserved1[0] = ISCSI_F_BIT;                        rsp.scsi_write.len = hdr.r2t.desired_data_len;                        rsp.scsi_write.lun = s->current_command->lun;                        rsp.scsi_write.itt = hdr.r2t.itt;                        rsp.scsi_write.ttt = hdr.r2t.ttt;                        hdr.scsi_write.exp_stat_rn = c->stat_rn++;                        rsp.scsi_write.buf_offset = write_off = hdr.r2t.buf_offset;                        iov[0].iov_len = ISCSI_HDR_SIZE;                        iov[0].iov_base = &rsp;                        num_iov = 2;                        if ((sg_cnt = s->current_command->use_sg) == 0) {                                // printk ("NOT USING SG in WRITE\n");                                iov[1].iov_len = rsp.scsi_write.len;                                if (s->current_command->request_bufflen < rsp.scsi_write.len + write_off) {                                        printk ("iscsi_client - Can't handle full write in R2T\n");                                        rsp.scsi_write.len = iov[1].iov_len = s->current_command->request_bufflen - write_off;                                }                                iov[1].iov_base = s->current_command->request_buffer + write_off;                        } else {                                // printk ("USING SG in WRITE\n");                                sg_lst = s->current_command->request_buffer;                                sg_off = 0;                                /* first find where we should start writing from */                                do {                                        if (write_off < (sg_off += sg_lst->length)) {                                                break;                                        }                                                                        } while (sg_lst++, sg_cnt--);                                /* now sg_lst should point to the element we want to start writing from                                 * and sg_cnt should tell us how many we have left                                  */                                ASSERT (sg_off > write_off);                                ASSERT (sg_off - sg_lst->length <= write_off);                                ASSERT (sg_cnt > 0);                                                                sg_off = write_off - (sg_off - sg_lst->length);                                                                ASSERT (sg_off < sg_lst->length);                                /* This may be a fragmented write so do outside the loop */                                bytes_to_write = rsp.scsi_write.len;                                if (bytes_to_write <= sg_lst->length - sg_off) {                                        iov[1].iov_base = sg_lst->address + sg_off;                                        iov[1].iov_len = bytes_to_write;                                } else {                                        iov[1].iov_base = sg_lst->address + sg_off;                                        iov[1].iov_len = sg_lst->length - sg_off;                                        bytes_to_write -= sg_lst->length - sg_off;                                        do {                                                sg_lst++;                                                sg_cnt--;                                                                                        ASSERT (sg_cnt > 0);                                                if (bytes_to_write <= sg_lst->length) {                                                        iov[num_iov].iov_base = sg_lst->address;                                                        iov[num_iov].iov_len = bytes_to_write;                                                        bytes_to_write = 0;                                                 } else {                                                        iov[num_iov].iov_base = sg_lst->address;                                                        iov[num_iov].iov_len = sg_lst->length;                                                        bytes_to_write -= sg_lst->length;                                                }                                                num_iov++;                                        } while (bytes_to_write);                                }                        }                                                /* lame but assume at least the header get written */                        bytes_to_write = rsp.scsi_write.len + ISCSI_HDR_SIZE;                        while (bytes_to_write) {                                current_write = iscsi_sendv (c->sock, iov, num_iov);                                bytes_to_write -= current_write;                                total_written += current_write;                                ASSERT (total_written >=48);                                iov[0].iov_base = s->current_command->request_buffer + write_off + total_written;                                iov[0].iov_len = bytes_to_write;                                num_iov = 1;                        }                        return 0;                                                break;                case ISCSI_OP_ASYNC_EVENT:                        printk ("iscsi_client - I don't know how to handle"                                " ASYNC_EVENT yet\n");                        if (bytes_to_read != 0) {                                printk ("iscsi_client - Leftover bytes in"                                        " ASYNC_EVENT %d\n", bytes_to_read);                                while (bytes_to_read) {                                        if ((bytes_read = iscsi_read (c->sock, scratch_pad, bytes_to_read)) == -1) {                                                break;                                        }                                        bytes_to_read -= bytes_read;                                }                                return -1;                        }                        return 0;                        break;                case ISCSI_OP_REJECT:                        printk ("iscsi_client - I don't know how to handle"                                " REJECT yet\n");                        if (bytes_to_read != 0) {                                printk ("iscsi_client - Leftover bytes in"                                        " REJECT %d\n", bytes_to_read);                                while (bytes_to_read) {                                        if ((bytes_read = iscsi_read (c->sock, scratch_pad, bytes_to_read)) == -1) {                                                break;                                        }                                        bytes_to_read -= bytes_read;                                }                                return -1;                        }                        return 0;                        break;                default:                        /* Bogus command sent */                        printk ("iscsi_client - BOGUS ISCSI MESSAGE:\n");                        iscsi_print_header (&hdr);                        if (bytes_to_read != 0) {                                printk ("iscsi_client - Leftover bytes in"                                        " NOP_IN %d\n", bytes_to_read);                                while (bytes_to_read) {                                        if ((bytes_read = iscsi_read (c->sock, scratch_pad, bytes_to_read)) == -1) {                                                break;                                        }                                        bytes_to_read -= bytes_read;                                }                                return -1;                        }                        return -1;                        break;        }        return -2; /* should not get here */}static void iscsi_client_it_finished(Scsi_Cmnd * SCpnt){        SCpnt->SCp.Status++;}/* This should close any socket's that we've opened as well as * perform graceful connection teardowns and terminate threads we've * launched */static int iscsi_client_release(struct Scsi_Host *SChost){        return 0;}static Scsi_Host_Template driver_template = ISCSI_CLIENT;/* Module linkage */MODULE_AUTHOR("Michael F. Brown");MODULE_DESCRIPTION("iSCSI Client");/* We probably won't have any parameters to a modprobe, at least not now */MODULE_PARM(def_reserved_size, "n/a");MODULE_PARM_DESC(def_reserved_size, "n/a");#include "scsi_module.c"/* Here are the init functions that get called *//*static int __init iscsi_client_init(void) {    printk("iscsi_client - iscsi_client_init() entry\n");    return 0;}static void __exit iscsi_client_exit(void){    printk("iscsi_client - iscsi_client_exit() entry\n");}module_init(iscsi_client_init);module_exit(iscsi_client_exit);*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -