diff options
| author | Anton Ivanov <aivanov@brocade.com> | 2015-12-21 13:54:00 -0500 |
|---|---|---|
| committer | Richard Weinberger <richard@nod.at> | 2016-01-10 15:49:48 -0500 |
| commit | 8c6157b6b30a765ec233a1be5f9446f24a5283de (patch) | |
| tree | 81128a9f0252bd4075b6093cf5408eab19d45ce4 /arch/um | |
| parent | 470a166e8c5a4da4be88545b1c4dde308abac5b2 (diff) | |
um: Update UBD to use pread/pwrite family of functions
This decreases the number of syscalls per read/write by half.
Signed-off-by: Anton Ivanov <aivanov@brocade.com>
Signed-off-by: Richard Weinberger <richard@nod.at>
Diffstat (limited to 'arch/um')
| -rw-r--r-- | arch/um/drivers/ubd_kern.c | 27 | ||||
| -rw-r--r-- | arch/um/include/shared/os.h | 2 | ||||
| -rw-r--r-- | arch/um/os-Linux/file.c | 19 |
3 files changed, 26 insertions, 22 deletions
diff --git a/arch/um/drivers/ubd_kern.c b/arch/um/drivers/ubd_kern.c index e8ab93c3e638..39ba20755e03 100644 --- a/arch/um/drivers/ubd_kern.c +++ b/arch/um/drivers/ubd_kern.c | |||
| @@ -535,11 +535,7 @@ static int read_cow_bitmap(int fd, void *buf, int offset, int len) | |||
| 535 | { | 535 | { |
| 536 | int err; | 536 | int err; |
| 537 | 537 | ||
| 538 | err = os_seek_file(fd, offset); | 538 | err = os_pread_file(fd, buf, len, offset); |
| 539 | if (err < 0) | ||
| 540 | return err; | ||
| 541 | |||
| 542 | err = os_read_file(fd, buf, len); | ||
| 543 | if (err < 0) | 539 | if (err < 0) |
| 544 | return err; | 540 | return err; |
| 545 | 541 | ||
| @@ -1377,14 +1373,8 @@ static int update_bitmap(struct io_thread_req *req) | |||
| 1377 | if(req->cow_offset == -1) | 1373 | if(req->cow_offset == -1) |
| 1378 | return 0; | 1374 | return 0; |
| 1379 | 1375 | ||
| 1380 | n = os_seek_file(req->fds[1], req->cow_offset); | 1376 | n = os_pwrite_file(req->fds[1], &req->bitmap_words, |
| 1381 | if(n < 0){ | 1377 | sizeof(req->bitmap_words), req->cow_offset); |
| 1382 | printk("do_io - bitmap lseek failed : err = %d\n", -n); | ||
| 1383 | return 1; | ||
| 1384 | } | ||
| 1385 | |||
| 1386 | n = os_write_file(req->fds[1], &req->bitmap_words, | ||
| 1387 | sizeof(req->bitmap_words)); | ||
| 1388 | if(n != sizeof(req->bitmap_words)){ | 1378 | if(n != sizeof(req->bitmap_words)){ |
| 1389 | printk("do_io - bitmap update failed, err = %d fd = %d\n", -n, | 1379 | printk("do_io - bitmap update failed, err = %d fd = %d\n", -n, |
| 1390 | req->fds[1]); | 1380 | req->fds[1]); |
| @@ -1399,7 +1389,6 @@ static void do_io(struct io_thread_req *req) | |||
| 1399 | char *buf; | 1389 | char *buf; |
| 1400 | unsigned long len; | 1390 | unsigned long len; |
| 1401 | int n, nsectors, start, end, bit; | 1391 | int n, nsectors, start, end, bit; |
| 1402 | int err; | ||
| 1403 | __u64 off; | 1392 | __u64 off; |
| 1404 | 1393 | ||
| 1405 | if (req->op == UBD_FLUSH) { | 1394 | if (req->op == UBD_FLUSH) { |
| @@ -1428,18 +1417,12 @@ static void do_io(struct io_thread_req *req) | |||
| 1428 | len = (end - start) * req->sectorsize; | 1417 | len = (end - start) * req->sectorsize; |
| 1429 | buf = &req->buffer[start * req->sectorsize]; | 1418 | buf = &req->buffer[start * req->sectorsize]; |
| 1430 | 1419 | ||
| 1431 | err = os_seek_file(req->fds[bit], off); | ||
| 1432 | if(err < 0){ | ||
| 1433 | printk("do_io - lseek failed : err = %d\n", -err); | ||
| 1434 | req->error = 1; | ||
| 1435 | return; | ||
| 1436 | } | ||
| 1437 | if(req->op == UBD_READ){ | 1420 | if(req->op == UBD_READ){ |
| 1438 | n = 0; | 1421 | n = 0; |
| 1439 | do { | 1422 | do { |
| 1440 | buf = &buf[n]; | 1423 | buf = &buf[n]; |
| 1441 | len -= n; | 1424 | len -= n; |
| 1442 | n = os_read_file(req->fds[bit], buf, len); | 1425 | n = os_pread_file(req->fds[bit], buf, len, off); |
| 1443 | if (n < 0) { | 1426 | if (n < 0) { |
| 1444 | printk("do_io - read failed, err = %d " | 1427 | printk("do_io - read failed, err = %d " |
| 1445 | "fd = %d\n", -n, req->fds[bit]); | 1428 | "fd = %d\n", -n, req->fds[bit]); |
| @@ -1449,7 +1432,7 @@ static void do_io(struct io_thread_req *req) | |||
| 1449 | } while((n < len) && (n != 0)); | 1432 | } while((n < len) && (n != 0)); |
| 1450 | if (n < len) memset(&buf[n], 0, len - n); | 1433 | if (n < len) memset(&buf[n], 0, len - n); |
| 1451 | } else { | 1434 | } else { |
| 1452 | n = os_write_file(req->fds[bit], buf, len); | 1435 | n = os_pwrite_file(req->fds[bit], buf, len, off); |
| 1453 | if(n != len){ | 1436 | if(n != len){ |
| 1454 | printk("do_io - write failed err = %d " | 1437 | printk("do_io - write failed err = %d " |
| 1455 | "fd = %d\n", -n, req->fds[bit]); | 1438 | "fd = %d\n", -n, req->fds[bit]); |
diff --git a/arch/um/include/shared/os.h b/arch/um/include/shared/os.h index 868e6c3f83dd..7a04ddd85334 100644 --- a/arch/um/include/shared/os.h +++ b/arch/um/include/shared/os.h | |||
| @@ -146,6 +146,8 @@ extern int os_read_file(int fd, void *buf, int len); | |||
| 146 | extern int os_write_file(int fd, const void *buf, int count); | 146 | extern int os_write_file(int fd, const void *buf, int count); |
| 147 | extern int os_sync_file(int fd); | 147 | extern int os_sync_file(int fd); |
| 148 | extern int os_file_size(const char *file, unsigned long long *size_out); | 148 | extern int os_file_size(const char *file, unsigned long long *size_out); |
| 149 | extern int os_pread_file(int fd, void *buf, int len, unsigned long long offset); | ||
| 150 | extern int os_pwrite_file(int fd, const void *buf, int count, unsigned long long offset); | ||
| 149 | extern int os_file_modtime(const char *file, unsigned long *modtime); | 151 | extern int os_file_modtime(const char *file, unsigned long *modtime); |
| 150 | extern int os_pipe(int *fd, int stream, int close_on_exec); | 152 | extern int os_pipe(int *fd, int stream, int close_on_exec); |
| 151 | extern int os_set_fd_async(int fd); | 153 | extern int os_set_fd_async(int fd); |
diff --git a/arch/um/os-Linux/file.c b/arch/um/os-Linux/file.c index 26e0164895e4..2db18cbbb0ea 100644 --- a/arch/um/os-Linux/file.c +++ b/arch/um/os-Linux/file.c | |||
| @@ -264,6 +264,15 @@ int os_read_file(int fd, void *buf, int len) | |||
| 264 | return n; | 264 | return n; |
| 265 | } | 265 | } |
| 266 | 266 | ||
| 267 | int os_pread_file(int fd, void *buf, int len, unsigned long long offset) | ||
| 268 | { | ||
| 269 | int n = pread(fd, buf, len, offset); | ||
| 270 | |||
| 271 | if (n < 0) | ||
| 272 | return -errno; | ||
| 273 | return n; | ||
| 274 | } | ||
| 275 | |||
| 267 | int os_write_file(int fd, const void *buf, int len) | 276 | int os_write_file(int fd, const void *buf, int len) |
| 268 | { | 277 | { |
| 269 | int n = write(fd, (void *) buf, len); | 278 | int n = write(fd, (void *) buf, len); |
| @@ -282,6 +291,16 @@ int os_sync_file(int fd) | |||
| 282 | return n; | 291 | return n; |
| 283 | } | 292 | } |
| 284 | 293 | ||
| 294 | int os_pwrite_file(int fd, const void *buf, int len, unsigned long long offset) | ||
| 295 | { | ||
| 296 | int n = pwrite(fd, (void *) buf, len, offset); | ||
| 297 | |||
| 298 | if (n < 0) | ||
| 299 | return -errno; | ||
| 300 | return n; | ||
| 301 | } | ||
| 302 | |||
| 303 | |||
| 285 | int os_file_size(const char *file, unsigned long long *size_out) | 304 | int os_file_size(const char *file, unsigned long long *size_out) |
| 286 | { | 305 | { |
| 287 | struct uml_stat buf; | 306 | struct uml_stat buf; |
