From dae7d11136a1565051ba65f080fe534419038d0e Mon Sep 17 00:00:00 2001 From: wang--ge Date: Tue, 26 Mar 2024 15:13:56 +0800 Subject: [PATCH] replace kernel obsolete api (cherry picked from commit 8af451068a31327753110a575971dc7ac1fe30a5) --- 0002-replace-kernel-obsolete-api.patch | 131 +++++++++++++++++++++++++ kvdo.spec | 8 +- 2 files changed, 137 insertions(+), 2 deletions(-) create mode 100644 0002-replace-kernel-obsolete-api.patch diff --git a/0002-replace-kernel-obsolete-api.patch b/0002-replace-kernel-obsolete-api.patch new file mode 100644 index 0000000..eceb80d --- /dev/null +++ b/0002-replace-kernel-obsolete-api.patch @@ -0,0 +1,131 @@ +From 1af6a3f5a848237f5ea045499f33d29b6a8b8fd3 Mon Sep 17 00:00:00 2001 +From: wang--ge +Date: Tue, 26 Mar 2024 15:06:39 +0800 +Subject: [PATCH] init pakcage + +--- + vdo/io-factory.c | 55 +++++++++++++++++++++++++++++++----------------- + 1 file changed, 36 insertions(+), 19 deletions(-) + +diff --git a/vdo/io-factory.c b/vdo/io-factory.c +index 1313da2..d0d189b 100644 +--- a/vdo/io-factory.c ++++ b/vdo/io-factory.c +@@ -11,7 +11,7 @@ + #include "logger.h" + #include "memory-alloc.h" + +-enum { BLK_FMODE = FMODE_READ | FMODE_WRITE }; ++enum { BLK_FMODE = BLK_OPEN_READ | BLK_OPEN_WRITE }; + + /* + * A kernel mode IO Factory object controls access to an index stored +@@ -19,6 +19,7 @@ enum { BLK_FMODE = FMODE_READ | FMODE_WRITE }; + */ + struct io_factory { + struct block_device *bdev; ++ struct bdev_handle *bdev_h; + atomic_t ref_count; + }; + +@@ -28,18 +29,30 @@ void get_uds_io_factory(struct io_factory *factory) + } + + static int get_block_device_from_name(const char *name, +- struct block_device **bdev) ++ struct bdev_handle **bdev_h) + { +- dev_t device = name_to_dev_t(name); +- +- if (device != 0) { +- *bdev = blkdev_get_by_dev(device, BLK_FMODE, NULL); ++ dev_t device; ++ unsigned int major, minor; ++ char dummy; ++ const struct blk_holder_ops hops = { NULL }; ++ ++ /* Extract the major/minor numbers */ ++ if (sscanf(name, "%u:%u%c", &major, &minor, &dummy) == 2) { ++ device = MKDEV(major, minor); ++ if (MAJOR(device) != major || MINOR(device) != minor) { ++ *bdev_h = NULL; ++ return uds_log_error_strerror(UDS_INVALID_ARGUMENT, ++ "%s is not a valid block device", ++ name); ++ } ++ *bdev_h = bdev_open_by_dev(device, BLK_FMODE, NULL, &hops); + } else { +- *bdev = blkdev_get_by_path(name, BLK_FMODE, NULL); ++ *bdev_h = bdev_open_by_path(name, BLK_FMODE, NULL, &hops); + } +- if (IS_ERR(*bdev)) { +- uds_log_error_strerror(-PTR_ERR(*bdev), +- "%s is not a block device", name); ++ ++ if (IS_ERR(*bdev_h)) { ++ uds_log_error_strerror(-PTR_ERR(*bdev_h), "%s is not a block device", name); ++ *bdev_h = NULL; + return UDS_INVALID_ARGUMENT; + } + +@@ -49,21 +62,22 @@ static int get_block_device_from_name(const char *name, + int make_uds_io_factory(const char *path, struct io_factory **factory_ptr) + { + int result; +- struct block_device *bdev; ++ struct bdev_handle *bdev_h; + struct io_factory *factory; + +- result = get_block_device_from_name(path, &bdev); ++ result = get_block_device_from_name(path, &bdev_h); + if (result != UDS_SUCCESS) { + return result; + } + + result = UDS_ALLOCATE(1, struct io_factory, __func__, &factory); + if (result != UDS_SUCCESS) { +- blkdev_put(bdev, BLK_FMODE); ++ bdev_release(bdev_h); + return result; + } + +- factory->bdev = bdev; ++ factory->bdev_h = bdev_h; ++ factory->bdev = bdev_h->bdev; + atomic_set_release(&factory->ref_count, 1); + + *factory_ptr = factory; +@@ -73,22 +87,25 @@ int make_uds_io_factory(const char *path, struct io_factory **factory_ptr) + int replace_uds_storage(struct io_factory *factory, const char *path) + { + int result; +- struct block_device *bdev; ++ struct bdev_handle *bdev_h; + +- result = get_block_device_from_name(path, &bdev); ++ result = get_block_device_from_name(path, &bdev_h); + if (result != UDS_SUCCESS) { + return result; + } + +- blkdev_put(factory->bdev, BLK_FMODE); +- factory->bdev = bdev; ++ factory->bdev = NULL; ++ bdev_release(factory->bdev_h); ++ factory->bdev_h = bdev_h; ++ factory->bdev = bdev_h->bdev; + return UDS_SUCCESS; + } + + void put_uds_io_factory(struct io_factory *factory) + { + if (atomic_add_return(-1, &factory->ref_count) <= 0) { +- blkdev_put(factory->bdev, BLK_FMODE); ++ factory->bdev=NULL; ++ bdev_release(factory->bdev_h); + UDS_FREE(factory); + } + } +-- +2.33.0 + diff --git a/kvdo.spec b/kvdo.spec index ffdbd31..2392de9 100644 --- a/kvdo.spec +++ b/kvdo.spec @@ -1,5 +1,5 @@ #This spec is obtained from source code(kvdo-6.2.2.24.tar.gz) -%define spec_release 3 +%define spec_release 4 %define kmod_name kmod-kvdo %define kmod_driver_version 8.2.1.2 %define kmod_rpm_release %{spec_release} @@ -15,7 +15,8 @@ Summary: Kernel Modules for Virtual Data Optimizer License: GPLv2+ URL: http://github.com/dm-vdo/kvdo Source0: https://github.com/dm-vdo/kvdo/archive/refs/tags/%{kmod_driver_version}.tar.gz -Patch1: 01-add-riscv64-support.patch +Patch1: 01-add-riscv64-support.patch +Patch2: 0002-replace-kernel-obsolete-api.patch BuildRoot: %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX) Requires: dkms @@ -78,6 +79,9 @@ rm -rf $RPM_BUILD_ROOT %{_usr}/src/%{kmod_name}-%{version}-%{kmod_rpm_release}/* %changelog +* Tue Mar 26 2024 Ge Wang - 8.2.1.2-4 +- Replace kernel obsolete api + * Wed Apr 12 2023 laokz - 8.2.1.2-3 - Add riscv64 support -- Gitee