Statistics
| Branch: | Revision:

root / block.h @ c021f8e6

History | View | Annotate | Download (8.5 kB)

1 faf07963 pbrook
#ifndef BLOCK_H
2 faf07963 pbrook
#define BLOCK_H
3 faf07963 pbrook
4 a76bab49 aliguori
#include "qemu-aio.h"
5 3b69e4b9 aliguori
#include "qemu-common.h"
6 0e7e1989 Kevin Wolf
#include "qemu-option.h"
7 d15e5465 Luiz Capitulino
#include "qobject.h"
8 a76bab49 aliguori
9 faf07963 pbrook
/* block.c */
10 faf07963 pbrook
typedef struct BlockDriver BlockDriver;
11 faf07963 pbrook
12 faf07963 pbrook
typedef struct BlockDriverInfo {
13 faf07963 pbrook
    /* in bytes, 0 if irrelevant */
14 faf07963 pbrook
    int cluster_size;
15 faf07963 pbrook
    /* offset at which the VM state can be saved (0 if not possible) */
16 faf07963 pbrook
    int64_t vm_state_offset;
17 faf07963 pbrook
} BlockDriverInfo;
18 faf07963 pbrook
19 faf07963 pbrook
typedef struct QEMUSnapshotInfo {
20 faf07963 pbrook
    char id_str[128]; /* unique snapshot id */
21 faf07963 pbrook
    /* the following fields are informative. They are not needed for
22 faf07963 pbrook
       the consistency of the snapshot */
23 faf07963 pbrook
    char name[256]; /* user choosen name */
24 faf07963 pbrook
    uint32_t vm_state_size; /* VM state info size */
25 faf07963 pbrook
    uint32_t date_sec; /* UTC date of the snapshot */
26 faf07963 pbrook
    uint32_t date_nsec;
27 faf07963 pbrook
    uint64_t vm_clock_nsec; /* VM clock relative to boot */
28 faf07963 pbrook
} QEMUSnapshotInfo;
29 faf07963 pbrook
30 faf07963 pbrook
#define BDRV_O_RDWR        0x0002
31 faf07963 pbrook
#define BDRV_O_SNAPSHOT    0x0008 /* open the file read only and save writes in a snapshot */
32 faf07963 pbrook
#define BDRV_O_FILE        0x0010 /* open as a raw file (do not try to
33 faf07963 pbrook
                                     use a disk image format on top of
34 faf07963 pbrook
                                     it (default for
35 faf07963 pbrook
                                     bdrv_file_open()) */
36 9f7965c7 aliguori
#define BDRV_O_NOCACHE     0x0020 /* do not use the host page cache */
37 9f7965c7 aliguori
#define BDRV_O_CACHE_WB    0x0040 /* use write-back caching */
38 5c6c3a6c Christoph Hellwig
#define BDRV_O_NATIVE_AIO  0x0080 /* use native AIO instead of the thread pool */
39 b783e409 Kevin Wolf
#define BDRV_O_NO_BACKING  0x0100 /* don't open the backing file */
40 9f7965c7 aliguori
41 0aa217e4 Kevin Wolf
#define BDRV_O_CACHE_MASK  (BDRV_O_NOCACHE | BDRV_O_CACHE_WB)
42 faf07963 pbrook
43 6ea44308 Jan Kiszka
#define BDRV_SECTOR_BITS   9
44 6ea44308 Jan Kiszka
#define BDRV_SECTOR_SIZE   (1 << BDRV_SECTOR_BITS)
45 6ea44308 Jan Kiszka
#define BDRV_SECTOR_MASK   ~(BDRV_SECTOR_SIZE - 1);
46 6ea44308 Jan Kiszka
47 d15e5465 Luiz Capitulino
void bdrv_info_print(Monitor *mon, const QObject *data);
48 d15e5465 Luiz Capitulino
void bdrv_info(Monitor *mon, QObject **ret_data);
49 218a536a Luiz Capitulino
void bdrv_stats_print(Monitor *mon, const QObject *data);
50 218a536a Luiz Capitulino
void bdrv_info_stats(Monitor *mon, QObject **ret_data);
51 faf07963 pbrook
52 faf07963 pbrook
void bdrv_init(void);
53 eb852011 Markus Armbruster
void bdrv_init_with_whitelist(void);
54 faf07963 pbrook
BlockDriver *bdrv_find_format(const char *format_name);
55 eb852011 Markus Armbruster
BlockDriver *bdrv_find_whitelisted_format(const char *format_name);
56 0e7e1989 Kevin Wolf
int bdrv_create(BlockDriver *drv, const char* filename,
57 0e7e1989 Kevin Wolf
    QEMUOptionParameter *options);
58 5eb45639 aliguori
int bdrv_create2(BlockDriver *drv,
59 5eb45639 aliguori
                 const char *filename, int64_t size_in_sectors,
60 5eb45639 aliguori
                 const char *backing_file, const char *backing_format,
61 5eb45639 aliguori
                 int flags);
62 faf07963 pbrook
BlockDriverState *bdrv_new(const char *device_name);
63 faf07963 pbrook
void bdrv_delete(BlockDriverState *bs);
64 faf07963 pbrook
int bdrv_file_open(BlockDriverState **pbs, const char *filename, int flags);
65 faf07963 pbrook
int bdrv_open(BlockDriverState *bs, const char *filename, int flags);
66 faf07963 pbrook
int bdrv_open2(BlockDriverState *bs, const char *filename, int flags,
67 faf07963 pbrook
               BlockDriver *drv);
68 faf07963 pbrook
void bdrv_close(BlockDriverState *bs);
69 e97fc193 aliguori
int bdrv_check(BlockDriverState *bs);
70 faf07963 pbrook
int bdrv_read(BlockDriverState *bs, int64_t sector_num,
71 faf07963 pbrook
              uint8_t *buf, int nb_sectors);
72 faf07963 pbrook
int bdrv_write(BlockDriverState *bs, int64_t sector_num,
73 faf07963 pbrook
               const uint8_t *buf, int nb_sectors);
74 faf07963 pbrook
int bdrv_pread(BlockDriverState *bs, int64_t offset,
75 faf07963 pbrook
               void *buf, int count);
76 faf07963 pbrook
int bdrv_pwrite(BlockDriverState *bs, int64_t offset,
77 faf07963 pbrook
                const void *buf, int count);
78 faf07963 pbrook
int bdrv_truncate(BlockDriverState *bs, int64_t offset);
79 faf07963 pbrook
int64_t bdrv_getlength(BlockDriverState *bs);
80 96b8f136 ths
void bdrv_get_geometry(BlockDriverState *bs, uint64_t *nb_sectors_ptr);
81 f3d54fc4 aliguori
void bdrv_guess_geometry(BlockDriverState *bs, int *pcyls, int *pheads, int *psecs);
82 faf07963 pbrook
int bdrv_commit(BlockDriverState *bs);
83 756e6736 Kevin Wolf
int bdrv_change_backing_file(BlockDriverState *bs,
84 756e6736 Kevin Wolf
    const char *backing_file, const char *backing_fmt);
85 5efa9d5a Anthony Liguori
void bdrv_register(BlockDriver *bdrv);
86 5efa9d5a Anthony Liguori
87 faf07963 pbrook
/* async block I/O */
88 faf07963 pbrook
typedef struct BlockDriverAIOCB BlockDriverAIOCB;
89 faf07963 pbrook
typedef void BlockDriverCompletionFunc(void *opaque, int ret);
90 7cd1e32a lirans@il.ibm.com
typedef void BlockDriverDirtyHandler(BlockDriverState *bs, int64_t sector,
91 7cd1e32a lirans@il.ibm.com
                                     int sector_num);
92 3b69e4b9 aliguori
BlockDriverAIOCB *bdrv_aio_readv(BlockDriverState *bs, int64_t sector_num,
93 3b69e4b9 aliguori
                                 QEMUIOVector *iov, int nb_sectors,
94 3b69e4b9 aliguori
                                 BlockDriverCompletionFunc *cb, void *opaque);
95 3b69e4b9 aliguori
BlockDriverAIOCB *bdrv_aio_writev(BlockDriverState *bs, int64_t sector_num,
96 3b69e4b9 aliguori
                                  QEMUIOVector *iov, int nb_sectors,
97 3b69e4b9 aliguori
                                  BlockDriverCompletionFunc *cb, void *opaque);
98 b2e12bc6 Christoph Hellwig
BlockDriverAIOCB *bdrv_aio_flush(BlockDriverState *bs,
99 b2e12bc6 Christoph Hellwig
                                 BlockDriverCompletionFunc *cb, void *opaque);
100 faf07963 pbrook
void bdrv_aio_cancel(BlockDriverAIOCB *acb);
101 faf07963 pbrook
102 40b4f539 Kevin Wolf
typedef struct BlockRequest {
103 40b4f539 Kevin Wolf
    /* Fields to be filled by multiwrite caller */
104 40b4f539 Kevin Wolf
    int64_t sector;
105 40b4f539 Kevin Wolf
    int nb_sectors;
106 40b4f539 Kevin Wolf
    QEMUIOVector *qiov;
107 40b4f539 Kevin Wolf
    BlockDriverCompletionFunc *cb;
108 40b4f539 Kevin Wolf
    void *opaque;
109 40b4f539 Kevin Wolf
110 40b4f539 Kevin Wolf
    /* Filled by multiwrite implementation */
111 40b4f539 Kevin Wolf
    int error;
112 40b4f539 Kevin Wolf
} BlockRequest;
113 40b4f539 Kevin Wolf
114 40b4f539 Kevin Wolf
int bdrv_aio_multiwrite(BlockDriverState *bs, BlockRequest *reqs,
115 40b4f539 Kevin Wolf
    int num_reqs);
116 40b4f539 Kevin Wolf
117 7d780669 aliguori
/* sg packet commands */
118 221f715d aliguori
int bdrv_ioctl(BlockDriverState *bs, unsigned long int req, void *buf);
119 221f715d aliguori
BlockDriverAIOCB *bdrv_aio_ioctl(BlockDriverState *bs,
120 221f715d aliguori
        unsigned long int req, void *buf,
121 221f715d aliguori
        BlockDriverCompletionFunc *cb, void *opaque);
122 7d780669 aliguori
123 faf07963 pbrook
/* Ensure contents are flushed to disk.  */
124 faf07963 pbrook
void bdrv_flush(BlockDriverState *bs);
125 c6ca28d6 aliguori
void bdrv_flush_all(void);
126 c6ca28d6 aliguori
127 f58c7b35 ths
int bdrv_is_allocated(BlockDriverState *bs, int64_t sector_num, int nb_sectors,
128 f58c7b35 ths
        int *pnum);
129 faf07963 pbrook
130 faf07963 pbrook
#define BDRV_TYPE_HD     0
131 faf07963 pbrook
#define BDRV_TYPE_CDROM  1
132 faf07963 pbrook
#define BDRV_TYPE_FLOPPY 2
133 faf07963 pbrook
#define BIOS_ATA_TRANSLATION_AUTO   0
134 faf07963 pbrook
#define BIOS_ATA_TRANSLATION_NONE   1
135 faf07963 pbrook
#define BIOS_ATA_TRANSLATION_LBA    2
136 faf07963 pbrook
#define BIOS_ATA_TRANSLATION_LARGE  3
137 faf07963 pbrook
#define BIOS_ATA_TRANSLATION_RECHS  4
138 faf07963 pbrook
139 faf07963 pbrook
void bdrv_set_geometry_hint(BlockDriverState *bs,
140 faf07963 pbrook
                            int cyls, int heads, int secs);
141 faf07963 pbrook
void bdrv_set_type_hint(BlockDriverState *bs, int type);
142 faf07963 pbrook
void bdrv_set_translation_hint(BlockDriverState *bs, int translation);
143 faf07963 pbrook
void bdrv_get_geometry_hint(BlockDriverState *bs,
144 faf07963 pbrook
                            int *pcyls, int *pheads, int *psecs);
145 faf07963 pbrook
int bdrv_get_type_hint(BlockDriverState *bs);
146 faf07963 pbrook
int bdrv_get_translation_hint(BlockDriverState *bs);
147 faf07963 pbrook
int bdrv_is_removable(BlockDriverState *bs);
148 faf07963 pbrook
int bdrv_is_read_only(BlockDriverState *bs);
149 985a03b0 ths
int bdrv_is_sg(BlockDriverState *bs);
150 e900a7b7 Christoph Hellwig
int bdrv_enable_write_cache(BlockDriverState *bs);
151 faf07963 pbrook
int bdrv_is_inserted(BlockDriverState *bs);
152 faf07963 pbrook
int bdrv_media_changed(BlockDriverState *bs);
153 faf07963 pbrook
int bdrv_is_locked(BlockDriverState *bs);
154 faf07963 pbrook
void bdrv_set_locked(BlockDriverState *bs, int locked);
155 aea2a33c Mark McLoughlin
int bdrv_eject(BlockDriverState *bs, int eject_flag);
156 faf07963 pbrook
void bdrv_set_change_cb(BlockDriverState *bs,
157 faf07963 pbrook
                        void (*change_cb)(void *opaque), void *opaque);
158 faf07963 pbrook
void bdrv_get_format(BlockDriverState *bs, char *buf, int buf_size);
159 faf07963 pbrook
BlockDriverState *bdrv_find(const char *name);
160 51de9760 aliguori
void bdrv_iterate(void (*it)(void *opaque, BlockDriverState *bs),
161 51de9760 aliguori
                  void *opaque);
162 faf07963 pbrook
int bdrv_is_encrypted(BlockDriverState *bs);
163 c0f4ce77 aliguori
int bdrv_key_required(BlockDriverState *bs);
164 faf07963 pbrook
int bdrv_set_key(BlockDriverState *bs, const char *key);
165 c0f4ce77 aliguori
int bdrv_query_missing_keys(void);
166 faf07963 pbrook
void bdrv_iterate_format(void (*it)(void *opaque, const char *name),
167 faf07963 pbrook
                         void *opaque);
168 faf07963 pbrook
const char *bdrv_get_device_name(BlockDriverState *bs);
169 faf07963 pbrook
int bdrv_write_compressed(BlockDriverState *bs, int64_t sector_num,
170 faf07963 pbrook
                          const uint8_t *buf, int nb_sectors);
171 faf07963 pbrook
int bdrv_get_info(BlockDriverState *bs, BlockDriverInfo *bdi);
172 faf07963 pbrook
173 045df330 aliguori
const char *bdrv_get_encrypted_filename(BlockDriverState *bs);
174 faf07963 pbrook
void bdrv_get_backing_filename(BlockDriverState *bs,
175 faf07963 pbrook
                               char *filename, int filename_size);
176 faf07963 pbrook
int bdrv_snapshot_create(BlockDriverState *bs,
177 faf07963 pbrook
                         QEMUSnapshotInfo *sn_info);
178 faf07963 pbrook
int bdrv_snapshot_goto(BlockDriverState *bs,
179 faf07963 pbrook
                       const char *snapshot_id);
180 faf07963 pbrook
int bdrv_snapshot_delete(BlockDriverState *bs, const char *snapshot_id);
181 faf07963 pbrook
int bdrv_snapshot_list(BlockDriverState *bs,
182 faf07963 pbrook
                       QEMUSnapshotInfo **psn_info);
183 faf07963 pbrook
char *bdrv_snapshot_dump(char *buf, int buf_size, QEMUSnapshotInfo *sn);
184 faf07963 pbrook
185 faf07963 pbrook
char *get_human_readable_size(char *buf, int buf_size, int64_t size);
186 faf07963 pbrook
int path_is_absolute(const char *path);
187 faf07963 pbrook
void path_combine(char *dest, int dest_size,
188 faf07963 pbrook
                  const char *base_path,
189 faf07963 pbrook
                  const char *filename);
190 faf07963 pbrook
191 45566e9c Christoph Hellwig
int bdrv_save_vmstate(BlockDriverState *bs, const uint8_t *buf,
192 45566e9c Christoph Hellwig
                      int64_t pos, int size);
193 178e08a5 aliguori
194 45566e9c Christoph Hellwig
int bdrv_load_vmstate(BlockDriverState *bs, uint8_t *buf,
195 45566e9c Christoph Hellwig
                      int64_t pos, int size);
196 178e08a5 aliguori
197 23bd90d2 Jan Kiszka
#define BDRV_SECTORS_PER_DIRTY_CHUNK 2048
198 6ea44308 Jan Kiszka
199 7cd1e32a lirans@il.ibm.com
void bdrv_set_dirty_tracking(BlockDriverState *bs, int enable);
200 7cd1e32a lirans@il.ibm.com
int bdrv_get_dirty(BlockDriverState *bs, int64_t sector);
201 a55eb92c Jan Kiszka
void bdrv_reset_dirty(BlockDriverState *bs, int64_t cur_sector,
202 a55eb92c Jan Kiszka
                      int nr_sectors);
203 faf07963 pbrook
#endif