Beispiel #1
0
static void
Libgenders_dealloc(Libgenders* self)
{
  genders_handle_destroy(self->gh);
  self->ob_type->tp_free((PyObject*)self);
}
Beispiel #2
0
genders_t
genders_copy(genders_t handle) 
{
  genders_t handlecopy = NULL;

  if (_genders_loaded_handle_error_check(handle) < 0)
    return NULL;

  if (!(handlecopy = genders_handle_create()))
    {
      handle->errnum = GENDERS_ERR_OUTMEM;
      goto cleanup;
    }

  handlecopy->is_loaded = handle->is_loaded;
  handlecopy->flags = handle->flags;
  handlecopy->numnodes = handle->numnodes;
  handlecopy->numattrs = handle->numattrs;
  handlecopy->maxattrs = handle->maxattrs;
  handlecopy->maxnodelen = handle->maxnodelen;
  handlecopy->maxattrlen = handle->maxattrlen;
  handlecopy->maxvallen = handle->maxvallen;

  memcpy(handlecopy->nodename, handle->nodename, GENDERS_MAXHOSTNAMELEN+1);
  
  if (_genders_copy_nodeslist(handle, handlecopy) < 0)
    goto cleanup;

  handlecopy->node_index_size = handle->node_index_size;

  __hash_create(handlecopy->node_index,
                handlecopy->node_index_size,
                (hash_key_f)hash_key_string,
                (hash_cmp_f)strcmp,
                NULL);

  if (_genders_copy_fill_node_index(handle, handlecopy) < 0)
    goto cleanup;

  if (_genders_copy_attrvalslist(handle, handlecopy) < 0)
    goto cleanup;

  if (_genders_copy_attrslist(handle, handlecopy) < 0)
    goto cleanup;

  handlecopy->attr_index_size = handle->attr_index_size;
  
  __hash_create(handlecopy->attr_index,
                handlecopy->attr_index_size,
                (hash_key_f)hash_key_string,
                (hash_cmp_f)strcmp,
                (hash_del_f)list_destroy);

  if (_genders_copy_fill_attr_index(handle, handlecopy) < 0)
    goto cleanup;
  
  if (_genders_copy_fill_node_data(handle, handlecopy) < 0)
    goto cleanup;

  /* Create a buffer for value substitutions */
  __xmalloc(handlecopy->valbuf, char *, handlecopy->maxvallen + 1);

  /* attrval_index, attrval_index_attr, and attrval_buflist
   * set/re-created by genders_index_attrvals
   */
  if (handle->attrval_index)
    {
      if (genders_index_attrvals(handlecopy, handle->attrval_index_attr) < 0)
	{
	  handle->errnum = GENDERS_ERR_INTERNAL;
	  goto cleanup;
	}
    }

  handle->errnum = GENDERS_ERR_SUCCESS;
  return handlecopy;

 cleanup:
  if (handlecopy)
    (void)genders_handle_destroy(handlecopy);
  return NULL;
}
static int
query_status(mysql_connection_t *conn)
{
	int rc = 0;
	unsigned int  num_fields;
	unsigned int  num_rows, i;
	uint64_t      errors = 0;
	MYSQL_RES    *res;
	MYSQL_ROW     row;
#if HAVE_LIBGENDERS
	genders_t genders_handle;
	char        **nodes = NULL;
	int           num_nodes = 0;
	switch_error_sum_t switch_error_sum;

	memset(&switch_error_sum, 0, (sizeof switch_error_sum));
#endif

	/* issue the query join for any errors */
	if (QUERY(conn,
			"select pe.SymbolErrors, pe.LinkRecovers,"
			" pe.LinkDowned, pe.RcvErrors, pe.RcvRemotePhysErrors,"
			" pe.RcvSwitchRelayErrors, pe.XmtDiscards,"
			" pe.XmtConstraintErrors, pe.RcvConstraintErrors,"
			" pe.LinkIntegrityErrors, pe.ExcBufOverrunErrors,"
			" pe.VL15Dropped, n.name, pe.port, n.guid"
			" from port_errors as pe,nodes as n where n.guid=pe.guid;")) {
		fprintf(stderr, "Failed to query node errors\n");
		return (1);
	}

	res = mysql_store_result(conn->conn);

	if ((num_fields = mysql_num_fields(res)) != 15) {
		fprintf(stderr, "%s:%d Failed to query status %d != 14\n",
			__FUNCTION__, __LINE__, num_fields);
		rc = 1;
		goto free_res;
	}

	num_rows = mysql_num_rows(res);

#if HAVE_LIBGENDERS
	genders_handle = genders_handle_create();
	if (!genders_handle || genders_load_data(genders_handle, NULL)) {
		fprintf(stderr, "Genders load failed: %s\n", genders_handle ?
			genders_errormsg(genders_handle)
			: "handle creation failed");
		goto genders_open_fail;
	}
#endif

	/* The basic algo is to sum up all the errors and report them together */
	for (i = 0; i < num_rows; i++) {
		char node_desc[65];
		char *node_name = NULL;

		row = mysql_fetch_row(res);

		/* add up all the errors reported. */
		errors = 0;
		errors += COL_TO_UINT64(0);
		errors += COL_TO_UINT64(1);
		errors += COL_TO_UINT64(2);
		errors += COL_TO_UINT64(3);
		errors += COL_TO_UINT64(4);
		errors += COL_TO_UINT64(5);
		errors += COL_TO_UINT64(6);
		errors += COL_TO_UINT64(7);
		errors += COL_TO_UINT64(8);
		errors += COL_TO_UINT64(9);
		errors += COL_TO_UINT64(10);
		errors += COL_TO_UINT64(11);

#if HAVE_LIBGENDERS
		if (sum_fabric_errors && !genders_isnode(genders_handle, row[12])) {
			switch_error_sum.SymbolErrors         += COL_TO_UINT64(0);
			switch_error_sum.LinkRecovers         += COL_TO_UINT64(1);
			switch_error_sum.LinkDowned           += COL_TO_UINT64(2);
			switch_error_sum.RcvErrors            += COL_TO_UINT64(3);
			switch_error_sum.RcvRemotePhysErrors  += COL_TO_UINT64(4);
			switch_error_sum.RcvSwitchRelayErrors += COL_TO_UINT64(5);
			switch_error_sum.XmtDiscards          += COL_TO_UINT64(6);
			switch_error_sum.XmtConstraintErrors  += COL_TO_UINT64(7);
			switch_error_sum.RcvConstraintErrors  += COL_TO_UINT64(8);
			switch_error_sum.LinkIntegrityErrors  += COL_TO_UINT64(9);
			switch_error_sum.ExcBufOverrunErrors  += COL_TO_UINT64(10);
			switch_error_sum.VL15Dropped          += COL_TO_UINT64(11);
		}
#endif

		strncpy(node_desc, row[12], 64);
		node_name = remap_node_name(node_name_map, COL_TO_UINT64(14), node_desc);
		clean_node_name(node_name);
		printf("%s,ibport%s-error_sum,%"PRIuLEAST64"\n",
			node_name, row[13], errors);
		free(node_name);
	}

#if HAVE_LIBGENDERS
	if (sum_fabric_errors) {
		printf("%s,SymbolErrors_sum,%"PRIuLEAST64"\n",
			IB_SWITCH_TOTAL_NODE_NAME,
			switch_error_sum.SymbolErrors);
		printf("%s,SymbolErrors_sum_counter,%"PRIuLEAST64"\n",
			IB_SWITCH_TOTAL_NODE_NAME,
			switch_error_sum.SymbolErrors);

		printf("%s,LinkRecovers_sum,%"PRIuLEAST64"\n",
			IB_SWITCH_TOTAL_NODE_NAME,
			switch_error_sum.LinkRecovers);
		printf("%s,LinkRecovers_sum_counter,%"PRIuLEAST64"\n",
			IB_SWITCH_TOTAL_NODE_NAME,
			switch_error_sum.LinkRecovers);

		printf("%s,LinkDowned_sum,%"PRIuLEAST64"\n",
			IB_SWITCH_TOTAL_NODE_NAME,
			switch_error_sum.LinkDowned);
		printf("%s,LinkDowned_sum_counter,%"PRIuLEAST64"\n",
			IB_SWITCH_TOTAL_NODE_NAME,
			switch_error_sum.LinkDowned);

		printf("%s,RcvErrors_sum,%"PRIuLEAST64"\n",
			IB_SWITCH_TOTAL_NODE_NAME,
			switch_error_sum.RcvErrors);
		printf("%s,RcvErrors_sum_counter,%"PRIuLEAST64"\n",
			IB_SWITCH_TOTAL_NODE_NAME,
			switch_error_sum.RcvErrors);

		printf("%s,RcvRemotePhysErrors_sum,%"PRIuLEAST64"\n",
			IB_SWITCH_TOTAL_NODE_NAME,
			switch_error_sum.RcvRemotePhysErrors);
		printf("%s,RcvRemotePhysErrors_sum_counter,%"PRIuLEAST64"\n",
			IB_SWITCH_TOTAL_NODE_NAME,
			switch_error_sum.RcvRemotePhysErrors);

		printf("%s,RcvSwitchRelayErrors_sum,%"PRIuLEAST64"\n",
			IB_SWITCH_TOTAL_NODE_NAME,
			switch_error_sum.RcvSwitchRelayErrors);
		printf("%s,RcvSwitchRelayErrors_sum_counter,%"PRIuLEAST64"\n",
			IB_SWITCH_TOTAL_NODE_NAME,
			switch_error_sum.RcvSwitchRelayErrors);

		printf("%s,XmtDiscards_sum,%"PRIuLEAST64"\n",
			IB_SWITCH_TOTAL_NODE_NAME,
			switch_error_sum.XmtDiscards);
		printf("%s,XmtDiscards_sum_counter,%"PRIuLEAST64"\n",
			IB_SWITCH_TOTAL_NODE_NAME,
			switch_error_sum.XmtDiscards);

		printf("%s,XmtConstraintErrors_sum,%"PRIuLEAST64"\n",
			IB_SWITCH_TOTAL_NODE_NAME,
			switch_error_sum.XmtConstraintErrors);
		printf("%s,XmtConstraintErrors_sum_counter,%"PRIuLEAST64"\n",
			IB_SWITCH_TOTAL_NODE_NAME,
			switch_error_sum.XmtConstraintErrors);

		printf("%s,RcvConstraintErrors_sum,%"PRIuLEAST64"\n",
			IB_SWITCH_TOTAL_NODE_NAME,
			switch_error_sum.RcvConstraintErrors);
		printf("%s,RcvConstraintErrors_sum_counter,%"PRIuLEAST64"\n",
			IB_SWITCH_TOTAL_NODE_NAME,
			switch_error_sum.RcvConstraintErrors);

		printf("%s,LinkIntegrityErrors_sum,%"PRIuLEAST64"\n",
			IB_SWITCH_TOTAL_NODE_NAME,
			switch_error_sum.LinkIntegrityErrors);
		printf("%s,LinkIntegrityErrors_sum_counter,%"PRIuLEAST64"\n",
			IB_SWITCH_TOTAL_NODE_NAME,
			switch_error_sum.LinkIntegrityErrors);

		printf("%s,ExcBufOverrunErrors_sum,%"PRIuLEAST64"\n",
			IB_SWITCH_TOTAL_NODE_NAME,
			switch_error_sum.ExcBufOverrunErrors);
		printf("%s,ExcBufOverrunErrors_sum_counter,%"PRIuLEAST64"\n",
			IB_SWITCH_TOTAL_NODE_NAME,
			switch_error_sum.ExcBufOverrunErrors);

		printf("%s,VL15Dropped_sum,%"PRIuLEAST64"\n",
			IB_SWITCH_TOTAL_NODE_NAME,
			switch_error_sum.VL15Dropped);
		printf("%s,VL15Dropped_sum_counter,%"PRIuLEAST64"\n",
			IB_SWITCH_TOTAL_NODE_NAME,
			switch_error_sum.VL15Dropped);
	}
genders_open_fail:
	genders_handle_destroy(genders_handle);
#endif

free_res:
	mysql_free_result(res);
	return (rc);
}