All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] iscsi: add iscsi_create support
@ 2012-11-17 15:13 Peter Lieven
  2012-11-19  8:26 ` Paolo Bonzini
  0 siblings, 1 reply; 2+ messages in thread
From: Peter Lieven @ 2012-11-17 15:13 UTC (permalink / raw)
  To: qemu-devel; +Cc: Kevin Wolf, Paolo Bonzini, aderumier, ronnie sahlberg

This patch adds support for bdrv_create. This allows e.g.
to use qemu-img to convert from any supported device to
an iscsi backed storage as destination.

Signed-off-by: Peter Lieven <pl@kamp.de>

diff --git a/block/iscsi.c b/block/iscsi.c
index 4bc3d4b..eb586cb 100644
--- a/block/iscsi.c
+++ b/block/iscsi.c
@@ -952,6 +952,54 @@ static void iscsi_close(BlockDriverState *bs)
     memset(iscsilun, 0, sizeof(IscsiLun));
 }
 
+static int iscsi_create(const char *filename, QEMUOptionParameter *options) {
+    int ret = 0;
+    int64_t total_size = 0;
+    BlockDriverState bs;
+    IscsiLun *iscsilun = NULL;
+    
+    memset(&bs, 0, sizeof(BlockDriverState));
+    
+    /* Read out options */
+    while (options && options->name) {
+        if (!strcmp(options->name, "size")) {
+            total_size = options->value.n / BDRV_SECTOR_SIZE;
+        }
+        options++;
+    }
+
+    bs.opaque = g_malloc0(sizeof(struct IscsiLun));
+    iscsilun = bs.opaque;
+
+    if ((ret = iscsi_open(&bs, filename, 0)) != 0) {
+        goto out;
+    }
+    if (iscsilun->type != TYPE_DISK) {
+        ret = -ENODEV;
+        goto out;
+    }
+    if (bs.total_sectors < total_size) {
+        ret = -ENOSPC;
+    }
+
+    ret = 0;
+out:
+    if (iscsilun->iscsi != NULL) {
+        iscsi_destroy_context(iscsilun->iscsi);
+    }
+    g_free(bs.opaque);
+    return ret;
+}
+
+static QEMUOptionParameter iscsi_create_options[] = {
+    {
+        .name = BLOCK_OPT_SIZE,
+        .type = OPT_SIZE,
+        .help = "Virtual disk size"
+    },
+    { NULL }
+};
+
 static BlockDriver bdrv_iscsi = {
     .format_name     = "iscsi",
     .protocol_name   = "iscsi",
@@ -959,6 +1007,8 @@ static BlockDriver bdrv_iscsi = {
     .instance_size   = sizeof(IscsiLun),
     .bdrv_file_open  = iscsi_open,
     .bdrv_close      = iscsi_close,
+    .bdrv_create     = iscsi_create,
+    .create_options  = iscsi_create_options,
 
     .bdrv_getlength  = iscsi_getlength,
 
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [Qemu-devel] [PATCH] iscsi: add iscsi_create support
  2012-11-17 15:13 [Qemu-devel] [PATCH] iscsi: add iscsi_create support Peter Lieven
@ 2012-11-19  8:26 ` Paolo Bonzini
  0 siblings, 0 replies; 2+ messages in thread
From: Paolo Bonzini @ 2012-11-19  8:26 UTC (permalink / raw)
  To: Peter Lieven; +Cc: Kevin Wolf, aderumier, qemu-devel, ronnie sahlberg

Il 17/11/2012 16:13, Peter Lieven ha scritto:
> This patch adds support for bdrv_create. This allows e.g.
> to use qemu-img to convert from any supported device to
> an iscsi backed storage as destination.
> 
> Signed-off-by: Peter Lieven <pl@kamp.de>
> 
> diff --git a/block/iscsi.c b/block/iscsi.c
> index 4bc3d4b..eb586cb 100644
> --- a/block/iscsi.c
> +++ b/block/iscsi.c
> @@ -952,6 +952,54 @@ static void iscsi_close(BlockDriverState *bs)
>      memset(iscsilun, 0, sizeof(IscsiLun));
>  }
>  
> +static int iscsi_create(const char *filename, QEMUOptionParameter *options) {

Incorrect brace positioning, fixed it myself.
+    int ret = 0;
> +    int64_t total_size = 0;
> +    BlockDriverState bs;
> +    IscsiLun *iscsilun = NULL;
> +    
> +    memset(&bs, 0, sizeof(BlockDriverState));
> +    
> +    /* Read out options */
> +    while (options && options->name) {
> +        if (!strcmp(options->name, "size")) {
> +            total_size = options->value.n / BDRV_SECTOR_SIZE;
> +        }
> +        options++;
> +    }
> +
> +    bs.opaque = g_malloc0(sizeof(struct IscsiLun));
> +    iscsilun = bs.opaque;
> +
> +    if ((ret = iscsi_open(&bs, filename, 0)) != 0) {
> +        goto out;
> +    }
> +    if (iscsilun->type != TYPE_DISK) {
> +        ret = -ENODEV;
> +        goto out;
> +    }
> +    if (bs.total_sectors < total_size) {
> +        ret = -ENOSPC;
> +    }
> +
> +    ret = 0;
> +out:
> +    if (iscsilun->iscsi != NULL) {
> +        iscsi_destroy_context(iscsilun->iscsi);
> +    }
> +    g_free(bs.opaque);
> +    return ret;
> +}
> +
> +static QEMUOptionParameter iscsi_create_options[] = {
> +    {
> +        .name = BLOCK_OPT_SIZE,
> +        .type = OPT_SIZE,
> +        .help = "Virtual disk size"
> +    },
> +    { NULL }
> +};
> +
>  static BlockDriver bdrv_iscsi = {
>      .format_name     = "iscsi",
>      .protocol_name   = "iscsi",
> @@ -959,6 +1007,8 @@ static BlockDriver bdrv_iscsi = {
>      .instance_size   = sizeof(IscsiLun),
>      .bdrv_file_open  = iscsi_open,
>      .bdrv_close      = iscsi_close,
> +    .bdrv_create     = iscsi_create,
> +    .create_options  = iscsi_create_options,
>  
>      .bdrv_getlength  = iscsi_getlength,
>  
> 

Applied to scsi-next branch.

Paolo

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-11-19  8:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-11-17 15:13 [Qemu-devel] [PATCH] iscsi: add iscsi_create support Peter Lieven
2012-11-19  8:26 ` Paolo Bonzini

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.