From: Stefan Hajnoczi <stefanha@redhat.com>
To: qemu-devel@nongnu.org
Cc: Peter Maydell <peter.maydell@linaro.org>,
Stefan Hajnoczi <stefanha@redhat.com>,
Markus Armbruster <armbru@redhat.com>,
MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
Subject: [Qemu-devel] [PULL 26/33] block/sheepdog: Propagate errors through connect_to_sdog()
Date: Fri, 23 May 2014 17:41:58 +0200 [thread overview]
Message-ID: <1400859725-31879-27-git-send-email-stefanha@redhat.com> (raw)
In-Reply-To: <1400859725-31879-1-git-send-email-stefanha@redhat.com>
From: Markus Armbruster <armbru@redhat.com>
Cc: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
block/sheepdog.c | 77 ++++++++++++++++++++++++++++++++++++++++----------------
1 file changed, 55 insertions(+), 22 deletions(-)
diff --git a/block/sheepdog.c b/block/sheepdog.c
index 2c3fb01..ff0aa89 100644
--- a/block/sheepdog.c
+++ b/block/sheepdog.c
@@ -526,17 +526,16 @@ static SheepdogAIOCB *sd_aio_setup(BlockDriverState *bs, QEMUIOVector *qiov,
return acb;
}
-static int connect_to_sdog(BDRVSheepdogState *s)
+static int connect_to_sdog(BDRVSheepdogState *s, Error **errp)
{
int fd;
- Error *err = NULL;
if (s->is_unix) {
- fd = unix_connect(s->host_spec, &err);
+ fd = unix_connect(s->host_spec, errp);
} else {
- fd = inet_connect(s->host_spec, &err);
+ fd = inet_connect(s->host_spec, errp);
- if (err == NULL) {
+ if (fd >= 0) {
int ret = socket_set_nodelay(fd);
if (ret < 0) {
error_report("%s", strerror(errno));
@@ -544,10 +543,7 @@ static int connect_to_sdog(BDRVSheepdogState *s)
}
}
- if (err != NULL) {
- qerror_report_err(err);
- error_free(err);
- } else {
+ if (fd >= 0) {
qemu_set_nonblock(fd);
}
@@ -916,10 +912,13 @@ static void co_write_request(void *opaque)
*/
static int get_sheep_fd(BDRVSheepdogState *s)
{
+ Error *local_err = NULL;
int fd;
- fd = connect_to_sdog(s);
+ fd = connect_to_sdog(s, &local_err);
if (fd < 0) {
+ qerror_report_err(local_err);
+ error_free(local_err);
return fd;
}
@@ -1063,14 +1062,17 @@ static int find_vdi_name(BDRVSheepdogState *s, const char *filename,
uint32_t snapid, const char *tag, uint32_t *vid,
bool lock)
{
+ Error *local_err = NULL;
int ret, fd;
SheepdogVdiReq hdr;
SheepdogVdiRsp *rsp = (SheepdogVdiRsp *)&hdr;
unsigned int wlen, rlen = 0;
char buf[SD_MAX_VDI_LEN + SD_MAX_VDI_TAG_LEN];
- fd = connect_to_sdog(s);
+ fd = connect_to_sdog(s, &local_err);
if (fd < 0) {
+ qerror_report_err(local_err);
+ error_free(local_err);
return fd;
}
@@ -1263,12 +1265,15 @@ static int write_object(int fd, char *buf, uint64_t oid, uint8_t copies,
/* update inode with the latest state */
static int reload_inode(BDRVSheepdogState *s, uint32_t snapid, const char *tag)
{
+ Error *local_err = NULL;
SheepdogInode *inode;
int ret = 0, fd;
uint32_t vid = 0;
- fd = connect_to_sdog(s);
+ fd = connect_to_sdog(s, &local_err);
if (fd < 0) {
+ qerror_report_err(local_err);
+ error_free(local_err);
return -EIO;
}
@@ -1436,8 +1441,10 @@ static int sd_open(BlockDriverState *bs, QDict *options, int flags,
s->is_snapshot = true;
}
- fd = connect_to_sdog(s);
+ fd = connect_to_sdog(s, &local_err);
if (fd < 0) {
+ qerror_report_err(local_err);
+ error_free(local_err);
ret = fd;
goto out;
}
@@ -1474,14 +1481,17 @@ out:
static int do_sd_create(BDRVSheepdogState *s, uint32_t *vdi_id, int snapshot)
{
+ Error *local_err = NULL;
SheepdogVdiReq hdr;
SheepdogVdiRsp *rsp = (SheepdogVdiRsp *)&hdr;
int fd, ret;
unsigned int wlen, rlen = 0;
char buf[SD_MAX_VDI_LEN];
- fd = connect_to_sdog(s);
+ fd = connect_to_sdog(s, &local_err);
if (fd < 0) {
+ qerror_report_err(local_err);
+ error_free(local_err);
return fd;
}
@@ -1730,6 +1740,7 @@ out:
static void sd_close(BlockDriverState *bs)
{
+ Error *local_err = NULL;
BDRVSheepdogState *s = bs->opaque;
SheepdogVdiReq hdr;
SheepdogVdiRsp *rsp = (SheepdogVdiRsp *)&hdr;
@@ -1738,8 +1749,10 @@ static void sd_close(BlockDriverState *bs)
DPRINTF("%s\n", s->name);
- fd = connect_to_sdog(s);
+ fd = connect_to_sdog(s, &local_err);
if (fd < 0) {
+ qerror_report_err(local_err);
+ error_free(local_err);
return;
}
@@ -1774,6 +1787,7 @@ static int64_t sd_getlength(BlockDriverState *bs)
static int sd_truncate(BlockDriverState *bs, int64_t offset)
{
+ Error *local_err = NULL;
BDRVSheepdogState *s = bs->opaque;
int ret, fd;
unsigned int datalen;
@@ -1786,8 +1800,10 @@ static int sd_truncate(BlockDriverState *bs, int64_t offset)
return -EINVAL;
}
- fd = connect_to_sdog(s);
+ fd = connect_to_sdog(s, &local_err);
if (fd < 0) {
+ qerror_report_err(local_err);
+ error_free(local_err);
return fd;
}
@@ -1846,6 +1862,7 @@ static void coroutine_fn sd_write_done(SheepdogAIOCB *acb)
/* Delete current working VDI on the snapshot chain */
static bool sd_delete(BDRVSheepdogState *s)
{
+ Error *local_err = NULL;
unsigned int wlen = SD_MAX_VDI_LEN, rlen = 0;
SheepdogVdiReq hdr = {
.opcode = SD_OP_DEL_VDI,
@@ -1856,8 +1873,10 @@ static bool sd_delete(BDRVSheepdogState *s)
SheepdogVdiRsp *rsp = (SheepdogVdiRsp *)&hdr;
int fd, ret;
- fd = connect_to_sdog(s);
+ fd = connect_to_sdog(s, &local_err);
if (fd < 0) {
+ qerror_report_err(local_err);
+ error_free(local_err);
return false;
}
@@ -1885,6 +1904,7 @@ static bool sd_delete(BDRVSheepdogState *s)
*/
static int sd_create_branch(BDRVSheepdogState *s)
{
+ Error *local_err = NULL;
int ret, fd;
uint32_t vid;
char *buf;
@@ -1907,8 +1927,10 @@ static int sd_create_branch(BDRVSheepdogState *s)
DPRINTF("%" PRIx32 " is created.\n", vid);
- fd = connect_to_sdog(s);
+ fd = connect_to_sdog(s, &local_err);
if (fd < 0) {
+ qerror_report_err(local_err);
+ error_free(local_err);
ret = fd;
goto out;
}
@@ -2122,6 +2144,7 @@ static int coroutine_fn sd_co_flush_to_disk(BlockDriverState *bs)
static int sd_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info)
{
+ Error *local_err = NULL;
BDRVSheepdogState *s = bs->opaque;
int ret, fd;
uint32_t new_vid;
@@ -2151,8 +2174,10 @@ static int sd_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info)
datalen = SD_INODE_SIZE - sizeof(s->inode.data_vdi_id);
/* refresh inode. */
- fd = connect_to_sdog(s);
+ fd = connect_to_sdog(s, &local_err);
if (fd < 0) {
+ qerror_report_err(local_err);
+ error_free(local_err);
ret = fd;
goto cleanup;
}
@@ -2249,6 +2274,7 @@ static int sd_snapshot_delete(BlockDriverState *bs,
static int sd_snapshot_list(BlockDriverState *bs, QEMUSnapshotInfo **psn_tab)
{
+ Error *local_err = NULL;
BDRVSheepdogState *s = bs->opaque;
SheepdogReq req;
int fd, nr = 1024, ret, max = BITS_TO_LONGS(SD_NR_VDIS) * sizeof(long);
@@ -2263,8 +2289,10 @@ static int sd_snapshot_list(BlockDriverState *bs, QEMUSnapshotInfo **psn_tab)
vdi_inuse = g_malloc(max);
- fd = connect_to_sdog(s);
+ fd = connect_to_sdog(s, &local_err);
if (fd < 0) {
+ qerror_report_err(local_err);
+ error_free(local_err);
ret = fd;
goto out;
}
@@ -2290,8 +2318,10 @@ static int sd_snapshot_list(BlockDriverState *bs, QEMUSnapshotInfo **psn_tab)
hval = fnv_64a_buf(s->name, strlen(s->name), FNV1A_64_INIT);
start_nr = hval & (SD_NR_VDIS - 1);
- fd = connect_to_sdog(s);
+ fd = connect_to_sdog(s, &local_err);
if (fd < 0) {
+ qerror_report_err(local_err);
+ error_free(local_err);
ret = fd;
goto out;
}
@@ -2341,6 +2371,7 @@ out:
static int do_load_save_vmstate(BDRVSheepdogState *s, uint8_t *data,
int64_t pos, int size, int load)
{
+ Error *local_err = NULL;
bool create;
int fd, ret = 0, remaining = size;
unsigned int data_len;
@@ -2349,8 +2380,10 @@ static int do_load_save_vmstate(BDRVSheepdogState *s, uint8_t *data,
uint32_t vdi_index;
uint32_t vdi_id = load ? s->inode.parent_vdi_id : s->inode.vdi_id;
- fd = connect_to_sdog(s);
+ fd = connect_to_sdog(s, &local_err);
if (fd < 0) {
+ qerror_report_err(local_err);
+ error_free(local_err);
return fd;
}
--
1.9.0
next prev parent reply other threads:[~2014-05-23 15:43 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-23 15:41 [Qemu-devel] [PULL 00/33] Block patches Stefan Hajnoczi
2014-05-23 15:41 ` [Qemu-devel] [PULL 01/33] qemu-iotests: Handle cache mode option in 091 Stefan Hajnoczi
2014-05-23 15:41 ` [Qemu-devel] [PULL 02/33] QemuOpt: add unit tests Stefan Hajnoczi
2014-05-23 15:41 ` [Qemu-devel] [PULL 03/33] qcow2: Fix memory leak in COW error path Stefan Hajnoczi
2014-05-23 15:41 ` [Qemu-devel] [PULL 04/33] aio: Fix use-after-free in cancellation path Stefan Hajnoczi
2014-05-23 15:41 ` [Qemu-devel] [PULL 05/33] iotests: Use _img_info in test 089 Stefan Hajnoczi
2014-05-23 15:41 ` [Qemu-devel] [PULL 06/33] block: Add BlockOpType enum Stefan Hajnoczi
2014-05-23 15:41 ` [Qemu-devel] [PULL 07/33] block: Introduce op_blockers to BlockDriverState Stefan Hajnoczi
2014-05-23 15:41 ` [Qemu-devel] [PULL 08/33] block: Replace in_use with operation blocker Stefan Hajnoczi
2014-05-23 15:41 ` [Qemu-devel] [PULL 09/33] block: Move op_blocker check from block_job_create to its caller Stefan Hajnoczi
2014-05-23 15:41 ` [Qemu-devel] [PULL 10/33] block: Add bdrv_set_backing_hd() Stefan Hajnoczi
2014-05-23 15:41 ` [Qemu-devel] [PULL 11/33] block: Use bdrv_set_backing_hd everywhere Stefan Hajnoczi
2014-05-23 15:41 ` [Qemu-devel] [PULL 12/33] block: Add backing_blocker in BlockDriverState Stefan Hajnoczi
2014-05-23 15:41 ` [Qemu-devel] [PULL 13/33] block: Drop redundant bdrv_refresh_limits Stefan Hajnoczi
2014-05-23 15:41 ` [Qemu-devel] [PULL 14/33] docs: Define refcount_bits value Stefan Hajnoczi
2014-05-23 15:41 ` [Qemu-devel] [PULL 15/33] blockdev: Don't use qerror_report_err() in drive_init() Stefan Hajnoczi
2014-05-23 15:41 ` [Qemu-devel] [PULL 16/33] blockdev: Don't use qerror_report() in do_drive_del() Stefan Hajnoczi
2014-05-23 15:41 ` [Qemu-devel] [PULL 17/33] qemu-nbd: Don't use qerror_report() Stefan Hajnoczi
2014-05-23 15:41 ` [Qemu-devel] [PULL 18/33] block/rbd: Propagate errors to open and create methods Stefan Hajnoczi
2014-05-23 15:41 ` [Qemu-devel] [PULL 19/33] block/ssh: Drop superfluous libssh2_session_last_errno() calls Stefan Hajnoczi
2014-05-23 15:41 ` [Qemu-devel] [PULL 20/33] block/ssh: Propagate errors through check_host_key() Stefan Hajnoczi
2014-05-23 15:41 ` [Qemu-devel] [PULL 21/33] block/ssh: Propagate errors through authenticate() Stefan Hajnoczi
2014-05-23 15:41 ` [Qemu-devel] [PULL 22/33] block/ssh: Propagate errors through connect_to_ssh() Stefan Hajnoczi
2014-05-23 15:41 ` [Qemu-devel] [PULL 23/33] block/ssh: Propagate errors to open and create methods Stefan Hajnoczi
2014-05-23 15:41 ` [Qemu-devel] [PULL 24/33] block/vvfat: Propagate errors through enable_write_target() Stefan Hajnoczi
2014-05-23 15:41 ` [Qemu-devel] [PULL 25/33] block/vvfat: Propagate errors through init_directories() Stefan Hajnoczi
2014-05-23 15:41 ` Stefan Hajnoczi [this message]
2014-05-23 15:41 ` [Qemu-devel] [PULL 27/33] block/sheepdog: Propagate errors through get_sheep_fd() Stefan Hajnoczi
2014-05-23 15:42 ` [Qemu-devel] [PULL 28/33] block/sheepdog: Propagate errors through sd_prealloc() Stefan Hajnoczi
2014-05-23 15:42 ` [Qemu-devel] [PULL 29/33] block/sheepdog: Propagate errors through do_sd_create() Stefan Hajnoczi
2014-05-23 15:42 ` [Qemu-devel] [PULL 30/33] block/sheepdog: Propagate errors through find_vdi_name() Stefan Hajnoczi
2014-05-23 15:42 ` [Qemu-devel] [PULL 31/33] block/sheepdog: Propagate errors to open and create methods Stefan Hajnoczi
2014-05-23 15:42 ` [Qemu-devel] [PULL 32/33] block/sheepdog: Fix silent sd_open(), sd_create() failures Stefan Hajnoczi
2014-05-23 15:42 ` [Qemu-devel] [PULL 33/33] block/sheepdog: Don't use qerror_report() Stefan Hajnoczi
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=1400859725-31879-27-git-send-email-stefanha@redhat.com \
--to=stefanha@redhat.com \
--cc=armbru@redhat.com \
--cc=morita.kazutaka@lab.ntt.co.jp \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
/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).