Whamcloud - gitweb
LU-13344 osd-ldiskfs: timespec64 is broken
[fs/lustre-release.git] / lustre / osd-ldiskfs / osd_internal.h
index 8b62608..7dc4bde 100644 (file)
@@ -55,7 +55,7 @@
 
 /* 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>
@@ -153,6 +153,7 @@ struct osd_object {
 
        struct list_head        oo_xattr_list;
        struct lu_object_header *oo_header;
+       __u64                   oo_dirent_count;
 };
 
 struct osd_obj_seq {
@@ -285,7 +286,18 @@ struct osd_device {
        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;
+
+       /* 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;
+
        int                     od_read_cache;
        int                     od_writethrough_cache;
 
@@ -369,17 +381,18 @@ 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 {
@@ -559,12 +572,14 @@ 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
-# define osd_timespec_trunc(ts, gran)  timespec64_trunc((ts), (gran))
 #else
 # define osd_timespec                  timespec
-# define osd_timespec_trunc(ts, gran)  timespec_trunc((ts), (gran))
 #endif
 
 static inline struct osd_timespec osd_inode_time(struct inode *inode,
@@ -572,7 +587,7 @@ static inline struct osd_timespec osd_inode_time(struct inode *inode,
 {
        struct osd_timespec ts = { .tv_sec = seconds };
 
-       return osd_timespec_trunc(ts, inode->i_sb->s_time_gran);
+       return ts;
 }
 
 #define OSD_INS_CACHE_SIZE     8
@@ -689,28 +704,13 @@ struct osd_thread_info {
 
 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
 
-#ifndef HAVE_VFS_SETXATTR
-#define osd_setxattr(dentry, inode, name, buf, len, flag) \
-               ((inode)->i_op->setxattr(dentry, name, buf, len, flag))
-#define osd_getxattr(dentry, inode, name, buf, len) \
-               ((inode)->i_op->getxattr(dentry, name, buf, len))
-#define osd_removexattr(dentry, inode, name) \
-               ((inode)->i_op->removexattr(dentry, name))
-#else /* HAVE_VFS_SETXATTR */
-#define osd_setxattr(dentry, inode, name, buf, len, flag) \
-               __vfs_setxattr(dentry, inode, name, buf, len, flag)
-#define osd_getxattr(dentry, inode, name, buf, len) \
-               __vfs_getxattr(dentry, inode, name, buf, len)
-#define osd_removexattr(dentry, inode, name) \
-               __vfs_removexattr(dentry, name)
-#endif /* !HAVE_VFS_SETXATTR */
-
 static inline int __osd_xattr_get(struct inode *inode, struct dentry *dentry,
                                  const char *name, void *buf, int len)
 {
@@ -719,7 +719,7 @@ static inline int __osd_xattr_get(struct inode *inode, struct dentry *dentry,
 
        dentry->d_inode = inode;
        dentry->d_sb = inode->i_sb;
-       return osd_getxattr(dentry, inode, name, buf, len);
+       return ll_vfs_getxattr(dentry, inode, name, buf, len);
 }
 
 static inline int __osd_xattr_set(struct osd_thread_info *info,
@@ -731,7 +731,7 @@ static inline int __osd_xattr_set(struct osd_thread_info *info,
        dquot_initialize(inode);
        dentry->d_inode = inode;
        dentry->d_sb = inode->i_sb;
-       return osd_setxattr(dentry, inode, name, buf, buflen, fl);
+       return ll_vfs_setxattr(dentry, inode, name, buf, buflen, fl);
 }
 
 #ifdef CONFIG_PROC_FS
@@ -777,7 +777,8 @@ 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);
@@ -797,10 +798,11 @@ 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(const char *name,
+struct dentry *osd_lookup_one_len_unlocked(struct osd_device *dev,
+                                          const char *name,
                                           struct dentry *base, int len);
-struct dentry *osd_ios_lookup_one_len(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);
@@ -832,38 +834,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)
 {
@@ -889,7 +870,8 @@ static inline void i_projid_write(struct inode *inode, __u32 projid)
 
 #ifdef HAVE_LDISKFS_IGET_WITH_FLAGS
 # define osd_ldiskfs_iget(sb, ino) \
-               ldiskfs_iget((sb), (ino), LDISKFS_IGET_HANDLE)
+               ldiskfs_iget((sb), (ino), \
+                            LDISKFS_IGET_HANDLE | LDISKFS_IGET_SPECIAL)
 #else
 # define osd_ldiskfs_iget(sb, ino) ldiskfs_iget((sb), (ino))
 #endif
@@ -914,9 +896,17 @@ 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) \
@@ -940,13 +930,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
 
 /*
@@ -976,6 +977,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;
 
@@ -1006,14 +1009,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)
@@ -1054,8 +1057,8 @@ static inline int osd_object_is_root(const struct osd_object *obj)
 
 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)
@@ -1129,8 +1132,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,
@@ -1178,6 +1179,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)
@@ -1472,7 +1478,7 @@ osd_index_backup(const struct lu_env *env, struct osd_device *osd, bool backup)
 
 int osd_trunc_lock(struct osd_object *obj, struct osd_thandle *oh,
                   bool shared);
-void osd_trunc_unlock_all(struct list_head *list);
+void osd_trunc_unlock_all(const struct lu_env *env, struct list_head *list);
 void osd_process_truncates(struct list_head *list);
 void osd_execute_truncate(struct osd_object *obj);
 
@@ -1533,4 +1539,10 @@ static inline bool bio_integrity_prep_fn(struct bio *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 */