Whamcloud - gitweb
LU-4984 llite: check for integer overflow in hsm user request
[fs/lustre-release.git] / lustre / include / lustre / lustre_user.h
index 2e97ab5..8b612a3 100644 (file)
 #error Unsupported operating system.
 #endif
 
-#ifdef __cplusplus
-#define LUSTRE_ANONYMOUS_UNION_NAME u
-#else
-#define LUSTRE_ANONYMOUS_UNION_NAME
-#endif
+#define LUSTRE_EOF 0xffffffffffffffffULL
 
 /* for statfs() */
 #define LL_SUPER_MAGIC 0x0BD00BD0
@@ -140,6 +136,11 @@ struct lu_fid {
        __u32 f_ver;
 };
 
+static inline bool fid_is_zero(const struct lu_fid *fid)
+{
+       return fid->f_seq == 0 && fid->f_oid == 0;
+}
+
 /* Currently, the filter_fid::ff_parent::f_ver is not the real parent
  * MDT-object's FID::f_ver, instead it is the OST-object index in its
  * parent MDT-object's layout EA. */
@@ -194,12 +195,12 @@ struct lustre_mdt_attrs {
  */
 struct ost_id {
        union {
-               struct ostid {
+               struct {
                        __u64   oi_id;
                        __u64   oi_seq;
                } oi;
                struct lu_fid oi_fid;
-       } LUSTRE_ANONYMOUS_UNION_NAME;
+       };
 };
 
 #define DOSTID LPX64":"LPU64
@@ -301,9 +302,14 @@ struct ost_id {
 
 #define LMV_USER_MAGIC    0x0CD30CD0    /*default lmv magic*/
 
-#define LOV_PATTERN_RAID0 0x001
-#define LOV_PATTERN_RAID1 0x002
-#define LOV_PATTERN_FIRST 0x100
+#define LOV_PATTERN_RAID0      0x001
+#define LOV_PATTERN_RAID1      0x002
+#define LOV_PATTERN_FIRST      0x100
+#define LOV_PATTERN_CMOBD      0x200
+
+#define LOV_PATTERN_F_MASK     0xffff0000
+#define LOV_PATTERN_F_HOLE     0x40000000 /* there is hole in LOV EA */
+#define LOV_PATTERN_F_RELEASED 0x80000000 /* HSM released file */
 
 #define LOV_MAXPOOLNAME 16
 #define LOV_POOLNAMEF "%.16s"
@@ -398,6 +404,15 @@ struct lmv_user_mds_data {
        __u32           lum_mds;
 };
 
+enum lmv_hash_type {
+       LMV_HASH_TYPE_UNKNOWN   = 0,    /* 0 is reserved for testing purpose */
+       LMV_HASH_TYPE_ALL_CHARS = 1,
+       LMV_HASH_TYPE_FNV_1A_64 = 2,
+};
+
+#define LMV_HASH_NAME_ALL_CHARS        "all_char"
+#define LMV_HASH_NAME_FNV_1A_64        "fnv_1a_64"
+
 /* Got this according to how get LOV_MAX_STRIPE_COUNT, see above,
  * (max buffer size - lmv+rpc header) / sizeof(struct lmv_user_mds_data) */
 #define LMV_MAX_STRIPE_COUNT 2000  /* ((12 * 4096 - 256) / 24) */
@@ -484,8 +499,8 @@ static inline void obd_uuid2fsname(char *buf, char *uuid, int buflen)
         strncpy(buf, uuid, buflen - 1);
         buf[buflen - 1] = '\0';
         p = strrchr(buf, '-');
-        if (p)
-           *p = '\0';
+       if (p != NULL)
+               *p = '\0';
 }
 
 /* printf display format
@@ -514,6 +529,20 @@ liblustreapi.c:2893: warning: format '%lx' expects type 'long unsigned int *', b
 
 /********* Quotas **********/
 
+#define LUSTRE_QUOTABLOCK_BITS 10
+#define LUSTRE_QUOTABLOCK_SIZE (1 << LUSTRE_QUOTABLOCK_BITS)
+
+static inline __u64 lustre_stoqb(size_t space)
+{
+       return (space + LUSTRE_QUOTABLOCK_SIZE - 1) >> LUSTRE_QUOTABLOCK_BITS;
+}
+
+#define Q_QUOTACHECK   0x800100 /* deprecated as of 2.4 */
+#define Q_INITQUOTA    0x800101 /* deprecated as of 2.4  */
+#define Q_GETOINFO     0x800102 /* get obd quota info */
+#define Q_GETOQUOTA    0x800103 /* get obd quotas */
+#define Q_FINVALIDATE  0x800104 /* deprecated as of 2.4 */
+
 /* these must be explicitly translated into linux Q_* in ll_dir_ioctl */
 #define LUSTRE_Q_QUOTAON    0x800002     /* turn quotas on */
 #define LUSTRE_Q_QUOTAOFF   0x800003     /* turn quotas off */
@@ -1020,12 +1049,25 @@ static inline void *hur_data(struct hsm_user_request *hur)
        return &(hur->hur_user_item[hur->hur_request.hr_itemcount]);
 }
 
-/** Compute the current length of the provided hsm_user_request. */
-static inline int hur_len(struct hsm_user_request *hur)
+/**
+ * Compute the current length of the provided hsm_user_request.  This returns -1
+ * instead of an errno because ssize_t is defined to be only [ -1, SSIZE_MAX ]
+ *
+ * return -1 on bounds check error.
+ */
+static inline ssize_t hur_len(struct hsm_user_request *hur)
 {
-       return offsetof(struct hsm_user_request, hur_user_item[0]) +
-               hur->hur_request.hr_itemcount * sizeof(hur->hur_user_item[0]) +
-               hur->hur_request.hr_data_len;
+       __u64   size;
+
+       /* can't overflow a __u64 since hr_itemcount is only __u32 */
+       size = offsetof(struct hsm_user_request, hur_user_item[0]) +
+               (__u64)hur->hur_request.hr_itemcount *
+               sizeof(hur->hur_user_item[0]) + hur->hur_request.hr_data_len;
+
+       if (size != (ssize_t)size)
+               return -1;
+
+       return size;
 }
 
 /****** HSM RPCs to copytool *****/