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:
@@ -174,12 +174,9 @@ 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);
|
||||
@@ -404,14 +401,9 @@ int main(int argc, char *argv[])
|
||||
|
||||
iscsi_set_session_type(iscsi, ISCSI_SESSION_DISCOVERY);
|
||||
|
||||
if (iscsi_url->user[0] != '\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);
|
||||
|
||||
@@ -266,15 +266,8 @@ int main(int argc, char *argv[])
|
||||
iscsi_get_error(client.src_iscsi));
|
||||
exit(10);
|
||||
}
|
||||
iscsi_set_targetname(client.src_iscsi, iscsi_url->target);
|
||||
iscsi_set_session_type(client.src_iscsi, ISCSI_SESSION_NORMAL);
|
||||
iscsi_set_header_digest(client.src_iscsi, ISCSI_HEADER_DIGEST_NONE_CRC32C);
|
||||
if (iscsi_url->user[0] != '\0') {
|
||||
if (iscsi_set_initiator_username_pwd(client.src_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(client.src_iscsi, iscsi_url->portal, iscsi_url->lun) != 0) {
|
||||
fprintf(stderr, "Login Failed. %s\n", iscsi_get_error(client.src_iscsi));
|
||||
iscsi_destroy_url(iscsi_url);
|
||||
@@ -325,15 +318,8 @@ int main(int argc, char *argv[])
|
||||
iscsi_get_error(client.dst_iscsi));
|
||||
exit(10);
|
||||
}
|
||||
iscsi_set_targetname(client.dst_iscsi, iscsi_url->target);
|
||||
iscsi_set_session_type(client.dst_iscsi, ISCSI_SESSION_NORMAL);
|
||||
iscsi_set_header_digest(client.dst_iscsi, ISCSI_HEADER_DIGEST_NONE_CRC32C);
|
||||
if (iscsi_url->user[0] != '\0') {
|
||||
if (iscsi_set_initiator_username_pwd(client.dst_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(client.dst_iscsi, iscsi_url->portal, iscsi_url->lun) != 0) {
|
||||
fprintf(stderr, "Login Failed. %s\n", iscsi_get_error(client.dst_iscsi));
|
||||
iscsi_destroy_url(iscsi_url);
|
||||
|
||||
@@ -92,19 +92,9 @@ int open(const char *path, int flags, mode_t mode)
|
||||
return -1;
|
||||
}
|
||||
|
||||
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] != '\0') {
|
||||
if (iscsi_set_initiator_username_pwd(iscsi, iscsi_url->user, iscsi_url->passwd) != 0) {
|
||||
LD_ISCSI_DPRINTF(0,"Failed to set initiator username and password");
|
||||
iscsi_destroy_context(iscsi);
|
||||
errno = ENOMEM;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (iscsi_full_connect_sync(iscsi, iscsi_url->portal, iscsi_url->lun) != 0) {
|
||||
LD_ISCSI_DPRINTF(0,"Login Failed. %s\n", iscsi_get_error(iscsi));
|
||||
iscsi_destroy_url(iscsi_url);
|
||||
|
||||
@@ -599,6 +599,14 @@ iscsi_parse_url(struct iscsi_context *iscsi, const char *url, int full)
|
||||
|
||||
iscsi_decode_url_string(&iscsi_url->target[0]);
|
||||
|
||||
/* NOTE: iscsi is allowed to be NULL. Especially qemu does call us with iscsi == NULL.
|
||||
* If we receive iscsi != NULL we apply the parsed settings to the context. */
|
||||
if (iscsi) {
|
||||
iscsi_set_targetname(iscsi, iscsi_url->target);
|
||||
iscsi_set_initiator_username_pwd(iscsi, iscsi_url->user, iscsi_url->passwd);
|
||||
iscsi_set_target_username_pwd(iscsi, iscsi_url->target_user, iscsi_url->target_passwd);
|
||||
}
|
||||
|
||||
return iscsi_url;
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user