blob: ac22f2ae1f78e0be24d2f2668885c98bacba42c4 [file] [log] [blame]
Markus Armbruster666daa62010-06-02 18:48:27 +02001/*
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
Paolo Bonzini737e1502012-12-17 18:19:44 +010013#include "block/block.h"
Paolo Bonzini1de7afc2012-12-17 18:20:00 +010014#include "qemu/queue.h"
Markus Armbruster666daa62010-06-02 18:48:27 +020015
Markus Armbruster4be74632014-10-07 13:59:18 +020016void blockdev_mark_auto_del(BlockBackend *blk);
17void blockdev_auto_del(BlockBackend *blk);
Markus Armbruster14bafc52010-06-25 08:09:10 +020018
Markus Armbruster904ebff2011-01-28 11:21:38 +010019typedef enum {
Markus Armbruster2292dda2011-01-28 11:21:41 +010020 IF_DEFAULT = -1, /* for use with drive_add() only */
Christian Borntraeger2d0d2832012-11-20 15:30:34 +010021 /*
Markus Armbrustera27fa282017-02-15 11:05:42 +010022 * IF_NONE must be zero, because we want MachineClass member
23 * block_default_type to default-initialize to IF_NONE
Christian Borntraeger2d0d2832012-11-20 15:30:34 +010024 */
Markus Armbrustera27fa282017-02-15 11:05:42 +010025 IF_NONE = 0,
26 IF_IDE, IF_SCSI, IF_FLOPPY, IF_PFLASH, IF_MTD, IF_SD, IF_VIRTIO, IF_XEN,
Markus Armbruster904ebff2011-01-28 11:21:38 +010027 IF_COUNT
28} BlockInterfaceType;
29
Blue Swirl24463332010-08-24 15:22:24 +000030struct DriveInfo {
Cornelia Huck75f4cd22018-07-06 15:06:19 +020031 const char *devaddr;
Markus Armbruster666daa62010-06-02 18:48:27 +020032 BlockInterfaceType type;
33 int bus;
34 int unit;
Markus Armbruster14bafc52010-06-25 08:09:10 +020035 int auto_del; /* see blockdev_mark_auto_del() */
John Snowa66c9dc2014-10-01 14:19:24 -040036 bool is_default; /* Added by default_drive() ? */
Markus Armbruster95b5edc2011-05-16 15:04:56 +020037 int media_cd;
Cornelia Huck6703db12018-07-06 15:06:20 +020038 int cyls, heads, secs, trans;
Markus Armbruster666daa62010-06-02 18:48:27 +020039 QemuOpts *opts;
Cornelia Huck44e8b462018-07-06 15:06:18 +020040 char *serial;
Markus Armbruster666daa62010-06-02 18:48:27 +020041 QTAILQ_ENTRY(DriveInfo) next;
Blue Swirl24463332010-08-24 15:22:24 +000042};
Markus Armbruster666daa62010-06-02 18:48:27 +020043
Markus Armbruster18e46a02014-10-07 13:59:06 +020044DriveInfo *blk_legacy_dinfo(BlockBackend *blk);
45DriveInfo *blk_set_legacy_dinfo(BlockBackend *blk, DriveInfo *dinfo);
46BlockBackend *blk_by_legacy_dinfo(DriveInfo *dinfo);
47
John Snow21dff8c2014-10-01 14:19:25 -040048void override_max_devs(BlockInterfaceType type, int max_devs);
49
Stefan Weil6ea421f2010-09-23 20:47:32 +020050DriveInfo *drive_get(BlockInterfaceType type, int bus, int unit);
Markus Armbruster720b8dc2017-02-15 11:05:46 +010051void drive_check_orphaned(void);
Markus Armbrusterf1bd51a2011-01-28 11:21:44 +010052DriveInfo *drive_get_by_index(BlockInterfaceType type, int index);
Stefan Weil6ea421f2010-09-23 20:47:32 +020053int drive_get_max_bus(BlockInterfaceType type);
John Snowd8f94e12014-10-01 14:19:27 -040054int drive_get_max_devs(BlockInterfaceType type);
Markus Armbruster13839972011-01-28 11:21:37 +010055DriveInfo *drive_get_next(BlockInterfaceType type);
Markus Armbruster666daa62010-06-02 18:48:27 +020056
Markus Armbruster2292dda2011-01-28 11:21:41 +010057QemuOpts *drive_def(const char *optstr);
58QemuOpts *drive_add(BlockInterfaceType type, int index, const char *file,
Markus Armbruster5645b0f2011-01-31 11:50:09 +010059 const char *optstr);
Markus Armbruster60e19e02014-06-06 14:50:58 +020060DriveInfo *drive_new(QemuOpts *arg, BlockInterfaceType block_default_type);
Markus Armbruster666daa62010-06-02 18:48:27 +020061
62/* device-hotplug */
63
Markus Armbruster3e5a50d2015-02-06 13:55:43 +010064void hmp_commit(Monitor *mon, const QDict *qdict);
Markus Armbruster072ebe62015-03-05 17:00:56 +010065void hmp_drive_del(Monitor *mon, const QDict *qdict);
Markus Armbruster666daa62010-06-02 18:48:27 +020066#endif