Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp781639pxb; Tue, 12 Apr 2022 13:18:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxe+dUixAdIFwALadSn8nBSKcaQE7VX5RjEll/53gDklTiR4pbHcIV3RiVz2XIL+2OUMUuf X-Received: by 2002:a65:5847:0:b0:39d:904e:f5d6 with SMTP id s7-20020a655847000000b0039d904ef5d6mr4645451pgr.31.1649794689030; Tue, 12 Apr 2022 13:18:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649794689; cv=none; d=google.com; s=arc-20160816; b=yBjepq7BOcerTNakglLs7IMptDVg4SpEsyJ2LsUeK9uWzwUWkQMVJSWjtgmna34Uhi b/Jf1rfa1GweLyHmDonDjPDtAZQyKaVZPLjxMakn8K+MXXGY/81M839atSiWfzZbYjK9 bDxt4bLzHn3lzOygunadUNLA+MU4HhkQJcJ/ZNoYUEnb2YLwEOv0Y+a7ONEX+aViaOGD CzYyoDLX1dMtJ+LVhRNzvEh8moWdL8QhNg9YOwdNyruvHIqRaPlMiFK6Dk1z3PTkmDQW ef/iMurYN2znI9Wz8cZMFq2fpiO7/xJPu+eR/i/ZbKVF8mP1eDvKr4W67ZLkGB9gGKcb vOSQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=2a4k2qLLNaosWKlBdedv8vDO3dYxgEkvFOFRGI1pJYE=; b=VR6lRCB3uIRfkp6B6e+DP447EVrVAZOW7ZjRr6/ZSsIQE2v1tgvyZYXIkK/E0+7UHf K29PxQgjbnygqXGSByihjuyAIJ1EC/M8ymnMhcUiIzkwc0eqAXjG0K/uYJJC0CGY5DNw r4WHgG9bSK4wF7OWliiCmIa8heBHvHm1jUzLzYu+HdDgn3BJ/TNSZ6DowtWEwWgvUWnz i2jDbV1IU9mX9X5wE9lMbktJLG3tImE2tKtvCJqWhvgYueKuR3vJumXHVljBrDwN2SPl AOAInS5qZz9LUDnaUmOcUs/plRCfZMsdFLduXKY3T/45qrxQfb9cA5bn2c3dYVNG99xN 7jDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=fwUDimW7; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id 207-20020a6302d8000000b0038295fbcb98si3659088pgc.247.2022.04.12.13.18.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Apr 2022 13:18:09 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=fwUDimW7; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 712888C7F0; Tue, 12 Apr 2022 13:01:32 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348913AbiDLGf1 (ORCPT + 99 others); Tue, 12 Apr 2022 02:35:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50660 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348898AbiDLGfZ (ORCPT ); Tue, 12 Apr 2022 02:35:25 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 194D535864; Mon, 11 Apr 2022 23:33:09 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 94E8CB81B41; Tue, 12 Apr 2022 06:33:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A09D5C385A6; Tue, 12 Apr 2022 06:33:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649745186; bh=L2IsNl0bmms7Q59edkGIyCctQprb8/wC5LLuVDxZR3o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fwUDimW77uCuf+kTIXmaGs5s/I++d1ZhBkAp9Krur5FyAkX1LEeMKmSRWQQ7EPbA+ zNX6sYMkHTD69sffbvLBd+tBWqA1C4Gf8FLfT5+5hpiUpeGIFEzWH5kUZsBfza+IQW WxohcZ+5jDVY6OZjR4yhBNTz6hEgvEmMMn8wOSEQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Zhihao Cheng , Richard Weinberger , Sasha Levin Subject: [PATCH 5.10 001/171] ubifs: Rectify space amount budget for mkdir/tmpfile operations Date: Tue, 12 Apr 2022 08:28:12 +0200 Message-Id: <20220412062927.915976662@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220412062927.870347203@linuxfoundation.org> References: <20220412062927.870347203@linuxfoundation.org> User-Agent: quilt/0.66 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Zhihao Cheng [ Upstream commit a6dab6607d4681d227905d5198710b575dbdb519 ] UBIFS should make sure the flash has enough space to store dirty (Data that is newer than disk) data (in memory), space budget is exactly designed to do that. If space budget calculates less data than we need, 'make_reservation()' will do more work(return -ENOSPC if no free space lelf, sometimes we can see "cannot reserve xxx bytes in jhead xxx, error -28" in ubifs error messages) with ubifs inodes locked, which may effect other syscalls. A simple way to decide how much space do we need when make a budget: See how much space is needed by 'make_reservation()' in ubifs_jnl_xxx() function according to corresponding operation. It's better to report ENOSPC in ubifs_budget_space(), as early as we can. Fixes: 474b93704f32163 ("ubifs: Implement O_TMPFILE") Fixes: 1e51764a3c2ac05 ("UBIFS: add new flash file system") Signed-off-by: Zhihao Cheng Signed-off-by: Richard Weinberger Signed-off-by: Sasha Levin --- fs/ubifs/dir.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/fs/ubifs/dir.c b/fs/ubifs/dir.c index 5daffd46369d..9257ee893bdb 100644 --- a/fs/ubifs/dir.c +++ b/fs/ubifs/dir.c @@ -353,15 +353,18 @@ static int do_tmpfile(struct inode *dir, struct dentry *dentry, { struct inode *inode; struct ubifs_info *c = dir->i_sb->s_fs_info; - struct ubifs_budget_req req = { .new_ino = 1, .new_dent = 1}; + struct ubifs_budget_req req = { .new_ino = 1, .new_dent = 1, + .dirtied_ino = 1}; struct ubifs_budget_req ino_req = { .dirtied_ino = 1 }; struct ubifs_inode *ui, *dir_ui = ubifs_inode(dir); int err, instantiated = 0; struct fscrypt_name nm; /* - * Budget request settings: new dirty inode, new direntry, - * budget for dirtied inode will be released via writeback. + * Budget request settings: new inode, new direntry, changing the + * parent directory inode. + * Allocate budget separately for new dirtied inode, the budget will + * be released via writeback. */ dbg_gen("dent '%pd', mode %#hx in dir ino %lu", @@ -949,7 +952,8 @@ static int ubifs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode) struct ubifs_inode *dir_ui = ubifs_inode(dir); struct ubifs_info *c = dir->i_sb->s_fs_info; int err, sz_change; - struct ubifs_budget_req req = { .new_ino = 1, .new_dent = 1 }; + struct ubifs_budget_req req = { .new_ino = 1, .new_dent = 1, + .dirtied_ino = 1}; struct fscrypt_name nm; /* -- 2.35.1