When special functionality is needed after storing a sysfs string, allow a function to be called after the store is complete. Use this to update auth->authenticate_target only when the relevant inputs have changed. Signed-off-by: Eric Seppanen <eric@xxxxxxxxxxxxxxx> --- drivers/target/iscsi/iscsi_target_configfs.c | 49 ++++++++++++++++---------- 1 file changed, 30 insertions(+), 19 deletions(-) diff --git a/drivers/target/iscsi/iscsi_target_configfs.c b/drivers/target/iscsi/iscsi_target_configfs.c index 23d02ce..44cbed4 100644 --- a/drivers/target/iscsi/iscsi_target_configfs.c +++ b/drivers/target/iscsi/iscsi_target_configfs.c @@ -452,7 +452,7 @@ static struct configfs_attribute *lio_target_nacl_attrib_attrs[] = { /* Start items for lio_target_nacl_auth_cit */ -#define __DEF_NACL_AUTH_STR(prefix, name, maxlen, flags) \ +#define __DEF_NACL_AUTH_STR(prefix, name, maxlen, flags, post_func) \ static ssize_t __iscsi_##prefix##_show_##name( \ struct iscsi_node_acl *nacl, \ char *page) \ @@ -483,12 +483,7 @@ static ssize_t __iscsi_##prefix##_store_##name( \ else \ auth->naf_flags |= flags; \ \ - if ((auth->naf_flags & NAF_USERID_IN_SET) && \ - (auth->naf_flags & NAF_PASSWORD_IN_SET)) \ - auth->authenticate_target = 1; \ - else \ - auth->authenticate_target = 0; \ - \ + post_func(auth); \ return count; \ } @@ -505,8 +500,8 @@ static ssize_t __iscsi_##prefix##_show_##name( \ return snprintf(page, PAGE_SIZE, "%d\n", auth->name); \ } -#define DEF_NACL_AUTH_STR(name, maxlen, flags) \ - __DEF_NACL_AUTH_STR(nacl_auth, name, maxlen, flags) \ +#define DEF_NACL_AUTH_STR(name, maxlen, flags, post_func) \ + __DEF_NACL_AUTH_STR(nacl_auth, name, maxlen, flags, post_func) \ static ssize_t iscsi_nacl_auth_show_##name( \ struct se_node_acl *nacl, \ char *page) \ @@ -536,15 +531,31 @@ static ssize_t iscsi_nacl_auth_show_##name( \ #define AUTH_ATTR(_name, _mode) TF_NACL_AUTH_ATTR(iscsi, _name, _mode); #define AUTH_ATTR_RO(_name) TF_NACL_AUTH_ATTR_RO(iscsi, _name); +static void post_nop(struct iscsi_node_auth *auth) +{ +} + +/* + * If userid and password are both set, enable target authentication. + */ +static void post_target_auth(struct iscsi_node_auth *auth) +{ + if ((auth->naf_flags & NAF_USERID_IN_SET) && + (auth->naf_flags & NAF_PASSWORD_IN_SET)) + auth->authenticate_target = 1; + else + auth->authenticate_target = 0; +} + /* * One-way authentication userid */ -DEF_NACL_AUTH_STR(userid, MAX_USER_LEN, NAF_USERID_SET); +DEF_NACL_AUTH_STR(userid, MAX_USER_LEN, NAF_USERID_SET, post_nop); AUTH_ATTR(userid, S_IRUGO | S_IWUSR); /* * One-way authentication password */ -DEF_NACL_AUTH_STR(password, MAX_PASS_LEN, NAF_PASSWORD_SET); +DEF_NACL_AUTH_STR(password, MAX_PASS_LEN, NAF_PASSWORD_SET, post_nop); AUTH_ATTR(password, S_IRUGO | S_IWUSR); /* * Enforce mutual authentication @@ -554,12 +565,12 @@ AUTH_ATTR_RO(authenticate_target); /* * Mutual authentication userid */ -DEF_NACL_AUTH_STR(userid_mutual, MAX_USER_LEN, NAF_USERID_IN_SET); +DEF_NACL_AUTH_STR(userid_mutual, MAX_USER_LEN, NAF_USERID_IN_SET, post_target_auth); AUTH_ATTR(userid_mutual, S_IRUGO | S_IWUSR); /* * Mutual authentication password */ -DEF_NACL_AUTH_STR(password_mutual, MAX_PASS_LEN, NAF_PASSWORD_IN_SET); +DEF_NACL_AUTH_STR(password_mutual, MAX_PASS_LEN, NAF_PASSWORD_IN_SET, post_target_auth); AUTH_ATTR(password_mutual, S_IRUGO | S_IWUSR); static struct configfs_attribute *lio_target_nacl_auth_attrs[] = { @@ -1433,8 +1444,8 @@ static void lio_target_call_coredeltiqn( /* Start lio_target_discovery_auth_cit */ -#define DEF_DISC_AUTH_STR(name, maxlen, flags) \ - __DEF_NACL_AUTH_STR(disc, name, maxlen, flags) \ +#define DEF_DISC_AUTH_STR(name, maxlen, flags, post_func) \ + __DEF_NACL_AUTH_STR(disc, name, maxlen, flags, post_func) \ static ssize_t iscsi_disc_show_##name( \ struct target_fabric_configfs *tf, \ char *page) \ @@ -1467,12 +1478,12 @@ static ssize_t iscsi_disc_show_##name( \ /* * One-way authentication userid */ -DEF_DISC_AUTH_STR(userid, MAX_USER_LEN, NAF_USERID_SET); +DEF_DISC_AUTH_STR(userid, MAX_USER_LEN, NAF_USERID_SET, post_nop); DISC_AUTH_ATTR(userid, S_IRUGO | S_IWUSR); /* * One-way authentication password */ -DEF_DISC_AUTH_STR(password, MAX_PASS_LEN, NAF_PASSWORD_SET); +DEF_DISC_AUTH_STR(password, MAX_PASS_LEN, NAF_PASSWORD_SET, post_nop); DISC_AUTH_ATTR(password, S_IRUGO | S_IWUSR); /* * Enforce mutual authentication @@ -1482,12 +1493,12 @@ DISC_AUTH_ATTR_RO(authenticate_target); /* * Mutual authentication userid */ -DEF_DISC_AUTH_STR(userid_mutual, MAX_USER_LEN, NAF_USERID_IN_SET); +DEF_DISC_AUTH_STR(userid_mutual, MAX_USER_LEN, NAF_USERID_IN_SET, post_target_auth); DISC_AUTH_ATTR(userid_mutual, S_IRUGO | S_IWUSR); /* * Mutual authentication password */ -DEF_DISC_AUTH_STR(password_mutual, MAX_PASS_LEN, NAF_PASSWORD_IN_SET); +DEF_DISC_AUTH_STR(password_mutual, MAX_PASS_LEN, NAF_PASSWORD_IN_SET, post_target_auth); DISC_AUTH_ATTR(password_mutual, S_IRUGO | S_IWUSR); /* -- 1.7.10.4 -- To unsubscribe from this list: send the line "unsubscribe target-devel" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html