File 0001-compat-test-for-pfn_t.patch of Package drbd

From b9e7ceaeb4937ccece18d5353fd10b57201a0726 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Christoph=20B=C3=B6hmwalder?=
 <christoph.boehmwalder@linbit.com>
Date: Tue, 11 Nov 2025 17:59:58 +0100
Subject: [PATCH] compat: test for pfn_t

The pfn_unused hack can also be removed since we don't support any
kernels before 4.18 anymore.
---
 drbd/drbd-kernel-compat/gen_patch_names.c  | 10 ++++++++++
 drbd/drbd-kernel-compat/tests/have_pfn_t.c |  5 +++++
 drbd/drbd_dax_pmem.c                       |  7 ++-----
 3 files changed, 17 insertions(+), 5 deletions(-)
 create mode 100644 drbd/drbd-kernel-compat/tests/have_pfn_t.c

diff --git a/drbd/drbd-kernel-compat/gen_patch_names.c b/drbd/drbd-kernel-compat/gen_patch_names.c
index f178476ec..39f19d802 100644
--- a/drbd/drbd-kernel-compat/gen_patch_names.c
+++ b/drbd/drbd-kernel-compat/gen_patch_names.c
@@ -521,8 +521,18 @@ int main(int argc, char **argv)
 	patch(1, "genhd_fl_no_part", true, false,
 	      COMPAT_HAVE_GENHD_FL_NO_PART, "present");
 
+#if defined(COMPAT_HAVE_PFN_T)
+	/* A few notes:
+	 * 1. dax_direct_access_takes_mode depends on the pfn_t type, so if we don't have that, we
+	 *    can't rely on the result of the test.
+	 * 2. If pfn_t does not exist, the kernel is new enough that dax_direct_access definitely
+	 *    takes the mode parameter anyway, making the dax_direct_access_takes_mode test redundant.
+	 * 3. pfn_t is only used within the dax_direct_access_takes_mode test, not in the actual
+	 *    code, so we don't need a separate cocci patch for it. */
+
 	patch(1, "dax_direct_access", true, false,
 	      COMPAT_DAX_DIRECT_ACCESS_TAKES_MODE, "takes_mode");
+#endif
 
 	patch(1, "bdev_max_discard_sectors", true, false,
 	      COMPAT_HAVE_BDEV_MAX_DISCARD_SECTORS, "present");
diff --git a/drbd/drbd-kernel-compat/tests/have_pfn_t.c b/drbd/drbd-kernel-compat/tests/have_pfn_t.c
new file mode 100644
index 000000000..7a3e7998e
--- /dev/null
+++ b/drbd/drbd-kernel-compat/tests/have_pfn_t.c
@@ -0,0 +1,5 @@
+/* { "version": "v6.17-rc1", "commit": "21aa65bf82a78c1e70447a45a85e533689b7f1a7", "comment": "pfn_t was removed", "author": "Alistair Popple <apopple@nvidia.com>", "date": "Thu Jun 19 18:58:05 2025 +1000" } */
+
+#include <linux/pfn_t.h>
+
+pfn_t foo;
diff --git a/drbd/drbd_dax_pmem.c b/drbd/drbd_dax_pmem.c
index fff09db74..6f29dfd76 100644
--- a/drbd/drbd_dax_pmem.c
+++ b/drbd/drbd_dax_pmem.c
@@ -22,7 +22,6 @@
 #include <linux/vmalloc.h>
 #include <linux/slab.h>
 #include <linux/dax.h>
-#include <linux/pfn_t.h>
 #include <linux/libnvdimm.h>
 #include <linux/blkdev.h>
 #include "drbd_int.h"
@@ -35,11 +34,10 @@ static int map_superblock_for_dax(struct drbd_backing_dev *bdev, struct dax_devi
 	pgoff_t pgoff = bdev->md.md_offset >> (PAGE_SHIFT - SECTOR_SHIFT);
 	void *kaddr;
 	long len;
-	pfn_t pfn_unused; /* before 4.18 it is required to pass in non-NULL */
 	int id;
 
 	id = dax_read_lock();
-	len = dax_direct_access(dax_dev, pgoff, want, DAX_ACCESS, &kaddr, &pfn_unused);
+	len = dax_direct_access(dax_dev, pgoff, want, DAX_ACCESS, &kaddr, NULL);
 	dax_read_unlock(id);
 
 	if (len < want)
@@ -93,11 +91,10 @@ int drbd_dax_map(struct drbd_backing_dev *bdev)
 	long al_offset_byte = (al_sector - first_sector) << SECTOR_SHIFT;
 	void *kaddr;
 	long len;
-	pfn_t pfn_unused; /* before 4.18 it is required to pass in non-NULL */
 	int id;
 
 	id = dax_read_lock();
-	len = dax_direct_access(dax_dev, pgoff, want, DAX_ACCESS, &kaddr, &pfn_unused);
+	len = dax_direct_access(dax_dev, pgoff, want, DAX_ACCESS, &kaddr, NULL);
 	dax_read_unlock(id);
 
 	if (len < want)
-- 
2.51.0

openSUSE Build Service is sponsored by