init: apply settings to context in iscsi_parse_url

if iscsi_context is not NULL we apply the parsed settings
to the context.

Signed-off-by: Peter Lieven <pl@kamp.de>
This commit is contained in:
Peter Lieven
2015-03-26 10:32:19 +01:00
parent a45094b7a7
commit 2955b2c616
9 changed files with 20 additions and 88 deletions

View File

@@ -322,17 +322,9 @@ int main(int argc, char *argv[])
exit(10);
}
iscsi_set_targetname(iscsi, iscsi_url->target);
iscsi_set_session_type(iscsi, ISCSI_SESSION_NORMAL);
iscsi_set_header_digest(iscsi, ISCSI_HEADER_DIGEST_NONE_CRC32C);
if (iscsi_url->user[0]) {
if (iscsi_set_initiator_username_pwd(iscsi, iscsi_url->user, iscsi_url->passwd) != 0) {
fprintf(stderr, "Failed to set initiator username and password\n");
exit(10);
}
}
if (iscsi_full_connect_sync(iscsi, iscsi_url->portal, iscsi_url->lun) != 0) {
fprintf(stderr, "Login Failed. %s\n", iscsi_get_error(iscsi));
iscsi_destroy_url(iscsi_url);

View File

@@ -172,12 +172,8 @@ void list_luns(struct client_state *clnt, const char *target, const char *portal
printf("Failed to create context\n");
exit(10);
}
if (clnt->username != NULL) {
if (iscsi_set_initiator_username_pwd(iscsi, clnt->username, clnt->password) != 0) {
fprintf(stderr, "Failed to set initiator username and password\n");
exit(10);
}
}
iscsi_set_initiator_username_pwd(iscsi, clnt->username, clnt->password);
if (iscsi_set_targetname(iscsi, target)) {
fprintf(stderr, "Failed to set target name\n");
exit(10);
@@ -430,14 +426,9 @@ int main(int argc, char *argv[])
iscsi_set_session_type(iscsi, ISCSI_SESSION_DISCOVERY);
if (iscsi_url->user[0]) {
state.username = iscsi_url->user;
state.password = iscsi_url->passwd;
if (iscsi_set_initiator_username_pwd(iscsi, iscsi_url->user, iscsi_url->passwd) != 0) {
fprintf(stderr, "Failed to set initiator username and password\n");
exit(10);
}
}
state.username = iscsi_url->user;
state.password = iscsi_url->passwd;
if (iscsi_connect_async(iscsi, iscsi_url->portal, discoveryconnect_cb, &state) != 0) {
fprintf(stderr, "iscsi_connect failed. %s\n", iscsi_get_error(iscsi));
exit(10);

View File

@@ -270,27 +270,17 @@ int main(int argc, char *argv[])
fprintf(stderr, "Failed to create context\n");
exit(10);
}
iscsi_url = iscsi_parse_full_url(client.iscsi, url);
iscsi_url = iscsi_parse_full_url(client.iscsi, url);
if (iscsi_url == NULL) {
fprintf(stderr, "Failed to parse URL: %s\n",
iscsi_get_error(client.iscsi));
exit(10);
}
iscsi_set_targetname(client.iscsi, iscsi_url->target);
iscsi_set_session_type(client.iscsi, ISCSI_SESSION_NORMAL);
iscsi_set_header_digest(client.iscsi, ISCSI_HEADER_DIGEST_NONE_CRC32C);
if (iscsi_url->user[0] != '\0') {
if (iscsi_set_initiator_username_pwd(client.iscsi, iscsi_url->user, iscsi_url->passwd) != 0) {
fprintf(stderr, "Failed to set initiator username and password\n");
iscsi_destroy_url(iscsi_url);
iscsi_destroy_context(client.iscsi);
exit(10);
}
}
if (iscsi_full_connect_sync(client.iscsi, iscsi_url->portal, iscsi_url->lun) != 0) {
fprintf(stderr, "Login Failed. %s\n", iscsi_get_error(client.iscsi));
iscsi_destroy_url(iscsi_url);

View File

@@ -145,17 +145,9 @@ int main(int argc, char *argv[])
exit(10);
}
iscsi_set_targetname(iscsi, iscsi_url->target);
iscsi_set_session_type(iscsi, ISCSI_SESSION_NORMAL);
iscsi_set_header_digest(iscsi, ISCSI_HEADER_DIGEST_NONE_CRC32C);
if (iscsi_url->user[0]) {
if (iscsi_set_initiator_username_pwd(iscsi, iscsi_url->user, iscsi_url->passwd) != 0) {
fprintf(stderr, "Failed to set initiator username and password\n");
exit(10);
}
}
if (iscsi_full_connect_sync(iscsi, iscsi_url->portal, iscsi_url->lun) != 0) {
fprintf(stderr, "Login Failed. %s\n", iscsi_get_error(iscsi));
iscsi_destroy_url(iscsi_url);

View File

@@ -158,18 +158,9 @@ int main(int argc, char *argv[])
goto finished;
}
iscsi_set_targetname(iscsi, iscsi_url->target);
iscsi_set_session_type(iscsi, ISCSI_SESSION_NORMAL);
iscsi_set_header_digest(iscsi, ISCSI_HEADER_DIGEST_NONE_CRC32C);
if (iscsi_url->user[0]) {
if (iscsi_set_initiator_username_pwd(iscsi, iscsi_url->user, iscsi_url->passwd) != 0) {
fprintf(stderr, "Failed to set initiator username and password\n");
ret = 10;
goto finished;
}
}
if (iscsi_full_connect_sync(iscsi, iscsi_url->portal, iscsi_url->lun) != 0) {
fprintf(stderr, "Login Failed. %s\n", iscsi_get_error(iscsi));
ret = 10;