4cc2db
diff -up open-iscsi-2.0-870-rc1/usr/discovery.c.start-iscsid open-iscsi-2.0-870-rc1/usr/discovery.c
4cc2db
--- open-iscsi-2.0-870-rc1/usr/discovery.c.start-iscsid	2008-07-01 03:14:03.000000000 +0200
4cc2db
+++ open-iscsi-2.0-870-rc1/usr/discovery.c	2008-09-30 10:41:57.000000000 +0200
4cc2db
@@ -87,7 +87,7 @@ int discovery_offload_sendtargets(int ho
4cc2db
 	 * and get back the results. We should do this since it would
4cc2db
 	 * allows us to then process the results like software iscsi.
4cc2db
 	 */
4cc2db
-	rc = do_iscsid(&req, &rsp;;
4cc2db
+	rc = do_iscsid(&req, &rsp, 1);
4cc2db
 	if (rc) {
4cc2db
 		log_error("Could not offload sendtargets to %s.\n",
4cc2db
 			  drec->address);
4cc2db
@@ -521,7 +521,7 @@ static int request_initiator_name(void)
4cc2db
 	memset(&req, 0, sizeof(req));
4cc2db
 	req.command = MGMT_IPC_CONFIG_INAME;
4cc2db
 
4cc2db
-	rc = do_iscsid(&req, &rsp;;
4cc2db
+	rc = do_iscsid(&req, &rsp, 1);
4cc2db
 	if (rc)
4cc2db
 		return EIO;
4cc2db
 
4cc2db
@@ -531,7 +531,7 @@ static int request_initiator_name(void)
4cc2db
 	memset(&req, 0, sizeof(req));
4cc2db
 	req.command = MGMT_IPC_CONFIG_IALIAS;
4cc2db
 
4cc2db
-	rc = do_iscsid(&req, &rsp;;
4cc2db
+	rc = do_iscsid(&req, &rsp, 0);
4cc2db
 	if (rc)
4cc2db
 		/* alias is optional so return ok */
4cc2db
 		return 0;
4cc2db
diff -up open-iscsi-2.0-870-rc1/usr/iscsiadm.c.start-iscsid open-iscsi-2.0-870-rc1/usr/iscsiadm.c
4cc2db
--- open-iscsi-2.0-870-rc1/usr/iscsiadm.c.start-iscsid	2008-09-30 10:41:57.000000000 +0200
4cc2db
+++ open-iscsi-2.0-870-rc1/usr/iscsiadm.c	2008-09-30 10:41:57.000000000 +0200
4cc2db
@@ -191,7 +191,7 @@ static void kill_iscsid(int priority)
4cc2db
 
4cc2db
 	memset(&req, 0, sizeof(req));
4cc2db
 	req.command = MGMT_IPC_IMMEDIATE_STOP;
4cc2db
-	rc = do_iscsid(&req, &rsp;;
15c0dd
+	rc = do_iscsid(&req, &rsp, 0);
4cc2db
 	if (rc) {
4cc2db
 		iscsid_handle_error(rc);
4cc2db
 		log_error("Could not stop iscsid. Trying sending iscsid "
4cc2db
@@ -823,7 +823,7 @@ static char *get_config_file(void)
4cc2db
 	memset(&req, 0, sizeof(req));
4cc2db
 	req.command = MGMT_IPC_CONFIG_FILE;
4cc2db
 
4cc2db
-	rc = do_iscsid(&req, &rsp;;
4cc2db
+	rc = do_iscsid(&req, &rsp, 1);
4cc2db
 	if (rc)
4cc2db
 		return NULL;
4cc2db
 
4cc2db
@@ -883,7 +883,7 @@ static int print_iscsi_state(int sid)
4cc2db
 	req.command = MGMT_IPC_SESSION_INFO;
4cc2db
 	req.u.session.sid = sid;
4cc2db
 
4cc2db
-	err = do_iscsid(&req, &rsp;;
4cc2db
+	err = do_iscsid(&req, &rsp, 1);
4cc2db
 	/*
4cc2db
 	 * for drivers like qla4xxx, iscsid does not display
4cc2db
 	 * anything here since it does not know about it.
4cc2db
@@ -1151,7 +1151,7 @@ session_stats(void *data, struct session
4cc2db
 	req.command = MGMT_IPC_SESSION_STATS;
4cc2db
 	req.u.session.sid = info->sid;
4cc2db
 
4cc2db
-	rc = do_iscsid(&req, &rsp;;
4cc2db
+	rc = do_iscsid(&req, &rsp, 1);
4cc2db
 	if (rc)
4cc2db
 		return EIO;
4cc2db
 
4cc2db
@@ -1617,7 +1617,7 @@ static int isns_dev_attr_query(discovery
4cc2db
 	memset(&req, 0, sizeof(iscsiadm_req_t));
4cc2db
 	req.command = MGMT_IPC_ISNS_DEV_ATTR_QUERY;
4cc2db
 
4cc2db
-	err = do_iscsid(&req, &rsp;;
4cc2db
+	err = do_iscsid(&req, &rsp, 1);
4cc2db
 	if (err) {
4cc2db
 		iscsid_handle_error(err);
4cc2db
 		return EIO;
4cc2db
diff -up open-iscsi-2.0-870-rc1/usr/iscsid.c.start-iscsid open-iscsi-2.0-870-rc1/usr/iscsid.c
4cc2db
--- open-iscsi-2.0-870-rc1/usr/iscsid.c.start-iscsid	2008-07-01 03:14:03.000000000 +0200
4cc2db
+++ open-iscsi-2.0-870-rc1/usr/iscsid.c	2008-09-30 10:41:57.000000000 +0200
4cc2db
@@ -252,7 +252,7 @@ static int sync_session(void *data, stru
4cc2db
 	req.u.session.sid = info->sid;
4cc2db
 	memcpy(&req.u.session.rec, &rec, sizeof(node_rec_t));
4cc2db
 
4cc2db
-	do_iscsid(&req, &rsp;;
4cc2db
+	do_iscsid(&req, &rsp, 0);
4cc2db
 	return 0;
4cc2db
 }
4cc2db
 
4cc2db
diff -up open-iscsi-2.0-870-rc1/usr/iscsistart.c.start-iscsid open-iscsi-2.0-870-rc1/usr/iscsistart.c
4cc2db
--- open-iscsi-2.0-870-rc1/usr/iscsistart.c.start-iscsid	2008-07-01 03:14:03.000000000 +0200
4cc2db
+++ open-iscsi-2.0-870-rc1/usr/iscsistart.c	2008-09-30 10:41:57.000000000 +0200
4cc2db
@@ -112,7 +112,7 @@ static int stop_event_loop(void)
4cc2db
 
4cc2db
 	memset(&req, 0, sizeof(req));
4cc2db
 	req.command = MGMT_IPC_IMMEDIATE_STOP;
4cc2db
-	rc = do_iscsid(&req, &rsp;;
4cc2db
+	rc = do_iscsid(&req, &rsp, 0);
4cc2db
 	if (rc) {
4cc2db
 		iscsid_handle_error(rc);
4cc2db
 		log_error("Could not stop event_loop\n");
4cc2db
@@ -142,7 +142,7 @@ static int setup_session(void)
4cc2db
 	memset(&req, 0, sizeof(req));
4cc2db
 	req.command = MGMT_IPC_SESSION_LOGIN;
4cc2db
 	memcpy(&req.u.session.rec, &config_rec, sizeof(node_rec_t));
4cc2db
-	rc = do_iscsid(&req, &rsp;;
4cc2db
+	rc = do_iscsid(&req, &rsp, 0);
4cc2db
 	if (rc)
4cc2db
 		iscsid_handle_error(rc);
4cc2db
 
4cc2db
diff -up open-iscsi-2.0-870-rc1/usr/util.c.start-iscsid open-iscsi-2.0-870-rc1/usr/util.c
4cc2db
--- open-iscsi-2.0-870-rc1/usr/util.c.start-iscsid	2008-07-01 03:14:03.000000000 +0200
4cc2db
+++ open-iscsi-2.0-870-rc1/usr/util.c	2008-09-30 11:25:38.000000000 +0200
4cc2db
@@ -120,7 +120,7 @@ int increase_max_files(void)
4cc2db
 
4cc2db
 #define MAXSLEEP 128
4cc2db
 
4cc2db
-static mgmt_ipc_err_e iscsid_connect(int *fd)
4cc2db
+static mgmt_ipc_err_e iscsid_connect(int *fd, int iscsid_start)
4cc2db
 {
4cc2db
 	int nsec;
4cc2db
 	struct sockaddr_un addr;
4cc2db
@@ -145,8 +145,12 @@ static mgmt_ipc_err_e iscsid_connect(int
4cc2db
 
4cc2db
 		/* If iscsid isn't there, there's no sense
4cc2db
 		 * in retrying. */
4cc2db
-		if (errno == ECONNREFUSED)
4cc2db
-			break;
4cc2db
+		if (errno == ECONNREFUSED) {
4cc2db
+			if (iscsid_start && nsec == 1)
15c0dd
+				system("/etc/rc.d/init.d/iscsid force-start");
4cc2db
+			else
4cc2db
+				break;
4cc2db
+		}
4cc2db
 
4cc2db
 		/*
4cc2db
 		 * Delay before trying again
4cc2db
@@ -158,11 +162,11 @@ static mgmt_ipc_err_e iscsid_connect(int
4cc2db
 	return MGMT_IPC_ERR_ISCSID_COMM_ERR;
4cc2db
 }
4cc2db
 
4cc2db
-mgmt_ipc_err_e iscsid_request(int *fd, iscsiadm_req_t *req)
4cc2db
+mgmt_ipc_err_e iscsid_request(int *fd, iscsiadm_req_t *req, int start_iscsid)
4cc2db
 {
4cc2db
 	int err;
4cc2db
 
4cc2db
-	err = iscsid_connect(fd);
4cc2db
+	err = iscsid_connect(fd, start_iscsid);
4cc2db
 	if (err)
4cc2db
 		return err;
4cc2db
 
4cc2db
@@ -192,12 +196,13 @@ mgmt_ipc_err_e iscsid_response(int fd, i
4cc2db
 	return iscsi_err;
4cc2db
 }
4cc2db
 
4cc2db
-mgmt_ipc_err_e do_iscsid(iscsiadm_req_t *req, iscsiadm_rsp_t *rsp)
4cc2db
+mgmt_ipc_err_e do_iscsid(iscsiadm_req_t *req, iscsiadm_rsp_t *rsp,
4cc2db
+			 int start_iscsid)
4cc2db
 {
4cc2db
 	int fd;
4cc2db
 	mgmt_ipc_err_e err;
4cc2db
 
4cc2db
-	err = iscsid_request(&fd, req);
4cc2db
+	err = iscsid_request(&fd, req, start_iscsid);
4cc2db
 	if (err)
4cc2db
 		return err;
4cc2db
 
4cc2db
@@ -220,7 +225,7 @@ int iscsid_req_by_rec_async(iscsiadm_cmd
4cc2db
 	req.command = cmd;
4cc2db
 	memcpy(&req.u.session.rec, rec, sizeof(node_rec_t));
4cc2db
 
4cc2db
-	return iscsid_request(fd, &req;;
4cc2db
+	return iscsid_request(fd, &req, 1);
4cc2db
 }
4cc2db
 
4cc2db
 int iscsid_req_by_rec(iscsiadm_cmd_e cmd, node_rec_t *rec)
4cc2db
@@ -241,7 +246,7 @@ int iscsid_req_by_sid_async(iscsiadm_cmd
4cc2db
 	req.command = cmd;
4cc2db
 	req.u.session.sid = sid;
4cc2db
 
4cc2db
-	return iscsid_request(fd, &req;;
4cc2db
+	return iscsid_request(fd, &req, 1);
4cc2db
 }
4cc2db
 
4cc2db
 int iscsid_req_by_sid(iscsiadm_cmd_e cmd, int sid)
4cc2db
diff -up open-iscsi-2.0-870-rc1/usr/util.h.start-iscsid open-iscsi-2.0-870-rc1/usr/util.h
4cc2db
--- open-iscsi-2.0-870-rc1/usr/util.h.start-iscsid	2008-07-01 03:14:03.000000000 +0200
4cc2db
+++ open-iscsi-2.0-870-rc1/usr/util.h	2008-09-30 10:41:57.000000000 +0200
4cc2db
@@ -13,9 +13,10 @@ extern int oom_adjust(void);
4cc2db
 extern void daemon_init(void);
4cc2db
 extern int increase_max_files(void);
4cc2db
 
4cc2db
-extern int do_iscsid(struct iscsiadm_req *req,  struct iscsiadm_rsp *rsp);
4cc2db
+extern int do_iscsid(struct iscsiadm_req *req,  struct iscsiadm_rsp *rsp,
4cc2db
+		     int iscsid_start);
4cc2db
 extern void iscsid_handle_error(int err);
4cc2db
-extern int iscsid_request(int *fd, struct iscsiadm_req *req);
4cc2db
+extern int iscsid_request(int *fd, struct iscsiadm_req *req, int iscsid_start);
4cc2db
 extern int iscsid_response(int fd, int cmd, struct iscsiadm_rsp *rsp);
4cc2db
 extern int iscsid_req_wait(int cmd, int fd);
4cc2db
 extern int iscsid_req_by_rec_async(int cmd, struct node_rec *rec, int *fd);