Linux commit 4e7b5671c6a8 ("block: remove i_bdev") changed function
lookup_bdev():
-struct block_device *lookup_bdev(const char *pathname)
+int lookup_bdev(const char *pathname, dev_t *dev)
And APFS module commit 3a2e3369d251 ("Take exclusive ownership of block
device on mount") didn't notice the change. It causes failed compilation
in v5.11 and later:
=======================================================================
/root/rw/super.c:1128:29: error: too few arguments to function call,
expected 2, have 1
bdev = lookup_bdev(dev_name);
~~~~~~~~~~~ ^
./include/linux/blkdev.h:1984:5: note: 'lookup_bdev' declared here
int lookup_bdev(const char *pathname, dev_t *dev);
^
1 error generated.
=======================================================================
Introduce new version apfs_nx_find_by_dev() for v5.11 and let
apfs_attach_nxi() call new version lookup_bdev(). Both two changes are
inside version preprocessors.
Signed-off-by: Su Yue <
l...@damenly.su>
---
super.c | 37 +++++++++++++++++++++++++++++++++++++
1 file changed, 37 insertions(+)
diff --git a/super.c b/super.c
index a65e6ea801dc..5af2ea0bdc06 100644
--- a/super.c
+++ b/super.c
@@ -23,6 +23,7 @@
DEFINE_MUTEX(nxs_mutex);
static LIST_HEAD(nxs);
+#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 11, 0)
/**
* apfs_nx_find_by_dev - Search for a device in the list of mounted containers
* @bdev: block device for the wanted container
@@ -44,6 +45,29 @@ static struct apfs_nxsb_info *apfs_nx_find_by_dev(struct block_device *bdev)
return NULL;
}
+#else
+/**
+ * apfs_nx_find_by_dev - Search for a device in the list of mounted containers
+ * @dev: device number of block device for the wanted container
+ *
+ * Returns a pointer to the container structure in the list, or NULL if the
+ * container isn't currently mounted.
+ */
+static struct apfs_nxsb_info *apfs_nx_find_by_dev(dev_t dev)
+{
+ struct apfs_nxsb_info *curr;
+
+ lockdep_assert_held(&nxs_mutex);
+ list_for_each_entry(curr, &nxs, nx_list) {
+ struct block_device *curr_bdev = curr->nx_bdev;
+
+ if (curr_bdev->bd_dev != dev)
+ return curr;
+ }
+ return NULL;
+}
+#endif
+
/**
* apfs_sb_set_blocksize - Set the block size for the container's device
* @sb: superblock structure
@@ -1122,6 +1146,7 @@ static int apfs_attach_nxi(struct apfs_sb_info *sbi, const char *dev_name, fmode
{
struct apfs_nxsb_info *nxi;
struct block_device *bdev;
+#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 11, 0)
lockdep_assert_held(&nxs_mutex);
@@ -1132,6 +1157,18 @@ static int apfs_attach_nxi(struct apfs_sb_info *sbi, const char *dev_name, fmode
nxi = apfs_nx_find_by_dev(bdev);
bdput(bdev);
bdev = NULL;
+#else
+ dev_t dev;
+ int ret;
+
+ lockdep_assert_held(&nxs_mutex);
+
+ ret = lookup_bdev(dev_name, &dev);
+ if (ret)
+ return ret;
+ nxi = apfs_nx_find_by_dev(dev);
+#endif
+
if (!nxi) {
nxi = kzalloc(sizeof(*nxi), GFP_KERNEL);
if (!nxi)
--
2.30.1