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