Skip to content

Commit

Permalink
Merge pull request #219 from sonroyaalmerol/server-nfs
Browse files Browse the repository at this point in the history
trim out unnecessary code from fuse implementation
  • Loading branch information
sonroyaalmerol authored Feb 26, 2025
2 parents c7e8c57 + 62a0ffa commit 81aa0d2
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 366 deletions.
4 changes: 2 additions & 2 deletions internal/agent/vssfs/vssfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,8 +422,8 @@ func (s *VSSFSServer) handleFstat(req arpc.Request) (arpc.Response, error) {
}

func (s *VSSFSServer) abs(filename string) (string, error) {
if filename == s.rootDir {
filename = string(filepath.Separator)
if filename == "" || filename == "." {
return s.rootDir, nil
}

path, err := securejoin.SecureJoin(s.rootDir, filename)
Expand Down
34 changes: 10 additions & 24 deletions internal/backend/arpc/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (

"github.com/go-git/go-billy/v5"
"github.com/sonroyaalmerol/pbs-plus/internal/arpc"
"github.com/sonroyaalmerol/pbs-plus/internal/backend/arpc/fuse"
"github.com/sonroyaalmerol/pbs-plus/internal/backend/arpc/types"
"github.com/sonroyaalmerol/pbs-plus/internal/syslog"
"github.com/sonroyaalmerol/pbs-plus/internal/utils"
Expand All @@ -25,27 +24,14 @@ func NewARPCFS(ctx context.Context, session *arpc.Session, hostname string, driv
return &ARPCFS{
ctx: ctx,
session: session,
drive: drive,
hostname: hostname,
Drive: drive,
Hostname: hostname,
}
}

func (f *ARPCFS) Mount(mountpoint string) error {
fsName := "agent://" + utils.Slugify(f.hostname) + "/" + f.drive
server, err := fuse.Mount(mountpoint, fsName, f, nil)
if err != nil {
return err
}

f.mount = server

f.mount.WaitMount()
return nil
}

func (f *ARPCFS) Unmount() {
if f.mount != nil {
_ = f.mount.Unmount()
if f.Mount != nil {
_ = f.Mount.Unmount()
}
}

Expand Down Expand Up @@ -76,7 +62,7 @@ func (fs *ARPCFS) OpenFile(filename string, flag int, perm os.FileMode) (billy.F
ctx, cancel := TimeoutCtx()
defer cancel()

err := fs.session.CallJSON(ctx, fs.drive+"/OpenFile", OpenRequest{
err := fs.session.CallJSON(ctx, fs.Drive+"/OpenFile", OpenRequest{
Path: filename,
Flag: flag,
Perm: int(perm),
Expand All @@ -93,7 +79,7 @@ func (fs *ARPCFS) OpenFile(filename string, flag int, perm os.FileMode) (billy.F
fs: fs,
name: filename,
handleID: resp.HandleID,
drive: fs.drive,
drive: fs.Drive,
}, nil
}

Expand All @@ -107,7 +93,7 @@ func (fs *ARPCFS) Stat(filename string) (os.FileInfo, error) {
ctx, cancel := TimeoutCtx()
defer cancel()

err := fs.session.CallJSON(ctx, fs.drive+"/Stat", struct {
err := fs.session.CallJSON(ctx, fs.Drive+"/Stat", struct {
Path string `json:"path"`
}{
Path: filename,
Expand Down Expand Up @@ -143,7 +129,7 @@ func (fs *ARPCFS) StatFS() (types.StatFS, error) {
ctx, cancel := TimeoutCtx()
defer cancel()

err := fs.session.CallJSON(ctx, fs.drive+"/FSstat", struct{}{}, &fsStat)
err := fs.session.CallJSON(ctx, fs.Drive+"/FSstat", struct{}{}, &fsStat)
if err != nil {
syslog.L.Errorf("StatFS RPC failed: %v", err)
return types.StatFS{}, os.ErrInvalid
Expand All @@ -170,7 +156,7 @@ func (fs *ARPCFS) ReadDir(path string) ([]os.FileInfo, error) {
ctx, cancel := TimeoutCtx()
defer cancel()

err := fs.session.CallJSON(ctx, fs.drive+"/ReadDir", struct {
err := fs.session.CallJSON(ctx, fs.Drive+"/ReadDir", struct {
Path string `json:"path"`
}{
Path: path,
Expand Down Expand Up @@ -227,7 +213,7 @@ func (fs *ARPCFS) Join(elem ...string) string {
}

func (fs *ARPCFS) Chroot(path string) (billy.Filesystem, error) {
return NewARPCFS(fs.ctx, fs.session, fs.hostname, fs.drive), nil
return NewARPCFS(fs.ctx, fs.session, fs.Hostname, fs.Drive), nil
}

func (fs *ARPCFS) Root() string {
Expand Down
Loading

0 comments on commit 81aa0d2

Please sign in to comment.