Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp1016131imw; Wed, 13 Jul 2022 12:12:07 -0700 (PDT) X-Google-Smtp-Source: AGRyM1s7L/BSSW4prMNxDcTK7v/WMwNLH8TC+DR0iZzDBgcu6PI/sKp/RIMWq2E7EBtFSxd8yySB X-Received: by 2002:a17:906:4794:b0:722:f10e:6240 with SMTP id cw20-20020a170906479400b00722f10e6240mr5212717ejc.704.1657739526886; Wed, 13 Jul 2022 12:12:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657739526; cv=none; d=google.com; s=arc-20160816; b=E4VWbdthR221PEcR3TyGxUREqXqODcrxRGdIHl8mlR0+LqvulKV58astPS7ChAxOGp qkaEvT2Cca7uBh/tl2eokskQ2wm6ckX8EtI83g20mq3YUDMu2foLKJqrAszBt8eAiJtL g+aL7K00XZo2H6kPoDiL5bgnuCb9cd9EFrSZV/FxndLHwPL+c7nSfYtpH6QIBCo00RZx 4LSsznANRoLSWN9YPgGlZn3aP7Z9ShSpejRSuyAYfQEN3FIPKfMU9veTaVhqdHPlTUHx b61cmzPlephg4uXUcSqH33ZtpQaAFoQqpZXydqxcObz5PQc9NWF/c8YDUmqnl1Mi+E27 uF7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent :content-transfer-encoding:references:in-reply-to:date:cc:to:from :subject:message-id; bh=KVfShHbbDg3sT1PkM9k9iBq2T9zIqyKVVq7q9DsCY2U=; b=L/X9qGHH42W9EMyXXaZvG7pub2pnrr8If/1hGjTfOyk5gp7FQfozFrSbNtQA8+DOAq 1UYIOo1EPr0B/uSdGRnbiybItbkzDx7Y1S0w7kmLvGMfFIShGUaTGh2I2gdmRpyKmLJc Tcjo+2kMYlWeQUVbh8WifSqW//rtlk7wAsZtPOV9swNHpQybZ5NdE7Qr5GjYf6EaZKri sVeoRNqoog0F9rLUy43vT22mbxPMlyHu2hTRIzGJwXAaIU6J4rZqMexfc4FS+iiyJTph ea/EejqCKlMbcGFq31MdZB5OdhG2p4RHJlo2/goOUDTx02GBN08g9c3TeeM16ENEo3XU B0Iw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id jg4-20020a170907970400b0072a47b13d67si20221398ejc.582.2022.07.13.12.11.40; Wed, 13 Jul 2022 12:12:06 -0700 (PDT) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236132AbiGMS6y convert rfc822-to-8bit (ORCPT + 99 others); Wed, 13 Jul 2022 14:58:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56314 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230479AbiGMS6x (ORCPT ); Wed, 13 Jul 2022 14:58:53 -0400 Received: from relay3.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C8C9BCE2E for ; Wed, 13 Jul 2022 11:58:50 -0700 (PDT) Received: from omf08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id EB65360B37; Wed, 13 Jul 2022 18:58:49 +0000 (UTC) Received: from [HIDDEN] (Authenticated sender: joe@perches.com) by omf08.hostedemail.com (Postfix) with ESMTPA id 183E120028; Wed, 13 Jul 2022 18:58:48 +0000 (UTC) Message-ID: <4d7e96ac0125bf8296689385f3f9dd54f7e2c0f1.camel@perches.com> Subject: Re: [PATCH 3/6] fs/ntfs3: Refactoring attr_punch_hole to restore after errors From: Joe Perches To: Konstantin Komarov , ntfs3@lists.linux.dev Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Date: Wed, 13 Jul 2022 11:58:48 -0700 In-Reply-To: <33c5b044-23a4-60a6-1649-9e5db228c2f7@paragon-software.com> References: <2101d95b-be41-6e6d-e019-bc70f816b2e8@paragon-software.com> <33c5b044-23a4-60a6-1649-9e5db228c2f7@paragon-software.com> Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 8BIT User-Agent: Evolution 3.44.1-0ubuntu1 MIME-Version: 1.0 X-Spam-Status: No, score=-0.5 required=5.0 tests=BAYES_00,FORGED_SPF_HELO, KHOP_HELO_FCRDNS,SPF_HELO_PASS,SPF_NONE,T_SCC_BODY_TEXT_LINE, UNPARSEABLE_RELAY autolearn=no autolearn_force=no version=3.4.6 X-Stat-Signature: 5i71eabwi3gnjdxdbku1yt9cdkro3i1k X-Rspamd-Server: rspamout01 X-Rspamd-Queue-Id: 183E120028 X-Session-Marker: 6A6F6540706572636865732E636F6D X-Session-ID: U2FsdGVkX18AYEEQZy5oL163g1bCUetolL4AeYrwDHU= X-HE-Tag: 1657738728-702200 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 On Wed, 2022-07-13 at 19:46 +0300, Konstantin Komarov wrote: > Added comments to code > Added new function run_clone to make a copy of run > Added done and undo labels for restoring after errors trivia: > diff --git a/fs/ntfs3/attrib.c b/fs/ntfs3/attrib.c [] > index 7bcae3094712..24d545041787 100644llocate_ex(struct ntfs_sb_info *sbi, struct runs_tree *run, > } > > if (lcn != SPARSE_LCN) { > - mark_as_free_ex(sbi, lcn, clen, trim); > + if (sbi) { > + /* mark bitmap range [lcn + clen) as free and trim clusters. */ presumably the brackets or parentheses [ ) should match [] > @@ -2091,69 +2098,91 @@ int attr_punch_hole(struct ntfs_inode *ni, u64 vbo, u64 bytes, u32 *frame_size) [] > + > + /* Make a hole range (sparse) [vcn1 + zero). */ here too > diff --git a/fs/ntfs3/run.c b/fs/ntfs3/run.c [] > @@ -1157,3 +1157,28 @@ int run_get_highest_vcn(CLST vcn, const u8 *run_buf, u64 *highest_vcn) > *highest_vcn = vcn64 - 1; > return 0; > } > + > +/* > + * run_clone > + * > + * Make a copy of run > + */ > +int run_clone(const struct runs_tree *run, struct runs_tree *new_run) > +{ > + size_t bytes = run->count * sizeof(struct ntfs_run); > + > + if (bytes > new_run->allocated) { > + struct ntfs_run *new_ptr = kvmalloc(bytes, GFP_KERNEL); kvmalloc_array ? > + > + if (!new_ptr) > + return -ENOMEM; > + > + kvfree(new_run->runs); > + new_run->runs = new_ptr; > + new_run->allocated = bytes; > + } > + > + memcpy(new_run->runs, run->runs, bytes); > + new_run->count = run->count; > + return 0; > +}