diff mbox series

tst_device: use raw syscall in the tst_device.h

Message ID 20200109071510.11223-1-liwang@redhat.com
State Changes Requested
Delegated to: Petr Vorel
Headers show
Series tst_device: use raw syscall in the tst_device.h | expand

Commit Message

Li Wang Jan. 9, 2020, 7:15 a.m. UTC
To follow up commit 447c223dba538efc7be23edc.

Signed-off-by: Li Wang <liwang@redhat.com>
Tested-by: Li Wang <liwang@redhat.com>
Cc: Petr Vorel <pvorel@suse.cz>
Cc: Cyril Hrubis <chrubis@suse.cz>
---
 include/tst_device.h                                | 6 ++++--
 testcases/kernel/syscalls/fadvise/posix_fadvise01.c | 1 +
 testcases/kernel/syscalls/fadvise/posix_fadvise02.c | 1 +
 testcases/kernel/syscalls/fadvise/posix_fadvise03.c | 1 +
 testcases/kernel/syscalls/fadvise/posix_fadvise04.c | 1 +
 testcases/kernel/syscalls/fstat/fstat03.c           | 1 +
 testcases/kernel/syscalls/pwrite/pwrite02.c         | 1 +
 7 files changed, 10 insertions(+), 2 deletions(-)

Comments

Petr Vorel Jan. 9, 2020, 7:45 a.m. UTC | #1
Hi Li,

> To follow up commit 447c223dba538efc7be23edc.

> Signed-off-by: Li Wang <liwang@redhat.com>
> Tested-by: Li Wang <liwang@redhat.com>
> Cc: Petr Vorel <pvorel@suse.cz>
BTW I wonder if my sieve filter is bad, because I didn't get this mail or git
send-email didn't sent it.

> Cc: Cyril Hrubis <chrubis@suse.cz>

Reviewed-by: Petr Vorel <pvorel@suse.cz>
Nice, thanks for a fix. + Note about _XOPEN_SOURCE below.

Tested-by: Petr Vorel <pvorel@suse.cz>
https://travis-ci.org/pevik/ltp/builds/634613112
NOTE: it works, failures to Debian testing are caused by bug in libtirpc 1.2.5,
fixed in a86b4ff Add authdes_seccreate() stub [1].

...
> diff --git a/include/tst_device.h b/include/tst_device.h
> index f277afd77..b4067be52 100644
> --- a/include/tst_device.h
> +++ b/include/tst_device.h
> @@ -18,7 +18,9 @@
>  #ifndef TST_DEVICE_H__
>  #define TST_DEVICE_H__

> +#define _GNU_SOURCE
>  #include <unistd.h>
> +#include <sys/syscall.h>

>  struct tst_device {
>  	const char *dev;
> @@ -75,9 +77,9 @@ int tst_detach_device(const char *dev_path);
>   * simply before the tst_dev_bytes_written invocation. For easy to use,
>   * we create this inline function tst_dev_sync.
>   */
> -static inline void tst_dev_sync(int fd)
> +static inline int tst_dev_sync(int fd)
>  {
> -	syncfs(fd);
> +	return syscall(__NR_syncfs, fd);
+1 for returning result.
>  }

>  /*
> diff --git a/testcases/kernel/syscalls/fadvise/posix_fadvise01.c b/testcases/kernel/syscalls/fadvise/posix_fadvise01.c
> index 2af040840..f5d7ca8ac 100644
> --- a/testcases/kernel/syscalls/fadvise/posix_fadvise01.c
> +++ b/testcases/kernel/syscalls/fadvise/posix_fadvise01.c
> @@ -20,6 +20,7 @@
>   *	None
>   */

> +#define _GNU_SOURCE
>  #define _XOPEN_SOURCE 600
If we define _GNU_SOURCE we probably don't need _XOPEN_SOURCE 600, do we?

>  #include <fcntl.h>

> diff --git a/testcases/kernel/syscalls/fadvise/posix_fadvise02.c b/testcases/kernel/syscalls/fadvise/posix_fadvise02.c
> index d533a7953..899f58af8 100644
> --- a/testcases/kernel/syscalls/fadvise/posix_fadvise02.c
> +++ b/testcases/kernel/syscalls/fadvise/posix_fadvise02.c
> @@ -20,6 +20,7 @@
>   *	None
>   */

> +#define _GNU_SOURCE
>  #define _XOPEN_SOURCE 600
Same here.

>  #include <fcntl.h>
>  #include <unistd.h>
> diff --git a/testcases/kernel/syscalls/fadvise/posix_fadvise03.c b/testcases/kernel/syscalls/fadvise/posix_fadvise03.c
> index 5bada5f3d..efd3ab378 100644
> --- a/testcases/kernel/syscalls/fadvise/posix_fadvise03.c
> +++ b/testcases/kernel/syscalls/fadvise/posix_fadvise03.c
> @@ -20,6 +20,7 @@
>   *	None
>   */

> +#define _GNU_SOURCE
>  #define _XOPEN_SOURCE 600
Same here.

...
> diff --git a/testcases/kernel/syscalls/fadvise/posix_fadvise04.c b/testcases/kernel/syscalls/fadvise/posix_fadvise04.c
> index d8d8fb601..58162c6fb 100644
> --- a/testcases/kernel/syscalls/fadvise/posix_fadvise04.c
> +++ b/testcases/kernel/syscalls/fadvise/posix_fadvise04.c
> @@ -20,6 +20,7 @@
>   *	None
>   */

> +#define _GNU_SOURCE
>  #define _XOPEN_SOURCE 600
Same here.
>  #include <fcntl.h>
>  #include <unistd.h>

...
> diff --git a/testcases/kernel/syscalls/pwrite/pwrite02.c b/testcases/kernel/syscalls/pwrite/pwrite02.c
> index 056d44da2..4582d4e94 100644
> --- a/testcases/kernel/syscalls/pwrite/pwrite02.c
> +++ b/testcases/kernel/syscalls/pwrite/pwrite02.c
> @@ -18,6 +18,7 @@
>   *      accessible address space, returns EFAULT.
>   */

> +#define _GNU_SOURCE
>  #define _XOPEN_SOURCE 500
Same here.

Kind regards,
Petr

[1] http://git.linux-nfs.org/?p=steved/libtirpc.git;a=commit;h=a86b4ff0c4b4e53df436f83c21a5fbf01568a301
Li Wang Jan. 9, 2020, 8:02 a.m. UTC | #2
Hi Petr,

On Thu, Jan 9, 2020 at 3:45 PM Petr Vorel <pvorel@suse.cz> wrote:

> ...
> > Cc: Petr Vorel <pvorel@suse.cz>
> BTW I wonder if my sieve filter is bad, because I didn't get this mail or
> git
> send-email didn't sent it.
>

I guess that might because of your email filter configuration, the
Cc'ed name will be kicked out if he/she has subscribed to the mailing list,
especially for my Gmail-client always do that.

This is git-send-email log FYI:
----------------------------
$ git send-email 0001-tst_device-use-raw-syscall-in-the-tst_device.h.patch
--to ltp@lists.linux.it
0001-tst_device-use-raw-syscall-in-the-tst_device.h.patch
(body) Adding cc: Petr Vorel <pvorel@suse.cz> from line 'Cc: Petr Vorel <
pvorel@suse.cz>'
(body) Adding cc: Cyril Hrubis <chrubis@suse.cz> from line 'Cc: Cyril
Hrubis <chrubis@suse.cz>'
OK. Log says:
Server: smtp.corp.redhat.com
MAIL FROM:<liwang@redhat.com>
RCPT TO:<ltp@lists.linux.it>
RCPT TO:<pvorel@suse.cz>
RCPT TO:<chrubis@suse.cz>
From: Li Wang <liwang@redhat.com>
To: ltp@lists.linux.it
Cc: Petr Vorel <pvorel@suse.cz>,
Cyril Hrubis <chrubis@suse.cz>
Subject: [PATCH] tst_device: use raw syscall in the tst_device.h
Date: Thu,  9 Jan 2020 15:15:10 +0800
Message-Id: <20200109071510.11223-1-liwang@redhat.com>
X-Mailer: git-send-email 2.20.1
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit

Result: 250


> > Cc: Cyril Hrubis <chrubis@suse.cz>
>
> Reviewed-by: Petr Vorel <pvorel@suse.cz>
> Nice, thanks for a fix. + Note about _XOPEN_SOURCE below.
>

Thanks for the quick reply.


>
> Tested-by: Petr Vorel <pvorel@suse.cz>
> https://travis-ci.org/pevik/ltp/builds/634613112
> NOTE: it works, failures to Debian testing are caused by bug in libtirpc
> 1.2.5,
> fixed in a86b4ff Add authdes_seccreate() stub [1].
>
> ...

> +#define _GNU_SOURCE
> >  #define _XOPEN_SOURCE 600
> If we define _GNU_SOURCE we probably don't need _XOPEN_SOURCE 600, do we?
>

Ah, right. I will remove it in patch merging.
Petr Vorel Jan. 9, 2020, 8:21 a.m. UTC | #3
Hi Li,

> > > Cc: Petr Vorel <pvorel@suse.cz>
> > BTW I wonder if my sieve filter is bad, because I didn't get this mail or
> > git
> > send-email didn't sent it.


> I guess that might because of your email filter configuration, the
> Cc'ed name will be kicked out if he/she has subscribed to the mailing list,
> especially for my Gmail-client always do that.

> This is git-send-email log FYI:
> ----------------------------
> $ git send-email 0001-tst_device-use-raw-syscall-in-the-tst_device.h.patch
> --to ltp@lists.linux.it
> 0001-tst_device-use-raw-syscall-in-the-tst_device.h.patch
> (body) Adding cc: Petr Vorel <pvorel@suse.cz> from line 'Cc: Petr Vorel <
> pvorel@suse.cz>'
> (body) Adding cc: Cyril Hrubis <chrubis@suse.cz> from line 'Cc: Cyril
> Hrubis <chrubis@suse.cz>'
> OK. Log says:
> Server: smtp.corp.redhat.com
> MAIL FROM:<liwang@redhat.com>
> RCPT TO:<ltp@lists.linux.it>
> RCPT TO:<pvorel@suse.cz>
> RCPT TO:<chrubis@suse.cz>
> From: Li Wang <liwang@redhat.com>
> To: ltp@lists.linux.it
> Cc: Petr Vorel <pvorel@suse.cz>,
> Cyril Hrubis <chrubis@suse.cz>
> Subject: [PATCH] tst_device: use raw syscall in the tst_device.h
> Date: Thu,  9 Jan 2020 15:15:10 +0800
> Message-Id: <20200109071510.11223-1-liwang@redhat.com>
> X-Mailer: git-send-email 2.20.1
> MIME-Version: 1.0
> Content-Transfer-Encoding: 8bit

> Result: 250

Thank you for info. Sorry, my fault (I had filter to List-Id: and *also* to To:
(normally I use just List-Id:, which is what I want).

> > +#define _GNU_SOURCE
> > >  #define _XOPEN_SOURCE 600
> > If we define _GNU_SOURCE we probably don't need _XOPEN_SOURCE 600, do we?


> Ah, right. I will remove it in patch merging.
Thanks!

Kind regards,
Petr
Cyril Hrubis Jan. 9, 2020, 9:52 a.m. UTC | #4
Hi!
> +#define _GNU_SOURCE
>  #include <unistd.h>
> +#include <sys/syscall.h>

Defining _GNU_SOURCE anywhere but at the top of the test source is
meaningless. It has to be defined before we include any libc headers
otherwise it's ignored.

>  struct tst_device {
>  	const char *dev;
> @@ -75,9 +77,9 @@ int tst_detach_device(const char *dev_path);
>   * simply before the tst_dev_bytes_written invocation. For easy to use,
>   * we create this inline function tst_dev_sync.
>   */
> -static inline void tst_dev_sync(int fd)
> +static inline int tst_dev_sync(int fd)
>  {
> -	syncfs(fd);
> +	return syscall(__NR_syncfs, fd);
>  }
>  
>  /*
> diff --git a/testcases/kernel/syscalls/fadvise/posix_fadvise01.c b/testcases/kernel/syscalls/fadvise/posix_fadvise01.c
> index 2af040840..f5d7ca8ac 100644
> --- a/testcases/kernel/syscalls/fadvise/posix_fadvise01.c
> +++ b/testcases/kernel/syscalls/fadvise/posix_fadvise01.c
> @@ -20,6 +20,7 @@
>   *	None
>   */
>  
> +#define _GNU_SOURCE
>  #define _XOPEN_SOURCE 600
>  #include <fcntl.h>

Why do we need the _GNU_SOURCE here? We switched to a syscall() in the
header, hence we do not need the syncfs() prototype anymore.
Petr Vorel Jan. 9, 2020, 9:59 a.m. UTC | #5
Hi Cyril, Li,

> Hi!
> > +#define _GNU_SOURCE
> >  #include <unistd.h>
> > +#include <sys/syscall.h>

> Defining _GNU_SOURCE anywhere but at the top of the test source is
> meaningless. It has to be defined before we include any libc headers
> otherwise it's ignored.

> >  struct tst_device {
> >  	const char *dev;
> > @@ -75,9 +77,9 @@ int tst_detach_device(const char *dev_path);
> >   * simply before the tst_dev_bytes_written invocation. For easy to use,
> >   * we create this inline function tst_dev_sync.
> >   */
> > -static inline void tst_dev_sync(int fd)
> > +static inline int tst_dev_sync(int fd)
> >  {
> > -	syncfs(fd);
> > +	return syscall(__NR_syncfs, fd);
> >  }

> > diff --git a/testcases/kernel/syscalls/fadvise/posix_fadvise01.c b/testcases/kernel/syscalls/fadvise/posix_fadvise01.c

> > +#define _GNU_SOURCE
> >  #define _XOPEN_SOURCE 600
> >  #include <fcntl.h>

> Why do we need the _GNU_SOURCE here? We switched to a syscall() in the
> header, hence we do not need the syncfs() prototype anymore.

Correct, both. Sorry for a complete wrong review.

Kind regards,
Petr
Li Wang Jan. 9, 2020, 12:41 p.m. UTC | #6
On Thu, Jan 9, 2020 at 5:52 PM Cyril Hrubis <chrubis@suse.cz> wrote:

> Hi!
> > +#define _GNU_SOURCE
> >  #include <unistd.h>
> > +#include <sys/syscall.h>
>
> Defining _GNU_SOURCE anywhere but at the top of the test source is
> meaningless. It has to be defined before we include any libc headers
> otherwise it's ignored.
>

I got the point. And yes, that means the definition should be removed from
the tst_device.h header file.


> >  /*
> > diff --git a/testcases/kernel/syscalls/fadvise/posix_fadvise01.c
> b/testcases/kernel/syscalls/fadvise/posix_fadvise01.c
> > index 2af040840..f5d7ca8ac 100644
> > --- a/testcases/kernel/syscalls/fadvise/posix_fadvise01.c
> > +++ b/testcases/kernel/syscalls/fadvise/posix_fadvise01.c
> > @@ -20,6 +20,7 @@
> >   *   None
> >   */
> >
> > +#define _GNU_SOURCE
> >  #define _XOPEN_SOURCE 600
> >  #include <fcntl.h>
>
> Why do we need the _GNU_SOURCE here? We switched to a syscall() in the
> header, hence we do not need the syncfs() prototype anymore.
>
>
But shouldn't we define the _GNU_SOURCE for syscall()?  Otherwise,
the _XOPEN_SOURCE 600 definitions will take effect and makes the compiler
print new errors[1].

Here I fee a little confused, or do we need to delete the _XOPEN_SOURCE
definition directly for the test posix_fadvise01.c?

[1]:
gcc -Werror=implicit-function-declaration -g -O2 -fno-strict-aliasing -pipe
-Wall -W -Wold-style-definition
 -I/root/ltp2/testcases/kernel/syscalls/fadvise
-I/root/ltp2/testcases/kernel/syscalls/fadvise/../utils
-I../../../../include -I../../../../include -I../../../../include/old/
-L../../../../lib  posix_fadvise01.c   -lltp -o posix_fadvise01
In file included from ../../../../include/tst_test.h:22,
                 from posix_fadvise01.c:31:
../../../../include/tst_device.h: In function ‘tst_dev_sync’:
../../../../include/tst_device.h:82:9: error: implicit declaration of
function ‘syscall’; did you mean ‘strcoll’?
[-Werror=implicit-function-declaration]
  return syscall(__NR_syncfs, fd);
         ^~~~~~~
         strcoll
Cyril Hrubis Jan. 9, 2020, 12:49 p.m. UTC | #7
Hi!
> > > diff --git a/testcases/kernel/syscalls/fadvise/posix_fadvise01.c
> > b/testcases/kernel/syscalls/fadvise/posix_fadvise01.c
> > > index 2af040840..f5d7ca8ac 100644
> > > --- a/testcases/kernel/syscalls/fadvise/posix_fadvise01.c
> > > +++ b/testcases/kernel/syscalls/fadvise/posix_fadvise01.c
> > > @@ -20,6 +20,7 @@
> > >   *   None
> > >   */
> > >
> > > +#define _GNU_SOURCE
> > >  #define _XOPEN_SOURCE 600
> > >  #include <fcntl.h>
> >
> > Why do we need the _GNU_SOURCE here? We switched to a syscall() in the
> > header, hence we do not need the syncfs() prototype anymore.
> >
> >
> But shouldn't we define the _GNU_SOURCE for syscall()?  Otherwise,
> the _XOPEN_SOURCE 600 definitions will take effect and makes the compiler
> print new errors[1].
> 
> Here I fee a little confused, or do we need to delete the _XOPEN_SOURCE
> definition directly for the test posix_fadvise01.c?

Sigh, looks like the _XOPEN_SOURCE 600 disables syscall() definition
from being exposed, which is otherwise exposed by default.

Also it looks like things works fine for me when I remove the
_XOPEN_SOURCE 600.

So I guess that we should try to remove the _XOPEN_SOURCE from the
posix_fadvise() tests and try to compile the code on old enough
distribution. If that works we should do it that way.
Petr Vorel Jan. 9, 2020, 12:56 p.m. UTC | #8
Hi,

> > > +#define _GNU_SOURCE
> > >  #include <unistd.h>
> > > +#include <sys/syscall.h>

> > Defining _GNU_SOURCE anywhere but at the top of the test source is
> > meaningless. It has to be defined before we include any libc headers
> > otherwise it's ignored.


> I got the point. And yes, that means the definition should be removed from
> the tst_device.h header file.


> > > diff --git a/testcases/kernel/syscalls/fadvise/posix_fadvise01.c
...
> > > +#define _GNU_SOURCE
> > >  #define _XOPEN_SOURCE 600
> > >  #include <fcntl.h>

> > Why do we need the _GNU_SOURCE here? We switched to a syscall() in the
> > header, hence we do not need the syncfs() prototype anymore.


> But shouldn't we define the _GNU_SOURCE for syscall()?  Otherwise,
> the _XOPEN_SOURCE 600 definitions will take effect and makes the compiler
> print new errors[1].
Correct, syscall() requires _GNU_SOURCE and <unistd.h>.
+ Not sure if <sys/syscall.h> should be used (as it's in your patch or
lapi/syscalls.h.

> Here I feel a little confused, or do we need to delete the _XOPEN_SOURCE
> definition directly for the test posix_fadvise01.c?

> [1]:
> gcc -Werror=implicit-function-declaration -g -O2 -fno-strict-aliasing -pipe
> -Wall -W -Wold-style-definition
>  -I/root/ltp2/testcases/kernel/syscalls/fadvise
> -I/root/ltp2/testcases/kernel/syscalls/fadvise/../utils
> -I../../../../include -I../../../../include -I../../../../include/old/
> -L../../../../lib  posix_fadvise01.c   -lltp -o posix_fadvise01
> In file included from ../../../../include/tst_test.h:22,
>                  from posix_fadvise01.c:31:
> ../../../../include/tst_device.h: In function ‘tst_dev_sync’:
> ../../../../include/tst_device.h:82:9: error: implicit declaration of
> function ‘syscall’; did you mean ‘strcoll’?
> [-Werror=implicit-function-declaration]
>   return syscall(__NR_syncfs, fd);
>          ^~~~~~~
>          strcoll

+ Our syscall numbers in include/lapi/syscalls/ are outdated (syncfs is not at
least in include/lapi/syscalls/sparc{64,}.in and
include/lapi/syscalls/x86_64.in).

Kind regards,
Petr
Li Wang Jan. 9, 2020, 12:56 p.m. UTC | #9
On Thu, Jan 9, 2020 at 8:49 PM Cyril Hrubis <chrubis@suse.cz> wrote:

> Hi!
> > > > diff --git a/testcases/kernel/syscalls/fadvise/posix_fadvise01.c
> > > b/testcases/kernel/syscalls/fadvise/posix_fadvise01.c
> > > > index 2af040840..f5d7ca8ac 100644
> > > > --- a/testcases/kernel/syscalls/fadvise/posix_fadvise01.c
> > > > +++ b/testcases/kernel/syscalls/fadvise/posix_fadvise01.c
> > > > @@ -20,6 +20,7 @@
> > > >   *   None
> > > >   */
> > > >
> > > > +#define _GNU_SOURCE
> > > >  #define _XOPEN_SOURCE 600
> > > >  #include <fcntl.h>
> > >
> > > Why do we need the _GNU_SOURCE here? We switched to a syscall() in the
> > > header, hence we do not need the syncfs() prototype anymore.
> > >
> > >
> > But shouldn't we define the _GNU_SOURCE for syscall()?  Otherwise,
> > the _XOPEN_SOURCE 600 definitions will take effect and makes the compiler
> > print new errors[1].
> >
> > Here I fee a little confused, or do we need to delete the _XOPEN_SOURCE
> > definition directly for the test posix_fadvise01.c?
>
> Sigh, looks like the _XOPEN_SOURCE 600 disables syscall() definition
> from being exposed, which is otherwise exposed by default.
>
> Also it looks like things works fine for me when I remove the
> _XOPEN_SOURCE 600.
>
> So I guess that we should try to remove the _XOPEN_SOURCE from the
> posix_fadvise() tests and try to compile the code on old enough
> distribution. If that works we should do it that way.
>

Ok, I will have a try (remove the _XOPEN_SOURCE) to build it on more
distros. If works fine will send patch v2.
Cyril Hrubis Jan. 9, 2020, 1:10 p.m. UTC | #10
Hi!
> > But shouldn't we define the _GNU_SOURCE for syscall()?  Otherwise,
> > the _XOPEN_SOURCE 600 definitions will take effect and makes the compiler
> > print new errors[1].
> Correct, syscall() requires _GNU_SOURCE and <unistd.h>.

Not really, it's guarded by _USE_MISC which is enabled by default and
disabled by _XOPEN_SOURCE.

Looks like the manual page is outdated at least.

> + Not sure if <sys/syscall.h> should be used (as it's in your patch or
> lapi/syscalls.h.

Well, given that syncfs is old enough (2.6.39) either should work.

> > Here I feel a little confused, or do we need to delete the _XOPEN_SOURCE
> > definition directly for the test posix_fadvise01.c?
> 
> > [1]:
> > gcc -Werror=implicit-function-declaration -g -O2 -fno-strict-aliasing -pipe
> > -Wall -W -Wold-style-definition
> >  -I/root/ltp2/testcases/kernel/syscalls/fadvise
> > -I/root/ltp2/testcases/kernel/syscalls/fadvise/../utils
> > -I../../../../include -I../../../../include -I../../../../include/old/
> > -L../../../../lib  posix_fadvise01.c   -lltp -o posix_fadvise01
> > In file included from ../../../../include/tst_test.h:22,
> >                  from posix_fadvise01.c:31:
> > ../../../../include/tst_device.h: In function ???tst_dev_sync???:
> > ../../../../include/tst_device.h:82:9: error: implicit declaration of
> > function ???syscall???; did you mean ???strcoll????
> > [-Werror=implicit-function-declaration]
> >   return syscall(__NR_syncfs, fd);
> >          ^~~~~~~
> >          strcoll
> 
> + Our syscall numbers in include/lapi/syscalls/ are outdated (syncfs is not at
> least in include/lapi/syscalls/sparc{64,}.in and
> include/lapi/syscalls/x86_64.in).

The lapi/syscall.h includes sys/syscall.h so it's probably not a
problem, since there are no distribution that are missing syncfs in the
system headers. Note that we are only adding fallback definitions there
and if present the system values take precedence.
Petr Vorel Jan. 9, 2020, 2:28 p.m. UTC | #11
Hi,

> > > But shouldn't we define the _GNU_SOURCE for syscall()?  Otherwise,
> > > the _XOPEN_SOURCE 600 definitions will take effect and makes the compiler
> > > print new errors[1].
> > Correct, syscall() requires _GNU_SOURCE and <unistd.h>.

> Not really, it's guarded by _USE_MISC which is enabled by default and
> disabled by _XOPEN_SOURCE.
Yep, looking into features.h __USE_MISC is defined by _DEFAULT_SOURCE,
which is enabled if nothing or only _GNU_SOURCE is defined.

> Looks like the manual page is outdated at least.
Yes, that's what I checked this time (I usually look into sources).

> > + Not sure if <sys/syscall.h> should be used (as it's in your patch or
> > lapi/syscalls.h.

> Well, given that syncfs is old enough (2.6.39) either should work.

> > > Here I feel a little confused, or do we need to delete the _XOPEN_SOURCE
> > > definition directly for the test posix_fadvise01.c?

> > > [1]:
> > > gcc -Werror=implicit-function-declaration -g -O2 -fno-strict-aliasing -pipe
> > > -Wall -W -Wold-style-definition
> > >  -I/root/ltp2/testcases/kernel/syscalls/fadvise
> > > -I/root/ltp2/testcases/kernel/syscalls/fadvise/../utils
> > > -I../../../../include -I../../../../include -I../../../../include/old/
> > > -L../../../../lib  posix_fadvise01.c   -lltp -o posix_fadvise01
> > > In file included from ../../../../include/tst_test.h:22,
> > >                  from posix_fadvise01.c:31:
> > > ../../../../include/tst_device.h: In function ???tst_dev_sync???:
> > > ../../../../include/tst_device.h:82:9: error: implicit declaration of
> > > function ???syscall???; did you mean ???strcoll????
> > > [-Werror=implicit-function-declaration]
> > >   return syscall(__NR_syncfs, fd);
> > >          ^~~~~~~
> > >          strcoll

> > + Our syscall numbers in include/lapi/syscalls/ are outdated (syncfs is not at
> > least in include/lapi/syscalls/sparc{64,}.in and
> > include/lapi/syscalls/x86_64.in).

> The lapi/syscall.h includes sys/syscall.h so it's probably not a
> problem, since there are no distribution that are missing syncfs in the
> system headers. Note that we are only adding fallback definitions there
> and if present the system values take precedence.
Good. Sorry for wrong report (haven't notice <sys/syscall.h> inclusion).

Kind regards,
Petr
diff mbox series

Patch

diff --git a/include/tst_device.h b/include/tst_device.h
index f277afd77..b4067be52 100644
--- a/include/tst_device.h
+++ b/include/tst_device.h
@@ -18,7 +18,9 @@ 
 #ifndef TST_DEVICE_H__
 #define TST_DEVICE_H__
 
+#define _GNU_SOURCE
 #include <unistd.h>
+#include <sys/syscall.h>
 
 struct tst_device {
 	const char *dev;
@@ -75,9 +77,9 @@  int tst_detach_device(const char *dev_path);
  * simply before the tst_dev_bytes_written invocation. For easy to use,
  * we create this inline function tst_dev_sync.
  */
-static inline void tst_dev_sync(int fd)
+static inline int tst_dev_sync(int fd)
 {
-	syncfs(fd);
+	return syscall(__NR_syncfs, fd);
 }
 
 /*
diff --git a/testcases/kernel/syscalls/fadvise/posix_fadvise01.c b/testcases/kernel/syscalls/fadvise/posix_fadvise01.c
index 2af040840..f5d7ca8ac 100644
--- a/testcases/kernel/syscalls/fadvise/posix_fadvise01.c
+++ b/testcases/kernel/syscalls/fadvise/posix_fadvise01.c
@@ -20,6 +20,7 @@ 
  *	None
  */
 
+#define _GNU_SOURCE
 #define _XOPEN_SOURCE 600
 #include <fcntl.h>
 
diff --git a/testcases/kernel/syscalls/fadvise/posix_fadvise02.c b/testcases/kernel/syscalls/fadvise/posix_fadvise02.c
index d533a7953..899f58af8 100644
--- a/testcases/kernel/syscalls/fadvise/posix_fadvise02.c
+++ b/testcases/kernel/syscalls/fadvise/posix_fadvise02.c
@@ -20,6 +20,7 @@ 
  *	None
  */
 
+#define _GNU_SOURCE
 #define _XOPEN_SOURCE 600
 #include <fcntl.h>
 #include <unistd.h>
diff --git a/testcases/kernel/syscalls/fadvise/posix_fadvise03.c b/testcases/kernel/syscalls/fadvise/posix_fadvise03.c
index 5bada5f3d..efd3ab378 100644
--- a/testcases/kernel/syscalls/fadvise/posix_fadvise03.c
+++ b/testcases/kernel/syscalls/fadvise/posix_fadvise03.c
@@ -20,6 +20,7 @@ 
  *	None
  */
 
+#define _GNU_SOURCE
 #define _XOPEN_SOURCE 600
 #include <fcntl.h>
 #include <unistd.h>
diff --git a/testcases/kernel/syscalls/fadvise/posix_fadvise04.c b/testcases/kernel/syscalls/fadvise/posix_fadvise04.c
index d8d8fb601..58162c6fb 100644
--- a/testcases/kernel/syscalls/fadvise/posix_fadvise04.c
+++ b/testcases/kernel/syscalls/fadvise/posix_fadvise04.c
@@ -20,6 +20,7 @@ 
  *	None
  */
 
+#define _GNU_SOURCE
 #define _XOPEN_SOURCE 600
 #include <fcntl.h>
 #include <unistd.h>
diff --git a/testcases/kernel/syscalls/fstat/fstat03.c b/testcases/kernel/syscalls/fstat/fstat03.c
index 68fae43df..51637cdd7 100644
--- a/testcases/kernel/syscalls/fstat/fstat03.c
+++ b/testcases/kernel/syscalls/fstat/fstat03.c
@@ -13,6 +13,7 @@ 
  *    -> EFAULT (or receive signal SIGSEGV)
  */
 
+#define _GNU_SOURCE
 #include <errno.h>
 #include <stdlib.h>
 #include <unistd.h>
diff --git a/testcases/kernel/syscalls/pwrite/pwrite02.c b/testcases/kernel/syscalls/pwrite/pwrite02.c
index 056d44da2..4582d4e94 100644
--- a/testcases/kernel/syscalls/pwrite/pwrite02.c
+++ b/testcases/kernel/syscalls/pwrite/pwrite02.c
@@ -18,6 +18,7 @@ 
  *      accessible address space, returns EFAULT.
  */
 
+#define _GNU_SOURCE
 #define _XOPEN_SOURCE 500
 
 #include <errno.h>