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

login
register
mail settings
Submitter Stefan Weil
Date Dec. 15, 2012, 2:09 p.m.
Message ID <1355580573-19323-2-git-send-email-sw@weilnetz.de>
Download mbox | patch
Permalink /patch/206620/
State Superseded
Headers show

Comments

Stefan Weil - Dec. 15, 2012, 2:09 p.m.
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(+)
Stefan Hajnoczi - Dec. 18, 2012, 2:34 p.m.
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.
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

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;