Skip to content

Commit

Permalink
Merge pull request moby#48143 from thaJeztah/graphdriver_remove_capab…
Browse files Browse the repository at this point in the history
…ilities

daemon/graphdriver: remove Capabilities, CapabilityDriver
  • Loading branch information
thaJeztah authored Jul 15, 2024
2 parents 20a0102 + 688301c commit fb5acc4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 55 deletions.
17 changes: 0 additions & 17 deletions daemon/graphdriver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,23 +94,6 @@ type Driver interface {
DiffDriver
}

// Capabilities defines a list of capabilities a driver may implement.
// These capabilities are not required; however, they do determine how a
// graphdriver can be used.
type Capabilities struct {
// Flags that this driver is capable of reproducing exactly equivalent
// diffs for read-only layers. If set, clients can rely on the driver
// for consistent tar streams, and avoid extra processing to account
// for potential differences (eg: the layer store's use of tar-split).
ReproducesExactDiffs bool
}

// CapabilityDriver is the interface for layered file system drivers that
// can report on their Capabilities.
type CapabilityDriver interface {
Capabilities() Capabilities
}

// DiffGetterDriver is the interface for layered file system drivers that
// provide a specialized function for getting file contents for tar-split.
type DiffGetterDriver interface {
Expand Down
57 changes: 19 additions & 38 deletions layer/layer_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@ import (
const maxLayerDepth = 125

type layerStore struct {
store *fileMetadataStore
driver graphdriver.Driver
useTarSplit bool
store *fileMetadataStore
driver graphdriver.Driver

layerMap map[ChainID]*roLayer
layerL sync.Mutex
Expand Down Expand Up @@ -77,23 +76,17 @@ func NewStoreFromOptions(options StoreOptions) (Store, error) {
// metadata store and graph driver. The metadata store will be used to restore
// the Store.
func newStoreFromGraphDriver(root string, driver graphdriver.Driver) (Store, error) {
caps := graphdriver.Capabilities{}
if capDriver, ok := driver.(graphdriver.CapabilityDriver); ok {
caps = capDriver.Capabilities()
}

ms, err := newFSMetadataStore(root)
if err != nil {
return nil, err
}

ls := &layerStore{
store: ms,
driver: driver,
layerMap: map[ChainID]*roLayer{},
mounts: map[string]*mountedLayer{},
locker: locker.New(),
useTarSplit: !caps.ReproducesExactDiffs,
store: ms,
driver: driver,
layerMap: map[ChainID]*roLayer{},
mounts: map[string]*mountedLayer{},
locker: locker.New(),
}

ids, mounts, err := ms.List()
Expand Down Expand Up @@ -225,24 +218,21 @@ func (ls *layerStore) loadMount(mount string) error {
}

func (ls *layerStore) applyTar(tx *fileMetadataTransaction, ts io.Reader, parent string, layer *roLayer) error {
tsw, err := tx.TarSplitWriter(true)
if err != nil {
return err
}
metaPacker := storage.NewJSONPacker(tsw)
defer tsw.Close()

digester := digest.Canonical.Digester()
tr := io.TeeReader(ts, digester.Hash())

rdr := tr
if ls.useTarSplit {
tsw, err := tx.TarSplitWriter(true)
if err != nil {
return err
}
metaPacker := storage.NewJSONPacker(tsw)
defer tsw.Close()

// we're passing nil here for the file putter, because the ApplyDiff will
// handle the extraction of the archive
rdr, err = asm.NewInputTarStream(tr, metaPacker, nil)
if err != nil {
return err
}
// we're passing nil here for the file putter, because the ApplyDiff will
// handle the extraction of the archive
rdr, err := asm.NewInputTarStream(tr, metaPacker, nil)
if err != nil {
return err
}

applySize, err := ls.driver.ApplyDiff(layer.cacheID, parent, rdr)
Expand Down Expand Up @@ -690,15 +680,6 @@ func (ls *layerStore) initMount(graphID, parent, mountLabel string, initFunc Mou
}

func (ls *layerStore) getTarStream(rl *roLayer) (io.ReadCloser, error) {
if !ls.useTarSplit {
var parentCacheID string
if rl.parent != nil {
parentCacheID = rl.parent.cacheID
}

return ls.driver.Diff(rl.cacheID, parentCacheID)
}

r, err := ls.store.TarSplitReader(rl.chainID)
if err != nil {
return nil, err
Expand Down

0 comments on commit fb5acc4

Please sign in to comment.