Przeglądaj źródła

Merge pull request #16683 from rhvgoyal/fix-couple-of-bugs

devmapper: Fix a bug and fix a comment and add one reliability check
David Calavera 9 lat temu
rodzic
commit
8ebd0c972a

+ 13 - 1
daemon/graphdriver/devmapper/deviceset.go

@@ -388,6 +388,11 @@ func (devices *DeviceSet) deviceFileWalkFunction(path string, finfo os.FileInfo)
 		return nil
 	}
 
+	if finfo.Name() == transactionMetaFile {
+		logrus.Debugf("Skipping file %s", path)
+		return nil
+	}
+
 	logrus.Debugf("Loading data for file %s", path)
 
 	hash := finfo.Name()
@@ -1516,6 +1521,13 @@ func (devices *DeviceSet) DeleteDevice(hash string) error {
 	devices.Lock()
 	defer devices.Unlock()
 
+	// If mountcount is not zero, that means devices is still in use
+	// or has not been Put() properly. Fail device deletion.
+
+	if info.mountCount != 0 {
+		return fmt.Errorf("devmapper: Can't delete device %v as it is still mounted. mntCount=%v", info.Hash, info.mountCount)
+	}
+
 	return devices.deleteDevice(info)
 }
 
@@ -1781,7 +1793,7 @@ func (devices *DeviceSet) UnmountDevice(hash string) error {
 	return nil
 }
 
-// HasDevice returns true if the device is in the hash and mounted.
+// HasDevice returns true if the device metadata exists.
 func (devices *DeviceSet) HasDevice(hash string) bool {
 	devices.Lock()
 	defer devices.Unlock()

+ 1 - 1
daemon/graphdriver/devmapper/driver.go

@@ -196,7 +196,7 @@ func (d *Driver) Put(id string) error {
 	return err
 }
 
-// Exists checks to see if the device is mounted.
+// Exists checks to see if the device exists.
 func (d *Driver) Exists(id string) bool {
 	return d.DeviceSet.HasDevice(id)
 }