multifd: Remove some redundant code
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
@@ -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
ping
Any comments?
Thanks
Li
Quoted 46 lines · Li Zhang
Clean up some unnecessary code
Signed-off-by Li Zhang <[email protected]>--- migration/multifd.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-)migration/multifd.c +3
-9@@ -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 ; }
Quoted 3 lines · Li Zhang
Clean up some unnecessary code
Signed-off-by Li Zhang <[email protected]>
Hi
Quoted 20 lines
--- migration/multifd.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-)migration/multifd.c +1
-3@@ -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 tomultifd_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.
Quoted 61 lines · Juan Quintela
Quoted 3 lines · Li Zhang
Clean up some unnecessary code
Signed-off-by Li Zhang <[email protected]>Hi
Quoted 20 lines
--- migration/multifd.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-)migration/multifd.c +1
-3@@ -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.
Quoted 61 lines · Juan Quintela
Quoted 3 lines · Li Zhang
Clean up some unnecessary code
Signed-off-by Li Zhang <[email protected]>Hi
Quoted 20 lines
--- migration/multifd.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-)migration/multifd.c +1
-3@@ -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.
Quoted 64 lines · Li Zhang
Quoted 59 lines · Juan Quintela
Quoted 3 lines · Li Zhang
Clean up some unnecessary code
Signed-off-by Li Zhang <[email protected]>Hi
Quoted 18 lines
---
migration/multifd.c| 12 +++---------1 file changed, 3 insertions(+), 9 deletions(-)migration/multifd.c +1
-3@@ -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
-2p->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
LiQuoted 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.
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
Signed-off-by Li Zhang <[email protected]>Hi
Quoted 18 lines
---
migration/multifd.c| 12 +++---------1 file changed, 3 insertions(+), 9 deletions(-)migration/multifd.c +1
-3@@ -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
-2p->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 functionmultifd_channel_connectreturn 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
LiQuoted 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.