aboutsummaryrefslogtreecommitdiff
path: root/nbd/common.c
diff options
context:
space:
mode:
authorEric Blake <eblake@redhat.com>2017-10-27 12:40:27 +0200
committerEric Blake <eblake@redhat.com>2017-10-30 21:07:21 +0100
commitdd6894404947d39a724ea265389fe0f2d6d5ecb7 (patch)
treef53596145ed5c1ee00c82ce4bdd96eea4691c67e /nbd/common.c
parente7a78d0eff820b56d33be31af1bb49e2948374fd (diff)
nbd: Move nbd_errno_to_system_errno() to public header
This is needed in preparation for structured reply handling, as we will be performing the translation from NBD error to system errno value higher in the stack at block/nbd-client.c. Signed-off-by: Eric Blake <eblake@redhat.com> Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> Message-Id: <20171027104037.8319-3-eblake@redhat.com>
Diffstat (limited to 'nbd/common.c')
-rw-r--r--nbd/common.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/nbd/common.c b/nbd/common.c
index 7456021f7e..593904f148 100644
--- a/nbd/common.c
+++ b/nbd/common.c
@@ -18,6 +18,7 @@
#include "qemu/osdep.h"
#include "qapi/error.h"
+#include "trace.h"
#include "nbd-internal.h"
/* Discard length bytes from channel. Return -errno on failure and 0 on
@@ -171,3 +172,36 @@ const char *nbd_err_lookup(int err)
return "<unknown>";
}
}
+
+
+int nbd_errno_to_system_errno(int err)
+{
+ int ret;
+ switch (err) {
+ case NBD_SUCCESS:
+ ret = 0;
+ break;
+ case NBD_EPERM:
+ ret = EPERM;
+ break;
+ case NBD_EIO:
+ ret = EIO;
+ break;
+ case NBD_ENOMEM:
+ ret = ENOMEM;
+ break;
+ case NBD_ENOSPC:
+ ret = ENOSPC;
+ break;
+ case NBD_ESHUTDOWN:
+ ret = ESHUTDOWN;
+ break;
+ default:
+ trace_nbd_unknown_error(err);
+ /* fallthrough */
+ case NBD_EINVAL:
+ ret = EINVAL;
+ break;
+ }
+ return ret;
+}