Bug 282432 - p9fs: wrong name gets deleted
Summary: p9fs: wrong name gets deleted
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: 15.0-CURRENT
Hardware: Any Any
: --- Affects Only Me
Assignee: Mark Johnston
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-10-30 21:48 UTC by Bakul Shah
Modified: 2024-11-07 18:35 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Bakul Shah 2024-10-30 21:48:13 UTC
Simple test (on a p9fs mounted filesystem)

date > foo
ln foo bar
rm bar
ls

And you will see it is file foo that gets deleted, not bar!
This doesn't happen from a linux VM so this is definitely a p9fs problem.
I suspect this has to do with wrong fid (that of foo) being used when the file is being removed.
Comment 1 Mark Johnston freebsd_committer freebsd_triage 2024-11-04 17:28:51 UTC
I made an attempt at fixing this: https://reviews.freebsd.org/D47438

It fixes the example, but more testing would be very appreciated.
Comment 2 Bakul Shah 2024-11-04 17:55:15 UTC
The review says "Just manual testing in bhyve. It's a bit tricky to write regression tests without having a socket-based transport, since that'd make it easy to implement a simple server using contrib/lib9p..."

Wasn't there /sys/dev/virtio/9pnet/ in the original Juniper Networks code? Wouldn't that help with this sort of thing? AFAIK there are at least two servers that implement 9P2000.L: https://github.com/chaos/diod and https://github.com/hugelgupf/p9
Comment 3 Mark Johnston freebsd_committer freebsd_triage 2024-11-04 18:06:41 UTC
(In reply to Bakul Shah from comment #2)
Looking at 9pnet from an old repo, only the virtio transport is implemented.  I want a socket-based transport so that the client and server can run in the same host.  It looks like most of the abstractions needed are there already.
Comment 4 Bakul Shah 2024-11-05 00:26:03 UTC
Verified this bug is fixed. Thanks!
Comment 5 commit-hook freebsd_committer freebsd_triage 2024-11-07 18:31:38 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=1d99e8d9a37e1ba528628186df57b79fe74e196c

commit 1d99e8d9a37e1ba528628186df57b79fe74e196c
Author:     Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2024-11-07 18:23:32 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2024-11-07 18:23:32 +0000

    p9fs: Use UNLINKAT instead of REMOVE to implement removals

    REMOVE doesn't work properly in the face of hard links.  Use UNLINKAT
    instead, which is implemented by qemu and bhyve and lets the client
    specify the name being removed.

    PR:             282432
    Reviewed by:    dfr
    Differential Revision:  https://reviews.freebsd.org/D47438

 sys/fs/p9fs/p9_client.c   | 21 +++++++++++++++++++++
 sys/fs/p9fs/p9_client.h   |  1 +
 sys/fs/p9fs/p9_protocol.h |  2 ++
 sys/fs/p9fs/p9fs_vnops.c  | 21 ++++++++++++++-------
 4 files changed, 38 insertions(+), 7 deletions(-)
Comment 6 Mark Johnston freebsd_committer freebsd_triage 2024-11-07 18:35:12 UTC
Thanks for the report.