/** * @brief - purge scheduler from system * * @param[in] psched - The pointer to the delete to delete * * @return error code * @retval 0 - scheduler purged * @retval PBSE_OBJBUSY - scheduler deletion not allowed */ int sched_delete(pbs_sched *psched) { pbs_db_obj_info_t obj; pbs_db_sched_info_t dbsched; pbs_db_conn_t *conn = (pbs_db_conn_t *) svr_db_conn; if (psched == NULL) return (0); /* TODO check for scheduler activity and return PBSE_OBJBUSY */ /* delete scheduler from database */ strcpy(dbsched.sched_name, psched->sc_name); obj.pbs_db_obj_type = PBS_DB_SCHED; obj.pbs_db_un.pbs_db_sched = &dbsched; if (pbs_db_delete_obj(conn, &obj) != 0) { snprintf(log_buffer, LOG_BUF_SIZE, "delete of scheduler %s from datastore failed", psched->sc_name); log_err(errno, __func__, log_buffer); } sched_free(psched); return (0); }
/** * @brief * Save a queue to the database * * @param[in] pque - Pointer to the queue to save * @param[in] mode: * QUE_SAVE_FULL - Save full queue information (update) * QUE_SAVE_NEW - Save new queue information (insert) * * @return Error code * @retval 0 - Success * @retval 1 - Failure * */ int que_save_db(pbs_queue *pque, int mode) { pbs_db_que_info_t dbque; pbs_db_attr_info_t attr_info; pbs_db_obj_info_t obj; pbs_db_conn_t *conn = (pbs_db_conn_t *) svr_db_conn; int flag=0; svr_to_db_que(pque, &dbque); obj.pbs_db_obj_type = PBS_DB_QUEUE; obj.pbs_db_un.pbs_db_que = &dbque; /* load que_qs */ if (pbs_db_begin_trx(conn, 0, 0) !=0) goto db_err; if (mode == QUE_SAVE_NEW) { if (pbs_db_insert_obj(conn, &obj) != 0) goto db_err; flag = 1; } else if (mode == QUE_SAVE_FULL) { /* * Delete the queue and write it afresh * Deleting the queue removes all attributes automatically * Thus when reinserting, we add only the set attributes */ pbs_db_delete_obj(conn, &obj); if (pbs_db_insert_obj(conn, &obj) != 0) goto db_err; flag = 1; } else { /* que_qs*/ if (pbs_db_update_obj(conn, &obj) != 0) goto db_err; } /* que_attrs */ attr_info.parent_obj_type = PARENT_TYPE_QUE_ALL; /* que attr */ attr_info.parent_id = dbque.qu_name; if (save_attr_db(conn, &attr_info, que_attr_def, pque->qu_attr, (int)QA_ATR_LAST, flag) !=0) goto db_err; if (pbs_db_end_trx(conn, PBS_DB_COMMIT) != 0) goto db_err; return (0); db_err: strcpy(log_buffer, "que_save failed "); if (conn->conn_db_err != NULL) strncat(log_buffer, conn->conn_db_err, LOG_BUF_SIZE - strlen(log_buffer) - 1); log_err(-1, __func__, log_buffer); (void) pbs_db_end_trx(conn, PBS_DB_ROLLBACK); panic_stop_db(log_buffer); return (-1); }
/** * @brief * que_purge - purge queue from system * The queue is dequeued, the queue file is unlinked. * If the queue contains any jobs, the purge is not allowed. * Eventually the queue is deleted from the database * * @param[in] pque - The pointer to the queue to purge * * @return error code * @retval 0 - queue purged or queue not valid * @retval PBSE_OBJBUSY - queue deletion not allowed */ int que_purge(pbs_queue *pque) { pbs_db_obj_info_t obj; pbs_db_que_info_t dbque; pbs_db_conn_t *conn = (pbs_db_conn_t *) svr_db_conn; /* * If the queue (pque) is not valid, then nothing to * do, just return 0. */ if (pque == NULL) return (0); /* are there any jobs still in the queue */ if (pque->qu_numjobs != 0) { /* * If the queue still has job(s), check if the SERVER * is configured for history info and all the jobs in * queue are history jobs. If yes, then allow queue * deletion otherwise return PBSE_OBJBUSY. */ if (svr_history_enable) { /* SVR histconf chk */ job *pjob = (job *)0; job *nxpjob = (job *)0; pjob = (job *)GET_NEXT(pque->qu_jobs); while (pjob) { /* * If it is not a history job (MOVED/FINISHED), then * return with PBSE_OBJBUSY error. */ if ((pjob->ji_qs.ji_state != JOB_STATE_MOVED) && (pjob->ji_qs.ji_state != JOB_STATE_FINISHED)) return (PBSE_OBJBUSY); pjob = (job *)GET_NEXT(pjob->ji_jobque); } /* * All are history jobs, unlink all of them from queue. * Update the number of jobs in the queue and their state * count as the queue is going to be purged. No job(s) * should point to the queue to be purged, make the queue * header pointer of job(pjob->ji_qhdr) to NULL. */ pjob = (job *)GET_NEXT(pque->qu_jobs); while (pjob) { nxpjob = (job *)GET_NEXT(pjob->ji_jobque); delete_link(&pjob->ji_jobque); --pque->qu_numjobs; --pque->qu_njstate[pjob->ji_qs.ji_state]; pjob->ji_qhdr = (pbs_queue *)0; pjob = nxpjob; } } else { return (PBSE_OBJBUSY); } } /* delete queue from database */ strcpy(dbque.qu_name, pque->qu_qs.qu_name); obj.pbs_db_obj_type = PBS_DB_QUEUE; obj.pbs_db_un.pbs_db_que = &dbque; if (pbs_db_delete_obj(conn, &obj) != 0) { (void)sprintf(log_buffer, "delete of que %s from datastore failed", pque->qu_qs.qu_name); log_err(errno, "queue_purge", log_buffer); } que_free(pque); return (0); }