Exemple #1
0
int path_lookup(
    TROVE_coll_id coll_id,
    TROVE_context_id trove_context,
    char *path,
    TROVE_handle * out_handle_p)
{
    int ret, count;
    TROVE_ds_state state;
    TROVE_keyval_s key, val;
    TROVE_op_id op_id;
    TROVE_handle handle;

    /* get root */
    key.buffer = ROOT_HANDLE_KEYSTR;
    key.buffer_sz = ROOT_HANDLE_KEYLEN;
    val.buffer = &handle;
    val.buffer_sz = sizeof(handle);

    ret = trove_collection_geteattr(coll_id, &key, &val, 0,
				    NULL, trove_context, &op_id);
    while (ret == 0)
	ret =
	    trove_dspace_test(coll_id, op_id, trove_context, &count, NULL, NULL,
			      &state, TROVE_DEFAULT_TEST_TIMEOUT);
    if (ret < 0)
    {
	fprintf(stderr, "collection geteattr (for root handle) failed.\n");
	return -1;
    }

    /* TODO: handle more than just a root handle! */

    *out_handle_p = handle;
    return 0;
}
Exemple #2
0
static int print_dspace_keyvals(TROVE_coll_id coll_id,
				TROVE_handle handle,
                                TROVE_context_id trove_context,
				TROVE_ds_type type)
{
    int ret, count;
    TROVE_ds_position pos;
    TROVE_keyval_s key, val;
    TROVE_op_id op_id;
    TROVE_ds_state state;

    key.buffer    = malloc(65536);
    key.buffer_sz = 65536;
    val.buffer    = malloc(65536);
    val.buffer_sz = 65536;

    pos = TROVE_ITERATE_START;
    count = 1;

    while (count > 0) {
	int opcount;
	ret = trove_keyval_iterate(coll_id,
				   handle,
				   &pos,
				   &key,
				   &val,
				   &count,
				   0 /* flags */,
				   NULL /* vtag */,
				   NULL /* user ptr */,
                                   trove_context,
				   &op_id, NULL);

	while (ret == 0) ret = trove_dspace_test(
            coll_id, op_id, trove_context, &opcount, NULL, NULL, &state,
            TROVE_DEFAULT_TEST_TIMEOUT);
	if (ret != 1) return -1;

	if (count > 0) print_keyval_pair(&key, &val, type, 65536);
    }

    free(key.buffer);
    free(val.buffer);

    return 0;
}
Exemple #3
0
static int print_dspaces(TROVE_coll_id coll_id,
			 TROVE_handle root_handle,
                         TROVE_context_id trove_context,
			 int no_root_handle)
{
    int ret, count;
    TROVE_ds_position pos;
    TROVE_handle harray[64];
    TROVE_op_id op_id;
    TROVE_ds_state state;

    pos = TROVE_ITERATE_START;
    count = 64;

    while (count > 0) {
	int opcount;

	ret = trove_dspace_iterate_handles(coll_id,
					   &pos,
					   harray,
					   &count,
					   0 /* flags */,
					   NULL /* vtag */,
					   NULL /* user ptr */,
                                           trove_context,
					   &op_id);
	while (ret == 0) ret = trove_dspace_test(
            coll_id, op_id, trove_context, &opcount, NULL, NULL, &state,
            TROVE_DEFAULT_TEST_TIMEOUT);
	if (ret != 1) return -1;

	if (count > 0) {
	    int i;
	    for (i = 0; i < count; i++) {
		ret = print_dspace(coll_id, harray[i], trove_context);
	    }
	}
    }

    return 0;
}
Exemple #4
0
static int print_dspace(TROVE_coll_id coll_id,
			TROVE_handle handle,
                        TROVE_context_id trove_context)
{
    int ret, opcount;
    TROVE_ds_attributes_s ds_attr;
    TROVE_op_id op_id;
    TROVE_ds_state state;

    ret = trove_dspace_getattr(coll_id,
			       handle,
			       &ds_attr,
			       0 /* flags */,
			       NULL /* user ptr */,
                               trove_context,
			       &op_id, NULL);
    while (ret == 0) {
	ret = trove_dspace_test(
            coll_id, op_id, trove_context, &opcount, NULL, NULL, &state,
            TROVE_DEFAULT_TEST_TIMEOUT);
    }
    if (ret != 1) return -1;
		
    fprintf(stdout,
	    "\t0x%08llx (dspace_getattr output: type = %s, b_size = %lld)\n",
	    llu(handle),
	    type_to_string(ds_attr.type),
	    lld(ds_attr.u.datafile.b_size));

    if (print_keyvals) {
	ret = print_dspace_keyvals(coll_id, handle,
                                   trove_context, ds_attr.type);
	if (ret != 0) return -1;
    }

    return 0;
}
Exemple #5
0
int main(
    int argc,
    char **argv)
{
    int ret = -1;
    int outcount = 0, count;
    struct BMI_unexpected_info request_info;
    flow_descriptor *flow_d = NULL;
    double time1, time2;
    int i;
    PINT_Request *req;
    char path_name[PATH_SIZE];
    TROVE_op_id op_id;
    TROVE_coll_id coll_id;
    TROVE_handle file_handle, parent_handle;
    TROVE_ds_state state;
    char *file_name;
    TROVE_keyval_s key, val;
    bmi_context_id context;
    TROVE_context_id trove_context;
    PVFS_handle_extent cur_extent;
    PVFS_handle_extent_array extent_array;

	/*************************************************************/
    /* initialization stuff */

    /* set debugging level */
    gossip_enable_stderr();
    gossip_set_debug_mask(0, GOSSIP_FLOW_PROTO_DEBUG | GOSSIP_BMI_DEBUG_TCP );

    /* start up BMI */
    ret = BMI_initialize("bmi_tcp", "tcp://NULL:3335", BMI_INIT_SERVER);
    if (ret < 0)
    {
	fprintf(stderr, "BMI init failure.\n");
	return (-1);
    }

    ret = BMI_open_context(&context);
    if (ret < 0)
    {
	fprintf(stderr, "BMI_open_context() failure.\n");
	return (-1);
    }

    ret = trove_initialize(
        TROVE_METHOD_DBPF, NULL, storage_space, 0);
    if (ret < 0)
    {
	fprintf(stderr, "initialize failed: run trove-mkfs first.\n");
	return -1;
    }

    /* initialize the flow interface. protocol specific */
    ret = PINT_flow_initialize("flowproto_bmi_cache", 0);
    if (ret < 0)
    {
	fprintf(stderr, "flow init failure.\n");
	return (-1);
    }

    /* try to look up collection used to store file system */
    ret = trove_collection_lookup(
        TROVE_METHOD_DBPF, file_system, &coll_id, NULL, &op_id);
    if (ret < 0)
    {
	fprintf(stderr, "collection lookup failed.\n");
	return -1;
    }

    ret = trove_open_context(coll_id, &trove_context);
    if (ret < 0)
    {
	fprintf(stderr, "TROVE_open_context() failure.\n");
	return (-1);
    }

    /* find the parent directory name */
    strcpy(path_name, path_to_file);
    for (i = strlen(path_name); i >= 0; i--)
    {
	if (path_name[i] != '/')
	    path_name[i] = '\0';
	else
	    break;
    }
    file_name = path_to_file + strlen(path_name);
    printf("path is %s\n", path_name);
    printf("file is %s\n", file_name);

    /* find the parent directory handle */
    ret = path_lookup(coll_id, trove_context, path_name, &parent_handle);
    if (ret < 0)
    {
	return -1;
    }

    file_handle = 0;

    cur_extent.first = cur_extent.last = requested_file_handle;
    extent_array.extent_count = 1;
    extent_array.extent_array = &cur_extent;
    ret = trove_dspace_create(coll_id,
			      &extent_array,
			      &file_handle,
			      TROVE_TEST_FILE,
			      NULL, 
				TROVE_FORCE_REQUESTED_HANDLE,
				NULL, trove_context, &op_id, NULL);
    while (ret == 0)
	ret =
	    trove_dspace_test(coll_id, op_id, trove_context, &count, NULL, NULL,
			      &state, TROVE_DEFAULT_TEST_TIMEOUT);
    if (ret < 0)
    {
	fprintf(stderr, "dspace create failed.\n");
	return -1;
    }

    /* TODO: set attributes of file? */

    /* add new file name/handle pair to parent directory */
    key.buffer = file_name;
    key.buffer_sz = strlen(file_name) + 1;
    val.buffer = &file_handle;
    val.buffer_sz = sizeof(file_handle);
    ret =
	trove_keyval_write(coll_id, parent_handle, &key, &val, 0, NULL, NULL,
			   trove_context, &op_id, NULL);
    while (ret == 0)
	ret =
	    trove_dspace_test(coll_id, op_id, trove_context, &count, NULL, NULL,
			      &state, TROVE_DEFAULT_TEST_TIMEOUT);
    if (ret < 0)
    {
	fprintf(stderr, "keyval write failed.\n");
	return -1;
    }


    /* wait for an initial communication via BMI */
    /* we don't give a crap about that message except that it tells us
     * where to find the client 
     */
    do
    {
	ret = BMI_testunexpected(1, &outcount, &request_info, 10);
    } while (ret == 0 && outcount == 0);
    if (ret < 0 || request_info.error_code != 0)
    {
	fprintf(stderr, "waitunexpected failure.\n");
	return (-1);
    }
    BMI_unexpected_free(request_info.addr, request_info.buffer);

	/******************************************************/
    /* setup request/dist stuff */

    /* request description */
    /* just want one contiguous region */
    ret = PVFS_Request_contiguous(TEST_SIZE, PVFS_BYTE, &req);
    if (ret < 0)
    {
	fprintf(stderr, "PVFS_Request_contiguous() failure.\n");
	return (-1);
    }


	/******************************************************/
    /* setup communicaton stuff */

    /* create a flow descriptor */
    flow_d = PINT_flow_alloc();
    if (!flow_d)
    {
	fprintf(stderr, "flow_alloc failed.\n");
	return (-1);
    }

    /* file data */
    flow_d->file_data.fsize = TEST_SIZE;
    flow_d->file_data.server_nr = 0;
    flow_d->file_data.server_ct = 1;
    flow_d->file_data.extend_flag = 1;
    flow_d->file_data.dist = PINT_dist_create("basic_dist");
    if (!flow_d->file_data.dist)
    {
	fprintf(stderr, "Error: failed to create dist.\n");
	return (-1);
    }
    ret = PINT_dist_lookup(flow_d->file_data.dist);
    if (ret != 0)
    {
	fprintf(stderr, "Error: failed to lookup dist.\n");
	return (-1);
    }
    flow_d->file_req = req;
    flow_d->tag = 0;
    flow_d->user_ptr = NULL;
    flow_d->aggregate_size = TEST_SIZE;

    /* fill in flow details */
    flow_d->src.endpoint_id = BMI_ENDPOINT;
    flow_d->src.u.bmi.address = request_info.addr;
    flow_d->dest.endpoint_id = TROVE_ENDPOINT;
    flow_d->dest.u.trove.handle = file_handle;
    flow_d->dest.u.trove.coll_id = coll_id;

	/***************************************************
	 * test bmi to file (analogous to a client side write)
	 */

    time1 = Wtime();
    ret = block_on_flow(flow_d);
    if (ret < 0)
    {
	return (-1);
    }
    time2 = Wtime();

#if 0
    printf("Server bw (recv): %f MB/sec\n",
	   ((TEST_SIZE) / ((time2 - time1) * 1000000.0)));
#endif

	/*******************************************************/
    /* final cleanup and output */

    PINT_flow_free(flow_d);

    /* shut down flow interface */
    ret = PINT_flow_finalize();
    if (ret < 0)
    {
	fprintf(stderr, "flow finalize failure.\n");
	return (-1);
    }

    /* shut down BMI */
    BMI_close_context(context);
    BMI_finalize();

    trove_close_context(coll_id, trove_context);
    trove_finalize(TROVE_METHOD_DBPF);

    gossip_disable();
    return (0);
}
Exemple #6
0
/* trove_check_handle_ranges:
 *  internal function to verify that handles
 *  on disk match our assigned handles.
 *  this function is *very* expensive.
 *
 * coll_id: id of collection which we will verify
 * extent_list: llist of legal handle ranges/extents
 * ledger: a book-keeping ledger object
 *
 * returns 0 on success; -1 otherwise
 */
static int trove_check_handle_ranges(TROVE_coll_id coll_id,
                                     TROVE_context_id context_id,
                                     PINT_llist *extent_list,
                                     struct handle_ledger *ledger)
{
    int ret = -1, i = 0, count = 0, op_count = 0;
    TROVE_op_id op_id = 0;
    TROVE_ds_state state = 0;
    TROVE_ds_position pos = TROVE_ITERATE_START;
    static TROVE_handle handles[MAX_NUM_VERIFY_HANDLE_COUNT] =
        {TROVE_HANDLE_NULL};

    if (extent_list && ledger)
    {
        count = MAX_NUM_VERIFY_HANDLE_COUNT;

        while(count > 0)
        {
            ret = trove_dspace_iterate_handles(coll_id,&pos,handles,
                                               &count,0,NULL,NULL,
                                               context_id,&op_id);
            while(ret == 0)
            {
                ret = trove_dspace_test(coll_id,op_id,context_id,
                                        &op_count,NULL,NULL,&state,
                                        TROVE_DEFAULT_TEST_TIMEOUT);
            }

            /* check result of testing */
            if (ret < 0)
            {
                gossip_debug(GOSSIP_TROVE_DEBUG,
                             "dspace test of iterate_handles failed\n");
                return ret;
            }

            ret = 0;

            /* also check result of actual operation, in this case,
             * trove_dspace_iterate_handles
             */
            if(state < 0)
            {
                gossip_debug(GOSSIP_TROVE_DEBUG,
                             "trove_dspace_iterate_handles failed\n");
                return state;
            }

            /* look for special case of a blank fs */
            if ((count == 1) && (handles[0] == 0))
            {
                gossip_debug(GOSSIP_TROVE_DEBUG,
                             "* Trove: Assuming a blank filesystem\n");
                return ret;
            }

            if (count > 0)
            {
                for(i = 0; i != count; i++)
                {
                    /* check every item in our range list */
                    if (!PINT_handle_in_extent_list(extent_list,
                                                    handles[i]))
                    {
                        gossip_err(
                            "Error: handle %llu is invalid "
                            "(out of bounds)\n", llu(handles[i]));
                        return -1;
                    }

		    /* remove handle from trove-handle-mgmt */
		    ret = trove_handle_remove(ledger, handles[i]);
		    if (ret != 0)
                    {
			gossip_err(
                            "WARNING: could not remove "
                            "handle %llu from ledger; continuing.\n", llu(handles[i]));
		    }
                }
                ret = ((i == count) ? 0 : -1);
            }
        }
    }
    return ret;
}
Exemple #7
0
int main(int argc, char **argv)	
{
	int ret = -1;
	int count;
	char *mybuffer, *verify_buffer;
	int i;
	char path_name[PATH_SIZE];
	TROVE_op_id op_id;
	TROVE_coll_id coll_id;
	TROVE_handle file_handle, parent_handle;
	TROVE_ds_state state;
	char *file_name;
	TROVE_keyval_s key, val;
        TROVE_context_id trove_context = -1;

	char *mem_offset_array[2] = {0};
	TROVE_size mem_size_array[2] = { 10*MB, 10*MB };
	int mem_count = 2;
	TROVE_offset stream_offset_array[4] = {0, 5*MB, 10*MB, 15*MB};
	TROVE_size stream_size_array[4] = { 5*MB, 5*MB, 5*MB, 5*MB };
	int stream_count = 4;
	TROVE_size output_size;
	void *user_ptr_array[1] = { (char *) 13 };
        int test_failed = 0;

        TROVE_extent cur_extent;
        TROVE_handle_extent_array extent_array;

	/*************************************************************/
	/* initialization stuff */

	ret = trove_initialize(
	    TROVE_METHOD_DBPF, NULL, storage_space, storage_space, 0);
	if (ret < 0) {
	    fprintf(stderr, "initialize failed: run trove-mkfs first.\n");
	    return -1;
	}

	/* try to look up collection used to store file system */
	ret = trove_collection_lookup(
	    TROVE_METHOD_DBPF, file_system, &coll_id, NULL, &op_id);
	if (ret < 0) {
	    fprintf(stderr, "collection lookup failed.\n");
	    return -1;
	}

        ret = trove_open_context(coll_id, &trove_context);
        if (ret < 0)
        {
            fprintf(stderr, "trove_open_context failed\n");
            return -1;
        }

	/* find the parent directory name */
	strcpy(path_name, path_to_file);
	for (i=strlen(path_name); i >= 0; i--) {
	    if (path_name[i] != '/') path_name[i] = '\0';
	    else break;
	}
	file_name = path_to_file + strlen(path_name);
	printf("path is %s\n", path_name);
	printf("file is %s\n", file_name);

        /* find the parent directory handle */
	ret = path_lookup(coll_id, trove_context, path_name, &parent_handle);
	if (ret < 0) {
	    return -1;
	}

	file_handle = 0;

        cur_extent.first = cur_extent.last = requested_file_handle;
        extent_array.extent_count = 1;
        extent_array.extent_array = &cur_extent;
	ret = trove_dspace_create(coll_id,
                                  &extent_array,
				  &file_handle,
				  TROVE_TEST_FILE,
				  NULL,
				  TROVE_FORCE_REQUESTED_HANDLE,
				  NULL,
                                  trove_context,
				  &op_id,
                                  NULL);
	while (ret == 0) ret = trove_dspace_test(
            coll_id, op_id, trove_context, &count, NULL, NULL, &state,
            TROVE_DEFAULT_TEST_TIMEOUT);
	if (ret < 0) {
	    fprintf(stderr, "dspace create failed.\n");
	    return -1;
	}

	/* TODO: set attributes of file? */

	/* add new file name/handle pair to parent directory */
	key.buffer = file_name;
	key.buffer_sz = strlen(file_name) + 1;
	val.buffer = &file_handle;
	val.buffer_sz = sizeof(file_handle);
	ret = trove_keyval_write(coll_id, parent_handle, &key, &val,
                                 0, NULL, NULL, trove_context, &op_id, NULL);
	while (ret == 0) ret = trove_dspace_test(
            coll_id, op_id, trove_context, &count, NULL, NULL, &state,
            TROVE_DEFAULT_TEST_TIMEOUT);
	if (ret < 0) {
	    fprintf(stderr, "keyval write failed.\n");
	    return -1;
	}

	/* memory buffer to xfer */
	mybuffer = (char *)malloc(TEST_SIZE);
	if (!mybuffer)
	{
            fprintf(stderr, "mem.\n");
            return(-1);
	}
	verify_buffer = (char *)malloc(TEST_SIZE);
	if (!verify_buffer)
	{
            fprintf(stderr, "mem.\n");
            return(-1);
	}

	mem_offset_array[0] = mybuffer;
	mem_offset_array[1] = (mem_offset_array[0] + 10*MB);

        memset(mem_offset_array[0], 0xFE, 10*MB);
        memset(mem_offset_array[1], 0xFD, 10*MB);

	/********************************/

	ret = trove_bstream_write_list(coll_id,
				       parent_handle,
				       mem_offset_array,
				       mem_size_array,
				       mem_count,
				       stream_offset_array,
				       stream_size_array,
				       stream_count,
				       &output_size,
				       0, /* flags */
				       NULL, /* vtag */
				       user_ptr_array,
                                       trove_context,
				       &op_id,
                                       NULL);
	while (ret == 0) ret = trove_dspace_test(
            coll_id, op_id, trove_context, &count, NULL, NULL, &state,
            TROVE_DEFAULT_TEST_TIMEOUT);
	if (ret < 0) {
	    fprintf(stderr, "listio write failed\n");
	    return -1;
	}

	mem_offset_array[0] = verify_buffer;
	mem_offset_array[1] = (mem_offset_array[0] + 10*MB);

        memset(mem_offset_array[0], 0xDE, 10*MB);
        memset(mem_offset_array[1], 0xDD, 10*MB);

        /* should read this back out and verify here */
	ret = trove_bstream_read_list(coll_id,
                                      parent_handle,
                                      mem_offset_array,
                                      mem_size_array,
                                      mem_count,
                                      stream_offset_array,
                                      stream_size_array,
                                      stream_count,
                                      &output_size,
                                      0, /* flags */
                                      NULL, /* vtag */
                                      user_ptr_array,
                                      trove_context,
                                      &op_id,
                                      NULL);
	while (ret == 0) ret = trove_dspace_test(
            coll_id, op_id, trove_context, &count, NULL, NULL, &state,
            TROVE_DEFAULT_TEST_TIMEOUT);
	if (ret < 0)
        {
	    fprintf(stderr, "listio read failed\n");
	    return -1;
	}

        for(i = 0; i < TEST_SIZE; i++)
        {
            if (mybuffer[i] != verify_buffer[i])
            {
                fprintf(stderr,"data mismatch at index %d (%x != %x)\n",
                        i,mybuffer[i],verify_buffer[i]);
                test_failed = 1;
                break;
            }
/*             fprintf(stderr,"data match at index %d (%x == %x)\n", */
/*                     i,mybuffer[i],verify_buffer[i]); */
        }

        free(mybuffer);
        free(verify_buffer);

        fprintf(stderr,"This bstream listio test %s\n",
                (test_failed ? "failed miserably" : "passed"));

        trove_close_context(coll_id, trove_context);
	trove_finalize(TROVE_METHOD_DBPF);
	return 0;
}
/**
 * Migrates collection xattrs from a 0.0.1 DBPF collection
 * \return 0 on succes, -1 on failure
 */
static int translate_coll_eattr_0_0_1(
    char* old_coll_path,            /**< path to old trove collection */
    TROVE_coll_id coll_id,          /**< collection id in string format */
    char* coll_name,                /**< name of collection */
    TROVE_context_id trove_context) /**< open trove context */                
{
    int ret = -1;
    char coll_db[PATH_MAX];
    DB *dbp;
    DBT key, data;
    DBC *dbc_p = NULL;
    TROVE_keyval_s t_key;
    TROVE_keyval_s t_val;
    TROVE_op_id op_id;
    int count = 0;
    TROVE_ds_state state;

    sprintf(coll_db, "%s/collection_attributes.db", old_coll_path);
    ret = db_create(&dbp, NULL, 0);
    if(ret != 0)
    {
        fprintf(stderr, "Error: db_create: %s.\n", db_strerror(ret));
        return(-1);
    }
    
    /* open collection_attributes.db from old collection */
    ret = dbp->open(dbp,
#ifdef HAVE_TXNID_PARAMETER_TO_DB_OPEN
                    NULL,
#endif
                    coll_db,
                    NULL,
                    DB_UNKNOWN,
                    0,
                    0);
    if(ret != 0)
    {
        fprintf(stderr, "Error: dbp->open: %s.\n", db_strerror(ret));
        return(-1);
    }

    ret = dbp->cursor(dbp, NULL, &dbc_p, 0);
    if (ret != 0)
    {
        fprintf(stderr, "Error: dbp->cursor: %s.\n", db_strerror(ret));
        dbp->close(dbp, 0);
        return(-1);
    }

    memset(&key, 0, sizeof(key));
    key.data = malloc(DEF_KEY_SIZE);
    if(!key.data)
    {
        perror("malloc");    
        dbc_p->c_close(dbc_p);
        dbp->close(dbp, 0);
        return(-1);
    }
    key.size = key.ulen = DEF_KEY_SIZE;
    key.flags |= DB_DBT_USERMEM;

    memset(&data, 0, sizeof(data));
    data.data = malloc(DEF_DATA_SIZE);
    if(!data.data)
    {
        perror("malloc");    
        free(key.data);
        dbc_p->c_close(dbc_p);
        dbp->close(dbp, 0);
        return(-1);
    }
    data.size = data.ulen = DEF_DATA_SIZE;
    data.flags |= DB_DBT_USERMEM;

    do
    {
        /* iterate through eattr's on the old collection */
        ret = dbc_p->c_get(dbc_p, &key, &data, DB_NEXT);
        if (ret != DB_NOTFOUND && ret != 0)
        {
            fprintf(stderr, "Error: dbc_p->c_get: %s.\n", db_strerror(ret));
            free(data.data);
            free(key.data);
            dbc_p->c_close(dbc_p);
            dbp->close(dbp, 0);
            return(-1);
        }
        /* skip the version attribute- we don't want to copy that one */
        if(ret == 0 && strncmp(key.data, "trove-dbpf-version", 
                               strlen("trove-dbpf-version")) != 0)
        {
            if(verbose) printf("VERBOSE Migrating collection eattr: %s\n", (char*)key.data);

            memset(&t_key, 0, sizeof(t_key));
            memset(&t_val, 0, sizeof(t_val));
            t_key.buffer = key.data;
            t_key.buffer_sz = key.size;
            t_val.buffer = data.data;
            t_val.buffer_sz = data.size;

            /* write out new eattr's */
            state = 0;
            ret = trove_collection_seteattr(
                coll_id,
                &t_key,
                &t_val,
                0,
                NULL,
                trove_context,
                &op_id);
            while (ret == 0)
            {
                ret = trove_dspace_test(
                    coll_id, op_id, trove_context, &count, NULL, NULL,
                    &state, 10);
            }
            if ((ret < 0) || (ret == 1 && state != 0))
            {
                fprintf(stderr, "Error: trove_collection_seteattr failure.\n");
                free(data.data);
                free(key.data);
                dbc_p->c_close(dbc_p);
                dbp->close(dbp, 0);
                return -1; 
            }   
        }
    }while(ret != DB_NOTFOUND);

    free(data.data);
    free(key.data);
    dbc_p->c_close(dbc_p);
    dbp->close(dbp, 0);

    return(0);
}
/**
 * Migrates a single keyval db from a 0.0.1 DBPF collection
 * \return 0 on succes, -1 on failure
 */
static int translate_keyval_db_0_0_1(
    TROVE_coll_id coll_id,          /**< collection id */
    char* full_db_path,             /**< fully resolved path to db file */
    TROVE_handle handle,            /**< handle of the object */
    char* coll_name,                /**< name of collection */
    TROVE_context_id trove_context) /**< open trove context */                
{
    int ret = -1;
    DB *dbp;
    DBT key, data;
    DBC *dbc_p = NULL;
    TROVE_op_id op_id;
    int count = 0;
    TROVE_ds_state state;
    TROVE_keyval_s t_key;
    TROVE_keyval_s t_val;

    if(verbose) 
        printf("VERBOSE Migrating keyvals for handle: %llu\n", llu(handle));

    ret = db_create(&dbp, NULL, 0);
    if(ret != 0)
    {
        fprintf(stderr, "Error: db_create: %s.\n", db_strerror(ret));
        return(-1);
    }
     
    ret = dbp->open(dbp,
#ifdef HAVE_TXNID_PARAMETER_TO_DB_OPEN
                    NULL,
#endif
                    full_db_path,
                    NULL,
                    DB_UNKNOWN,
                    0,
                    0);
    if(ret != 0)
    {
        fprintf(stderr, "Error: dbp->open: %s.\n", db_strerror(ret));
        return(-1);
    }

    ret = dbp->cursor(dbp, NULL, &dbc_p, 0);
    if (ret != 0)
    {
        fprintf(stderr, "Error: dbp->cursor: %s.\n", db_strerror(ret));
        dbp->close(dbp, 0);
        return(-1);
    }

    memset(&key, 0, sizeof(key));
    key.data = malloc(DEF_KEY_SIZE);
    if(!key.data)
    {
        perror("malloc");    
        dbc_p->c_close(dbc_p);
        dbp->close(dbp, 0);
        return(-1);
    }
    key.size = key.ulen = DEF_KEY_SIZE;
    key.flags |= DB_DBT_USERMEM;

    memset(&data, 0, sizeof(data));
    data.data = malloc(DEF_DATA_SIZE);
    if(!data.data)
    {
        perror("malloc");    
        free(key.data);
        dbc_p->c_close(dbc_p);
        dbp->close(dbp, 0);
        return(-1);
    }
    data.size = data.ulen = DEF_DATA_SIZE;
    data.flags |= DB_DBT_USERMEM;

    do
    {
        /* iterate through keys in the old keyval db */
        ret = dbc_p->c_get(dbc_p, &key, &data, DB_NEXT);
        if (ret != DB_NOTFOUND && ret != 0)
        {
            fprintf(stderr, "Error: dbc_p->c_get: %s.\n", db_strerror(ret));
            free(data.data);
            free(key.data);
            dbc_p->c_close(dbc_p);
            dbp->close(dbp, 0);
            return(-1);
        }
        if(ret == 0)
        {
            int tvalbuf_free = 0;
            PVFS_ds_flags trove_flags = TROVE_SYNC;
            memset(&t_key, 0, sizeof(t_key));
            memset(&t_val, 0, sizeof(t_val));
            if(translate_keyval_key_0_0_1(&t_key, &key) < 0)
            {
                /* assume its a component name of a directory entry */
                t_key.buffer = key.data;
                t_key.buffer_sz = key.size;
		t_val.buffer = data.data;
		t_val.buffer_sz = data.size;
                trove_flags |= TROVE_KEYVAL_HANDLE_COUNT;
                trove_flags |= TROVE_NOOVERWRITE;
            }
            else if(!strncmp(t_key.buffer, "md", 2)) /* metafile_dist */
            {
                PINT_dist *newdist;
                newdist = data.data;
                
                ret = translate_dist_0_0_1(newdist);
                if(ret != 0)
                {
                    free(data.data);
                    free(key.data);
                    dbc_p->c_close(dbc_p);
                    dbp->close(dbp, 0);
                    return(-1);
                }
                
                t_val.buffer_sz = PINT_DIST_PACK_SIZE(newdist);
                t_val.buffer = malloc(t_val.buffer_sz);
                if(!t_val.buffer)
                {
                    fprintf(stderr, "Error: trove_keyval_write failure.\n");
                    free(data.data);
                    free(key.data);
                    dbc_p->c_close(dbc_p);
                    dbp->close(dbp, 0);
                    return -1; 
                }
                tvalbuf_free = 1;

                PINT_dist_encode(t_val.buffer, newdist);
            } 
            else
            {
                t_val.buffer = data.data;
                t_val.buffer_sz = data.size;
            }
           
            /* write out new keyval pair */
            state = 0;
            ret = trove_keyval_write(
                coll_id, handle, &t_key, &t_val, trove_flags, 0, NULL,
                trove_context, &op_id, NULL);

            while (ret == 0)
            {   
                ret = trove_dspace_test(
                    coll_id, op_id, trove_context, &count, NULL, NULL,
                    &state, 10);
            }
            
            if(tvalbuf_free)
            {
                tvalbuf_free = 0;
                free(t_val.buffer);
            }

            if ((ret < 0) || (ret == 1 && state != 0))
            {
                fprintf(stderr, "Error: trove_keyval_write failure.\n");
                free(data.data);
                free(key.data);
                dbc_p->c_close(dbc_p);
                dbp->close(dbp, 0);
                return -1; 
            }
        }
    }while(ret != DB_NOTFOUND);

    free(data.data);
    free(key.data);
    dbc_p->c_close(dbc_p);
    dbp->close(dbp, 0);

    return(0);
}
/**
 * Migrates dspace attrs from a 0.0.1 DBPF collection
 * \return 0 on succes, -1 on failure
 */
static int translate_dspace_attr_0_0_1(
    char* old_coll_path,            /**< path to old collection */
    TROVE_coll_id coll_id,          /**< collection id */
    char* coll_name,                /**< name of collection */
    TROVE_context_id trove_context) /**< open trove context */                
{
    int ret = -1;
    char attr_db[PATH_MAX];
    DB *dbp;
    DBT key, data;
    DBC *dbc_p = NULL;
    TROVE_op_id op_id;
    int count = 0;
    TROVE_ds_state state;
    TROVE_handle_extent cur_extent;
    TROVE_handle_extent_array extent_array;
    TROVE_handle new_handle;
    TROVE_handle* tmp_handle;
    PVFS_ds_storedattr_0_0_1* tmp_attr;
    TROVE_ds_attributes new_attr;

    sprintf(attr_db, "%s/dataspace_attributes.db", old_coll_path);
    ret = db_create(&dbp, NULL, 0);
    if(ret != 0)
    {
        fprintf(stderr, "Error: db_create: %s.\n", db_strerror(ret));
        return(-1);
    }
    
    /* open dataspace_attributes.db from old collection */
    ret = dbp->open(dbp,
#ifdef HAVE_TXNID_PARAMETER_TO_DB_OPEN
                    NULL,
#endif
                    attr_db,
                    NULL,
                    DB_UNKNOWN,
                    0,
                    0);
    if(ret != 0)
    {
        fprintf(stderr, "Error: dbp->open: %s.\n", db_strerror(ret));
        return(-1);
    }

    ret = dbp->cursor(dbp, NULL, &dbc_p, 0);
    if (ret != 0)
    {
        fprintf(stderr, "Error: dbp->cursor: %s.\n", db_strerror(ret));
        dbp->close(dbp, 0);
        return(-1);
    }

    memset(&key, 0, sizeof(key));
    key.data = malloc(DEF_KEY_SIZE);
    if(!key.data)
    {
        perror("malloc");    
        dbc_p->c_close(dbc_p);
        dbp->close(dbp, 0);
        return(-1);
    }
    key.size = key.ulen = DEF_KEY_SIZE;
    key.flags |= DB_DBT_USERMEM;

    memset(&data, 0, sizeof(data));
    data.data = malloc(DEF_DATA_SIZE);
    if(!data.data)
    {
        perror("malloc");    
        free(key.data);
        dbc_p->c_close(dbc_p);
        dbp->close(dbp, 0);
        return(-1);
    }
    data.size = data.ulen = DEF_DATA_SIZE;
    data.flags |= DB_DBT_USERMEM;

    do
    {
        /* iterate through handles in the old collection */
        ret = dbc_p->c_get(dbc_p, &key, &data, DB_NEXT);
        if (ret != DB_NOTFOUND && ret != 0)
        {
            fprintf(stderr, "Error: dbc_p->c_get: %s.\n", db_strerror(ret));
            free(data.data);
            free(key.data);
            dbc_p->c_close(dbc_p);
            dbp->close(dbp, 0);
            return(-1);
        }
        if(ret == 0)
        {
            tmp_handle = ((PVFS_handle*)key.data);
            tmp_attr = ((PVFS_ds_storedattr_0_0_1*)data.data);

            if(verbose) printf("VERBOSE Migrating attributes for handle: %llu, type: %d\n", 
                llu(*tmp_handle), (int)tmp_attr->type);

            cur_extent.first = cur_extent.last = *tmp_handle;
            extent_array.extent_count = 1;
            extent_array.extent_array = &cur_extent;

            state = 0;
            ret = trove_dspace_create(
                coll_id, &extent_array, &new_handle,
                tmp_attr->type, NULL,
                (TROVE_SYNC | TROVE_FORCE_REQUESTED_HANDLE),
                NULL, trove_context, &op_id, NULL);

            while (ret == 0)
            {
                ret = trove_dspace_test(coll_id, op_id, trove_context,
                                        &count, NULL, NULL, &state,
                                        10);
            }
            if ((ret < 0) || (ret == 1 && state != 0))
            {
                fprintf(stderr, "Error: trove_dspace_create failure.\n");
                free(data.data);
                free(key.data);
                dbc_p->c_close(dbc_p);
                dbp->close(dbp, 0);
                return -1; 
            }
            
            /* convert out of stored format, disregard k_size and b_size
             * (those will be implicitly set later) 
             */
            /* NOTE: we cannot memcpy or use trove_ds_stored_to_attr() macro
             * because the alignment changed after 0.0.1
             */
            new_attr.fs_id = tmp_attr->fs_id;
            new_attr.handle = tmp_attr->handle;
            new_attr.type = tmp_attr->type;
            new_attr.uid = tmp_attr->uid;
            new_attr.gid = tmp_attr->gid;
            new_attr.mode = tmp_attr->mode;
            new_attr.ctime = tmp_attr->ctime;
            new_attr.mtime = tmp_attr->mtime;
            new_attr.atime = tmp_attr->atime;
            new_attr.u.metafile.dfile_count = tmp_attr->dfile_count;
            new_attr.u.metafile.dist_size = tmp_attr->dist_size;
            
            /* write the attributes into the new collection */
            state = 0;
            ret = trove_dspace_setattr(coll_id,
                                       *tmp_handle,
                                       &new_attr,
                                       TROVE_SYNC,
                                       NULL,
                                       trove_context,
                                       &op_id, NULL);
            while (ret == 0)
            {
                ret = trove_dspace_test( 
                    coll_id, op_id, trove_context, &count, NULL, NULL,
                    &state, 10);
            }
            if ((ret < 0) || (ret == 1 && state != 0))
            {
                fprintf(stderr, "Error: trove_dspace_setattr failure.\n");
                free(data.data);
                free(key.data);
                dbc_p->c_close(dbc_p);
                dbp->close(dbp, 0);
                return -1;
            }          
        }
    }while(ret != DB_NOTFOUND);

    free(data.data);
    free(key.data);
    dbc_p->c_close(dbc_p);
    dbp->close(dbp, 0);

    return(0);
}
Exemple #11
0
int main(int argc, char **argv)
{
    int ret, count, no_root_handle = 0;
    TROVE_op_id op_id;
    TROVE_coll_id coll_id;
    TROVE_handle root_handle;
    TROVE_ds_state state;
    TROVE_keyval_s key, val;
    TROVE_context_id trove_context = -1;

    ret = parse_args(argc, argv);
    if (ret < 0) {
	fprintf(stderr,
		"%s: error: argument parsing failed; aborting!\n",
		argv[0]);
	return -1;
    }

    /* initialize trove, verifying storage space exists */
    ret = trove_initialize(
        TROVE_METHOD_DBPF, NULL, storage_space, 0);
    if (ret < 0) 
    {
	fprintf(stderr,
		"%s: error: trove initialize failed; aborting!\n",
		argv[0]);
	return -1;
    }

    if (verbose) fprintf(stderr,
			 "%s: info: initialized with storage space '%s'.\n",
			 argv[0],
			 storage_space);

    /* if no collection was specified, simply print out the collections and exit */
    if (!got_collection) {
	ret = print_collections();
	if (ret != 0) {
	    fprintf(stderr,
		    "%s: error: collection iterate failed; aborting!\n",
		    argv[0]);
	    trove_finalize(TROVE_METHOD_DBPF);
	    return -1;
	}
	trove_finalize(TROVE_METHOD_DBPF);
	return 0;
    }

    /* a collection was specified.
     * - look up the collection
     * - find the root handle (or maybe show all the collection attribs?)
     * - print out information on the dataspaces in the collection
     */

    ret = trove_collection_lookup(TROVE_METHOD_DBPF,
                                  collection,
				  &coll_id,
				  NULL,
				  &op_id);
    if (ret != 1) {
	fprintf(stderr,
		"%s: error: collection lookup failed for collection '%s'; aborting!.\n",
		argv[0],
		collection);
	trove_finalize(TROVE_METHOD_DBPF);
	return -1;
    }

    if (verbose) fprintf(stderr,
			 "%s: info: found collection '%s'.\n",
			 argv[0],
			 collection);


    ret = trove_open_context(coll_id, &trove_context);
    if (ret < 0)
    {
        fprintf(stderr, "trove_open_context failed\n");
        return -1;
    }

    /* find root handle */
    key.buffer = ROOT_HANDLE_KEYSTR;
    key.buffer_sz = ROOT_HANDLE_KEYLEN;
    val.buffer = &root_handle;
    val.buffer_sz = sizeof(root_handle);
    ret = trove_collection_geteattr(coll_id,
				    &key,
				    &val,
				    0,
				    NULL,
                                    trove_context,
				    &op_id);

    while (ret == 0) {
	ret = trove_dspace_test(
            coll_id, op_id, trove_context, &count, NULL, NULL, &state,
            TROVE_DEFAULT_TEST_TIMEOUT);
    }
    if (ret != 1) {
	if (verbose) fprintf(stderr,
			     "%s: warning: collection geteattr (for root handle) failed; aborting!\n",
			     argv[0]);
	no_root_handle = 1;
    }

    /* TODO: NEED ITERATE FOR EATTRS? */

    /* TODO: GET A COUNT OF DATASPACES? */

    /* print basic stats on collection */
    if (no_root_handle) {
	fprintf(stdout,
		"Storage space %s, collection %s (coll_id = %d, "
                "*** no root_handle found ***):\n",
		storage_space,
		collection,
		coll_id);
    }
    else {
	fprintf(stdout,
		"Storage space %s, collection %s (coll_id = %d, "
                "root_handle = 0x%08llx):\n",
		storage_space,
		collection,
		coll_id,
		llu(root_handle));
    }

    if (got_dspace_handle)
    {
        ret = print_dspace(coll_id, dspace_handle, trove_context);
    }
    else
    {
        ret = print_dspaces(coll_id, root_handle,
                            trove_context, no_root_handle);
    }

    trove_close_context(coll_id, trove_context);
    trove_finalize(TROVE_METHOD_DBPF);

    return 0;
}
Exemple #12
0
int main(int argc, char **argv)	
{
	int ret = -1;
	int count;
	void* mybuffer;
	int i;
	char path_name[PATH_SIZE];
	TROVE_op_id op_id;
	TROVE_coll_id coll_id;
	TROVE_handle file_handle, parent_handle;
	TROVE_ds_state state;
	char *file_name;
	TROVE_keyval_s key, val;
        TROVE_context_id trove_context = -1;

	char *mem_offset_array[1];
	TROVE_size mem_size_array[1] = { 4*1048576 };
	int mem_count = 1;
	TROVE_offset stream_offset_array[1] = { 0 };
	TROVE_size stream_size_array[1] = { 4*1048576 };
	int stream_count = 1;
	TROVE_size output_size;
	void *user_ptr_array[1] = { (char *) 13 };

        TROVE_extent cur_extent;
        TROVE_handle_extent_array extent_array;

	/*************************************************************/
	/* initialization stuff */

	ret = trove_initialize(
	    TROVE_METHOD_DBPF, NULL, storage_space, 0);
	if (ret < 0) {
	    fprintf(stderr, "initialize failed: run trove-mkfs first.\n");
	    return -1;
	}

	/* try to look up collection used to store file system */
	ret = trove_collection_lookup(
	    TROVE_METHOD_DBPF, file_system, &coll_id, NULL, &op_id);
	if (ret < 0) {
	    fprintf(stderr, "collection lookup failed.\n");
	    return -1;
	}

        ret = trove_open_context(coll_id, &trove_context);
        if (ret < 0)
        {
            fprintf(stderr, "trove_open_context failed\n");
            return -1;
        }

	/* find the parent directory name */
	strcpy(path_name, path_to_file);
	for (i=strlen(path_name); i >= 0; i--) {
	    if (path_name[i] != '/') path_name[i] = '\0';
	    else break;
	}
	file_name = path_to_file + strlen(path_name);
	printf("path is %s\n", path_name);
	printf("file is %s\n", file_name);

    /* find the parent directory handle */
	ret = path_lookup(coll_id, trove_context, path_name, &parent_handle);
	if (ret < 0) {
	    return -1;
	}

	file_handle = 0;

        cur_extent.first = cur_extent.last = requested_file_handle;
        extent_array.extent_count = 1;
        extent_array.extent_array = &cur_extent;
	ret = trove_dspace_create(coll_id,
                                  &extent_array,
				  &file_handle,
				  TROVE_TEST_FILE,
				  NULL,
				  TROVE_FORCE_REQUESTED_HANDLE,
				  NULL,
                                  trove_context,
				  &op_id,
                                  NULL);
	while (ret == 0) ret = trove_dspace_test(
            coll_id, op_id, trove_context, &count, NULL, NULL, &state,
            TROVE_DEFAULT_TEST_TIMEOUT);
	if (ret < 0) {
	    fprintf(stderr, "dspace create failed.\n");
	    return -1;
	}

	/* TODO: set attributes of file? */

	/* add new file name/handle pair to parent directory */
	key.buffer = file_name;
	key.buffer_sz = strlen(file_name) + 1;
	val.buffer = &file_handle;
	val.buffer_sz = sizeof(file_handle);
	ret = trove_keyval_write(coll_id, parent_handle, &key, &val,
                                 0, NULL, NULL, trove_context, &op_id,
                                 NULL);
	while (ret == 0) ret = trove_dspace_test(
            coll_id, op_id, trove_context, &count, NULL, NULL, &state,
            TROVE_DEFAULT_TEST_TIMEOUT);
	if (ret < 0) {
	    fprintf(stderr, "keyval write failed.\n");
	    return -1;
	}

	/* memory buffer to xfer */
	mybuffer = (void*)malloc(TEST_SIZE);
	if(!mybuffer)
	{
		fprintf(stderr, "mem.\n");
		return(-1);
	}
	memset(mybuffer, 0, TEST_SIZE);

	mem_offset_array[0] = mybuffer;

	/********************************/

	ret = trove_bstream_write_list(coll_id,
				       parent_handle,
				       mem_offset_array,
				       mem_size_array,
				       mem_count,
				       stream_offset_array,
				       stream_size_array,
				       stream_count,
				       &output_size,
				       0, /* flags */
				       NULL, /* vtag */
				       user_ptr_array,
                                       trove_context,
				       &op_id,
                                       NULL);
	while (ret == 0) ret = trove_dspace_test(
            coll_id, op_id, trove_context, &count, NULL, NULL, &state,
            TROVE_DEFAULT_TEST_TIMEOUT);
	if (ret < 0) {
	    fprintf(stderr, "listio write failed\n");
	    return -1;
	}

        trove_close_context(coll_id, trove_context);
	trove_finalize(TROVE_METHOD_DBPF);
	return 0;
}
Exemple #13
0
int main(int argc, char **argv)
{
    int ret, count, i, myuid, mygid;
    TROVE_op_id op_id;
    TROVE_coll_id coll_id;
    TROVE_handle file_handle, parent_handle;
    TROVE_ds_state state;
    TROVE_keyval_s key, val;
    TROVE_ds_attributes_s s_attr;
    char *file_name;
    char path_name[PATH_SIZE];
    time_t mytime;
    TROVE_extent cur_extent;
    TROVE_handle_extent_array extent_array;
    TROVE_context_id trove_context = -1;

    ret = parse_args(argc, argv);
    if (ret < 0) {
	fprintf(stderr, "argument parsing failed.\n");
	return -1;
    }

    ret = trove_initialize(
        TROVE_METHOD_DBPF, NULL, storage_space, 0);
    if (ret < 0) {
	fprintf(stderr, "initialize failed.\n");
	return -1;
    }

    /* try to look up collection used to store file system */
    ret = trove_collection_lookup(
        TROVE_METHOD_DBPF, file_system, &coll_id, NULL, &op_id);
    if (ret < 0) {
	fprintf(stderr, "collection lookup failed.\n");
	return -1;
    }

    ret = trove_open_context(coll_id, &trove_context);
    if (ret < 0)
    {
        fprintf(stderr, "trove_open_context failed\n");
        return -1;
    }

    myuid = getuid();
    mygid = getgid();
    mytime = time(NULL);

    /* find the parent directory name */
    strcpy(path_name, path_to_file);
    for (i=strlen(path_name); i >= 0; i--) {
	if (path_name[i] != '/') path_name[i] = '\0';
	else break;
    }
    file_name = path_to_file + strlen(path_name);
#if 0
    printf("path is %s\n", path_name);
    printf("file is %s\n", file_name);
#endif

    /* find the parent directory handle */
    ret = path_lookup(coll_id, path_name, &parent_handle);
    if (ret < 0) {
	return -1;
    }

    /* TODO: verify that this is in fact a directory! */
    
    for (i=0; i < file_count; i++) {
	char tmp_file_name[PATH_SIZE];
	file_handle = 0;

        cur_extent.first = cur_extent.last = requested_file_handle;
        extent_array.extent_count = 1;
        extent_array.extent_array = &cur_extent;
	ret = trove_dspace_create(coll_id,
                                  &extent_array,
				  &file_handle,
				  TROVE_TEST_FILE,
				  NULL,
				  TROVE_FORCE_REQUESTED_HANDLE,
				  NULL,
                                  trove_context,
				  &op_id,
                                  NULL);
	while (ret == 0) ret = trove_dspace_test(
            coll_id, op_id, trove_context, &count, NULL, NULL, &state,
            TROVE_DEFAULT_TEST_TIMEOUT);
	if (ret < 0) {
	    fprintf(stderr, "dspace create failed.\n");
	    return -1;
	}

	s_attr.fs_id  = coll_id; /* for now */
	s_attr.handle = file_handle;
	s_attr.type   = TROVE_TEST_FILE; /* shouldn't need to fill this one in. */
	s_attr.uid    = myuid;
	s_attr.gid    = mygid;
	s_attr.mode   = 0755;
	s_attr.ctime  = mytime;
	count = 1;

	ret = trove_dspace_setattr(coll_id,
				   file_handle,
				   &s_attr,
				   0 /* flags */,
				   NULL /* user ptr */,
                                   trove_context,
				   &op_id,
                                   NULL);
	while (ret == 0) ret = trove_dspace_test(
            coll_id, op_id, trove_context, &count, NULL, NULL, &state,
            TROVE_DEFAULT_TEST_TIMEOUT);
	if (ret < 0) return -1;

	/* add new file name/handle pair to parent directory */
	snprintf(tmp_file_name, PATH_SIZE, "%s/file%d", path_name, i);
	key.buffer = tmp_file_name;
	key.buffer_sz = strlen(tmp_file_name) + 1;
	val.buffer = &file_handle;
	val.buffer_sz = sizeof(file_handle);

	ret = trove_keyval_write(coll_id, parent_handle, &key, &val,
                                 0, NULL, NULL, trove_context, &op_id, NULL);
	while (ret == 0) ret = trove_dspace_test(
            coll_id, op_id, trove_context, &count, NULL, NULL, &state,
            TROVE_DEFAULT_TEST_TIMEOUT);
	if (ret < 0) {
	    fprintf(stderr, "keyval write failed.\n");
	    return -1;
	}
    }
    
    trove_close_context(coll_id, trove_context);
    trove_finalize(TROVE_METHOD_DBPF);

    return 0;
}
Exemple #14
0
int main(int argc, char **argv)
{
    int ret, count, i, fd;
    TROVE_op_id op_id;
    TROVE_coll_id coll_id;
    TROVE_handle file_handle, parent_handle;
    TROVE_ds_state state;
    TROVE_keyval_s key, val;
    TROVE_ds_attributes_s s_attr;
    TROVE_size f_size;
    char *file_name;
    char path_name[PATH_SIZE];
    char *buf;
    TROVE_context_id trove_context = -1;

    ret = parse_args(argc, argv);
    if (ret < 0) {
	fprintf(stderr, "argument parsing failed.\n");
	return -1;
    }

    if (optind + 1 >= argc) return -1;

    strcpy(path_to_file, argv[optind]);
    strcpy(path_to_unix, argv[optind+1]);

    ret = trove_initialize(
        TROVE_METHOD_DBPF, NULL, storage_space, 0);
    if (ret < 0) {
	fprintf(stderr, "initialize failed.\n");
	return -1;
    }

    /* try to look up collection used to store file system */
    ret = trove_collection_lookup(
        TROVE_METHOD_DBPF, file_system, &coll_id, NULL, &op_id);
    if (ret < 0) {
	fprintf(stderr, "collection lookup failed.\n");
	return -1;
    }

    ret = trove_open_context(coll_id, &trove_context);
    if (ret < 0)
    {
        fprintf(stderr, "trove_open_context failed\n");
        return -1;
    }

    /* find the parent directory name */
    strcpy(path_name, path_to_file);
    for (i=strlen(path_name); i >= 0; i--) {
	if (path_name[i] != '/') path_name[i] = '\0';
	else break;
    }
    file_name = path_to_file + strlen(path_name);
#if 0
    printf("path is %s\n", path_name);
    printf("file is %s\n", file_name);
#endif

    /* find the parent directory handle */
    ret = path_lookup(coll_id, path_name, &parent_handle);
    if (ret < 0) {
	return -1;
    }


    /* add new file name/handle pair to parent directory */
    key.buffer = file_name;
    key.buffer_sz = strlen(file_name) + 1;
    val.buffer = &file_handle;
    val.buffer_sz = sizeof(file_handle);

    ret = trove_keyval_read(coll_id, parent_handle, &key, &val,
                            0, NULL, NULL, trove_context, &op_id, NULL);
    count = 1;
    while (ret == 0) ret = trove_dspace_test(
        coll_id, op_id, trove_context, &count, NULL, NULL, &state,
        TROVE_DEFAULT_TEST_TIMEOUT);
    if (ret < 0) {
	fprintf(stderr, "keyval read failed.\n");
	return -1;
    }

    ret = trove_dspace_getattr(coll_id,
			       file_handle,
			       &s_attr,
			       0 /* flags */,
			       NULL,
                               trove_context,
			       &op_id,
                               NULL);
    while (ret == 0) ret = trove_dspace_test(
        coll_id, op_id, trove_context, &count, NULL, NULL, &state,
        TROVE_DEFAULT_TEST_TIMEOUT);
    if (ret < 0) return -1;

    /* get a buffer */
    buf = (char *) malloc((size_t) s_attr.u.datafile.b_size);
    if (buf == NULL) return -1;

    f_size = s_attr.u.datafile.b_size;
    /* read data from trove file */
    ret = trove_bstream_read_at(coll_id,
				file_handle,
				buf,
				&f_size,
				0, /* offset */
				0, /* flags */
				NULL, /* vtag */
				NULL, /* user ptr */
                                trove_context,
				&op_id,
                                NULL);
    count = 1;
    while ( ret == 0) ret = trove_dspace_test(
        coll_id, op_id, trove_context, &count, NULL, NULL, &state,
        TROVE_DEFAULT_TEST_TIMEOUT);
    if (ret < 0 ) {
	fprintf(stderr, "bstream write failed.\n");
	return -1;
    }

    /* open up the unix file */
    fd = open(path_to_unix, O_RDWR | O_CREAT, 0644);
    if (fd < 0) {
	perror("open");
	return -1;
    }

    /* write data to file */
    write(fd, buf, f_size);

    close(fd);

    trove_close_context(coll_id, trove_context);
    trove_finalize(TROVE_METHOD_DBPF);
#if 0
    printf("created file %s (handle = %d)\n", file_name, (int) file_handle);
#endif
    return 0;
}
Exemple #15
0
int main(int argc, char **argv)
{
    int ret, count, i;
    char *file_name;
    char path_name[PATH_SIZE];

    TROVE_op_id op_id;
    TROVE_coll_id coll_id;
    TROVE_handle file_handle, parent_handle;
    TROVE_ds_state state;
    TROVE_keyval_s key, val;
    TROVE_ds_attributes_s s_attr;
    TROVE_context_id trove_context = -1;

    ret = parse_args(argc, argv);
    if (ret < 0) {
	fprintf(stderr, "argument parsing failed.\n");
	return -1;
    }

    ret = trove_initialize(
        TROVE_METHOD_DBPF, NULL, storage_space, storage_space, 0);
    if (ret < 0) {
	fprintf(stderr, "initialize failed.\n");
	return -1;
    }

    /* try to look up collection used to store file system */
    ret = trove_collection_lookup(
        TROVE_METHOD_DBPF, file_system, &coll_id, NULL, &op_id);
    if (ret < 0) {
	fprintf(stderr, "collection lookup failed.\n");
	return -1;
    }

    ret = trove_open_context(coll_id, &trove_context);
    if (ret < 0)
    {
        fprintf(stderr, "trove_open_context failed\n");
        return -1;
    }

    /* find the parent directory name */
    strcpy(path_name, path_to_file);
    for (i=strlen(path_name); i >= 0; i--) {
	if (path_name[i] != '/') path_name[i] = '\0';
	else break;
    }
    file_name = path_to_file + strlen(path_name);
#if 0
    printf("path is %s\n", path_name);
    printf("file is %s\n", file_name);
#endif

    /* find the parent directory handle */
    ret = path_lookup(coll_id, path_name, &parent_handle);
    if (ret < 0) {
	return -1;
    }

    /* TODO: make a is_dir function... maybe make a full blown stat(2)? */
    
    /* look up the handle for the file */
    memset(&key, 0, sizeof(key));
    memset(&val, 0, sizeof(val));
    key.buffer = file_name;
    key.buffer_sz = strlen(file_name)+1;
    val.buffer = &file_handle;
    val.buffer_sz = sizeof(TROVE_handle);

    /* it would be smart to verify that this is a directory first... */
    ret = trove_keyval_read(coll_id, parent_handle, &key, &val,
                            0, NULL, NULL, trove_context, &op_id, NULL);
    while (ret == 0) ret = trove_dspace_test(
        coll_id, op_id, trove_context, &count, NULL, NULL, &state,
        TROVE_DEFAULT_TEST_TIMEOUT);
    if ( ret < 0 || state == -1) {
	    fprintf(stderr, "read failed for key %s\n", file_name);
	    return -1;
    }

    ret = trove_dspace_getattr(coll_id,
			       file_handle,
			       &s_attr,
			       0 /* flags */,
			       NULL,
                               trove_context,
			       &op_id,
                               NULL);
    while (ret == 0) ret = trove_dspace_test(
        coll_id, op_id, trove_context, &count, NULL, NULL, &state,
        TROVE_DEFAULT_TEST_TIMEOUT);
    if (ret < 0) return -1;

    /* 'handles are everything':  now that we've gotten a handle from the
     * file_name, we can wipe the keyval (via name) and the dspace (via
     * handle)*/

    key.buffer = file_name;
    key.buffer_sz = strlen(file_name)+1;

    ret = trove_keyval_remove(coll_id, parent_handle, &key, NULL,
                              0, NULL, NULL, trove_context, &op_id, NULL);
    while (ret == 0) ret = trove_dspace_test(
        coll_id, op_id, trove_context, &count, NULL, NULL, &state,
        TROVE_DEFAULT_TEST_TIMEOUT);
    if (ret < 0 ) {
	    fprintf(stderr, "removal failed for %s\n", file_name);
	    return -1;
    }

    /* the question: is it up to the caller to clean up the dspace if it removed the last entry?  no no no*/
    /* gar gar being dense:  the dspace gets removed.  */
    ret = trove_dspace_remove(coll_id, 
			      file_handle,
			      TROVE_SYNC,
			      NULL,
                              trove_context,
			      &op_id,
                              NULL);
    while (ret == 0) ret = trove_dspace_test(
        coll_id, op_id, trove_context, &count, NULL, NULL, &state,
        TROVE_DEFAULT_TEST_TIMEOUT);
    if (ret < 0) {
	fprintf(stderr, "dspace remove failed.\n");
	return -1;
    }

    trove_close_context(coll_id, trove_context);
    trove_finalize(TROVE_METHOD_DBPF);
    printf("file %s removed (file handle = %d, parent handle = %d).\n",
	   file_name, 
	   (int) file_handle,
	   (int) parent_handle);

    return 0;
}