From eac03ca97867240b3a1b3eced666a6a7aaddf60c Mon Sep 17 00:00:00 2001 From: Nikitas Angelinas Date: Fri, 6 Jan 2023 21:01:52 +0200 Subject: [PATCH] LU-16464 osp: fix off-by-one errors in oxe_can_hold() There are a couple of off-by-one errors when calculating the required buffer size in oxe_can_hold(), which can cause the xattr entry to be reallocated unnecessarily. HPE-bug-id: LUS-11423 Fixes: a1c5adf7f466 ("LU-14607 osp: separate buffer for large XATTR") Change-Id: I486963066d7f8783ad64f1ea110fb73db0a8274b Signed-off-by: Nikitas Angelinas Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/49617 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Andreas Dilger Reviewed-by: Lai Siyao Reviewed-by: Oleg Drokin --- lustre/osp/osp_object.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lustre/osp/osp_object.c b/lustre/osp/osp_object.c index a2f245b..078b1e3 100644 --- a/lustre/osp/osp_object.c +++ b/lustre/osp/osp_object.c @@ -340,13 +340,21 @@ osp_oac_xattr_find_or_add(struct osp_object *obj, const char *name, size_t len) return oxe; } -/* whether \a oxe is large enough to hold XATTR value */ +/** + * Check whether \a oxe is large enough to hold the xattr value + * + * \param[in] oxe pointer to the OSP object attributes cache xattr entry + * \param[in] len xattr value size in bytes + * + * \retval true if xattr can fit in \a oxe + * \retval false if xattr can not fit in \a oxe + */ static inline bool oxe_can_hold(struct osp_xattr_entry *oxe, size_t len) { if (unlikely(oxe->oxe_largebuf)) - return oxe->oxe_buflen > len; + return oxe->oxe_buflen >= len; - return oxe->oxe_buflen - oxe->oxe_namelen - 1 - sizeof(*oxe) > len; + return oxe->oxe_buflen - oxe->oxe_namelen - 1 - sizeof(*oxe) >= len; } /** -- 1.8.3.1