btrfs.go 17 KB

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