Whamcloud - gitweb
LU-4984 llite: check for integer overflow in hsm user request
[fs/lustre-release.git] / lustre / include / lustre / lustre_user.h
index 9aea58b..8b612a3 100644 (file)
@@ -49,7 +49,6 @@
 #ifndef __KERNEL__
 #include <stdio.h>
 #include <libcfs/posix/posix-types.h>
-#include <stdio.h>
 #endif
 #include <lustre/ll_fiemap.h>
 #if defined(__linux__)
 #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
@@ -141,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. */
@@ -195,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
@@ -216,26 +216,20 @@ struct ost_id {
  * *STRIPE* - set/get lov_user_md
  * *INFO    - set/get lov_user_mds_data
  */
-/* see <lustre_lib.h> for ioctl numberss 101-150 */
+/*     lustre_ioctl.h                  101-150 */
 #define LL_IOC_GETFLAGS                 _IOR ('f', 151, long)
 #define LL_IOC_SETFLAGS                 _IOW ('f', 152, long)
 #define LL_IOC_CLRFLAGS                 _IOW ('f', 153, long)
-/* LL_IOC_LOV_SETSTRIPE: See also OBD_IOC_LOV_SETSTRIPE */
 #define LL_IOC_LOV_SETSTRIPE            _IOW ('f', 154, long)
-/* LL_IOC_LOV_GETSTRIPE: See also OBD_IOC_LOV_GETSTRIPE */
 #define LL_IOC_LOV_GETSTRIPE            _IOW ('f', 155, long)
-/* LL_IOC_LOV_SETEA: See also OBD_IOC_LOV_SETEA */
 #define LL_IOC_LOV_SETEA                _IOW ('f', 156, long)
 #define LL_IOC_RECREATE_OBJ             _IOW ('f', 157, long)
 #define LL_IOC_RECREATE_FID             _IOW ('f', 157, struct lu_fid)
 #define LL_IOC_GROUP_LOCK               _IOW ('f', 158, long)
 #define LL_IOC_GROUP_UNLOCK             _IOW ('f', 159, long)
-/* LL_IOC_QUOTACHECK: See also OBD_IOC_QUOTACHECK */
-#define LL_IOC_QUOTACHECK               _IOW ('f', 160, int)
-/* LL_IOC_POLL_QUOTACHECK: See also OBD_IOC_POLL_QUOTACHECK */
-#define LL_IOC_POLL_QUOTACHECK          _IOR ('f', 161, struct if_quotacheck *)
-/* LL_IOC_QUOTACTL: See also OBD_IOC_QUOTACTL */
-#define LL_IOC_QUOTACTL                 _IOWR('f', 162, struct if_quotactl)
+/*     LL_IOC_QUOTACHECK               160 OBD_IOC_QUOTACHECK */
+/*     LL_IOC_POLL_QUOTACHECK          161 OBD_IOC_POLL_QUOTACHECK */
+/*     LL_IOC_QUOTACTL                 162 OBD_IOC_QUOTACTL */
 #define IOC_OBD_STATFS                  _IOWR('f', 164, struct obd_statfs *)
 #define IOC_LOV_GETINFO                 _IOWR('f', 165, struct lov_user_mds_data *)
 #define LL_IOC_FLUSHCTX                 _IOW ('f', 166, long)
@@ -248,9 +242,7 @@ struct ost_id {
 #define LL_IOC_PATH2FID                 _IOR ('f', 173, long)
 #define LL_IOC_GET_CONNECT_FLAGS        _IOWR('f', 174, __u64 *)
 #define LL_IOC_GET_MDTIDX               _IOR ('f', 175, int)
-
-/* see <lustre_lib.h> for ioctl numbers 177-210 */
-
+/*     lustre_ioctl.h                  177-210 */
 #define LL_IOC_HSM_STATE_GET           _IOR('f', 211, struct hsm_user_state)
 #define LL_IOC_HSM_STATE_SET           _IOW('f', 212, struct hsm_state_set)
 #define LL_IOC_HSM_CT_START            _IOW('f', 213, struct lustre_kernelcomm)
@@ -263,8 +255,7 @@ struct ost_id {
                                                struct lustre_swap_layouts)
 #define LL_IOC_HSM_ACTION              _IOR('f', 220, \
                                                struct hsm_current_action)
-/* see <lustre_lib.h> for ioctl numbers 221-232 */
-
+/*     lustre_ioctl.h                  221-232 */
 #define LL_IOC_LMV_SETSTRIPE           _IOWR('f', 240, struct lmv_user_md)
 #define LL_IOC_LMV_GETSTRIPE           _IOWR('f', 241, struct lmv_user_md)
 #define LL_IOC_REMOVE_ENTRY            _IOWR('f', 242, __u64)
@@ -284,11 +275,6 @@ struct ost_id {
 #define IOC_MDC_GETFILEINFO     _IOWR(IOC_MDC_TYPE, 22, struct lov_user_mds_data *)
 #define LL_IOC_MDC_GETINFO      _IOWR(IOC_MDC_TYPE, 23, struct lov_user_mds_data *)
 
-/* Keep these for backward compartability. */
-#define LL_IOC_OBD_STATFS       IOC_OBD_STATFS
-#define IOC_MDC_GETSTRIPE       IOC_MDC_GETFILESTRIPE
-
-
 #define MAX_OBD_NAME 128 /* If this changes, a NEW ioctl must be added */
 
 /* Define O_LOV_DELAY_CREATE to be a mask that is not useful for regular
@@ -314,12 +300,16 @@ struct ost_id {
 #define LOV_USER_MAGIC_JOIN_V1 0x0BD20BD0
 #define LOV_USER_MAGIC_V3 0x0BD30BD0
 
-#define LMV_MAGIC_V1      0x0CD10CD0    /*normal stripe lmv magic */
-#define LMV_USER_MAGIC    0x0CD20CD0    /*default lmv magic*/
+#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_CMOBD      0x200
 
-#define LOV_PATTERN_RAID0 0x001
-#define LOV_PATTERN_RAID1 0x002
-#define LOV_PATTERN_FIRST 0x100
+#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"
@@ -414,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) */
@@ -500,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
@@ -530,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 */
@@ -1036,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 *****/