Skip to contentSkip to conversation

multifd: Remove some redundant code

PATCH Superseded Li Zhang 2 participants 7 messages Dec 17, 2021 – Jan 27, 2022

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Li Zhang

author
#0 lore raw

PATCH v2 1/1 multifd: Remove some redundant code

Clean up some unnecessary code

---
 migration/multifd.c | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)
migration/multifd.c +3 -9
index 3242f688e5..212be1ed04 100644
@@ -854,19 +854,16 @@ static void multifd_new_send_channel_async(QIOTask *task, gpointer opaque)
     Error *local_err = NULL;
 
     trace_multifd_new_send_channel_async(p->id);
-    if (qio_task_propagate_error(task, &local_err)) {
-        goto cleanup;
-    } else {
+    if (!qio_task_propagate_error(task, &local_err)) {
         p->c = QIO_CHANNEL(sioc);
         qio_channel_set_delay(p->c, false);
         p->running = true;
         if (!multifd_channel_connect(p, sioc, local_err)) {
-            goto cleanup;
+            multifd_new_send_channel_cleanup(p, sioc, local_err);
         }
         return;
     }
 
-cleanup:
     multifd_new_send_channel_cleanup(p, sioc, local_err);
 }
 
@@ -1078,10 +1075,7 @@ static void *multifd_recv_thread(void *opaque)
 
         ret = qio_channel_read_all_eof(p->c, (void *)p->packet,
                                        p->packet_len, &local_err);
-        if (ret == 0) {   /* EOF */
-            break;
-        }
-        if (ret == -1) {   /* Error */
+        if (ret == 0 || ret == -1) {   /* 0: EOF  -1: Error */
             break;
         }
 
Signature · 1 line
2.31.1
author
#1 lore raw

ping

Any comments?

Thanks
Li

Quoted 46 lines · Li Zhang

Clean up some unnecessary code

---
  migration/multifd.c | 12 +++---------
  1 file changed, 3 insertions(+), 9 deletions(-)
migration/multifd.c +3 -9
index 3242f688e5..212be1ed04 100644
@@ -854,19 +854,16 @@ static void multifd_new_send_channel_async(QIOTask *task, gpointer opaque)
      Error *local_err = NULL;
 
      trace_multifd_new_send_channel_async(p->id);
-    if (qio_task_propagate_error(task, &local_err)) {
-        goto cleanup;
-    } else {
+    if (!qio_task_propagate_error(task, &local_err)) {
          p->c = QIO_CHANNEL(sioc);
          qio_channel_set_delay(p->c, false);
          p->running = true;
          if (!multifd_channel_connect(p, sioc, local_err)) {
-            goto cleanup;
+            multifd_new_send_channel_cleanup(p, sioc, local_err);
          }
          return;
      }
 
-cleanup:
      multifd_new_send_channel_cleanup(p, sioc, local_err);
  }
 
@@ -1078,10 +1075,7 @@ static void *multifd_recv_thread(void *opaque)
 
          ret = qio_channel_read_all_eof(p->c, (void *)p->packet,
                                         p->packet_len, &local_err);
-        if (ret == 0) {   /* EOF */
-            break;
-        }
-        if (ret == -1) {   /* Error */
+        if (ret == 0 || ret == -1) {   /* 0: EOF  -1: Error */
              break;
          }
 
#2 lore raw
In reply to Li Zhang
Quoted 3 lines · Li Zhang

Clean up some unnecessary code

Hi

Quoted 20 lines
---
 migration/multifd.c | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)
migration/multifd.c +1 -3
index 3242f688e5..212be1ed04 100644
@@ -854,19 +854,16 @@ static void multifd_new_send_channel_async(QIOTask *task, gpointer opaque)
     Error *local_err = NULL;
 
     trace_multifd_new_send_channel_async(p->id);
-    if (qio_task_propagate_error(task, &local_err)) {
-        goto cleanup;
-    } else {
+    if (!qio_task_propagate_error(task, &local_err)) {
         p->c = QIO_CHANNEL(sioc);
         qio_channel_set_delay(p->c, false);
         p->running = true;
         if (!multifd_channel_connect(p, sioc, local_err)) {

migration/multifd.c static void multifd_new_send_channel_async(QIOTask *task, gpointer opaque) · line 869

Quoted 10 lines
migration/multifd.c +1 -2
-            goto cleanup;
+            multifd_new_send_channel_cleanup(p, sioc, local_err);
         }
         return;
     }
 
-cleanup:
     multifd_new_send_channel_cleanup(p, sioc, local_err);
 }
 

Once there, why are we duplicating the call to
multifd_new_send_channel_cleanup()

What about:

static void multifd_new_send_channel_async(QIOTask *task, gpointer opaque)

{
    MultiFDSendParams *p = opaque;
    QIOChannel *sioc = QIO_CHANNEL(qio_task_get_source(task));
    Error *local_err = NULL;

    trace_multifd_new_send_channel_async(p->id);
    if (!qio_task_propagate_error(task, &local_err)) {
        p->c = QIO_CHANNEL(sioc);
        qio_channel_set_delay(p->c, false);
        p->running = true;
        if (multifd_channel_connect(p, sioc, local_err)) {
            return;
        }
    }
    multifd_new_send_channel_cleanup(p, sioc, local_err);
}

What do you think?

Later, Juan.

migration/multifd.c static void *multifd_recv_thread(void *opaque) · line 1080

Quoted 11 lines
migration/multifd.c +1 -4
@@ -1078,10 +1075,7 @@ static void *multifd_recv_thread(void *opaque)
 
         ret = qio_channel_read_all_eof(p->c, (void *)p->packet,
                                        p->packet_len, &local_err);
-        if (ret == 0) {   /* EOF */
-            break;
-        }
-        if (ret == -1) {   /* Error */
+        if (ret == 0 || ret == -1) {   /* 0: EOF  -1: Error */
             break;
         }

This bit is ok.

author
#3 lore raw
Quoted 61 lines · Juan Quintela
Quoted 3 lines · Li Zhang

Clean up some unnecessary code

Hi

Quoted 20 lines
---
  migration/multifd.c | 12 +++---------
  1 file changed, 3 insertions(+), 9 deletions(-)
migration/multifd.c +1 -3
index 3242f688e5..212be1ed04 100644
@@ -854,19 +854,16 @@ static void multifd_new_send_channel_async(QIOTask *task, gpointer opaque)
      Error *local_err = NULL;
 
      trace_multifd_new_send_channel_async(p->id);
-    if (qio_task_propagate_error(task, &local_err)) {
-        goto cleanup;
-    } else {
+    if (!qio_task_propagate_error(task, &local_err)) {
          p->c = QIO_CHANNEL(sioc);
          qio_channel_set_delay(p->c, false);
          p->running = true;
          if (!multifd_channel_connect(p, sioc, local_err)) {

migration/multifd.c static void multifd_new_send_channel_async(QIOTask *task, gpointer opaque) · line 869

Quoted 10 lines
migration/multifd.c +1 -2
-            goto cleanup;
+            multifd_new_send_channel_cleanup(p, sioc, local_err);
          }
          return;
      }
 
-cleanup:
      multifd_new_send_channel_cleanup(p, sioc, local_err);
  }
 

Once there, why are we duplicating the call to
multifd_new_send_channel_cleanup()

What about:

static void multifd_new_send_channel_async(QIOTask *task, gpointer opaque)

{
     MultiFDSendParams *p = opaque;
     QIOChannel *sioc = QIO_CHANNEL(qio_task_get_source(task));
     Error *local_err = NULL;

     trace_multifd_new_send_channel_async(p->id);
     if (!qio_task_propagate_error(task, &local_err)) {
         p->c = QIO_CHANNEL(sioc);
         qio_channel_set_delay(p->c, false);
         p->running = true;
         if (multifd_channel_connect(p, sioc, local_err)) {
             return;
         }
     }
     multifd_new_send_channel_cleanup(p, sioc, local_err);
}
Quoted 1 line

What do you think?

Ah, this is better. thanks. :)

Quoted 18 lines

Later, Juan.

migration/multifd.c static void *multifd_recv_thread(void *opaque) · line 1080

Quoted 11 lines
migration/multifd.c +1 -4
@@ -1078,10 +1075,7 @@ static void *multifd_recv_thread(void *opaque)
 
          ret = qio_channel_read_all_eof(p->c, (void *)p->packet,
                                         p->packet_len, &local_err);
-        if (ret == 0) {   /* EOF */
-            break;
-        }
-        if (ret == -1) {   /* Error */
+        if (ret == 0 || ret == -1) {   /* 0: EOF  -1: Error */
              break;
          }

This bit is ok.

author
#4 lore raw
In reply to Juan Quintela
Quoted 61 lines · Juan Quintela
Quoted 3 lines · Li Zhang

Clean up some unnecessary code

Hi

Quoted 20 lines
---
  migration/multifd.c | 12 +++---------
  1 file changed, 3 insertions(+), 9 deletions(-)
migration/multifd.c +1 -3
index 3242f688e5..212be1ed04 100644
@@ -854,19 +854,16 @@ static void multifd_new_send_channel_async(QIOTask *task, gpointer opaque)
      Error *local_err = NULL;
 
      trace_multifd_new_send_channel_async(p->id);
-    if (qio_task_propagate_error(task, &local_err)) {
-        goto cleanup;
-    } else {
+    if (!qio_task_propagate_error(task, &local_err)) {
          p->c = QIO_CHANNEL(sioc);
          qio_channel_set_delay(p->c, false);
          p->running = true;
          if (!multifd_channel_connect(p, sioc, local_err)) {

migration/multifd.c static void multifd_new_send_channel_async(QIOTask *task, gpointer opaque) · line 869

Quoted 10 lines
migration/multifd.c +1 -2
-            goto cleanup;
+            multifd_new_send_channel_cleanup(p, sioc, local_err);
          }
          return;
      }
 
-cleanup:
      multifd_new_send_channel_cleanup(p, sioc, local_err);
  }
 

Once there, why are we duplicating the call to
multifd_new_send_channel_cleanup()

What about:

static void multifd_new_send_channel_async(QIOTask *task, gpointer opaque)

{
     MultiFDSendParams *p = opaque;
     QIOChannel *sioc = QIO_CHANNEL(qio_task_get_source(task));
     Error *local_err = NULL;

     trace_multifd_new_send_channel_async(p->id);
     if (!qio_task_propagate_error(task, &local_err)) {
         p->c = QIO_CHANNEL(sioc);
         qio_channel_set_delay(p->c, false);
         p->running = true;
         if (multifd_channel_connect(p, sioc, local_err)) {
             return;
         }
     }
     multifd_new_send_channel_cleanup(p, sioc, local_err);
}
Quoted 1 line

What do you think?

Hi Juan,

Sorry about the code. I check it again, it still needs to cleaup if it fails on multifd_channel_connect(). I just remove the goto and put the cleanup function there.

The second cleanup is called if (qio_task_propagate_error(task, &local_err)) ), otherwise, it won't cleanup and return normally.

If removing the first cleanup and move the return, the logic is not right. It is that: when no error happens, it still calls the second cleanup.

Thanks
Li

Quoted 18 lines

Later, Juan.

migration/multifd.c static void *multifd_recv_thread(void *opaque) · line 1080

Quoted 11 lines
migration/multifd.c +1 -4
@@ -1078,10 +1075,7 @@ static void *multifd_recv_thread(void *opaque)
 
          ret = qio_channel_read_all_eof(p->c, (void *)p->packet,
                                         p->packet_len, &local_err);
-        if (ret == 0) {   /* EOF */
-            break;
-        }
-        if (ret == -1) {   /* Error */
+        if (ret == 0 || ret == -1) {   /* 0: EOF  -1: Error */
              break;
          }

This bit is ok.

author
#5 lore raw
Quoted 64 lines · Li Zhang
Quoted 59 lines · Juan Quintela
Quoted 3 lines · Li Zhang

Clean up some unnecessary code

Hi

Quoted 18 lines

---
  migration/multifd.c | 12 +++---------

  1 file changed, 3 insertions(+), 9 deletions(-)
migration/multifd.c +1 -3
index 3242f688e5..212be1ed04 100644
@@ -854,19 +854,16 @@ static void 
 multifd_new_send_channel_async(QIOTask *task, gpointer opaque)
       Error *local_err = NULL;
       trace_multifd_new_send_channel_async(p->id);
-    if (qio_task_propagate_error(task, &local_err)) {
-        goto cleanup;
-    } else {
+    if (!qio_task_propagate_error(task, &local_err)) {
           p->c = QIO_CHANNEL(sioc);
           qio_channel_set_delay(p->c, false);

migration/multifd.c static void · line 867

Quoted 10 lines
migration/multifd.c +1 -2
           p->running = true;
           if (!multifd_channel_connect(p, sioc, local_err)) {
-            goto cleanup;
+            multifd_new_send_channel_cleanup(p, sioc, local_err);
           }
           return;
       }
-cleanup:
       multifd_new_send_channel_cleanup(p, sioc, local_err);
   }

Once there, why are we duplicating the call to
multifd_new_send_channel_cleanup()

What about:

static void multifd_new_send_channel_async(QIOTask *task, gpointer opaque) {
     MultiFDSendParams *p = opaque;
     QIOChannel *sioc = QIO_CHANNEL(qio_task_get_source(task)); Error *local_err = NULL;

     trace_multifd_new_send_channel_async(p->id); if (!qio_task_propagate_error(task, &local_err)) { p->c = QIO_CHANNEL(sioc); qio_channel_set_delay(p->c, false); p->running = true;
         if (multifd_channel_connect(p, sioc, local_err)) { return;
         }
     }
     multifd_new_send_channel_cleanup(p, sioc, local_err); }

Quoted 1 line

What do you think?

Hi Juan,

Quoted 9 lines

Sorry about the code. I check it again, it still needs to cleaup if it fails on multifd_channel_connect(). I just remove the goto and put the cleanup function there.

The second cleanup is called if (qio_task_propagate_error(task, &local_err)) ), otherwise, it won't cleanup and return normally.

If removing the first cleanup and move the return, the logic is not right.  It is that: when no error happens, it still calls the second cleanup.

I checked source code from the qemu.
This condition is not right,
if (!multifd_channel_connect(p, sioc, local_err)) is not right. The function multifd_channel_connect return true if no error.

The mail is right. :)

Quoted 21 lines

Thanks
Li

Quoted 17 lines

Later, Juan.

migration/multifd.c static void *multifd_recv_thread(void *opaque) · line 1079

Quoted 10 lines
migration/multifd.c +1 -4
@@ -1078,10 +1075,7 @@ static void *multifd_recv_thread(void *opaque)
           ret = qio_channel_read_all_eof(p->c, (void *)p->packet,
                                          p->packet_len, &local_err);
-        if (ret == 0) {   /* EOF */
-            break;
-        }
-        if (ret == -1) {   /* Error */
+        if (ret == 0 || ret == -1) {   /* 0: EOF  -1: Error */
               break;
           }

This bit is ok.

author
#6 lore raw
Quoted 75 lines · Li Zhang
Quoted 64 lines · Li Zhang
Quoted 59 lines · Juan Quintela
Quoted 3 lines · Li Zhang

Clean up some unnecessary code

Hi

Quoted 18 lines

---
  migration/multifd.c | 12 +++---------

  1 file changed, 3 insertions(+), 9 deletions(-)
migration/multifd.c +1 -3
index 3242f688e5..212be1ed04 100644
@@ -854,19 +854,16 @@ static void 
 multifd_new_send_channel_async(QIOTask *task, gpointer opaque)
       Error *local_err = NULL;
       trace_multifd_new_send_channel_async(p->id);
-    if (qio_task_propagate_error(task, &local_err)) {
-        goto cleanup;
-    } else {
+    if (!qio_task_propagate_error(task, &local_err)) {
           p->c = QIO_CHANNEL(sioc);
           qio_channel_set_delay(p->c, false);

migration/multifd.c static void · line 867

Quoted 10 lines
migration/multifd.c +1 -2
           p->running = true;
           if (!multifd_channel_connect(p, sioc, local_err)) {
-            goto cleanup;
+            multifd_new_send_channel_cleanup(p, sioc, local_err);
           }
           return;
       }
-cleanup:
       multifd_new_send_channel_cleanup(p, sioc, local_err);
   }

Once there, why are we duplicating the call to
multifd_new_send_channel_cleanup()

What about:

static void multifd_new_send_channel_async(QIOTask *task, gpointer opaque) {
     MultiFDSendParams *p = opaque;
     QIOChannel *sioc = QIO_CHANNEL(qio_task_get_source(task)); Error *local_err = NULL;

     trace_multifd_new_send_channel_async(p->id); if (!qio_task_propagate_error(task, &local_err)) { p->c = QIO_CHANNEL(sioc); qio_channel_set_delay(p->c, false); p->running = true;
         if (multifd_channel_connect(p, sioc, local_err)) { return;
         }
     }
     multifd_new_send_channel_cleanup(p, sioc, local_err); }

Quoted 1 line

What do you think?

Hi Juan,

Quoted 9 lines

Sorry about the code. I check it again, it still needs to cleaup if it fails on multifd_channel_connect(). I just remove the goto and put the cleanup function there.

The second cleanup is called if (qio_task_propagate_error(task, &local_err)) ), otherwise, it won't cleanup and return normally.

If removing the first cleanup and move the return, the logic is not right.  It is that: when no error happens, it still calls the second cleanup.

Quoted 6 lines

I checked source code from the qemu.
This condition is not right,
if (!multifd_channel_connect(p, sioc, local_err)) is not right. The function multifd_channel_connect return true if no error.

The mail is right. :)

Please ignore my mail. I made mistakes and I will update it soon.

Thanks
LI

Quoted 24 lines
Quoted 22 lines

Thanks
Li

Quoted 17 lines

Later, Juan.

migration/multifd.c static void *multifd_recv_thread(void *opaque) · line 1079

Quoted 10 lines
migration/multifd.c +1 -4
@@ -1078,10 +1075,7 @@ static void *multifd_recv_thread(void *opaque)
           ret = qio_channel_read_all_eof(p->c, (void *)p->packet,
                                          p->packet_len, &local_err);
-        if (ret == 0) {   /* EOF */
-            break;
-        }
-        if (ret == -1) {   /* Error */
+        if (ret == 0 || ret == -1) {   /* 0: EOF  -1: Error */
               break;
           }

This bit is ok.