kmod-kvdo/0002-replace-kernel-obsolete-api.patch

132 lines
3.6 KiB
Diff
Raw Permalink Normal View History

2024-03-26 15:13:56 +08:00
From 1af6a3f5a848237f5ea045499f33d29b6a8b8fd3 Mon Sep 17 00:00:00 2001
From: wang--ge <wang__ge@126.com>
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