Пример #1
0
static int test_write_beyond(void){
    PVFS_sysresp_lookup resp_lk;
    PVFS_Request req_io;
    PVFS_Request req_mem;
    PVFS_sysresp_io resp_io;
    PVFS_credentials credentials;
    char *filename;
    char *io_buffer;
    int fs_id, ret, i;
    PVFS_size oldsize;
    PVFS_sysresp_getattr resp;
    PVFS_offset file_req_offset = 0;
    uint32_t attrmask;

    attrmask = PVFS_ATTR_SYS_ALL_NOSIZE;

    filename = (char *) malloc(sizeof(char) * 100);
    filename = strcpy(filename, "name");

    memset(&req_io, 0, sizeof(PVFS_Request));
    memset(&req_mem, 0, sizeof(PVFS_Request));
    memset(&resp_io, 0, sizeof(PVFS_sysresp_io));

    memset(&resp_lk, 0, sizeof(PVFS_sysresp_lookup));

    PVFS_util_gen_credentials(&credentials);

    if (initialize_sysint() < 0)
    {
        debug_printf("UNABLE TO INIT THE SYSTEM INTERFACE\n");
        return -1;
    }
    fs_id = pvfs_helper.fs_id;

    ret = PVFS_sys_lookup(fs_id, filename, &credentials,
                          &resp_lk, PVFS2_LOOKUP_LINK_NO_FOLLOW);
    if (ret < 0)
    {
        debug_printf("test_pvfs_datatype_hvector: lookup failed "
                     "on %s\n", filename);
    }
    if((ret = PVFS_sys_getattr(resp_lk.ref, attrmask, &credentials, &resp)) < 0)
	return ret;
    io_buffer = malloc(sizeof(char)*(size_t)resp.attr.size+100);

    /* req_io.size = resp_io.size + 100; */
    oldsize = resp.attr.size +100;
    for(i = 0; i < oldsize; i++)
    {
	io_buffer[i] = 'a';
    }
    ret = PVFS_sys_write(resp_lk.ref, req_io, file_req_offset, io_buffer, req_mem,
                           &credentials, &resp_io);
    if(ret < 0){
	debug_printf("write failed on %s\n", filename);
    }

/*     finalize_sysint(); */
    return ret;
}
Пример #2
0
/* Preconditions: none
 * Parameters: none
 * Postconditions: returns error from getattr
 * Has 2 Test Cases
 */
static int test_getattr(void)
{
    int fs_id, ret;
    PVFS_credentials credentials;
    PVFS_object_ref pinode_refn;
    uint32_t attrmask;
    PVFS_sysresp_lookup resp_lookup;
    PVFS_sysresp_getattr resp_getattr;
    char *name;

    ret = -2;
    name = (char *) malloc(sizeof(char) * 100);
    name = strcpy(name, "name");

    fs_id = 9;

    PVFS_util_gen_credentials(&credentials);

    if ((ret = PVFS_sys_lookup(
             fs_id, name, &credentials,
             &resp_lookup, PVFS2_LOOKUP_LINK_NO_FOLLOW)) < 0)
    {
	fprintf(stderr, "lookup failed %d\n", ret);
	return ret;
    }

    pinode_refn = resp_lookup.ref;
    attrmask = PVFS_ATTR_SYS_ALL_NOSIZE;

    ret = PVFS_sys_getattr(pinode_refn, attrmask, &credentials, &resp_getattr);
    return ret;
}
Пример #3
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);
        }
    }
}
Пример #4
0
static int test_get_set_attr_empty(int testcase)
{
    int fs_id, ret;
    PVFS_credentials credentials;
    PVFS_object_ref pinode_refn;
    PVFS_sysresp_lookup resp_lookup;
    PVFS_sys_attr attr;
    PVFS_sysresp_getattr resp;
    uint32_t attrmask;
    char *name;

    ret = -2;
    name = (char *) malloc(sizeof(char) * 100);
    name = strcpy(name, "nofileyea");

    if (initialize_sysint() < 0)
    {
        debug_printf("ERROR UNABLE TO INIT SYSTEM INTERFACE\n");
        return -1;
    }
    fs_id = pvfs_helper.fs_id;

    PVFS_util_gen_credentials(&credentials);
    if ((ret = PVFS_sys_lookup(
             fs_id, name, &credentials,
             &resp_lookup, PVFS2_LOOKUP_LINK_NO_FOLLOW)) < 0)
    {
        fprintf(stderr, "lookup failed which it should but keep going\n");
	
       /* return ret; */
    }

    pinode_refn = resp_lookup.ref;
    attr.mask = PVFS_ATTR_SYS_ALL_NOSIZE;
    attr.owner = credentials.uid;
    attr.group = credentials.gid;
    attr.perms = 1877;
    attr.atime = attr.mtime = attr.ctime = 0xdeadbeef;
    attr.objtype = PVFS_TYPE_METAFILE;

    attrmask = PVFS_ATTR_SYS_ALL_NOSIZE;

    switch(testcase){
	case 0:
	    ret = PVFS_sys_setattr(pinode_refn, attr, &credentials);
	    break;
	case 1:
	    ret = PVFS_sys_getattr(pinode_refn, attrmask, &credentials, &resp);
	    break;
    }

    return ret;
}
Пример #5
0
int traverse_directory_tree(PVFS_fs_id cur_fs,
			    struct handlelist *hl,
			    PVFS_BMI_addr_t *addr_array,
			    int server_count,
			    PVFS_credentials *creds)
{
    int ret, server_idx = 0;
    PVFS_sysresp_lookup lookup_resp;
    PVFS_sysresp_getattr getattr_resp;
    PVFS_object_ref pref;

    ret = PVFS_sys_lookup(cur_fs,
			  "/",
			  creds,
			  &lookup_resp,
			  PVFS2_LOOKUP_LINK_NO_FOLLOW, NULL);
    assert(ret == 0);

    pref = lookup_resp.ref;

    PVFS_sys_getattr(pref,
		     PVFS_ATTR_SYS_ALL_NOHINT,
		     creds,
		     &getattr_resp, NULL);

    assert(getattr_resp.attr.objtype == PVFS_TYPE_DIRECTORY);

    ret = handlelist_find_handle(hl, pref.handle, &server_idx);
    assert(ret == 0);

    handlelist_remove_handle(hl, pref.handle, server_idx);

    ret = match_dirdata(hl,
			NULL /* optional second handle list */,
			pref,
			creds);
    if (ret != 0) {
	assert(0);
    }

    descend(cur_fs, hl, NULL, pref, creds);

    return 0;
}
Пример #6
0
void ADIOI_PVFS2_Fcntl(ADIO_File fd, int flag, ADIO_Fcntl_t *fcntl_struct,
		       int *error_code)
{
    int ret;
    ADIOI_PVFS2_fs *pvfs_fs;
    PVFS_sysresp_getattr resp_getattr;
    static char myname[] = "ADIOI_PVFS2_FCNTL";

    pvfs_fs = (ADIOI_PVFS2_fs*)fd->fs_ptr;

    switch(flag) {
    case ADIO_FCNTL_GET_FSIZE:
	ret = PVFS_sys_getattr(pvfs_fs->object_ref, PVFS_ATTR_SYS_SIZE, 
		&(pvfs_fs->credentials), &resp_getattr);
	if (ret != 0 ) {
	    /* --BEGIN ERROR HANDLING-- */
	    *error_code = MPIO_Err_create_code(MPI_SUCCESS,
					       MPIR_ERR_RECOVERABLE,
					       myname, __LINE__,
					       ADIOI_PVFS2_error_convert(ret),
					       "Error in PVFS_sys_getattr", 0);
	    /* --END ERROR HANDLING-- */
	}
	else {
	    *error_code = MPI_SUCCESS;
	}
	fcntl_struct->fsize = resp_getattr.attr.size;
	return;

    case ADIO_FCNTL_SET_DISKSPACE:
	ADIOI_GEN_Prealloc(fd, fcntl_struct->diskspace, error_code);
	break;

    /* --BEGIN ERROR HANDLING-- */
    case ADIO_FCNTL_SET_ATOMICITY:
    default:
	*error_code = MPIO_Err_create_code(MPI_SUCCESS,
					   MPIR_ERR_RECOVERABLE,
					   myname, __LINE__,
					   MPI_ERR_ARG,
					   "**flag", "**flag %d", flag);
    /* --END ERROR HANDLING-- */
    }
}
Пример #7
0
/**
 * PVFSIOStore::Readlink:  read symbolic link
 *
 * @param link the link to read
 * @param buf the place the write the result
 * @param the size of the result buffer
 * @param readlen return size
 * @return PLFS_SUCCESS or PLFS_E* on error
 */
plfs_error_t PVFSIOStore::Readlink(const char *link, char *buf, size_t bufsize,
                                   ssize_t *readlen) {
    char *cpath;
    PVFS_object_ref ref;
    PVFS_credentials creds;
    size_t l;
    int nev, pev, cpy;
    PVFS_sysresp_getattr resp;

    cpath = pvfsios_dedup_slash(link);
    if (cpath) {
        nev = pvfsios_get_object(this->fsid, cpath, &ref, &creds,
                                 PVFS2_LOOKUP_LINK_NO_FOLLOW);
        free(cpath);
    } else {
        nev = -ENOMEM;
    }
    
    *readlen = -1;
    if (nev < 0) {
        return errno_to_plfs_error(-nev);
    }
    
    pev = PVFS_sys_getattr(ref, PVFS_ATTR_SYS_ALL_NOHINT, &creds, &resp);
    if (pev < 0) {
        return errno_to_plfs_error(-get_err(pev));
    }

    if (resp.attr.objtype != PVFS_TYPE_SYMLINK) {
        nev = -EINVAL;
    } else {
        l = strlen(resp.attr.link_target);
        cpy = (l < bufsize - 1) ? l : bufsize;
        memcpy(buf, resp.attr.link_target, cpy);
        buf[cpy] = 0;
        *readlen = l;   /* need to return length */
        /* nev still zero from get_obj call, no need to reset */
    }

    /* XXX: pvfs2fuse didn't release, memory leak? */
    PVFS_util_release_sys_attr(&resp.attr);  /* frees memory chained off ats */

    return errno_to_plfs_error(-nev);
}
Пример #8
0
void cull_leftovers(PVFS_fs_id cur_fs,
		    struct handlelist *hl_all,
		    PVFS_BMI_addr_t *addr_array,
		    PVFS_credentials *creds)
{
    int ret;
    int server_idx;
    PVFS_handle handle;

    /* recall that return_handle removes from list */
    while (handlelist_return_handle(hl_all,
				    &handle,
				    &server_idx) == 0)
    {
	PVFS_object_ref handle_ref;
	PVFS_sysresp_getattr getattr_resp;

	handle_ref.handle = handle;
	handle_ref.fs_id  = cur_fs;

	ret = PVFS_sys_getattr(handle_ref,
			       PVFS_ATTR_SYS_ALL_NOHINT,
			       creds,
			       &getattr_resp, NULL);
	if (ret) {
	    printf("warning: problem calling getattr on %llu\n",
		   llu(handle));
	    getattr_resp.attr.objtype = 0;
	}

	/* metafile and directory handles should have been removed
	 * in the previous pass.
	 */
	assert(getattr_resp.attr.objtype != PVFS_TYPE_METAFILE);
	assert(getattr_resp.attr.objtype != PVFS_TYPE_DIRECTORY);

	ret = remove_object(handle_ref,
			    getattr_resp.attr.objtype,
			    creds);
	assert(ret == 0);
    }
}
Пример #9
0
int descend(PVFS_fs_id cur_fs,
	    struct handlelist *hl,
	    struct handlelist *alt_hl,
	    PVFS_object_ref dir_ref,
	    PVFS_credentials *creds)
{
    int i, count;
    PVFS_ds_position token; 
    PVFS_sysresp_readdir readdir_resp;
    PVFS_sysresp_getattr getattr_resp;
    PVFS_object_ref entry_ref = {0, 0};

    count = 64;

    token = 0;
    do {
        memset(&readdir_resp, 0, sizeof(PVFS_sysresp_readdir));
        PVFS_sys_readdir(dir_ref,
                         (!token ? PVFS_READDIR_START : token),
                         count,
                         creds,
                         &readdir_resp, NULL);

        for (i = 0; i < readdir_resp.pvfs_dirent_outcount; i++)
        {
            int server_idx = 0, ret, in_main_list = 0, in_alt_list = 0;
            char *cur_file;
            PVFS_handle cur_handle;

            cur_handle = readdir_resp.dirent_array[i].handle;
            cur_file   = readdir_resp.dirent_array[i].d_name;

            entry_ref.handle = cur_handle;
            entry_ref.fs_id  = cur_fs;

            if (handlelist_find_handle(hl, cur_handle, &server_idx) == 0)
            {
                in_main_list = 1;
            }
            if (!in_main_list &&
                alt_hl &&
                handlelist_find_handle(alt_hl,
                                       cur_handle,
                                       &server_idx) == 0)
            {
                in_alt_list = 1;
            }
            if (!in_main_list && !in_alt_list) {
                ret = remove_directory_entry(dir_ref,
                                             entry_ref,
                                             cur_file,
                                             creds);
                assert(ret == 0);

                continue;
            }

            ret = PVFS_sys_getattr(entry_ref,
                                   PVFS_ATTR_SYS_ALL_NOHINT,
                                   creds,
                                   &getattr_resp, NULL);
            if (ret != 0) {
                ret = remove_directory_entry(dir_ref,
                                             entry_ref,
                                             cur_file,
                                             creds);
                assert(ret == 0);
                /* handle removed from list below */
            }
            else
            {
                switch (getattr_resp.attr.objtype)
                {
                    case PVFS_TYPE_METAFILE:
                        if (verify_datafiles(cur_fs,
                                             hl,
                                             alt_hl,
                                             entry_ref,
                                             getattr_resp.attr.dfile_count,
                                             creds) < 0)
                        {
                            /* not recoverable; remove */
                            printf("* File %s (%llu) is not recoverable.\n",
                                   cur_file,
                                   llu(cur_handle));

                            /* verify_datafiles() removed the datafiles */
                            ret = remove_object(entry_ref,
                                                getattr_resp.attr.objtype,
                                                creds);
                            assert(ret == 0);

                            ret = remove_directory_entry(dir_ref,
                                                         entry_ref,
                                                         cur_file,
                                                         creds);
                            assert(ret == 0);
                        }
                        
                        break;
                    case PVFS_TYPE_DIRECTORY:
                        ret = match_dirdata(hl,
                                            alt_hl,
                                            entry_ref,
                                            creds);
                        if (ret != 0)
                        {
                            printf("* Directory %s (%llu) is missing DirData.\n",
                                   cur_file,
                                   llu(cur_handle));

                            ret = remove_object(entry_ref,
                                                getattr_resp.attr.objtype,
                                                creds);
                            assert(ret == 0);

                            ret = remove_directory_entry(dir_ref,
                                                         entry_ref,
                                                         cur_file,
                                                         creds);
                            break;
                        }

                        if (in_main_list) {
                            ret = descend(cur_fs,
                                          hl,
                                          alt_hl,
                                          entry_ref,
                                          creds);
                            assert(ret == 0);
                        }
                        break;
                    case PVFS_TYPE_SYMLINK:
                        /* nothing to do */
                        break;
                    default:
                        /* whatever this is, blow it away now. */
                        ret = remove_object(entry_ref,
                                            getattr_resp.attr.objtype,
                                            creds);
                        assert(ret == 0);
                        
                        ret = remove_directory_entry(dir_ref,
                                                     entry_ref,
                                                     cur_file,
                                                     creds);
                        assert(ret == 0);
                        break;
                }
            }

            /* remove from appropriate handle list */
            if (in_alt_list) {
                handlelist_remove_handle(alt_hl, cur_handle, server_idx);
            }
            else if (in_main_list) {
                handlelist_remove_handle(hl, cur_handle, server_idx);
            }
        }
        token = readdir_resp.token;
        if (readdir_resp.pvfs_dirent_outcount)
        {
            free(readdir_resp.dirent_array);
            readdir_resp.dirent_array = NULL;
        }
    } while (readdir_resp.pvfs_dirent_outcount == count);

    if (readdir_resp.pvfs_dirent_outcount)
    {
        free(readdir_resp.dirent_array);
        readdir_resp.dirent_array = NULL;
    }
    return 0;
}
Пример #10
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);
}
Пример #11
0
static int test_truncat(int testcase)
{
    int ret, fs_id;
    PVFS_credentials credentials;
    PVFS_sysresp_lookup resp_look;
    PVFS_size size = 0, oldsize = 0;
    PVFS_sysresp_getattr resp;
    uint32_t attrmask;
    char *filename;

    attrmask = PVFS_ATTR_SYS_ALL_NOSIZE;

    filename = (char *) malloc(sizeof(char) * 100);
    filename = strcpy(filename, "altrun");

    PVFS_util_gen_credentials(&credentials);

    if (initialize_sysint() < 0)
    {
        debug_printf("UNABLE TO INIT THE SYSTEM INTERFACE\n");
        return -1;
    }
    fs_id = pvfs_helper.fs_id;

    /* get file */
    ret = PVFS_sys_lookup(fs_id, filename, &credentials,
                          &resp_look, PVFS2_LOOKUP_LINK_NO_FOLLOW);
    if (ret < 0)
    {
        printf("Lookup failed with errcode = %d\n", ret);
        return (-1);
    }
    if((ret = PVFS_sys_getattr(resp_look.ref, attrmask, &credentials, &resp)) < 0)
	return ret;

    oldsize = resp.attr.size;

    switch(testcase)
    {
    case 0:
	size = 1000000;
	ret = PVFS_sys_truncate(resp_look.ref, size, &credentials);
	break;
    case 1:
	size = 100000;
	ret = PVFS_sys_truncate(resp_look.ref, size, &credentials);
	break;
    case 2:
	size = 5;
	ret = PVFS_sys_truncate(resp_look.ref, size, &credentials);
	break;
    }

    /* get file */
    ret = PVFS_sys_lookup(fs_id, filename, &credentials,
                          &resp_look, PVFS2_LOOKUP_LINK_NO_FOLLOW);
    if (ret < 0)
    {
        printf("Lookup failed with errcode = %d\n", ret);
        return (-1);
    }
    if((ret = PVFS_sys_getattr(resp_look.ref, attrmask, &credentials, &resp)) < 0)
	return ret;

    if(resp.attr.size != (oldsize - size))
    {
	return -1;
    }
    return 0;
}
Пример #12
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;
}
Пример #13
0
int main(int argc, char **argv)
{
    PVFS_sysresp_lookup resp_lk;
    PVFS_sysresp_create resp_cr;
    PVFS_sysresp_io resp_io;
    char *filename = NULL;
    int ret = -1, io_size = DEFAULT_IO_SIZE;
    int *io_buffer = NULL;
    int i, errors, buffer_size;
    PVFS_fs_id fs_id;
    char name[512] = {0};
    char *entry_name = NULL;
    PVFS_credentials credentials;
    PVFS_object_ref parent_refn;
    PVFS_sys_attr attr;
    PVFS_object_ref pinode_refn;
    PVFS_Request file_req;
    PVFS_Request mem_req;
    void *buffer = NULL;
    PVFS_sysresp_getattr resp_getattr;
    PVFS_handle *dfile_array = NULL;

    if (argc != 2)
    {
	fprintf(stderr, "Usage: %s <file name>\n", argv[0]);
	return (-1);
    }

    /* create a buffer for running I/O on */
    io_buffer = (int *) malloc(io_size * sizeof(int));
    if (!io_buffer)
    {
	return (-1);
    }

    /* put some data in the buffer so we can verify */
    for (i = 0; i < io_size; i++)
    {
	io_buffer[i] = i;
    }

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

    if (argv[1][0] == '/')
    {
        snprintf(name, 512, "%s", argv[1]);
    }
    else
    {
        snprintf(name, 512, "/%s", argv[1]);
    }

    PVFS_util_gen_credentials(&credentials);
    ret = PVFS_sys_lookup(fs_id, name, &credentials,
			  &resp_lk, PVFS2_LOOKUP_LINK_FOLLOW, NULL);
    if (ret == -PVFS_ENOENT)
    {
        PVFS_sysresp_getparent gp_resp;

	printf("IO-TEST: lookup failed; creating new file.\n");

        memset(&gp_resp, 0, sizeof(PVFS_sysresp_getparent));
	ret = PVFS_sys_getparent(fs_id, name, &credentials, &gp_resp, NULL);
	if (ret < 0)
	{
            PVFS_perror("PVFS_sys_getparent failed", ret);
	    return ret;
	}

	attr.owner = credentials.uid;
	attr.group = credentials.gid;
	attr.perms = PVFS_U_WRITE | PVFS_U_READ;
	attr.atime = attr.ctime = attr.mtime = time(NULL);
	attr.mask = PVFS_ATTR_SYS_ALL_SETABLE;
	parent_refn = gp_resp.parent_ref;

        entry_name = rindex(name, (int)'/');
        assert(entry_name);
        entry_name++;
        assert(entry_name);

	ret = PVFS_sys_create(entry_name, parent_refn, attr,
			      &credentials, NULL, &resp_cr, NULL, NULL);
	if (ret < 0)
	{
	    PVFS_perror("PVFS_sys_create() failure", ret);
	    return (-1);
	}

	pinode_refn.fs_id = fs_id;
	pinode_refn.handle = resp_cr.ref.handle;
    }
    else
    {
	printf("IO-TEST: lookup succeeded; performing I/O on "
               "existing file.\n");

	pinode_refn.fs_id = fs_id;
	pinode_refn.handle = resp_lk.ref.handle;
    }

	/**************************************************************
	 * carry out I/O operation
	 */

    printf("IO-TEST: performing write on handle: %ld, fs: %d\n",
	   (long) pinode_refn.handle, (int) pinode_refn.fs_id);

    buffer = io_buffer;
    buffer_size = io_size * sizeof(int);

    /*
      file datatype is tiled, so we can get away with a trivial type
      here
    */
    file_req = PVFS_BYTE;

    ret = PVFS_Request_contiguous(io_size * sizeof(int),
                                  PVFS_BYTE, &(mem_req));
    if (ret < 0)
    {
        PVFS_perror("PVFS_request_contiguous failure", ret);
	return (-1);
    }

    ret = PVFS_sys_write(pinode_refn, file_req, 0, buffer, mem_req,
			 &credentials, &resp_io, NULL);
    if (ret < 0)
    {
        PVFS_perror("PVFS_sys_write failure", ret);
	return (-1);
    }

    printf("IO-TEST: wrote %d bytes.\n", (int) resp_io.total_completed);

    /* uncomment and try out the readback-and-verify stuff that follows
     * once reading back actually works */
    memset(io_buffer, 0, io_size * sizeof(int));

    /* verify */
    printf("IO-TEST: performing read on handle: %ld, fs: %d\n",
	   (long) pinode_refn.handle, (int) pinode_refn.fs_id);

    ret = PVFS_sys_read(pinode_refn, file_req, 0, buffer, mem_req,
			&credentials, &resp_io, NULL);
    if (ret < 0)
    {
        PVFS_perror("PVFS_sys_read failure", ret);
	return (-1);
    }
    printf("IO-TEST: read %d bytes.\n", (int) resp_io.total_completed);
    if ((io_size * sizeof(int)) != resp_io.total_completed)
    {
	fprintf(stderr, "Error: SHORT READ! skipping verification...\n");
    }
    else
    {
	errors = 0;
	for (i = 0; i < io_size; i++)
	{
	    if (i != io_buffer[i])
	    {
		fprintf(stderr,
			"error: element %d differs: should be %d, is %d\n", i,
			i, io_buffer[i]);
		errors++;
	    }
	}
	if (errors != 0)
	{
	    fprintf(stderr, "ERROR: found %d errors\n", errors);
	}
	else
	{
	    printf("IO-TEST: no errors found.\n");
	}
    }

    /* test out some of the mgmt functionality */
    ret = PVFS_sys_getattr(pinode_refn, PVFS_ATTR_SYS_ALL_NOSIZE,
			   &credentials, &resp_getattr, NULL);
    if (ret < 0)
    {
	PVFS_perror("PVFS_sys_getattr", ret);
	return (-1);
    }

    printf("Target file had %d datafiles:\n", resp_getattr.attr.dfile_count);

    dfile_array = (PVFS_handle *) malloc(resp_getattr.attr.dfile_count
					 * sizeof(PVFS_handle));
    if (!dfile_array)
    {
	perror("malloc");
	return (-1);
    }

    ret = PVFS_mgmt_get_dfile_array(pinode_refn, &credentials,
				    dfile_array, resp_getattr.attr.dfile_count, NULL);
    if (ret < 0)
    {
	PVFS_perror("PVFS_mgmt_get_dfile_array", ret);
	return (-1);
    }
    for (i = 0; i < resp_getattr.attr.dfile_count; i++)
    {
	printf("%llu\n", llu(dfile_array[i]));
    }

	/**************************************************************
	 * shut down pending interfaces
	 */

    ret = PVFS_sys_finalize();
    if (ret < 0)
    {
	fprintf(stderr, "Error: PVFS_sys_finalize() failed with errcode = %d\n",
		ret);
	return (-1);
    }

    free(filename);
    free(io_buffer);
    return (0);
}
Пример #14
0
struct handlelist *find_sub_trees(PVFS_fs_id cur_fs,
				  struct handlelist *hl_all,
				  PVFS_BMI_addr_t *addr_array,
				  PVFS_credentials *creds)
{
    int ret;
    int server_idx;
    PVFS_handle handle;
    struct handlelist *alt_hl;

    /* TODO: DON'T DIRECTLY USE THESE MEMBERS... */
    alt_hl = handlelist_initialize(hl_all->size_array,
				   hl_all->server_ct);

    /* make a pass working on directories first */
    /* Q: do we want to try to figure out who the root of the tree
     *    really is?  that could be tricky.  we could build this though.
     */
    while (handlelist_return_handle(hl_all,
				    &handle,
				    &server_idx) == 0)
    {
	PVFS_object_ref handle_ref;
	PVFS_sysresp_getattr getattr_resp;

	handle_ref.handle = handle;
	handle_ref.fs_id  = cur_fs;

	ret = PVFS_sys_getattr(handle_ref,
			       PVFS_ATTR_SYS_ALL_NOHINT,
			       creds,
			       &getattr_resp, NULL);
	if (ret) {
	    /* remove anything we can't get attributes on */
	    ret = remove_object(handle_ref,
				0,
				creds);
	    continue;
	}

	switch (getattr_resp.attr.objtype)
	{
	    case PVFS_TYPE_METAFILE:
		/* just hold onto this for now */
		handlelist_add_handle(alt_hl, handle, server_idx);
		break;
	    case PVFS_TYPE_DIRECTORY:
		/* add to directory list */
		printf("# looking for dirdata match to %llu.\n", llu(handle));

		descend(cur_fs,
			hl_all,
			alt_hl,
			handle_ref,
			creds);

		handlelist_add_handle(alt_hl, handle, server_idx);
		break;
	    case PVFS_TYPE_DATAFILE:
		/* save for later */
		handlelist_add_handle(alt_hl, handle, server_idx);
		break;
	    case PVFS_TYPE_DIRDATA:
		handlelist_add_handle(alt_hl, handle, server_idx);
		break;
	    case PVFS_TYPE_SYMLINK:
		handlelist_add_handle(alt_hl, handle, server_idx);
		break;
	    default:
		ret = remove_object(handle_ref,
				    getattr_resp.attr.objtype,
				    creds);
		assert(ret == 0);
		break;
	}

    }

    return alt_hl;
}
Пример #15
0
/**
 * pvfsios_object_stat: stat a pvfs object
 *
 * @param rp the object to state
 * @param cp the creds used to do the stat
 * @param stb the stat buffer to fill out
 * @return 0 or -err
 */
static int pvfsios_object_stat(PVFS_object_ref *rp, PVFS_credentials *cp,
                               struct stat *stb) {
    PVFS_sysresp_getattr reply;
    PVFS_sys_attr *ats;
    int pev, m;

    memset(stb, 0, sizeof(*stb));
    memset(&reply, 0, sizeof(reply));

    /* do the RPC */
    pev = PVFS_sys_getattr(*rp, PVFS_ATTR_SYS_ALL_NOHINT, cp, &reply);
    if (pev != 0) {
        return(get_err(pev));
    }

    ats = &reply.attr;

    /* set st_blocks, st_size and type bits of st_mode */
    switch (ats->objtype) {
    case PVFS_TYPE_METAFILE:   /* a file */
        stb->st_mode |= S_IFREG;
        if (ats->mask & PVFS_ATTR_SYS_SIZE) {
            stb->st_size = ats->size;
            stb->st_blocks = (((ats->size + 4095)/4096)*4096)/512;
        }
        break;
    case PVFS_TYPE_SYMLINK:
        stb->st_mode |= S_IFLNK;
        if (ats->link_target)
            stb->st_size = strlen(ats->link_target);
        break;
    case PVFS_TYPE_DIRECTORY:
        stb->st_mode |= S_IFDIR;
        break;
    default:
        /* just leave the values at zero */
        break;
    }

    stb->st_nlink = 1;
    stb->st_uid = ats->owner;
    stb->st_gid = ats->group;
    stb->st_atime = ats->atime;
    stb->st_mtime = ats->mtime;
    stb->st_ctime = ats->ctime;
    
    m = 0;   /* yuck */
    if (ats->perms & PVFS_O_EXECUTE)
        m |= S_IXOTH;
    if (ats->perms & PVFS_O_WRITE)
        m |= S_IWOTH;
    if (ats->perms & PVFS_O_READ)
        m |= S_IROTH;
    
    if (ats->perms & PVFS_G_EXECUTE)
        m |= S_IXGRP;
    if (ats->perms & PVFS_G_WRITE)
        m |= S_IWGRP;
    if (ats->perms & PVFS_G_READ)
        m |= S_IRGRP;

    if (ats->perms & PVFS_U_EXECUTE)
        m |= S_IXUSR;
    if (ats->perms & PVFS_U_WRITE)
        m |= S_IWUSR;
    if (ats->perms & PVFS_U_READ)
        m |= S_IRUSR;

    if (ats->perms & PVFS_G_SGID)
        m |= S_ISGID;
    if (ats->perms & PVFS_U_SUID)
        m |= S_ISUID;

    stb->st_mode |= m;

    stb->st_dev = rp->fs_id;
    stb->st_ino = rp->handle;
    stb->st_rdev = 0;
    stb->st_blksize = 4096;

    PVFS_util_release_sys_attr(ats);  /* frees memory chained off ats */
    return(0);
}
Пример #16
0
struct handlelist *fill_lost_and_found(PVFS_fs_id cur_fs,
				       struct handlelist *hl_all,
				       PVFS_BMI_addr_t *addr_array,
				       PVFS_credentials *creds)
{
    int ret;
    int server_idx;
    PVFS_handle handle;
    struct handlelist *alt_hl;
    static char filename[64] = "lostfile.";
    static char dirname[64] = "lostdir.";

    /* TODO: DON'T DIRECTLY USE THESE MEMBERS... */
    alt_hl = handlelist_initialize(hl_all->size_array,
				   hl_all->server_ct);

    /* recall that return_handle removes from list */
    while (handlelist_return_handle(hl_all,
				    &handle,
				    &server_idx) == 0)
    {
	PVFS_object_ref handle_ref;
	PVFS_sysresp_getattr getattr_resp;

	handle_ref.handle = handle;
	handle_ref.fs_id  = cur_fs;

	ret = PVFS_sys_getattr(handle_ref,
			       PVFS_ATTR_SYS_ALL_NOHINT,
			       creds,
			       &getattr_resp, NULL);
	if (ret) {
	    printf("warning: problem calling getattr on %llu; assuming datafile for now.\n",
		   llu(handle));
	    getattr_resp.attr.objtype = PVFS_TYPE_DATAFILE;
	}

	switch (getattr_resp.attr.objtype)
	{
	    case PVFS_TYPE_METAFILE:
		printf("# trying to salvage %s %lld.\n",
		       get_type_str(getattr_resp.attr.objtype),
		       llu(handle));
		if (verify_datafiles(cur_fs,
				     hl_all,
				     alt_hl,
				     handle_ref, 
				     getattr_resp.attr.dfile_count,
				     creds) != 0)
		{
		    ret = remove_object(handle_ref,
					getattr_resp.attr.objtype,
					creds);
		    assert(ret == 0);
		}
		else
		{
		    sprintf(filename + 9, "%llu", llu(handle));
		    ret = create_dirent(laf_ref,
					filename,
					handle,
					creds);
                    assert(ret == 0);
		}
		break;
	    case PVFS_TYPE_DIRECTORY:
                /* assumption: we will often suceed in creating a new entry,
                 * but if the file system is messed up we may not be able to
                 * find dirdata, so match_dirdata before create_dirent */
		if (match_dirdata(hl_all,
				    alt_hl,
				    handle_ref,
				    creds)  != 0)
                {
                    ret = remove_object(handle_ref, 
                            getattr_resp.attr.objtype,
                            creds);
                    assert(ret == 0);
                }

		sprintf(dirname + 8, "%llu", llu(handle));
		ret = create_dirent(laf_ref,
				    dirname,
				    handle,
				    creds);
                if (ret != 0)
                {
                    ret = remove_object(handle_ref,
                            getattr_resp.attr.objtype,
                            creds);
                }

		break;
	    case PVFS_TYPE_DATAFILE:
#if 0
		printf("# saving %llu (datafile) for later.\n", llu(handle));
#endif
		handlelist_add_handle(alt_hl, handle, server_idx);
		break;
	    case PVFS_TYPE_DIRDATA:
#if 0
		printf("# saving %llu (dirdata) for later.\n", llu(handle));
#endif
		handlelist_add_handle(alt_hl, handle, server_idx);
		break;
	    case PVFS_TYPE_SYMLINK:
	    default:
		/* delete on handle -- unknown type */
		printf("* delete handle %llu (unknown type).\n",
		       llu(handle));
		break;
	}

    }

    return alt_hl;
}
Пример #17
0
/**
 * PVFSIOStore::Access: permission check
 *
 * @param path the path we are checking
 * @param mode the mode to check
 * @return PLFS_SUCCESS or PLFS_E* on error
 */
plfs_error_t PVFSIOStore::Access(const char* path, int mode)
{
    char *cpath;
    PVFS_object_ref ref;
    PVFS_credentials creds;
    int nev, pev;
    PVFS_sysresp_getattr rep;
    PVFS_uid auid;
    PVFS_gid agid;
    PVFS_permissions aperms;

    cpath = pvfsios_dedup_slash(path);
    if (cpath) {
        nev = pvfsios_get_object(this->fsid, cpath, &ref, &creds,
                                 PVFS2_LOOKUP_LINK_FOLLOW);
        free(cpath);
    } else {
        nev = -ENOMEM;
    }
    if (nev < 0) {
        return errno_to_plfs_error(-nev);
    }
    
    /* root or exist check */
    if (creds.uid == 0 || mode == F_OK) {
        return PLFS_SUCCESS;
    }
    
    pev = PVFS_sys_getattr(ref, PVFS_ATTR_SYS_ALL_NOHINT, &creds, &rep);
    if (pev < 0) {
        return errno_to_plfs_error(get_err(pev));
    }

#if 0
    /*
     * XXXCDC: we'd really like to call PINT_check_mode, but libpvfs2
     * includes don't provide a prototype for it even though it is
     * present in the lib.  does that mean it is a private interface?
     */
    pev = PINT_check_mode(&rep.attr, creds.uid, credis.gid, 0);
    PVFS_util_release_sys_attr(&rep.attr);  /* frees memory chained off ats */
    return(get_err(pev));
#endif
    
    /*
     * XXX: pvfs2fuse doesn't call PVFS_util_release_sys_attr on
     * repl.attr for access.  this seems like a memory leak mistake to
     * me.
     */
    auid = rep.attr.owner;
    agid = rep.attr.group;
    aperms = rep.attr.perms;
    PVFS_util_release_sys_attr(&rep.attr);  /* frees memory chained off ats */

    if (auid == creds.uid) {
        if ((mode & R_OK) && (aperms & PVFS_U_READ))
            return PLFS_SUCCESS;
        if ((mode & W_OK) && (aperms & PVFS_U_WRITE))
            return PLFS_SUCCESS;
        if ((mode & X_OK) && (aperms & PVFS_U_EXECUTE))
            return PLFS_SUCCESS;
    }
    /* XXXCDC: doesn't check group list, e.g. getgroups() */
    if (agid == creds.gid) {
        if ((mode & R_OK) && (aperms & PVFS_G_READ))
            return PLFS_SUCCESS;
        if ((mode & W_OK) && (aperms & PVFS_G_WRITE))
            return PLFS_SUCCESS;
        if ((mode & X_OK) && (aperms & PVFS_G_EXECUTE))
            return PLFS_SUCCESS;
    }
    if ((mode & R_OK) && (aperms & PVFS_O_READ))
        return PLFS_SUCCESS;
    if ((mode & W_OK) && (aperms & PVFS_O_WRITE))
        return PLFS_SUCCESS;
    if ((mode & X_OK) && (aperms & PVFS_O_EXECUTE))
        return PLFS_SUCCESS;

    return PLFS_EACCES;
}
Пример #18
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;
}
Пример #19
0
static int test_read_sparse_files(void){
    PVFS_credentials credentials;
    PVFS_sysresp_lookup resp_lk;
    PVFS_Request req_io;
    PVFS_Request req_mem;
    PVFS_sysresp_io resp_io;
    PVFS_sysresp_getattr resp;
    PVFS_offset file_req_offset = 0;
    uint32_t attrmask;
    char *filename;
    char io_buffer[100];
    int fs_id, ret, i;

    attrmask = PVFS_ATTR_SYS_ALL_NOSIZE;

    filename = (char *) malloc(sizeof(char) * 100);
    filename = strcpy(filename, "sparse2");

    memset(&req_io, 0, sizeof(PVFS_Request));
    memset(&req_mem, 0, sizeof(PVFS_Request));
    memset(&resp_io, 0, sizeof(PVFS_sysresp_io));

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

    if (initialize_sysint() < 0)
    {
        debug_printf("UNABLE TO INIT THE SYSTEM INTERFACE\n");
        return -1;
    }
    fs_id = pvfs_helper.fs_id;

    ret = PVFS_sys_lookup(fs_id, filename, &credentials,
                          &resp_lk, PVFS2_LOOKUP_LINK_NO_FOLLOW);
    if (ret < 0)
    {
        debug_printf("test_pvfs_datatype_hvector: lookup failed "
                     "on %s\n", filename);
    }
    if((ret = PVFS_sys_getattr(resp_lk.ref, attrmask, &credentials, &resp)) < 0)
	return ret;

    assert(0);
    /* TODO: what's this?  we shouldn't edit these fields directly -Phil */
#if 0
    switch(testcase)
    {
    case 0:
	req_io->offset = 78000;
	break;
    case 1:
	req_io->offset = 150000;
	break;
    case 2:
	req_io->offset = 330000;
	break;
    }
#endif

    for(i = 0; i < 100; i++)
    {
	io_buffer[i] = 'a';
    }
    ret = PVFS_sys_write(resp_lk.ref, req_io, file_req_offset, io_buffer, req_mem,
                           &credentials, &resp_io);
    if(ret < 0){
	debug_printf("write failed on %s\n", filename);
    }
    ret = PVFS_sys_read(resp_lk.ref, req_io, file_req_offset, io_buffer, req_mem,
                           &credentials, &resp_io);
    if(ret < 0){
	debug_printf("write failed on %s\n", filename);
    }

/*     finalize_sysint(); */
    for(i = 0; i < 100; i++)
    {
	if(io_buffer[i] != 0){
	    return -1;
	}
    }

    /* check for whats in the buffer */
    return 0;
}