forked from Ivasoft/device-mapping-manager
This commit is contained in:
@@ -20,6 +20,12 @@
|
|||||||
"Value": "0"
|
"Value": "0"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
"Interface": {
|
||||||
|
"Socket": "dvd.sock",
|
||||||
|
"Types": [
|
||||||
|
"docker.volumedriver/1.0"
|
||||||
|
]
|
||||||
|
},
|
||||||
"Linux": {
|
"Linux": {
|
||||||
"Capabilities": [
|
"Capabilities": [
|
||||||
"CAP_BPF",
|
"CAP_BPF",
|
||||||
|
|||||||
58
main.go
58
main.go
@@ -8,21 +8,28 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"device-volume-driver/internal/cgroup"
|
"device-volume-driver/internal/cgroup"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
"os/user"
|
||||||
|
"path"
|
||||||
|
"path/filepath"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
"github.com/docker/docker/api/types/filters"
|
"github.com/docker/docker/api/types/filters"
|
||||||
"github.com/docker/docker/client"
|
"github.com/docker/docker/client"
|
||||||
|
"github.com/docker/go-plugins-helpers/volume"
|
||||||
_ "github.com/opencontainers/runtime-spec/specs-go"
|
_ "github.com/opencontainers/runtime-spec/specs-go"
|
||||||
"golang.org/x/sys/unix"
|
"golang.org/x/sys/unix"
|
||||||
"log"
|
|
||||||
"os"
|
|
||||||
"path"
|
|
||||||
"path/filepath"
|
|
||||||
"strings"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const pluginId = "dvd"
|
const pluginId = "dvd"
|
||||||
const rootPath = "/host"
|
const rootPath = "/host"
|
||||||
|
|
||||||
|
type fakeDriver struct {
|
||||||
|
}
|
||||||
|
|
||||||
func Ptr[T any](v T) *T {
|
func Ptr[T any](v T) *T {
|
||||||
return &v
|
return &v
|
||||||
}
|
}
|
||||||
@@ -62,6 +69,14 @@ func getDeviceInfo(devicePath string) (string, int64, int64, error) {
|
|||||||
func listenForMounts() {
|
func listenForMounts() {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
|
d := &fakeDriver{}
|
||||||
|
h := volume.NewHandler(d)
|
||||||
|
u, _ := user.Lookup("root")
|
||||||
|
gid, _ := strconv.Atoi(u.Gid)
|
||||||
|
if err := h.ServeUnix("/run/docker/plugins/dvd.sock", gid); err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
|
cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -178,3 +193,36 @@ func applyDeviceRules(api cgroup.Interface, mountPath string, cgroupPath string,
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (d *fakeDriver) Capabilities() *volume.CapabilitiesResponse {
|
||||||
|
return &volume.CapabilitiesResponse{Capabilities: volume.Capability{Scope: "local"}}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *fakeDriver) Create(r *volume.CreateRequest) error {
|
||||||
|
return fmt.Error("This driver device-mapping-manager cannot create volumes.")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *fakeDriver) List() (*volume.ListResponse, error) {
|
||||||
|
var vols []*volume.Volume
|
||||||
|
return &volume.ListResponse{Volumes: vols}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *fakeDriver) Get(r *volume.GetRequest) (*volume.GetResponse, error) {
|
||||||
|
return &volume.GetResponse{}, fmt.Errorf("volume %s does not exist", r.Name)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *fakeDriver) Remove(r *volume.RemoveRequest) error {
|
||||||
|
return fmt.Errorf("volume %s does not exist", r.Name)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *fakeDriver) Path(r *volume.PathRequest) (*volume.PathResponse, error) {
|
||||||
|
return &volume.PathResponse{}, fmt.Errorf("volume %s does not exist", r.Name)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *fakeDriver) Mount(r *volume.MountRequest) (*volume.MountResponse, error) {
|
||||||
|
return &volume.MountResponse{}, fmt.Errorf("volume %s does not exist", r.Name)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *fakeDriver) Unmount(r *volume.UnmountRequest) error {
|
||||||
|
return fmt.Errorf("volume %s does not exist", r.Name)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user