📄 iscsi_client.c
字号:
/* * $Id: iscsi_client.c,v 1.24 2001/04/24 05:49:09 mbrown Exp $ * * iscsi_client.c implements the iSCSI initiator (or client) SCSI adapter * driver. This is based on a proposed iSCSI standard * ( http://search.ietf.org/internet-drafts/draft-ietf-ips-iscsi-03.txt ) * and as all internet drafts in intended to be a work in progress. * Therefore this driver will likely break, change significantly, and * corrupt your hard disks. * Copyright (C) 2001 Michael F. Brown (mbrown@cs.uml.edu) * * Changes : * * $Log: iscsi_client.c,v $ * Revision 1.24 2001/04/24 05:49:09 mbrown * verbose error messages commented for now * * Revision 1.23 2001/04/24 05:05:08 mbrown * write functionality functional * * Revision 1.22 2001/04/24 03:51:42 mbrown * more fixes for scsi write data * * Revision 1.21 2001/04/24 03:28:54 mbrown * fixed but in write data * * Revision 1.20 2001/04/24 00:33:39 mbrown * write bug fix (still hacked) * * Revision 1.19 2001/04/24 00:04:47 mbrown * fixed bugs * * Revision 1.18 2001/04/23 23:41:39 mbrown * fixed bugs * * Revision 1.17 2001/04/23 22:50:27 jhawkins * added converge read for READ_DATA op * * Revision 1.16 2001/04/23 19:18:34 mbrown * changed target addr to cypher, (10.1.1.20) * * Revision 1.15 2001/04/21 04:07:01 mbrown * more bug fixing, mount readonly works, use the new DISK file, it * contains a valid ext2 partition * * Revision 1.14 2001/04/20 03:35:01 mbrown * lun bug fixed, debug prints in big endian order * * Revision 1.13 2001/04/19 15:16:50 mbrown * devices now show up, fdisk still causes a kernel panic, * checkin per jhawkins' request * * Revision 1.12 2001/04/18 07:56:36 mbrown * more debug output in reader() and dispatch() * * Revision 1.11 2001/04/18 07:52:43 mbrown * minor cleanup * * Revision 1.10 2001/04/15 03:50:00 jhawkins * successful login after a bit of hacking, changed version code expectation from 0 to 1, target sends us a 1 * * Revision 1.9 2001/04/15 03:01:04 mostman * Some debugging * * Revision 1.8 2001/04/15 02:58:27 jhawkins * address/localhost issues * * Revision 1.7 2001/04/11 20:33:57 mbrown * debug string newline fixes, aesthetic update * * Revision 1.6 2001/04/06 04:07:37 mbrown * bug fix having to do with byte ordering fixed. Added lots of debug * prints in iscsi_client.c now that I can start testing * * Revision 1.5 2001/04/03 09:44:58 mbrown * iscsi.o and iscsi_client.o now successfully compile. * * Revision 1.4 2001/04/03 03:04:39 mbrown * latest and greatest hacks. iscsi_client_reader() implemented along with * iscsi_client_proc_info(). Should be all set to test now, will work * on compiling. * * Revision 1.3 2001/03/12 10:49:31 mbrown * iscsi_client is now basically fully implemented minus proper * /proc communication and compilation fixes. This is going * to be put aside for now. * * Revision 1.2 2001/03/09 11:03:15 mbrown * implemented queue_command. All that's left is the dispatch * function, /proc stuff, and cleanup. Then its on to help * mostman and jhawkins with the pass-through target. * * Revision 1.1 2001/03/04 10:24:43 mbrown * initial revision. Doesn't compile but source here might be * useful for Mike and Josh. * * * * 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. * *//* Credits: * * Some of this code was copied and or modified from sym53c416.c and * Alan Cox's Linux Gear articles on SCSI drivers: * * http://www.linux-mag.com/1999-08/gear_01.html * http://www.linux-mag.com/1999-09/gear_01.html */#include <linux/config.h>#include <linux/module.h>#include <linux/kernel.h>#include <linux/types.h>#include <linux/string.h>#include <linux/errno.h>#include <linux/socket.h>#include <linux/uio.h>#include <linux/kdev_t.h>#include <linux/in.h>#include <linux/slab.h>#include <linux/net.h>#include <linux/sched.h>#include <linux/tcp.h>#include <linux/skbuff.h>#include <linux/wait.h>#include <linux/bitops.h>#include <linux/spinlock.h>#include <linux/blkdev.h>#include <linux/blk.h>#include <linux/init.h>#include <linux/byteorder/generic.h>#include <asm/processor.h>#include <asm/scatterlist.h>#include <net/sock.h>#include "scsi.h"#include "scsi_obsolete.h"#include "sd.h"#include "hosts.h"#include "iscsi.h"#include "iscsi_client.h"static void DUMP_DATA (void *start, int len){ int i; unsigned char *tmp = start; for (i=0; i<len; i++) { if ((i % 4) == 0) { printk ("\n\t0x"); } printk ("%02x", tmp[i]); } printk ("\n");}#define ISCSI_MAX_CONNECTIONS 1#define ISCSI_MAX_SESSIONS 1typedef struct iscsi_session_t iscsi_session_t;typedef struct iscsi_connection_t { iscsi_session_t *s; struct socket *sock; u16 in_use; u32 cid; u32 stat_rn; pid_t reader;} iscsi_connection_t;struct iscsi_session_t { struct iscsi_connection_t connection[ISCSI_MAX_CONNECTIONS]; u32 num_connections; u16 in_use; u16 isid; u16 tsid; u32 itt; u32 cmd_rn; u32 max_cmd_rn; /* this should eventually be a queue */ Scsi_Cmnd *current_command;};#define ASSERT(cond) { if (!(cond)) { printk ("iscsi_client - ASSERT FAILED " \ "%s:%d\n", __FILE__, __LINE__); } }static __inline void iscsi_close_connection (iscsi_connection_t *c) { sock_release (c->sock);}/* Local prototypes */static unsigned int iscsi_client_probe(void);static int iscsi_client_start (iscsi_session_t *s);static int iscsi_client_login(iscsi_session_t *s, u16 c_idx);static int iscsi_client_reader(void *connection);static int iscsi_client_dispatch (iscsi_connection_t *c, iscsi_header_t hdr, s32 bytes_to_read);static void iscsi_client_it_finished(Scsi_Cmnd * SCpnt);static int iscsi_client_release(struct Scsi_Host *SChost);/* iSCSI Globals */static void *scratch_pad = NULL;static iscsi_session_t session[ISCSI_MAX_SESSIONS];static u16 isid = 1;/* Exported definitions *//* lifted from scsi_debug.c *//* iscsi_client_proc_info * Used if the driver currently has no own support for /proc/scsi */int iscsi_client_proc_info(char *buffer, char **start, off_t offset, int length, int inode, int inout){ int len, pos, begin; int orig_length = length; // printk ("iscsi_client - PID %d iscsi_client_proc_info(%p,%p,_,%d,%d,%d) ENTRY\n",// current->pid, buffer, start, length, inode, inout); if (inout == 1) { /* First check for the Signature */ if (length >= 12 && strncmp(buffer, "iscsi_client", 12) == 0) { buffer += 13; length -= 13; if (buffer[length - 1] == '\n') { buffer[length - 1] = '\0'; length--; } /* * OK, we are getting some kind of command. Figure out * what we are supposed to do here. Simulate bus lockups * to test our reset capability. */ if (length == 4 && strncmp(buffer, "test", length) == 0) { printk("iscsi_client - Recieved test\n"); return orig_length; } if (length == 6 && strncmp(buffer, "lockup", length) == 0) { printk("iscsi_client - Recieved lockup\n"); return orig_length; } if (length == 6 && strncmp(buffer, "unlock", length) == 0) { printk("iscsi_client Recieved unlock\n"); return orig_length; } printk("Unknown command:%s (%d)\n", buffer, length); } else printk("Wrong Signature:%10s\n", (char *) buffer); return -EINVAL; } begin = 0; pos = len = sprintf(buffer, "This driver implements the IETF iSCSI draft (SCSI over TCP/IP)\n"); if (pos < offset) { len = 0; begin = pos; } *start = buffer + (offset - begin); /* Start of wanted data */ len -= (offset - begin); if (len > length) len = length; // printk ("iscsi_client - PID %d iscsi_client_proc_info(%p,%p,_,%d,%d,%d) EXIT\n",// current->pid, buffer, start, length, inode, inout); return (len);}const char *iscsi_client_info(struct Scsi_Host *SChost){ return ("iSCSI Client Adapter: $Id: iscsi_client.c,v 1.24 2001/04/24 05:49:09 mbrown Exp $");}int iscsi_client_detect(Scsi_Host_Template * tpnt){ struct Scsi_Host *shpnt;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -