Skip to contentSkip to conversation

Block patches

GIT PULL Stefan Hajnoczi 6 participants 17 messages Jul 7, 2015 – Jul 21, 2015 Block layer

lore
Share & tools
lore
#0 lore raw

The following changes since commit f6e3035f75e5c6a73485335765ae070304c7a110:

Merge remote-tracking branch 'remotes/bonzini/tags/for-upstream-smm' into staging (2015-07-06 23:37:53 +0100)

are available in the git repository at:

git://github.com/stefanha/qemu.git tags/block-pull-request

for you to fetch changes up to e065a2d586f4f66fe0aa6ef9fc5af3acdfe76fab:

blockjob: add block_job_release function (2015-07-07 12:53:12 +0100)

----------------------------------------------------------------

----------------------------------------------------------------

Alberto Garcia (1):
qcow2: remove unnecessary check

Fam Zheng (2):
block: Initialize local_err in bdrv_append_temp_snapshot
block: Use bdrv_drain to replace uncessary bdrv_drain_all

Peter Lieven (1):
block/nfs: add support for setting debug level

Richard W.M. Jones (1):
block/raw-posix: Don't think /dev/fd/<NN> is a floppy drive.

Stefan Hajnoczi (1):
block: update bdrv_drain_all()/bdrv_drain() comments

Ting Wang (1):
blockjob: add block_job_release function

 block.c                  |  8 ++++----
 block/io.c               | 20 ++++++++++----------
 block/mirror.c           |  2 ++
 block/nfs.c              | 28 ++++++++++++++++++++++++----
 block/qcow2-cache.c      |  3 ---
 block/raw-posix.c        |  3 ++-
 block/snapshot.c         |  2 +-
 blockjob.c               | 20 ++++++++++++--------
 include/block/blockjob.h |  8 ++++++++
 migration/block.c        |  2 +-
 qapi/block-core.json     | 20 ++++++++++++++++----
 11 files changed, 80 insertions(+), 36 deletions(-)
Signature · 1 line
2.4.3
#1 lore raw

[Qemu-devel] [PULL for-2.4 1/7] qcow2: remove unnecessary check

From: Alberto Garcia <[email protected]>

The value of 'i' is guaranteed to be >= 0

Message-id: [email protected]

---
 block/qcow2-cache.c | 3 ---
 1 file changed, 3 deletions(-)
block/qcow2-cache.c +0 -3
index ed92a09..53b8afc 100644
@@ -281,9 +281,6 @@ static int qcow2_cache_do_get(BlockDriverState *bs, Qcow2Cache *c,
     i = min_lru_index;
     trace_qcow2_cache_get_replace_entry(qemu_coroutine_self(),
                                         c == s->l2_table_cache, i);
-    if (i < 0) {
-        return i;
-    }
 
     ret = qcow2_cache_entry_flush(bs, c, i);
     if (ret < 0) {
Signature · 1 line
2.4.3
#2 lore raw

[Qemu-devel] [PULL for-2.4 2/7] block: update bdrv_drain_all()/bdrv_drain() comments

In reply to Stefan Hajnoczi

The doc comments for bdrv_drain_all() and bdrv_drain() are outdated:

* The bdrv_drain() comment is a poor man's bdrv_lock()/bdrv_unlock() which Fam Zheng is currently developing. Unfortunately this warning was never really enough because devices keep submitting I/O and op blockers don't prevent that.

* The bdrv_drain_all() comment is still partially correct but reflects the nature of the implementation rather than API documentation.

Do make it clear that bdrv_drain() is only appropriate within an AioContext. For anything spanning AioContexts you need bdrv_drain_all().

Message-id: [email protected]

---
 block/io.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)
block/io.c +10 -10
index 305e0d9..d4bc83b 100644
@@ -236,12 +236,12 @@ static bool bdrv_requests_pending(BlockDriverState *bs)
 /*
  * Wait for pending requests to complete on a single BlockDriverState subtree
  *
- * See the warning in bdrv_drain_all().  This function can only be called if
- * you are sure nothing can generate I/O because you have op blockers
- * installed.
- *
  * Note that unlike bdrv_drain_all(), the caller must hold the BlockDriverState
  * AioContext.
+ *
+ * Only this BlockDriverState's AioContext is run, so in-flight requests must
+ * not depend on events in other AioContexts.  In that case, use
+ * bdrv_drain_all() instead.
  */
 void bdrv_drain(BlockDriverState *bs)
 {
@@ -260,12 +260,6 @@ void bdrv_drain(BlockDriverState *bs)
  *
  * This function does not flush data to disk, use bdrv_flush_all() for that
  * after calling this function.
- *
- * Note that completion of an asynchronous I/O operation can trigger any
- * number of other I/O operations on other devices---for example a coroutine
- * can be arbitrarily complex and a constant flow of I/O can come until the
- * coroutine is complete.  Because of this, it is not possible to have a
- * function to drain a single device's I/O queue.
  */
 void bdrv_drain_all(void)
 {
@@ -288,6 +282,12 @@ void bdrv_drain_all(void)
         }
     }
 
+    /* Note that completion of an asynchronous I/O operation can trigger any
+     * number of other I/O operations on other devices---for example a
+     * coroutine can submit an I/O request to another device in response to
+     * request completion.  Therefore we must keep looping until there was no
+     * more activity rather than simply draining each device independently.
+     */
     while (busy) {
         busy = false;
 
Signature · 1 line
2.4.3
#3 lore raw

[Qemu-devel] [PULL for-2.4 3/7] block/nfs: add support for setting debug level

In reply to Stefan Hajnoczi

From: Peter Lieven <[email protected]>

upcoming libnfs versions will support logging debug messages. Add support for it in qemu through a per-drive option.

Examples:
qemu -drive if=virtio,file=nfs://...,file.debug=2 qemu-img create -o debug=2 nfs://... 10G

Message-id: [email protected]

---
 block/nfs.c          | 28 ++++++++++++++++++++++++----
 qapi/block-core.json | 20 ++++++++++++++++----
 2 files changed, 40 insertions(+), 8 deletions(-)
block/nfs.c +24 -4
index c026ff6..72a4247 100644
@@ -233,6 +233,11 @@ static QemuOptsList runtime_opts = {
             .type = QEMU_OPT_STRING,
             .help = "URL to the NFS file",
         },
+        {
+            .name = "debug",
+            .type = QEMU_OPT_NUMBER,
+            .help = "Set libnfs debug level (default 0 = no debug)",
+        },
         { /* end of list */ }
     },
 };
@@ -277,9 +282,9 @@ static void nfs_file_close(BlockDriverState *bs)
 }
 
 static int64_t nfs_client_open(NFSClient *client, const char *filename,
-                               int flags, Error **errp)
+                               int flags, QemuOpts *opts, Error **errp)
 {
-    int ret = -EINVAL, i;
+    int ret = -EINVAL, i, debug;
     struct stat st;
     URI *uri;
     QueryParams *qp = NULL;
@@ -343,6 +348,16 @@ static int64_t nfs_client_open(NFSClient *client, const char *filename,
         }
     }
 
+    debug = qemu_opt_get_number(opts, "debug", 0);
+    if (debug) {
+#ifdef LIBNFS_FEATURE_DEBUG
+        nfs_set_debug(client->context, debug);
+#else
+        error_report("NFS Warning: The linked version of libnfs does"
+                     " not support setting debug levels");
+#endif
+    }
+
     ret = nfs_mount(client->context, uri->server, uri->path);
     if (ret < 0) {
         error_setg(errp, "Failed to mount nfs share: %s",
@@ -405,7 +420,7 @@ static int nfs_file_open(BlockDriverState *bs, QDict *options, int flags,
     }
     ret = nfs_client_open(client, qemu_opt_get(opts, "filename"),
                           (flags & BDRV_O_RDWR) ? O_RDWR : O_RDONLY,
-                          errp);
+                          opts, errp);
     if (ret < 0) {
         goto out;
     }
@@ -425,6 +440,11 @@ static QemuOptsList nfs_create_opts = {
             .type = QEMU_OPT_SIZE,
             .help = "Virtual disk size"
         },
+        {
+            .name = "debug",
+            .type = QEMU_OPT_NUMBER,
+            .help = "Set libnfs debug level (default 0 = no debug)",
+        },
         { /* end of list */ }
     }
 };
@@ -441,7 +461,7 @@ static int nfs_file_create(const char *url, QemuOpts *opts, Error **errp)
     total_size = ROUND_UP(qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0),
                           BDRV_SECTOR_SIZE);
 
-    ret = nfs_client_open(client, url, O_CREAT, errp);
+    ret = nfs_client_open(client, url, O_CREAT, opts, errp);
     if (ret < 0) {
         goto out;
     }
qapi/block-core.json +16 -4
index 7b2efb8..f43a1b1 100644
@@ -1381,9 +1381,9 @@
 { 'enum': 'BlockdevDriver',
   'data': [ 'archipelago', 'blkdebug', 'blkverify', 'bochs', 'cloop',
             'dmg', 'file', 'ftp', 'ftps', 'host_cdrom', 'host_device',
-            'host_floppy', 'http', 'https', 'null-aio', 'null-co', 'parallels',
-            'qcow', 'qcow2', 'qed', 'quorum', 'raw', 'tftp', 'vdi', 'vhdx',
-            'vmdk', 'vpc', 'vvfat' ] }
+            'host_floppy', 'http', 'https', 'nfs', 'null-aio', 'null-co',
+            'parallels', 'qcow', 'qcow2', 'qed', 'quorum', 'raw', 'tftp',
+            'vdi', 'vhdx', 'vmdk', 'vpc', 'vvfat' ] }
 
 ##
 # @BlockdevOptionsBase
@@ -1635,6 +1635,18 @@
             '*vport': 'int',
             '*segment': 'str' } }
 
+##
+# @BlockdevOptionsNFS
+#
+# Driver specific block device options for NFS.
+#
+# @debug:       #optional set libnfs debug level (default: 0 = disabled)
+#
+# Since: 2.4
+##
+{ 'struct': 'BlockdevOptionsNFS',
+  'base': 'BlockdevOptionsFile',
+  'data': { '*debug': 'int' } }
 
 ##
 # @BlkdebugEvent
@@ -1816,7 +1828,7 @@
       'https':      'BlockdevOptionsFile',
 # TODO iscsi: Wait for structured options
 # TODO nbd: Should take InetSocketAddress for 'host'?
-# TODO nfs: Wait for structured options
+      'nfs':        'BlockdevOptionsNFS',
       'null-aio':   'BlockdevOptionsNull',
       'null-co':    'BlockdevOptionsNull',
       'parallels':  'BlockdevOptionsGenericFormat',
Signature · 1 line
2.4.3
#4 lore raw

Re: [Qemu-devel] [PULL for-2.4 3/7] block/nfs: add support for setting debug level

Am 07.07.2015 um 14:08 schrieb Stefan Hajnoczi:

Quoted 5 lines

From: Peter Lieven <[email protected]>

upcoming libnfs versions will support logging debug messages. Add support for it in qemu through a per-drive option.

Quoted 8 lines

Examples:
qemu -drive if=virtio,file=nfs://...,file.debug=2 qemu-img create -o debug=2 nfs://... 10G

Message-id: [email protected]

Thanks for pulling this.

Question: Is it possible to insert a CDROM other than with the 'change' command? The change command obviously does not support file.debug parameters...

Peter

#5 lore raw

Re: [Qemu-devel] [PULL for-2.4 3/7] block/nfs: add support for setting debug level

Quoted 17 lines · Peter Lieven

Am 07.07.2015 um 14:08 schrieb Stefan Hajnoczi:

Quoted 6 lines

From: Peter Lieven <[email protected]>

upcoming libnfs versions will support logging debug messages. Add support for it in qemu through a per-drive option.

Quoted 8 lines

Examples:
qemu -drive if=virtio,file=nfs://...,file.debug=2 qemu-img create -o debug=2 nfs://... 10G

Message-id: [email protected]

Quoted 5 lines

Thanks for pulling this.

Question: Is it possible to insert a CDROM other than with the 'change' command?
The change command obviously does not support file.debug parameters...

Not that I'm aware of.

You may be able to hotplug SCSI CD-ROM drives, but that's not the same as ejecting/inserting CD-ROM media.

Sounds like an item for the block layer todo list:
http://qemu-project.org/Features/Block/Todo

Stefan

#6 lore raw

Re: [Qemu-devel] [PULL for-2.4 3/7] block/nfs: add support for setting debug level

Am 07.07.2015 um 15:13 hat Stefan Hajnoczi geschrieben:

Quoted 24 lines · Peter Lieven
Quoted 17 lines

Am 07.07.2015 um 14:08 schrieb Stefan Hajnoczi:

Quoted 6 lines

From: Peter Lieven <[email protected]>

upcoming libnfs versions will support logging debug messages. Add support for it in qemu through a per-drive option.

Quoted 8 lines

Examples:
qemu -drive if=virtio,file=nfs://...,file.debug=2 qemu-img create -o debug=2 nfs://... 10G

Message-id: [email protected]

Quoted 5 lines

Thanks for pulling this.

Question: Is it possible to insert a CDROM other than with the 'change' command?
The change command obviously does not support file.debug parameters...

Quoted 7 lines

Not that I'm aware of.

You may be able to hotplug SCSI CD-ROM drives, but that's not the same as ejecting/inserting CD-ROM media.

Sounds like an item for the block layer todo list:
http://qemu-project.org/Features/Block/Todo

I think Max' media handling series might implement this or at least go a step in that direction. CCing Max.

Kevin

#7 lore raw

Re: [Qemu-devel] [PULL for-2.4 3/7] block/nfs: add support for setting debug level

Quoted 27 lines · Kevin Wolf

Am 07.07.2015 um 15:13 hat Stefan Hajnoczi geschrieben:

Quoted 26 lines · Peter Lieven
Quoted 17 lines

Am 07.07.2015 um 14:08 schrieb Stefan Hajnoczi:

Quoted 6 lines

From: Peter Lieven <[email protected]>

upcoming libnfs versions will support logging debug messages. Add support for it in qemu through a per-drive option.

Quoted 8 lines

Examples:

   qemu -drive if=virtio,file=nfs://...,file.debug=2
   qemu-img create -o debug=2 nfs://... 10G

Message-id: [email protected]

Quoted 5 lines

Thanks for pulling this.

Question: Is it possible to insert a CDROM other than with the 'change' command?
The change command obviously does not support file.debug parameters...

Not that I'm aware of.

Quoted 8 lines
Quoted 5 lines

You may be able to hotplug SCSI CD-ROM drives, but that's not the same as ejecting/inserting CD-ROM media.

Sounds like an item for the block layer todo list:
http://qemu-project.org/Features/Block/Todo

I think Max' media handling series might implement this or at least go a step in that direction. CCing Max.

Since with that series, you can insert any BDS as a medium, yes, it naturally does.

But for now, wouldn't JSON file names work?

Max

#8 lore raw

Re: [Qemu-devel] [PULL for-2.4 3/7] block/nfs: add support for setting debug level

In reply to Stefan Hajnoczi
Quoted 9 lines · Stefan Hajnoczi

From: Peter Lieven <[email protected]>

upcoming libnfs versions will support logging debug messages. Add support for it in qemu through a per-drive option.

Examples:
qemu -drive if=virtio,file=nfs://...,file.debug=2 qemu-img create -o debug=2 nfs://... 10G

Quoted 8 lines

Message-id: [email protected]

---
 block/nfs.c          | 28 ++++++++++++++++++++++++----
 qapi/block-core.json | 20 ++++++++++++++++----
 2 files changed, 40 insertions(+), 8 deletions(-)

Kevin has pointed out at the QAPI portion of this patch isn't ready for prime time yet, so I will revert the patch and resend the pull request.

#9 lore raw

Re: [Qemu-devel] [PULL for-2.4 3/7] block/nfs: add support for setting debug level

Am 07.07.2015 um 15:24 schrieb Stefan Hajnoczi:

Quoted 18 lines · Stefan Hajnoczi
Quoted 9 lines

From: Peter Lieven <[email protected]>

upcoming libnfs versions will support logging debug messages. Add support for it in qemu through a per-drive option.

Examples:
qemu -drive if=virtio,file=nfs://...,file.debug=2 qemu-img create -o debug=2 nfs://... 10G

Quoted 8 lines

Message-id: [email protected]

---
  block/nfs.c          | 28 ++++++++++++++++++++++++----
  qapi/block-core.json | 20 ++++++++++++++++----
  2 files changed, 40 insertions(+), 8 deletions(-)
Quoted 3 lines

Kevin has pointed out at the QAPI portion of this patch isn't ready for prime time yet, so I will revert the patch and resend the pull request.

Yes please, I was not aware that adding the QAPI part has such an impact. I would appreciate if someone who has more experience with the QAPI stuff would look at this and make a proposal how to handle the NFS (and also the iSCSI) case. I'm happy to look at the implementation then.

Peter

#10 lore raw

Re: [Qemu-devel] [PULL for-2.4 3/7] block/nfs: add support for setting debug level

Am 07.07.2015 um 15:41 hat Peter Lieven geschrieben:

Quoted 23 lines

Am 07.07.2015 um 15:24 schrieb Stefan Hajnoczi:

Quoted 18 lines · Stefan Hajnoczi
Quoted 9 lines

From: Peter Lieven <[email protected]>

upcoming libnfs versions will support logging debug messages. Add support for it in qemu through a per-drive option.

Examples:
qemu -drive if=virtio,file=nfs://...,file.debug=2 qemu-img create -o debug=2 nfs://... 10G

Quoted 8 lines

Message-id: [email protected]

---
 block/nfs.c          | 28 ++++++++++++++++++++++++----
 qapi/block-core.json | 20 ++++++++++++++++----
 2 files changed, 40 insertions(+), 8 deletions(-)
Quoted 3 lines

Kevin has pointed out at the QAPI portion of this patch isn't ready for prime time yet, so I will revert the patch and resend the pull request.

Quoted 5 lines

Yes please, I was not aware that adding the QAPI part has such an impact. I would appreciate if someone who has more experience with the QAPI stuff would look at this and make a proposal how to handle the NFS (and also the iSCSI) case. I'm happy to look at the implementation then.

We should definitely come to a conclusion on this for 2.5. The same problem doesn't only apply for NFS, but for all network protocols, and this is one of the major reasons why blockdev-add isn't ready yet.

We'll need Eric for this discussion, though, and he'll only return from vacation next Monday.

Kevin

#11 lore raw

Re: [Qemu-devel] [PULL for-2.4 3/7] block/nfs: add support for setting debug level

Quoted 10 lines · Kevin Wolf
Quoted 9 lines
Quoted 3 lines

Kevin has pointed out at the QAPI portion of this patch isn't ready for prime time yet, so I will revert the patch and resend the pull request.

Yes please, I was not aware that adding the QAPI part has such an impact. I would appreciate if someone who has more experience with the QAPI stuff would look at this and make a proposal how to handle the NFS (and also the iSCSI) case. I'm happy to look at the implementation then.

Quoted 6 lines

We should definitely come to a conclusion on this for 2.5. The same problem doesn't only apply for NFS, but for all network protocols, and this is one of the major reasons why blockdev-add isn't ready yet.

We'll need Eric for this discussion, though, and he'll only return from vacation next Monday.

I'm back now (obviously), but we should probably discuss in a separate thread rather than dangling off this pull request ;)

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#12 lore raw

Re: [Qemu-devel] [PULL for-2.4 3/7] block/nfs: add support for setting debug level

In reply to Stefan Hajnoczi
Quoted 21 lines · Stefan Hajnoczi

From: Peter Lieven <[email protected]>

upcoming libnfs versions will support logging debug messages. Add support for it in qemu through a per-drive option.

Examples:
qemu -drive if=virtio,file=nfs://...,file.debug=2 qemu-img create -o debug=2 nfs://... 10G

Message-id: [email protected]

---
 block/nfs.c          | 28 ++++++++++++++++++++++++----
 qapi/block-core.json | 20 ++++++++++++++++----
 2 files changed, 40 insertions(+), 8 deletions(-)

+++ b/qapi/block-core.json

qapi/block-core.json line 1386

Quoted 9 lines
qapi/block-core.json +3 -3
@@ -1381,9 +1381,9 @@
 { 'enum': 'BlockdevDriver',
   'data': [ 'archipelago', 'blkdebug', 'blkverify', 'bochs', 'cloop',
             'dmg', 'file', 'ftp', 'ftps', 'host_cdrom', 'host_device',
-            'host_floppy', 'http', 'https', 'null-aio', 'null-co', 'parallels',
-            'qcow', 'qcow2', 'qed', 'quorum', 'raw', 'tftp', 'vdi', 'vhdx',
-            'vmdk', 'vpc', 'vvfat' ] }
+            'host_floppy', 'http', 'https', 'nfs', 'null-aio', 'null-co',
+            'parallels', 'qcow', 'qcow2', 'qed', 'quorum', 'raw', 'tftp',
+            'vdi', 'vhdx', 'vmdk', 'vpc', 'vvfat' ] }

Probably also ought to document the docs for BlockDeviceInfo.drv, to mention that 'nfs' was added in 2.4.

[may be moot for now, since this patch was dropped when the pull request was resent; or even mean you want "2.5" when you DO add and document it]

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#13 lore raw

[Qemu-devel] [PULL for-2.4 4/7] block: Initialize local_err in bdrv_append_temp_snapshot

In reply to Stefan Hajnoczi

From: Fam Zheng <[email protected]>

Message-id: [email protected]

---
 block.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
block.c +1 -1
index 7e130cc..42eb8e3 100644
@@ -1271,7 +1271,7 @@ int bdrv_append_temp_snapshot(BlockDriverState *bs, int flags, Error **errp)
     QemuOpts *opts = NULL;
     QDict *snapshot_options;
     BlockDriverState *bs_snapshot;
-    Error *local_err;
+    Error *local_err = NULL;
     int ret;
 
     /* if snapshot, we create a temporary backing file and open it
Signature · 1 line
2.4.3
#14 lore raw

[Qemu-devel] [PULL for-2.4 5/7] block: Use bdrv_drain to replace uncessary bdrv_drain_all

In reply to Stefan Hajnoczi

From: Fam Zheng <[email protected]>

There callers work on a single BlockDriverState subtree, where using bdrv_drain() is more accurate.

---
 block.c           | 6 +++---
 block/snapshot.c  | 2 +-
 migration/block.c | 2 +-
 3 files changed, 5 insertions(+), 5 deletions(-)
block.c +3 -3
index 42eb8e3..5e80336 100644
@@ -1841,9 +1841,9 @@ void bdrv_close(BlockDriverState *bs)
     if (bs->job) {
         block_job_cancel_sync(bs->job);
     }
-    bdrv_drain_all(); /* complete I/O */
+    bdrv_drain(bs); /* complete I/O */
     bdrv_flush(bs);
-    bdrv_drain_all(); /* in case flush left pending I/O */
+    bdrv_drain(bs); /* in case flush left pending I/O */
     notifier_list_notify(&bs->close_notifiers, bs);
 
     if (bs->drv) {
@@ -3906,7 +3906,7 @@ void bdrv_attach_aio_context(BlockDriverState *bs,
 
 void bdrv_set_aio_context(BlockDriverState *bs, AioContext *new_context)
 {
-    bdrv_drain_all(); /* ensure there are no in-flight requests */
+    bdrv_drain(bs); /* ensure there are no in-flight requests */
 
     bdrv_detach_aio_context(bs);
 
block/snapshot.c +1 -1
index 19395ae..49e143e 100644
@@ -239,7 +239,7 @@ int bdrv_snapshot_delete(BlockDriverState *bs,
     }
 
     /* drain all pending i/o before deleting snapshot */
-    bdrv_drain_all();
+    bdrv_drain(bs);
 
     if (drv->bdrv_snapshot_delete) {
         return drv->bdrv_snapshot_delete(bs, snapshot_id, name, errp);
migration/block.c +1 -1
index ddb59cc..ed865ed 100644
@@ -457,7 +457,7 @@ static int mig_save_device_dirty(QEMUFile *f, BlkMigDevState *bmds,
         blk_mig_lock();
         if (bmds_aio_inflight(bmds, sector)) {
             blk_mig_unlock();
-            bdrv_drain_all();
+            bdrv_drain(bmds->bs);
         } else {
             blk_mig_unlock();
         }
Signature · 1 line
2.4.3
#15 lore raw

[Qemu-devel] [PULL for-2.4 7/7] blockjob: add block_job_release function

In reply to Stefan Hajnoczi

From: Ting Wang <[email protected]>

There is job resource leak in function mirror_start_job, although bdrv_create_dirty_bitmap is unlikely failed. Add block_job_release for each release when needed.

Message-id: [email protected]

---
 block/mirror.c           |  2 ++
 blockjob.c               | 20 ++++++++++++--------
 include/block/blockjob.h |  8 ++++++++
 3 files changed, 22 insertions(+), 8 deletions(-)
block/mirror.c +2 -0
index 8888cea..d409337 100644
@@ -708,6 +708,8 @@ static void mirror_start_job(BlockDriverState *bs, BlockDriverState *target,
 
     s->dirty_bitmap = bdrv_create_dirty_bitmap(bs, granularity, NULL, errp);
     if (!s->dirty_bitmap) {
+        g_free(s->replaces);
+        block_job_release(bs);
         return;
     }
     bdrv_set_enable_write_cache(s->target, true);
blockjob.c +12 -8
index ec46fad..62bb906 100644
@@ -66,10 +66,7 @@ void *block_job_create(const BlockJobDriver *driver, BlockDriverState *bs,
 
         block_job_set_speed(job, speed, &local_err);
         if (local_err) {
-            bs->job = NULL;
-            bdrv_op_unblock_all(bs, job->blocker);
-            error_free(job->blocker);
-            g_free(job);
+            block_job_release(bs);
             error_propagate(errp, local_err);
             return NULL;
         }
@@ -77,18 +74,25 @@ void *block_job_create(const BlockJobDriver *driver, BlockDriverState *bs,
     return job;
 }
 
-void block_job_completed(BlockJob *job, int ret)
+void block_job_release(BlockDriverState *bs)
 {
-    BlockDriverState *bs = job->bs;
+    BlockJob *job = bs->job;
 
-    assert(bs->job == job);
-    job->cb(job->opaque, ret);
     bs->job = NULL;
     bdrv_op_unblock_all(bs, job->blocker);
     error_free(job->blocker);
     g_free(job);
 }
 
+void block_job_completed(BlockJob *job, int ret)
+{
+    BlockDriverState *bs = job->bs;
+
+    assert(bs->job == job);
+    job->cb(job->opaque, ret);
+    block_job_release(bs);
+}
+
 void block_job_set_speed(BlockJob *job, int64_t speed, Error **errp)
 {
     Error *local_err = NULL;
include/block/blockjob.h +8 -0
index 57d8ef1..dd9d5e6 100644
@@ -166,6 +166,14 @@ void block_job_sleep_ns(BlockJob *job, QEMUClockType type, int64_t ns);
 void block_job_yield(BlockJob *job);
 
 /**
+ * block_job_release:
+ * @bs: The block device.
+ *
+ * Release job resources when an error occurred or job completed.
+ */
+void block_job_release(BlockDriverState *bs);
+
+/**
  * block_job_completed:
  * @job: The job being completed.
  * @ret: The status code.
Signature · 1 line
2.4.3
#16 lore raw

[Qemu-devel] [PULL for-2.4 6/7] block/raw-posix: Don't think /dev/fd/<NN> is a floppy drive.

In reply to Stefan Hajnoczi

From: "Richard W.M. Jones" <[email protected]>

In libguestfs we use /dev/fd/<NN> to pass pre-opened file descriptors to qemu-img. Lately I've discovered that although this works, qemu believes that these are floppy disk images. That in itself isn't much of a problem, but now qemu prints a warning about host floppy pass-thru being deprecated.

Extend the existing test so that it ignores /dev/fd/ as well as /dev/fdset/

A simple test of this, if you are using the bash shell, is:

qemu-img info <( cat /dev/null )

without this patch:

  $ qemu-img info <( cat /dev/null )
  qemu-img: Host floppy pass-through is deprecated
  Support for it will be removed in a future release.
  qemu-img: Could not open '/dev/fd/63': Could not refresh total sector count: Illegal seek

with this patch:

  $ qemu-img info <( cat /dev/null )
  qemu-img: Could not open '/dev/fd/63': Could not refresh total sector count: Illegal seek

Message-id: [email protected]

---
 block/raw-posix.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
block/raw-posix.c +2 -1
index cbe6574..855febe 100644
@@ -2430,7 +2430,8 @@ static int floppy_probe_device(const char *filename)
     struct stat st;
 
     if (strstart(filename, "/dev/fd", NULL) &&
-        !strstart(filename, "/dev/fdset/", NULL)) {
+        !strstart(filename, "/dev/fdset/", NULL) &&
+        !strstart(filename, "/dev/fd/", NULL)) {
         prio = 50;
     }
 
Signature · 1 line
2.4.3