Example #1
0
/**
 * @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;
}
Example #2
0
/**
 * @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;
}
Example #3
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);
  }
Example #4
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() */
Example #5
0
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);
}