overlay.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662
  1. // +build linux
  2. package overlay2
  3. import (
  4. "bufio"
  5. "errors"
  6. "fmt"
  7. "io"
  8. "io/ioutil"
  9. "os"
  10. "os/exec"
  11. "path"
  12. "path/filepath"
  13. "strconv"
  14. "strings"
  15. "sync"
  16. "syscall"
  17. "github.com/Sirupsen/logrus"
  18. "github.com/docker/docker/daemon/graphdriver"
  19. "github.com/docker/docker/daemon/graphdriver/overlayutils"
  20. "github.com/docker/docker/daemon/graphdriver/quota"
  21. "github.com/docker/docker/pkg/archive"
  22. "github.com/docker/docker/pkg/chrootarchive"
  23. "github.com/docker/docker/pkg/directory"
  24. "github.com/docker/docker/pkg/fsutils"
  25. "github.com/docker/docker/pkg/idtools"
  26. "github.com/docker/docker/pkg/mount"
  27. "github.com/docker/docker/pkg/parsers"
  28. "github.com/docker/docker/pkg/parsers/kernel"
  29. "github.com/docker/go-units"
  30. "github.com/opencontainers/runc/libcontainer/label"
  31. )
  32. var (
  33. // untar defines the untar method
  34. untar = chrootarchive.UntarUncompressed
  35. )
  36. // This backend uses the overlay union filesystem for containers
  37. // with diff directories for each layer.
  38. // This version of the overlay driver requires at least kernel
  39. // 4.0.0 in order to support mounting multiple diff directories.
  40. // Each container/image has at least a "diff" directory and "link" file.
  41. // If there is also a "lower" file when there are diff layers
  42. // below as well as "merged" and "work" directories. The "diff" directory
  43. // has the upper layer of the overlay and is used to capture any
  44. // changes to the layer. The "lower" file contains all the lower layer
  45. // mounts separated by ":" and ordered from uppermost to lowermost
  46. // layers. The overlay itself is mounted in the "merged" directory,
  47. // and the "work" dir is needed for overlay to work.
  48. // The "link" file for each layer contains a unique string for the layer.
  49. // Under the "l" directory at the root there will be a symbolic link
  50. // with that unique string pointing the "diff" directory for the layer.
  51. // The symbolic links are used to reference lower layers in the "lower"
  52. // file and on mount. The links are used to shorten the total length
  53. // of a layer reference without requiring changes to the layer identifier
  54. // or root directory. Mounts are always done relative to root and
  55. // referencing the symbolic links in order to ensure the number of
  56. // lower directories can fit in a single page for making the mount
  57. // syscall. A hard upper limit of 128 lower layers is enforced to ensure
  58. // that mounts do not fail due to length.
  59. const (
  60. driverName = "overlay2"
  61. linkDir = "l"
  62. lowerFile = "lower"
  63. maxDepth = 128
  64. // idLength represents the number of random characters
  65. // which can be used to create the unique link identifer
  66. // for every layer. If this value is too long then the
  67. // page size limit for the mount command may be exceeded.
  68. // The idLength should be selected such that following equation
  69. // is true (512 is a buffer for label metadata).
  70. // ((idLength + len(linkDir) + 1) * maxDepth) <= (pageSize - 512)
  71. idLength = 26
  72. )
  73. type overlayOptions struct {
  74. overrideKernelCheck bool
  75. quota quota.Quota
  76. }
  77. // Driver contains information about the home directory and the list of active mounts that are created using this driver.
  78. type Driver struct {
  79. home string
  80. uidMaps []idtools.IDMap
  81. gidMaps []idtools.IDMap
  82. ctr *graphdriver.RefCounter
  83. quotaCtl *quota.Control
  84. options overlayOptions
  85. naiveDiff graphdriver.DiffDriver
  86. supportsDType bool
  87. }
  88. var (
  89. backingFs = "<unknown>"
  90. projectQuotaSupported = false
  91. useNaiveDiffLock sync.Once
  92. useNaiveDiffOnly bool
  93. )
  94. func init() {
  95. graphdriver.Register(driverName, Init)
  96. }
  97. // Init returns the a native diff driver for overlay filesystem.
  98. // If overlay filesystem is not supported on the host, graphdriver.ErrNotSupported is returned as error.
  99. // If an overlay filesystem is not supported over an existing filesystem then error graphdriver.ErrIncompatibleFS is returned.
  100. func Init(home string, options []string, uidMaps, gidMaps []idtools.IDMap) (graphdriver.Driver, error) {
  101. opts, err := parseOptions(options)
  102. if err != nil {
  103. return nil, err
  104. }
  105. if err := supportsOverlay(); err != nil {
  106. return nil, graphdriver.ErrNotSupported
  107. }
  108. // require kernel 4.0.0 to ensure multiple lower dirs are supported
  109. v, err := kernel.GetKernelVersion()
  110. if err != nil {
  111. return nil, err
  112. }
  113. if kernel.CompareKernelVersion(*v, kernel.VersionInfo{Kernel: 4, Major: 0, Minor: 0}) < 0 {
  114. if !opts.overrideKernelCheck {
  115. return nil, graphdriver.ErrNotSupported
  116. }
  117. logrus.Warn("Using pre-4.0.0 kernel for overlay2, mount failures may require kernel update")
  118. }
  119. fsMagic, err := graphdriver.GetFSMagic(home)
  120. if err != nil {
  121. return nil, err
  122. }
  123. if fsName, ok := graphdriver.FsNames[fsMagic]; ok {
  124. backingFs = fsName
  125. }
  126. // check if they are running over btrfs, aufs, zfs, overlay, or ecryptfs
  127. switch fsMagic {
  128. case graphdriver.FsMagicBtrfs, graphdriver.FsMagicAufs, graphdriver.FsMagicZfs, graphdriver.FsMagicOverlay, graphdriver.FsMagicEcryptfs:
  129. logrus.Errorf("'overlay2' is not supported over %s", backingFs)
  130. return nil, graphdriver.ErrIncompatibleFS
  131. }
  132. rootUID, rootGID, err := idtools.GetRootUIDGID(uidMaps, gidMaps)
  133. if err != nil {
  134. return nil, err
  135. }
  136. // Create the driver home dir
  137. if err := idtools.MkdirAllAs(path.Join(home, linkDir), 0700, rootUID, rootGID); err != nil && !os.IsExist(err) {
  138. return nil, err
  139. }
  140. if err := mount.MakePrivate(home); err != nil {
  141. return nil, err
  142. }
  143. supportsDType, err := fsutils.SupportsDType(home)
  144. if err != nil {
  145. return nil, err
  146. }
  147. if !supportsDType {
  148. // not a fatal error until v1.16 (#27443)
  149. logrus.Warn(overlayutils.ErrDTypeNotSupported("overlay2", backingFs))
  150. }
  151. d := &Driver{
  152. home: home,
  153. uidMaps: uidMaps,
  154. gidMaps: gidMaps,
  155. ctr: graphdriver.NewRefCounter(graphdriver.NewFsChecker(graphdriver.FsMagicOverlay)),
  156. supportsDType: supportsDType,
  157. }
  158. d.naiveDiff = graphdriver.NewNaiveDiffDriver(d, uidMaps, gidMaps)
  159. if backingFs == "xfs" {
  160. // Try to enable project quota support over xfs.
  161. if d.quotaCtl, err = quota.NewControl(home); err == nil {
  162. projectQuotaSupported = true
  163. }
  164. }
  165. logrus.Debugf("backingFs=%s, projectQuotaSupported=%v", backingFs, projectQuotaSupported)
  166. return d, nil
  167. }
  168. func parseOptions(options []string) (*overlayOptions, error) {
  169. o := &overlayOptions{}
  170. for _, option := range options {
  171. key, val, err := parsers.ParseKeyValueOpt(option)
  172. if err != nil {
  173. return nil, err
  174. }
  175. key = strings.ToLower(key)
  176. switch key {
  177. case "overlay2.override_kernel_check":
  178. o.overrideKernelCheck, err = strconv.ParseBool(val)
  179. if err != nil {
  180. return nil, err
  181. }
  182. default:
  183. return nil, fmt.Errorf("overlay2: Unknown option %s\n", key)
  184. }
  185. }
  186. return o, nil
  187. }
  188. func supportsOverlay() error {
  189. // We can try to modprobe overlay first before looking at
  190. // proc/filesystems for when overlay is supported
  191. exec.Command("modprobe", "overlay").Run()
  192. f, err := os.Open("/proc/filesystems")
  193. if err != nil {
  194. return err
  195. }
  196. defer f.Close()
  197. s := bufio.NewScanner(f)
  198. for s.Scan() {
  199. if s.Text() == "nodev\toverlay" {
  200. return nil
  201. }
  202. }
  203. logrus.Error("'overlay' not found as a supported filesystem on this host. Please ensure kernel is new enough and has overlay support loaded.")
  204. return graphdriver.ErrNotSupported
  205. }
  206. func useNaiveDiff(home string) bool {
  207. useNaiveDiffLock.Do(func() {
  208. if err := hasOpaqueCopyUpBug(home); err != nil {
  209. logrus.Warnf("Not using native diff for overlay2: %v", err)
  210. useNaiveDiffOnly = true
  211. }
  212. })
  213. return useNaiveDiffOnly
  214. }
  215. func (d *Driver) String() string {
  216. return driverName
  217. }
  218. // Status returns current driver information in a two dimensional string array.
  219. // Output contains "Backing Filesystem" used in this implementation.
  220. func (d *Driver) Status() [][2]string {
  221. return [][2]string{
  222. {"Backing Filesystem", backingFs},
  223. {"Supports d_type", strconv.FormatBool(d.supportsDType)},
  224. {"Native Overlay Diff", strconv.FormatBool(!useNaiveDiff(d.home))},
  225. }
  226. }
  227. // GetMetadata returns meta data about the overlay driver such as
  228. // LowerDir, UpperDir, WorkDir and MergeDir used to store data.
  229. func (d *Driver) GetMetadata(id string) (map[string]string, error) {
  230. dir := d.dir(id)
  231. if _, err := os.Stat(dir); err != nil {
  232. return nil, err
  233. }
  234. metadata := map[string]string{
  235. "WorkDir": path.Join(dir, "work"),
  236. "MergedDir": path.Join(dir, "merged"),
  237. "UpperDir": path.Join(dir, "diff"),
  238. }
  239. lowerDirs, err := d.getLowerDirs(id)
  240. if err != nil {
  241. return nil, err
  242. }
  243. if len(lowerDirs) > 0 {
  244. metadata["LowerDir"] = strings.Join(lowerDirs, ":")
  245. }
  246. return metadata, nil
  247. }
  248. // Cleanup any state created by overlay which should be cleaned when daemon
  249. // is being shutdown. For now, we just have to unmount the bind mounted
  250. // we had created.
  251. func (d *Driver) Cleanup() error {
  252. return mount.Unmount(d.home)
  253. }
  254. // CreateReadWrite creates a layer that is writable for use as a container
  255. // file system.
  256. func (d *Driver) CreateReadWrite(id, parent string, opts *graphdriver.CreateOpts) error {
  257. return d.Create(id, parent, opts)
  258. }
  259. // Create is used to create the upper, lower, and merge directories required for overlay fs for a given id.
  260. // The parent filesystem is used to configure these directories for the overlay.
  261. func (d *Driver) Create(id, parent string, opts *graphdriver.CreateOpts) (retErr error) {
  262. if opts != nil && len(opts.StorageOpt) != 0 && !projectQuotaSupported {
  263. return fmt.Errorf("--storage-opt is supported only for overlay over xfs with 'pquota' mount option")
  264. }
  265. dir := d.dir(id)
  266. rootUID, rootGID, err := idtools.GetRootUIDGID(d.uidMaps, d.gidMaps)
  267. if err != nil {
  268. return err
  269. }
  270. if err := idtools.MkdirAllAs(path.Dir(dir), 0700, rootUID, rootGID); err != nil {
  271. return err
  272. }
  273. if err := idtools.MkdirAs(dir, 0700, rootUID, rootGID); err != nil {
  274. return err
  275. }
  276. defer func() {
  277. // Clean up on failure
  278. if retErr != nil {
  279. os.RemoveAll(dir)
  280. }
  281. }()
  282. if opts != nil && len(opts.StorageOpt) > 0 {
  283. driver := &Driver{}
  284. if err := d.parseStorageOpt(opts.StorageOpt, driver); err != nil {
  285. return err
  286. }
  287. if driver.options.quota.Size > 0 {
  288. // Set container disk quota limit
  289. if err := d.quotaCtl.SetQuota(dir, driver.options.quota); err != nil {
  290. return err
  291. }
  292. }
  293. }
  294. if err := idtools.MkdirAs(path.Join(dir, "diff"), 0755, rootUID, rootGID); err != nil {
  295. return err
  296. }
  297. lid := generateID(idLength)
  298. if err := os.Symlink(path.Join("..", id, "diff"), path.Join(d.home, linkDir, lid)); err != nil {
  299. return err
  300. }
  301. // Write link id to link file
  302. if err := ioutil.WriteFile(path.Join(dir, "link"), []byte(lid), 0644); err != nil {
  303. return err
  304. }
  305. // if no parent directory, done
  306. if parent == "" {
  307. return nil
  308. }
  309. if err := idtools.MkdirAs(path.Join(dir, "work"), 0700, rootUID, rootGID); err != nil {
  310. return err
  311. }
  312. if err := idtools.MkdirAs(path.Join(dir, "merged"), 0700, rootUID, rootGID); err != nil {
  313. return err
  314. }
  315. lower, err := d.getLower(parent)
  316. if err != nil {
  317. return err
  318. }
  319. if lower != "" {
  320. if err := ioutil.WriteFile(path.Join(dir, lowerFile), []byte(lower), 0666); err != nil {
  321. return err
  322. }
  323. }
  324. return nil
  325. }
  326. // Parse overlay storage options
  327. func (d *Driver) parseStorageOpt(storageOpt map[string]string, driver *Driver) error {
  328. // Read size to set the disk project quota per container
  329. for key, val := range storageOpt {
  330. key := strings.ToLower(key)
  331. switch key {
  332. case "size":
  333. size, err := units.RAMInBytes(val)
  334. if err != nil {
  335. return err
  336. }
  337. driver.options.quota.Size = uint64(size)
  338. default:
  339. return fmt.Errorf("Unknown option %s", key)
  340. }
  341. }
  342. return nil
  343. }
  344. func (d *Driver) getLower(parent string) (string, error) {
  345. parentDir := d.dir(parent)
  346. // Ensure parent exists
  347. if _, err := os.Lstat(parentDir); err != nil {
  348. return "", err
  349. }
  350. // Read Parent link fileA
  351. parentLink, err := ioutil.ReadFile(path.Join(parentDir, "link"))
  352. if err != nil {
  353. return "", err
  354. }
  355. lowers := []string{path.Join(linkDir, string(parentLink))}
  356. parentLower, err := ioutil.ReadFile(path.Join(parentDir, lowerFile))
  357. if err == nil {
  358. parentLowers := strings.Split(string(parentLower), ":")
  359. lowers = append(lowers, parentLowers...)
  360. }
  361. if len(lowers) > maxDepth {
  362. return "", errors.New("max depth exceeded")
  363. }
  364. return strings.Join(lowers, ":"), nil
  365. }
  366. func (d *Driver) dir(id string) string {
  367. return path.Join(d.home, id)
  368. }
  369. func (d *Driver) getLowerDirs(id string) ([]string, error) {
  370. var lowersArray []string
  371. lowers, err := ioutil.ReadFile(path.Join(d.dir(id), lowerFile))
  372. if err == nil {
  373. for _, s := range strings.Split(string(lowers), ":") {
  374. lp, err := os.Readlink(path.Join(d.home, s))
  375. if err != nil {
  376. return nil, err
  377. }
  378. lowersArray = append(lowersArray, path.Clean(path.Join(d.home, linkDir, lp)))
  379. }
  380. } else if !os.IsNotExist(err) {
  381. return nil, err
  382. }
  383. return lowersArray, nil
  384. }
  385. // Remove cleans the directories that are created for this id.
  386. func (d *Driver) Remove(id string) error {
  387. dir := d.dir(id)
  388. lid, err := ioutil.ReadFile(path.Join(dir, "link"))
  389. if err == nil {
  390. if err := os.RemoveAll(path.Join(d.home, linkDir, string(lid))); err != nil {
  391. logrus.Debugf("Failed to remove link: %v", err)
  392. }
  393. }
  394. if err := os.RemoveAll(dir); err != nil && !os.IsNotExist(err) {
  395. return err
  396. }
  397. return nil
  398. }
  399. // Get creates and mounts the required file system for the given id and returns the mount path.
  400. func (d *Driver) Get(id string, mountLabel string) (s string, err error) {
  401. dir := d.dir(id)
  402. if _, err := os.Stat(dir); err != nil {
  403. return "", err
  404. }
  405. diffDir := path.Join(dir, "diff")
  406. lowers, err := ioutil.ReadFile(path.Join(dir, lowerFile))
  407. if err != nil {
  408. // If no lower, just return diff directory
  409. if os.IsNotExist(err) {
  410. return diffDir, nil
  411. }
  412. return "", err
  413. }
  414. mergedDir := path.Join(dir, "merged")
  415. if count := d.ctr.Increment(mergedDir); count > 1 {
  416. return mergedDir, nil
  417. }
  418. defer func() {
  419. if err != nil {
  420. if c := d.ctr.Decrement(mergedDir); c <= 0 {
  421. syscall.Unmount(mergedDir, 0)
  422. }
  423. }
  424. }()
  425. workDir := path.Join(dir, "work")
  426. splitLowers := strings.Split(string(lowers), ":")
  427. absLowers := make([]string, len(splitLowers))
  428. for i, s := range splitLowers {
  429. absLowers[i] = path.Join(d.home, s)
  430. }
  431. opts := fmt.Sprintf("lowerdir=%s,upperdir=%s,workdir=%s", strings.Join(absLowers, ":"), path.Join(dir, "diff"), path.Join(dir, "work"))
  432. mountData := label.FormatMountLabel(opts, mountLabel)
  433. mount := syscall.Mount
  434. mountTarget := mergedDir
  435. pageSize := syscall.Getpagesize()
  436. // Go can return a larger page size than supported by the system
  437. // as of go 1.7. This will be fixed in 1.8 and this block can be
  438. // removed when building with 1.8.
  439. // See https://github.com/golang/go/commit/1b9499b06989d2831e5b156161d6c07642926ee1
  440. // See https://github.com/docker/docker/issues/27384
  441. if pageSize > 4096 {
  442. pageSize = 4096
  443. }
  444. // Use relative paths and mountFrom when the mount data has exceeded
  445. // the page size. The mount syscall fails if the mount data cannot
  446. // fit within a page and relative links make the mount data much
  447. // smaller at the expense of requiring a fork exec to chroot.
  448. if len(mountData) > pageSize {
  449. opts = fmt.Sprintf("lowerdir=%s,upperdir=%s,workdir=%s", string(lowers), path.Join(id, "diff"), path.Join(id, "work"))
  450. mountData = label.FormatMountLabel(opts, mountLabel)
  451. if len(mountData) > pageSize {
  452. return "", fmt.Errorf("cannot mount layer, mount label too large %d", len(mountData))
  453. }
  454. mount = func(source string, target string, mType string, flags uintptr, label string) error {
  455. return mountFrom(d.home, source, target, mType, flags, label)
  456. }
  457. mountTarget = path.Join(id, "merged")
  458. }
  459. if err := mount("overlay", mountTarget, "overlay", 0, mountData); err != nil {
  460. return "", fmt.Errorf("error creating overlay mount to %s: %v", mergedDir, err)
  461. }
  462. // chown "workdir/work" to the remapped root UID/GID. Overlay fs inside a
  463. // user namespace requires this to move a directory from lower to upper.
  464. rootUID, rootGID, err := idtools.GetRootUIDGID(d.uidMaps, d.gidMaps)
  465. if err != nil {
  466. return "", err
  467. }
  468. if err := os.Chown(path.Join(workDir, "work"), rootUID, rootGID); err != nil {
  469. return "", err
  470. }
  471. return mergedDir, nil
  472. }
  473. // Put unmounts the mount path created for the give id.
  474. func (d *Driver) Put(id string) error {
  475. mountpoint := path.Join(d.dir(id), "merged")
  476. if count := d.ctr.Decrement(mountpoint); count > 0 {
  477. return nil
  478. }
  479. if err := syscall.Unmount(mountpoint, 0); err != nil {
  480. logrus.Debugf("Failed to unmount %s overlay: %s - %v", id, mountpoint, err)
  481. }
  482. return nil
  483. }
  484. // Exists checks to see if the id is already mounted.
  485. func (d *Driver) Exists(id string) bool {
  486. _, err := os.Stat(d.dir(id))
  487. return err == nil
  488. }
  489. // isParent returns if the passed in parent is the direct parent of the passed in layer
  490. func (d *Driver) isParent(id, parent string) bool {
  491. lowers, err := d.getLowerDirs(id)
  492. if err != nil {
  493. return false
  494. }
  495. if parent == "" && len(lowers) > 0 {
  496. return false
  497. }
  498. parentDir := d.dir(parent)
  499. var ld string
  500. if len(lowers) > 0 {
  501. ld = filepath.Dir(lowers[0])
  502. }
  503. if ld == "" && parent == "" {
  504. return true
  505. }
  506. return ld == parentDir
  507. }
  508. // ApplyDiff applies the new layer into a root
  509. func (d *Driver) ApplyDiff(id string, parent string, diff io.Reader) (size int64, err error) {
  510. if !d.isParent(id, parent) {
  511. return d.naiveDiff.ApplyDiff(id, parent, diff)
  512. }
  513. applyDir := d.getDiffPath(id)
  514. logrus.Debugf("Applying tar in %s", applyDir)
  515. // Overlay doesn't need the parent id to apply the diff
  516. if err := untar(diff, applyDir, &archive.TarOptions{
  517. UIDMaps: d.uidMaps,
  518. GIDMaps: d.gidMaps,
  519. WhiteoutFormat: archive.OverlayWhiteoutFormat,
  520. }); err != nil {
  521. return 0, err
  522. }
  523. return directory.Size(applyDir)
  524. }
  525. func (d *Driver) getDiffPath(id string) string {
  526. dir := d.dir(id)
  527. return path.Join(dir, "diff")
  528. }
  529. // DiffSize calculates the changes between the specified id
  530. // and its parent and returns the size in bytes of the changes
  531. // relative to its base filesystem directory.
  532. func (d *Driver) DiffSize(id, parent string) (size int64, err error) {
  533. if useNaiveDiff(d.home) || !d.isParent(id, parent) {
  534. return d.naiveDiff.DiffSize(id, parent)
  535. }
  536. return directory.Size(d.getDiffPath(id))
  537. }
  538. // Diff produces an archive of the changes between the specified
  539. // layer and its parent layer which may be "".
  540. func (d *Driver) Diff(id, parent string) (io.ReadCloser, error) {
  541. if useNaiveDiff(d.home) || !d.isParent(id, parent) {
  542. return d.naiveDiff.Diff(id, parent)
  543. }
  544. diffPath := d.getDiffPath(id)
  545. logrus.Debugf("Tar with options on %s", diffPath)
  546. return archive.TarWithOptions(diffPath, &archive.TarOptions{
  547. Compression: archive.Uncompressed,
  548. UIDMaps: d.uidMaps,
  549. GIDMaps: d.gidMaps,
  550. WhiteoutFormat: archive.OverlayWhiteoutFormat,
  551. })
  552. }
  553. // Changes produces a list of changes between the specified layer
  554. // and its parent layer. If parent is "", then all changes will be ADD changes.
  555. func (d *Driver) Changes(id, parent string) ([]archive.Change, error) {
  556. if useNaiveDiff(d.home) || !d.isParent(id, parent) {
  557. return d.naiveDiff.Changes(id, parent)
  558. }
  559. // Overlay doesn't have snapshots, so we need to get changes from all parent
  560. // layers.
  561. diffPath := d.getDiffPath(id)
  562. layers, err := d.getLowerDirs(id)
  563. if err != nil {
  564. return nil, err
  565. }
  566. return archive.OverlayChanges(layers, diffPath)
  567. }