Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1779453imm; Fri, 7 Sep 2018 06:07:53 -0700 (PDT) X-Google-Smtp-Source: ANB0VdaFiJloUuRIMuKMF8H6FXBCKMZjKM65v8JVB2VSfthOr/4hUZ6qJyLMXnAmEhZY7glp4fqu X-Received: by 2002:a63:3c5c:: with SMTP id i28-v6mr8064019pgn.415.1536325672970; Fri, 07 Sep 2018 06:07:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536325672; cv=none; d=google.com; s=arc-20160816; b=wCzw21R1zB/5eYsYivIAIgrotUOhkkvgHNaVAusPozKU1h3QH1dpy2SQ7XFtcyCA7m NOD1zQ9FOrh1lGDylpMfDnNcfLRYAOW/+UFgTgNix7adq7M7VHfHZhYsIll2uJQZJvxW T6EMo5pVue/8+GDwuDgkzQH0VIDike+lge6gppB/CMS3YTFKrwsqgTkjpb1PlrnlarRH foo7Kl6GgFW34X43XyjI0N4QV8i7yU7Fu0tBnpX7pUJIGZCqlG6XDy875/m7bPXD+eJC CeCMeXw2+bOUVD0cwWH4jzWA6FL5wMuWaFETtHHAcLvb/7YPovJMNvTKplu2Lwp4Kext 748A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=YNQlKyHr0znyHwLOn7qCaJpTVBe4vAALyXwbfzu6hoA=; b=gYbDjYzVmuusqchbmmA3ZC8QRecbwnQcMETuWpzbopyIbnxH/zJ6y0RP1opmIaGDEK 7bLMZaSwRHDt4HNSAbTdB4izP+fargJN7pMtXXQ6ExfS3pxWVKv7MuOVN5RZ6aLxrtqG 8kyLVCXVuPXhi5x+xujG0vA4tMcLoqb7RTw5jSfXK+kwRcc08dn3YV9Ulw7vpJa8n8Z6 aNx6ZcoEcREVj4xng4n/FmpHdEchAMgB3EQtGR8Y3TYm/vVn8Kq17/cHC0+tly3X9BEJ N8Dgol/bx/fOJB9/V/eTheBJl+SJJXvJVmqrp66m5qq4ovytC14AZeGt/6kp8m76XYW4 LgBg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 7-v6si8556010pgq.637.2018.09.07.06.07.37; Fri, 07 Sep 2018 06:07:52 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729275AbeIGRTc (ORCPT + 99 others); Fri, 7 Sep 2018 13:19:32 -0400 Received: from metis.ext.pengutronix.de ([85.220.165.71]:46251 "EHLO metis.ext.pengutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729215AbeIGRTb (ORCPT ); Fri, 7 Sep 2018 13:19:31 -0400 Received: from dude.hi.pengutronix.de ([2001:67c:670:100:1d::7]) by metis.ext.pengutronix.de with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1fyG27-0007bt-J5; Fri, 07 Sep 2018 14:38:43 +0200 Received: from sha by dude.hi.pengutronix.de with local (Exim 4.91) (envelope-from ) id 1fyG26-000620-De; Fri, 07 Sep 2018 14:38:42 +0200 From: Sascha Hauer To: linux-mtd@lists.infradead.org Cc: David Gstir , Richard Weinberger , kernel@pengutronix.de, linux-kernel@vger.kernel.org, Sascha Hauer Subject: [PATCH 08/25] ubifs: Store read superblock node Date: Fri, 7 Sep 2018 14:36:29 +0200 Message-Id: <20180907123646.12688-9-s.hauer@pengutronix.de> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180907123646.12688-1-s.hauer@pengutronix.de> References: <20180907123646.12688-1-s.hauer@pengutronix.de> X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::7 X-SA-Exim-Mail-From: sha@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The superblock node is read/modified/written several times throughout the UBIFS code. Instead of reading it from the device each time just keep a copy in memory and write back the modified copy when necessary. This patch helps for authentication support, here we not only have to read the superblock node, but also have to authenticate it, which is easier if we do it once during initialization. Signed-off-by: Sascha Hauer --- fs/ubifs/sb.c | 19 +++++-------------- fs/ubifs/super.c | 8 +------- fs/ubifs/ubifs.h | 3 ++- 3 files changed, 8 insertions(+), 22 deletions(-) diff --git a/fs/ubifs/sb.c b/fs/ubifs/sb.c index cf7ee2880c57..7e08c8143316 100644 --- a/fs/ubifs/sb.c +++ b/fs/ubifs/sb.c @@ -497,7 +497,7 @@ static int validate_sb(struct ubifs_info *c, struct ubifs_sb_node *sup) * code. Note, the user of this function is responsible of kfree()'ing the * returned superblock buffer. */ -struct ubifs_sb_node *ubifs_read_sb_node(struct ubifs_info *c) +static struct ubifs_sb_node *ubifs_read_sb_node(struct ubifs_info *c) { struct ubifs_sb_node *sup; int err; @@ -554,6 +554,8 @@ int ubifs_read_superblock(struct ubifs_info *c) if (IS_ERR(sup)) return PTR_ERR(sup); + c->sup_node = sup; + c->fmt_version = le32_to_cpu(sup->fmt_version); c->ro_compat_version = le32_to_cpu(sup->ro_compat_version); @@ -685,7 +687,6 @@ int ubifs_read_superblock(struct ubifs_info *c) err = validate_sb(c, sup); out: - kfree(sup); return err; } @@ -814,7 +815,7 @@ static int fixup_free_space(struct ubifs_info *c) int ubifs_fixup_free_space(struct ubifs_info *c) { int err; - struct ubifs_sb_node *sup; + struct ubifs_sb_node *sup = c->sup_node; ubifs_assert(c, c->space_fixup); ubifs_assert(c, !c->ro_mount); @@ -825,16 +826,11 @@ int ubifs_fixup_free_space(struct ubifs_info *c) if (err) return err; - sup = ubifs_read_sb_node(c); - if (IS_ERR(sup)) - return PTR_ERR(sup); - /* Free-space fixup is no longer required */ c->space_fixup = 0; sup->flags &= cpu_to_le32(~UBIFS_FLG_SPACE_FIXUP); err = ubifs_write_sb_node(c, sup); - kfree(sup); if (err) return err; @@ -845,7 +841,7 @@ int ubifs_fixup_free_space(struct ubifs_info *c) int ubifs_enable_encryption(struct ubifs_info *c) { int err; - struct ubifs_sb_node *sup; + struct ubifs_sb_node *sup = c->sup_node; if (c->encrypted) return 0; @@ -858,16 +854,11 @@ int ubifs_enable_encryption(struct ubifs_info *c) return -EINVAL; } - sup = ubifs_read_sb_node(c); - if (IS_ERR(sup)) - return PTR_ERR(sup); - sup->flags |= cpu_to_le32(UBIFS_FLG_ENCRYPTION); err = ubifs_write_sb_node(c, sup); if (!err) c->encrypted = 1; - kfree(sup); return err; } diff --git a/fs/ubifs/super.c b/fs/ubifs/super.c index 23e7042666a7..c197492802c2 100644 --- a/fs/ubifs/super.c +++ b/fs/ubifs/super.c @@ -1605,16 +1605,10 @@ static int ubifs_remount_rw(struct ubifs_info *c) goto out; if (c->old_leb_cnt != c->leb_cnt) { - struct ubifs_sb_node *sup; + struct ubifs_sb_node *sup = c->sup_node; - sup = ubifs_read_sb_node(c); - if (IS_ERR(sup)) { - err = PTR_ERR(sup); - goto out; - } sup->leb_cnt = cpu_to_le32(c->leb_cnt); err = ubifs_write_sb_node(c, sup); - kfree(sup); if (err) goto out; } diff --git a/fs/ubifs/ubifs.h b/fs/ubifs/ubifs.h index 306cc7a4f725..93e1c34c097f 100644 --- a/fs/ubifs/ubifs.h +++ b/fs/ubifs/ubifs.h @@ -983,6 +983,7 @@ struct ubifs_debug_info; * struct ubifs_info - UBIFS file-system description data structure * (per-superblock). * @vfs_sb: VFS @struct super_block object + * @sup_node: The super block node as read from the device * * @highest_inum: highest used inode number * @max_sqnum: current global sequence number @@ -1230,6 +1231,7 @@ struct ubifs_debug_info; */ struct ubifs_info { struct super_block *vfs_sb; + struct ubifs_sb_node *sup_node; ino_t highest_inum; unsigned long long max_sqnum; @@ -1664,7 +1666,6 @@ int ubifs_write_master(struct ubifs_info *c); /* sb.c */ int ubifs_read_superblock(struct ubifs_info *c); -struct ubifs_sb_node *ubifs_read_sb_node(struct ubifs_info *c); int ubifs_write_sb_node(struct ubifs_info *c, struct ubifs_sb_node *sup); int ubifs_fixup_free_space(struct ubifs_info *c); int ubifs_enable_encryption(struct ubifs_info *c); -- 2.18.0