Skip to contentSkip to conversation

syscalls/getdents: Use getdents64 if SYS_getdents is not defined

PATCH In review Markos Chandras 4 participants 7 messages Mar 13, 2013 – Mar 14, 2013 2 messages not in the archive

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 syscalls/getdents: Use getdents64 if SYS_getdents is not defined

From: Markos Chandras <[email protected]>

New Linux Kernel architectures do not define NR_getdents so we try to use the getdents64 syscall instead

---
 testcases/kernel/syscalls/getdents/getdents.h |   15 +++++++++++++++
 1 files changed, 15 insertions(+), 0 deletions(-)
testcases/kernel/syscalls/getdents/getdents.h +15 -0
index 1d5e584..12d2be4 100644
@@ -38,12 +38,23 @@
  * declare our own here.  Wheeeeee.
  */
 
+#ifdef SYS_getdents
 struct linux_dirent {
 	unsigned long   d_ino;
 	unsigned long   d_off;
 	unsigned short  d_reclen;
 	char            d_name[];
 };
+#else
+/* Use the 64-bit definition */
+struct linux_dirent {
+	unsigned long long	d_ino;
+	long long		d_off;
+	unsigned short		d_reclen;
+	unsigned char		d_type;
+	char			d_name[0];
+};
+#endif
 
 static inline int
 getdents(unsigned int fd, struct dirent *dirp, unsigned int count)
@@ -57,7 +68,11 @@ getdents(unsigned int fd, struct dirent *dirp, unsigned int count)
 	unsigned int i;
 
 	ptrs.buf = buf;
+#ifdef SYS_getdents
 	ret = syscall(SYS_getdents, fd, buf, count);
+#else
+	ret = syscall(SYS_getdents64, fd, buf, count);
+#endif
 	if (ret < 0)
 		return ret;
 
Signature · 13 lines
1.7.1



------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_mar
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
#1 lore raw
Quoted 5 lines · On Wednesday 13 March 2013 10:01:34 Markos Chandras wrote:
testcases/kernel/syscalls/getdents/getdents.h +1 -0
+#ifdef SYS_getdents
 struct linux_dirent {
 	unsigned long   d_ino;
 	unsigned long   d_off;
 	unsigned short  d_reclen;

testcases/kernel/syscalls/getdents/getdents.h line 55

Quoted 10 lines
testcases/kernel/syscalls/getdents/getdents.h +8 -0
 	char            d_name[];
 };
+#else
+/* Use the 64-bit definition */
+struct linux_dirent {
+	unsigned long long	d_ino;
+	long long		d_off;
+	unsigned short		d_reclen;
+	unsigned char		d_type;
+	char			d_name[0];

any reason for using [0] instead of [] ?
-mike

------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_mar

_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

#2 lore raw
Quoted 11 lines · Mike Frysinger
Quoted 10 lines · On Wednesday 13 March 2013 10:01:34 Markos Chandras wrote:
testcases/kernel/syscalls/getdents/getdents.h +4 -0
+#ifdef SYS_getdents
 struct linux_dirent {
      unsigned long   d_ino;
      unsigned long   d_off;
      unsigned short  d_reclen;
      char            d_name[];
 };
+#else
+/* Use the 64-bit definition */
+struct linux_dirent {
Quoted 8 lines

testcases/kernel/syscalls/getdents/getdents.h line 55

Quoted 5 lines
testcases/kernel/syscalls/getdents/getdents.h +5 -0
+     unsigned long long      d_ino;
+     long long               d_off;
+     unsigned short          d_reclen;
+     unsigned char           d_type;
+     char                    d_name[0];

any reason for using [0] instead of [] ?
-mike

Nope just copying what kernel does in $KDIR/include/linux/dirent.h

Signature · 12 lines
Regards,
Markos Chandras

------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_mar
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
#3 lore raw
In reply to Markos Chandras

----- Original Message -----

Quoted 45 lines

From: "Markos Chandras" <[email protected]>
To: [email protected]
Sent: Wednesday, 13 March, 2013 3:01:34 PM
Subject: [LTP] [PATCH 1/2] syscalls/getdents: Use getdents64 if SYS_getdents is not defined

From: Markos Chandras <[email protected]>

New Linux Kernel architectures do not define NR_getdents so we try to use the getdents64 syscall instead

---
 testcases/kernel/syscalls/getdents/getdents.h |   15 +++++++++++++++
 1 files changed, 15 insertions(+), 0 deletions(-)
testcases/kernel/syscalls/getdents/getdents.h +11 -0
index 1d5e584..12d2be4 100644
@@ -38,12 +38,23 @@
  * declare our own here.  Wheeeeee.
  */
 
+#ifdef SYS_getdents
 struct linux_dirent {
 	unsigned long   d_ino;
 	unsigned long   d_off;
 	unsigned short  d_reclen;
 	char            d_name[];
 };
+#else
+/* Use the 64-bit definition */
+struct linux_dirent {
+	unsigned long long	d_ino;
+	long long		d_off;
+	unsigned short		d_reclen;
+	unsigned char		d_type;
+	char			d_name[0];
+};
+#endif
 
 static inline int
 getdents(unsigned int fd, struct dirent *dirp, unsigned int count)

testcases/kernel/syscalls/getdents/getdents.h getdents(unsigned int fd, struct dirent *dirp, · line 76

Quoted 9 lines
testcases/kernel/syscalls/getdents/getdents.h +4 -0
@@ -57,7 +68,11 @@ getdents(unsigned int fd, struct dirent *dirp,
 unsigned int count)
 	unsigned int i;
 
 	ptrs.buf = buf;
+#ifdef SYS_getdents
 	ret = syscall(SYS_getdents, fd, buf, count);
+#else
+	ret = syscall(SYS_getdents64, fd, buf, count);
+#endif

Just a thought.. What about turning it to runtime check? There could be parameter to switch between SYS_getdents/SYS_getdents64 and we can have both (with/without that parameter) in runtest/syscalls. If it's supported it runs, if not ends with TCONF. That way we could have both version on arches that support both syscalls.

Regards,
Jan

Quoted 8 lines
testcases/kernel/syscalls/getdents/getdents.h +0 -1
 	if (ret < 0)
 		return ret;
 
--

1.7.1

Quoted 10 lines

------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_mar
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_mar
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

#4 lore raw
Quoted 51 lines · Jan Stancek

----- Original Message -----

Quoted 48 lines

From: "Markos Chandras" <[email protected]>
To: [email protected]
Sent: Wednesday, 13 March, 2013 3:01:34 PM
Subject: [LTP] [PATCH 1/2] syscalls/getdents: Use getdents64 if SYS_getdents is not defined

From: Markos Chandras <[email protected]>

New Linux Kernel architectures do not define NR_getdents so we try to use the getdents64 syscall instead

---
 testcases/kernel/syscalls/getdents/getdents.h |   15 +++++++++++++++
 1 files changed, 15 insertions(+), 0 deletions(-)
testcases/kernel/syscalls/getdents/getdents.h +11 -0
index 1d5e584..12d2be4 100644
@@ -38,12 +38,23 @@
  * declare our own here.  Wheeeeee.
  */
 
+#ifdef SYS_getdents
 struct linux_dirent {
      unsigned long   d_ino;
      unsigned long   d_off;
      unsigned short  d_reclen;
      char            d_name[];
 };
+#else
+/* Use the 64-bit definition */
+struct linux_dirent {
+     unsigned long long      d_ino;
+     long long               d_off;
+     unsigned short          d_reclen;
+     unsigned char           d_type;
+     char                    d_name[0];
+};
+#endif
 
 static inline int
 getdents(unsigned int fd, struct dirent *dirp, unsigned int count)
@@ -57,7 +68,11 @@ getdents(unsigned int fd, struct dirent *dirp,
 unsigned int count)
      unsigned int i;
 
Quoted 12 lines

testcases/kernel/syscalls/getdents/getdents.h getdents(unsigned int fd, struct dirent *dirp, unsigned int count) · line 75

Quoted 6 lines
testcases/kernel/syscalls/getdents/getdents.h +4 -0
      ptrs.buf = buf;
+#ifdef SYS_getdents
      ret = syscall(SYS_getdents, fd, buf, count);
+#else
+     ret = syscall(SYS_getdents64, fd, buf, count);
+#endif

Just a thought.. What about turning it to runtime check? There could be parameter to switch between SYS_getdents/SYS_getdents64 and we can have both (with/without that parameter) in runtest/syscalls. If it's supported it runs, if not ends with TCONF. That way we could have both version on arches that support both syscalls.

The problem is that for arches that don't have SYS_getdents defined, you will not be able to compile LTP on them so you really need to hide this codepath from them.

A similar commit that changes the codepath based on whether a particular __NR_XX is defined is this
https://github.com/linux-test-project/ltp/commit/75201f160b9aa49af70d8f46fb1f087e63d603dd

I don't see an easy way to determine if __NR_XX is defined or not during runtime.

Signature · 12 lines
Regards,
Markos Chandras

------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_mar
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
#5 lore raw

Hi!

Quoted 10 lines

The problem is that for arches that don't have SYS_getdents defined, you will not be able to compile LTP on them so you really need to hide this codepath from them.

A similar commit that changes the codepath based on whether a particular __NR_XX is defined is this
https://github.com/linux-test-project/ltp/commit/75201f160b9aa49af70d8f46fb1f087e63d603dd

I don't see an easy way to determine if __NR_XX is defined or not during runtime.

There is code that tries to address this issue in testcases/kernel/include/linux_syscall_numbers.h which defines macro ltp_syscall() that turns undefined syscall numbers into ENOSYS.

The idea is to:

1) include sys/syscall.h to get the definitions system definitons

2) if your system headers are older (i.e. particular __NR_xxx is not defined) definitions from arch.in files are used

3) if __NR_xxx is not defined, there are stubs at the end of the header that defines the __NR_xxx to 0 which is then used by the ltp_syscall() macro to return -1 and set errno to ENOSYS

Signature · 12 lines
Cyril Hrubis
[email protected]

------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_mar
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

A message that is not in the archive (sent off-list or not yet received): CAG2jQ8hbT_8h8KR0V2=7qzwdSy8cqzOWb_oHt4JJ5Y22yFEeDg@mail.gmail.com

A message that is not in the archive (sent off-list or not yet received): CAG2jQ8j23+74_JZbrkM55aKg4YG+V-g4G1+NsS4fLGy=efRDjQ@mail.gmail.com

#8 lore raw

Hi!

Quoted 7 lines

I wrote patch that does what we talked about.

https://github.com/hwoarang/ltp/commit/3e361757a9cfd6c6af50a395c2de68777356a4b6

If you are happy with the way it is implemented, I will post it to the mailing list for further review.

The patch looks realtive good, please send it to he ML for review.

Signature · 12 lines
Cyril Hrubis
[email protected]

------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_mar
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list