diff mbox

[1/4] block: Add special error code for wrong format

Message ID 1355580573-19323-2-git-send-email-sw@weilnetz.de
State Superseded
Headers show

Commit Message

Stefan Weil Dec. 15, 2012, 2:09 p.m. UTC
The block drivers normally return -errno for typical errors.
There is no appropriate error code for "wrong format", so
use a special error code which does not conflict with system
error codes.

Signed-off-by: Stefan Weil <sw@weilnetz.de>
---
 block.h |    7 +++++++
 1 file changed, 7 insertions(+)

Comments

Stefan Hajnoczi Dec. 18, 2012, 2:34 p.m. UTC | #1
On Sat, Dec 15, 2012 at 03:09:30PM +0100, Stefan Weil wrote:
> The block drivers normally return -errno for typical errors.
> There is no appropriate error code for "wrong format", so
> use a special error code which does not conflict with system
> error codes.

ENOTTY is used when something is of the wrong type.  Since the name
"ENOTTY" is not clear, defining a new error code makes sense though.

Stefan
Kevin Wolf Jan. 17, 2013, 12:01 p.m. UTC | #2
Am 15.12.2012 15:09, schrieb Stefan Weil:
> The block drivers normally return -errno for typical errors.
> There is no appropriate error code for "wrong format", so
> use a special error code which does not conflict with system
> error codes.
> 
> Signed-off-by: Stefan Weil <sw@weilnetz.de>
> ---
>  block.h |    7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/block.h b/block.h
> index 893448a..829e18b 100644
> --- a/block.h
> +++ b/block.h
> @@ -90,6 +90,13 @@ typedef struct BlockDevOps {
>  #define BDRV_SECTOR_SIZE   (1ULL << BDRV_SECTOR_BITS)
>  #define BDRV_SECTOR_MASK   ~(BDRV_SECTOR_SIZE - 1)
>  
> +/* The block drivers normally return -errno for typical errors.
> + * There is no appropriate error code for "wrong format", so
> + * use a special error code which does not conflict with system
> + * error codes.
> + */
> +#define BDRV_WRONG_FORMAT  INT_MIN

I think it would be better to use the E* format and a positive number so
that it's obvious that it's meant to be used in -errno returns.

Also, I would consider moving it to qemu-common.h where other errno
values are defined that may be missing on some systems, so that
everything stays in one place and we won't define overlapping codes:

#if !defined(ENOTSUP)
#define ENOTSUP 4096
#endif
#if !defined(ECANCELED)
#define ECANCELED 4097
#endif

This sounds like a good addition in the same place would be:

#define EBDRV_WRONG_FORMAT 4098

Or just use EINVAL or ENOTTY like Stefan suggested.

Kevin
diff mbox

Patch

diff --git a/block.h b/block.h
index 893448a..829e18b 100644
--- a/block.h
+++ b/block.h
@@ -90,6 +90,13 @@  typedef struct BlockDevOps {
 #define BDRV_SECTOR_SIZE   (1ULL << BDRV_SECTOR_BITS)
 #define BDRV_SECTOR_MASK   ~(BDRV_SECTOR_SIZE - 1)
 
+/* The block drivers normally return -errno for typical errors.
+ * There is no appropriate error code for "wrong format", so
+ * use a special error code which does not conflict with system
+ * error codes.
+ */
+#define BDRV_WRONG_FORMAT  INT_MIN
+
 typedef enum {
     BDRV_ACTION_REPORT, BDRV_ACTION_IGNORE, BDRV_ACTION_STOP
 } BlockErrorAction;