Add basic logic needed to correctly mount the VHD when initializing a server.
This commit is contained in:
committed by
DaneEveritt
parent
7fed6a68cb
commit
265f8a6b39
@@ -2,6 +2,7 @@ package filesystem
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"context"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
@@ -20,6 +21,7 @@ import (
|
||||
ignore "github.com/sabhiram/go-gitignore"
|
||||
|
||||
"github.com/pterodactyl/wings/config"
|
||||
"github.com/pterodactyl/wings/internal/vhd"
|
||||
"github.com/pterodactyl/wings/system"
|
||||
)
|
||||
|
||||
@@ -30,6 +32,7 @@ type Filesystem struct {
|
||||
diskUsed int64
|
||||
diskCheckInterval time.Duration
|
||||
denylist *ignore.GitIgnore
|
||||
vhd *vhd.Disk
|
||||
|
||||
// The maximum amount of disk space (in bytes) that this Filesystem instance can use.
|
||||
diskLimit int64
|
||||
@@ -41,8 +44,9 @@ type Filesystem struct {
|
||||
}
|
||||
|
||||
// New creates a new Filesystem instance for a given server.
|
||||
func New(root string, size int64, denylist []string) *Filesystem {
|
||||
return &Filesystem{
|
||||
func New(uuid string, size int64, denylist []string) *Filesystem {
|
||||
root := filepath.Join(config.Get().System.Data, uuid)
|
||||
fs := Filesystem{
|
||||
root: root,
|
||||
diskLimit: size,
|
||||
diskCheckInterval: time.Duration(config.Get().System.DiskCheckInterval),
|
||||
@@ -50,6 +54,16 @@ func New(root string, size int64, denylist []string) *Filesystem {
|
||||
lookupInProgress: system.NewAtomicBool(false),
|
||||
denylist: ignore.CompileIgnoreLines(denylist...),
|
||||
}
|
||||
|
||||
if config.Get().System.UseVirtualDisks {
|
||||
fs.vhd = vhd.New(size, VirtualDiskPath(uuid), fs.root)
|
||||
}
|
||||
|
||||
return &fs
|
||||
}
|
||||
|
||||
func VirtualDiskPath(uuid string) string {
|
||||
return filepath.Join(config.Get().System.Data, ".vhd/", uuid+".img")
|
||||
}
|
||||
|
||||
// Path returns the root path for the Filesystem instance.
|
||||
@@ -57,6 +71,25 @@ func (fs *Filesystem) Path() string {
|
||||
return fs.root
|
||||
}
|
||||
|
||||
// IsVirtual returns true if the filesystem is currently using a virtual disk.
|
||||
func (fs *Filesystem) IsVirtual() bool {
|
||||
return fs.vhd != nil
|
||||
}
|
||||
|
||||
// MountDisk will attempt to mount the underlying virtual disk for the server.
|
||||
// If the disk is already mounted this is a no-op function. If the filesystem is
|
||||
// not configured for virtual disks this function will panic.
|
||||
func (fs *Filesystem) MountDisk(ctx context.Context) error {
|
||||
if !fs.IsVirtual() {
|
||||
panic(errors.New("filesystem: cannot call MountDisk on Filesystem instance without VHD present"))
|
||||
}
|
||||
err := fs.vhd.Mount(ctx)
|
||||
if errors.Is(err, vhd.ErrFilesystemMounted) {
|
||||
return nil
|
||||
}
|
||||
return errors.WrapIf(err, "filesystem: failed to mount VHD")
|
||||
}
|
||||
|
||||
// File returns a reader for a file instance as well as the stat information.
|
||||
func (fs *Filesystem) File(p string) (*os.File, Stat, error) {
|
||||
cleaned, err := fs.SafePath(p)
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
package filesystem
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/pterodactyl/wings/config"
|
||||
"github.com/pterodactyl/wings/internal/vhd"
|
||||
)
|
||||
|
||||
func (fs *Filesystem) NewVHD() *vhd.Disk {
|
||||
parts := strings.Split(fs.root, "/")
|
||||
disk := filepath.Join(config.Get().System.Data, ".disks/", parts[len(parts)-1]+".img")
|
||||
|
||||
return vhd.New(250, disk, fs.root)
|
||||
// return vhd.New(fs.diskLimit/1024/1024, disk, fs.root)
|
||||
}
|
||||
Reference in New Issue
Block a user