Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp7926129pxb; Fri, 19 Feb 2021 03:01:46 -0800 (PST) X-Google-Smtp-Source: ABdhPJzUtDtMT55jfJSH3026anrnhMoCRa/VwtrHeWmlkdaa9gIvK/aw6e9GWv2i83LOQ9RWijBN X-Received: by 2002:a17:906:48ca:: with SMTP id d10mr4376319ejt.38.1613732505963; Fri, 19 Feb 2021 03:01:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613732505; cv=none; d=google.com; s=arc-20160816; b=rM7FAM5UOKri5SJgrgUBK5BpTrs509DHOwXVllCZt3U6oM1j1EXcSpQlfNJYpoI8GH pra88is59w9gLmeyM1mpQpVGcW8UD2mMLA262kdfvUN6P//GZu5E+yDCMxMPo2cb8vNL 5blgbTFredkbP702m0gOQuobfom2yio3RsL64rLIXQ6uX6AnGSzt3p4ocYPL+KQug+Lj Wg514wIstNiIOMV2HWM9wJ+UjOzpqbslj/J3w8ogOBEuS1niyPxrG+3iOj3vnSWfeRyj qL4MM8NtXYFretHqqyTPe56t7eGfXUh6Eo0QKaerLTlrDKrnH0UkrbJC0tPKiwv2/+12 ccBQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=X7LMWOkJCMH3WfOoS9JsrRIfV3D5dYTOEERH9KDfO+s=; b=p8NRYiUo1bz7J5povf0ccMLK8VEJnm6pcwwdYH6eFsyv5boYnFT+DLErpwuYENaECa xxWiFEkFC84kk5pAgnsy9ZwpRITkA2BllFq+YIBv0I5XrSc8JxR2Dj60U2oNnj3zM1BS 4dMOspwxO9kc16UujNqmDciO5bXR0FPWsmyd5NxK1oFNK4B/ZqYtUSAnJ/VV4hwJkiGK FnaV8DDTZVmMEQHYE1TKjjBD6ArNfzXBN9At9S5S2c4k3C+5CSHhA12hZfLX7SEQ5oqO zk9nWcBQ0fI2I5w5t3zZY1Ua+FnAvtj+k5DpW+yW1F7bWfCEJgF/opFKcV/a909xR6t6 Z2Pg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=aYXub7bC; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bs1si6085014edb.502.2021.02.19.03.01.16; Fri, 19 Feb 2021 03:01:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=aYXub7bC; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230038AbhBSLBF (ORCPT + 99 others); Fri, 19 Feb 2021 06:01:05 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:29567 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230264AbhBSK6v (ORCPT ); Fri, 19 Feb 2021 05:58:51 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613732244; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=X7LMWOkJCMH3WfOoS9JsrRIfV3D5dYTOEERH9KDfO+s=; b=aYXub7bCcirbhvC00fELRO3CtcRHaHw1FVnw7+fVTvgBligi5rqZHwQeUeU/1e5Ko2JQ2g bd0yk501i8NRK5gGyEtCAFkkLUfBbKo1uXtqRHY2V3E1FcjxwX20wfYU+WP+fzqv8B4ZC3 oPYNyx/lhiEv+kxjcfiOGflDneJrwK0= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-146-0Te4qAuhOoSVeyfPJsARBQ-1; Fri, 19 Feb 2021 05:57:23 -0500 X-MC-Unique: 0Te4qAuhOoSVeyfPJsARBQ-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C1E431005501; Fri, 19 Feb 2021 10:57:21 +0000 (UTC) Received: from work (unknown [10.40.194.236]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6BD6A6268F; Fri, 19 Feb 2021 10:57:17 +0000 (UTC) Date: Fri, 19 Feb 2021 11:57:13 +0100 From: Lukas Czerner To: Alexey Lyashkov Cc: Andreas Dilger , Artem Blagodarenko , linux-ext4@vger.kernel.org, Eric Sandeen Subject: Re: [PATCH v2] mmp: do not use O_DIRECT when working with regular file Message-ID: <20210219105713.uu2mywenytfd2e5j@work> References: <20210212093719.162065-1-lczerner@redhat.com> <20210218095146.265302-1-lczerner@redhat.com> <99A17D19-8764-4027-8B1E-E7ADBE5E2CEE@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <99A17D19-8764-4027-8B1E-E7ADBE5E2CEE@gmail.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org On Fri, Feb 19, 2021 at 01:08:17PM +0300, Alexey Lyashkov wrote: > Andreas, > > What about to disable a O_DIRECT global on any block devices in the e2fsprogs library as this don’t work on 4k disk drives at all ? > Instead of fixing an O_DIRECT access with patches sends early. Why would it not work at all ? This is a fix for a specific problem and I am not currently aware of ony other problems e2fsprogs should have with 4k sector size drives. Do you have a specific problem in mind ? Thanks! -Lukas > > > Alex > > > 19 февр. 2021 г., в 1:20, Andreas Dilger написал(а): > > > > On Feb 18, 2021, at 2:51 AM, Lukas Czerner wrote: > >> > >> Currently the mmp block is read using O_DIRECT to avoid any caching that > >> may be done by the VM. However when working with regular files this > >> creates alignment issues when the device of the host file system has > >> sector size larger than the blocksize of the file system in the file > >> we're working with. > >> > >> This can be reproduced with t_mmp_fail test when run on the device with > >> 4k sector size because the mke2fs fails when trying to read the mmp > >> block. > >> > >> Fix it by disabling O_DIRECT when working with regular files. I don't > >> think there is any risk of doing so since the file system layer, unlike > >> shared block device, should guarantee cache consistency. > >> > >> Signed-off-by: Lukas Czerner > >> Reviewed-by: Eric Sandeen > > > > Reviewed-by: Andreas Dilger > > > >> --- > >> v2: Fix comment - it avoids problems when the sector size is larger not > >> smaller than blocksize > >> > >> lib/ext2fs/mmp.c | 22 +++++++++++----------- > >> 1 file changed, 11 insertions(+), 11 deletions(-) > >> > >> diff --git a/lib/ext2fs/mmp.c b/lib/ext2fs/mmp.c > >> index c21ae272..cca2873b 100644 > >> --- a/lib/ext2fs/mmp.c > >> +++ b/lib/ext2fs/mmp.c > >> @@ -57,21 +57,21 @@ errcode_t ext2fs_mmp_read(ext2_filsys fs, blk64_t mmp_blk, void *buf) > >> * regardless of how the io_manager is doing reads, to avoid caching of > >> * the MMP block by the io_manager or the VM. It needs to be fresh. */ > >> if (fs->mmp_fd <= 0) { > >> + struct stat st; > >> int flags = O_RDWR | O_DIRECT; > >> > >> -retry: > >> + /* > >> + * There is no reason for using O_DIRECT if we're working with > >> + * regular file. Disabling it also avoids problems with > >> + * alignment when the device of the host file system has sector > >> + * size larger than blocksize of the fs we're working with. > >> + */ > >> + if (stat(fs->device_name, &st) == 0 && > >> + S_ISREG(st.st_mode)) > >> + flags &= ~O_DIRECT; > >> + > >> fs->mmp_fd = open(fs->device_name, flags); > >> if (fs->mmp_fd < 0) { > >> - struct stat st; > >> - > >> - /* Avoid O_DIRECT for filesystem image files if open > >> - * fails, since it breaks when running on tmpfs. */ > >> - if (errno == EINVAL && (flags & O_DIRECT) && > >> - stat(fs->device_name, &st) == 0 && > >> - S_ISREG(st.st_mode)) { > >> - flags &= ~O_DIRECT; > >> - goto retry; > >> - } > >> retval = EXT2_ET_MMP_OPEN_DIRECT; > >> goto out; > >> } > >> -- > >> 2.26.2 > >> > > > > > > Cheers, Andreas > > > > > > > > > > >