From patchwork Tue Apr 3 04:37:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Cody X-Patchwork-Id: 10320549 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 0B00A60532 for ; Tue, 3 Apr 2018 04:38:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DD78E2893A for ; Tue, 3 Apr 2018 04:38:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D1F332896B; Tue, 3 Apr 2018 04:38:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 200392893A for ; Tue, 3 Apr 2018 04:38:30 +0000 (UTC) Received: from localhost ([::1]:59506 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f3DiH-00049Q-Na for patchwork-qemu-devel@patchwork.kernel.org; Tue, 03 Apr 2018 00:38:29 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57646) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f3DhU-0003iB-D7 for qemu-devel@nongnu.org; Tue, 03 Apr 2018 00:37:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f3DhT-0006gu-Jn for qemu-devel@nongnu.org; Tue, 03 Apr 2018 00:37:40 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:51636 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1f3DhP-0006cv-53; Tue, 03 Apr 2018 00:37:35 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2A9548182D0A; Tue, 3 Apr 2018 04:37:30 +0000 (UTC) Received: from localhost (ovpn-121-230.rdu2.redhat.com [10.10.121.230]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 090C3D7DFB; Tue, 3 Apr 2018 04:37:26 +0000 (UTC) From: Jeff Cody To: qemu-devel@nongnu.org Date: Tue, 3 Apr 2018 00:37:26 -0400 Message-Id: X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Tue, 03 Apr 2018 04:37:30 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Tue, 03 Apr 2018 04:37:30 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'jcody@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH for-2.12] block: handle invalid lseek returns gracefully X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, qemu-block@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP In commit 223a23c198787328ae75bc65d84edf5fde33c0b6, we implemented a workaround in the gluster driver to handle invalid values returned for SEEK_DATA or SEEK_HOLE. In some instances, these same invalid values can be seen in the posix file handler as well - for example, it has been reported on FUSE gluster mounts. Calling assert() for these invalid values is overly harsh; we can safely return -EIO and allow this case to be treated as a "learned nothing" case (e.g., D4 / H4, as commented in the code). This patch does the same thing that 223a23c198787 did for gluster.c, except in file-posix.c Signed-off-by: Jeff Cody Reviewed-by: Eric Blake --- block/file-posix.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/block/file-posix.c b/block/file-posix.c index d7fb772c14..a2f6d8a8c8 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -2114,7 +2114,12 @@ static int find_allocation(BlockDriverState *bs, off_t start, if (offs < 0) { return -errno; /* D3 or D4 */ } - assert(offs >= start); + + if (offs < start) { + /* This is not a valid return by lseek(). We are safe to just return + * -EIO in this case, and we'll treat it like D4. */ + return -EIO; + } if (offs > start) { /* D2: in hole, next data at offs */ @@ -2146,7 +2151,12 @@ static int find_allocation(BlockDriverState *bs, off_t start, if (offs < 0) { return -errno; /* D1 and (H3 or H4) */ } - assert(offs >= start); + + if (offs < start) { + /* This is not a valid return by lseek(). We are safe to just return + * -EIO in this case, and we'll treat it like H4. */ + return -EIO; + } if (offs > start) { /*