Patchwork [RFC,11/24] qed: add open_conversion_target()

login
register
mail settings
Submitter Devin Nakamura
Date July 29, 2011, 4:49 a.m.
Message ID <1311914994-20482-12-git-send-email-devin122@gmail.com>
Download mbox | patch
Permalink /patch/107344/
State New
Headers show

Comments

Devin Nakamura - July 29, 2011, 4:49 a.m.
Signed-off-by: Devin Nakamura <devin122@gmail.com>
---
 block/qed.c |   86 +++++++++++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 69 insertions(+), 17 deletions(-)

Patch

diff --git a/block/qed.c b/block/qed.c
index daf82fd..b05224a 100644
--- a/block/qed.c
+++ b/block/qed.c
@@ -1451,6 +1451,57 @@  static int bdrv_qed_check(BlockDriverState *bs, BdrvCheckResult *result)
     return qed_check(s, result, false);
 }
 
+static int bdrv_qed_open_conversion_target(BlockDriverState *bs,
+                                           BlockConversionOptions *drv_options,
+                                           QEMUOptionParameter *usr_options)
+{
+    BDRVQEDState *s = bs->opaque;
+    s->bs = bs;
+    if (drv_options->encryption_type != BLOCK_CRYPT_NONE) {
+        return -1; //TODO: FIXME
+    }
+    if (drv_options->cluster_size != drv_options->allocation_size) {
+        return -1; //TODO: FIXME
+    }
+    s->header.magic = QED_MAGIC;
+    s->header.table_size = QED_DEFAULT_TABLE_SIZE;
+    if(qed_is_cluster_size_valid(drv_options->cluster_size)) {
+        s->header.cluster_size = drv_options->cluster_size;
+    } else {
+        return -EINVAL;
+    }
+    if(qed_is_image_size_valid(drv_options->image_size, s->header.cluster_size,
+                               s->header.table_size)) {
+        /*TODO: check if qed_is_image_size_valid
+        * checks image_size % cluster_size =0 */
+        s->header.image_size = drv_options->image_size;
+    } else {
+        return -EINVAL;
+    }
+    s->file_size = bs->file->total_sectors << BDRV_SECTOR_BITS;
+    s->l1_table = qed_alloc_table(s);
+    s->header.l1_table_offset = qed_alloc_clusters(s, s->header.table_size);
+    QSIMPLEQ_INIT(&s->allocating_write_reqs);
+
+
+    if (!qed_check_table_offset(s, s->header.l1_table_offset)) {
+        return -EINVAL;
+    }
+
+    s->table_nelems = (s->header.cluster_size * s->header.table_size) /
+                      sizeof(uint64_t);
+    s->l2_shift = ffs(s->header.cluster_size) - 1;
+    s->l2_mask = s->table_nelems - 1;
+    s->l1_shift = s->l2_shift + ffs(s->table_nelems) - 1;
+
+    qed_init_l2_cache(&s->l2_cache);
+
+    s->need_check_timer = qemu_new_timer_ns(vm_clock,
+                                            qed_need_check_timer_cb, s);
+    qed_write_l1_table_sync(s, 0, s->table_nelems);
+    return 0;
+}
+
 static int bdrv_qed_get_mapping(BlockDriverState *bs, uint64_t *guest_offset,
                                 uint64_t *host_offset,
                                 uint64_t *contiguous_bytes)
@@ -1559,23 +1610,24 @@  static BlockDriver bdrv_qed = {
     .instance_size            = sizeof(BDRVQEDState),
     .create_options           = qed_create_options,
 
-    .bdrv_probe               = bdrv_qed_probe,
-    .bdrv_open                = bdrv_qed_open,
-    .bdrv_close               = bdrv_qed_close,
-    .bdrv_create              = bdrv_qed_create,
-    .bdrv_flush               = bdrv_qed_flush,
-    .bdrv_is_allocated        = bdrv_qed_is_allocated,
-    .bdrv_make_empty          = bdrv_qed_make_empty,
-    .bdrv_aio_readv           = bdrv_qed_aio_readv,
-    .bdrv_aio_writev          = bdrv_qed_aio_writev,
-    .bdrv_aio_flush           = bdrv_qed_aio_flush,
-    .bdrv_truncate            = bdrv_qed_truncate,
-    .bdrv_getlength           = bdrv_qed_getlength,
-    .bdrv_get_info            = bdrv_qed_get_info,
-    .bdrv_change_backing_file = bdrv_qed_change_backing_file,
-    .bdrv_check               = bdrv_qed_check,
-    .bdrv_get_mapping         = bdrv_qed_get_mapping,
-    .bdrv_map                 = bdrv_qed_map,
+    .bdrv_probe                  = bdrv_qed_probe,
+    .bdrv_open                   = bdrv_qed_open,
+    .bdrv_close                  = bdrv_qed_close,
+    .bdrv_create                 = bdrv_qed_create,
+    .bdrv_flush                  = bdrv_qed_flush,
+    .bdrv_is_allocated           = bdrv_qed_is_allocated,
+    .bdrv_make_empty             = bdrv_qed_make_empty,
+    .bdrv_aio_readv              = bdrv_qed_aio_readv,
+    .bdrv_aio_writev             = bdrv_qed_aio_writev,
+    .bdrv_aio_flush              = bdrv_qed_aio_flush,
+    .bdrv_truncate               = bdrv_qed_truncate,
+    .bdrv_getlength              = bdrv_qed_getlength,
+    .bdrv_get_info               = bdrv_qed_get_info,
+    .bdrv_change_backing_file    = bdrv_qed_change_backing_file,
+    .bdrv_check                  = bdrv_qed_check,
+    .bdrv_open_conversion_target = bdrv_qed_open_conversion_target,
+    .bdrv_get_mapping            = bdrv_qed_get_mapping,
+    .bdrv_map                    = bdrv_qed_map,
 };
 
 static void bdrv_qed_init(void)