Skip to contentSkip to conversation

block: Minor cleanups

PATCH Applied Markus Armbruster 4 participants 10 messages Jun 6, 2014 – Jun 13, 2014 Block layer

lore
Share & tools
lore
#0 lore raw

cover block: Minor cleanups

Markus Armbruster (3):
blockdev: Rename drive_init(), drive_uninit() to drive_new(),

    drive_del()

blockdev: Remove unused DriveInfo reference count block/qapi: Give some functions internal linkage

 block/qapi.c              | 13 ++++++-------
 blockdev.c                | 28 +++++++---------------------
 device-hotplug.c          |  4 ++--
 hw/ide/piix.c             |  2 +-
 hw/usb/dev-storage.c      |  2 +-
 include/block/qapi.h      |  7 -------
 include/sysemu/blockdev.h |  8 +++-----
 vl.c                      |  4 ++--
 8 files changed, 22 insertions(+), 46 deletions(-)
Signature · 1 line
1.9.3
#1 lore raw

PATCH 1/3 blockdev: Rename drive_init(), drive_uninit() to drive_new(), drive_del()

"Init" and "uninit" suggest the functions don't allocate / free storage. But they do.

---
 blockdev.c                | 14 +++++++-------
 device-hotplug.c          |  2 +-
 hw/usb/dev-storage.c      |  2 +-
 include/sysemu/blockdev.h |  4 ++--
 vl.c                      |  4 ++--
 5 files changed, 13 insertions(+), 13 deletions(-)
blockdev.c +7 -7
index 9b5261b..1256013 100644
@@ -213,7 +213,7 @@ static void bdrv_format_print(void *opaque, const char *name)
     error_printf(" %s", name);
 }
 
-static void drive_uninit(DriveInfo *dinfo)
+static void drive_del(DriveInfo *dinfo)
 {
     if (dinfo->opts) {
         qemu_opts_del(dinfo->opts);
@@ -230,7 +230,7 @@ void drive_put_ref(DriveInfo *dinfo)
 {
     assert(dinfo->refcount);
     if (--dinfo->refcount == 0) {
-        drive_uninit(dinfo);
+        drive_del(dinfo);
     }
 }
 
@@ -658,7 +658,7 @@ QemuOptsList qemu_legacy_drive_opts = {
     },
 };
 
-DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type)
+DriveInfo *drive_new(QemuOpts *all_opts, BlockInterfaceType block_default_type)
 {
     const char *value;
     DriveInfo *dinfo = NULL;
@@ -1791,7 +1791,7 @@ int do_drive_del(Monitor *mon, const QDict *qdict, QObject **ret_data)
         bdrv_set_on_error(bs, BLOCKDEV_ON_ERROR_REPORT,
                           BLOCKDEV_ON_ERROR_REPORT);
     } else {
-        drive_uninit(drive_get_by_blockdev(bs));
+        drive_del(drive_get_by_blockdev(bs));
     }
 
     return 0;
@@ -2334,9 +2334,9 @@ void qmp_blockdev_add(BlockdevOptions *options, Error **errp)
         goto fail;
     }
 
-    /* TODO Sort it out in raw-posix and drive_init: Reject aio=native with
+    /* TODO Sort it out in raw-posix and drive_new(): Reject aio=native with
      * cache.direct=false instead of silently switching to aio=threads, except
-     * if called from drive_init.
+     * when called from drive_new().
      *
      * For now, simply forbidding the combination for all drivers will do. */
     if (options->has_aio && options->aio == BLOCKDEV_AIO_OPTIONS_NATIVE) {
@@ -2368,7 +2368,7 @@ void qmp_blockdev_add(BlockdevOptions *options, Error **errp)
     }
 
     if (bdrv_key_required(dinfo->bdrv)) {
-        drive_uninit(dinfo);
+        drive_del(dinfo);
         error_setg(errp, "blockdev-add doesn't support encrypted devices");
         goto fail;
     }
device-hotplug.c +1 -1
index eecb08e..fc09d10 100644
@@ -40,7 +40,7 @@ DriveInfo *add_init_drive(const char *optstr)
         return NULL;
 
     mc = MACHINE_GET_CLASS(current_machine);
-    dinfo = drive_init(opts, mc->block_default_type);
+    dinfo = drive_new(opts, mc->block_default_type);
     if (!dinfo) {
         qemu_opts_del(opts);
         return NULL;
hw/usb/dev-storage.c +1 -1
index e919100..ae4efcb 100644
@@ -691,7 +691,7 @@ static USBDevice *usb_msd_init(USBBus *bus, const char *filename)
     qemu_opt_set(opts, "if", "none");
 
     /* create host drive */
-    dinfo = drive_init(opts, 0);
+    dinfo = drive_new(opts, 0);
     if (!dinfo) {
         qemu_opts_del(opts);
         return NULL;
include/sysemu/blockdev.h +2 -2
index 134712b..0fdbd68 100644
@@ -37,7 +37,7 @@ struct DriveInfo {
     int bus;
     int unit;
     int auto_del;               /* see blockdev_mark_auto_del() */
-    bool enable_auto_del; /* Only for legacy drive_init() */
+    bool enable_auto_del;       /* Only for legacy drive_new() */
     int media_cd;
     int cyls, heads, secs, trans;
     QemuOpts *opts;
@@ -57,7 +57,7 @@ DriveInfo *drive_get_by_blockdev(BlockDriverState *bs);
 QemuOpts *drive_def(const char *optstr);
 QemuOpts *drive_add(BlockInterfaceType type, int index, const char *file,
                     const char *optstr);
-DriveInfo *drive_init(QemuOpts *arg, BlockInterfaceType block_default_type);
+DriveInfo *drive_new(QemuOpts *arg, BlockInterfaceType block_default_type);
 
 /* device-hotplug */
 
vl.c +2 -2
index a3def97..f4b4841 100644
@@ -1074,7 +1074,7 @@ static int drive_init_func(QemuOpts *opts, void *opaque)
 {
     BlockInterfaceType *block_default_type = opaque;
 
-    return drive_init(opts, *block_default_type) == NULL;
+    return drive_new(opts, *block_default_type) == NULL;
 }
 
 static int drive_enable_snapshot(QemuOpts *opts, void *opaque)
@@ -1098,7 +1098,7 @@ static void default_drive(int enable, int snapshot, BlockInterfaceType type,
     if (snapshot) {
         drive_enable_snapshot(opts, NULL);
     }
-    if (!drive_init(opts, type)) {
+    if (!drive_new(opts, type)) {
         exit(1);
     }
 }
Signature · 1 line
1.9.3
Reviewed-by Benoit Canet on v1 1/3
#2 lore raw

Re: [Qemu-devel] [PATCH 1/3] blockdev: Rename drive_init(), drive_uninit() to drive_new(), drive_del()

vl.c

Quoted 122 lines · Markus Armbruster

"Init" and "uninit" suggest the functions don't allocate / free storage. But they do.

---
 blockdev.c                | 14 +++++++-------
 device-hotplug.c          |  2 +-
 hw/usb/dev-storage.c      |  2 +-
 include/sysemu/blockdev.h |  4 ++--
 vl.c                      |  4 ++--
 5 files changed, 13 insertions(+), 13 deletions(-)
blockdev.c +7 -7
index 9b5261b..1256013 100644
@@ -213,7 +213,7 @@ static void bdrv_format_print(void *opaque, const char *name)
     error_printf(" %s", name);
 }
 
-static void drive_uninit(DriveInfo *dinfo)
+static void drive_del(DriveInfo *dinfo)
 {
     if (dinfo->opts) {
         qemu_opts_del(dinfo->opts);
@@ -230,7 +230,7 @@ void drive_put_ref(DriveInfo *dinfo)
 {
     assert(dinfo->refcount);
     if (--dinfo->refcount == 0) {
-        drive_uninit(dinfo);
+        drive_del(dinfo);
     }
 }
 
@@ -658,7 +658,7 @@ QemuOptsList qemu_legacy_drive_opts = {
     },
 };
 
-DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type)
+DriveInfo *drive_new(QemuOpts *all_opts, BlockInterfaceType block_default_type)
 {
     const char *value;
     DriveInfo *dinfo = NULL;
@@ -1791,7 +1791,7 @@ int do_drive_del(Monitor *mon, const QDict *qdict, QObject **ret_data)
         bdrv_set_on_error(bs, BLOCKDEV_ON_ERROR_REPORT,
                           BLOCKDEV_ON_ERROR_REPORT);
     } else {
-        drive_uninit(drive_get_by_blockdev(bs));
+        drive_del(drive_get_by_blockdev(bs));
     }
 
     return 0;
@@ -2334,9 +2334,9 @@ void qmp_blockdev_add(BlockdevOptions *options, Error **errp)
         goto fail;
     }
 
-    /* TODO Sort it out in raw-posix and drive_init: Reject aio=native with
+    /* TODO Sort it out in raw-posix and drive_new(): Reject aio=native with
      * cache.direct=false instead of silently switching to aio=threads, except
-     * if called from drive_init.
+     * when called from drive_new().
      *
      * For now, simply forbidding the combination for all drivers will do. */
     if (options->has_aio && options->aio == BLOCKDEV_AIO_OPTIONS_NATIVE) {
@@ -2368,7 +2368,7 @@ void qmp_blockdev_add(BlockdevOptions *options, Error **errp)
     }
 
     if (bdrv_key_required(dinfo->bdrv)) {
-        drive_uninit(dinfo);
+        drive_del(dinfo);
         error_setg(errp, "blockdev-add doesn't support encrypted devices");
         goto fail;
     }
device-hotplug.c +1 -1
index eecb08e..fc09d10 100644
@@ -40,7 +40,7 @@ DriveInfo *add_init_drive(const char *optstr)
         return NULL;
 
     mc = MACHINE_GET_CLASS(current_machine);
-    dinfo = drive_init(opts, mc->block_default_type);
+    dinfo = drive_new(opts, mc->block_default_type);
     if (!dinfo) {
         qemu_opts_del(opts);
         return NULL;
hw/usb/dev-storage.c +1 -1
index e919100..ae4efcb 100644
@@ -691,7 +691,7 @@ static USBDevice *usb_msd_init(USBBus *bus, const char *filename)
     qemu_opt_set(opts, "if", "none");
 
     /* create host drive */
-    dinfo = drive_init(opts, 0);
+    dinfo = drive_new(opts, 0);
     if (!dinfo) {
         qemu_opts_del(opts);
         return NULL;
include/sysemu/blockdev.h +2 -2
index 134712b..0fdbd68 100644
@@ -37,7 +37,7 @@ struct DriveInfo {
     int bus;
     int unit;
     int auto_del;               /* see blockdev_mark_auto_del() */
-    bool enable_auto_del; /* Only for legacy drive_init() */
+    bool enable_auto_del;       /* Only for legacy drive_new() */
     int media_cd;
     int cyls, heads, secs, trans;
     QemuOpts *opts;
@@ -57,7 +57,7 @@ DriveInfo *drive_get_by_blockdev(BlockDriverState *bs);
 QemuOpts *drive_def(const char *optstr);
 QemuOpts *drive_add(BlockInterfaceType type, int index, const char *file,
                     const char *optstr);
-DriveInfo *drive_init(QemuOpts *arg, BlockInterfaceType block_default_type);
+DriveInfo *drive_new(QemuOpts *arg, BlockInterfaceType block_default_type);
 
 /* device-hotplug */
 
vl.c +0 -0

gG> index a3def97..f4b4841 100644

Quoted 12 lines
vl.c +1 -1
@@ -1074,7 +1074,7 @@ static int drive_init_func(QemuOpts *opts, void *opaque)
 {
     BlockInterfaceType *block_default_type = opaque;
 
-    return drive_init(opts, *block_default_type) == NULL;
+    return drive_new(opts, *block_default_type) == NULL;
 }
 
 static int drive_enable_snapshot(QemuOpts *opts, void *opaque)

vl.c static void default_drive(int enable, int snapshot, BlockInterfaceType type, · line 1101

Quoted 5 lines
vl.c +1 -1
@@ -1098,7 +1098,7 @@ static void default_drive(int enable, int snapshot, BlockInterfaceType type,
     if (snapshot) {
         drive_enable_snapshot(opts, NULL);
     }
-    if (!drive_init(opts, type)) {
+    if (!drive_new(opts, type)) {

Unrelated but it seems QEMU is leaking this one on exit.

Quoted 7 lines
vl.c +0 -0
         exit(1);
     }
 }
Signature · 1 line
1.9.3
#3 lore raw

Re: [Qemu-devel] [PATCH 1/3] blockdev: Rename drive_init(), drive_uninit() to drive_new(), drive_del()

Quoted 134 lines · Benoît Canet

vl.c

Quoted 122 lines · Markus Armbruster

"Init" and "uninit" suggest the functions don't allocate / free storage. But they do.

---
 blockdev.c                | 14 +++++++-------
 device-hotplug.c          |  2 +-
 hw/usb/dev-storage.c      |  2 +-
 include/sysemu/blockdev.h |  4 ++--
 vl.c                      |  4 ++--
 5 files changed, 13 insertions(+), 13 deletions(-)
blockdev.c +7 -7
index 9b5261b..1256013 100644
@@ -213,7 +213,7 @@ static void bdrv_format_print(void *opaque, const char *name)
     error_printf(" %s", name);
 }
 
-static void drive_uninit(DriveInfo *dinfo)
+static void drive_del(DriveInfo *dinfo)
 {
     if (dinfo->opts) {
         qemu_opts_del(dinfo->opts);
@@ -230,7 +230,7 @@ void drive_put_ref(DriveInfo *dinfo)
 {
     assert(dinfo->refcount);
     if (--dinfo->refcount == 0) {
-        drive_uninit(dinfo);
+        drive_del(dinfo);
     }
 }
 
@@ -658,7 +658,7 @@ QemuOptsList qemu_legacy_drive_opts = {
     },
 };
 
-DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type)
+DriveInfo *drive_new(QemuOpts *all_opts, BlockInterfaceType block_default_type)
 {
     const char *value;
     DriveInfo *dinfo = NULL;
@@ -1791,7 +1791,7 @@ int do_drive_del(Monitor *mon, const QDict *qdict, QObject **ret_data)
         bdrv_set_on_error(bs, BLOCKDEV_ON_ERROR_REPORT,
                           BLOCKDEV_ON_ERROR_REPORT);
     } else {
-        drive_uninit(drive_get_by_blockdev(bs));
+        drive_del(drive_get_by_blockdev(bs));
     }
 
     return 0;
@@ -2334,9 +2334,9 @@ void qmp_blockdev_add(BlockdevOptions *options, Error **errp)
         goto fail;
     }
 
-    /* TODO Sort it out in raw-posix and drive_init: Reject aio=native with
+    /* TODO Sort it out in raw-posix and drive_new(): Reject aio=native with
      * cache.direct=false instead of silently switching to aio=threads, except
-     * if called from drive_init.
+     * when called from drive_new().
      *
      * For now, simply forbidding the combination for all drivers will do. */
     if (options->has_aio && options->aio == BLOCKDEV_AIO_OPTIONS_NATIVE) {
@@ -2368,7 +2368,7 @@ void qmp_blockdev_add(BlockdevOptions *options, Error **errp)
     }
 
     if (bdrv_key_required(dinfo->bdrv)) {
-        drive_uninit(dinfo);
+        drive_del(dinfo);
         error_setg(errp, "blockdev-add doesn't support encrypted devices");
         goto fail;
     }
device-hotplug.c +1 -1
index eecb08e..fc09d10 100644
@@ -40,7 +40,7 @@ DriveInfo *add_init_drive(const char *optstr)
         return NULL;
 
     mc = MACHINE_GET_CLASS(current_machine);
-    dinfo = drive_init(opts, mc->block_default_type);
+    dinfo = drive_new(opts, mc->block_default_type);
     if (!dinfo) {
         qemu_opts_del(opts);
         return NULL;
hw/usb/dev-storage.c +1 -1
index e919100..ae4efcb 100644
@@ -691,7 +691,7 @@ static USBDevice *usb_msd_init(USBBus *bus, const char *filename)
     qemu_opt_set(opts, "if", "none");
 
     /* create host drive */
-    dinfo = drive_init(opts, 0);
+    dinfo = drive_new(opts, 0);
     if (!dinfo) {
         qemu_opts_del(opts);
         return NULL;
include/sysemu/blockdev.h +2 -2
index 134712b..0fdbd68 100644
@@ -37,7 +37,7 @@ struct DriveInfo {
     int bus;
     int unit;
     int auto_del;               /* see blockdev_mark_auto_del() */
-    bool enable_auto_del; /* Only for legacy drive_init() */
+    bool enable_auto_del;       /* Only for legacy drive_new() */
     int media_cd;
     int cyls, heads, secs, trans;
     QemuOpts *opts;
@@ -57,7 +57,7 @@ DriveInfo *drive_get_by_blockdev(BlockDriverState *bs);
 QemuOpts *drive_def(const char *optstr);
 QemuOpts *drive_add(BlockInterfaceType type, int index, const char *file,
                     const char *optstr);
-DriveInfo *drive_init(QemuOpts *arg, BlockInterfaceType block_default_type);
+DriveInfo *drive_new(QemuOpts *arg, BlockInterfaceType block_default_type);
 
 /* device-hotplug */
 
vl.c +0 -0

gG> index a3def97..f4b4841 100644

Quoted 10 lines
vl.c +1 -1
@@ -1074,7 +1074,7 @@ static int drive_init_func(QemuOpts *opts, void *opaque)
 {
     BlockInterfaceType *block_default_type = opaque;
 
-    return drive_init(opts, *block_default_type) == NULL;
+    return drive_new(opts, *block_default_type) == NULL;
 }
 
Quoted 9 lines

vl.c static void default_drive(int enable, int snapshot, BlockInterfaceType type, · line 1101

Quoted 7 lines
vl.c +1 -1
 static int drive_enable_snapshot(QemuOpts *opts, void *opaque)
@@ -1098,7 +1098,7 @@ static void default_drive(int enable, int snapshot, BlockInterfaceType type,
     if (snapshot) {
         drive_enable_snapshot(opts, NULL);
     }
-    if (!drive_init(opts, type)) {
+    if (!drive_new(opts, type)) {

Unrelated but it seems QEMU is leaking this one on exit.

The kernel cleans it up for free, along with zillions of other unfreed pieces of memory, file descriptors, and more.

Quoted 10 lines
Quoted 8 lines
vl.c +0 -0
         exit(1);
     }
 }
Signature · 1 line
1.9.3

Thanks!

#4 lore raw

PATCH 2/3 blockdev: Remove unused DriveInfo reference count

In reply to Markus Armbruster

It's always one since commit fa510eb dropped the last drive_get_ref().

---
 blockdev.c                | 18 ++----------------
 device-hotplug.c          |  2 +-
 hw/ide/piix.c             |  2 +-
 include/sysemu/blockdev.h |  4 +---
 4 files changed, 5 insertions(+), 21 deletions(-)
blockdev.c +2 -16
index 1256013..2e855d2 100644
@@ -106,7 +106,7 @@ void blockdev_auto_del(BlockDriverState *bs)
     DriveInfo *dinfo = drive_get_by_blockdev(bs);
 
     if (dinfo && dinfo->auto_del) {
-        drive_put_ref(dinfo);
+        drive_del(dinfo);
     }
 }
 
@@ -213,7 +213,7 @@ static void bdrv_format_print(void *opaque, const char *name)
     error_printf(" %s", name);
 }
 
-static void drive_del(DriveInfo *dinfo)
+void drive_del(DriveInfo *dinfo)
 {
     if (dinfo->opts) {
         qemu_opts_del(dinfo->opts);
@@ -226,19 +226,6 @@ static void drive_del(DriveInfo *dinfo)
     g_free(dinfo);
 }
 
-void drive_put_ref(DriveInfo *dinfo)
-{
-    assert(dinfo->refcount);
-    if (--dinfo->refcount == 0) {
-        drive_del(dinfo);
-    }
-}
-
-void drive_get_ref(DriveInfo *dinfo)
-{
-    dinfo->refcount++;
-}
-
 typedef struct {
     QEMUBH *bh;
     BlockDriverState *bs;
@@ -500,7 +487,6 @@ static DriveInfo *blockdev_init(const char *file, QDict *bs_opts,
     dinfo->bdrv->open_flags = snapshot ? BDRV_O_SNAPSHOT : 0;
     dinfo->bdrv->read_only = ro;
     dinfo->bdrv->detect_zeroes = detect_zeroes;
-    dinfo->refcount = 1;
     if (serial != NULL) {
         dinfo->serial = g_strdup(serial);
     }
device-hotplug.c +1 -1
index fc09d10..e6a1ffb 100644
@@ -76,6 +76,6 @@ void drive_hot_add(Monitor *mon, const QDict *qdict)
 
 err:
     if (dinfo) {
-        drive_put_ref(dinfo);
+        drive_del(dinfo);
     }
 }
hw/ide/piix.c +1 -1
index 40757eb..8651726 100644
@@ -184,7 +184,7 @@ int pci_piix3_xen_ide_unplug(DeviceState *dev)
             }
             bdrv_close(di->bdrv);
             pci_ide->bus[di->bus].ifs[di->unit].bs = NULL;
-            drive_put_ref(di);
+            drive_del(di);
         }
     }
     qdev_reset_all(DEVICE(dev));
include/sysemu/blockdev.h +1 -3
index 0fdbd68..23a5d10 100644
@@ -43,21 +43,19 @@ struct DriveInfo {
     QemuOpts *opts;
     char *serial;
     QTAILQ_ENTRY(DriveInfo) next;
-    int refcount;
 };
 
 DriveInfo *drive_get(BlockInterfaceType type, int bus, int unit);
 DriveInfo *drive_get_by_index(BlockInterfaceType type, int index);
 int drive_get_max_bus(BlockInterfaceType type);
 DriveInfo *drive_get_next(BlockInterfaceType type);
-void drive_get_ref(DriveInfo *dinfo);
-void drive_put_ref(DriveInfo *dinfo);
 DriveInfo *drive_get_by_blockdev(BlockDriverState *bs);
 
 QemuOpts *drive_def(const char *optstr);
 QemuOpts *drive_add(BlockInterfaceType type, int index, const char *file,
                     const char *optstr);
 DriveInfo *drive_new(QemuOpts *arg, BlockInterfaceType block_default_type);
+void drive_del(DriveInfo *dinfo);
 
 /* device-hotplug */
 
Signature · 1 line
1.9.3
Reviewed-by Benoit Canet on v1 2/3
#5 lore raw

Re: [Qemu-devel] [PATCH 2/3] blockdev: Remove unused DriveInfo reference count

Quoted 116 lines · Markus Armbruster

It's always one since commit fa510eb dropped the last drive_get_ref().

---
 blockdev.c                | 18 ++----------------
 device-hotplug.c          |  2 +-
 hw/ide/piix.c             |  2 +-
 include/sysemu/blockdev.h |  4 +---
 4 files changed, 5 insertions(+), 21 deletions(-)
blockdev.c +2 -16
index 1256013..2e855d2 100644
@@ -106,7 +106,7 @@ void blockdev_auto_del(BlockDriverState *bs)
     DriveInfo *dinfo = drive_get_by_blockdev(bs);
 
     if (dinfo && dinfo->auto_del) {
-        drive_put_ref(dinfo);
+        drive_del(dinfo);
     }
 }
 
@@ -213,7 +213,7 @@ static void bdrv_format_print(void *opaque, const char *name)
     error_printf(" %s", name);
 }
 
-static void drive_del(DriveInfo *dinfo)
+void drive_del(DriveInfo *dinfo)
 {
     if (dinfo->opts) {
         qemu_opts_del(dinfo->opts);
@@ -226,19 +226,6 @@ static void drive_del(DriveInfo *dinfo)
     g_free(dinfo);
 }
 
-void drive_put_ref(DriveInfo *dinfo)
-{
-    assert(dinfo->refcount);
-    if (--dinfo->refcount == 0) {
-        drive_del(dinfo);
-    }
-}
-
-void drive_get_ref(DriveInfo *dinfo)
-{
-    dinfo->refcount++;
-}
-
 typedef struct {
     QEMUBH *bh;
     BlockDriverState *bs;
@@ -500,7 +487,6 @@ static DriveInfo *blockdev_init(const char *file, QDict *bs_opts,
     dinfo->bdrv->open_flags = snapshot ? BDRV_O_SNAPSHOT : 0;
     dinfo->bdrv->read_only = ro;
     dinfo->bdrv->detect_zeroes = detect_zeroes;
-    dinfo->refcount = 1;
     if (serial != NULL) {
         dinfo->serial = g_strdup(serial);
     }
device-hotplug.c +1 -1
index fc09d10..e6a1ffb 100644
@@ -76,6 +76,6 @@ void drive_hot_add(Monitor *mon, const QDict *qdict)
 
 err:
     if (dinfo) {
-        drive_put_ref(dinfo);
+        drive_del(dinfo);
     }
 }
hw/ide/piix.c +1 -1
index 40757eb..8651726 100644
@@ -184,7 +184,7 @@ int pci_piix3_xen_ide_unplug(DeviceState *dev)
             }
             bdrv_close(di->bdrv);
             pci_ide->bus[di->bus].ifs[di->unit].bs = NULL;
-            drive_put_ref(di);
+            drive_del(di);
         }
     }
     qdev_reset_all(DEVICE(dev));
include/sysemu/blockdev.h +1 -3
index 0fdbd68..23a5d10 100644
@@ -43,21 +43,19 @@ struct DriveInfo {
     QemuOpts *opts;
     char *serial;
     QTAILQ_ENTRY(DriveInfo) next;
-    int refcount;
 };
 
 DriveInfo *drive_get(BlockInterfaceType type, int bus, int unit);
 DriveInfo *drive_get_by_index(BlockInterfaceType type, int index);
 int drive_get_max_bus(BlockInterfaceType type);
 DriveInfo *drive_get_next(BlockInterfaceType type);
-void drive_get_ref(DriveInfo *dinfo);
-void drive_put_ref(DriveInfo *dinfo);
 DriveInfo *drive_get_by_blockdev(BlockDriverState *bs);
 
 QemuOpts *drive_def(const char *optstr);
 QemuOpts *drive_add(BlockInterfaceType type, int index, const char *file,
                     const char *optstr);
 DriveInfo *drive_new(QemuOpts *arg, BlockInterfaceType block_default_type);
+void drive_del(DriveInfo *dinfo);
 
 /* device-hotplug */
 
Signature · 1 line
1.9.3
#6 lore raw

PATCH 3/3 block/qapi: Give some functions internal linkage

In reply to Markus Armbruster
---
 block/qapi.c         | 13 ++++++-------
 include/block/qapi.h |  7 -------
 2 files changed, 6 insertions(+), 14 deletions(-)
block/qapi.c +6 -7
index 97e1641..f420e9a 100644
@@ -89,9 +89,9 @@ BlockDeviceInfo *bdrv_block_device_info(BlockDriverState *bs)
  * information, or NULL because there are no snapshots.  Returns -errno on
  * error, with *p_list untouched.
  */
-int bdrv_query_snapshot_info_list(BlockDriverState *bs,
-                                  SnapshotInfoList **p_list,
-                                  Error **errp)
+static int bdrv_query_snapshot_info_list(BlockDriverState *bs,
+                                         SnapshotInfoList **p_list,
+                                         Error **errp)
 {
     int i, sn_count;
     QEMUSnapshotInfo *sn_tab = NULL;
@@ -236,9 +236,8 @@ void bdrv_query_image_info(BlockDriverState *bs,
 }
 
 /* @p_info will be set only on success. */
-void bdrv_query_info(BlockDriverState *bs,
-                     BlockInfo **p_info,
-                     Error **errp)
+static void bdrv_query_info(BlockDriverState *bs, BlockInfo **p_info,
+                            Error **errp)
 {
     BlockInfo *info = g_malloc0(sizeof(*info));
     BlockDriverState *bs0;
@@ -293,7 +292,7 @@ void bdrv_query_info(BlockDriverState *bs,
     qapi_free_BlockInfo(info);
 }
 
-BlockStats *bdrv_query_stats(const BlockDriverState *bs)
+static BlockStats *bdrv_query_stats(const BlockDriverState *bs)
 {
     BlockStats *s;
 
include/block/qapi.h +0 -7
index e92c00d..6672179 100644
@@ -30,16 +30,9 @@
 #include "block/snapshot.h"
 
 BlockDeviceInfo *bdrv_block_device_info(BlockDriverState *bs);
-int bdrv_query_snapshot_info_list(BlockDriverState *bs,
-                                  SnapshotInfoList **p_list,
-                                  Error **errp);
 void bdrv_query_image_info(BlockDriverState *bs,
                            ImageInfo **p_info,
                            Error **errp);
-void bdrv_query_info(BlockDriverState *bs,
-                     BlockInfo **p_info,
-                     Error **errp);
-BlockStats *bdrv_query_stats(const BlockDriverState *bs);
 
 void bdrv_snapshot_dump(fprintf_function func_fprintf, void *f,
                         QEMUSnapshotInfo *sn);
Signature · 1 line
1.9.3
Reviewed-by Benoit Canet on v1 3/3
#7 lore raw

Re: [Qemu-devel] [PATCH 3/3] block/qapi: Give some functions internal linkage

Quoted 69 lines · Markus Armbruster
---
 block/qapi.c         | 13 ++++++-------
 include/block/qapi.h |  7 -------
 2 files changed, 6 insertions(+), 14 deletions(-)
block/qapi.c +6 -7
index 97e1641..f420e9a 100644
@@ -89,9 +89,9 @@ BlockDeviceInfo *bdrv_block_device_info(BlockDriverState *bs)
  * information, or NULL because there are no snapshots.  Returns -errno on
  * error, with *p_list untouched.
  */
-int bdrv_query_snapshot_info_list(BlockDriverState *bs,
-                                  SnapshotInfoList **p_list,
-                                  Error **errp)
+static int bdrv_query_snapshot_info_list(BlockDriverState *bs,
+                                         SnapshotInfoList **p_list,
+                                         Error **errp)
 {
     int i, sn_count;
     QEMUSnapshotInfo *sn_tab = NULL;
@@ -236,9 +236,8 @@ void bdrv_query_image_info(BlockDriverState *bs,
 }
 
 /* @p_info will be set only on success. */
-void bdrv_query_info(BlockDriverState *bs,
-                     BlockInfo **p_info,
-                     Error **errp)
+static void bdrv_query_info(BlockDriverState *bs, BlockInfo **p_info,
+                            Error **errp)
 {
     BlockInfo *info = g_malloc0(sizeof(*info));
     BlockDriverState *bs0;
@@ -293,7 +292,7 @@ void bdrv_query_info(BlockDriverState *bs,
     qapi_free_BlockInfo(info);
 }
 
-BlockStats *bdrv_query_stats(const BlockDriverState *bs)
+static BlockStats *bdrv_query_stats(const BlockDriverState *bs)
 {
     BlockStats *s;
 
include/block/qapi.h +0 -7
index e92c00d..6672179 100644
@@ -30,16 +30,9 @@
 #include "block/snapshot.h"
 
 BlockDeviceInfo *bdrv_block_device_info(BlockDriverState *bs);
-int bdrv_query_snapshot_info_list(BlockDriverState *bs,
-                                  SnapshotInfoList **p_list,
-                                  Error **errp);
 void bdrv_query_image_info(BlockDriverState *bs,
                            ImageInfo **p_info,
                            Error **errp);
-void bdrv_query_info(BlockDriverState *bs,
-                     BlockInfo **p_info,
-                     Error **errp);
-BlockStats *bdrv_query_stats(const BlockDriverState *bs);
 
 void bdrv_snapshot_dump(fprintf_function func_fprintf, void *f,
                         QEMUSnapshotInfo *sn);
Signature · 1 line
1.9.3
#8 lore raw

Re: [Qemu-devel] [PATCH 3/3] block/qapi: Give some functions internal linkage

In reply to Markus Armbruster
Quoted 5 lines · Markus Armbruster
---
 block/qapi.c         | 13 ++++++-------
 include/block/qapi.h |  7 -------
 2 files changed, 6 insertions(+), 14 deletions(-)

Unfortunately I had to drop this patch because it conflicts with the following qemu.git commit which was recently merged:

commit b21631f3b5cdecd14114034cd9e4e7f63ed7fde1

Author: Hani Benhabiles <[email protected]>
Date:   Tue May 27 23:39:37 2014 +0100

monitor: Add delvm and loadvm argument completion

If you want to send an updated patch, please rebase qemu.git. I have kept the other patches in this series.

#9 lore raw
In reply to Markus Armbruster
Quoted 6 lines · Markus Armbruster

Markus Armbruster (3):
blockdev: Rename drive_init(), drive_uninit() to drive_new(),

    drive_del()

blockdev: Remove unused DriveInfo reference count block/qapi: Give some functions internal linkage

Quoted 13 lines
 block/qapi.c              | 13 ++++++-------
 blockdev.c                | 28 +++++++---------------------
 device-hotplug.c          |  4 ++--
 hw/ide/piix.c             |  2 +-
 hw/usb/dev-storage.c      |  2 +-
 include/block/qapi.h      |  7 -------
 include/sysemu/blockdev.h |  8 +++-----
 vl.c                      |  4 ++--
 8 files changed, 22 insertions(+), 46 deletions(-)
Signature · 1 line
1.9.3

Thanks, applied to my block tree:
https://github.com/stefanha/qemu/commits/block

Stefan