Skip to contentSkip to conversation

libxl: report correct errno from virNetSocketNewConnectTCP on migration

PATCH Michal Privoznik 3 participants 5 messages Sep 3, 2015 3 messages not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw
Quoted 25 lines · Ian Campbell

saved_errno is never written to in this function after it is initialised and it is only used to log the failure from virNetSocketNewConnectTCP masking the real errno from that function.

Drop saved_errno and use errno itself.

---
 src/libxl/libxl_migration.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
src/libxl/libxl_migration.c +0 -1
index 39e4a65..e291d71 100644
@@ -480,7 +480,6 @@ libxlDomainMigrationPerform(libxlDriverPrivatePtr driver,
     virURIPtr uri = NULL;
     virNetSocketPtr sock;
     int sockfd = -1;
-    int saved_errno = EINVAL;
     int ret = -1;
 
     /* parse dst host:port from uri */

src/libxl/libxl_migration.c libxlDomainMigrationPerform(libxlDriverPrivatePtr driver, · line 501

Quoted 8 lines
src/libxl/libxl_migration.c +1 -1
@@ -496,7 +495,7 @@ libxlDomainMigrationPerform(libxlDriverPrivatePtr driver,
     if (virNetSocketNewConnectTCP(hostname, portstr,
                                   AF_UNSPEC,
                                   &sock) < 0) {
-        virReportSystemError(saved_errno,
+        virReportSystemError(errno,
                              _("unable to connect to '%s:%s'"),
                              hostname, portstr);
         goto cleanup;

In fact, virNetSocketNewConnectTCP itself returns meaningful message on error. I think this overwriting should be dropped completely.

Michal

A message that is not in the archive (sent off-list or not yet received): [email protected]

#3 lore raw
Quoted 23 lines · Michal Privoznik
Quoted 22 lines · Ian Campbell

saved_errno is never written to in this function after it is initialised and it is only used to log the failure from virNetSocketNewConnectTCP masking the real errno from that function.

Drop saved_errno and use errno itself.

---
  src/libxl/libxl_migration.c | 3 +--
  1 file changed, 1 insertion(+), 2 deletions(-)
src/libxl/libxl_migration.c +0 -1
index 39e4a65..e291d71 100644
@@ -480,7 +480,6 @@ libxlDomainMigrationPerform(libxlDriverPrivatePtr driver,
      virURIPtr uri = NULL;
      virNetSocketPtr sock;
      int sockfd = -1;
-    int saved_errno = EINVAL;
      int ret = -1;
 
Quoted 13 lines

src/libxl/libxl_migration.c libxlDomainMigrationPerform(libxlDriverPrivatePtr driver, · line 501

Quoted 11 lines
src/libxl/libxl_migration.c +1 -1
      /* parse dst host:port from uri */
@@ -496,7 +495,7 @@ libxlDomainMigrationPerform(libxlDriverPrivatePtr driver,
      if (virNetSocketNewConnectTCP(hostname, portstr,
                                    AF_UNSPEC,
                                    &sock) < 0) {
-        virReportSystemError(saved_errno,
+        virReportSystemError(errno,
                               _("unable to connect to '%s:%s'"),
                               hostname, portstr);
          goto cleanup;

In fact, virNetSocketNewConnectTCP itself returns meaningful message on error. I think this overwriting should be dropped completely.

Agreed. How about the following patch?

Regards,
Jim

Quoted 1 line

From a30c493bd9e20c9a7a423789a202c444a5eba344 Mon Sep 17 00:00:00 2001

From: Jim Fehlig <[email protected]>
Date: Thu, 3 Sep 2015 10:14:20 -0600
Subject: [PATCH] libxl: don't overwrite error from virNetSocketNewConnectTCP()

Remove redundant error reporting libxlDomainMigrationPerform(). virNetSocketNewConnectTCP() is perfectly capable of reporting sensible errors.

---
 src/libxl/libxl_migration.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
src/libxl/libxl_migration.c +1 -5
index 9609e06..de2de91 100644
@@ -487,12 +487,8 @@ libxlDomainMigrationPerform(libxlDriverPrivatePtr driver,
     /* socket connect to dst host:port */
     if (virNetSocketNewConnectTCP(hostname, portstr,
                                   AF_UNSPEC,
-                                  &sock) < 0) {
-        virReportSystemError(saved_errno,
-                             _("unable to connect to '%s:%s'"),
-                             hostname, portstr);
+                                  &sock) < 0)
         goto cleanup;
-    }
 
     if (virNetSocketSetBlocking(sock, true) < 0) {
         virObjectUnref(sock);
Signature · 1 line
2.5.0

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

A message that is not in the archive (sent off-list or not yet received): [email protected]

#5 lore raw
Quoted 9 lines · Jim Fehlig

Agreed. How about the following patch?

Quoted 1 line

From a30c493bd9e20c9a7a423789a202c444a5eba344 Mon Sep 17 00:00:00 2001

From: Jim Fehlig<[email protected]>
Date: Thu, 3 Sep 2015 10:14:20 -0600
Subject: [PATCH] libxl: don't overwrite error from virNetSocketNewConnectTCP()

Remove redundant error reporting libxlDomainMigrationPerform().

FYI, I've changed s/reporting/reporting in/ in the commit message.

Regards,
Jim

Quoted 4 lines

virNetSocketNewConnectTCP() is perfectly capable of reporting sensible errors.

#6 lore raw
In reply to a message not in the archive
Quoted 11 lines · Jim Fehlig

From a30c493bd9e20c9a7a423789a202c444a5eba344 Mon Sep 17 00:00:00 2001
From: Jim Fehlig <[email protected]>
Date: Thu, 3 Sep 2015 10:14:20 -0600
Subject: [PATCH] libxl: don't overwrite error from virNetSocketNewConnectTCP()

Remove redundant error reporting libxlDomainMigrationPerform(). virNetSocketNewConnectTCP() is perfectly capable of reporting sensible errors.

FWIW: Acked-by: Ian Campbell <[email protected]>

#7 lore raw
In reply to a message not in the archive
Quoted 22 lines · Jim Fehlig

Agreed. How about the following patch?

Quoted 1 line

From a30c493bd9e20c9a7a423789a202c444a5eba344 Mon Sep 17 00:00:00 2001

From: Jim Fehlig<[email protected]>
Date: Thu, 3 Sep 2015 10:14:20 -0600
Subject: [PATCH] libxl: don't overwrite error from virNetSocketNewConnectTCP()

Remove redundant error reporting libxlDomainMigrationPerform(). virNetSocketNewConnectTCP() is perfectly capable of reporting sensible errors.

---
  src/libxl/libxl_migration.c | 6 +-----
  1 file changed, 1 insertion(+), 5 deletions(-)
src/libxl/libxl_migration.c +0 -0
index 9609e06..de2de91 100644

src/libxl/libxl_migration.c libxlDomainMigrationPerform(libxlDriverPrivatePtr driver, · line 495

Quoted 10 lines
src/libxl/libxl_migration.c +1 -5
@@ -487,12 +487,8 @@ libxlDomainMigrationPerform(libxlDriverPrivatePtr driver,
      /* socket connect to dst host:port */
      if (virNetSocketNewConnectTCP(hostname, portstr,
                                    AF_UNSPEC,
-                                  &sock) < 0) {
-        virReportSystemError(saved_errno,
-                             _("unable to connect to '%s:%s'"),
-                             hostname, portstr);
+                                  &sock) < 0)
          goto cleanup;
-    }

I should try compiling before sending patches:

libxl/libxl_migration.c:475:9: error: unused variable 'saved_errno' [-Werror=unused-variable]

     int saved_errno = EINVAL;

I posted a working V2:

https://www.redhat.com/archives/libvir-list/2015-September/msg00107.html

Regards,
Jim