From 28c366cee6dd1ec8293e0a5aed61c9b15d8b9a96 Mon Sep 17 00:00:00 2001 From: Bobi Jam Date: Mon, 23 Oct 2023 15:29:07 +0800 Subject: [PATCH] LU-17218 ofd: improve filter_fid upgrade compatibility filter_fid could be expanded in later Lustre version, and with upgrade then downgrade process, the filter_fid EA on disk could has been expanded during upgrade, and won't work after the downgrade. This patch improves this process by allocating bigger buffer to hold the expanded filter_fid EA then trims the unrecognizable fileds off. Signed-off-by: Bobi Jam Change-Id: I4c99f1d9f3962d46ebf9e9b799988ff3dba4f919 Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/52798 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Oleg Drokin Reviewed-by: Andreas Dilger Reviewed-by: Qian Yingjin Reviewed-by: Alex Zhuravlev --- lustre/ofd/ofd_internal.h | 7 +++++++ lustre/ofd/ofd_objects.c | 14 ++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/lustre/ofd/ofd_internal.h b/lustre/ofd/ofd_internal.h index 55e1639..688c332 100644 --- a/lustre/ofd/ofd_internal.h +++ b/lustre/ofd/ofd_internal.h @@ -179,6 +179,13 @@ static inline char *ofd_name(struct ofd_device *ofd) return ofd->ofd_dt_dev.dd_lu_dev.ld_obd->obd_name; } +/** + * for compatibility, filter_fid could occupy more space in newer version and + * downgraded Lustre would fail reading it with -ERANGE, so it can read it + * again with more space to hold it. + */ +#define FILTER_FID_EXTRA_SIZE 32 + struct ofd_object { struct lu_object_header ofo_header; struct dt_object ofo_obj; diff --git a/lustre/ofd/ofd_objects.c b/lustre/ofd/ofd_objects.c index fe74fa1..a3cdad5 100644 --- a/lustre/ofd/ofd_objects.c +++ b/lustre/ofd/ofd_objects.c @@ -145,6 +145,20 @@ int ofd_object_ff_load(const struct lu_env *env, struct ofd_object *fo) buf->lb_buf = ff; buf->lb_len = sizeof(*ff); rc = dt_xattr_get(env, ofd_object_child(fo), buf, XATTR_NAME_FID); + if (rc == -ERANGE) { + struct filter_fid *ff_new; + + OBD_ALLOC(ff_new, sizeof(*ff) + FILTER_FID_EXTRA_SIZE); + if (!ff_new) + return -ENOMEM; + buf->lb_buf = ff_new; + buf->lb_len = sizeof(*ff) + FILTER_FID_EXTRA_SIZE; + rc = dt_xattr_get(env, ofd_object_child(fo), buf, + XATTR_NAME_FID); + if (rc > 0) + memcpy(ff, ff_new, sizeof(*ff)); + OBD_FREE(ff_new, sizeof(*ff) + FILTER_FID_EXTRA_SIZE); + } if (rc < 0) return rc; -- 1.8.3.1