Blame view

include/linux/buffer_head.h 14.5 KB
b24413180   Greg Kroah-Hartman   License cleanup: ...
1
  /* SPDX-License-Identifier: GPL-2.0 */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2
3
4
5
6
7
8
9
10
11
12
13
14
15
  /*
   * include/linux/buffer_head.h
   *
   * Everything to do with buffer_heads.
   */
  
  #ifndef _LINUX_BUFFER_HEAD_H
  #define _LINUX_BUFFER_HEAD_H
  
  #include <linux/types.h>
  #include <linux/fs.h>
  #include <linux/linkage.h>
  #include <linux/pagemap.h>
  #include <linux/wait.h>
60063497a   Arun Sharma   atomic: use <linu...
16
  #include <linux/atomic.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
17

9361401eb   David Howells   [PATCH] BLOCK: Ma...
18
  #ifdef CONFIG_BLOCK
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
19
20
21
22
23
24
25
26
27
28
29
30
31
  enum bh_state_bits {
  	BH_Uptodate,	/* Contains valid data */
  	BH_Dirty,	/* Is dirty */
  	BH_Lock,	/* Is locked */
  	BH_Req,		/* Has been submitted for I/O */
  
  	BH_Mapped,	/* Has a disk mapping */
  	BH_New,		/* Disk mapping was newly created by get_block */
  	BH_Async_Read,	/* Is under end_buffer_async_read I/O */
  	BH_Async_Write,	/* Is under end_buffer_async_write I/O */
  	BH_Delay,	/* Buffer is not yet allocated on disk */
  	BH_Boundary,	/* Block is followed by a discontiguity */
  	BH_Write_EIO,	/* I/O error on write */
33a266dda   David Chinner   [PATCH] Make BH_U...
32
  	BH_Unwritten,	/* Buffer is allocated on disk but not written */
08bafc034   Keith Mannthey   block: Supress Bu...
33
  	BH_Quiet,	/* Buffer Error Prinks to be quiet */
877f962c5   Theodore Ts'o   buffer: add BH_Pr...
34
35
  	BH_Meta,	/* Buffer contains metadata */
  	BH_Prio,	/* Buffer should be submitted with REQ_PRIO */
7b7a8665e   Christoph Hellwig   direct-io: Implem...
36
  	BH_Defer_Completion, /* Defer AIO completion to workqueue */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
37
38
39
40
41
  
  	BH_PrivateStart,/* not a state bit, but the first bit available
  			 * for private allocation by other entities
  			 */
  };
09cbfeaf1   Kirill A. Shutemov   mm, fs: get rid o...
42
  #define MAX_BUF_PER_PAGE (PAGE_SIZE / 512)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
43
44
45
46
47
48
49
  
  struct page;
  struct buffer_head;
  struct address_space;
  typedef void (bh_end_io_t)(struct buffer_head *bh, int uptodate);
  
  /*
205f87f6b   Badari Pulavarty   [PATCH] change bu...
50
51
52
53
54
55
56
   * Historically, a buffer_head was used to map a single block
   * within a page, and of course as the unit of I/O through the
   * filesystem and block layers.  Nowadays the basic I/O unit
   * is the bio, and buffer_heads are used for extracting block
   * mappings (via a get_block_t call), for tracking state within
   * a page (via a page_mapping) and for wrapping bio submission
   * for backward compatibility reasons (e.g. submit_bh).
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
57
58
   */
  struct buffer_head {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
59
60
61
  	unsigned long b_state;		/* buffer state bitmap (see above) */
  	struct buffer_head *b_this_page;/* circular list of page's buffers */
  	struct page *b_page;		/* the page this bh is mapped to */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
62

205f87f6b   Badari Pulavarty   [PATCH] change bu...
63
64
65
  	sector_t b_blocknr;		/* start block number */
  	size_t b_size;			/* size of mapping */
  	char *b_data;			/* pointer to data within the page */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
66
67
68
69
70
  
  	struct block_device *b_bdev;
  	bh_end_io_t *b_end_io;		/* I/O completion */
   	void *b_private;		/* reserved for b_end_io */
  	struct list_head b_assoc_buffers; /* associated with another mapping */
58ff407be   Jan Kara   [PATCH] Fix IO er...
71
72
  	struct address_space *b_assoc_map;	/* mapping this buffer is
  						   associated with */
205f87f6b   Badari Pulavarty   [PATCH] change bu...
73
  	atomic_t b_count;		/* users using this buffer_head */
f1e67e355   Thomas Gleixner   fs/buffer: Make B...
74
75
76
  	spinlock_t b_uptodate_lock;	/* Used by the first bh in a page, to
  					 * serialise IO completion of other
  					 * buffers in the page */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
77
78
79
80
81
  };
  
  /*
   * macro tricks to expand the set_buffer_foo(), clear_buffer_foo()
   * and buffer_foo() functions.
60f91826c   Kemi Wang   buffer: Avoid set...
82
83
   * To avoid reset buffer flags that are already set, because that causes
   * a costly cache line transition, check the flag first.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
84
85
   */
  #define BUFFER_FNS(bit, name)						\
ee91ef617   Denys Vlasenko   bufferhead: force...
86
  static __always_inline void set_buffer_##name(struct buffer_head *bh)	\
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
87
  {									\
60f91826c   Kemi Wang   buffer: Avoid set...
88
89
  	if (!test_bit(BH_##bit, &(bh)->b_state))			\
  		set_bit(BH_##bit, &(bh)->b_state);			\
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
90
  }									\
ee91ef617   Denys Vlasenko   bufferhead: force...
91
  static __always_inline void clear_buffer_##name(struct buffer_head *bh)	\
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
92
93
94
  {									\
  	clear_bit(BH_##bit, &(bh)->b_state);				\
  }									\
ee91ef617   Denys Vlasenko   bufferhead: force...
95
  static __always_inline int buffer_##name(const struct buffer_head *bh)	\
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
96
97
98
99
100
101
102
103
  {									\
  	return test_bit(BH_##bit, &(bh)->b_state);			\
  }
  
  /*
   * test_set_buffer_foo() and test_clear_buffer_foo()
   */
  #define TAS_BUFFER_FNS(bit, name)					\
ee91ef617   Denys Vlasenko   bufferhead: force...
104
  static __always_inline int test_set_buffer_##name(struct buffer_head *bh) \
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
105
106
107
  {									\
  	return test_and_set_bit(BH_##bit, &(bh)->b_state);		\
  }									\
ee91ef617   Denys Vlasenko   bufferhead: force...
108
  static __always_inline int test_clear_buffer_##name(struct buffer_head *bh) \
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
109
110
111
112
113
114
115
116
117
  {									\
  	return test_and_clear_bit(BH_##bit, &(bh)->b_state);		\
  }									\
  
  /*
   * Emit the buffer bitops functions.   Note that there are also functions
   * of the form "mark_buffer_foo()".  These are higher-level functions which
   * do something in addition to setting a b_state bit.
   */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
118
119
120
  BUFFER_FNS(Dirty, dirty)
  TAS_BUFFER_FNS(Dirty, dirty)
  BUFFER_FNS(Lock, locked)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
121
122
123
124
125
126
127
128
129
  BUFFER_FNS(Req, req)
  TAS_BUFFER_FNS(Req, req)
  BUFFER_FNS(Mapped, mapped)
  BUFFER_FNS(New, new)
  BUFFER_FNS(Async_Read, async_read)
  BUFFER_FNS(Async_Write, async_write)
  BUFFER_FNS(Delay, delay)
  BUFFER_FNS(Boundary, boundary)
  BUFFER_FNS(Write_EIO, write_io_error)
33a266dda   David Chinner   [PATCH] Make BH_U...
130
  BUFFER_FNS(Unwritten, unwritten)
877f962c5   Theodore Ts'o   buffer: add BH_Pr...
131
132
  BUFFER_FNS(Meta, meta)
  BUFFER_FNS(Prio, prio)
7b7a8665e   Christoph Hellwig   direct-io: Implem...
133
  BUFFER_FNS(Defer_Completion, defer_completion)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
134

b437275e8   Mikulas Patocka   add barriers to b...
135
136
137
  static __always_inline void set_buffer_uptodate(struct buffer_head *bh)
  {
  	/*
7c6333411   Linus Torvalds   fs: only do a mem...
138
139
140
141
142
143
144
145
146
147
148
  	 * If somebody else already set this uptodate, they will
  	 * have done the memory barrier, and a reader will thus
  	 * see *some* valid buffer state.
  	 *
  	 * Any other serialization (with IO errors or whatever that
  	 * might clear the bit) has to come from other state (eg BH_Lock).
  	 */
  	if (test_bit(BH_Uptodate, &bh->b_state))
  		return;
  
  	/*
b437275e8   Mikulas Patocka   add barriers to b...
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
  	 * make it consistent with folio_mark_uptodate
  	 * pairs with smp_load_acquire in buffer_uptodate
  	 */
  	smp_mb__before_atomic();
  	set_bit(BH_Uptodate, &bh->b_state);
  }
  
  static __always_inline void clear_buffer_uptodate(struct buffer_head *bh)
  {
  	clear_bit(BH_Uptodate, &bh->b_state);
  }
  
  static __always_inline int buffer_uptodate(const struct buffer_head *bh)
  {
  	/*
  	 * make it consistent with folio_test_uptodate
  	 * pairs with smp_mb__before_atomic in set_buffer_uptodate
  	 */
  	return (smp_load_acquire(&bh->b_state) & (1UL << BH_Uptodate)) != 0;
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
169
  #define bh_offset(bh)		((unsigned long)(bh)->b_data & ~PAGE_MASK)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
170
171
172
173
  
  /* If we *know* page->private refers to buffer_heads */
  #define page_buffers(page)					\
  	({							\
4c21e2f24   Hugh Dickins   [PATCH] mm: split...
174
175
  		BUG_ON(!PagePrivate(page));			\
  		((struct buffer_head *)page_private(page));	\
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
176
177
  	})
  #define page_has_buffers(page)	PagePrivate(page)
b45972265   Mel Gorman   mm: vmscan: take ...
178
179
  void buffer_check_dirty_writeback(struct page *page,
  				     bool *dirty, bool *writeback);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
180
181
182
  /*
   * Declarations
   */
b3c975286   Harvey Harrison   include/linux: Re...
183
  void mark_buffer_dirty(struct buffer_head *bh);
87354e5de   Jeff Layton   buffer: set error...
184
  void mark_buffer_write_io_error(struct buffer_head *bh);
f0059afd3   Tejun Heo   buffer: make touc...
185
  void touch_buffer(struct buffer_head *bh);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
186
187
188
189
  void set_bh_page(struct buffer_head *bh,
  		struct page *page, unsigned long offset);
  int try_to_free_buffers(struct page *);
  struct buffer_head *alloc_page_buffers(struct page *page, unsigned long size,
640ab98fb   Jens Axboe   buffer: have allo...
190
  		bool retry);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
191
192
193
194
  void create_empty_buffers(struct page *, unsigned long,
  			unsigned long b_state);
  void end_buffer_read_sync(struct buffer_head *bh, int uptodate);
  void end_buffer_write_sync(struct buffer_head *bh, int uptodate);
35c80d5f4   Chris Mason   Add block_write_f...
195
  void end_buffer_async_write(struct buffer_head *bh, int uptodate);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
196
197
198
199
200
201
202
  
  /* Things to do with buffers at mapping->private_list */
  void mark_buffer_dirty_inode(struct buffer_head *bh, struct inode *inode);
  int inode_has_buffers(struct inode *);
  void invalidate_inode_buffers(struct inode *);
  int remove_inode_buffers(struct inode *inode);
  int sync_mapping_buffers(struct address_space *mapping);
29f3ad7d8   Jan Kara   fs: Provide funct...
203
204
  void clean_bdev_aliases(struct block_device *bdev, sector_t block,
  			sector_t len);
e64855c6c   Jan Kara   fs: Add helper to...
205
206
207
208
  static inline void clean_bdev_bh_alias(struct buffer_head *bh)
  {
  	clean_bdev_aliases(bh->b_bdev, bh->b_blocknr, 1);
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
209
210
  
  void mark_buffer_async_write(struct buffer_head *bh);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
211
212
  void __wait_on_buffer(struct buffer_head *);
  wait_queue_head_t *bh_waitq_head(struct buffer_head *bh);
3991d3bd1   Tomasz Kvarsin   [PATCH] warning f...
213
214
  struct buffer_head *__find_get_block(struct block_device *bdev, sector_t block,
  			unsigned size);
3b5e6454a   Gioh Kim   fs/buffer.c: supp...
215
216
  struct buffer_head *__getblk_gfp(struct block_device *bdev, sector_t block,
  				  unsigned size, gfp_t gfp);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
217
218
  void __brelse(struct buffer_head *);
  void __bforget(struct buffer_head *);
3991d3bd1   Tomasz Kvarsin   [PATCH] warning f...
219
  void __breadahead(struct block_device *, sector_t block, unsigned int size);
d87f63925   Roman Gushchin   ext4: use non-mov...
220
221
  void __breadahead_gfp(struct block_device *, sector_t block, unsigned int size,
  		  gfp_t gfp);
3b5e6454a   Gioh Kim   fs/buffer.c: supp...
222
223
  struct buffer_head *__bread_gfp(struct block_device *,
  				sector_t block, unsigned size, gfp_t gfp);
f9a14399a   Peter Zijlstra   mm: optimize kill...
224
  void invalidate_bh_lrus(void);
243418e39   Minchan Kim   mm: fs: invalidat...
225
  void invalidate_bh_lrus_cpu(void);
8cc621d2f   Minchan Kim   mm: fs: invalidat...
226
  bool has_bh_in_lru(int cpu, void *dummy);
dd0fc66fb   Al Viro   [PATCH] gfp flags...
227
  struct buffer_head *alloc_buffer_head(gfp_t gfp_flags);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
228
  void free_buffer_head(struct buffer_head * bh);
b3c975286   Harvey Harrison   include/linux: Re...
229
230
  void unlock_buffer(struct buffer_head *bh);
  void __lock_buffer(struct buffer_head *bh);
dfec8a14f   Mike Christie   fs: have ll_rw_bl...
231
  void ll_rw_block(int, int, int, struct buffer_head * bh[]);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
232
  int sync_dirty_buffer(struct buffer_head *bh);
2a222ca99   Mike Christie   fs: have submit_b...
233
234
  int __sync_dirty_buffer(struct buffer_head *bh, int op_flags);
  void write_dirty_buffer(struct buffer_head *bh, int op_flags);
2a222ca99   Mike Christie   fs: have submit_b...
235
  int submit_bh(int, int, struct buffer_head *);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
236
237
  void write_boundary_block(struct block_device *bdev,
  			sector_t bblock, unsigned blocksize);
389d1b083   Aneesh Kumar K.V   Add buffer head r...
238
239
  int bh_uptodate_or_lock(struct buffer_head *bh);
  int bh_submit_read(struct buffer_head *bh);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
240
241
242
243
244
245
246
  
  extern int buffer_heads_over_limit;
  
  /*
   * Generic address_space_operations implementations for buffer_head-backed
   * address_spaces.
   */
d47992f86   Lukas Czerner   mm: change invali...
247
248
  void block_invalidatepage(struct page *page, unsigned int offset,
  			  unsigned int length);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
249
250
  int block_write_full_page(struct page *page, get_block_t *get_block,
  				struct writeback_control *wbc);
b4bba3890   Benjamin Marzinski   fs: export __bloc...
251
252
253
  int __block_write_full_page(struct inode *inode, struct page *page,
  			get_block_t *get_block, struct writeback_control *wbc,
  			bh_end_io_t *handler);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
254
  int block_read_full_page(struct page*, get_block_t*);
c186afb4d   Al Viro   switch ->is_parti...
255
256
  int block_is_partially_uptodate(struct page *page, unsigned long from,
  				unsigned long count);
155130a4f   Christoph Hellwig   get rid of block_...
257
258
  int block_write_begin(struct address_space *mapping, loff_t pos, unsigned len,
  		unsigned flags, struct page **pagep, get_block_t *get_block);
6e1db88d5   Christoph Hellwig   introduce __block...
259
260
  int __block_write_begin(struct page *page, loff_t pos, unsigned len,
  		get_block_t *get_block);
afddba49d   Nick Piggin   fs: introduce wri...
261
262
263
264
265
266
267
  int block_write_end(struct file *, struct address_space *,
  				loff_t, unsigned, unsigned,
  				struct page *, void *);
  int generic_write_end(struct file *, struct address_space *,
  				loff_t, unsigned, unsigned,
  				struct page *, void *);
  void page_zero_new_buffers(struct page *page, unsigned from, unsigned to);
f892760aa   Matthew Wilcox   fs/mpage.c: fix m...
268
  void clean_page_buffers(struct page *page);
89e107877   Nick Piggin   fs: new cont helpers
269
270
271
  int cont_write_begin(struct file *, struct address_space *, loff_t,
  			unsigned, unsigned, struct page **, void **,
  			get_block_t *, loff_t *);
05eb0b51f   OGAWA Hirofumi   [PATCH] fat: supp...
272
  int generic_cont_expand_simple(struct inode *inode, loff_t size);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
273
  int block_commit_write(struct page *page, unsigned from, unsigned to);
c2ec175c3   Nick Piggin   mm: page_mkwrite ...
274
  int block_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf,
541716902   David Chinner   [FS] Implement bl...
275
  				get_block_t get_block);
24da4fab5   Jan Kara   vfs: Create __blo...
276
  /* Convert errno to return value from ->page_mkwrite() call */
401b25aa1   Souptick Joarder   ext4: convert fau...
277
  static inline vm_fault_t block_page_mkwrite_return(int err)
24da4fab5   Jan Kara   vfs: Create __blo...
278
279
280
  {
  	if (err == 0)
  		return VM_FAULT_LOCKED;
0911d0041   Jan Kara   mm: avoid returni...
281
  	if (err == -EFAULT || err == -EAGAIN)
24da4fab5   Jan Kara   vfs: Create __blo...
282
283
284
285
286
287
  		return VM_FAULT_NOPAGE;
  	if (err == -ENOMEM)
  		return VM_FAULT_OOM;
  	/* -ENOSPC, -EDQUOT, -EIO ... */
  	return VM_FAULT_SIGBUS;
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
288
  sector_t generic_block_bmap(struct address_space *, sector_t, get_block_t *);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
289
  int block_truncate_page(struct address_space *, loff_t, get_block_t *);
ea0f04e59   Christoph Hellwig   get rid of nobh_w...
290
  int nobh_write_begin(struct address_space *, loff_t, unsigned, unsigned,
03158cd7e   Nick Piggin   fs: restore nobh
291
292
293
294
295
  				struct page **, void **, get_block_t*);
  int nobh_write_end(struct file *, struct address_space *,
  				loff_t, unsigned, unsigned,
  				struct page *, void *);
  int nobh_truncate_page(struct address_space *, loff_t, get_block_t *);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
296
297
  int nobh_writepage(struct page *page, get_block_t *get_block,
                          struct writeback_control *wbc);
b6cd0b772   Adrian Bunk   [PATCH] fs/buffer...
298
  void buffer_init(void);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
299
300
301
302
  
  /*
   * inline definitions
   */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
303
304
305
306
307
308
309
  static inline void get_bh(struct buffer_head *bh)
  {
          atomic_inc(&bh->b_count);
  }
  
  static inline void put_bh(struct buffer_head *bh)
  {
4e857c58e   Peter Zijlstra   arch: Mass conver...
310
          smp_mb__before_atomic();
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
          atomic_dec(&bh->b_count);
  }
  
  static inline void brelse(struct buffer_head *bh)
  {
  	if (bh)
  		__brelse(bh);
  }
  
  static inline void bforget(struct buffer_head *bh)
  {
  	if (bh)
  		__bforget(bh);
  }
  
  static inline struct buffer_head *
  sb_bread(struct super_block *sb, sector_t block)
  {
3b5e6454a   Gioh Kim   fs/buffer.c: supp...
329
330
331
332
333
334
335
  	return __bread_gfp(sb->s_bdev, block, sb->s_blocksize, __GFP_MOVABLE);
  }
  
  static inline struct buffer_head *
  sb_bread_unmovable(struct super_block *sb, sector_t block)
  {
  	return __bread_gfp(sb->s_bdev, block, sb->s_blocksize, 0);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
336
337
338
339
340
341
342
  }
  
  static inline void
  sb_breadahead(struct super_block *sb, sector_t block)
  {
  	__breadahead(sb->s_bdev, block, sb->s_blocksize);
  }
d87f63925   Roman Gushchin   ext4: use non-mov...
343
344
345
346
347
  static inline void
  sb_breadahead_unmovable(struct super_block *sb, sector_t block)
  {
  	__breadahead_gfp(sb->s_bdev, block, sb->s_blocksize, 0);
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
348
349
350
  static inline struct buffer_head *
  sb_getblk(struct super_block *sb, sector_t block)
  {
3b5e6454a   Gioh Kim   fs/buffer.c: supp...
351
  	return __getblk_gfp(sb->s_bdev, block, sb->s_blocksize, __GFP_MOVABLE);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
352
  }
bd7ade3cd   Nikolay Borisov   bufferhead: Add _...
353
354
355
356
357
358
  
  static inline struct buffer_head *
  sb_getblk_gfp(struct super_block *sb, sector_t block, gfp_t gfp)
  {
  	return __getblk_gfp(sb->s_bdev, block, sb->s_blocksize, gfp);
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
359
360
361
362
363
364
365
366
367
368
369
370
  static inline struct buffer_head *
  sb_find_get_block(struct super_block *sb, sector_t block)
  {
  	return __find_get_block(sb->s_bdev, block, sb->s_blocksize);
  }
  
  static inline void
  map_bh(struct buffer_head *bh, struct super_block *sb, sector_t block)
  {
  	set_buffer_mapped(bh);
  	bh->b_bdev = sb->s_bdev;
  	bh->b_blocknr = block;
b0cf2321c   Badari Pulavarty   [PATCH] pass b_si...
371
  	bh->b_size = sb->s_blocksize;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
372
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
373
374
375
  static inline void wait_on_buffer(struct buffer_head *bh)
  {
  	might_sleep();
a9877cc29   Richard Kennedy   buffer_head: remo...
376
  	if (buffer_locked(bh))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
377
378
  		__wait_on_buffer(bh);
  }
ca5de404f   Nick Piggin   fs: rename buffer...
379
380
  static inline int trylock_buffer(struct buffer_head *bh)
  {
51b07fc3c   Nick Piggin   fs: buffer lock u...
381
  	return likely(!test_and_set_bit_lock(BH_Lock, &bh->b_state));
ca5de404f   Nick Piggin   fs: rename buffer...
382
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
383
384
385
  static inline void lock_buffer(struct buffer_head *bh)
  {
  	might_sleep();
ca5de404f   Nick Piggin   fs: rename buffer...
386
  	if (!trylock_buffer(bh))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
387
388
  		__lock_buffer(bh);
  }
3b5e6454a   Gioh Kim   fs/buffer.c: supp...
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
  static inline struct buffer_head *getblk_unmovable(struct block_device *bdev,
  						   sector_t block,
  						   unsigned size)
  {
  	return __getblk_gfp(bdev, block, size, 0);
  }
  
  static inline struct buffer_head *__getblk(struct block_device *bdev,
  					   sector_t block,
  					   unsigned size)
  {
  	return __getblk_gfp(bdev, block, size, __GFP_MOVABLE);
  }
  
  /**
   *  __bread() - reads a specified block and returns the bh
   *  @bdev: the block_device to read from
   *  @block: number of block
   *  @size: size (in bytes) to read
   *
   *  Reads a specified block, and returns buffer head that contains it.
   *  The page cache is allocated from movable area so that it can be migrated.
   *  It returns NULL if the block was unreadable.
   */
  static inline struct buffer_head *
  __bread(struct block_device *bdev, sector_t block, unsigned size)
  {
  	return __bread_gfp(bdev, block, size, __GFP_MOVABLE);
  }
cf9a2ae8d   David Howells   [PATCH] BLOCK: Mo...
418
  extern int __set_page_dirty_buffers(struct page *page);
9361401eb   David Howells   [PATCH] BLOCK: Ma...
419
420
421
422
423
  
  #else /* CONFIG_BLOCK */
  
  static inline void buffer_init(void) {}
  static inline int try_to_free_buffers(struct page *page) { return 1; }
9361401eb   David Howells   [PATCH] BLOCK: Ma...
424
425
426
427
  static inline int inode_has_buffers(struct inode *inode) { return 0; }
  static inline void invalidate_inode_buffers(struct inode *inode) {}
  static inline int remove_inode_buffers(struct inode *inode) { return 1; }
  static inline int sync_mapping_buffers(struct address_space *mapping) { return 0; }
243418e39   Minchan Kim   mm: fs: invalidat...
428
  static inline void invalidate_bh_lrus_cpu(void) {}
6de522d16   Jing Yangyang   include/linux/buf...
429
  static inline bool has_bh_in_lru(int cpu, void *dummy) { return false; }
d2de7ea48   Christoph Hellwig   fs: move the buff...
430
  #define buffer_heads_over_limit 0
9361401eb   David Howells   [PATCH] BLOCK: Ma...
431
432
  
  #endif /* CONFIG_BLOCK */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
433
  #endif /* _LINUX_BUFFER_HEAD_H */