[stgt] [PATCH] Unbinding a non-existent ACL returns success

Paul Ryan pajryan at gmail.com
Wed Oct 5 03:08:18 CEST 2011


This adds support so tgtadm can return an error code and error
message when a non-existent ACL is unbound from a target.

Signed-off-by: Paul Ryan <pajryan at gmail.com>
---
 usr/mgmt.c         |    6 ++----
 usr/target.c       |   14 ++++++++++----
 usr/tgtadm.c       |    1 +
 usr/tgtadm_error.h |    1 +
 usr/tgtd.h         |    4 ++--
 5 files changed, 16 insertions(+), 10 deletions(-)

diff --git a/usr/mgmt.c b/usr/mgmt.c
index 82a70e1..af37480 100644
--- a/usr/mgmt.c
+++ b/usr/mgmt.c
@@ -109,14 +109,12 @@ static int target_mgmt(int lld_no, struct
mgmt_task *mtask)

 			p = strstr(mtask->buf, "initiator-address=");
 			if (p) {
-				err = 0;
-				acl_del(req->tid, p + strlen("initiator-address="));
+				err = acl_del(req->tid, p + strlen("initiator-address="));
 			}

 			p = strstr(mtask->buf, "initiator-name=");
 			if (p) {
-				err = 0;
-				iqn_acl_del(req->tid, p + strlen("initiator-name="));
+				err = iqn_acl_del(req->tid, p + strlen("initiator-name="));
 			}
 		}
 		break;
diff --git a/usr/target.c b/usr/target.c
index 5a8dfa6..f2c30ea 100644
--- a/usr/target.c
+++ b/usr/target.c
@@ -1482,23 +1482,26 @@ int acl_add(int tid, char *address)
 	return 0;
 }

-void acl_del(int tid, char *address)
+int acl_del(int tid, char *address)
 {
 	struct target *target;
 	struct acl_entry *acl, *tmp;
+	int err = TGTADM_ACL_NOEXIST;

 	target = target_lookup(tid);
 	if (!target)
-		return;
+		return TGTADM_NO_TARGET;

 	list_for_each_entry_safe(acl, tmp, &target->acl_list, aclent_list) {
 		if (!strcmp(address, acl->address)) {
 			list_del(&acl->aclent_list);
 			free(acl->address);
 			free(acl);
+			err = 0;
 			break;
 		}
 	}
+	return err;
 }

 char *acl_get(int tid, int idx)
@@ -1549,23 +1552,26 @@ int iqn_acl_add(int tid, char *name)
 	return 0;
 }

-void iqn_acl_del(int tid, char *name)
+int iqn_acl_del(int tid, char *name)
 {
 	struct target *target;
 	struct iqn_acl_entry *iqn_acl, *tmp;
+	int err = TGTADM_ACL_NOEXIST;

 	target = target_lookup(tid);
 	if (!target)
-		return;
+		return TGTADM_ACL_NOEXIST;

 	list_for_each_entry_safe(iqn_acl, tmp, &target->iqn_acl_list,
iqn_aclent_list) {
 		if (!strcmp(name, iqn_acl->name)) {
 			list_del(&iqn_acl->iqn_aclent_list);
 			free(iqn_acl->name);
 			free(iqn_acl);
+			err = 0;
 			break;
 		}
 	}
+	return err;
 }

 char *iqn_acl_get(int tid, int idx)
diff --git a/usr/tgtadm.c b/usr/tgtadm.c
index 5e107a4..b2b1aa3 100644
--- a/usr/tgtadm.c
+++ b/usr/tgtadm.c
@@ -66,6 +66,7 @@ static const char * tgtadm_strerror(int err)
 		{ TGTADM_TARGET_EXIST, "this target already exists" },
 		{ TGTADM_LUN_EXIST, "this logical unit number already exists" },
 		{ TGTADM_ACL_EXIST, "this access control rule already exists" },
+		{ TGTADM_ACL_NOEXIST, "this access control rule does not exist" },
 		{ TGTADM_USER_EXIST, "this account already exists" },
 		{ TGTADM_NO_USER, "can't find the account" },
 		{ TGTADM_TOO_MANY_USER, "too many accounts" },
diff --git a/usr/tgtadm_error.h b/usr/tgtadm_error.h
index 319a4ad..4cd8f81 100644
--- a/usr/tgtadm_error.h
+++ b/usr/tgtadm_error.h
@@ -15,6 +15,7 @@ enum tgtadm_errno {
 	TGTADM_LUN_EXIST,

 	TGTADM_ACL_EXIST,
+	TGTADM_ACL_NOEXIST,
 	TGTADM_USER_EXIST,
 	TGTADM_NO_USER,
 	TGTADM_TOO_MANY_USER,
diff --git a/usr/tgtd.h b/usr/tgtd.h
index 93e6049..86198c8 100644
--- a/usr/tgtd.h
+++ b/usr/tgtd.h
@@ -285,11 +285,11 @@ extern enum scsi_target_state
tgt_get_target_state(int tid);
 extern int tgt_set_target_state(int tid, char *str);

 extern int acl_add(int tid, char *address);
-extern void acl_del(int tid, char *address);
+extern int acl_del(int tid, char *address);
 extern char *acl_get(int tid, int idx);

 extern int iqn_acl_add(int tid, char *name);
-extern void iqn_acl_del(int tid, char *name);
+extern int iqn_acl_del(int tid, char *name);
 extern char *iqn_acl_get(int tid, int idx);

 extern int account_lookup(int tid, int type, char *user, int ulen,
char *password, int plen);
-- 
1.7.4.1
--
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