Sfoglia il codice sorgente

DeviceSet: Add UnmountDevice()

Right now this does nothing but add a new layer, but it means
that all DeviceMounts are paired with DeviceUnmounts so that we
can track (and cleanup) active mounts.
Alexander Larsson 11 anni fa
parent
commit
251a7ed437
3 ha cambiato i file con 24 aggiunte e 8 eliminazioni
  1. 5 0
      deviceset.go
  2. 11 1
      devmapper/deviceset_devmapper.go
  3. 8 7
      image.go

+ 5 - 0
deviceset.go

@@ -6,6 +6,7 @@ type DeviceSet interface {
 	DeactivateDevice(hash string) error
 	RemoveDevice(hash string) error
 	MountDevice(hash, path string) error
+	UnmountDevice(hash, path string) error
 	HasDevice(hash string) bool
 	HasInitializedDevice(hash string) bool
 }
@@ -43,6 +44,10 @@ func (wrapper *DeviceSetWrapper) MountDevice(hash, path string) error {
 	return wrapper.wrapped.MountDevice(wrapper.wrap(hash), path)
 }
 
+func (wrapper *DeviceSetWrapper) UnmountDevice(hash, path string) error {
+	return wrapper.wrapped.UnmountDevice(wrapper.wrap(hash), path)
+}
+
 func (wrapper *DeviceSetWrapper) HasDevice(hash string) bool {
 	return wrapper.wrapped.HasDevice(wrapper.wrap(hash))
 }

+ 11 - 1
devmapper/deviceset_devmapper.go

@@ -637,7 +637,7 @@ func (devices *DeviceSetDM) setupBaseImage() error {
 		return err
 	}
 
-	err = syscall.Unmount(tmpDir, 0)
+	err = devices.UnmountDevice("", tmpDir)
 	if err != nil {
 		return err
 	}
@@ -840,6 +840,16 @@ func (devices *DeviceSetDM) MountDevice(hash, path string) error {
 	return nil
 }
 
+func (devices *DeviceSetDM) UnmountDevice(hash, path string) error {
+	err := syscall.Unmount(path, 0)
+	if err != nil {
+		return err
+	}
+
+	return nil
+}
+
+
 func (devices *DeviceSetDM) HasDevice(hash string) bool {
 	if err := devices.ensureInit(); err != nil {
 		return false

+ 8 - 7
image.go

@@ -379,7 +379,7 @@ func (image *Image) ensureImageDevice(devices DeviceSet) error {
 		return err
 	}
 
-	err = syscall.Unmount(mountDir, 0)
+	err = devices.UnmountDevice(image.ID, mountDir)
 	if err != nil {
 		_ = devices.RemoveDevice(image.ID)
 		return err
@@ -467,16 +467,17 @@ func (image *Image) Unmount(runtime *Runtime, root string, id string) error {
 		return Unmount(root)
 
 	case MountMethodDeviceMapper:
-		err := syscall.Unmount(root, 0)
-		if err != nil {
-			return err
-		}
-
 		// Try to deactivate the device as generally there is no use for it anymore
 		devices, err := runtime.GetDeviceSet()
 		if err != nil {
 			return err;
 		}
+
+		err = devices.UnmountDevice(id, root)
+		if err != nil {
+			return err
+		}
+
 		return devices.DeactivateDevice(id)
 	}
 	return nil
@@ -509,7 +510,7 @@ func (image *Image) Changes(runtime *Runtime, root, rw, id string) ([]Change, er
 		}
 
 		changes, err := ChangesDirs(root, rw)
-		_ = syscall.Unmount(rw, 0)
+		_ = devices.UnmountDevice(image.ID, rw)
 		if err != nil {
 			return nil, err
 		}