[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Libguestfs] [PATCH libnbd 1/2] examples: copy-libev: Simplify start_extents()



When extents request is in progress, starting a request put it to sleep.
Move this logic to start_request(), so start_extents() is used only when
actually starting an extents request.

Signed-off-by: Nir Soffer <nsoffer redhat com>
---
 examples/copy-libev.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/examples/copy-libev.c b/examples/copy-libev.c
index 502b177..e988cd9 100644
--- a/examples/copy-libev.c
+++ b/examples/copy-libev.c
@@ -252,12 +252,6 @@ start_extents (struct request *r)
     size_t count = MIN (EXTENTS_SIZE, size - offset);
     int64_t cookie;
 
-    if (extents_in_progress) {
-        /* Sleep until extents request completes. */
-        r->state = SLEEP;
-        return true;
-    }
-
     DEBUG ("r%zu: start extents offset=%" PRIi64 " count=%zu",
            r->index, offset, count);
 
@@ -374,8 +368,15 @@ start_request(struct request *r)
     r->started = ev_now (loop);
 
     /* If needed, get more extents from server. */
-    if (src.can_extents && extents == NULL && start_extents (r))
-        return;
+    if (src.can_extents && extents == NULL) {
+        if (extents_in_progress) {
+            r->state = SLEEP;
+            return;
+        }
+
+        if (start_extents (r))
+            return;
+    }
 
     if (src.can_extents) {
         /* Handle the next extent. */
-- 
2.26.3


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]