qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Kevin Wolf <kwolf@redhat.com>
To: anthony@codemonkey.ws
Cc: kwolf@redhat.com, qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH 12/32] monitor: Allow add-fd to any specified fd set
Date: Wed, 24 Oct 2012 11:50:36 +0200	[thread overview]
Message-ID: <1351072256-6112-13-git-send-email-kwolf@redhat.com> (raw)
In-Reply-To: <1351072256-6112-1-git-send-email-kwolf@redhat.com>

From: Corey Bryant <coreyb@linux.vnet.ibm.com>

The first call to add an fd to an fd set was previously not
allowed to choose the fd set ID.  The ID was generated as
the first available and ensuing calls could add more fds by
specifying the fd set ID.  This change allows users to
choose the fd set ID on the first call.

Signed-off-by: Corey Bryant <coreyb@linux.vnet.ibm.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 monitor.c        |   54 +++++++++++++++++++++++++++++++++++++-----------------
 qapi-schema.json |    2 +-
 2 files changed, 38 insertions(+), 18 deletions(-)

diff --git a/monitor.c b/monitor.c
index d17ae2d..3519b39 100644
--- a/monitor.c
+++ b/monitor.c
@@ -2135,7 +2135,7 @@ AddfdInfo *qmp_add_fd(bool has_fdset_id, int64_t fdset_id, bool has_opaque,
 {
     int fd;
     Monitor *mon = cur_mon;
-    MonFdset *mon_fdset;
+    MonFdset *mon_fdset = NULL;
     MonFdsetFd *mon_fdset_fd;
     AddfdInfo *fdinfo;
 
@@ -2147,34 +2147,54 @@ AddfdInfo *qmp_add_fd(bool has_fdset_id, int64_t fdset_id, bool has_opaque,
 
     if (has_fdset_id) {
         QLIST_FOREACH(mon_fdset, &mon_fdsets, next) {
-            if (mon_fdset->id == fdset_id) {
+            /* Break if match found or match impossible due to ordering by ID */
+            if (fdset_id <= mon_fdset->id) {
+                if (fdset_id < mon_fdset->id) {
+                    mon_fdset = NULL;
+                }
                 break;
             }
         }
-        if (mon_fdset == NULL) {
-            error_set(errp, QERR_INVALID_PARAMETER_VALUE, "fdset-id",
-                      "an existing fdset-id");
-            goto error;
-        }
-    } else {
+    }
+
+    if (mon_fdset == NULL) {
         int64_t fdset_id_prev = -1;
         MonFdset *mon_fdset_cur = QLIST_FIRST(&mon_fdsets);
 
-        /* Use first available fdset ID */
-        QLIST_FOREACH(mon_fdset, &mon_fdsets, next) {
-            mon_fdset_cur = mon_fdset;
-            if (fdset_id_prev == mon_fdset_cur->id - 1) {
-                fdset_id_prev = mon_fdset_cur->id;
-                continue;
+        if (has_fdset_id) {
+            if (fdset_id < 0) {
+                error_set(errp, QERR_INVALID_PARAMETER_VALUE, "fdset-id",
+                          "a non-negative value");
+                goto error;
+            }
+            /* Use specified fdset ID */
+            QLIST_FOREACH(mon_fdset, &mon_fdsets, next) {
+                mon_fdset_cur = mon_fdset;
+                if (fdset_id < mon_fdset_cur->id) {
+                    break;
+                }
+            }
+        } else {
+            /* Use first available fdset ID */
+            QLIST_FOREACH(mon_fdset, &mon_fdsets, next) {
+                mon_fdset_cur = mon_fdset;
+                if (fdset_id_prev == mon_fdset_cur->id - 1) {
+                    fdset_id_prev = mon_fdset_cur->id;
+                    continue;
+                }
+                break;
             }
-            break;
         }
 
         mon_fdset = g_malloc0(sizeof(*mon_fdset));
-        mon_fdset->id = fdset_id_prev + 1;
+        if (has_fdset_id) {
+            mon_fdset->id = fdset_id;
+        } else {
+            mon_fdset->id = fdset_id_prev + 1;
+        }
 
         /* The fdset list is ordered by fdset ID */
-        if (mon_fdset->id == 0) {
+        if (!mon_fdset_cur) {
             QLIST_INSERT_HEAD(&mon_fdsets, mon_fdset, next);
         } else if (mon_fdset->id < mon_fdset_cur->id) {
             QLIST_INSERT_BEFORE(mon_fdset_cur, mon_fdset, next);
diff --git a/qapi-schema.json b/qapi-schema.json
index c615ee2..36278cc 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -2625,7 +2625,7 @@
 #
 # Returns: @AddfdInfo on success
 #          If file descriptor was not received, FdNotSupplied
-#          If @fdset-id does not exist, InvalidParameterValue
+#          If @fdset-id is a negative value, InvalidParameterValue
 #
 # Notes: The list of fd sets is shared by all monitor connections.
 #
-- 
1.7.6.5

  parent reply	other threads:[~2012-10-24  9:51 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-24  9:50 [Qemu-devel] [PULL 00/32] Block patches Kevin Wolf
2012-10-24  9:50 ` [Qemu-devel] [PATCH 01/32] qemu-img: Fix division by zero for zero size images Kevin Wolf
2012-10-24  9:50 ` [Qemu-devel] [PATCH 02/32] qemu-iotests: Test qemu-img operation on zero size image Kevin Wolf
2012-10-24  9:50 ` [Qemu-devel] [PATCH 03/32] qmp: fix __accept() in qmp.py Kevin Wolf
2012-10-24  9:50 ` [Qemu-devel] [PATCH 04/32] qemu-img rebase: use empty string to rebase without backing file Kevin Wolf
2012-10-24  9:50 ` [Qemu-devel] [PATCH 05/32] block: make bdrv_find_backing_image compare canonical filenames Kevin Wolf
2012-10-24  9:50 ` [Qemu-devel] [PATCH 06/32] block: in commit, determine base image from the top image Kevin Wolf
2012-10-24  9:50 ` [Qemu-devel] [PATCH 07/32] qemu-iotests: add relative backing file tests for block-commit (040) Kevin Wolf
2012-10-24  9:50 ` [Qemu-devel] [PATCH 08/32] qemu-img: Add --backing-chain option to info command Kevin Wolf
2012-10-24  9:50 ` [Qemu-devel] [PATCH 09/32] qemu-iotests: Add 043 backing file chain infinite loop test Kevin Wolf
2012-10-24  9:50 ` [Qemu-devel] [PATCH 10/32] qemu-img: document 'info --backing-chain' Kevin Wolf
2012-10-24  9:50 ` [Qemu-devel] [PATCH 11/32] block: bdrv_create(): don't leak cco.filename on error Kevin Wolf
2012-10-24  9:50 ` Kevin Wolf [this message]
2012-10-24  9:50 ` [Qemu-devel] [PATCH 13/32] monitor: Enable adding an inherited fd to an fd set Kevin Wolf
2012-10-24  9:50 ` [Qemu-devel] [PATCH 14/32] monitor: Prevent removing fd from set during init Kevin Wolf
2012-10-24  9:50 ` [Qemu-devel] [PATCH 15/32] qemu-config: Add new -add-fd command line option Kevin Wolf
2012-10-24  9:50 ` [Qemu-devel] [PATCH 16/32] block: add bdrv_query_info Kevin Wolf
2012-10-24  9:50 ` [Qemu-devel] [PATCH 17/32] block: add bdrv_query_stats Kevin Wolf
2012-10-24  9:50 ` [Qemu-devel] [PATCH 18/32] block: add bdrv_open_backing_file Kevin Wolf
2012-10-24  9:50 ` [Qemu-devel] [PATCH 19/32] block: introduce new dirty bitmap functionality Kevin Wolf
2012-10-24  9:50 ` [Qemu-devel] [PATCH 20/32] block: export dirty bitmap information in query-block Kevin Wolf
2012-10-24  9:50 ` [Qemu-devel] [PATCH 21/32] block: rename block_job_complete to block_job_completed Kevin Wolf
2012-10-24  9:50 ` [Qemu-devel] [PATCH 22/32] block: add block-job-complete Kevin Wolf
2012-10-24  9:50 ` [Qemu-devel] [PATCH 23/32] block: introduce BLOCK_JOB_READY event Kevin Wolf
2012-10-24  9:50 ` [Qemu-devel] [PATCH 24/32] mirror: introduce mirror job Kevin Wolf
2012-10-24  9:50 ` [Qemu-devel] [PATCH 25/32] qmp: add drive-mirror command Kevin Wolf
2012-10-24  9:50 ` [Qemu-devel] [PATCH 26/32] mirror: implement completion Kevin Wolf
2012-10-24  9:50 ` [Qemu-devel] [PATCH 27/32] qemu-iotests: add mirroring test case Kevin Wolf
2012-10-24  9:50 ` [Qemu-devel] [PATCH 28/32] iostatus: forward block_job_iostatus_reset to block job Kevin Wolf
2012-10-24  9:50 ` [Qemu-devel] [PATCH 29/32] mirror: add support for on-source-error/on-target-error Kevin Wolf
2012-10-24  9:50 ` [Qemu-devel] [PATCH 30/32] qmp: add pull_event function Kevin Wolf
2012-10-24  9:50 ` [Qemu-devel] [PATCH 31/32] qemu-iotests: add testcases for mirroring on-source-error/on-target-error Kevin Wolf
2012-10-24  9:50 ` [Qemu-devel] [PATCH 32/32] osdep: Less restrictive F_SEFL in qemu_dup_flags() Kevin Wolf
2012-10-29 19:24 ` [Qemu-devel] [PULL 00/32] Block patches Anthony Liguori

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1351072256-6112-13-git-send-email-kwolf@redhat.com \
    --to=kwolf@redhat.com \
    --cc=anthony@codemonkey.ws \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).