Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp630107pxb; Tue, 5 Apr 2022 16:33:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxp1ClmPJ1BTYhCFQ2xU7xoF+6TX9106oSQR5pnTvoI4RhvSRbEJo0yPS6Eba7hLZ7QCmNY X-Received: by 2002:a17:90a:b115:b0:1ca:9d56:24f9 with SMTP id z21-20020a17090ab11500b001ca9d5624f9mr6747024pjq.130.1649201625018; Tue, 05 Apr 2022 16:33:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649201625; cv=none; d=google.com; s=arc-20160816; b=ga7K619CNkSTbzJeI6wGtkVC+DHxMpEHgPsyGCdyRDlAQXajyWsFUJ31xRRea+14xf T1qO5bZKyht42ffc+ylqPRLw72IseJzA/GuFTyEaNtn6RBOMM1kwjrksygc9eVBoNlgU AvKw620Cqc3xoq99yUD7TF7HByLj8efPCe1i++0Cw8qe+8v8aHOLtLTjXIuRQF1cIwBU 7jVTCiIKl5xoVOKgPb1q3N2Z0+aEGui++ihzJxhplvLZUVi0k15iy3MypmumfDtWmneG 9rMoZRO0qwn7bUhQxeHSyLSC6jLi5BLoQbW4MW0UqetQub4iByBljH7CJJfQfp8m/CEB J+jA== 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=J/NROjtySR2mjVynHmDzOxeKcRIum0FEOk5HooTzojk=; b=E+L/a7UWxKCpZzMGU5FbFsrvziO8Ul8PaophzrST0N0hHzp87MMCQLgXzVvRTs64fR h+NiykSZdAjR839QedKyZxLdSvbNmRgVOW/Fatgkm5s9pSaC8u0C1ExtBcBwGuUl1/Rm RsvY5pHh0kMCrX0NSV/6PPSWtg4sknfXU7U0ZGwvA0nDkTURGd96AcXYrpdHQBcrQ6Gu bTGF9oFleqOdHbbKxtBZTMRpnHGEll9Nu7sM/OAsRdgISbjZbGGz7CcufBVjyT+i5oBd A+uOKVnKgPDhZpqqUiLtTtsm0Mt5bIfI7MliYxavUfYSXrVprOP0sA+gE1uuXWIvmBJS YyMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="bv0FrDt/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id q2-20020a17090aa00200b001c5f7c491d4si3577865pjp.166.2022.04.05.16.33.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Apr 2022 16:33:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="bv0FrDt/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 D4916FFFB0; Tue, 5 Apr 2022 16:18:07 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1390821AbiDENnd (ORCPT + 99 others); Tue, 5 Apr 2022 09:43:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37396 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346215AbiDEJXh (ORCPT ); Tue, 5 Apr 2022 05:23:37 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B21E1C8BFC; Tue, 5 Apr 2022 02:13:10 -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 8B4FEB81C15; Tue, 5 Apr 2022 09:13:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C9B57C385D9; Tue, 5 Apr 2022 09:13:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649149987; bh=XPMpb65O3CeKvKBW3+kH3pERPeRlgpPUhWQrxjl1KbM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bv0FrDt/VCjSpmZAv/8eqBnC6coPsVddu1wfyzSzZ5oPfLBbax7IJX9vnLWY0yuNH zJZrnBmHmMTiFv/HMhFu2xPjKe8optD/qPJkuycyve3QmpapYF47bbAceVTdO5peW3 efkS44qQtDaA/D4ymJbH/aCmn4ynwdCgv6F4fg5I= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Zhihao Cheng , Richard Weinberger Subject: [PATCH 5.16 0912/1017] ubifs: Rectify space amount budget for mkdir/tmpfile operations Date: Tue, 5 Apr 2022 09:30:25 +0200 Message-Id: <20220405070421.293866089@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070354.155796697@linuxfoundation.org> References: <20220405070354.155796697@linuxfoundation.org> User-Agent: quilt/0.66 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 commit a6dab6607d4681d227905d5198710b575dbdb519 upstream. 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: Greg Kroah-Hartman --- fs/ubifs/dir.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) --- a/fs/ubifs/dir.c +++ b/fs/ubifs/dir.c @@ -428,15 +428,18 @@ static int ubifs_tmpfile(struct user_nam { 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; 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", @@ -979,7 +982,8 @@ static int ubifs_mkdir(struct user_names 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; /*