@@ -849,56 +849,18 @@ static BDRVQEDState *acb_to_s(QEDAIOCB *acb)
849
849
* @s: QED state
850
850
* @pos: Byte position in device
851
851
* @qiov: Destination I/O vector
852
- * @backing_qiov: Possibly shortened copy of qiov, to be allocated here
853
- * @cb: Completion function
854
- * @opaque: User data for completion function
855
852
*
856
853
* This function reads qiov->size bytes starting at pos from the backing file.
857
854
* If there is no backing file then zeroes are read.
858
855
*/
859
856
static int coroutine_fn qed_read_backing_file (BDRVQEDState * s , uint64_t pos ,
860
- QEMUIOVector * qiov ,
861
- QEMUIOVector * * backing_qiov )
857
+ QEMUIOVector * qiov )
862
858
{
863
- uint64_t backing_length = 0 ;
864
- size_t size ;
865
- int ret ;
866
-
867
- /* If there is a backing file, get its length. Treat the absence of a
868
- * backing file like a zero length backing file.
869
- */
870
859
if (s -> bs -> backing ) {
871
- int64_t l = bdrv_getlength (s -> bs -> backing -> bs );
872
- if (l < 0 ) {
873
- return l ;
874
- }
875
- backing_length = l ;
876
- }
877
-
878
- /* Zero all sectors if reading beyond the end of the backing file */
879
- if (pos >= backing_length ||
880
- pos + qiov -> size > backing_length ) {
881
- qemu_iovec_memset (qiov , 0 , 0 , qiov -> size );
882
- }
883
-
884
- /* Complete now if there are no backing file sectors to read */
885
- if (pos >= backing_length ) {
886
- return 0 ;
887
- }
888
-
889
- /* If the read straddles the end of the backing file, shorten it */
890
- size = MIN ((uint64_t )backing_length - pos , qiov -> size );
891
-
892
- assert (* backing_qiov == NULL );
893
- * backing_qiov = g_new (QEMUIOVector , 1 );
894
- qemu_iovec_init (* backing_qiov , qiov -> niov );
895
- qemu_iovec_concat (* backing_qiov , qiov , 0 , size );
896
-
897
- BLKDBG_EVENT (s -> bs -> file , BLKDBG_READ_BACKING_AIO );
898
- ret = bdrv_co_preadv (s -> bs -> backing , pos , size , * backing_qiov , 0 );
899
- if (ret < 0 ) {
900
- return ret ;
860
+ BLKDBG_EVENT (s -> bs -> file , BLKDBG_READ_BACKING_AIO );
861
+ return bdrv_co_preadv (s -> bs -> backing , pos , qiov -> size , qiov , 0 );
901
862
}
863
+ qemu_iovec_memset (qiov , 0 , 0 , qiov -> size );
902
864
return 0 ;
903
865
}
904
866
@@ -915,7 +877,6 @@ static int coroutine_fn qed_copy_from_backing_file(BDRVQEDState *s,
915
877
uint64_t offset )
916
878
{
917
879
QEMUIOVector qiov ;
918
- QEMUIOVector * backing_qiov = NULL ;
919
880
int ret ;
920
881
921
882
/* Skip copy entirely if there is no work to do */
@@ -925,13 +886,7 @@ static int coroutine_fn qed_copy_from_backing_file(BDRVQEDState *s,
925
886
926
887
qemu_iovec_init_buf (& qiov , qemu_blockalign (s -> bs , len ), len );
927
888
928
- ret = qed_read_backing_file (s , pos , & qiov , & backing_qiov );
929
-
930
- if (backing_qiov ) {
931
- qemu_iovec_destroy (backing_qiov );
932
- g_free (backing_qiov );
933
- backing_qiov = NULL ;
934
- }
889
+ ret = qed_read_backing_file (s , pos , & qiov );
935
890
936
891
if (ret ) {
937
892
goto out ;
@@ -1339,8 +1294,7 @@ static int coroutine_fn qed_aio_read_data(void *opaque, int ret,
1339
1294
qemu_iovec_memset (& acb -> cur_qiov , 0 , 0 , acb -> cur_qiov .size );
1340
1295
r = 0 ;
1341
1296
} else if (ret != QED_CLUSTER_FOUND ) {
1342
- r = qed_read_backing_file (s , acb -> cur_pos , & acb -> cur_qiov ,
1343
- & acb -> backing_qiov );
1297
+ r = qed_read_backing_file (s , acb -> cur_pos , & acb -> cur_qiov );
1344
1298
} else {
1345
1299
BLKDBG_EVENT (bs -> file , BLKDBG_READ_AIO );
1346
1300
r = bdrv_co_preadv (bs -> file , offset , acb -> cur_qiov .size ,
@@ -1365,12 +1319,6 @@ static int coroutine_fn qed_aio_next_io(QEDAIOCB *acb)
1365
1319
while (1 ) {
1366
1320
trace_qed_aio_next_io (s , acb , 0 , acb -> cur_pos + acb -> cur_qiov .size );
1367
1321
1368
- if (acb -> backing_qiov ) {
1369
- qemu_iovec_destroy (acb -> backing_qiov );
1370
- g_free (acb -> backing_qiov );
1371
- acb -> backing_qiov = NULL ;
1372
- }
1373
-
1374
1322
acb -> qiov_offset += acb -> cur_qiov .size ;
1375
1323
acb -> cur_pos += acb -> cur_qiov .size ;
1376
1324
qemu_iovec_reset (& acb -> cur_qiov );
0 commit comments