[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 17/27] block/parallels: move parallels_open/probe to
From: |
Denis V. Lunev |
Subject: |
[Qemu-devel] [PATCH 17/27] block/parallels: move parallels_open/probe to the very end of the file |
Date: |
Wed, 11 Mar 2015 13:28:11 +0300 |
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 <address@hidden>
Reviewed-by: Roman Kagan <address@hidden>
CC: Kevin Wolf <address@hidden>
CC: Stefan Hajnoczi <address@hidden>
---
block/parallels.c | 185 ++++++++++++++++++++++++++++--------------------------
1 file changed, 95 insertions(+), 90 deletions(-)
diff --git a/block/parallels.c b/block/parallels.c
index 3d515dd..3d71624 100644
--- a/block/parallels.c
+++ b/block/parallels.c
@@ -67,96 +67,6 @@ typedef struct BDRVParallelsState {
unsigned int off_multiplier;
} 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);
-
- 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)
{
@@ -391,6 +301,101 @@ 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);
+
+ 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;
--
1.9.1
- [Qemu-devel] [PATCH 15/27] block/parallels: keep BAT bitmap data in little endian in memory, (continued)
- [Qemu-devel] [PATCH 15/27] block/parallels: keep BAT bitmap data in little endian in memory, Denis V. Lunev, 2015/03/11
- [Qemu-devel] [PATCH 18/27] block/parallels: implement parallels_check method of block driver, Denis V. Lunev, 2015/03/11
- [Qemu-devel] [PATCH 21/27] block/parallels: no need to flush on each block allocation table update, Denis V. Lunev, 2015/03/11
- [Qemu-devel] [PATCH 08/27] block/parallels: _co_writev callback for Parallels format, Denis V. Lunev, 2015/03/11
- [Qemu-devel] [PATCH 12/27] parallels: change copyright information in the image header, Denis V. Lunev, 2015/03/11
- [Qemu-devel] [PATCH 04/27] block/parallels: read up to cluster end in one go, Denis V. Lunev, 2015/03/11
- [Qemu-devel] [PATCH 14/27] block/parallels: create bat2sect helper, Denis V. Lunev, 2015/03/11
- [Qemu-devel] [PATCH 07/27] block/parallels: replace magic constants 4, 64 with proper sizeofs, Denis V. Lunev, 2015/03/11
- [Qemu-devel] [PATCH 09/27] iotests, parallels: test for write into Parallels image, Denis V. Lunev, 2015/03/11
- [Qemu-devel] [PATCH 25/27] block/parallels: add prealloc-mode and prealloc-size open paramemets, Denis V. Lunev, 2015/03/11
- [Qemu-devel] [PATCH 17/27] block/parallels: move parallels_open/probe to the very end of the file,
Denis V. Lunev <=
- [Qemu-devel] [PATCH 02/27] block/parallels: rename parallels_header to ParallelsHeader, Denis V. Lunev, 2015/03/11
- [Qemu-devel] [PATCH 23/27] block/parallels: create bat_entry_off helper, Denis V. Lunev, 2015/03/11
- [Qemu-devel] [PATCH 06/27] block/parallels: provide _co_readv routine for parallels format driver, Denis V. Lunev, 2015/03/11
- [Qemu-devel] [PATCH 26/27] block/parallels: optimize linear image expansion, Denis V. Lunev, 2015/03/11
- [Qemu-devel] [PATCH 16/27] block/parallels: read parallels image header and BAT into single buffer, Denis V. Lunev, 2015/03/11
- [Qemu-devel] [PATCH 20/27] iotests, parallels: check for incorrectly closed image in tests, Denis V. Lunev, 2015/03/11