48d880c
diff -aurp open-iscsi-2.0-868-test1.orig/doc/iscsiadm.8 open-iscsi-2.0-868-test1/doc/iscsiadm.8
48d880c
--- open-iscsi-2.0-868-test1.orig/doc/iscsiadm.8	2008-01-11 17:30:38.000000000 -0600
48d880c
+++ open-iscsi-2.0-868-test1/doc/iscsiadm.8	2008-01-11 17:51:12.000000000 -0600
48d880c
@@ -12,7 +12,7 @@ iscsiadm \- open-iscsi administration ut
48d880c
 
48d880c
 \fBiscsiadm\fR -m iface [ -hV ] [ -d debug_level ] [ -P printlevel ] [ -I ifacename ] [ [ -o  operation  ] [ -n name ] [ -v value ] ]
48d880c
 
48d880c
-\fBiscsiadm\fR -m fw
48d880c
+\fBiscsiadm\fR -m fw [-l]
48d880c
 
48d880c
 \fBiscsiadm\fR -k priority
48d880c
 
48d880c
@@ -90,7 +90,7 @@ This command and iscsid's SIGTERM handli
48d880c
 
48d880c
 .TP
48d880c
 \fB\-l\fR, \fB\-\-login\fR
48d880c
-For node mode, login to a specified record. For discovery mode, login to
48d880c
+For node and fw mode, login to a specified record. For discovery mode, login to
48d880c
 all discovered targets.
48d880c
 .IP
48d880c
 This option is only valid for discovery and node modes.
48d880c
diff -aurp open-iscsi-2.0-868-test1.orig/usr/iscsiadm.c open-iscsi-2.0-868-test1/usr/iscsiadm.c
48d880c
--- open-iscsi-2.0-868-test1.orig/usr/iscsiadm.c	2008-01-11 17:30:38.000000000 -0600
48d880c
+++ open-iscsi-2.0-868-test1/usr/iscsiadm.c	2008-01-11 17:53:29.000000000 -0600
48d880c
@@ -102,6 +102,7 @@ iscsiadm -m node [ -hV ] [ -d debug_leve
48d880c
 [ [ -o  operation  ] [ -n name ] [ -v value ] ]\n\
48d880c
 iscsiadm -m session [ -hV ] [ -d debug_level ] [ -P  printlevel] [ -r sessionid | sysfsdir [ -R | -u | -s ] [ -o operation ] [ -n name ] [ -v value ] ]\n\
48d880c
 iscsiadm -m iface [ -hV ] [ -d debug_level ] [ -P printlevel ] [ -I ifacename ] [ [ -o  operation  ] [ -n name ] [ -v value ] ]\n\
48d880c
+iscsiadm -m fw [ -l ]\n\
48d880c
 iscsiadm -k priority\n");
48d880c
 	}
48d880c
 	exit(status == 0 ? 0 : -1);
48d880c
@@ -1538,53 +1539,6 @@ static void print_fw_nodes(struct node_r
48d880c
 	}
48d880c
 }
48d880c
 
48d880c
-static int do_fw_discovery(idbm_t *db, discovery_rec_t *drec, int do_login,
48d880c
-			   int info_level)
48d880c
-{
48d880c
-	struct boot_context context;
48d880c
-	struct node_rec *rec;
48d880c
-	int ret;
48d880c
-
48d880c
-	memset(&context, 0, sizeof(struct boot_context));
48d880c
-	ret = fw_get_entry(&context, NULL);
48d880c
-	if (ret) {
48d880c
-		log_error("Could not read fw values.");
48d880c
-		return ret;
48d880c
-	}
48d880c
-	/* tpgt hard coded to 1 */
48d880c
-	rec = create_node_record(db, context.targetname, 1,
48d880c
-				 context.target_ipaddr, context.target_port,
48d880c
-				 NULL, 1);
48d880c
-	if (!rec) {
48d880c
-		log_error("Could not setup rec for fw discovery login.");
48d880c
-		return ENOMEM;
48d880c
-	}
48d880c
-
48d880c
-	/* todo - grab mac and set that here */
48d880c
-	iface_init(&rec->iface);
48d880c
-	strncpy(rec->iface.iname, context.initiatorname,
48d880c
-		sizeof(context.initiatorname));
48d880c
-	strncpy(rec->session.auth.username, context.chap_name,
48d880c
-		sizeof(context.chap_name));
48d880c
-	strncpy((char *)rec->session.auth.password, context.chap_password,
48d880c
-		sizeof(context.chap_password));
48d880c
-	strncpy(rec->session.auth.username_in, context.chap_name_in,
48d880c
-		sizeof(context.chap_name_in));
48d880c
-	strncpy((char *)rec->session.auth.password_in, context.chap_password_in,
48d880c
-		sizeof(context.chap_password_in));
48d880c
-	rec->session.auth.password_length =
48d880c
-				strlen((char *)context.chap_password);
48d880c
-	rec->session.auth.password_in_length =
48d880c
-				strlen((char *)context.chap_password_in);
48d880c
-
48d880c
-	print_fw_nodes(rec, info_level);
48d880c
-	if (do_login)
48d880c
-		ret = login_portal(db, NULL, rec);
48d880c
-	free(rec);
48d880c
-	return ret;
48d880c
-}
48d880c
-
48d880c
-
48d880c
 static int isns_dev_attr_query(idbm_t *db, discovery_rec_t *drec,
48d880c
 			       int info_level)
48d880c
 {
48d880c
@@ -1887,10 +1841,46 @@ out:
48d880c
 	return rc;
48d880c
 }
48d880c
 
48d880c
-static int exec_fw_op(void)
48d880c
+static struct node_rec *
48d880c
+fw_create_rec_by_entry(idbm_t *db, struct boot_context *context)
48d880c
+{
48d880c
+	struct node_rec *rec;
48d880c
+
48d880c
+	/* tpgt hard coded to 1 ??? */
48d880c
+	rec = create_node_record(db, context->targetname, 1,
48d880c
+				 context->target_ipaddr, context->target_port,
48d880c
+				 NULL, 1);
48d880c
+	if (!rec) {
48d880c
+		log_error("Could not setup rec for fw discovery login.");
48d880c
+		return NULL;
48d880c
+	}
48d880c
+
48d880c
+	/* todo - grab mac and set that here */
48d880c
+	iface_init(&rec->iface);
48d880c
+	strncpy(rec->iface.iname, context->initiatorname,
48d880c
+		sizeof(context->initiatorname));
48d880c
+	strncpy(rec->session.auth.username, context->chap_name,
48d880c
+		sizeof(context->chap_name));
48d880c
+	strncpy((char *)rec->session.auth.password, context->chap_password,
48d880c
+		sizeof(context->chap_password));
48d880c
+	strncpy(rec->session.auth.username_in, context->chap_name_in,
48d880c
+		sizeof(context->chap_name_in));
48d880c
+	strncpy((char *)rec->session.auth.password_in,
48d880c
+		context->chap_password_in,
48d880c
+		sizeof(context->chap_password_in));
48d880c
+	rec->session.auth.password_length =
48d880c
+				strlen((char *)context->chap_password);
48d880c
+	rec->session.auth.password_in_length =
48d880c
+				strlen((char *)context->chap_password_in);
48d880c
+	return rec;
48d880c
+}
48d880c
+
48d880c
+static int exec_fw_op(idbm_t *db, discovery_rec_t *drec, int do_login,
48d880c
+		     int info_level)
48d880c
 {
48d880c
 	struct boot_context context;
48d880c
-	int ret;
48d880c
+	struct node_rec *rec;
48d880c
+	int ret = 0;
48d880c
 
48d880c
 	memset(&context, 0, sizeof(struct boot_context));
48d880c
 	ret = fw_get_entry(&context, NULL);
48d880c
@@ -1899,8 +1889,22 @@ static int exec_fw_op(void)
48d880c
 		return ret;
48d880c
 	}
48d880c
 
48d880c
-	fw_print_entry(&context);
48d880c
-	return 0;
48d880c
+	rec = fw_create_rec_by_entry(db, &context);
48d880c
+	if (!rec)
48d880c
+		return ENODEV;
48d880c
+
48d880c
+	/* if discovery, print nodes that were found. */
48d880c
+	if (drec)
48d880c
+		print_fw_nodes(rec, info_level);
48d880c
+
48d880c
+	if (do_login)
48d880c
+		ret = login_portal(db, NULL, rec);
48d880c
+	free(rec);
48d880c
+
48d880c
+	/* print the fw node info if called in fw mode with no params */
48d880c
+	if (!do_login && !drec)
48d880c
+		fw_print_entry(&context);
48d880c
+	return ret;
48d880c
 }
48d880c
 
48d880c
 static int parse_sid(char *session)
48d880c
@@ -2106,14 +2110,14 @@ main(int argc, char **argv)
48d880c
 		usage(0);
48d880c
 
48d880c
 	if (mode == MODE_FW) {
48d880c
-		if ((rc = verify_mode_params(argc, argv, "m", 0))) {
48d880c
+		if ((rc = verify_mode_params(argc, argv, "ml", 0))) {
48d880c
 			log_error("fw mode: option '-%c' is not "
48d880c
 				  "allowed/supported", rc);
48d880c
 			rc = -1;
48d880c
 			goto out;
48d880c
 		}
48d880c
 
48d880c
-		rc = exec_fw_op();
48d880c
+		rc = exec_fw_op(db, NULL, do_login, info_level);
48d880c
 		goto out;
48d880c
 	}
48d880c
 
48d880c
@@ -2186,7 +2190,7 @@ main(int argc, char **argv)
48d880c
 			break;
48d880c
 		case DISCOVERY_TYPE_FWBOOT:
48d880c
 			drec.type = DISCOVERY_TYPE_FWBOOT;
48d880c
-			if (do_fw_discovery(db, &drec, do_login, info_level))
48d880c
+			if (exec_fw_op(db, &drec, do_login, info_level))
48d880c
 				rc = -1;
48d880c
 			break;
48d880c
 		default: