Whamcloud - gitweb
LU-13124 scrub: check for multiple linked file
[fs/lustre-release.git] / lustre / osd-ldiskfs / osd_internal.h
index 2e94edb..11f8a6e 100644 (file)
@@ -27,7 +27,6 @@
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
- * Lustre is a trademark of Sun Microsystems, Inc.
  *
  * lustre/osd/osd_internal.h
  *
 /* struct dirent64 */
 #include <linux/dirent.h>
 #include <linux/statfs.h>
+#include <linux/bio.h>
 #include <ldiskfs/ldiskfs.h>
 #include <ldiskfs/ldiskfs_jbd2.h>
 
 /* LUSTRE_OSD_NAME */
 #include <obd.h>
-/* class_register_type(), class_unregister_type(), class_get_type() */
+/* class_register_type(), class_unregister_type() */
 #include <obd_class.h>
 #include <lustre_disk.h>
 #include <dt_object.h>
@@ -90,6 +90,9 @@ extern struct kmem_cache *dynlock_cachep;
 #define OSD_STATFS_RESERVED            (1ULL << 23) /* 8MB */
 #define OSD_STATFS_RESERVED_SHIFT      (7) /* reserve 0.78% of all space */
 
+/* Default extent bytes when declaring write commit */
+#define OSD_DEFAULT_EXTENT_BYTES       (1U << 20)
+
 /* check if ldiskfs support project quota */
 #ifndef LDISKFS_IOC_FSSETXATTR
 #undef HAVE_PROJECT_QUOTA
@@ -135,26 +138,24 @@ struct osd_object {
        /** protects inode attributes. */
        spinlock_t              oo_guard;
 
+       /**
+        * Following two members *compat_dot* are used to indicate
+        * the presence of dot and dotdot in the given directory.
+        * This is required for interop mode (b11826).
+        */
        __u32                   oo_destroyed:1,
-                               oo_pfid_in_lma:1;
+                               oo_pfid_in_lma:1,
+                               oo_compat_dot_created:1,
+                               oo_compat_dotdot_created:1;
 
        /* the i_flags in LMA */
-       __u32                   oo_lma_flags;
-        /**
-         * Following two members are used to indicate the presence of dot and
-         * dotdot in the given directory. This is required for interop mode
-         * (b11826).
-         */
-        int                     oo_compat_dot_created;
-        int                     oo_compat_dotdot_created;
+       __u32                   oo_lma_flags;
 
         const struct lu_env    *oo_owner;
-#ifdef CONFIG_LOCKDEP
-        struct lockdep_map      oo_dep_map;
-#endif
 
        struct list_head        oo_xattr_list;
        struct lu_object_header *oo_header;
+       __u64                   oo_dirent_count;
 };
 
 struct osd_obj_seq {
@@ -240,6 +241,14 @@ struct osd_obj_orphan {
        __u32 oor_ino;
 };
 
+enum osd_t10_type {
+       OSD_T10_TYPE_UNKNOWN = 0,
+       OSD_T10_TYPE1_CRC,
+       OSD_T10_TYPE3_CRC,
+       OSD_T10_TYPE1_IP,
+       OSD_T10_TYPE3_IP
+};
+
 /*
  * osd device.
  */
@@ -261,7 +270,12 @@ struct osd_device {
                                  od_check_ff:1,
                                  od_is_ost:1,
                                  od_in_init:1,
-                                 od_index_in_idif:1;
+                                 od_index_in_idif:1,
+       /* Other flags */
+                                 od_read_cache:1,
+                                 od_writethrough_cache:1,
+                                 od_nonrotational:1;
+
 
        __s64                     od_auto_scrub_interval;
        __u32                     od_dirent_journal;
@@ -271,15 +285,24 @@ struct osd_device {
 
        spinlock_t                od_osfs_lock;
 
+       int                       od_fallocate_zero_blocks;
        int                       od_connects;
        struct lu_site            od_site;
 
        struct osd_obj_map      *od_ost_map;
        struct osd_mdobj_map    *od_mdt_map;
 
+       /* objects with size > od_readcache_max_filesize will be
+        * served bypassing pagecache unless already cached */
        unsigned long long      od_readcache_max_filesize;
-       int                     od_read_cache;
-       int                     od_writethrough_cache;
+
+       /* reads > od_readcache_max_iosize will be
+        * served bypassing pagecache unless already cached */
+       unsigned long           od_readcache_max_iosize;
+
+       /* writes > od_writethough_max_iosize will be
+        * served bypassing pagecache unless already cached */
+       unsigned long           od_writethrough_max_iosize;
 
        struct brw_stats        od_brw_stats;
        atomic_t                od_r_in_flight;
@@ -293,9 +316,13 @@ struct osd_device {
        /* service name associated with the osd device */
        char                      od_svname[MAX_OBD_NAME];
        char                      od_mntdev[MAX_OBD_NAME];
+       uuid_t                  od_uuid;
+
+       /* quota slave instance for inode */
+       struct qsd_instance      *od_quota_slave_md;
 
-       /* quota slave instance */
-       struct qsd_instance      *od_quota_slave;
+       /* quota slave instance for block */
+       struct qsd_instance      *od_quota_slave_dt;
 
        /* osd seq instance */
        struct lu_client_seq    *od_cl_seq;
@@ -317,8 +344,21 @@ struct osd_device {
        struct inode            *od_index_backup_inode;
        enum lustre_index_backup_policy od_index_backup_policy;
        int                      od_index_backup_stop;
+       /* T10PI type, zero if not supported  */
+       enum osd_t10_type        od_t10_type;
+       atomic_t                 od_commit_cb_in_flight;
+       wait_queue_head_t        od_commit_cb_done;
+       unsigned int __percpu   *od_extent_bytes_percpu;
 };
 
+static inline struct qsd_instance *osd_def_qsd(struct osd_device *osd)
+{
+       if (osd->od_is_ost)
+               return osd->od_quota_slave_dt;
+       else
+               return osd->od_quota_slave_md;
+}
+
 enum osd_full_scrub_ratio {
        /* Trigger OI scrub to scan the whole device directly. */
        OFSR_DIRECTLY   = 0,
@@ -347,17 +387,29 @@ enum osd_full_scrub_ratio {
 
 enum osd_op_type {
        OSD_OT_ATTR_SET         = 0,
-       OSD_OT_PUNCH            = 1,
-       OSD_OT_XATTR_SET        = 2,
-       OSD_OT_CREATE           = 3,
-       OSD_OT_DESTROY          = 4,
-       OSD_OT_REF_ADD          = 5,
-       OSD_OT_REF_DEL          = 6,
-       OSD_OT_WRITE            = 7,
-       OSD_OT_INSERT           = 8,
-       OSD_OT_DELETE           = 9,
-       OSD_OT_QUOTA            = 10,
-       OSD_OT_MAX              = 11
+       OSD_OT_PUNCH,
+       OSD_OT_XATTR_SET,
+       OSD_OT_CREATE,
+       OSD_OT_DESTROY,
+       OSD_OT_REF_ADD,
+       OSD_OT_REF_DEL,
+       OSD_OT_WRITE,
+       OSD_OT_INSERT,
+       OSD_OT_DELETE,
+       OSD_OT_QUOTA,
+       OSD_OT_PREALLOC,
+       OSD_OT_MAX
+};
+
+struct osd_access_lock {
+       struct list_head         tl_list;
+       struct osd_object       *tl_obj;
+       loff_t                   tl_start;
+       loff_t                   tl_end;
+       int                      tl_mode;
+       bool                     tl_shared;
+       bool                     tl_truncate;
+       bool                     tl_punch;
 };
 
 struct osd_thandle {
@@ -369,11 +421,16 @@ struct osd_thandle {
        /* Link to the device, for debugging. */
        struct lu_ref_link      ot_dev_link;
        unsigned int            ot_credits;
+       unsigned int            oh_declared_ext;
+
+       /* quota IDs related to the transaction */
        unsigned short          ot_id_cnt;
-       __u8                    ot_id_types[OSD_MAX_UGID_CNT];
-       unsigned int            ot_remove_agents:1;
+       __u8                    ot_id_res[OSD_MAX_UGID_CNT];
+       __u8                    ot_id_types[OSD_MAX_UGID_CNT];
        uid_t                   ot_id_array[OSD_MAX_UGID_CNT];
        struct lquota_trans    *ot_quota_trans;
+
+       unsigned int            ot_remove_agents:1;
 #if OSD_THANDLE_STATS
         /** time when this handle was allocated */
        ktime_t oth_alloced;
@@ -381,6 +438,7 @@ struct osd_thandle {
         /** time when this thanle was started */
        ktime_t oth_started;
 #endif
+       struct list_head        ot_trunc_locks;
 };
 
 /**
@@ -511,12 +569,13 @@ struct osd_iobuf {
        int                dr_npages;
        int                dr_error;
        int                dr_frags;
-       unsigned int       dr_ignore_quota:1;
        unsigned int       dr_elapsed_valid:1; /* we really did count time */
        unsigned int       dr_rw:1;
        struct lu_buf      dr_pg_buf;
        struct page      **dr_pages;
+       struct niobuf_local     **dr_lnbs;
        struct lu_buf      dr_bl_buf;
+       struct lu_buf      dr_lnb_buf;
        sector_t          *dr_blocks;
        ktime_t            dr_start_time;
        ktime_t            dr_elapsed;  /* how long io took */
@@ -524,6 +583,24 @@ struct osd_iobuf {
        unsigned int       dr_init_at;  /* the line iobuf was initialized */
 };
 
+int osd_security_file_alloc(struct file *file);
+
+#define osd_dirty_inode(inode, flag)  (inode)->i_sb->s_op->dirty_inode((inode), flag)
+
+#ifdef HAVE_INODE_TIMESPEC64
+# define osd_timespec                  timespec64
+#else
+# define osd_timespec                  timespec
+#endif
+
+static inline struct osd_timespec osd_inode_time(struct inode *inode,
+                                                s64 seconds)
+{
+       struct osd_timespec ts = { .tv_sec = seconds };
+
+       return ts;
+}
+
 #define OSD_INS_CACHE_SIZE     8
 
 struct osd_thread_info {
@@ -554,11 +631,6 @@ struct osd_thread_info {
        struct osd_inode_id    oti_id3;
         struct ost_id          oti_ostid;
 
-        /*
-         * XXX temporary: for ->i_op calls.
-         */
-        struct timespec        oti_time;
-
         /**
          * following ipd and it structures are used for osd_index_iam_lookup()
          * these are defined separately as we might do index operation
@@ -587,38 +659,38 @@ struct osd_thread_info {
        struct osd_idmap_cache oti_cache;
 
        /* dedicated OI cache for insert (which needs inum) */
-       struct osd_idmap_cache *oti_ins_cache;
-       int                    oti_ins_cache_size;
-       int                    oti_ins_cache_used;
-
-        int                    oti_r_locks;
-        int                    oti_w_locks;
-        int                    oti_txns;
-        /** used in osd_fid_set() to put xattr */
-        struct lu_buf          oti_buf;
-       struct lu_buf          oti_big_buf;
-        /** used in osd_ea_fid_set() to set fid into common ea */
+       struct osd_idmap_cache          *oti_ins_cache;
+       int                             oti_ins_cache_size;
+       int                             oti_ins_cache_used;
+       /* inc by osd_trans_create and dec by osd_trans_stop */
+       int                             oti_ins_cache_depth;
+
+       int                             oti_r_locks;
+       int                             oti_w_locks;
+       int                             oti_txns;
+       /** used in osd_fid_set() to put xattr */
+       struct lu_buf                   oti_buf;
+       struct lu_buf                   oti_big_buf;
+       /** used in osd_ea_fid_set() to set fid into common ea */
        union {
                struct lustre_ost_attrs oti_ost_attrs;
-               struct filter_fid_old   oti_ff;
-               struct filter_fid       oti_ff_new;
+               struct filter_fid_18_23 oti_ff_old;
+               struct filter_fid       oti_ff;
        };
        /** 0-copy IO */
-       struct osd_iobuf       oti_iobuf;
+       struct osd_iobuf                oti_iobuf;
        /* used to access objects in /O */
-       struct inode          *oti_inode;
+       struct inode                    *oti_inode;
 #define OSD_FID_REC_SZ 32
-       char                   oti_ldp[OSD_FID_REC_SZ];
-       char                   oti_ldp2[OSD_FID_REC_SZ];
+       char                            oti_ldp[OSD_FID_REC_SZ];
+       char                            oti_ldp2[OSD_FID_REC_SZ];
 
        /* used by quota code */
        union {
 #if defined(HAVE_DQUOT_QC_DQBLK)
                struct qc_dqblk         oti_qdq;
-#elif defined(HAVE_DQUOT_FS_DISK_QUOTA)
-               struct fs_disk_quota    oti_fdq;
 #else
-               struct if_dqblk         oti_dqblk;
+               struct fs_disk_quota    oti_fdq;
 #endif
                struct if_dqinfo        oti_dqinfo;
        };
@@ -636,10 +708,23 @@ struct osd_thread_info {
        unsigned int            oti_declare_ops_cred[OSD_OT_MAX];
        unsigned int            oti_declare_ops_used[OSD_OT_MAX];
        struct osd_directory    oti_iam;
+
+       struct page             **oti_dio_pages;
+       int                     oti_dio_pages_used;
+
+       struct osd_it_ea_dirent *oti_seq_dirent;
+       struct osd_it_ea_dirent *oti_dir_dirent;
 };
 
 extern int ldiskfs_pdo;
 
+/* autoconf test is in lustre-build-ldiskfs.m4 */
+#ifdef HAVE_BVEC_ITER_ALL
+#define DECLARE_BVEC_ITER_ALL(iter) struct bvec_iter_all iter
+#else
+#define DECLARE_BVEC_ITER_ALL(iter) int iter
+#endif
+
 static inline int __osd_xattr_get(struct inode *inode, struct dentry *dentry,
                                  const char *name, void *buf, int len)
 {
@@ -648,7 +733,7 @@ static inline int __osd_xattr_get(struct inode *inode, struct dentry *dentry,
 
        dentry->d_inode = inode;
        dentry->d_sb = inode->i_sb;
-       return inode->i_op->getxattr(dentry, name, buf, len);
+       return ll_vfs_getxattr(dentry, inode, name, buf, len);
 }
 
 static inline int __osd_xattr_set(struct osd_thread_info *info,
@@ -657,16 +742,26 @@ static inline int __osd_xattr_set(struct osd_thread_info *info,
 {
        struct dentry *dentry = &info->oti_child_dentry;
 
-       ll_vfs_dq_init(inode);
+       dquot_initialize(inode);
        dentry->d_inode = inode;
        dentry->d_sb = inode->i_sb;
-       return inode->i_op->setxattr(dentry, name, buf, buflen, fl);
+       return ll_vfs_setxattr(dentry, inode, name, buf, buflen, fl);
+}
+
+static inline char *osd_oid_name(char *name, size_t name_size,
+                                const struct lu_fid *fid, u64 id)
+{
+       snprintf(name, name_size,
+                (fid_seq_is_rsvd(fid_seq(fid)) ||
+                 fid_seq_is_mdt0(fid_seq(fid)) ||
+                 fid_seq_is_idif(fid_seq(fid))) ? "%llu" : "%llx", id);
+
+       return name;
 }
 
 #ifdef CONFIG_PROC_FS
 /* osd_lproc.c */
 extern struct lprocfs_vars lprocfs_osd_obd_vars[];
-extern struct lprocfs_vars lprocfs_osd_module_vars[];
 int osd_procfs_init(struct osd_device *osd, const char *name);
 int osd_procfs_fini(struct osd_device *osd);
 void osd_brw_stats_update(struct osd_device *osd, struct osd_iobuf *iobuf);
@@ -676,7 +771,7 @@ int osd_register_proc_index_in_idif(struct osd_device *osd);
 
 #endif
 int osd_statfs(const struct lu_env *env, struct dt_device *dev,
-               struct obd_statfs *sfs);
+              struct obd_statfs *sfs, struct obd_statfs_info *info);
 struct inode *osd_iget(struct osd_thread_info *info, struct osd_device *dev,
                       struct osd_inode_id *id);
 struct inode *
@@ -684,12 +779,19 @@ osd_iget_fid(struct osd_thread_info *info, struct osd_device *dev,
             struct osd_inode_id *id, struct lu_fid *fid);
 int osd_ea_fid_set(struct osd_thread_info *info, struct inode *inode,
                   const struct lu_fid *fid, __u32 compat, __u32 incompat);
+struct osd_obj_seq *osd_seq_load(struct osd_thread_info *info,
+                                struct osd_device *osd, u64 seq);
 int osd_get_lma(struct osd_thread_info *info, struct inode *inode,
                struct dentry *dentry, struct lustre_ost_attrs *loa);
 void osd_add_oi_cache(struct osd_thread_info *info, struct osd_device *osd,
                      struct osd_inode_id *id, const struct lu_fid *fid);
 int osd_get_idif(struct osd_thread_info *info, struct inode *inode,
                 struct dentry *dentry, struct lu_fid *fid);
+struct osd_it_ea *osd_it_dir_init(const struct lu_env *env, struct inode *inode,
+                                 __u32 attr);
+void osd_it_dir_fini(const struct lu_env *env, struct osd_it_ea *oie,
+                    struct inode *inode);
+int osd_ldiskfs_it_fill(const struct lu_env *env, const struct dt_it *di);
 
 int osd_obj_map_init(const struct lu_env *env, struct osd_device *osd);
 void osd_obj_map_fini(struct osd_device *dev);
@@ -707,25 +809,37 @@ int osd_obj_map_recover(struct osd_thread_info *info, struct osd_device *osd,
                        struct inode *src_parent, struct dentry *src_child,
                        const struct lu_fid *fid);
 int osd_obj_spec_lookup(struct osd_thread_info *info, struct osd_device *osd,
-                       const struct lu_fid *fid, struct osd_inode_id *id);
+                       const struct lu_fid *fid, struct osd_inode_id *id,
+                       enum oi_check_flags flags);
 int osd_obj_spec_insert(struct osd_thread_info *info, struct osd_device *osd,
                        const struct lu_fid *fid, const struct osd_inode_id *id,
                        handle_t *th);
 int osd_obj_spec_update(struct osd_thread_info *info, struct osd_device *osd,
                        const struct lu_fid *fid, const struct osd_inode_id *id,
                        handle_t *th);
+int osd_obj_del_entry(struct osd_thread_info *info, struct osd_device *osd,
+                     struct dentry *dird, char *name, int namelen,
+                     handle_t *th);
 
 char *osd_lf_fid2name(const struct lu_fid *fid);
 int osd_scrub_start(const struct lu_env *env, struct osd_device *dev,
                    __u32 flags);
-int osd_scrub_setup(const struct lu_env *env, struct osd_device *dev);
+void osd_scrub_stop(struct osd_device *dev);
+int osd_scrub_setup(const struct lu_env *env, struct osd_device *dev,
+                   bool restored);
 void osd_scrub_cleanup(const struct lu_env *env, struct osd_device *dev);
-int osd_oii_insert(struct osd_device *dev, struct osd_idmap_cache *oic,
-                  int insert);
+int osd_oii_insert(struct osd_device *dev, const struct lu_fid *fid,
+                  struct osd_inode_id *id, int insert);
 int osd_oii_lookup(struct osd_device *dev, const struct lu_fid *fid,
                   struct osd_inode_id *id);
 void osd_scrub_dump(struct seq_file *m, struct osd_device *dev);
 
+struct dentry *osd_lookup_one_len_unlocked(struct osd_device *dev,
+                                          const char *name,
+                                          struct dentry *base, int len);
+struct dentry *osd_lookup_one_len(struct osd_device *dev, const char *name,
+                                 struct dentry *base, int len);
+
 int osd_fld_lookup(const struct lu_env *env, struct osd_device *osd,
                   u64 seq, struct lu_seq_range *range);
 
@@ -742,6 +856,13 @@ int osd_lookup_in_remote_parent(struct osd_thread_info *oti,
 
 int osd_ost_seq_exists(struct osd_thread_info *info, struct osd_device *osd,
                       __u64 seq);
+int osd_scrub_refresh_mapping(struct osd_thread_info *info,
+                             struct osd_device *dev,
+                             const struct lu_fid *fid,
+                             const struct osd_inode_id *id,
+                             int ops, bool force,
+                             enum oi_check_flags flags, bool *exist);
+
 /* osd_quota_fmt.c */
 int walk_tree_dqentry(const struct lu_env *env, struct osd_object *obj,
                       int type, uint blk, int depth, uint index,
@@ -756,38 +877,17 @@ loff_t find_tree_dqentry(const struct lu_env *env,
 /* osd_quota.c */
 int osd_declare_qid(const struct lu_env *env, struct osd_thandle *oh,
                    struct lquota_id_info *qi, struct osd_object *obj,
-                   bool enforce, int *flags);
+                   bool enforce, enum osd_quota_local_flags *local_flags);
 int osd_declare_inode_qid(const struct lu_env *env, qid_t uid, qid_t gid,
                          __u32 projid, long long space, struct osd_thandle *oh,
-                         struct osd_object *obj, int *flags,
+                         struct osd_object *obj,
+                         enum osd_quota_local_flags *local_flags,
                          enum osd_qid_declare_flags);
 const struct dt_rec *osd_quota_pack(struct osd_object *obj,
                                    const struct dt_rec *rec,
                                    union lquota_rec *quota_rec);
 void osd_quota_unpack(struct osd_object *obj, const struct dt_rec *rec);
 
-#ifndef HAVE_I_UID_READ
-static inline uid_t i_uid_read(const struct inode *inode)
-{
-       return inode->i_uid;
-}
-
-static inline gid_t i_gid_read(const struct inode *inode)
-{
-       return inode->i_gid;
-}
-
-static inline void i_uid_write(struct inode *inode, uid_t uid)
-{
-       inode->i_uid = uid;
-}
-
-static inline void i_gid_write(struct inode *inode, gid_t gid)
-{
-       inode->i_gid = gid;
-}
-#endif
-
 #ifdef HAVE_PROJECT_QUOTA
 static inline __u32 i_projid_read(struct inode *inode)
 {
@@ -811,6 +911,14 @@ static inline void i_projid_write(struct inode *inode, __u32 projid)
 }
 #endif
 
+#ifdef HAVE_LDISKFS_IGET_WITH_FLAGS
+# define osd_ldiskfs_iget(sb, ino) \
+               ldiskfs_iget((sb), (ino), \
+                            LDISKFS_IGET_HANDLE | LDISKFS_IGET_SPECIAL)
+#else
+# define osd_ldiskfs_iget(sb, ino) ldiskfs_iget((sb), (ino))
+#endif
+
 #ifdef HAVE_LDISKFS_INFO_JINODE
 # define osd_attach_jinode(inode) ldiskfs_inode_attach_jinode(inode)
 #else  /* HAVE_LDISKFS_INFO_JINODE */
@@ -831,14 +939,22 @@ static inline struct buffer_head *osd_ldiskfs_append(handle_t *handle,
                return ERR_PTR(rc);
        return ldiskfs_append(handle, inode, nblock);
 }
-# define osd_ldiskfs_find_entry(dir, name, de, inlined, lock) \
+
+# ifdef HAVE___LDISKFS_FIND_ENTRY
+#  define osd_ldiskfs_find_entry(dir, name, de, inlined, lock) \
                (__ldiskfs_find_entry(dir, name, de, inlined, lock) ?: \
                 ERR_PTR(-ENOENT))
+# else
+#  define osd_ldiskfs_find_entry(dir, name, de, inlined, lock) \
+               (ldiskfs_find_entry_locked(dir, name, de, inlined, lock) ?: \
+                ERR_PTR(-ENOENT))
+# endif
+
 # define osd_journal_start(inode, type, nblocks) \
                ldiskfs_journal_start(inode, type, nblocks)
 # define osd_transaction_size(dev) \
                (osd_journal(dev)->j_max_transaction_buffers / 2)
-#else
+#else /* ! defined LDISKFS_HT_MISC */
 # define LDISKFS_HT_MISC       0
 # define osd_journal_start_sb(sb, type, nblock) \
                ldiskfs_journal_start_sb(sb, nblock)
@@ -857,13 +973,24 @@ static inline struct buffer_head *osd_ldiskfs_append(handle_t *handle,
        return bh;
 }
 
-# define osd_ldiskfs_find_entry(dir, name, de, inlined, lock) \
+# ifdef HAVE___LDISKFS_FIND_ENTRY
+#  define osd_ldiskfs_find_entry(dir, name, de, inlined, lock) \
                (__ldiskfs_find_entry(dir, name, de, lock) ?: \
                 ERR_PTR(-ENOENT))
+# else
+#  define osd_ldiskfs_find_entry(dir, name, de, inlined, lock) \
+               (ldiskfs_find_entry_locked(dir, name, de, lock) ?: \
+                ERR_PTR(-ENOENT))
+# endif
 # define osd_journal_start(inode, type, nblocks) \
                ldiskfs_journal_start(inode, nblocks)
 # define osd_transaction_size(dev) \
                (osd_journal(dev)->j_max_transaction_buffers)
+#endif /* LDISKFS_HT_MISC */
+
+#ifndef HAVE___LDISKFS_FIND_ENTRY
+# define __ldiskfs_add_entry(handle, child, inode, hlock) \
+               ldiskfs_add_entry_locked(handle, child, inode, hlock)
 #endif
 
 /*
@@ -893,6 +1020,8 @@ static inline int osd_invariant(const struct osd_object *obj)
 #endif
 
 #define OSD_MAX_CACHE_SIZE OBD_OBJECT_EOF
+#define OSD_READCACHE_MAX_IO_MB                8
+#define OSD_WRITECACHE_MAX_IO_MB       8
 
 extern const struct dt_index_operations osd_otable_ops;
 
@@ -923,14 +1052,14 @@ static inline int lu_device_is_osd(const struct lu_device *d)
 
 static inline struct osd_device *osd_dt_dev(const struct dt_device *d)
 {
-        LASSERT(lu_device_is_osd(&d->dd_lu_dev));
-        return container_of0(d, struct osd_device, od_dt_dev);
+       LASSERT(lu_device_is_osd(&d->dd_lu_dev));
+       return container_of(d, struct osd_device, od_dt_dev);
 }
 
 static inline struct osd_device *osd_dev(const struct lu_device *d)
 {
-        LASSERT(lu_device_is_osd(d));
-        return osd_dt_dev(container_of0(d, struct dt_device, dd_lu_dev));
+       LASSERT(lu_device_is_osd(d));
+       return osd_dt_dev(container_of(d, struct dt_device, dd_lu_dev));
 }
 
 static inline struct osd_device *osd_obj2dev(const struct osd_object *o)
@@ -943,14 +1072,22 @@ static inline struct super_block *osd_sb(const struct osd_device *dev)
        return dev->od_mnt->mnt_sb;
 }
 
+static inline const char *osd_sb2name(const struct super_block *sb)
+{
+       /* this is LDISKFS_SB(sb), but preserves "const" */
+       const struct ldiskfs_sb_info *sbi = sb->s_fs_info;
+
+       return sbi->s_es->s_volume_name;
+}
+
 static inline const char *osd_dev2name(const struct osd_device *dev)
 {
-       return osd_sb(dev)->s_id;
+       return osd_sb2name(osd_sb(dev));
 }
 
 static inline const char *osd_ino2name(const struct inode *inode)
 {
-       return inode->i_sb->s_id;
+       return osd_sb2name(inode->i_sb);
 }
 
 /**
@@ -966,13 +1103,13 @@ static inline void osd_object_put(const struct lu_env *env,
 
 static inline int osd_object_is_root(const struct osd_object *obj)
 {
-        return osd_sb(osd_obj2dev(obj))->s_root->d_inode == obj->oo_inode;
+       return obj->oo_inode && is_root_inode(obj->oo_inode);
 }
 
 static inline struct osd_object *osd_obj(const struct lu_object *o)
 {
-        LASSERT(lu_device_is_osd(o->lo_dev));
-        return container_of0(o, struct osd_object, oo_dt.do_lu);
+       LASSERT(lu_device_is_osd(o->lo_dev));
+       return container_of(o, struct osd_object, oo_dt.do_lu);
 }
 
 static inline struct osd_object *osd_dt_obj(const struct dt_object *d)
@@ -1046,8 +1183,6 @@ int osd_calc_bkmap_credits(struct super_block *sb, struct inode *inode,
                           const int blocks);
 
 int osd_ldiskfs_read(struct inode *inode, void *buf, int size, loff_t *offs);
-int osd_ldiskfs_write_record(struct inode *inode, void *buf, int bufsize,
-                            int write_NUL, loff_t *offs, handle_t *handle);
 
 static inline
 struct dentry *osd_child_dentry_by_inode(const struct lu_env *env,
@@ -1069,6 +1204,43 @@ struct dentry *osd_child_dentry_by_inode(const struct lu_env *env,
         return child_dentry;
 }
 
+/* build quasi file structure when it is needed to call an inode i_fop */
+static inline struct file *osd_quasi_file_init(const struct lu_env *env,
+                                              struct dentry *dentry,
+                                              struct inode *inode)
+{
+       struct osd_thread_info *info = osd_oti_get(env);
+
+       info->oti_file.f_path.dentry = dentry;
+       info->oti_file.f_mapping = inode->i_mapping;
+       info->oti_file.f_op = inode->i_fop;
+       info->oti_file.f_inode = inode;
+       info->oti_file.f_pos = 0;
+       info->oti_file.private_data = NULL;
+       info->oti_file.f_cred = current_cred();
+       info->oti_file.f_flags = O_NOATIME;
+       info->oti_file.f_mode = FMODE_64BITHASH | FMODE_NONOTIFY;
+
+       return &info->oti_file;
+}
+
+static inline struct file *osd_quasi_file(const struct lu_env *env,
+                                         struct inode *inode)
+{
+       struct osd_thread_info *info = osd_oti_get(env);
+
+       info->oti_obj_dentry.d_inode = inode;
+       info->oti_obj_dentry.d_sb = inode->i_sb;
+
+       return osd_quasi_file_init(env, &info->oti_obj_dentry, inode);
+}
+
+static inline struct file *osd_quasi_file_by_dentry(const struct lu_env *env,
+                                                   struct dentry *dentry)
+{
+       return osd_quasi_file_init(env, dentry, dentry->d_inode);
+}
+
 extern int osd_trans_declare_op2rb[];
 extern int ldiskfs_track_declares_assert;
 void osd_trans_dump_creds(const struct lu_env *env, struct thandle *th);
@@ -1095,6 +1267,11 @@ static inline void osd_trans_declare_op(const struct lu_env *env,
        oh->ot_credits += credits;
 }
 
+/* linux: v5.4-rc3-21-g933f1c1e0b75 renamed h_buffer_credits */
+#ifdef HAVE_JOURNAL_TOTAL_CREDITS
+#define h_buffer_credits h_total_credits
+#endif
+
 static inline void osd_trans_exec_op(const struct lu_env *env,
                                     struct thandle *th,
                                     enum osd_op_type op)
@@ -1273,9 +1450,14 @@ static inline int fid_is_internal(const struct lu_fid *fid)
        return (!fid_is_namespace_visible(fid) && !fid_is_idif(fid));
 }
 
-static inline unsigned long osd_remote_parent_ino(struct osd_device *dev)
+static inline bool is_remote_parent_ino(struct osd_device *o, unsigned long ino)
 {
-       return dev->od_mdt_map->omm_remote_parent->d_inode->i_ino;
+       if (o->od_is_ost)
+               return false;
+
+       LASSERT(o->od_mdt_map != NULL);
+
+       return ino == o->od_mdt_map->omm_remote_parent->d_inode->i_ino;
 }
 
 /**
@@ -1307,6 +1489,20 @@ static inline struct buffer_head *__ldiskfs_bread(handle_t *handle,
        return bh;
 }
 
+#ifndef HAVE_BIO_INTEGRITY_ENABLED
+bool bio_integrity_enabled(struct bio *bio);
+#endif
+
+#ifdef HAVE_BI_BDEV
+# define bio_get_dev(bio)      ((bio)->bi_bdev)
+# define bio_get_disk(bio)     (bio_get_dev(bio)->bd_disk)
+# define bio_get_queue(bio)    bdev_get_queue(bio_get_dev(bio))
+# define bio_set_dev(bio, bdev) (bio_get_dev(bio) = (bdev))
+#else
+# define bio_get_disk(bio)     ((bio)->bi_disk)
+# define bio_get_queue(bio)    (bio_get_disk(bio)->queue)
+#endif
+
 void ldiskfs_inc_count(handle_t *handle, struct inode *inode);
 void ldiskfs_dec_count(handle_t *handle, struct inode *inode);
 
@@ -1339,4 +1535,102 @@ osd_index_backup(const struct lu_env *env, struct osd_device *osd, bool backup)
                            &osd->od_index_backup_stop, backup);
 }
 
+#ifdef LDISKFS_HAS_INCOMPAT_FEATURE
+
+# ifdef LDISKFS_FEATURE_INCOMPAT_EXTENTS
+# define ldiskfs_has_feature_extents(sb) \
+       LDISKFS_HAS_INCOMPAT_FEATURE(sb, LDISKFS_FEATURE_INCOMPAT_EXTENTS)
+# endif
+# ifdef LDISKFS_FEATURE_INCOMPAT_EA_INODE
+# define ldiskfs_has_feature_ea_inode(sb) \
+       LDISKFS_HAS_INCOMPAT_FEATURE(sb, LDISKFS_FEATURE_INCOMPAT_EA_INODE)
+# endif
+# ifdef LDISKFS_FEATURE_INCOMPAT_DIRDATA
+# define ldiskfs_has_feature_dirdata(sb) \
+       LDISKFS_HAS_INCOMPAT_FEATURE(sb, LDISKFS_FEATURE_INCOMPAT_DIRDATA)
+# endif
+# ifdef LDISKFS_FEATURE_COMPAT_HAS_JOURNAL
+# define ldiskfs_has_feature_journal(sb) \
+       LDISKFS_HAS_COMPAT_FEATURE(sb, LDISKFS_FEATURE_COMPAT_HAS_JOURNAL)
+# endif
+# ifdef LDISKFS_FEATURE_RO_COMPAT_QUOTA
+# define ldiskfs_has_feature_quota(sb) \
+       LDISKFS_HAS_RO_COMPAT_FEATURE(sb, LDISKFS_FEATURE_RO_COMPAT_QUOTA)
+# endif
+# ifdef LDISKFS_FEATURE_RO_COMPAT_PROJECT
+# define ldiskfs_has_feature_project(sb) \
+       LDISKFS_HAS_RO_COMPAT_FEATURE(sb, LDISKFS_FEATURE_RO_COMPAT_PROJECT)
+# endif
+
+#endif
+
+int osd_trunc_lock(struct osd_object *obj, struct osd_thandle *oh,
+                  bool shared);
+void osd_trunc_unlock_all(const struct lu_env *env, struct list_head *list);
+void osd_process_truncates(const struct lu_env *env, struct list_head *list);
+void osd_execute_truncate(struct osd_object *obj);
+
+#ifdef HAVE_BIO_ENDIO_USES_ONE_ARG
+#define osd_dio_complete_routine(bio, error) dio_complete_routine(bio)
+#else
+#define osd_dio_complete_routine(bio, error) dio_complete_routine(bio, error)
+#endif
+
+#ifndef HAVE___BI_CNT
+#define __bi_cnt bi_cnt
+#endif
+
+#ifndef HAVE_BI_OPF
+#define bi_opf bi_rw
+#endif
+
+#ifndef HAVE_CLEAN_BDEV_ALIASES
+#define clean_bdev_aliases(bdev, block, len)   \
+       unmap_underlying_metadata((bdev), (block))
+#endif
+
+#ifndef HAVE_BI_STATUS
+#define bi_status bi_error
+#endif
+
+/*
+ * Maximum size of xattr attributes for FEATURE_INCOMPAT_EA_INODE 1Mb
+ * This limit is arbitrary, but is reasonable for the xattr API.
+ */
+#define LDISKFS_XATTR_MAX_LARGE_EA_SIZE    (1024 * 1024)
+
+struct osd_bio_private {
+       struct osd_iobuf        *obp_iobuf;
+       /* Start page index in the obp_iobuf for the bio */
+       int                      obp_start_page_idx;
+};
+
+#ifdef HAVE_BIO_INTEGRITY_PREP_FN
+int osd_get_integrity_profile(struct osd_device *osd,
+                             integrity_gen_fn **generate_fn,
+                             integrity_vrfy_fn **verify_fn);
+#else
+#define integrity_gen_fn void
+#define integrity_vrfy_fn int
+static inline int osd_get_integrity_profile(struct osd_device *osd,
+                                           integrity_gen_fn **generate_fn,
+                                           integrity_vrfy_fn **verify_fn)
+{
+       return 0;
+}
+
+static inline bool bio_integrity_prep_fn(struct bio *bio,
+                                        integrity_gen_fn *generate_fn,
+                                        integrity_vrfy_fn *verify_fn)
+{
+       return bio_integrity_prep(bio);
+}
+#endif
+
+#ifdef HAVE_BIO_BI_PHYS_SEGMENTS
+#define osd_bio_nr_segs(bio)           ((bio)->bi_phys_segments)
+#else
+#define osd_bio_nr_segs(bio)           bio_segments((bio))
+#endif /* HAVE_BIO_BI_PHYS_SEGMENTS */
+
 #endif /* _OSD_INTERNAL_H */