From 3742646beeb658f321745f5c275836879b9d077d Mon Sep 17 00:00:00 2001 From: Ned Bass Date: Tue, 28 Apr 2015 11:13:28 -0700 Subject: [PATCH] LU-6536 llapi: lmm_stripe_count used unswabbed The function llapi_layout_get_by_fd() uses the value lum->lmm_stripe_count without first checking if it needs to be swabbed. This causes a false error on PowerPC clients because the lov_user_md data appears corrupted. Signed-off-by: Ned Bass Change-Id: I5aacbd5804c784ec8231d51f8c93645fda077102 Reviewed-on: http://review.whamcloud.com/14633 Tested-by: Jenkins Tested-by: Maloo Reviewed-by: John L. Hammond Reviewed-by: Emoly Liu Reviewed-by: Oleg Drokin --- lustre/utils/liblustreapi_layout.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/lustre/utils/liblustreapi_layout.c b/lustre/utils/liblustreapi_layout.c index eff35e2..937d5cc 100644 --- a/lustre/utils/liblustreapi_layout.c +++ b/lustre/utils/liblustreapi_layout.c @@ -402,7 +402,9 @@ struct llapi_layout *llapi_layout_get_by_fd(int fd, uint32_t flags) struct llapi_layout *layout = NULL; ssize_t bytes_read; int object_count; + int lum_stripe_count; struct stat st; + bool need_swab; lum_len = XATTR_SIZE_MAX; lum = malloc(lum_len); @@ -426,6 +428,14 @@ struct llapi_layout *llapi_layout_get_by_fd(int fd, uint32_t flags) object_count = llapi_layout_objects_in_lum(lum, bytes_read); + need_swab = lum->lmm_magic == __swab32(LOV_MAGIC_V1) || + lum->lmm_magic == __swab32(LOV_MAGIC_V3); + + if (need_swab) + lum_stripe_count = __swab16(lum->lmm_stripe_count); + else + lum_stripe_count = lum->lmm_stripe_count; + /* Directories may have a positive non-zero lum->lmm_stripe_count * yet have an empty lum->lmm_objects array. For non-directories the * amount of data returned from the kernel must be consistent @@ -433,13 +443,12 @@ struct llapi_layout *llapi_layout_get_by_fd(int fd, uint32_t flags) if (fstat(fd, &st) < 0) goto out; - if (!S_ISDIR(st.st_mode) && object_count != lum->lmm_stripe_count) { + if (!S_ISDIR(st.st_mode) && object_count != lum_stripe_count) { errno = EINTR; goto out; } - if (lum->lmm_magic == __swab32(LOV_MAGIC_V1) || - lum->lmm_magic == __swab32(LOV_MAGIC_V3)) + if (need_swab) llapi_layout_swab_lov_user_md(lum, object_count); layout = llapi_layout_from_lum(lum, object_count); -- 1.8.3.1