Skip to content

Commit

Permalink
Streamline error handling.
Browse files Browse the repository at this point in the history
When we fail in backup due to a version mismatch on the FD protocol
or in restore and verify for every failure we close the FD connection
if we opened that and return from the function. For backup we keep
the wait_for_job_termination() call as we really need that but as
we closed the FD connection already when we got a FD protocol version
mismatch we no longer hang waiting for something to be returned from
the FD which won't happen when the DIR detects a protocol version
mismatch.
  • Loading branch information
Marco van Wieringen committed Oct 2, 2013
1 parent 2f0ebb0 commit 47a2264
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 22 deletions.
27 changes: 14 additions & 13 deletions src/dird/backup.c
Expand Up @@ -305,7 +305,8 @@ bool do_native_backup(JCR *jcr)
{
int status;
int tls_need = BNET_TLS_NONE;
BSOCK *fd, *sd;
BSOCK *fd = NULL;
BSOCK *sd = NULL;
STORERES *store = NULL;
CLIENTRES *client = NULL;
char ed1[100];
Expand Down Expand Up @@ -389,19 +390,19 @@ bool do_native_backup(JCR *jcr)
if (!connect_to_file_daemon(jcr, 10, me->FDConnectTimeout, 1)) {
goto bail_out;
}
fd = jcr->file_bsock;

/*
* Check if the file daemon supports passive client mode.
*/
if (jcr->passive_client && jcr->FDVersion < FD_VERSION_51) {
Jmsg(jcr, M_FATAL, 0,
_("Client \"%s\" doesn't support passive client mode. Please upgrade your client.\n\n"),
_("Client \"%s\" doesn't support passive client mode. Please upgrade your client.\n"),
jcr->res.client->name());
goto bail_out;
goto close_fd;
}

jcr->setJobStatus(JS_Running);
fd = jcr->file_bsock;

if (!send_level_command(jcr)) {
goto bail_out;
Expand Down Expand Up @@ -555,20 +556,20 @@ bool do_native_backup(JCR *jcr)
native_backup_cleanup(jcr, status);
return true;
}

return false;

close_fd:
if (jcr->file_bsock) {
jcr->file_bsock->signal(BNET_TERMINATE);
jcr->file_bsock->close();
jcr->file_bsock = NULL;
}

bail_out:
/*
* Come here only after starting SD thread
*/
jcr->setJobStatus(JS_ErrorTerminated);
Dmsg1(400, "wait for sd. use=%d\n", jcr->use_count());

/*
* Cancel SD
*/
wait_for_job_termination(jcr, me->FDConnectTimeout);
Dmsg1(400, "after wait for sd. use=%d\n", jcr->use_count());

return false;
}

Expand Down
19 changes: 12 additions & 7 deletions src/dird/restore.c
Expand Up @@ -121,10 +121,9 @@ static inline bool do_native_restore_bootstrap(JCR *jcr)
STORERES *store;
bootstrap_info info;
BSOCK *fd = NULL;
BSOCK *sd;
BSOCK *sd = NULL;
bool first_time = true;
POOL_MEM restore_cmd(PM_MESSAGE);
bool ret = false;

/*
* This command is used for each part
Expand Down Expand Up @@ -181,18 +180,17 @@ static inline bool do_native_restore_bootstrap(JCR *jcr)
if (!connect_to_file_daemon(jcr, 10, me->FDConnectTimeout, 1)) {
goto bail_out;
}
fd = jcr->file_bsock;

/*
* Check if the file daemon supports passive client mode.
*/
if (jcr->passive_client && jcr->FDVersion < FD_VERSION_51) {
Jmsg(jcr, M_FATAL, 0,
_("Client \"%s\" doesn't support passive client mode. Please upgrade your client.\n\n"),
_("Client \"%s\" doesn't support passive client mode. Please upgrade your client.\n"),
jcr->res.client->name());
goto bail_out;
}

fd = jcr->file_bsock;
}

jcr->setJobStatus(JS_Running);
Expand Down Expand Up @@ -343,11 +341,18 @@ static inline bool do_native_restore_bootstrap(JCR *jcr)
fd->fsend("endrestore");
}

ret = true;
close_bootstrap_file(info);
return true;

bail_out:
if (jcr->file_bsock) {
jcr->file_bsock->signal(BNET_TERMINATE);
jcr->file_bsock->close();
jcr->file_bsock = NULL;
}

close_bootstrap_file(info);
return ret;
return false;
}

/**
Expand Down
11 changes: 9 additions & 2 deletions src/dird/verify.c
Expand Up @@ -266,13 +266,14 @@ bool do_verify(JCR *jcr)
if (!connect_to_file_daemon(jcr, 10, me->FDConnectTimeout, 1)) {
goto bail_out;
}
fd = jcr->file_bsock;

/*
* Check if the file daemon supports passive client mode.
*/
if (jcr->passive_client && jcr->FDVersion < FD_VERSION_51) {
Jmsg(jcr, M_FATAL, 0,
_("Client \"%s\" doesn't support passive client mode. Please upgrade your client.\n\n"),
_("Client \"%s\" doesn't support passive client mode. Please upgrade your client.\n"),
jcr->res.client->name());
goto bail_out;
}
Expand All @@ -285,11 +286,11 @@ bool do_verify(JCR *jcr)
if (!connect_to_file_daemon(jcr, 10, me->FDConnectTimeout, 1)) {
goto bail_out;
}
fd = jcr->file_bsock;
break;
}

jcr->setJobStatus(JS_Running);
fd = jcr->file_bsock;

Dmsg0(30, ">filed: Send include list\n");
if (!send_include_list(jcr)) {
Expand Down Expand Up @@ -459,6 +460,12 @@ bool do_verify(JCR *jcr)
return true;

bail_out:
if (jcr->file_bsock) {
jcr->file_bsock->signal(BNET_TERMINATE);
jcr->file_bsock->close();
jcr->file_bsock = NULL;
}

return false;
}

Expand Down

0 comments on commit 47a2264

Please sign in to comment.