* [Qemu-devel] [PATCH] block: Remove -errno return value from bdrv_assign_node_name
@ 2014-03-18 9:00 Kevin Wolf
2014-03-18 10:09 ` Markus Armbruster
0 siblings, 1 reply; 5+ messages in thread
From: Kevin Wolf @ 2014-03-18 9:00 UTC (permalink / raw)
To: qemu-devel; +Cc: kwolf, stefanha
It takes an errp argument. That's enough for error handling.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
block.c | 21 ++++++++++-----------
1 file changed, 10 insertions(+), 11 deletions(-)
diff --git a/block.c b/block.c
index acb70fd..b4f3f77 100644
--- a/block.c
+++ b/block.c
@@ -783,18 +783,18 @@ static int bdrv_open_flags(BlockDriverState *bs, int flags)
return open_flags;
}
-static int bdrv_assign_node_name(BlockDriverState *bs,
- const char *node_name,
- Error **errp)
+static void bdrv_assign_node_name(BlockDriverState *bs,
+ const char *node_name,
+ Error **errp)
{
if (!node_name) {
- return 0;
+ return;
}
/* empty string node name is invalid */
if (node_name[0] == '\0') {
error_setg(errp, "Empty node name");
- return -EINVAL;
+ return;
}
/* takes care of avoiding namespaces collisions */
@@ -807,14 +807,12 @@ static int bdrv_assign_node_name(BlockDriverState *bs,
/* takes care of avoiding duplicates node names */
if (bdrv_find_node(node_name)) {
error_setg(errp, "Duplicate node name");
- return -EINVAL;
+ return;
}
/* copy node name into the bs and insert it into the graph list */
pstrcpy(bs->node_name, sizeof(bs->node_name), node_name);
QTAILQ_INSERT_TAIL(&graph_bdrv_states, bs, node_list);
-
- return 0;
}
/*
@@ -849,9 +847,10 @@ static int bdrv_open_common(BlockDriverState *bs, BlockDriverState *file,
trace_bdrv_open_common(bs, filename ?: "", flags, drv->format_name);
node_name = qdict_get_try_str(options, "node-name");
- ret = bdrv_assign_node_name(bs, node_name, errp);
- if (ret < 0) {
- return ret;
+ bdrv_assign_node_name(bs, node_name, &local_err);
+ if (error_is_set(&local_err)) {
+ error_propagate(errp, local_err);
+ return -EINVAL;
}
qdict_del(options, "node-name");
--
1.8.3.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH] block: Remove -errno return value from bdrv_assign_node_name
2014-03-18 9:00 [Qemu-devel] [PATCH] block: Remove -errno return value from bdrv_assign_node_name Kevin Wolf
@ 2014-03-18 10:09 ` Markus Armbruster
2014-03-18 10:54 ` Kevin Wolf
0 siblings, 1 reply; 5+ messages in thread
From: Markus Armbruster @ 2014-03-18 10:09 UTC (permalink / raw)
To: Kevin Wolf; +Cc: qemu-devel, stefanha
Kevin Wolf <kwolf@redhat.com> writes:
> It takes an errp argument. That's enough for error handling.
>
> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
> ---
> block.c | 21 ++++++++++-----------
> 1 file changed, 10 insertions(+), 11 deletions(-)
>
> diff --git a/block.c b/block.c
> index acb70fd..b4f3f77 100644
> --- a/block.c
> +++ b/block.c
> @@ -783,18 +783,18 @@ static int bdrv_open_flags(BlockDriverState *bs, int flags)
> return open_flags;
> }
>
> -static int bdrv_assign_node_name(BlockDriverState *bs,
> - const char *node_name,
> - Error **errp)
> +static void bdrv_assign_node_name(BlockDriverState *bs,
> + const char *node_name,
> + Error **errp)
> {
> if (!node_name) {
> - return 0;
> + return;
> }
>
> /* empty string node name is invalid */
> if (node_name[0] == '\0') {
> error_setg(errp, "Empty node name");
> - return -EINVAL;
> + return;
> }
>
> /* takes care of avoiding namespaces collisions */
> @@ -807,14 +807,12 @@ static int bdrv_assign_node_name(BlockDriverState *bs,
> /* takes care of avoiding duplicates node names */
> if (bdrv_find_node(node_name)) {
> error_setg(errp, "Duplicate node name");
> - return -EINVAL;
> + return;
> }
>
> /* copy node name into the bs and insert it into the graph list */
> pstrcpy(bs->node_name, sizeof(bs->node_name), node_name);
> QTAILQ_INSERT_TAIL(&graph_bdrv_states, bs, node_list);
> -
> - return 0;
> }
>
> /*
> @@ -849,9 +847,10 @@ static int bdrv_open_common(BlockDriverState *bs, BlockDriverState *file,
> trace_bdrv_open_common(bs, filename ?: "", flags, drv->format_name);
>
> node_name = qdict_get_try_str(options, "node-name");
> - ret = bdrv_assign_node_name(bs, node_name, errp);
> - if (ret < 0) {
> - return ret;
> + bdrv_assign_node_name(bs, node_name, &local_err);
> + if (error_is_set(&local_err)) {
> + error_propagate(errp, local_err);
> + return -EINVAL;
> }
> qdict_del(options, "node-name");
Please use 'if (local_err)' instead of 'if (error_is_set(&local_err))'.
See commit 84d18f0.
I don't like functions returning their only value through a pointer
rather than the function value, but I guess it's how Error wants to be
used.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH] block: Remove -errno return value from bdrv_assign_node_name
2014-03-18 10:09 ` Markus Armbruster
@ 2014-03-18 10:54 ` Kevin Wolf
2014-03-18 12:03 ` Markus Armbruster
0 siblings, 1 reply; 5+ messages in thread
From: Kevin Wolf @ 2014-03-18 10:54 UTC (permalink / raw)
To: Markus Armbruster; +Cc: qemu-devel, stefanha
Am 18.03.2014 um 11:09 hat Markus Armbruster geschrieben:
> Kevin Wolf <kwolf@redhat.com> writes:
>
> > It takes an errp argument. That's enough for error handling.
> >
> > Signed-off-by: Kevin Wolf <kwolf@redhat.com>
> > ---
> > block.c | 21 ++++++++++-----------
> > 1 file changed, 10 insertions(+), 11 deletions(-)
> >
> > diff --git a/block.c b/block.c
> > index acb70fd..b4f3f77 100644
> > --- a/block.c
> > +++ b/block.c
> > @@ -783,18 +783,18 @@ static int bdrv_open_flags(BlockDriverState *bs, int flags)
> > return open_flags;
> > }
> >
> > -static int bdrv_assign_node_name(BlockDriverState *bs,
> > - const char *node_name,
> > - Error **errp)
> > +static void bdrv_assign_node_name(BlockDriverState *bs,
> > + const char *node_name,
> > + Error **errp)
> > {
> > if (!node_name) {
> > - return 0;
> > + return;
> > }
> >
> > /* empty string node name is invalid */
> > if (node_name[0] == '\0') {
> > error_setg(errp, "Empty node name");
> > - return -EINVAL;
> > + return;
> > }
> >
> > /* takes care of avoiding namespaces collisions */
> > @@ -807,14 +807,12 @@ static int bdrv_assign_node_name(BlockDriverState *bs,
> > /* takes care of avoiding duplicates node names */
> > if (bdrv_find_node(node_name)) {
> > error_setg(errp, "Duplicate node name");
> > - return -EINVAL;
> > + return;
> > }
> >
> > /* copy node name into the bs and insert it into the graph list */
> > pstrcpy(bs->node_name, sizeof(bs->node_name), node_name);
> > QTAILQ_INSERT_TAIL(&graph_bdrv_states, bs, node_list);
> > -
> > - return 0;
> > }
> >
> > /*
> > @@ -849,9 +847,10 @@ static int bdrv_open_common(BlockDriverState *bs, BlockDriverState *file,
> > trace_bdrv_open_common(bs, filename ?: "", flags, drv->format_name);
> >
> > node_name = qdict_get_try_str(options, "node-name");
> > - ret = bdrv_assign_node_name(bs, node_name, errp);
> > - if (ret < 0) {
> > - return ret;
> > + bdrv_assign_node_name(bs, node_name, &local_err);
> > + if (error_is_set(&local_err)) {
> > + error_propagate(errp, local_err);
> > + return -EINVAL;
> > }
> > qdict_del(options, "node-name");
>
> Please use 'if (local_err)' instead of 'if (error_is_set(&local_err))'.
> See commit 84d18f0.
I can do that; this patch predates your change and I just dug it out
from an old branch. Note that there are still many places that use
error_is_set() where it's not necessary, including documentation that
should show how to do things right, e.g. docs/writing-qmp-commands.txt.
(By the way, would the actual problem with Coverity in commit 84d18f0
not be fixed more easily and for all instances by making error_is_set()
a static inline function in the header?)
What was the proper use case for error_is_set() again? Or can we get rid
of it? As long as it's there, you'll keep getting new offenders.
Kevin
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH] block: Remove -errno return value from bdrv_assign_node_name
2014-03-18 10:54 ` Kevin Wolf
@ 2014-03-18 12:03 ` Markus Armbruster
2014-03-18 15:50 ` Markus Armbruster
0 siblings, 1 reply; 5+ messages in thread
From: Markus Armbruster @ 2014-03-18 12:03 UTC (permalink / raw)
To: Kevin Wolf; +Cc: qemu-devel, stefanha
Kevin Wolf <kwolf@redhat.com> writes:
> Am 18.03.2014 um 11:09 hat Markus Armbruster geschrieben:
>> Kevin Wolf <kwolf@redhat.com> writes:
>>
>> > It takes an errp argument. That's enough for error handling.
>> >
>> > Signed-off-by: Kevin Wolf <kwolf@redhat.com>
>> > ---
>> > block.c | 21 ++++++++++-----------
>> > 1 file changed, 10 insertions(+), 11 deletions(-)
>> >
>> > diff --git a/block.c b/block.c
>> > index acb70fd..b4f3f77 100644
>> > --- a/block.c
>> > +++ b/block.c
>> > @@ -783,18 +783,18 @@ static int bdrv_open_flags(BlockDriverState *bs, int flags)
>> > return open_flags;
>> > }
>> >
>> > -static int bdrv_assign_node_name(BlockDriverState *bs,
>> > - const char *node_name,
>> > - Error **errp)
>> > +static void bdrv_assign_node_name(BlockDriverState *bs,
>> > + const char *node_name,
>> > + Error **errp)
>> > {
>> > if (!node_name) {
>> > - return 0;
>> > + return;
>> > }
>> >
>> > /* empty string node name is invalid */
>> > if (node_name[0] == '\0') {
>> > error_setg(errp, "Empty node name");
>> > - return -EINVAL;
>> > + return;
>> > }
>> >
>> > /* takes care of avoiding namespaces collisions */
>> > @@ -807,14 +807,12 @@ static int bdrv_assign_node_name(BlockDriverState *bs,
>> > /* takes care of avoiding duplicates node names */
>> > if (bdrv_find_node(node_name)) {
>> > error_setg(errp, "Duplicate node name");
>> > - return -EINVAL;
>> > + return;
>> > }
>> >
>> > /* copy node name into the bs and insert it into the graph list */
>> > pstrcpy(bs->node_name, sizeof(bs->node_name), node_name);
>> > QTAILQ_INSERT_TAIL(&graph_bdrv_states, bs, node_list);
>> > -
>> > - return 0;
>> > }
>> >
>> > /*
>> > @@ -849,9 +847,10 @@ static int bdrv_open_common(BlockDriverState *bs, BlockDriverState *file,
>> > trace_bdrv_open_common(bs, filename ?: "", flags, drv->format_name);
>> >
>> > node_name = qdict_get_try_str(options, "node-name");
>> > - ret = bdrv_assign_node_name(bs, node_name, errp);
>> > - if (ret < 0) {
>> > - return ret;
>> > + bdrv_assign_node_name(bs, node_name, &local_err);
>> > + if (error_is_set(&local_err)) {
>> > + error_propagate(errp, local_err);
>> > + return -EINVAL;
>> > }
>> > qdict_del(options, "node-name");
>>
>> Please use 'if (local_err)' instead of 'if (error_is_set(&local_err))'.
>> See commit 84d18f0.
>
> I can do that; this patch predates your change and I just dug it out
> from an old branch.
No harm done :)
> Note that there are still many places that use
> error_is_set() where it's not necessary, including documentation that
> should show how to do things right, e.g. docs/writing-qmp-commands.txt.
The documentation I simply missed. The others probably crept in after I
prepared the patch that became commit 84d18f0. Such things usually take
an extra iteration or two.
> (By the way, would the actual problem with Coverity in commit 84d18f0
> not be fixed more easily and for all instances by making error_is_set()
> a static inline function in the header?)
I wouldn't bet on it. Coverity is pretty good at looking through
compilation unit boundaries, but it gets easily spooked by null tests.
> What was the proper use case for error_is_set() again? Or can we get rid
> of it? As long as it's there, you'll keep getting new offenders.
I don't like it myself, and I think we can get rid of it.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH] block: Remove -errno return value from bdrv_assign_node_name
2014-03-18 12:03 ` Markus Armbruster
@ 2014-03-18 15:50 ` Markus Armbruster
0 siblings, 0 replies; 5+ messages in thread
From: Markus Armbruster @ 2014-03-18 15:50 UTC (permalink / raw)
To: Kevin Wolf; +Cc: qemu-devel, stefanha
Markus Armbruster <armbru@redhat.com> writes:
> Kevin Wolf <kwolf@redhat.com> writes:
[...]
>> What was the proper use case for error_is_set() again? Or can we get rid
>> of it? As long as it's there, you'll keep getting new offenders.
>
> I don't like it myself, and I think we can get rid of it.
At first glance, quite a few uses of error_set() look like bugs, usually
latent ones. I guess we better examine them one by one. Yet another
tree-wide cleanups... getting those committed has been a royal pain.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2014-03-18 15:51 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-03-18 9:00 [Qemu-devel] [PATCH] block: Remove -errno return value from bdrv_assign_node_name Kevin Wolf
2014-03-18 10:09 ` Markus Armbruster
2014-03-18 10:54 ` Kevin Wolf
2014-03-18 12:03 ` Markus Armbruster
2014-03-18 15:50 ` Markus Armbruster
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).