Merge remote-tracking branch 'kwolf/for-anthony' into staging
* kwolf/for-anthony: qemu-iotests: add backing file smaller than image test case stream: complete early if end of backing file is reached qed: refuse unaligned zero writes with a backing file
This commit is contained in:
		
						commit
						cdedd9d867
					
				
							
								
								
									
										11
									
								
								block/qed.c
								
								
								
								
							
							
						
						
									
										11
									
								
								block/qed.c
								
								
								
								
							| 
						 | 
					@ -1363,10 +1363,21 @@ static int coroutine_fn bdrv_qed_co_write_zeroes(BlockDriverState *bs,
 | 
				
			||||||
                                                 int nb_sectors)
 | 
					                                                 int nb_sectors)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    BlockDriverAIOCB *blockacb;
 | 
					    BlockDriverAIOCB *blockacb;
 | 
				
			||||||
 | 
					    BDRVQEDState *s = bs->opaque;
 | 
				
			||||||
    QEDWriteZeroesCB cb = { .done = false };
 | 
					    QEDWriteZeroesCB cb = { .done = false };
 | 
				
			||||||
    QEMUIOVector qiov;
 | 
					    QEMUIOVector qiov;
 | 
				
			||||||
    struct iovec iov;
 | 
					    struct iovec iov;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /* Refuse if there are untouched backing file sectors */
 | 
				
			||||||
 | 
					    if (bs->backing_hd) {
 | 
				
			||||||
 | 
					        if (qed_offset_into_cluster(s, sector_num * BDRV_SECTOR_SIZE) != 0) {
 | 
				
			||||||
 | 
					            return -ENOTSUP;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        if (qed_offset_into_cluster(s, nb_sectors * BDRV_SECTOR_SIZE) != 0) {
 | 
				
			||||||
 | 
					            return -ENOTSUP;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* Zero writes start without an I/O buffer.  If a buffer becomes necessary
 | 
					    /* Zero writes start without an I/O buffer.  If a buffer becomes necessary
 | 
				
			||||||
     * then it will be allocated during request processing.
 | 
					     * then it will be allocated during request processing.
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -122,6 +122,12 @@ wait:
 | 
				
			||||||
             * known-unallocated area [sector_num, sector_num+n).  */
 | 
					             * known-unallocated area [sector_num, sector_num+n).  */
 | 
				
			||||||
            ret = bdrv_co_is_allocated_above(bs->backing_hd, base,
 | 
					            ret = bdrv_co_is_allocated_above(bs->backing_hd, base,
 | 
				
			||||||
                                             sector_num, n, &n);
 | 
					                                             sector_num, n, &n);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            /* Finish early if end of backing file has been reached */
 | 
				
			||||||
 | 
					            if (ret == 0 && n == 0) {
 | 
				
			||||||
 | 
					                n = end - sector_num;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            copy = (ret == 1);
 | 
					            copy = (ret == 1);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        trace_stream_one_iteration(s, sector_num, n, ret);
 | 
					        trace_stream_one_iteration(s, sector_num, n, ret);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -125,6 +125,39 @@ class TestSingleDrive(ImageStreamingTestCase):
 | 
				
			||||||
        result = self.vm.qmp('block-stream', device='nonexistent')
 | 
					        result = self.vm.qmp('block-stream', device='nonexistent')
 | 
				
			||||||
        self.assert_qmp(result, 'error/class', 'DeviceNotFound')
 | 
					        self.assert_qmp(result, 'error/class', 'DeviceNotFound')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class TestSmallerBackingFile(ImageStreamingTestCase):
 | 
				
			||||||
 | 
					    backing_len = 1 * 1024 * 1024 # MB
 | 
				
			||||||
 | 
					    image_len = 2 * backing_len
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def setUp(self):
 | 
				
			||||||
 | 
					        self.create_image(backing_img, self.backing_len)
 | 
				
			||||||
 | 
					        qemu_img('create', '-f', iotests.imgfmt, '-o', 'backing_file=%s' % backing_img, test_img, str(self.image_len))
 | 
				
			||||||
 | 
					        self.vm = iotests.VM().add_drive(test_img)
 | 
				
			||||||
 | 
					        self.vm.launch()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    # If this hangs, then you are missing a fix to complete streaming when the
 | 
				
			||||||
 | 
					    # end of the backing file is reached.
 | 
				
			||||||
 | 
					    def test_stream(self):
 | 
				
			||||||
 | 
					        self.assert_no_active_streams()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        result = self.vm.qmp('block-stream', device='drive0')
 | 
				
			||||||
 | 
					        self.assert_qmp(result, 'return', {})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        completed = False
 | 
				
			||||||
 | 
					        while not completed:
 | 
				
			||||||
 | 
					            for event in self.vm.get_qmp_events(wait=True):
 | 
				
			||||||
 | 
					                if event['event'] == 'BLOCK_JOB_COMPLETED':
 | 
				
			||||||
 | 
					                    self.assert_qmp(event, 'data/type', 'stream')
 | 
				
			||||||
 | 
					                    self.assert_qmp(event, 'data/device', 'drive0')
 | 
				
			||||||
 | 
					                    self.assert_qmp(event, 'data/offset', self.image_len)
 | 
				
			||||||
 | 
					                    self.assert_qmp(event, 'data/len', self.image_len)
 | 
				
			||||||
 | 
					                    completed = True
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        self.assert_no_active_streams()
 | 
				
			||||||
 | 
					        self.vm.shutdown()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class TestStreamStop(ImageStreamingTestCase):
 | 
					class TestStreamStop(ImageStreamingTestCase):
 | 
				
			||||||
    image_len = 8 * 1024 * 1024 * 1024 # GB
 | 
					    image_len = 8 * 1024 * 1024 * 1024 # GB
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,5 +1,5 @@
 | 
				
			||||||
......
 | 
					.......
 | 
				
			||||||
----------------------------------------------------------------------
 | 
					----------------------------------------------------------------------
 | 
				
			||||||
Ran 6 tests
 | 
					Ran 7 tests
 | 
				
			||||||
 | 
					
 | 
				
			||||||
OK
 | 
					OK
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue