R&D/Hypervisor

[struct] BlockDriverState, BlockDriver

sunshout 2014. 5. 21. 23:36

@include/block/block_int.h

struct BlockDriverState



/*

 * Note: the function bdrv_append() copies and swaps contents of

 * BlockDriverStates, so if you add new fields to this struct, please

 * inspect bdrv_append() to determine if the new fields need to be

 * copied as well.

 */

struct BlockDriverState {

    int64_t total_sectors; /* if we are reading a disk image, give its

                              size in sectors */

    int read_only; /* if true, the media is read only */

    int open_flags; /* flags used to open the file, re-used for re-open */

    int encrypted; /* if true, the media is encrypted */

    int valid_key; /* if true, a valid encryption key has been set */

    int sg;        /* if true, the device is a /dev/sg* */

    int copy_on_read; /* if true, copy read backing sectors into image

                         note this is a reference count */


    BlockDriver *drv; /* NULL means no media */

    void *opaque;


    void *dev;                  /* attached device model, if any */

    /* TODO change to DeviceState when all users are qdevified */

    const BlockDevOps *dev_ops;

    void *dev_opaque;


    char filename[1024];

    char backing_file[1024]; /* if non zero, the image is a diff of

                                this file image */

    char backing_format[16]; /* if non-zero and backing_file exists */


    BlockDriverState *backing_hd;

    BlockDriverState *file;


    NotifierList close_notifiers;


    /* Callback before write request is processed */

    NotifierWithReturnList before_write_notifiers;


    /* number of in-flight serialising requests */

    unsigned int serialising_in_flight;


    /* I/O throttling */
    ThrottleState throttle_state;
    CoQueue      throttled_reqs[2];
    bool         io_limits_enabled;

    /* I/O stats (display with "info blockstats"). */
    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;

    /* I/O Limits */
    BlockLimits bl;

    /* Whether the disk can expand beyond total_sectors */
    int growable;

    /* Whether produces zeros when read beyond eof */
    bool zero_beyond_eof;

    /* Alignment requirement for offset/length of I/O requests */
    unsigned int request_alignment;

    /* the block size for which the guest device expects atomicity */
    int guest_block_size;

    /* do we need to tell the quest if we have a volatile write cache? */
    int enable_write_cache;

    /* NOTE: the following infos are only hints for real hardware
       drivers. They are not used by the block driver */
    BlockdevOnError on_read_error, on_write_error;
    bool iostatus_enabled;
    BlockDeviceIoStatus iostatus;

    /* the following member gives a name to every node on the bs graph. */
    char node_name[32];
    /* element of the list of named nodes building the graph */
    QTAILQ_ENTRY(BlockDriverState) node_list;
    /* Device name is the name associated with the "drive" the guest sees */
    char device_name[32];
    /* element of the list of "drives" the guest sees */
    QTAILQ_ENTRY(BlockDriverState) device_list;
    QLIST_HEAD(, BdrvDirtyBitmap) dirty_bitmaps;
    int refcnt;
    int in_use; /* users other than guest access, eg. block migration */

    QLIST_HEAD(, BdrvTrackedRequest) tracked_requests;

    /* long-running background operation */
    BlockJob *job;

    QDict *options;
};



@include/block/block_int.h

struct BlockDriver


struct BlockDriver {

    const char *format_name;

    int instance_size;


    /* set to true if the BlockDriver is a block filter */

    bool is_filter;

    /* for snapshots block filter like Quorum can implement the

     * following recursive callback.

     * It's purpose is to recurse on the filter children while calling

     * bdrv_recurse_is_first_non_filter on them.

     * For a sample implementation look in the future Quorum block filter.

     */

    bool (*bdrv_recurse_is_first_non_filter)(BlockDriverState *bs,

                                             BlockDriverState *candidate);


    int (*bdrv_probe)(const uint8_t *buf, int buf_size, const char *filename);

    int (*bdrv_probe_device)(const char *filename);


    /* Any driver implementing this callback is expected to be able to handle

     * NULL file names in its .bdrv_open() implementation */

    void (*bdrv_parse_filename)(const char *filename, QDict *options, Error **errp);

    /* Drivers not implementing bdrv_parse_filename nor bdrv_open should have

     * this field set to true, except ones that are defined only by their

     * child's bs.

     * An example of the last type will be the quorum block driver.

     */

    bool bdrv_needs_filename;


    /* For handling image reopen for split or non-split files */

    int (*bdrv_reopen_prepare)(BDRVReopenState *reopen_state,

                               BlockReopenQueue *queue, Error **errp);

    void (*bdrv_reopen_commit)(BDRVReopenState *reopen_state);

    void (*bdrv_reopen_abort)(BDRVReopenState *reopen_state);


    int (*bdrv_open)(BlockDriverState *bs, QDict *options, int flags,
                     Error **errp);
    int (*bdrv_file_open)(BlockDriverState *bs, QDict *options, int flags,
                          Error **errp);
    int (*bdrv_read)(BlockDriverState *bs, int64_t sector_num,
                     uint8_t *buf, int nb_sectors);
    int (*bdrv_write)(BlockDriverState *bs, int64_t sector_num,
                      const uint8_t *buf, int nb_sectors);
    void (*bdrv_close)(BlockDriverState *bs);
    void (*bdrv_rebind)(BlockDriverState *bs);
    int (*bdrv_create)(const char *filename, QEMUOptionParameter *options,
                       Error **errp);
    int (*bdrv_set_key)(BlockDriverState *bs, const char *key);
    int (*bdrv_make_empty)(BlockDriverState *bs);