int llapi_layout_comp_iterate(struct llapi_layout *layout,
llapi_layout_iter_cb cb, void *cbdata);
+int llapi_verify_pool_name(struct llapi_layout *layout, void *arg);
+
/**
* FLR: mirror operation APIs
*/
int llapi_ioctl(int fd, unsigned int cmd, void *buf);
int llapi_layout_sanity(struct llapi_layout *layout, bool incomplete, bool flr);
+int llapi_layout_v2_sanity(struct llapi_layout *layout, bool incomplete,
+ bool flr, char *fsname);
void llapi_layout_sanity_perror(int error);
int llapi_layout_dom_size(struct llapi_layout *layout, uint64_t *size);
# setstripe with the same pool name plus 1 letter
$LFS setstripe -c 1 $DIR/$tdir/testfile1 --pool "${pool}X" &&
- error "setstripe succedeed"
+ error "setstripe succeeded"
rm -f $DIR/$tdir/testfile1
( $LFS getstripe -p $DIR/$tdir | grep -q $pool ) ||
error "fail to set pool on $DIR/$tdir"
- $LFS setstripe -p ignore $DIR/$tdir/$tfile ||
+ local ig_pool="ignore_pool"
+
+ pool_add $ig_pool || error "add $ig_pool failed"
+
+ $LFS setstripe -p $ig_pool $DIR/$tdir/$tfile ||
error "setstripe fail on $DIR/$tdir/$tfile"
- ! ( $LFS getstripe -p $DIR/$tdir/$tfile | egrep -q "[^ ]+" ) ||
+ ( $LFS getstripe -p $DIR/$tdir/$tfile | grep -q $ig_pool ) ||
error "fail to create $DIR/$tdir/$tfile without pool"
# Test with start index
local got idx
for ((idx = 0; idx < OSTCOUNT; idx++)); do
- $LFS setstripe -p ignore -i $idx $DIR/$tdir/$tfile.$idx ||
+ $LFS setstripe -p $ig_pool -i $idx $DIR/$tdir/$tfile.$idx ||
error "setstripe -i fail on $DIR/$tdir/$tfile.$idx"
got=$($LFS getstripe -i $DIR/$tdir/$tfile.$idx)
done
# Test with ost list
- $LFS setstripe -p ignore -o 1,0 $DIR/$tdir/$tfile.1_0 ||
+ $LFS setstripe -p $ig_pool -o 1,0 $DIR/$tdir/$tfile.1_0 ||
error "setstripe --ost fail on $DIR/$tdir/$tfile.1_0"
got=$($LFS getstripe -i $DIR/$tdir/$tfile.1_0)
$LFS setstripe -S 8M -c -1 -p $pool_name $td ||
error "$LFS setstripe $td failed"
+ create_pool $FSNAME.flash || error "create OST pool flash failed"
+ create_pool $FSNAME.archive || error "create OST pool archive failed"
+
# create a mirrored file with plain layout mirrors
$mirror_cmd -N -N -S 4M -c 2 -p flash -i 2 -o 2,3 \
-N -S 16M -N -c -1 -N -p archive -N -p none $tf ||
$LFS setstripe -E 32M -S 8M -c -1 -p $pool_name -E eof -S 16M $td ||
error "$LFS setstripe $td failed"
+ create_pool $FSNAME.flash ||
+ error "create OST pool flash failed"
+ create_pool $FSNAME.archive ||
+ error "create OST pool archive failed"
+
# create a mirrored file with composite layout mirrors
$mirror_cmd -N2 -E 8M -c 2 -p flash -i 1 -o 1,3 -E eof -S 4M \
-N -c 4 -p none \
# create parent directory
mkdir $td || error "mkdir $td failed"
+ create_pool $FSNAME.ssd ||
+ error "create OST pool ssd failed"
+
# create a mirrored file with plain layout mirrors
$LFS mirror create -N -S 32M -c 3 -p ssd -i 1 -o 1,2,3 $tf ||
error "create mirrored file $tf failed"
+ create_pool $FSNAME.flash ||
+ error "create OST pool flash failed"
+ create_pool $FSNAME.archive ||
+ error "create OST pool archive failed"
+
# extend the mirrored file with plain layout mirrors
$mirror_cmd -N -S 4M -c 2 -p flash -i 2 -o 2,3 \
-N -S 16M -N -c -1 -N -p archive -N -p none $tf ||
# create parent directory
mkdir $td || error "mkdir $td failed"
+ create_pool $FSNAME.ssd ||
+ error "create OST pool ssd failed"
+
# create a mirrored file with composite layout mirror
$LFS mirror create -N -E 32M -S 16M -p ssd -E eof -S 32M $tf ||
error "create mirrored file $tf failed"
+ create_pool $FSNAME.flash ||
+ error "create OST pool flash failed"
+ create_pool $FSNAME.archive ||
+ error "create OST pool archive failed"
+
# extend the mirrored file with composite layout mirrors
$mirror_cmd -N -p archive \
-N2 -E 8M -c 2 -p flash -i 1 -o 1,3 -E eof -S 4M \
local file=$DIR/$tdir/$tfile
test_mkdir -p $DIR/$tdir
rm -f $file
+ local p1="pool1"
+ local p2="pool2"
- $LFS setstripe -E1m -c1 -S1m --pool="pool1" -E2m \
- -E4m -c2 -S2m --pool="pool2" -E-1 $file ||
+ create_pool $FSNAME.$p1 || error "create_pool $FSNAME.$p1 failed"
+ create_pool $FSNAME.$p2 || error "create_pool $FSNAME.$p2 failed"
+ $LFS setstripe -E1m -c1 -S1m --pool=$p1 -E2m \
+ -E4m -c2 -S2m --pool=$p2 -E-1 $file ||
error "Create $file failed"
# check --pool inheritance
* Return: 0 on success or a negative error code on failure.
*/
static int mirror_create_sanity_check(const char *fname,
- struct mirror_args *list,
- bool check_fname)
+ struct mirror_args *list)
{
int rc = 0;
bool has_m_file = false;
+ char fsname[MAX_OBD_NAME + 1] = { 0 };
bool has_m_layout = false;
if (!list)
return -EINVAL;
- if (fname && check_fname) {
- struct llapi_layout *layout;
-
- layout = llapi_layout_get_by_path(fname, 0);
- if (!layout) {
- fprintf(stderr,
- "error: %s: file '%s' couldn't get layout\n",
- progname, fname);
- return -ENODATA;
- }
-
- rc = llapi_layout_sanity(layout, false, true);
-
- llapi_layout_free(layout);
-
+ if (fname) {
+ rc = llapi_search_fsname(fname, fsname);
if (rc) {
- llapi_layout_sanity_perror(rc);
+ fprintf(stderr,
+ "error: %s: file '%s' has no fsname\n",
+ progname, fname);
return rc;
}
}
return -EINVAL;
}
}
-
- rc = llapi_layout_sanity(list->m_layout, false, true);
+ rc = llapi_layout_v2_sanity(list->m_layout, false, true,
+ fsname);
if (rc) {
llapi_layout_sanity_perror(rc);
return rc;
int i = 0;
int rc = 0;
- rc = mirror_create_sanity_check(fname, mirror_list, false);
+ rc = mirror_create_sanity_check(fname, mirror_list);
if (rc)
return rc;
}
}
- for (fname = argv[optind]; fname != NULL; fname = argv[++optind]) {
+ for (fname = argv[optind]; (optind < argc) && (fname != NULL);
+ fname = argv[++optind]) {
if (from_copy) {
layout = llapi_layout_get_by_path(template ?: fname, 0);
if (!layout) {
* < 0, error code on failre
*/
static int llapi_stripe_param_verify(const struct llapi_stripe_param *param,
- const char **pool_name)
+ const char **pool_name, char *fsname)
{
int count;
static int page_size;
"Invalid Poolname '%s'", *pool_name);
goto out;
}
+
+ /* Make sure the pool exists */
+ rc = llapi_search_ost(fsname, *pool_name, NULL);
+ if (rc < 0) {
+ llapi_error(LLAPI_MSG_ERROR, rc,
+ "pool '%s fsname %s' does not exist",
+ *pool_name, fsname);
+ rc = -EINVAL;
+ goto out;
+ }
}
out:
int llapi_file_open_param(const char *name, int flags, mode_t mode,
const struct llapi_stripe_param *param)
{
+ char fsname[MAX_OBD_NAME + 1] = { 0 };
struct lov_user_md *lum = NULL;
const char *pool_name = param->lsp_pool;
size_t lum_size;
int fd, rc;
+ /* Make sure we are on a Lustre file system */
+ rc = llapi_search_fsname(name, fsname);
+ if (rc) {
+ llapi_error(LLAPI_MSG_ERROR, rc,
+ "'%s' is not on a Lustre filesystem", name);
+ return rc;
+ }
+
/* Check if the stripe pattern is sane. */
- rc = llapi_stripe_param_verify(param, &pool_name);
- if (rc != 0)
+ rc = llapi_stripe_param_verify(param, &pool_name, fsname);
+ if (rc < 0)
return rc;
if (param->lsp_is_specific)
int tmp;
struct lov_user_md *lum;
size_t lum_size;
+ char fsname[MAX_OBD_NAME + 1] = { 0 };
if (path == NULL ||
(layout != NULL && layout->llot_magic != LLAPI_LAYOUT_MAGIC)) {
}
if (layout) {
- rc = llapi_layout_sanity((struct llapi_layout *)layout, false,
- !!(layout->llot_mirror_count > 1));
+ /* Make sure we are on a Lustre file system */
+ rc = llapi_search_fsname(path, fsname);
+ if (rc) {
+ errno = ENOTTY;
+ return -1;
+ }
+ rc = llapi_layout_v2_sanity((struct llapi_layout *)layout,
+ false,
+ !!(layout->llot_mirror_count > 1),
+ fsname);
if (rc) {
llapi_layout_sanity_perror(rc);
return -1;
int rc, fd = -1, lum_size, tmp_errno = 0;
struct llapi_layout *existing_layout = NULL;
struct lov_user_md *lum = NULL;
+ char fsname[MAX_OBD_NAME + 1] = { 0 };
if (path == NULL || layout == NULL ||
layout->llot_magic != LLAPI_LAYOUT_MAGIC) {
goto out;
}
- rc = llapi_layout_sanity(existing_layout, false, false);
+ rc = llapi_search_fsname(path, fsname);
+ if (rc) {
+ tmp_errno = -rc;
+ rc = -1;
+ goto out;
+ }
+
+ rc = llapi_layout_v2_sanity(existing_layout, false, false, fsname);
if (rc) {
tmp_errno = errno;
llapi_layout_sanity_perror(rc);
struct llapi_layout *layout = NULL;
struct llapi_layout_comp *comp;
struct lov_user_md *lum = NULL;
+ char fsname[MAX_OBD_NAME + 1] = { 0 };
if (path == NULL) {
errno = EINVAL;
goto out;
}
- rc = llapi_layout_sanity(existing_layout, false, false);
+ rc = llapi_search_fsname(path, fsname);
+ if (rc) {
+ tmp_errno = -rc;
+ rc = -1;
+ goto out;
+ }
+
+ rc = llapi_layout_v2_sanity(existing_layout, false, false, fsname);
if (rc) {
tmp_errno = errno;
llapi_layout_sanity_perror(rc);
bool lsa_flr;
bool lsa_ondisk;
int lsa_rc;
+ char *fsname;
};
/* The component flags can be set by users at creation/modification time. */
#define LCME_USER_COMP_FLAGS (LCME_FL_PREF_RW | LCME_FL_NOSYNC | \
LCME_FL_EXTENSION)
+/* Inline function to verify the pool name */
+static inline int verify_pool_name(char *fsname, struct llapi_layout *layout)
+{
+ struct llapi_layout_comp *comp;
+
+ if (!fsname || fsname[0] == '\0')
+ return 0;
+
+ comp = __llapi_layout_cur_comp(layout);
+ if (!comp)
+ return 0;
+ if (comp->llc_pool_name[0] == '\0')
+ return 0;
+ /* check if the pool name exist */
+ if (llapi_search_ost(fsname, comp->llc_pool_name, NULL) < 0)
+ return -1;
+ return 0;
+}
+
/**
* When modified, adjust llapi_stripe_param_verify() if needed as well.
*/
goto out_err;
}
+ if (verify_pool_name(args->fsname, layout) != 0) {
+ args->lsa_rc = -1;
+ goto out_err;
+ }
+
if (comp->llc_list.prev != &layout->llot_comp_list)
prev = list_last_entry(&comp->llc_list, typeof(*prev),
llc_list);
* \retval 0, success, positive: various errors, see
* llapi_layout_sanity_perror, -1, failure
*/
+
int llapi_layout_sanity(struct llapi_layout *layout,
- bool incomplete,
- bool flr)
+ bool incomplete, bool flr)
+{
+ return llapi_layout_v2_sanity(layout, incomplete, flr, NULL);
+}
+
+/* This function has been introduced to do pool name checking
+ * on top of llapi_layout_sanity, the file name passed in this
+ * function is used later to verify if pool exist. The older version
+ * of the sanity function is passing NULL for the filename
+ * Input arguments ---
+ * \param[in] layout component layout list.
+ * \param[in] fname file the layout to be checked for
+ * \param[in] incomplete if layout is complete or not - some checks can
+ * only be done on complete layouts.
+ * \param[in] flr set when this is called from FLR mirror create
+ * \param[in] fsname filesystem name is used to check pool name, if
+ * NULL no pool name check is performed
+ *
+ * \retval 0, success, positive: various errors, see
+ */
+
+int llapi_layout_v2_sanity(struct llapi_layout *layout,
+ bool incomplete, bool flr, char *fsname)
{
struct llapi_layout_sanity_args args = { 0 };
struct llapi_layout_comp *curr;
args.lsa_rc = 0;
args.lsa_flr = flr;
args.lsa_incomplete = incomplete;
+ args.fsname = fsname;
/* When we modify an existing layout, this tells us if it's FLR */
if (mirror_id_of(curr->llc_id) > 0)