void process_Dreply( int sock) { int handle; struct work_task *ptask; int rc; struct batch_request *request; /* find the work task for the socket, it will point us to the request */ ptask = (struct work_task *)GET_NEXT(task_list_event); handle = svr_conn[sock].cn_handle; while (ptask != NULL) { if ((ptask->wt_type == WORK_Deferred_Reply) && (ptask->wt_event == handle)) break; ptask = (struct work_task *)GET_NEXT(ptask->wt_linkall); } if (ptask == NULL) { log_err(-1, "process_Dreply", msg_err_malloc); close_conn(sock); return; } request = ptask->wt_parm1; /* read and decode the reply */ if ((rc = DIS_reply_read(sock, &request->rq_reply)) != 0) { close_conn(sock); request->rq_reply.brp_code = rc; request->rq_reply.brp_choice = BATCH_REPLY_CHOICE_NULL; } /* now dispatch the reply to the routine in the work task */ dispatch_task(ptask); return; } /* END process_Dreply() */
int send_request_to_remote_server( int conn, batch_request *request) { struct attropl *patrl; struct svrattrl *psvratl; int rc = PBSE_NONE; int tmp_rc = PBSE_NONE; int sock = 0; char log_buf[LOCAL_LOG_BUF_SIZE]; struct tcp_chan *chan = NULL; pthread_mutex_lock(connection[conn].ch_mutex); sock = connection[conn].ch_socket; pthread_mutex_unlock(connection[conn].ch_mutex); request->rq_conn = sock; if ((chan = DIS_tcp_setup(sock)) == NULL) { log_err(PBSE_MEM_MALLOC, __func__, "Could not allocate memory for socket buffer"); close_conn(sock, FALSE); return(PBSE_MEM_MALLOC); } /* the request is bound to another server, encode/send the request */ switch (request->rq_type) { case PBS_BATCH_DeleteJob: rc = PBSD_mgr_put( conn, PBS_BATCH_DeleteJob, MGR_CMD_DELETE, MGR_OBJ_JOB, request->rq_ind.rq_delete.rq_objname, NULL, NULL); break; case PBS_BATCH_HoldJob: attrl_fixlink(&request->rq_ind.rq_hold.rq_orig.rq_attr); psvratl = (struct svrattrl *)GET_NEXT(request->rq_ind.rq_hold.rq_orig.rq_attr); patrl = &psvratl->al_atopl; rc = PBSD_mgr_put( conn, PBS_BATCH_HoldJob, MGR_CMD_SET, MGR_OBJ_JOB, request->rq_ind.rq_hold.rq_orig.rq_objname, patrl, NULL); break; case PBS_BATCH_CheckpointJob: rc = PBSD_mgr_put( conn, PBS_BATCH_CheckpointJob, MGR_CMD_SET, MGR_OBJ_JOB, request->rq_ind.rq_hold.rq_orig.rq_objname, NULL, NULL); break; case PBS_BATCH_GpuCtrl: rc = PBSD_gpu_put( conn, request->rq_ind.rq_gpuctrl.rq_momnode, request->rq_ind.rq_gpuctrl.rq_gpuid, request->rq_ind.rq_gpuctrl.rq_gpumode, request->rq_ind.rq_gpuctrl.rq_reset_perm, request->rq_ind.rq_gpuctrl.rq_reset_vol, NULL); break; case PBS_BATCH_MessJob: rc = PBSD_msg_put( conn, request->rq_ind.rq_message.rq_jid, request->rq_ind.rq_message.rq_file, request->rq_ind.rq_message.rq_text, NULL); break; case PBS_BATCH_ModifyJob: case PBS_BATCH_AsyModifyJob: attrl_fixlink(&request->rq_ind.rq_modify.rq_attr); patrl = (struct attropl *) & ((struct svrattrl *)GET_NEXT( request->rq_ind.rq_modify.rq_attr))->al_atopl; rc = PBSD_mgr_put( conn, request->rq_type, MGR_CMD_SET, MGR_OBJ_JOB, request->rq_ind.rq_modify.rq_objname, patrl, NULL); break; case PBS_BATCH_Rerun: if ((rc = encode_DIS_ReqHdr(chan, PBS_BATCH_Rerun, msg_daemonname))) break; if ((rc = encode_DIS_JobId(chan, request->rq_ind.rq_rerun))) break; if ((rc = encode_DIS_ReqExtend(chan, 0))) break; rc = DIS_tcp_wflush(chan); break; case PBS_BATCH_RegistDep: if ((rc = encode_DIS_ReqHdr(chan, PBS_BATCH_RegistDep, msg_daemonname))) break; if ((rc = encode_DIS_Register(chan, request))) break; if ((rc = encode_DIS_ReqExtend(chan, 0))) break; rc = DIS_tcp_wflush(chan); break; case PBS_BATCH_AsySignalJob: case PBS_BATCH_SignalJob: rc = PBSD_sig_put( conn, request->rq_ind.rq_signal.rq_jid, request->rq_ind.rq_signal.rq_signame, request->rq_extra); break; case PBS_BATCH_StatusJob: rc = PBSD_status_put( conn, PBS_BATCH_StatusJob, request->rq_ind.rq_status.rq_id, NULL, NULL); break; case PBS_BATCH_TrackJob: if ((rc = encode_DIS_ReqHdr(chan, PBS_BATCH_TrackJob, msg_daemonname))) break; if ((rc = encode_DIS_TrackJob(chan, request))) break; if ((rc = encode_DIS_ReqExtend(chan, 0))) break; rc = DIS_tcp_wflush(chan); break; case PBS_BATCH_ReturnFiles: if ((rc = encode_DIS_ReqHdr(chan, PBS_BATCH_ReturnFiles, msg_daemonname))) break; if ((rc = encode_DIS_ReturnFiles(chan, request))) break; if ((rc = encode_DIS_ReqExtend(chan, 0))) break; rc = DIS_tcp_wflush(chan); break; case PBS_BATCH_CopyFiles: if ((rc = encode_DIS_ReqHdr(chan, PBS_BATCH_CopyFiles, msg_daemonname))) break; if ((rc = encode_DIS_CopyFiles(chan, request))) break; if ((rc = encode_DIS_ReqExtend(chan, 0))) break; rc = DIS_tcp_wflush(chan); break; case PBS_BATCH_DelFiles: if ((rc = encode_DIS_ReqHdr(chan, PBS_BATCH_DelFiles, msg_daemonname))) break; if ((rc = encode_DIS_CopyFiles(chan, request))) break; if ((rc = encode_DIS_ReqExtend(chan, 0))) break; rc = DIS_tcp_wflush(chan); break; case PBS_BATCH_DeleteReservation: if ((rc = encode_DIS_ReqHdr(chan, PBS_BATCH_DeleteReservation, msg_daemonname))) break; if ((rc = encode_DIS_ReqExtend(chan, request->rq_extend))) break; rc = DIS_tcp_wflush(chan); break; default: sprintf(log_buf, msg_issuebad, request->rq_type); log_err(-1, __func__, log_buf); rc = -1; break; } /* END switch (request->rq_type) */ if ((tmp_rc = DIS_reply_read(chan, &request->rq_reply)) != 0) { sprintf(log_buf, "DIS_reply_read failed: %d", tmp_rc); log_record(PBSEVENT_JOB, PBS_EVENTCLASS_JOB, __func__, log_buf); request->rq_reply.brp_code = tmp_rc; request->rq_reply.brp_choice = BATCH_REPLY_CHOICE_NULL; } DIS_tcp_cleanup(chan); svr_disconnect(conn); return(rc); } /* END send_request_to_remote_server() */
/** * @brief * process the reply received for a request issued to * another server via issue_request() * * Reads the reply from the RPP stream and executes the work task associated * with the RPP reply message. The RPP request for which this reply arrived * is matched by comparing the msgid of the reply with the msgid of the work * tasks stored in the msr_deferred_cmds list of the mom for this stream. * * @param[in] handle - RPP handle on which reply/close arrived * * @return void */ void process_DreplyRPP(int handle) { struct work_task *ptask; int rc; struct batch_request *request; struct batch_reply *reply; char *msgid = NULL; mominfo_t *pmom = 0; if ((pmom = tfind2((u_long) handle, 0, &streams)) == NULL) return; DIS_rpp_reset(); /* find the work task for the socket, it will point us to the request */ msgid = disrst(handle, &rc); if (!msgid || rc) { /* rpp connection actually broke, cull all pending requests */ while ((ptask = (struct work_task *)GET_NEXT((((mom_svrinfo_t *) (pmom->mi_data))->msr_deferred_cmds)))) { /* no need to compare wt_event with handle, since the * task list is for this mom and so it will always match */ if (ptask->wt_type == WORK_Deferred_Reply) { request = ptask->wt_parm1; if (request) { request->rq_reply.brp_code = rc; request->rq_reply.brp_choice = BATCH_REPLY_CHOICE_NULL; } } ptask->wt_aux = PBSE_NORELYMOM; pbs_errno = PBSE_NORELYMOM; if (ptask->wt_event2) free(ptask->wt_event2); dispatch_task(ptask); } } else { /* we read msgid fine, so proceed to match it and process the respective task */ /* get the task list */ ptask = (struct work_task *)GET_NEXT((((mom_svrinfo_t *) (pmom->mi_data))->msr_deferred_cmds)); while (ptask) { char *cmd_msgid = ptask->wt_event2; if (strcmp(cmd_msgid, msgid) == 0) { if (ptask->wt_type == WORK_Deferred_Reply) request = ptask->wt_parm1; else request = NULL; if (!request) { if ((reply = (struct batch_reply *) malloc(sizeof(struct batch_reply))) == 0) { delete_task(ptask); free(cmd_msgid); log_err(errno, msg_daemonname, "Out of memory creating batch reply"); return; } (void) memset(reply, 0, sizeof(struct batch_reply)); } else { reply = &request->rq_reply; } /* read and decode the reply */ if ((rc = DIS_reply_read(handle, reply, 1)) != 0) { reply->brp_code = rc; reply->brp_choice = BATCH_REPLY_CHOICE_NULL; ptask->wt_aux = PBSE_NORELYMOM; pbs_errno = PBSE_NORELYMOM; } else { ptask->wt_aux = reply->brp_code; pbs_errno = reply->brp_code; } ptask->wt_parm3 = reply; /* set the reply in case callback fn uses without having a preq */ dispatch_task(ptask); if (!request) PBSD_FreeReply(reply); free(cmd_msgid); break; } ptask = (struct work_task *) GET_NEXT(ptask->wt_linkobj2); } free(msgid); /* the msgid read should be free after use in matching */ } }
/** * @brief * process the reply received for a request issued to * another server via issue_request() over TCP * * @param[in] sock - TCP socket over which reply arrived * * @return void */ void process_Dreply(int sock) { int handle; struct work_task *ptask; int rc; struct batch_request *request; #ifdef WIN32 int i; #endif conn_t *conn; conn = get_conn(sock); if(!conn) return; /* find the work task for the socket, it will point us to the request */ ptask = (struct work_task *)GET_NEXT(task_list_event); #ifdef WIN32 handle = -1; for (i=0;i < PBS_MAX_CONNECTIONS; i++) { if (connection[i].ch_inuse && connection[i].ch_socket == sock) { handle = i; break; } } #else handle = conn->cn_handle; #endif while (ptask) { if ((ptask->wt_type == WORK_Deferred_Reply) && (ptask->wt_event == handle)) break; ptask = (struct work_task *)GET_NEXT(ptask->wt_linkall); } if (!ptask) { close_conn(sock); return; } request = ptask->wt_parm1; /* read and decode the reply */ /* set long timeout on I/O */ pbs_tcp_timeout = PBS_DIS_TCP_TIMEOUT_LONG; if ((rc = DIS_reply_read(sock, &request->rq_reply, 0)) != 0) { close_conn(sock); request->rq_reply.brp_code = rc; request->rq_reply.brp_choice = BATCH_REPLY_CHOICE_NULL; } pbs_tcp_timeout = PBS_DIS_TCP_TIMEOUT_SHORT; /* short timeout */ /* now dispatch the reply to the routine in the work task */ dispatch_task(ptask); return; }