mount: report a read-only mount root that does not exist as not found, not as the create error (#12799)

This commit is contained in:
Carlos Leyva authored and GitHub committed 2026-11-19 19:45:41 -08:00
1 parent f2acfb7be4
commit 2e4be5e25e
2 files changed
+62

No files matched your search

+3
View File
@@ -296,6 +296,9 @@ func ensureMountRootDirectory(ctx context.Context, filerClient filer_pb.FilerCli
// than match the error.
entry, _, _, lookupErr := filer_pb.GetEntry(ctx, filerClient, mountRootPath)
if lookupErr != nil {
if errors.Is(lookupErr, filer_pb.ErrNotFound) {
return fmt.Errorf("mount root %s does not exist and could not be created: %w", mountRoot, err)
}
return err
}
return mountRootMustBeDirectory(mountRoot, entry)
+59
View File
@@ -10,6 +10,7 @@ import (
"os"
"path/filepath"
"strconv"
"strings"
"testing"
"github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
@@ -269,6 +270,8 @@ type mountRootFiler struct {
lookups int
creates []*filer_pb.CreateEntryRequest
updates int
lookupErrors []error
createError error
}
func (f *mountRootFiler) WithFilerClient(_ bool, fn func(filer_pb.SeaweedFilerClient) error) error {
@@ -279,6 +282,9 @@ func (f *mountRootFiler) GetDataCenter() string { return "" }
func (f *mountRootFiler) LookupDirectoryEntry(_ context.Context, _ *filer_pb.LookupDirectoryEntryRequest, _ ...grpc.CallOption) (*filer_pb.LookupDirectoryEntryResponse, error) {
f.lookups++
if f.lookups <= len(f.lookupErrors) && f.lookupErrors[f.lookups-1] != nil {
return nil, f.lookupErrors[f.lookups-1]
}
if f.entry == nil {
return nil, status.Error(codes.NotFound, filer_pb.ErrNotFound.Error())
}
@@ -290,6 +296,9 @@ func (f *mountRootFiler) CreateEntry(_ context.Context, in *filer_pb.CreateEntry
if f.beforeCreate != nil {
f.beforeCreate(f)
}
if f.createError != nil {
return nil, f.createError
}
failed := func(code filer_pb.FilerError, text string) (*filer_pb.CreateEntryResponse, error) {
resp := &filer_pb.CreateEntryResponse{Error: text}
if !f.textOnlyErrors {
@@ -324,6 +333,56 @@ func (f *mountRootFiler) UpdateEntry(_ context.Context, in *filer_pb.UpdateEntry
return &filer_pb.UpdateEntryResponse{}, nil
}
func TestEnsureMountRootDirectoryReadOnlyFailures(t *testing.T) {
denied := status.Error(codes.PermissionDenied, "fixture read-only grant")
unavailable := status.Error(codes.Unavailable, "fixture lookup unavailable")
directory := &filer_pb.Entry{Name: "data", IsDirectory: true,
Attributes: &filer_pb.FuseAttributes{FileMode: uint32(os.ModeDir | 0750), Uid: 1234},
Extended: map[string][]byte{"fixture": []byte("preserved")}}
cases := []struct {
name string
entry *filer_pb.Entry
lookupErrors []error
createRace bool
wantErr error
wantMissing bool
wantLookups, wantCreates int
}{
{name: "existing read-only directory needs no write", entry: directory, wantLookups: 1},
{name: "missing read-only root is diagnosed", wantErr: denied, wantMissing: true, wantLookups: 2, wantCreates: 1},
{name: "initial lookup failure is preserved", lookupErrors: []error{unavailable}, wantErr: unavailable, wantLookups: 1},
{name: "failed readback preserves create error", lookupErrors: []error{nil, unavailable}, wantErr: denied, wantLookups: 2, wantCreates: 1},
{name: "directory created during refused create survives", createRace: true, wantLookups: 2, wantCreates: 1},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
client := &mountRootFiler{entry: tc.entry, lookupErrors: tc.lookupErrors, createError: denied}
if tc.createRace {
client.beforeCreate = func(f *mountRootFiler) { f.entry = proto.Clone(directory).(*filer_pb.Entry) }
}
err := ensureMountRootDirectory(context.Background(), client, "/buckets/a/data")
if !errors.Is(err, tc.wantErr) {
t.Fatalf("error = %v, want wrapped %v", err, tc.wantErr)
}
missing := err != nil && strings.Contains(err.Error(), "mount root /buckets/a/data does not exist and could not be created")
if missing != tc.wantMissing {
t.Fatalf("missing-root diagnostic = %v, want %v: %v", missing, tc.wantMissing, err)
}
if client.lookups != tc.wantLookups || len(client.creates) != tc.wantCreates || client.updates != 0 {
t.Fatalf("lookups/creates/updates = %d/%d/%d, want %d/%d/0", client.lookups, len(client.creates), client.updates, tc.wantLookups, tc.wantCreates)
}
for _, create := range client.creates {
if !create.OExcl || create.Directory != "/buckets/a" || create.Entry.Name != "data" || !create.Entry.IsDirectory {
t.Fatalf("unexpected root create contract: %v", create)
}
}
if (tc.entry != nil || tc.createRace) && !proto.Equal(client.entry, directory) {
t.Fatal("existing root attributes changed")
}
})
}
}
func Test_ensureMountRootDirectory(t *testing.T) {
bucket := func() *filer_pb.Entry {
return &filer_pb.Entry{