block: Extract the BlockAcctStats structure
Extract the block accounting statistics into a structure so the block device models can hold them in the future. CC: Kevin Wolf <kwolf@redhat.com> CC: Stefan Hajnoczi <stefanha@redhat.com> CC: Max Reitz <mreitz@redhat.com> CC: Eric Blake <eblake@redhat.com> Signed-off-by: Benoît Canet <benoit.canet@nodalink.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
		
							parent
							
								
									1a7044bb62
								
							
						
					
					
						commit
						0ddd0ad96a
					
				
							
								
								
									
										11
									
								
								block.c
								
								
								
								
							
							
						
						
									
										11
									
								
								block.c
								
								
								
								
							| 
						 | 
					@ -3363,8 +3363,8 @@ static int coroutine_fn bdrv_aligned_pwritev(BlockDriverState *bs,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    bdrv_set_dirty(bs, sector_num, nb_sectors);
 | 
					    bdrv_set_dirty(bs, sector_num, nb_sectors);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (bs->wr_highest_sector < sector_num + nb_sectors - 1) {
 | 
					    if (bs->stats.wr_highest_sector < sector_num + nb_sectors - 1) {
 | 
				
			||||||
        bs->wr_highest_sector = sector_num + nb_sectors - 1;
 | 
					        bs->stats.wr_highest_sector = sector_num + nb_sectors - 1;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    if (bs->growable && ret >= 0) {
 | 
					    if (bs->growable && ret >= 0) {
 | 
				
			||||||
        bs->total_sectors = MAX(bs->total_sectors, sector_num + nb_sectors);
 | 
					        bs->total_sectors = MAX(bs->total_sectors, sector_num + nb_sectors);
 | 
				
			||||||
| 
						 | 
					@ -5588,9 +5588,10 @@ bdrv_acct_done(BlockDriverState *bs, BlockAcctCookie *cookie)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    assert(cookie->type < BDRV_MAX_IOTYPE);
 | 
					    assert(cookie->type < BDRV_MAX_IOTYPE);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    bs->nr_bytes[cookie->type] += cookie->bytes;
 | 
					    bs->stats.nr_bytes[cookie->type] += cookie->bytes;
 | 
				
			||||||
    bs->nr_ops[cookie->type]++;
 | 
					    bs->stats.nr_ops[cookie->type]++;
 | 
				
			||||||
    bs->total_time_ns[cookie->type] += get_clock() - cookie->start_time_ns;
 | 
					    bs->stats.total_time_ns[cookie->type] += get_clock() -
 | 
				
			||||||
 | 
					                                             cookie->start_time_ns;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void bdrv_img_create(const char *filename, const char *fmt,
 | 
					void bdrv_img_create(const char *filename, const char *fmt,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										19
									
								
								block/qapi.c
								
								
								
								
							
							
						
						
									
										19
									
								
								block/qapi.c
								
								
								
								
							| 
						 | 
					@ -333,15 +333,16 @@ static BlockStats *bdrv_query_stats(const BlockDriverState *bs)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    s->stats = g_malloc0(sizeof(*s->stats));
 | 
					    s->stats = g_malloc0(sizeof(*s->stats));
 | 
				
			||||||
    s->stats->rd_bytes = bs->nr_bytes[BDRV_ACCT_READ];
 | 
					    s->stats->rd_bytes = bs->stats.nr_bytes[BDRV_ACCT_READ];
 | 
				
			||||||
    s->stats->wr_bytes = bs->nr_bytes[BDRV_ACCT_WRITE];
 | 
					    s->stats->wr_bytes = bs->stats.nr_bytes[BDRV_ACCT_WRITE];
 | 
				
			||||||
    s->stats->rd_operations = bs->nr_ops[BDRV_ACCT_READ];
 | 
					    s->stats->rd_operations = bs->stats.nr_ops[BDRV_ACCT_READ];
 | 
				
			||||||
    s->stats->wr_operations = bs->nr_ops[BDRV_ACCT_WRITE];
 | 
					    s->stats->wr_operations = bs->stats.nr_ops[BDRV_ACCT_WRITE];
 | 
				
			||||||
    s->stats->wr_highest_offset = bs->wr_highest_sector * BDRV_SECTOR_SIZE;
 | 
					    s->stats->wr_highest_offset =
 | 
				
			||||||
    s->stats->flush_operations = bs->nr_ops[BDRV_ACCT_FLUSH];
 | 
					        bs->stats.wr_highest_sector * BDRV_SECTOR_SIZE;
 | 
				
			||||||
    s->stats->wr_total_time_ns = bs->total_time_ns[BDRV_ACCT_WRITE];
 | 
					    s->stats->flush_operations = bs->stats.nr_ops[BDRV_ACCT_FLUSH];
 | 
				
			||||||
    s->stats->rd_total_time_ns = bs->total_time_ns[BDRV_ACCT_READ];
 | 
					    s->stats->wr_total_time_ns = bs->stats.total_time_ns[BDRV_ACCT_WRITE];
 | 
				
			||||||
    s->stats->flush_total_time_ns = bs->total_time_ns[BDRV_ACCT_FLUSH];
 | 
					    s->stats->rd_total_time_ns = bs->stats.total_time_ns[BDRV_ACCT_READ];
 | 
				
			||||||
 | 
					    s->stats->flush_total_time_ns = bs->stats.total_time_ns[BDRV_ACCT_FLUSH];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (bs->file) {
 | 
					    if (bs->file) {
 | 
				
			||||||
        s->has_parent = true;
 | 
					        s->has_parent = true;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -492,6 +492,13 @@ enum BlockAcctType {
 | 
				
			||||||
    BDRV_MAX_IOTYPE,
 | 
					    BDRV_MAX_IOTYPE,
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					typedef struct BlockAcctStats {
 | 
				
			||||||
 | 
					    uint64_t nr_bytes[BDRV_MAX_IOTYPE];
 | 
				
			||||||
 | 
					    uint64_t nr_ops[BDRV_MAX_IOTYPE];
 | 
				
			||||||
 | 
					    uint64_t total_time_ns[BDRV_MAX_IOTYPE];
 | 
				
			||||||
 | 
					    uint64_t wr_highest_sector;
 | 
				
			||||||
 | 
					} BlockAcctStats;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
typedef struct BlockAcctCookie {
 | 
					typedef struct BlockAcctCookie {
 | 
				
			||||||
    int64_t bytes;
 | 
					    int64_t bytes;
 | 
				
			||||||
    int64_t start_time_ns;
 | 
					    int64_t start_time_ns;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -359,10 +359,7 @@ struct BlockDriverState {
 | 
				
			||||||
    bool         io_limits_enabled;
 | 
					    bool         io_limits_enabled;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* I/O stats (display with "info blockstats"). */
 | 
					    /* I/O stats (display with "info blockstats"). */
 | 
				
			||||||
    uint64_t nr_bytes[BDRV_MAX_IOTYPE];
 | 
					    BlockAcctStats stats;
 | 
				
			||||||
    uint64_t nr_ops[BDRV_MAX_IOTYPE];
 | 
					 | 
				
			||||||
    uint64_t total_time_ns[BDRV_MAX_IOTYPE];
 | 
					 | 
				
			||||||
    uint64_t wr_highest_sector;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* I/O Limits */
 | 
					    /* I/O Limits */
 | 
				
			||||||
    BlockLimits bl;
 | 
					    BlockLimits bl;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue