* [PATCH 0/1] Work around systems defining statfs.f_type as long
@ 2014-03-19 13:26 Jes.Sorensen
2014-03-19 13:26 ` [PATCH 1/1] Work around architectures having statfs.f_type defined " Jes.Sorensen
0 siblings, 1 reply; 4+ messages in thread
From: Jes.Sorensen @ 2014-03-19 13:26 UTC (permalink / raw)
To: neilb; +Cc: linux-raid, arnd, ralf
From: Jes Sorensen <Jes.Sorensen@redhat.com>
Hi
I was scratching my head over this build failure on s390x - thanks to
Arnd for suggesting the solution.
Allowing RAMFS_MAGIC to be defined as a number > 31 bits was a mistake
from the beginning, but trying to change it now is probably going to
cause even more headaches.
The problem is that some architectures, such as s390x and MIPS, define
statfs.f_type as signed long, which means the cast to unsigned long
and then comparing it against RAMFS_MAGIC is going to fail. Instead
this patch brutally casts both to unsigned long and then masks off the
lower 32 bits and comparing those - this avoids having to add #ifdef
cases to the code.
Cheers,
Jes
Jes Sorensen (1):
Work around architectures having statfs.f_type defined as long
util.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
--
1.8.5.3
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/1] Work around architectures having statfs.f_type defined as long
2014-03-19 13:26 [PATCH 0/1] Work around systems defining statfs.f_type as long Jes.Sorensen
@ 2014-03-19 13:26 ` Jes.Sorensen
2014-03-19 20:43 ` Arnd Bergmann
2014-03-19 22:24 ` NeilBrown
0 siblings, 2 replies; 4+ messages in thread
From: Jes.Sorensen @ 2014-03-19 13:26 UTC (permalink / raw)
To: neilb; +Cc: linux-raid, arnd, ralf
From: Jes Sorensen <Jes.Sorensen@redhat.com>
Having RAMFS_MAGIC defined as 0x858458f6 causing problems when trying
to compare it directly against statfs.f_type being cast from long to
unsigned long.
This hack is extremly ugly, but it should at least do the right thing
for every situation.
Thanks to Arnd Bergmann for suggesting the fix.
Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
---
util.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/util.c b/util.c
index e32d97a..afb2bb1 100644
--- a/util.c
+++ b/util.c
@@ -1946,9 +1946,13 @@ int in_initrd(void)
{
/* This is based on similar function in systemd. */
struct statfs s;
+ /* statfs.f_type is signed long on s390x and MIPS, causing all
+ sorts of sign extension problems with RAMFS_MAGIC being
+ defined as 0x858458f6 */
return statfs("/", &s) >= 0 &&
((unsigned long)s.f_type == TMPFS_MAGIC ||
- (unsigned long)s.f_type == RAMFS_MAGIC);
+ ((unsigned long)s.f_type & 0xFFFFFFFFUL) ==
+ ((unsigned long)RAMFS_MAGIC & 0xFFFFFFFFUL));
}
void reopen_mddev(int mdfd)
--
1.8.5.3
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 1/1] Work around architectures having statfs.f_type defined as long
2014-03-19 13:26 ` [PATCH 1/1] Work around architectures having statfs.f_type defined " Jes.Sorensen
@ 2014-03-19 20:43 ` Arnd Bergmann
2014-03-19 22:24 ` NeilBrown
1 sibling, 0 replies; 4+ messages in thread
From: Arnd Bergmann @ 2014-03-19 20:43 UTC (permalink / raw)
To: Jes.Sorensen; +Cc: neilb, linux-raid, ralf
On Wednesday 19 March 2014, Jes.Sorensen@redhat.com wrote:
> @@ -1946,9 +1946,13 @@ int in_initrd(void)
> {
> /* This is based on similar function in systemd. */
> struct statfs s;
> + /* statfs.f_type is signed long on s390x and MIPS, causing all
> + sorts of sign extension problems with RAMFS_MAGIC being
> + defined as 0x858458f6 */
> return statfs("/", &s) >= 0 &&
> ((unsigned long)s.f_type == TMPFS_MAGIC ||
> - (unsigned long)s.f_type == RAMFS_MAGIC);
> + ((unsigned long)s.f_type & 0xFFFFFFFFUL) ==
> + ((unsigned long)RAMFS_MAGIC & 0xFFFFFFFFUL));
The comment is wrong: on s390x the type is actually 'unsigned int'.
The fix however works on all variants as far as I can tell.
Thinking about it a bit more, I guess we can also cast both
sides to 'unsigned int' for the same effect and get rid of
the mask.
Arnd
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 1/1] Work around architectures having statfs.f_type defined as long
2014-03-19 13:26 ` [PATCH 1/1] Work around architectures having statfs.f_type defined " Jes.Sorensen
2014-03-19 20:43 ` Arnd Bergmann
@ 2014-03-19 22:24 ` NeilBrown
1 sibling, 0 replies; 4+ messages in thread
From: NeilBrown @ 2014-03-19 22:24 UTC (permalink / raw)
To: Jes.Sorensen; +Cc: linux-raid, arnd, ralf
[-- Attachment #1: Type: text/plain, Size: 1296 bytes --]
On Wed, 19 Mar 2014 14:26:02 +0100 Jes.Sorensen@redhat.com wrote:
> From: Jes Sorensen <Jes.Sorensen@redhat.com>
>
> Having RAMFS_MAGIC defined as 0x858458f6 causing problems when trying
> to compare it directly against statfs.f_type being cast from long to
> unsigned long.
>
> This hack is extremly ugly, but it should at least do the right thing
> for every situation.
>
> Thanks to Arnd Bergmann for suggesting the fix.
>
> Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
> ---
> util.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/util.c b/util.c
> index e32d97a..afb2bb1 100644
> --- a/util.c
> +++ b/util.c
> @@ -1946,9 +1946,13 @@ int in_initrd(void)
> {
> /* This is based on similar function in systemd. */
> struct statfs s;
> + /* statfs.f_type is signed long on s390x and MIPS, causing all
> + sorts of sign extension problems with RAMFS_MAGIC being
> + defined as 0x858458f6 */
> return statfs("/", &s) >= 0 &&
> ((unsigned long)s.f_type == TMPFS_MAGIC ||
> - (unsigned long)s.f_type == RAMFS_MAGIC);
> + ((unsigned long)s.f_type & 0xFFFFFFFFUL) ==
> + ((unsigned long)RAMFS_MAGIC & 0xFFFFFFFFUL));
> }
>
> void reopen_mddev(int mdfd)
Applied, thanks.
NeilBrown
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 828 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2014-03-19 22:24 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-03-19 13:26 [PATCH 0/1] Work around systems defining statfs.f_type as long Jes.Sorensen
2014-03-19 13:26 ` [PATCH 1/1] Work around architectures having statfs.f_type defined " Jes.Sorensen
2014-03-19 20:43 ` Arnd Bergmann
2014-03-19 22:24 ` NeilBrown
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).