Commit eda578e559879b1a6a85f924adf2942070ae7ec3
1 parent
04eeb8b6
Drop internal bdrv_pread()/bdrv_pwrite() APIs (Avi Kivity)
Now that scsi generic no longer uses bdrv_pread() and bdrv_pwrite(), we can drop the corresponding internal APIs, which overlap bdrv_read()/bdrv_write() and, being byte oriented, are unnatural for a block device. Signed-off-by: Avi Kivity <avi@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6824 c046a42c-6fe2-441c-8c8c-71466251a162
Showing
4 changed files
with
34 additions
and
89 deletions
block-raw-posix.c
@@ -358,6 +358,12 @@ static int raw_pread(BlockDriverState *bs, int64_t offset, | @@ -358,6 +358,12 @@ static int raw_pread(BlockDriverState *bs, int64_t offset, | ||
358 | return raw_pread_aligned(bs, offset, buf, count) + sum; | 358 | return raw_pread_aligned(bs, offset, buf, count) + sum; |
359 | } | 359 | } |
360 | 360 | ||
361 | +static int raw_read(BlockDriverState *bs, int64_t sector_num, | ||
362 | + uint8_t *buf, int nb_sectors) | ||
363 | +{ | ||
364 | + return raw_pread(bs, sector_num * 512, buf, (uint64_t)nb_sectors * 512); | ||
365 | +} | ||
366 | + | ||
361 | /* | 367 | /* |
362 | * offset and count are in bytes and possibly not aligned. For files opened | 368 | * offset and count are in bytes and possibly not aligned. For files opened |
363 | * with O_DIRECT, necessary alignments are ensured before calling | 369 | * with O_DIRECT, necessary alignments are ensured before calling |
@@ -436,6 +442,12 @@ static int raw_pwrite(BlockDriverState *bs, int64_t offset, | @@ -436,6 +442,12 @@ static int raw_pwrite(BlockDriverState *bs, int64_t offset, | ||
436 | return raw_pwrite_aligned(bs, offset, buf, count) + sum; | 442 | return raw_pwrite_aligned(bs, offset, buf, count) + sum; |
437 | } | 443 | } |
438 | 444 | ||
445 | +static int raw_write(BlockDriverState *bs, int64_t sector_num, | ||
446 | + const uint8_t *buf, int nb_sectors) | ||
447 | +{ | ||
448 | + return raw_pwrite(bs, sector_num * 512, buf, (uint64_t)nb_sectors * 512); | ||
449 | +} | ||
450 | + | ||
439 | #ifdef CONFIG_AIO | 451 | #ifdef CONFIG_AIO |
440 | /***********************************************************/ | 452 | /***********************************************************/ |
441 | /* Unix AIO using POSIX AIO */ | 453 | /* Unix AIO using POSIX AIO */ |
@@ -843,8 +855,8 @@ BlockDriver bdrv_raw = { | @@ -843,8 +855,8 @@ BlockDriver bdrv_raw = { | ||
843 | .aiocb_size = sizeof(RawAIOCB), | 855 | .aiocb_size = sizeof(RawAIOCB), |
844 | #endif | 856 | #endif |
845 | 857 | ||
846 | - .bdrv_pread = raw_pread, | ||
847 | - .bdrv_pwrite = raw_pwrite, | 858 | + .bdrv_read = raw_read, |
859 | + .bdrv_write = raw_write, | ||
848 | .bdrv_truncate = raw_truncate, | 860 | .bdrv_truncate = raw_truncate, |
849 | .bdrv_getlength = raw_getlength, | 861 | .bdrv_getlength = raw_getlength, |
850 | }; | 862 | }; |
@@ -1219,8 +1231,8 @@ BlockDriver bdrv_host_device = { | @@ -1219,8 +1231,8 @@ BlockDriver bdrv_host_device = { | ||
1219 | .aiocb_size = sizeof(RawAIOCB), | 1231 | .aiocb_size = sizeof(RawAIOCB), |
1220 | #endif | 1232 | #endif |
1221 | 1233 | ||
1222 | - .bdrv_pread = raw_pread, | ||
1223 | - .bdrv_pwrite = raw_pwrite, | 1234 | + .bdrv_read = raw_read, |
1235 | + .bdrv_write = raw_write, | ||
1224 | .bdrv_getlength = raw_getlength, | 1236 | .bdrv_getlength = raw_getlength, |
1225 | 1237 | ||
1226 | /* removable device support */ | 1238 | /* removable device support */ |
block-raw-win32.c
@@ -122,13 +122,15 @@ static int raw_open(BlockDriverState *bs, const char *filename, int flags) | @@ -122,13 +122,15 @@ static int raw_open(BlockDriverState *bs, const char *filename, int flags) | ||
122 | return 0; | 122 | return 0; |
123 | } | 123 | } |
124 | 124 | ||
125 | -static int raw_pread(BlockDriverState *bs, int64_t offset, | ||
126 | - uint8_t *buf, int count) | 125 | +static int raw_read(BlockDriverState *bs, int64_t sector_num, |
126 | + uint8_t *buf, int nb_sectors) | ||
127 | { | 127 | { |
128 | BDRVRawState *s = bs->opaque; | 128 | BDRVRawState *s = bs->opaque; |
129 | OVERLAPPED ov; | 129 | OVERLAPPED ov; |
130 | DWORD ret_count; | 130 | DWORD ret_count; |
131 | int ret; | 131 | int ret; |
132 | + int64_t offset = sector_num * 512; | ||
133 | + int count = nb_sectors * 512; | ||
132 | 134 | ||
133 | memset(&ov, 0, sizeof(ov)); | 135 | memset(&ov, 0, sizeof(ov)); |
134 | ov.Offset = offset; | 136 | ov.Offset = offset; |
@@ -146,13 +148,15 @@ static int raw_pread(BlockDriverState *bs, int64_t offset, | @@ -146,13 +148,15 @@ static int raw_pread(BlockDriverState *bs, int64_t offset, | ||
146 | return ret_count; | 148 | return ret_count; |
147 | } | 149 | } |
148 | 150 | ||
149 | -static int raw_pwrite(BlockDriverState *bs, int64_t offset, | ||
150 | - const uint8_t *buf, int count) | 151 | +static int raw_write(BlockDriverState *bs, int64_t sector_num, |
152 | + const uint8_t *buf, int nb_sectors) | ||
151 | { | 153 | { |
152 | BDRVRawState *s = bs->opaque; | 154 | BDRVRawState *s = bs->opaque; |
153 | OVERLAPPED ov; | 155 | OVERLAPPED ov; |
154 | DWORD ret_count; | 156 | DWORD ret_count; |
155 | int ret; | 157 | int ret; |
158 | + int64_t offset = sector_num * 512; | ||
159 | + int count = nb_sectors * 512; | ||
156 | 160 | ||
157 | memset(&ov, 0, sizeof(ov)); | 161 | memset(&ov, 0, sizeof(ov)); |
158 | ov.Offset = offset; | 162 | ov.Offset = offset; |
@@ -359,8 +363,8 @@ BlockDriver bdrv_raw = { | @@ -359,8 +363,8 @@ BlockDriver bdrv_raw = { | ||
359 | .bdrv_aio_cancel = raw_aio_cancel, | 363 | .bdrv_aio_cancel = raw_aio_cancel, |
360 | .aiocb_size = sizeof(RawAIOCB); | 364 | .aiocb_size = sizeof(RawAIOCB); |
361 | #endif | 365 | #endif |
362 | - .bdrv_pread = raw_pread, | ||
363 | - .bdrv_pwrite = raw_pwrite, | 366 | + .bdrv_read = raw_read, |
367 | + .bdrv_write = raw_write, | ||
364 | .bdrv_truncate = raw_truncate, | 368 | .bdrv_truncate = raw_truncate, |
365 | .bdrv_getlength = raw_getlength, | 369 | .bdrv_getlength = raw_getlength, |
366 | }; | 370 | }; |
@@ -508,7 +512,7 @@ BlockDriver bdrv_host_device = { | @@ -508,7 +512,7 @@ BlockDriver bdrv_host_device = { | ||
508 | .bdrv_aio_cancel = raw_aio_cancel, | 512 | .bdrv_aio_cancel = raw_aio_cancel, |
509 | .aiocb_size = sizeof(RawAIOCB); | 513 | .aiocb_size = sizeof(RawAIOCB); |
510 | #endif | 514 | #endif |
511 | - .bdrv_pread = raw_pread, | ||
512 | - .bdrv_pwrite = raw_pwrite, | 515 | + .bdrv_read = raw_read, |
516 | + .bdrv_write = raw_write, | ||
513 | .bdrv_getlength = raw_getlength, | 517 | .bdrv_getlength = raw_getlength, |
514 | }; | 518 | }; |
block.c
@@ -142,7 +142,7 @@ static void bdrv_register(BlockDriver *bdrv) | @@ -142,7 +142,7 @@ static void bdrv_register(BlockDriver *bdrv) | ||
142 | bdrv->bdrv_aio_write = bdrv_aio_write_em; | 142 | bdrv->bdrv_aio_write = bdrv_aio_write_em; |
143 | bdrv->bdrv_aio_cancel = bdrv_aio_cancel_em; | 143 | bdrv->bdrv_aio_cancel = bdrv_aio_cancel_em; |
144 | bdrv->aiocb_size = sizeof(BlockDriverAIOCBSync); | 144 | bdrv->aiocb_size = sizeof(BlockDriverAIOCBSync); |
145 | - } else if (!bdrv->bdrv_read && !bdrv->bdrv_pread) { | 145 | + } else if (!bdrv->bdrv_read) { |
146 | /* add synchronous IO emulation layer */ | 146 | /* add synchronous IO emulation layer */ |
147 | bdrv->bdrv_read = bdrv_read_em; | 147 | bdrv->bdrv_read = bdrv_read_em; |
148 | bdrv->bdrv_write = bdrv_write_em; | 148 | bdrv->bdrv_write = bdrv_write_em; |
@@ -568,22 +568,7 @@ int bdrv_read(BlockDriverState *bs, int64_t sector_num, | @@ -568,22 +568,7 @@ int bdrv_read(BlockDriverState *bs, int64_t sector_num, | ||
568 | if (bdrv_check_request(bs, sector_num, nb_sectors)) | 568 | if (bdrv_check_request(bs, sector_num, nb_sectors)) |
569 | return -EIO; | 569 | return -EIO; |
570 | 570 | ||
571 | - if (drv->bdrv_pread) { | ||
572 | - int ret, len; | ||
573 | - len = nb_sectors * 512; | ||
574 | - ret = drv->bdrv_pread(bs, sector_num * 512, buf, len); | ||
575 | - if (ret < 0) | ||
576 | - return ret; | ||
577 | - else if (ret != len) | ||
578 | - return -EINVAL; | ||
579 | - else { | ||
580 | - bs->rd_bytes += (unsigned) len; | ||
581 | - bs->rd_ops ++; | ||
582 | - return 0; | ||
583 | - } | ||
584 | - } else { | ||
585 | - return drv->bdrv_read(bs, sector_num, buf, nb_sectors); | ||
586 | - } | 571 | + return drv->bdrv_read(bs, sector_num, buf, nb_sectors); |
587 | } | 572 | } |
588 | 573 | ||
589 | /* Return < 0 if error. Important errors are: | 574 | /* Return < 0 if error. Important errors are: |
@@ -603,27 +588,11 @@ int bdrv_write(BlockDriverState *bs, int64_t sector_num, | @@ -603,27 +588,11 @@ int bdrv_write(BlockDriverState *bs, int64_t sector_num, | ||
603 | if (bdrv_check_request(bs, sector_num, nb_sectors)) | 588 | if (bdrv_check_request(bs, sector_num, nb_sectors)) |
604 | return -EIO; | 589 | return -EIO; |
605 | 590 | ||
606 | - if (drv->bdrv_pwrite) { | ||
607 | - int ret, len, count = 0; | ||
608 | - len = nb_sectors * 512; | ||
609 | - do { | ||
610 | - ret = drv->bdrv_pwrite(bs, sector_num * 512, buf, len - count); | ||
611 | - if (ret < 0) { | ||
612 | - printf("bdrv_write ret=%d\n", ret); | ||
613 | - return ret; | ||
614 | - } | ||
615 | - count += ret; | ||
616 | - buf += ret; | ||
617 | - } while (count != len); | ||
618 | - bs->wr_bytes += (unsigned) len; | ||
619 | - bs->wr_ops ++; | ||
620 | - return 0; | ||
621 | - } | ||
622 | return drv->bdrv_write(bs, sector_num, buf, nb_sectors); | 591 | return drv->bdrv_write(bs, sector_num, buf, nb_sectors); |
623 | } | 592 | } |
624 | 593 | ||
625 | -static int bdrv_pread_em(BlockDriverState *bs, int64_t offset, | ||
626 | - uint8_t *buf, int count1) | 594 | +int bdrv_pread(BlockDriverState *bs, int64_t offset, |
595 | + void *buf, int count1) | ||
627 | { | 596 | { |
628 | uint8_t tmp_buf[SECTOR_SIZE]; | 597 | uint8_t tmp_buf[SECTOR_SIZE]; |
629 | int len, nb_sectors, count; | 598 | int len, nb_sectors, count; |
@@ -666,8 +635,8 @@ static int bdrv_pread_em(BlockDriverState *bs, int64_t offset, | @@ -666,8 +635,8 @@ static int bdrv_pread_em(BlockDriverState *bs, int64_t offset, | ||
666 | return count1; | 635 | return count1; |
667 | } | 636 | } |
668 | 637 | ||
669 | -static int bdrv_pwrite_em(BlockDriverState *bs, int64_t offset, | ||
670 | - const uint8_t *buf, int count1) | 638 | +int bdrv_pwrite(BlockDriverState *bs, int64_t offset, |
639 | + const void *buf, int count1) | ||
671 | { | 640 | { |
672 | uint8_t tmp_buf[SECTOR_SIZE]; | 641 | uint8_t tmp_buf[SECTOR_SIZE]; |
673 | int len, nb_sectors, count; | 642 | int len, nb_sectors, count; |
@@ -715,42 +684,6 @@ static int bdrv_pwrite_em(BlockDriverState *bs, int64_t offset, | @@ -715,42 +684,6 @@ static int bdrv_pwrite_em(BlockDriverState *bs, int64_t offset, | ||
715 | } | 684 | } |
716 | 685 | ||
717 | /** | 686 | /** |
718 | - * Read with byte offsets (needed only for file protocols) | ||
719 | - */ | ||
720 | -int bdrv_pread(BlockDriverState *bs, int64_t offset, | ||
721 | - void *buf1, int count1) | ||
722 | -{ | ||
723 | - BlockDriver *drv = bs->drv; | ||
724 | - | ||
725 | - if (!drv) | ||
726 | - return -ENOMEDIUM; | ||
727 | - if (bdrv_check_byte_request(bs, offset, count1)) | ||
728 | - return -EIO; | ||
729 | - | ||
730 | - if (!drv->bdrv_pread) | ||
731 | - return bdrv_pread_em(bs, offset, buf1, count1); | ||
732 | - return drv->bdrv_pread(bs, offset, buf1, count1); | ||
733 | -} | ||
734 | - | ||
735 | -/** | ||
736 | - * Write with byte offsets (needed only for file protocols) | ||
737 | - */ | ||
738 | -int bdrv_pwrite(BlockDriverState *bs, int64_t offset, | ||
739 | - const void *buf1, int count1) | ||
740 | -{ | ||
741 | - BlockDriver *drv = bs->drv; | ||
742 | - | ||
743 | - if (!drv) | ||
744 | - return -ENOMEDIUM; | ||
745 | - if (bdrv_check_byte_request(bs, offset, count1)) | ||
746 | - return -EIO; | ||
747 | - | ||
748 | - if (!drv->bdrv_pwrite) | ||
749 | - return bdrv_pwrite_em(bs, offset, buf1, count1); | ||
750 | - return drv->bdrv_pwrite(bs, offset, buf1, count1); | ||
751 | -} | ||
752 | - | ||
753 | -/** | ||
754 | * Truncate file to 'offset' bytes (needed only for file protocols) | 687 | * Truncate file to 'offset' bytes (needed only for file protocols) |
755 | */ | 688 | */ |
756 | int bdrv_truncate(BlockDriverState *bs, int64_t offset) | 689 | int bdrv_truncate(BlockDriverState *bs, int64_t offset) |
block_int.h
@@ -58,10 +58,6 @@ struct BlockDriver { | @@ -58,10 +58,6 @@ struct BlockDriver { | ||
58 | int aiocb_size; | 58 | int aiocb_size; |
59 | 59 | ||
60 | const char *protocol_name; | 60 | const char *protocol_name; |
61 | - int (*bdrv_pread)(BlockDriverState *bs, int64_t offset, | ||
62 | - uint8_t *buf, int count); | ||
63 | - int (*bdrv_pwrite)(BlockDriverState *bs, int64_t offset, | ||
64 | - const uint8_t *buf, int count); | ||
65 | int (*bdrv_truncate)(BlockDriverState *bs, int64_t offset); | 61 | int (*bdrv_truncate)(BlockDriverState *bs, int64_t offset); |
66 | int64_t (*bdrv_getlength)(BlockDriverState *bs); | 62 | int64_t (*bdrv_getlength)(BlockDriverState *bs); |
67 | int (*bdrv_write_compressed)(BlockDriverState *bs, int64_t sector_num, | 63 | int (*bdrv_write_compressed)(BlockDriverState *bs, int64_t sector_num, |