From patchwork Wed Nov 6 10:14:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukas Czerner X-Patchwork-Id: 1190247 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="HWKxi4gE"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 477Mqc5dyQz9sPk for ; Wed, 6 Nov 2019 21:15:40 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731317AbfKFKPj (ORCPT ); Wed, 6 Nov 2019 05:15:39 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:54970 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1731222AbfKFKPj (ORCPT ); Wed, 6 Nov 2019 05:15:39 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573035338; 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=tASMyTn3iDx6KanL4j5gvaTNnbhhGJNqEPX7SwlHmDM=; b=HWKxi4gEu/2+E5xXNHhezBT//3FauzcPQdKSExvcl/IdnqMtg5Jb+qGAshEPhlAsC6A7iq 0aZn1vjAak01dGT3PRKvUoGMJ6eeUQOLK4W0fMJo0nLYS/8JLFjVq/YtCP9OfqQzZr3luD hEVmuHEAFtWqxQAeWhyIRrLUNl7RMYk= 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-396-FRJK08NUNKKAV7dDpu8DHg-1; Wed, 06 Nov 2019 05:15:37 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5A619107ACC4; Wed, 6 Nov 2019 10:15:36 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.205.19]) by smtp.corp.redhat.com (Postfix) with ESMTP id 440DE19481; Wed, 6 Nov 2019 10:15:35 +0000 (UTC) From: Lukas Czerner To: linux-ext4@vger.kernel.org Cc: Theodore Ts'o , David Howells , Al Viro Subject: [PATCH 12/17] ext4: refactor ext4_remount() Date: Wed, 6 Nov 2019 11:14:52 +0100 Message-Id: <20191106101457.11237-13-lczerner@redhat.com> In-Reply-To: <20191106101457.11237-1-lczerner@redhat.com> References: <20191106101457.11237-1-lczerner@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-MC-Unique: FRJK08NUNKKAV7dDpu8DHg-1 X-Mimecast-Spam-Score: 0 Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Refactor ext4_remount() so that we can parse mount options separately. Signed-off-by: Lukas Czerner --- fs/ext4/super.c | 62 ++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 49 insertions(+), 13 deletions(-) diff --git a/fs/ext4/super.c b/fs/ext4/super.c index 76f7d742de8e..f863fddc3df3 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -5801,8 +5801,10 @@ struct ext4_mount_options { #endif }; -static int ext4_remount(struct super_block *sb, int *flags, char *data) +static int __ext4_remount(struct fs_context *fc, struct super_block *sb, + int *flags) { + struct ext4_fs_context *ctx = fc->fs_private; struct ext4_super_block *es; struct ext4_sb_info *sbi = EXT4_SB(sb); unsigned long old_sb_flags; @@ -5815,10 +5817,6 @@ static int ext4_remount(struct super_block *sb, int *flags, char *data) int i, j; char *to_free[EXT4_MAXQUOTAS]; #endif - char *orig_data = kstrdup(data, GFP_KERNEL); - - if (data && !orig_data) - return -ENOMEM; /* Store the original options */ old_sb_flags = sb->s_flags; @@ -5839,7 +5837,6 @@ static int ext4_remount(struct super_block *sb, int *flags, char *data) if (!old_opts.s_qf_names[i]) { for (j = 0; j < i; j++) kfree(old_opts.s_qf_names[j]); - kfree(orig_data); return -ENOMEM; } } else @@ -5848,10 +5845,10 @@ 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; - if (!parse_apply_options(data, sb, NULL, &journal_ioprio, 1)) { - err = -EINVAL; - goto restore_opts; - } + if (ctx->spec & EXT4_SPEC_JOURNAL_IOPRIO) + journal_ioprio = ctx->journal_ioprio; + + ext4_apply_options(fc, sb); ext4_clamp_want_extra_isize(sb); @@ -6050,8 +6047,6 @@ static int ext4_remount(struct super_block *sb, int *flags, char *data) #endif *flags = (*flags & ~SB_LAZYTIME) | (sb->s_flags & SB_LAZYTIME); - ext4_msg(sb, KERN_INFO, "re-mounted. Opts: %s", orig_data); - kfree(orig_data); return 0; restore_opts: @@ -6073,10 +6068,51 @@ static int ext4_remount(struct super_block *sb, int *flags, char *data) for (i = 0; i < EXT4_MAXQUOTAS; i++) kfree(to_free[i]); #endif - kfree(orig_data); return err; } +static int ext4_remount(struct super_block *sb, int *flags, char *data) +{ + struct ext4_sb_info *sbi = EXT4_SB(sb); + struct ext4_fs_context ctx; + struct fs_context fc; + char *orig_data; + int ret; + + orig_data = kstrdup(data, GFP_KERNEL); + if (data && !orig_data) + return -ENOMEM; + + memset(&fc, 0, sizeof(fc)); + memset(&ctx, 0, sizeof(ctx)); + + fc.fs_private = &ctx; + fc.purpose = FS_CONTEXT_FOR_RECONFIGURE; + fc.s_fs_info = sbi; + + ret = parse_options(&fc, (char *) data); + if (ret < 0) + goto err_out; + + ret = ext4_check_opt_consistency(&fc, sb); + if (ret < 0) + goto err_out; + + ret = __ext4_remount(&fc, sb, flags); + if (ret < 0) + goto err_out; + + ext4_msg(sb, KERN_INFO, "re-mounted. Opts: %s", orig_data); + cleanup_ctx(&ctx); + kfree(orig_data); + return 0; + +err_out: + cleanup_ctx(&ctx); + kfree(orig_data); + return ret; +} + #ifdef CONFIG_QUOTA static int ext4_statfs_project(struct super_block *sb, kprojid_t projid, struct kstatfs *buf)