All of lore.kernel.org
 help / color / mirror / Atom feed
From: Joel Becker <Joel.Becker@oracle.com>
To: Eric Sandeen <sandeen@redhat.com>
Cc: Andreas Dilger <adilger@dilger.ca>, "Ted Ts'o" <tytso@mit.edu>,
	linux-fsdevel@vger.kernel.org, Jan Kara <jack@suse.cz>,
	linux-ext4@vger.kernel.org, ocfs2-devel@oss.oracle.com
Subject: Re: [PATCH 1/3] ext3/ext4: Factor out disk addressability check
Date: Mon, 16 Aug 2010 12:13:19 -0700	[thread overview]
Message-ID: <20100816191319.GC5786@mail.oracle.com> (raw)
In-Reply-To: <4C694ED3.5070500@redhat.com>

On Mon, Aug 16, 2010 at 09:44:35AM -0500, Eric Sandeen wrote:
> Joel Becker wrote:
> > How about:
> > 
> > 	u64 last_fs_page = last_fs_block >> (PAGE_CACHE_SHIFT - blocksize_bits);
> > 
> > 	... ||
> > 	(last_fs_page > (pgoff_t)(~0ULL))) {
> > 
> > Is that more readable?
> 
> To me, yes.  Maybe do similar for last_fs_sector.

	last_fs_sector would be shifting up, which could wrap a really
large last_fs_blocks.  So I'm going to keep the sector_t check as-is.
How's this:

>From 8de5cb9164cdc179ba84a07b282a895d0eb794b0 Mon Sep 17 00:00:00 2001
>From: Joel Becker <joel.becker@oracle.com>
Date: Mon, 16 Aug 2010 12:10:17 -0700
Subject: [PATCH] libfs: Fix shift bug in generic_check_addressable()

generic_check_addressable() erroneously shifts pages down by a block
factor when it should be shifting up.  To prevent overflow, we shift
blocks down to pages.

Signed-off-by: Joel Becker <joel.becker@oracle.com>
---
 fs/libfs.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/fs/libfs.c b/fs/libfs.c
index 8debe7b..62baa03 100644
--- a/fs/libfs.c
+++ b/fs/libfs.c
@@ -925,6 +925,8 @@ EXPORT_SYMBOL(generic_file_fsync);
 int generic_check_addressable(unsigned blocksize_bits, u64 num_blocks)
 {
 	u64 last_fs_block = num_blocks - 1;
+	u64 last_fs_page =
+		last_fs_block >> (PAGE_CACHE_SHIFT - blocksize_bits);
 
 	if (unlikely(num_blocks == 0))
 		return 0;
@@ -932,10 +934,8 @@ int generic_check_addressable(unsigned blocksize_bits, u64 num_blocks)
 	if ((blocksize_bits < 9) || (blocksize_bits > PAGE_CACHE_SHIFT))
 		return -EINVAL;
 
-	if ((last_fs_block >
-	     (sector_t)(~0ULL) >> (blocksize_bits - 9)) ||
-	    (last_fs_block >
-	     (pgoff_t)(~0ULL) >> (PAGE_CACHE_SHIFT - blocksize_bits))) {
+	if ((last_fs_block > (sector_t)(~0ULL) >> (blocksize_bits - 9)) ||
+	    (last_fs_page > (pgoff_t)(~0ULL))) {
 		return -EFBIG;
 	}
 	return 0;
-- 
1.7.1

-- 

Life's Little Instruction Book #267

	"Lie on your back and look at the stars."

Joel Becker
Consulting Software Developer
Oracle
E-mail: joel.becker@oracle.com
Phone: (650) 506-8127

WARNING: multiple messages have this Message-ID (diff)
From: Joel Becker <Joel.Becker@oracle.com>
To: Eric Sandeen <sandeen@redhat.com>
Cc: Andreas Dilger <adilger@dilger.ca>, Ted Ts'o <tytso@mit.edu>,
	linux-fsdevel@vger.kernel.org, Jan Kara <jack@suse.cz>,
	linux-ext4@vger.kernel.org, ocfs2-devel@oss.oracle.com
Subject: [Ocfs2-devel] [PATCH 1/3] ext3/ext4: Factor out disk addressability check
Date: Mon, 16 Aug 2010 12:13:19 -0700	[thread overview]
Message-ID: <20100816191319.GC5786@mail.oracle.com> (raw)
In-Reply-To: <4C694ED3.5070500@redhat.com>

On Mon, Aug 16, 2010 at 09:44:35AM -0500, Eric Sandeen wrote:
> Joel Becker wrote:
> > How about:
> > 
> > 	u64 last_fs_page = last_fs_block >> (PAGE_CACHE_SHIFT - blocksize_bits);
> > 
> > 	... ||
> > 	(last_fs_page > (pgoff_t)(~0ULL))) {
> > 
> > Is that more readable?
> 
> To me, yes.  Maybe do similar for last_fs_sector.

	last_fs_sector would be shifting up, which could wrap a really
large last_fs_blocks.  So I'm going to keep the sector_t check as-is.
How's this:

From 8de5cb9164cdc179ba84a07b282a895d0eb794b0 Mon Sep 17 00:00:00 2001
>From: Joel Becker <joel.becker@oracle.com>
Date: Mon, 16 Aug 2010 12:10:17 -0700
Subject: [PATCH] libfs: Fix shift bug in generic_check_addressable()

generic_check_addressable() erroneously shifts pages down by a block
factor when it should be shifting up.  To prevent overflow, we shift
blocks down to pages.

Signed-off-by: Joel Becker <joel.becker@oracle.com>
---
 fs/libfs.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/fs/libfs.c b/fs/libfs.c
index 8debe7b..62baa03 100644
--- a/fs/libfs.c
+++ b/fs/libfs.c
@@ -925,6 +925,8 @@ EXPORT_SYMBOL(generic_file_fsync);
 int generic_check_addressable(unsigned blocksize_bits, u64 num_blocks)
 {
 	u64 last_fs_block = num_blocks - 1;
+	u64 last_fs_page =
+		last_fs_block >> (PAGE_CACHE_SHIFT - blocksize_bits);
 
 	if (unlikely(num_blocks == 0))
 		return 0;
@@ -932,10 +934,8 @@ int generic_check_addressable(unsigned blocksize_bits, u64 num_blocks)
 	if ((blocksize_bits < 9) || (blocksize_bits > PAGE_CACHE_SHIFT))
 		return -EINVAL;
 
-	if ((last_fs_block >
-	     (sector_t)(~0ULL) >> (blocksize_bits - 9)) ||
-	    (last_fs_block >
-	     (pgoff_t)(~0ULL) >> (PAGE_CACHE_SHIFT - blocksize_bits))) {
+	if ((last_fs_block > (sector_t)(~0ULL) >> (blocksize_bits - 9)) ||
+	    (last_fs_page > (pgoff_t)(~0ULL))) {
 		return -EFBIG;
 	}
 	return 0;
-- 
1.7.1

-- 

Life's Little Instruction Book #267

	"Lie on your back and look at the stars."

Joel Becker
Consulting Software Developer
Oracle
E-mail: joel.becker at oracle.com
Phone: (650) 506-8127

  reply	other threads:[~2010-08-16 19:13 UTC|newest]

Thread overview: 63+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-07-22 22:03 [PATCH 1/3] ext3/ext4: Factor out disk addressability check Patrick J. LoPresti
2010-07-22 22:03 ` [Ocfs2-devel] " Patrick J. LoPresti
2010-07-22 22:04 ` [PATCH 2/3] JBD2: Allow feature checks before journal recovery Patrick J. LoPresti
2010-07-22 22:04   ` [Ocfs2-devel] " Patrick J. LoPresti
2010-07-22 22:05   ` [PATCH 3/3] OCFS2: Allow huge (> 16 TiB) volumes to mount Patrick J. LoPresti
2010-07-22 22:05     ` [Ocfs2-devel] " Patrick J. LoPresti
2010-08-12 17:43   ` [Ocfs2-devel] [PATCH 2/3] JBD2: Allow feature checks before journal recovery Joel Becker
2010-08-12 17:43     ` Joel Becker
2010-08-12 23:03     ` Joel Becker
2010-08-12 23:03       ` Joel Becker
2010-08-12 23:03       ` [Ocfs2-devel] " Joel Becker
2010-08-12 23:03     ` Joel Becker
2010-08-12 23:03     ` Joel Becker
2010-08-13  3:39     ` Ted Ts'o
2010-08-13  3:39       ` Ted Ts'o
2010-08-13  7:17       ` Joel Becker
2010-08-13  7:17         ` Joel Becker
2010-08-13  7:17         ` Joel Becker
2010-08-10 15:15 ` [Ocfs2-devel] [PATCH 1/3] ext3/ext4: Factor out disk addressability check Joel Becker
2010-08-10 15:15   ` Joel Becker
2010-08-12 17:42 ` Joel Becker
2010-08-12 17:42   ` Joel Becker
2010-08-12 18:45   ` Andreas Dilger
2010-08-12 18:45     ` Andreas Dilger
2010-08-12 20:15     ` Joel Becker
2010-08-12 20:15       ` Joel Becker
2010-08-12 21:32       ` Andreas Dilger
2010-08-12 21:32         ` Andreas Dilger
2010-08-12 22:29         ` Joel Becker
2010-08-12 22:29           ` Joel Becker
2010-08-12 23:07           ` Andreas Dilger
2010-08-12 23:07             ` Andreas Dilger
2010-08-12 23:13             ` Joel Becker
2010-08-12 23:13               ` Joel Becker
2010-08-13 16:30           ` Jan Kara
2010-08-13 16:30             ` Jan Kara
2010-08-13 20:47             ` Joel Becker
2010-08-13 20:47               ` Joel Becker
2010-08-13 22:52               ` Joel Becker
2010-08-13 22:52                 ` Joel Becker
2010-08-16 15:09                 ` Jan Kara
2010-08-16 15:09                   ` Jan Kara
2010-08-15 17:19             ` Eric Sandeen
2010-08-15 17:19               ` Eric Sandeen
2010-08-16  2:54               ` Joel Becker
2010-08-16  2:54                 ` [Ocfs2-devel] " Joel Becker
2010-08-16  3:36                 ` Eric Sandeen
2010-08-16  3:36                   ` Eric Sandeen
2010-08-16  9:21                   ` Joel Becker
2010-08-16  9:21                     ` [Ocfs2-devel] " Joel Becker
2010-08-16 14:44                     ` Eric Sandeen
2010-08-16 14:44                     ` Eric Sandeen
2010-08-16 14:44                       ` Eric Sandeen
2010-08-16 19:13                       ` Joel Becker [this message]
2010-08-16 19:13                         ` Joel Becker
2010-08-16 19:21                         ` Jan Kara
2010-08-16 19:21                           ` Jan Kara
2010-08-16 20:45                           ` Joel Becker
2010-08-16 20:45                             ` [Ocfs2-devel] " Joel Becker
2010-08-12 23:03   ` Joel Becker
2010-08-12 23:03     ` [Ocfs2-devel] " Joel Becker
2010-08-13  3:39   ` Ted Ts'o
2010-08-13  3:39     ` Ted Ts'o

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=20100816191319.GC5786@mail.oracle.com \
    --to=joel.becker@oracle.com \
    --cc=adilger@dilger.ca \
    --cc=jack@suse.cz \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=ocfs2-devel@oss.oracle.com \
    --cc=sandeen@redhat.com \
    --cc=tytso@mit.edu \
    /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.