diff options
author | Damien Zammit <damien@zamaudio.com> | 2020-11-09 18:09:06 +1100 |
---|---|---|
committer | Samuel Thibault <samuel.thibault@ens-lyon.org> | 2020-11-09 08:46:27 +0100 |
commit | 986c7a7d686a850830f9fc5bea1fadcfe9f4999c (patch) | |
tree | 74b3cc6724f464ef8f75dd9cb977d83d601df766 /rumpdisk | |
parent | cf99ce09b4b2487d557860b794dbd1b57a9f035b (diff) | |
download | hurd-986c7a7d686a850830f9fc5bea1fadcfe9f4999c.tar.gz hurd-986c7a7d686a850830f9fc5bea1fadcfe9f4999c.tar.bz2 hurd-986c7a7d686a850830f9fc5bea1fadcfe9f4999c.zip |
rumpdisk: Use rump_sys_pread/pwrite instead of lseek+r/w for atomic accesses
TESTED by booting a QEMU passthrough disk via rumpdisk.static
Message-Id: <20201109070906.20796-1-damien@zamaudio.com>
Diffstat (limited to 'rumpdisk')
-rw-r--r-- | rumpdisk/block-rump.c | 21 |
1 files changed, 4 insertions, 17 deletions
diff --git a/rumpdisk/block-rump.c b/rumpdisk/block-rump.c index e094a199..f7444260 100644 --- a/rumpdisk/block-rump.c +++ b/rumpdisk/block-rump.c @@ -248,18 +248,12 @@ device_write (void *d, mach_port_t reply_port, int *bytes_written) { struct block_data *bd = d; - int64_t written = 0; + ssize_t written; if ((bd->mode & D_WRITE) == 0) return D_INVALID_OPERATION; - if (rump_sys_lseek (bd->rump_fd, (off_t) bn * bd->block_size, SEEK_SET) < 0) - { - *bytes_written = 0; - return EIO; - } - - written = rump_sys_write (bd->rump_fd, data, count); + written = rump_sys_pwrite (bd->rump_fd, (const void *)data, (size_t)count, (off_t)bn * bd->block_size); if (written < 0) { *bytes_written = 0; @@ -282,7 +276,7 @@ device_read (void *d, mach_port_t reply_port, char *buf; int pagesize = sysconf (_SC_PAGE_SIZE); int npages = (count + pagesize - 1) / pagesize; - io_return_t err = D_SUCCESS; + ssize_t err; if ((bd->mode & D_READ) == 0) return D_INVALID_OPERATION; @@ -296,13 +290,7 @@ device_read (void *d, mach_port_t reply_port, if (buf == MAP_FAILED) return errno; - if (rump_sys_lseek (bd->rump_fd, (off_t) bn * bd->block_size, SEEK_SET) < 0) - { - *bytes_read = 0; - return EIO; - } - - err = rump_sys_read (bd->rump_fd, buf, count); + err = rump_sys_pread (bd->rump_fd, (void *)buf, (size_t)count, (off_t)bn * bd->block_size); if (err < 0) { *bytes_read = 0; @@ -346,7 +334,6 @@ device_get_status (void *d, dev_flavor_t flavor, dev_status_t status, /* FIXME: * Short term strategy: * - * Use rump_sys_pread/pwrite instead of rump_sys_lseek + rump_sys_read/write. * Make device_read/write multithreaded. * * Long term strategy: |