Message ID | 3f4de192-d3f3-f2b3-2b05-8c1c027d1d8c@paragon-software.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp197554wrn; Wed, 15 Feb 2023 05:44:19 -0800 (PST) X-Google-Smtp-Source: AK7set+G5Oo8eyEZ8ZNybXhrrHc+i4I4fpZACC66DgqtpIBalTp3DcwfriLiq2RzBdcdb8clHJN6 X-Received: by 2002:a05:6a20:4285:b0:bf:8ee2:2009 with SMTP id o5-20020a056a20428500b000bf8ee22009mr3331066pzj.26.1676468659710; Wed, 15 Feb 2023 05:44:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676468659; cv=none; d=google.com; s=arc-20160816; b=M5Yx4NRfwz/cR1ABH9Ww+dZM7ZVgORbJnHzDFB5nJzFlOFfauhwxrCL/H6EDXDvVWO YOXBhZK5K+rW8gx5AkfkWZohfDSCNoH5mc44oSn29M6bLbO9hbABNJd+ZuMnBrwFVTn7 TzYLnXcH2N66p/TIvOCaBQ2CsH2z4mptJ+IkxxjEn1wGpByMid3cBXHCaub8QK6NriWF YO8kUTHvL/5GClFGKAtCz+NMBv4MkSJ+TaY0+FIMXptnuzRZYs7D4sGv7eTaJGtN/vDf 5+Dk88v3raAlYD9eiSd1t2noHlO/EOSLO94l8HWC5HmoNXbi8QAIapzNdVvsS8m0gM2v O7yA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:references :cc:to:from:content-language:subject:user-agent:mime-version:date :message-id:dkim-signature; bh=s+jnBTb+FEAmnBEVyyEk7i0waZIXU0NPfdQERDIaNfE=; b=BMs7qMqiCP1h885qOoDbfhdAe8O7Ux4EPCQk/7/g2PALBDGB2t3NogDk+lE7fho2l0 rxdrG3lJMtCQYG/7nnhNQJAJOlb+px/QzPeaaz30y1aJiypUpRI4VcH/lCWVUDd2pFsA NxXn3VZIu3+JPXwNPdhQFpG6UOlBsoN/s4Db6m7JhSl3oVejiFjGvV05ibiQx+Bec4EK Tzv7NAXd6b4VnGaqtjb19OOUmdsJ9F5wEFnb/3tL/51l7vmvxTNOF1fgmLAqDdNu6pky WsViC+T1J1ry4hYburVwGl4n61W9NAs14I6qwPEhwJgsNBBVrfOYEUrjjUSHh+BzE2yt 0Ayg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@paragon-software.com header.s=mail header.b=ndKFZlp5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=paragon-software.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f5-20020aa79685000000b005a8ee167e52si3087959pfk.325.2023.02.15.05.44.06; Wed, 15 Feb 2023 05:44:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@paragon-software.com header.s=mail header.b=ndKFZlp5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=paragon-software.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230474AbjBONh1 (ORCPT <rfc822;tebrre53rla2o@gmail.com> + 99 others); Wed, 15 Feb 2023 08:37:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54408 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229460AbjBONh0 (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 15 Feb 2023 08:37:26 -0500 Received: from relayaws-01.paragon-software.com (relayaws-01.paragon-software.com [35.157.23.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2B980358D; Wed, 15 Feb 2023 05:37:25 -0800 (PST) Received: from dlg2.mail.paragon-software.com (vdlg-exch-02.paragon-software.com [172.30.1.105]) by relayaws-01.paragon-software.com (Postfix) with ESMTPS id D63352147; Wed, 15 Feb 2023 13:33:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1676467992; bh=s+jnBTb+FEAmnBEVyyEk7i0waZIXU0NPfdQERDIaNfE=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=ndKFZlp5o5+usKaaciH36JgPDyMsCNQzIeMorpXuUXxrHaeCrx5tuzcEccSGTQwZr 8N7sIMjEzZ0wshdQifn3gEbFbZRBqU+RiYSZZgTxpp5qBmEqS+GrRb/6y4p8ZUQJJr el3CtPeW4mvu41Zlz/1+woYx27WOLOdtnDxaaXsE= Received: from [192.168.211.36] (192.168.211.36) by vdlg-exch-02.paragon-software.com (172.30.1.105) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.7; Wed, 15 Feb 2023 16:37:22 +0300 Message-ID: <3f4de192-d3f3-f2b3-2b05-8c1c027d1d8c@paragon-software.com> Date: Wed, 15 Feb 2023 17:37:22 +0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.7.2 Subject: [PATCH 06/11] fs/ntfs3: Undo critial modificatins to keep directory consistency Content-Language: en-US From: Konstantin Komarov <almaz.alexandrovich@paragon-software.com> To: <ntfs3@lists.linux.dev> CC: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>, <linux-fsdevel@vger.kernel.org> References: <d7c91201-5e09-5c06-3283-7887f5a5b7f1@paragon-software.com> In-Reply-To: <d7c91201-5e09-5c06-3283-7887f5a5b7f1@paragon-software.com> Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [192.168.211.36] X-ClientProxiedBy: vdlg-exch-02.paragon-software.com (172.30.1.105) To vdlg-exch-02.paragon-software.com (172.30.1.105) X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757904801215744489?= X-GMAIL-MSGID: =?utf-8?q?1757904801215744489?= |
Series |
fs/ntfs3: Bugfix and refactoring
|
|
Commit Message
Konstantin Komarov
Feb. 15, 2023, 1:37 p.m. UTC
Affect xfstest 320.
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
---
fs/ntfs3/index.c | 30 ++++++++++++++++++++----------
1 file changed, 20 insertions(+), 10 deletions(-)
e = fnd->level - 1 == level ? fnd->de[level] : NULL;
@@ -1814,6 +1815,13 @@ indx_insert_into_buffer(struct ntfs_index *indx,
struct ntfs_inode *ni,
return -ENOMEM;
memcpy(up_e, sp, sp_size);
+ used1 = le32_to_cpu(hdr1->used);
+ hdr1_saved = kmemdup(hdr1, used1, GFP_NOFS);
+ if (!hdr1_saved) {
+ err = -ENOMEM;
+ goto out;
+ }
+
if (!hdr1->flags) {
up_e->flags |= NTFS_IE_HAS_SUBNODES;
up_e->size = cpu_to_le16(sp_size + sizeof(u64));
@@ -1846,7 +1854,7 @@ indx_insert_into_buffer(struct ntfs_index *indx,
struct ntfs_inode *ni,
hdr_insert_head(hdr2, de_t, to_copy);
/* Remove all entries (sp including) from hdr1. */
- used = le32_to_cpu(hdr1->used) - to_copy - sp_size;
+ used = used1 - to_copy - sp_size;
memmove(de_t, Add2Ptr(sp, sp_size), used - le32_to_cpu(hdr1->de_off));
hdr1->used = cpu_to_le32(used);
@@ -1876,8 +1884,6 @@ indx_insert_into_buffer(struct ntfs_index *indx,
struct ntfs_inode *ni,
if (!level) {
/* Insert in root. */
err = indx_insert_into_root(indx, ni, up_e, NULL, ctx, fnd, 0);
- if (err)
- goto out;
} else {
/*
* The target buffer's parent is another index buffer.
@@ -1885,12 +1891,20 @@ indx_insert_into_buffer(struct ntfs_index *indx,
struct ntfs_inode *ni,
*/
err = indx_insert_into_buffer(indx, ni, root, up_e, ctx,
level - 1, fnd);
- if (err)
- goto out;
+ }
+
+ if (err) {
+ /*
+ * Undo critical operations.
+ */
+ indx_mark_free(indx, ni, new_vbn >> indx->idx2vbn_bits);
+ memcpy(hdr1, hdr1_saved, used1);
+ indx_write(indx, ni, n1, 0);
}
out:
kfree(up_e);
+ kfree(hdr1_saved);
return err;
}
@@ -1949,16 +1963,12 @@ int indx_insert_entry(struct ntfs_index *indx,
struct ntfs_inode *ni,
*/
err = indx_insert_into_root(indx, ni, new_de, fnd->root_de, ctx,
fnd, undo);
- if (err)
- goto out;
} else {
/*
* Found a leaf buffer, so we'll insert the new entry into it.
*/
err = indx_insert_into_buffer(indx, ni, root, new_de, ctx,
fnd->level - 1, fnd);
- if (err)
- goto out;
}
out:
diff --git a/fs/ntfs3/index.c b/fs/ntfs3/index.c index 9fefeac5fe7e..5d1ec0124137 100644 --- a/fs/ntfs3/index.c +++ b/fs/ntfs3/index.c @@ -1778,10 +1778,11 @@ indx_insert_into_buffer(struct ntfs_index *indx, struct ntfs_inode *ni, struct indx_node *n1 = fnd->nodes[level]; struct INDEX_HDR *hdr1 = &n1->index->ihdr; struct INDEX_HDR *hdr2; - u32 to_copy, used; + u32 to_copy, used, used1; CLST new_vbn; __le64 t_vbn, *sub_vbn; u16 sp_size; + void *hdr1_saved = NULL; /* Try the most easy case. */