From 54c4af4ff432f45adc8bd697d9097dc570eae49b Mon Sep 17 00:00:00 2001
From: Rob Latham <robl@mcs.anl.gov>
Date: Wed, 10 Jul 2019 17:04:27 -0500
Subject: [PATCH] LU-12527 utils: Make lustre_user.h c++-legal

recent c++ compilers did not like some of the C idioms used in this
header:
- C++ checks the types of enums more forecfully than is done in C
- signed vs unsigned comparisons will generate a warning under g++
- "invalid suffix on literal" warning: Lustre is not trying to
  generate a new literal identifier.

Signed-off-by: Rob Latham <robl@mcs.anl.gov>
Change-Id: I6aa8ba18407c14e071a7e2943b5a1a3f5be27bac
---
 .../include/uapi/linux/lustre/lustre_user.h   | 115 ++++++++++--------
 1 file changed, 65 insertions(+), 50 deletions(-)

diff --git a/lustre/include/uapi/linux/lustre/lustre_user.h b/lustre/include/uapi/linux/lustre/lustre_user.h
index 66c8fd1e..06d888c7 100644
--- a/lustre/include/uapi/linux/lustre/lustre_user.h
+++ b/lustre/include/uapi/linux/lustre/lustre_user.h
@@ -958,7 +958,7 @@ static inline void obd_uuid2fsname(char *buf, char *uuid, int buflen)
 #define FID_NOBRACE_LEN 40
 #define FID_LEN (FID_NOBRACE_LEN + 2)
 #define DFID_NOBRACE "%#llx:0x%x:0x%x"
-#define DFID "["DFID_NOBRACE"]"
+#define DFID "[" DFID_NOBRACE "]"
 #define PFID(fid) (unsigned long long)(fid)->f_seq, (fid)->f_oid, (fid)->f_ver
 
 /* scanf input parse format for fids in DFID_NOBRACE format
@@ -1017,7 +1017,7 @@ static inline __u64 lustre_stoqb(size_t space)
 #define LQUOTA_FLAG_DEFAULT	0x0001
 
 #define ALLQUOTA 255       /* set all quota */
-static inline char *qtype_name(int qtype)
+static inline const char *qtype_name(int qtype)
 {
 	switch (qtype) {
 	case USRQUOTA:
@@ -1349,7 +1349,8 @@ static inline enum hsm_event hsm_get_cl_event(__u16 flags)
 static inline void hsm_set_cl_event(enum changelog_rec_flags *clf_flags,
 				    enum hsm_event he)
 {
-	*clf_flags |= (he << CLF_HSM_EVENT_L);
+	*clf_flags = (enum changelog_rec_flags) (*clf_flags |
+                (he << CLF_HSM_EVENT_L));
 }
 
 static inline __u16 hsm_get_cl_flags(enum changelog_rec_flags clf_flags)
@@ -1360,7 +1361,8 @@ static inline __u16 hsm_get_cl_flags(enum changelog_rec_flags clf_flags)
 static inline void hsm_set_cl_flags(enum changelog_rec_flags *clf_flags,
 				    unsigned int bits)
 {
-	*clf_flags |= (bits << CLF_HSM_FLAG_L);
+	*clf_flags = (enum changelog_rec_flags) (*clf_flags |
+                (bits << CLF_HSM_FLAG_L));
 }
 
 static inline int hsm_get_cl_error(enum changelog_rec_flags clf_flags)
@@ -1371,7 +1373,8 @@ static inline int hsm_get_cl_error(enum changelog_rec_flags clf_flags)
 static inline void hsm_set_cl_error(enum changelog_rec_flags *clf_flags,
 				    unsigned int error)
 {
-	*clf_flags |= (error << CLF_HSM_ERR_L);
+	*clf_flags = (enum changelog_rec_flags) (*clf_flags |
+                (error << CLF_HSM_ERR_L));
 }
 
 enum changelog_rec_extra_flags {
@@ -1510,9 +1513,10 @@ static inline size_t changelog_rec_size(const struct changelog_rec *rec)
 	enum changelog_rec_extra_flags cref = CLFE_INVALID;
 
 	if (rec->cr_flags & CLF_EXTRA_FLAGS)
-		cref = changelog_rec_extra_flags(rec)->cr_extra_flags;
+		cref = (enum changelog_rec_extra_flags)
+                    changelog_rec_extra_flags(rec)->cr_extra_flags;
 
-	return changelog_rec_offset(rec->cr_flags, cref);
+	return changelog_rec_offset((enum changelog_rec_flags)rec->cr_flags, cref);
 }
 
 static inline size_t changelog_rec_varsize(const struct changelog_rec *rec)
@@ -1523,7 +1527,8 @@ static inline size_t changelog_rec_varsize(const struct changelog_rec *rec)
 static inline
 struct changelog_ext_rename *changelog_rec_rename(const struct changelog_rec *rec)
 {
-	enum changelog_rec_flags crf = rec->cr_flags & CLF_VERSION;
+	enum changelog_rec_flags crf = (enum changelog_rec_flags)
+            (rec->cr_flags & CLF_VERSION);
 
 	return (struct changelog_ext_rename *)((char *)rec +
 					       changelog_rec_offset(crf,
@@ -1534,8 +1539,8 @@ struct changelog_ext_rename *changelog_rec_rename(const struct changelog_rec *re
 static inline
 struct changelog_ext_jobid *changelog_rec_jobid(const struct changelog_rec *rec)
 {
-	enum changelog_rec_flags crf = rec->cr_flags &
-					(CLF_VERSION | CLF_RENAME);
+	enum changelog_rec_flags crf = (enum changelog_rec_flags)(rec->cr_flags &
+					(CLF_VERSION | CLF_RENAME));
 
 	return (struct changelog_ext_jobid *)((char *)rec +
 					      changelog_rec_offset(crf,
@@ -1547,8 +1552,8 @@ static inline
 struct changelog_ext_extra_flags *changelog_rec_extra_flags(
 	const struct changelog_rec *rec)
 {
-	enum changelog_rec_flags crf = rec->cr_flags &
-		(CLF_VERSION | CLF_RENAME | CLF_JOBID);
+	enum changelog_rec_flags crf = (enum changelog_rec_flags)(rec->cr_flags &
+		(CLF_VERSION | CLF_RENAME | CLF_JOBID));
 
 	return (struct changelog_ext_extra_flags *)((char *)rec +
 						 changelog_rec_offset(crf,
@@ -1560,8 +1565,8 @@ static inline
 struct changelog_ext_uidgid *changelog_rec_uidgid(
 	const struct changelog_rec *rec)
 {
-	enum changelog_rec_flags crf = rec->cr_flags &
-		(CLF_VERSION | CLF_RENAME | CLF_JOBID | CLF_EXTRA_FLAGS);
+	enum changelog_rec_flags crf = (enum changelog_rec_flags)(rec->cr_flags &
+		(CLF_VERSION | CLF_RENAME | CLF_JOBID | CLF_EXTRA_FLAGS));
 
 	return (struct changelog_ext_uidgid *)((char *)rec +
 					       changelog_rec_offset(crf,
@@ -1572,13 +1577,14 @@ struct changelog_ext_uidgid *changelog_rec_uidgid(
 static inline
 struct changelog_ext_nid *changelog_rec_nid(const struct changelog_rec *rec)
 {
-	enum changelog_rec_flags crf = rec->cr_flags &
-		(CLF_VERSION | CLF_RENAME | CLF_JOBID | CLF_EXTRA_FLAGS);
+	enum changelog_rec_flags crf = (enum changelog_rec_flags)(rec->cr_flags &
+		(CLF_VERSION | CLF_RENAME | CLF_JOBID | CLF_EXTRA_FLAGS));
 	enum changelog_rec_extra_flags cref = CLFE_INVALID;
 
 	if (rec->cr_flags & CLF_EXTRA_FLAGS)
-		cref = changelog_rec_extra_flags(rec)->cr_extra_flags &
-		       CLFE_UIDGID;
+		cref = (enum changelog_rec_extra_flags)
+                    (changelog_rec_extra_flags(rec)->cr_extra_flags &
+		       CLFE_UIDGID);
 
 	return (struct changelog_ext_nid *)((char *)rec +
 					    changelog_rec_offset(crf, cref));
@@ -1589,13 +1595,14 @@ static inline
 struct changelog_ext_openmode *changelog_rec_openmode(
 	const struct changelog_rec *rec)
 {
-	enum changelog_rec_flags crf = rec->cr_flags &
-		(CLF_VERSION | CLF_RENAME | CLF_JOBID | CLF_EXTRA_FLAGS);
+	enum changelog_rec_flags crf = (enum changelog_rec_flags)(rec->cr_flags &
+		(CLF_VERSION | CLF_RENAME | CLF_JOBID | CLF_EXTRA_FLAGS));
 	enum changelog_rec_extra_flags cref = CLFE_INVALID;
 
 	if (rec->cr_flags & CLF_EXTRA_FLAGS)
-		cref = changelog_rec_extra_flags(rec)->cr_extra_flags &
-		       (CLFE_UIDGID | CLFE_NID);
+		cref = (enum changelog_rec_extra_flags)
+                    (changelog_rec_extra_flags(rec)->cr_extra_flags &
+		       (CLFE_UIDGID | CLFE_NID));
 
 	return (struct changelog_ext_openmode *)((char *)rec +
 					       changelog_rec_offset(crf, cref));
@@ -1606,13 +1613,14 @@ static inline
 struct changelog_ext_xattr *changelog_rec_xattr(
 	const struct changelog_rec *rec)
 {
-	enum changelog_rec_flags crf = rec->cr_flags &
-		(CLF_VERSION | CLF_RENAME | CLF_JOBID | CLF_EXTRA_FLAGS);
+	enum changelog_rec_flags crf = (enum changelog_rec_flags)(rec->cr_flags &
+		(CLF_VERSION | CLF_RENAME | CLF_JOBID | CLF_EXTRA_FLAGS));
 	enum changelog_rec_extra_flags cref = CLFE_INVALID;
 
 	if (rec->cr_flags & CLF_EXTRA_FLAGS)
-		cref = changelog_rec_extra_flags(rec)->cr_extra_flags &
-			(CLFE_UIDGID | CLFE_NID | CLFE_OPEN);
+		cref = (enum changelog_rec_extra_flags)
+                    (changelog_rec_extra_flags(rec)->cr_extra_flags &
+			(CLFE_UIDGID | CLFE_NID | CLFE_OPEN));
 
 	return (struct changelog_ext_xattr *)((char *)rec +
 					      changelog_rec_offset(crf, cref));
@@ -1624,10 +1632,12 @@ static inline char *changelog_rec_name(const struct changelog_rec *rec)
 	enum changelog_rec_extra_flags cref = CLFE_INVALID;
 
 	if (rec->cr_flags & CLF_EXTRA_FLAGS)
-		cref = changelog_rec_extra_flags(rec)->cr_extra_flags;
+		cref = (enum changelog_rec_extra_flags)
+                    changelog_rec_extra_flags(rec)->cr_extra_flags;
 
-	return (char *)rec + changelog_rec_offset(rec->cr_flags & CLF_SUPPORTED,
-						  cref & CLFE_SUPPORTED);
+	return (char *)rec + changelog_rec_offset(
+                (enum changelog_rec_flags)(rec->cr_flags & CLF_SUPPORTED),
+                (enum changelog_rec_extra_flags)(cref & CLFE_SUPPORTED));
 }
 
 static inline size_t changelog_rec_snamelen(const struct changelog_rec *rec)
@@ -1676,8 +1686,8 @@ static inline void changelog_remap_rec(struct changelog_rec *rec,
 	char *rnm_mov;
 	enum changelog_rec_extra_flags cref = CLFE_INVALID;
 
-	crf_wanted &= CLF_SUPPORTED;
-	cref_want &= CLFE_SUPPORTED;
+	crf_wanted = (enum changelog_rec_flags)(crf_wanted & CLF_SUPPORTED);
+	cref_want = (enum changelog_rec_extra_flags)(cref_want & CLFE_SUPPORTED);
 
 	if ((rec->cr_flags & CLF_SUPPORTED) == crf_wanted) {
 		if (!(rec->cr_flags & CLF_EXTRA_FLAGS) ||
@@ -1695,38 +1705,43 @@ static inline void changelog_remap_rec(struct changelog_rec *rec,
 	/* Locations of extensions in the remapped record */
 	if (rec->cr_flags & CLF_EXTRA_FLAGS) {
 		xattr_mov = (char *)rec +
-			changelog_rec_offset(crf_wanted & CLF_SUPPORTED,
-					     cref_want & ~CLFE_XATTR);
+			changelog_rec_offset(
+                                (enum changelog_rec_flags)(crf_wanted & CLF_SUPPORTED),
+                                (enum changelog_rec_extra_flags)(cref_want & ~CLFE_XATTR));
 		omd_mov = (char *)rec +
-			changelog_rec_offset(crf_wanted & CLF_SUPPORTED,
-					     cref_want & ~(CLFE_OPEN |
-							   CLFE_XATTR));
+			changelog_rec_offset(
+                                (enum changelog_rec_flags)(crf_wanted & CLF_SUPPORTED),
+                                (enum changelog_rec_extra_flags)(cref_want & ~(CLFE_OPEN |
+							   CLFE_XATTR)));
 		nid_mov = (char *)rec +
-			changelog_rec_offset(crf_wanted & CLF_SUPPORTED,
-					     cref_want & ~(CLFE_NID |
-							   CLFE_OPEN |
-							   CLFE_XATTR));
+			changelog_rec_offset(
+                                (enum changelog_rec_flags)(crf_wanted & CLF_SUPPORTED),
+                                (enum changelog_rec_extra_flags)(cref_want & ~(CLFE_NID |
+							   CLFE_OPEN | CLFE_XATTR)));
 		uidgid_mov = (char *)rec +
-			changelog_rec_offset(crf_wanted & CLF_SUPPORTED,
-					     cref_want & ~(CLFE_UIDGID |
+			changelog_rec_offset(
+                                (enum changelog_rec_flags)(crf_wanted & CLF_SUPPORTED),
+                                (enum changelog_rec_extra_flags)(cref_want & ~(CLFE_UIDGID |
 							   CLFE_NID |
 							   CLFE_OPEN |
-							   CLFE_XATTR));
-		cref = changelog_rec_extra_flags(rec)->cr_extra_flags;
+							   CLFE_XATTR)));
+		cref = (enum changelog_rec_extra_flags)
+                    changelog_rec_extra_flags(rec)->cr_extra_flags;
 	}
 
 	ef_mov  = (char *)rec +
-		  changelog_rec_offset(crf_wanted & ~CLF_EXTRA_FLAGS,
+		  changelog_rec_offset(
+                          (enum changelog_rec_flags)(crf_wanted & ~CLF_EXTRA_FLAGS),
 				       CLFE_INVALID);
 	jid_mov = (char *)rec +
-		  changelog_rec_offset(crf_wanted &
-				       ~(CLF_EXTRA_FLAGS | CLF_JOBID),
+		  changelog_rec_offset((enum changelog_rec_flags)(crf_wanted &
+				       ~(CLF_EXTRA_FLAGS | CLF_JOBID) ),
 				       CLFE_INVALID);
 	rnm_mov = (char *)rec +
-		  changelog_rec_offset(crf_wanted &
+		  changelog_rec_offset((enum changelog_rec_flags)(crf_wanted &
 				       ~(CLF_EXTRA_FLAGS |
 					 CLF_JOBID |
-					 CLF_RENAME),
+					 CLF_RENAME)),
 				       CLFE_INVALID);
 
 	/* Move the extension fields to the desired positions */
@@ -1986,7 +2001,7 @@ static inline ssize_t hur_len(struct hsm_user_request *hur)
 		(__u64)hur->hur_request.hr_itemcount *
 		sizeof(hur->hur_user_item[0]) + hur->hur_request.hr_data_len;
 
-	if (size != (ssize_t)size)
+	if (size != (size_t)size)
 		return -1;
 
 	return size;
-- 
2.17.1

