mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
Add tmpfs IOFS (#1212)
* Define an interface for IOFS handling. Add no-op and temporary directory implementations. * Move IOFS stuff out into separate file, add basic tmpfs implementation for linux only * Switch between directory and tmpfs based on platform and config * Respect FN_IOFS_OPTS * Make directory iofs default on all platforms * At least try to clean up a bit on failure * Add backout if IOFS creation fails * Add comment about iofs.Close
This commit is contained in:
committed by
Reed Allman
parent
822fa71fd2
commit
493790dbd2
38
api/agent/iofs_linux.go
Normal file
38
api/agent/iofs_linux.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package agent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/fnproject/fn/api/common"
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
type tmpfsIOFS struct {
|
||||
directoryIOFS
|
||||
}
|
||||
|
||||
func (t *tmpfsIOFS) Close() error {
|
||||
if err := unix.Unmount(t.AgentPath(), 0); err != nil {
|
||||
// At this point we don't have a lot of choice but to leak the directory and mount
|
||||
return err
|
||||
}
|
||||
return t.directoryIOFS.Close()
|
||||
}
|
||||
|
||||
func newTmpfsIOFS(ctx context.Context, cfg *Config) (*tmpfsIOFS, error) {
|
||||
dirIOFS, err := newDirectoryIOFS(ctx, cfg)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err = unix.Mount("tmpfs", dirIOFS.AgentPath(), "tmpfs", uintptr(unix.MS_NOEXEC|unix.MS_NOSUID|unix.MS_NODEV), cfg.IOFSOpts); err != nil {
|
||||
// Best effort to clean up after failure. If the dirIOFS.Close() fails we're not going to see the error though...
|
||||
if err := dirIOFS.Close(); err != nil {
|
||||
common.Logger(ctx).WithError(err).Error("failed to cleanup iofs dir")
|
||||
}
|
||||
return nil, fmt.Errorf("cannot mount/create tmpfs at %s", dirIOFS.AgentPath())
|
||||
}
|
||||
return &tmpfsIOFS{*dirIOFS}, nil
|
||||
}
|
||||
|
||||
var _ iofs = &tmpfsIOFS{}
|
||||
Reference in New Issue
Block a user