Use preadv/pwritev instead of readv/writev
PATCH 1/1 Use preadv/pwritev instead of readv/writev
readv & writev, read & write respectively from the current offset
of the file & hence their use has to be preceeded by a call to lseek. preadv/writev can be used instead, as they take the offset as an argument. This saves one system call( lseek ).
In case preadv is not supported, it is implemented by an lseek followed by a readv. Depending upon the configuration of QEMU, the appropriate read & write methods are selected. This patch also fixes the zero byte read/write bug & obviates the need to apply a fix for that bug separately.
Signed-off-by M. Mohan Kumar <[email protected]>
Signed-off-by Sanchit Garg <[email protected]>
--- hw/file-op-9p.h | 5 +- hw/virtio-9p-local.c | 48 +++++++++++++++------ hw/virtio-9p.c | 116 +++++++++++++++++--------------------------------- 3 files changed, 75 insertions(+), 94 deletions(-)
hw/file-op-9p.h +2 -3
@@ -77,9 +77,8 @@ typedef struct FileOperationsoff_t (*telldir)(FsContext *,DIR *);struct dirent *(*readdir)(FsContext *,DIR *);void (*seekdir)(FsContext *,DIR *,off_t ); -ssize_t (*readv)(FsContext *,int ,const struct iovec *,int ); -ssize_t (*writev)(FsContext *,int ,const struct iovec *,int ); -off_t (*lseek)(FsContext *,int ,off_t ,int ); +ssize_t (*preadv)(FsContext *,int ,const struct iovec *,int ,off_t ); +ssize_t (*pwritev)(FsContext *,int ,const struct iovec *,int ,off_t );int (*mkdir)(FsContext *,const char *,FsCred *);int (*fstat)(FsContext *,int ,struct stat *);int (*rename)(FsContext *,const char *,const char *);
hw/virtio-9p-local.c +34 -14
64 lines not on this page · raw message
hw/virtio-9p.c +39 -77
186 lines not on this page · raw message