From: Andrew Morton <akpm@zip.com.au>
To: Pavel Machek <pavel@ucw.cz>
Cc: kernel list <linux-kernel@vger.kernel.org>
Subject: Re: Reading page from given block device
Date: Wed, 08 May 2002 14:21:41 -0700 [thread overview]
Message-ID: <3CD996E5.BFB5CF9E@zip.com.au> (raw)
In-Reply-To: <20020508204809.GA2300@elf.ucw.cz>
Pavel Machek wrote:
>
> Hi!
>
> For swsusp, I kind of need to read 4K from given block device.
>
> Here's my attempt:
>
> static int bdev_read_page(kdev_t dev, long pos, void *buf)
> {
> struct buffer_head *bh;
> struct block_device *bdev;
>
> if (pos%PAGE_SIZE) panic("Sorry, dave, I can't let you do
> that!\n");
It's possible I guess that someone has a pinned buffer against
the same page which has a different block size. See the "lock up"
comment over __getblk().
> bdev = bdget(kdev_t_to_nr(dev));
> if (!bdev) {
> printk("No block device for %s\n", __bdevname(dev));
> BUG();
> }
> printk("C");
> bh = __bread(bdev, pos/PAGE_SIZE, PAGE_SIZE);
> printk("D");
> bdput(bdev);
> if (!bh || (!bh->b_data)) {
> return -1;
> }
> memcpy(buf, bh->b_data, PAGE_SIZE);
You'll need to kmap bh->b_page before copying the data.
>
> It works *once*, second time it deadlocks in __bread(). I tried both
> bforget() and brelse(). Kernel is 2.5.13. What am I doing wrong/what's
> wrong?
brelse is safer.
Please try 2.5.14. 2.5.13 had a few leaky problems which
could perhaps result in a pinned buffer which will cause
try_to_free_buffers() to fail, which triggers the __getblk()
nastiness.
Generally, if you're reading from a swap partition then
it may be better to use brw_page(). bread() is backed
by bdev->bd_inode->i_mapping, and there may be coherency
problems if the target blocks are currently in swapper_space.
Although probably your bdget() here will create a new inode
with no pagecache, so it'll work OK.
It really depends on what you're trying to do. It may
be best to just cook up a local buffer_head and submit
the darn thing.
-
next prev parent reply other threads:[~2002-05-08 21:22 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-05-08 20:48 Reading page from given block device Pavel Machek
2002-05-08 21:21 ` Andrew Morton [this message]
2002-05-08 21:30 ` Andrew Morton
2002-05-08 22:56 ` Pavel Machek
[not found] ` <3CD9AE15.114D13E3@zip.com.au>
2002-05-08 23:15 ` Pavel Machek
2002-05-09 0:07 ` Andrew Morton
2002-05-09 4:42 ` Alexander Viro
2002-05-09 21:36 ` Pavel Machek
2002-05-09 21:45 ` Alexander Viro
2002-05-08 22:59 ` Pavel Machek
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3CD996E5.BFB5CF9E@zip.com.au \
--to=akpm@zip.com.au \
--cc=linux-kernel@vger.kernel.org \
--cc=pavel@ucw.cz \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.