block: Factor bdrv_read_unthrottled() out of guess_disk_lchs()
To prepare move of guess_disk_lchs() into hw/, where it poking BlockDriverState member io_limits_enabled directly would be unclean. Signed-off-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
		
							parent
							
								
									bb494a505e
								
							
						
					
					
						commit
						07d27a442e
					
				
							
								
								
									
										24
									
								
								block.c
									
									
									
									
									
								
							
							
						
						
									
										24
									
								
								block.c
									
									
									
									
									
								
							@ -1639,6 +1639,20 @@ int bdrv_read(BlockDriverState *bs, int64_t sector_num,
 | 
				
			|||||||
    return bdrv_rw_co(bs, sector_num, buf, nb_sectors, false);
 | 
					    return bdrv_rw_co(bs, sector_num, buf, nb_sectors, false);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* Just like bdrv_read(), but with I/O throttling temporarily disabled */
 | 
				
			||||||
 | 
					int bdrv_read_unthrottled(BlockDriverState *bs, int64_t sector_num,
 | 
				
			||||||
 | 
					                          uint8_t *buf, int nb_sectors)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    bool enabled;
 | 
				
			||||||
 | 
					    int ret;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    enabled = bs->io_limits_enabled;
 | 
				
			||||||
 | 
					    bs->io_limits_enabled = false;
 | 
				
			||||||
 | 
					    ret = bdrv_read(bs, 0, buf, 1);
 | 
				
			||||||
 | 
					    bs->io_limits_enabled = enabled;
 | 
				
			||||||
 | 
					    return ret;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define BITS_PER_LONG  (sizeof(unsigned long) * 8)
 | 
					#define BITS_PER_LONG  (sizeof(unsigned long) * 8)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void set_dirty_bitmap(BlockDriverState *bs, int64_t sector_num,
 | 
					static void set_dirty_bitmap(BlockDriverState *bs, int64_t sector_num,
 | 
				
			||||||
@ -2136,11 +2150,10 @@ static int guess_disk_lchs(BlockDriverState *bs,
 | 
				
			|||||||
                           int *pcylinders, int *pheads, int *psectors)
 | 
					                           int *pcylinders, int *pheads, int *psectors)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    uint8_t buf[BDRV_SECTOR_SIZE];
 | 
					    uint8_t buf[BDRV_SECTOR_SIZE];
 | 
				
			||||||
    int ret, i, heads, sectors, cylinders;
 | 
					    int i, heads, sectors, cylinders;
 | 
				
			||||||
    struct partition *p;
 | 
					    struct partition *p;
 | 
				
			||||||
    uint32_t nr_sects;
 | 
					    uint32_t nr_sects;
 | 
				
			||||||
    uint64_t nb_sectors;
 | 
					    uint64_t nb_sectors;
 | 
				
			||||||
    bool enabled;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    bdrv_get_geometry(bs, &nb_sectors);
 | 
					    bdrv_get_geometry(bs, &nb_sectors);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -2149,12 +2162,9 @@ static int guess_disk_lchs(BlockDriverState *bs,
 | 
				
			|||||||
     * but also in async I/O mode. So the I/O throttling function has to
 | 
					     * but also in async I/O mode. So the I/O throttling function has to
 | 
				
			||||||
     * be disabled temporarily here, not permanently.
 | 
					     * be disabled temporarily here, not permanently.
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    enabled = bs->io_limits_enabled;
 | 
					    if (bdrv_read_unthrottled(bs, 0, buf, 1) < 0) {
 | 
				
			||||||
    bs->io_limits_enabled = false;
 | 
					 | 
				
			||||||
    ret = bdrv_read(bs, 0, buf, 1);
 | 
					 | 
				
			||||||
    bs->io_limits_enabled = enabled;
 | 
					 | 
				
			||||||
    if (ret < 0)
 | 
					 | 
				
			||||||
        return -1;
 | 
					        return -1;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
    /* test msdos magic */
 | 
					    /* test msdos magic */
 | 
				
			||||||
    if (buf[510] != 0x55 || buf[511] != 0xaa)
 | 
					    if (buf[510] != 0x55 || buf[511] != 0xaa)
 | 
				
			||||||
        return -1;
 | 
					        return -1;
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										2
									
								
								block.h
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								block.h
									
									
									
									
									
								
							@ -142,6 +142,8 @@ bool bdrv_dev_is_tray_open(BlockDriverState *bs);
 | 
				
			|||||||
bool bdrv_dev_is_medium_locked(BlockDriverState *bs);
 | 
					bool bdrv_dev_is_medium_locked(BlockDriverState *bs);
 | 
				
			||||||
int bdrv_read(BlockDriverState *bs, int64_t sector_num,
 | 
					int bdrv_read(BlockDriverState *bs, int64_t sector_num,
 | 
				
			||||||
              uint8_t *buf, int nb_sectors);
 | 
					              uint8_t *buf, int nb_sectors);
 | 
				
			||||||
 | 
					int bdrv_read_unthrottled(BlockDriverState *bs, int64_t sector_num,
 | 
				
			||||||
 | 
					                          uint8_t *buf, int nb_sectors);
 | 
				
			||||||
int bdrv_write(BlockDriverState *bs, int64_t sector_num,
 | 
					int bdrv_write(BlockDriverState *bs, int64_t sector_num,
 | 
				
			||||||
               const uint8_t *buf, int nb_sectors);
 | 
					               const uint8_t *buf, int nb_sectors);
 | 
				
			||||||
int bdrv_pread(BlockDriverState *bs, int64_t offset,
 | 
					int bdrv_pread(BlockDriverState *bs, int64_t offset,
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user