#include "qemu/module.h"
#include "qemu/bswap.h"
#include "qemu/bitmap.h"
-#include "qapi/util.h"
/**************************************************************/
PRL_PREALLOC_MODE__MAX = 2,
} ParallelsPreallocMode;
-static const char *prealloc_mode_lookup[] = {
- "falloc",
- "truncate",
- NULL,
+static QEnumLookup prealloc_mode_lookup = {
+ .array = (const char *const[]) {
+ "falloc",
+ "truncate",
+ NULL,
+ },
+ .size = PRL_PREALLOC_MODE__MAX
};
-
typedef struct BDRVParallelsState {
/** Locking is conservative, the lock protects
* - image file extending (truncate, fallocate)
int nb_sectors, int *pnum)
{
BDRVParallelsState *s = bs->opaque;
- int64_t pos, space, idx, to_allocate, i;
+ int64_t pos, space, idx, to_allocate, i, len;
pos = block_status(s, sector_num, nb_sectors, pnum);
if (pos > 0) {
assert(idx < s->bat_size && idx + to_allocate <= s->bat_size);
space = to_allocate * s->tracks;
- if (s->data_end + space > bdrv_getlength(bs->file->bs) >> BDRV_SECTOR_BITS) {
+ len = bdrv_getlength(bs->file->bs);
+ if (len < 0) {
+ return len;
+ }
+ if (s->data_end + space > (len >> BDRV_SECTOR_BITS)) {
int ret;
space += s->prealloc_size;
if (s->prealloc_mode == PRL_PREALLOC_MODE_FALLOCATE) {
qemu_opt_get_size_del(opts, PARALLELS_OPT_PREALLOC_SIZE, 0);
s->prealloc_size = MAX(s->tracks, s->prealloc_size >> BDRV_SECTOR_BITS);
buf = qemu_opt_get_del(opts, PARALLELS_OPT_PREALLOC_MODE);
- s->prealloc_mode = qapi_enum_parse(prealloc_mode_lookup, buf,
- PRL_PREALLOC_MODE__MAX, PRL_PREALLOC_MODE_FALLOCATE, &local_err);
+ s->prealloc_mode = qapi_enum_parse(&prealloc_mode_lookup, buf,
+ PRL_PREALLOC_MODE_FALLOCATE,
+ &local_err);
g_free(buf);
if (local_err != NULL) {
goto fail_options;
}
- if (!(flags & BDRV_O_RESIZE) || !bdrv_has_zero_init(bs->file->bs) ||
- bdrv_truncate(bs->file, bdrv_getlength(bs->file->bs),
- PREALLOC_MODE_OFF, NULL) != 0) {
+ if (!bdrv_has_zero_init(bs->file->bs)) {
s->prealloc_mode = PRL_PREALLOC_MODE_FALLOCATE;
}