Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp1403803ybh; Thu, 23 Jul 2020 08:06:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwg6aAwzMDHSQzEaS/tXnJiT0oiVEErXeU0gX3/2QvjSUp6dQ6h1E2M4vpEKfkgdvyGA4dL X-Received: by 2002:a17:906:490c:: with SMTP id b12mr4736254ejq.294.1595516766054; Thu, 23 Jul 2020 08:06:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595516766; cv=none; d=google.com; s=arc-20160816; b=HpQEtq3b5N/Jknl+2mk0cE0Jk34uNFnzHUHHxKEwR2pBtkyAhhXl5C+IAdj2Roxy1Y il/mbDuShiFC0hqFYxhXsw8ZUvPagwNQXZc+9rWVu0n10YqIfVHiAnhJv9Kn6Qk+bzPO Wfder3vlKHuQbv4vr/Y1rtP2WEVm2VofyC9t/Mpvv+yeYkkkYkbM0ytzZ3EeSJ6vpPgl l2dQgBPEeaqHO8WFdkAgCk0LFBidbG8e+QhXVb/lWcZtXvtSOtdnfyQkBASLLV8hMWLL 2TaB1P7RJlZiMa5ZYTDj534uyh1GUzzi7dNscWWKf9BVRA+8Gx/nguGVc5NNE8d+i0eK DYkQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=UHeCrznzqXoe2/XAP4BQ2MEUqBxwRsB0ZsZP/VO7+nE=; b=YfFROI4MWxuHu7Ov1EwsDeY6wt4kW35NVKY4tmRaOcVqtOmCcB0o9cgk9kG3QwYHrp AMiUepTClMXiQ4QCrbesSmL+GxcPtrfuiWeJmxq9xWAUzzLUwWjdwr5/kq6EtkNJTi88 5Z4jPGx+lxyF/Jd2b0HmrnUZNcdevN3LpdSCZEW8/sxeWyz9keGt3u43/uz9G6axDS// VlwyoAqPo7Yf99PjATvj7pECvaPDccfXDJxTmLTxnY35C3be7isQSwkVasUEhh1Q4tud jLBXNwXmFxWQmdk6DRfUuRGSg2Fci+CS1Nwy4Y5t/OpilLrDgrYhr+gEEZ/coW+oqucD wlVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=AJeHkytn; 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 w20si2057137eds.305.2020.07.23.08.05.41; Thu, 23 Jul 2020 08:06:06 -0700 (PDT) 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=AJeHkytn; 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 S1727996AbgGWPFj (ORCPT + 99 others); Thu, 23 Jul 2020 11:05:39 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:37394 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727885AbgGWPFi (ORCPT ); Thu, 23 Jul 2020 11:05:38 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1595516735; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=UHeCrznzqXoe2/XAP4BQ2MEUqBxwRsB0ZsZP/VO7+nE=; b=AJeHkytnK6N5PQM0GwfROCoN7YYnVKWT+xs14PUs1GdjnhyeujdXjjcULVF6EapoCXcEeh Hoxp80or1RMBSQiRxnkruwG/Qwe1P39epaWwbLdSyCJTMbQA2TWdUxxnaXaAz5F8UXU2Lm +KklUMQoGtQ2T/4F/EsF/PjWvp7g6/M= 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-11-tnW97FTbOM2hCrxp3OQlaw-1; Thu, 23 Jul 2020 11:05:31 -0400 X-MC-Unique: tnW97FTbOM2hCrxp3OQlaw-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D62F68AF85E; Thu, 23 Jul 2020 15:05:30 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.194.0]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0DBA6101E59C; Thu, 23 Jul 2020 15:05:29 +0000 (UTC) From: Lukas Czerner To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu Subject: [PATCH] ext4: handle option set by mount flags correctly Date: Thu, 23 Jul 2020 17:05:26 +0200 Message-Id: <20200723150526.19931-1-lczerner@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Currently there is a problem with mount options that can be both set by vfs using mount flags or by a string parsing in ext4. i_version/iversion options gets lost after remount, for example $ mount -o i_version /dev/pmem0 /mnt $ grep pmem0 /proc/self/mountinfo | grep i_version 310 95 259:0 / /mnt rw,relatime shared:163 - ext4 /dev/pmem0 rw,seclabel,i_version $ mount -o remount,ro /mnt $ grep pmem0 /proc/self/mountinfo | grep i_version nolazytime gets ignored by ext4 on remount, for example $ mount -o lazytime /dev/pmem0 /mnt $ grep pmem0 /proc/self/mountinfo | grep lazytime 310 95 259:0 / /mnt rw,relatime shared:163 - ext4 /dev/pmem0 rw,lazytime,seclabel $ mount -o remount,nolazytime /mnt $ grep pmem0 /proc/self/mountinfo | grep lazytime 310 95 259:0 / /mnt rw,relatime shared:163 - ext4 /dev/pmem0 rw,lazytime,seclabel Fix it by applying the SB_LAZYTIME and SB_I_VERSION flags from *flags to s_flags before we parse the option and use the resulting state of the same flags in *flags at the end of successful remount. Signed-off-by: Lukas Czerner --- fs/ext4/super.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/fs/ext4/super.c b/fs/ext4/super.c index 330957ed1f05..caab4c57f909 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -5445,7 +5445,7 @@ static int ext4_remount(struct super_block *sb, int *flags, char *data) { struct ext4_super_block *es; struct ext4_sb_info *sbi = EXT4_SB(sb); - unsigned long old_sb_flags; + unsigned long old_sb_flags, vfs_flags; struct ext4_mount_options old_opts; int enable_quota = 0; ext4_group_t g; @@ -5488,6 +5488,14 @@ static int ext4_remount(struct super_block *sb, int *flags, char *data) if (sbi->s_journal && sbi->s_journal->j_task->io_context) journal_ioprio = sbi->s_journal->j_task->io_context->ioprio; + /* + * Some options can be enabled by ext4 and/or by VFS mount flag + * either way we need to make sure it matches in both *flags and + * s_flags. Copy those selected flags from *flags to s_flags + */ + vfs_flags = SB_LAZYTIME | SB_I_VERSION; + sb->s_flags = (sb->s_flags & ~vfs_flags) | (*flags & vfs_flags); + if (!parse_options(data, sb, NULL, &journal_ioprio, 1)) { err = -EINVAL; goto restore_opts; @@ -5541,9 +5549,6 @@ static int ext4_remount(struct super_block *sb, int *flags, char *data) set_task_ioprio(sbi->s_journal->j_task, journal_ioprio); } - if (*flags & SB_LAZYTIME) - sb->s_flags |= SB_LAZYTIME; - if ((bool)(*flags & SB_RDONLY) != sb_rdonly(sb)) { if (sbi->s_mount_flags & EXT4_MF_FS_ABORTED) { err = -EROFS; @@ -5675,7 +5680,13 @@ static int ext4_remount(struct super_block *sb, int *flags, char *data) } #endif - *flags = (*flags & ~SB_LAZYTIME) | (sb->s_flags & SB_LAZYTIME); + /* + * Some options can be enabled by ext4 and/or by VFS mount flag + * either way we need to make sure it matches in both *flags and + * s_flags. Copy those selected flags from s_flags to *flags + */ + *flags = (*flags & ~vfs_flags) | (sb->s_flags & vfs_flags); + ext4_msg(sb, KERN_INFO, "re-mounted. Opts: %s", orig_data); kfree(orig_data); return 0; -- 2.21.3