qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v2 0/7] introduce BSD-licensed block driver for "raw"
@ 2013-08-21 10:41 Laszlo Ersek
  2013-08-21 10:41 ` [Qemu-devel] [PATCH v2 1/7] add skeleton for BSD licensed "raw" BlockDriver Laszlo Ersek
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: Laszlo Ersek @ 2013-08-21 10:41 UTC (permalink / raw)
  To: kwolf, stefanha, pbonzini, hch, anthony, qemu-devel

v1->v2:
- added comment to raw_probe() [Kevin]
- fixed raw_reopen_prepare() [Paolo & Kevin]
- keeping BSDL: according to the v1 discussion, LGPLv2+ could work too,
  but "but most of the block layer is BSD" [Paolo] and I haven't been
  clearly instructed to switch to LGPLv2+.

  diff --git a/block/raw_bsd.c b/block/raw_bsd.c
  index 07e6f06..ab2b0fd 100644
  --- a/block/raw_bsd.c
  +++ b/block/raw_bsd.c
  @@ -41,10 +41,7 @@ static QEMUOptionParameter raw_create_options[] = {
   static int raw_reopen_prepare(BDRVReopenState *reopen_state,
                                 BlockReopenQueue *queue, Error **errp)
   {
  -    BDRVReopenState tmp = *reopen_state;
  -
  -    tmp.bs = tmp.bs->file;
  -    return bdrv_reopen_prepare(&tmp, queue, errp);
  +    return 0;
   }

   static int coroutine_fn raw_co_readv(BlockDriverState *bs, int64_t sector_num,
  @@ -150,6 +147,9 @@ static void raw_close(BlockDriverState *bs)

   static int raw_probe(const uint8_t *buf, int buf_size, const char *filename)
   {
  +    /* smallest possible positive score so that raw is used if and only if no
  +     * other block driver works
  +     */
       return 1;
   }

v1 blurb:

Paolo asked me to write such a driver based on his textual specification
alone. The first patch captures his email in full, the rest re-quotes
parts that are being implemented.

The tree compiles at each patch. The series passes "make check-block".

"block/raw.c" is not removed because I wanted to keep it out of my
series and out of my brain.

Laszlo Ersek (7):
  add skeleton for BSD licensed "raw" BlockDriver
  raw_bsd: emit debug events in bdrv_co_readv() and bdrv_co_writev()
  raw_bsd: add raw_create()
  raw_bsd: introduce "special members"
  raw_bsd: add raw_create_options
  raw_bsd: register bdrv_raw
  switch raw block driver from "raw.o" to "raw_bsd.o"

 block/Makefile.objs |    2 +-
 block/raw_bsd.c     |  186 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 187 insertions(+), 1 deletions(-)
 create mode 100644 block/raw_bsd.c

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

* [Qemu-devel] [PATCH v2 1/7] add skeleton for BSD licensed "raw" BlockDriver
  2013-08-21 10:41 [Qemu-devel] [PATCH v2 0/7] introduce BSD-licensed block driver for "raw" Laszlo Ersek
@ 2013-08-21 10:41 ` Laszlo Ersek
  2013-08-21 10:41 ` [Qemu-devel] [PATCH v2 2/7] raw_bsd: emit debug events in bdrv_co_readv() and bdrv_co_writev() Laszlo Ersek
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Laszlo Ersek @ 2013-08-21 10:41 UTC (permalink / raw)
  To: kwolf, stefanha, pbonzini, hch, anthony, qemu-devel

On 08/05/13 15:03, Paolo Bonzini wrote:
>
>
> ----- Original Message -----
>> From: "Laszlo Ersek" <lersek@redhat.com>
>> To: "Paolo Bonzini" <pbonzini@redhat.com>
>> Sent: Monday, August 5, 2013 2:43:46 PM
>> Subject: Re: [PATCH 1/2] raw: add license header
>>
>> On 08/02/13 00:27, Paolo Bonzini wrote:
>>> On 08/01/2013 10:13 AM, Christoph Hellwig wrote:
>>>> On Wed, Jul 31, 2013 at 08:19:51AM +0200, Paolo Bonzini wrote:
>>>>> Most of the block layer is under the BSD license, thus it is
>>>>> reasonable to license block/raw.c the same way.  CCed people should
>>>>> ACK by replying with a Signed-off-by line.
>>>>
>>>> The coded was intended to be GPLv2.
>>>
>>> Laszlo, would you be willing to do clean-room reverse engineering?
>>>
>>> (No rants, please. :))
>>
>> What's the scope exactly?
>
> It's quite small, it's a file full of forwarders like
>
> static void raw_foo(BlockDriverState *bs)
> {
>     return bdrv_foo(bs->file);
> }
>
> It's 170 lines of code, all as boring as this.  I only picked you
> because I'm quite certain you have never seen the file (and the answer
> confirmed it).
>
> Basically:
>
> 1) BlockDriver is a struct in which these function members are
> interesting:
>
>     .bdrv_reopen_prepare
>     .bdrv_co_readv
>     .bdrv_co_writev
>     .bdrv_co_is_allocated
>     .bdrv_co_write_zeroes
>     .bdrv_co_discard
>     .bdrv_getlength
>     .bdrv_get_info
>     .bdrv_truncate
>     .bdrv_is_inserted
>     .bdrv_media_changed
>     .bdrv_eject
>     .bdrv_lock_medium
>     .bdrv_ioctl
>     .bdrv_aio_ioctl
>     .bdrv_has_zero_init
>
> They should be implemented as simple forwarders (see above).
> There are 16 functions listed here, you can easily see how this
> already accounts for 100+ SLOC roughly...
>
> The implementations of bdrv_co_readv and bdrv_co_writev should also
> call BLKDBG_EVENT on bs->file too, before forwarding to bs->file.  The
> events to be generated are BLKDBG_READ_AIO and BLKDBG_WRITE_AIO.
>
> 2) This is also a simple forwarder function:
>
>     .bdrv_create
>
> but there is no BlockDriverState argument so the forwarded-to function
> does not have a bs->file argument either.  The forwarded-to function
> is bdrv_create_file.
>
> 3) These members are special
>
>     .format_name   is the string "raw"
>     .bdrv_open     raw_open should set bs->sg to bs->file->sg and return 0
>     .bdrv_close    raw_close should do nothing
>     .bdrv_probe    raw_probe should just return 1.
>
> 4) There is another member, .create_options, which is an array of
> QEMUOptionParameter structs, terminated by an all-zero item.  The only
> option you need is for the virtual disk size.  You will find something
> to copy from in other block drivers, for example block/qcow2.c.
>
> 5) Formats are registered with bdrv_register (takes a BlockDriver*).
> You also need to pass the caller of bdrv_register to block_init.
>
> 6) I'm not sure how to organize the patch series, so I'll leave this to
> your creativity.  I guess in this case move/copy detection of git should
> be disabled.  I would definitely include this spec in the commit
> message as a proof of clean-room reverse engineering.
>
> 7) Remember a BSD header like the one in block.c.
>
> Paolo

This patch implements the email up to the paragraph ending with "100+ SLOC
roughly". The skeleton is generated from the list there, with a simple
shell loop using "sed" and the raw_foo() template.

The BSD license block is copied (and reflowed) from
"util/qemu-progress.c".

Signed-off-by: Laszlo Ersek <lersek@redhat.com>
---
 block/raw_bsd.c |  108 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 108 insertions(+), 0 deletions(-)
 create mode 100644 block/raw_bsd.c

diff --git a/block/raw_bsd.c b/block/raw_bsd.c
new file mode 100644
index 0000000..5c17d53
--- /dev/null
+++ b/block/raw_bsd.c
@@ -0,0 +1,108 @@
+/* BlockDriver implementation for "raw"
+ *
+ * Copyright (C) 2013, Red Hat, Inc.
+ *
+ * Author:
+ *   Laszlo Ersek <lersek@redhat.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#include "block/block_int.h"
+
+static TYPE raw_reopen_prepare(BlockDriverState *bs)
+{
+    return bdrv_reopen_prepare(bs->file);
+}
+
+static TYPE raw_co_readv(BlockDriverState *bs)
+{
+    return bdrv_co_readv(bs->file);
+}
+
+static TYPE raw_co_writev(BlockDriverState *bs)
+{
+    return bdrv_co_writev(bs->file);
+}
+
+static TYPE raw_co_is_allocated(BlockDriverState *bs)
+{
+    return bdrv_co_is_allocated(bs->file);
+}
+
+static TYPE raw_co_write_zeroes(BlockDriverState *bs)
+{
+    return bdrv_co_write_zeroes(bs->file);
+}
+
+static TYPE raw_co_discard(BlockDriverState *bs)
+{
+    return bdrv_co_discard(bs->file);
+}
+
+static TYPE raw_getlength(BlockDriverState *bs)
+{
+    return bdrv_getlength(bs->file);
+}
+
+static TYPE raw_get_info(BlockDriverState *bs)
+{
+    return bdrv_get_info(bs->file);
+}
+
+static TYPE raw_truncate(BlockDriverState *bs)
+{
+    return bdrv_truncate(bs->file);
+}
+
+static TYPE raw_is_inserted(BlockDriverState *bs)
+{
+    return bdrv_is_inserted(bs->file);
+}
+
+static TYPE raw_media_changed(BlockDriverState *bs)
+{
+    return bdrv_media_changed(bs->file);
+}
+
+static TYPE raw_eject(BlockDriverState *bs)
+{
+    return bdrv_eject(bs->file);
+}
+
+static TYPE raw_lock_medium(BlockDriverState *bs)
+{
+    return bdrv_lock_medium(bs->file);
+}
+
+static TYPE raw_ioctl(BlockDriverState *bs)
+{
+    return bdrv_ioctl(bs->file);
+}
+
+static TYPE raw_aio_ioctl(BlockDriverState *bs)
+{
+    return bdrv_aio_ioctl(bs->file);
+}
+
+static TYPE raw_has_zero_init(BlockDriverState *bs)
+{
+    return bdrv_has_zero_init(bs->file);
+}
+
-- 
1.7.1

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

* [Qemu-devel] [PATCH v2 2/7] raw_bsd: emit debug events in bdrv_co_readv() and bdrv_co_writev()
  2013-08-21 10:41 [Qemu-devel] [PATCH v2 0/7] introduce BSD-licensed block driver for "raw" Laszlo Ersek
  2013-08-21 10:41 ` [Qemu-devel] [PATCH v2 1/7] add skeleton for BSD licensed "raw" BlockDriver Laszlo Ersek
@ 2013-08-21 10:41 ` Laszlo Ersek
  2013-08-21 10:41 ` [Qemu-devel] [PATCH v2 3/7] raw_bsd: add raw_create() Laszlo Ersek
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Laszlo Ersek @ 2013-08-21 10:41 UTC (permalink / raw)
  To: kwolf, stefanha, pbonzini, hch, anthony, qemu-devel

On 08/05/13 15:03, Paolo Bonzini wrote:
>
> [...]
>
> 1) BlockDriver is a struct in which these function members are
> interesting:
>
>     .bdrv_reopen_prepare
>     .bdrv_co_readv
>     .bdrv_co_writev
>     .bdrv_co_is_allocated
>     .bdrv_co_write_zeroes
>     .bdrv_co_discard
>     .bdrv_getlength
>     .bdrv_get_info
>     .bdrv_truncate
>     .bdrv_is_inserted
>     .bdrv_media_changed
>     .bdrv_eject
>     .bdrv_lock_medium
>     .bdrv_ioctl
>     .bdrv_aio_ioctl
>     .bdrv_has_zero_init
>
> They should be implemented as simple forwarders (see above). There are
> 16 functions listed here, you can easily see how this already accounts
> for 100+ SLOC roughly...
>
> The implementations of bdrv_co_readv and bdrv_co_writev should also call
> BLKDBG_EVENT on bs->file too, before forwarding to bs->file.  The events
> to be generated are BLKDBG_READ_AIO and BLKDBG_WRITE_AIO.

Signed-off-by: Laszlo Ersek <lersek@redhat.com>
---
 block/raw_bsd.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/block/raw_bsd.c b/block/raw_bsd.c
index 5c17d53..19091a3 100644
--- a/block/raw_bsd.c
+++ b/block/raw_bsd.c
@@ -33,11 +33,13 @@ static TYPE raw_reopen_prepare(BlockDriverState *bs)
 
 static TYPE raw_co_readv(BlockDriverState *bs)
 {
+    BLKDBG_EVENT(bs->file, BLKDBG_READ_AIO);
     return bdrv_co_readv(bs->file);
 }
 
 static TYPE raw_co_writev(BlockDriverState *bs)
 {
+    BLKDBG_EVENT(bs->file, BLKDBG_WRITE_AIO);
     return bdrv_co_writev(bs->file);
 }
 
-- 
1.7.1

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

* [Qemu-devel] [PATCH v2 3/7] raw_bsd: add raw_create()
  2013-08-21 10:41 [Qemu-devel] [PATCH v2 0/7] introduce BSD-licensed block driver for "raw" Laszlo Ersek
  2013-08-21 10:41 ` [Qemu-devel] [PATCH v2 1/7] add skeleton for BSD licensed "raw" BlockDriver Laszlo Ersek
  2013-08-21 10:41 ` [Qemu-devel] [PATCH v2 2/7] raw_bsd: emit debug events in bdrv_co_readv() and bdrv_co_writev() Laszlo Ersek
@ 2013-08-21 10:41 ` Laszlo Ersek
  2013-08-21 10:41 ` [Qemu-devel] [PATCH v2 4/7] raw_bsd: introduce "special members" Laszlo Ersek
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Laszlo Ersek @ 2013-08-21 10:41 UTC (permalink / raw)
  To: kwolf, stefanha, pbonzini, hch, anthony, qemu-devel

On 08/05/13 15:03, Paolo Bonzini wrote:
>
> [...]
>
> 2) This is also a simple forwarder function:
>
>     .bdrv_create
>
> but there is no BlockDriverState argument so the forwarded-to function
> does not have a bs->file argument either.  The forwarded-to function is
> bdrv_create_file.

Signed-off-by: Laszlo Ersek <lersek@redhat.com>
---
 block/raw_bsd.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/block/raw_bsd.c b/block/raw_bsd.c
index 19091a3..5bcbe71 100644
--- a/block/raw_bsd.c
+++ b/block/raw_bsd.c
@@ -108,3 +108,7 @@ static TYPE raw_has_zero_init(BlockDriverState *bs)
     return bdrv_has_zero_init(bs->file);
 }
 
+static TYPE raw_create(void)
+{
+    return bdrv_create_file();
+}
-- 
1.7.1

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

* [Qemu-devel] [PATCH v2 4/7] raw_bsd: introduce "special members"
  2013-08-21 10:41 [Qemu-devel] [PATCH v2 0/7] introduce BSD-licensed block driver for "raw" Laszlo Ersek
                   ` (2 preceding siblings ...)
  2013-08-21 10:41 ` [Qemu-devel] [PATCH v2 3/7] raw_bsd: add raw_create() Laszlo Ersek
@ 2013-08-21 10:41 ` Laszlo Ersek
  2013-08-21 10:41 ` [Qemu-devel] [PATCH v2 5/7] raw_bsd: add raw_create_options Laszlo Ersek
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Laszlo Ersek @ 2013-08-21 10:41 UTC (permalink / raw)
  To: kwolf, stefanha, pbonzini, hch, anthony, qemu-devel

On 08/05/13 15:03, Paolo Bonzini wrote:
>
> [...]
>
> 3) These members are special
>
>     .format_name   is the string "raw"
>     .bdrv_open     raw_open should set bs->sg to bs->file->sg and return 0
>     .bdrv_close    raw_close should do nothing
>     .bdrv_probe    raw_probe should just return 1.

v1->v2:

On 08/20/13 10:11, Kevin Wolf wrote:
> Am 16.08.2013 um 16:15 hat Laszlo Ersek geschrieben:

>> +static int raw_probe(void)
>> +{
>> +    return 1;
>> +}
>
> Maybe add a comment here like "smallest possible positive score so that
> raw is used if and only if no other block driver works".

Signed-off-by: Laszlo Ersek <lersek@redhat.com>
---
 block/raw_bsd.c |   23 +++++++++++++++++++++++
 1 files changed, 23 insertions(+), 0 deletions(-)

diff --git a/block/raw_bsd.c b/block/raw_bsd.c
index 5bcbe71..b1d7209 100644
--- a/block/raw_bsd.c
+++ b/block/raw_bsd.c
@@ -112,3 +112,26 @@ static TYPE raw_create(void)
 {
     return bdrv_create_file();
 }
+
+static const char *raw_format_name(void)
+{
+    return "raw";
+}
+
+static int raw_open(BlockDriverState *bs)
+{
+    bs->sg = bs->file->sg;
+    return 0;
+}
+
+static void raw_close(void)
+{
+}
+
+static int raw_probe(void)
+{
+    /* smallest possible positive score so that raw is used if and only if no
+     * other block driver works
+     */
+    return 1;
+}
-- 
1.7.1

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

* [Qemu-devel] [PATCH v2 5/7] raw_bsd: add raw_create_options
  2013-08-21 10:41 [Qemu-devel] [PATCH v2 0/7] introduce BSD-licensed block driver for "raw" Laszlo Ersek
                   ` (3 preceding siblings ...)
  2013-08-21 10:41 ` [Qemu-devel] [PATCH v2 4/7] raw_bsd: introduce "special members" Laszlo Ersek
@ 2013-08-21 10:41 ` Laszlo Ersek
  2013-08-21 10:41 ` [Qemu-devel] [PATCH v2 6/7] raw_bsd: register bdrv_raw Laszlo Ersek
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Laszlo Ersek @ 2013-08-21 10:41 UTC (permalink / raw)
  To: kwolf, stefanha, pbonzini, hch, anthony, qemu-devel

On 08/05/13 15:03, Paolo Bonzini wrote:
>
> [...]
>
> 4) There is another member, .create_options, which is an array of
> QEMUOptionParameter structs, terminated by an all-zero item.  The only
> option you need is for the virtual disk size.  You will find something
> to copy from in other block drivers, for example block/qcow2.c.

Code taken and adapted from "block/qcow2.c", as suggested. The code being
copied/modified is blamed on

    commit 20d97356c9df6d68fbd37d6334fdb7063f24eab6
    Author: Blue Swirl <blauwirbel@gmail.com>
    Date:   Fri Apr 23 20:19:47 2010 +0000

        Fix OpenBSD build

and

    commit 7c80ab3f21f0b1342f23057d4345ae266c7348d9
    Author: Jes Sorensen <Jes.Sorensen@redhat.com>
    Date:   Fri Dec 17 16:02:39 2010 +0100

        block/qcow2.c: rename qcow_ functions to qcow2_

Signed-off-by: Laszlo Ersek <lersek@redhat.com>
---
 block/raw_bsd.c |   13 ++++++++++++-
 1 files changed, 12 insertions(+), 1 deletions(-)

diff --git a/block/raw_bsd.c b/block/raw_bsd.c
index b1d7209..b70245d 100644
--- a/block/raw_bsd.c
+++ b/block/raw_bsd.c
@@ -1,6 +1,7 @@
 /* BlockDriver implementation for "raw"
  *
- * Copyright (C) 2013, Red Hat, Inc.
+ * Copyright (C) 2010, 2013, Red Hat, Inc.
+ * Copyright (C) 2010, Blue Swirl <blauwirbel@gmail.com>
  *
  * Author:
  *   Laszlo Ersek <lersek@redhat.com>
@@ -25,6 +26,16 @@
  */
 
 #include "block/block_int.h"
+#include "qemu/option.h"
+
+static const QEMUOptionParameter raw_create_options[] = {
+    {
+        .name = BLOCK_OPT_SIZE,
+        .type = OPT_SIZE,
+        .help = "Virtual disk size"
+    },
+    { 0 }
+};
 
 static TYPE raw_reopen_prepare(BlockDriverState *bs)
 {
-- 
1.7.1

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

* [Qemu-devel] [PATCH v2 6/7] raw_bsd: register bdrv_raw
  2013-08-21 10:41 [Qemu-devel] [PATCH v2 0/7] introduce BSD-licensed block driver for "raw" Laszlo Ersek
                   ` (4 preceding siblings ...)
  2013-08-21 10:41 ` [Qemu-devel] [PATCH v2 5/7] raw_bsd: add raw_create_options Laszlo Ersek
@ 2013-08-21 10:41 ` Laszlo Ersek
  2013-08-21 10:41 ` [Qemu-devel] [PATCH v2 7/7] switch raw block driver from "raw.o" to "raw_bsd.o" Laszlo Ersek
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Laszlo Ersek @ 2013-08-21 10:41 UTC (permalink / raw)
  To: kwolf, stefanha, pbonzini, hch, anthony, qemu-devel

On 08/05/13 15:03, Paolo Bonzini wrote:
>
> [...]
>
> 5) Formats are registered with bdrv_register (takes a BlockDriver*). You
> also need to pass the caller of bdrv_register to block_init.

Fill in the BlockDriver structure with the raw_*() functions that have
been added to "block/raw_bsd.c", in the order the fields are defined in
"include/block/block_int.h".

I needed more explanation / naming examples for registering the driver
than what Paolo gave me, so I copied / adapted from "block/qcow2.c". The
parts I took as basis for modification are blamed on

    commit 5efa9d5a8b18841c9c62208a494d7f519238979a
    Author: Anthony Liguori <aliguori@us.ibm.com>
    Date:   Sat May 9 17:03:42 2009 -0500

        Convert block infrastructure to use new module init functionality

    commit 20d97356c9df6d68fbd37d6334fdb7063f24eab6
    Author: Blue Swirl <blauwirbel@gmail.com>
    Date:   Fri Apr 23 20:19:47 2010 +0000

        Fix OpenBSD build

Signed-off-by: Laszlo Ersek <lersek@redhat.com>
---
 block/raw_bsd.c |   38 +++++++++++++++++++++++++++++++++-----
 1 files changed, 33 insertions(+), 5 deletions(-)

diff --git a/block/raw_bsd.c b/block/raw_bsd.c
index b70245d..2dc1921 100644
--- a/block/raw_bsd.c
+++ b/block/raw_bsd.c
@@ -2,6 +2,7 @@
  *
  * Copyright (C) 2010, 2013, Red Hat, Inc.
  * Copyright (C) 2010, Blue Swirl <blauwirbel@gmail.com>
+ * Copyright (C) 2009, Anthony Liguori <aliguori@us.ibm.com>
  *
  * Author:
  *   Laszlo Ersek <lersek@redhat.com>
@@ -124,11 +125,6 @@ static TYPE raw_create(void)
     return bdrv_create_file();
 }
 
-static const char *raw_format_name(void)
-{
-    return "raw";
-}
-
 static int raw_open(BlockDriverState *bs)
 {
     bs->sg = bs->file->sg;
@@ -146,3 +142,35 @@ static int raw_probe(void)
      */
     return 1;
 }
+
+static BlockDriver bdrv_raw = {
+    .format_name          = "raw",
+    .bdrv_probe           = &raw_probe,
+    .bdrv_reopen_prepare  = &raw_reopen_prepare,
+    .bdrv_open            = &raw_open,
+    .bdrv_close           = &raw_close,
+    .bdrv_create          = &raw_create,
+    .bdrv_co_readv        = &raw_co_readv,
+    .bdrv_co_writev       = &raw_co_writev,
+    .bdrv_co_write_zeroes = &raw_co_write_zeroes,
+    .bdrv_co_discard      = &raw_co_discard,
+    .bdrv_co_is_allocated = &raw_co_is_allocated,
+    .bdrv_truncate        = &raw_truncate,
+    .bdrv_getlength       = &raw_getlength,
+    .bdrv_get_info        = &raw_get_info,
+    .bdrv_is_inserted     = &raw_is_inserted,
+    .bdrv_media_changed   = &raw_media_changed,
+    .bdrv_eject           = &raw_eject,
+    .bdrv_lock_medium     = &raw_lock_medium,
+    .bdrv_ioctl           = &raw_ioctl,
+    .bdrv_aio_ioctl       = &raw_aio_ioctl,
+    .create_options       = &raw_create_options[0],
+    .bdrv_has_zero_init   = &raw_has_zero_init
+};
+
+static void bdrv_raw_init(void)
+{
+    bdrv_register(&bdrv_raw);
+}
+
+block_init(bdrv_raw_init);
-- 
1.7.1

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

* [Qemu-devel] [PATCH v2 7/7] switch raw block driver from "raw.o" to "raw_bsd.o"
  2013-08-21 10:41 [Qemu-devel] [PATCH v2 0/7] introduce BSD-licensed block driver for "raw" Laszlo Ersek
                   ` (5 preceding siblings ...)
  2013-08-21 10:41 ` [Qemu-devel] [PATCH v2 6/7] raw_bsd: register bdrv_raw Laszlo Ersek
@ 2013-08-21 10:41 ` Laszlo Ersek
  2013-08-28 10:50 ` [Qemu-devel] [PATCH v2 0/7] introduce BSD-licensed block driver for "raw" Laszlo Ersek
  2013-08-28 13:17 ` Kevin Wolf
  8 siblings, 0 replies; 10+ messages in thread
From: Laszlo Ersek @ 2013-08-21 10:41 UTC (permalink / raw)
  To: kwolf, stefanha, pbonzini, hch, anthony, qemu-devel

"Incoming" function prototypes and "outgoing" function calls must match
reality. Implemented using the "struct BlockDriver" definition in
"include/block/block_int.h", and gcc errors & warnings.

v1->v2:

On 08/20/13 09:51, Kevin Wolf wrote:
> Am 18.08.2013 um 16:29 hat Paolo Bonzini geschrieben:
>> Il 16/08/2013 16:15, Laszlo Ersek ha scritto:
>>> +static int raw_reopen_prepare(BDRVReopenState *reopen_state,
>>> +                              BlockReopenQueue *queue, Error **errp)
>>>  {
>>> -    return bdrv_reopen_prepare(bs->file);
>>> +    BDRVReopenState tmp = *reopen_state;
>>> +
>>> +    tmp.bs = tmp.bs->file;
>>> +    return bdrv_reopen_prepare(&tmp, queue, errp);
>>>  }
>>
>> This should just return zero, my fault.
>
> Which is because bdrv_reopen_queue() already queues bs->file for reopen.
> The simple return 0; implementation is shared by all other format drivers
> that support reopening images.

Signed-off-by: Laszlo Ersek <lersek@redhat.com>
---
 block/Makefile.objs |    2 +-
 block/raw_bsd.c     |   78 ++++++++++++++++++++++++++++----------------------
 2 files changed, 45 insertions(+), 35 deletions(-)

diff --git a/block/Makefile.objs b/block/Makefile.objs
index 4cf9aa4..3bb85b5 100644
--- a/block/Makefile.objs
+++ b/block/Makefile.objs
@@ -1,4 +1,4 @@
-block-obj-y += raw.o cow.o qcow.o vdi.o vmdk.o cloop.o dmg.o bochs.o vpc.o vvfat.o
+block-obj-y += raw_bsd.o cow.o qcow.o vdi.o vmdk.o cloop.o dmg.o bochs.o vpc.o vvfat.o
 block-obj-y += qcow2.o qcow2-refcount.o qcow2-cluster.o qcow2-snapshot.o qcow2-cache.o
 block-obj-y += qed.o qed-gencb.o qed-l2-cache.o qed-table.o qed-cluster.o
 block-obj-y += qed-check.o
diff --git a/block/raw_bsd.c b/block/raw_bsd.c
index 2dc1921..ab2b0fd 100644
--- a/block/raw_bsd.c
+++ b/block/raw_bsd.c
@@ -29,7 +29,7 @@
 #include "block/block_int.h"
 #include "qemu/option.h"
 
-static const QEMUOptionParameter raw_create_options[] = {
+static QEMUOptionParameter raw_create_options[] = {
     {
         .name = BLOCK_OPT_SIZE,
         .type = OPT_SIZE,
@@ -38,104 +38,114 @@ static const QEMUOptionParameter raw_create_options[] = {
     { 0 }
 };
 
-static TYPE raw_reopen_prepare(BlockDriverState *bs)
+static int raw_reopen_prepare(BDRVReopenState *reopen_state,
+                              BlockReopenQueue *queue, Error **errp)
 {
-    return bdrv_reopen_prepare(bs->file);
+    return 0;
 }
 
-static TYPE raw_co_readv(BlockDriverState *bs)
+static int coroutine_fn raw_co_readv(BlockDriverState *bs, int64_t sector_num,
+                                     int nb_sectors, QEMUIOVector *qiov)
 {
     BLKDBG_EVENT(bs->file, BLKDBG_READ_AIO);
-    return bdrv_co_readv(bs->file);
+    return bdrv_co_readv(bs->file, sector_num, nb_sectors, qiov);
 }
 
-static TYPE raw_co_writev(BlockDriverState *bs)
+static int coroutine_fn raw_co_writev(BlockDriverState *bs, int64_t sector_num,
+                                      int nb_sectors, QEMUIOVector *qiov)
 {
     BLKDBG_EVENT(bs->file, BLKDBG_WRITE_AIO);
-    return bdrv_co_writev(bs->file);
+    return bdrv_co_writev(bs->file, sector_num, nb_sectors, qiov);
 }
 
-static TYPE raw_co_is_allocated(BlockDriverState *bs)
+static int coroutine_fn raw_co_is_allocated(BlockDriverState *bs,
+                                            int64_t sector_num, int nb_sectors,
+                                            int *pnum)
 {
-    return bdrv_co_is_allocated(bs->file);
+    return bdrv_co_is_allocated(bs->file, sector_num, nb_sectors, pnum);
 }
 
-static TYPE raw_co_write_zeroes(BlockDriverState *bs)
+static int coroutine_fn raw_co_write_zeroes(BlockDriverState *bs,
+                                            int64_t sector_num, int nb_sectors)
 {
-    return bdrv_co_write_zeroes(bs->file);
+    return bdrv_co_write_zeroes(bs->file, sector_num, nb_sectors);
 }
 
-static TYPE raw_co_discard(BlockDriverState *bs)
+static int coroutine_fn raw_co_discard(BlockDriverState *bs,
+                                       int64_t sector_num, int nb_sectors)
 {
-    return bdrv_co_discard(bs->file);
+    return bdrv_co_discard(bs->file, sector_num, nb_sectors);
 }
 
-static TYPE raw_getlength(BlockDriverState *bs)
+static int64_t raw_getlength(BlockDriverState *bs)
 {
     return bdrv_getlength(bs->file);
 }
 
-static TYPE raw_get_info(BlockDriverState *bs)
+static int raw_get_info(BlockDriverState *bs, BlockDriverInfo *bdi)
 {
-    return bdrv_get_info(bs->file);
+    return bdrv_get_info(bs->file, bdi);
 }
 
-static TYPE raw_truncate(BlockDriverState *bs)
+static int raw_truncate(BlockDriverState *bs, int64_t offset)
 {
-    return bdrv_truncate(bs->file);
+    return bdrv_truncate(bs->file, offset);
 }
 
-static TYPE raw_is_inserted(BlockDriverState *bs)
+static int raw_is_inserted(BlockDriverState *bs)
 {
     return bdrv_is_inserted(bs->file);
 }
 
-static TYPE raw_media_changed(BlockDriverState *bs)
+static int raw_media_changed(BlockDriverState *bs)
 {
     return bdrv_media_changed(bs->file);
 }
 
-static TYPE raw_eject(BlockDriverState *bs)
+static void raw_eject(BlockDriverState *bs, bool eject_flag)
 {
-    return bdrv_eject(bs->file);
+    bdrv_eject(bs->file, eject_flag);
 }
 
-static TYPE raw_lock_medium(BlockDriverState *bs)
+static void raw_lock_medium(BlockDriverState *bs, bool locked)
 {
-    return bdrv_lock_medium(bs->file);
+    bdrv_lock_medium(bs->file, locked);
 }
 
-static TYPE raw_ioctl(BlockDriverState *bs)
+static int raw_ioctl(BlockDriverState *bs, unsigned long int req, void *buf)
 {
-    return bdrv_ioctl(bs->file);
+    return bdrv_ioctl(bs->file, req, buf);
 }
 
-static TYPE raw_aio_ioctl(BlockDriverState *bs)
+static BlockDriverAIOCB *raw_aio_ioctl(BlockDriverState *bs,
+                                       unsigned long int req, void *buf,
+                                       BlockDriverCompletionFunc *cb,
+                                       void *opaque)
 {
-    return bdrv_aio_ioctl(bs->file);
+    return bdrv_aio_ioctl(bs->file, req, buf, cb, opaque);
 }
 
-static TYPE raw_has_zero_init(BlockDriverState *bs)
+static int raw_has_zero_init(BlockDriverState *bs)
 {
     return bdrv_has_zero_init(bs->file);
 }
 
-static TYPE raw_create(void)
+static int raw_create(const char *filename, QEMUOptionParameter *options)
 {
-    return bdrv_create_file();
+    return bdrv_create_file(filename, options);
 }
 
-static int raw_open(BlockDriverState *bs)
+static int raw_open(BlockDriverState *bs, QDict *options, int flags)
 {
     bs->sg = bs->file->sg;
     return 0;
 }
 
-static void raw_close(void)
+static void raw_close(BlockDriverState *bs)
 {
 }
 
-static int raw_probe(void)
+static int raw_probe(const uint8_t *buf, int buf_size, const char *filename)
 {
     /* smallest possible positive score so that raw is used if and only if no
      * other block driver works
-- 
1.7.1

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

* Re: [Qemu-devel] [PATCH v2 0/7] introduce BSD-licensed block driver for "raw"
  2013-08-21 10:41 [Qemu-devel] [PATCH v2 0/7] introduce BSD-licensed block driver for "raw" Laszlo Ersek
                   ` (6 preceding siblings ...)
  2013-08-21 10:41 ` [Qemu-devel] [PATCH v2 7/7] switch raw block driver from "raw.o" to "raw_bsd.o" Laszlo Ersek
@ 2013-08-28 10:50 ` Laszlo Ersek
  2013-08-28 13:17 ` Kevin Wolf
  8 siblings, 0 replies; 10+ messages in thread
From: Laszlo Ersek @ 2013-08-28 10:50 UTC (permalink / raw)
  To: kwolf, stefanha; +Cc: qemu-devel

On 08/21/13 12:41, Laszlo Ersek wrote:
> v1->v2:
> - added comment to raw_probe() [Kevin]
> - fixed raw_reopen_prepare() [Paolo & Kevin]
> - keeping BSDL: according to the v1 discussion, LGPLv2+ could work too,
>   but "but most of the block layer is BSD" [Paolo] and I haven't been
>   clearly instructed to switch to LGPLv2+.
> 
>   diff --git a/block/raw_bsd.c b/block/raw_bsd.c
>   index 07e6f06..ab2b0fd 100644
>   --- a/block/raw_bsd.c
>   +++ b/block/raw_bsd.c
>   @@ -41,10 +41,7 @@ static QEMUOptionParameter raw_create_options[] = {
>    static int raw_reopen_prepare(BDRVReopenState *reopen_state,
>                                  BlockReopenQueue *queue, Error **errp)
>    {
>   -    BDRVReopenState tmp = *reopen_state;
>   -
>   -    tmp.bs = tmp.bs->file;
>   -    return bdrv_reopen_prepare(&tmp, queue, errp);
>   +    return 0;
>    }
> 
>    static int coroutine_fn raw_co_readv(BlockDriverState *bs, int64_t sector_num,
>   @@ -150,6 +147,9 @@ static void raw_close(BlockDriverState *bs)
> 
>    static int raw_probe(const uint8_t *buf, int buf_size, const char *filename)
>    {
>   +    /* smallest possible positive score so that raw is used if and only if no
>   +     * other block driver works
>   +     */
>        return 1;
>    }
> 
> v1 blurb:
> 
> Paolo asked me to write such a driver based on his textual specification
> alone. The first patch captures his email in full, the rest re-quotes
> parts that are being implemented.
> 
> The tree compiles at each patch. The series passes "make check-block".
> 
> "block/raw.c" is not removed because I wanted to keep it out of my
> series and out of my brain.
> 
> Laszlo Ersek (7):
>   add skeleton for BSD licensed "raw" BlockDriver
>   raw_bsd: emit debug events in bdrv_co_readv() and bdrv_co_writev()
>   raw_bsd: add raw_create()
>   raw_bsd: introduce "special members"
>   raw_bsd: add raw_create_options
>   raw_bsd: register bdrv_raw
>   switch raw block driver from "raw.o" to "raw_bsd.o"
> 
>  block/Makefile.objs |    2 +-
>  block/raw_bsd.c     |  186 +++++++++++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 187 insertions(+), 1 deletions(-)
>  create mode 100644 block/raw_bsd.c

Ping.

Laszlo

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

* Re: [Qemu-devel] [PATCH v2 0/7] introduce BSD-licensed block driver for "raw"
  2013-08-21 10:41 [Qemu-devel] [PATCH v2 0/7] introduce BSD-licensed block driver for "raw" Laszlo Ersek
                   ` (7 preceding siblings ...)
  2013-08-28 10:50 ` [Qemu-devel] [PATCH v2 0/7] introduce BSD-licensed block driver for "raw" Laszlo Ersek
@ 2013-08-28 13:17 ` Kevin Wolf
  8 siblings, 0 replies; 10+ messages in thread
From: Kevin Wolf @ 2013-08-28 13:17 UTC (permalink / raw)
  To: Laszlo Ersek; +Cc: anthony, pbonzini, hch, stefanha, qemu-devel

Am 21.08.2013 um 12:41 hat Laszlo Ersek geschrieben:
> v1->v2:
> - added comment to raw_probe() [Kevin]
> - fixed raw_reopen_prepare() [Paolo & Kevin]
> - keeping BSDL: according to the v1 discussion, LGPLv2+ could work too,
>   but "but most of the block layer is BSD" [Paolo] and I haven't been
>   clearly instructed to switch to LGPLv2+.
> 
>   diff --git a/block/raw_bsd.c b/block/raw_bsd.c
>   index 07e6f06..ab2b0fd 100644
>   --- a/block/raw_bsd.c
>   +++ b/block/raw_bsd.c
>   @@ -41,10 +41,7 @@ static QEMUOptionParameter raw_create_options[] = {
>    static int raw_reopen_prepare(BDRVReopenState *reopen_state,
>                                  BlockReopenQueue *queue, Error **errp)
>    {
>   -    BDRVReopenState tmp = *reopen_state;
>   -
>   -    tmp.bs = tmp.bs->file;
>   -    return bdrv_reopen_prepare(&tmp, queue, errp);
>   +    return 0;
>    }
> 
>    static int coroutine_fn raw_co_readv(BlockDriverState *bs, int64_t sector_num,
>   @@ -150,6 +147,9 @@ static void raw_close(BlockDriverState *bs)
> 
>    static int raw_probe(const uint8_t *buf, int buf_size, const char *filename)
>    {
>   +    /* smallest possible positive score so that raw is used if and only if no
>   +     * other block driver works
>   +     */
>        return 1;
>    }
> 
> v1 blurb:
> 
> Paolo asked me to write such a driver based on his textual specification
> alone. The first patch captures his email in full, the rest re-quotes
> parts that are being implemented.
> 
> The tree compiles at each patch. The series passes "make check-block".
> 
> "block/raw.c" is not removed because I wanted to keep it out of my
> series and out of my brain.
> 
> Laszlo Ersek (7):
>   add skeleton for BSD licensed "raw" BlockDriver
>   raw_bsd: emit debug events in bdrv_co_readv() and bdrv_co_writev()
>   raw_bsd: add raw_create()
>   raw_bsd: introduce "special members"
>   raw_bsd: add raw_create_options
>   raw_bsd: register bdrv_raw
>   switch raw block driver from "raw.o" to "raw_bsd.o"
> 
>  block/Makefile.objs |    2 +-
>  block/raw_bsd.c     |  186 +++++++++++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 187 insertions(+), 1 deletions(-)
>  create mode 100644 block/raw_bsd.c

Thanks, applied to the block branch.

Kevin

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

end of thread, other threads:[~2013-08-28 13:17 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-08-21 10:41 [Qemu-devel] [PATCH v2 0/7] introduce BSD-licensed block driver for "raw" Laszlo Ersek
2013-08-21 10:41 ` [Qemu-devel] [PATCH v2 1/7] add skeleton for BSD licensed "raw" BlockDriver Laszlo Ersek
2013-08-21 10:41 ` [Qemu-devel] [PATCH v2 2/7] raw_bsd: emit debug events in bdrv_co_readv() and bdrv_co_writev() Laszlo Ersek
2013-08-21 10:41 ` [Qemu-devel] [PATCH v2 3/7] raw_bsd: add raw_create() Laszlo Ersek
2013-08-21 10:41 ` [Qemu-devel] [PATCH v2 4/7] raw_bsd: introduce "special members" Laszlo Ersek
2013-08-21 10:41 ` [Qemu-devel] [PATCH v2 5/7] raw_bsd: add raw_create_options Laszlo Ersek
2013-08-21 10:41 ` [Qemu-devel] [PATCH v2 6/7] raw_bsd: register bdrv_raw Laszlo Ersek
2013-08-21 10:41 ` [Qemu-devel] [PATCH v2 7/7] switch raw block driver from "raw.o" to "raw_bsd.o" Laszlo Ersek
2013-08-28 10:50 ` [Qemu-devel] [PATCH v2 0/7] introduce BSD-licensed block driver for "raw" Laszlo Ersek
2013-08-28 13:17 ` Kevin Wolf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).