From nobody Mon Apr 29 01:38:05 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1522730329652290.8506167663829; Mon, 2 Apr 2018 21:38:49 -0700 (PDT) Received: from localhost ([::1]:59506 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f3DiV-00049Q-8z for importer@patchew.org; Tue, 03 Apr 2018 00:38:43 -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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 >=3D start); + + if (offs < start) { + /* This is not a valid return by lseek(). We are safe to just ret= urn + * -EIO in this case, and we'll treat it like D4. */ + return -EIO; + } =20 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 >=3D start); + + if (offs < start) { + /* This is not a valid return by lseek(). We are safe to just ret= urn + * -EIO in this case, and we'll treat it like H4. */ + return -EIO; + } =20 if (offs > start) { /* --=20 2.13.6