enum llapi_layout_get_flags flags)
{
struct llapi_layout *layout = NULL;
+ bool failed = false;
+ int open_flags;
int fd;
int tmp;
if (flags & LLAPI_LAYOUT_GET_EXPECTED)
return llapi_layout_expected(path);
- fd = open(path, O_RDONLY);
- if (fd < 0)
- return layout;
+ /* Always get layout in O_DIRECT */
+ /* Allow fetching layout even without the key on encrypted files */
+ open_flags = O_RDONLY | O_DIRECT | O_FILE_ENC;
+do_open:
+ fd = open(path, open_flags);
+ if (fd < 0) {
+ if (errno != EINVAL || failed)
+ return layout;
+ /* EINVAL is because a directory cannot be opened in O_DIRECT */
+ open_flags = O_RDONLY | O_FILE_ENC;
+ failed = true;
+ goto do_open;
+ }
layout = llapi_layout_get_by_fd(fd, flags);
tmp = errno;
* the old API uses 0 and -1.
*/
-static bool llapi_layout_stripe_count_is_valid(int64_t stripe_count)
+bool llapi_layout_stripe_count_is_valid(int64_t stripe_count)
{
return stripe_count == LLAPI_LAYOUT_DEFAULT ||
stripe_count == LLAPI_LAYOUT_WIDE ||
* \retval -1 if arguments are invalid or pool name is too long
*/
int llapi_layout_pool_name_set(struct llapi_layout *layout,
- const char *pool_name)
+ char *pool_name)
{
struct llapi_layout_comp *comp;
- char *ptr;
comp = __llapi_layout_cur_comp(layout);
if (comp == NULL)
return -1;
- if (pool_name == NULL) {
- errno = EINVAL;
- return -1;
- }
-
- /* Strip off any 'fsname.' portion. */
- ptr = strchr(pool_name, '.');
- if (ptr != NULL)
- pool_name = ptr + 1;
-
- if (strlen(pool_name) > LOV_MAXPOOLNAME) {
+ if (!llapi_pool_name_is_valid(&pool_name, NULL)) {
errno = EINVAL;
return -1;
}
strncpy(comp->llc_pool_name, pool_name, sizeof(comp->llc_pool_name));
-
return 0;
}
}
if (layout) {
- rc = llapi_layout_sanity((struct llapi_layout *)layout, false,
+ rc = llapi_layout_sanity((struct llapi_layout *)layout,
+ path, false,
!!(layout->llot_mirror_count > 1));
if (rc) {
llapi_layout_sanity_perror(rc);
return "0";
}
-const __u16 llapi_layout_string_flags(char *string)
+__u16 llapi_layout_string_flags(char *string)
{
if (strncmp(string, "ro", strlen(string)) == 0)
return LCM_FL_RDONLY;
goto out;
}
- rc = llapi_layout_sanity(existing_layout, false, false);
+ rc = llapi_layout_sanity(existing_layout, path, false, false);
if (rc) {
tmp_errno = errno;
llapi_layout_sanity_perror(rc);
goto out;
}
- rc = llapi_layout_sanity(existing_layout, false, false);
+ rc = llapi_layout_sanity(existing_layout, path, false, false);
if (rc) {
tmp_errno = errno;
llapi_layout_sanity_perror(rc);
goto out;
}
- rc = llapi_layout_sanity(existing_layout, false, false);
+ rc = llapi_layout_sanity(existing_layout, path, false, false);
if (rc) {
tmp_errno = errno;
llapi_layout_sanity_perror(rc);
if (m_comp == NULL)
return -EINVAL;
- m_comp->llc_stripe_size = f_comp->llc_stripe_size;
+ /* DoM component does not inherit stripe size */
+ if (m_comp->llc_pattern != LLAPI_LAYOUT_MDT)
+ m_comp->llc_stripe_size = f_comp->llc_stripe_size;
m_comp->llc_stripe_count = f_comp->llc_stripe_count;
return rc;
}
/* locate @layout to a valid component covering file [file_start, file_end) */
-uint32_t llapi_mirror_find(struct llapi_layout *layout,
- uint64_t file_start, uint64_t file_end,
- uint64_t *endp)
+int llapi_mirror_find(struct llapi_layout *layout, uint64_t file_start,
+ uint64_t file_end, uint64_t *endp)
{
uint32_t mirror_id = 0;
int rc;
if (comp_array[i].lrc_synced && pos & (page_size - 1)) {
rc = llapi_mirror_truncate(fd,
comp_array[i].lrc_mirror_id, pos);
- if (rc < 0)
+ /* Ignore truncate error on encrypted file without the
+ * key if tried on LUSTRE_ENCRYPTION_UNIT_SIZE boundary.
+ */
+ if (rc < 0 && (rc != -ENOKEY ||
+ pos & ~LUSTRE_ENCRYPTION_MASK))
comp_array[i].lrc_synced = false;
}
}
LSE_START_GT_END,
LSE_ALIGN_END,
LSE_ALIGN_EXT,
+ LSE_UNKNOWN_OST,
LSE_LAST,
};
"The component end must be aligned by the stripe size",
[LSE_ALIGN_EXT] =
"The extension size must be aligned by the stripe size",
+ [LSE_UNKNOWN_OST] =
+ "An unknown OST idx is specified",
};
struct llapi_layout_sanity_args {
+ char lsa_fsname[MAX_OBD_NAME + 1];
bool lsa_incomplete;
bool lsa_flr;
bool lsa_ondisk;
#define LCME_USER_COMP_FLAGS (LCME_FL_PREF_RW | LCME_FL_NOSYNC | \
LCME_FL_EXTENSION)
+/**
+ * When modified, adjust llapi_stripe_param_verify() if needed as well.
+ */
static int llapi_layout_sanity_cb(struct llapi_layout *layout,
void *arg)
{
goto out_err;
}
+ if (args->lsa_fsname[0] != '\0') {
+ int i, rc = 0;
+
+ if (comp->llc_pattern & LLAPI_LAYOUT_SPECIFIC) {
+ assert(comp->llc_stripe_count <=
+ comp->llc_objects_count);
+
+ for (i = 0; i < comp->llc_stripe_count && rc == 0; i++){
+ if (comp->llc_objects[i].l_ost_idx ==
+ LLAPI_LAYOUT_IDX_MAX) {
+ args->lsa_rc = -1;
+ goto out_err;
+ }
+ rc = llapi_layout_search_ost(
+ comp->llc_objects[i].l_ost_idx,
+ comp->llc_pool_name, args->lsa_fsname);
+ }
+ } else if (comp->llc_stripe_offset != LLAPI_LAYOUT_DEFAULT) {
+ rc = llapi_layout_search_ost(
+ comp->llc_stripe_offset,
+ comp->llc_pool_name, args->lsa_fsname);
+ }
+ if (rc) {
+ args->lsa_rc = LSE_UNKNOWN_OST;
+ goto out_err;
+ }
+ }
+
return LLAPI_LAYOUT_ITER_CONT;
out_err:
* components"?
*
* \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
* \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)
+int llapi_layout_sanity(struct llapi_layout *layout,
+ const char *fname,
+ bool incomplete,
+ bool flr)
{
- struct llapi_layout_sanity_args args;
+ struct llapi_layout_sanity_args args = { { 0 } };
struct llapi_layout_comp *curr;
int rc = 0;
if (!curr)
return 0;
+ /* Make sure we are on a Lustre file system */
+ if (fname) {
+ rc = llapi_search_fsname(fname, args.lsa_fsname);
+ if (rc) {
+ llapi_error(LLAPI_MSG_ERROR, rc,
+ "'%s' is not on a Lustre filesystem",
+ fname);
+ return rc;
+ }
+ }
+
/* Set up args */
args.lsa_rc = 0;
args.lsa_flr = flr;