From: Andreas Dilger <adilger@sun.com>
To: Valerie Aurora Henson <vaurora@redhat.com>
Cc: linux-ext4@vger.kernel.org
Subject: Re: [RFC PATCH 04/17] Implement 64-bit "bitarray" bmap ops
Date: Wed, 12 Nov 2008 13:47:56 -0700 [thread overview]
Message-ID: <20081112204756.GO16005@webber.adilger.int> (raw)
In-Reply-To: <1226461390-5502-5-git-send-email-vaurora@redhat.com>
On Nov 11, 2008 19:42 -0800, Valerie Aurora Henson wrote:
> +/*
> + * Private data for bit array implementation of bitmap ops.
> + * Currently, this is just a pointer to our big flat hunk of memory,
> + * exactly equivalent to the old-skool char * bitmap member.
> + */
> +
> +struct ext2fs_ba_private_struct {
> + char *bitarray;
> +};
Since we're going to the expense of allocating a 1-pointer data structure,
we may as well make it useful by adding a magic value in there that can
be verified later and catch code bugs or corruption.
> +static errcode_t ba_new_bmap(ext2_filsys fs, ext2fs_generic_bitmap64 bitmap)
> {
> + bp = (ext2fs_ba_private) bitmap->private;
Then use a simple accessor function ba_private_to_bitarray() to verify the
pointer magic and return the bitarray pointer directly. That would remove
the direct use of "ext2fs_ba_private" in the majority of the code.
> static errcode_t ba_copy_bmap(ext2fs_generic_bitmap64 src,
> + ext2fs_generic_bitmap64 dest)
> {
> + size = (size_t) (((src->real_end - src->start) / 8) + 1);
> + memcpy (dest_bp->bitarray, src_bp->bitarray, size);
Would it also be worthwhile to store the size of the bitarray in the
ba_private_struct for verification?
> - errcode_t (*new_bmap)(ext2_filsys fs, ext2fs_generic_bitmap64 *bmap);
> + errcode_t (*new_bmap)(ext2_filsys fs, ext2fs_generic_bitmap64 bmap);
As a general rule, I dislike types that are pointers, as it isn't clear
from looking at this code if you are passing "bmap" by reference or a
copy.
> @@ -162,37 +163,53 @@ errcode_t ext2fs_copy_generic_bmap(ext2fs_generic_bitmap64 src,
> ext2fs_generic_bitmap64 *dest)
> {
> if (!EXT2FS_IS_64_BITMAP(src))
> - return;
> + return EINVAL;
Is this worth a better error than "EINVAL"? In general, anything that
returns "errcode_t" can have a very specific error return value as
defined in lib/ext2fs/ext2_err.et.in. This is true of all of these
functions that return EINVAL.
> +__u64 ext2fs_get_generic_bmap_start(ext2fs_generic_bitmap64 bitmap)
> +{
> + if (!bitmap)
> + return EINVAL;
> +
> + if (EXT2FS_IS_32_BITMAP(bitmap)) {
> + return ext2fs_get_generic_bitmap_start((ext2fs_generic_bitmap)
> + bitmap);
> +
> + }
> +
> + if (!EXT2FS_IS_64_BITMAP(bitmap))
> + return EINVAL;
> +
> + return bitmap->start;
> +}
Hmm, how do you distinguish between EINVAL and an actual start value here?
> +void ext2fs_clear_generic_bmap(ext2fs_generic_bitmap64 bitmap)
> +{
> + if (EXT2FS_IS_32_BITMAP(bitmap)) {
> + ext2fs_clear_generic_bitmap((ext2fs_generic_bitmap) bitmap);
> + return;
> + }
> +
> + bitmap->bitmap_ops->clear_bmap (bitmap);
> +}
To be "fail safe" this should probably prefer to believe there is a 32-bit
bitmap (i.e. what is used in all existing applications/deployments) instead
of a 64-bit bitmap. Failing that, is there a reason the 32-bit bitmap
cannot register a ->clear_bmap() method itself, and this code can never
fail?
> +int ext2fs_test_block_bitmap_range2(ext2fs_block_bitmap64 bmap,
> + blk64_t block, int num)
> +{
> + int i;
> +
> + if (!bmap)
> + return EINVAL;
> +
> + if (EXT2FS_IS_32_BITMAP(bmap)) {
> + if ((block+num) & ~0xffffffffULL) {
> + ext2fs_warn_bitmap2((ext2fs_generic_bitmap) bmap,
> + EXT2FS_UNMARK_ERROR, 0xffffffff);
> + return EINVAL;
> + }
> + return ext2fs_test_block_bitmap_range((ext2fs_generic_bitmap) bmap,
> + block, num);
> + }
> +
> + if (!EXT2FS_IS_64_BITMAP(bmap))
> + return EINVAL;
Similarly, I don't see how the caller of this code can distinguish between
EINVAL and (what is expected to be a boolean) whether the entire bitmap
range is clear or not.
Cheers, Andreas
--
Andreas Dilger
Sr. Staff Engineer, Lustre Group
Sun Microsystems of Canada, Inc.
next prev parent reply other threads:[~2008-11-12 20:48 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-11-12 3:42 [RFC,PATCH] 64-bit support for e2fsprogs Valerie Aurora Henson
2008-11-12 3:42 ` [RFC PATCH 01/17] Disable tst_refcount - doesn't compile, don't know why Valerie Aurora Henson
2008-11-12 3:42 ` [RFC PATCH 02/17] Squash warnings Valerie Aurora Henson
2008-11-12 3:42 ` [RFC PATCH 03/17] Add 64-bit bitops Valerie Aurora Henson
2008-11-12 3:42 ` [RFC PATCH 04/17] Implement 64-bit "bitarray" bmap ops Valerie Aurora Henson
2008-11-12 3:42 ` [RFC PATCH 05/17] Convert libext2fs to 64-bit bitmap interface Valerie Aurora Henson
2008-11-12 3:42 ` [RFC PATCH 06/17] Convert mke2fs to new " Valerie Aurora Henson
2008-11-12 3:43 ` [RFC PATCH 07/17] Convert e2fsck " Valerie Aurora Henson
2008-11-12 3:43 ` [RFC PATCH 08/17] Turn on new bitmaps in e2fsck and mke2fs Valerie Aurora Henson
2008-11-12 3:43 ` [RFC PATCH 09/17] Add progress bar for allocating block tables - takes forever on large Valerie Aurora Henson
2008-11-12 3:43 ` [RFC PATCH 10/17] signed int -> blk64_t to fix bugs at 2^31 - 2^32 blocks Valerie Aurora Henson
2008-11-12 3:43 ` [RFC PATCH 11/17] Fix overflow in calculation of total file system blocks Valerie Aurora Henson
2008-11-12 3:43 ` [RFC PATCH 12/17] Add ext2fs_block_iterate3 (from Ted) Valerie Aurora Henson
2008-11-12 3:43 ` [RFC PATCH 13/17] Support 48-bit file acl blocks Valerie Aurora Henson
2008-11-12 3:43 ` [RFC PATCH 14/17] super->s_*_blocks_count -> ext2fs_*_blocks_count() Valerie Aurora Henson
2008-11-12 3:43 ` [RFC PATCH 15/17] Convert to inode/block/bitmap/table loc()/loc_set() functions Valerie Aurora Henson
2008-11-12 3:43 ` [RFC PATCH 16/17] ext2fs_block_alloc_stats -> ext2fs_block_alloc_stats2 Valerie Aurora Henson
2008-11-12 3:43 ` [RFC PATCH 17/17] Convert to 64-bit IO Valerie Aurora Henson
2008-11-13 20:26 ` [RFC PATCH 15/17] Convert to inode/block/bitmap/table loc()/loc_set() functions Andreas Dilger
2008-11-13 20:24 ` [RFC PATCH 14/17] super->s_*_blocks_count -> ext2fs_*_blocks_count() Andreas Dilger
2008-11-14 3:25 ` Valerie Aurora Henson
2008-11-14 16:24 ` Eric Sandeen
2008-11-13 20:14 ` [RFC PATCH 13/17] Support 48-bit file acl blocks Andreas Dilger
2008-11-14 2:30 ` Valerie Aurora Henson
2008-11-13 20:04 ` [RFC PATCH 11/17] Fix overflow in calculation of total file system blocks Andreas Dilger
2008-11-14 2:34 ` Valerie Aurora Henson
2008-11-14 3:10 ` 64-bit inode support in e2fsprogs? (was Re: [RFC PATCH 11/17] Fix overflow in calculation of total file system blocks) Valerie Aurora Henson
2008-11-14 20:32 ` Andreas Dilger
2008-11-13 19:57 ` [RFC PATCH 10/17] signed int -> blk64_t to fix bugs at 2^31 - 2^32 blocks Andreas Dilger
2008-11-14 2:38 ` Valerie Aurora Henson
2008-11-14 3:42 ` Eric Sandeen
2008-11-14 3:54 ` Valerie Aurora Henson
2008-11-14 4:04 ` Eric Sandeen
2008-11-14 14:24 ` Theodore Tso
2008-11-14 20:35 ` Andreas Dilger
2008-11-16 15:06 ` Theodore Tso
2008-11-13 19:54 ` [RFC PATCH 09/17] Add progress bar for allocating block tables - takes forever on large Andreas Dilger
2008-11-14 2:45 ` Valerie Aurora Henson
2008-11-12 20:47 ` Andreas Dilger [this message]
2008-11-14 2:59 ` [RFC PATCH 04/17] Implement 64-bit "bitarray" bmap ops Valerie Aurora Henson
2008-11-12 20:25 ` [RFC,PATCH] 64-bit support for e2fsprogs Andreas Dilger
2008-11-13 20:30 ` Theodore Tso
2008-11-14 3:01 ` Valerie Aurora Henson
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=20081112204756.GO16005@webber.adilger.int \
--to=adilger@sun.com \
--cc=linux-ext4@vger.kernel.org \
--cc=vaurora@redhat.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).