]> git.sesse.net Git - bcachefs-tools-debian/blobdiff - libbcachefs/fs-io.h
Move c_src dirs back to toplevel
[bcachefs-tools-debian] / libbcachefs / fs-io.h
index 9fdcb6b6602a80310d9f7a674e88a72a187f721f..ca70346e68dc3d9196c85ce7768b1c9f53e6e792 100644 (file)
+/* SPDX-License-Identifier: GPL-2.0 */
 #ifndef _BCACHEFS_FS_IO_H
 #define _BCACHEFS_FS_IO_H
 
-#include "buckets.h"
-#include <linux/uio.h>
-
-int bch2_set_page_dirty(struct page *);
-
-int bch2_writepage(struct page *, struct writeback_control *);
-int bch2_readpage(struct file *, struct page *);
-
-int bch2_writepages(struct address_space *, struct writeback_control *);
-int bch2_readpages(struct file *, struct address_space *,
-                  struct list_head *, unsigned);
-
-int bch2_write_begin(struct file *, struct address_space *, loff_t,
-                    unsigned, unsigned, struct page **, void **);
-int bch2_write_end(struct file *, struct address_space *, loff_t,
-                  unsigned, unsigned, struct page *, void *);
-
-ssize_t bch2_direct_IO(struct kiocb *, struct iov_iter *);
-
-ssize_t bch2_write_iter(struct kiocb *, struct iov_iter *);
-
-int bch2_fsync(struct file *, loff_t, loff_t, int);
-
-int bch2_truncate(struct inode *, struct iattr *);
-long bch2_fallocate_dispatch(struct file *, int, loff_t, loff_t);
-
-loff_t bch2_llseek(struct file *, loff_t, int);
+#ifndef NO_BCACHEFS_FS
 
-int bch2_page_mkwrite(struct vm_fault *);
-void bch2_invalidatepage(struct page *, unsigned int, unsigned int);
-int bch2_releasepage(struct page *, gfp_t);
-int bch2_migrate_page(struct address_space *, struct page *,
-                     struct page *, enum migrate_mode);
-
-struct i_sectors_hook {
-       struct extent_insert_hook       hook;
-       s64                             sectors;
-       struct bch_inode_info           *ei;
-};
+#include "buckets.h"
+#include "fs.h"
+#include "io_write_types.h"
+#include "quota.h"
 
-struct bchfs_write_op {
-       struct bch_inode_info   *ei;
-       s64                     sectors_added;
-       bool                    is_dio;
-       u64                     new_i_size;
+#include <linux/uio.h>
 
-       /* must be last: */
-       struct bch_write_op     op;
+struct folio_vec {
+       struct folio    *fv_folio;
+       size_t          fv_offset;
+       size_t          fv_len;
 };
 
-struct bch_writepage_io {
-       struct closure          cl;
-
-       /* must be last: */
-       struct bchfs_write_op   op;
+static inline struct folio_vec biovec_to_foliovec(struct bio_vec bv)
+{
+
+       struct folio *folio     = page_folio(bv.bv_page);
+       size_t offset           = (folio_page_idx(folio, bv.bv_page) << PAGE_SHIFT) +
+               bv.bv_offset;
+       size_t len = min_t(size_t, folio_size(folio) - offset, bv.bv_len);
+
+       return (struct folio_vec) {
+               .fv_folio       = folio,
+               .fv_offset      = offset,
+               .fv_len         = len,
+       };
+}
+
+static inline struct folio_vec bio_iter_iovec_folio(struct bio *bio,
+                                                   struct bvec_iter iter)
+{
+       return biovec_to_foliovec(bio_iter_iovec(bio, iter));
+}
+
+#define __bio_for_each_folio(bvl, bio, iter, start)                    \
+       for (iter = (start);                                            \
+            (iter).bi_size &&                                          \
+               ((bvl = bio_iter_iovec_folio((bio), (iter))), 1);       \
+            bio_advance_iter_single((bio), &(iter), (bvl).fv_len))
+
+/**
+ * bio_for_each_folio - iterate over folios within a bio
+ *
+ * Like other non-_all versions, this iterates over what bio->bi_iter currently
+ * points to. This version is for drivers, where the bio may have previously
+ * been split or cloned.
+ */
+#define bio_for_each_folio(bvl, bio, iter)                             \
+       __bio_for_each_folio(bvl, bio, iter, (bio)->bi_iter)
+
+struct quota_res {
+       u64                             sectors;
 };
 
-extern struct bio_set *bch2_writepage_bioset;
-
-struct dio_write {
-       struct closure          cl;
-       struct kiocb            *req;
-       struct bch_fs           *c;
-       long                    written;
-       long                    error;
-       loff_t                  offset;
-
-       struct disk_reservation res;
+#ifdef CONFIG_BCACHEFS_QUOTA
+
+static inline void __bch2_quota_reservation_put(struct bch_fs *c,
+                                        struct bch_inode_info *inode,
+                                        struct quota_res *res)
+{
+       BUG_ON(res->sectors > inode->ei_quota_reserved);
+
+       bch2_quota_acct(c, inode->ei_qid, Q_SPC,
+                       -((s64) res->sectors), KEY_TYPE_QUOTA_PREALLOC);
+       inode->ei_quota_reserved -= res->sectors;
+       res->sectors = 0;
+}
+
+static inline void bch2_quota_reservation_put(struct bch_fs *c,
+                                      struct bch_inode_info *inode,
+                                      struct quota_res *res)
+{
+       if (res->sectors) {
+               mutex_lock(&inode->ei_quota_lock);
+               __bch2_quota_reservation_put(c, inode, res);
+               mutex_unlock(&inode->ei_quota_lock);
+       }
+}
+
+static inline int bch2_quota_reservation_add(struct bch_fs *c,
+                                     struct bch_inode_info *inode,
+                                     struct quota_res *res,
+                                     u64 sectors,
+                                     bool check_enospc)
+{
+       int ret;
+
+       if (test_bit(EI_INODE_SNAPSHOT, &inode->ei_flags))
+               return 0;
+
+       mutex_lock(&inode->ei_quota_lock);
+       ret = bch2_quota_acct(c, inode->ei_qid, Q_SPC, sectors,
+                             check_enospc ? KEY_TYPE_QUOTA_PREALLOC : KEY_TYPE_QUOTA_NOCHECK);
+       if (likely(!ret)) {
+               inode->ei_quota_reserved += sectors;
+               res->sectors += sectors;
+       }
+       mutex_unlock(&inode->ei_quota_lock);
+
+       return ret;
+}
+
+#else
+
+static inline void __bch2_quota_reservation_put(struct bch_fs *c,
+                                        struct bch_inode_info *inode,
+                                        struct quota_res *res) {}
+
+static inline void bch2_quota_reservation_put(struct bch_fs *c,
+                                      struct bch_inode_info *inode,
+                                      struct quota_res *res) {}
+
+static inline int bch2_quota_reservation_add(struct bch_fs *c,
+                                     struct bch_inode_info *inode,
+                                     struct quota_res *res,
+                                     unsigned sectors,
+                                     bool check_enospc)
+{
+       return 0;
+}
+
+#endif
+
+void __bch2_i_sectors_acct(struct bch_fs *, struct bch_inode_info *,
+                          struct quota_res *, s64);
+
+static inline void bch2_i_sectors_acct(struct bch_fs *c, struct bch_inode_info *inode,
+                                      struct quota_res *quota_res, s64 sectors)
+{
+       if (sectors) {
+               mutex_lock(&inode->ei_quota_lock);
+               __bch2_i_sectors_acct(c, inode, quota_res, sectors);
+               mutex_unlock(&inode->ei_quota_lock);
+       }
+}
+
+static inline struct address_space *faults_disabled_mapping(void)
+{
+       return (void *) (((unsigned long) current->faults_disabled_mapping) & ~1UL);
+}
+
+static inline void set_fdm_dropped_locks(void)
+{
+       current->faults_disabled_mapping =
+               (void *) (((unsigned long) current->faults_disabled_mapping)|1);
+}
+
+static inline bool fdm_dropped_locks(void)
+{
+       return ((unsigned long) current->faults_disabled_mapping) & 1;
+}
+
+void bch2_inode_flush_nocow_writes_async(struct bch_fs *,
+                       struct bch_inode_info *, struct closure *);
+
+int __must_check bch2_write_inode_size(struct bch_fs *,
+                                      struct bch_inode_info *,
+                                      loff_t, unsigned);
 
-       struct iovec            *iovec;
-       struct iovec            inline_vecs[UIO_FASTIOV];
-       struct iov_iter         iter;
-
-       struct mm_struct        *mm;
+int bch2_fsync(struct file *, loff_t, loff_t, int);
 
-       /* must be last: */
-       struct bchfs_write_op   iop;
-};
+int bchfs_truncate(struct mnt_idmap *,
+                 struct bch_inode_info *, struct iattr *);
+long bch2_fallocate_dispatch(struct file *, int, loff_t, loff_t);
 
-extern struct bio_set *bch2_dio_write_bioset;
+loff_t bch2_remap_file_range(struct file *, loff_t, struct file *,
+                            loff_t, loff_t, unsigned);
 
-struct dio_read {
-       struct closure          cl;
-       struct kiocb            *req;
-       long                    ret;
-       struct bch_read_bio     rbio;
-};
+loff_t bch2_llseek(struct file *, loff_t, int);
 
-extern struct bio_set *bch2_dio_read_bioset;
+void bch2_fs_fsio_exit(struct bch_fs *);
+int bch2_fs_fsio_init(struct bch_fs *);
+#else
+static inline void bch2_fs_fsio_exit(struct bch_fs *c) {}
+static inline int bch2_fs_fsio_init(struct bch_fs *c) { return 0; }
+#endif
 
 #endif /* _BCACHEFS_FS_IO_H */