2007-09-21 05:25:13

by Aneesh Kumar K.V

[permalink] [raw]
Subject: [PATCH] Introduce ext4_find_next_bit

Also add generic_find_next_le_bit

This gets used by the ext4 multi block allocator patches.

Signed-off-by: Aneesh Kumar K.V <[email protected]>
---
include/asm-generic/bitops/ext2-non-atomic.h | 2 +
include/asm-generic/bitops/le.h | 4 ++
include/asm-powerpc/bitops.h | 4 ++
include/linux/ext4_fs.h | 1 +
lib/find_next_bit.c | 44 ++++++++++++++++++++++++++
5 files changed, 55 insertions(+), 0 deletions(-)

diff --git a/include/asm-generic/bitops/ext2-non-atomic.h b/include/asm-generic/bitops/ext2-non-atomic.h
index 1697404..63cf822 100644
--- a/include/asm-generic/bitops/ext2-non-atomic.h
+++ b/include/asm-generic/bitops/ext2-non-atomic.h
@@ -14,5 +14,7 @@
generic_find_first_zero_le_bit((unsigned long *)(addr), (size))
#define ext2_find_next_zero_bit(addr, size, off) \
generic_find_next_zero_le_bit((unsigned long *)(addr), (size), (off))
+#define ext2_find_next_bit(addr, size, off) \
+ generic_find_next_le_bit((unsigned long *)(addr), (size), (off))

#endif /* _ASM_GENERIC_BITOPS_EXT2_NON_ATOMIC_H_ */
diff --git a/include/asm-generic/bitops/le.h b/include/asm-generic/bitops/le.h
index b9c7e5d..80e3bf1 100644
--- a/include/asm-generic/bitops/le.h
+++ b/include/asm-generic/bitops/le.h
@@ -20,6 +20,8 @@
#define generic___test_and_clear_le_bit(nr, addr) __test_and_clear_bit(nr, addr)

#define generic_find_next_zero_le_bit(addr, size, offset) find_next_zero_bit(addr, size, offset)
+#define generic_find_next_le_bit(addr, size, offset) \
+ find_next_bit(addr, size, offset)

#elif defined(__BIG_ENDIAN)

@@ -42,6 +44,8 @@

extern unsigned long generic_find_next_zero_le_bit(const unsigned long *addr,
unsigned long size, unsigned long offset);
+extern unsigned long generic_find_next_le_bit(const unsigned long *addr,
+ unsigned long size, unsigned long offset);

#else
#error "Please fix <asm/byteorder.h>"
diff --git a/include/asm-powerpc/bitops.h b/include/asm-powerpc/bitops.h
index 8144a27..60652a3 100644
--- a/include/asm-powerpc/bitops.h
+++ b/include/asm-powerpc/bitops.h
@@ -310,6 +310,8 @@ static __inline__ int test_le_bit(unsigned long nr,
unsigned long generic_find_next_zero_le_bit(const unsigned long *addr,
unsigned long size, unsigned long offset);

+unsigned long generic_find_next_le_bit(const unsigned long *addr,
+ unsigned long size, unsigned long offset);
/* Bitmap functions for the ext2 filesystem */

#define ext2_set_bit(nr,addr) \
@@ -329,6 +331,8 @@ unsigned long generic_find_next_zero_le_bit(const unsigned long *addr,
#define ext2_find_next_zero_bit(addr, size, off) \
generic_find_next_zero_le_bit((unsigned long*)addr, size, off)

+#define ext2_find_next_bit(addr, size, off) \
+ generic_find_next_le_bit((unsigned long *)addr, size, off)
/* Bitmap functions for the minix filesystem. */

#define minix_test_and_set_bit(nr,addr) \
diff --git a/include/linux/ext4_fs.h b/include/linux/ext4_fs.h
index cdee7aa..c7b9bb2 100644
--- a/include/linux/ext4_fs.h
+++ b/include/linux/ext4_fs.h
@@ -502,6 +502,7 @@ do { \
#define ext4_test_bit ext2_test_bit
#define ext4_find_first_zero_bit ext2_find_first_zero_bit
#define ext4_find_next_zero_bit ext2_find_next_zero_bit
+#define ext4_find_next_bit ext2_find_next_bit

/*
* Maximal mount counts between two filesystem checks
diff --git a/lib/find_next_bit.c b/lib/find_next_bit.c
index bda0d71..0306c04 100644
--- a/lib/find_next_bit.c
+++ b/lib/find_next_bit.c
@@ -178,4 +178,48 @@ found_middle_swap:

EXPORT_SYMBOL(generic_find_next_zero_le_bit);

+unsigned long generic_find_next_le_bit(const unsigned long *addr, unsigned
+ long size, unsigned long offset)
+{
+ const unsigned long *p = addr + BITOP_WORD(offset);
+ unsigned long result = offset & ~(BITS_PER_LONG - 1);
+ unsigned long tmp;
+
+ if (offset >= size)
+ return size;
+ size -= result;
+ offset &= (BITS_PER_LONG - 1UL);
+ if (offset) {
+ tmp = ext2_swabp(p++);
+ tmp &= (~0UL << offset);
+ if (size < BITS_PER_LONG)
+ goto found_first;
+ if (tmp)
+ goto found_middle;
+ size -= BITS_PER_LONG;
+ result += BITS_PER_LONG;
+ }
+
+ while (size & ~(BITS_PER_LONG - 1)) {
+ tmp = *(p++);
+ if (tmp)
+ goto found_middle_swap;
+ result += BITS_PER_LONG;
+ size -= BITS_PER_LONG;
+ }
+ if (!size)
+ return result;
+ tmp = ext2_swabp(p);
+found_first:
+ tmp &= (~0UL >> (BITS_PER_LONG - size));
+ if (tmp == 0UL) /* Are any bits set? */
+ return result + size; /* Nope. */
+found_middle:
+ return result + __ffs(tmp);
+
+found_middle_swap:
+ return result + __ffs(ext2_swab(tmp));
+}
+EXPORT_SYMBOL(generic_find_next_le_bit);
+
#endif /* __BIG_ENDIAN */
--
1.5.3.1.91.gd3392-dirty


2007-09-21 05:25:14

by Aneesh Kumar K.V

[permalink] [raw]
Subject: [PATCH] ext4: Fix spare warnings

Signed-off-by: Aneesh Kumar K.V <[email protected]>
---
fs/ext4/inode.c | 6 ++++--
include/linux/ext4_fs.h | 16 ++++++++--------
2 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index a4848e0..307e240 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -3177,12 +3177,14 @@ int ext4_mark_inode_dirty(handle_t *handle, struct inode *inode)
iloc, handle);
if (ret) {
EXT4_I(inode)->i_state |= EXT4_STATE_NO_EXPAND;
- if (mnt_count != sbi->s_es->s_mnt_count) {
+ if (mnt_count !=
+ le16_to_cpu(sbi->s_es->s_mnt_count)) {
ext4_warning(inode->i_sb, __FUNCTION__,
"Unable to expand inode %lu. Delete"
" some EAs or run e2fsck.",
inode->i_ino);
- mnt_count = sbi->s_es->s_mnt_count;
+ mnt_count =
+ le16_to_cpu(sbi->s_es->s_mnt_count);
}
}
}
diff --git a/include/linux/ext4_fs.h b/include/linux/ext4_fs.h
index c7b9bb2..ab7edaa 100644
--- a/include/linux/ext4_fs.h
+++ b/include/linux/ext4_fs.h
@@ -129,7 +129,7 @@ struct ext4_group_desc
__le16 bg_free_blocks_count; /* Free blocks count */
__le16 bg_free_inodes_count; /* Free inodes count */
__le16 bg_used_dirs_count; /* Directories count */
- __u16 bg_flags;
+ __le16 bg_flags;
__u32 bg_reserved[3];
__le32 bg_block_bitmap_hi; /* Blocks bitmap block MSB */
__le32 bg_inode_bitmap_hi; /* Inodes bitmap block MSB */
@@ -596,13 +596,13 @@ struct ext4_super_block {
/*150*/ __le32 s_blocks_count_hi; /* Blocks count */
__le32 s_r_blocks_count_hi; /* Reserved blocks count */
__le32 s_free_blocks_count_hi; /* Free blocks count */
- __u16 s_min_extra_isize; /* All inodes have at least # bytes */
- __u16 s_want_extra_isize; /* New inodes should reserve # bytes */
- __u32 s_flags; /* Miscellaneous flags */
- __u16 s_raid_stride; /* RAID stride */
- __u16 s_mmp_interval; /* # seconds to wait in MMP checking */
- __u64 s_mmp_block; /* Block for multi-mount protection */
- __u32 s_raid_stripe_width; /* blocks on all data disks (N*stride)*/
+ __le16 s_min_extra_isize; /* All inodes have at least # bytes */
+ __le16 s_want_extra_isize; /* New inodes should reserve # bytes */
+ __le32 s_flags; /* Miscellaneous flags */
+ __le16 s_raid_stride; /* RAID stride */
+ __le16 s_mmp_interval; /* # seconds to wait in MMP checking */
+ __le64 s_mmp_block; /* Block for multi-mount protection */
+ __le32 s_raid_stripe_width; /* blocks on all data disks (N*stride)*/
__u32 s_reserved[163]; /* Padding to the end of the block */
};

--
1.5.3.1.91.gd3392-dirty

2007-09-21 06:02:56

by Balbir Singh

[permalink] [raw]
Subject: Re: [PATCH] ext4: Fix spare warnings

Aneesh,

The subject is a bit confusing, I presume you mean sparse warnings

Balbir

2007-09-21 06:45:16

by Balbir Singh

[permalink] [raw]
Subject: Re: [PATCH] Introduce ext4_find_next_bit

Aneesh Kumar K.V wrote:
> Also add generic_find_next_le_bit
>
> This gets used by the ext4 multi block allocator patches.
>

Looks like it's a straight forward on Little Endian Architectures.
I see something for powerpc, what about other architectures?

>
> +unsigned long generic_find_next_le_bit(const unsigned long *addr, unsigned
> + long size, unsigned long offset)
> +{

Docbook style comments on the function and arguments would be nice.

> + const unsigned long *p = addr + BITOP_WORD(offset);
> + unsigned long result = offset & ~(BITS_PER_LONG - 1);
> + unsigned long tmp;
> +
> + if (offset >= size)
> + return size;
> + size -= result;
> + offset &= (BITS_PER_LONG - 1UL);
> + if (offset) {
> + tmp = ext2_swabp(p++);
> + tmp &= (~0UL << offset);
> + if (size < BITS_PER_LONG)
> + goto found_first;
> + if (tmp)
> + goto found_middle;
> + size -= BITS_PER_LONG;
> + result += BITS_PER_LONG;
> + }
> +
> + while (size & ~(BITS_PER_LONG - 1)) {
> + tmp = *(p++);
> + if (tmp)
> + goto found_middle_swap;
> + result += BITS_PER_LONG;
> + size -= BITS_PER_LONG;
> + }
> + if (!size)
> + return result;
> + tmp = ext2_swabp(p);
> +found_first:
> + tmp &= (~0UL >> (BITS_PER_LONG - size));
> + if (tmp == 0UL) /* Are any bits set? */
> + return result + size; /* Nope. */
> +found_middle:
> + return result + __ffs(tmp);
> +
> +found_middle_swap:
> + return result + __ffs(ext2_swab(tmp));
> +}
> +EXPORT_SYMBOL(generic_find_next_le_bit);
> +
> #endif /* __BIG_ENDIAN */


--
Warm Regards,
Balbir Singh
Linux Technology Center
IBM, ISTL

2007-09-21 09:04:44

by Aneesh Kumar K.V

[permalink] [raw]
Subject: Re: [PATCH] ext4: Fix spare warnings



Balbir Singh wrote:
> Aneesh,
>
> The subject is a bit confusing, I presume you mean sparse warnings


yes. I will send an updated patch. The group descriptor bg_flags -> le16 conversion
should actually go with the uninitialized block group patch.

-aneesh.

2007-09-21 09:09:15

by Aneesh Kumar K.V

[permalink] [raw]
Subject: Re: [PATCH] Introduce ext4_find_next_bit



Balbir Singh wrote:
> Aneesh Kumar K.V wrote:
>> Also add generic_find_next_le_bit
>>
>> This gets used by the ext4 multi block allocator patches.
>>
>
> Looks like it's a straight forward on Little Endian Architectures.
> I see something for powerpc, what about other architectures?
>
>
All include/asm-<arch>/bitops.h except powerpc have

#include <asm-generic/bitops/ext2-non-atomic.h>

and ext2-non-atomic.h have #include <asm-generic/bitops/le.h>


-aneesh

2007-11-13 07:59:19

by Andrew Morton

[permalink] [raw]
Subject: Re: [PATCH] Introduce ext4_find_next_bit

On Fri, 21 Sep 2007 10:55:05 +0530 "Aneesh Kumar K.V" <[email protected]> wrote:

> Also add generic_find_next_le_bit
>
> This gets used by the ext4 multi block allocator patches.
>

arm allmodconfig:

fs/ext4/mballoc.c: In function `ext4_mb_generate_buddy':
fs/ext4/mballoc.c:836: error: implicit declaration of function `ext2_find_next_bit'

This patch makes my head spin.

Why did we declare generic_find_next_le_bit() in
include/asm-powerpc/bitops.h (wrong) as well as in
include/asm-generic/bitops/le.h (presumably correct)?

Why is it touching a powerpc file and no any other architectures?
Something screwed up in powerpc land?

And why did arm break?

Shudder. Anyway, please fix, and if that fix requires that various
braindamaged be repaired, please repair the braindamage rather than going
along with it.

Thanks.

2007-11-13 19:11:03

by Aneesh Kumar K.V

[permalink] [raw]
Subject: Re: [PATCH] Introduce ext4_find_next_bit



Andrew Morton wrote:
> On Fri, 21 Sep 2007 10:55:05 +0530 "Aneesh Kumar K.V" <[email protected]> wrote:
>
>> Also add generic_find_next_le_bit
>>
>> This gets used by the ext4 multi block allocator patches.
>>
>
> arm allmodconfig:
>
> fs/ext4/mballoc.c: In function `ext4_mb_generate_buddy':
> fs/ext4/mballoc.c:836: error: implicit declaration of function `ext2_find_next_bit'
>
> This patch makes my head spin.
>
> Why did we declare generic_find_next_le_bit() in
> include/asm-powerpc/bitops.h (wrong) as well as in
> include/asm-generic/bitops/le.h (presumably correct)?
>

I was following the coding style used for rest of the APIs
like ext4_set_bit.


> Why is it touching a powerpc file and no any other architectures?
> Something screwed up in powerpc land?
>
> And why did arm break?

arm and below list of arch doesn't include the asm-generic/bitops/ext2-non-atomic.h

I did a grep and that list the below architectures as also affected.
arm, m68k, m68knommu, s390

>
> Shudder. Anyway, please fix, and if that fix requires that various
> braindamaged be repaired, please repair the braindamage rather than going
> along with it.
>
>

That should be a separate patch altogether. I wanted to do the cleanup
along with the usages such as but never got time to do the same.

#define ocfs2_set_bit ext2_set_bit
#define udf_set_bit(nr,addr) ext2_set_bit(nr,addr)
direct usage in mb
md/bitmap.c +799
md/dm-log.c +177

I will send a patch tomorrow that fix arm and other architectures. I guess the cleanup
can be a separate patch ?

-aneesh

2007-11-13 20:43:20

by Andrew Morton

[permalink] [raw]
Subject: Re: [PATCH] Introduce ext4_find_next_bit

On Wed, 14 Nov 2007 00:41:03 +0530 "Aneesh Kumar K.V" <[email protected]> wrote:

>
>
> Andrew Morton wrote:
> > On Fri, 21 Sep 2007 10:55:05 +0530 "Aneesh Kumar K.V" <[email protected]> wrote:
> >
> >> Also add generic_find_next_le_bit
> >>
> >> This gets used by the ext4 multi block allocator patches.
> >>
> >
> > arm allmodconfig:
> >
> > fs/ext4/mballoc.c: In function `ext4_mb_generate_buddy':
> > fs/ext4/mballoc.c:836: error: implicit declaration of function `ext2_find_next_bit'
> >
> > This patch makes my head spin.
> >
> > Why did we declare generic_find_next_le_bit() in
> > include/asm-powerpc/bitops.h (wrong) as well as in
> > include/asm-generic/bitops/le.h (presumably correct)?
> >
>
> I was following the coding style used for rest of the APIs
> like ext4_set_bit.

Well. There's quite a bit of cruft in there. If you do come across
something which isn't right, please do try to find the time to fix it up
first.

That might be non-trivial - powerpc does seem to have gone off on a strange
tangent there.

>
> > Why is it touching a powerpc file and no any other architectures?
> > Something screwed up in powerpc land?
> >
> > And why did arm break?
>
> arm and below list of arch doesn't include the asm-generic/bitops/ext2-non-atomic.h
>
> I did a grep and that list the below architectures as also affected.
> arm, m68k, m68knommu, s390
>
> >
> > Shudder. Anyway, please fix, and if that fix requires that various
> > braindamaged be repaired, please repair the braindamage rather than going
> > along with it.
> >
> >
>
> That should be a separate patch altogether. I wanted to do the cleanup
> along with the usages such as but never got time to do the same.
>
> #define ocfs2_set_bit ext2_set_bit
> #define udf_set_bit(nr,addr) ext2_set_bit(nr,addr)
> direct usage in mb
> md/bitmap.c +799
> md/dm-log.c +177
>
> I will send a patch tomorrow that fix arm and other architectures. I guess the cleanup
> can be a separate patch ?
>

Yes, that's a separate work, thanks.