Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp1063345pxb; Wed, 6 Apr 2022 07:53:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzxUwWIhTtjAKz+37vtHAqjTjhGKIjhbjB3iXm/cug491Dm33OqWFqz+HmSrREIWqgFPyKS X-Received: by 2002:a17:90b:1d04:b0:1c7:1174:56ae with SMTP id on4-20020a17090b1d0400b001c7117456aemr10263658pjb.153.1649256836882; Wed, 06 Apr 2022 07:53:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649256836; cv=none; d=google.com; s=arc-20160816; b=vA925z2LSj25Ul4/1WNV/cZdY3S9ieiVf4jdjOP2GUe7YHJtrUOj0a16zeOl7+jyL+ DUQEAO+Yv0HyiUqxUgqBPI+Ssz6yF7imil0uEBET3bLxVLcW3pMx6J3Y0xxWYb0jhscF JSBSJi9DivIGDzUHnaumNu+nqtfM/UtYFuSFaThA/Fw+833FtWw4FcO8VvE9jzDI6fGH EOw1/DywaWgeH1N0pQ+GA8KWiLDaJczyuAn/DYSjr6/KswMEJD2HorQzLuzjjj+QCVGz LcqCTbVxzQcVmj8oAaJpV2wcvefk+OsuiulTs1A89Nqt2FRr38dpcT8yza0bOl0Ig2v6 yRXw== 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=sw99ztjTVfq3076AH/eU3ySw4PH/pqMrJBkhwrCqFVHmC8Av+MYPwRe5bPldB0YoG9 IQYIHOWPONJHHbh3BvgXLVg5YhHt/+pOwrxHarONz1Fr6V4qky9txifnjxKARjPWohjc kvDE7uTLkTZamPjfA962e8kRVzsgOiHzSSGQ/Q4EsDawNroOHXjvLN8mFBy0z8+JuxCg u3JmwcVfHXoj5MZ5+8LCCjVqUX4qSaEwgNawiaTYU57K86E9TTeY+s2AK54LlFLQIDw8 PCb3ERTh4XbdTD28w2nyAdRvQQq/jzvkFUwBQLfB37iy17vJFNnWUqTgE9nweVeqfvm3 eZsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=hHffpIUM; 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 l19-20020a170902f69300b001569ad93732si10196062plg.352.2022.04.06.07.53.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 07:53:56 -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=hHffpIUM; 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 071B94D2E4B; Wed, 6 Apr 2022 05:38:02 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1380056AbiDEVgF (ORCPT + 99 others); Tue, 5 Apr 2022 17:36:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52340 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353968AbiDEKKO (ORCPT ); Tue, 5 Apr 2022 06:10:14 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5342EC5588; Tue, 5 Apr 2022 02:56:05 -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 dfw.source.kernel.org (Postfix) with ESMTPS id C5534616E7; Tue, 5 Apr 2022 09:56:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D65C1C385A1; Tue, 5 Apr 2022 09:56:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649152564; bh=XPMpb65O3CeKvKBW3+kH3pERPeRlgpPUhWQrxjl1KbM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hHffpIUMnZo17aLj2W8xxobTWBFAIytQcdiXqeI/nL3D98GvdaOGDge6sNWrxaJBq +giAPicgiPwtENdEMIys3eYbFbok+guariogkw2KmgCwM2UyjFCswU5LG/V9tiYG0y 4KDRZgjZJQ0uHy056Yra2+ojZNAGQAmKK/w7XAhM= 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.15 821/913] ubifs: Rectify space amount budget for mkdir/tmpfile operations Date: Tue, 5 Apr 2022 09:31:23 +0200 Message-Id: <20220405070404.440472442@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070339.801210740@linuxfoundation.org> References: <20220405070339.801210740@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; /*