Beispiel #1
0
resource_t *
create_child_clone(resource_t * rsc, int sub_id, pe_working_set_t * data_set)
{
    gboolean as_orphan = FALSE;
    char *inc_num = NULL;
    char *inc_max = NULL;
    resource_t *child_rsc = NULL;
    xmlNode *child_copy = NULL;
    clone_variant_data_t *clone_data = NULL;

    get_clone_variant_data(clone_data, rsc);

    CRM_CHECK(clone_data->xml_obj_child != NULL, return FALSE);

    if (sub_id < 0) {
        as_orphan = TRUE;
        sub_id = clone_data->total_clones;
    }
    inc_num = crm_itoa(sub_id);
    inc_max = crm_itoa(clone_data->clone_max);

    child_copy = copy_xml(clone_data->xml_obj_child);

    crm_xml_add(child_copy, XML_RSC_ATTR_INCARNATION, inc_num);

    if (common_unpack(child_copy, &child_rsc, rsc, data_set) == FALSE) {
        pe_err("Failed unpacking resource %s", crm_element_value(child_copy, XML_ATTR_ID));
        child_rsc = NULL;
        goto bail;
    }
/*  child_rsc->globally_unique = rsc->globally_unique; */

    CRM_ASSERT(child_rsc);
    clone_data->total_clones += 1;
    pe_rsc_trace(child_rsc, "Setting clone attributes for: %s", child_rsc->id);
    rsc->children = g_list_append(rsc->children, child_rsc);
    if (as_orphan) {
        mark_as_orphan(child_rsc);
    }

    add_hash_param(child_rsc->meta, XML_RSC_ATTR_INCARNATION_MAX, inc_max);

    print_resource(LOG_DEBUG_3, "Added ", child_rsc, FALSE);

  bail:
    free(inc_num);
    free(inc_max);

    return child_rsc;
}
Beispiel #2
0
gboolean
group_unpack(resource_t * rsc, pe_working_set_t * data_set)
{
    xmlNode *xml_obj = rsc->xml;
    xmlNode *xml_native_rsc = NULL;
    group_variant_data_t *group_data = NULL;
    const char *group_ordered = g_hash_table_lookup(rsc->meta, XML_RSC_ATTR_ORDERED);
    const char *group_colocated = g_hash_table_lookup(rsc->meta, "collocated");
    const char *clone_id = NULL;

    pe_rsc_trace(rsc, "Processing resource %s...", rsc->id);

    group_data = calloc(1, sizeof(group_variant_data_t));
    group_data->num_children = 0;
    group_data->first_child = NULL;
    group_data->last_child = NULL;
    rsc->variant_opaque = group_data;

    group_data->ordered = TRUE;
    group_data->colocated = TRUE;

    if (group_ordered != NULL) {
        crm_str_to_boolean(group_ordered, &(group_data->ordered));
    }
    if (group_colocated != NULL) {
        crm_str_to_boolean(group_colocated, &(group_data->colocated));
    }

    clone_id = crm_element_value(rsc->xml, XML_RSC_ATTR_INCARNATION);

    for (xml_native_rsc = __xml_first_child(xml_obj); xml_native_rsc != NULL;
            xml_native_rsc = __xml_next(xml_native_rsc)) {
        if (crm_str_eq((const char *)xml_native_rsc->name, XML_CIB_TAG_RESOURCE, TRUE)) {
            resource_t *new_rsc = NULL;

            crm_xml_add(xml_native_rsc, XML_RSC_ATTR_INCARNATION, clone_id);
            if (common_unpack(xml_native_rsc, &new_rsc, rsc, data_set) == FALSE) {
                pe_err("Failed unpacking resource %s", crm_element_value(xml_obj, XML_ATTR_ID));
                if (new_rsc != NULL && new_rsc->fns != NULL) {
                    new_rsc->fns->free(new_rsc);
                }
            }

            group_data->num_children++;
            rsc->children = g_list_append(rsc->children, new_rsc);

            if (group_data->first_child == NULL) {
                group_data->first_child = new_rsc;
            }
            group_data->last_child = new_rsc;
            print_resource(LOG_DEBUG_3, "Added ", new_rsc, FALSE);
        }
    }

    if (group_data->num_children == 0) {
#if 0
        /* Bug #1287 */
        crm_config_err("Group %s did not have any children", rsc->id);
        return FALSE;
#else
        crm_config_warn("Group %s did not have any children", rsc->id);
        return TRUE;
#endif
    }

    pe_rsc_trace(rsc, "Added %d children to resource %s...", group_data->num_children, rsc->id);

    return TRUE;
}
Beispiel #3
0
gboolean
group_unpack(resource_t * rsc, pe_working_set_t * data_set)
{
    resource_t *self = NULL;
    xmlNode *xml_obj = rsc->xml;
    xmlNode *xml_self = copy_xml(rsc->xml);
    xmlNode *xml_native_rsc = NULL;
    group_variant_data_t *group_data = NULL;
    const char *group_ordered = g_hash_table_lookup(rsc->meta, XML_RSC_ATTR_ORDERED);
    const char *group_colocated = g_hash_table_lookup(rsc->meta, "collocated");
    const char *clone_id = NULL;

    crm_debug_3("Processing resource %s...", rsc->id);

    crm_malloc0(group_data, sizeof(group_variant_data_t));
    group_data->num_children = 0;
    group_data->self = NULL;
    group_data->first_child = NULL;
    group_data->last_child = NULL;
    rsc->variant_opaque = group_data;

    group_data->ordered = TRUE;
    group_data->colocated = TRUE;

    if (group_ordered != NULL) {
        crm_str_to_boolean(group_ordered, &(group_data->ordered));
    }
    if (group_colocated != NULL) {
        crm_str_to_boolean(group_colocated, &(group_data->colocated));
    }

    /* this is a bit of a hack - but simplifies everything else */
    xmlNodeSetName(xml_self, ((const xmlChar *)XML_CIB_TAG_RESOURCE));
    if (common_unpack(xml_self, &self, NULL, data_set)) {
        group_data->self = self;
        self->restart_type = pe_restart_restart;

    } else {
        crm_log_xml_err(xml_self, "Couldnt unpack dummy child");
        return FALSE;
    }

    clone_id = crm_element_value(rsc->xml, XML_RSC_ATTR_INCARNATION);

    for (xml_native_rsc = __xml_first_child(xml_obj); xml_native_rsc != NULL;
         xml_native_rsc = __xml_next(xml_native_rsc)) {
        if (crm_str_eq((const char *)xml_native_rsc->name, XML_CIB_TAG_RESOURCE, TRUE)) {
            resource_t *new_rsc = NULL;

            crm_xml_add(xml_native_rsc, XML_RSC_ATTR_INCARNATION, clone_id);
            if (common_unpack(xml_native_rsc, &new_rsc, rsc, data_set) == FALSE) {
                pe_err("Failed unpacking resource %s", crm_element_value(xml_obj, XML_ATTR_ID));
                if (new_rsc != NULL && new_rsc->fns != NULL) {
                    new_rsc->fns->free(new_rsc);
                }
            }

            group_data->num_children++;
            rsc->children = g_list_append(rsc->children, new_rsc);

            if (group_data->first_child == NULL) {
                group_data->first_child = new_rsc;
            }
            group_data->last_child = new_rsc;
            print_resource(LOG_DEBUG_3, "Added", new_rsc, FALSE);
        }
    }

    if (group_data->num_children == 0) {
#if 0
        /* Bug #1287 */
        crm_config_err("Group %s did not have any children", rsc->id);
        return FALSE;
#else
        crm_config_warn("Group %s did not have any children", rsc->id);
        return TRUE;
#endif
    }

    crm_debug_3("Added %d children to resource %s...", group_data->num_children, rsc->id);

    return TRUE;
}
Beispiel #4
0
void bench(char* proj, int cache, int image) {
    struct sockaddr_in server;
    struct sockaddr_in client;
    struct hostent h;
    int i, res_len, client_socket;
    common_work_t work;
    void *res_buf;
    unsigned char *image24;
    clock_t ticks1, ticks2, ticks3;
    tfloat t;


    ticks1 = clock();
    tienet_sem_init(&bench_net_sem, 0);

    printf("loading and prepping ...\n");
    /* Camera with no threads */
    util_camera_init(&camera, 1);

    /* Parse Env Data */
    common_db_load(&db, proj);

    /*
     * Hack the environment settings to make it think there is no cache file
     * if the user is generating one, otherwise it never generates one
     */
    if (cache)
	db.env.kdtree_cache_file[0] = 0;

    /* Read the data off disk and pack it */
    app_size = common_pack(&db, &app_data, proj);

    /* Launch a networking thread to do ipc data streaming */
    pthread_create(&bench_thread, NULL, bench_ipc, 0);

    /* Parse the data into memory for rendering */
    /* create a socket */
    if ((client_socket = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
	fprintf(stderr, "unable to create socket, exiting.\n");
	exit(1);
    }

    /* Bind any available port number */
    client.sin_family = AF_INET;
    client.sin_addr.s_addr = htonl(INADDR_ANY);
    client.sin_port = htons(0);

    if (bind(client_socket, (struct sockaddr *)&client, sizeof(client)) < 0) {
	fprintf(stderr, "unable to bind socket, exiting\n");
	exit(1);
    }

    /* Establish ipc connection */
    if (gethostbyname("localhost")) {
	h = gethostbyname("localhost")[0];
    } else {
	fprintf(stderr, "unknown host: %s\n", "localhost");
	exit(1);
    }

    server.sin_family = h.h_addrtype;
    memcpy((char *)&server.sin_addr.s_addr, h.h_addr_list[0], h.h_length);
    server.sin_port = htons(LOCAL_PORT);

    tienet_sem_wait(&bench_net_sem);
    if (connect(client_socket, (struct sockaddr *)&server, sizeof(server)) < 0) {
	fprintf(stderr, "cannot establish connection, exiting.\n");
	exit(1);
    }

    /* stream and unpack the data */
    common_unpack(&db, &tie, &camera, client_socket);
    tie_prep(&tie);

    /* Prep */
    common_env_prep(&db.env);
    util_camera_prep(&camera, &db);

    /* Allocate memory for a frame */
    bench_frame = malloc(4 * sizeof(tfloat) * db.env.img_w * db.env.img_h);
    if (!bench_frame) {
	perror("bench_frame");
	exit(1);
    }
    memset(bench_frame, 0, 4 * sizeof(tfloat) * db.env.img_w * db.env.img_h);

    /* Render an image */
    work.orig_x = 0;
    work.orig_y = 0;
    work.size_x = db.env.img_w;
    work.size_y = db.env.img_h;
    work.format = COMMON_BIT_DEPTH_24;

    printf("rendering ...\n");
    res_buf = NULL;
    ticks2 = clock();
    util_camera_render(&camera, &db, &tie, &work, sizeof(common_work_t), &res_buf, &res_len);
    ticks3 = clock();

    printf("prep   time: %.3f sec\n", (tfloat)(ticks2 - ticks1) / (tfloat)CLOCKS_PER_SEC);
    t = (tfloat)(ticks3 - ticks2) / (tfloat)CLOCKS_PER_SEC;
    printf("render time: %.3f sec\n", t);
    printf("rays /  sec: %d\n", (int)((db.env.img_w * db.env.img_h) / t));
    if (image) {
	image24 = &((unsigned char *)res_buf)[sizeof(common_work_t)];
	util_image_save_ppm("dump.ppm", image24, db.env.img_w, db.env.img_h);
    }

    close(client_socket);

    util_camera_free(&camera);
    free(app_data);
    free(bench_frame);
    common_unpack_free(&db);

    if (cache) {
	void *kdcache;
	unsigned int size;
	FILE *fh;

	tie_kdtree_cache_free(&tie, &kdcache);
	memcpy(&size, kdcache, sizeof(unsigned int));
	printf("saving kd-tree cache: %d bytes\n", size);
	fh = fopen("kdtree.cache", "wb");
	fwrite(kdcache, size, 1, fh);
	fclose(fh);
	free(kdcache);
    }
}