@@ -22,6 +22,9 @@ import (
2222 "encoding/binary"
2323 "errors"
2424 "fmt"
25+ "io"
26+ "net/http"
27+ "net/url"
2528 "os"
2629 "os/exec"
2730 "path"
@@ -86,6 +89,12 @@ type Registry struct {
8689 Insecure bool `json:"insecure"`
8790}
8891
92+ type ExperimentalConfig struct {
93+ Enabled bool `json:"enabled"`
94+ PreAuth bool `json:"preAuth"`
95+ OverlaybdApiServer string `json:"overlaybdApiServer"`
96+ }
97+
8998type BootConfig struct {
9099 AsyncRemove bool `json:"asyncRemove"`
91100 Address string `json:"address"`
@@ -102,6 +111,7 @@ type BootConfig struct {
102111 Tenant int `json:"tenant"` // do not set this if only a single snapshotter service in the host
103112 TurboFsType []string `json:"turboFsType"`
104113 RuntimeType string `json:"runtimeType"` // "containerd" (default) or "docker"
114+ Experimental ExperimentalConfig `json:"experimental"`
105115}
106116
107117func DefaultBootConfig () * BootConfig {
@@ -126,6 +136,11 @@ func DefaultBootConfig() *BootConfig {
126136 "ext4" ,
127137 },
128138 RuntimeType : "containerd" ,
139+ Experimental : ExperimentalConfig {
140+ Enabled : false ,
141+ PreAuth : true ,
142+ OverlaybdApiServer : "http://127.0.0.1:9862" ,
143+ },
129144 }
130145}
131146
@@ -206,6 +221,7 @@ type snapshotter struct {
206221 turboFsType []string
207222 asyncRemove bool
208223 runtimeType string
224+ experimental ExperimentalConfig
209225
210226 quotaDriver * diskquota.PrjQuotaDriver
211227 quotaSize string
@@ -270,6 +286,7 @@ func NewSnapshotter(bootConfig *BootConfig, opts ...Opt) (snapshots.Snapshotter,
270286 turboFsType : bootConfig .TurboFsType ,
271287 tenant : bootConfig .Tenant ,
272288 quotaSize : bootConfig .RootfsQuota ,
289+ experimental : bootConfig .Experimental ,
273290 quotaDriver : & diskquota.PrjQuotaDriver {
274291 QuotaIDs : make (map [uint32 ]struct {}),
275292 },
@@ -434,6 +451,61 @@ func (o *snapshotter) lockSnapshotID(id string) func() {
434451 }
435452}
436453
454+ func (o * snapshotter ) preAuthEnabled () bool {
455+ return o .experimental .Enabled && o .experimental .PreAuth
456+ }
457+
458+ func (o * snapshotter ) notifyOverlaybdAPIServer (configPath string ) {
459+ if ! o .preAuthEnabled () || configPath == "" {
460+ return
461+ }
462+
463+ go func () {
464+ address := strings .TrimSpace (o .experimental .OverlaybdApiServer )
465+ if address == "" {
466+ log .L .Warn ("overlaybd api server address is empty" )
467+ return
468+ }
469+
470+ authBase , err := url .Parse (address )
471+ if err != nil {
472+ log .L .WithError (err ).Warnf ("failed to parse overlaybd api server address %q" , address )
473+ return
474+ }
475+
476+ authURL := authBase .ResolveReference (& url.URL {Path : "/auth" })
477+ query := authURL .Query ()
478+ query .Set ("config" , configPath )
479+ authURL .RawQuery = query .Encode ()
480+
481+ log .L .Infof ("overlaybd api request: %s" , authURL .String ())
482+
483+ reqCtx , cancel := context .WithTimeout (context .Background (), 10 * time .Second )
484+ defer cancel ()
485+
486+ req , err := http .NewRequestWithContext (reqCtx , http .MethodGet , authURL .String (), nil )
487+ if err != nil {
488+ log .L .WithError (err ).Warnf ("failed to create overlaybd api request for %s" , authURL .String ())
489+ return
490+ }
491+
492+ resp , err := http .DefaultClient .Do (req )
493+ if err != nil {
494+ log .L .WithError (err ).Warnf ("overlaybd api request failed: %s" , authURL .String ())
495+ return
496+ }
497+ defer resp .Body .Close ()
498+
499+ body , err := io .ReadAll (resp .Body )
500+ if err != nil {
501+ log .L .WithError (err ).Warnf ("failed to read overlaybd api response from %s" , authURL .String ())
502+ return
503+ }
504+
505+ log .L .Infof ("overlaybd api response: url=%s status=%s body=%s" , authURL .String (), resp .Status , strings .TrimSpace (string (body )))
506+ }()
507+ }
508+
437509func (o * snapshotter ) cleanupFailedPrepare (ctx context.Context , key , id string ) {
438510 // TODO: recover half-done prepare state after process crash. This path only
439511 // cleans up failures observed in-process after metadata has been committed.
@@ -757,6 +829,7 @@ func (o *snapshotter) createMountPoint(ctx context.Context, kind snapshots.Kind,
757829 // concurrent Prepare/Mounts/Remove operating on the same parent snapshot.
758830 unlockObd = o .lockSnapshotID (obdID )
759831 }
832+ o .notifyOverlaybdAPIServer (o .overlaybdConfPath (obdID ))
760833 if err = o .attachAndMountBlockDevice (ctx , obdID , writeType , fsType , parent == "" ); err != nil {
761834 unlockObd ()
762835 log .G (ctx ).Errorf ("%v" , err )
0 commit comments