Skip to contentSkip to conversation

sheepdog: Set error when connection fails

PATCH Applied Fam Zheng 6 participants 14 messages Apr 20, 2017 – Apr 21, 2017 Block layer

lore
Share & tools
lore

Fam Zheng

author
#0 lore raw

PATCH 1/1 sheepdog: Set error when connection fails

---
 block/sheepdog.c | 1 +
 1 file changed, 1 insertion(+)
block/sheepdog.c +1 -0
index fb9203e..7e889ee 100644
@@ -608,6 +608,7 @@ static int connect_to_sdog(BDRVSheepdogState *s, Error **errp)
         qemu_set_nonblock(fd);
     } else {
         fd = -EIO;
+        error_setg(errp, "Failed to connect to sheepdog server");
     }
 
     return fd;
Signature · 1 line
2.9.3
Reviewed-by on v1 1/1
#1 lore raw
Quoted 1 line · Fam Zheng
Quoted 17 lines
---
 block/sheepdog.c | 1 +
 1 file changed, 1 insertion(+)
block/sheepdog.c +1 -0
index fb9203e..7e889ee 100644
@@ -608,6 +608,7 @@ static int connect_to_sdog(BDRVSheepdogState *s, Error **errp)
         qemu_set_nonblock(fd);
     } else {
         fd = -EIO;
+        error_setg(errp, "Failed to connect to sheepdog server");
     }
 
     return fd;
Reviewed-by on v1 1/1
#2 lore raw
In reply to Fam Zheng
Quoted 10 lines · Fam Zheng
---
 block/sheepdog.c | 1 +
 1 file changed, 1 insertion(+)
block/sheepdog.c +0 -0
index fb9203e..7e889ee 100644

block/sheepdog.c static int connect_to_sdog(BDRVSheepdogState *s, Error **errp) · line 612

Quoted 5 lines
block/sheepdog.c +1 -0
@@ -608,6 +608,7 @@ static int connect_to_sdog(BDRVSheepdogState *s, Error **errp)
         qemu_set_nonblock(fd);
     } else {
         fd = -EIO;
+        error_setg(errp, "Failed to connect to sheepdog server");
     }

A bit odd that we don't just return right away in this function after a failed called to socket_connect(), but that has nothing to do with your patch.

Quoted 5 lines
block/sheepdog.c +0 -0
     return fd;
Signature · 1 line
2.9.3
Applied
#3 lore raw
In reply to Fam Zheng
Quoted 20 lines · Fam Zheng
---
 block/sheepdog.c | 1 +
 1 file changed, 1 insertion(+)
block/sheepdog.c +1 -0
index fb9203e..7e889ee 100644
@@ -608,6 +608,7 @@ static int connect_to_sdog(BDRVSheepdogState *s, Error **errp)
         qemu_set_nonblock(fd);
     } else {
         fd = -EIO;
+        error_setg(errp, "Failed to connect to sheepdog server");
     }
 
     return fd;
Signature · 1 line
2.9.3

Thanks,

Applied to my block branch:

git://github.com/codyprime/qemu-kvm-jtc block

-Jeff

#4 lore raw
In reply to Fam Zheng
Quoted 10 lines · Fam Zheng
---
 block/sheepdog.c | 1 +
 1 file changed, 1 insertion(+)
block/sheepdog.c +0 -0
index fb9203e..7e889ee 100644

block/sheepdog.c static int connect_to_sdog(BDRVSheepdogState *s, Error **errp) · line 612

Quoted 5 lines
block/sheepdog.c +1 -0
@@ -608,6 +608,7 @@ static int connect_to_sdog(BDRVSheepdogState *s, Error **errp)
         qemu_set_nonblock(fd);
     } else {
         fd = -EIO;
+        error_setg(errp, "Failed to connect to sheepdog server");
     }

This doesn't make much sense to me. The lines just above the diff context have this:

    fd = socket_connect(s->addr, errp, NULL, NULL);

socket_connect should have already reported an error on "errp" in the scenario that 'fd == -1'. So AFAICT the new error_setg is just throwing away the real detailed error message in favour of a generic message.

So I'm puzzelled why we need to change anything - error reporting should already be working fine.

Regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#5 lore raw
Quoted 22 lines · Daniel P. Berrange
Quoted 10 lines · Fam Zheng
---
 block/sheepdog.c | 1 +
 1 file changed, 1 insertion(+)
block/sheepdog.c +0 -0
index fb9203e..7e889ee 100644

block/sheepdog.c static int connect_to_sdog(BDRVSheepdogState *s, Error **errp) · line 612

Quoted 5 lines
block/sheepdog.c +1 -0
@@ -608,6 +608,7 @@ static int connect_to_sdog(BDRVSheepdogState *s, Error **errp)
         qemu_set_nonblock(fd);
     } else {
         fd = -EIO;
+        error_setg(errp, "Failed to connect to sheepdog server");
     }

This doesn't make much sense to me. The lines just above the diff context have this:

    fd = socket_connect(s->addr, errp, NULL, NULL);
Quoted 8 lines

socket_connect should have already reported an error on "errp" in the scenario that 'fd == -1'. So AFAICT the new error_setg is just throwing away the real detailed error message in favour of a generic message.

So I'm puzzelled why we need to change anything - error reporting should already be working fine.

Indeed, you are right. (Dequeuing patch)

It would also make more sense to check fd after the socket_connect() call and return error then, rather than keep checking fd throughout the rest of the function.

-Jeff

#6 lore raw
Quoted 32 lines · Jeff Cody
Quoted 22 lines · Daniel P. Berrange
Quoted 10 lines · Fam Zheng
---
 block/sheepdog.c | 1 +
 1 file changed, 1 insertion(+)
block/sheepdog.c +0 -0
index fb9203e..7e889ee 100644

block/sheepdog.c static int connect_to_sdog(BDRVSheepdogState *s, Error **errp) · line 612

Quoted 5 lines
block/sheepdog.c +1 -0
@@ -608,6 +608,7 @@ static int connect_to_sdog(BDRVSheepdogState *s, Error **errp)
         qemu_set_nonblock(fd);
     } else {
         fd = -EIO;
+        error_setg(errp, "Failed to connect to sheepdog server");
     }

This doesn't make much sense to me. The lines just above the diff context have this:

    fd = socket_connect(s->addr, errp, NULL, NULL);
Quoted 8 lines

socket_connect should have already reported an error on "errp" in the scenario that 'fd == -1'. So AFAICT the new error_setg is just throwing away the real detailed error message in favour of a generic message.

So I'm puzzelled why we need to change anything - error reporting should already be working fine.

Quoted 5 lines

Indeed, you are right. (Dequeuing patch)

It would also make more sense to check fd after the socket_connect() call and return error then, rather than keep checking fd throughout the rest of the function.

Yeah that would make it much more obvious that the error reporting is correct.

Regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#7 lore raw
In reply to Daniel P. Berrange

Am 20.04.2017 um 17:30 hat Daniel P. Berrange geschrieben:

Quoted 20 lines · Fam Zheng
Quoted 10 lines
---
 block/sheepdog.c | 1 +
 1 file changed, 1 insertion(+)
block/sheepdog.c +0 -0
index fb9203e..7e889ee 100644

block/sheepdog.c static int connect_to_sdog(BDRVSheepdogState *s, Error **errp) · line 612

Quoted 5 lines
block/sheepdog.c +1 -0
@@ -608,6 +608,7 @@ static int connect_to_sdog(BDRVSheepdogState *s, Error **errp)
         qemu_set_nonblock(fd);
     } else {
         fd = -EIO;
+        error_setg(errp, "Failed to connect to sheepdog server");
     }

This doesn't make much sense to me. The lines just above the diff context have this:

Quoted 4 lines
    fd = socket_connect(s->addr, errp, NULL, NULL);

socket_connect should have already reported an error on "errp" in the scenario that 'fd == -1'.

By the way, am I the only one who thinks that having errp anywhere else than as the last argument is bad style? I can easily see myself missing that this functions sets it because the last argument is NULL.

Kevin

#8 lore raw
Quoted 21 lines · Kevin Wolf

Am 20.04.2017 um 17:30 hat Daniel P. Berrange geschrieben:

Quoted 20 lines · Fam Zheng
Quoted 10 lines
---
 block/sheepdog.c | 1 +
 1 file changed, 1 insertion(+)
block/sheepdog.c +0 -0
index fb9203e..7e889ee 100644

block/sheepdog.c static int connect_to_sdog(BDRVSheepdogState *s, Error **errp) · line 612

Quoted 5 lines
block/sheepdog.c +1 -0
@@ -608,6 +608,7 @@ static int connect_to_sdog(BDRVSheepdogState *s, Error **errp)
         qemu_set_nonblock(fd);
     } else {
         fd = -EIO;
+        error_setg(errp, "Failed to connect to sheepdog server");
     }

This doesn't make much sense to me. The lines just above the diff context have this:

Quoted 9 lines
Quoted 4 lines
    fd = socket_connect(s->addr, errp, NULL, NULL);

socket_connect should have already reported an error on "errp" in the scenario that 'fd == -1'.

By the way, am I the only one who thinks that having errp anywhere else than as the last argument is bad style? I can easily see myself missing that this functions sets it because the last argument is NULL.

No, you are not - that is precisely why I missed it in my review.

-Jeff

author
#9 lore raw
In reply to Kevin Wolf
Quoted 22 lines · Kevin Wolf

Am 20.04.2017 um 17:30 hat Daniel P. Berrange geschrieben:

Quoted 21 lines · Fam Zheng
Quoted 10 lines
---
 block/sheepdog.c | 1 +
 1 file changed, 1 insertion(+)
block/sheepdog.c +0 -0
index fb9203e..7e889ee 100644

block/sheepdog.c static int connect_to_sdog(BDRVSheepdogState *s, Error **errp) · line 612

Quoted 5 lines
block/sheepdog.c +1 -0
@@ -608,6 +608,7 @@ static int connect_to_sdog(BDRVSheepdogState *s, Error **errp)
         qemu_set_nonblock(fd);
     } else {
         fd = -EIO;
+        error_setg(errp, "Failed to connect to sheepdog server");
     }

This doesn't make much sense to me. The lines just above the diff context have this:

    fd = socket_connect(s->addr, errp, NULL, NULL);

Oops! :(

Quoted 7 lines
Quoted 3 lines

socket_connect should have already reported an error on "errp" in the scenario that 'fd == -1'.

By the way, am I the only one who thinks that having errp anywhere else than as the last argument is bad style? I can easily see myself missing that this functions sets it because the last argument is NULL.

Hmm, exactly.. Socket code does this here and there, and it's hard to read.

Fam

#10 lore raw
In reply to Kevin Wolf
Quoted 21 lines · Kevin Wolf

Am 20.04.2017 um 17:30 hat Daniel P. Berrange geschrieben:

Quoted 20 lines · Fam Zheng
Quoted 10 lines
---
 block/sheepdog.c | 1 +
 1 file changed, 1 insertion(+)
block/sheepdog.c +0 -0
index fb9203e..7e889ee 100644

block/sheepdog.c static int connect_to_sdog(BDRVSheepdogState *s, Error **errp) · line 612

Quoted 5 lines
block/sheepdog.c +1 -0
@@ -608,6 +608,7 @@ static int connect_to_sdog(BDRVSheepdogState *s, Error **errp)
         qemu_set_nonblock(fd);
     } else {
         fd = -EIO;
+        error_setg(errp, "Failed to connect to sheepdog server");
     }

This doesn't make much sense to me. The lines just above the diff context have this:

Quoted 8 lines
Quoted 4 lines
    fd = socket_connect(s->addr, errp, NULL, NULL);

socket_connect should have already reported an error on "errp" in the scenario that 'fd == -1'.

By the way, am I the only one who thinks that having errp anywhere else than as the last argument is bad style? I can easily see myself missing that this functions sets it because the last argument is NULL.

Yes, it's bad style because it's suprising. Worth fixing.

#11 lore raw
Quoted 25 lines · Markus Armbruster
Quoted 23 lines · Kevin Wolf

Am 20.04.2017 um 17:30 hat Daniel P. Berrange geschrieben:

Quoted 22 lines · Fam Zheng
Quoted 10 lines
---
 block/sheepdog.c | 1 +
 1 file changed, 1 insertion(+)
block/sheepdog.c +0 -0
index fb9203e..7e889ee 100644

block/sheepdog.c static int connect_to_sdog(BDRVSheepdogState *s, Error **errp) · line 612

Quoted 5 lines
block/sheepdog.c +1 -0
@@ -608,6 +608,7 @@ static int connect_to_sdog(BDRVSheepdogState *s, Error **errp)
         qemu_set_nonblock(fd);
     } else {
         fd = -EIO;
+        error_setg(errp, "Failed to connect to sheepdog server");
     }

This doesn't make much sense to me. The lines just above the diff context have this:

    fd = socket_connect(s->addr, errp, NULL, NULL);
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

socket_connect should have already reported an error on "errp" in the scenario that 'fd == -1'.

By the way, am I the only one who thinks that having errp anywhere else than as the last argument is bad style? I can easily see myself missing that this functions sets it because the last argument is NULL.

Yes, it's bad style because it's suprising. Worth fixing.

In fact we can simply delete the last two arguments to socket_connect() entirely. Most code is now switched over to use QIOChannel APIs, so we don't have anything which uses the non-blocking connect feature of socket_connect() anymore.

Regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
author
#12 lore raw
Quoted 33 lines · Daniel P. Berrange
Quoted 32 lines · Markus Armbruster
Quoted 29 lines · Kevin Wolf

Am 20.04.2017 um 17:30 hat Daniel P. Berrange geschrieben:

Quoted 20 lines · Fam Zheng
Quoted 10 lines
---
 block/sheepdog.c | 1 +
 1 file changed, 1 insertion(+)
block/sheepdog.c +0 -0
index fb9203e..7e889ee 100644

block/sheepdog.c static int connect_to_sdog(BDRVSheepdogState *s, Error **errp) · line 612

Quoted 5 lines
block/sheepdog.c +1 -0
@@ -608,6 +608,7 @@ static int connect_to_sdog(BDRVSheepdogState *s, Error **errp)
         qemu_set_nonblock(fd);
     } else {
         fd = -EIO;
+        error_setg(errp, "Failed to connect to sheepdog server");
     }

This doesn't make much sense to me. The lines just above the diff context have this:

Quoted 4 lines
    fd = socket_connect(s->addr, errp, NULL, NULL);

socket_connect should have already reported an error on "errp" in the scenario that 'fd == -1'.

By the way, am I the only one who thinks that having errp anywhere else than as the last argument is bad style? I can easily see myself missing that this functions sets it because the last argument is NULL.

Quoted 6 lines
Quoted 1 line

Yes, it's bad style because it's suprising. Worth fixing.

In fact we can simply delete the last two arguments to socket_connect() entirely. Most code is now switched over to use QIOChannel APIs, so we don't have anything which uses the non-blocking connect feature of socket_connect() anymore.

There is one caller that passes non-NULL last two parameters, which seems non-trivial to convert:

static int net_socket_connect_init(NetClientState *peer,
const char *model, const char *name, const char *host_str)

{
    socket_connect_data *c = g_new0(socket_connect_data, 1);
    int fd = -1;
    Error *local_error = NULL;

    c->peer = peer;
    c->model = g_strdup(model);
    c->name = g_strdup(name);
    c->saddr = socket_parse(host_str, &local_error);
    if (c->saddr == NULL) {
        goto err;
    }

    fd = socket_connect(c->saddr, net_socket_connected, c, &local_error);
    if (fd < 0) {
        goto err;
    }

    return 0;

err:

    error_report_err(local_error);
    socket_connect_data_free(c);
    return -1;
}
#13 lore raw
Quoted 68 lines · Fam Zheng
Quoted 33 lines · Daniel P. Berrange
Quoted 32 lines · Markus Armbruster
Quoted 29 lines · Kevin Wolf

Am 20.04.2017 um 17:30 hat Daniel P. Berrange geschrieben:

Quoted 20 lines · Fam Zheng
Quoted 10 lines
---
 block/sheepdog.c | 1 +
 1 file changed, 1 insertion(+)
block/sheepdog.c +0 -0
index fb9203e..7e889ee 100644

block/sheepdog.c static int connect_to_sdog(BDRVSheepdogState *s, Error **errp) · line 612

Quoted 5 lines
block/sheepdog.c +1 -0
@@ -608,6 +608,7 @@ static int connect_to_sdog(BDRVSheepdogState *s, Error **errp)
         qemu_set_nonblock(fd);
     } else {
         fd = -EIO;
+        error_setg(errp, "Failed to connect to sheepdog server");
     }

This doesn't make much sense to me. The lines just above the diff context have this:

Quoted 4 lines
    fd = socket_connect(s->addr, errp, NULL, NULL);

socket_connect should have already reported an error on "errp" in the scenario that 'fd == -1'.

By the way, am I the only one who thinks that having errp anywhere else than as the last argument is bad style? I can easily see myself missing that this functions sets it because the last argument is NULL.

Quoted 6 lines
Quoted 1 line

Yes, it's bad style because it's suprising. Worth fixing.

In fact we can simply delete the last two arguments to socket_connect() entirely. Most code is now switched over to use QIOChannel APIs, so we don't have anything which uses the non-blocking connect feature of socket_connect() anymore.

There is one caller that passes non-NULL last two parameters, which seems non-trivial to convert:

static int net_socket_connect_init(NetClientState *peer,
const char *model, const char *name, const char *host_str)

{
    socket_connect_data *c = g_new0(socket_connect_data, 1);
    int fd = -1;
    Error *local_error = NULL;

    c->peer = peer;
    c->model = g_strdup(model);
    c->name = g_strdup(name);
    c->saddr = socket_parse(host_str, &local_error);
    if (c->saddr == NULL) {
        goto err;
    }

    fd = socket_connect(c->saddr, net_socket_connected, c, &local_error);
    if (fd < 0) {
        goto err;
    }

    return 0;
Quoted 5 lines

err:

    error_report_err(local_error);
    socket_connect_data_free(c);
    return -1;
}

Oh i missed that in my grep. I think it could probably be converted to QIOChannel though, at least for the initial connection setup. Then just steal the FD from the QIOChannel object for direct usage thereafter or something like that.

Regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|