xref: /openbmc/qemu/include/sysemu/blockdev.h (revision cd4eb4c5)
1 /*
2  * QEMU host block devices
3  *
4  * Copyright (c) 2003-2008 Fabrice Bellard
5  *
6  * This work is licensed under the terms of the GNU GPL, version 2 or
7  * later.  See the COPYING file in the top-level directory.
8  */
9 
10 #ifndef BLOCKDEV_H
11 #define BLOCKDEV_H
12 
13 #include "block/block.h"
14 #include "qapi/error.h"
15 #include "qemu/queue.h"
16 
17 void blockdev_mark_auto_del(BlockDriverState *bs);
18 void blockdev_auto_del(BlockDriverState *bs);
19 
20 typedef enum {
21     IF_DEFAULT = -1,            /* for use with drive_add() only */
22     /*
23      * IF_IDE must be zero, because we want QEMUMachine member
24      * block_default_type to default-initialize to IF_IDE
25      */
26     IF_IDE = 0,
27     IF_NONE,
28     IF_SCSI, IF_FLOPPY, IF_PFLASH, IF_MTD, IF_SD, IF_VIRTIO, IF_XEN,
29     IF_COUNT
30 } BlockInterfaceType;
31 
32 struct DriveInfo {
33     BlockDriverState *bdrv;
34     char *id;
35     const char *devaddr;
36     BlockInterfaceType type;
37     int bus;
38     int unit;
39     int auto_del;               /* see blockdev_mark_auto_del() */
40     bool enable_auto_del; /* Only for legacy drive_init() */
41     int media_cd;
42     int cyls, heads, secs, trans;
43     QemuOpts *opts;
44     char *serial;
45     QTAILQ_ENTRY(DriveInfo) next;
46     int refcount;
47 };
48 
49 DriveInfo *drive_get(BlockInterfaceType type, int bus, int unit);
50 DriveInfo *drive_get_by_index(BlockInterfaceType type, int index);
51 int drive_get_max_bus(BlockInterfaceType type);
52 DriveInfo *drive_get_next(BlockInterfaceType type);
53 void drive_get_ref(DriveInfo *dinfo);
54 void drive_put_ref(DriveInfo *dinfo);
55 DriveInfo *drive_get_by_blockdev(BlockDriverState *bs);
56 
57 QemuOpts *drive_def(const char *optstr);
58 QemuOpts *drive_add(BlockInterfaceType type, int index, const char *file,
59                     const char *optstr);
60 DriveInfo *drive_init(QemuOpts *arg, BlockInterfaceType block_default_type);
61 
62 /* device-hotplug */
63 
64 DriveInfo *add_init_drive(const char *opts);
65 
66 void qmp_change_blockdev(const char *device, const char *filename,
67                          const char *format, Error **errp);
68 void do_commit(Monitor *mon, const QDict *qdict);
69 int do_drive_del(Monitor *mon, const QDict *qdict, QObject **ret_data);
70 #endif
71