Statistics
| Branch: | Revision:

root / block_int.h @ dc1c13d9

History | View | Annotate | Download (16.6 kB)

1 ea2384d3 bellard
/*
2 ea2384d3 bellard
 * QEMU System Emulator block driver
3 5fafdf24 ths
 *
4 ea2384d3 bellard
 * Copyright (c) 2003 Fabrice Bellard
5 5fafdf24 ths
 *
6 ea2384d3 bellard
 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 ea2384d3 bellard
 * of this software and associated documentation files (the "Software"), to deal
8 ea2384d3 bellard
 * in the Software without restriction, including without limitation the rights
9 ea2384d3 bellard
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 ea2384d3 bellard
 * copies of the Software, and to permit persons to whom the Software is
11 ea2384d3 bellard
 * furnished to do so, subject to the following conditions:
12 ea2384d3 bellard
 *
13 ea2384d3 bellard
 * The above copyright notice and this permission notice shall be included in
14 ea2384d3 bellard
 * all copies or substantial portions of the Software.
15 ea2384d3 bellard
 *
16 ea2384d3 bellard
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 ea2384d3 bellard
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 ea2384d3 bellard
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 ea2384d3 bellard
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 ea2384d3 bellard
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 ea2384d3 bellard
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 ea2384d3 bellard
 * THE SOFTWARE.
23 ea2384d3 bellard
 */
24 ea2384d3 bellard
#ifndef BLOCK_INT_H
25 ea2384d3 bellard
#define BLOCK_INT_H
26 ea2384d3 bellard
27 faf07963 pbrook
#include "block.h"
28 0e7e1989 Kevin Wolf
#include "qemu-option.h"
29 1b7bdbc1 Stefan Hajnoczi
#include "qemu-queue.h"
30 da1fa91d Kevin Wolf
#include "qemu-coroutine.h"
31 c488c7f6 Christoph Hellwig
#include "qemu-timer.h"
32 b2023818 Luiz Capitulino
#include "qapi-types.h"
33 9aeaddff Luiz Capitulino
#include "qerror.h"
34 faf07963 pbrook
35 bfe8043e Stefan Hajnoczi
#define BLOCK_FLAG_ENCRYPT          1
36 bfe8043e Stefan Hajnoczi
#define BLOCK_FLAG_COMPAT6          4
37 bfe8043e Stefan Hajnoczi
#define BLOCK_FLAG_LAZY_REFCOUNTS   8
38 ec36ba14 ths
39 0563e191 Zhi Yong Wu
#define BLOCK_IO_LIMIT_READ     0
40 0563e191 Zhi Yong Wu
#define BLOCK_IO_LIMIT_WRITE    1
41 0563e191 Zhi Yong Wu
#define BLOCK_IO_LIMIT_TOTAL    2
42 0563e191 Zhi Yong Wu
43 0563e191 Zhi Yong Wu
#define BLOCK_IO_SLICE_TIME     100000000
44 98f90dba Zhi Yong Wu
#define NANOSECONDS_PER_SECOND  1000000000.0
45 0563e191 Zhi Yong Wu
46 bfe8043e Stefan Hajnoczi
#define BLOCK_OPT_SIZE              "size"
47 bfe8043e Stefan Hajnoczi
#define BLOCK_OPT_ENCRYPT           "encryption"
48 bfe8043e Stefan Hajnoczi
#define BLOCK_OPT_COMPAT6           "compat6"
49 bfe8043e Stefan Hajnoczi
#define BLOCK_OPT_BACKING_FILE      "backing_file"
50 bfe8043e Stefan Hajnoczi
#define BLOCK_OPT_BACKING_FMT       "backing_fmt"
51 bfe8043e Stefan Hajnoczi
#define BLOCK_OPT_CLUSTER_SIZE      "cluster_size"
52 bfe8043e Stefan Hajnoczi
#define BLOCK_OPT_TABLE_SIZE        "table_size"
53 bfe8043e Stefan Hajnoczi
#define BLOCK_OPT_PREALLOC          "preallocation"
54 bfe8043e Stefan Hajnoczi
#define BLOCK_OPT_SUBFMT            "subformat"
55 bfe8043e Stefan Hajnoczi
#define BLOCK_OPT_COMPAT_LEVEL      "compat"
56 bfe8043e Stefan Hajnoczi
#define BLOCK_OPT_LAZY_REFCOUNTS    "lazy_refcounts"
57 0e7e1989 Kevin Wolf
58 dbffbdcf Stefan Hajnoczi
typedef struct BdrvTrackedRequest BdrvTrackedRequest;
59 dbffbdcf Stefan Hajnoczi
60 0563e191 Zhi Yong Wu
typedef struct BlockIOLimit {
61 0563e191 Zhi Yong Wu
    int64_t bps[3];
62 0563e191 Zhi Yong Wu
    int64_t iops[3];
63 0563e191 Zhi Yong Wu
} BlockIOLimit;
64 0563e191 Zhi Yong Wu
65 0563e191 Zhi Yong Wu
typedef struct BlockIOBaseValue {
66 0563e191 Zhi Yong Wu
    uint64_t bytes[2];
67 0563e191 Zhi Yong Wu
    uint64_t ios[2];
68 0563e191 Zhi Yong Wu
} BlockIOBaseValue;
69 0563e191 Zhi Yong Wu
70 eeec61f2 Stefan Hajnoczi
typedef struct BlockJob BlockJob;
71 dc534f8f Paolo Bonzini
72 dc534f8f Paolo Bonzini
/**
73 dc534f8f Paolo Bonzini
 * BlockJobType:
74 dc534f8f Paolo Bonzini
 *
75 dc534f8f Paolo Bonzini
 * A class type for block job objects.
76 dc534f8f Paolo Bonzini
 */
77 eeec61f2 Stefan Hajnoczi
typedef struct BlockJobType {
78 eeec61f2 Stefan Hajnoczi
    /** Derived BlockJob struct size */
79 eeec61f2 Stefan Hajnoczi
    size_t instance_size;
80 eeec61f2 Stefan Hajnoczi
81 eeec61f2 Stefan Hajnoczi
    /** String describing the operation, part of query-block-jobs QMP API */
82 eeec61f2 Stefan Hajnoczi
    const char *job_type;
83 eeec61f2 Stefan Hajnoczi
84 eeec61f2 Stefan Hajnoczi
    /** Optional callback for job types that support setting a speed limit */
85 882ec7ce Stefan Hajnoczi
    void (*set_speed)(BlockJob *job, int64_t speed, Error **errp);
86 eeec61f2 Stefan Hajnoczi
} BlockJobType;
87 eeec61f2 Stefan Hajnoczi
88 eeec61f2 Stefan Hajnoczi
/**
89 dc534f8f Paolo Bonzini
 * BlockJob:
90 dc534f8f Paolo Bonzini
 *
91 dc534f8f Paolo Bonzini
 * Long-running operation on a BlockDriverState.
92 eeec61f2 Stefan Hajnoczi
 */
93 eeec61f2 Stefan Hajnoczi
struct BlockJob {
94 dc534f8f Paolo Bonzini
    /** The job type, including the job vtable.  */
95 eeec61f2 Stefan Hajnoczi
    const BlockJobType *job_type;
96 dc534f8f Paolo Bonzini
97 dc534f8f Paolo Bonzini
    /** The block device on which the job is operating.  */
98 eeec61f2 Stefan Hajnoczi
    BlockDriverState *bs;
99 dc534f8f Paolo Bonzini
100 dc534f8f Paolo Bonzini
    /**
101 fa4478d5 Paolo Bonzini
     * The coroutine that executes the job.  If not NULL, it is
102 fa4478d5 Paolo Bonzini
     * reentered when busy is false and the job is cancelled.
103 fa4478d5 Paolo Bonzini
     */
104 fa4478d5 Paolo Bonzini
    Coroutine *co;
105 fa4478d5 Paolo Bonzini
106 fa4478d5 Paolo Bonzini
    /**
107 dc534f8f Paolo Bonzini
     * Set to true if the job should cancel itself.  The flag must
108 dc534f8f Paolo Bonzini
     * always be tested just before toggling the busy flag from false
109 4513eafe Paolo Bonzini
     * to true.  After a job has been cancelled, it should only yield
110 4513eafe Paolo Bonzini
     * if #qemu_aio_wait will ("sooner or later") reenter the coroutine.
111 dc534f8f Paolo Bonzini
     */
112 eeec61f2 Stefan Hajnoczi
    bool cancelled;
113 dc534f8f Paolo Bonzini
114 dc534f8f Paolo Bonzini
    /**
115 dc534f8f Paolo Bonzini
     * Set to false by the job while it is in a quiescent state, where
116 4513eafe Paolo Bonzini
     * no I/O is pending and the job has yielded on any condition
117 4513eafe Paolo Bonzini
     * that is not detected by #qemu_aio_wait, such as a timer.
118 dc534f8f Paolo Bonzini
     */
119 3e914655 Paolo Bonzini
    bool busy;
120 eeec61f2 Stefan Hajnoczi
121 dc534f8f Paolo Bonzini
    /** Offset that is published by the query-block-jobs QMP API */
122 eeec61f2 Stefan Hajnoczi
    int64_t offset;
123 dc534f8f Paolo Bonzini
124 dc534f8f Paolo Bonzini
    /** Length that is published by the query-block-jobs QMP API */
125 eeec61f2 Stefan Hajnoczi
    int64_t len;
126 dc534f8f Paolo Bonzini
127 dc534f8f Paolo Bonzini
    /** Speed that was set with @block_job_set_speed.  */
128 eeec61f2 Stefan Hajnoczi
    int64_t speed;
129 eeec61f2 Stefan Hajnoczi
130 dc534f8f Paolo Bonzini
    /** The completion function that will be called when the job completes.  */
131 eeec61f2 Stefan Hajnoczi
    BlockDriverCompletionFunc *cb;
132 dc534f8f Paolo Bonzini
133 dc534f8f Paolo Bonzini
    /** The opaque value that is passed to the completion function.  */
134 eeec61f2 Stefan Hajnoczi
    void *opaque;
135 eeec61f2 Stefan Hajnoczi
};
136 eeec61f2 Stefan Hajnoczi
137 ea2384d3 bellard
struct BlockDriver {
138 ea2384d3 bellard
    const char *format_name;
139 ea2384d3 bellard
    int instance_size;
140 ea2384d3 bellard
    int (*bdrv_probe)(const uint8_t *buf, int buf_size, const char *filename);
141 508c7cb3 Christoph Hellwig
    int (*bdrv_probe_device)(const char *filename);
142 e971aa12 Jeff Cody
143 e971aa12 Jeff Cody
    /* For handling image reopen for split or non-split files */
144 e971aa12 Jeff Cody
    int (*bdrv_reopen_prepare)(BDRVReopenState *reopen_state,
145 e971aa12 Jeff Cody
                               BlockReopenQueue *queue, Error **errp);
146 e971aa12 Jeff Cody
    void (*bdrv_reopen_commit)(BDRVReopenState *reopen_state);
147 e971aa12 Jeff Cody
    void (*bdrv_reopen_abort)(BDRVReopenState *reopen_state);
148 e971aa12 Jeff Cody
149 66f82cee Kevin Wolf
    int (*bdrv_open)(BlockDriverState *bs, int flags);
150 66f82cee Kevin Wolf
    int (*bdrv_file_open)(BlockDriverState *bs, const char *filename, int flags);
151 5fafdf24 ths
    int (*bdrv_read)(BlockDriverState *bs, int64_t sector_num,
152 ea2384d3 bellard
                     uint8_t *buf, int nb_sectors);
153 5fafdf24 ths
    int (*bdrv_write)(BlockDriverState *bs, int64_t sector_num,
154 ea2384d3 bellard
                      const uint8_t *buf, int nb_sectors);
155 e2731add bellard
    void (*bdrv_close)(BlockDriverState *bs);
156 e023b2e2 Paolo Bonzini
    void (*bdrv_rebind)(BlockDriverState *bs);
157 0e7e1989 Kevin Wolf
    int (*bdrv_create)(const char *filename, QEMUOptionParameter *options);
158 ea2384d3 bellard
    int (*bdrv_set_key)(BlockDriverState *bs, const char *key);
159 95389c86 bellard
    int (*bdrv_make_empty)(BlockDriverState *bs);
160 83f64091 bellard
    /* aio */
161 f141eafe aliguori
    BlockDriverAIOCB *(*bdrv_aio_readv)(BlockDriverState *bs,
162 f141eafe aliguori
        int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
163 ce1a14dc pbrook
        BlockDriverCompletionFunc *cb, void *opaque);
164 f141eafe aliguori
    BlockDriverAIOCB *(*bdrv_aio_writev)(BlockDriverState *bs,
165 f141eafe aliguori
        int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
166 ce1a14dc pbrook
        BlockDriverCompletionFunc *cb, void *opaque);
167 b2e12bc6 Christoph Hellwig
    BlockDriverAIOCB *(*bdrv_aio_flush)(BlockDriverState *bs,
168 b2e12bc6 Christoph Hellwig
        BlockDriverCompletionFunc *cb, void *opaque);
169 4265d620 Paolo Bonzini
    BlockDriverAIOCB *(*bdrv_aio_discard)(BlockDriverState *bs,
170 4265d620 Paolo Bonzini
        int64_t sector_num, int nb_sectors,
171 4265d620 Paolo Bonzini
        BlockDriverCompletionFunc *cb, void *opaque);
172 83f64091 bellard
173 da1fa91d Kevin Wolf
    int coroutine_fn (*bdrv_co_readv)(BlockDriverState *bs,
174 da1fa91d Kevin Wolf
        int64_t sector_num, int nb_sectors, QEMUIOVector *qiov);
175 da1fa91d Kevin Wolf
    int coroutine_fn (*bdrv_co_writev)(BlockDriverState *bs,
176 da1fa91d Kevin Wolf
        int64_t sector_num, int nb_sectors, QEMUIOVector *qiov);
177 f08f2dda Stefan Hajnoczi
    /*
178 f08f2dda Stefan Hajnoczi
     * Efficiently zero a region of the disk image.  Typically an image format
179 f08f2dda Stefan Hajnoczi
     * would use a compact metadata representation to implement this.  This
180 f08f2dda Stefan Hajnoczi
     * function pointer may be NULL and .bdrv_co_writev() will be called
181 f08f2dda Stefan Hajnoczi
     * instead.
182 f08f2dda Stefan Hajnoczi
     */
183 f08f2dda Stefan Hajnoczi
    int coroutine_fn (*bdrv_co_write_zeroes)(BlockDriverState *bs,
184 f08f2dda Stefan Hajnoczi
        int64_t sector_num, int nb_sectors);
185 4265d620 Paolo Bonzini
    int coroutine_fn (*bdrv_co_discard)(BlockDriverState *bs,
186 4265d620 Paolo Bonzini
        int64_t sector_num, int nb_sectors);
187 376ae3f1 Stefan Hajnoczi
    int coroutine_fn (*bdrv_co_is_allocated)(BlockDriverState *bs,
188 376ae3f1 Stefan Hajnoczi
        int64_t sector_num, int nb_sectors, int *pnum);
189 da1fa91d Kevin Wolf
190 c68b89ac Kevin Wolf
    /*
191 0f15423c Anthony Liguori
     * Invalidate any cached meta-data.
192 0f15423c Anthony Liguori
     */
193 0f15423c Anthony Liguori
    void (*bdrv_invalidate_cache)(BlockDriverState *bs);
194 0f15423c Anthony Liguori
195 0f15423c Anthony Liguori
    /*
196 c68b89ac Kevin Wolf
     * Flushes all data that was already written to the OS all the way down to
197 c68b89ac Kevin Wolf
     * the disk (for example raw-posix calls fsync()).
198 c68b89ac Kevin Wolf
     */
199 c68b89ac Kevin Wolf
    int coroutine_fn (*bdrv_co_flush_to_disk)(BlockDriverState *bs);
200 c68b89ac Kevin Wolf
201 eb489bb1 Kevin Wolf
    /*
202 eb489bb1 Kevin Wolf
     * Flushes all internal caches to the OS. The data may still sit in a
203 eb489bb1 Kevin Wolf
     * writeback cache of the host OS, but it will survive a crash of the qemu
204 eb489bb1 Kevin Wolf
     * process.
205 eb489bb1 Kevin Wolf
     */
206 eb489bb1 Kevin Wolf
    int coroutine_fn (*bdrv_co_flush_to_os)(BlockDriverState *bs);
207 eb489bb1 Kevin Wolf
208 83f64091 bellard
    const char *protocol_name;
209 83f64091 bellard
    int (*bdrv_truncate)(BlockDriverState *bs, int64_t offset);
210 83f64091 bellard
    int64_t (*bdrv_getlength)(BlockDriverState *bs);
211 4a1d5e1f Fam Zheng
    int64_t (*bdrv_get_allocated_file_size)(BlockDriverState *bs);
212 5fafdf24 ths
    int (*bdrv_write_compressed)(BlockDriverState *bs, int64_t sector_num,
213 faea38e7 bellard
                                 const uint8_t *buf, int nb_sectors);
214 faea38e7 bellard
215 5fafdf24 ths
    int (*bdrv_snapshot_create)(BlockDriverState *bs,
216 faea38e7 bellard
                                QEMUSnapshotInfo *sn_info);
217 5fafdf24 ths
    int (*bdrv_snapshot_goto)(BlockDriverState *bs,
218 faea38e7 bellard
                              const char *snapshot_id);
219 faea38e7 bellard
    int (*bdrv_snapshot_delete)(BlockDriverState *bs, const char *snapshot_id);
220 5fafdf24 ths
    int (*bdrv_snapshot_list)(BlockDriverState *bs,
221 faea38e7 bellard
                              QEMUSnapshotInfo **psn_info);
222 51ef6727 edison
    int (*bdrv_snapshot_load_tmp)(BlockDriverState *bs,
223 51ef6727 edison
                                  const char *snapshot_name);
224 faea38e7 bellard
    int (*bdrv_get_info)(BlockDriverState *bs, BlockDriverInfo *bdi);
225 83f64091 bellard
226 45566e9c Christoph Hellwig
    int (*bdrv_save_vmstate)(BlockDriverState *bs, const uint8_t *buf,
227 45566e9c Christoph Hellwig
                             int64_t pos, int size);
228 45566e9c Christoph Hellwig
    int (*bdrv_load_vmstate)(BlockDriverState *bs, uint8_t *buf,
229 45566e9c Christoph Hellwig
                             int64_t pos, int size);
230 178e08a5 aliguori
231 756e6736 Kevin Wolf
    int (*bdrv_change_backing_file)(BlockDriverState *bs,
232 756e6736 Kevin Wolf
        const char *backing_file, const char *backing_fmt);
233 756e6736 Kevin Wolf
234 19cb3738 bellard
    /* removable device specific */
235 19cb3738 bellard
    int (*bdrv_is_inserted)(BlockDriverState *bs);
236 19cb3738 bellard
    int (*bdrv_media_changed)(BlockDriverState *bs);
237 f36f3949 Luiz Capitulino
    void (*bdrv_eject)(BlockDriverState *bs, bool eject_flag);
238 025e849a Markus Armbruster
    void (*bdrv_lock_medium)(BlockDriverState *bs, bool locked);
239 3b46e624 ths
240 985a03b0 ths
    /* to control generic scsi devices */
241 985a03b0 ths
    int (*bdrv_ioctl)(BlockDriverState *bs, unsigned long int req, void *buf);
242 221f715d aliguori
    BlockDriverAIOCB *(*bdrv_aio_ioctl)(BlockDriverState *bs,
243 221f715d aliguori
        unsigned long int req, void *buf,
244 221f715d aliguori
        BlockDriverCompletionFunc *cb, void *opaque);
245 985a03b0 ths
246 0e7e1989 Kevin Wolf
    /* List of options for creating images, terminated by name == NULL */
247 0e7e1989 Kevin Wolf
    QEMUOptionParameter *create_options;
248 0e7e1989 Kevin Wolf
249 5eb45639 aliguori
250 9ac228e0 Kevin Wolf
    /*
251 9ac228e0 Kevin Wolf
     * Returns 0 for completed check, -errno for internal errors.
252 9ac228e0 Kevin Wolf
     * The check results are stored in result.
253 9ac228e0 Kevin Wolf
     */
254 4534ff54 Kevin Wolf
    int (*bdrv_check)(BlockDriverState* bs, BdrvCheckResult *result,
255 4534ff54 Kevin Wolf
        BdrvCheckMode fix);
256 e97fc193 aliguori
257 8b9b0cc2 Kevin Wolf
    void (*bdrv_debug_event)(BlockDriverState *bs, BlkDebugEvent event);
258 8b9b0cc2 Kevin Wolf
259 336c1c12 Kevin Wolf
    /*
260 336c1c12 Kevin Wolf
     * Returns 1 if newly created images are guaranteed to contain only
261 336c1c12 Kevin Wolf
     * zeros, 0 otherwise.
262 336c1c12 Kevin Wolf
     */
263 336c1c12 Kevin Wolf
    int (*bdrv_has_zero_init)(BlockDriverState *bs);
264 12c09b8c Kevin Wolf
265 8a22f02a Stefan Hajnoczi
    QLIST_ENTRY(BlockDriver) list;
266 ea2384d3 bellard
};
267 ea2384d3 bellard
268 8802d1fd Jeff Cody
/*
269 8802d1fd Jeff Cody
 * Note: the function bdrv_append() copies and swaps contents of
270 8802d1fd Jeff Cody
 * BlockDriverStates, so if you add new fields to this struct, please
271 8802d1fd Jeff Cody
 * inspect bdrv_append() to determine if the new fields need to be
272 8802d1fd Jeff Cody
 * copied as well.
273 8802d1fd Jeff Cody
 */
274 ea2384d3 bellard
struct BlockDriverState {
275 d15a771d bellard
    int64_t total_sectors; /* if we are reading a disk image, give its
276 d15a771d bellard
                              size in sectors */
277 ea2384d3 bellard
    int read_only; /* if true, the media is read only */
278 4dca4b63 Naphtali Sprei
    int open_flags; /* flags used to open the file, re-used for re-open */
279 ea2384d3 bellard
    int encrypted; /* if true, the media is encrypted */
280 c0f4ce77 aliguori
    int valid_key; /* if true, a valid encryption key has been set */
281 985a03b0 ths
    int sg;        /* if true, the device is a /dev/sg* */
282 53fec9d3 Stefan Hajnoczi
    int copy_on_read; /* if true, copy read backing sectors into image
283 53fec9d3 Stefan Hajnoczi
                         note this is a reference count */
284 ea2384d3 bellard
285 19cb3738 bellard
    BlockDriver *drv; /* NULL means no media */
286 ea2384d3 bellard
    void *opaque;
287 ea2384d3 bellard
288 fa879d62 Markus Armbruster
    void *dev;                  /* attached device model, if any */
289 fa879d62 Markus Armbruster
    /* TODO change to DeviceState when all users are qdevified */
290 0e49de52 Markus Armbruster
    const BlockDevOps *dev_ops;
291 0e49de52 Markus Armbruster
    void *dev_opaque;
292 18846dee Markus Armbruster
293 ea2384d3 bellard
    char filename[1024];
294 ea2384d3 bellard
    char backing_file[1024]; /* if non zero, the image is a diff of
295 ea2384d3 bellard
                                this file image */
296 5eb45639 aliguori
    char backing_format[16]; /* if non-zero and backing_file exists */
297 ea2384d3 bellard
    int is_temporary;
298 19cb3738 bellard
299 ea2384d3 bellard
    BlockDriverState *backing_hd;
300 66f82cee Kevin Wolf
    BlockDriverState *file;
301 66f82cee Kevin Wolf
302 470c0504 Stefan Hajnoczi
    /* number of in-flight copy-on-read requests */
303 470c0504 Stefan Hajnoczi
    unsigned int copy_on_read_in_flight;
304 470c0504 Stefan Hajnoczi
305 0563e191 Zhi Yong Wu
    /* the time for latest disk I/O */
306 0563e191 Zhi Yong Wu
    int64_t slice_time;
307 0563e191 Zhi Yong Wu
    int64_t slice_start;
308 0563e191 Zhi Yong Wu
    int64_t slice_end;
309 0563e191 Zhi Yong Wu
    BlockIOLimit io_limits;
310 0563e191 Zhi Yong Wu
    BlockIOBaseValue  io_base;
311 0563e191 Zhi Yong Wu
    CoQueue      throttled_reqs;
312 0563e191 Zhi Yong Wu
    QEMUTimer    *block_timer;
313 0563e191 Zhi Yong Wu
    bool         io_limits_enabled;
314 0563e191 Zhi Yong Wu
315 a36e69dd ths
    /* I/O stats (display with "info blockstats"). */
316 a597e79c Christoph Hellwig
    uint64_t nr_bytes[BDRV_MAX_IOTYPE];
317 a597e79c Christoph Hellwig
    uint64_t nr_ops[BDRV_MAX_IOTYPE];
318 c488c7f6 Christoph Hellwig
    uint64_t total_time_ns[BDRV_MAX_IOTYPE];
319 294cc35f Kevin Wolf
    uint64_t wr_highest_sector;
320 a36e69dd ths
321 71d0770c aliguori
    /* Whether the disk can expand beyond total_sectors */
322 71d0770c aliguori
    int growable;
323 71d0770c aliguori
324 e268ca52 aliguori
    /* the memory alignment required for the buffers handled by this driver */
325 e268ca52 aliguori
    int buffer_alignment;
326 e268ca52 aliguori
327 e900a7b7 Christoph Hellwig
    /* do we need to tell the quest if we have a volatile write cache? */
328 e900a7b7 Christoph Hellwig
    int enable_write_cache;
329 e900a7b7 Christoph Hellwig
330 ea2384d3 bellard
    /* NOTE: the following infos are only hints for real hardware
331 ea2384d3 bellard
       drivers. They are not used by the block driver */
332 abd7f68d Markus Armbruster
    BlockErrorAction on_read_error, on_write_error;
333 d6bf279e Luiz Capitulino
    bool iostatus_enabled;
334 b2023818 Luiz Capitulino
    BlockDeviceIoStatus iostatus;
335 ea2384d3 bellard
    char device_name[32];
336 c6d22830 Jan Kiszka
    unsigned long *dirty_bitmap;
337 aaa0eb75 Liran Schour
    int64_t dirty_count;
338 db593f25 Marcelo Tosatti
    int in_use; /* users other than guest access, eg. block migration */
339 1b7bdbc1 Stefan Hajnoczi
    QTAILQ_ENTRY(BlockDriverState) list;
340 dbffbdcf Stefan Hajnoczi
341 dbffbdcf Stefan Hajnoczi
    QLIST_HEAD(, BdrvTrackedRequest) tracked_requests;
342 eeec61f2 Stefan Hajnoczi
343 eeec61f2 Stefan Hajnoczi
    /* long-running background operation */
344 eeec61f2 Stefan Hajnoczi
    BlockJob *job;
345 e971aa12 Jeff Cody
346 ea2384d3 bellard
};
347 ea2384d3 bellard
348 eba25057 Jim Meyering
int get_tmp_filename(char *filename, int size);
349 95389c86 bellard
350 0563e191 Zhi Yong Wu
void bdrv_set_io_limits(BlockDriverState *bs,
351 0563e191 Zhi Yong Wu
                        BlockIOLimit *io_limits);
352 0563e191 Zhi Yong Wu
353 508c7cb3 Christoph Hellwig
#ifdef _WIN32
354 508c7cb3 Christoph Hellwig
int is_windows_drive(const char *filename);
355 508c7cb3 Christoph Hellwig
#endif
356 508c7cb3 Christoph Hellwig
357 dc534f8f Paolo Bonzini
/**
358 dc534f8f Paolo Bonzini
 * block_job_create:
359 dc534f8f Paolo Bonzini
 * @job_type: The class object for the newly-created job.
360 dc534f8f Paolo Bonzini
 * @bs: The block
361 c83c66c3 Stefan Hajnoczi
 * @speed: The maximum speed, in bytes per second, or 0 for unlimited.
362 dc534f8f Paolo Bonzini
 * @cb: Completion function for the job.
363 dc534f8f Paolo Bonzini
 * @opaque: Opaque pointer value passed to @cb.
364 fd7f8c65 Stefan Hajnoczi
 * @errp: Error object.
365 dc534f8f Paolo Bonzini
 *
366 dc534f8f Paolo Bonzini
 * Create a new long-running block device job and return it.  The job
367 dc534f8f Paolo Bonzini
 * will call @cb asynchronously when the job completes.  Note that
368 dc534f8f Paolo Bonzini
 * @bs may have been closed at the time the @cb it is called.  If
369 dc534f8f Paolo Bonzini
 * this is the case, the job may be reported as either cancelled or
370 dc534f8f Paolo Bonzini
 * completed.
371 dc534f8f Paolo Bonzini
 *
372 dc534f8f Paolo Bonzini
 * This function is not part of the public job interface; it should be
373 dc534f8f Paolo Bonzini
 * called from a wrapper that is specific to the job type.
374 dc534f8f Paolo Bonzini
 */
375 eeec61f2 Stefan Hajnoczi
void *block_job_create(const BlockJobType *job_type, BlockDriverState *bs,
376 c83c66c3 Stefan Hajnoczi
                       int64_t speed, BlockDriverCompletionFunc *cb,
377 c83c66c3 Stefan Hajnoczi
                       void *opaque, Error **errp);
378 dc534f8f Paolo Bonzini
379 dc534f8f Paolo Bonzini
/**
380 4513eafe Paolo Bonzini
 * block_job_sleep_ns:
381 4513eafe Paolo Bonzini
 * @job: The job that calls the function.
382 4513eafe Paolo Bonzini
 * @clock: The clock to sleep on.
383 4513eafe Paolo Bonzini
 * @ns: How many nanoseconds to stop for.
384 4513eafe Paolo Bonzini
 *
385 4513eafe Paolo Bonzini
 * Put the job to sleep (assuming that it wasn't canceled) for @ns
386 4513eafe Paolo Bonzini
 * nanoseconds.  Canceling the job will interrupt the wait immediately.
387 4513eafe Paolo Bonzini
 */
388 4513eafe Paolo Bonzini
void block_job_sleep_ns(BlockJob *job, QEMUClock *clock, int64_t ns);
389 4513eafe Paolo Bonzini
390 4513eafe Paolo Bonzini
/**
391 dc534f8f Paolo Bonzini
 * block_job_complete:
392 dc534f8f Paolo Bonzini
 * @job: The job being completed.
393 dc534f8f Paolo Bonzini
 * @ret: The status code.
394 dc534f8f Paolo Bonzini
 *
395 dc534f8f Paolo Bonzini
 * Call the completion function that was registered at creation time, and
396 dc534f8f Paolo Bonzini
 * free @job.
397 dc534f8f Paolo Bonzini
 */
398 eeec61f2 Stefan Hajnoczi
void block_job_complete(BlockJob *job, int ret);
399 dc534f8f Paolo Bonzini
400 dc534f8f Paolo Bonzini
/**
401 dc534f8f Paolo Bonzini
 * block_job_set_speed:
402 dc534f8f Paolo Bonzini
 * @job: The job to set the speed for.
403 dc534f8f Paolo Bonzini
 * @speed: The new value
404 9e6636c7 Stefan Hajnoczi
 * @errp: Error object.
405 dc534f8f Paolo Bonzini
 *
406 dc534f8f Paolo Bonzini
 * Set a rate-limiting parameter for the job; the actual meaning may
407 dc534f8f Paolo Bonzini
 * vary depending on the job type.
408 dc534f8f Paolo Bonzini
 */
409 882ec7ce Stefan Hajnoczi
void block_job_set_speed(BlockJob *job, int64_t speed, Error **errp);
410 dc534f8f Paolo Bonzini
411 dc534f8f Paolo Bonzini
/**
412 dc534f8f Paolo Bonzini
 * block_job_cancel:
413 dc534f8f Paolo Bonzini
 * @job: The job to be canceled.
414 dc534f8f Paolo Bonzini
 *
415 dc534f8f Paolo Bonzini
 * Asynchronously cancel the specified job.
416 dc534f8f Paolo Bonzini
 */
417 eeec61f2 Stefan Hajnoczi
void block_job_cancel(BlockJob *job);
418 dc534f8f Paolo Bonzini
419 dc534f8f Paolo Bonzini
/**
420 dc534f8f Paolo Bonzini
 * block_job_is_cancelled:
421 dc534f8f Paolo Bonzini
 * @job: The job being queried.
422 dc534f8f Paolo Bonzini
 *
423 dc534f8f Paolo Bonzini
 * Returns whether the job is scheduled for cancellation.
424 dc534f8f Paolo Bonzini
 */
425 eeec61f2 Stefan Hajnoczi
bool block_job_is_cancelled(BlockJob *job);
426 dc534f8f Paolo Bonzini
427 dc534f8f Paolo Bonzini
/**
428 dc534f8f Paolo Bonzini
 * block_job_cancel:
429 dc534f8f Paolo Bonzini
 * @job: The job to be canceled.
430 dc534f8f Paolo Bonzini
 *
431 dc534f8f Paolo Bonzini
 * Asynchronously cancel the job and wait for it to reach a quiescent
432 dc534f8f Paolo Bonzini
 * state.  Note that the completion callback will still be called
433 dc534f8f Paolo Bonzini
 * asynchronously, hence it is *not* valid to call #bdrv_delete
434 dc534f8f Paolo Bonzini
 * immediately after #block_job_cancel_sync.  Users of block jobs
435 dc534f8f Paolo Bonzini
 * will usually protect the BlockDriverState objects with a reference
436 dc534f8f Paolo Bonzini
 * count, should this be a concern.
437 fa4478d5 Paolo Bonzini
 *
438 fa4478d5 Paolo Bonzini
 * Returns the return value from the job if the job actually completed
439 fa4478d5 Paolo Bonzini
 * during the call, or -ECANCELED if it was canceled.
440 dc534f8f Paolo Bonzini
 */
441 fa4478d5 Paolo Bonzini
int block_job_cancel_sync(BlockJob *job);
442 eeec61f2 Stefan Hajnoczi
443 dc534f8f Paolo Bonzini
/**
444 dc534f8f Paolo Bonzini
 * stream_start:
445 dc534f8f Paolo Bonzini
 * @bs: Block device to operate on.
446 dc534f8f Paolo Bonzini
 * @base: Block device that will become the new base, or %NULL to
447 dc534f8f Paolo Bonzini
 * flatten the whole backing file chain onto @bs.
448 dc534f8f Paolo Bonzini
 * @base_id: The file name that will be written to @bs as the new
449 dc534f8f Paolo Bonzini
 * backing file if the job completes.  Ignored if @base is %NULL.
450 c83c66c3 Stefan Hajnoczi
 * @speed: The maximum speed, in bytes per second, or 0 for unlimited.
451 dc534f8f Paolo Bonzini
 * @cb: Completion function for the job.
452 dc534f8f Paolo Bonzini
 * @opaque: Opaque pointer value passed to @cb.
453 fd7f8c65 Stefan Hajnoczi
 * @errp: Error object.
454 dc534f8f Paolo Bonzini
 *
455 dc534f8f Paolo Bonzini
 * Start a streaming operation on @bs.  Clusters that are unallocated
456 dc534f8f Paolo Bonzini
 * in @bs, but allocated in any image between @base and @bs (both
457 dc534f8f Paolo Bonzini
 * exclusive) will be written to @bs.  At the end of a successful
458 dc534f8f Paolo Bonzini
 * streaming job, the backing file of @bs will be changed to
459 dc534f8f Paolo Bonzini
 * @base_id in the written image and to @base in the live BlockDriverState.
460 dc534f8f Paolo Bonzini
 */
461 fd7f8c65 Stefan Hajnoczi
void stream_start(BlockDriverState *bs, BlockDriverState *base,
462 c83c66c3 Stefan Hajnoczi
                  const char *base_id, int64_t speed,
463 c83c66c3 Stefan Hajnoczi
                  BlockDriverCompletionFunc *cb,
464 fd7f8c65 Stefan Hajnoczi
                  void *opaque, Error **errp);
465 4f1043b4 Stefan Hajnoczi
466 ea2384d3 bellard
#endif /* BLOCK_INT_H */