Thread (7 messages) 7 messages, 1 author, 2021-01-02
DORMANTno replies

[PATCH 4/6] bcache-tools: check incompatible feature set

From: Coly Li <hidden>
Date: 2021-01-02 07:14:10
Also in: linux-bcache
Subsystem: the rest · Maintainer: Linus Torvalds

When bcache-tools is not updated with kernel driver (or on the versus),
we need to make sure the feature set conflict can be detected to avoid
unexpected data operation.

This patch checks whether there is unsupported {compatc, ro_compat,
incompat} features detected in detail_dev(). If there is, prints out
error message and return error to its caller.

Signed-off-by: Coly Li <redacted>
---
 lib.c | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)
diff --git a/lib.c b/lib.c
index 29172f5..a529ad3 100644
--- a/lib.c
+++ b/lib.c
@@ -442,6 +442,33 @@ int detail_dev(char *devname, struct bdev *bd, struct cdev *cd, int *type)
 		goto Fail;
 	}
 
+	/* Check for incompat feature set */
+	if (sb.version >= BCACHE_SB_VERSION_BDEV_WITH_FEATURES ||
+	    sb.version >= BCACHE_SB_VERSION_CDEV_WITH_FEATURES) {
+		uint64_t features;
+
+		features = sb.feature_compat & ~BCH_FEATURE_COMPAT_SUPP;
+		if (features) {
+			fprintf(stderr,
+				"Unsupported compatible feature found\n");
+			goto Fail;
+		}
+
+		features = sb.feature_ro_compat & ~BCH_FEATURE_RO_COMPAT_SUPP;
+		if (features) {
+			fprintf(stderr,
+				"Unsupported read-only compatible feature found\n");
+			goto Fail;
+		}
+
+		features = sb.feature_incompat & ~BCH_FEATURE_INCOMPAT_SUPP;
+		if (features) {
+			fprintf(stderr,
+				"Unsupported incompatible feature found\n");
+			goto Fail;
+		}
+	}
+
 	*type = sb.version;
 	if (sb.version == BCACHE_SB_VERSION_BDEV ||
 	    sb.version == BCACHE_SB_VERSION_BDEV_WITH_OFFSET ||
-- 
2.26.2
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help