overlay2

package module
v0.0.0-...-8877415 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 14, 2016 License: Apache-2.0 Imports: 25 Imported by: 0

README

go-overlay2

GoDoc

Copyright (c) 2016 Dennis Chen barracks510@gmail.com

Description

Port of the Docker Overlay2 GraphDriver to a non-Docker implementation.

OverlayFS is a union filesystem that allows the presentation of a single filesystem that results from the overlay of one unto another.

Installation

This package can be installed with the go get command:

go get github.com/barracks510/go-overlay2

go-overlay2 depends on Linux kernel 4.0 or newer, compiled with OverlayFS. RedHat has backported the latest OverlayFS to kernel 3.10 for RHEL7.1 and CentOS 7.1. Using go-overlay2 on these backported kernels has been minimally tested. If you want to build your app with go-overlay2, you will need to cross compile for Linux.

This package currently is a work-in-progress. I do not forsee the API becoming stable in the near future. It is not recommended to use this package without locking in or vendoring it as a dependency.

Documentation

API documentation may be found here: https://godoc.org/github.com/barracks510/go-overlay2
Kernel documentation may be found here: https://www.kernel.org/doc/Documentation/filesystems/overlayfs.txt
Docker docmentation may be found here: https://docs.docker.com/engine/userguide/storagedriver/overlayfs-driver/

Examples can be found under the ./_example directory

License

Apache Software License 2.0. See COPYING for details.
This repository contains code from other projects. See NOTICE for details.

Documentation

Overview

This backend uses the overlay union filesystem for containers with diff directories for each layer.

This version of the overlay driver requires at least kernel 4.0.0 in order to support mounting multiple diff directories.

Each container/image has at least a "diff" directory and "link" file. If there is also a "lower" file when there are diff layers below as well as "merged" and "work" directories. The "diff" directory has the upper layer of the overlay and is used to capture any changes to the layer. The "lower" file contains all the lower layer mounts separated by ":" and ordered from uppermost to lowermost layers. The overlay itself is mounted in the "merged" directory, and the "work" dir is needed for overlay to work.

The "link" file for each layer contains a unique string for the layer. Under the "l" directory at the root there will be a symbolic link with that unique string pointing the "diff" directory for the layer. The symbolic links are used to reference lower layers in the "lower" file and on mount. The links are used to shorten the total length of a layer reference without requiring changes to the layer identifier or root directory. Mounts are always done relative to root and referencing the symbolic links in order to ensure the number of lower directories can fit in a single page for making the mount syscall. A hard upper limit of 128 lower layers is enforced to ensure that mounts do not fail due to length.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Init

func Init(home string, options []string, uidMaps, gidMaps []idtools.IDMap) (graphdriver.Driver, error)

Init returns the a native diff driver for overlay filesystem. If overlay filesystem is not supported on the host, graphdriver.ErrNotSupported is returned as error. If a overlay filesystem is not supported over a existing filesystem then error graphdriver.ErrIncompatibleFS is returned.

Types

type Driver

type Driver struct {
	// contains filtered or unexported fields
}

Driver contains information about the home directory and the list of active mounts that are created using this driver.

func (*Driver) ApplyDiff

func (d *Driver) ApplyDiff(id string, parent string, diff archive.Reader) (size int64, err error)

ApplyDiff applies the new layer into a root

func (*Driver) Changes

func (d *Driver) Changes(id, parent string) ([]archive.Change, error)

Changes produces a list of changes between the specified layer and its parent layer. If parent is "", then all changes will be ADD changes.

func (*Driver) Cleanup

func (d *Driver) Cleanup() error

Cleanup any state created by overlay which should be cleaned when daemon is being shutdown. For now, we just have to unmount the bind mounted we had created.

func (*Driver) Create

func (d *Driver) Create(id, parent, mountLabel string, storageOpt map[string]string) (retErr error)

Create is used to create the upper, lower, and merge directories required for overlay fs for a given id. The parent filesystem is used to configure these directories for the overlay.

func (*Driver) CreateReadWrite

func (d *Driver) CreateReadWrite(id, parent, mountLabel string, storageOpt map[string]string) error

CreateReadWrite creates a layer that is writable for use as a container file system.

func (*Driver) Diff

func (d *Driver) Diff(id, parent string) (archive.Archive, error)

Diff produces an archive of the changes between the specified layer and its parent layer which may be "".

func (*Driver) DiffSize

func (d *Driver) DiffSize(id, parent string) (size int64, err error)

DiffSize calculates the changes between the specified id and its parent and returns the size in bytes of the changes relative to its base filesystem directory.

func (*Driver) Exists

func (d *Driver) Exists(id string) bool

Exists checks to see if the id is already mounted.

func (*Driver) Get

func (d *Driver) Get(id string, mountLabel string) (s string, err error)

Get creates and mounts the required file system for the given id and returns the mount path.

func (*Driver) GetMetadata

func (d *Driver) GetMetadata(id string) (map[string]string, error)

GetMetadata returns meta data about the overlay driver such as LowerDir, UpperDir, WorkDir and MergeDir used to store data.

func (*Driver) Put

func (d *Driver) Put(id string) error

Put unmounts the mount path created for the give id.

func (*Driver) Remove

func (d *Driver) Remove(id string) error

Remove cleans the directories that are created for this id.

func (*Driver) Status

func (d *Driver) Status() [][2]string

Status returns current driver information in a two dimensional string array. Output contains "Backing Filesystem" used in this implementation.

func (*Driver) String

func (d *Driver) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL