* Send Storage address to the FD
*/
jcr->file_bsock->fsend(storaddr, store_address, store_port, tls_need);
- if (!response(jcr, jcr->file_bsock, OKstore, "Storage", DISPLAY_ERROR)) {
+ if (!response(jcr, jcr->file_bsock, BSOCK_TYPE_FD, OKstore, "Storage", DISPLAY_ERROR)) {
return false;
}
return true;
* Send Client address to the SD
*/
sd->fsend(clientaddr, get_client_address(jcr, jcr->client, buf.addr()), jcr->client->FDport, tls_need);
- if (!response(jcr, sd, OKclient, "Client", DISPLAY_ERROR)) {
+ if (!response(jcr, sd, BSOCK_TYPE_SD, OKclient, "Client", DISPLAY_ERROR)) {
return false;
}
return true;
/* Send backup command */
fd->fsend(backupcmd, jcr->JobFiles);
Dmsg1(100, ">filed: %s", fd->msg);
- if (!response(jcr, fd, OKbackup, "backup", DISPLAY_ERROR)) {
+ if (!response(jcr, fd, BSOCK_TYPE_FD, OKbackup, "backup", DISPLAY_ERROR)) {
goto bail_out;
}
tid = start_bsock_timer(fd, timeout); /* TODO: New timeout directive??? */
}
/* Wait for Client to terminate */
- while ((n = bget_dirmsg(fd)) >= 0) {
+ while ((n = bget_dirmsg(jcr, fd, BSOCK_TYPE_FD)) >= 0) {
if (!fd_ok &&
(sscanf(fd->msg, newEndJob, &jcr->FDJobStatus, &JobFiles,
&ReadBytes, &JobBytes, &JobErrors, &VSS, &Encrypt,
memset(jcr->sd_auth_key, 0, strlen(jcr->sd_auth_key));
}
Dmsg1(100, ">filed: %s", fd->msg);
- if (bget_dirmsg(fd) > 0) {
+ if (bget_dirmsg(jcr, fd, BSOCK_TYPE_FD) > 0) {
Dmsg1(110, "<filed: %s", fd->msg);
if (strncmp(fd->msg, OKjob, strlen(OKjob)) != 0) {
Jmsg(jcr, M_FATAL, 0, _("File daemon \"%s\" rejected Job command: %s\n"),
stime = str_to_utime(jcr->stime);
fd->fsend(levelcmd, "", NT_("since_utime "), edit_uint64(stime, ed1), 0,
NT_("prev_job="), jcr->PrevJob);
- while (bget_dirmsg(fd) >= 0) { /* allow him to poll us to sync clocks */
+ while (bget_dirmsg(jcr, fd, BSOCK_TYPE_FD) >= 0) { /* allow him to poll us to sync clocks */
Jmsg(jcr, M_INFO, 0, "%s\n", fd->msg);
}
}
BSOCK *fd = jcr->file_bsock;
if (jcr->FDVersion >= 4) {
fd->fsend(bandwidthcmd, jcr->max_bandwidth, Job);
- if (!response(jcr, fd, OKBandwidth, "Bandwidth", DISPLAY_ERROR)) {
+ if (!response(jcr, fd, BSOCK_TYPE_FD, OKBandwidth, "Bandwidth", DISPLAY_ERROR)) {
jcr->max_bandwidth = 0; /* can't set bandwidth limit */
return false;
}
return 0;
}
Dmsg1(120, ">filed: %s", fd->msg);
- if (!response(jcr, fd, OKlevel, "Level", DISPLAY_ERROR)) {
+ if (!response(jcr, fd, BSOCK_TYPE_FD, OKlevel, "Level", DISPLAY_ERROR)) {
return false;
}
return true;
}
fd->signal(BNET_EOD); /* end of data */
- if (!response(jcr, fd, OKinc, "Include", DISPLAY_ERROR)) {
+ if (!response(jcr, fd, BSOCK_TYPE_FD, OKinc, "Include", DISPLAY_ERROR)) {
goto bail_out;
}
return true;
fd->fsend("N\n");
fd->signal(BNET_EOD); /* end of data */
- if (!response(jcr, fd, OKinc, "Include", DISPLAY_ERROR)) {
+ if (!response(jcr, fd, BSOCK_TYPE_FD, OKinc, "Include", DISPLAY_ERROR)) {
return false;
}
return true;
fd->fsend("N\n");
fd->signal(BNET_EOD); /* end of data */
- if (!response(jcr, fd, OKinc, "Include", DISPLAY_ERROR)) {
+ if (!response(jcr, fd, BSOCK_TYPE_FD, OKinc, "Include", DISPLAY_ERROR)) {
return false;
}
return true;
Dmsg1(120, "bdird: sending old runcommand to fd '%s'\n",msg);
if (when & SCRIPT_Before) {
jcr->file_bsock->fsend(runbefore, msg);
- ret = response(jcr, jcr->file_bsock, OKRunBefore, "ClientRunBeforeJob", DISPLAY_ERROR);
+ ret = response(jcr, jcr->file_bsock, BSOCK_TYPE_FD, OKRunBefore, "ClientRunBeforeJob", DISPLAY_ERROR);
} else {
jcr->file_bsock->fsend(runafter, msg);
- ret = response(jcr, jcr->file_bsock, OKRunAfter, "ClientRunAfterJob", DISPLAY_ERROR);
+ ret = response(jcr, jcr->file_bsock, BSOCK_TYPE_FD, OKRunAfter, "ClientRunAfterJob", DISPLAY_ERROR);
}
return ret;
} /* END OF TODO */
cmd->when,
msg);
- result = response(jcr, fd, OKRunScript, "RunScript", DISPLAY_ERROR);
+ result = response(jcr, fd, BSOCK_TYPE_FD, OKRunScript, "RunScript", DISPLAY_ERROR);
launch_before_cmd = true;
}
/* Tell the FD to execute the ClientRunBeforeJob */
if (launch_before_cmd) {
fd->fsend(runbeforenow);
- if (!response(jcr, fd, OKRunBeforeNow, "RunBeforeNow", DISPLAY_ERROR)) {
+ if (!response(jcr, fd, BSOCK_TYPE_FD, OKRunBeforeNow, "RunBeforeNow", DISPLAY_ERROR)) {
goto bail_out;
}
}
*/
fd->fsend("PluginFeatures\n");
- while (bget_dirmsg(fd) > 0) {
+ while (bget_dirmsg(jcr, fd, BSOCK_TYPE_FD) > 0) {
buf.check_size(fd->msglen+1);
if (sscanf(fd->msg, "2000 plugin=%127s features=%s", ed1, buf.c_str()) == 2) {
/* We have buf=feature1,feature2,feature3 */
if (octx.count > 0) {
fd = jcr->file_bsock;
fd->fsend("restoreobject end\n");
- if (!response(jcr, fd, OKRestoreObject, "RestoreObject", DISPLAY_ERROR)) {
+ if (!response(jcr, fd, BSOCK_TYPE_FD, OKRestoreObject, "RestoreObject", DISPLAY_ERROR)) {
Jmsg(jcr, M_FATAL, 0, _("RestoreObject failed.\n"));
return false;
}
Dmsg1(050, "Send component_info to FD: %s\n", buf);
}
fd->signal(BNET_EOD);
- if (!response(jcr, fd, OKComponentInfo, "ComponentInfo", DISPLAY_ERROR)) {
+ if (!response(jcr, fd, BSOCK_TYPE_FD, OKComponentInfo, "ComponentInfo", DISPLAY_ERROR)) {
Jmsg(jcr, M_FATAL, 0, _("ComponentInfo failed.\n"));
ok = false;
}
Dmsg0(120, "bdird: waiting to receive file attributes\n");
/* Pickup file attributes and digest */
- while (!fd->errors && (n = bget_dirmsg(fd)) > 0) {
+ while (!fd->errors && (n = bget_dirmsg(jcr, fd, BSOCK_TYPE_FD)) > 0) {
int32_t file_index;
int stream, len;
char *p, *fn;
* *System* for the Job name, and hence no JCR is obtained. This
* is a *rare* case where a jcr is not really needed.
*
+ * role is the role of component at the other side of the BSOCK
+ * BSOCK_TYPE_FD for a file daemon (that cannot update the catalog)
+ * BSOCK_TYPE_SD for a storage daemon
*/
-int bget_dirmsg(BSOCK *bs)
+int bget_dirmsg(JCR *jcr, BSOCK *bs, BSOCK_CLIENT_TYPE role)
{
int32_t n = BNET_TERMINATE;
char Job[MAX_NAME_LENGTH];
char MsgType[20];
int type;
utime_t mtime; /* message time */
- JCR *jcr = bs->jcr();
char *msg;
for ( ; !bs->is_stop() && !bs->is_timed_out(); ) {
dispatch_message(jcr, type, mtime, msg);
continue;
}
+
/*
- * Here we expact a CatReq message
- * CatReq JobId=nn Catalog-Request-Message
+ * Here we expect a catalog request message from the SD
+ * CatReq JobId=nn .....
+ * UpdCat JobId=nn ......
+ * BlastAttr JobId=nn ....
+ *
*/
- if (bs->msg[0] == 'C') { /* Catalog request */
+ if (role==BSOCK_TYPE_SD && bs->msg[0] == 'C') { /* Catalog request */
Dmsg2(900, "Catalog req jcr=%p: %s", jcr, bs->msg);
catalog_request(jcr, bs);
continue;
}
- if (bs->msg[0] == 'U') { /* SD sending attributes */
+ if (role==BSOCK_TYPE_SD && bs->msg[0] == 'U') { /* SD sending attributes */
Dmsg2(900, "Catalog upd jcr=%p: %s", jcr, bs->msg);
catalog_update(jcr, bs);
continue;
}
- if (bs->msg[0] == 'B') { /* SD sending file spool attributes */
+ if (role==BSOCK_TYPE_SD && bs->msg[0] == 'B') { /* SD sending file spool attributes */
Dmsg2(100, "Blast attributes jcr=%p: %s", jcr, bs->msg);
char filename[256];
if (sscanf(bs->msg, "BlastAttr JobId=%ld File=%255s",
continue;
}
/* Get Progress: files, bytes, bytes/sec */
- if (bs->msg[0] == 'P') { /* Progress report */
+ if (role==BSOCK_TYPE_FD && bs->msg[0] == 'P') { /* Progress report */
uint32_t files, bps;
uint64_t bytes;
if ((sscanf(bs->msg, "Progress JobId=%ld files=%ld bytes=%lld bps=%ld\n",
}
continue;
}
- if (bs->msg[0] == 'S') { /* Status change */
+ if (role==BSOCK_TYPE_SD && bs->msg[0] == 'S') { /* Status change */
int JobStatus;
if (sscanf(bs->msg, Job_status, &JobId, &JobStatus) == 2) {
set_jcr_sd_job_status(jcr, JobStatus); /* current status */
}
#ifdef needed
/* No JCR for Device Updates! */
- if (bs->msg[0] = 'D') { /* Device update */
+ if (role==BSOCK_TYPE_SD && bs->msg[0] = 'D') { /* Device update */
DEVICE *dev;
POOL_MEM dev_name, changer_name, media_type, volume_name;
int dev_open, dev_append, dev_read, dev_labeled;
* Returns: false on failure
* true on success
*/
-bool response(JCR *jcr, BSOCK *bs, char *resp, const char *cmd, e_prtmsg prtmsg)
+bool response(JCR *jcr, BSOCK *bs, BSOCK_CLIENT_TYPE role, const char *resp, const char *cmd, e_prtmsg prtmsg)
{
int n;
if (bs->is_error()) {
return false;
}
- if ((n = bget_dirmsg(bs)) >= 0) {
+ if ((n = bget_dirmsg(jcr, bs, role)) >= 0) {
if (strcmp(bs->msg, resp) == 0) {
return true;
}
Dmsg2(200, "=== Job=%s sd auth key=%s\n", Job, sd_auth_key);
jcr->store_bsock->fsend(storaddr, store_address, store_port,
tls_need, Job, sd_auth_key);
- if (!response(jcr, jcr->store_bsock, OKstore, "Storage", DISPLAY_ERROR)) {
+ if (!response(jcr, jcr->store_bsock, BSOCK_TYPE_SD, OKstore, "Storage", DISPLAY_ERROR)) {
Dmsg4(050, "Response fail for: JobId=%d storeaddr=%s:%d Job=%s\n",
jcr->JobId, store_address, store_port, Job);
Jmsg3(jcr, M_FATAL, 0, "Response failure: storeddr=%s:%d Job=%s\n",
sd->fsend(query_device, device_name.c_str());
Dmsg1(100, ">stored: %s\n", sd->msg);
/* The data is returned through Device_update */
- if (bget_dirmsg(sd) <= 0) {
+ if (bget_dirmsg(jcr, sd, BSOCK_TYPE_SD) <= 0) {
return false;
}
return true;
Dmsg1(100, ">stored: %s", sd->msg);
Dmsg2(100, "=== rstore=%p wstore=%p\n", rstore, wstore);
- if (bget_dirmsg(sd) > 0) {
+ if (bget_dirmsg(jcr, sd, BSOCK_TYPE_SD) > 0) {
Dmsg1(100, "<stored: %s", sd->msg);
if (sscanf(sd->msg, OKjob, &jcr->VolSessionId,
&jcr->VolSessionTime, &sd_auth_key) != 3) {
}
if (send_bsr && (!send_bootstrap_file(jcr, sd) ||
- !response(jcr, sd, OKbootstrap, "Bootstrap", DISPLAY_ERROR))) {
+ !response(jcr, sd, BSOCK_TYPE_SD, OKbootstrap, "Bootstrap", DISPLAY_ERROR))) {
return false;
}
sd->signal(BNET_EOD); /* end of Devices */
}
sd->signal(BNET_EOD); /* end of Storages */
- if (bget_dirmsg(sd) > 0) {
+ if (bget_dirmsg(jcr, sd, BSOCK_TYPE_SD) > 0) {
Dmsg1(100, "<stored: %s", sd->msg);
ok = sscanf(sd->msg, OK_device, device_name.c_str()) == 1;
} else {
sd->signal(BNET_EOD); /* end of Devices */
}
sd->signal(BNET_EOD); /* end of Storages */
- if (bget_dirmsg(sd) > 0) {
+ if (bget_dirmsg(jcr, sd, BSOCK_TYPE_SD) > 0) {
Dmsg1(100, "<stored: %s", sd->msg);
ok = sscanf(sd->msg, OK_device, device_name.c_str()) == 1;
} else {
*/
Dmsg0(100, "Start msg_thread loop\n");
n = 0;
- while (!job_canceled(jcr) && (n=bget_dirmsg(sd)) >= 0) {
+ while (!job_canceled(jcr) && (n=bget_dirmsg(jcr, sd, BSOCK_TYPE_SD)) >= 0) {
Dmsg1(400, "<stored: %s", sd->msg);
if (sscanf(sd->msg, Job_start, Job) == 1) {
continue;
DISPLAY_ERROR,
NO_DISPLAY
};
-extern bool response(JCR *jcr, BSOCK *fd, char *resp, const char *cmd, e_prtmsg prtmsg);
+extern bool response(JCR *jcr, BSOCK *fd, BSOCK_CLIENT_TYPE role, const char *resp, const char *cmd, e_prtmsg prtmsg);
/* job.c */
extern bool allow_duplicate_job(JCR *jcr);
extern bool start_storage_daemon_job(JCR *jcr, alist *rstore, alist *wstore, bool wait,
bool send_bsr=false);
extern bool start_storage_daemon_message_thread(JCR *jcr);
-extern int bget_dirmsg(BSOCK *bs);
+extern int bget_dirmsg(JCR *jcr, BSOCK *bs, BSOCK_CLIENT_TYPE role);
extern void wait_for_storage_daemon_termination(JCR *jcr);
extern bool send_bootstrap_file(JCR *jcr, BSOCK *sd);
* Send the bootstrap file -- what Volumes/files to restore
*/
if (!send_bootstrap_file(jcr, sd, info) ||
- !response(jcr, sd, OKbootstrap, "Bootstrap", DISPLAY_ERROR)) {
+ !response(jcr, sd, BSOCK_TYPE_SD, OKbootstrap, "Bootstrap", DISPLAY_ERROR)) {
goto bail_out;
}
fd->fsend(storaddr, store_address, store_port, tls_need, jcr->sd_auth_key);
memset(jcr->sd_auth_key, 0, strlen(jcr->sd_auth_key));
Dmsg1(6, "dird>filed: %s\n", fd->msg);
- if (!response(jcr, fd, OKstore, "Storage", DISPLAY_ERROR)) {
+ if (!response(jcr, fd, BSOCK_TYPE_FD, OKstore, "Storage", DISPLAY_ERROR)) {
goto bail_out;
}
}
fd->fsend("%s", restore_cmd.c_str());
- if (!response(jcr, fd, OKrestore, "Restore", DISPLAY_ERROR)) {
+ if (!response(jcr, fd, BSOCK_TYPE_FD, OKrestore, "Restore", DISPLAY_ERROR)) {
goto bail_out;
}
if (jcr->FDVersion < 2) { /* Old FD */
break; /* we do only one loop */
} else {
- if (!response(jcr, fd, OKstoreend, "Store end", DISPLAY_ERROR)) {
+ if (!response(jcr, fd, BSOCK_TYPE_FD, OKstoreend, "Store end", DISPLAY_ERROR)) {
goto bail_out;
}
wait_for_storage_daemon_termination(jcr);
char ed1[50];
if (val > 0 && jcr->FDVersion >= 13) {
fd->fsend(snapretentioncmd, edit_uint64(val, ed1));
- if (!response(jcr, fd, (char*)"2000 Snapshot retention\n", "set Snapshot Retention", DISPLAY_ERROR)) {
+ if (!response(jcr, fd, BSOCK_TYPE_FD, "2000 Snapshot retention\n", "set Snapshot Retention", DISPLAY_ERROR)) {
jcr->snapshot_retention = 0; /* can't set snapshot retention */
return false;
}
unbash_spaces(truncate_option);
/* Check for valid response */
- while (bget_dirmsg(sd) >= 0) {
+ while (bget_dirmsg(ua->jcr, sd, BSOCK_TYPE_SD) >= 0) {
if (strncmp(sd->msg, "3000 OK truncate cache", 22) == 0) {
ua->send_msg("%s", sd->msg);
ok = true;
bash_spaces(dev_name);
sd->fsend("mount %s drive=%d slot=%d", dev_name, drive, mr.Slot);
unbash_spaces(dev_name);
- while (bget_dirmsg(sd) >= 0) {
+ while (bget_dirmsg(ua->jcr, sd, BSOCK_TYPE_SD) >= 0) {
ua->send_msg("%s", sd->msg);
/* Here we can get
* 3001 OK mount. Device=xxx or
dev_name, mr->VolumeName, pr->Name, mr->MediaType, mr->Slot, drive);
}
- while (bget_dirmsg(sd) >= 0) {
+ while (bget_dirmsg(ua->jcr, sd, BSOCK_TYPE_SD) >= 0) {
ua->send_msg("%s", sd->msg);
if (sscanf(sd->msg, "3000 OK label. VolBytes=%llu VolABytes=%lld VolType=%d ",
&VolBytes, &VolABytes, &VolType) == 3) {
/* Check for valid response. With cloud volumes, the upload of the part.1 can
* generate a dir_update_volume_info() message that is handled by bget_dirmsg()
*/
- while (bget_dirmsg(sd) >= 0) {
+ while (bget_dirmsg(ua->jcr, sd, BSOCK_TYPE_SD) >= 0) {
ua->send_msg("%s", sd->msg);
if (sscanf(sd->msg, "3000 OK label. VolBytes=%llu VolABytes=%lld VolType=%d ",
&VolBytes, &VolABytes, &VolType) == 3) {
* Send the bootstrap file -- what Volumes/files to restore
*/
if (!send_bootstrap_file(jcr, sd) ||
- !response(jcr, sd, OKbootstrap, "Bootstrap", DISPLAY_ERROR)) {
+ !response(jcr, sd, BSOCK_TYPE_SD, OKbootstrap, "Bootstrap", DISPLAY_ERROR)) {
goto bail_out;
}
if (!jcr->sd_calls_client) {
* Send verify command/level to File daemon
*/
fd->fsend(verifycmd, level);
- if (!response(jcr, fd, OKverify, "Verify", DISPLAY_ERROR)) {
+ if (!response(jcr, fd, BSOCK_TYPE_FD, OKverify, "Verify", DISPLAY_ERROR)) {
goto bail_out;
}
case L_VERIFY_DATA:
/* Nothing special to do */
- bget_dirmsg(fd); /* eat EOD */
+ bget_dirmsg(jcr, fd, BSOCK_TYPE_FD); /* eat EOD */
break;
default:
Jmsg1(jcr, M_FATAL, 0, _("Unimplemented verify level %d\n"), jcr->getJobLevel());
* Attributes
* Link name ???
*/
- while ((n=bget_dirmsg(fd)) >= 0 && !job_canceled(jcr)) {
+ while ((n=bget_dirmsg(jcr, fd, BSOCK_TYPE_FD)) >= 0 && !job_canceled(jcr)) {
int32_t stream, full_stream;
char *attr, *p, *fn;
char Opts_Digest[MAXSTRING]; /* Verify Opts or MD5/SHA1 digest */
#define BSOCK_TIMEOUT 3600 * 24 * 200; /* default 200 days */
+/* Type of bsock connection (to sd, to fd, to console, to dir...) */
+typedef enum {
+ BSOCK_TYPE_UNKN,
+ BSOCK_TYPE_FD, // Connected to FD
+ BSOCK_TYPE_SD, // Connected to DIR
+ BSOCK_TYPE_CONS // Connected to console
+} BSOCK_CLIENT_TYPE;
+
class BSOCK: public BSOCKCORE {
public:
FILE *m_spool_fd; /* spooling file */
static char Job_status[] = "Status JobId=%ld JobStatus=%d\n";
-
void lock_jobs()
{
P(job_start_mutex);
/*
* Send Job status to Director
+ * ATTN: Only the SD like components are expected to send there job status
*/
bool JCR::sendJobStatus()
{
/*
* Set and send Job status to Director
+ * ATTN: Only the SD like components are expected to send there job status
*/
bool JCR::sendJobStatus(int aJobStatus)
{