Пример #1
0
int File_GetStripeByPath( const char *entry_path, stripe_info_t * p_stripe_info,
                          stripe_items_t * p_stripe_items )
{
    int            rc;
    struct lov_user_md *p_lum;

    if ( !entry_path || !entry_path[0] )
        return -EFAULT;

    p_lum = (struct lov_user_md *)MemAlloc(LUM_SIZE_MAX);
    if (!p_lum)
        return -ENOMEM;

    memset(p_lum, 0, LUM_SIZE_MAX);
    rc = llapi_file_get_stripe(entry_path, p_lum);

    if ( rc != 0 )
    {
        if ( rc == -ENODATA )
            DisplayLog( LVL_DEBUG, TAG_STRIPE,
                        "File %s has no stripe information",
                        entry_path );
        else if ( ( rc != -ENOENT ) && ( rc != -ESTALE ) )
            DisplayLog( LVL_CRIT, TAG_STRIPE,
                        "Error %d getting stripe info for %s", rc,
                        entry_path );
        goto out_free;
    }

    rc = fill_stripe_info(p_lum, p_stripe_info, p_stripe_items);

out_free:
    MemFree(p_lum);
    return rc;
}
Пример #2
0
int main(int argc, char **argv)
{
	struct lov_user_md *lum_dir, *lum_file1 = NULL, *lum_file2 = NULL;
	struct obd_uuid uuid;
	int lum_size, rc;
	DIR *dir;

	if (argc < 3) {
		llapi_err_noerrno(LLAPI_MSG_ERROR,
				  "Usage: %s <dirname> <filename1> [filename2]\n",
				  argv[0]);
		return 1;
	}

	dir = opendir(argv[1]);
	if (dir == NULL) {
		rc = -errno;
		llapi_error(LLAPI_MSG_ERROR, rc,
			    "error: %s opendir failed", argv[1]);
		return rc;
	}

	lum_size = lov_user_md_size(MAX_LOV_UUID_COUNT, LOV_USER_MAGIC);
	lum_dir = (struct lov_user_md *)malloc(lum_size);
	if (lum_dir == NULL) {
		rc = -ENOMEM;
		llapi_error(LLAPI_MSG_ERROR, rc,
			    "error: can't allocate %d bytes "
			    "for dir EA", lum_size);
		goto cleanup;
	}

	rc = llapi_file_get_stripe(argv[1], lum_dir);
	if (rc == -ENODATA) {
		char root[PATH_MAX], path[PATH_MAX + 2];

		rc = llapi_search_mounts(argv[1], 0, root, NULL);
		if (rc) {
			llapi_error(LLAPI_MSG_ERROR, rc, "error: can't get "
				    "root path for %s\n", argv[1]);
			goto cleanup;
		}

		snprintf(path, sizeof(path), "%s/.", root);
		rc = llapi_file_get_stripe(path, lum_dir);
		if (rc == -ENODATA) {
			free(lum_dir);
			lum_dir = NULL;
		} else if (rc) {
			llapi_error(LLAPI_MSG_ERROR, rc, "error: cant't get "
				    "root's LOVEA for %s\n", path);
			goto cleanup;
		}
	} else if (rc) {
		llapi_error(LLAPI_MSG_ERROR, rc, "error: can't get LOVEA for "
			    "%s", argv[1]);
		goto cleanup;
	}

	/* XXX should be llapi_lov_getname() */
	rc = llapi_file_get_lov_uuid(argv[1], &uuid);
	if (rc) {
		llapi_error(LLAPI_MSG_ERROR, rc,
			    "error: can't get lov name for %s",
			    argv[1]);
		return rc;
	}

	lum_file1 = malloc(lum_size);
	if (lum_file1 == NULL) {
		rc = -ENOMEM;
		llapi_error(LLAPI_MSG_ERROR, rc,
			    "error: can't allocate %d bytes for EA",
			    lum_size);
		goto cleanup;
	}

	rc = llapi_file_get_stripe(argv[2], lum_file1);
	if (rc) {
		llapi_error(LLAPI_MSG_ERROR, rc,
			    "error: unable to get EA for %s", argv[2]);
		goto cleanup;
	}

	if (argc == 4) {
		lum_file2 = (struct lov_user_md *)malloc(lum_size);
		if (lum_file2 == NULL) {
			rc = -ENOMEM;
			llapi_error(LLAPI_MSG_ERROR, rc,
				    "error: can't allocate %d "
				    "bytes for file2 EA", lum_size);
			goto cleanup;
		}

		rc = llapi_file_get_stripe(argv[3], lum_file2);
		if (rc) {
			llapi_error(LLAPI_MSG_ERROR, rc,
				    "error: can't get EA for %s", argv[3]);
			goto cleanup;
		}
	}

	rc = compare_lum(&uuid, lum_dir, lum_file1, lum_file2);

cleanup:
	closedir(dir);
	if (lum_dir != NULL)
		free(lum_dir);
	if (lum_file1 != NULL)
		free(lum_file1);
	if (lum_file2 != NULL)
		free(lum_file2);

	return rc;
}
Пример #3
0
int main(int argc, char **argv)
{
        DIR * dir;
        struct lov_user_md *lum_dir, *lum_file1 = NULL, *lum_file2 = NULL;
        int rc;
        int lum_size;

        if (argc < 3) {
                llapi_err(LLAPI_MSG_ERROR,
                          "Usage: %s <dirname> <filename1> [filename2]\n",
                          argv[0]);
                return 1;
        }

        dir = opendir(argv[1]);
        if (dir == NULL) {
                rc = errno;
                llapi_err(LLAPI_MSG_ERROR,
                          "error: %s opendir failed\n", argv[1]);
                return rc;
        }

        lum_size = lov_mds_md_size(MAX_LOV_UUID_COUNT, LOV_MAGIC);
        if ((lum_dir = (struct lov_user_md *)malloc(lum_size)) == NULL) {
                rc = ENOMEM;
                llapi_err(LLAPI_MSG_ERROR, "error: can't allocate %d bytes "
                          "for dir EA", lum_size);
                goto cleanup;
        }

        rc = llapi_file_get_stripe(argv[1], lum_dir);
        if (rc) {
                if (errno == ENODATA) {
                        free(lum_dir);
                        lum_dir = NULL;
                } else {
                        rc = errno;
                        llapi_err(LLAPI_MSG_ERROR,
                                  "error: can't get EA for %s\n", argv[1]);
                        goto cleanup;
                }
        }

        /* XXX should be llapi_lov_getname() */
        rc = llapi_file_get_lov_uuid(argv[1], &lov_uuid);
        if (rc) {
                rc = errno;
                llapi_err(LLAPI_MSG_ERROR, "error: can't get lov name for %s\n",
                          argv[1]);
                return rc;
        }

        if ((lum_file1 = (struct lov_user_md *)malloc(lum_size)) == NULL) {
                rc = ENOMEM;
                llapi_err(LLAPI_MSG_ERROR,
                          "error: can't allocate %d bytes for EA\n", lum_size);
                goto cleanup;
        }

        rc = llapi_file_get_stripe(argv[2], lum_file1);
        if (rc) {
                rc = errno;
                llapi_err(LLAPI_MSG_ERROR,
                          "error: unable to get EA for %s\n", argv[2]);
                goto cleanup;
        }

        if (argc == 4) {
                lum_file2 = (struct lov_user_md *)malloc(lum_size);
                if (lum_file2 == NULL) {
                        rc = ENOMEM;
                        llapi_err(LLAPI_MSG_ERROR, "error: can't allocate %d "
                                  "bytes for file2 EA\n", lum_size);
                        goto cleanup;
                }

                rc = llapi_file_get_stripe(argv[3], lum_file2);
                if (rc) {
                        rc = errno;
                        llapi_err(LLAPI_MSG_ERROR,
                                  "error: can't get EA for %s\n", argv[3]);
                        goto cleanup;
                }
        }

        rc = compare(lum_dir, lum_file1, lum_file2);

cleanup:
        closedir(dir);
        if (lum_dir != NULL)
                free(lum_dir);
        if (lum_file1 != NULL)
                free(lum_file1);
        if (lum_file2 != NULL)
                free(lum_file2);

        return rc;
}
Пример #4
0
int main(int argc, char *argv[])
{
	struct lov_user_md lum;

	return llapi_file_get_stripe(argv[1], &lum);
}
Пример #5
0
static int hioi_fs_query_lustre (const char *path, hio_fs_attr_t *fs_attr) {
  struct lov_user_md *lum;
  struct find_param param;
  char mountdir[PATH_MAX];
  int rc, fd, obd_count;

  rc = llapi_search_mounts (path, 0, mountdir, NULL);
  if (0 != rc) {
    return hioi_err_errno (-rc);
  }

#if !HAVE_LLAPI_GET_OBD_COUNT
  fd = open (mountdir, O_RDONLY);
  if (-1 == fd) {
    return hioi_err_errno (errno);
  }

  rc = llapi_lov_get_uuids (fd, NULL, &obd_count);
  close (fd);
#else
  rc = llapi_get_obd_count (mountdir, &obd_count, 0);
#endif

  if (0 != rc) {
    return hioi_err_errno (errno);
  }

  fs_attr->fs_flags |= HIO_FS_SUPPORTS_STRIPING | HIO_FS_SUPPORTS_RAID;
  fs_attr->fs_type        = HIO_FS_TYPE_LUSTRE;
  fs_attr->fs_sunit       = 64 * 1024;
  fs_attr->fs_smax_size   = 0x100000000ul;
  fs_attr->fs_smax_count  = obd_count;

  lum = hioi_alloc_lustre_data ();
  assert (NULL != lum);

  rc = llapi_file_get_stripe (path, lum);
  if (0 != rc) {
    /* assuming this is a directory try reading the default for the directory. this
     * should be updated to check the parent directory if path is a file. */
    fd = open (path, O_RDONLY);
    if (-1 == fd) {
      free (lum);
      return hioi_err_errno (errno);
    }

    rc = ioctl (fd, LL_IOC_LOV_GETSTRIPE, lum);
    close (fd);
    if (0 > rc) {
      free (lum);
      return hioi_err_errno (errno);
    }
  }

  fs_attr->fs_scount = lum->lmm_stripe_count ? lum->lmm_stripe_count : 1;
  fs_attr->fs_ssize  = lum->lmm_stripe_size;

  switch (lum->lmm_pattern) {
  case LOV_PATTERN_RAID0:
    fs_attr->fs_raid_level = 0;
    break;
#if defined(LOV_PATTERN_RAID1)
  case LOV_PATTERN_RAID1:
    fs_attr->fs_raid_level = 1;
    break;
#endif
  default:
    fs_attr->fs_raid_level = -1;
    break;
  }

  free (lum);

  return HIO_SUCCESS;
}
Пример #6
0
int File_GetStripeByPath( const char *entry_path, stripe_info_t * p_stripe_info,
                          stripe_items_t * p_stripe_items )
{
    /* buffer used for llapi_get_stripe.
     * oversize it to 4kB because there can be many stripe entries
     * in the case of join'ed files.
     */
    int            rc;
    struct lov_user_md *p_lum;
#ifdef LOV_USER_MAGIC_V3
    struct lov_user_md_v3 *p_lum3;
#endif
    unsigned int   i;

    if ( !entry_path || !entry_path[0] )
        return -EFAULT;

    p_lum = (struct lov_user_md *)MemAlloc(LUM_SIZE_MAX);
    if (!p_lum)
        return -ENOMEM;

    memset(p_lum, 0, LUM_SIZE_MAX);
    rc = llapi_file_get_stripe( entry_path, p_lum );

    if ( rc != 0 )
    {
        if ( rc == -ENODATA )
            DisplayLog( LVL_DEBUG, TAG_STRIPE,
                        "File %s has no stripe information",
                        entry_path );
        else if ( ( rc != -ENOENT ) && ( rc != -ESTALE ) )
            DisplayLog( LVL_CRIT, TAG_STRIPE,
                        "Error %d getting stripe info for %s", rc,
                        entry_path );
        goto out_free;
    }

    /* Check protocol version number */
    if ( p_lum->lmm_magic == LOV_USER_MAGIC_V1 )
    {

        if ( p_stripe_info )
        {
            p_stripe_info->stripe_size = p_lum->lmm_stripe_size;
            p_stripe_info->stripe_count = p_lum->lmm_stripe_count;
            p_stripe_info->pool_name[0] = '\0';
        }

        if ( p_stripe_items )
        {
            p_stripe_items->count = p_lum->lmm_stripe_count;

            if ( p_lum->lmm_stripe_count > 0 )
            {
                p_stripe_items->stripe_units =
                    ( storage_unit_id_t * ) MemCalloc( p_lum->lmm_stripe_count,
                                                       sizeof( storage_unit_id_t ) );
                if (p_stripe_items->stripe_units == NULL)
                {
                    rc = -ENOMEM;
                    goto out_free;
                }

                /* fill OST ids */
                for ( i = 0; i < p_lum->lmm_stripe_count; i++ )
                {
                    p_stripe_items->stripe_units[i] = p_lum->lmm_objects[i].l_ost_idx;
                }
            }
            else
            {
                p_stripe_items->stripe_units = NULL;
            }
        }

        rc = 0;
        goto out_free;
    }
#ifdef LOV_USER_MAGIC_V3
    else if ( p_lum->lmm_magic == LOV_USER_MAGIC_V3 )
    {
        p_lum3 = ( struct lov_user_md_v3 * ) p_lum;

        if ( p_stripe_info )
        {
            p_stripe_info->stripe_size = p_lum3->lmm_stripe_size;
            p_stripe_info->stripe_count = p_lum3->lmm_stripe_count;
            strncpy( p_stripe_info->pool_name, p_lum3->lmm_pool_name, LOV_MAXPOOLNAME );
            p_stripe_info->pool_name[MAX_POOL_LEN-1] = 0;
        }

        if ( p_stripe_items )
        {
            p_stripe_items->count = p_lum3->lmm_stripe_count;

            if ( p_lum3->lmm_stripe_count > 0 )
            {
                p_stripe_items->stripe_units =
                    ( storage_unit_id_t * ) MemCalloc( p_lum3->lmm_stripe_count,
                                                       sizeof( storage_unit_id_t ) );
                if (p_stripe_items->stripe_units == NULL)
                {
                    rc = -ENOMEM;
                    goto out_free;
                }

                /* fill OST ids */
                for ( i = 0; i < p_lum3->lmm_stripe_count; i++ )
                {
                    p_stripe_items->stripe_units[i] = p_lum3->lmm_objects[i].l_ost_idx;
                }
            }
            else
            {
                p_stripe_items->stripe_units = NULL;
            }
        }

        rc = 0;
        goto out_free;
    }
#endif
    else
    {
        DisplayLog( LVL_CRIT, TAG_STRIPE, "Unsupported Luster magic number for %s: %#X",
                    entry_path, p_lum->lmm_magic );
        rc = -EINVAL;
        goto out_free;
    }
out_free:
    MemFree(p_lum);
    return rc;
}
Пример #7
0
int
mca_fs_lustre_file_open (struct ompi_communicator_t *comm,
                     char* filename,
                     int access_mode,
                     struct ompi_info_t *info,
                     mca_io_ompio_file_t *fh)
{
    int amode;
    int old_mask, perm;
    int rc;
    int flag;
    int fs_lustre_stripe_size = -1;
    int fs_lustre_stripe_width = -1;
    char char_stripe[MPI_MAX_INFO_KEY];

    struct lov_user_md *lump=NULL;

    if (fh->f_perm == OMPIO_PERM_NULL) {
        old_mask = umask(022);
        umask(old_mask);
        perm = old_mask ^ 0666;
    }
    else {
        perm = fh->f_perm;
    }

    amode = 0;
    if (access_mode & MPI_MODE_CREATE)
        amode = amode | O_CREAT;
    if (access_mode & MPI_MODE_RDONLY)
        amode = amode | O_RDONLY;
    if (access_mode & MPI_MODE_WRONLY)
        amode = amode | O_WRONLY;
    if (access_mode & MPI_MODE_RDWR)
        amode = amode | O_RDWR;
    if (access_mode & MPI_MODE_EXCL)
        amode = amode | O_EXCL;


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

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

    if (fs_lustre_stripe_size < 0) {
        fs_lustre_stripe_size = mca_fs_lustre_stripe_size;
    }

    if (fs_lustre_stripe_width < 0) {
        fs_lustre_stripe_width = mca_fs_lustre_stripe_width;
    }

    if ( (fs_lustre_stripe_size>0 || fs_lustre_stripe_width>0) &&
        (amode&O_CREAT) && (amode&O_RDWR)) {
        if (0 == fh->f_rank) {
            llapi_file_create(filename,
                              fs_lustre_stripe_size,
                              -1, /* MSC need to change that */
                              fs_lustre_stripe_width,
                              0); /* MSC need to change that */

            fh->fd = open(filename, O_CREAT | O_RDWR | O_LOV_DELAY_CREATE, perm);
            if (fh->fd < 0) {
                fprintf(stderr, "Can't open %s file: %d (%s)\n",
                        filename, errno, strerror(errno));
                return OMPI_ERROR;
            }
            close (fh->fd);
        }
        fh->f_comm->c_coll.coll_barrier (fh->f_comm,
                                         fh->f_comm->c_coll.coll_barrier_module);
    }

    fh->fd = open (filename, amode, perm);
    if (fh->fd < 0) {
        opal_output(1, "error opening file %s\n", filename);
        return OMPI_ERROR;
    }

    if (mca_fs_lustre_stripe_size > 0) {
        fh->f_stripe_size = mca_fs_lustre_stripe_size;
    }
    else {
      lump = alloc_lum();
      if (NULL == lump ){
	fprintf(stderr,"Cannot allocate memory for extracting stripe size\n");
	return OMPI_ERROR;
      }
      rc = llapi_file_get_stripe(filename, lump);
      if (rc != 0) {
          opal_output(1, "get_stripe failed: %d (%s)\n", errno, strerror(errno));
	  return OMPI_ERROR;
      }
      fh->f_stripe_size = lump->lmm_stripe_size;

      //      if ( NULL != lump ) {
      //	free ( lump );
      //      }
    }
    return OMPI_SUCCESS;
}