Skip to content

Conversation

@phlogistonjohn
Copy link
Collaborator

Fixes: #1088

I've been meaning to look at this for a long time. Thanks for providing the extra motivation to work on it.

First, fix a few things in the lib that the fstest from Golang digs up.

Then implement fscompat.go a file providing a MountWrapper type that implements fs.FS, as well as private types that implement fs.File, fs.FileInfo, fs.ReadDirFile, and fs.DirEntry.

The new wrapper classes sit between the Go stdlib and the native CephFS
focused types we provide. Ideally, some of our types would be directly
compatible with the fs interfaces but in many cases our code predates
io/fs. I hope we consider the io/fs use case for any new types added to
the cephfs subpackage in the future - and possibly make compatible
types. But for now I think this is sufficent - especially since the
"native" types support things like writing and other ceph focused
operations.

Checklist

  • Added tests for features and functional changes
  • Public functions and types are documented
  • Standard formatting is applied to Go code
  • Is this a new API? Added a new file that begins with //go:build ceph_preview
  • Ran make api-update to record new APIs

New or infrequent contributors may want to review the go-ceph Developer's Guide including the section on how we track API Status and the API Stability Plan.

The go-ceph project uses mergify. View the mergify command guide for information on how to interact with mergify. Add a comment with @Mergifyio rebase to rebase your PR when github indicates that the PR is out of date with the base branch.

@phlogistonjohn
Copy link
Collaborator Author

@Mergifyio rebase

@mergify
Copy link

mergify bot commented Mar 25, 2025

rebase

✅ Branch has been successfully rebased

@phlogistonjohn phlogistonjohn force-pushed the jjm-cephfs-io-fs branch 2 times, most recently from 9f3527f to 50b1f55 Compare March 25, 2025 17:44
@phlogistonjohn phlogistonjohn marked this pull request as ready for review March 27, 2025 12:19
@phlogistonjohn phlogistonjohn added the API This PR includes a change to the public API of a go-ceph package label Mar 27, 2025
@phlogistonjohn
Copy link
Collaborator Author

@ansiwen @anoopcs9 I would appreciate reviews before the next release. Even if we miss the window due to feedback it would be nice to try and aim for the 15th.

Copy link
Collaborator

@ansiwen ansiwen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general LGTM, just some curious remarks.

// under-documented. They mainly seem to try and enforce "clean" paths.
// look for them and reject them here because ceph libs won't reject on
// its own
if strings.HasPrefix(name, "/") ||
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how performance critical the Open functions is, but there is certainly room for improvement instead of iterating the string several times with a single RE like

var invalidPathPattern = regexp.MustCompile(`^/|/\.{0,2}/|/\.$`)

But as I said, probably premature optimization.

return nil, &fs.PathError{Op: "open", Path: name, Err: errInvalid}
}

d, err := mw.mount.OpenDir(name)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, we can assume this is as efficient as using a stat first to check if it is a directory?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that is a pretty fast operation, but if we find that this limits performance later we can come back and fix it because how we determine to open the "file" is not part of the interface and just up to our implementation.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's also a preference of mine to avoid "look before you leap" calls when doing fs ops because of race conditions. It is probably silly in this case, but there's the chance a file could be replaced between a stat and open and this is potentially racy. Using the "system call" directly and handling errors from that call is a habit I have developed when doing FS related work.

@mergify mergify bot force-pushed the jjm-cephfs-io-fs branch from 50b1f55 to 9e2ad03 Compare April 10, 2025 14:11
@mergify
Copy link

mergify bot commented Apr 10, 2025

This pull request has been removed from the queue for the following reason: pull request dequeued.

Pull request #1089 has been dequeued. The pull request rule doesn't match anymore. The following conditions don't match anymore:

  • status-success=check
  • status-success=test-suite (octopus)
  • status-success=test-suite (pacific)
  • status-success=test-suite (quincy)
  • status-success=test-suite (reef)
  • status-success=test-suite (squid)
  • any of:
    • all of:
      • label=no-API
    • all of:
      • #approved-reviews-by>=2
    • all of:
      • updated-at<10 days ago
  • any of: [🔀 queue conditions]
    • all of: [📌 queue conditions of queue default]
      • any of: [🛡 GitHub branch protection]
        • check-neutral = check
        • check-skipped = check
        • check-success = check
      • any of: [🛡 GitHub branch protection]
        • check-neutral = test-suite (octopus)
        • check-skipped = test-suite (octopus)
        • check-success = test-suite (octopus)
      • any of: [🛡 GitHub branch protection]
        • check-neutral = test-suite (pacific)
        • check-skipped = test-suite (pacific)
        • check-success = test-suite (pacific)
      • any of: [🛡 GitHub branch protection]
        • check-neutral = test-suite (quincy)
        • check-skipped = test-suite (quincy)
        • check-success = test-suite (quincy)
      • any of: [🛡 GitHub branch protection]
        • check-neutral = test-suite (reef)
        • check-skipped = test-suite (reef)
        • check-success = test-suite (reef)
      • any of: [🛡 GitHub branch protection]
        • check-neutral = test-suite (squid)
        • check-skipped = test-suite (squid)
        • check-success = test-suite (squid).

You should look at the reason for the failure and decide if the pull request needs to be fixed or if you want to requeue it.
If you do update this pull request, it will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue instead, you can requeue the pull request, without updating it, by posting a @mergifyio requeue comment.

@phlogistonjohn
Copy link
Collaborator Author

@Mergifyio rebase

@mergify
Copy link

mergify bot commented Apr 11, 2025

rebase

✅ Branch has been successfully rebased

@phlogistonjohn
Copy link
Collaborator Author

@anoopcs9 do you think you find time to look at this prior to the 15th? Thanks!

@anoopcs9
Copy link
Collaborator

@Mergifyio rebase

Make the Directory objects support multiple calls to Close() by nil'ing
out the dir.dir property after closing the ceph object. Then subsequent
calls to Directory methods need to check that dir.dir is not nil.
Add a wrapper for EBADF to mimic the system behavior of trying to
operate on a closed directory FD.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
Make calling file Read and Write calls a no-op when called with a zero
length byte slice and prevent a panic when trying to get the address of
the array for these slices.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
Add a MountWrapper type that implements fs.FS, as well as private types
that implement fs.File, fs.FileInfo, fs.ReadDirFile, and fs.DirEntry.

The new wrapper classes sit between the Go stdlib and the native CephFS
focused types we provide. Ideally, some of our types would be directly
compatible with the fs interfaces but in many cases our code predates
io/fs. I hope we consider the io/fs use case for any new types added to
the cephfs subpackage in the future - and possibly make compatible
types. But for now I think this is sufficent - especially since the
"native" types support things like writing and other ceph focused
operations.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
Signed-off-by: John Mulligan <jmulligan@redhat.com>
Signed-off-by: John Mulligan <jmulligan@redhat.com>
@mergify
Copy link

mergify bot commented Apr 15, 2025

rebase

✅ Branch has been successfully rebased

@mergify mergify bot merged commit 8952e53 into ceph:master Apr 15, 2025
15 checks passed
@phlogistonjohn phlogistonjohn deleted the jjm-cephfs-io-fs branch May 5, 2025 11:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

API This PR includes a change to the public API of a go-ceph package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cephfs: go io/fs interface

3 participants