diff --git a/cmd/gateway.go b/cmd/gateway.go index 5cd16dce9157..702bf723373c 100644 --- a/cmd/gateway.go +++ b/cmd/gateway.go @@ -158,12 +158,16 @@ func gateway(c *cli.Context) error { if err != nil { return err } - - if _, err := jfsGateway.GetBucketInfo(context.Background(), minio.MinioMetaBucket); errors.As(err, &minio.BucketNotFound{}) { - if err := jfsGateway.MakeBucketWithLocation(context.Background(), minio.MinioMetaBucket, minio.BucketOptions{}); err != nil { - logger.Fatalf("init MinioMetaBucket error %s: %s", minio.MinioMetaBucket, err) + if c.IsSet("read-only") { + os.Setenv("JUICEFS_META_READ_ONLY", "1") + } else { + if _, err := jfsGateway.GetBucketInfo(context.Background(), minio.MinioMetaBucket); errors.As(err, &minio.BucketNotFound{}) { + if err := jfsGateway.MakeBucketWithLocation(context.Background(), minio.MinioMetaBucket, minio.BucketOptions{}); err != nil { + logger.Fatalf("init MinioMetaBucket error %s: %s", minio.MinioMetaBucket, err) + } } } + args := []string{"server", "--address", listenAddr, "--anonymous"} if c.Bool("no-banner") { args = append(args, "--quiet") diff --git a/go.mod b/go.mod index 76736ebb5662..b9c79db1d13c 100644 --- a/go.mod +++ b/go.mod @@ -253,7 +253,7 @@ require ( xorm.io/builder v0.3.7 // indirect ) -replace github.com/minio/minio v0.0.0-20210206053228-97fe57bba92c => github.com/juicedata/minio v0.0.0-20240612084555-8a33dba0f571 +replace github.com/minio/minio v0.0.0-20210206053228-97fe57bba92c => github.com/juicedata/minio v0.0.0-20240719032536-5d15c7c0135d replace github.com/hanwen/go-fuse/v2 v2.1.1-0.20210611132105-24a1dfe6b4f8 => github.com/juicedata/go-fuse/v2 v2.1.1-0.20240425033113-7c40cb5eb3e9 diff --git a/go.sum b/go.sum index 59146873a380..b675f8be1585 100644 --- a/go.sum +++ b/go.sum @@ -511,8 +511,8 @@ github.com/juicedata/gogfapi v0.0.0-20230626071140-fc28e5537825 h1:7KrwI4HPqvNLK github.com/juicedata/gogfapi v0.0.0-20230626071140-fc28e5537825/go.mod h1:Ho5G4KgrgbMKW0buAJdOmYoJcOImkzznJQaLiATrsx4= github.com/juicedata/huaweicloud-sdk-go-obs v3.22.12-0.20230228031208-386e87b5c091+incompatible h1:2/ttSmYoX+QMegpNyAJR0Y6aHcVk57F7RJit5xN2T/s= github.com/juicedata/huaweicloud-sdk-go-obs v3.22.12-0.20230228031208-386e87b5c091+incompatible/go.mod h1:Ukwa8ffRQLV6QRwpqGioPjn2Wnf7TBDA4DbennDOqHE= -github.com/juicedata/minio v0.0.0-20240612084555-8a33dba0f571 h1:usZ1RJ9AssiJxSVRibh2mbQ5cI9FuSbkXJTiweL3hxk= -github.com/juicedata/minio v0.0.0-20240612084555-8a33dba0f571/go.mod h1:UOWyfa3ls1tnpJrNw2yzGqfrwM4nzsZq/qz+zd6H+/Q= +github.com/juicedata/minio v0.0.0-20240719032536-5d15c7c0135d h1:rDGD7VqSTs2gTr8HNFgnit1xrUPUWl6v+5HsgL2QrYM= +github.com/juicedata/minio v0.0.0-20240719032536-5d15c7c0135d/go.mod h1:UOWyfa3ls1tnpJrNw2yzGqfrwM4nzsZq/qz+zd6H+/Q= github.com/juicedata/mpb/v7 v7.0.4-0.20231024073412-2b8d31be510b h1:0/6suPNZnrOlRlBaU/Bnitu8HiKkkLSzQhHbwQ9AysM= github.com/juicedata/mpb/v7 v7.0.4-0.20231024073412-2b8d31be510b/go.mod h1:NXGsfPGx6G2JssqvEcULtDqUrxuuYs4llpv8W6ZUpzk= github.com/juju/ratelimit v1.0.2 h1:sRxmtRiajbvrcLQT7S+JbqU0ntsb9W2yhSdNN8tWfaI= diff --git a/pkg/gateway/gateway.go b/pkg/gateway/gateway.go index e9f641c33923..dd10c89bacd5 100644 --- a/pkg/gateway/gateway.go +++ b/pkg/gateway/gateway.go @@ -218,9 +218,11 @@ func (n *jfsObjects) MakeBucketWithLocation(ctx context.Context, bucket string, } } eno := n.fs.Mkdir(mctx, n.path(bucket), 0777, n.gConf.Umask) - metadata := minio.NewBucketMetadata(bucket) - if err := metadata.Save(ctx, n); err != nil { - return err + if eno == 0 { + metadata := minio.NewBucketMetadata(bucket) + if err := metadata.Save(ctx, n); err != nil { + return err + } } return jfsToObjectErr(ctx, eno, bucket) } @@ -1200,6 +1202,9 @@ func (j *jfsFLock) GetLock(ctx context.Context, timeout *minio.DynamicTimeout) ( } func (j *jfsFLock) getFlockWithTimeOut(ctx context.Context, ltype uint32, timeout *minio.DynamicTimeout) (context.Context, error) { + if os.Getenv("JUICEFS_META_READ_ONLY") != "" { + return ctx, nil + } if j.inode == 0 { logger.Warnf("failed to get lock") return ctx, nil @@ -1254,7 +1259,7 @@ func (j *jfsFLock) getFlockWithTimeOut(ctx context.Context, ltype uint32, timeou } func (j *jfsFLock) Unlock() { - if j.inode == 0 { + if j.inode == 0 || os.Getenv("JUICEFS_META_READ_ONLY") != "" { return } if errno := j.meta.Flock(mctx, j.inode, j.owner, meta.F_UNLCK, true); errno != 0 { @@ -1268,7 +1273,7 @@ func (j *jfsFLock) GetRLock(ctx context.Context, timeout *minio.DynamicTimeout) } func (j *jfsFLock) RUnlock() { - if j.inode == 0 { + if j.inode == 0 || os.Getenv("JUICEFS_META_READ_ONLY") != "" { return } if errno := j.meta.Flock(mctx, j.inode, j.owner, meta.F_UNLCK, true); errno != 0 { @@ -1278,6 +1283,9 @@ func (j *jfsFLock) RUnlock() { } func (n *jfsObjects) NewNSLock(bucket string, objects ...string) minio.RWLocker { + if os.Getenv("JUICEFS_META_READ_ONLY") != "" { + return &jfsFLock{} + } if len(objects) != 1 { panic(fmt.Errorf("jfsObjects.NewNSLock: the length of the objects parameter must be 1, current %s", objects)) }