Skip to contentSkip to conversation

Add preadv and pwritev system calls.

RFC/PATCH Gerd Hoffmann 2 participants 3 messages Dec 11, 2008 – Dec 12, 2008

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

Hi,

The attached 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 patch sports the actual system call implementation and the windup in the x86 system call tables. Other archs are TBD.

Comments? Reviews? Suggestions? Flames?

cheers,
Gerd

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 +49 -0

55 lines not on this page · raw message

fs/read_write.c +48 -0

54 lines not on this page · raw message

#1 lore raw
Quoted 8 lines · Gerd Hoffmann

Hi,

The attached 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.

Quoted 7 lines

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

The patch sports the actual system call implementation and the windup in the x86 system call tables. Other archs are TBD.

Comments? Reviews? Suggestions? Flames?

Looks good, but you should Cc linux-arch so that arch maintainers get a heads up to wire up the syscalls.

fs/read_write.c sys_writev(unsigned long fd, const struct iovec __user *vec, unsigned long vlen) · line 725

Quoted 4 lines
fs/read_write.c +4 -0
+	if (ret > 0)
+		add_rchar(current, ret);
+	inc_syscr(current);
+	return ret;

Could it be that these are missing for the compat case both for the existing readv/writev and your new syscalls?

#2 lore raw
Quoted 3 lines · Christoph Hellwig

Looks good, but you should Cc linux-arch so that arch maintainers get a heads up to wire up the syscalls.

Will do for the next version.

Quoted 7 lines

fs/read_write.c sys_writev(unsigned long fd, const struct iovec __user *vec, unsigned long vlen) · line 725

Quoted 4 lines
fs/read_write.c +4 -0
+	if (ret > 0)
+		add_rchar(current, ret);
+	inc_syscr(current);
+	return ret;

Could it be that these are missing for the compat case both for the existing readv/writev and your new syscalls?

Yep, seems so, I can't spot them anywhere in compat.c. I'll sort that too.

thanks,
Gerd