Skip to content
This repository has been archived by the owner on Sep 6, 2022. It is now read-only.

Commit

Permalink
upgrade minfs to start using v7 minio-go SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
minio-trusted committed May 11, 2021
1 parent f8f6382 commit 2b44798
Show file tree
Hide file tree
Showing 13 changed files with 204 additions and 241 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
### Install Golang

If you do not have a working Golang environment setup please follow [Golang Installation Guide](https://docs.minio.io/docs/how-to-install-golang).
If you do not have a working Golang environment setup please follow [Golang Installation Guide](https://docs.min.io/docs/how-to-install-golang).

### Setup your Minfs Github Repository
Fork [MinIO upstream](https://github.com/minio/minfs/fork) source repository to your own personal repository. Copy the URL for minio from your personal github repo (you will need it for the `git clone` command below).
Expand Down
2 changes: 1 addition & 1 deletion DESIGN.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Introduction [![Slack](https://slack.minio.io/slack?type=svg)](https://slack.minio.io)
Introduction [![Slack](https://slack.min.io/slack?type=svg)](https://slack.min.io)
------------

This fuse driver allows MinIO bucket or any bucket on S3 compatible storage to be mounted as a local, as a prerequesite you need [fusermount](http://man7.org/linux/man-pages/man1/fusermount3.1.html). This feature allows MinIO to serve a bucket over a minimal POSIX API.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# MinFS Quickstart Guide [![Slack](https://slack.minio.io/slack?type=svg)](https://slack.minio.io) [![Go Report Card](https://goreportcard.com/badge/minio/minfs)](https://goreportcard.com/report/minio/minfs)
# MinFS Quickstart Guide [![Slack](https://slack.min.io/slack?type=svg)](https://slack.min.io) [![Go Report Card](https://goreportcard.com/badge/minio/minfs)](https://goreportcard.com/report/minio/minfs)

MinFS is a fuse driver for Amazon S3 compatible object storage server. MinFS lets you mount a remote bucket (from a S3 compatible object store), as if it were a local directory. This allows you to read and write from the remote bucket just by operating on the local mount directory.

Expand Down
91 changes: 91 additions & 0 deletions buildscripts/gen-ldflags.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
// +build ignore

// Copyright (c) 2015-2021 MinIO, Inc.
//
// This file is part of MinIO Object Storage stack
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

package main

import (
"fmt"
"os"
"os/exec"
"strings"
"time"
)

func genLDFlags(version string) string {
ldflagsStr := "-s -w"
ldflagsStr += " -X github.com/minio/minio/cmd.Version=" + version
ldflagsStr += " -X github.com/minio/minio/cmd.ReleaseTag=" + releaseTag(version)
ldflagsStr += " -X github.com/minio/minio/cmd.CommitID=" + commitID()
ldflagsStr += " -X github.com/minio/minio/cmd.ShortCommitID=" + commitID()[:12]
ldflagsStr += " -X github.com/minio/minio/cmd.GOPATH=" + os.Getenv("GOPATH")
ldflagsStr += " -X github.com/minio/minio/cmd.GOROOT=" + os.Getenv("GOROOT")
return ldflagsStr
}

// genReleaseTag prints release tag to the console for easy git tagging.
func releaseTag(version string) string {
relPrefix := "DEVELOPMENT"
if prefix := os.Getenv("MINIO_RELEASE"); prefix != "" {
relPrefix = prefix
}

relSuffix := ""
if hotfix := os.Getenv("MINIO_HOTFIX"); hotfix != "" {
relSuffix = hotfix
}

relTag := strings.Replace(version, " ", "-", -1)
relTag = strings.Replace(relTag, ":", "-", -1)
relTag = strings.Replace(relTag, ",", "", -1)
relTag = relPrefix + "." + relTag

if relSuffix != "" {
relTag += "." + relSuffix
}

return relTag
}

// commitID returns the abbreviated commit-id hash of the last commit.
func commitID() string {
// git log --format="%h" -n1
var (
commit []byte
e error
)
cmdName := "git"
cmdArgs := []string{"log", "--format=%H", "-n1"}
if commit, e = exec.Command(cmdName, cmdArgs...).Output(); e != nil {
fmt.Fprintln(os.Stderr, "Error generating git commit-id: ", e)
os.Exit(1)
}

return strings.TrimSpace(string(commit))
}

func main() {
var version string
if len(os.Args) > 1 {
version = os.Args[1]
} else {
version = time.Now().UTC().Format(time.RFC3339)
}

fmt.Println(genLDFlags(version))
}
8 changes: 4 additions & 4 deletions docs/minfs.8
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.TH MinFS 8 "Fuse driver for Object Storage" "23 January 2017" "MinIO, Inc."
.TH MinFS 8 "Fuse driver for Object Storage" "23 January 2021" "MinIO, Inc."
.SH NAME
MinFS \- fuse driver for Object Storage
.SH SYNOPSIS
Expand Down Expand Up @@ -26,9 +26,9 @@ Print the minfs version.
.SH FILES
/etc/minfs/config.json
.SH EXAMPLES
mount a bucket named foo at server play.minio.io:9000 on mount point /mnt/foo
mount a bucket named foo at server play.min.io:9000 on mount point /mnt/foo

# minfs https://play.minio.io:9000/foo /mnt/foo
# minfs https://play.min.io:9000/foo /mnt/foo

.SH SEE ALSO
.nf
Expand All @@ -37,6 +37,6 @@ mount a bucket named foo at server play.minio.io:9000 on mount point /mnt/foo
.fi
.SH COPYRIGHT
.nf
Copyright(c) 2017 MinIO, Inc. <https://www.minio.io>
Copyright(c) 2017 MinIO, Inc. <https://www.min.io>
\fR
.fi
4 changes: 2 additions & 2 deletions docs/mount.minfs.8
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.TH mount.minfs 8 "MinFS mount wrapper for Object Storage" "23 January 2017" "MinIO, Inc."
.TH mount.minfs 8 "MinFS mount wrapper for Object Storage" "23 January 2021" "MinIO, Inc."
.SH NAME
MinFS \- fuse driver for Object Storage
.SH SYNOPSIS
Expand Down Expand Up @@ -44,6 +44,6 @@ An example entry of a MinFS mountpoint in /proc/mounts looks like below
.fi
.SH COPYRIGHT
.nf
Copyright(c) 2017 MinIO, Inc. <https://www.minio.io>
Copyright(c) 2021 MinIO, Inc. <https://www.min.io>
\fR
.fi
89 changes: 35 additions & 54 deletions fs/dir.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"bazil.org/fuse/fs"

"github.com/minio/minfs/meta"
minio "github.com/minio/minio-go/v6"
minio "github.com/minio/minio-go/v7"
)

// Dir implements both Node and Handle for the root directory.
Expand Down Expand Up @@ -249,32 +249,22 @@ func (dir *Dir) scan(ctx context.Context) error {
prefix = prefix + "/"
}

// The channel will abort the ListObjectsV2 request.
doneCh := make(chan struct{})
defer close(doneCh)
ch := dir.mfs.api.ListObjects(ctx, dir.mfs.config.bucket, minio.ListObjectsOptions{
Prefix: prefix,
Recursive: false,
})

ch := dir.mfs.api.ListObjectsV2(dir.mfs.config.bucket, prefix, false, doneCh)
for objInfo := range ch {
key := objInfo.Key[len(prefix):]
baseKey := path.Base(key)

loop:
for {
select {
case <-ctx.Done():
break loop
case objInfo, ok := <-ch:
if !ok {
break loop
}
key := objInfo.Key[len(prefix):]
baseKey := path.Base(key)

// object still exists
objects[baseKey] = nil
// object still exists
objects[baseKey] = nil

if strings.HasSuffix(key, "/") {
dir.storeDir(b, tx, baseKey, objInfo)
} else {
dir.storeFile(b, tx, baseKey, objInfo)
}
if strings.HasSuffix(key, "/") {
dir.storeDir(b, tx, baseKey, objInfo)
} else {
dir.storeFile(b, tx, baseKey, objInfo)
}
}

Expand Down Expand Up @@ -408,7 +398,7 @@ func (dir *Dir) Remove(ctx context.Context, req *fuse.RemoveRequest) error {
b.DeleteBucket(req.Name + "/")
}

if err := dir.mfs.api.RemoveObject(dir.mfs.config.bucket, path.Join(dir.RemotePath(), req.Name)); err != nil {
if err := dir.mfs.api.RemoveObject(ctx, dir.mfs.config.bucket, path.Join(dir.RemotePath(), req.Name), minio.RemoveObjectOptions{}); err != nil {
return err
}

Expand Down Expand Up @@ -584,35 +574,26 @@ func (dir *Dir) Rename(ctx context.Context, req *fuse.RenameRequest, nd fs.Node)

oldPath := path.Join(dir.RemotePath(), req.OldName)

doneCh := make(chan struct{})
defer close(doneCh)

ch := dir.mfs.api.ListObjectsV2(dir.mfs.config.bucket, oldPath+"/", true, doneCh)
loop:
for {
select {
case <-ctx.Done():
break loop
case message, ok := <-ch:
if !ok {
break loop
}

newPath := path.Join(newDir.RemotePath(), req.NewName, message.Key[len(oldPath):])

sr := newMoveOp(message.Key, newPath)
if err := dir.mfs.sync(&sr); err == nil {
} else if meta.IsNoSuchObject(err) {
return fuse.ENOENT
} else if err != nil {
return err
}

// we'll wait for the request to be uploaded and synced, before
// releasing the file
if err := <-sr.Error; err != nil {
return err
}
ch := dir.mfs.api.ListObjects(ctx, dir.mfs.config.bucket, minio.ListObjectsOptions{
Prefix: oldPath + "/",
Recursive: true,
})

for message := range ch {
newPath := path.Join(newDir.RemotePath(), req.NewName, message.Key[len(oldPath):])

sr := newMoveOp(message.Key, newPath)
if err := dir.mfs.sync(&sr); err == nil {
} else if meta.IsNoSuchObject(err) {
return fuse.ENOENT
} else if err != nil {
return err
}

// we'll wait for the request to be uploaded and synced, before
// releasing the file
if err := <-sr.Error; err != nil {
return err
}
}
} else {
Expand Down
8 changes: 4 additions & 4 deletions fs/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"bazil.org/fuse"
"bazil.org/fuse/fs"
"github.com/minio/minfs/meta"
minio "github.com/minio/minio-go/v6"
minio "github.com/minio/minio-go/v7"
)

// File implements both Node and Handle for the hello file.
Expand Down Expand Up @@ -142,7 +142,7 @@ func (f *File) FullPath() string {

// Saves a new file at cached path and fetches the object based on
// the incoming fuse request.
func (f *File) cacheSave(path string, req *fuse.OpenRequest) error {
func (f *File) cacheSave(ctx context.Context, path string, req *fuse.OpenRequest) error {
file, err := os.Create(path)
if err != nil {
return err
Expand All @@ -154,7 +154,7 @@ func (f *File) cacheSave(path string, req *fuse.OpenRequest) error {
return nil
}

object, err := f.mfs.api.GetObject(f.mfs.config.bucket, f.RemotePath(), minio.GetObjectOptions{})
object, err := f.mfs.api.GetObject(ctx, f.mfs.config.bucket, f.RemotePath(), minio.GetObjectOptions{})
if err != nil {
if meta.IsNoSuchObject(err) {
return fuse.ENOENT
Expand Down Expand Up @@ -198,7 +198,7 @@ func (f *File) Open(ctx context.Context, req *fuse.OpenRequest, resp *fuse.OpenR
return nil, err
}

err = f.cacheSave(cachePath, req)
err = f.cacheSave(ctx, cachePath, req)
if err != nil {
return nil, err
}
Expand Down
Loading

0 comments on commit 2b44798

Please sign in to comment.