From: Viacheslav Dubeyko <slava@dubeyko.com>
To: Hengyu Liang <hengyul@cs.unc.edu>
Cc: glaubitz@physik.fu-berlin.de, frank.li@vivo.com,
linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org
Subject: Re: [PATCH v2] hfs: avoid reusing occupied CNIDs after deletion
Date: Mon, 23 Nov 2026 14:18:05 -0800 [thread overview]
Message-ID: <f9f16109d00dd0caef1bdda38b71ad63e44e78d5.camel@dubeyko.com> (raw)
In-Reply-To: <20261121101929.3395994-1-hengyul@cs.unc.edu>
On Sat, 2026-11-21 at 05:19 -0500, Hengyu Liang wrote:
> Hi Slava,
>
> Thanks for the review. OK to all remarks about empty lines. The other
> points are below; there is one I would like to check with you before
> v3 (the flag).
>
> On Mon, 2026-11-16 at 17:02 -0800, Viacheslav Dubeyko wrote:
> > > +static u32 hfs_brec_cnid(struct hfs_bnode *node, u32 off)
> [...]
> > This function is completely not clear. You try to read the
> > hfs_cat_rec. Simply read it and analyze the record. Now it looks
> > like a
> > dark magic.
>
> OK.
>
> > Is this insert argument used anywhere?
>
> Yes, in the loop below: an added CNID can only raise the maximum, a
> removed one can only lower it.
>
> > > + if (tree->cnid != HFS_CAT_CNID || node->type !=
> > > HFS_NODE_LEAF)
> >
> > I would like to see some inline function with good name for this
> > check.
>
> OK.
>
> > > + if (!cnid)
> >
> > The #0 is reserved CNID. It's not good choice for such check.
>
> OK.
>
> > I assume that we limited by tree's height here. Could we used it
> > instead of infinite loop?
>
> OK.
>
> > I dislike insert like a boolean value. Why do we need to inform
> > this
> > function about insert? Why this function cannot make this decision
> > alone?
>
> OK. In v3 it will run after the record is added or removed, recompute
> the leaf's maximum, and compare it with the old value, so it no
> longer
> needs to know whether a record was added or removed.
>
> > You don't need in done if you are limited by b-tree height.
>
> OK. The loop will still stop early when a node does not change,
> because
> then the nodes above it do not change either.
>
> On Tue, 2026-11-17 at 16:20 -0800, Viacheslav Dubeyko wrote:
> > > + * of an index node. If a child has no max_cnid yet, return the
> > > number of
> > > + * that child in @child instead.
> >
> > Do you mean that we return CNID? I don't quite follow. We always
> > have
> > any CNID in the node that will be maximum one for node. How is it
> > possible "If a child has no max_cnid yet, return the number of that
> > child in @child instead."?
>
> No, @child is a node number, not a CNID, and this only happens for
> index nodes. An index record holds a key and the child's node number,
> but no file or folder CNID, so an index node's max_cnid is the
> largest
> max_cnid among its children. If a child has no cached max_cnid yet
> (for example, it has just been read from disk), the function returns
> that
> child's node number; hfs_btree_max_cnid() computes the child first
> and
> then comes back to the parent. I will make the name and the comment
> clearer.
>
> > If it is the index node, then we don't need to traverse the items.
> > No?
>
> We do need to: each record in an index node points to a child node,
> so the loop goes over those records to find the largest max_cnid
> among
> the children.
>
> > It looks like internal error but not I/O error.
>
> OK, I will return -EFSCORRUPTED.
>
> > The max CNID cannot be lower that HFS_FIRSTUSER_CNID.
> [...]
> > I still don't see a necessity in HFS_BNODE_MAX_CNID flag.
>
> These two are related, so let me answer them together.
>
> max_cnid is not stored on disk, so a node that hfs_bnode_find() has
> just read has no max_cnid yet. For a leaf it could be computed right
> away, but
> an index node needs all nodes below it, so computing it at read time
> would read the whole catalog. That is why the code needs a "not
> computed yet" state.
>
> I can drop the flag and use max_cnid == 0 to mean "not computed yet",
> by starting the computation of each maximum from HFS_FIRSTUSER_CNID -
> 1
> (15) instead of 0, so a computed value is never 0. It has to be 15,
> not
> HFS_FIRSTUSER_CNID: a node without user files or folders (only the
> root
> folder, CNID 2, or only thread records) then gets 15, and on a volume
> without user files the root gets 15, so next_id stays 16 (15 + 1).
> Starting from 16 would give 17 there. Would this work for you?
Yes, I think that "max_cnid == 0" looks better. And we can introduce a
constant HFS_INVALID_CNID == 0 (or something like this).
>
> > We need to have comments at one place for the whole structure. Here
> > it
> > looks not good at all.
>
> OK.
>
> > I still don't see the point why should we change anything here?
>
> Changing `<` to `!=` does not change the result:
> hfs_set_next_unused_CNID() updates next_id with cmpxchg only if
> next_id is still cnid + 1. The `!=` check only skips computing the
> maximum when cnid + 1 > next_id, where nothing would be updated
> anyway. I will drop this change.
>
> > The max_cnid or max_cnid + 1?
>
> max_cnid. hfs_set_next_unused_CNID() adds 1 itself (and uses
> HFS_FIRSTUSER_CNID for anything lower), as the old code expected.
>
>
OK. Let me take another look and double check it when you'll send the
v3 of the patch.
Thanks,
Slava.
prev parent reply other threads:[~2026-11-23 22:18 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-12 11:01 Hengyu Liang
2026-11-12 22:34 ` Viacheslav Dubeyko
2026-11-13 19:14 ` Viacheslav Dubeyko
2026-11-13 19:41 ` Hengyu Liang
2026-11-16 23:21 ` Viacheslav Dubeyko
2026-11-21 10:19 ` Hengyu Liang
2026-11-23 22:08 ` Viacheslav Dubeyko
2026-11-17 1:02 ` Viacheslav Dubeyko
2026-11-18 0:20 ` Viacheslav Dubeyko
2026-11-21 10:19 ` Hengyu Liang
2026-11-23 22:18 ` Viacheslav Dubeyko [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=f9f16109d00dd0caef1bdda38b71ad63e44e78d5.camel@dubeyko.com \
--to=slava@dubeyko.com \
--cc=frank.li@vivo.com \
--cc=glaubitz@physik.fu-berlin.de \
--cc=hengyul@cs.unc.edu \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®