Пример #1
0
int initialize_sysint(void)
{
    int ret = -1;

    memset(&pvfs_helper,0,sizeof(pvfs_helper));

    ret = PVFS_util_init_defaults();
    if(ret < 0)
    {
	PVFS_perror("PVFS_util_init_defaults", ret);
	return(ret);
    }

    ret = PVFS_util_get_default_fsid(&pvfs_helper.fs_id);
    if(ret < 0)
    {
	PVFS_perror("PVFS_util_get_default_fsid", ret);
	return(ret);
    }

    pvfs_helper.initialized = 1;
    pvfs_helper.num_test_files = NUM_TEST_FILES;

    gossip_debug(GOSSIP_CLIENT_DEBUG,"sysint intialized\n");
    return 0;
}
Пример #2
0
/* write 'count' bytes from 'buffer' into (unix or pvfs2) file 'dest' */
size_t generic_write(file_object *dest, char *buffer, 
    int64_t offset, size_t count, PVFS_credentials *credentials)
{
    PVFS_Request mem_req, file_req;
    PVFS_sysresp_io resp_io;
    int ret;

    if (dest->fs_type == UNIX_FILE)
	return(write(dest->u.ufs.fd, buffer, count));
    else
    {
	file_req = PVFS_BYTE;
	ret = PVFS_Request_contiguous(count, PVFS_BYTE, &mem_req);
	if (ret < 0)
	{
	    PVFS_perror("PVFS_Request_contiguous", ret);
	    return(ret);
	}
	ret = PVFS_sys_write(dest->u.pvfs2.ref, file_req, offset,
		buffer, mem_req, credentials, &resp_io, hints);
	if (ret == 0) 
        {
            PVFS_Request_free(&mem_req);
	    return(resp_io.total_completed);
        }
	else
	    PVFS_perror("PVFS_sys_write", ret);
    }
    return ret;
}
Пример #3
0
int main(int argc, char **argv)
{
    int ret = -1;
    PVFS_fs_id cur_fs;
    struct options* user_opts = NULL;
    char pvfs_path[PVFS_NAME_MAX] = {0};
    PVFS_credentials creds;

    /* look at command line arguments */
    user_opts = parse_args(argc, argv);
    if(!user_opts)
    {
	fprintf(stderr, "Error: failed to parse command line arguments.\n");
	usage(argc, argv);
	return(-1);
    }

    ret = PVFS_util_init_defaults();
    if(ret < 0)
    {
	PVFS_perror("PVFS_util_init_defaults", ret);
	return(-1);
    }

    /* translate local path into pvfs2 relative path */
    ret = PVFS_util_resolve(user_opts->mnt_point,
        &cur_fs, pvfs_path, PVFS_NAME_MAX);
    if(ret < 0)
    {
	fprintf(stderr, "Error: could not find filesystem for %s in pvfstab\n", 
	    user_opts->mnt_point);
	return(-1);
    }

    PVFS_util_gen_credentials(&creds);

    ret = PVFS_mgmt_setparam_all(cur_fs,
				 &creds,
				 PVFS_SERV_PARAM_DROP_CACHES,
				 0,
				 NULL,
				 NULL /* detailed errors */);
    if(ret < 0)
    {
        PVFS_perror("PVFS_mgmt_setparam_all", ret);
        return(-1);
    }

    PVFS_sys_finalize();

    return(ret);
}
Пример #4
0
int test_util_get_io_perfs(
    PVFS_fs_id cur_fs,
    PVFS_credentials creds,
    int count)
{
    int ret, i, j;
    ret = PVFS_mgmt_perf_mon_list(
              cur_fs, &creds, perf_matrix,
              end_time_ms_array, addr_array, next_id_array,
              count, HISTORY, NULL, NULL);
    if(ret < 0)
    {
        PVFS_perror("PVFS_mgmt_perf_mon_list", ret);
        return -1;
    }

    for(i = 0; i < count; i++)
    {
        for(j = 0; j < HISTORY; ++j)
        {
            if(!perf_matrix[i][j].valid_flag)
            {
                break;
            }

            printf("%d\t%llu\t%lld\t%lld\n",
                   count,
                   llu(perf_matrix[i][j].start_time_ms),
                   lld(perf_matrix[i][j].write),
                   lld(perf_matrix[i][j].read));
        }
    }

    return 0;
}
Пример #5
0
int create_dirent(PVFS_object_ref dir_ref,
		  char *name,
		  PVFS_handle handle,
		  PVFS_credentials *creds)
{
    int ret;

    printf("* %s creating new reference to %s (%llu) in %llu.\n",
	   fsck_opts->destructive ? "" : "not",
	   name,
	   llu(handle),
	   llu(dir_ref.handle));

    if (fsck_opts->destructive) {
	ret = PVFS_mgmt_create_dirent(dir_ref,
				      name,
				      handle,
				      creds, NULL);
	if (ret != 0) {
	    PVFS_perror("PVFS_mgmt_create_dirent", ret);
	}
    }
    else {
	ret = 0;
    }

    return ret;
}
Пример #6
0
int remove_directory_entry(PVFS_object_ref dir_ref,
			   PVFS_object_ref entry_ref,
			   char *name,
			   PVFS_credentials *creds)
{
    int ret;

    printf("* %s deleting directory entry for missing object %s (%llu) from dir %llu.\n",
	   fsck_opts->destructive ? "" : "not",
	   name,
	   llu(entry_ref.handle),
	   llu(dir_ref.handle));
    if( (fsck_opts->safety_check) &&
        (++global_removals >= fsck_opts->safety_count) )
    {
        get_user_action_to_continue( );
    }

    if (fsck_opts->destructive) {
	ret = PVFS_mgmt_remove_dirent(dir_ref,
				      name,
				      creds, NULL);
	if (ret != 0) {
	    PVFS_perror("PVFS_mgmt_remove_dirent", ret);
	}
    }
    else {
	ret = 0;
    }
    assert(ret == 0);
    return 0;
}
Пример #7
0
int remove_object(PVFS_object_ref obj_ref,
		  PVFS_ds_type obj_type,
		  PVFS_credentials *creds)
{
    int ret;

    printf("* %s removing %s %llu.\n",
	   fsck_opts->destructive ? "" : "not",
	   get_type_str(obj_type),
	   llu(obj_ref.handle));

    if( (fsck_opts->safety_check) &&
        (++global_removals >= fsck_opts->safety_count) )
    {
        get_user_action_to_continue( );
    }

    if (fsck_opts->destructive) {
	ret = PVFS_mgmt_remove_object(obj_ref,
				      creds, NULL);
	if (ret != 0) {
	    PVFS_perror("PVFS_mgmt_remove_object", ret);
	}
    }
    else {
	ret = 0;
    }

    assert(ret == 0);

    return 0;
}
Пример #8
0
int match_dirdata(struct handlelist *hl,
		  struct handlelist *alt_hl,
		  PVFS_object_ref dir_ref,
		  PVFS_credentials *creds)
{
    int ret, idx;
    PVFS_handle dirdata_handle;

    printf("# looking for dirdata match to %llu.\n",
	   llu(dir_ref.handle));

    ret = PVFS_mgmt_get_dirdata_handle(dir_ref,
				       &dirdata_handle,
				       creds, NULL);
    if (ret != 0)
    {
        PVFS_perror("match_dirdata", ret);
	return -1;
    }

    printf("# mgmt_get_dirdata returned %llu.\n", llu(dirdata_handle));

    if (handlelist_find_handle(hl, dirdata_handle, &idx) == 0)
    {
	handlelist_remove_handle(hl, dirdata_handle, idx);
	return 0;
    }
    if (alt_hl && handlelist_find_handle(alt_hl, dirdata_handle, &idx) == 0)
    {
	handlelist_remove_handle(alt_hl, dirdata_handle, idx);
	return 0;
    }

    return -1;
}
Пример #9
0
/* read 'count' bytes from a (unix or pvfs2) file 'src', placing the result in
 * 'buffer' */
size_t generic_read(file_object *src, char *buffer, 
	int64_t offset, size_t count, PVFS_credentials *credentials)
{
    PVFS_Request mem_req, file_req;
    PVFS_sysresp_io resp_io;
    int ret;

    if(src->fs_type == UNIX_FILE)
	return (read(src->u.ufs.fd, buffer, count));
    else
    {
	file_req = PVFS_BYTE;
	ret = PVFS_Request_contiguous(count, PVFS_BYTE, &mem_req);
	if (ret < 0)
	{
	    fprintf(stderr, "Error: PVFS_Request_contiguous failure\n");
	    return (ret);
	}
	ret = PVFS_sys_read(src->u.pvfs2.ref, file_req, offset,
		buffer, mem_req, credentials, &resp_io, hints);
	if (ret == 0)
	{
            PVFS_Request_free(&mem_req);
	    return (resp_io.total_completed);
	} 
	else 
	    PVFS_perror("PVFS_sys_read", ret);
    }
    return (ret);
}
Пример #10
0
void print_entry(
    char *entry_name,
    PVFS_handle handle,
    PVFS_fs_id fs_id,
    PVFS_sys_attr *attr,
    int attr_error,
    struct options *opts)
{
    int ret = -1;
    PVFS_object_ref ref;
    PVFS_credentials credentials;
    PVFS_sysresp_getattr getattr_response;

    if (!opts->list_long)
    {
        if (opts->list_inode)
        {
            printf("%llu %s\n", llu(handle), entry_name);
        }
        else
        {
            printf("%s\n", entry_name);
        }
        return;
    }

    if (attr_error == 0)
    {
        if(!attr)
        {
            /* missing attributes (possibly for . or .. entries); get them
             * the old fashioned way
             */
            ref.handle = handle;
            ref.fs_id = fs_id;

            memset(&getattr_response,0, sizeof(PVFS_sysresp_getattr));
            PVFS_util_gen_credentials(&credentials);

            ret = PVFS_sys_getattr(ref, PVFS_ATTR_SYS_ALL_NOHINT,
                &credentials, &getattr_response, NULL);
            if (ret)
            {
                fprintf(stderr,"Failed to get attributes on handle %llu,%d\n",
                    llu(handle),fs_id);
                PVFS_perror("Getattr failure", ret);
                return;
            }
            print_entry_attr(handle, entry_name,  &getattr_response.attr, opts);
        }
        else
        {
            print_entry_attr(handle, entry_name, attr, opts);
        }
    }
}
Пример #11
0
int pvfsInit()
{
 int ret;
 PVFS_hint_import_env(& hints);
 ret = PVFS_util_init_defaults();
 if(ret < 0)
 {
     PVFS_perror("PVFS_util_init_defaults",ret);
     return -1;
 }
 PVFS_util_gen_credentials(&credentials);
}
Пример #12
0
int main(int argc, char **argv)
{
    int ret = -1;
    struct options* user_opts = NULL;
    struct PVFS_sys_mntent* tmp_ent = NULL;
    char config_server[256];

    /* look at command line arguments */
    user_opts = parse_args(argc, argv);
    if(!user_opts)
    {
        fprintf(stderr, "Error: failed to parse command "
                        "line arguments.\n");
        usage(argc, argv);
        return(-1);
    }

    sprintf(config_server, "%.50s://%.150s:%d", user_opts->network_proto,
        user_opts->hostname, user_opts->port);

    /* build mnt entry */
    tmp_ent = PVFS_util_gen_mntent(config_server, user_opts->fsname);
    if(!tmp_ent)
    {
        fprintf(stderr, "Error: failed to build mnt entry.\n");
        return(-1);
    }

    ret = PVFS_sys_initialize(GOSSIP_NO_DEBUG);
    if(ret < 0)
    {
        fprintf(stderr, "Error: failed to initialize PVFS2 library.\n");
        return(-1);
    }

    ret = PVFS_sys_fs_add(tmp_ent);
    if(ret < 0)
    {
        PVFS_perror("Error: could not retrieve configuration from server", ret);
        return(-1);
    }

    PVFS_sys_finalize();

    PVFS_util_gen_mntent_release(tmp_ent);

    return(ret);
}
Пример #13
0
int main(int argc, char **argv)
{
  int ret = 0;
  struct options* user_opts = NULL;
  int i, k;

  /* look at command line arguments */
  user_opts = parse_args(argc, argv);
  if(!user_opts)
  {
    fprintf(stderr, "Error: failed to parse "
            "command line arguments.\n");
    return(-1);
  }

  ret = PVFS_util_init_defaults();
  if(ret < 0)
  {
    PVFS_perror("PVFS_util_init_defaults", ret);
    return(-1);
  }

  /*
   * for each file the user specified
   * for each file the user specified
   */
  for (i = 0; i < user_opts->target_count; i++) {
    ret = pvfs2_geteattr(user_opts->nkey, user_opts->key, user_opts->val,
            user_opts->destfiles[i]);
    if (ret != 0) {
        printf("geteattr returned error code - exiting\n");
        break;
    }
    for (k = 0; k < user_opts->nkey; k++) {
        printf("key[%d]:%s Value:\n%s\n",k,
                (char *)user_opts->key[k].buffer,
                (char *)user_opts->val[k].buffer);
    }
    /* TODO: need to free the request descriptions */
  }
  PVFS_sys_finalize();
  return(ret);
}
Пример #14
0
/*
 *	file_open_pvfs2: This is the same strategy as ROMIO's pvfs2 open
 *
 *	Function:	- opens a new file
 *	Accepts:	- same arguments as MPI_File_open()
 *	Returns:	- Success if new file handle
 */
int
mca_fs_pvfs2_file_open (struct ompi_communicator_t *comm,
                        const char* filename,
                        int access_mode,
                        struct ompi_info_t *info,
                        mca_io_ompio_file_t *fh)
{
    int ret;
    mca_fs_pvfs2 *pvfs2_fs;
    PVFS_fs_id pvfs2_id;
    char pvfs2_path[OMPIO_MAX_NAME] = {0};
    char * ncache_timeout;
    open_status o_status = {0, {0, 0}};
    struct ompi_datatype_t *open_status_type;
    struct ompi_datatype_t *types[2] = {&ompi_mpi_int.dt, &ompi_mpi_byte.dt};
    int lens[2] = {1, sizeof(PVFS_object_ref)};
    OPAL_PTRDIFF_TYPE offsets[2];
    char char_stripe[MPI_MAX_INFO_KEY];
    int flag;
    int fs_pvfs2_stripe_size = -1;
    int fs_pvfs2_stripe_width = -1;

    /* We are going to do what ROMIO does with one process resolving
     * the name and broadcasting to others */

    pvfs2_fs = (mca_fs_pvfs2 *) malloc(sizeof(mca_fs_pvfs2));
    if (NULL == pvfs2_fs) {
        opal_output (1, "OUT OF MEMORY\n");
        return OMPI_ERR_OUT_OF_RESOURCE;
    }

    if (!mca_fs_pvfs2_IS_INITIALIZED) {
        /* disable the pvfs2 ncache */
        ncache_timeout = getenv("PVFS2_NCACHE_TIMEOUT");
        if (ncache_timeout == NULL ) {
            setenv("PVFS2_NCACHE_TIMEOUT", "0", 1);
        }
        ret = PVFS_util_init_defaults();
        if (ret < 0) {
            PVFS_perror("PVFS_util_init_defaults", ret);
            return OMPI_ERROR;
        }
        mca_fs_pvfs2_IS_INITIALIZED = 1;
    }

    memset(&(pvfs2_fs->credentials), 0, sizeof(PVFS_credentials));
    PVFS_util_gen_credentials(&(pvfs2_fs->credentials));

    /* check for stripe size and stripe depth in the info object and
       update mca_fs_pvfs2_stripe_width and mca_fs_pvfs2_stripe_size
       before calling fake_an_open() */

    ompi_info_get (info, "stripe_size", MPI_MAX_INFO_VAL, char_stripe, &flag);
    if ( flag ) {
        sscanf ( char_stripe, "%d", &fs_pvfs2_stripe_size );
    }

    ompi_info_get (info, "stripe_width", MPI_MAX_INFO_VAL, char_stripe, &flag);
    if ( flag ) {
        sscanf ( char_stripe, "%d", &fs_pvfs2_stripe_width );
    }

    if (fs_pvfs2_stripe_size < 0) {
        fs_pvfs2_stripe_size = mca_fs_pvfs2_stripe_size;
    }

    if (fs_pvfs2_stripe_width < 0) {
        fs_pvfs2_stripe_width = mca_fs_pvfs2_stripe_width;
    }


    if (OMPIO_ROOT == fh->f_rank) {
        ret = PVFS_util_resolve(filename, &pvfs2_id, pvfs2_path, OMPIO_MAX_NAME);
        if (ret < 0 ) {
            PVFS_perror("PVFS_util_resolve", ret);
	    o_status.error = -1;
        }
        else {
            fake_an_open (pvfs2_id,
                          pvfs2_path,
                          access_mode,
                          fs_pvfs2_stripe_width,
                          (PVFS_size)fs_pvfs2_stripe_size,
                          pvfs2_fs,
                          &o_status);
        }
        pvfs2_fs->object_ref = o_status.object_ref;
	fh->f_fs_ptr = pvfs2_fs;
    }

    /* broadcast status and (possibly valid) object reference */
    offsets[0] = (MPI_Aint)(&o_status.error);
    offsets[1] = (MPI_Aint)(&o_status.object_ref);

    ompi_datatype_create_struct (2, lens, offsets, types, &open_status_type);
    ompi_datatype_commit (&open_status_type);

    fh->f_comm->c_coll.coll_bcast (MPI_BOTTOM,
                                   1,
                                   open_status_type,
                                   OMPIO_ROOT,
                                   fh->f_comm,
                                   fh->f_comm->c_coll.coll_bcast_module);

    ompi_datatype_destroy (&open_status_type);

    if (o_status.error != 0) {
	/* No need to free the pvfs2_fs structure, since it will
	   be deallocated in file_close in case of an error */
	fh->f_fs_ptr = NULL;
	return OMPI_ERROR;
    }

    pvfs2_fs->object_ref = o_status.object_ref;
    fh->f_fs_ptr = pvfs2_fs;

    /* update the internal ompio structure to store stripe
       size and stripe depth correctly.
       Hadi(to be done): For this read the stripe size and stripe depth from
       the file itself
    */

    if (fs_pvfs2_stripe_size > 0 && fs_pvfs2_stripe_width > 0) {
        fh->f_stripe_size = fs_pvfs2_stripe_size;
        fh->f_stripe_count = fs_pvfs2_stripe_width;
    }

    return OMPI_SUCCESS;
}
Пример #15
0
/**
 * Migrates an entire 0.0.1 DBPF collection
 * \return 0 on succes, -1 on failure
 */
static int translate_0_0_1(
    char* storage_space,   /**< path to storage space */
    char* old_coll_path,   /**< path to old collection */
    char* coll_name,       /**< collection name */
    TROVE_coll_id coll_id) /**< collection id in string format */
{
    int ret = -1;
    /* choose a handle range big enough to encompass anything pvfs2-genconfig
     * will create
     */
    char handle_range[] = "4-64000000000";
    TROVE_op_id op_id;
    TROVE_context_id trove_context = -1;
    char current_path[PATH_MAX];

    /* rename old collection */
    snprintf(current_path, PATH_MAX, "%s/%08x", storage_space, coll_id);

    if(access(current_path, F_OK) != 0)
    {
        fprintf(stderr, 
                "Error: could not find old collection: %s\n"
                "       fs: %s (%08x)\n",
                old_coll_path, coll_name, coll_id);
        return -1;
    }
                        
    if(verbose) printf("VERBOSE Renaming old collection.\n");
    ret = rename(current_path, old_coll_path);
    if(ret < 0)
    {
        perror("rename");
        return(-1);
    }

    ret = remove_collection_entry(storage_space, coll_name);
    if(ret < 0)
    {
        fprintf(stderr, "Error: failed to remove collection entry: %s\n",
                coll_name);
        return(-1);
    }
    
    /* create new collection */
    /* NOTE: deliberately not specifying root handle; it will get translated
     * later as a normal directory if applicable
     */
    if(verbose) 
        printf("VERBOSE Creating temporary collection to migrate to.\n");
    ret = pvfs2_mkspace(
        storage_space, 
        coll_name,
        coll_id, 
        TROVE_HANDLE_NULL,
        handle_range,
        NULL,
        1,
        0);
    if(ret != 0)
    {
        fprintf(stderr, "Error: failed to create new collection.\n");
        return(-1);
    }

    /* initialize distribution infrastructure */
    /* NOTE: server config argument is not required here */
    ret = PINT_dist_initialize(NULL);
    if (ret < 0)
    {
        PVFS_perror("PINT_dist_initialize", ret);
        if(verbose) printf("VERBOSE Destroying temporary collection.\n");
        pvfs2_rmspace(storage_space, coll_name, coll_id, 1, 0);
        return(-1);
    }

    /* initialize trove and lookup collection */
    ret = trove_initialize(
        TROVE_METHOD_DBPF, NULL, storage_space, 0);
    if (ret < 0)
    {
        PVFS_perror("trove_initialize", ret);
        if(verbose) printf("VERBOSE Destroying temporary collection.\n");
        pvfs2_rmspace(storage_space, coll_name, coll_id, 1, 0);
        return(-1);
    }
    ret = trove_collection_lookup(
        TROVE_METHOD_DBPF, coll_name, &coll_id, NULL, &op_id);
    if (ret != 1)
    {   
        fprintf(stderr, "Error: failed to lookup new collection.\n");
        if(verbose) printf("VERBOSE Destroying temporary collection.\n");
        pvfs2_rmspace(storage_space, coll_name, coll_id, 1, 0);
        return -1; 
    }   

    ret = trove_open_context(coll_id, &trove_context);
    if (ret < 0)
    {
        PVFS_perror("trove_open_context", ret);
        return(-1);
    }

    /* convert collection xattrs */
    ret = translate_coll_eattr_0_0_1(
        old_coll_path, coll_id, coll_name, trove_context);
    if(ret < 0)
    {
        fprintf(stderr, "Error: failed to migrate collection extended attributes.\n");
        if(verbose) printf("VERBOSE Destroying temporary collection.\n");
        pvfs2_rmspace(storage_space, coll_name, coll_id, 1, 0);
        return(-1);
    }

    /* convert dspace attrs */
    ret = translate_dspace_attr_0_0_1(
        old_coll_path, coll_id, coll_name, trove_context);
    if(ret < 0)
    {
        fprintf(stderr, "Error: failed to migrate dspace attributes.\n");
        if(verbose) printf("VERBOSE Destroying temporary collection.\n");
        pvfs2_rmspace(storage_space, coll_name, coll_id, 1, 0);
        return(-1);
    }

    /* convert dspace keyvals */
    ret = translate_keyvals_0_0_1(
        old_coll_path, coll_id, coll_name, trove_context);
    if(ret < 0)
    {
        fprintf(stderr, "Error: failed to migrate keyvals.\n");
        if(verbose) printf("VERBOSE Destroying temporary collection.\n");
        pvfs2_rmspace(storage_space, coll_name, coll_id, 1, 0);
        return(-1);
    }

    /* at this point, we are done with the Trove API */
    trove_close_context(coll_id, trove_context);
    trove_finalize(TROVE_METHOD_DBPF);
    PINT_dist_finalize();

    /* convert bstreams */
    ret = translate_bstreams_0_0_1(
        storage_space, old_coll_path, coll_id, coll_name, trove_context);
    if(ret < 0)
    {
        fprintf(stderr, "Error: failed to migrate bstreams.\n");
        if(verbose) printf("VERBOSE Destroying temporary collection.\n");
        pvfs2_rmspace(storage_space, coll_name, coll_id, 1, 0);
        return(-1);
    }

    printf("Migration successful.\n");

    if(!opts.cleanup_set)
    {
        printf("===================================================================\n");
        printf("IMPORTANT!!! IMPORTANT!!! IMPORTANT!!! IMPORTANT!!!\n");
        printf("Please delete the old collection once you have tested and confirmed\n");
        printf("the results of the migration.\n");
        printf("Command: \"pvfs2-migrate-collection -cleanup <fs config> <server config>\"\n");
        printf("===================================================================\n");
    }

    return(0);
}
Пример #16
0
int main(int argc, char **argv)
{
    int ret = -1;
    char *retc = NULL;
    PVFS_fs_id cur_fs;
    struct options* user_opts = NULL;
    char pvfs_path[PVFS_NAME_MAX] = {0};
    int i;
    PVFS_credentials creds;
    int io_server_count;
    int64_t **perf_matrix;
    uint64_t* end_time_ms_array;
    uint32_t* next_id_array;
    PVFS_BMI_addr_t *addr_array, server_addr;
    char *cmd_buffer = (char *)malloc(CMD_BUF_SIZE);
    int max_keys, key_count;

    /* look at command line arguments */
    user_opts = parse_args(argc, argv);
    if (!user_opts)
    {
        fprintf(stderr, "Error: failed to parse command line arguments.\n");
        usage(argc, argv);
        return(-1);
    }

    ret = PVFS_util_init_defaults();
    if (ret < 0)
    {
        PVFS_perror("PVFS_util_init_defaults", ret);
        return(-1);
    }

    PVFS_util_gen_credentials(&creds);
    if (user_opts->server_addr_set)
    {
        if (PVFS_util_get_default_fsid(&cur_fs) < 0)
        {
            /* Can't find a file system */
            fprintf(stderr, "Error: failed to find a file system.\n");
            usage(argc, argv);
            return(-1);
        }
        if (user_opts->server_addr &&
                (BMI_addr_lookup (&server_addr, user_opts->server_addr) == 0))
        {
            /* set up single server */
            addr_array = (PVFS_BMI_addr_t *)malloc(sizeof(PVFS_BMI_addr_t));
            addr_array[0] = server_addr;
            io_server_count = 1;
        }
        else
        {
            /* bad argument - address not found */
            fprintf(stderr, "Error: failed to parse server address.\n");
            usage(argc, argv);
            return(-1);
        }
    }
    else
    {
        /* will sample all servers */
        /* translate local path into pvfs2 relative path */
        ret = PVFS_util_resolve(user_opts->mnt_point,
                                &cur_fs, pvfs_path, PVFS_NAME_MAX);
        if (ret < 0)
        {
            PVFS_perror("PVFS_util_resolve", ret);
            return(-1);
        }

        /* count how many I/O servers we have */
        ret = PVFS_mgmt_count_servers(cur_fs, &creds, PVFS_MGMT_IO_SERVER,
                                    &io_server_count);
        if (ret < 0)
        {
            PVFS_perror("PVFS_mgmt_count_servers", ret);
	        return(-1);
        }
    
        /* build a list of servers to talk to */
        addr_array = (PVFS_BMI_addr_t *)
	    malloc(io_server_count * sizeof(PVFS_BMI_addr_t));
        if (addr_array == NULL)
        {
	        perror("malloc");
	        return -1;
        }
        ret = PVFS_mgmt_get_server_array(cur_fs,
				     &creds,
				     PVFS_MGMT_IO_SERVER,
				     addr_array,
				     &io_server_count);
        if (ret < 0)
        {
	        PVFS_perror("PVFS_mgmt_get_server_array", ret);
	        return -1;
        }
    }

    /* count keys */
    for (max_keys = 0; key_table[max_keys].key_number >= 0; max_keys++);

    /* allocate a 2 dimensional array for statistics */
    perf_matrix = (int64_t **)malloc(io_server_count * sizeof(int64_t *));
    if (!perf_matrix)
    {
        perror("malloc");
        return(-1);
    }
    for(i=0; i<io_server_count; i++)
    {
	    perf_matrix[i] = (int64_t *)malloc(HISTORY * (max_keys + 2)
                                        * sizeof(int64_t));
	    if (perf_matrix[i] == NULL)
	    {
	        perror("malloc");
	        return -1;
	    }
    }

    /* allocate an array to keep up with what iteration of statistics
     * we need from each server 
     */
    next_id_array = (uint32_t *) malloc(io_server_count * sizeof(uint32_t));
    if (next_id_array == NULL)
    {
	     perror("malloc");
	     return -1;
    }
    memset(next_id_array, 0, io_server_count*sizeof(uint32_t));

    /* allocate an array to keep up with end times from each server */
    end_time_ms_array = (uint64_t *)malloc(io_server_count * sizeof(uint64_t));
    if (end_time_ms_array == NULL)
    {
	    perror("malloc");
	    return -1;
    }


    /* loop for ever, grabbing stats when requested */
    while (1)
    {
        int srv = 0;
        time_t snaptime = 0;
        const char *returnType = NULL; 
        int64_t returnValue = 0;
        /* wait for a request from SNMP driver */
        retc = fgets(cmd_buffer, CMD_BUF_SIZE, stdin);
        if (!retc)
        {
            /* error on read */
            return -1;
        }

        /* if PING output PONG */
        if (!strncasecmp(cmd_buffer, "PING", 4))
        {
            fprintf(stdout,"PONG\n");
	        fflush(stdout);
            continue;
        }

        /* try to parse GET command */
        if (!strncasecmp(cmd_buffer, "GET", 3))
        {
            char *c;
            /* found GET read OID */
            retc = fgets(cmd_buffer, CMD_BUF_SIZE, stdin);
            if (!retc)
            {
                /* error on read */
                return -1;
            }
            /* replace newlines with null char */
            for(c = cmd_buffer; *c != '\0'; c++)
                if (*c == '\n')
                    *c = '\0';
        }
        else
        {
            /* bad command */
            fprintf(stdout, "NONE\n");
            fflush(stdout);
            continue;
        }

        /* good command - read counters */
        if (time(NULL) - snaptime > 60)
        {
            snaptime = time(NULL);
            key_count = max_keys;
	        ret = PVFS_mgmt_perf_mon_list(cur_fs,
				          &creds,
				          perf_matrix, 
				          end_time_ms_array,
				          addr_array,
				          next_id_array,
				          io_server_count, 
                          &key_count,
				          HISTORY,
				          NULL, NULL);
	        if (ret < 0)
	        {
	            PVFS_perror("PVFS_mgmt_perf_mon_list", ret);
	            return -1;
	        }
        }

        /* format requested OID */
        if (perf_matrix[srv][key_count] != 0)
        {
            int k;
            /* this is a valid measurement */
            for(k = 0; k < max_keys &&
                    strcmp(cmd_buffer, key_table[k].key_oid); k++);
            /* out of for loop k equals selected key */
            if (k < max_keys)
            {
                returnType = key_table[k].key_type;
                returnValue = perf_matrix[srv][key_table[k].key_number];
            }
            else
            {
                /* invalid command */
                fprintf(stdout,"NONE\n");
                fflush(stdout);
                continue;
            }
        }
        else
        {
            /* invalid measurement */
            fprintf(stdout,"NONE\n");
            fflush(stdout);
            continue;
        }
        fprintf(stdout, "%s\n%llu\n", returnType, llu(returnValue));
        fflush(stdout);
        /* return to top for next command */
    }

    PVFS_sys_finalize();

    return(ret);
}
Пример #17
0
int pvfs_connect(char *fs_spec)
{
    int ret = 0;
    struct PVFS_sys_mntent *me = &pvfs_mntent;
    char *cp;
    int cur_server;

    /* the following is copied from PVFS_util_init_defaults()
       in fuse/lib/pvfs2-util.c */

    /* initialize pvfs system interface */
    ret = PVFS_sys_initialize(GOSSIP_NO_DEBUG);
    if (ret < 0)
    {
        return(ret);
    }

    /* the following is copied from PVFS_util_parse_pvfstab()
       in fuse/lib/pvfs2-util.c */
    memset( me, 0, sizeof(pvfs_mntent) );

    /* Enable integrity checks by default */
    me->integrity_check = 1;
    /* comma-separated list of ways to contact a config server */
    me->num_pvfs_config_servers = 1;

    for (cp=fs_spec; *cp; cp++)
        if (*cp == ',')
            ++me->num_pvfs_config_servers;

    /* allocate room for our copies of the strings */
    me->pvfs_config_servers =
        malloc(me->num_pvfs_config_servers *
               sizeof(*me->pvfs_config_servers));
    if (!me->pvfs_config_servers)
        exit(-1);
    memset(me->pvfs_config_servers, 0,
           me->num_pvfs_config_servers * sizeof(*me->pvfs_config_servers));

    me->mnt_dir = NULL;
    me->mnt_opts = NULL;

    cp = fs_spec;
    cur_server = 0;
    for (;;) {
        char *tok;
        int slashcount;
        char *slash;
        char *last_slash;

        tok = strsep(&cp, ",");
        if (!tok) break;

        slash = tok;
        slashcount = 0;
        while ((slash = index(slash, '/')))
        {
            slash++;
            slashcount++;
        }
        if (slashcount != 3)
        {
            fprintf(stderr,"Error: invalid FS spec: %s\n",
                    fs_spec);
            exit(-1);
        }

        /* find a reference point in the string */
        last_slash = rindex(tok, '/');
        *last_slash = '\0';

        /* config server and fs name are a special case, take one 
         * string and split it in half on "/" delimiter
         */
        me->pvfs_config_servers[cur_server] = strdup(tok);
        if (!me->pvfs_config_servers[cur_server])
            exit(-1);

        ++last_slash;

        if (cur_server == 0) {
            me->pvfs_fs_name = strdup(last_slash);
            if (!me->pvfs_fs_name)
                exit(-1);
        } else {
            if (strcmp(last_slash, me->pvfs_fs_name) != 0) {
                fprintf(stderr,
                        "Error: different fs names in server addresses: %s\n",
                        fs_spec);
                exit(-1);
            }
        }
        ++cur_server;
    }

    /* FIXME flowproto should be an option */
    me->flowproto = FLOWPROTO_DEFAULT;

    /* FIXME encoding should be an option */
    me->encoding = PVFS2_ENCODING_DEFAULT;

    /* FIXME default_num_dfiles should be an option */

    ret = PVFS_sys_fs_add(me);
    if( ret < 0 )
    {
        PVFS_perror("Could not add mnt entry", ret);
        return(-1);
    }
    pvfs_fsid = me->fs_id;

    ret = pvfs_generate_serverlist();

    /* XXX: Turn off attribute caches, they screw with us.  In the future, we
     * might want to investigate invalidating them only when needed. */
    PVFS_sys_set_info(PVFS_SYS_NCACHE_TIMEOUT_MSECS, 0);
    PVFS_sys_set_info(PVFS_SYS_ACACHE_TIMEOUT_MSECS, 0);

    return ret;
}
Пример #18
0
struct handlelist *build_handlelist(PVFS_fs_id cur_fs,
				    PVFS_BMI_addr_t *addr_array,
				    int server_count,
				    PVFS_credentials *creds)
{
    int ret, i, more_flag;
    unsigned long j;
    PVFS_handle **handle_matrix;
    int  *hcount_array;
    unsigned long *handle_count_array;
    unsigned long *total_count_array;
    PVFS_ds_position *position_array;
    struct PVFS_mgmt_server_stat *stat_array;
    struct handlelist *hl;
    struct PVFS_mgmt_setparam_value param_value;

    /* find out how many handles are in use on each */
    stat_array = (struct PVFS_mgmt_server_stat *)
	malloc(server_count * sizeof(struct PVFS_mgmt_server_stat));
    if (stat_array == NULL)
    {
        param_value.type = PVFS_MGMT_PARAM_TYPE_UINT64;
        param_value.u.value = PVFS_SERVER_NORMAL_MODE;
	PVFS_mgmt_setparam_list(cur_fs,
				creds,
				PVFS_SERV_PARAM_MODE,
				&param_value,
				addr_array,
				server_count,
				NULL, NULL);
	return NULL;
    }

    ret = PVFS_mgmt_statfs_list(cur_fs,
				creds,
				stat_array,
				addr_array,
				server_count,
				NULL /* details */
                , NULL);
    if (ret != 0)
    {
        param_value.type = PVFS_MGMT_PARAM_TYPE_UINT64;
        param_value.u.value = PVFS_SERVER_NORMAL_MODE;

	PVFS_perror("PVFS_mgmt_statfs_list", ret);
	PVFS_mgmt_setparam_list(cur_fs,
				creds,
				PVFS_SERV_PARAM_MODE,
                                &param_value,
				addr_array,
				server_count,
				NULL, NULL);
	return NULL;
    }

    /* allocate a 2 dimensional array for handles from mgmt fn. */
    handle_matrix = (PVFS_handle **) calloc(server_count, sizeof(PVFS_handle));
    if (handle_matrix == NULL)
    {
	perror("malloc");
	return NULL;
    }
    for (i=0; i < server_count; i++)
    {
	handle_matrix[i] = (PVFS_handle *) calloc(HANDLE_BATCH, sizeof(PVFS_handle));
	if (handle_matrix[i] == NULL)
	{
	    perror("malloc");
	    return NULL;
	}
    }

    /* allocate some arrays to keep up with state */
    handle_count_array = (unsigned long *) calloc(server_count, sizeof(unsigned long));
    if (handle_count_array == NULL)
    {
	perror("malloc");
	return NULL;
    }
    position_array = (PVFS_ds_position *) calloc(server_count, sizeof(PVFS_ds_position));
    if (position_array == NULL)
    {
	perror("malloc");
	return NULL;
    }
    /* total_count_array */
    total_count_array = (unsigned long *) calloc(server_count, sizeof(unsigned long));
    if (total_count_array == NULL)
    {
        perror("malloc");
        return NULL;
    }
    /* hcount array */
    hcount_array = (int *) calloc(server_count, sizeof(int));
    if (hcount_array == NULL)
    {
        perror("malloc:");
        return NULL;
    }

    for (i=0; i < server_count; i++) {
	handle_count_array[i] = stat_array[i].handles_total_count -
	    stat_array[i].handles_available_count;
        total_count_array[i] = 0;
    }


    hl = handlelist_initialize(handle_count_array, server_count);

    for (i=0; i < server_count; i++)
    {
	hcount_array[i] = HANDLE_BATCH;
	position_array[i] = PVFS_ITERATE_START;
    }

    /* iterate until we have retrieved all handles */
    more_flag = 1;
    while (more_flag)
    {
	ret = PVFS_mgmt_iterate_handles_list(cur_fs,
					     creds,
					     handle_matrix,
					     hcount_array,
					     position_array,
					     addr_array,
					     server_count,
                                             0,
					     NULL /* details */,
                                             NULL /* hints */);
	if (ret < 0)
	{
            param_value.type = PVFS_MGMT_PARAM_TYPE_UINT64;
            param_value.u.value = PVFS_SERVER_NORMAL_MODE;

	    PVFS_perror("PVFS_mgmt_iterate_handles_list", ret);
	    PVFS_mgmt_setparam_list(cur_fs,
				    creds,
				    PVFS_SERV_PARAM_MODE,
                                    &param_value,
				    addr_array,
				    server_count,
				    NULL, NULL);
	    return NULL;
	}

	for (i=0; i < server_count; i++)
	{
            total_count_array[i] += hcount_array[i];
	    for (j=0; j < hcount_array[i]; j++)
	    {
                PVFS_BMI_addr_t tmp_addr;
		/* verify that handles are
		 * within valid ranges for the given server here.
		 */
                ret = PINT_cached_config_map_to_server(&tmp_addr, handle_matrix[i][j], cur_fs);
                if (ret || tmp_addr != addr_array[i])
                {
                    fprintf(stderr, "Ugh! handle does not seem to be owned by the server!\n");
                    return NULL;
                }
	    }

	    handlelist_add_handles(hl,
				   handle_matrix[i],
				   hcount_array[i],
				   i);
	}

	/* find out if any servers have more handles to dump */
	more_flag = 0;
	for (i=0; i < server_count; i++)
	{
	    if (position_array[i] != PVFS_ITERATE_END)
	    {
		more_flag = 1;
		break;
	    }
	}
    }

    for (i = 0; i < server_count; i++)
    {
        unsigned long used_handles = handle_count_array[i];
        if (total_count_array[i] != used_handles)
        {
            fprintf(stderr, "Ugh! Server %d, Received %ld total handles instead of %ld\n",
                    i, total_count_array[i], used_handles);
            return NULL;
        }
    }

    handlelist_finished_adding_handles(hl); /* sanity check */

    /* now look for reserved handles */
    for (i=0; i < server_count; i++)
    {
	hcount_array[i] = HANDLE_BATCH;
	position_array[i] = PVFS_ITERATE_START;
    }

    more_flag = 1;
    while (more_flag)
    {
	ret = PVFS_mgmt_iterate_handles_list(cur_fs,
					     creds,
					     handle_matrix,
					     hcount_array,
					     position_array,
					     addr_array,
					     server_count,
                                             PVFS_MGMT_RESERVED,
					     NULL /* details */,
                                             NULL /* hints */);
	if (ret < 0)
	{
	    PVFS_perror("PVFS_mgmt_iterate_handles_list", ret);
            param_value.type = PVFS_MGMT_PARAM_TYPE_UINT64;
            param_value.u.value = PVFS_SERVER_NORMAL_MODE;
	    PVFS_mgmt_setparam_list(cur_fs,
				    creds,
				    PVFS_SERV_PARAM_MODE,
				    &param_value,
				    addr_array,
				    server_count,
				    NULL,
				    NULL);
	    return NULL;
	}

	for (i=0; i < server_count; i++)
	{
            /* remove any reserved handles from the handlelist.  These will
             * not show up in normal objects when we walk the file system
             * tree.
             */
	    for (j=0; j < hcount_array[i]; j++)
	    {
                /* we don't know the server index.  Reserved handles can be
                 * reported by any server; not just the server that actually
                 * owns that handle.
                 */
	        handlelist_remove_handle_no_idx(hl,
				   handle_matrix[i][j]);
            }
	}

	/* find out if any servers have more handles to dump */
	more_flag = 0;
	for (i=0; i < server_count; i++)
	{
	    if (position_array[i] != PVFS_ITERATE_END)
	    {
		more_flag = 1;
                hcount_array[i] = HANDLE_BATCH;
	    }
	}
    }

    for (i = 0; i < server_count; i++)
    {
	free(handle_matrix[i]);
    }

    free(handle_matrix);
    free(handle_count_array);
    free(hcount_array);
    free(total_count_array);
    free(position_array);

    free(stat_array);
    stat_array = NULL;

    return hl;
}
Пример #19
0
int main(int argc, char **argv)
{
    int ret = -1, in_admin_mode = 0;
    PVFS_fs_id cur_fs;
    char pvfs_path[PVFS_NAME_MAX] = {0};
    PVFS_credentials creds;
    int server_count;
    PVFS_BMI_addr_t *addr_array = NULL;
    struct handlelist *hl_all, *hl_unrefd, *hl_notree;
    struct PVFS_mgmt_setparam_value param_value;

    fsck_opts = parse_args(argc, argv);
    if (!fsck_opts)
    {
	fprintf(stderr, "Error: failed to parse command line arguments.\n");
	usage(argc, argv);
	return -1;
    }

    ret = PVFS_util_init_defaults();
    if (ret != 0)
    {
	PVFS_perror("PVFS_util_init_defaults", ret);
	return -1;
    }

    /* translate local path into pvfs2 relative path */
    ret = PVFS_util_resolve(fsck_opts->mnt_point,
			    &cur_fs,
			    pvfs_path,
			    PVFS_NAME_MAX);
    if (ret != 0)
    {
	PVFS_perror("PVFS_util_resolve", ret);
	return -1;
    }

    PVFS_util_gen_credentials(&creds);

    printf("# Current FSID is %u.\n", cur_fs);

    /* count how many servers we have */
    ret = PVFS_mgmt_count_servers(cur_fs, &creds, 
	PVFS_MGMT_IO_SERVER|PVFS_MGMT_META_SERVER,
	&server_count);
    if (ret != 0)
    {
	PVFS_perror("PVFS_mgmt_count_servers", ret);
	return -1;
    }

    /* build a list of servers to talk to */
    addr_array = (PVFS_BMI_addr_t *)
	malloc(server_count * sizeof(PVFS_BMI_addr_t));
    if (addr_array == NULL)
    {
	perror("malloc");
	return -1;
    }
    ret = PVFS_mgmt_get_server_array(cur_fs,
				     &creds, 
				     PVFS_MGMT_IO_SERVER|PVFS_MGMT_META_SERVER,
				     addr_array,
				     &server_count);
    if (ret != 0)
    {
	PVFS_perror("PVFS_mgmt_get_server_array", ret);
	return -1;
    }

    /* create /lost+found, if it isn't there already */
    ret = create_lost_and_found(cur_fs,
				&creds);
    if (ret != 0) {
	if (ret == -PVFS_EAGAIN) {
	    printf("Failed to create lost+found: likely the system is "
		   "already in admin mode.  Use pvfs2-set-mode to change "
		   "back to normal mode prior to running pvfs2-fsck.\n");
	}
	return -1;
    }

    param_value.type = PVFS_MGMT_PARAM_TYPE_UINT64;
    param_value.u.value = PVFS_SERVER_ADMIN_MODE;
    /* put the servers into administrative mode */
    ret = PVFS_mgmt_setparam_list(cur_fs,
				  &creds,
				  PVFS_SERV_PARAM_MODE,
				  &param_value,
				  addr_array,
				  server_count,
				  NULL, /* detailed errors */
                                  NULL);
    if (ret != 0)
    {
	PVFS_perror("PVFS_mgmt_setparam_list", ret);
	ret = -1;
	goto exit_now;
    }
    
    in_admin_mode = 1;

    hl_all = build_handlelist(cur_fs, addr_array, server_count, &creds);
    if (hl_all == NULL) {
	ret = -1;
	goto exit_now;
    }

    /* first pass traverses the directory tree:
     * - cleans up any direntries that refer to missing objects
     * - verifies that files in the tree have all their datafiles 
     *   (or repairs if possible)
     * - verifies that all directories have their dirdata
     *   (or repairs if possible)
     */
    printf("# first pass: traversing directory tree.\n");
    traverse_directory_tree(cur_fs,
			    hl_all,
			    addr_array,
			    server_count,
			    &creds);

    /* second pass examines handles not in the directory tree:
     * - finds orphaned "sub trees" and keeps references to head
     *   - verifies files in the sub tree have all datafiles
     *     (or repairs if possible)
     *   - verifies all sub tree directories have their dirdata
     *     (or repairs if possible)
     * - builds list of metafile, dirdata, and datafiles not referenced
     *   in some sub tree to be processed later
     */
    printf("# second pass: finding orphaned sub trees.\n");
    hl_notree = find_sub_trees(cur_fs,
			       hl_all,
			       addr_array,
			       &creds);

    handlelist_finalize(&hl_all);

    param_value.type = PVFS_MGMT_PARAM_TYPE_UINT64;
    param_value.u.value = PVFS_SERVER_NORMAL_MODE;

    /* drop out of admin mode now that we've traversed the dir tree */
    PVFS_mgmt_setparam_list(cur_fs,
			    &creds,
			    PVFS_SERV_PARAM_MODE,
			    &param_value,
			    addr_array,
			    server_count,
			    NULL, NULL);
    in_admin_mode = 0;

    /* third pass moves salvagable objects into lost+found:
     * - moves sub trees into lost+found
     * - verifies that orphaned files have all their datafiles
     *   (or repairs if possible)
     *   - if orphaned file is salvagable, moves into lost+found
     * - builds list of remaining dirdata and datafiles not
     *   referenced in sub tree or orphaned file
     */
    printf("# third pass: moving orphaned sub trees and files to lost+found.\n");
    hl_unrefd = fill_lost_and_found(cur_fs,
				    hl_notree,
				    addr_array,
				    &creds);
    handlelist_finalize(&hl_notree);

    /* fourth pass removes orphaned dirdata and datafiles
     * left from the previous passes.
     */
    printf("# fourth pass: removing unreferenced objects.\n");
    cull_leftovers(cur_fs, hl_unrefd, addr_array, &creds);
    handlelist_finalize(&hl_unrefd);

 exit_now:
    if (in_admin_mode) {

        param_value.type = PVFS_MGMT_PARAM_TYPE_UINT64;
        param_value.u.value = PVFS_SERVER_NORMAL_MODE;

	/* get us out of admin mode */
	PVFS_mgmt_setparam_list(cur_fs,
				&creds,
				PVFS_SERV_PARAM_MODE,
                                &param_value,
				addr_array,
				server_count,
				NULL, NULL);
    }
    
    PVFS_sys_finalize();

    if (addr_array != NULL) free(addr_array);
    if (fsck_opts != NULL)   free(fsck_opts);

    return(ret);
}
Пример #20
0
int do_list(
    char *full_path,
    char *start,
    int fs_id,
    struct options *opts)
{
    int i = 0, printed_dot_info = 0;
    int ret = -1;
    int pvfs_dirent_incount;
    char *name = NULL, *cur_file = NULL;
    PVFS_handle cur_handle;
    PVFS_sysresp_lookup lk_response;
    PVFS_sysresp_readdirplus rdplus_response;
    PVFS_sysresp_getattr getattr_response;
    PVFS_credentials credentials;
    PVFS_object_ref ref;
    PVFS_ds_position token;
    uint64_t dir_version = 0;
    double begin = 0., end;
    subdir *current, *head = NULL, *tail = NULL;

    name = start;

    memset(&lk_response,0,sizeof(PVFS_sysresp_lookup));
    PVFS_util_gen_credentials(&credentials);

    if (opts->list_recursive || opts->num_starts > 1)
    {
        printf("%s%s:\n",full_path,start);
    }

    ret = PVFS_sys_lookup(fs_id, name, &credentials,
                        &lk_response, PVFS2_LOOKUP_LINK_NO_FOLLOW, NULL);
    if(ret < 0)
    {
        PVFS_perror("PVFS_sys_lookup", ret);
        return -1;
    }

    ref.handle = lk_response.ref.handle;
    ref.fs_id = fs_id;
    pvfs_dirent_incount = MAX_NUM_DIRENTS;

    memset(&getattr_response,0,sizeof(PVFS_sysresp_getattr));
    if (PVFS_sys_getattr(ref, PVFS_ATTR_SYS_ALL,
                         &credentials, &getattr_response, NULL) == 0)
    {
        if ((getattr_response.attr.objtype == PVFS_TYPE_METAFILE) ||
            (getattr_response.attr.objtype == PVFS_TYPE_SYMLINK) ||
            ((getattr_response.attr.objtype == PVFS_TYPE_DIRECTORY) &&
             (opts->list_directory)))
        {
            char segment[128] = {0};
            PVFS_sysresp_getparent getparent_resp;
            PINT_remove_base_dir(name, segment, 128);
            if (strcmp(segment,"") == 0)
            {
                snprintf(segment,128,"/");
            }

            if (getattr_response.attr.objtype == PVFS_TYPE_DIRECTORY)
            {
                if (PVFS_sys_getparent(ref.fs_id, name, &credentials,
                                       &getparent_resp, NULL) == 0)
                {
                    print_dot_and_dot_dot_info_if_required(
                        getparent_resp.parent_ref);
                }
            }

            if (opts->list_long)
            {
                print_entry_attr(ref.handle, segment,
                                 &getattr_response.attr, opts);
            }
            else
            {
                print_entry(segment, ref.handle, ref.fs_id, 
                        NULL,
                        0,
                        opts);
            }
            return 0;
        }
    }

    if (do_timing)
        begin = Wtime();
    token = 0;
    do
    {
        memset(&rdplus_response, 0, sizeof(PVFS_sysresp_readdirplus));
        ret = PVFS_sys_readdirplus(
                ref, (!token ? PVFS_READDIR_START : token),
                pvfs_dirent_incount, &credentials,
                (opts->list_long) ? 
                PVFS_ATTR_SYS_ALL : PVFS_ATTR_SYS_ALL_NOSIZE,
                &rdplus_response,
                NULL);
        if(ret < 0)
        {
            PVFS_perror("PVFS_sys_readdir", ret);
            return -1;
        }

        if (dir_version == 0)
        {
            dir_version = rdplus_response.directory_version;
        }
        else if (opts->list_verbose)
        {
            if (dir_version != rdplus_response.directory_version)
            {
                fprintf(stderr, "*** directory changed! listing may "
                        "not be correct\n");
                dir_version = rdplus_response.directory_version;
            }
        }

        if (!printed_dot_info)
        {
            /*
              the list_all option prints files starting with .;
              the almost_all option skips the '.', '..' printing
            */
            print_dot_and_dot_dot_info_if_required(ref);
            printed_dot_info = 1;
        }

        for(i = 0; i < rdplus_response.pvfs_dirent_outcount; i++)
        {
            cur_file = rdplus_response.dirent_array[i].d_name;
            cur_handle = rdplus_response.dirent_array[i].handle;

            print_entry(cur_file, cur_handle, fs_id,
                    &rdplus_response.attr_array[i],
                    rdplus_response.stat_err_array[i],
                    opts);

            PVFS_sys_attr *attr = &rdplus_response.attr_array[i];
            if(attr->objtype == PVFS_TYPE_DIRECTORY && opts->list_recursive)
            {
                int path_len = strlen(start) + strlen(cur_file) + 1;
                current = (subdir *) malloc(sizeof(subdir));

                /* Prevent duplicate slashes in path */
                if(start[strlen(start)-1] == '/')
                {
                    current->path = (char *) malloc(path_len);
                    snprintf(current->path,path_len,"%s%s",start,cur_file);
                }
                else
                {
                    current->path = (char *) malloc(path_len + 1);
                    snprintf(current->path,path_len+1,"%s/%s",start,cur_file);
                }

                /* Update linked list of subdirectories to recurse */
                current->next = NULL;
                if(!head)
                {
                    head = current;
                    tail = current;
                }
                else
                {
                    tail->next = current;
                    tail = current;
                }
            }
        }
        token = rdplus_response.token;

        if (rdplus_response.pvfs_dirent_outcount)
        {
            free(rdplus_response.dirent_array);
            rdplus_response.dirent_array = NULL;
            free(rdplus_response.stat_err_array);
            rdplus_response.stat_err_array = NULL;
            for (i = 0; i < rdplus_response.pvfs_dirent_outcount; i++) {
                if (rdplus_response.attr_array)
                {
                    PVFS_util_release_sys_attr(&rdplus_response.attr_array[i]);
                }
            }
            free(rdplus_response.attr_array);
            rdplus_response.attr_array = NULL;
        }

    } while(rdplus_response.pvfs_dirent_outcount == pvfs_dirent_incount);
    if (do_timing) {
        end = Wtime();
        printf("PVFS_sys_readdirplus took %g msecs\n", 
                (end - begin));
    }

    if (rdplus_response.pvfs_dirent_outcount)
    {
        free(rdplus_response.dirent_array);
        rdplus_response.dirent_array = NULL;
        free(rdplus_response.stat_err_array);
        rdplus_response.stat_err_array = NULL;
        for (i = 0; i < rdplus_response.pvfs_dirent_outcount; i++) {
            if (rdplus_response.attr_array)
            {
                PVFS_util_release_sys_attr(&rdplus_response.attr_array[i]);
            }
        }
        free(rdplus_response.attr_array);
        rdplus_response.attr_array = NULL;
    }

    if (opts->list_recursive)
    {
        current = head;
        while(current)
        {
            printf("\n");
            do_list(full_path,current->path,fs_id,opts);
            current = current->next;
            free(head->path);
            free(head);
            head = current;
        }
    }
    return 0;
}
Пример #21
0
int main(int argc, char **argv)
{
    int ret = -1;
    options_t *user_opts = NULL;
    PVFS_object_ref ref;
    PVFS_credentials credentials;

    user_opts = parse_args(argc, argv);
    if (!user_opts)
    {
        usage(argc, argv);
	return ret;
    }

    ref.fs_id = user_opts->fs_id;
    if (user_opts->remove_object_only)
    {
        ref.handle = user_opts->object_handle;
        if ((ref.handle == PVFS_HANDLE_NULL) ||
            (ref.fs_id == PVFS_FS_ID_NULL))
        {
            fprintf(stderr, "Invalid object reference specified: "
                    "%llu,%d\n", llu(ref.handle), ref.fs_id);
            return ret;
        }
    }
    else
    {
        ref.handle = user_opts->parent_handle;
        if ((ref.handle == PVFS_HANDLE_NULL) ||
            (ref.fs_id == PVFS_FS_ID_NULL))
        {
            fprintf(stderr, "Invalid parent reference specified: "
                    "%llu,%d\n", llu(ref.handle), ref.fs_id);
            return ret;
        }

        if (!user_opts->dirent_name)
        {
            fprintf(stderr, "No dirent name specified under parent "
                    "%llu,%d\n", llu(ref.handle), ref.fs_id);
            return ret;
        }
    }

    ret = PVFS_util_init_defaults();
    if (ret < 0)
    {
	PVFS_perror("PVFS_util_init_defaults", ret);
	return -1;
    }

    PVFS_util_gen_credentials(&credentials);

    if (user_opts->remove_object_only)
    {
        fprintf(stderr,"Attempting to remove object %llu,%d\n",
                llu(ref.handle), ref.fs_id);

        ret = PVFS_mgmt_remove_object(ref, &credentials, NULL);
        if (ret)
        {
            PVFS_perror("PVFS_mgmt_remove_object", ret);
        }
    }
    else
    {
        fprintf(stderr,"Attempting to remove dirent \"%s\" under %llu,%d"
                "\n", user_opts->dirent_name, llu(ref.handle), ref.fs_id);

        ret = PVFS_mgmt_remove_dirent(
            ref, user_opts->dirent_name, &credentials, NULL);
        if (ret)
        {
            PVFS_perror("PVFS_mgmt_remove_dirent", ret);
        }
    }

    free(user_opts);
    return ret;
}
Пример #22
0
int main(int argc, char **argv)
{
    int ret = -1, i = 0;
    char pvfs_path[MAX_NUM_PATHS][PVFS_NAME_MAX];
    PVFS_fs_id fs_id_array[MAX_NUM_PATHS] = {0};
    const PVFS_util_tab* tab;
    struct options* user_opts = NULL;
    char current_dir[PVFS_NAME_MAX] = {0};
    int found_one = 0;

    process_name = argv[0];

    user_opts = parse_args(argc, argv);
    if (!user_opts)
    {
	fprintf(stderr, "Error: failed to parse command line "
                "arguments.\n");
 	usage(argc, argv);
	return(-1);
    }

    tab = PVFS_util_parse_pvfstab(NULL);
    if (!tab)
    {
        fprintf(stderr, "Error: failed to parse pvfstab.\n");
        return(-1);
    }

    for(i = 0; i < MAX_NUM_PATHS; i++)
    {
        memset(pvfs_path[i],0,PVFS_NAME_MAX);
    }

    ret = PVFS_sys_initialize(GOSSIP_NO_DEBUG);
    if (ret < 0)
    {
	PVFS_perror("PVFS_sys_initialize", ret);
	return(-1);
    }

    /* initialize each file system that we found in the tab file */
    for(i = 0; i < tab->mntent_count; i++)
    {
	ret = PVFS_sys_fs_add(&tab->mntent_array[i]);
	if (ret == 0)
        {
	    found_one = 1;
        }
    }

    if (!found_one)
    {
	fprintf(stderr, "Error: could not initialize any file systems "
                "from %s\n", tab->tabfile_name);
	PVFS_sys_finalize();
	return(-1);
    }

    if (user_opts->num_starts == 0)
    {
	snprintf(current_dir,PVFS_NAME_MAX,"%s/",
		 tab->mntent_array[0].mnt_dir);
	user_opts->start[0] = current_dir;
	user_opts->num_starts = 1;
    }

    for(i = 0; i < user_opts->num_starts; i++)
    {
	ret = PVFS_util_resolve(user_opts->start[i],
	    &fs_id_array[i], pvfs_path[i], PVFS_NAME_MAX);
	if ((ret == 0) && (pvfs_path[i][0] == '\0'))
	{
            strcpy(pvfs_path[i], "/");
	}

	if (ret < 0)
	{
	    fprintf(stderr, "Error: could not find file system "
                    "for %s in pvfstab\n", user_opts->start[i]);
	    return(-1);
	}
    }

    for(i = 0; i < user_opts->num_starts; i++)
    {
        char *substr = strstr(user_opts->start[i],pvfs_path[i]);
        char *index = user_opts->start[i];
        char *search = substr; 
        int j = 0;

        /* Keep the mount path info to mimic /bin/ls output */
        if( strncmp(pvfs_path[i],"/",strlen(pvfs_path[i])) )
        {
            /* Get last matching substring */
            while (search) 
            {
                substr = search;
                search = strstr(++search,pvfs_path[i]);
            }
        }
        else /* Root directory case has nothing to match */
        {
            substr = &user_opts->start[i][strlen(user_opts->start[i])-1];
        }

        while ((index != substr) && (substr != NULL))
        {
            index++;
            j++;
        }
        user_opts->start[i][j] = '\0';

        do_list(user_opts->start[i], pvfs_path[i], fs_id_array[i], user_opts);

        if (user_opts->num_starts > 1)
        {
            printf("\n");
        }
    }

    PVFS_sys_finalize();
    free(user_opts);

    return(ret);
}
Пример #23
0
int main(int argc, char **argv)
{
    int ret = -1;
    char str_buf[256] = {0};
    char *filename = (char *)0;
    PVFS_fs_id cur_fs;
    PVFS_sysresp_symlink resp_sym;
    char* entry_name = NULL;
    char *target = NULL;
    PVFS_object_ref parent_refn;
    PVFS_sys_attr attr;
    PVFS_credentials credentials;

    if (argc != 3)
    {
        fprintf(stderr,"Usage: %s filename target\n",argv[0]);
        return ret;
    }
    filename = argv[1];
    target = argv[2];

    ret = PVFS_util_init_defaults();
    if (ret < 0)
    {
	PVFS_perror("PVFS_util_init_defaults", ret);
	return (-1);
    }
    ret = PVFS_util_get_default_fsid(&cur_fs);
    if (ret < 0)
    {
	PVFS_perror("PVFS_util_get_default_fsid", ret);
	return (-1);
    }

    if (PINT_remove_base_dir(filename,str_buf,256))
    {
        if (filename[0] != '/')
        {
            printf("You forgot the leading '/'\n");
        }
        printf("Cannot retrieve link name for creation on %s\n",
               filename);
        return(-1);
    }
    printf("Link to be created is %s\n",str_buf);

    memset(&resp_sym, 0, sizeof(PVFS_sysresp_symlink));
    PVFS_util_gen_credentials(&credentials);

    entry_name = str_buf;
    attr.mask = PVFS_ATTR_SYS_ALL_SETABLE;
    attr.owner = credentials.uid;
    attr.group = credentials.gid;
    attr.perms = 1877;
    attr.atime = attr.ctime = attr.mtime = time(NULL);

    ret = PINT_lookup_parent(filename, cur_fs, &credentials, 
                             &parent_refn.handle);
    if(ret < 0)
    {
	PVFS_perror("PVFS_util_lookup_parent", ret);
	return(-1);
    }
    parent_refn.fs_id = cur_fs;

    ret = PVFS_sys_symlink(entry_name, parent_refn, target,
                           attr, &credentials, &resp_sym, NULL);
    if (ret < 0)
    {
        printf("symlink failed with errcode = %d\n", ret);
        return(-1);
    }
	
    printf("--symlink--\n"); 
    printf("Handle: %lld\n", lld(resp_sym.ref.handle));

    ret = PVFS_sys_finalize();
    if (ret < 0)
    {
        printf("finalizing sysint failed with errcode = %d\n", ret);
        return (-1);
    }

    return(0);
}
Пример #24
0
int test_util_init_perfs(
    PVFS_fs_id cur_fs,
    PVFS_credentials creds,
    int32_t flags,
    int * server_count)
{
    int ret, i;
    int count;

    /* count how many meta servers we have */
    ret = PVFS_mgmt_count_servers(cur_fs, &creds, flags,
                                  server_count);
    if(ret < 0)
    {
        PVFS_perror("PVFS_mgmt_count_servers", ret);
        return(ret);
    }

    count = *server_count;
    /* allocate a 2 dimensional array for statistics */
    perf_matrix = (struct PVFS_mgmt_perf_stat**)malloc(
                      count*sizeof(struct PVFS_mgmt_perf_stat*));
    if(!perf_matrix)
    {
        PVFS_perror("malloc", -1);
        return(-1);
    }
    for(i=0; i<count; i++)
    {
        perf_matrix[i] = (struct PVFS_mgmt_perf_stat *)
                         malloc(HISTORY * sizeof(struct PVFS_mgmt_perf_stat));
        if (perf_matrix[i] == NULL)
        {
            PVFS_perror("malloc", -1);
            return -1;
        }
    }

    /* allocate an array to keep up with what iteration of statistics
     * we need from each server
     */
    next_id_array = (uint32_t *) malloc(count * sizeof(uint32_t));
    if (next_id_array == NULL)
    {
        PVFS_perror("malloc", -1);
        return -1;
    }
    memset(next_id_array, 0, count*sizeof(uint32_t));

    /* allocate an array to keep up with end times from each server */
    end_time_ms_array = (uint64_t *)
                        malloc(count * sizeof(uint64_t));
    if (end_time_ms_array == NULL)
    {
        PVFS_perror("malloc", -1);
        return -1;
    }

    /* build a list of servers to talk to */
    addr_array = (PVFS_BMI_addr_t *)
                 malloc(count * sizeof(PVFS_BMI_addr_t));
    if (addr_array == NULL)
    {
        PVFS_perror("malloc", -1);
        return -1;
    }
    ret = PVFS_mgmt_get_server_array(cur_fs,
                                     &creds,
                                     flags,
                                     addr_array,
                                     &count);
    if (ret < 0)
    {
        PVFS_perror("PVFS_mgmt_get_server_array", ret);
        return -1;
    }

    return 0;

}
Пример #25
0
int main(int argc, char *argv[])
{
   int ret;

   if (argc != 4){
       usage(argv[0]);
       exit(1);
   }

  pvfs2fuse.fs_spec = argv[1];
  pvfs2fuse.scratch_dir = argv[2];

  struct PVFS_sys_mntent *me = &pvfs2fuse.mntent;
  char *cp;
  int cur_server;

  /* the following is copied from PVFS_util_init_defaults()
     in fuse/lib/pvfs2-util.c */

  /* initialize pvfs system interface */
  ret = PVFS_sys_initialize(GOSSIP_NO_DEBUG);
  if (ret < 0)
  {
     return(ret);
  }

  /* the following is copied from PVFS_util_parse_pvfstab()
     in fuse/lib/pvfs2-util.c */
  memset( me, 0, sizeof(pvfs2fuse.mntent) );

  /* Enable integrity checks by default */
  me->integrity_check = 1;
  /* comma-separated list of ways to contact a config server */
  me->num_pvfs_config_servers = 1;

  for (cp=pvfs2fuse.fs_spec; *cp; cp++)
     if (*cp == ',')
        ++me->num_pvfs_config_servers;

  /* allocate room for our copies of the strings */
  me->pvfs_config_servers =
     malloc(me->num_pvfs_config_servers *
            sizeof(*me->pvfs_config_servers));
  if (!me->pvfs_config_servers)
     exit(-1);
  memset(me->pvfs_config_servers, 0,
         me->num_pvfs_config_servers * sizeof(*me->pvfs_config_servers));

  me->mnt_dir = NULL;
  me->mnt_opts = NULL;
  me->encoding = PVFS2_ENCODING_DEFAULT;

  cp = pvfs2fuse.fs_spec;
  cur_server = 0;
  for (;;) {
     char *tok;
     int slashcount;
     char *slash;
     char *last_slash;

     tok = strsep(&cp, ",");
     if (!tok) break;

     slash = tok;
     slashcount = 0;
     while ((slash = index(slash, '/')))
     {
        slash++;
        slashcount++;
     }
     if (slashcount != 3)
     {
        fprintf(stderr,"Error: invalid FS spec: %s\n",
                pvfs2fuse.fs_spec);
        exit(-1);
     }

     /* find a reference point in the string */
     last_slash = rindex(tok, '/');
     *last_slash = '\0';

     /* config server and fs name are a special case, take one 
      * string and split it in half on "/" delimiter
      */
     me->pvfs_config_servers[cur_server] = strdup(tok);
     if (!me->pvfs_config_servers[cur_server])
        exit(-1);

     ++last_slash;

     if (cur_server == 0) {
        me->pvfs_fs_name = strdup(last_slash);
        if (!me->pvfs_fs_name)
           exit(-1);
     } else {
        if (strcmp(last_slash, me->pvfs_fs_name) != 0) {
           fprintf(stderr,
                   "Error: different fs names in server addresses: %s\n",
                   pvfs2fuse.fs_spec);
           exit(-1);
        }
     }
     ++cur_server;
  }

  me->flowproto = FLOWPROTO_DEFAULT;

  ret = PVFS_sys_fs_add(me);
  if( ret < 0 )
  {
      PVFS_perror("Could not add mnt entry", ret);
      return(-1);
  }
  pvfs2fuse.fs_id = me->fs_id;

  signal(SIGALRM, alarmhandler);
  do_test(atol(argv[3]));

  return 0;
}
Пример #26
0
int main(int argc, char **argv)
{
	 PVFS_error pvfs_error;
    int i;
	 char test_file[PATH_MAX];
	 PVFS_sys_attr attr;
	 PVFS_fs_id cur_fs;
	 PVFS_credentials credentials;
	 PVFS_sysresp_lookup lookup_resp;
	 PVFS_sysresp_create create_resp;
	 char basepath[PATH_MAX];
	 
    int rank, nprocs, ret;
    MPI_Info info;

	 MPI_Init(&argc, &argv);
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
    MPI_Comm_size(MPI_COMM_WORLD, &nprocs);

    parse_args(argc, argv);

    /* provide hints if you want  */
    info = MPI_INFO_NULL;

	 if (rank == 0)
	 {
		  printf("\nprocs: %d\nops: %d\n===========\n", nprocs, opt_nfiles);
	 }

	 ret = PVFS_util_init_defaults();
	 if(ret != 0)
	 {
		  PVFS_perror("PVFS_util_init_defaults", ret);
		  return ret;
	 }

	 ret = PVFS_util_resolve(opt_basedir, &cur_fs, basepath, PATH_MAX);
	 if(ret != 0)
	 {
		  PVFS_perror("PVFS_util_resolve", ret);
		  return ret;
	 }

	 PVFS_util_gen_credentials(&credentials);

	 pvfs_error = PVFS_sys_lookup(
		  cur_fs, basepath, &credentials, &lookup_resp, 
		  PVFS2_LOOKUP_LINK_NO_FOLLOW);
	 if(pvfs_error != 0)
	 {
		  PVFS_perror("PVFS_sys_lookup", pvfs_error);
		  return PVFS_get_errno_mapping(pvfs_error);
	 }

	 attr.mask = PVFS_ATTR_SYS_ALL_SETABLE;
	 attr.owner = credentials.uid;
	 attr.group = credentials.gid;
	 attr.perms = 1877;
	 attr.atime = attr.ctime = attr.mtime = time(NULL);

	 /* synchronize with other clients (if any) */
	 MPI_Barrier(MPI_COMM_WORLD);

	 for(i = 0; i < opt_nfiles; ++i)
    {
		  memset(test_file, 0, PATH_MAX);
		  snprintf(test_file, PATH_MAX, "testfile.%d.%d", rank, i);

		  test_util_start_timing();
		  pvfs_error = PVFS_sys_create(test_file, lookup_resp.ref,
												 attr, &credentials,
												 NULL, NULL, &create_resp);
		  test_util_stop_timing();
		  if(pvfs_error != 0)
		  {
				PVFS_perror("PVFS_sys_craete", pvfs_error);
				return PVFS_get_errno_mapping(pvfs_error);
		  }

		  test_util_print_timing(rank);
	 }
	 
	 for(i = 0; i < opt_nfiles; ++i)
	 {
		  memset(test_file, 0, PATH_MAX);
		  snprintf(test_file, PATH_MAX, "testfile.%d.%d", rank, i);

		  pvfs_error = PVFS_sys_remove(test_file, lookup_resp.ref, &credentials);
		  if(pvfs_error != 0)
		  {
				fprintf(stderr, "Failed to remove: %s\n", test_file);
				PVFS_perror("PVFS_sys_remove", pvfs_error);
				return PVFS_get_errno_mapping(pvfs_error);
		  }
	 }

	 MPI_Finalize();
    return 0;
}
Пример #27
0
int generic_open(file_object *obj, PVFS_credentials *credentials,
                        int nr_datafiles, PVFS_size strip_size, 
                        char *srcname, int open_type)
{
    struct stat stat_buf;
    PVFS_sysresp_lookup resp_lookup;
    PVFS_sysresp_getattr resp_getattr;
    PVFS_sysresp_create resp_create;
    PVFS_object_ref parent_ref;
    PVFS_sys_dist   *new_dist;
    int ret = -1;
    char *entry_name;		    /* name of the pvfs2 file */
    char str_buf[PVFS_NAME_MAX];    /* basename of pvfs2 file */
 
    if (obj->fs_type == UNIX_FILE)
    {
        memset(&stat_buf, 0, sizeof(struct stat));

        stat(obj->u.ufs.path, &stat_buf);
	if (open_type == OPEN_SRC)
	{
	    if (S_ISDIR(stat_buf.st_mode))
	    {
		fprintf(stderr, "Source cannot be a directory\n");
		return(-1);
	    }
	    obj->u.ufs.fd = open(obj->u.ufs.path, O_RDONLY);
            obj->u.ufs.mode = (int)stat_buf.st_mode;
	}
	else
	{
	    if (S_ISDIR(stat_buf.st_mode))
	    {
		if (srcname)
                {
		    strncat(obj->u.ufs.path, basename(srcname), NAME_MAX);
                }
		else
		{
		    fprintf(stderr, "cannot find name for "
                            "destination. giving up\n");
		    return(-1);
		}
	    }
	    obj->u.ufs.fd = open(obj->u.ufs.path,
                               O_WRONLY|O_CREAT|O_LARGEFILE|O_TRUNC,0666);
	}
	if (obj->u.ufs.fd < 0)
	{
	    perror("open");
	    fprintf(stderr, "could not open %s\n", obj->u.ufs.path);
	    return (-1);
	}
    }
    else
    {
	entry_name = str_buf;
	/* it's a PVFS2 file */
	if (strcmp(obj->u.pvfs2.pvfs2_path, "/") == 0)
	{
	    /* special case: PVFS2 root file system, so stuff the end of
	     * srcfile onto pvfs2_path */
	    char *segp = NULL, *prev_segp = NULL;
	    void *segstate = NULL;
	    
	    /* can only perform this special case if we know srcname */
	    if (srcname == NULL)
	    {
		fprintf(stderr, "unable to guess filename in "
                        "toplevel PVFS2\n");
		return -1;
	    }

	    memset(&resp_lookup, 0, sizeof(PVFS_sysresp_lookup));
	    ret = PVFS_sys_lookup(obj->u.pvfs2.fs_id, obj->u.pvfs2.pvfs2_path,
                                  credentials, &resp_lookup,
                                  PVFS2_LOOKUP_LINK_FOLLOW, hints);
	    if (ret < 0)
	    {
		PVFS_perror("PVFS_sys_lookup", ret);
		return (-1);
	    }
	    parent_ref.handle = resp_lookup.ref.handle;
	    parent_ref.fs_id = resp_lookup.ref.fs_id;

	    while (!PINT_string_next_segment(srcname, &segp, &segstate))
	    {
		prev_segp = segp;
	    }
	    entry_name = prev_segp; /* see... points to basename of srcname */
	}
	else /* given either a pvfs2 directory or a pvfs2 file */
	{
	    /* get the absolute path on the pvfs2 file system */
	    
	    /*parent_ref.fs_id = obj->pvfs2.fs_id; */

	    if (PINT_remove_base_dir(obj->u.pvfs2.pvfs2_path,str_buf, 
                                     PVFS_NAME_MAX))
	    {
		if(obj->u.pvfs2.pvfs2_path[0] != '/')
		{
		    fprintf(stderr, "Error: poorly formatted path.\n");
		}
		fprintf(stderr, "Error: cannot retrieve entry name for "
			"creation on %s\n", obj->u.pvfs2.user_path);
		return(-1);
	    }
	    ret = PINT_lookup_parent(obj->u.pvfs2.pvfs2_path, 
                                     obj->u.pvfs2.fs_id, credentials,
                                     &parent_ref.handle);
	    if (ret < 0)
	    {
		PVFS_perror("PVFS_util_lookup_parent", ret);
		return (-1);
	    }
	    else /* parent lookup succeeded. if the pvfs2 path is just a
		    directory, use basename of src for the new file */
	    {
		int len = strlen(obj->u.pvfs2.pvfs2_path);
		if (obj->u.pvfs2.pvfs2_path[len - 1] == '/')
		{
		    char *segp = NULL, *prev_segp = NULL;
		    void *segstate = NULL;

		    if (srcname == NULL)
		    {
			fprintf(stderr, "unable to guess filename\n");
			return(-1);
		    }
		    while (!PINT_string_next_segment(srcname, 
				&segp, &segstate))
		    {
			prev_segp = segp;
		    }
		    strncat(obj->u.pvfs2.pvfs2_path, prev_segp, PVFS_NAME_MAX);
		    entry_name = prev_segp;
		}
		parent_ref.fs_id = obj->u.pvfs2.fs_id;
	    }
	}

	memset(&resp_lookup, 0, sizeof(PVFS_sysresp_lookup));
	ret = PVFS_sys_ref_lookup(parent_ref.fs_id, entry_name,
                                  parent_ref, credentials, &resp_lookup,
                                  PVFS2_LOOKUP_LINK_FOLLOW, hints);

        if ((ret == 0) && (open_type == OPEN_SRC))
        {
            memset(&resp_getattr, 0, sizeof(PVFS_sysresp_getattr));
            ret = PVFS_sys_getattr(resp_lookup.ref, PVFS_ATTR_SYS_ALL_NOHINT,
                                   credentials, &resp_getattr, hints);
            if (ret)
            {
                fprintf(stderr, "Failed to do pvfs2 getattr on %s\n",
                        entry_name);
                return -1;
            }

            if (resp_getattr.attr.objtype == PVFS_TYPE_SYMLINK)
            {
                free(resp_getattr.attr.link_target);
                resp_getattr.attr.link_target = NULL;
            }
            obj->u.pvfs2.perms = resp_getattr.attr.perms;
            memcpy(&obj->u.pvfs2.attr, &resp_getattr.attr,
                   sizeof(PVFS_sys_attr));
            obj->u.pvfs2.attr.mask = PVFS_ATTR_SYS_ALL_SETABLE;
        }

	/* at this point, we have looked up the file in the parent directory.
	 * . If we found something, and we are the SRC, then we're done. 
	 * . We will maintain the semantic of pvfs2-import and refuse to
	 *   overwrite existing PVFS2 files, so if we found something, and we
	 *   are the DEST, then that's an error.  
	 * . Otherwise, we found nothing and we will create the destination. 
	 */
	if (open_type == OPEN_SRC)
	{
	    if (ret == 0)
	    {
		obj->u.pvfs2.ref = resp_lookup.ref;
		return 0;
	    }
	    else
	    {
		PVFS_perror("PVFS_sys_ref_lookup", ret);
		return (ret);
	    }
	}
	if (open_type == OPEN_DEST)
	{
	    if (ret == 0)
	    {
                obj->u.pvfs2.ref = resp_lookup.ref;
		return 0;
	    } 
	    else 
	    {
                memset(&stat_buf, 0, sizeof(struct stat));

                /* preserve permissions doing a unix => pvfs2 copy */
                stat(srcname, &stat_buf);
		make_attribs(&(obj->u.pvfs2.attr), credentials, nr_datafiles,
                             (int)stat_buf.st_mode);
                if (strip_size > 0) {
                    new_dist = PVFS_sys_dist_lookup("simple_stripe");
                    ret = PVFS_sys_dist_setparam(new_dist, "strip_size", &strip_size);
                    if (ret < 0)
                    {
                       PVFS_perror("PVFS_sys_dist_setparam", ret); 
		       return -1; 
                    }
                }
                else {
                    new_dist=NULL;
                }
            
		ret = PVFS_sys_create(entry_name, parent_ref, 
                                      obj->u.pvfs2.attr, credentials,
                                      new_dist, &resp_create, NULL, hints);
		if (ret < 0)
		{
		    PVFS_perror("PVFS_sys_create", ret); 
		    return -1; 
		}
		obj->u.pvfs2.ref = resp_create.ref;
	    }
	}
    }
    return 0;
}
Пример #28
0
static int do_stat(const char             * pszFile,
                   const char             * pszRelativeFile, 
                   const PVFS_fs_id         fs_id, 
                   const PVFS_credentials * credentials,
                   const struct options   * opts)
{
   int                  ret = 0;
   PVFS_sysresp_lookup  lk_response;
   PVFS_object_ref      ref;
   PVFS_sysresp_getattr getattr_response;

   /* Initialize memory */
   memset(&lk_response,     0, sizeof(lk_response));
   memset(&ref,             0, sizeof(ref));
   memset(&getattr_response,0, sizeof(getattr_response));
   

   /* Do we want to follow if the file is a symbolic link */
   if(opts->nFollowLink)
   {
      ret = PVFS_sys_lookup(fs_id, 
                            (char *) pszRelativeFile, 
                            (PVFS_credentials *) credentials, 
                            &lk_response, 
                            PVFS2_LOOKUP_LINK_FOLLOW, NULL);
   }
   else
   {
      ret = PVFS_sys_lookup(fs_id, 
                            (char *) pszRelativeFile, 
                            (PVFS_credentials *) credentials, 
                            &lk_response, 
                            PVFS2_LOOKUP_LINK_NO_FOLLOW, NULL);
   }
   
   if(ret < 0)
   {
      if(opts->nVerbose)
      {
         fprintf(stderr, "PVFS_sys_lookup call on [%s]\n", pszRelativeFile);
      }
      PVFS_perror("PVFS_sys_lookup", ret);
      return -1;
   }

   ref.handle = lk_response.ref.handle;
   ref.fs_id  = fs_id;
   
   ret = PVFS_sys_getattr(ref, 
                          PVFS_ATTR_SYS_ALL_NOHINT,
                          (PVFS_credentials *) credentials, 
                          &getattr_response, NULL);

   if(ret < 0)
   {                          
      PVFS_perror("PVFS_sys_getattr", ret);
      return -1;
   }

   /* Display the attributes for the file */
   print_stats(&ref,
               pszFile, 
               pszRelativeFile, 
               &(getattr_response.attr));
   
   return(0);
}
Пример #29
0
int main(int argc,char **argv)
{
    int ret = -1;
    char str_buf[256] = {0};
    char *filename = (char *)0;
    PVFS_fs_id cur_fs;
    char* entry_name;
    PVFS_object_ref parent_refn;
    PVFS_credentials credentials;

    if (argc != 2)
    {
        printf("usage: %s file_to_remove\n", argv[0]);
        return 1;
    }
    filename = argv[1];

    ret = PVFS_util_init_defaults();
    if (ret < 0)
    {
	PVFS_perror("PVFS_util_init_defaults", ret);
	return (-1);
    }
    ret = PVFS_util_get_default_fsid(&cur_fs);
    if (ret < 0)
    {
	PVFS_perror("PVFS_util_get_default_fsid", ret);
	return (-1);
    }

    if (PINT_remove_base_dir(filename,str_buf,256))
    {
        if (filename[0] != '/')
        {
            printf("You forgot the leading '/'\n");
        }
        printf("Cannot retrieve entry name for creation on %s\n",
               filename);
        return(-1);
    }
    printf("File to be removed is %s\n",str_buf);

    entry_name = str_buf;

    PVFS_util_gen_credentials(&credentials);
    ret = PINT_lookup_parent(filename, cur_fs, &credentials,
                             &parent_refn.handle);
    if(ret < 0)
    {
	PVFS_perror("PVFS_util_lookup_parent", ret);
	return(-1);
    }
    parent_refn.fs_id = cur_fs;

    ret = PVFS_sys_remove(entry_name, parent_refn, &credentials, NULL);
    if (ret < 0)
    {
        PVFS_perror("remove failed ", ret);
        return(-1);
    }

    printf("===================================\n");
    printf("file named %s has been removed.\n", filename);

    //close it down
    ret = PVFS_sys_finalize();
    if (ret < 0)
    {
        printf("finalizing sysint failed with errcode = %d\n", ret);
        return (-1);
    }

    return(0);
}
Пример #30
0
int main(int argc, char **argv)
{
   int               ret          = -1,
                     i            =  0;
   char           ** ppszPvfsPath = NULL;
   PVFS_fs_id     *  pfs_id       = NULL;
   PVFS_credentials  credentials;
   struct options    user_opts;

   /* Initialize any memory */
   memset(&user_opts,   0, sizeof(user_opts));
   memset(&credentials, 0, sizeof(credentials));
   
   ret = parse_args(argc, argv, &user_opts);
   if(ret < 0)
   {
      fprintf(stderr, "Error: failed to parse command line arguments.\n");
      usage(argc, argv);
      return(-1);
   }

   if(user_opts.nVerbose)
   {
      fprintf(stdout, "Starting pvfs2-stat\n");
   }
   
   /* Allocate space to hold the relative pvfs2 path & fs_id for each 
    * requested file 
    */
   ppszPvfsPath = (char **)calloc(user_opts.nNumFiles, sizeof(char *));
   
   if(ppszPvfsPath == NULL)
   {
      fprintf(stderr, "Unable to allocate memory\n");
      return(-1);
   }
   
    /* Allocate enough space to hold file system id for each directory */
   pfs_id = (PVFS_fs_id *)calloc(user_opts.nNumFiles, sizeof(PVFS_fs_id));
   
   if(pfs_id == NULL)
   {
      fprintf(stderr, "Unable to allocate memory\n");
      return(-1);
   }
   
   
   for(i = 0; i < user_opts.nNumFiles; i++)
   {
      ppszPvfsPath[i] = (char *)calloc(PVFS_NAME_MAX, sizeof(char));
      if(ppszPvfsPath[i] == NULL)
      {
         fprintf(stderr, "Unable to allocate memory\n");
         return(-1);
      }
   }

   ret = PVFS_util_init_defaults();
   if(ret < 0)
   {
      PVFS_perror("PVFS_util_init_defaults", ret);
      return(-1);
   }
   
   /* Let's verify that all the given files reside on a PVFS2 filesytem */
   for(i = 0; i < user_opts.nNumFiles; i++)
   {
      ret = PVFS_util_resolve(user_opts.pszFiles[i], 
                              &pfs_id[i], 
                              ppszPvfsPath[i], 
                              PVFS_NAME_MAX);

      if (ret < 0)
      {
         fprintf(stderr, "Error: could not find file system for %s\n", 
                 user_opts.pszFiles[i]);
         return(-1);
      }
   }

   /* We will re-use the same credentials for each call */
   PVFS_util_gen_credentials(&credentials);

   for(i = 0; i < user_opts.nNumFiles; i++)
   {
      ret = do_stat(user_opts.pszFiles[i], 
                    ppszPvfsPath[i], 
                    pfs_id[i], 
                    &credentials,
                    &user_opts);
      if(ret != 0)
      {
         fprintf(stderr, "Error stating [%s]\n", user_opts.pszFiles[i]);
      }
   }

   PVFS_sys_finalize();

   /* Deallocate any allocated memory */
   if(user_opts.pszFiles != NULL)
   {
      free(user_opts.pszFiles);
   }
   
   if(ppszPvfsPath != NULL)
   {
       for(i=0;i<user_opts.nNumFiles;i++)
       {
          if(ppszPvfsPath[i] != NULL)
          {
             free(ppszPvfsPath[i]);
          }
       }
   
      free(ppszPvfsPath);
   }
   
   if(pfs_id != NULL)
   {
      free(pfs_id);
   }

   return(0);
}