Block-related miscellaneous cleanups
cover Block-related miscellaneous cleanups
Random crap I ran into while working on a bigger task.
Markus Armbruster (4):
qemu-io: Clean up openfile() after commit 2e40134
xen_disk: Plug memory leak on error path
xen: Drop redundant bdrv_close() from pci_piix3_xen_ide_unplug()
thread-pool: Drop unnecessary includes
hw/block/xen_disk.c | 31 ++++++++++++++----------------- hw/ide/piix.c | 1 - include/block/thread-pool.h | 6 +----- qemu-io.c | 34 ++++++++++++---------------------- thread-pool.c | 1 - 5 files changed, 27 insertions(+), 46 deletions(-)
Signature · 1 line
1.9.3
PATCH 1/4 qemu-io: Clean up openfile() after commit 2e40134
Commit 6db9560 split off the growable case so it can use bdrv_file_open() instead of bdrv_open() then. Growable BDSes become anonymous. Weird.
Commit 2e40134 folded bdrv_file_open() back into bdrv_open() with new flag BDRV_O_PROTOCOL. We still have two bdrv_open() calls, and growable BDSes remain anonymous.
Circle back to before commit 6db9560: just one call, not anonymous.
--- qemu-io.c | 34 ++++++++++++---------------------- 1 file changed, 12 insertions(+), 22 deletions(-)
qemu-io.c +12 -22
@@ -58,30 +58,20 @@ static int openfile(char *name, int flags, int growable, QDict *opts)return 1 ; } + qemuio_bs =bdrv_new ("hda" , &error_abort); +if (growable) { -if (bdrv_open (&qemuio_bs, name,NULL , opts, flags |BDRV_O_PROTOCOL , -NULL , &local_err)) - { -fprintf (stderr,"%s: can't open%s%s: %s\n" , progname, - name ?" device " :"" , name ?:"" , -error_get_pretty (local_err)); -error_free (local_err); -return 1 ; - } - }else { - qemuio_bs =bdrv_new ("hda" , &error_abort); + flags |=BDRV_O_PROTOCOL ; + } -if (bdrv_open (&qemuio_bs, name,NULL , opts, flags,NULL , &local_err) - <0 ) - { -fprintf (stderr,"%s: can't open%s%s: %s\n" , progname, - name ?" device " :"" , name ?:"" , -error_get_pretty (local_err)); -error_free (local_err); -bdrv_unref (qemuio_bs); - qemuio_bs =NULL ; -return 1 ; - } +if (bdrv_open (&qemuio_bs, name,NULL , opts, flags,NULL , &local_err) <0 ) { +fprintf (stderr,"%s: can't open%s%s: %s\n" , progname, + name ?" device " :"" , name ?:"" , +error_get_pretty (local_err)); +error_free (local_err); +bdrv_unref (qemuio_bs); + qemuio_bs =NULL ; +return 1 ; }return 0 ;
Signature · 1 line
1.9.3
PATCH 2/4 xen_disk: Plug memory leak on error path
In reply to Markus ArmbrusterWhile there, streamline control flow a bit.
--- hw/block/xen_disk.c | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-)
hw/block/xen_disk.c +14 -17
@@ -852,28 +852,25 @@ static int blk_connect(struct XenDevice *xendev) blkdev->dinfo =drive_get (IF_XEN ,0 , index);if (!blkdev->dinfo) {Error *local_err =NULL ; +BlockDriver *drv; +/* setup via xenbus -> create new block driver instance */ xen_be_printf (&blkdev->xendev,2 ,"create new bdrv (xenbus setup)\n" ); - blkdev->bs =bdrv_new (blkdev->dev, &local_err); -if (local_err) { - blkdev->bs =NULL ; - } -if (blkdev->bs) { -BlockDriver *drv =bdrv_find_whitelisted_format (blkdev->fileproto, - readonly); -if (bdrv_open (&blkdev->bs, blkdev->filename,NULL ,NULL , qflags, - drv, &local_err) !=0 ) - { -xen_be_printf (&blkdev->xendev,0 ,"error: %s\n" , -error_get_pretty (local_err)); -error_free (local_err); -bdrv_unref (blkdev->bs); - blkdev->bs =NULL ; - } - } + blkdev->bs =bdrv_new (blkdev->dev,NULL );if (!blkdev->bs) {return -1 ; } + + drv =bdrv_find_whitelisted_format (blkdev->fileproto, readonly); +if (bdrv_open (&blkdev->bs, blkdev->filename,NULL ,NULL , qflags, + drv, &local_err) !=0 ) { +xen_be_printf (&blkdev->xendev,0 ,"error: %s\n" , +error_get_pretty (local_err)); +error_free (local_err); +bdrv_unref (blkdev->bs); + blkdev->bs =NULL ; +return -1 ; + } }else {/* setup via qemu cmdline -> already setup for us */ xen_be_printf (&blkdev->xendev,2 ,"get configured bdrv (cmdline setup)\n" );
Signature · 1 line
1.9.3
PATCH 3/4 xen: Drop redundant bdrv_close() from pci_piix3_xen_ide_unplug()
In reply to Markus Armbrusterdrive_del() closes just fine.
--- hw/ide/piix.c | 1 - 1 file changed, 1 deletion(-)
hw/ide/piix.c +0 -1
@@ -182,7 +182,6 @@ int pci_piix3_xen_ide_unplug(DeviceState *dev)if (ds) {bdrv_detach_dev (di->bdrv, ds); } -bdrv_close (di->bdrv); pci_ide->bus[di->bus].ifs[di->unit].bs =NULL ;drive_del (di); }
Signature · 1 line
1.9.3
PATCH 4/4 thread-pool: Drop unnecessary includes
In reply to Markus ArmbrusterDragging block_int.h into a header is *not* nice. Fortunately, this is the only offender.
--- include/block/thread-pool.h | 6 +----- thread-pool.c | 1 - 2 files changed, 1 insertion(+), 6 deletions(-)
include/block/thread-pool.h +1 -5
@@ -18,11 +18,7 @@#ifndef QEMU_THREAD_POOL_H #define QEMU_THREAD_POOL_H 1 -#include "qemu-common.h" -#include "qemu/queue.h" -#include "qemu/thread.h" -#include "block/coroutine.h" -#include "block/block_int.h" +#include "block/block.h" typedef int ThreadPoolFunc (void *opaque);
thread-pool.c +0 -1
@@ -20,7 +20,6 @@#include "qemu/osdep.h" #include "block/coroutine.h" #include "trace.h" -#include "block/block_int.h" #include "block/thread-pool.h" #include "qemu/main-loop.h"
Signature · 1 line
1.9.3
Kevin Wolf
AppliedAm 08.09.2014 um 18:50 hat Markus Armbruster geschrieben:
Quoted 7 lines
Random crap I ran into while working on a bigger task.
Markus Armbruster (4):
qemu-io: Clean upopenfile()after commit 2e40134
xen_disk: Plug memory leak on error path
xen: Drop redundantbdrv_close()frompci_piix3_xen_ide_unplug()
thread-pool: Drop unnecessary includes
Thanks, applied all to the block branch.
Kevin