b00d328107
This is not currently working correctly — when setting the limit to 0 all existing files are destroyed. When setting it back to a non-zero value the old files are returned from the allocated disk. This at least starts getting the code pathways in place to handle it and introduces some additional lock safety on the VHD management code.
43 lines
1.3 KiB
Go
43 lines
1.3 KiB
Go
package filesystem
|
|
|
|
import (
|
|
"context"
|
|
"emperror.dev/errors"
|
|
"github.com/pterodactyl/wings/internal/vhd"
|
|
)
|
|
|
|
// IsVirtual returns true if the filesystem is currently using a virtual disk.
|
|
func (fs *Filesystem) IsVirtual() bool {
|
|
return fs.vhd != nil
|
|
}
|
|
|
|
// ConfigureDisk will attempt to create a new VHD if there is not one already
|
|
// created for the filesystem. If there is this method will attempt to resize
|
|
// the underlying data volume. Passing a size of 0 or less will panic.
|
|
func (fs *Filesystem) ConfigureDisk(ctx context.Context, size int64) error {
|
|
if size <= 0 {
|
|
panic("filesystem: attempt to configure disk with empty size")
|
|
}
|
|
if fs.vhd == nil {
|
|
fs.vhd = vhd.New(size, vhd.DiskPath(fs.uuid), fs.root)
|
|
if err := fs.MountDisk(ctx); err != nil {
|
|
return errors.WithStackIf(err)
|
|
}
|
|
}
|
|
// Resize the disk now that it is for sure mounted and exists on the system.
|
|
if err := fs.vhd.Resize(ctx, size); err != nil {
|
|
return errors.WithStackIf(err)
|
|
}
|
|
return 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.
|
|
func (fs *Filesystem) MountDisk(ctx context.Context) error {
|
|
err := fs.vhd.Mount(ctx)
|
|
if errors.Is(err, vhd.ErrFilesystemMounted) {
|
|
return nil
|
|
}
|
|
return errors.WrapIf(err, "filesystem: failed to mount VHD")
|
|
}
|