Ejemplo n.º 1
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;
}
Ejemplo n.º 2
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;
}
Ejemplo n.º 3
0
/* Preconditions: none
 * Parameters: testcase - the test case that is checked for this function
 * Postconditions: returns error code of readdir
 * Has 2 test cases
 */
static int test_create(void)
{
    int ret, fs_id;
    PVFS_sys_attr attr;
    PVFS_credentials credentials;
    PVFS_sysresp_lookup resp_look;
    PVFS_sysresp_create resp_create;
    char *filename;

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

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

    fs_id = 9;

    ret = PVFS_sys_lookup(fs_id, "/", &credentials,
                          &resp_look, PVFS2_LOOKUP_LINK_NO_FOLLOW);
    if (ret < 0)
    {
	printf("Lookup failed with errcode = %d\n", ret);
	return (-1);
    }

    ret =
	PVFS_sys_create(filename, resp_look.ref, attr, &credentials,
			NULL, NULL, &resp_create);
    return ret;
}
Ejemplo n.º 4
0
int create_dir(PVFS_object_ref parent_refn, char *name,
               PVFS_object_ref *out_refn)
{
    int ret = -1;
    PVFS_sys_attr attr;
    PVFS_credentials credentials;
    PVFS_sysresp_mkdir resp_mkdir;

    memset(&attr, 0, sizeof(PVFS_sys_attr));
    memset(&resp_mkdir, 0, sizeof(resp_mkdir));

    PVFS_util_gen_credentials(&credentials);

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

    ret = PVFS_sys_mkdir(name, parent_refn,
                         attr, &credentials, &resp_mkdir);
    if (ret < 0)
    {
        printf("mkdir failed\n");
        return (-1);
    }
    if (out_refn)
    {
        memset(out_refn, 0, sizeof(PVFS_object_ref));
        memcpy(out_refn, &resp_mkdir.ref,
               sizeof(PVFS_object_ref));
    }
    return 0;
}
Ejemplo n.º 5
0
/*
 * simple helper to lookup a handle given a filename
 *
 * returns a handle to the new directory
 *          -1 if some error happened
 */
int lookup_name(PVFS_object_ref pinode_refn, char *name,
                PVFS_object_ref *out_refn)
{
    int ret = -1;
    PVFS_credentials credentials;
    PVFS_sysresp_lookup resp_lookup;

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

    PVFS_util_gen_credentials(&credentials);

    ret = PVFS_sys_lookup(pinode_refn.fs_id, name,
                          &credentials, &resp_lookup,
                          PVFS2_LOOKUP_LINK_NO_FOLLOW);
    if (ret < 0)
    {
       printf("Lookup failed with errcode = %d\n", ret);
       return(-1);
    }
    if (out_refn)
    {
        memcpy(out_refn, &resp_lookup.ref,
               sizeof(PVFS_object_ref));
    }
    return 0;
}
Ejemplo n.º 6
0
/*
 * helper function to fill in the root pinode_refn
 * fs_id:   fsid of our file system
 *
 * returns:  0 on success; 
 *      -1 if a problem
 */
int get_root(PVFS_fs_id fs_id, PVFS_object_ref *pinode_refn)
{
    int ret = -1;
    PVFS_credentials credentials;
    PVFS_sysresp_lookup resp_look;
    char *root = "/";

    if (pinode_refn)
    {
        memset(&resp_look, 0, sizeof(resp_look));

        PVFS_util_gen_credentials(&credentials);

        printf("looking up the root handle for fsid = %d\n", fs_id);
        ret = PVFS_sys_lookup(fs_id, root, &credentials,
                              &resp_look, PVFS2_LOOKUP_LINK_NO_FOLLOW);
        if (ret < 0)
        {
            printf("Lookup failed with errcode = %d\n", ret);
        }
        memcpy(pinode_refn, &resp_look.ref,
               sizeof(PVFS_object_ref));
    }
    return ret;
}
Ejemplo n.º 7
0
/* Preconditions: none
 * Parameters: testcase - the test case that is checked for this function
 * Postconditions: returns error code of readdir
 * Has 2 tset cases
 */
static int test_remove(void)
{
    PVFS_credentials credentials;
    PVFS_sysresp_lookup resp_look;
    char *filename;
    int ret;
    int fs_id;

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

    PVFS_util_gen_credentials(&credentials);

    fs_id = 9;

    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);
    }
    ret = PVFS_sys_remove(filename, resp_look.ref, &credentials);
    return ret;
}
Ejemplo n.º 8
0
/* Preconditions: none
 * Parameters: testcase - the test case that is checked for this function
 * Postconditions: returns error code of readdir
 * Has 2 test cases
 */
static int test_write(void)
{
    PVFS_credentials credentials;
    PVFS_sysresp_lookup resp_lk;
    PVFS_Request req_io;
    PVFS_sysresp_io resp_io;
    char *filename;
    char io_buffer[100];
    int fs_id, ret;

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

    memset(&req_io, 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));

    fs_id = 9;

    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);
    }

    ret =
	PVFS_sys_write(resp_lk.ref, req_io, 0, io_buffer, NULL, &credentials,
		       &resp_io);
    return ret;
}
Ejemplo n.º 9
0
static int test_files_as_dirs(int testcase)
{
    int ret = 1, fs_id;
    PVFS_sys_attr attr;
    PVFS_credentials credentials;
    PVFS_sysresp_lookup resp_look;
    PVFS_sysresp_create resp_create;
    char *filename;

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

    PVFS_util_gen_credentials(&credentials);

    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;

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

    switch(testcase)
    {
    case 0:
	/* get root */
	ret = PVFS_sys_lookup(fs_id, "/", &credentials,
                              &resp_look, PVFS2_LOOKUP_LINK_NO_FOLLOW);
	if (ret < 0)
	{
	    printf("Lookup failed with errcode = %d\n", ret);
	    return (-1);
	}

	ret = PVFS_sys_create("foo", resp_look.ref, attr, &credentials,
                           NULL, NULL, &resp_create);
	/* get root */
	ret = PVFS_sys_lookup(fs_id, "/foo", &credentials,
                              &resp_look, PVFS2_LOOKUP_LINK_NO_FOLLOW);
	if (ret < 0)
	{
	    printf("Lookup failed with errcode = %d\n", ret);
	    return (-1);
	}

	ret = PVFS_sys_create("bar", resp_look.ref, attr, &credentials,
                           NULL, NULL, &resp_create);
	break;
    case 1:
	/* Need to add some more interesting cases */
	break; 
    }

    return ret;
}
Ejemplo n.º 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);
        }
    }
}
Ejemplo n.º 11
0
static int test_io_on_dir(int testcase)
{
    int fs_id, ret,i;
    PVFS_credentials credentials;
    PVFS_sysresp_lookup resp_lookup;
    PVFS_Request req_io;
    PVFS_Request req_mem;
    PVFS_sysresp_io resp_io;
    PVFS_offset file_req_offset = 0;
    char *name;
    char io_buffer[100];

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

    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\n");
	return ret;
    }

    memset(&req_io, 0, sizeof(req_io));
    memset(&req_mem, 0, sizeof(req_mem));

    switch(testcase)
    {
	case 0:
	    ret = PVFS_sys_read(resp_lookup.ref, req_io, file_req_offset, io_buffer, req_mem, &credentials, &resp_io);
	    break;
	case 1:
	    for(i = 0; i < 100; i++)
	    {
		io_buffer[i] = 'a';
	    }
	    ret = PVFS_sys_write(resp_lookup.ref, req_io, file_req_offset, io_buffer, req_mem, &credentials, &resp_io);
	    break;

    }

/*     finalize_sysint(); */
    return ret;
}
Ejemplo n.º 12
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);
}
Ejemplo n.º 13
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;
}
Ejemplo n.º 14
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);
}
Ejemplo n.º 15
0
static int pvfs_generate_serverlist(){
    int ret, servercount, i;
    PVFS_credentials credentials; PVFS_util_gen_credentials(&credentials);

    // What hostname are we using
    if (!myhostname)
        myhostname = getenv("HOSTNAME");
    if (!myhostname){
        myhostname = malloc(HOST_NAME_MAX + 1);
        gethostname(myhostname, HOST_NAME_MAX);
        myhostname[HOST_NAME_MAX] = '\0';
    }

    skye_options.servernum = -1;

    ret = PVFS_mgmt_count_servers(pvfs_fsid,&credentials,PVFS_MGMT_META_SERVER,&servercount);
    if (ret < 0) return ret;

    skye_options.serveraddrs = malloc(sizeof(PVFS_BMI_addr_t)*(servercount));
    if (!skye_options.serveraddrs) return -ENOMEM;

    ret = PVFS_mgmt_get_server_array(pvfs_fsid,&credentials,PVFS_MGMT_META_SERVER, skye_options.serveraddrs, &servercount);
    if (ret < 0) return ret;

    const char **servers = malloc(sizeof(char*)*(servercount));
    if (!servers) return -ENOMEM;

    for (i = 0; i < servercount; i++){
        servers[i] = PVFS_mgmt_map_addr(pvfs_fsid,&credentials,skye_options.serveraddrs[i],NULL);    

        char *start, *end;

        /* cut out just the server portion of tcp://servername:port */
        end = rindex(servers[i], ':');
        start = rindex(servers[i], '/');

        servers[i] = strndup(start + 1, end - start - 1);

        if (!servers[i]) return -ENOMEM; 
        
        if (strcmp(servers[i],myhostname) == 0)
            skye_options.servernum = i;
    }

    skye_options.serverlist = servers;
    skye_options.servercount = servercount;

    return 0;
}
Ejemplo n.º 16
0
/*
 * simple helper to remove a pvfs2 file
 *
 * returns 0 on success.
 *          -1 if some error happened.
 */
int remove_file(PVFS_object_ref parent_refn, char *name)
{
    int ret = -1;
    PVFS_credentials credentials;

    PVFS_util_gen_credentials(&credentials);

    ret = PVFS_sys_remove(name, parent_refn, &credentials);
    if (ret < 0)
    {
        printf("remove failed\n");
        return ret;
    }
    return 0;
}
Ejemplo n.º 17
0
/* Preconditions: none
 * Parameters: none
 * Postconditions: returns the error code given by lookup - thats if it doesn't segfault or other catostrophic failure
 * Hase 1 test cases
 */
static int test_lookup(void)
{
    int fs_id, ret;
    PVFS_credentials credentials;
    PVFS_sysresp_lookup resp_lookup;
    char *name;

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

    fs_id = 9;

    PVFS_util_gen_credentials(&credentials);

    ret = PVFS_sys_lookup(fs_id, name, &credentials,
                          &resp_lookup, PVFS2_LOOKUP_LINK_NO_FOLLOW);
    return ret;
}
/*
 *	file_delete_pvfs2
 *
 *	Function:	- deletes a file
 *	Accepts:	- file name & info
 *	Returns:	- Success if file closed
 */
int
mca_fs_pvfs2_file_delete (char* file_name,
                          struct ompi_info_t *info)
{
    PVFS_credentials credentials;
    PVFS_sysresp_getparent resp_getparent;
    int ret;
    PVFS_fs_id pvfs2_id;
    char pvfs2_path[OMPIO_MAX_NAME] = {0};
    char * ncache_timeout;

    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) {
            return OMPI_ERROR;
        }
        mca_fs_pvfs2_IS_INITIALIZED = 1;
    }

    memset (&credentials, 0, sizeof(PVFS_credentials));
    PVFS_util_gen_credentials (&credentials);

    ret = PVFS_util_resolve(file_name, &pvfs2_id, pvfs2_path, OMPIO_MAX_NAME);
    if (ret != 0) {
        return OMPI_ERROR;
    }

    ret = PVFS_sys_getparent(pvfs2_id, pvfs2_path, &credentials, &resp_getparent);

    ret = PVFS_sys_remove(resp_getparent.basename,
                          resp_getparent.parent_ref, &credentials);
    if (ret != 0) {
        return OMPI_ERROR;
    }
    return OMPI_SUCCESS;
}
Ejemplo n.º 19
0
static int test_remove_nonempty_dir(int testcase)
{
    PVFS_credentials credentials;
    PVFS_sysresp_lookup resp_look;
    char *filename;
    int ret; 
    int fs_id;
    
    ret = -2;
    filename = (char *) malloc(sizeof(char) * 100);
    filename = strcpy(filename, "/");
    
    PVFS_util_gen_credentials(&credentials);

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

    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);
    }
    switch (testcase)
    {
    case 0:
        ret = PVFS_sys_remove(NULL, resp_look.ref, &credentials);
        break;
    default:
        fprintf(stderr, "Error: invalid case number \n");
    }
    return ret;

}
Ejemplo n.º 20
0
/* Preconditions: none
 * Parameters: testcase - the test case to be run
 * Postconditions: returns error code of readdir
 * Has 2 Test cases
 */
static int test_readdir(void)
{

    int ret;

    PVFS_object_ref pinode_refn;
    PVFS_ds_position token;
    int pvfs_dirent_incount;
    PVFS_credentials credentials;
    PVFS_sysresp_readdir resp_readdir;

    int fs_id;
    PVFS_sysresp_lookup resp_lookup;
    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 -1;
    }

    pinode_refn = resp_lookup.ref;
    token = PVFS_READDIR_START;
    pvfs_dirent_incount = 1;

    ret =
	PVFS_sys_readdir(pinode_refn, token, pvfs_dirent_incount, &credentials,
			 &resp_readdir);
    return ret;
}
Ejemplo n.º 21
0
/* Preconditions: None
 * Parameters: testcase - the test case to be run
 * Postconditions: returns the error returned by mkdir
 * Has 2 test cases
 */
static int test_mkdir(void)
{
    PVFS_object_ref parent_refn;
    PVFS_sys_attr attr;
    PVFS_sysresp_mkdir resp_mkdir;

    int ret = -2;
    int fs_id;
    PVFS_credentials credentials;
    PVFS_sysresp_lookup resp_lookup;
    char *name;

    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 -1;
    }

    parent_refn = resp_lookup.ref;
    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 = PVFS_sys_mkdir(name, parent_refn, attr, &credentials, &resp_mkdir);
    return ret;
}
Ejemplo n.º 22
0
static int test_lookup_empty(void)
{
    int fs_id, ret;
    PVFS_credentials credentials;
    PVFS_sysresp_lookup resp_lookup;
    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);
    ret = PVFS_sys_lookup(fs_id, name, &credentials,
                          &resp_lookup, PVFS2_LOOKUP_LINK_NO_FOLLOW);

    return ret;
}
Ejemplo n.º 23
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;
}
Ejemplo n.º 24
0
/*
  given mount information, retrieve the server's configuration by
  issuing a getconfig operation.  on successful response, we parse the
  configuration and fill in the config object specified.

  returns 0 on success, -errno on error
*/
int PVFS_mgmt_get_config(
    const PVFS_fs_id * fsid,
    PVFS_BMI_addr_t * addr,
    char *fs_buf,
    int fs_buf_size)
{
    int ret = -PVFS_EINVAL;
    PINT_smcb *smcb = NULL;
    PINT_client_sm *sm_p = NULL;
    PVFS_error error = 0;
    PVFS_credentials creds;
    struct filesystem_configuration_s *cur_fs = NULL;
    PVFS_sys_op_id op_id;
    struct server_configuration_s *config = NULL;
    struct PVFS_sys_mntent mntent;
    int server_type = 0;

    gossip_debug(GOSSIP_CLIENT_DEBUG, "PVFS_mgmt_get_config entered\n");

    PVFS_util_gen_credentials(&creds);

    PINT_smcb_alloc(&smcb, PVFS_SERVER_GET_CONFIG,
                    sizeof(struct PINT_client_sm),
                    client_op_state_get_machine,
                    client_state_machine_terminate,
                    pint_client_sm_context);
    if(smcb == NULL)
    {
        return -PVFS_ENOMEM;
    }

    sm_p = PINT_sm_frame(smcb, PINT_FRAME_CURRENT);

    sm_p->u.get_config.persist_config_buffers = 1;

    PINT_init_msgarray_params(sm_p, *fsid);

    PINT_init_sysint_credentials(sm_p->cred_p, &creds);

    config = PINT_get_server_config_struct(*fsid);

    mntent.the_pvfs_config_server =
        (char*)PINT_cached_config_map_addr(*fsid, *addr, &server_type);

    PINT_put_server_config_struct(config);

    cur_fs = PINT_config_find_fs_id(config, *fsid);

    mntent.encoding = cur_fs->encoding;
    mntent.flowproto = cur_fs->flowproto;

    mntent.fs_id = *fsid;

    mntent.pvfs_fs_name = cur_fs->file_system_name;
    sm_p->u.get_config.config = config;

    sm_p->msgarray_op.msgpair.enc_type = cur_fs->encoding;

    sm_p->u.get_config.mntent = &mntent;

    PINT_msgpair_init(&sm_p->msgarray_op);

    ret = PINT_client_state_machine_post(
        smcb, &op_id, NULL);

    if (ret)
    {
        PVFS_perror_gossip("PINT_client_state_machine_post call", ret);
        error = ret;
    }
    else
    {
        ret = PVFS_mgmt_wait(op_id, "X-get_config", &error);
        if (ret)
        {
            PVFS_perror_gossip("PVFS_mgmt_wait call", ret);
            error = ret;
        }
    }

    if (error)
    {
        goto exit_path;
    }

    gossip_debug(GOSSIP_CLIENT_DEBUG, "PVFS_mgmt_get_config completed\n");

    /* make sure strings will be null terminated after strncpy */
    fs_buf[fs_buf_size-1] = '\0';

    /* The following copies the retrieved configuration buffers
       into the return buffers */
    strncpy(fs_buf, sm_p->u.get_config.fs_config_buf, (fs_buf_size - 1));

  exit_path:

    if (sm_p && sm_p->u.get_config.persist_config_buffers)
    {
        free(sm_p->u.get_config.fs_config_buf);
        sm_p->u.get_config.fs_config_buf = NULL;
    }

    PINT_mgmt_release(op_id);
    return error;
}
Ejemplo n.º 25
0
int main(int argc, char * argv[])
{
    FILE * f;
    int ret;
    PVFS_fs_id curfs;
    PVFS_Request file_req;
    PVFS_Request mem_req;
    int count;
    char line[255];
    int size;
    PVFS_offset offset=0;
    PVFS_credentials creds;
    PVFS_sysresp_create create_resp;
    PVFS_sysresp_io io_resp;
    PVFS_sysresp_lookup lookup_resp;
    PVFS_sys_attr attr;
    const char * filename = "test-accesses-file";
    int j = 0, i = 0;
    char * membuff;
    char errormsg[255];

    if(argc < 2)
    {
	fprintf(stderr, "test-accesses <sizes file>\n");
	exit(1);
    }
    
    f = fopen(argv[1], "r");
    if(!f)
    {
	fprintf(stderr, "error opening file\n");
	return errno;
    }
    
    if(fgets(line, 255, f) == NULL)
    {
	fprintf(stderr, "error in file\n");
	exit(1);
    } 

    if(sscanf(line, "%d", &count) < 1)
    {
	fprintf(stderr, "error in file\n");
	exit(1);
    }
    
    ret = PVFS_util_init_defaults();
    if(ret < 0) goto error;

    ret = PVFS_util_get_default_fsid(&curfs);
    if(ret < 0) goto error;

    ret = PVFS_sys_lookup(curfs, "/", &creds, &lookup_resp, 0, NULL);
    if(ret < 0) goto error;

    PVFS_util_gen_credentials(&creds);

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

    ret = PVFS_sys_create(
	(char*)filename, 
	lookup_resp.ref, attr, &creds, NULL, &create_resp, NULL, NULL);
    if(ret < 0) goto error;

    for(; i < count; ++i)
    {
	if(fgets(line, 255, f) == NULL)
	{
	    fprintf(stderr, "error in file\n");
	    exit(1);
	} 

	if(sscanf(line, "%d", &size) < 1)
	{
	    fprintf(stderr, "error in file\n");
	    exit(1);
	}

	membuff = malloc(size);
	assert(membuff);

	for(j = 0; j < size; ++j)
	{
	    membuff[j] = j;
	}

	ret = PVFS_Request_contiguous(
	    size, PVFS_BYTE, &file_req);
	if(ret < 0) goto error;

	ret = PVFS_Request_contiguous(
	    size, PVFS_BYTE, &mem_req);
	if(ret < 0) goto error;

	printf("Performing Write: offset: %llu, size: %d\n",
	       llu(offset), size);

	ret = PVFS_sys_io(
	    create_resp.ref, file_req, offset, membuff, mem_req,
	    &creds, &io_resp, PVFS_IO_WRITE, NULL);
	if(ret < 0) goto error;

	printf("Write response: size: %llu\n", llu(io_resp.total_completed));
	offset += size;

	PVFS_Request_free(&mem_req);
	PVFS_Request_free(&file_req);
	free(membuff);
    }

    return 0;
error:

    fclose(f);

    PVFS_sys_remove(
	(char*)filename,
	lookup_resp.ref,
	&creds,
        NULL);

    PVFS_perror_gossip(errormsg, ret);
    fprintf(stderr, "%s\n", errormsg);
    return PVFS_get_errno_mapping(ret);
}
Ejemplo n.º 26
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);
}
Ejemplo n.º 27
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;
}
Ejemplo n.º 28
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);
}
Ejemplo n.º 29
0
Archivo: remove.c Proyecto: Goon83/SALB
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);
}
Ejemplo n.º 30
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);
}