Ejemplo n.º 1
0
int main(int argc, char *argv[])
{
	char fsname[8 + 1];
	int rc;

	process_args(argc, argv);
	if (lustre_dir == NULL)
		lustre_dir = "/mnt/lustre";

	rc = llapi_search_mounts(lustre_dir, 0, fsmountdir, fsname);
	if (rc != 0) {
		fprintf(stderr, "Error: '%s': not a Lustre filesystem\n",
			lustre_dir);
		return EXIT_FAILURE;
	}

	/* Play nice with Lustre test scripts. Non-line buffered output
	 * stream under I/O redirection may appear incorrectly. */
	setvbuf(stdout, NULL, _IOLBF, 0);

	/* Create a test filename and reuse it. Remove possibly old files. */
	rc = snprintf(mainpath, sizeof(mainpath), "%s/%s", lustre_dir, maindir);
	ASSERTF(rc > 0 && rc < sizeof(mainpath), "invalid name for mainpath");
	cleanup();

	atexit(cleanup);

	PERFORM(test10);
	PERFORM(test11);
	PERFORM(test12);
	PERFORM(test20);
	PERFORM(test30);

	return EXIT_SUCCESS;
}
Ejemplo n.º 2
0
int main(int argc, char *argv[])
{
	char fsname[8 + 1];
	int rc;

	process_args(argc, argv);
	if (lustre_dir == NULL)
		lustre_dir = "/mnt/lustre";

	rc = llapi_search_mounts(lustre_dir, 0, fsmountdir, fsname);
	if (rc != 0) {
		fprintf(stderr, "Error: %s: not a Lustre filesystem\n",
			lustre_dir);
		return EXIT_FAILURE;
	}

	/* Play nice with Lustre test scripts. Non-line buffered output
	 * stream under I/O redirection may appear incorrectly. */
	setvbuf(stdout, NULL, _IOLBF, 0);

	PERFORM(test1);
	PERFORM(test2);
	PERFORM(test3);
	PERFORM(test4);
	PERFORM(test5);
	PERFORM(test6);
	PERFORM(test7);
	PERFORM(test50);
	PERFORM(test51);
	PERFORM(test52);
	PERFORM(test100);
	PERFORM(test101);
	PERFORM(test102);
	PERFORM(test103);
	PERFORM(test104);
	PERFORM(test105);
	PERFORM(test106);
	PERFORM(test107);
	PERFORM(test108);
	PERFORM(test109);
	PERFORM(test110);
	PERFORM(test111);
	PERFORM(test112);

	return EXIT_SUCCESS;
}
Ejemplo n.º 3
0
/**
 * Get the expected striping layout for a file at \a path.
 *
 * Substitute expected inherited attribute values for unspecified
 * attributes.  Unspecified attributes may belong to directories and
 * never-written-to files, and indicate that default values will be
 * assigned when files are created or first written to.  A default value
 * is inherited from the parent directory if the attribute is specified
 * there, otherwise it is inherited from the filesystem root.
 * Unspecified attributes normally have the value LLAPI_LAYOUT_DEFAULT.
 *
 * The complete \a path need not refer to an existing file or directory,
 * but some leading portion of it must reside within a lustre filesystem.
 * A use case for this interface would be to obtain the literal striping
 * values that would be assigned to a new file in a given directory.
 *
 * \param[in] path	path for which to get the expected layout
 *
 * \retval	valid llapi_layout pointer on success
 * \retval	NULL if an error occurs
 */
static struct llapi_layout *llapi_layout_expected(const char *path)
{
    struct llapi_layout	*path_layout = NULL;
    struct llapi_layout	*donor_layout;
    char			donor_path[PATH_MAX];
    struct stat st;
    int fd;
    int rc;

    fd = open(path, O_RDONLY);
    if (fd < 0 && errno != ENOENT)
        return NULL;

    if (fd >= 0) {
        int tmp;

        path_layout = llapi_layout_get_by_fd(fd, 0);
        tmp = errno;
        close(fd);
        errno = tmp;
    }

    if (path_layout == NULL) {
        if (errno != ENODATA && errno != ENOENT)
            return NULL;

        path_layout = llapi_layout_alloc();
        if (path_layout == NULL)
            return NULL;
    }

    if (is_fully_specified(path_layout))
        return path_layout;

    rc = stat(path, &st);
    if (rc < 0 && errno != ENOENT) {
        llapi_layout_free(path_layout);
        return NULL;
    }

    /* If path is a not a directory or doesn't exist, inherit unspecified
     * attributes from parent directory. */
    if ((rc == 0 && !S_ISDIR(st.st_mode)) ||
            (rc < 0 && errno == ENOENT)) {
        get_parent_dir(path, donor_path, sizeof(donor_path));
        donor_layout = llapi_layout_get_by_path(donor_path, 0);
        if (donor_layout != NULL) {
            inherit_layout_attributes(donor_layout, path_layout);
            llapi_layout_free(donor_layout);
            if (is_fully_specified(path_layout))
                return path_layout;
        }
    }

    /* Inherit remaining unspecified attributes from the filesystem root. */
    rc = llapi_search_mounts(path, 0, donor_path, NULL);
    if (rc < 0) {
        llapi_layout_free(path_layout);
        return NULL;
    }
    donor_layout = llapi_layout_get_by_path(donor_path, 0);
    if (donor_layout == NULL) {
        llapi_layout_free(path_layout);
        return NULL;
    }

    inherit_layout_attributes(donor_layout, path_layout);
    llapi_layout_free(donor_layout);

    return path_layout;
}
Ejemplo n.º 4
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;
}
Ejemplo n.º 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;
}