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

📄 initiator_proc_iface.c

📁 iscsi源代码 UNH的progect 有initiator端和target端的源码
💻 C
📖 第 1 页 / 共 3 页
字号:
	if (strcmp(ptr, "s") == 0)		targ_data->init_conn_flags |= USE_SECURITY_PHASE;	else if (strcmp(ptr, "o") == 0)		targ_data->init_conn_flags |= USE_OPERATIONAL_PHASE;	else if (strcmp(ptr, "f") == 0)		targ_data->init_conn_flags |= USE_FLAT_SPACE_LUN;	else if (strcmp(ptr, "r") == 0)		targ_data->init_conn_flags |= USE_FULL_REPLIES;	else if (strcmp(ptr, "xok") == 0)		targ_data->init_conn_flags |= USE_REFLECT_XKEYS;	else if (strncmp(ptr, "n=", 2) == 0) {		/* set periodic timer for sending nop-out to target */		scan_numeric(ptr+2, UINT_MAX, &targ_data->nop_period, &result);	} else if (strncmp(ptr, "v=", 2) == 0) {		/* ignore any draft number */		TRACE(TRACE_ISCSI, "Draft number \"%s\" ignored\n", ptr);	} else if (strncmp(ptr, "p=", 2) == 0) {		/* Store the retran_interval - SAI */		scan_numeric(ptr+2, UINT_MAX, &targ_data->retran_period, &result);		TRACE(TRACE_DEBUG, "Set Initiator to enforce retransmit"			  " wait period as %u\n", targ_data->retran_period);	} else if (strncmp(ptr, "sch=", 4) == 0) {		/* Store the connection scheduling scheme - SAI */		scan_numeric(ptr+4, UINT_MAX, &targ_data->sched_scheme, &result);		TRACE(TRACE_DEBUG, "Set Initiator to enforce Connection"			  " Scheduling Scheme as %u\n",			  targ_data->sched_scheme);	} else if (strcmp(ptr, "t") == 0) {		/* chap and srp support - CHONG */		TRACE(TRACE_ISCSI, "target authentication enabled\n");		targ_data->auth_parameter.auth_flags			|= USE_TARGET_CONFIRMATION;	} else if (strcmp(ptr, "b") == 0) {		TRACE(TRACE_ISCSI, "base64 format enabled\n");		targ_data->auth_parameter.auth_flags |= USE_BASE64;		targ_data->auth_parameter.chap_local_ctx->number_format			= BASE64_FORMAT;		targ_data->auth_parameter.chap_peer_ctx->number_format			= BASE64_FORMAT;		targ_data->auth_parameter.srp_ctx->format			= BASE64_FORMAT;	} else if (strncmp(ptr, "px=", 3) == 0) {		TRACE(TRACE_ISCSI, "CHAP peer secret set to \"%s\"\n",			  ptr + 3);		CHAP_SetSecret(ptr + 3,			       targ_data->auth_parameter.chap_peer_ctx);	} else if (strncmp(ptr, "pn=", 3) == 0) {		TRACE(TRACE_ISCSI, "CHAP peer name set to \"%s\"\n",			  ptr + 3);		CHAP_SetName(ptr + 3,			     targ_data->auth_parameter.chap_peer_ctx);	} else if (strncmp(ptr, "lx=", 3) == 0) {		TRACE(TRACE_ISCSI, "CHAP local secret set to \"%s\"\n",			  ptr + 3);		CHAP_SetSecret(ptr + 3,			      targ_data->auth_parameter.chap_local_ctx);	} else if (strncmp(ptr, "ln=", 3) == 0) {		TRACE(TRACE_ISCSI, "CHAP local name set to \"%s\"\n",			  ptr + 3);		CHAP_SetName(ptr + 3,			     targ_data->auth_parameter.chap_local_ctx);	} else if (strncmp(ptr, "cl=", 3) == 0) {		scan_numeric(ptr+3, MAX_CHAP_BINARY_LENGTH, &c_len, &result);		if (c_len == 0 || result < 0) {			TRACE_ERROR("invalid CHAP challenge length: \"%s\"\n",				    ptr + 3);		} else {			TRACE(TRACE_ISCSI,				  "CHAP challenge length set to %u\n", c_len);			CHAP_SetChallengeLength(c_len,						targ_data->auth_parameter.							chap_local_ctx);		}	} else if (strncmp(ptr, "sx=", 3) == 0) {		TRACE(TRACE_ISCSI, "SRP secret set to \"%s\"\n",			  ptr + 3);		SRP_SetSecret(ptr + 3,				  targ_data->auth_parameter.srp_ctx);	} else if (strncmp(ptr, "sn=", 3) == 0) {		TRACE(TRACE_ISCSI, "SRP name set to \"%s\"\n",			  ptr + 3);		SRP_SetName(ptr + 3,					targ_data->auth_parameter.srp_ctx);	} else if (strncmp(ptr, "sg=", 3) == 0) {		if (SRP_SetSRPGroup(ptr + 3,				targ_data->auth_parameter.srp_ctx) == 0) {			TRACE_ERROR("Unable to set SRP group %s\n",						ptr + 3);		} else {			TRACE(TRACE_ISCSI, "SRP group number set to %s\n",				  ptr + 3);		}	} else if (strncmp(ptr, "V=", 2) == 0) {		scan_numeric(ptr+2, UINT_MAX, &trace_info, &result);		printk("trace_info = 0x%04x\n", trace_info);		TRACE_SET(trace_info);	} else if (strncmp(ptr, "isidt=", 6) == 0) {		scan_numeric(ptr+6, 3, &targ_data->isid_type, &result);	} else if (strncmp(ptr, "isidn=", 6) == 0) {		scan_numeric(ptr+6, MASK_24_BITS, &targ_data->isid_number,			     &result);	} else if (strncmp(ptr, "isidq=", 6) == 0) {		scan_numeric(ptr+6, MASK_24_BITS, &targ_data->isid_qualifier,			     &result);	}else {		TRACE_ERROR("Unknown force \"%s\"\n", ptr);		result = -EINVAL;	}	return result;}/* * executed only by command process. * Called only by scan_manage_stuff() * Scan Error Recovery Options to enable or disable snack - SAI */static void __attribute__ ((no_instrument_function))scan_snack_stuff(char *ptr, struct iscsi_targetdata *targ_data){	if (strncmp(ptr, "d=", 2) == 0) {		/* enable or disable data snack */		if (strcmp(ptr + 2, "y") == 0)			targ_data->init_snack_flag |= DATA_SNACK_ENABLE;		else if (strcmp(ptr + 2, "Y") == 0)			targ_data->init_snack_flag |= DATA_SNACK_ENABLE;	} else if (strncmp(ptr, "s=", 2) == 0) {		/* enable or disable status snack */		if (strcmp(ptr + 2, "y") == 0)			targ_data->init_snack_flag |= STATUS_SNACK_ENABLE;		else if (strcmp(ptr + 2, "Y") == 0)			targ_data->init_snack_flag |= STATUS_SNACK_ENABLE;	} else {		TRACE_ERROR("unknown snack \"%s\"\n", ptr);	}	TRACE(TRACE_DEBUG,		  "SNACK Flags: datasnack %d statsnack %d\n",		  (targ_data->init_snack_flag & DATA_SNACK_ENABLE),		  (targ_data-> init_snack_flag & STATUS_SNACK_ENABLE) >> 1);}/* * executed only by command process. * Called only by scan_manage_stuff() * Restore all settings to default values */static void __attribute__ ((no_instrument_function))scan_restore_stuff(struct iscsi_targetdata *targ_data){	uninit_targetdata(targ_data);	init_targetdata(targ_data);	global_hostdata->init_sessrec_flg = 0;}/* * executed only by command process. * Called only by iscsi_initiator_proc_info() * this is for configuring the login parameters */static int __attribute__ ((no_instrument_function))scan_manage_stuff(char *ptr, int result){	__u32 target_no, param_neg_info;	struct iscsi_targetdata *targ_data;	/* Set the target number */	target_no = simple_strtoul(ptr, &ptr, 0);	if (target_no >= global_host->max_id) {		result = -EINVAL;		goto out;	}	targ_data = &global_hostdata->target_data[target_no];	/* scan number for "set/setr/unset/setp/restore/force" */	param_neg_info = simple_strtoul(ptr+1, &ptr, 0);	/* Move a position to ignore space */	ptr++;	/* Now configure the parameters */	if (param_neg_info == FORCE) {		result = scan_force_stuff(ptr, targ_data, result);	} else if (param_neg_info == SNACK) {		scan_snack_stuff(ptr, targ_data);	} else if (param_neg_info == RESTORE) {		/* restore all settings to default values */		scan_restore_stuff(targ_data);	} else {		/* a "normal" key=value type of thing */		configure_parameter(param_neg_info, ptr, targ_data->param_tbl);	}out:	return result;}/* * executed only by command process. * Called only by iscsi_initiator_proc_info() * This is for triggering test actions in the initiator */static int __attribute__ ((no_instrument_function))scan_test_stuff(char * ptr, int result){	int i;	__u32 target_no, cid, test_no;	TRACE(TRACE_DEBUG, "trigger test action\n");	if (strncmp(ptr, " target ", 8) != 0) {		result = -EINVAL;		goto out;	}	/* this buffer has expected preface, scan target number */	target_no = simple_strtoul(ptr + 8, &ptr, 0);	TRACE(TRACE_DEBUG, "got target number %u\n", target_no);	if (target_no >= global_host->max_id || strncmp(ptr, " cid ", 5) != 0) {		result = -EINVAL;		goto out;	}	/* this buffer has expected preface, scan cid number */	cid = simple_strtoul(ptr + 5, &ptr, 0);	TRACE(TRACE_DEBUG, "got cid %u\n", cid);	if (cid > 0xff || strncmp(ptr, " test ", 6) != 0) {		result = -EINVAL;		goto out;	}	/* this buffer has expected preface, scan test number */	test_no = simple_strtoul(ptr + 6, &ptr, 0);	TRACE(TRACE_DEBUG, "got test_no %u\n", test_no);	if (strspn(ptr, WHITE_SPACE) != strlen(ptr)) {		result = -EINVAL;		goto out;	}	if ((i = do_test(target_no, cid, test_no)) < 0)		result = i;out:	return result;}/* * executed only by command process. * Called only by iscsi_initiator_proc_info() */static int __attribute__ ((no_instrument_function))scan_ip_stuff(char * ip_string, int result){	char *ptr, *port_string;	__u32 port_no, target, lun, cid;	int i;	struct sockaddr *ip_address;	int ip_length;	ptr = strchr(ip_string, ' ');	if (ptr == NULL || strncmp(ptr, " port ", 6) != 0) {		result = -EINVAL;		goto out;	}	/* this buffer has expected preface, scan port number */	port_string = ptr + 6;	port_no = simple_strtoul(port_string, &ptr, 0);	if (strncmp(ptr, " target ", 8) != 0) {		result = -EINVAL;		goto out;	}	/* this buffer has expected preface, scan target number */	target = simple_strtoul(ptr + 8, &ptr, 0);	if (target >= global_host->max_id || strncmp(ptr, " lun ", 5) != 0) {		result = -EINVAL;		goto out;	}	/* this buffer has expected preface, scan lun number */	lun = simple_strtoul(ptr + 5, &ptr, 0);	if (lun >= global_host->max_lun || strncmp(ptr, " cid ", 5) != 0) {		result = -EINVAL;		goto out;	}	/* this buffer has expected preface, scan cid number */	cid = simple_strtoul(ptr + 5, &ptr, 0);	if (cid > 0xff || strspn(ptr, WHITE_SPACE) != strlen(ptr)) {		result = -EINVAL;		goto out;	}	if (port_no == 0) {		/* "down target lun cid" on this host */		if ((i = remove_session_from_hostdata(target, lun, cid,						      global_hostdata)) <= 0) {			/* error (<0) or only old connection removed (==0)			 * pass this back as the result			 */			result = i;		}		/*  else >0, removed old session or lun, result==length */	} else {		if ((i = cnv_string_to_inet(ip_string, port_string,						&ip_address, &ip_length)) < 0) {			result = i;		} else {#if defined(CONFIG_ISCSI_DEBUG)			__u32 save_trace;#endif			/* "up target lun cid" to ip:port on this host.			 * Returns:			 * < 0: error			 * = 0: added new connection (only) to existing session			 * = 1: added complete new session, lun and connection			 * = 2: added a new lun (only) to existing session			 */			TRACE_GET(save_trace);			if ((i = create_session(target, ip_address, ip_length,						lun, cid, global_host)) <= 0) {				/* error (<0) or new connection (only) (==0)				 * pass this back as the result				 */				result = i;			}			/*  else >0, added new session or lun, result==length */			TRACE_SET(save_trace);		}	}out:	return result;}/*******************************************************************************	Called when the host file "0" or "1" or ...*	in the /proc/scsi/iscsi_initiator/ directory is read or written.*	The parameter "inout" is 0 for a read, 1 for a write operation.*	A write expects the buffer to contain something in the format:*		"iscsi_initiator ip 1234abcd port 4000 target 6 lun 0"*	or*		"iscsi_initiator manage 0 5 key=value"*	or		"iscsi_iniitator manage 1 32 o"*	or*		"iscsi_initiator test 7"*	Return value:	0, on success*					-Exxxx, on failure******************************************************************************//* Ming Zhang, mingz@ele.uri.edu */#ifdef K26intiscsi_initiator_proc_info(struct Scsi_Host *sh, char *buffer, char **start,			  off_t offset, int length, int inout){	unsigned long flags;	int pos, begin, result;	struct session *sess;	TRACE(TRACE_ENTER_LEAVE, "Enter iscsi_initiator_proc_info\n");	TRACE(TRACE_DEBUG, "host %p, priv %p, buffer %p, start %p\n",	      sh, &sh->hostdata[0], buffer, start);	TRACE(TRACE_DEBUG, "offset %ld, length %d, inout %d\n",	      offset, length, inout);#elseintiscsi_initiator_proc_info(char *buffer, char **start, off_t offset,			  int length, int inode, int inout){	unsigned long flags;	int pos, begin, result;	struct session *sess;	TRACE(TRACE_ENTER_LEAVE, "Enter iscsi_initiator_proc_info\n");	TRACE(TRACE_DEBUG, "buffer %p, offset %ld, length %d, inout %d\n",	      buffer, offset, length, inout);#endif	if (inout) {		/* write to this file, buffer should be:		 * "iscsi_initiator ip 1234abcd port 4000 target 1 lun 2 cid 3"		 * or		 * "iscsi_initiator manage 0		 * <neg_info number for "set/setr/unset/setp/restore/force">		 * <parameter for "set/setr/unset/setp/restore/force"> "		*/		if (global_host == NULL) {			/* this should never happen */			TRACE_ERROR("global_host is NULL\n");			result = -ENODEV;		} else if (global_hostdata == NULL) {			/* this should never happen */			TRACE_ERROR("global_hostdata is NULL\n");			result = -ENODEV;		} else if (buffer == NULL || length > PAGE_SIZE)			result = -EINVAL;		else {			result = length;			if (length == PAGE_SIZE)				length--;			/* make the buffer into a string */			buffer[length] = '\0';			TRACE(TRACE_ISCSI,			      "iSCSI write to proc_info (%d): %s\n",			      length, buffer);			if (length >= 23			       && strncmp(buffer, "iscsi_initiator manage ", 23)									== 0) {				result = scan_manage_stuff(buffer + 23, result);			} else if (length >= 21				 && strncmp(buffer, "iscsi_initiator test ", 21)									== 0) {				/* Trigger test actions in the initiator */				result = scan_test_stuff(buffer + 20, result);			} else if (length >= 19				&& strncmp(buffer, "iscsi_initiator ip ", 19)									== 0) {				result = scan_ip_stuff(buffer + 19, result);			} else {				TRACE(TRACE_ISCSI,				      "Illegal write to proc_info\n");				result = -EINVAL;			}		}	} else {		/* read from this file		 * this is what gets printed		 * by "cat /proc/scsi/iscsi_initiator/0"		 */		pos = sprintf(buffer, "%s\n", OUR_NAME);		/*  When using global data, be sure nobody else accesses it */		UNH_LOCK(&host_data_lock, flags);		if (global_host != NULL && global_hostdata != NULL) {			pos = print_host_info(global_host, buffer, pos);			pos += sprintf(buffer + pos, "host has %u session%s\n",				      global_hostdata->nsessions,				      global_hostdata->nsessions==1 ? "" : "s");			if (global_hostdata->nsessions == 0 ) {				pos += print_config_info(						global_hostdata->target_data[0]								.param_tbl,						buffer + pos);			}			list_for_each_entry(sess,					    &global_hostdata->session_list,					    link) {				pos = print_session_info(sess, buffer, pos);				/* if initiator has lots of sessions,				 * printing the session parameters for all of				 * them here may overflow the proc 4K buffer.				 */				/********** RDR				pos += print_session_params(sess->oper_param,							  *sess->session_params,							  buffer + pos);				**********/				pos += sprintf(buffer + pos, "\n");			}#ifdef ISCSI_STATS			pos += dump_instance_stats(buffer + pos);#endif		} else {			pos += sprintf(buffer + pos, "\n");		}		/* release our exclusive access to the global data */		UNH_UNLOCK(&host_data_lock, flags);

⌨️ 快捷键说明

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