コード例 #1
0
ファイル: queue_func.c プロジェクト: gto11520/torque
int que_purge(

  pbs_queue *pque)

  {
  char     namebuf[MAXPATHLEN];
  char     log_buf[LOCAL_LOG_BUF_SIZE];

  if (pque->qu_numjobs != 0)
    {
    return(PBSE_QUEBUSY);
    }

  snprintf(namebuf, sizeof(namebuf), "%s%s", path_queues, pque->qu_qs.qu_name);

  if (unlink(namebuf) < 0)
    {
    sprintf(log_buf, msg_err_unlink, "Queue", namebuf);

    log_err(errno, "queue_purge", log_buf);
    }

  que_free(pque, FALSE);

  return(0);
  }
コード例 #2
0
ファイル: queue_func.c プロジェクト: Johnlihj/torque
int que_purge(

  pbs_queue *pque)

  {
  char     namebuf[MAXPATHLEN];

  if (pque->qu_numjobs != 0)
    {
    return(PBSE_QUEBUSY);
    }

  strcpy(namebuf, path_queues); /* delete queue file */

  strcat(namebuf, pque->qu_qs.qu_name);

  if (unlink(namebuf) < 0)
    {
    sprintf(log_buffer, msg_err_unlink, "Queue", namebuf);

    log_err(errno, "queue_purge", log_buffer);
    }

  que_free(pque);

  return(0);
  }
コード例 #3
0
ファイル: queue_recov_db.c プロジェクト: A9-William/pbspro
/**
 * @brief
 *		Recover a queue from the database
 *
 * @param[in]	qname	- Name of the queue to recover
 *
 * @return	The recovered queue structure
 * @retval	NULL	- Failure
 * @retval	!NULL	- Success - address of recovered queue returned
 *
 */
pbs_queue *
que_recov_db(char *qname)
{
	pbs_queue		*pq;
	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;

	obj.pbs_db_obj_type = PBS_DB_QUEUE;
	obj.pbs_db_un.pbs_db_que = &dbque;

	pq = que_alloc(qname);  /* allocate & init queue structure space */
	if (pq == (pbs_queue *)0) {
		log_err(-1, "que_recov", "que_alloc failed");
		return ((pbs_queue *)0);
	}

	/* load server_qs */
	strcpy(dbque.qu_name, qname);

	if (pbs_db_begin_trx(conn, 0, 0) !=0)
		goto db_err;

	/* read in job fixed sub-structure */
	if (pbs_db_load_obj(conn, &obj) != 0)
		goto db_err;

	db_to_svr_que(pq, &dbque);

	attr_info.parent_id = pq->qu_qs.qu_name;
	attr_info.parent_obj_type = PARENT_TYPE_QUE_ALL; /* que attr */

	/* read in que attributes */
	if (recov_attr_db(conn, pq, &attr_info, que_attr_def, pq->qu_attr,
		(int)QA_ATR_LAST, 0) != 0)
		goto db_err;

	if (pbs_db_end_trx(conn, PBS_DB_COMMIT) != 0)
		goto db_err;

	/* all done recovering the queue */
	return (pq);
db_err:
	log_err(-1, "que_recov", "read of queuedb failed");
	(void) pbs_db_end_trx(conn, PBS_DB_ROLLBACK);
	if (pq)
		que_free(pq);
	return 0;
}
コード例 #4
0
ファイル: xtt_jop.cpp プロジェクト: ManfredHerrmann/proview
void Jop::scan()
{
  char *command;
  int sts;

  sts = que_get( &command);
  while ( ODD(sts))
  {
    printf( "Jop received : %s\n", command);
    if ( command_cb)
      (command_cb)( parent_ctx, command);
    que_free( command);
    sts = que_get( &command);
  }
}
コード例 #5
0
ファイル: queue_recov_db.c プロジェクト: Bhagat-Rajput/pbspro
/**
 * @brief
 *		Recover a queue from the database
 *
 * @param[in]	qname	- Name of the queue to recover
 *
 * @return	The recovered queue structure
 * @retval	NULL	- Failure
 * @retval	!NULL	- Success - address of recovered queue returned
 *
 */
pbs_queue *
que_recov_db(char *qname)
{
	pbs_queue		*pq;
	pbs_db_que_info_t	dbque;
	pbs_db_obj_info_t	obj;
	pbs_db_conn_t		*conn = (pbs_db_conn_t *) svr_db_conn;

	obj.pbs_db_obj_type = PBS_DB_QUEUE;
	obj.pbs_db_un.pbs_db_que = &dbque;

	pq = que_alloc(qname);  /* allocate & init queue structure space */
	if (pq == NULL) {
		log_err(-1, "que_recov", "que_alloc failed");
		return NULL;
	}

	/* load server_qs */
	dbque.qu_name[sizeof(dbque.qu_name) - 1] = '\0';
	strncpy(dbque.qu_name, qname, sizeof(dbque.qu_name));

	/* read in job fixed sub-structure */
	if (pbs_db_load_obj(conn, &obj) != 0)
		goto db_err;

	if (db_to_svr_que(pq, &dbque) != 0)
		goto db_err;

	pbs_db_reset_obj(&obj);

	/* all done recovering the queue */
	return (pq);

db_err:
	log_err(-1, "que_recov", "read of queuedb failed");
	if (pq)
		que_free(pq);
	return 0;
}
コード例 #6
0
pbs_queue *que_recov(

  char *filename) /* pathname to queue save file */

  {
  int        fds;
  int        i;
  pbs_queue *pq;
  char       namebuf[MAXPATHLEN];
  time_t     time_now = time(NULL);

  pq = que_alloc(filename, TRUE);  /* allocate & init queue structure space */

  if (pq == NULL)
    {
    log_err(-1, __func__, "que_alloc failed");

    return(NULL);
    }

  snprintf(namebuf, sizeof(namebuf), "%s%s", path_queues, filename);

  fds = open(namebuf, O_RDONLY, 0);

  if (fds < 0)
    {
    log_err(errno, __func__, "open error");

    que_free(pq, TRUE);

    return(NULL);
    }

  /* read in queue save sub-structure */

  if (read_ac_socket(fds, (char *)&pq->qu_qs, sizeof(queuefix)) !=
      sizeof(queuefix))
    {
    log_err(errno, __func__, "read error");
    que_free(pq, TRUE);
    close(fds);
    return ((pbs_queue *)0);
    }

  /* read in queue attributes */

  if (recov_attr(fds, pq, que_attr_def, pq->qu_attr,
	               QA_ATR_LAST, 0, TRUE) != 0)
    {
    log_err(-1, __func__, "recov_attr[common] failed");
    que_free(pq, TRUE);
    close(fds);
    return ((pbs_queue *)0);
    }

  /*
   * now reload the access control lists, these attributes were
   * saved separately
   */

  for (i = 0;i < QA_ATR_LAST;i++)
    {
    if (pq->qu_attr[i].at_type == ATR_TYPE_ACL)
      {
      recov_acl(
        &pq->qu_attr[i],
        &que_attr_def[i],
        que_attr_def[i].at_name,
        pq->qu_qs.qu_name);
      }
    }

  /* all done recovering the queue */

  close(fds);

  if ((pq->qu_attr[QA_ATR_MTime].at_flags & ATR_VFLAG_SET) == 0)
    {
    /* if we are recovering a pre-2.1.2 queue, save a new mtime */

    pq->qu_attr[QA_ATR_MTime].at_val.at_long = time_now;
    pq->qu_attr[QA_ATR_MTime].at_flags = ATR_VFLAG_SET;

    que_save(pq);
    }

  return(pq);
  }
コード例 #7
0
pbs_queue *que_recov_xml(

  char *filename)

  {
  int          fds;
  int          rc;
  pbs_queue   *pq;
  char         namebuf[MAXPATHLEN];
  char         buf[MAXLINE<<10];
  char        *parent;
  char        *child;

  char        *current;
  char        *begin;
  char        *end;
  char         log_buf[LOCAL_LOG_BUF_SIZE];
  time_t       time_now = time(NULL);

  pq = que_alloc(filename, TRUE);  /* allocate & init queue structure space */

  if (pq == NULL)
    {
    log_err(-1, __func__, "que_alloc failed");

    return(NULL);
    }

  snprintf(namebuf, sizeof(namebuf), "%s%s", path_queues, filename);

  fds = open(namebuf, O_RDONLY, 0);

  if (fds < 0)
    {
    log_err(errno, __func__, "open error");

    que_free(pq, TRUE);

    return(NULL);
    }

  /* read in queue save sub-structure */
  if (read_ac_socket(fds,buf,sizeof(buf)) < 0)
    {
    snprintf(log_buf,sizeof(log_buf),
      "Unable to read from queue file %s",
      filename);
    log_err(errno, __func__, log_buf);
    
    close(fds);

    return(NULL);
    }

  current = begin = buf;

  /* advance past the queue tag */
  current = strstr(current,"<queue>");
  if (current == NULL)
    {
    log_event(PBSEVENT_SYSTEM,
      PBS_EVENTCLASS_SERVER,
      __func__,
      "Cannot find a queue tag, attempting to load legacy format");
    que_free(pq, TRUE);
    
    close(fds);

    return(que_recov(filename));
    }

  end = strstr(current,"</queue>");

  if (end == NULL)
    {
    log_err(-1, __func__, "No queue tag found in the queue file???");
    que_free(pq, TRUE);
    close(fds);
    return(NULL);
    }

  /* move past the queue tag */
  current += strlen("<queue>");
  /* adjust the end for the newline preceeding the close queue tag */
  end--;

  while (current < end)
    {
    if (get_parent_and_child(current,&parent,&child,&current))
      {
      /* ERROR */
      snprintf(log_buf,sizeof(log_buf),
        "Bad XML in the queue file at: %s",
        current);
      log_err(-1, __func__, log_buf);

      que_free(pq, TRUE);
      close(fds);
      return(NULL);
      }

    if (!strcmp(parent,"modified"))
      pq->qu_qs.qu_modified = atoi(child);
    else if (!strcmp(parent,"type"))
      pq->qu_qs.qu_type = atoi(child);
    else if (!strcmp(parent,"create_time"))
      pq->qu_qs.qu_ctime = atoi(child);
    else if (!strcmp(parent,"modify_time"))
      pq->qu_qs.qu_mtime = atoi(child);
    else if (!strcmp(parent,"name"))
      snprintf(pq->qu_qs.qu_name,sizeof(pq->qu_qs.qu_name),"%s",child);
    else if (!strcmp(parent,"attributes"))
      {
      char *attr_ptr = child;
      char *child_parent;
      char *child_attr;

      while (*attr_ptr != '\0')
        {
        if (get_parent_and_child(attr_ptr,&child_parent,&child_attr,&attr_ptr))
          {
          /* ERROR */
          snprintf(log_buf,sizeof(log_buf),
            "Bad XML in the queue file at: %s",
            current);
          log_err(-1, __func__, log_buf);
          
          que_free(pq, TRUE);
          close(fds);
          return(NULL);
          }

        if ((rc = str_to_attr(child_parent,child_attr,pq->qu_attr,que_attr_def)))
          {
          /* ERROR */
          snprintf(log_buf,sizeof(log_buf),
            "Error creating attribute %s",
            child_parent);
          log_err(rc, __func__, log_buf);

          que_free(pq, TRUE);
          close(fds);
          return(NULL);
          }
        }
      }
    } 

  /* all done recovering the queue */

  close(fds);

  if ((pq->qu_attr[QA_ATR_MTime].at_flags & ATR_VFLAG_SET) == 0)
    {
    /* if we are recovering a pre-2.1.2 queue, save a new mtime */

    pq->qu_attr[QA_ATR_MTime].at_val.at_long = time_now;
    pq->qu_attr[QA_ATR_MTime].at_flags = ATR_VFLAG_SET;

    que_save(pq);
    }

  return(pq);
  } /* END que_recov_xml() */
コード例 #8
0
ファイル: queue_recov.c プロジェクト: A9-William/pbspro
pbs_queue *
que_recov_fs(char   *filename)
{
	int	   fds;
	int	   i;
	pbs_queue *pq;


	pq = que_alloc(filename);  /* allocate & init queue structure space */
	if (pq == (pbs_queue *)0) {
		log_err(-1, "que_recov", "que_alloc failed");
		return ((pbs_queue *)0);
	}

	(void)strcpy(pbs_recov_filename, path_queues);
	(void)strcat(pbs_recov_filename, filename);

#ifdef WIN32
	fix_perms(pbs_recov_filename);
#endif

	fds = open(pbs_recov_filename, O_RDONLY, 0);
	if (fds < 0) {
		sprintf(log_buffer, "error opening %s", pbs_recov_filename);
		log_err(errno, "que_recov", log_buffer);
		free((char *)pq);
		return ((pbs_queue *)0);
	}

#ifdef WIN32
	setmode(fds, O_BINARY);
#endif

	/* read in queue save sub-structure */

	errno = -1;
	if (read(fds, (char *)&pq->qu_qs, sizeof(struct queuefix)) !=
		sizeof(struct queuefix)) {
		sprintf(log_buffer, "error reading %s", pbs_recov_filename);
		log_err(errno, "que_recov", log_buffer);
		free((char *)pq);
		(void)close(fds);
		return ((pbs_queue *)0);
	}

	/* read in queue attributes */

	if (recov_attr_fs(fds, pq, que_attr_def, pq->qu_attr,
		(int)QA_ATR_LAST, 0) != 0) {
		log_err(-1, "que_recov", "recov_attr[common] failed");
		que_free(pq);
		(void)close(fds);
		return ((pbs_queue *)0);
	}

	/*
	 * now reload the access control lists, these attributes were
	 * saved separately
	 */

	for (i=0; i < (int)QA_ATR_LAST; i++) {
		if (pq->qu_attr[i].at_type == ATR_TYPE_ACL) {
			recov_acl(&pq->qu_attr[i], &que_attr_def[i],
				que_attr_def[i].at_name, pq->qu_qs.qu_name);
		}
	}

	/* all done recovering the queue */

	(void)close(fds);
	return (pq);
}
コード例 #9
0
ファイル: queue_func.c プロジェクト: A9-William/pbspro
/**
 * @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);
}