From: Lachlan McIlroy <lachlan@sgi.com>
To: Christoph Hellwig <hch@infradead.org>
Cc: xfs-dev <xfs-dev@sgi.com>, xfs-oss <xfs@oss.sgi.com>
Subject: Re: [PATCH] Fix up xfs_buf_associate_memory()
Date: Mon, 26 Nov 2007 11:25:45 +1100 [thread overview]
Message-ID: <474A1289.2080500@sgi.com> (raw)
In-Reply-To: <20071123134302.GA4256@infradead.org>
Christoph Hellwig wrote:
> On Fri, Nov 23, 2007 at 03:29:06PM +1100, Lachlan McIlroy wrote:
>> Fixed a few bugs in xfs_buf_associate_memory() including:
>>
>> - calculation of 'page_count' was incorrect as it did not
>> consider the offset of 'mem' into the first page. The
>> logic to bump 'page_count' didn't work if 'len' was <=
>> PAGE_CACHE_SIZE (ie offset = 3k, len = 2k).
>> - setting b_buffer_length to 'len' is incorrect if
>> 'offset' is > 0. Set it to the total length of the
>> buffer.
>> - I suspect that passing a non-aligned address into
>> mem_to_page() for the first page may have been causing
>> issues - don't know but just tidy up that code anyway.
>>
>> These fixes prevent an data corruption issue that can
>> occur during log replay.
>
> Last time I tried to clean up this gem everything went bezerk, so be
> aware :)
>
>
> --- fs/xfs/linux-2.6/xfs_buf.c_1.247 2007-11-23 12:03:16.000000000 +1100
> +++ fs/xfs/linux-2.6/xfs_buf.c 2007-11-23 12:02:32.000000000 +1100
> @@ -726,14 +726,14 @@ xfs_buf_associate_memory(
> int rval;
> int i = 0;
> size_t ptr;
> + size_t buflen;
> off_t offset;
> int page_count;
>
> + ptr = (size_t) mem & PAGE_CACHE_MASK;
> + offset = (off_t) mem - (off_t) ptr;
>
> Casting pointers to size_t or off_t makes little sense, these should be
> unsigned long. And using a variable name of ptr is quite odd :)
I just left those as they were before the change. I'll tidy them too.
>
> + while (i < bp->b_page_count) {
> + bp->b_pages[i++] = mem_to_page((void *)ptr);
> ptr += PAGE_CACHE_SIZE;
> }
>
> This could be much cleaner written as:
>
> for (i = 0; i < bp->b_page_count; i++) {
> bp->b_pages[i] = mem_to_page((void *)ptr);
> ptr += PAGE_CACHE_SIZE;
> }
>
Fine with me.
Thanks.
prev parent reply other threads:[~2007-11-26 0:26 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-11-23 4:29 [PATCH] Fix up xfs_buf_associate_memory() Lachlan McIlroy
2007-11-23 13:43 ` Christoph Hellwig
2007-11-26 0:25 ` Lachlan McIlroy [this message]
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=474A1289.2080500@sgi.com \
--to=lachlan@sgi.com \
--cc=hch@infradead.org \
--cc=xfs-dev@sgi.com \
--cc=xfs@oss.sgi.com \
/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.