From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33321) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yqhuo-0000Ou-GW for qemu-devel@nongnu.org; Fri, 08 May 2015 09:02:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Yqhuk-0006Qj-CN for qemu-devel@nongnu.org; Fri, 08 May 2015 09:02:06 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39195) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yqhuk-0006Qa-4u for qemu-devel@nongnu.org; Fri, 08 May 2015 09:02:02 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t48D21dt014081 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Fri, 8 May 2015 09:02:01 -0400 Message-ID: <554CB3C6.3040506@redhat.com> Date: Fri, 08 May 2015 15:01:58 +0200 From: Max Reitz MIME-Version: 1.0 References: <1431012374-14113-1-git-send-email-pbonzini@redhat.com> <1431012374-14113-2-git-send-email-pbonzini@redhat.com> <554CAFF1.9070308@redhat.com> In-Reply-To: <554CAFF1.9070308@redhat.com> Content-Type: text/plain; charset=iso-8859-15; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH] qemu-nbd: only send a limited number of errno codes on the wire List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paolo Bonzini , qemu-devel@nongnu.org Cc: kwolf@redhat.com On 08.05.2015 14:45, Max Reitz wrote: > On 07.05.2015 17:26, Paolo Bonzini wrote: >> Right now, NBD includes potentially platform-specific error values in >> the wire protocol. >> >> Luckily, most common error values are more or less universal: in >> particular, of all errno values <= 34 (up to ERANGE), they are all >> the same on supported platforms except for 11 (which is EAGAIN on >> Windows and Linux, but EDEADLK on Darwin and the *BSDs). >> >> So, in order to guarantee some portability, only keep a dozen >> possible error codes and squash everything else to EINVAL. >> >> Signed-off-by: Paolo Bonzini >> --- >> nbd.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ >> 1 file changed, 47 insertions(+) >> >> diff --git a/nbd.c b/nbd.c >> index eea8c51..1ad5b66 100644 >> --- a/nbd.c >> +++ b/nbd.c >> @@ -86,6 +86,37 @@ >> #define NBD_OPT_ABORT (2) >> #define NBD_OPT_LIST (3) >> +/* NBD errors are based on errno numbers, so there is a 1:1 mapping, >> + * but only a limited set of errno values is specified in the protocol. >> + * Everything else is squashed to EINVAL. >> + */ >> +static int system_errno_to_nbd_errno(int err) >> +{ >> + switch (err) { >> + case EPERM: >> + return 1; >> + case EIO: >> + return 5; >> + case ENXIO: >> + return 6; >> + case E2BIG: >> + return 7; >> + case ENOMEM: >> + return 12; >> + case EACCES: >> + return 13; >> + case EFBIG: >> + return 27; >> + case ENOSPC: >> + return 28; >> + case EROFS: >> + return 30; >> + case EINVAL: >> + default: >> + return 22; >> + } >> +} >> + >> /* Definitions for opaque data types */ >> typedef struct NBDRequest NBDRequest; >> @@ -856,6 +887,20 @@ ssize_t nbd_receive_reply(int csock, struct >> nbd_reply *reply) >> reply->error = be32_to_cpup((uint32_t*)(buf + 4)); >> reply->handle = be64_to_cpup((uint64_t*)(buf + 8)); >> + /* NBD errors should be universally equal to the corresponding >> + * errno values, check it here. >> + */ >> + QEMU_BUILD_BUG_ON(EPERM != 1); >> + QEMU_BUILD_BUG_ON(EIO != 5); >> + QEMU_BUILD_BUG_ON(ENXIO != 6); >> + QEMU_BUILD_BUG_ON(E2BIG != 7); >> + QEMU_BUILD_BUG_ON(ENOMEM != 12); >> + QEMU_BUILD_BUG_ON(EACCES != 13); >> + QEMU_BUILD_BUG_ON(EINVAL != 22); >> + QEMU_BUILD_BUG_ON(EFBIG != 27); >> + QEMU_BUILD_BUG_ON(ENOSPC != 28); >> + QEMU_BUILD_BUG_ON(EROFS != 30); >> + > > Why no nbd_errno_to_system_errno() function? Oops, I missed v2. Sorry. Max