From 6fa0e7eec2ccf9a2759d803de822754c6a82b6f0 Mon Sep 17 00:00:00 2001 From: Aurelien Degremont Date: Fri, 4 Nov 2011 23:01:59 +0100 Subject: [PATCH] LU-810 changelog: Fix hsm_get_cl_xxx() helpers Fix helpers for extracting information from HSM changelog records. HSM records in changelog contain additionnal information from standard records. This includes HSM event, error code and some flags. Macros helpers exist to help user-space tools, like Policy Engine, to extract them. Those helpers were broken, this fixes them. Signed-off-by: Aurelien Degremont Change-Id: I7ba1e6a3ec7635b646f7a2dfa8173bf90529fbd9 Reviewed-on: http://review.whamcloud.com/1651 Reviewed-by: Bobi Jam Tested-by: Hudson Tested-by: Maloo Reviewed-by: Andreas Dilger --- lustre/include/lustre/lustre_user.h | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/lustre/include/lustre/lustre_user.h b/lustre/include/lustre/lustre_user.h index eab9d3c..d371b8d 100644 --- a/lustre/include/lustre/lustre_user.h +++ b/lustre/include/lustre/lustre_user.h @@ -536,9 +536,10 @@ static inline const char *changelog_type2str(int type) { #define CLF_HSM_SPARE_H 15 #define CLF_HSM_LAST 15 -#define CLF_GET_BITS(_b, _h, _l) \ - _b &= (0xFFFF << (CLF_HSM_LAST - _h)); \ - _b = _b >> (_l + CLF_HSM_LAST - _h) +/* Remove bits higher than _h, then extract the value + * between _h and _l by shifting lower weigth to bit 0. */ +#define CLF_GET_BITS(_b, _h, _l) (((_b << (CLF_HSM_LAST - _h)) & 0xFFFF) \ + >> (CLF_HSM_LAST - _h + _l)) #define CLF_HSM_SUCCESS 0x00 #define CLF_HSM_MAXERROR 0x7E @@ -560,11 +561,7 @@ enum hsm_event { static inline enum hsm_event hsm_get_cl_event(__u16 flags) { - enum hsm_event he; - - CLF_GET_BITS(flags, CLF_HSM_EVENT_H, CLF_HSM_EVENT_L); - he = flags; - return he; + return CLF_GET_BITS(flags, CLF_HSM_EVENT_H, CLF_HSM_EVENT_L); } static inline void hsm_set_cl_event(int *flags, enum hsm_event he) @@ -574,8 +571,7 @@ static inline void hsm_set_cl_event(int *flags, enum hsm_event he) static inline __u16 hsm_get_cl_flags(int flags) { - CLF_GET_BITS(flags, CLF_HSM_FLAG_H, CLF_HSM_FLAG_L); - return flags; + return CLF_GET_BITS(flags, CLF_HSM_FLAG_H, CLF_HSM_FLAG_L); } static inline void hsm_set_cl_flags(int *flags, int bits) @@ -585,8 +581,7 @@ static inline void hsm_set_cl_flags(int *flags, int bits) static inline int hsm_get_cl_error(int flags) { - CLF_GET_BITS(flags, CLF_HSM_ERR_H, CLF_HSM_ERR_L); - return flags; + return CLF_GET_BITS(flags, CLF_HSM_ERR_H, CLF_HSM_ERR_L); } static inline void hsm_set_cl_error(int *flags, int error) -- 1.8.3.1