Whamcloud - gitweb
LU-810 changelog: Fix hsm_get_cl_xxx() helpers
authorAurelien Degremont <aurelien.degremont@cea.fr>
Fri, 4 Nov 2011 22:01:59 +0000 (23:01 +0100)
committerOleg Drokin <green@whamcloud.com>
Mon, 12 Dec 2011 17:51:42 +0000 (12:51 -0500)
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 <aurelien.degremont@cea.fr>
Change-Id: I7ba1e6a3ec7635b646f7a2dfa8173bf90529fbd9
Reviewed-on: http://review.whamcloud.com/1651
Reviewed-by: Bobi Jam <bobijam@whamcloud.com>
Tested-by: Hudson
Tested-by: Maloo <whamcloud.maloo@gmail.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
lustre/include/lustre/lustre_user.h

index eab9d3c..d371b8d 100644 (file)
@@ -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)