summaryrefslogtreecommitdiff
path: root/block
diff options
context:
space:
mode:
authorDenis V. Lunev <den@openvz.org>2015-04-28 10:46:51 +0300
committerStefan Hajnoczi <stefanha@redhat.com>2015-05-22 09:37:32 +0100
commit23d6bd3bd1225e8c8ade6ed829eabcf90ddfa6f7 (patch)
tree877e872e2a0210d3c3871397e717e7ed21cef22a /block
parent9eae9cca95e76afc2f2288a665e08a64953f2820 (diff)
block/parallels: move parallels_open/probe to the very end of the file
This will help to avoid forward declarations for upcoming parallels_check Some very obvious formatting fixes were made to the moved code to make checkpatch happy. Signed-off-by: Denis V. Lunev <den@openvz.org> Reviewed-by: Roman Kagan <rkagan@parallels.com> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> Signed-off-by: Roman Kagan <rkagan@parallels.com> Message-id: 1430207220-24458-19-git-send-email-den@openvz.org CC: Kevin Wolf <kwolf@redhat.com> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Diffstat (limited to 'block')
-rw-r--r--block/parallels.c191
1 files changed, 98 insertions, 93 deletions
diff --git a/block/parallels.c b/block/parallels.c
index f8a99810ed..35ffb6f398 100644
--- a/block/parallels.c
+++ b/block/parallels.c
@@ -73,99 +73,6 @@ typedef struct BDRVParallelsState {
bool has_truncate;
} BDRVParallelsState;
-static int parallels_probe(const uint8_t *buf, int buf_size, const char *filename)
-{
- const ParallelsHeader *ph = (const void *)buf;
-
- if (buf_size < sizeof(ParallelsHeader))
- return 0;
-
- if ((!memcmp(ph->magic, HEADER_MAGIC, 16) ||
- !memcmp(ph->magic, HEADER_MAGIC2, 16)) &&
- (le32_to_cpu(ph->version) == HEADER_VERSION))
- return 100;
-
- return 0;
-}
-
-static int parallels_open(BlockDriverState *bs, QDict *options, int flags,
- Error **errp)
-{
- BDRVParallelsState *s = bs->opaque;
- ParallelsHeader ph;
- int ret, size;
-
- ret = bdrv_pread(bs->file, 0, &ph, sizeof(ph));
- if (ret < 0) {
- goto fail;
- }
-
- bs->total_sectors = le64_to_cpu(ph.nb_sectors);
-
- if (le32_to_cpu(ph.version) != HEADER_VERSION) {
- goto fail_format;
- }
- if (!memcmp(ph.magic, HEADER_MAGIC, 16)) {
- s->off_multiplier = 1;
- bs->total_sectors = 0xffffffff & bs->total_sectors;
- } else if (!memcmp(ph.magic, HEADER_MAGIC2, 16)) {
- s->off_multiplier = le32_to_cpu(ph.tracks);
- } else {
- goto fail_format;
- }
-
- s->tracks = le32_to_cpu(ph.tracks);
- if (s->tracks == 0) {
- error_setg(errp, "Invalid image: Zero sectors per track");
- ret = -EINVAL;
- goto fail;
- }
- if (s->tracks > INT32_MAX/513) {
- error_setg(errp, "Invalid image: Too big cluster");
- ret = -EFBIG;
- goto fail;
- }
-
- s->bat_size = le32_to_cpu(ph.bat_entries);
- if (s->bat_size > INT_MAX / sizeof(uint32_t)) {
- error_setg(errp, "Catalog too large");
- ret = -EFBIG;
- goto fail;
- }
-
- size = sizeof(ParallelsHeader) + sizeof(uint32_t) * s->bat_size;
- s->header_size = ROUND_UP(size, bdrv_opt_mem_align(bs->file));
- s->header = qemu_try_blockalign(bs->file, s->header_size);
- if (s->header == NULL) {
- ret = -ENOMEM;
- goto fail;
- }
- if (le32_to_cpu(ph.data_off) < s->header_size) {
- /* there is not enough unused space to fit to block align between BAT
- and actual data. We can't avoid read-modify-write... */
- s->header_size = size;
- }
-
- ret = bdrv_pread(bs->file, 0, s->header, s->header_size);
- if (ret < 0) {
- goto fail;
- }
- s->bat_bitmap = (uint32_t *)(s->header + 1);
-
- s->has_truncate = bdrv_has_zero_init(bs->file) &&
- bdrv_truncate(bs->file, bdrv_getlength(bs->file)) == 0;
-
- qemu_co_mutex_init(&s->lock);
- return 0;
-
-fail_format:
- error_setg(errp, "Image not in Parallels format");
- ret = -EINVAL;
-fail:
- qemu_vfree(s->header);
- return ret;
-}
-
static int64_t bat2sect(BDRVParallelsState *s, uint32_t idx)
{
@@ -407,6 +314,104 @@ exit:
goto done;
}
+
+static int parallels_probe(const uint8_t *buf, int buf_size,
+ const char *filename)
+{
+ const ParallelsHeader *ph = (const void *)buf;
+
+ if (buf_size < sizeof(ParallelsHeader)) {
+ return 0;
+ }
+
+ if ((!memcmp(ph->magic, HEADER_MAGIC, 16) ||
+ !memcmp(ph->magic, HEADER_MAGIC2, 16)) &&
+ (le32_to_cpu(ph->version) == HEADER_VERSION)) {
+ return 100;
+ }
+
+ return 0;
+}
+
+static int parallels_open(BlockDriverState *bs, QDict *options, int flags,
+ Error **errp)
+{
+ BDRVParallelsState *s = bs->opaque;
+ ParallelsHeader ph;
+ int ret, size;
+
+ ret = bdrv_pread(bs->file, 0, &ph, sizeof(ph));
+ if (ret < 0) {
+ goto fail;
+ }
+
+ bs->total_sectors = le64_to_cpu(ph.nb_sectors);
+
+ if (le32_to_cpu(ph.version) != HEADER_VERSION) {
+ goto fail_format;
+ }
+ if (!memcmp(ph.magic, HEADER_MAGIC, 16)) {
+ s->off_multiplier = 1;
+ bs->total_sectors = 0xffffffff & bs->total_sectors;
+ } else if (!memcmp(ph.magic, HEADER_MAGIC2, 16)) {
+ s->off_multiplier = le32_to_cpu(ph.tracks);
+ } else {
+ goto fail_format;
+ }
+
+ s->tracks = le32_to_cpu(ph.tracks);
+ if (s->tracks == 0) {
+ error_setg(errp, "Invalid image: Zero sectors per track");
+ ret = -EINVAL;
+ goto fail;
+ }
+ if (s->tracks > INT32_MAX/513) {
+ error_setg(errp, "Invalid image: Too big cluster");
+ ret = -EFBIG;
+ goto fail;
+ }
+
+ s->bat_size = le32_to_cpu(ph.bat_entries);
+ if (s->bat_size > INT_MAX / sizeof(uint32_t)) {
+ error_setg(errp, "Catalog too large");
+ ret = -EFBIG;
+ goto fail;
+ }
+
+ size = sizeof(ParallelsHeader) + sizeof(uint32_t) * s->bat_size;
+ s->header_size = ROUND_UP(size, bdrv_opt_mem_align(bs->file));
+ s->header = qemu_try_blockalign(bs->file, s->header_size);
+ if (s->header == NULL) {
+ ret = -ENOMEM;
+ goto fail;
+ }
+ if (le32_to_cpu(ph.data_off) < s->header_size) {
+ /* there is not enough unused space to fit to block align between BAT
+ and actual data. We can't avoid read-modify-write... */
+ s->header_size = size;
+ }
+
+ ret = bdrv_pread(bs->file, 0, s->header, s->header_size);
+ if (ret < 0) {
+ goto fail;
+ }
+ s->bat_bitmap = (uint32_t *)(s->header + 1);
+
+ s->has_truncate = bdrv_has_zero_init(bs->file) &&
+ bdrv_truncate(bs->file, bdrv_getlength(bs->file)) == 0;
+
+ qemu_co_mutex_init(&s->lock);
+ return 0;
+
+fail_format:
+ error_setg(errp, "Image not in Parallels format");
+ ret = -EINVAL;
+fail:
+ qemu_vfree(s->header);
+ return ret;
+}
+
+
static void parallels_close(BlockDriverState *bs)
{
BDRVParallelsState *s = bs->opaque;