1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _BCACHEFS_FS_IO_H
3 #define _BCACHEFS_FS_IO_H
9 #include "io_write_types.h"
12 #include <linux/uio.h>
15 struct folio
*fv_folio
;
20 static inline struct folio_vec
biovec_to_foliovec(struct bio_vec bv
)
23 struct folio
*folio
= page_folio(bv
.bv_page
);
24 size_t offset
= (folio_page_idx(folio
, bv
.bv_page
) << PAGE_SHIFT
) +
26 size_t len
= min_t(size_t, folio_size(folio
) - offset
, bv
.bv_len
);
28 return (struct folio_vec
) {
35 static inline struct folio_vec
bio_iter_iovec_folio(struct bio
*bio
,
36 struct bvec_iter iter
)
38 return biovec_to_foliovec(bio_iter_iovec(bio
, iter
));
41 #define __bio_for_each_folio(bvl, bio, iter, start) \
42 for (iter = (start); \
44 ((bvl = bio_iter_iovec_folio((bio), (iter))), 1); \
45 bio_advance_iter_single((bio), &(iter), (bvl).fv_len))
48 * bio_for_each_folio - iterate over folios within a bio
50 * Like other non-_all versions, this iterates over what bio->bi_iter currently
51 * points to. This version is for drivers, where the bio may have previously
52 * been split or cloned.
54 #define bio_for_each_folio(bvl, bio, iter) \
55 __bio_for_each_folio(bvl, bio, iter, (bio)->bi_iter)
61 #ifdef CONFIG_BCACHEFS_QUOTA
63 static inline void __bch2_quota_reservation_put(struct bch_fs
*c
,
64 struct bch_inode_info
*inode
,
65 struct quota_res
*res
)
67 BUG_ON(res
->sectors
> inode
->ei_quota_reserved
);
69 bch2_quota_acct(c
, inode
->ei_qid
, Q_SPC
,
70 -((s64
) res
->sectors
), KEY_TYPE_QUOTA_PREALLOC
);
71 inode
->ei_quota_reserved
-= res
->sectors
;
75 static inline void bch2_quota_reservation_put(struct bch_fs
*c
,
76 struct bch_inode_info
*inode
,
77 struct quota_res
*res
)
80 mutex_lock(&inode
->ei_quota_lock
);
81 __bch2_quota_reservation_put(c
, inode
, res
);
82 mutex_unlock(&inode
->ei_quota_lock
);
86 static inline int bch2_quota_reservation_add(struct bch_fs
*c
,
87 struct bch_inode_info
*inode
,
88 struct quota_res
*res
,
94 if (test_bit(EI_INODE_SNAPSHOT
, &inode
->ei_flags
))
97 mutex_lock(&inode
->ei_quota_lock
);
98 ret
= bch2_quota_acct(c
, inode
->ei_qid
, Q_SPC
, sectors
,
99 check_enospc
? KEY_TYPE_QUOTA_PREALLOC
: KEY_TYPE_QUOTA_NOCHECK
);
101 inode
->ei_quota_reserved
+= sectors
;
102 res
->sectors
+= sectors
;
104 mutex_unlock(&inode
->ei_quota_lock
);
111 static inline void __bch2_quota_reservation_put(struct bch_fs
*c
,
112 struct bch_inode_info
*inode
,
113 struct quota_res
*res
) {}
115 static inline void bch2_quota_reservation_put(struct bch_fs
*c
,
116 struct bch_inode_info
*inode
,
117 struct quota_res
*res
) {}
119 static inline int bch2_quota_reservation_add(struct bch_fs
*c
,
120 struct bch_inode_info
*inode
,
121 struct quota_res
*res
,
130 void __bch2_i_sectors_acct(struct bch_fs
*, struct bch_inode_info
*,
131 struct quota_res
*, s64
);
133 static inline void bch2_i_sectors_acct(struct bch_fs
*c
, struct bch_inode_info
*inode
,
134 struct quota_res
*quota_res
, s64 sectors
)
137 mutex_lock(&inode
->ei_quota_lock
);
138 __bch2_i_sectors_acct(c
, inode
, quota_res
, sectors
);
139 mutex_unlock(&inode
->ei_quota_lock
);
143 static inline struct address_space
*faults_disabled_mapping(void)
145 return (void *) (((unsigned long) current
->faults_disabled_mapping
) & ~1UL);
148 static inline void set_fdm_dropped_locks(void)
150 current
->faults_disabled_mapping
=
151 (void *) (((unsigned long) current
->faults_disabled_mapping
)|1);
154 static inline bool fdm_dropped_locks(void)
156 return ((unsigned long) current
->faults_disabled_mapping
) & 1;
159 void bch2_inode_flush_nocow_writes_async(struct bch_fs
*,
160 struct bch_inode_info
*, struct closure
*);
162 int __must_check
bch2_write_inode_size(struct bch_fs
*,
163 struct bch_inode_info
*,
166 int bch2_fsync(struct file
*, loff_t
, loff_t
, int);
168 int bchfs_truncate(struct mnt_idmap
*,
169 struct bch_inode_info
*, struct iattr
*);
170 long bch2_fallocate_dispatch(struct file
*, int, loff_t
, loff_t
);
172 loff_t
bch2_remap_file_range(struct file
*, loff_t
, struct file
*,
173 loff_t
, loff_t
, unsigned);
175 loff_t
bch2_llseek(struct file
*, loff_t
, int);
177 void bch2_fs_fsio_exit(struct bch_fs
*);
178 int bch2_fs_fsio_init(struct bch_fs
*);
180 static inline void bch2_fs_fsio_exit(struct bch_fs
*c
) {}
181 static inline int bch2_fs_fsio_init(struct bch_fs
*c
) { return 0; }
184 #endif /* _BCACHEFS_FS_IO_H */