示例#1
0
static void print_graph_node(NODE *node)
{
    int i;
    GRAPH *graph = CAST_TO_GRAPH(node);
    
    printf("\n");
    
    for (i = 0; i < tree_num_children(node); i++)
    {
        HASH_ENTRY *he;
        
        printf("%d ->", i);
        he = find_in_hash(graph->forward, tree_get_child(node, i), sizeof(void *));
        if (he)
        {
            HASH *subhash = he->data;
            HASH_ITERATOR iter;
            for (hash_iterator(subhash, &iter); hash_iterator_valid(&iter); hash_iterator_next(&iter))
            {
                NODE *n = iter.entry->key;
                HASH_ENTRY *he2 = find_in_hash(graph->labels, n, sizeof(void *));
                if (he2)
                    printf(" %d", (int) he2->data);
            }
        }
        printf("\n");
        
        tree_print(tree_get_child(node, i), 2);
    }
}
示例#2
0
void cleanup_graph(FUNCTION *func)
{
    GRAPH *graph = func->graph;
    int i;
    
restart:
    for (i = 2; i < tree_num_children(graph); i++)
    {
        NODE *vertex = tree_get_child(graph, i);
        if (vertex == NULL)
            continue;
        
        if (!find_in_hash(graph->forward, vertex, sizeof(void *))
            || !find_in_hash(graph->backward, vertex, sizeof(void *)))
        {
            //printf("   dead-end: ");
            //tree_print(vertex, 2);
        }
        
        if (tree_is_type(vertex, STMT_PASS))
        {
            HASH *subhash = get_from_hash(graph->forward, vertex, sizeof(void *));
            HASH_ITERATOR iter;
            hash_iterator(subhash, &iter);
            if (hash_iterator_valid(&iter))
            {
                NODE *successor = iter.entry->key;
                EDGE_TYPE type = (EDGE_TYPE) iter.entry->data;
                replace_backward(graph, vertex, successor, type);
                remove_edge(graph, vertex, successor);
                remove_vertex(graph, vertex);
                goto restart;
            }
        }
        else if (tree_is_type(vertex, STMT_JOIN))
        {
            HASH *subhash = get_from_hash(graph->forward, vertex, sizeof(void *));
            if (subhash->num != 1)
                error("Join does not have exactly 1 successor");
            HASH_ITERATOR iter;
            hash_iterator(subhash, &iter);
            if (hash_iterator_valid(&iter))
            {
                NODE *successor = iter.entry->key;
                EDGE_TYPE type = (EDGE_TYPE) iter.entry->data;
                replace_backward(graph, vertex, successor, type);
                remove_edge(graph, vertex, successor);
                remove_vertex(graph, vertex);
                goto restart;
            }
        }
    }
}
示例#3
0
//key, incr, ttl, timestamp
static ERL_NIF_TERM update(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) {

    int ttl=0, timestamp=0, incr=0, next=0;
    CHECK(enif_get_string(env, argv[0], keybuff, KEY_MAX_LEN, ERL_NIF_LATIN1));
    CHECK(enif_get_int(env, argv[1], &incr));
    CHECK(enif_get_int(env, argv[2], &ttl));
    CHECK(enif_get_int(env, argv[3], &timestamp));

    metronome_item * item = find_in_hash(keybuff, timestamp);
    item->ttl = ttl;

    if(item->timestamp + ttl > timestamp) {
        item->value += incr;
        next = item->timestamp + ttl - timestamp;
    } else {
        item->value = incr;
        item->timestamp = timestamp;
        next = ttl;
    }

    //
    return enif_make_tuple3(env,
                            enif_make_atom(env, "ok"),
                            enif_make_int(env, item->value),
                            enif_make_int(env, next)
                           );
}
示例#4
0
/* LINT - not static as fwcadm uses it */
static int
disable_one_sv(char *path)
{
	int setnumber;
	int rc;

	sv_get_maxdevs();
	sv_check_cluster(path);
	sv_cfg_open(CFG_WRLOCK);

	create_cfg_hash();
	if ((setnumber = find_in_hash(path)) != -1) {
		/* remove from kernel */
		if ((rc = disable_dev(path)) == 0) {
			/* remove the cfgline */
			remove_from_cfgfile(path, setnumber);
		} else if (errno == SV_ENODEV) {
			remove_from_cfgfile(path, setnumber);
		}
	} else {
		/* warn the user that we didn't find it in cfg file */
		warn(NULL,
		    gettext("%s was not found in the config storage"), path);
		/* still attempt to remove */
		(void) disable_dev(path);
		rc = 1;
	}
	destroy_hashtable();

	sv_cfg_close();
	return (rc);
}
示例#5
0
char *add_string(MODULE *module, char *str, size_t len)
{
    HASH_ENTRY *he = find_in_hash(module->strings, str, len);
    if (he)
        return he->data;
    
    str = strndup(str, len);
    add_to_hash(module->strings, str, len, str);
    return str;
}
示例#6
0
void remove_vertex(GRAPH *graph, NODE *vertex)
{
    HASH_ENTRY *he = find_in_hash(graph->labels, vertex, sizeof(void *));
    if (!he)
        return;
    
    int label = (int) he->data;
    graph->node.children->items[label] = NULL;
    remove_from_hash(graph->labels, vertex, sizeof(void *));
}
示例#7
0
static void remove_edge1(HASH *hash, NODE *from, NODE *to)
{
    HASH_ENTRY *he = find_in_hash(hash, from, sizeof(void *));
    HASH *subhash;
    if (!he)
        return;
    
    subhash = he->data;
    remove_from_hash(subhash, to, sizeof(void *));
    
    if (subhash->num == 0)
        remove_from_hash(hash, from, sizeof(void *));
}
示例#8
0
static void add_edge1(HASH *hash, NODE *from, NODE *to, EDGE_TYPE type)
{
    HASH_ENTRY *he = find_in_hash(hash, from, sizeof(void *));
    HASH *subhash;
    if (he)
    {
        subhash = he->data;
    }
    else
    {
        subhash = create_hash(10, key_type_direct);
        add_to_hash(hash, from, sizeof(void *), subhash);
    }
    
    add_to_hash(subhash, to, sizeof(void *), (void *) type);
}
示例#9
0
void add_vertex(GRAPH *graph, NODE *vertex)
{
    if (!vertex)
    {
        /* N.B. Vertex positions are sometimes important, so a NULL one still
           needs to occupy a position in the child list. */
        tree_add_child(graph, vertex);
        return;
    }
    
    HASH_ENTRY *he = find_in_hash(graph->labels, vertex, sizeof(void *));
    if (he)
        return;
    
    add_to_hash(graph->labels, vertex, sizeof(void *), (void *) tree_num_children(graph));
    tree_add_child(graph, vertex);
}
示例#10
0
static ERL_NIF_TERM lookup(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) {

    int timestamp=0, next=0, value=0;
    CHECK(enif_get_string(env, argv[0], keybuff, KEY_MAX_LEN, ERL_NIF_LATIN1));
    CHECK(enif_get_int(env, argv[1], &timestamp));

    metronome_item * item = find_in_hash(keybuff, timestamp);

    if(item->timestamp + item->ttl > timestamp) {
        next = item->timestamp + item->ttl - timestamp;
        value = item->value;
    } else {
        next = item->ttl;
        value = 0;
    }

    //
    return enif_make_tuple3(env,
                            enif_make_atom(env, "ok"),
                            enif_make_int(env, value),
                            enif_make_int(env, next)
                           );
}
示例#11
0
void migrate_unpack_elem(void *data, int num_gid_entries, ZOLTAN_ID_PTR elem_gid,
                         int elem_data_size, char *buf, int *ierr)
{
    MESH_INFO_PTR mesh;
    ELEM_INFO *elem, *elem_mig;
    ELEM_INFO *current_elem;
    int *buf_int;
    float *buf_float;
    int size, num_nodes;
    int i, j, idx;
    int proc;
    int gid = num_gid_entries-1;

    if (data == NULL) {
        *ierr = ZOLTAN_FATAL;
        return;
    }
    mesh = (MESH_INFO_PTR) data;
    elem = mesh->elements;
    elem_mig = (ELEM_INFO *) buf;

    MPI_Comm_rank(MPI_COMM_WORLD, &proc);

    idx = find_in_hash(elem_gid[gid]);
    if (idx >= 0)
        idx = New_Elem_Hash_Nodes[idx].localID;
    else {
        Gen_Error(0, "fatal: Unable to locate position for element");
        *ierr = ZOLTAN_FATAL;
        return;
    }

    current_elem = &(elem[idx]);
    /* now put the migrated information into the array */
    *current_elem = *elem_mig;
    num_nodes = mesh->eb_nnodes[current_elem->elem_blk];

    size = sizeof(ELEM_INFO);

    /*
     * copy the allocated integer fields for this element.
     */

    /* Pad the buffer so the following casts will work.  */
    size = Zoltan_Align(size);
    buf_int = (int *) (buf + size);

    /* copy the connect table */
    if (mesh->num_dims > 0) {
        current_elem->connect = (int *) malloc(num_nodes * sizeof(int));
        if (current_elem->connect == NULL) {
            Gen_Error(0, "fatal: insufficient memory");
            *ierr = ZOLTAN_MEMERR;
            return;
        }
        for (i = 0; i < num_nodes; i++) {
            current_elem->connect[i] = *buf_int;
            buf_int++;
        }
        size += num_nodes * sizeof(int);
    }

    /* copy the adjacency info */
    /* globalIDs are received; convert to local IDs when adj elem is local */
    if (current_elem->adj_len > 0) {
        current_elem->adj      = (int *)malloc(current_elem->adj_len * sizeof(int));
        current_elem->adj_proc = (int *)malloc(current_elem->adj_len * sizeof(int));
        if (current_elem->adj == NULL || current_elem->adj_proc == NULL) {
            Gen_Error(0, "fatal: insufficient memory");
            *ierr = ZOLTAN_MEMERR;
            return;
        }
        for (i =  0; i < current_elem->adj_len; i++) {
            current_elem->adj[i] = *buf_int;
            buf_int++;
            current_elem->adj_proc[i] = *buf_int;
            buf_int++;
            if (current_elem->adj[i] != -1 && current_elem->adj_proc[i] == proc) {
                int idx = find_in_hash(current_elem->adj[i]);
                if (idx >= 0)
                    current_elem->adj[i] = New_Elem_Hash_Nodes[idx].localID;
                else {
                    Gen_Error(0, "fatal: Unable to locate position for neighbor");
                    *ierr = ZOLTAN_FATAL;
                    return;
                }
            }
        }
        size += current_elem->adj_len * 2 * sizeof(int);

        /* copy the edge_wgt data */
        if (Use_Edge_Wgts) {

            /* Pad the buffer so the following casts will work.  */
            size = Zoltan_Align(size);
            buf_float = (float *) (buf + size);

            current_elem->edge_wgt = (float *) malloc(current_elem->adj_len
                                     * sizeof(float));
            if (current_elem->edge_wgt == NULL) {
                Gen_Error(0, "fatal: insufficient memory");
                *ierr = ZOLTAN_MEMERR;
                return;
            }
            for (i = 0; i < current_elem->adj_len; i++) {
                current_elem->edge_wgt[i] = *buf_float;
                buf_float++;
            }
            size += current_elem->adj_len * sizeof(float);
        }
    }

    /* copy coordinate data */
    if (num_nodes > 0) {

        /* Pad the buffer so the following casts will work.  */
        size = Zoltan_Align(size);
        buf_float = (float *) (buf + size);

        current_elem->coord = (float **) malloc(num_nodes * sizeof(float *));
        if (current_elem->coord == NULL) {
            Gen_Error(0, "fatal: insufficient memory");
            *ierr = ZOLTAN_MEMERR;
            return;
        }
        for (i = 0; i < num_nodes; i++) {
            current_elem->coord[i] = (float *) malloc(mesh->num_dims * sizeof(float));
            if (current_elem->coord[i] == NULL) {
                Gen_Error(0, "fatal: insufficient memory");
                *ierr = ZOLTAN_MEMERR;
                return;
            }
            for (j = 0; j < mesh->num_dims; j++) {
                current_elem->coord[i][j] = *buf_float;
                buf_float++;
            }
        }
        size += num_nodes * mesh->num_dims * sizeof(float);
    }


    /* and update the Mesh struct */
    mesh->num_elems++;
    mesh->eb_cnts[current_elem->elem_blk]++;

    if (size > elem_data_size)
        *ierr = ZOLTAN_WARN;
    else
        *ierr = ZOLTAN_OK;
}
示例#12
0
void migrate_pre_process(void *data, int num_gid_entries, int num_lid_entries,
                         int num_import,
                         ZOLTAN_ID_PTR import_global_ids,
                         ZOLTAN_ID_PTR import_local_ids, int *import_procs,
                         int *import_to_part,
                         int num_export, ZOLTAN_ID_PTR export_global_ids,
                         ZOLTAN_ID_PTR export_local_ids, int *export_procs,
                         int *export_to_part,
                         int *ierr)
{
    int i, j, k, idx, maxlen, proc, offset;
    int *proc_ids = NULL;   /* Temp array of processor assignments for elements.*/
    char *change = NULL;    /* Temp array indicating whether local element's adj
                           list must be updated due to a nbor's migration.  */
    int new_proc;           /* New processor assignment for nbor element.       */
    int exp_elem;           /* index of an element being exported */
    int bor_elem;           /* index of an element along the processor border */
    int *send_vec = NULL, *recv_vec = NULL;  /* Communication vecs. */
    MESH_INFO_PTR mesh;
    ELEM_INFO_PTR elements;
    int lid = num_lid_entries-1;
    int gid = num_gid_entries-1;
    char msg[256];

    *ierr = ZOLTAN_OK;

    if (data == NULL) {
        *ierr = ZOLTAN_FATAL;
        return;
    }
    mesh = (MESH_INFO_PTR) data;
    elements = mesh->elements;

    for (i=0; i < mesh->num_elems; i++) {
        /* don't migrate a pointer created on this process */
        safe_free((void **)(void *)&(elements[i].adj_blank));
    }

    /*
     *  Set some flags. Assume if true for one element, true for all elements.
     *  Note that some procs may have no elements.
     */

    if (elements[0].edge_wgt != NULL)
        k = 1;
    else
        k = 0;
    /* Make sure all procs have the same value */
    MPI_Allreduce(&k, &Use_Edge_Wgts, 1, MPI_INT, MPI_MAX, MPI_COMM_WORLD);

    /* NOT IMPLEMENTED: blanking information is not sent along.  Subsequent
       lb_eval may be incorrect, since imported elements may have blanked
       adjacencies.

    if (mesh->blank_count > 0)
      k = 1;
    else
      k = 0;

    MPI_Allreduce(&k, &Vertex_Blanking, 1, MPI_INT, MPI_MAX, MPI_COMM_WORLD);

    */

    /*
     *  For all elements, update adjacent elements' processor information.
     *  That way, when perform migration, will be migrating updated adjacency
     *  information.
     */

    MPI_Comm_rank(MPI_COMM_WORLD, &proc);

    /*
     *  Build New_Elem_Index array and list of processor assignments.
     */

    New_Elem_Index_Size = mesh->num_elems + num_import - num_export;
    if (mesh->elem_array_len > New_Elem_Index_Size)
        New_Elem_Index_Size = mesh->elem_array_len;
    New_Elem_Index = (int *) malloc(New_Elem_Index_Size * sizeof(int));
    New_Elem_Hash_Table = (int *) malloc(New_Elem_Index_Size * sizeof(int));
    New_Elem_Hash_Nodes = (struct New_Elem_Hash_Node *)
                          malloc(New_Elem_Index_Size * sizeof(struct New_Elem_Hash_Node));

    if (New_Elem_Index == NULL ||
            New_Elem_Hash_Table == NULL || New_Elem_Hash_Nodes == NULL) {
        Gen_Error(0, "fatal: insufficient memory");
        *ierr = ZOLTAN_MEMERR;
        return;
    }

    for (i = 0; i < New_Elem_Index_Size; i++)
        New_Elem_Hash_Table[i] = -1;
    for (i = 0; i < New_Elem_Index_Size; i++) {
        New_Elem_Hash_Nodes[i].globalID = -1;
        New_Elem_Hash_Nodes[i].localID = -1;
        New_Elem_Hash_Nodes[i].next = -1;
    }

    if (mesh->num_elems > 0) {

        proc_ids = (int *)  malloc(mesh->num_elems * sizeof(int));
        change   = (char *) malloc(mesh->num_elems * sizeof(char));

        if (New_Elem_Index == NULL || proc_ids == NULL || change == NULL ||
                New_Elem_Hash_Table == NULL || New_Elem_Hash_Nodes == NULL) {
            Gen_Error(0, "fatal: insufficient memory");
            *ierr = ZOLTAN_MEMERR;
            return;
        }

        for (i = 0; i < mesh->num_elems; i++) {
            New_Elem_Index[i] = elements[i].globalID;
            insert_in_hash(elements[i].globalID, i);
            proc_ids[i] = proc;
            change[i] = 0;
        }
    }

    for (i = mesh->num_elems; i < New_Elem_Index_Size; i++) {
        New_Elem_Index[i] = -1;
    }

    for (i = 0; i < num_export; i++) {
        if (num_lid_entries)
            exp_elem = export_local_ids[lid+i*num_lid_entries];
        else  /* testing num_lid_entries == 0 */
            search_by_global_id(mesh, export_global_ids[gid+i*num_gid_entries],
                                &exp_elem);

        if (export_procs[i] != proc) {
            /* Export is moving to a new processor */
            New_Elem_Index[exp_elem] = -1;
            remove_from_hash(export_global_ids[gid+i*num_gid_entries]);
            proc_ids[exp_elem] = export_procs[i];
        }
    }

    j = 0;
    for (i = 0; i < num_import; i++) {
        if (import_procs[i] != proc) {
            /* Import is moving from a new processor, not just from a new partition */
            /* search for first free location */
            for ( ; j < New_Elem_Index_Size; j++)
                if (New_Elem_Index[j] == -1) break;

            New_Elem_Index[j] = import_global_ids[gid+i*num_gid_entries];
            insert_in_hash((int) import_global_ids[gid+i*num_gid_entries], j);
        }
    }

    /*
     * Update local information
     */

    /* Set change flag for elements whose adjacent elements are being exported */

    for (i = 0; i < num_export; i++) {

        if (num_lid_entries)
            exp_elem = export_local_ids[lid+i*num_lid_entries];
        else  /* testing num_lid_entries == 0 */
            search_by_global_id(mesh, export_global_ids[gid+i*num_gid_entries],
                                &exp_elem);

        elements[exp_elem].my_part = export_to_part[i];

        if (export_procs[i] == proc)
            continue;  /* No adjacency changes needed if export is changing
                    only partition, not processor. */

        for (j = 0; j < elements[exp_elem].adj_len; j++) {

            /* Skip NULL adjacencies (sides that are not adjacent to another elem). */
            if (elements[exp_elem].adj[j] == -1) continue;

            /* Set change flag for adjacent local elements. */
            if (elements[exp_elem].adj_proc[j] == proc) {
                change[elements[exp_elem].adj[j]] = 1;
            }
        }
    }

    /* Change adjacency information in marked elements */
    for (i = 0; i < mesh->num_elems; i++) {
        if (change[i] == 0) continue;

        /* loop over marked element's adjacencies; look for ones that are moving */
        for (j = 0; j < elements[i].adj_len; j++) {

            /* Skip NULL adjacencies (sides that are not adjacent to another elem). */
            if (elements[i].adj[j] == -1) continue;

            if (elements[i].adj_proc[j] == proc) {
                /* adjacent element is local; check whether it is moving. */
                if ((new_proc = proc_ids[elements[i].adj[j]]) != proc) {
                    /* Adjacent element is being exported; update this adjacency entry */
                    elements[i].adj[j] = elements[elements[i].adj[j]].globalID;
                    elements[i].adj_proc[j] = new_proc;
                }
            }
        }
    }
    safe_free((void **)(void *) &change);

    /*
     * Update off-processor information
     */

    maxlen = 0;
    for (i = 0; i < mesh->necmap; i++)
        maxlen += mesh->ecmap_cnt[i];

    if (maxlen > 0) {
        send_vec = (int *) malloc(maxlen * sizeof(int));
        if (send_vec == NULL) {
            Gen_Error(0, "fatal: insufficient memory");
            *ierr = ZOLTAN_MEMERR;
            return;
        }

        /* Load send vector */

        for (i = 0; i < maxlen; i++)
            send_vec[i] = proc_ids[mesh->ecmap_elemids[i]];
    }

    safe_free((void **)(void *) &proc_ids);

    if (maxlen > 0)
        recv_vec = (int *) malloc(maxlen * sizeof(int));

    /*  Perform boundary exchange */

    boundary_exchange(mesh, 1, send_vec, recv_vec);

    /* Unload receive vector */

    offset = 0;
    for (i = 0; i < mesh->necmap; i++) {
        for (j = 0; j < mesh->ecmap_cnt[i]; j++, offset++) {
            if (recv_vec[offset] == mesh->ecmap_id[i]) {
                /* off-processor element is not changing processors.  */
                /* no changes are needed in the local data structure. */
                continue;
            }
            /* Change processor assignment in local element's adjacency list */
            bor_elem = mesh->ecmap_elemids[offset];
            for (k = 0; k < elements[bor_elem].adj_len; k++) {

                /* Skip NULL adjacencies (sides that are not adj to another elem). */
                if (elements[bor_elem].adj[k] == -1) continue;

                if (elements[bor_elem].adj[k] == mesh->ecmap_neighids[offset] &&
                        elements[bor_elem].adj_proc[k] == mesh->ecmap_id[i]) {
                    elements[bor_elem].adj_proc[k] = recv_vec[offset];
                    if (recv_vec[offset] == proc) {
                        /* element is moving to this processor; */
                        /* convert adj from global to local ID. */
                        idx = find_in_hash(mesh->ecmap_neighids[offset]);
                        if (idx >= 0)
                            idx = New_Elem_Hash_Nodes[idx].localID;
                        else {
                            sprintf(msg, "fatal: unable to locate element %d in "
                                    "New_Elem_Index", mesh->ecmap_neighids[offset]);
                            Gen_Error(0, msg);
                            *ierr = ZOLTAN_FATAL;
                            return;
                        }
                        elements[bor_elem].adj[k] = idx;
                    }
                    break;  /* from k loop */
                }
            }
        }
    }

    safe_free((void **)(void *) &recv_vec);
    safe_free((void **)(void *) &send_vec);

    /*
     * Allocate space (if needed) for the new element data.
     */

    if (mesh->elem_array_len < New_Elem_Index_Size) {
        mesh->elem_array_len = New_Elem_Index_Size;
        mesh->elements = (ELEM_INFO_PTR) realloc (mesh->elements,
                         mesh->elem_array_len * sizeof(ELEM_INFO));
        if (mesh->elements == NULL) {
            Gen_Error(0, "fatal: insufficient memory");
            return;
        }

        /* initialize the new spots */
        for (i = mesh->num_elems; i < mesh->elem_array_len; i++)
            initialize_element(&(mesh->elements[i]));
    }
}
示例#13
0
/* LINT - not static as fwcadm uses it */
static void
print_sv(int verbose)
{
	sv_name_t *svn, *svn_system;	/* Devices in system */
	sv_list_t svl_system;
	int fd, i;
	int setnumber;

	sv_check_cluster(NULL);
	sv_cfg_open(CFG_RDLOCK);

	svn_system = sv_alloc_svnames();

	if ((fd = open(sv_rpath, O_RDONLY)) < 0) {
		(void) printf(gettext("unable to open %s: %s"),
			sv_rpath, strerror(errno));
		return;
	}

	/* Grab the system list from the driver */
	svl_system.svl_count = sv_max_devices;
	svl_system.svl_names = &svn_system[0];
	svl_system.svl_error = spcs_s_ucreate();

	if (ioctl(fd, SVIOC_LIST, &svl_system) < 0) {
		error(&svl_system.svl_error, gettext("unable to get list"));
	}

	spcs_s_ufree(&svl_system.svl_error);
	(void) close(fd);

	/*
	 * We build a hashmap out of the entries from the config file to make
	 * searching faster. We end up taking a performance hit when the # of
	 * volumes is small, but for larger configurations it's a
	 * HUGE improvement.
	 */

	/* build the hashtable */
	cfg_rewind(cfg, CFG_SEC_CONF);
	create_cfg_hash();

	/*
	 * For each volume found from the kernel, print out
	 * info about it from the kernel.
	 */
	for (i = 0; i < svl_system.svl_count; i++) {
		if (*svn_system[i].svn_path == '\0') {
			break;
		}

		svn = &svn_system[i];
		if (svn->svn_mode == 0) {
#ifdef DEBUG
			(void) printf(gettext("%s [kernel guard]\n"),
			    svn->svn_path);
#endif
			continue;
		}
		/* get sv entry from the hashtable */
		if ((setnumber = find_in_hash(svn->svn_path)) != -1) {
			(void) printf("%-*s", STATWIDTH, svn->svn_path);

			if (verbose) {
				print_cluster_tag(setnumber);
			}

			(void) printf("\n");

		} else {
			/*
			 * We didn't find the entry in the hashtable.  Let
			 * the user know that the persistent storage is
			 * inconsistent with the kernel configuration.
			 */
			if (cfg_cluster_tag == NULL)
				warn(NULL, gettext(
					"%s is configured, but not in the "
					"config storage"), svn->svn_path);
		}
	}

	/* free up the hashtable */
	destroy_hashtable();

	sv_cfg_close();
}
示例#14
0
/* LINT - not static as fwcadm uses it */
static void
compare_sv(char *conf_file)
{
	sv_name_t *svn_config;		/* Devices in config file */
	sv_name_t *svn_system;		/* Devices in system */
	sv_name_t *enable;		/* Devices that need enabled */
	sv_list_t svl_system;
	int config_cnt;
	int sys_cnt = 0;
	int setnumber, i, j;
	int index = 0;	/* Index in enable[] */
	int found;
	int fd0;

	svn_config = sv_alloc_svnames();
	svn_system = sv_alloc_svnames();
	enable = sv_alloc_svnames();

	bzero(svn_system, sizeof (svn_system));
	bzero(&svl_system, sizeof (svl_system));
	bzero(enable, sizeof (enable));

	/*
	 * Read the configuration file
	 * The return value is the number of entries
	 */
	config_cnt = read_config_file(conf_file, svn_config);

	if ((fd0 = open(sv_rpath, O_RDONLY)) < 0)
		error(NULL, gettext("unable to open %s: %s"),
			sv_rpath, strerror(errno));

	/* Grab the system list from the driver */
	svl_system.svl_count = sv_max_devices;
	svl_system.svl_names = &svn_system[0];
	svl_system.svl_error = spcs_s_ucreate();

	if (ioctl(fd0, SVIOC_LIST, &svl_system) < 0) {
		error(&svl_system.svl_error, gettext("unable to get list"));
	}

	spcs_s_ufree(&svl_system.svl_error);
	(void) close(fd0);

	/*
	 * Count the number of devices in the system.
	 * The last entry in the array has '\0' for a path name.
	 */
	for (j = 0; j < sv_max_devices; j++) {
		if (svn_system[j].svn_path[0] != '\0') {
			sys_cnt++;
		} else {
			break;
		}
	}
	/*
	 * Compare the configuration array with the system array.
	 * Mark any differences and disable conflicting devices.
	 */
	for (i = 0; i < config_cnt; i++) {
		found = 0;
		for (j = 0; j < sys_cnt; j++) {
			if (svn_system[j].svn_path[0] == '\0' ||
			    svn_system[j].svn_mode == 0)
				continue;

			/*  Check to see if path matches */
			if (strcmp(svn_system[j].svn_path,
			    svn_config[i].svn_path) == 0) {
				/*  Found a match  */
				svn_system[j].svn_path[0] = '\0';
				found++;
				break;
			}
		}

		if (!found) {
			/* Minor number not in system  = > enable device */
			enable[index].svn_mode = svn_config[i].svn_mode;
			(void) strcpy(enable[index].svn_path,
			    svn_config[i].svn_path);
			index++;
		}
	}

	/* Disable any devices that weren't in the config file */
	for (j = 0; j < sys_cnt; j++) {
		sv_check_cluster(NULL);
		sv_cfg_open(CFG_WRLOCK);
		create_cfg_hash();
		if (svn_system[j].svn_path[0] != '\0' &&
		    svn_system[j].svn_mode != 0) {
			(void) printf(gettext("%s: disabling sv: %s\n"),
			    program, svn_system[j].svn_path);
			if (disable_dev(svn_system[j].svn_path) == 0) {
				setnumber =
					find_in_hash(svn_system[j].svn_path);
				if (setnumber != -1) {
					/* the volume was found in cfg store */
					remove_from_cfgfile(
					svn_system[j].svn_path, setnumber);
				}
			}
		}
		sv_cfg_close();
		destroy_hashtable();
	}

	while (index) {
		/*
		 * Config file doesn't match system => enable the devices
		 * in enable[]
		 */
		index--;
		(void) printf(gettext("%s: enabling new sv: %s\n"),
		    program, enable[index].svn_path);
		(void) enable_dev(&enable[index]);
	}

	/*
	 * Search for entries where the cluster tag has changed.
	 */
	sv_check_cluster(NULL);
	sv_cfg_open(CFG_WRLOCK);

	for (i = 0; i < sv_max_devices; i++) {
		if (svn_config[i].svn_path[0] == '\0')
			break;

		compare_tag(svn_config[i].svn_path);
	}

	sv_cfg_close();
}
示例#15
0
/* LINT - not static as fwcadm uses it */
static int
disable_sv(char *conf_file)
{
	sv_name_t *svn, *svn_system;	/* Devices in system */
	sv_list_t svl_system;
	int fd, i, setnumber;
	int rc, ret;

	svn_system = sv_alloc_svnames();

	rc = ret = 0;

	if (conf_file == NULL) {
		if ((fd = open(sv_rpath, O_RDONLY)) < 0) {
			(void) printf(gettext("unable to open %s: %s"),
				sv_rpath, strerror(errno));
			return (1);
		}

		/* Grab the system list from the driver */
		svl_system.svl_count = sv_max_devices;
		svl_system.svl_names = &svn_system[0];
		svl_system.svl_error = spcs_s_ucreate();

		if (ioctl(fd, SVIOC_LIST, &svl_system) < 0) {
			error(&(svl_system.svl_error),
					gettext("unable to get list"));
		}

		spcs_s_ufree(&(svl_system.svl_error));
		(void) close(fd);
	} else {
		svl_system.svl_count = read_config_file(conf_file, svn_system);
	}


	for (i = 0; i < svl_system.svl_count; i++) {
		if (*svn_system[i].svn_path == '\0')
			break;

		svn = &svn_system[i];

		sv_check_cluster(svn->svn_path);
		sv_cfg_open(CFG_WRLOCK);
		create_cfg_hash();
		rc = 0;
		if ((setnumber = find_in_hash(svn->svn_path)) != -1) {
			if ((rc = disable_dev(svn->svn_path)) != -1) {
				remove_from_cfgfile(svn->svn_path, setnumber);
			} else if (errno == SV_ENODEV) {
				remove_from_cfgfile(svn->svn_path, setnumber);
			}
		} else {
			/* warn the user that we didn't find it in cfg file */
			warn(NULL, gettext(
				"%s was not found in the config storage"),
				svn->svn_path);
			/* try to disable anyway */
			(void) disable_dev(svn->svn_path);
			rc = 1;
		}

		sv_cfg_close();
		destroy_hashtable();

		if (rc && !ret)
			ret = rc;
	}

	return (ret);
}
示例#16
0
int emit_function(FUNCTION *func, EMIT_FUNCTIONS *functions, void *data)
{
    GRAPH *graph = func->graph;
    
    QUEUE *queue = create_queue();
    HASH *done = create_hash(10, key_type_direct);
    
    queue_push(queue, tree_get_child(graph, 0));
    
    NODE *last = NULL;
    while (!queue_is_empty(queue))
    {
        NODE *vertex = queue_pop(queue);
        
        if (find_in_hash(done, vertex, sizeof(void *)))
            continue;
        
do_next:
        add_to_hash(done, vertex, sizeof(void *), (void *) 1);
        int label = (int) get_from_hash(graph->labels, vertex, sizeof(void *));
        HASH *predecessor_hash = get_from_hash(graph->backward, vertex, sizeof(void *));
        HASH_ITERATOR iter;
        hash_iterator(predecessor_hash, &iter);
        if (predecessor_hash && (predecessor_hash->num > 1 || (predecessor_hash->num == 1 && last != iter.entry->key)))
        {
            functions->emit_label(label, data);
        }
        functions->emit_comment(vertex, data);
        
        HASH *successor_hash = get_from_hash(graph->forward, vertex, sizeof(void *));
        NODE *successor;
        int successor_label;
        if (successor_hash)
        {
            hash_iterator(successor_hash, &iter);
            successor = iter.entry->key;
            successor_label = (int) get_from_hash(graph->labels, successor, sizeof(void *));
        }
        else
            successor = NULL;
        
        if (tree_is_type(vertex, STMT_ENTER))
        {
            functions->emit_enter(vertex, data);
        }
        else if (tree_is_type(vertex, STMT_EXIT))
        {
            functions->emit_exit(vertex, data);
            last = vertex;
            continue;
        }
        else if (tree_is_type(vertex, STMT_ASSIGN))
            functions->emit_assign(vertex, data);
        else if (tree_is_type(vertex, STMT_RETURN))
            functions->emit_return(vertex, data);
        else if (tree_is_type(vertex, STMT_TEST))
        {
            hash_iterator_next(&iter);
            NODE *branch = iter.entry->key;
            EDGE_TYPE branch_type = (EDGE_TYPE) iter.entry->data;
            int branch_label = (int) get_from_hash(graph->labels, branch, sizeof(void *));
            
            functions->emit_test(vertex, branch_type, branch_label, data);
            if (!find_in_hash(done, branch, sizeof(void *)))
                queue_push(queue, branch);
            
            /* Force label on next vertex, in case we jumped to it in the test's branch.
               Fixes a bug where the label is omitted just because the test was before it,
                by neglecting to notice that the test reaches it by a jump. */
            vertex = NULL;
        }
        last = vertex;
        if (find_in_hash(done, successor, sizeof(void *)))
        {
            functions->emit_jump(successor_label, data);
            continue;
        }
        vertex = successor;
        if (vertex)
            goto do_next;
    }
    
    functions->emit_end(data);
    
    destroy_queue(queue);
    destroy_hash(done);
    
    return 1;
}
示例#17
0
void print_expression(EXPRESSION *expr, DAA_SET *set)
{
    if (expr == NULL)
    {
        printf("?null?");
    }
    else if (tree_is_type(expr, EXPR_VARIABLE))
    {
        VARIABLE *var = CAST_TO_VARIABLE(expr);
        int defined = !set || find_in_hash(set->set, var->name, strlen(var->name));
        if (set)
            printf("<font color=\"%s\">", get_colour(var->decl->colour));
        printf("%s", var->name);
        if (set)
            printf("</font>");
    }
    else if (tree_is_type(expr, EXPR_INTEGER))
    {
        INTEGER *integer = CAST_TO_INTEGER(expr);
        printf("%d", integer->value);
    }
    else if (tree_is_type(expr, EXPR_STRING))
    {
        STRING *str = CAST_TO_STRING(expr);
        printf("\"%s\"", str->value);
    }
    else if (tree_is_type(expr, EXPR_TUPLE))
    {
        printf("(");
        if (tree_num_children(expr) >= 1)
        {
            print_expression(tree_get_child(expr, 0), set);
        }
        int i;
        for (i = 1; i < tree_num_children(expr); i++)
        {
            printf(", ");
            print_expression(tree_get_child(expr, i), set);
        }
        printf(")");
    }
    else if (is_unary_op(expr))
    {
        printf("%s", get_escaped_op_symbol(expr));
        print_expression(tree_get_child(expr, 0), set);
    }
    else if (is_binary_op(expr))
    {
        print_expression(tree_get_child(expr, 0), set);
        printf(" %s ", get_escaped_op_symbol(expr));
        print_expression(tree_get_child(expr, 1), set);
    }
    else if (tree_is_type(expr, STMT_ASSIGN))
    {
        printf("assign ");
        print_expression(tree_get_child(expr, 0), set);
        printf(" = ");
        print_expression(tree_get_child(expr, 1), set);
    }
    else if (tree_is_type(expr, STMT_TEST))
    {
        printf("test ");
        print_expression(tree_get_child(expr, 0), set);
    }
    else if (tree_is_type(expr, EXPR_CALL))
    {
        VARIABLE *var = tree_get_child(expr, 0);
        printf("%s(", var->name);
        print_expression(tree_get_child(expr, 1), set);
        printf(")");
    }
    else if (tree_is_type(expr, STMT_RETURN))
    {
        printf("return ");
        print_expression(tree_get_child(expr, 0), set);
    }
    else if (tree_is_type(expr, STMT_ENTER))
    {
        printf("enter");
    }
    else if (tree_is_type(expr, STMT_EXIT))
    {
        printf("exit");
    }
    else
    {
        printf("?expr %p %s?", expr, tree_get_name(expr));
    }
}
示例#18
0
void print_graph(GRAPH *graph, char *name, void *data)
{
    int i;
    
    graph_sequence++;
    
    printf("subgraph cluster_%s_%d {\n", name, graph_sequence);
    printf("    label=\"%s\"; labelloc=\"t\";\n", name);
    printf("    ranksep=0.1\n");
    printf("    node [shape=\"box\", style=\"filled\"];\n");
    
    /* Vertices. */
    for (i = 0; i < tree_num_children(graph); i++)
    {
        NODE *vertex = tree_get_child(graph, i);
        if (vertex == NULL)
            continue;
        
        if (combine_bb && !tree_is_type(vertex, DEF_VARIABLE) && get_bb_next(graph, vertex, 2))
            continue;
        
        printf("    %s_%d_%d [label=<<table border=\"0\">\n", name, graph_sequence, i);
        printf("<tr><td>%d. ", i);
        vertex_printer(vertex, data);
        printf("</td></tr>\n");
        
        if (combine_bb && !tree_is_type(vertex, DEF_VARIABLE))
        {
            NODE *next_vertex = get_bb_next(graph, vertex, 1);
            while (next_vertex)
            {
                vertex = next_vertex;
                int pos = (int) get_from_hash(graph->labels, vertex, sizeof(void *));
                printf("<tr><td>%d. ", pos);
                vertex_printer(vertex, data);
                printf("</td></tr>\n");
                next_vertex = get_bb_next(graph, vertex, 1);
            }
        }
        
        printf("</table>>");
        if (tree_is_type(vertex, DEF_VARIABLE))
        {
            DECLARATION *decl = CAST_TO_DECLARATION(vertex);
            printf(", fillcolor=%s", get_colour(decl->colour));
        }
        printf("];\n");
        
        HASH_ENTRY *he;
        NODE *from = vertex;
        
        he = find_in_hash(graph->forward, from, sizeof(void *));
        if (he)
        {
            HASH *subhash = he->data;
            HASH_ITERATOR iter;
            for (hash_iterator(subhash, &iter); hash_iterator_valid(&iter); hash_iterator_next(&iter))
            {
                NODE *to = iter.entry->key;
                HASH_ENTRY *he2 = find_in_hash(graph->labels, to, sizeof(void *));
                if (he2)
                {
                    EDGE_TYPE type = (EDGE_TYPE) iter.entry->data;
                    if (type == EDGE_SYMMETRICAL)
                        continue;
                    printf("    %s_%d_%d -> %s_%d_%d [label=<", name, graph_sequence, i, name, graph_sequence, (int) he2->data);
                    if (type & EDGE_YES)
                        printf("Y");
                    if (type & EDGE_NO)
                        printf("N");
                    if (type & EDGE_BACK)
                        printf("B");
                    if (type & EDGE_LOOP)
                        printf("L");
                    edge_printer(from, to, data);
                    printf(">];\n");
                }
            }
        }
    }
    printf("}\n");
}