From patchwork Thu Feb 27 21:15:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Simmons X-Patchwork-Id: 11410529 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 77B70138D for ; Thu, 27 Feb 2020 21:40:35 +0000 (UTC) Received: from pdx1-mailman02.dreamhost.com (pdx1-mailman02.dreamhost.com [64.90.62.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 60B3624690 for ; Thu, 27 Feb 2020 21:40:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 60B3624690 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lustre-devel-bounces@lists.lustre.org Received: from pdx1-mailman02.dreamhost.com (localhost [IPv6:::1]) by pdx1-mailman02.dreamhost.com (Postfix) with ESMTP id 5F60434A7D6; Thu, 27 Feb 2020 13:33:02 -0800 (PST) X-Original-To: lustre-devel@lists.lustre.org Delivered-To: lustre-devel-lustre.org@pdx1-mailman02.dreamhost.com Received: from smtp3.ccs.ornl.gov (smtp3.ccs.ornl.gov [160.91.203.39]) by pdx1-mailman02.dreamhost.com (Postfix) with ESMTP id 07ECB21FF50 for ; Thu, 27 Feb 2020 13:20:34 -0800 (PST) Received: from star.ccs.ornl.gov (star.ccs.ornl.gov [160.91.202.134]) by smtp3.ccs.ornl.gov (Postfix) with ESMTP id 71A188F2F; Thu, 27 Feb 2020 16:18:18 -0500 (EST) Received: by star.ccs.ornl.gov (Postfix, from userid 2004) id 704B146D; Thu, 27 Feb 2020 16:18:18 -0500 (EST) From: James Simmons To: Andreas Dilger , Oleg Drokin , NeilBrown Date: Thu, 27 Feb 2020 16:15:07 -0500 Message-Id: <1582838290-17243-440-git-send-email-jsimmons@infradead.org> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1582838290-17243-1-git-send-email-jsimmons@infradead.org> References: <1582838290-17243-1-git-send-email-jsimmons@infradead.org> Subject: [lustre-devel] [PATCH 439/622] lustre: llite: swab LOV EA data in ll_getxattr_lov() X-BeenThere: lustre-devel@lists.lustre.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "For discussing Lustre software development." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Lustre Development List MIME-Version: 1.0 Errors-To: lustre-devel-bounces@lists.lustre.org Sender: "lustre-devel" From: Jian Yu On PPC client, the LOV EA data returned by getfattr from x86_64 server was not swabbed to the host endian. While running setfattr, the data was swabbed in ll_lov_setstripe_ea_info(), which caused magic mis-match in ll_lov_user_md_size() and then ll_setstripe_ea() returned -ERANGE. This patch fixed the above issue by swabbing LOV EA data in ll_getxattr_lov(). WC-bug-id: https://jira.whamcloud.com/browse/LU-12589 Lustre-commit: 5590f5aa94a5 ("LU-12589 llite: swab LOV EA data in ll_getxattr_lov()") Signed-off-by: Jian Yu Reviewed-on: https://review.whamcloud.com/35626 Reviewed-by: Andreas Dilger Reviewed-by: Patrick Farrell Signed-off-by: James Simmons --- fs/lustre/include/lustre_swab.h | 2 +- fs/lustre/llite/dir.c | 4 ++-- fs/lustre/llite/file.c | 4 ++-- fs/lustre/llite/xattr.c | 16 ++++++++-------- fs/lustre/ptlrpc/pack_generic.c | 40 ++++++++++++++++++++++++++++++++++------ 5 files changed, 47 insertions(+), 19 deletions(-) diff --git a/fs/lustre/include/lustre_swab.h b/fs/lustre/include/lustre_swab.h index e99e16d..dd3c50c 100644 --- a/fs/lustre/include/lustre_swab.h +++ b/fs/lustre/include/lustre_swab.h @@ -86,7 +86,7 @@ void lustre_swab_lov_comp_md_v1(struct lov_comp_md_v1 *lum); void lustre_swab_lov_user_md_objects(struct lov_user_ost_data *lod, int stripe_count); -void lustre_swab_lov_user_md(struct lov_user_md *lum); +void lustre_swab_lov_user_md(struct lov_user_md *lum, size_t size); void lustre_swab_lov_mds_md(struct lov_mds_md *lmm); void lustre_swab_lustre_capa(struct lustre_capa *c); void lustre_swab_lustre_capa_key(struct lustre_capa_key *k); diff --git a/fs/lustre/llite/dir.c b/fs/lustre/llite/dir.c index 3540c18..812f535 100644 --- a/fs/lustre/llite/dir.c +++ b/fs/lustre/llite/dir.c @@ -564,7 +564,7 @@ int ll_dir_setstripe(struct inode *inode, struct lov_user_md *lump, */ if ((__swab32(lump->lmm_magic) & le32_to_cpu(LOV_MAGIC_MASK)) == le32_to_cpu(LOV_MAGIC_MAGIC)) - lustre_swab_lov_user_md(lump); + lustre_swab_lov_user_md(lump, 0); } else { lum_size = sizeof(struct lov_user_md_v1); } @@ -696,7 +696,7 @@ int ll_dir_getstripe(struct inode *inode, void **plmm, int *plmm_size, case LOV_MAGIC_COMP_V1: case LOV_USER_MAGIC_SPECIFIC: if (cpu_to_le32(LOV_MAGIC) != LOV_MAGIC) - lustre_swab_lov_user_md((struct lov_user_md *)lmm); + lustre_swab_lov_user_md((struct lov_user_md *)lmm, 0); break; case LMV_MAGIC_V1: if (cpu_to_le32(LMV_MAGIC) != LMV_MAGIC) diff --git a/fs/lustre/llite/file.c b/fs/lustre/llite/file.c index fa61b09..6c5b9eb 100644 --- a/fs/lustre/llite/file.c +++ b/fs/lustre/llite/file.c @@ -1873,7 +1873,7 @@ int ll_lov_setstripe_ea_info(struct inode *inode, struct dentry *dentry, if ((__swab32(lum->lmm_magic) & le32_to_cpu(LOV_MAGIC_MASK)) == le32_to_cpu(LOV_MAGIC_MAGIC)) { /* this code will only exist for big-endian systems */ - lustre_swab_lov_user_md(lum); + lustre_swab_lov_user_md(lum, 0); } ll_inode_size_lock(inode); @@ -1956,7 +1956,7 @@ int ll_lov_getstripe_ea_info(struct inode *inode, const char *filename, stripe_count = 0; } - lustre_swab_lov_user_md((struct lov_user_md *)lmm); + lustre_swab_lov_user_md((struct lov_user_md *)lmm, 0); /* if function called for directory - we should * avoid swab not existent lsm objects diff --git a/fs/lustre/llite/xattr.c b/fs/lustre/llite/xattr.c index cf1cfd2..4e1ce34 100644 --- a/fs/lustre/llite/xattr.c +++ b/fs/lustre/llite/xattr.c @@ -320,7 +320,7 @@ static int ll_xattr_set(const struct xattr_handler *handler, if (strncmp(name, "lov.", 4) == 0 && (__swab32(((struct lov_user_md *)value)->lmm_magic) & le32_to_cpu(LOV_MAGIC_MASK)) == le32_to_cpu(LOV_MAGIC_MAGIC)) - lustre_swab_lov_user_md((struct lov_user_md *)value); + lustre_swab_lov_user_md((struct lov_user_md *)value, 0); return ll_xattr_set_common(handler, dentry, inode, name, value, size, flags); @@ -459,7 +459,6 @@ static ssize_t ll_getxattr_lov(struct inode *inode, void *buf, size_t buf_size) }; struct lu_env *env; u16 refcheck; - u32 magic; if (!obj) return -ENODATA; @@ -490,12 +489,12 @@ static ssize_t ll_getxattr_lov(struct inode *inode, void *buf, size_t buf_size) * recognizing layout gen as stripe offset when the * file is restored. See LU-2809. */ - magic = ((struct lov_mds_md *)buf)->lmm_magic; - if ((magic & __swab32(LOV_MAGIC_MAGIC)) == - __swab32(LOV_MAGIC_MAGIC)) - magic = __swab32(magic); + if ((((struct lov_mds_md *)buf)->lmm_magic & + __swab32(LOV_MAGIC_MAGIC)) == __swab32(LOV_MAGIC_MAGIC)) + lustre_swab_lov_user_md((struct lov_user_md *)buf, + cl.cl_size); - switch (magic) { + switch (((struct lov_mds_md *)buf)->lmm_magic) { case LOV_MAGIC_V1: case LOV_MAGIC_V3: case LOV_MAGIC_SPECIFIC: @@ -505,7 +504,8 @@ static ssize_t ll_getxattr_lov(struct inode *inode, void *buf, size_t buf_size) case LOV_MAGIC_FOREIGN: goto out_env; default: - CERROR("Invalid LOV magic %08x\n", magic); + CERROR("Invalid LOV magic %08x\n", + ((struct lov_mds_md *)buf)->lmm_magic); rc = -EINVAL; goto out_env; } diff --git a/fs/lustre/ptlrpc/pack_generic.c b/fs/lustre/ptlrpc/pack_generic.c index b066113..6a4ea7a 100644 --- a/fs/lustre/ptlrpc/pack_generic.c +++ b/fs/lustre/ptlrpc/pack_generic.c @@ -2147,23 +2147,51 @@ void lustre_swab_lov_user_md_objects(struct lov_user_ost_data *lod, } EXPORT_SYMBOL(lustre_swab_lov_user_md_objects); -void lustre_swab_lov_user_md(struct lov_user_md *lum) +void lustre_swab_lov_user_md(struct lov_user_md *lum, size_t size) { + struct lov_user_md_v1 *v1; + struct lov_user_md_v3 *v3; + struct lov_foreign_md *lfm; + u16 stripe_count; + CDEBUG(D_IOCTL, "swabbing lov_user_md\n"); switch (lum->lmm_magic) { case __swab32(LOV_MAGIC_V1): case LOV_USER_MAGIC_V1: - lustre_swab_lov_user_md_v1((struct lov_user_md_v1 *)lum); + { + v1 = (struct lov_user_md_v1 *)lum; + stripe_count = v1->lmm_stripe_count; + + if (lum->lmm_magic != LOV_USER_MAGIC_V1) + __swab16s(&stripe_count); + + lustre_swab_lov_user_md_v1(v1); + if (size > sizeof(*v1)) + lustre_swab_lov_user_md_objects(v1->lmm_objects, + stripe_count); + break; + } case __swab32(LOV_MAGIC_V3): case LOV_USER_MAGIC_V3: - lustre_swab_lov_user_md_v3((struct lov_user_md_v3 *)lum); + { + v3 = (struct lov_user_md_v3 *)lum; + stripe_count = v3->lmm_stripe_count; + + if (lum->lmm_magic != LOV_USER_MAGIC_V3) + __swab16s(&stripe_count); + + lustre_swab_lov_user_md_v3(v3); + if (size > sizeof(*v3)) + lustre_swab_lov_user_md_objects(v3->lmm_objects, + stripe_count); break; + } case __swab32(LOV_USER_MAGIC_SPECIFIC): case LOV_USER_MAGIC_SPECIFIC: { - struct lov_user_md_v3 *v3 = (struct lov_user_md_v3 *)lum; - u16 stripe_count = v3->lmm_stripe_count; + v3 = (struct lov_user_md_v3 *)lum; + stripe_count = v3->lmm_stripe_count; if (lum->lmm_magic != LOV_USER_MAGIC_SPECIFIC) __swab16s(&stripe_count); @@ -2179,7 +2207,7 @@ void lustre_swab_lov_user_md(struct lov_user_md *lum) case __swab32(LOV_MAGIC_FOREIGN): case LOV_USER_MAGIC_FOREIGN: { - struct lov_foreign_md *lfm = (struct lov_foreign_md *)lum; + lfm = (struct lov_foreign_md *)lum; __swab32s(&lfm->lfm_magic); __swab32s(&lfm->lfm_length);