btrfs.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672
  1. // +build linux
  2. package btrfs
  3. /*
  4. #include <stdlib.h>
  5. #include <dirent.h>
  6. #include <btrfs/ioctl.h>
  7. #include <btrfs/ctree.h>
  8. static void set_name_btrfs_ioctl_vol_args_v2(struct btrfs_ioctl_vol_args_v2* btrfs_struct, const char* value) {
  9. snprintf(btrfs_struct->name, BTRFS_SUBVOL_NAME_MAX, "%s", value);
  10. }
  11. */
  12. import "C"
  13. import (
  14. "fmt"
  15. "io/ioutil"
  16. "math"
  17. "os"
  18. "path"
  19. "path/filepath"
  20. "strconv"
  21. "strings"
  22. "sync"
  23. "unsafe"
  24. "github.com/docker/docker/daemon/graphdriver"
  25. "github.com/docker/docker/pkg/containerfs"
  26. "github.com/docker/docker/pkg/idtools"
  27. "github.com/docker/docker/pkg/mount"
  28. "github.com/docker/docker/pkg/parsers"
  29. "github.com/docker/docker/pkg/system"
  30. "github.com/docker/go-units"
  31. "github.com/opencontainers/selinux/go-selinux/label"
  32. "github.com/sirupsen/logrus"
  33. "golang.org/x/sys/unix"
  34. )
  35. func init() {
  36. graphdriver.Register("btrfs", Init)
  37. }
  38. type btrfsOptions struct {
  39. minSpace uint64
  40. size uint64
  41. }
  42. // Init returns a new BTRFS driver.
  43. // An error is returned if BTRFS is not supported.
  44. func Init(home string, options []string, uidMaps, gidMaps []idtools.IDMap) (graphdriver.Driver, error) {
  45. fsMagic, err := graphdriver.GetFSMagic(home)
  46. if err != nil {
  47. return nil, err
  48. }
  49. if fsMagic != graphdriver.FsMagicBtrfs {
  50. return nil, graphdriver.ErrPrerequisites
  51. }
  52. rootUID, rootGID, err := idtools.GetRootUIDGID(uidMaps, gidMaps)
  53. if err != nil {
  54. return nil, err
  55. }
  56. if err := idtools.MkdirAllAs(home, 0700, rootUID, rootGID); err != nil {
  57. return nil, err
  58. }
  59. if err := mount.MakePrivate(home); err != nil {
  60. return nil, err
  61. }
  62. opt, userDiskQuota, err := parseOptions(options)
  63. if err != nil {
  64. return nil, err
  65. }
  66. driver := &Driver{
  67. home: home,
  68. uidMaps: uidMaps,
  69. gidMaps: gidMaps,
  70. options: opt,
  71. }
  72. if userDiskQuota {
  73. if err := driver.subvolEnableQuota(); err != nil {
  74. return nil, err
  75. }
  76. }
  77. return graphdriver.NewNaiveDiffDriver(driver, uidMaps, gidMaps), nil
  78. }
  79. func parseOptions(opt []string) (btrfsOptions, bool, error) {
  80. var options btrfsOptions
  81. userDiskQuota := false
  82. for _, option := range opt {
  83. key, val, err := parsers.ParseKeyValueOpt(option)
  84. if err != nil {
  85. return options, userDiskQuota, err
  86. }
  87. key = strings.ToLower(key)
  88. switch key {
  89. case "btrfs.min_space":
  90. minSpace, err := units.RAMInBytes(val)
  91. if err != nil {
  92. return options, userDiskQuota, err
  93. }
  94. userDiskQuota = true
  95. options.minSpace = uint64(minSpace)
  96. default:
  97. return options, userDiskQuota, fmt.Errorf("Unknown option %s", key)
  98. }
  99. }
  100. return options, userDiskQuota, nil
  101. }
  102. // Driver contains information about the filesystem mounted.
  103. type Driver struct {
  104. //root of the file system
  105. home string
  106. uidMaps []idtools.IDMap
  107. gidMaps []idtools.IDMap
  108. options btrfsOptions
  109. quotaEnabled bool
  110. once sync.Once
  111. }
  112. // String prints the name of the driver (btrfs).
  113. func (d *Driver) String() string {
  114. return "btrfs"
  115. }
  116. // Status returns current driver information in a two dimensional string array.
  117. // Output contains "Build Version" and "Library Version" of the btrfs libraries used.
  118. // Version information can be used to check compatibility with your kernel.
  119. func (d *Driver) Status() [][2]string {
  120. status := [][2]string{}
  121. if bv := btrfsBuildVersion(); bv != "-" {
  122. status = append(status, [2]string{"Build Version", bv})
  123. }
  124. if lv := btrfsLibVersion(); lv != -1 {
  125. status = append(status, [2]string{"Library Version", fmt.Sprintf("%d", lv)})
  126. }
  127. return status
  128. }
  129. // GetMetadata returns empty metadata for this driver.
  130. func (d *Driver) GetMetadata(id string) (map[string]string, error) {
  131. return nil, nil
  132. }
  133. // Cleanup unmounts the home directory.
  134. func (d *Driver) Cleanup() error {
  135. if err := d.subvolDisableQuota(); err != nil {
  136. return err
  137. }
  138. return mount.Unmount(d.home)
  139. }
  140. func free(p *C.char) {
  141. C.free(unsafe.Pointer(p))
  142. }
  143. func openDir(path string) (*C.DIR, error) {
  144. Cpath := C.CString(path)
  145. defer free(Cpath)
  146. dir := C.opendir(Cpath)
  147. if dir == nil {
  148. return nil, fmt.Errorf("Can't open dir")
  149. }
  150. return dir, nil
  151. }
  152. func closeDir(dir *C.DIR) {
  153. if dir != nil {
  154. C.closedir(dir)
  155. }
  156. }
  157. func getDirFd(dir *C.DIR) uintptr {
  158. return uintptr(C.dirfd(dir))
  159. }
  160. func subvolCreate(path, name string) error {
  161. dir, err := openDir(path)
  162. if err != nil {
  163. return err
  164. }
  165. defer closeDir(dir)
  166. var args C.struct_btrfs_ioctl_vol_args
  167. for i, c := range []byte(name) {
  168. args.name[i] = C.char(c)
  169. }
  170. _, _, errno := unix.Syscall(unix.SYS_IOCTL, getDirFd(dir), C.BTRFS_IOC_SUBVOL_CREATE,
  171. uintptr(unsafe.Pointer(&args)))
  172. if errno != 0 {
  173. return fmt.Errorf("Failed to create btrfs subvolume: %v", errno.Error())
  174. }
  175. return nil
  176. }
  177. func subvolSnapshot(src, dest, name string) error {
  178. srcDir, err := openDir(src)
  179. if err != nil {
  180. return err
  181. }
  182. defer closeDir(srcDir)
  183. destDir, err := openDir(dest)
  184. if err != nil {
  185. return err
  186. }
  187. defer closeDir(destDir)
  188. var args C.struct_btrfs_ioctl_vol_args_v2
  189. args.fd = C.__s64(getDirFd(srcDir))
  190. var cs = C.CString(name)
  191. C.set_name_btrfs_ioctl_vol_args_v2(&args, cs)
  192. C.free(unsafe.Pointer(cs))
  193. _, _, errno := unix.Syscall(unix.SYS_IOCTL, getDirFd(destDir), C.BTRFS_IOC_SNAP_CREATE_V2,
  194. uintptr(unsafe.Pointer(&args)))
  195. if errno != 0 {
  196. return fmt.Errorf("Failed to create btrfs snapshot: %v", errno.Error())
  197. }
  198. return nil
  199. }
  200. func isSubvolume(p string) (bool, error) {
  201. var bufStat unix.Stat_t
  202. if err := unix.Lstat(p, &bufStat); err != nil {
  203. return false, err
  204. }
  205. // return true if it is a btrfs subvolume
  206. return bufStat.Ino == C.BTRFS_FIRST_FREE_OBJECTID, nil
  207. }
  208. func subvolDelete(dirpath, name string, quotaEnabled bool) error {
  209. dir, err := openDir(dirpath)
  210. if err != nil {
  211. return err
  212. }
  213. defer closeDir(dir)
  214. fullPath := path.Join(dirpath, name)
  215. var args C.struct_btrfs_ioctl_vol_args
  216. // walk the btrfs subvolumes
  217. walkSubvolumes := func(p string, f os.FileInfo, err error) error {
  218. if err != nil {
  219. if os.IsNotExist(err) && p != fullPath {
  220. // missing most likely because the path was a subvolume that got removed in the previous iteration
  221. // since it's gone anyway, we don't care
  222. return nil
  223. }
  224. return fmt.Errorf("error walking subvolumes: %v", err)
  225. }
  226. // we want to check children only so skip itself
  227. // it will be removed after the filepath walk anyways
  228. if f.IsDir() && p != fullPath {
  229. sv, err := isSubvolume(p)
  230. if err != nil {
  231. return fmt.Errorf("Failed to test if %s is a btrfs subvolume: %v", p, err)
  232. }
  233. if sv {
  234. if err := subvolDelete(path.Dir(p), f.Name(), quotaEnabled); err != nil {
  235. return fmt.Errorf("Failed to destroy btrfs child subvolume (%s) of parent (%s): %v", p, dirpath, err)
  236. }
  237. }
  238. }
  239. return nil
  240. }
  241. if err := filepath.Walk(path.Join(dirpath, name), walkSubvolumes); err != nil {
  242. return fmt.Errorf("Recursively walking subvolumes for %s failed: %v", dirpath, err)
  243. }
  244. if quotaEnabled {
  245. if qgroupid, err := subvolLookupQgroup(fullPath); err == nil {
  246. var args C.struct_btrfs_ioctl_qgroup_create_args
  247. args.qgroupid = C.__u64(qgroupid)
  248. _, _, errno := unix.Syscall(unix.SYS_IOCTL, getDirFd(dir), C.BTRFS_IOC_QGROUP_CREATE,
  249. uintptr(unsafe.Pointer(&args)))
  250. if errno != 0 {
  251. logrus.Errorf("Failed to delete btrfs qgroup %v for %s: %v", qgroupid, fullPath, errno.Error())
  252. }
  253. } else {
  254. logrus.Errorf("Failed to lookup btrfs qgroup for %s: %v", fullPath, err.Error())
  255. }
  256. }
  257. // all subvolumes have been removed
  258. // now remove the one originally passed in
  259. for i, c := range []byte(name) {
  260. args.name[i] = C.char(c)
  261. }
  262. _, _, errno := unix.Syscall(unix.SYS_IOCTL, getDirFd(dir), C.BTRFS_IOC_SNAP_DESTROY,
  263. uintptr(unsafe.Pointer(&args)))
  264. if errno != 0 {
  265. return fmt.Errorf("Failed to destroy btrfs snapshot %s for %s: %v", dirpath, name, errno.Error())
  266. }
  267. return nil
  268. }
  269. func (d *Driver) updateQuotaStatus() {
  270. d.once.Do(func() {
  271. if !d.quotaEnabled {
  272. // In case quotaEnabled is not set, check qgroup and update quotaEnabled as needed
  273. if err := subvolQgroupStatus(d.home); err != nil {
  274. // quota is still not enabled
  275. return
  276. }
  277. d.quotaEnabled = true
  278. }
  279. })
  280. }
  281. func (d *Driver) subvolEnableQuota() error {
  282. d.updateQuotaStatus()
  283. if d.quotaEnabled {
  284. return nil
  285. }
  286. dir, err := openDir(d.home)
  287. if err != nil {
  288. return err
  289. }
  290. defer closeDir(dir)
  291. var args C.struct_btrfs_ioctl_quota_ctl_args
  292. args.cmd = C.BTRFS_QUOTA_CTL_ENABLE
  293. _, _, errno := unix.Syscall(unix.SYS_IOCTL, getDirFd(dir), C.BTRFS_IOC_QUOTA_CTL,
  294. uintptr(unsafe.Pointer(&args)))
  295. if errno != 0 {
  296. return fmt.Errorf("Failed to enable btrfs quota for %s: %v", dir, errno.Error())
  297. }
  298. d.quotaEnabled = true
  299. return nil
  300. }
  301. func (d *Driver) subvolDisableQuota() error {
  302. d.updateQuotaStatus()
  303. if !d.quotaEnabled {
  304. return nil
  305. }
  306. dir, err := openDir(d.home)
  307. if err != nil {
  308. return err
  309. }
  310. defer closeDir(dir)
  311. var args C.struct_btrfs_ioctl_quota_ctl_args
  312. args.cmd = C.BTRFS_QUOTA_CTL_DISABLE
  313. _, _, errno := unix.Syscall(unix.SYS_IOCTL, getDirFd(dir), C.BTRFS_IOC_QUOTA_CTL,
  314. uintptr(unsafe.Pointer(&args)))
  315. if errno != 0 {
  316. return fmt.Errorf("Failed to disable btrfs quota for %s: %v", dir, errno.Error())
  317. }
  318. d.quotaEnabled = false
  319. return nil
  320. }
  321. func (d *Driver) subvolRescanQuota() error {
  322. d.updateQuotaStatus()
  323. if !d.quotaEnabled {
  324. return nil
  325. }
  326. dir, err := openDir(d.home)
  327. if err != nil {
  328. return err
  329. }
  330. defer closeDir(dir)
  331. var args C.struct_btrfs_ioctl_quota_rescan_args
  332. _, _, errno := unix.Syscall(unix.SYS_IOCTL, getDirFd(dir), C.BTRFS_IOC_QUOTA_RESCAN_WAIT,
  333. uintptr(unsafe.Pointer(&args)))
  334. if errno != 0 {
  335. return fmt.Errorf("Failed to rescan btrfs quota for %s: %v", dir, errno.Error())
  336. }
  337. return nil
  338. }
  339. func subvolLimitQgroup(path string, size uint64) error {
  340. dir, err := openDir(path)
  341. if err != nil {
  342. return err
  343. }
  344. defer closeDir(dir)
  345. var args C.struct_btrfs_ioctl_qgroup_limit_args
  346. args.lim.max_referenced = C.__u64(size)
  347. args.lim.flags = C.BTRFS_QGROUP_LIMIT_MAX_RFER
  348. _, _, errno := unix.Syscall(unix.SYS_IOCTL, getDirFd(dir), C.BTRFS_IOC_QGROUP_LIMIT,
  349. uintptr(unsafe.Pointer(&args)))
  350. if errno != 0 {
  351. return fmt.Errorf("Failed to limit qgroup for %s: %v", dir, errno.Error())
  352. }
  353. return nil
  354. }
  355. // subvolQgroupStatus performs a BTRFS_IOC_TREE_SEARCH on the root path
  356. // with search key of BTRFS_QGROUP_STATUS_KEY.
  357. // In case qgroup is enabled, the retuned key type will match BTRFS_QGROUP_STATUS_KEY.
  358. // For more details please see https://github.com/kdave/btrfs-progs/blob/v4.9/qgroup.c#L1035
  359. func subvolQgroupStatus(path string) error {
  360. dir, err := openDir(path)
  361. if err != nil {
  362. return err
  363. }
  364. defer closeDir(dir)
  365. var args C.struct_btrfs_ioctl_search_args
  366. args.key.tree_id = C.BTRFS_QUOTA_TREE_OBJECTID
  367. args.key.min_type = C.BTRFS_QGROUP_STATUS_KEY
  368. args.key.max_type = C.BTRFS_QGROUP_STATUS_KEY
  369. args.key.max_objectid = C.__u64(math.MaxUint64)
  370. args.key.max_offset = C.__u64(math.MaxUint64)
  371. args.key.max_transid = C.__u64(math.MaxUint64)
  372. args.key.nr_items = 4096
  373. _, _, errno := unix.Syscall(unix.SYS_IOCTL, getDirFd(dir), C.BTRFS_IOC_TREE_SEARCH,
  374. uintptr(unsafe.Pointer(&args)))
  375. if errno != 0 {
  376. return fmt.Errorf("Failed to search qgroup for %s: %v", path, errno.Error())
  377. }
  378. sh := (*C.struct_btrfs_ioctl_search_header)(unsafe.Pointer(&args.buf))
  379. if sh._type != C.BTRFS_QGROUP_STATUS_KEY {
  380. return fmt.Errorf("Invalid qgroup search header type for %s: %v", path, sh._type)
  381. }
  382. return nil
  383. }
  384. func subvolLookupQgroup(path string) (uint64, error) {
  385. dir, err := openDir(path)
  386. if err != nil {
  387. return 0, err
  388. }
  389. defer closeDir(dir)
  390. var args C.struct_btrfs_ioctl_ino_lookup_args
  391. args.objectid = C.BTRFS_FIRST_FREE_OBJECTID
  392. _, _, errno := unix.Syscall(unix.SYS_IOCTL, getDirFd(dir), C.BTRFS_IOC_INO_LOOKUP,
  393. uintptr(unsafe.Pointer(&args)))
  394. if errno != 0 {
  395. return 0, fmt.Errorf("Failed to lookup qgroup for %s: %v", dir, errno.Error())
  396. }
  397. if args.treeid == 0 {
  398. return 0, fmt.Errorf("Invalid qgroup id for %s: 0", dir)
  399. }
  400. return uint64(args.treeid), nil
  401. }
  402. func (d *Driver) subvolumesDir() string {
  403. return path.Join(d.home, "subvolumes")
  404. }
  405. func (d *Driver) subvolumesDirID(id string) string {
  406. return path.Join(d.subvolumesDir(), id)
  407. }
  408. func (d *Driver) quotasDir() string {
  409. return path.Join(d.home, "quotas")
  410. }
  411. func (d *Driver) quotasDirID(id string) string {
  412. return path.Join(d.quotasDir(), id)
  413. }
  414. // CreateReadWrite creates a layer that is writable for use as a container
  415. // file system.
  416. func (d *Driver) CreateReadWrite(id, parent string, opts *graphdriver.CreateOpts) error {
  417. return d.Create(id, parent, opts)
  418. }
  419. // Create the filesystem with given id.
  420. func (d *Driver) Create(id, parent string, opts *graphdriver.CreateOpts) error {
  421. quotas := path.Join(d.home, "quotas")
  422. subvolumes := path.Join(d.home, "subvolumes")
  423. rootUID, rootGID, err := idtools.GetRootUIDGID(d.uidMaps, d.gidMaps)
  424. if err != nil {
  425. return err
  426. }
  427. if err := idtools.MkdirAllAs(subvolumes, 0700, rootUID, rootGID); err != nil {
  428. return err
  429. }
  430. if parent == "" {
  431. if err := subvolCreate(subvolumes, id); err != nil {
  432. return err
  433. }
  434. } else {
  435. parentDir := d.subvolumesDirID(parent)
  436. st, err := os.Stat(parentDir)
  437. if err != nil {
  438. return err
  439. }
  440. if !st.IsDir() {
  441. return fmt.Errorf("%s: not a directory", parentDir)
  442. }
  443. if err := subvolSnapshot(parentDir, subvolumes, id); err != nil {
  444. return err
  445. }
  446. }
  447. var storageOpt map[string]string
  448. if opts != nil {
  449. storageOpt = opts.StorageOpt
  450. }
  451. if _, ok := storageOpt["size"]; ok {
  452. driver := &Driver{}
  453. if err := d.parseStorageOpt(storageOpt, driver); err != nil {
  454. return err
  455. }
  456. if err := d.setStorageSize(path.Join(subvolumes, id), driver); err != nil {
  457. return err
  458. }
  459. if err := idtools.MkdirAllAs(quotas, 0700, rootUID, rootGID); err != nil {
  460. return err
  461. }
  462. if err := ioutil.WriteFile(path.Join(quotas, id), []byte(fmt.Sprint(driver.options.size)), 0644); err != nil {
  463. return err
  464. }
  465. }
  466. // if we have a remapped root (user namespaces enabled), change the created snapshot
  467. // dir ownership to match
  468. if rootUID != 0 || rootGID != 0 {
  469. if err := os.Chown(path.Join(subvolumes, id), rootUID, rootGID); err != nil {
  470. return err
  471. }
  472. }
  473. mountLabel := ""
  474. if opts != nil {
  475. mountLabel = opts.MountLabel
  476. }
  477. return label.Relabel(path.Join(subvolumes, id), mountLabel, false)
  478. }
  479. // Parse btrfs storage options
  480. func (d *Driver) parseStorageOpt(storageOpt map[string]string, driver *Driver) error {
  481. // Read size to change the subvolume disk quota per container
  482. for key, val := range storageOpt {
  483. key := strings.ToLower(key)
  484. switch key {
  485. case "size":
  486. size, err := units.RAMInBytes(val)
  487. if err != nil {
  488. return err
  489. }
  490. driver.options.size = uint64(size)
  491. default:
  492. return fmt.Errorf("Unknown option %s", key)
  493. }
  494. }
  495. return nil
  496. }
  497. // Set btrfs storage size
  498. func (d *Driver) setStorageSize(dir string, driver *Driver) error {
  499. if driver.options.size <= 0 {
  500. return fmt.Errorf("btrfs: invalid storage size: %s", units.HumanSize(float64(driver.options.size)))
  501. }
  502. if d.options.minSpace > 0 && driver.options.size < d.options.minSpace {
  503. return fmt.Errorf("btrfs: storage size cannot be less than %s", units.HumanSize(float64(d.options.minSpace)))
  504. }
  505. if err := d.subvolEnableQuota(); err != nil {
  506. return err
  507. }
  508. if err := subvolLimitQgroup(dir, driver.options.size); err != nil {
  509. return err
  510. }
  511. return nil
  512. }
  513. // Remove the filesystem with given id.
  514. func (d *Driver) Remove(id string) error {
  515. dir := d.subvolumesDirID(id)
  516. if _, err := os.Stat(dir); err != nil {
  517. return err
  518. }
  519. quotasDir := d.quotasDirID(id)
  520. if _, err := os.Stat(quotasDir); err == nil {
  521. if err := os.Remove(quotasDir); err != nil {
  522. return err
  523. }
  524. } else if !os.IsNotExist(err) {
  525. return err
  526. }
  527. // Call updateQuotaStatus() to invoke status update
  528. d.updateQuotaStatus()
  529. if err := subvolDelete(d.subvolumesDir(), id, d.quotaEnabled); err != nil {
  530. return err
  531. }
  532. if err := system.EnsureRemoveAll(dir); err != nil {
  533. return err
  534. }
  535. if err := d.subvolRescanQuota(); err != nil {
  536. return err
  537. }
  538. return nil
  539. }
  540. // Get the requested filesystem id.
  541. func (d *Driver) Get(id, mountLabel string) (containerfs.ContainerFS, error) {
  542. dir := d.subvolumesDirID(id)
  543. st, err := os.Stat(dir)
  544. if err != nil {
  545. return nil, err
  546. }
  547. if !st.IsDir() {
  548. return nil, fmt.Errorf("%s: not a directory", dir)
  549. }
  550. if quota, err := ioutil.ReadFile(d.quotasDirID(id)); err == nil {
  551. if size, err := strconv.ParseUint(string(quota), 10, 64); err == nil && size >= d.options.minSpace {
  552. if err := d.subvolEnableQuota(); err != nil {
  553. return nil, err
  554. }
  555. if err := subvolLimitQgroup(dir, size); err != nil {
  556. return nil, err
  557. }
  558. }
  559. }
  560. return containerfs.NewLocalContainerFS(dir), nil
  561. }
  562. // Put is not implemented for BTRFS as there is no cleanup required for the id.
  563. func (d *Driver) Put(id string) error {
  564. // Get() creates no runtime resources (like e.g. mounts)
  565. // so this doesn't need to do anything.
  566. return nil
  567. }
  568. // Exists checks if the id exists in the filesystem.
  569. func (d *Driver) Exists(id string) bool {
  570. dir := d.subvolumesDirID(id)
  571. _, err := os.Stat(dir)
  572. return err == nil
  573. }