Whamcloud - gitweb
LU-12624 lod: alloc dir stripes by QoS
[fs/lustre-release.git] / lustre / include / uapi / linux / lustre / lustre_user.h
index 710aca8..5c5cd41 100644 (file)
@@ -113,6 +113,138 @@ typedef struct stat     lstat_t;
 #define fstatat_f       fstatat
 #endif
 
+#ifndef STATX_BASIC_STATS
+/*
+ * Timestamp structure for the timestamps in struct statx.
+ *
+ * tv_sec holds the number of seconds before (negative) or after (positive)
+ * 00:00:00 1st January 1970 UTC.
+ *
+ * tv_nsec holds a number of nanoseconds (0..999,999,999) after the tv_sec time.
+ *
+ * __reserved is held in case we need a yet finer resolution.
+ */
+struct statx_timestamp {
+       __s64   tv_sec;
+       __u32   tv_nsec;
+       __s32   __reserved;
+};
+
+/*
+ * Structures for the extended file attribute retrieval system call
+ * (statx()).
+ *
+ * The caller passes a mask of what they're specifically interested in as a
+ * parameter to statx().  What statx() actually got will be indicated in
+ * st_mask upon return.
+ *
+ * For each bit in the mask argument:
+ *
+ * - if the datum is not supported:
+ *
+ *   - the bit will be cleared, and
+ *
+ *   - the datum will be set to an appropriate fabricated value if one is
+ *     available (eg. CIFS can take a default uid and gid), otherwise
+ *
+ *   - the field will be cleared;
+ *
+ * - otherwise, if explicitly requested:
+ *
+ *   - the datum will be synchronised to the server if AT_STATX_FORCE_SYNC is
+ *     set or if the datum is considered out of date, and
+ *
+ *   - the field will be filled in and the bit will be set;
+ *
+ * - otherwise, if not requested, but available in approximate form without any
+ *   effort, it will be filled in anyway, and the bit will be set upon return
+ *   (it might not be up to date, however, and no attempt will be made to
+ *   synchronise the internal state first);
+ *
+ * - otherwise the field and the bit will be cleared before returning.
+ *
+ * Items in STATX_BASIC_STATS may be marked unavailable on return, but they
+ * will have values installed for compatibility purposes so that stat() and
+ * co. can be emulated in userspace.
+ */
+struct statx {
+       /* 0x00 */
+       __u32   stx_mask;       /* What results were written [uncond] */
+       __u32   stx_blksize;    /* Preferred general I/O size [uncond] */
+       __u64   stx_attributes; /* Flags conveying information about the file [uncond] */
+       /* 0x10 */
+       __u32   stx_nlink;      /* Number of hard links */
+       __u32   stx_uid;        /* User ID of owner */
+       __u32   stx_gid;        /* Group ID of owner */
+       __u16   stx_mode;       /* File mode */
+       __u16   __spare0[1];
+       /* 0x20 */
+       __u64   stx_ino;        /* Inode number */
+       __u64   stx_size;       /* File size */
+       __u64   stx_blocks;     /* Number of 512-byte blocks allocated */
+       __u64   stx_attributes_mask; /* Mask to show what's supported in stx_attributes */
+       /* 0x40 */
+       struct statx_timestamp  stx_atime;      /* Last access time */
+       struct statx_timestamp  stx_btime;      /* File creation time */
+       struct statx_timestamp  stx_ctime;      /* Last attribute change time */
+       struct statx_timestamp  stx_mtime;      /* Last data modification time */
+       /* 0x80 */
+       __u32   stx_rdev_major; /* Device ID of special file [if bdev/cdev] */
+       __u32   stx_rdev_minor;
+       __u32   stx_dev_major;  /* ID of device containing file [uncond] */
+       __u32   stx_dev_minor;
+       /* 0x90 */
+       __u64   __spare2[14];   /* Spare space for future expansion */
+       /* 0x100 */
+};
+
+/*
+ * Flags to be stx_mask
+ *
+ * Query request/result mask for statx() and struct statx::stx_mask.
+ *
+ * These bits should be set in the mask argument of statx() to request
+ * particular items when calling statx().
+ */
+#define STATX_TYPE             0x00000001U     /* Want/got stx_mode & S_IFMT */
+#define STATX_MODE             0x00000002U     /* Want/got stx_mode & ~S_IFMT */
+#define STATX_NLINK            0x00000004U     /* Want/got stx_nlink */
+#define STATX_UID              0x00000008U     /* Want/got stx_uid */
+#define STATX_GID              0x00000010U     /* Want/got stx_gid */
+#define STATX_ATIME            0x00000020U     /* Want/got stx_atime */
+#define STATX_MTIME            0x00000040U     /* Want/got stx_mtime */
+#define STATX_CTIME            0x00000080U     /* Want/got stx_ctime */
+#define STATX_INO              0x00000100U     /* Want/got stx_ino */
+#define STATX_SIZE             0x00000200U     /* Want/got stx_size */
+#define STATX_BLOCKS           0x00000400U     /* Want/got stx_blocks */
+#define STATX_BASIC_STATS      0x000007ffU     /* The stuff in the normal stat struct */
+#define STATX_BTIME            0x00000800U     /* Want/got stx_btime */
+#define STATX_ALL              0x00000fffU     /* All currently supported flags */
+#define STATX__RESERVED                0x80000000U     /* Reserved for future struct statx expansion */
+
+/*
+ * Attributes to be found in stx_attributes and masked in stx_attributes_mask.
+ *
+ * These give information about the features or the state of a file that might
+ * be of use to ordinary userspace programs such as GUIs or ls rather than
+ * specialised tools.
+ *
+ * Note that the flags marked [I] correspond to generic FS_IOC_FLAGS
+ * semantically.  Where possible, the numerical value is picked to correspond
+ * also.
+ */
+#define STATX_ATTR_COMPRESSED          0x00000004 /* [I] File is compressed by the fs */
+#define STATX_ATTR_IMMUTABLE           0x00000010 /* [I] File is marked immutable */
+#define STATX_ATTR_APPEND              0x00000020 /* [I] File is append-only */
+#define STATX_ATTR_NODUMP              0x00000040 /* [I] File is not to be dumped */
+#define STATX_ATTR_ENCRYPTED           0x00000800 /* [I] File requires key to decrypt in fs */
+
+#define STATX_ATTR_AUTOMOUNT           0x00001000 /* Dir: Automount trigger */
+
+#endif
+
+typedef struct statx lstatx_t;
+
 #define HAVE_LOV_USER_MDS_DATA
 
 #define LUSTRE_EOF 0xffffffffffffffffULL
@@ -126,9 +258,11 @@ typedef struct stat     lstat_t;
 #define LUSTRE_FIEMAP_FLAGS_COMPAT (FIEMAP_FLAG_SYNC | FIEMAP_FLAG_DEVICE_ORDER)
 
 enum obd_statfs_state {
-       OS_STATE_DEGRADED       = 0x00000001, /**< RAID degraded/rebuilding */
-       OS_STATE_READONLY       = 0x00000002, /**< filesystem is read-only */
-       OS_STATE_NOPRECREATE    = 0x00000004, /**< no object precreation */
+       OS_STATE_DEGRADED       = 0x00000001, /**< RAID degraded/rebuilding */
+       OS_STATE_READONLY       = 0x00000002, /**< filesystem is read-only */
+       OS_STATE_NOPRECREATE    = 0x00000004, /**< no object precreation */
+       OS_STATE_UNUSED1        = 0x00000008, /**< obsolete 1.6, was EROFS=30 */
+       OS_STATE_UNUSED2        = 0x00000010, /**< obsolete 1.6, was EROFS=30 */
        OS_STATE_ENOSPC         = 0x00000020, /**< not enough free space */
        OS_STATE_ENOINO         = 0x00000040, /**< not enough inodes */
        OS_STATE_SUM            = 0x00000100, /**< aggregated for all tagrets */
@@ -161,6 +295,13 @@ struct obd_statfs {
        __u32           os_spare9;
 };
 
+/** additional filesystem attributes for target device */
+struct obd_statfs_info {
+       __u32           os_reserved_mb_low;     /* reserved mb low */
+       __u32           os_reserved_mb_high;    /* reserved mb high */
+       bool            os_enable_pre;          /* enable pre create logic */
+};
+
 /**
  * File IDentifier.
  *
@@ -471,6 +612,7 @@ struct ll_ioc_lease_id {
 #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)
+#define LL_IOC_RMFID                   _IOR('f', 242, struct fid_array)
 #define LL_IOC_SET_LEASE               _IOWR('f', 243, struct ll_ioc_lease)
 #define LL_IOC_SET_LEASE_OLD           _IOWR('f', 243, long)
 #define LL_IOC_GET_LEASE               _IO('f', 244)
@@ -482,8 +624,8 @@ struct ll_ioc_lease_id {
 #define LL_IOC_LADVISE                 _IOR('f', 250, struct llapi_lu_ladvise)
 #define LL_IOC_HEAT_GET                        _IOWR('f', 251, struct lu_heat)
 #define LL_IOC_HEAT_SET                        _IOW('f', 251, __u64)
-#define LL_IOC_PCC_DETACH              _IO('f', 252)
-#define LL_IOC_PCC_DETACH_BY_FID       _IOW('f', 252, struct lu_pcc_detach)
+#define LL_IOC_PCC_DETACH              _IOW('f', 252, struct lu_pcc_detach)
+#define LL_IOC_PCC_DETACH_BY_FID       _IOW('f', 252, struct lu_pcc_detach_fid)
 #define LL_IOC_PCC_STATE               _IOR('f', 252, struct lu_pcc_state)
 
 #ifndef        FS_IOC_FSGETXATTR
@@ -511,11 +653,15 @@ struct fsxattr {
 #define LL_STATFS_LOV          2
 #define LL_STATFS_NODELAY      4
 
-#define IOC_MDC_TYPE            'i'
-#define IOC_MDC_LOOKUP          _IOWR(IOC_MDC_TYPE, 20, struct obd_device *)
-#define IOC_MDC_GETFILESTRIPE   _IOWR(IOC_MDC_TYPE, 21, struct lov_user_md *)
-#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 *)
+#define IOC_MDC_TYPE           'i'
+#define IOC_MDC_LOOKUP         _IOWR(IOC_MDC_TYPE, 20, struct obd_device *)
+#define IOC_MDC_GETFILESTRIPE  _IOWR(IOC_MDC_TYPE, 21, struct lov_user_md *)
+#ifdef HAVE_LOV_USER_MDS_DATA
+#define IOC_MDC_GETFILEINFO_OLD        _IOWR(IOC_MDC_TYPE, 22, struct lov_user_mds_data_v1 *)
+#define IOC_MDC_GETFILEINFO    _IOWR(IOC_MDC_TYPE, 22, struct lov_user_mds_data)
+#define LL_IOC_MDC_GETINFO_OLD _IOWR(IOC_MDC_TYPE, 23, struct lov_user_mds_data_v1 *)
+#define LL_IOC_MDC_GETINFO     _IOWR(IOC_MDC_TYPE, 23, struct lov_user_mds_data)
+#endif
 
 #define MAX_OBD_NAME 128 /* If this changes, a NEW ioctl must be added */
 
@@ -538,6 +684,7 @@ struct fsxattr {
 #define LL_FILE_READAHEA        0x00000004
 #define LL_FILE_LOCKED_DIRECTIO 0x00000008 /* client-side locks with dio */
 #define LL_FILE_LOCKLESS_IO     0x00000010 /* server-side locks with cio */
+#define LL_FILE_FLOCK_WARNING   0x00000020 /* warned about disabled flock */
 
 #define LOV_USER_MAGIC_V1      0x0BD10BD0
 #define LOV_USER_MAGIC         LOV_USER_MAGIC_V1
@@ -547,6 +694,7 @@ struct fsxattr {
 #define LOV_USER_MAGIC_SPECIFIC 0x0BD50BD0     /* for specific OSTs */
 #define LOV_USER_MAGIC_COMP_V1 0x0BD60BD0
 #define LOV_USER_MAGIC_FOREIGN 0x0BD70BD0
+#define LOV_USER_MAGIC_SEL     0x0BD80BD0
 
 #define LMV_USER_MAGIC         0x0CD30CD0    /* default lmv magic */
 #define LMV_USER_MAGIC_V0      0x0CD20CD0    /* old default lmv magic*/
@@ -564,6 +712,7 @@ struct fsxattr {
 #define LOV_PATTERN_DEFAULT    0xffffffff
 
 #define LOV_OFFSET_DEFAULT      ((__u16)-1)
+#define LMV_OFFSET_DEFAULT      ((__u32)-1)
 
 static inline bool lov_pattern_supported(__u32 pattern)
 {
@@ -660,13 +809,19 @@ struct lov_foreign_md {
        (le32_to_cpu(((struct lov_foreign_md *)lfm)->lfm_length) + \
        offsetof(struct lov_foreign_md, lfm_value))
 
+/**
+ * The stripe size fields are shared for the extension size storage, however
+ * the extension size is stored in KB, not bytes.
+ */
+#define SEL_UNIT_SIZE 1024llu
+
 struct lu_extent {
        __u64   e_start;
        __u64   e_end;
 };
 
 #define DEXT "[%#llx, %#llx)"
-#define PEXT(ext) (ext)->e_start, (ext)->e_end
+#define PEXT(ext) (unsigned long long)(ext)->e_start, (unsigned long long)(ext)->e_end
 
 static inline bool lu_extent_is_overlapped(struct lu_extent *e1,
                                           struct lu_extent *e2)
@@ -680,29 +835,41 @@ static inline bool lu_extent_is_whole(struct lu_extent *e)
 }
 
 enum lov_comp_md_entry_flags {
-       LCME_FL_STALE   = 0x00000001,   /* FLR: stale data */
-       LCME_FL_PREF_RD = 0x00000002,   /* FLR: preferred for reading */
-       LCME_FL_PREF_WR = 0x00000004,   /* FLR: preferred for writing */
-       LCME_FL_PREF_RW = LCME_FL_PREF_RD | LCME_FL_PREF_WR,
-       LCME_FL_OFFLINE = 0x00000008,   /* Not used */
-       LCME_FL_INIT    = 0x00000010,   /* instantiated */
-       LCME_FL_NOSYNC  = 0x00000020,   /* FLR: no sync for the mirror */
-       LCME_FL_NEG     = 0x80000000    /* used to indicate a negative flag,
-                                          won't be stored on disk */
+       LCME_FL_STALE     = 0x00000001, /* FLR: stale data */
+       LCME_FL_PREF_RD   = 0x00000002, /* FLR: preferred for reading */
+       LCME_FL_PREF_WR   = 0x00000004, /* FLR: preferred for writing */
+       LCME_FL_PREF_RW   = LCME_FL_PREF_RD | LCME_FL_PREF_WR,
+       LCME_FL_OFFLINE   = 0x00000008, /* Not used */
+       LCME_FL_INIT      = 0x00000010, /* instantiated */
+       LCME_FL_NOSYNC    = 0x00000020, /* FLR: no sync for the mirror */
+       LCME_FL_EXTENSION = 0x00000040, /* extension comp, never init */
+       LCME_FL_NEG       = 0x80000000  /* used to indicate a negative flag,
+                                        * won't be stored on disk
+                                        */
 };
 
 #define LCME_KNOWN_FLAGS       (LCME_FL_NEG | LCME_FL_INIT | LCME_FL_STALE | \
-                                LCME_FL_PREF_RW | LCME_FL_NOSYNC)
-/* The flags can be set by users at mirror creation time. */
-#define LCME_USER_FLAGS                (LCME_FL_PREF_RW)
+                                LCME_FL_PREF_RW | LCME_FL_NOSYNC | \
+                                LCME_FL_EXTENSION)
+
+/* The component flags can be set by users at creation/modification time. */
+#define LCME_USER_COMP_FLAGS   (LCME_FL_PREF_RW | LCME_FL_NOSYNC | \
+                                LCME_FL_EXTENSION)
 
-/* The flags are for mirrors */
+/* The mirror flags can be set by users at creation time. */
+#define LCME_USER_MIRROR_FLAGS (LCME_FL_PREF_RW)
+
+/* The allowed flags obtained from the client at component creation time. */
+#define LCME_CL_COMP_FLAGS     (LCME_USER_MIRROR_FLAGS | LCME_FL_EXTENSION)
+
+/* The mirror flags sent by client */
 #define LCME_MIRROR_FLAGS      (LCME_FL_NOSYNC)
 
 /* These flags have meaning when set in a default layout and will be inherited
  * from the default/template layout set on a directory.
  */
-#define LCME_TEMPLATE_FLAGS    (LCME_FL_PREF_RW | LCME_FL_NOSYNC)
+#define LCME_TEMPLATE_FLAGS    (LCME_FL_PREF_RW | LCME_FL_NOSYNC | \
+                                LCME_FL_EXTENSION)
 
 /* the highest bit in obdo::o_layout_version is used to mark if the file is
  * being resynced. */
@@ -792,11 +959,20 @@ static inline __u32 lov_user_md_size(__u16 stripes, __u32 lmm_magic)
  * use this.  It is unsafe to #define those values in this header as it
  * is possible the application has already #included <sys/stat.h>. */
 #ifdef HAVE_LOV_USER_MDS_DATA
-#define lov_user_mds_data lov_user_mds_data_v1
+#define lov_user_mds_data lov_user_mds_data_v2
 struct lov_user_mds_data_v1 {
        lstat_t lmd_st;                 /* MDS stat struct */
        struct lov_user_md_v1 lmd_lmm;  /* LOV EA V1 user data */
 } __attribute__((packed));
+
+struct lov_user_mds_data_v2 {
+       struct lu_fid lmd_fid;          /* Lustre FID */
+       lstatx_t lmd_stx;               /* MDS statx struct */
+       __u64 lmd_flags;                /* MDS stat flags */
+       __u32 lmd_lmmsize;              /* LOV EA size */
+       __u32 lmd_padding;              /* unused */
+       struct lov_user_md_v1 lmd_lmm;  /* LOV EA user data */
+} __attribute__((packed));
 #endif
 
 struct lmv_user_mds_data {
@@ -809,17 +985,37 @@ 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,
-       LMV_HASH_TYPE_SPACE     = 3,    /*
-                                        * distribute subdirs among all MDTs
-                                        * with balanced space usage.
-                                        */
        LMV_HASH_TYPE_MAX,
 };
 
+#define LMV_HASH_TYPE_DEFAULT LMV_HASH_TYPE_FNV_1A_64
+
 #define LMV_HASH_NAME_ALL_CHARS        "all_char"
 #define LMV_HASH_NAME_FNV_1A_64        "fnv_1a_64"
+
+/* not real hash type, but exposed to user as "space" hash type */
 #define LMV_HASH_NAME_SPACE    "space"
 
+/* Right now only the lower part(0-16bits) of lmv_hash_type is being used,
+ * and the higher part will be the flag to indicate the status of object,
+ * for example the object is being migrated. And the hash function
+ * might be interpreted differently with different flags. */
+#define LMV_HASH_TYPE_MASK 0x0000ffff
+
+static inline bool lmv_is_known_hash_type(__u32 type)
+{
+       return (type & LMV_HASH_TYPE_MASK) == LMV_HASH_TYPE_FNV_1A_64 ||
+              (type & LMV_HASH_TYPE_MASK) == LMV_HASH_TYPE_ALL_CHARS;
+}
+
+/* The striped directory has ever lost its master LMV EA, then LFSCK
+ * re-generated it. This flag is used to indicate such case. It is an
+ * on-disk flag. */
+#define LMV_HASH_FLAG_LOST_LMV 0x10000000
+
+#define LMV_HASH_FLAG_BAD_TYPE 0x20000000
+#define LMV_HASH_FLAG_MIGRATION        0x80000000
+
 extern char *mdt_hash_name[LMV_HASH_TYPE_MAX];
 
 struct lustre_foreign_type {
@@ -957,14 +1153,14 @@ 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
  * Need to strip '[' from DFID format first or use "["SFID"]" at caller.
  * usage: sscanf(fidstr, SFID, RFID(&fid)); */
 #define SFID "0x%llx:0x%x:0x%x"
-#define RFID(fid) &((fid)->f_seq), &((fid)->f_oid), &((fid)->f_ver)
+#define RFID(fid) (unsigned long long *)&((fid)->f_seq), &((fid)->f_oid), &((fid)->f_ver)
 
 /********* Quotas **********/
 
@@ -1016,7 +1212,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:
@@ -1348,7 +1544,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)
@@ -1359,7 +1556,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)
@@ -1370,7 +1568,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 {
@@ -1509,9 +1708,11 @@ 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)
@@ -1522,7 +1723,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,
@@ -1533,8 +1735,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,
@@ -1546,8 +1748,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,
@@ -1559,8 +1761,9 @@ 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,
@@ -1571,13 +1774,15 @@ 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));
@@ -1588,13 +1793,16 @@ 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);
+       if (rec->cr_flags & CLF_EXTRA_FLAGS) {
+               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));
@@ -1605,13 +1813,15 @@ 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));
@@ -1623,10 +1833,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)
@@ -1675,8 +1887,10 @@ 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) ||
@@ -1694,38 +1908,50 @@ 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,
-                                      CLFE_INVALID);
+                 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 */
@@ -1985,7 +2211,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 ((ssize_t)size < 0)
                return -1;
 
        return size;
@@ -2324,9 +2550,19 @@ struct lu_pcc_attach {
        __u32 pcca_id; /* archive ID for readwrite, group ID for readonly */
 };
 
-struct lu_pcc_detach {
+enum lu_pcc_detach_opts {
+       PCC_DETACH_OPT_NONE = 0, /* Detach only, keep the PCC copy */
+       PCC_DETACH_OPT_UNCACHE, /* Remove the cached file after detach */
+};
+
+struct lu_pcc_detach_fid {
        /* fid of the file to detach */
        struct lu_fid   pccd_fid;
+       __u32           pccd_opt;
+};
+
+struct lu_pcc_detach {
+       __u32           pccd_opt;
 };
 
 enum lu_pcc_state_flags {
@@ -2337,6 +2573,14 @@ enum lu_pcc_state_flags {
        PCC_STATE_FL_ATTACHING          = 0x02,
        /* Allow to auto attach at open */
        PCC_STATE_FL_OPEN_ATTACH        = 0x04,
+       /* Allow to auto attach during I/O after layout lock revocation */
+       PCC_STATE_FL_IO_ATTACH          = 0x08,
+       /* Allow to auto attach at stat */
+       PCC_STATE_FL_STAT_ATTACH        = 0x10,
+       /* Allow to auto attach at the next open or layout refresh */
+       PCC_STATE_FL_AUTO_ATTACH        = PCC_STATE_FL_OPEN_ATTACH |
+                                         PCC_STATE_FL_IO_ATTACH |
+                                         PCC_STATE_FL_STAT_ATTACH,
 };
 
 struct lu_pcc_state {
@@ -2347,6 +2591,15 @@ struct lu_pcc_state {
        char    pccs_path[PATH_MAX];
 };
 
+struct fid_array {
+       __u32 fa_nr;
+       /* make header's size equal lu_fid */
+       __u32 fa_padding0;
+       __u64 fa_padding1;
+       struct lu_fid fa_fids[0];
+};
+#define OBD_MAX_FIDS_IN_ARRAY  4096
+
 #if defined(__cplusplus)
 }
 #endif