From: Max Reitz <mreitz@redhat.com>
To: qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>,
Stefan Hajnoczi <stefanha@redhat.com>,
Max Reitz <mreitz@redhat.com>
Subject: [Qemu-devel] [PATCH 4/6] blkdebug: Always call read_config()
Date: Thu, 21 Nov 2013 20:05:52 +0100 [thread overview]
Message-ID: <1385060754-18821-5-git-send-email-mreitz@redhat.com> (raw)
In-Reply-To: <1385060754-18821-1-git-send-email-mreitz@redhat.com>
Move the check whether there actually is a config file into the
read_config() function.
Signed-off-by: Max Reitz <mreitz@redhat.com>
---
block/blkdebug.c | 42 ++++++++++++++++++++++--------------------
1 file changed, 22 insertions(+), 20 deletions(-)
diff --git a/block/blkdebug.c b/block/blkdebug.c
index 59d33a8..8d52173 100644
--- a/block/blkdebug.c
+++ b/block/blkdebug.c
@@ -273,23 +273,25 @@ static void remove_rule(BlkdebugRule *rule)
static int read_config(BDRVBlkdebugState *s, const char *filename, Error **errp)
{
- FILE *f;
+ FILE *f = NULL;
int ret;
struct add_rule_data d;
- f = fopen(filename, "r");
- if (f == NULL) {
- error_setg_errno(errp, errno, "Could not read blkdebug config file "
- "'%s'", filename);
- return -errno;
- }
+ if (filename) {
+ f = fopen(filename, "r");
+ if (f == NULL) {
+ error_setg_errno(errp, errno, "Could not read blkdebug config file "
+ "'%s'", filename);
+ return -errno;
+ }
- ret = qemu_config_parse(f, config_groups, filename);
- if (ret < 0) {
- error_setg(errp, "Could not parse blkdebug config file '%s'",
- filename);
- ret = -EINVAL;
- goto fail;
+ ret = qemu_config_parse(f, config_groups, filename);
+ if (ret < 0) {
+ error_setg(errp, "Could not parse blkdebug config file '%s'",
+ filename);
+ ret = -EINVAL;
+ goto fail;
+ }
}
d.s = s;
@@ -303,7 +305,9 @@ static int read_config(BDRVBlkdebugState *s, const char *filename, Error **errp)
fail:
qemu_opts_reset(&inject_error_opts);
qemu_opts_reset(&set_state_opts);
- fclose(f);
+ if (f) {
+ fclose(f);
+ }
return ret;
}
@@ -376,12 +380,10 @@ static int blkdebug_open(BlockDriverState *bs, QDict *options, int flags,
/* Read rules from config file */
config = qemu_opt_get(opts, "config");
- if (config) {
- ret = read_config(s, config, &local_err);
- if (ret) {
- error_propagate(errp, local_err);
- goto fail;
- }
+ ret = read_config(s, config, &local_err);
+ if (ret) {
+ error_propagate(errp, local_err);
+ goto fail;
}
/* Set initial state */
--
1.8.4.2
next prev parent reply other threads:[~2013-11-21 19:05 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-11-21 19:05 [Qemu-devel] [PATCH 0/6] blkdebug/blkverify: Allow command-line configuration Max Reitz
2013-11-21 19:05 ` [Qemu-devel] [PATCH 1/6] blkdebug: Use errp for read_config() Max Reitz
2013-11-21 19:05 ` [Qemu-devel] [PATCH 2/6] blkdebug: Don't require sophisticated filename Max Reitz
2013-11-21 19:05 ` [Qemu-devel] [PATCH 3/6] qemu-option: Add qemu_config_parse_qdict() Max Reitz
2013-11-22 8:08 ` Fam Zheng
2013-11-22 14:05 ` Max Reitz
2013-11-21 19:05 ` Max Reitz [this message]
2013-11-21 19:05 ` [Qemu-devel] [PATCH 5/6] blkdebug: Use command-line in read_config() Max Reitz
2013-11-21 19:05 ` [Qemu-devel] [PATCH 6/6] blkverify: Don't require protocol filename Max Reitz
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1385060754-18821-5-git-send-email-mreitz@redhat.com \
--to=mreitz@redhat.com \
--cc=kwolf@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).