Browse code

Allow existing setups to continue using d_type

Even though it's highly discouraged, there are existing
installs that are running overlay/overlay2 on filesystems
without d_type support.

This patch allows the daemon to start in such cases, instead of
refusing to start without an option to override.

For fresh installs, backing filesystems without d_type support
will still cause the overlay/overlay2 drivers to be marked as
"unsupported", and skipped during the automatic selection.

This feature is only to keep backward compatibility, but
will be removed at some point.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>

Sebastiaan van Stijn authored on 2017/12/05 10:02:52
Showing 3 changed files
... ...
@@ -277,6 +277,18 @@ func scanPriorDrivers(root string) map[string]bool {
277 277
 	return driversMap
278 278
 }
279 279
 
280
+// IsInitialized checks if the driver's home-directory exists and is non-empty.
281
+func IsInitialized(driverHome string) bool {
282
+	_, err := os.Stat(driverHome)
283
+	if os.IsNotExist(err) {
284
+		return false
285
+	}
286
+	if err != nil {
287
+		logrus.Warnf("graphdriver.IsInitialized: stat failed: %v", err)
288
+	}
289
+	return !isEmptyDir(driverHome)
290
+}
291
+
280 292
 // isEmptyDir checks if a directory is empty. It is used to check if prior
281 293
 // storage-driver directories exist. If an error occurs, it also assumes the
282 294
 // directory is not empty (which preserves the behavior _before_ this check
... ...
@@ -148,7 +148,11 @@ func Init(home string, options []string, uidMaps, gidMaps []idtools.IDMap) (grap
148 148
 		return nil, err
149 149
 	}
150 150
 	if !supportsDType {
151
-		return nil, overlayutils.ErrDTypeNotSupported("overlay", backingFs)
151
+		if !graphdriver.IsInitialized(home) {
152
+			return nil, overlayutils.ErrDTypeNotSupported("overlay", backingFs)
153
+		}
154
+		// allow running without d_type only for existing setups (#27443)
155
+		logrus.Warn(overlayutils.ErrDTypeNotSupported("overlay", backingFs))
152 156
 	}
153 157
 
154 158
 	rootUID, rootGID, err := idtools.GetRootUIDGID(uidMaps, gidMaps)
... ...
@@ -184,7 +184,11 @@ func Init(home string, options []string, uidMaps, gidMaps []idtools.IDMap) (grap
184 184
 		return nil, err
185 185
 	}
186 186
 	if !supportsDType {
187
-		return nil, overlayutils.ErrDTypeNotSupported("overlay2", backingFs)
187
+		if !graphdriver.IsInitialized(home) {
188
+			return nil, overlayutils.ErrDTypeNotSupported("overlay2", backingFs)
189
+		}
190
+		// allow running without d_type only for existing setups (#27443)
191
+		logrus.Warn(overlayutils.ErrDTypeNotSupported("overlay2", backingFs))
188 192
 	}
189 193
 
190 194
 	rootUID, rootGID, err := idtools.GetRootUIDGID(uidMaps, gidMaps)