diff mbox

[04/12] blockdev: New drive_of_blockdev()

Message ID 1277484812-22012-5-git-send-email-armbru@redhat.com
State New
Headers show

Commit Message

Markus Armbruster June 25, 2010, 4:53 p.m. UTC
Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 blockdev.c |   12 ++++++++++++
 blockdev.h |    1 +
 2 files changed, 13 insertions(+), 0 deletions(-)

Comments

Christoph Hellwig June 25, 2010, 7:42 p.m. UTC | #1
> +DriveInfo *drive_of_blockdev(BlockDriverState *bs)

I'd call this find_drive_by_blockdev.
Markus Armbruster June 26, 2010, 5:32 a.m. UTC | #2
Christoph Hellwig <hch@lst.de> writes:

>> +DriveInfo *drive_of_blockdev(BlockDriverState *bs)
>
> I'd call this find_drive_by_blockdev.

For what it's worth, all externally visible functions dealing with
drives start with "drive_".
Christoph Hellwig June 26, 2010, 9:46 a.m. UTC | #3
On Sat, Jun 26, 2010 at 07:32:09AM +0200, Markus Armbruster wrote:
> Christoph Hellwig <hch@lst.de> writes:
> 
> >> +DriveInfo *drive_of_blockdev(BlockDriverState *bs)
> >
> > I'd call this find_drive_by_blockdev.
> 
> For what it's worth, all externally visible functions dealing with
> drives start with "drive_".

Ok.  How about drive_get_by_blockdev, matching the drive_get_by_id we
have around?
Markus Armbruster June 26, 2010, 2:46 p.m. UTC | #4
Christoph Hellwig <hch@lst.de> writes:

> On Sat, Jun 26, 2010 at 07:32:09AM +0200, Markus Armbruster wrote:
>> Christoph Hellwig <hch@lst.de> writes:
>> 
>> >> +DriveInfo *drive_of_blockdev(BlockDriverState *bs)
>> >
>> > I'd call this find_drive_by_blockdev.
>> 
>> For what it's worth, all externally visible functions dealing with
>> drives start with "drive_".
>
> Ok.  How about drive_get_by_blockdev, matching the drive_get_by_id we
> have around?

drive_get_by_id() gets removed by 07/12.  But there's still drive_get().

drive_get_by_blockdev()?  blockdev_to_drive()?
Christoph Hellwig June 27, 2010, 9:36 a.m. UTC | #5
On Sat, Jun 26, 2010 at 04:46:28PM +0200, Markus Armbruster wrote:
> drive_get_by_id() gets removed by 07/12.  But there's still drive_get().
> 
> drive_get_by_blockdev()?  blockdev_to_drive()?

Oh well, just keep any name - it's not that important aftet all.
Paolo Bonzini June 28, 2010, 9:58 a.m. UTC | #6
On 06/26/2010 04:46 PM, Markus Armbruster wrote:
> drive_get_by_blockdev()?  blockdev_to_drive()?

I like drive_find_by_blockdev or drive_get_by_blockdev, in any case I'll 
make sure my own cpu_get_by_id is named in the same style that you choose.

Paolo
Markus Armbruster June 29, 2010, 8:57 a.m. UTC | #7
Paolo Bonzini <pbonzini@redhat.com> writes:

> On 06/26/2010 04:46 PM, Markus Armbruster wrote:
>> drive_get_by_blockdev()?  blockdev_to_drive()?
>
> I like drive_find_by_blockdev or drive_get_by_blockdev, in any case
> I'll make sure my own cpu_get_by_id is named in the same style that
> you choose.

drive_get_by_blockdev() it is.

As long as this is the only change, I don't think another post to the
list is necessary.  Instead, I'll push to my tree and let Kevin pick it
up from there.
diff mbox

Patch

diff --git a/blockdev.c b/blockdev.c
index e0495e5..8023cfd 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -78,6 +78,18 @@  int drive_get_max_bus(BlockInterfaceType type)
     return max_bus;
 }
 
+DriveInfo *drive_of_blockdev(BlockDriverState *bs)
+{
+    DriveInfo *dinfo;
+
+    QTAILQ_FOREACH(dinfo, &drives, next) {
+        if (dinfo->bdrv == bs) {
+            return dinfo;
+        }
+    }
+    return NULL;
+}
+
 static void bdrv_format_print(void *opaque, const char *name)
 {
     fprintf(stderr, " %s", name);
diff --git a/blockdev.h b/blockdev.h
index a936785..4bf75b1 100644
--- a/blockdev.h
+++ b/blockdev.h
@@ -40,6 +40,7 @@  extern DriveInfo *drive_get(BlockInterfaceType type, int bus, int unit);
 extern DriveInfo *drive_get_by_id(const char *id);
 extern int drive_get_max_bus(BlockInterfaceType type);
 extern void drive_uninit(DriveInfo *dinfo);
+extern DriveInfo *drive_of_blockdev(BlockDriverState *bs);
 
 extern QemuOpts *drive_add(const char *file, const char *fmt, ...);
 extern DriveInfo *drive_init(QemuOpts *arg, int default_to_scsi,