With soft updates, unlink, rmdir and rename set IN_CHANGE on the inode
when the directory entry is removed, and handle_workitem_remove() sets
it again when the deferred link count decrement is done. The second
update makes ctime change after the operation has returned, which is not
POSIX compliant and breaks e.g. git's check of the shallow file.
Set IN_MODIFIED instead of IN_CHANGE in handle_workitem_remove(), so
that the new link count is still written but the timestamps are not
touched. The decrement is not visible to stat(2), which reports
i_effnlink.
1a75045196a2, which added the immediate update, kept the deferred one
for programs that read the disk, like dump(8). dump -L reads a
snapshot, and the suspension for a snapshot does not complete until all
soft updates work is done, so a snapshot never sees the state between
the unlink and the deferred decrement.
As a consequence, the deferred decrement no longer bumps i_modrev. This
matches ctime, and the NFS change attribute, which is derived from
i_modrev, stops changing behind the client's back. The fb_modrev check
in handle_complete_freeblocks() is not affected, since it is only
reached for partial truncations done by softdep_journal_freeblocks(),
which ffs_truncate() has not called since 621a274820c8.
Reported by: jrtc27
Fixes: 1a75045196a2 ("After the unlink() of one name of a file with multiple links, ...")Details
Diff Detail
- Repository
- rG FreeBSD src repository
- Lint
Lint Skipped - Unit
Tests Skipped
Event Timeline
Huh, interesting. So the conclusion is that this historic practice was in fact not an appropriate thing to be doing, rather than that Git should accommodate it?
(My reading of 1a75045196a26c2dd00a03a3d6d231dd5b422a9b's commit message was that this was, at least historically, regarded as a feature for dump?)
At lea
At least this is my opinion.
Also, suppose that we do not enable SU. Then the behavior is compliant, and we update ctime right on unlink or rename. I do not see why SU should do it differently.
Kirk proposal was transposed, lets only update on SU workitem completion, he did not yet read the patch I think.
I think POSIX would then require stat of the file to wait until SU is done, due to:
An implementation may update timestamps that are marked for update immediately, or it may update such timestamps periodically. At the point in time when an update occurs, any marked timestamps shall be set to the current time and the update marks shall be cleared. All timestamps that are marked for update shall be updated when the file ceases to be open by any process or before a fstat(), fstatat(), fsync(), futimens(), lstat(), stat(), utimensat(), or utimes() is successfully performed on the file.
(https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/V1_chap04.html#tag_04_12)
Git certainly wouldn't be happy with the ctime changing after a stat due to SU.
I do not read the cited text as the requirement that update must happen after SU resolved all dependencies. In fact, it is arguably in reverse, due to the 'fstat etc' language, and the fact that we allow the userspace to observe other effects of unlink.
POSIX says, for rename(2):
Upon successful completion, rename() shall mark for update the last data modification and last file status change timestamps of the parent directory of each file.
Therefore, once rename returns, the file is marked for update wrt ctime. Then, the previous quote says that, before a stat of that file completes, any marked for update timestamps must be updated. Putting the two together, the ctime must show as updated if you stat after a rename. The only question is whether you can have *additional* updates to ctime stemming from things the kernel decided to do that don't modify the inode, and even if you can, whether it's a good idea to expose that to userspace.
So I do not understand what is the disagreement, and whether there is any disagreement at all. Rename or unlink must make ctime update (in term of our VFS, ctime must be updated on unlink or rename before the vnode is unlocked). Then additional updates of timestamps must not occur, which is what my patch provides.
I think I don't understand what you meant by your previous message then. But based on this one alone, it sounds like we are in strong agreement.
Looks good. Some suggested changes:
- See inline comment.
- As Jessica said, 1a75045196a2 mentioned the second update was kept for dump(8), so I'd mention that commit in the commit message, explaining that in fact the change here is harmless because dump(8) never uses di_nlink so not having an up-to-date di_nlink on dump because ctime was not updated is not a concern.
- POSIX may actually allow an update basically at any point in time and for any function as long as it's documented (see XBD 4.12). So I'd either just remove the "is not POSIX compliant and" part in the commit message, or explicitly say that is was not POSIX-compliant because the second update was not documented.
- Not sure I understand the end of the commit message: "handle_complete_freeblocks() is affected only when a removal completes between a truncation and its freeblks processing; the link count change does not affect the block count, so applying the i_blocks correction in that case is correct.". In any case, that i_blocks correction will lead to applying IN_CHANGE. I haven't dug deeply but a priori it looks like setting IN_CHANGE can be replaced with IN_MODIFIED as well (dump(8) does not restore di_blocks either).
| sys/ufs/ffs/ffs_softdep.c | ||
|---|---|---|
| 10142–10143 | In passing, I'd remove this entirely, as this is redundant with the same call above. | |