Received: from eggs.gnu.org ([2001:4830:134:3::10]:42058) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yqf99-00089s-IL for qemu-devel@nongnu.org; Fri, 08 May 2015 06:04:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Yqf95-0003OS-Bl for qemu-devel@nongnu.org; Fri, 08 May 2015 06:04:43 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50804) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yqf95-0003Nq-4Q for qemu-devel@nongnu.org; Fri, 08 May 2015 06:04:39 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (Postfix) with ESMTPS id A6D138E670 for ; Fri, 8 May 2015 10:04:38 +0000 (UTC) From: Markus Armbruster References: <1431012374-14113-1-git-send-email-pbonzini@redhat.com> <1431012374-14113-2-git-send-email-pbonzini@redhat.com> <87a8xfr2ig.fsf@blackfin.pond.sub.org> <554C740A.9050705@redhat.com> <87ioc3ifdu.fsf@blackfin.pond.sub.org> <554C8494.7070609@redhat.com> Date: Fri, 08 May 2015 12:04:35 +0200 In-Reply-To: <554C8494.7070609@redhat.com> (Paolo Bonzini's message of "Fri, 08 May 2015 11:40:36 +0200") Message-ID: <873837gzbg.fsf@blackfin.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain 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 Cc: kwolf@redhat.com, qemu-devel@nongnu.org, mreitz@redhat.com Paolo Bonzini writes: > On 08/05/2015 11:32, Markus Armbruster wrote: >>>>> +/* 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. >>>>> + */ >>>> >>>> Is the protocol defined anywhere? >> >> https://github.com/yoe/nbd/blob/master/doc/proto.txt >> >> All it has on the error code is this paragraph: >> >> The reply contains three fields: a 32 bit magic number ('magic'), a >> 32 bit error code ('error'; 0, unless an error occurred in which >> case it is the errno of the error on the server side), and the same >> 64 bit handle that the corresponding request had in its 'handle' >> field. In case the reply is sent in response to a read request and >> the error field is 0 (zero), the reply header is immediately >> followed by request.len bytes of data. >> >> Could you update it to document the errno compatibility issues, and >> recommended practice (i.e. this patch's)? > > Yes, I've sent a patch yesterday. Excellent! >>>>> +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; >>>>> + } >>>>> +} >>>>> + >>>> >>>> This maps recognized OS errnos to NBD errnos. The latter are literals. >>>> >>>>> /* 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); >>>>> + >>>> >>>> This checks that the mapping above is the identify function for all the >>>> recognized NBD errnos. Why is that necessary? >> >> Still curious. Explain, and earn my R-by :) > > Because block/nbd.c expects host errnos, and I was too lazy to add a > switch and a nbd_errno_to_system_errno function. But Eric pointed out > that Hurd has weird errnos (the low bits match, but there's a 0x10 > subsystem code in bits 24-31) so I'll add it. Oww! That's going to hurd... >>>> Same literals as above. Violates DRY. I don't mind all that much, but >>>> wonder whether we could at least do the checking next to >>>> system_errno_to_nbd_errno(). >> >> Could we? > > Yes, s/could/should/. Also, should have added RFC to the patch. Thanks!