[stgt] [PATCH 1/7] move set_mtask_result() call to mtask_received()

nezhinsky at gmail.com nezhinsky at gmail.com
Fri May 18 12:24:23 CEST 2012


From: Alexander Nezhinsky <alexandern at mellanox.com>

Set tgtadm error code in mtask just before response send is initiated, in mtask_received().
mtask_execute() carries out all requests and returns appropriate error codes.
This way set_mtask_result() is called in a single place, while previously those errors
were returned from sys_mgmt, target_mgmt etc. All these calls are removed.

Signed-off-by: Alexander Nezhinsky <alexandern at mellanox.com>
---
 usr/mgmt.c |   23 ++++++++---------------
 1 file changed, 8 insertions(+), 15 deletions(-)

diff --git a/usr/mgmt.c b/usr/mgmt.c
index 8915dea..ef1b265 100644
--- a/usr/mgmt.c
+++ b/usr/mgmt.c
@@ -195,7 +195,6 @@ static tgtadm_err target_mgmt(int lld_no, struct mgmt_task *mtask)
 		break;
 	}
 
-	set_mtask_result(mtask, adm_err);
 	return adm_err;
 }
 
@@ -225,7 +224,6 @@ static tgtadm_err portal_mgmt(int lld_no, struct mgmt_task *mtask)
 		break;
 	}
 
-	set_mtask_result(mtask, adm_err);
 	return adm_err;
 }
 
@@ -251,7 +249,6 @@ static tgtadm_err device_mgmt(int lld_no, struct mgmt_task *mtask)
 		break;
 	}
 
-	set_mtask_result(mtask, adm_err);
 	return adm_err;
 }
 
@@ -268,13 +265,13 @@ static tgtadm_err account_mgmt(int lld_no,  struct mgmt_task *mtask)
 	case OP_UNBIND:
 		user = strstr(mtask->req_buf, "user=");
 		if (!user)
-			goto out;
+			return TGTADM_INVALID_REQUEST;
 		user += 5;
 
 		if (req->op == OP_NEW) {
 			password = strchr(user, ',');
 			if (!password)
-				goto out;
+				return TGTADM_INVALID_REQUEST;
 
 			*password++ = '\0';
 			password += strlen("password=");
@@ -296,8 +293,7 @@ static tgtadm_err account_mgmt(int lld_no,  struct mgmt_task *mtask)
 	default:
 		break;
 	}
-out:
-	set_mtask_result(mtask, adm_err);
+
 	return adm_err;
 }
 
@@ -343,7 +339,6 @@ static tgtadm_err sys_mgmt(int lld_no, struct mgmt_task *mtask)
 		break;
 	}
 
-	set_mtask_result(mtask, adm_err);
 	return adm_err;
 }
 
@@ -373,7 +368,6 @@ static tgtadm_err connection_mgmt(int lld_no, struct mgmt_task *mtask)
 		break;
 	}
 
-	set_mtask_result(mtask, adm_err);
 	return adm_err;
 }
 
@@ -393,8 +387,7 @@ static tgtadm_err mtask_execute(struct mgmt_task *mtask)
 			else
 				eprintf("driver %s is in state: %s\n",
 					req->lld, driver_state_name(tgt_drivers[lld_no]));
-			set_mtask_result(mtask, TGTADM_NO_DRIVER);
-			return 0;
+			return TGTADM_NO_DRIVER;
 		}
 	}
 
@@ -429,11 +422,11 @@ static tgtadm_err mtask_execute(struct mgmt_task *mtask)
 							    req->cid, req->lun,
 							    &mtask->rsp_concat);
 			concat_buf_finish(&mtask->rsp_concat);
-		}
+		} else
+			eprintf("unsupported mode: %d\n", req->mode);
 		break;
 	}
 
-	set_mtask_result(mtask, adm_err);
 	return adm_err;
 }
 
@@ -500,9 +493,9 @@ static int mtask_received(struct mgmt_task *mtask, int fd)
 	int err;
 
 	adm_err = mtask_execute(mtask);
-	if (adm_err != TGTADM_SUCCESS)
-		eprintf("mgmt task processing failed, err: %d\n", adm_err);
+	set_mtask_result(mtask, adm_err);
 
+	/* whatever the result of mtask execution, a response is sent */
 	mtask->mtask_state = MTASK_STATE_HDR_SEND;
 	mtask->done = 0;
 	err = tgt_event_modify(fd, EPOLLOUT);
-- 
1.7.9.6

--
To unsubscribe from this list: send the line "unsubscribe stgt" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html



More information about the stgt mailing list