On 06.03.2017 21:09, Eric Blake wrote: > On 03/06/2017 01:54 PM, Max Reitz wrote: >> Add missing error messages for the drivers I am comfortable to do this >> in. >> >> Signed-off-by: Max Reitz <mre...@redhat.com> >> --- >> block/file-posix.c | 8 +++++++- >> block/qcow2.c | 2 ++ >> block/qed.c | 4 +++- >> block/raw-format.c | 2 ++ >> 4 files changed, 14 insertions(+), 2 deletions(-) >> >> diff --git a/block/file-posix.c b/block/file-posix.c >> index 9d2bea730d..553213221c 100644 >> --- a/block/file-posix.c >> +++ b/block/file-posix.c >> @@ -1341,20 +1341,26 @@ static int raw_truncate(BlockDriverState *bs, >> int64_t offset, Error **errp) >> { >> BDRVRawState *s = bs->opaque; >> struct stat st; >> + int ret; >> >> if (fstat(s->fd, &st)) { >> - return -errno; >> + ret = -errno; >> + error_setg_errno(errp, -ret, "Failed to fstat() the file"); >> + return ret; >> } >> >> if (S_ISREG(st.st_mode)) { >> if (ftruncate(s->fd, offset) < 0) { >> + /* The generic error message will be fine */ >> return -errno; > > Relying on a generic error message in the caller is awkward. I see it as > evidence of a partial conversion if we have an interface that requires a > return of a negative errno value to make up for when errp is not set.
I'm not sure what you mean by this exactly. I can agree that it's not nice within a single driver. But I think it's fine to have some drivers that generate an Error object and others that do not, as long as the generic interface (bdrv_truncate()) masks this behavior. > I > know you aren't comfortable converting all drivers, but for the drivers > you do convert, I'd rather guarantee that ALL errors set errp. Can do, I just felt bad that it be would exactly the same as the message that would be generated in bdrv_truncate() anyway. Max
signature.asc
Description: OpenPGP digital signature