Skip to contentSkip to conversation

System call design: preadv & pwritev.

PATCH In review Gerd Hoffmann 2 participants 6 messages Dec 18, 2008

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

v4 cover System call design: preadv & pwritev.

Hi folks,

Guess I have your attention now thanks to LWN ;)

Next round of the preadv & pwritev patch series, hopefully finally solving the architecture issues. I've decided to go with the suggestion from the s390 guys: split the 64bit offset into two explicitly coded 32bit halves. The syscall prototype should work now for all archs without (in-kernel) wrappers. glibc must wrap the syscalls though to hide that split from the applications. But there is no way around glibc wrappers anyway, so I think that is sensible decision.

cheers,
Gerd

--
To unsubscribe from this list: send the line "unsubscribe linux-api" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#1 lore raw

PATCH v4 1/3 Add missing accounting calls to compat_sys_{readv,writev}.

[ Note: unrelated bugfix spotted during preadv review,
included for completeness, akpm picked it into -mm already. ]

---
 fs/compat.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
fs/compat.c +6 -0
index e5f49f5..aab2234 100644
@@ -1187,6 +1187,9 @@ compat_sys_readv(unsigned long fd, const struct compat_iovec __user *vec, unsign
 	ret = compat_do_readv_writev(READ, file, vec, vlen, &file->f_pos);
 
 out:
+	if (ret > 0)
+		add_rchar(current, ret);
+	inc_syscr(current);
 	fput(file);
 	return ret;
 }
@@ -1210,6 +1213,9 @@ compat_sys_writev(unsigned long fd, const struct compat_iovec __user *vec, unsig
 	ret = compat_do_readv_writev(WRITE, file, vec, vlen, &file->f_pos);
 
 out:
+	if (ret > 0)
+		add_wchar(current, ret);
+	inc_syscw(current);
 	fput(file);
 	return ret;
 }
Signature · 1 line
1.5.6.5
#2 lore raw

PATCH v4 2/3 Add preadv and pwritev system calls.

In reply to Gerd Hoffmann

This patch adds preadv and pwritev system calls. These syscalls are a pretty straightforward combination of pread and readv (same for write). They are quite useful for doing vectored I/O in threaded applications. Using lseek+readv instead opens race windows you'll have to plug with locking.

Other systems have such system calls too, for example NetBSD, check
here: http://www.daemon-systems.org/man/preadv.2.html

The application-visible interface provided by glibc should look like this to be compatible to the existing implementations in the *BSD family:

ssize_t preadv(int d, const struct iovec *iov, int iovcnt, off_t offset); ssize_t pwritev(int d, const struct iovec *iov, int iovcnt, off_t offset);

This prototype has one problem though: On 32bit archs is the (64bit) offset argument unaligned, which the syscall ABI of several archs doesn't allow to do. At least s390 needs a wrapper in glibc to handle this. As we'll need a wrappers in glibc anyway I've decided to push problem to glibc entriely and use a syscall prototype which works without arch-specific wrappers inside the kernel: The offset argument is explicitly splitted into two 32bit values.

The patch sports the actual system call implementation and the windup in the x86 system call tables. Other archs follow as separate patches.

---
 arch/x86/ia32/ia32entry.S          |    2 +
 arch/x86/include/asm/unistd_32.h   |    2 +
 arch/x86/include/asm/unistd_64.h   |    4 ++
 arch/x86/kernel/syscall_table_32.S |    2 +
 fs/compat.c                        |   63 ++++++++++++++++++++++++++++++++++++
 fs/read_write.c                    |   50 ++++++++++++++++++++++++++++
 6 files changed, 123 insertions(+), 0 deletions(-)
arch/x86/ia32/ia32entry.S +2 -0
index 256b00b..9a8501b 100644
@@ -826,4 +826,6 @@ ia32_sys_call_table:
 	.quad sys_dup3			/* 330 */
 	.quad sys_pipe2
 	.quad sys_inotify_init1
+	.quad compat_sys_preadv
+	.quad compat_sys_pwritev
 ia32_syscall_end:
arch/x86/include/asm/unistd_32.h +2 -0
index f2bba78..6e72d74 100644
@@ -338,6 +338,8 @@
 #define __NR_dup3		330
 #define __NR_pipe2		331
 #define __NR_inotify_init1	332
+#define __NR_preadv		333
+#define __NR_pwritev		334
 
 #ifdef __KERNEL__
 
arch/x86/include/asm/unistd_64.h +4 -0
index d2e415e..f818294 100644
@@ -653,6 +653,10 @@ __SYSCALL(__NR_dup3, sys_dup3)
 __SYSCALL(__NR_pipe2, sys_pipe2)
 #define __NR_inotify_init1			294
 __SYSCALL(__NR_inotify_init1, sys_inotify_init1)
+#define __NR_preadv				295
+__SYSCALL(__NR_preadv, sys_preadv)
+#define __NR_pwritev				296
+__SYSCALL(__NR_pwritev, sys_pwritev)
 
 
 #ifndef __NO_STUBS
arch/x86/kernel/syscall_table_32.S +2 -0
index d44395f..a1a5506 100644
@@ -332,3 +332,5 @@ ENTRY(sys_call_table)
 	.long sys_dup3			/* 330 */
 	.long sys_pipe2
 	.long sys_inotify_init1
+	.long sys_preadv
+	.long sys_pwritev
fs/compat.c +63 -0

69 lines not on this page · raw message

fs/read_write.c +50 -0

56 lines not on this page · raw message

Signature · 1 line
1.5.6.5
maintainer
#3 lore raw

Re: [PATCH v4 2/3] Add preadv and pwritev system calls.

Quoted 7 lines · Gerd Hoffmann

This prototype has one problem though: On 32bit archs is the (64bit) offset argument unaligned, which the syscall ABI of several archs doesn't allow to do. At least s390 needs a wrapper in glibc to handle this. As we'll need a wrappers in glibc anyway I've decided to push problem to glibc entriely and use a syscall prototype which works without arch-specific wrappers inside the kernel: The offset argument is explicitly splitted into two 32bit values.

Obviously, the interface looks good to me now.

Please remember to add the function prototypes to
include/linux/syscalls.h.

fs/compat.c out: · line 1227

Quoted 5 lines
fs/compat.c +5 -0
+asmlinkage ssize_t
+compat_sys_preadv(unsigned long fd, const struct compat_iovec __user *vec,
+                  unsigned long vlen, u32 pos_high, u32 pos_low)
+{
+        loff_t pos = ((loff_t)pos_high << 32) | pos_low;

This is whitespace damaged, as are the other four functions in the same place.

fs/compat.c out: · line 1236

Quoted 9 lines
fs/compat.c +9 -0
+	struct file *file;
+	ssize_t ret = -EBADF;
+
+	if (pos < 0)
+		return -EINVAL;
+
+	file = fget(fd);
+	if (!file)
+		return -EBADF;

Any reason for using fget() here, but fget_light() in sys_preadv?

fs/compat.c out: · line 1243

Quoted 6 lines
fs/compat.c +6 -0
+	if (!(file->f_mode & FMODE_READ))
+		goto out;
+
+	ret = -EINVAL;
+	if (!file->f_op || (!file->f_op->aio_read && !file->f_op->read))
+		goto out;

Maybe this logic could get moved into a compat_readv() function, similar to vfs_readv(). The advantage would be that we can make the native and compat paths more similar.

	Arnd <><

--
To unsubscribe from this list: send the line "unsubscribe linux-api" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#4 lore raw

Re: [PATCH v4 2/3] Add preadv and pwritev system calls.

Hi,

Quoted 2 lines

Please remember to add the function prototypes to
include/linux/syscalls.h.

Done.

Quoted 8 lines

fs/compat.c out: · line 1227

Quoted 5 lines
fs/compat.c +5 -0
+asmlinkage ssize_t
+compat_sys_preadv(unsigned long fd, const struct compat_iovec __user *vec,
+                  unsigned long vlen, u32 pos_high, u32 pos_low)
+{.
+        loff_t pos = ((loff_t)pos_high << 32) | pos_low;

This is whitespace damaged, as are the other four functions in the same place.

Fixed.

Quoted 11 lines

fs/compat.c out: · line 1236

Quoted 9 lines
fs/compat.c +9 -0
+	struct file *file;
+	ssize_t ret = -EBADF;
+
+	if (pos < 0)
+		return -EINVAL;
+
+	file = fget(fd);
+	if (!file)
+		return -EBADF;

Any reason for using fget() here, but fget_light() in sys_preadv?

Due to the new syscalls being derived from the readv()/preadv() versions, which have the same inconsistency. Dunno why. I'd suspect the reason is that the compat syscalls tend to be overlooked when the code is updated. Proof: patch #1 in this series ...

I'll switch them all over in a separate followup patch.

Quoted 9 lines

fs/compat.c out: · line 1243

Quoted 6 lines
fs/compat.c +6 -0
+	if (!(file->f_mode & FMODE_READ))
+		goto out;
+
+	ret = -EINVAL;
+	if (!file->f_op || (!file->f_op->aio_read && !file->f_op->read))
+		goto out;

Maybe this logic could get moved into a compat_readv() function, similar to vfs_readv().

Yes, makes sense.

cheers,
Gerd

--
To unsubscribe from this list: send the line "unsubscribe linux-api" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#5 lore raw

PATCH v4 3/3 MIPS: Add preadv(2) and pwritev(2) syscalls.

In reply to Gerd Hoffmann

From: Ralf Baechle <[email protected]>

From: Ralf Baechle <[email protected]>

---
 arch/mips/include/asm/unistd.h |   18 ++++++++++++------
 arch/mips/kernel/scall32-o32.S |    2 ++
 arch/mips/kernel/scall64-64.S  |    2 ++
 arch/mips/kernel/scall64-n32.S |    2 ++
 arch/mips/kernel/scall64-o32.S |    2 ++
 5 files changed, 20 insertions(+), 6 deletions(-)
arch/mips/include/asm/unistd.h +12 -6
index a73e153..4000501 100644
@@ -350,16 +350,18 @@
 #define __NR_dup3			(__NR_Linux + 327)
 #define __NR_pipe2			(__NR_Linux + 328)
 #define __NR_inotify_init1		(__NR_Linux + 329)
+#define __NR_preadv			(__NR_Linux + 330)
+#define __NR_pwritev			(__NR_Linux + 331)
 
 /*
  * Offset of the last Linux o32 flavoured syscall
  */
-#define __NR_Linux_syscalls		329
+#define __NR_Linux_syscalls		331
 
 #endif /* _MIPS_SIM == _MIPS_SIM_ABI32 */
 
 #define __NR_O32_Linux			4000
-#define __NR_O32_Linux_syscalls		329
+#define __NR_O32_Linux_syscalls		331
 
 #if _MIPS_SIM == _MIPS_SIM_ABI64
 
@@ -656,16 +658,18 @@
 #define __NR_dup3			(__NR_Linux + 286)
 #define __NR_pipe2			(__NR_Linux + 287)
 #define __NR_inotify_init1		(__NR_Linux + 288)
+#define __NR_preadv			(__NR_Linux + 289)
+#define __NR_pwritev			(__NR_Linux + 290)
 
 /*
  * Offset of the last Linux 64-bit flavoured syscall
  */
-#define __NR_Linux_syscalls		288
+#define __NR_Linux_syscalls		290
 
 #endif /* _MIPS_SIM == _MIPS_SIM_ABI64 */
 
 #define __NR_64_Linux			5000
-#define __NR_64_Linux_syscalls		288
+#define __NR_64_Linux_syscalls		290
 
 #if _MIPS_SIM == _MIPS_SIM_NABI32
 
@@ -966,16 +970,18 @@
 #define __NR_dup3			(__NR_Linux + 290)
 #define __NR_pipe2			(__NR_Linux + 291)
 #define __NR_inotify_init1		(__NR_Linux + 292)
+#define __NR_preadv			(__NR_Linux + 293)
+#define __NR_pwritev			(__NR_Linux + 294)
 
 /*
  * Offset of the last N32 flavoured syscall
  */
-#define __NR_Linux_syscalls		292
+#define __NR_Linux_syscalls		294
 
 #endif /* _MIPS_SIM == _MIPS_SIM_NABI32 */
 
 #define __NR_N32_Linux			6000
-#define __NR_N32_Linux_syscalls		292
+#define __NR_N32_Linux_syscalls		294
 
 #ifdef __KERNEL__
 
arch/mips/kernel/scall32-o32.S +2 -0
index d0916a5..4a8b3e8 100644
@@ -650,6 +650,8 @@ einval:	li	v0, -ENOSYS
 	sys	sys_dup3		3
 	sys	sys_pipe2		2
 	sys	sys_inotify_init1	1
+	sys	sys_preadv		6	/* 4330 */
+	sys	sys_pwritev		6
 	.endm
 
 	/* We pre-compute the number of _instruction_ bytes needed to
arch/mips/kernel/scall64-64.S +2 -0
index a9e1716..217e3ce 100644
@@ -487,4 +487,6 @@ sys_call_table:
 	PTR	sys_dup3
 	PTR	sys_pipe2
 	PTR	sys_inotify_init1
+	PTR	sys_preadv
+	PTR	sys_pwritev			/* 5390 */
 	.size	sys_call_table,.-sys_call_table
arch/mips/kernel/scall64-n32.S +2 -0
index 30f3b63..f340963 100644
@@ -413,4 +413,6 @@ EXPORT(sysn32_call_table)
 	PTR	sys_dup3			/* 5290 */
 	PTR	sys_pipe2
 	PTR	sys_inotify_init1
+	PTR	sys_preadv
+	PTR	sys_pwritev
 	.size	sysn32_call_table,.-sysn32_call_table
arch/mips/kernel/scall64-o32.S +2 -0
index fefef4a..b1d281a 100644
@@ -533,4 +533,6 @@ sys_call_table:
 	PTR	sys_dup3
 	PTR	sys_pipe2
 	PTR	sys_inotify_init1
+	PTR	compat_sys_preadv		/* 4330 */
+	PTR	compat_sys_pwritev
 	.size	sys_call_table,.-sys_call_table
Signature · 1 line
1.5.6.5