Пример #1
0
int main(int argc, char **argv)
{
    int ret = -1;
    struct options* user_opts = NULL;
    struct PVFS_sys_mntent* tmp_ent = NULL;
    char config_server[256];

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

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

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

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

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

    PVFS_sys_finalize();

    PVFS_util_gen_mntent_release(tmp_ent);

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

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

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

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

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

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

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

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

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

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

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

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

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

        ++last_slash;

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

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

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

    /* FIXME default_num_dfiles should be an option */

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

    ret = pvfs_generate_serverlist();

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

     ++last_slash;

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

  me->flowproto = FLOWPROTO_DEFAULT;

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

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

  return 0;
}
Пример #4
0
/**
 * PVFSIOStore::PVFSIOStore_xnew: make a new PVFSIOStore
 *
 * @param phys_path the physical path of the backing store
 * @param prelenp return the length of the prefix here
 * @param bmpointp return the bmpoint string here
 * @param res_store return the newly allocated class or NULL on error
 * @return PLFS_SUCCESS or PLFS_E* on error
 */
plfs_error_t PVFSIOStore::PVFSIOStore_xnew(char *phys_path,
                                           int *prelenp,
                                           char **bmpointp,
                                           class PVFSIOStore **res_store) {
    char *p, *sl, *cp;
    int plen, rv, pev;
    class PVFSIOStore *pio;
    *res_store = NULL;

    if (strncmp(phys_path, "pvfs://", sizeof("pvfs://")-1) != 0) {
        return PLFS_TBD;     /* should never happen, but play it safe */
    }
    p = phys_path + sizeof("pvfs://") - 1;
    sl = strchr(p, '/');  /* find start of bmpoint */
    if (sl == NULL) {
        return PLFS_TBD;
    }
    plen = sl - phys_path;

    /* start initing and allocating stuff */
    pio = NULL;

    /* make a writable copy of the spec so we can parse it */
    cp = (char *) malloc(sl - p + 1);
    if (cp == NULL) {
        goto error;
    }
    strncpy(cp, p, sl - p);

    pio = new PVFSIOStore;
    if (pio == NULL) {
        goto error;
    }

    rv = pvfsios_load_mnt(cp, &pio->pvmnt);
    if (rv < 0) {
        goto error;
    }
    
    pio->pvmnt.integrity_check = 1;
    /* XXX: mnt_dir (logical mount point): why does it need this? */
    pio->pvmnt.mnt_dir = NULL;
    pio->pvmnt.mnt_opts = NULL;

    pev = PVFS_sys_initialize(GOSSIP_NO_DEBUG);
    if (pev < 0) {
        goto error;
    }
    pio->pvmnt.flowproto = FLOWPROTO_DEFAULT;
    pio->pvmnt.encoding = PVFS2_ENCODING_DEFAULT;

    pev = PVFS_sys_fs_add(&pio->pvmnt);
    if (pev < 0) {
        goto error;
    }

    pio->fsid = pio->pvmnt.fs_id;

    *prelenp = plen;
    *bmpointp = sl;
    *res_store = pio;
    return PLFS_SUCCESS;

    
 error:
    if (cp != NULL) {
        free(cp);
    }
    if (pio != NULL) {
        pvfsios_free_mnt(&pio->pvmnt);
        delete pio;
    }
    return PLFS_TBD;
}
Пример #5
0
int main(int argc, char **argv)
{
    int ret = -1, i = 0;
    char pvfs_path[MAX_NUM_PATHS][PVFS_NAME_MAX];
    PVFS_fs_id fs_id_array[MAX_NUM_PATHS] = {0};
    const PVFS_util_tab* tab;
    struct options* user_opts = NULL;
    char current_dir[PVFS_NAME_MAX] = {0};
    int found_one = 0;

    process_name = argv[0];

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    PVFS_sys_finalize();
    free(user_opts);

    return(ret);
}