<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">--- a/drivers/md/dm-table.c
+++ b/drivers/md/dm-table.c
@@ -21,6 +21,7 @@
 #include &lt;linux/blk-mq.h&gt;
 #include &lt;linux/mount.h&gt;
 #include &lt;linux/dax.h&gt;
+#include &lt;linux/blkdev.h&gt;
 
 #define DM_MSG_PREFIX "table"
 
@@ -400,6 +401,132 @@ static int upgrade_mode(struct dm_dev_in
 }
 
 /*
+ * Note for patch conflicts/building failure when upgrading kernel:
+ * Most of the following code is copied from init/do_mounts.c
+ */
+struct uuidcmp {
+	const char *uuid;
+	int len;
+};
+
+/**
+ * match_dev_by_uuid - callback for finding a partition using its uuid
+ * @dev:	device passed in by the caller
+ * @data:	opaque pointer to the desired struct uuidcmp to match
+ *
+ * Returns 1 if the device matches, and 0 otherwise.
+ */
+static int match_dev_by_uuid(struct device *dev, const void *data)
+{
+	const struct uuidcmp *cmp = data;
+	struct hd_struct *part = dev_to_part(dev);
+
+	if (!part-&gt;info)
+		goto no_match;
+
+	if (strncasecmp(cmp-&gt;uuid, part-&gt;info-&gt;uuid, cmp-&gt;len))
+		goto no_match;
+
+	return 1;
+no_match:
+	return 0;
+}
+
+
+/**
+ * devt_from_partuuid - looks up the dev_t of a partition by its UUID
+ * @uuid_str:	char array containing ascii UUID
+ *
+ * The function will return the first partition which contains a matching
+ * UUID value in its partition_meta_info struct.  This does not search
+ * by filesystem UUIDs.
+ *
+ * If @uuid_str is followed by a "/PARTNROFF=%d", then the number will be
+ * extracted and used as an offset from the partition identified by the UUID.
+ *
+ * Returns the matching dev_t on success or 0 on failure.
+ */
+static dev_t devt_from_partuuid(const char *uuid_str)
+{
+	dev_t res = 0;
+	struct uuidcmp cmp;
+	struct device *dev = NULL;
+	struct gendisk *disk;
+	struct hd_struct *part;
+	int offset = 0;
+	bool prompt_failure = false;
+	char *slash;
+
+	cmp.uuid = uuid_str;
+
+	slash = strchr(uuid_str, '/');
+	/* Check for optional partition number offset attributes. */
+	if (slash) {
+		char c = 0;
+		/* Explicitly fail on poor PARTUUID syntax. */
+		if (sscanf(slash + 1,
+			   "PARTNROFF=%d%c", &amp;offset, &amp;c) != 1) {
+			prompt_failure = true;
+			goto done;
+		}
+		cmp.len = slash - uuid_str;
+	} else {
+		cmp.len = strlen(uuid_str);
+	}
+
+	if (!cmp.len) {
+		prompt_failure = true;
+		goto done;
+	}
+
+	dev = class_find_device(&amp;block_class, NULL, &amp;cmp,
+				&amp;match_dev_by_uuid);
+	if (!dev)
+		goto done;
+
+	res = dev-&gt;devt;
+
+	/* Attempt to find the partition by offset. */
+	if (!offset)
+		goto no_offset;
+
+	res = 0;
+	disk = part_to_disk(dev_to_part(dev));
+	part = disk_get_part(disk, dev_to_part(dev)-&gt;partno + offset);
+	if (part) {
+		res = part_devt(part);
+		put_device(part_to_dev(part));
+	}
+
+no_offset:
+	put_device(dev);
+done:
+	if (prompt_failure) {
+		pr_err("DM: PARTUUID= is invalid.\n"
+		       "Expected PARTUUID=&lt;valid-uuid-id&gt;[/PARTNROFF=%%d]\n");
+	}
+	return res;
+}
+
+/**
+ * match_dev_by_label - callback for finding a partition using its label
+ * @dev:	device passed in by the caller
+ * @data:	opaque pointer to the label to match
+ *
+ * Returns 1 if the device matches, and 0 otherwise.
+ */
+static int match_dev_by_label(struct device *dev, const void *data)
+{
+	const char *label = data;
+	struct hd_struct *part = dev_to_part(dev);
+
+	if (part-&gt;info &amp;&amp; !strcmp(label, part-&gt;info-&gt;volname))
+		return 1;
+
+	return 0;
+}
+
+/*
  * Convert the path to a device
  */
 dev_t dm_get_dev_t(const char *path)
@@ -407,6 +534,21 @@ dev_t dm_get_dev_t(const char *path)
 	dev_t dev;
 	struct block_device *bdev;
 
+	if (strncmp(path, "PARTUUID=", 9) == 0) {
+		return devt_from_partuuid(path + 9);
+	} else if (strncmp(path, "PARTLABEL=", 10) == 0) {
+		struct device *ddev;
+
+		ddev = class_find_device(&amp;block_class, NULL, path + 10,
+					&amp;match_dev_by_label);
+		if (!ddev)
+			return 0;
+
+		dev = ddev-&gt;devt;
+		put_device(ddev);
+		return dev;
+	}
+
 	bdev = lookup_bdev(path);
 	if (IS_ERR(bdev))
 		dev = name_to_dev_t(path);
</pre></body></html>