Skip to contentSkip to conversation

Support for preadv()/pwritev()

RFC PATCH New Badari Pulavarty 1 participant 1 message Dec 9, 2005 VFS

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 Support for preadv()/pwritev()

Hi,

Some of the database folks are looking going towards "threaded" database model and wants support for preadv() and pwritev() - so that they have a way of doing lseek() followed by readv/writev() in the thread-safe way.

Here is the patch I cooked up and looking for feedback. I really don't like adding new syscalls for this, but I don't see a way out.

Of course, database folks want aio_readv/aio_writev() support also, which Zack is working on.

Comments ? Suggestions ?

Thanks,
Badari

arch/i386/kernel/syscall_table.S +2 -0
diff -Narup -X dontdiff linux-2.6.15-rc5/arch/i386/kernel/syscall_table.S linux-2.6.15-rc5.preadv/arch/i386/kernel/syscall_table.S
@@ -294,3 +294,5 @@ ENTRY(sys_call_table)
 	.long sys_inotify_init
 	.long sys_inotify_add_watch
 	.long sys_inotify_rm_watch
+	.long sys_preadv
+	.long sys_pwritev
fs/read_write.c +40 -0
diff -Narup -X dontdiff linux-2.6.15-rc5/fs/read_write.c linux-2.6.15-rc5.preadv/fs/read_write.c
@@ -622,6 +622,46 @@ sys_writev(unsigned long fd, const struc
 	return ret;
 }
 
+asmlinkage ssize_t sys_preadv(unsigned int fd, const struct iovec __user *vec,
+			     unsigned long vlen, loff_t pos)
+{
+	struct file *file;
+	ssize_t ret = -EBADF;
+	int fput_needed;
+
+	if (pos < 0)
+		return -EINVAL;
+
+	file = fget_light(fd, &fput_needed);
+	if (file) {
+		ret = -ESPIPE;
+		if (file->f_mode & FMODE_PREAD)
+			ret = vfs_readv(file, vec, vlen, &pos);
+		fput_light(file, fput_needed);
+	}
+	return ret;
+}
+
+asmlinkage ssize_t sys_pwritev(unsigned int fd, const struct iovec __user *vec,
+			     unsigned long vlen, loff_t pos)
+{
+	struct file *file;
+	ssize_t ret = -EBADF;
+	int fput_needed;
+
+	if (pos < 0)
+		return -EINVAL;
+
+	file = fget_light(fd, &fput_needed);
+	if (file) {
+		ret = -ESPIPE;
+		if (file->f_mode & FMODE_PWRITE)  
+			ret = vfs_writev(file, vec, vlen, &pos);
+		fput_light(file, fput_needed);
+	}
+	return ret;
+}
+
 static ssize_t do_sendfile(int out_fd, int in_fd, loff_t *ppos,
 			   size_t count, loff_t max)
 {