All of lore.kernel.org
 help / color / mirror / Atom feed
From: Akshat Aranya <aranya@nec-labs.com>
To: linux-btrfs@vger.kernel.org
Subject: Possible bug in btrfs_file_aio_write()
Date: Wed, 02 Feb 2011 15:15:52 -0500	[thread overview]
Message-ID: <4D49BB78.2000906@nec-labs.com> (raw)

Hi,

I'm looking at the code for btrfs_file_aio_write().  Specifically, the 
following lines:


	first_index = pos >> PAGE_CACHE_SHIFT;
	last_index = (pos + iov_iter_count(&i)) >> PAGE_CACHE_SHIFT;

	/*
	 * there are lots of better ways to do this, but this code
	 * makes sure the first and last page in the file range are
	 * up to date and ready for cow
	 */
	if ((pos & (PAGE_CACHE_SIZE - 1))) {
		pinned[0] = grab_cache_page(inode->i_mapping, first_index);
		if (!PageUptodate(pinned[0])) {
			ret = btrfs_readpage(NULL, pinned[0]);
			BUG_ON(ret);
			wait_on_page_locked(pinned[0]);
		} else {
			unlock_page(pinned[0]);
		}
	}
	if ((pos + iov_iter_count(&i)) & (PAGE_CACHE_SIZE - 1)) {
		pinned[1] = grab_cache_page(inode->i_mapping, last_index);
		if (!PageUptodate(pinned[1])) {
			ret = btrfs_readpage(NULL, pinned[1]);
			BUG_ON(ret);
			wait_on_page_locked(pinned[1]);
		} else {
			unlock_page(pinned[1]);
		}
	}


Am I missing something, or is there an off-by-one error over here?  The 
last byte in the written region would be "pos + iov_iter_count(&i) - 1", 
not "pos + iov_iter_count(&i)".  I verified this by writing 4096 bytes 
at offset 0. first_index evaluates to 0 and last_index evaluates to 1.

-Akshat

                 reply	other threads:[~2011-02-02 20:15 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=4D49BB78.2000906@nec-labs.com \
    --to=aranya@nec-labs.com \
    --cc=linux-btrfs@vger.kernel.org \
    /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.