xref: /linux/include/linux/buffer_head.h (revision b9a3eae9453b7547e4ab27df53a2ee8c7eb90c01)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * include/linux/buffer_head.h
4  *
5  * Everything to do with buffer_heads.
6  */
7 
8 #ifndef _LINUX_BUFFER_HEAD_H
9 #define _LINUX_BUFFER_HEAD_H
10 
11 #include <linux/types.h>
12 #include <linux/blk_types.h>
13 #include <linux/fs.h>
14 #include <linux/linkage.h>
15 #include <linux/pagemap.h>
16 #include <linux/wait.h>
17 #include <linux/atomic.h>
18 
19 enum bh_state_bits {
20 	BH_Uptodate,	/* Contains valid data */
21 	BH_Dirty,	/* Is dirty */
22 	BH_Lock,	/* Is locked */
23 	BH_Req,		/* Has been submitted for I/O */
24 
25 	BH_Mapped,	/* Has a disk mapping */
26 	BH_New,		/* Disk mapping was newly created by get_block */
27 	BH_Async_Read,	/* Is under end_buffer_async_read I/O */
28 	BH_Async_Write,	/* Is under end_buffer_async_write I/O */
29 	BH_Delay,	/* Buffer is not yet allocated on disk */
30 	BH_Boundary,	/* Block is followed by a discontiguity */
31 	BH_Write_EIO,	/* I/O error on write */
32 	BH_Unwritten,	/* Buffer is allocated on disk but not written */
33 	BH_Quiet,	/* Buffer Error Prinks to be quiet */
34 	BH_Meta,	/* Buffer contains metadata */
35 	BH_Prio,	/* Buffer should be submitted with REQ_PRIO */
36 	BH_Defer_Completion, /* Defer AIO completion to workqueue */
37 	BH_Migrate,     /* Buffer is being migrated (norefs) */
38 
39 	BH_PrivateStart,/* not a state bit, but the first bit available
40 			 * for private allocation by other entities
41 			 */
42 };
43 
44 #define MAX_BUF_PER_PAGE (PAGE_SIZE / 512)
45 
46 struct page;
47 struct buffer_head;
48 struct address_space;
49 
50 /*
51  * Historically, a buffer_head was used to map a single block
52  * within a page, and of course as the unit of I/O through the
53  * filesystem and block layers.  Nowadays the basic I/O unit
54  * is the bio, and buffer_heads are used for extracting block
55  * mappings (via a get_block_t call), for tracking state within
56  * a folio (via a folio_mapping) and for wrapping bio submission
57  * for backward compatibility reasons (e.g. bh_submit).
58  */
59 struct buffer_head {
60 	unsigned long b_state;		/* buffer state bitmap (see above) */
61 	struct buffer_head *b_this_page;/* circular list of page's buffers */
62 	struct folio *b_folio;		/* the folio this bh is mapped to */
63 
64 	sector_t b_blocknr;		/* start block number */
65 	size_t b_size;			/* size of mapping */
66 	char *b_data;			/* pointer to data within the page */
67 
68 	struct block_device *b_bdev;
69 	void *b_private;		/* reserved for bio_end_io */
70 	struct list_head b_assoc_buffers; /* associated with another mapping */
71 	struct mapping_metadata_bhs *b_mmb; /* head of the list of metadata bhs
72 					     * this buffer is associated with */
73 	atomic_t b_count;		/* users using this buffer_head */
74 	spinlock_t b_uptodate_lock;	/* Used by the first bh in a page, to
75 					 * serialise IO completion of other
76 					 * buffers in the page */
77 };
78 
79 /*
80  * macro tricks to expand the set_buffer_foo(), clear_buffer_foo()
81  * and buffer_foo() functions.
82  * To avoid reset buffer flags that are already set, because that causes
83  * a costly cache line transition, check the flag first.
84  */
85 #define BUFFER_FNS(bit, name)						\
86 static __always_inline void set_buffer_##name(struct buffer_head *bh)	\
87 {									\
88 	if (!test_bit(BH_##bit, &(bh)->b_state))			\
89 		set_bit(BH_##bit, &(bh)->b_state);			\
90 }									\
91 static __always_inline void clear_buffer_##name(struct buffer_head *bh)	\
92 {									\
93 	clear_bit(BH_##bit, &(bh)->b_state);				\
94 }									\
95 static __always_inline int buffer_##name(const struct buffer_head *bh)	\
96 {									\
97 	return test_bit(BH_##bit, &(bh)->b_state);			\
98 }
99 
100 /*
101  * test_set_buffer_foo() and test_clear_buffer_foo()
102  */
103 #define TAS_BUFFER_FNS(bit, name)					\
104 static __always_inline int test_set_buffer_##name(struct buffer_head *bh) \
105 {									\
106 	return test_and_set_bit(BH_##bit, &(bh)->b_state);		\
107 }									\
108 static __always_inline int test_clear_buffer_##name(struct buffer_head *bh) \
109 {									\
110 	return test_and_clear_bit(BH_##bit, &(bh)->b_state);		\
111 }									\
112 
113 /*
114  * Emit the buffer bitops functions.   Note that there are also functions
115  * of the form "mark_buffer_foo()".  These are higher-level functions which
116  * do something in addition to setting a b_state bit.
117  */
BUFFER_FNS(Dirty,dirty)118 BUFFER_FNS(Dirty, dirty)
119 TAS_BUFFER_FNS(Dirty, dirty)
120 BUFFER_FNS(Lock, locked)
121 BUFFER_FNS(Req, req)
122 TAS_BUFFER_FNS(Req, req)
123 BUFFER_FNS(Mapped, mapped)
124 BUFFER_FNS(New, new)
125 BUFFER_FNS(Async_Read, async_read)
126 BUFFER_FNS(Async_Write, async_write)
127 BUFFER_FNS(Delay, delay)
128 BUFFER_FNS(Boundary, boundary)
129 BUFFER_FNS(Write_EIO, write_io_error)
130 BUFFER_FNS(Unwritten, unwritten)
131 BUFFER_FNS(Meta, meta)
132 BUFFER_FNS(Prio, prio)
133 BUFFER_FNS(Defer_Completion, defer_completion)
134 
135 static __always_inline void set_buffer_uptodate(struct buffer_head *bh)
136 {
137 	/*
138 	 * If somebody else already set this uptodate, they will
139 	 * have done the memory barrier, and a reader will thus
140 	 * see *some* valid buffer state.
141 	 *
142 	 * Any other serialization (with IO errors or whatever that
143 	 * might clear the bit) has to come from other state (eg BH_Lock).
144 	 */
145 	if (test_bit(BH_Uptodate, &bh->b_state))
146 		return;
147 
148 	/*
149 	 * make it consistent with folio_mark_uptodate
150 	 * pairs with smp_load_acquire in buffer_uptodate
151 	 */
152 	smp_mb__before_atomic();
153 	set_bit(BH_Uptodate, &bh->b_state);
154 }
155 
clear_buffer_uptodate(struct buffer_head * bh)156 static __always_inline void clear_buffer_uptodate(struct buffer_head *bh)
157 {
158 	clear_bit(BH_Uptodate, &bh->b_state);
159 }
160 
buffer_uptodate(const struct buffer_head * bh)161 static __always_inline int buffer_uptodate(const struct buffer_head *bh)
162 {
163 	/*
164 	 * make it consistent with folio_test_uptodate
165 	 * pairs with smp_mb__before_atomic in set_buffer_uptodate
166 	 */
167 	return test_bit_acquire(BH_Uptodate, &bh->b_state);
168 }
169 
bh_offset(const struct buffer_head * bh)170 static inline unsigned long bh_offset(const struct buffer_head *bh)
171 {
172 	return (unsigned long)(bh)->b_data & (folio_size(bh->b_folio) - 1);
173 }
174 
175 /**
176  * kmap_local_bh - Map the data of a buffer.
177  * @bh: The buffer.
178  *
179  * Buffers usually live in the page cache, but a few are built over memory
180  * which is not.  Those carry no folio and b_data is already a kernel address
181  * which is always mapped, so there is nothing to do for them.  Pair with
182  * kunmap_local_bh().
183  *
184  * Return: A pointer to the buffer's data.
185  */
kmap_local_bh(const struct buffer_head * bh)186 static inline void *kmap_local_bh(const struct buffer_head *bh)
187 {
188 	if (!bh->b_folio)
189 		return bh->b_data;
190 	return kmap_local_folio(bh->b_folio, bh_offset(bh));
191 }
192 
193 /**
194  * kunmap_local_bh - Unmap the data of a buffer.
195  * @bh: The buffer.
196  * @addr: The address returned by kmap_local_bh().
197  */
kunmap_local_bh(const struct buffer_head * bh,void * addr)198 static inline void kunmap_local_bh(const struct buffer_head *bh, void *addr)
199 {
200 	if (bh->b_folio)
201 		kunmap_local(addr);
202 }
203 
204 /* If we *know* page->private refers to buffer_heads */
205 #define page_buffers(page)					\
206 	({							\
207 		BUG_ON(!PagePrivate(page));			\
208 		((struct buffer_head *)page_private(page));	\
209 	})
210 #define folio_buffers(folio)		folio_get_private(folio)
211 
212 void buffer_check_dirty_writeback(struct folio *folio,
213 				     bool *dirty, bool *writeback);
214 
215 /*
216  * Declarations
217  */
218 
219 void mark_buffer_dirty(struct buffer_head *bh);
220 void mark_buffer_write_io_error(struct buffer_head *bh);
221 void touch_buffer(struct buffer_head *bh);
222 void folio_set_bh(struct buffer_head *bh, struct folio *folio,
223 		  unsigned long offset);
224 struct buffer_head *folio_alloc_buffers(struct folio *folio, unsigned long size,
225 					gfp_t gfp);
226 struct buffer_head *alloc_page_buffers(struct page *page, unsigned long size);
227 struct buffer_head *create_empty_buffers(struct folio *folio,
228 		unsigned long blocksize, unsigned long b_state);
229 void end_buffer_read_sync(struct buffer_head *bh, int uptodate);
230 bool bio_endio_bh(struct bio *bio, struct buffer_head **bhp);
231 
232 /* Completion routines suitable for passing to bh_submit() */
233 void bh_end_read(struct bio *bio);
234 void bh_end_write(struct bio *bio);
235 void bh_end_async_write(struct bio *bio);
236 
237 /* Things to do with metadata buffers list */
238 void mmb_mark_buffer_dirty(struct buffer_head *bh, struct mapping_metadata_bhs *mmb);
239 void clean_bdev_aliases(struct block_device *bdev, sector_t block,
240 			sector_t len);
clean_bdev_bh_alias(struct buffer_head * bh)241 static inline void clean_bdev_bh_alias(struct buffer_head *bh)
242 {
243 	clean_bdev_aliases(bh->b_bdev, bh->b_blocknr, 1);
244 }
245 
246 void __wait_on_buffer(struct buffer_head *);
247 wait_queue_head_t *bh_waitq_head(struct buffer_head *bh);
248 struct buffer_head *__find_get_block(struct block_device *bdev, sector_t block,
249 			unsigned size);
250 struct buffer_head *__find_get_block_nonatomic(struct block_device *bdev,
251 			sector_t block, unsigned size);
252 struct buffer_head *bdev_getblk(struct block_device *bdev, sector_t block,
253 		unsigned size, gfp_t gfp);
254 void __brelse(struct buffer_head *);
255 void __bforget(struct buffer_head *);
256 void __breadahead(struct block_device *, sector_t block, unsigned int size);
257 struct buffer_head *__bread_gfp(struct block_device *,
258 				sector_t block, unsigned size, gfp_t gfp);
259 struct buffer_head *alloc_buffer_head(gfp_t gfp_flags);
260 void free_buffer_head(struct buffer_head * bh);
261 void unlock_buffer(struct buffer_head *bh);
262 void __lock_buffer(struct buffer_head *bh);
263 int sync_dirty_buffer(struct buffer_head *bh);
264 int __sync_dirty_buffer(struct buffer_head *bh, blk_opf_t op_flags);
265 void write_dirty_buffer(struct buffer_head *bh, blk_opf_t op_flags);
266 void bh_submit(struct buffer_head *, blk_opf_t, bio_end_io_t);
267 void write_boundary_block(struct block_device *bdev,
268 			sector_t bblock, unsigned blocksize);
269 int bh_uptodate_or_lock(struct buffer_head *bh);
270 int __bh_read(struct buffer_head *bh, blk_opf_t op_flags, bool wait);
271 void __bh_read_batch(int nr, struct buffer_head *bhs[],
272 		     blk_opf_t op_flags, bool force_lock);
273 
274 /*
275  * Generic address_space_operations implementations for buffer_head-backed
276  * address_spaces.
277  */
278 void block_invalidate_folio(struct folio *folio, size_t offset, size_t length);
279 int block_write_full_folio(struct folio *folio, struct writeback_control *wbc,
280 		void *get_block);
281 int __block_write_full_folio(struct inode *inode, struct folio *folio,
282 		get_block_t *get_block, struct writeback_control *wbc);
283 int block_read_full_folio(struct folio *, get_block_t *);
284 bool block_is_partially_uptodate(struct folio *, size_t from, size_t count);
285 int block_write_begin(struct address_space *mapping, loff_t pos, unsigned len,
286 		struct folio **foliop, get_block_t *get_block);
287 int __block_write_begin(struct folio *folio, loff_t pos, unsigned len,
288 		get_block_t *get_block);
289 int block_write_end(loff_t pos, unsigned len, unsigned copied, struct folio *);
290 int generic_write_end(const struct kiocb *, struct address_space *,
291 				loff_t, unsigned len, unsigned copied,
292 				struct folio *, void *);
293 void folio_zero_new_buffers(struct folio *folio, size_t from, size_t to);
294 int cont_write_begin(const struct kiocb *, struct address_space *, loff_t,
295 			unsigned, struct folio **, void **,
296 			get_block_t *, loff_t *);
297 int generic_cont_expand_simple(struct inode *inode, loff_t size);
298 void block_commit_write(struct folio *folio, size_t from, size_t to);
299 int block_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf,
300 				get_block_t get_block);
301 sector_t generic_block_bmap(struct address_space *, sector_t, get_block_t *);
302 int block_truncate_page(struct address_space *, loff_t, get_block_t *);
303 
304 #ifdef CONFIG_MIGRATION
305 extern int buffer_migrate_folio(struct address_space *,
306 		struct folio *dst, struct folio *src, enum migrate_mode);
307 extern int buffer_migrate_folio_norefs(struct address_space *,
308 		struct folio *dst, struct folio *src, enum migrate_mode);
309 #else
310 #define buffer_migrate_folio NULL
311 #define buffer_migrate_folio_norefs NULL
312 #endif
313 
314 /*
315  * inline definitions
316  */
317 
get_bh(struct buffer_head * bh)318 static inline void get_bh(struct buffer_head *bh)
319 {
320         atomic_inc(&bh->b_count);
321 }
322 
put_bh(struct buffer_head * bh)323 static inline void put_bh(struct buffer_head *bh)
324 {
325         smp_mb__before_atomic();
326         atomic_dec(&bh->b_count);
327 }
328 
329 /**
330  * brelse - Release a buffer.
331  * @bh: The buffer to release.
332  *
333  * Decrement a buffer_head's reference count.  If @bh is NULL, this
334  * function is a no-op.
335  *
336  * If all buffers on a folio have zero reference count, are clean
337  * and unlocked, and if the folio is unlocked and not under writeback
338  * then try_to_free_buffers() may strip the buffers from the folio in
339  * preparation for freeing it (sometimes, rarely, buffers are removed
340  * from a folio but it ends up not being freed, and buffers may later
341  * be reattached).
342  *
343  * Context: Any context.
344  */
brelse(struct buffer_head * bh)345 static inline void brelse(struct buffer_head *bh)
346 {
347 	if (bh)
348 		__brelse(bh);
349 }
350 
351 /**
352  * bforget - Discard any dirty data in a buffer.
353  * @bh: The buffer to forget.
354  *
355  * Call this function instead of brelse() if the data written to a buffer
356  * no longer needs to be written back.  It will clear the buffer's dirty
357  * flag so writeback of this buffer will be skipped.
358  *
359  * Context: Any context.
360  */
bforget(struct buffer_head * bh)361 static inline void bforget(struct buffer_head *bh)
362 {
363 	if (bh)
364 		__bforget(bh);
365 }
366 
367 /**
368  * sb_bread - Read a block.
369  * @sb: The superblock to read from.
370  * @block: Block number in units of block size.
371  *
372  * Read a specified block, and return the buffer head that refers
373  * to it.  The memory is allocated from the movable area so that it can
374  * be migrated.  The returned buffer head has its refcount increased.
375  * The caller should call brelse() when it has finished with the buffer.
376  *
377  * Context: May sleep waiting for I/O.
378  * Return: NULL if the block was unreadable.
379  */
380 static inline
sb_bread(struct super_block * sb,sector_t block)381 struct buffer_head *sb_bread(struct super_block *sb, sector_t block)
382 {
383 	return __bread_gfp(sb->s_bdev, block, sb->s_blocksize, __GFP_MOVABLE);
384 }
385 
386 /**
387  * sb_bread_unmovable - Read a block.
388  * @sb: The superblock to read from.
389  * @block: Block number in units of block size.
390  *
391  * Read a specified block, and return the buffer head that refers to it.
392  * The memory is allocated from the unmovable area so that pointers into
393  * it remain valid after compaction runs.  The returned buffer head has
394  * its refcount increased.  The caller should call brelse() when it has
395  * finished with the buffer.
396  *
397  * Context: May sleep waiting for I/O.
398  * Return: NULL if the block was unreadable.
399  */
400 static inline
sb_bread_unmovable(struct super_block * sb,sector_t block)401 struct buffer_head *sb_bread_unmovable(struct super_block *sb, sector_t block)
402 {
403 	return __bread_gfp(sb->s_bdev, block, sb->s_blocksize, 0);
404 }
405 
406 /**
407  * sb_breadahead - Start readahead.
408  * @sb: Superblock identifying the block device.
409  * @block: The block to read.
410  *
411  * Read this block.  The I/O will be flagged as being readahead rather
412  * than immediate read, but (unlike the page cache), surrounding blocks
413  * will not be read.
414  *
415  * Context: May sleep in order to allocate memory.
416  */
417 static inline
sb_breadahead(struct super_block * sb,sector_t block)418 void sb_breadahead(struct super_block *sb, sector_t block)
419 {
420 	__breadahead(sb->s_bdev, block, sb->s_blocksize);
421 }
422 
getblk_unmovable(struct block_device * bdev,sector_t block,unsigned size)423 static inline struct buffer_head *getblk_unmovable(struct block_device *bdev,
424 		sector_t block, unsigned size)
425 {
426 	gfp_t gfp;
427 
428 	gfp = mapping_gfp_constraint(bdev->bd_mapping, ~__GFP_FS);
429 	gfp |= __GFP_NOFAIL;
430 
431 	return bdev_getblk(bdev, block, size, gfp);
432 }
433 
__getblk(struct block_device * bdev,sector_t block,unsigned size)434 static inline struct buffer_head *__getblk(struct block_device *bdev,
435 		sector_t block, unsigned size)
436 {
437 	gfp_t gfp;
438 
439 	gfp = mapping_gfp_constraint(bdev->bd_mapping, ~__GFP_FS);
440 	gfp |= __GFP_MOVABLE | __GFP_NOFAIL;
441 
442 	return bdev_getblk(bdev, block, size, gfp);
443 }
444 
sb_getblk(struct super_block * sb,sector_t block)445 static inline struct buffer_head *sb_getblk(struct super_block *sb,
446 		sector_t block)
447 {
448 	return __getblk(sb->s_bdev, block, sb->s_blocksize);
449 }
450 
sb_getblk_gfp(struct super_block * sb,sector_t block,gfp_t gfp)451 static inline struct buffer_head *sb_getblk_gfp(struct super_block *sb,
452 		sector_t block, gfp_t gfp)
453 {
454 	return bdev_getblk(sb->s_bdev, block, sb->s_blocksize, gfp);
455 }
456 
457 static inline struct buffer_head *
sb_find_get_block(struct super_block * sb,sector_t block)458 sb_find_get_block(struct super_block *sb, sector_t block)
459 {
460 	return __find_get_block(sb->s_bdev, block, sb->s_blocksize);
461 }
462 
463 static inline struct buffer_head *
sb_find_get_block_nonatomic(struct super_block * sb,sector_t block)464 sb_find_get_block_nonatomic(struct super_block *sb, sector_t block)
465 {
466 	return __find_get_block_nonatomic(sb->s_bdev, block, sb->s_blocksize);
467 }
468 
469 static inline void
map_bh(struct buffer_head * bh,struct super_block * sb,sector_t block)470 map_bh(struct buffer_head *bh, struct super_block *sb, sector_t block)
471 {
472 	set_buffer_mapped(bh);
473 	bh->b_bdev = sb->s_bdev;
474 	bh->b_blocknr = block;
475 	bh->b_size = sb->s_blocksize;
476 }
477 
wait_on_buffer(struct buffer_head * bh)478 static inline void wait_on_buffer(struct buffer_head *bh)
479 {
480 	might_sleep();
481 	if (buffer_locked(bh))
482 		__wait_on_buffer(bh);
483 }
484 
trylock_buffer(struct buffer_head * bh)485 static inline int trylock_buffer(struct buffer_head *bh)
486 {
487 	return likely(!test_and_set_bit_lock(BH_Lock, &bh->b_state));
488 }
489 
lock_buffer(struct buffer_head * bh)490 static inline void lock_buffer(struct buffer_head *bh)
491 {
492 	might_sleep();
493 	if (!trylock_buffer(bh))
494 		__lock_buffer(bh);
495 }
496 
bh_readahead(struct buffer_head * bh,blk_opf_t op_flags)497 static inline void bh_readahead(struct buffer_head *bh, blk_opf_t op_flags)
498 {
499 	if (!buffer_uptodate(bh) && trylock_buffer(bh)) {
500 		if (!buffer_uptodate(bh))
501 			__bh_read(bh, op_flags, false);
502 		else
503 			unlock_buffer(bh);
504 	}
505 }
506 
bh_read_nowait(struct buffer_head * bh,blk_opf_t op_flags)507 static inline void bh_read_nowait(struct buffer_head *bh, blk_opf_t op_flags)
508 {
509 	if (!bh_uptodate_or_lock(bh))
510 		__bh_read(bh, op_flags, false);
511 }
512 
513 /* Returns 1 if buffer uptodated, 0 on success, and -EIO on error. */
bh_read(struct buffer_head * bh,blk_opf_t op_flags)514 static inline int bh_read(struct buffer_head *bh, blk_opf_t op_flags)
515 {
516 	if (bh_uptodate_or_lock(bh))
517 		return 1;
518 	return __bh_read(bh, op_flags, true);
519 }
520 
bh_read_batch(int nr,struct buffer_head * bhs[])521 static inline void bh_read_batch(int nr, struct buffer_head *bhs[])
522 {
523 	__bh_read_batch(nr, bhs, 0, true);
524 }
525 
bh_readahead_batch(int nr,struct buffer_head * bhs[],blk_opf_t op_flags)526 static inline void bh_readahead_batch(int nr, struct buffer_head *bhs[],
527 				      blk_opf_t op_flags)
528 {
529 	__bh_read_batch(nr, bhs, op_flags, false);
530 }
531 
532 /**
533  * __bread() - Read a block.
534  * @bdev: The block device to read from.
535  * @block: Block number in units of block size.
536  * @size: The block size of this device in bytes.
537  *
538  * Read a specified block, and return the buffer head that refers
539  * to it.  The memory is allocated from the movable area so that it can
540  * be migrated.  The returned buffer head has its refcount increased.
541  * The caller should call brelse() when it has finished with the buffer.
542  *
543  * Context: May sleep waiting for I/O.
544  * Return: NULL if the block was unreadable.
545  */
__bread(struct block_device * bdev,sector_t block,unsigned size)546 static inline struct buffer_head *__bread(struct block_device *bdev,
547 		sector_t block, unsigned size)
548 {
549 	return __bread_gfp(bdev, block, size, __GFP_MOVABLE);
550 }
551 
552 /**
553  * get_nth_bh - Get a reference on the n'th buffer after this one.
554  * @bh: The buffer to start counting from.
555  * @count: How many buffers to skip.
556  *
557  * This is primarily useful for finding the nth buffer in a folio; in
558  * that case you pass the head buffer and the byte offset in the folio
559  * divided by the block size.  It can be used for other purposes, but
560  * it will wrap at the end of the folio rather than returning NULL or
561  * proceeding to the next folio for you.
562  *
563  * Return: The requested buffer with an elevated refcount.
564  */
565 static inline __must_check
get_nth_bh(struct buffer_head * bh,unsigned int count)566 struct buffer_head *get_nth_bh(struct buffer_head *bh, unsigned int count)
567 {
568 	while (count--)
569 		bh = bh->b_this_page;
570 	get_bh(bh);
571 	return bh;
572 }
573 
574 bool block_dirty_folio(struct address_space *mapping, struct folio *folio);
575 
576 #ifdef CONFIG_BUFFER_HEAD
577 
578 void buffer_init(void);
579 bool try_to_free_buffers(struct folio *folio);
580 void mmb_init(struct mapping_metadata_bhs *mmb, struct address_space *mapping);
581 bool mmb_has_buffers(struct mapping_metadata_bhs *mmb);
582 void mmb_invalidate(struct mapping_metadata_bhs *mmb);
583 int mmb_sync(struct mapping_metadata_bhs *mmb);
584 void invalidate_bh_lrus(void);
585 void invalidate_bh_lrus_cpu(void);
586 bool has_bh_in_lru(int cpu, void *dummy);
587 extern int buffer_heads_over_limit;
588 
589 #else /* CONFIG_BUFFER_HEAD */
590 
buffer_init(void)591 static inline void buffer_init(void) {}
try_to_free_buffers(struct folio * folio)592 static inline bool try_to_free_buffers(struct folio *folio) { return true; }
mmb_sync(struct mapping_metadata_bhs * mmb)593 static inline int mmb_sync(struct mapping_metadata_bhs *mmb) { return 0; }
invalidate_bh_lrus(void)594 static inline void invalidate_bh_lrus(void) {}
invalidate_bh_lrus_cpu(void)595 static inline void invalidate_bh_lrus_cpu(void) {}
has_bh_in_lru(int cpu,void * dummy)596 static inline bool has_bh_in_lru(int cpu, void *dummy) { return false; }
597 #define buffer_heads_over_limit 0
598 
599 #endif /* CONFIG_BUFFER_HEAD */
600 #endif /* _LINUX_BUFFER_HEAD_H */
601