aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--fs/buffer.c44
-rw-r--r--include/linux/buffer_head.h2
2 files changed, 46 insertions, 0 deletions
diff --git a/fs/buffer.c b/fs/buffer.c
index 7249e014819e..456c9ab7705b 100644
--- a/fs/buffer.c
+++ b/fs/buffer.c
@@ -3213,6 +3213,50 @@ static int buffer_cpu_notify(struct notifier_block *self,
3213 return NOTIFY_OK; 3213 return NOTIFY_OK;
3214} 3214}
3215 3215
3216/**
3217 * bh_uptodate_or_lock: Test whether the buffer is uptodate
3218 * @bh: struct buffer_head
3219 *
3220 * Return true if the buffer is up-to-date and false,
3221 * with the buffer locked, if not.
3222 */
3223int bh_uptodate_or_lock(struct buffer_head *bh)
3224{
3225 if (!buffer_uptodate(bh)) {
3226 lock_buffer(bh);
3227 if (!buffer_uptodate(bh))
3228 return 0;
3229 unlock_buffer(bh);
3230 }
3231 return 1;
3232}
3233EXPORT_SYMBOL(bh_uptodate_or_lock);
3234
3235/**
3236 * bh_submit_read: Submit a locked buffer for reading
3237 * @bh: struct buffer_head
3238 *
3239 * Returns zero on success and -EIO on error.
3240 */
3241int bh_submit_read(struct buffer_head *bh)
3242{
3243 BUG_ON(!buffer_locked(bh));
3244
3245 if (buffer_uptodate(bh)) {
3246 unlock_buffer(bh);
3247 return 0;
3248 }
3249
3250 get_bh(bh);
3251 bh->b_end_io = end_buffer_read_sync;
3252 submit_bh(READ, bh);
3253 wait_on_buffer(bh);
3254 if (buffer_uptodate(bh))
3255 return 0;
3256 return -EIO;
3257}
3258EXPORT_SYMBOL(bh_submit_read);
3259
3216void __init buffer_init(void) 3260void __init buffer_init(void)
3217{ 3261{
3218 int nrpages; 3262 int nrpages;
diff --git a/include/linux/buffer_head.h b/include/linux/buffer_head.h
index da0d83fbadc0..e98801f06dcc 100644
--- a/include/linux/buffer_head.h
+++ b/include/linux/buffer_head.h
@@ -192,6 +192,8 @@ int sync_dirty_buffer(struct buffer_head *bh);
192int submit_bh(int, struct buffer_head *); 192int submit_bh(int, struct buffer_head *);
193void write_boundary_block(struct block_device *bdev, 193void write_boundary_block(struct block_device *bdev,
194 sector_t bblock, unsigned blocksize); 194 sector_t bblock, unsigned blocksize);
195int bh_uptodate_or_lock(struct buffer_head *bh);
196int bh_submit_read(struct buffer_head *bh);
195 197
196extern int buffer_heads_over_limit; 198extern int buffer_heads_over_limit;
197 199