[v3,1/3] libc: fix setting return value and errno in fallocate()

Submitted by Yuriy Kolerov on Sept. 23, 2015, 12:43 p.m.

Details

Message ID 1443012219-10992-1-git-send-email-yuriy.kolerov@synopsys.com
State New
Headers show

Commit Message

Yuriy Kolerov Sept. 23, 2015, 12:43 p.m.
fallocate system call must return 0 on success. On error, -1 is returned
and errno is set to indicate the error.

However there is an error in fallocate which is fixed by this patch - it
does not set errno and returns invalid value on error (it returns error
code instead of -1).

This error is detected in LTP's test kernel/syscalls/fallocate02:

    ----------->8----------
    fallocate(..., 1, 0, 1024) failed, expected errno:9: TEST_ERRNO=0
    fallocate(..., 1, -1024, 1024) failed, expected errno:22: TEST_ERRNO=0
    fallocate(..., 1, 1024, -1024) failed, expected errno:22: TEST_ERRNO=0
    fallocate(..., 1, 12288, 0) failed, expected errno:22: TEST_ERRNO=0
    fallocate(..., 1, 12288, -1024) failed, expected errno:22: TEST_ERRNO=0
    fallocate(..., 1, -24576, 1024) failed, expected errno:22: TEST_ERRNO=0
    ----------->8----------

Signed-off-by: Yuriy Kolerov <yuriy.kolerov@synopsys.com>
---
 libc/sysdeps/linux/common/fallocate.c   | 9 ++++++---
 libc/sysdeps/linux/common/fallocate64.c | 9 ++++++---
 2 files changed, 12 insertions(+), 6 deletions(-)

Comments

Anthony Basile Oct. 5, 2015, 8:57 p.m.
On 9/23/15 8:43 AM, Yuriy Kolerov wrote:
> fallocate system call must return 0 on success. On error, -1 is returned
> and errno is set to indicate the error.
>

Sorry for coming to the conversation late --- real life.  I did the 
first stab at implementing fallocate() and fallocate64() and I can see 
now I forgot all about errno.  Anyhow, this patch and the other one 
against posix_fallocate() look good.  They should also be backported to 
the 0.9.33 branch which we are using extensively in gentoo.  We can help 
Bernhard out by making sure they apply there cleanly.

I've heard of the linux test project but never played with it.  Sounds 
useful!
Yuriy Kolerov Oct. 7, 2015, 1:44 p.m.
Hi Anthony,

I hope these patches will be applied soon.

Regards,
Yuriy Kolerov


> -----Original Message-----
> From: uClibc [mailto:uclibc-bounces@uclibc.org] On Behalf Of Anthony G.
> Basile
> Sent: Monday, October 05, 2015 11:57 PM
> To: uclibc@uclibc.org
> Subject: Re: [PATCH v3 1/3] libc: fix setting return value and errno in
> fallocate()
> 
> On 9/23/15 8:43 AM, Yuriy Kolerov wrote:
> > fallocate system call must return 0 on success. On error, -1 is
> > returned and errno is set to indicate the error.
> >
> 
> Sorry for coming to the conversation late --- real life.  I did the first stab at
> implementing fallocate() and fallocate64() and I can see now I forgot all about
> errno.  Anyhow, this patch and the other one against posix_fallocate() look
> good.  They should also be backported to the 0.9.33 branch which we are
> using extensively in gentoo.  We can help Bernhard out by making sure they
> apply there cleanly.
> 
> I've heard of the linux test project but never played with it.  Sounds useful!
> 
> --
> Anthony G. Basile, Ph. D.
> Chair of Information Technology
> D'Youville College
> Buffalo, NY 14201
> (716) 829-8197
> _______________________________________________
> uClibc mailing list
> uClibc@uclibc.org
> http://lists.busybox.net/mailman/listinfo/uclibc
Yuriy Kolerov Dec. 23, 2015, 12:43 p.m.
Ping :(

Regards,
Yuriy Kolerov


> -----Original Message-----
> From: Yuriy Kolerov [mailto:yuriy.kolerov@synopsys.com]
> Sent: Wednesday, September 23, 2015 3:44 PM
> To: uclibc@uclibc.org; Vineet Gupta; Alexey Brodkin; Anton Kolesov
> Cc: Francois Bedard; yuriy.kolerov@synopsys.com
> Subject: [PATCH v3 1/3] libc: fix setting return value and errno in fallocate()
> 
> fallocate system call must return 0 on success. On error, -1 is returned and
> errno is set to indicate the error.
> 
> However there is an error in fallocate which is fixed by this patch - it does not
> set errno and returns invalid value on error (it returns error code instead of -
> 1).
> 
> This error is detected in LTP's test kernel/syscalls/fallocate02:
> 
>     ----------->8----------
>     fallocate(..., 1, 0, 1024) failed, expected errno:9: TEST_ERRNO=0
>     fallocate(..., 1, -1024, 1024) failed, expected errno:22: TEST_ERRNO=0
>     fallocate(..., 1, 1024, -1024) failed, expected errno:22: TEST_ERRNO=0
>     fallocate(..., 1, 12288, 0) failed, expected errno:22: TEST_ERRNO=0
>     fallocate(..., 1, 12288, -1024) failed, expected errno:22: TEST_ERRNO=0
>     fallocate(..., 1, -24576, 1024) failed, expected errno:22: TEST_ERRNO=0
>     ----------->8----------
> 
> Signed-off-by: Yuriy Kolerov <yuriy.kolerov@synopsys.com>
> ---
>  libc/sysdeps/linux/common/fallocate.c   | 9 ++++++---
>  libc/sysdeps/linux/common/fallocate64.c | 9 ++++++---
>  2 files changed, 12 insertions(+), 6 deletions(-)
> 
> diff --git a/libc/sysdeps/linux/common/fallocate.c
> b/libc/sysdeps/linux/common/fallocate.c
> index b231226..b2309e9 100644
> --- a/libc/sysdeps/linux/common/fallocate.c
> +++ b/libc/sysdeps/linux/common/fallocate.c
> @@ -12,6 +12,7 @@
>  #include <fcntl.h>
>  #include <bits/kernel-features.h>
>  #include <stdint.h>
> +#include <errno.h>
> 
>  #if defined __NR_fallocate
>  extern __typeof(fallocate) __libc_fallocate attribute_hidden; @@ -34,9
> +35,11 @@ int attribute_hidden __libc_fallocate(int fd, int mode, __off_t
> offset, __off_t  # else  # error your machine is neither 32 bit or 64 bit ... it
> must be magical  # endif
> -	if (unlikely(INTERNAL_SYSCALL_ERROR_P (ret, err)))
> -		return INTERNAL_SYSCALL_ERRNO (ret, err);
> -	return 0;
> +	if (unlikely(INTERNAL_SYSCALL_ERROR_P (ret, err))) {
> +		__set_errno(INTERNAL_SYSCALL_ERRNO (ret, err));
> +		ret = -1;
> +	}
> +	return ret;
>  }
> 
>  # if defined __UCLIBC_LINUX_SPECIFIC__ && defined __USE_GNU diff --git
> a/libc/sysdeps/linux/common/fallocate64.c
> b/libc/sysdeps/linux/common/fallocate64.c
> index cf75693..1aa351e 100644
> --- a/libc/sysdeps/linux/common/fallocate64.c
> +++ b/libc/sysdeps/linux/common/fallocate64.c
> @@ -13,6 +13,7 @@
>  #include <fcntl.h>
>  #include <bits/kernel-features.h>
>  #include <stdint.h>
> +#include <errno.h>
> 
>  #if defined __NR_fallocate
> 
> @@ -27,9 +28,11 @@ int attribute_hidden __libc_fallocate64(int fd, int
> mode, __off64_t offset,
>  	INTERNAL_SYSCALL_DECL(err);
>  	ret = (int) (INTERNAL_SYSCALL(fallocate, err, 6, fd, mode,
>  		OFF64_HI_LO (offset), OFF64_HI_LO (len)));
> -	if (unlikely(INTERNAL_SYSCALL_ERROR_P (ret, err)))
> -		return INTERNAL_SYSCALL_ERRNO (ret, err);
> -	return 0;
> +	if (unlikely(INTERNAL_SYSCALL_ERROR_P (ret, err))) {
> +		__set_errno(INTERNAL_SYSCALL_ERRNO (ret, err));
> +		ret = -1;
> +	}
> +	return ret;
>  }
> 
>  #  if defined __UCLIBC_LINUX_SPECIFIC__ && defined __USE_GNU
> --
> 2.2.0

Patch hide | download patch | download mbox

diff --git a/libc/sysdeps/linux/common/fallocate.c b/libc/sysdeps/linux/common/fallocate.c
index b231226..b2309e9 100644
--- a/libc/sysdeps/linux/common/fallocate.c
+++ b/libc/sysdeps/linux/common/fallocate.c
@@ -12,6 +12,7 @@ 
 #include <fcntl.h>
 #include <bits/kernel-features.h>
 #include <stdint.h>
+#include <errno.h>
 
 #if defined __NR_fallocate
 extern __typeof(fallocate) __libc_fallocate attribute_hidden;
@@ -34,9 +35,11 @@  int attribute_hidden __libc_fallocate(int fd, int mode, __off_t offset, __off_t
 # else
 # error your machine is neither 32 bit or 64 bit ... it must be magical
 # endif
-	if (unlikely(INTERNAL_SYSCALL_ERROR_P (ret, err)))
-		return INTERNAL_SYSCALL_ERRNO (ret, err);
-	return 0;
+	if (unlikely(INTERNAL_SYSCALL_ERROR_P (ret, err))) {
+		__set_errno(INTERNAL_SYSCALL_ERRNO (ret, err));
+		ret = -1;
+	}
+	return ret;
 }
 
 # if defined __UCLIBC_LINUX_SPECIFIC__ && defined __USE_GNU
diff --git a/libc/sysdeps/linux/common/fallocate64.c b/libc/sysdeps/linux/common/fallocate64.c
index cf75693..1aa351e 100644
--- a/libc/sysdeps/linux/common/fallocate64.c
+++ b/libc/sysdeps/linux/common/fallocate64.c
@@ -13,6 +13,7 @@ 
 #include <fcntl.h>
 #include <bits/kernel-features.h>
 #include <stdint.h>
+#include <errno.h>
 
 #if defined __NR_fallocate
 
@@ -27,9 +28,11 @@  int attribute_hidden __libc_fallocate64(int fd, int mode, __off64_t offset,
 	INTERNAL_SYSCALL_DECL(err);
 	ret = (int) (INTERNAL_SYSCALL(fallocate, err, 6, fd, mode,
 		OFF64_HI_LO (offset), OFF64_HI_LO (len)));
-	if (unlikely(INTERNAL_SYSCALL_ERROR_P (ret, err)))
-		return INTERNAL_SYSCALL_ERRNO (ret, err);
-	return 0;
+	if (unlikely(INTERNAL_SYSCALL_ERROR_P (ret, err))) {
+		__set_errno(INTERNAL_SYSCALL_ERRNO (ret, err));
+		ret = -1;
+	}
+	return ret;
 }
 
 #  if defined __UCLIBC_LINUX_SPECIFIC__ && defined __USE_GNU