From patchwork Mon Jan 16 08:55:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13102751 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 61BC2C67871 for ; Mon, 16 Jan 2023 08:55:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7AA626B0072; Mon, 16 Jan 2023 03:55:44 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 733B46B0073; Mon, 16 Jan 2023 03:55:44 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5D3466B0074; Mon, 16 Jan 2023 03:55:44 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 4411B6B0073 for ; Mon, 16 Jan 2023 03:55:44 -0500 (EST) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 1E49D407B4 for ; Mon, 16 Jan 2023 08:55:44 +0000 (UTC) X-FDA: 80360054208.03.9B72705 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf08.hostedemail.com (Postfix) with ESMTP id 4A3D6160011 for ; Mon, 16 Jan 2023 08:55:42 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b="ax/Y5gnT"; dmarc=none; spf=none (imf08.hostedemail.com: domain of BATV+12421fe7f975503e585d+7085+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+12421fe7f975503e585d+7085+infradead.org+hch@bombadil.srs.infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1673859342; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=NG71ox6jr7uM23QDAMDsMfdxiN0WqWQj6pY4BZkkyg4=; b=lZst0jCEEn4i2Dae2Veiv/s3dr2BQoXkZ0uHXaUtn01RLSGMqxBfU/tlRM32j6WkmwPahz rcf/3WkbQ9w1A0jQ5gkIZRSNSWgOR7XuASAHmWGvHSS7M7iwgNik6W2v4EnwHiq7nmoZw3 CrWkqTeHj1+VUEmorX+QXH69wQtxuow= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b="ax/Y5gnT"; dmarc=none; spf=none (imf08.hostedemail.com: domain of BATV+12421fe7f975503e585d+7085+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+12421fe7f975503e585d+7085+infradead.org+hch@bombadil.srs.infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1673859342; a=rsa-sha256; cv=none; b=4f2p8goq6k8dWIqmM4uIFG8Gu2PAGvhzTt1GkMeXsT+TIdwFcM9HaI5cmjfzyQq4cKuMHd O6jYzdba4L/QJPwuIkUyQOPpry1pzR64Il4ia7y2uBBSARhqkG86m+Ml2+WF7IIhQ91W9g DXTakXUpBwyd60jbxzxNp5JG9E89TO4= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=NG71ox6jr7uM23QDAMDsMfdxiN0WqWQj6pY4BZkkyg4=; b=ax/Y5gnTZrhv4w+jf2OeQVm0tO ApYJIKsK4ZXfMVwKWlqPdLSJGP7kZIKwE+8CcUbfwwIAFByrMjNSd07pUOBcF66nJ5xWCREc2zMkU 6mQdASNdx+VRTkGlDR6nv34V1Gyn0I0mgWr5vC6NPNwqutc4UvBh0Fclq2irNimI4eewwgg36uQdO fLLkCZXLsoD2eFF6L1iPPsq0srwwA50/WBOJGtJgd6NxY3jjsggeAISiUmyxXvl/WudhRuyFHtfm1 mUmQWnGtNpkbvWi694jhOU5G5hCEQcsB1/CbOSDSPOS+AuNO46i3WVwUrCXrGG3oKZbpzYuFdcpMd vHS2daEQ==; Received: from [2001:4bb8:19a:2039:c63c:c37c:1cda:3fb2] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1pHLH8-009EfR-M6; Mon, 16 Jan 2023 08:55:31 +0000 From: Christoph Hellwig To: Andrew Morton , Mark Fasheh , Joel Becker , Joseph Qi , Evgeniy Dushistov , "Matthew Wilcox (Oracle)" Cc: ocfs2-devel@oss.oracle.com, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 2/6] minix: fix error handling in minix_set_link Date: Mon, 16 Jan 2023 09:55:19 +0100 Message-Id: <20230116085523.2343176-3-hch@lst.de> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230116085523.2343176-1-hch@lst.de> References: <20230116085523.2343176-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 4A3D6160011 X-Stat-Signature: khze44ns89xshpamtoyxbc7gebpzzd1j X-HE-Tag: 1673859342-197519 X-HE-Meta: U2FsdGVkX1+MyPZhpb2ZqGGFn60nwqOgRqub16Kc7OxegaDJTC6l64XtpBew+gzUKIjxyUWBDyKSycKWDGmQ8eX0XS+wC3J++8GCyKEHXCUnVsuB1w5OdeKP3DmcYdp3r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szQwwmBP7E= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: If minix_prepare_chunk fails, updating c/mtime and marking the dir inode dirty is wrong, as the inode hasn't been modified. Also propagate the error to the caller. Note that this moves the dir_put_page call later, but that matches other uses of this helper in the directory code. Signed-off-by: Christoph Hellwig --- fs/minix/dir.c | 23 ++++++++++++----------- fs/minix/minix.h | 3 ++- fs/minix/namei.c | 8 +++++--- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/fs/minix/dir.c b/fs/minix/dir.c index a8e76284cb71ec..c9a3d520b72671 100644 --- a/fs/minix/dir.c +++ b/fs/minix/dir.c @@ -410,8 +410,8 @@ int minix_empty_dir(struct inode * inode) } /* Releases the page */ -void minix_set_link(struct minix_dir_entry *de, struct page *page, - struct inode *inode) +int minix_set_link(struct minix_dir_entry *de, struct page *page, + struct inode *inode) { struct inode *dir = page->mapping->host; struct minix_sb_info *sbi = minix_sb(dir->i_sb); @@ -420,20 +420,21 @@ void minix_set_link(struct minix_dir_entry *de, struct page *page, int err; lock_page(page); - err = minix_prepare_chunk(page, pos, sbi->s_dirsize); - if (err == 0) { - if (sbi->s_version == MINIX_V3) - ((minix3_dirent *) de)->inode = inode->i_ino; - else - de->inode = inode->i_ino; - err = dir_commit_chunk(page, pos, sbi->s_dirsize); - } else { + if (err) { unlock_page(page); + goto out_put_page; } - dir_put_page(page); + if (sbi->s_version == MINIX_V3) + ((minix3_dirent *)de)->inode = inode->i_ino; + else + de->inode = inode->i_ino; + err = dir_commit_chunk(page, pos, sbi->s_dirsize); dir->i_mtime = dir->i_ctime = current_time(dir); mark_inode_dirty(dir); +out_put_page: + dir_put_page(page); + return err; } struct minix_dir_entry * minix_dotdot (struct inode *dir, struct page **p) diff --git a/fs/minix/minix.h b/fs/minix/minix.h index 20217336802570..8f7a636bd1b241 100644 --- a/fs/minix/minix.h +++ b/fs/minix/minix.h @@ -69,7 +69,8 @@ extern int minix_add_link(struct dentry*, struct inode*); extern int minix_delete_entry(struct minix_dir_entry*, struct page*); extern int minix_make_empty(struct inode*, struct inode*); extern int minix_empty_dir(struct inode*); -extern void minix_set_link(struct minix_dir_entry*, struct page*, struct inode*); +int minix_set_link(struct minix_dir_entry *de, struct page *page, + struct inode *inode); extern struct minix_dir_entry *minix_dotdot(struct inode*, struct page**); extern ino_t minix_inode_by_name(struct dentry*); diff --git a/fs/minix/namei.c b/fs/minix/namei.c index 8afdc408ca4fd5..82d46c28f01b01 100644 --- a/fs/minix/namei.c +++ b/fs/minix/namei.c @@ -223,7 +223,9 @@ static int minix_rename(struct user_namespace *mnt_userns, new_de = minix_find_entry(new_dentry, &new_page); if (!new_de) goto out_dir; - minix_set_link(new_de, new_page, old_inode); + err = minix_set_link(new_de, new_page, old_inode); + if (err) + goto out_dir; new_inode->i_ctime = current_time(new_inode); if (dir_de) drop_nlink(new_inode); @@ -240,10 +242,10 @@ static int minix_rename(struct user_namespace *mnt_userns, mark_inode_dirty(old_inode); if (dir_de) { - minix_set_link(dir_de, dir_page, new_dir); + err = minix_set_link(dir_de, dir_page, new_dir); inode_dec_link_count(old_dir); } - return 0; + return err; out_dir: if (dir_de) {