aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Snitzer <snitzer@kernel.org>2023-09-28 15:08:25 -0500
committerMike Snitzer <snitzer@kernel.org>2023-09-28 16:28:59 -0400
commit5f2330c4b82c9cb6f5bbb48c3a9ad360a89a4665 (patch)
treec45df8acbb500477c9537a208f784dee7f50cfcf
parentd8d00bd5558e65451b766530f8f59d8f749f12a5 (diff)
downloadlinux-dm-vdo.v3-with-bdev-changes-aka-v4.tar.gz
dm vdo: use block_device already opened by VDO target in indexerdm-vdo.v3-with-bdev-changes-aka-v4
Remove indexer's name-based configuration management in favor of just using the VDO target's already opened block_device struct (via dm_dev). Avoids needless complications due to needless memory allocation, etc. But also removes io-factory.c's extraneous blkdev_get_by* calls. FIXME: this must be folded into the baseline VDO patchset because there have been quite a few changes to block core's bdev open functions (and more are coming in Linux 6.7). Signed-off-by: Mike Snitzer <snitzer@kernel.org>
-rw-r--r--drivers/md/dm-vdo/config.c2
-rw-r--r--drivers/md/dm-vdo/config.h4
-rw-r--r--drivers/md/dm-vdo/dedupe.c6
-rw-r--r--drivers/md/dm-vdo/index-layout.c6
-rw-r--r--drivers/md/dm-vdo/index-layout.h3
-rw-r--r--drivers/md/dm-vdo/index-session.c82
-rw-r--r--drivers/md/dm-vdo/index.c4
-rw-r--r--drivers/md/dm-vdo/index.h3
-rw-r--r--drivers/md/dm-vdo/io-factory.c55
-rw-r--r--drivers/md/dm-vdo/io-factory.h4
-rw-r--r--drivers/md/dm-vdo/uds.h8
-rw-r--r--drivers/md/dm-vdo/volume.c5
-rw-r--r--drivers/md/dm-vdo/volume.h3
13 files changed, 48 insertions, 137 deletions
diff --git a/drivers/md/dm-vdo/config.c b/drivers/md/dm-vdo/config.c
index 18ec44faf0b0b3..6a89f029dc21c1 100644
--- a/drivers/md/dm-vdo/config.c
+++ b/drivers/md/dm-vdo/config.c
@@ -357,7 +357,7 @@ int uds_make_configuration(const struct uds_parameters *params, struct configura
config->volume_index_mean_delta = DEFAULT_VOLUME_INDEX_MEAN_DELTA;
config->sparse_sample_rate = (params->sparse ? DEFAULT_SPARSE_SAMPLE_RATE : 0);
config->nonce = params->nonce;
- config->name = params->name;
+ config->bdev = params->bdev;
config->offset = params->offset;
config->size = params->size;
diff --git a/drivers/md/dm-vdo/config.h b/drivers/md/dm-vdo/config.h
index d5120412b885fb..de23f5470f9c2d 100644
--- a/drivers/md/dm-vdo/config.h
+++ b/drivers/md/dm-vdo/config.h
@@ -25,8 +25,8 @@ enum {
/* A set of configuration parameters for the indexer. */
struct configuration {
- /* String describing the storage device */
- const char *name;
+ /* block_device of the index */
+ struct block_device *bdev;
/* The maximum allowable size of the index */
size_t size;
diff --git a/drivers/md/dm-vdo/dedupe.c b/drivers/md/dm-vdo/dedupe.c
index cddfa329230678..a6546a90312091 100644
--- a/drivers/md/dm-vdo/dedupe.c
+++ b/drivers/md/dm-vdo/dedupe.c
@@ -2233,7 +2233,7 @@ static int initialize_index(struct vdo *vdo, struct hash_zones *zones)
uds_offset = ((vdo_get_index_region_start(geometry) -
geometry.bio_offset) * VDO_BLOCK_SIZE);
zones->parameters = (struct uds_parameters) {
- .name = vdo->device_config->parent_device_name,
+ .bdev = vdo->device_config->owned_device->bdev,
.offset = uds_offset,
.size = (vdo_get_index_region_size(geometry) * VDO_BLOCK_SIZE),
.memory_size = geometry.index_config.mem,
@@ -2642,8 +2642,8 @@ static void resume_index(void *context, struct vdo_completion *parent)
struct device_config *config = parent->vdo->device_config;
int result;
- zones->parameters.name = config->parent_device_name;
- result = uds_resume_index_session(zones->index_session, zones->parameters.name);
+ zones->parameters.bdev = config->owned_device->bdev;
+ result = uds_resume_index_session(zones->index_session, zones->parameters.bdev);
if (result != UDS_SUCCESS)
uds_log_error_strerror(result, "Error resuming dedupe index");
diff --git a/drivers/md/dm-vdo/index-layout.c b/drivers/md/dm-vdo/index-layout.c
index ead2dcbbd58e54..a3bd56e3ef2d97 100644
--- a/drivers/md/dm-vdo/index-layout.c
+++ b/drivers/md/dm-vdo/index-layout.c
@@ -1677,7 +1677,7 @@ static int create_layout_factory(struct index_layout *layout, const struct confi
size_t writable_size;
struct io_factory *factory = NULL;
- result = uds_make_io_factory(config->name, &factory);
+ result = uds_make_io_factory(config->bdev, &factory);
if (result != UDS_SUCCESS)
return result;
@@ -1751,9 +1751,9 @@ void uds_free_index_layout(struct index_layout *layout)
UDS_FREE(layout);
}
-int uds_replace_index_layout_storage(struct index_layout *layout, const char *name)
+int uds_replace_index_layout_storage(struct index_layout *layout, struct block_device *bdev)
{
- return uds_replace_storage(layout->factory, name);
+ return uds_replace_storage(layout->factory, bdev);
}
/* Obtain a dm_bufio_client for the volume region. */
diff --git a/drivers/md/dm-vdo/index-layout.h b/drivers/md/dm-vdo/index-layout.h
index 2128e3826f7809..2a32c0bcb00bdd 100644
--- a/drivers/md/dm-vdo/index-layout.h
+++ b/drivers/md/dm-vdo/index-layout.h
@@ -24,7 +24,8 @@ int __must_check uds_make_index_layout(struct configuration *config,
void uds_free_index_layout(struct index_layout *layout);
-int __must_check uds_replace_index_layout_storage(struct index_layout *layout, const char *name);
+int __must_check uds_replace_index_layout_storage(struct index_layout *layout,
+ struct block_device *bdev);
int __must_check uds_load_index_state(struct index_layout *layout, struct uds_index *index);
diff --git a/drivers/md/dm-vdo/index-session.c b/drivers/md/dm-vdo/index-session.c
index 333de13d15994c..f635341bbf0398 100644
--- a/drivers/md/dm-vdo/index-session.c
+++ b/drivers/md/dm-vdo/index-session.c
@@ -356,13 +356,14 @@ int uds_open_index(enum uds_open_index_type open_type,
struct uds_index_session *session)
{
int result;
+ char name[BDEVNAME_SIZE];
if (parameters == NULL) {
uds_log_error("missing required parameters");
return -EINVAL;
}
- if (parameters->name == NULL) {
- uds_log_error("missing required index name");
+ if (parameters->bdev == NULL) {
+ uds_log_error("missing required index bdev");
return -EINVAL;
}
if (session == NULL) {
@@ -374,27 +375,10 @@ int uds_open_index(enum uds_open_index_type open_type,
if (result != UDS_SUCCESS)
return uds_map_to_system_error(result);
- if ((session->parameters.name == NULL) ||
- (strcmp(parameters->name, session->parameters.name) != 0)) {
- char *new_name;
+ session->parameters = *parameters;
- result = uds_duplicate_string(parameters->name, "device name", &new_name);
- if (result != UDS_SUCCESS) {
- finish_loading_index_session(session, result);
- return uds_map_to_system_error(result);
- }
-
- uds_free_const(session->parameters.name);
- session->parameters = *parameters;
- session->parameters.name = new_name;
- } else {
- const char *old_name = session->parameters.name;
-
- session->parameters = *parameters;
- session->parameters.name = old_name;
- }
-
- uds_log_notice("%s: %s", get_open_type_string(open_type), parameters->name);
+ format_dev_t(name, parameters->bdev->bd_dev);
+ uds_log_notice("%s: %s", get_open_type_string(open_type), name);
result = initialize_index_session(session, open_type);
if (result != UDS_SUCCESS)
uds_log_error_strerror(result, "Failed %s", get_open_type_string(open_type));
@@ -497,31 +481,23 @@ int uds_suspend_index_session(struct uds_index_session *session, bool save)
return uds_map_to_system_error(result);
}
-static int replace_device(struct uds_index_session *session, const char *name)
+static int replace_device(struct uds_index_session *session, struct block_device *bdev)
{
int result;
- char *new_name;
- result = uds_duplicate_string(name, "device name", &new_name);
+ result = uds_replace_index_storage(session->index, bdev);
if (result != UDS_SUCCESS)
return result;
- result = uds_replace_index_storage(session->index, name);
- if (result != UDS_SUCCESS) {
- UDS_FREE(new_name);
- return result;
- }
-
- uds_free_const(session->parameters.name);
- session->parameters.name = new_name;
+ session->parameters.bdev = bdev;
return UDS_SUCCESS;
}
/*
- * Resume index operation after being suspended. If the index is suspended and the supplied name is
- * different from the current backing store, the index will start using the new backing store.
+ * Resume index operation after being suspended. If the index is suspended and the supplied bdev
+ * is different from the current backing store, the index will start using the new backing store.
*/
-int uds_resume_index_session(struct uds_index_session *session, const char *name)
+int uds_resume_index_session(struct uds_index_session *session, struct block_device *bdev)
{
int result = UDS_SUCCESS;
bool no_work = false;
@@ -546,9 +522,10 @@ int uds_resume_index_session(struct uds_index_session *session, const char *name
if (no_work)
return result;
- if ((name != NULL) && (session->index != NULL) &&
- (strcmp(name, session->parameters.name) != 0)) {
- result = replace_device(session, name);
+ // FIXME: is bdev ever be NULL?
+ if (bdev != NULL && session->index != NULL &&
+ bdev != session->parameters.bdev) {
+ result = replace_device(session, bdev);
if (result != UDS_SUCCESS) {
uds_lock_mutex(&session->request_mutex);
session->state &= ~IS_FLAG_WAITING;
@@ -709,7 +686,6 @@ int uds_destroy_index_session(struct uds_index_session *index_session)
wait_for_no_requests_in_progress(index_session);
result = save_and_free_index(index_session);
- uds_free_const(index_session->parameters.name);
uds_request_queue_finish(index_session->callback_queue);
index_session->callback_queue = NULL;
uds_destroy_cond(&index_session->load_context.cond);
@@ -730,41 +706,19 @@ int uds_flush_index_session(struct uds_index_session *index_session)
}
/*
- * Return the most recent parameters used to open an index. The caller is responsible for freeing
- * the returned structure.
+ * Return the most recent parameters used to open an index. The caller is responsible
+ * for freeing the returned structure.
*/
int uds_get_index_parameters(struct uds_index_session *index_session,
struct uds_parameters **parameters)
{
int result;
- const char *name = index_session->parameters.name;
if (parameters == NULL) {
uds_log_error("received a NULL parameters pointer");
return -EINVAL;
}
- if (name != NULL) {
- char *name_copy = NULL;
- size_t name_length = strlen(name) + 1;
- struct uds_parameters *copy;
-
- result = UDS_ALLOCATE_EXTENDED(struct uds_parameters,
- name_length,
- char,
- __func__,
- &copy);
- if (result != UDS_SUCCESS)
- return uds_map_to_system_error(result);
-
- *copy = index_session->parameters;
- name_copy = (char *) copy + sizeof(struct uds_parameters);
- memcpy(name_copy, name, name_length);
- copy->name = name_copy;
- *parameters = copy;
- return UDS_SUCCESS;
- }
-
result = UDS_ALLOCATE(1, struct uds_parameters, __func__, parameters);
if (result == UDS_SUCCESS)
**parameters = index_session->parameters;
diff --git a/drivers/md/dm-vdo/index.c b/drivers/md/dm-vdo/index.c
index 0e78ff3e32199e..e8859cee2b93d6 100644
--- a/drivers/md/dm-vdo/index.c
+++ b/drivers/md/dm-vdo/index.c
@@ -1351,9 +1351,9 @@ int uds_save_index(struct uds_index *index)
return result;
}
-int uds_replace_index_storage(struct uds_index *index, const char *path)
+int uds_replace_index_storage(struct uds_index *index, struct block_device *bdev)
{
- return uds_replace_volume_storage(index->volume, index->layout, path);
+ return uds_replace_volume_storage(index->volume, index->layout, bdev);
}
/* Accessing statistics should be safe from any thread. */
diff --git a/drivers/md/dm-vdo/index.h b/drivers/md/dm-vdo/index.h
index 1effe70d485495..aca61cabc433d0 100644
--- a/drivers/md/dm-vdo/index.h
+++ b/drivers/md/dm-vdo/index.h
@@ -72,7 +72,8 @@ int __must_check uds_save_index(struct uds_index *index);
void uds_free_index(struct uds_index *index);
-int __must_check uds_replace_index_storage(struct uds_index *index, const char *path);
+int __must_check uds_replace_index_storage(struct uds_index *index,
+ struct block_device *bdev);
void uds_get_index_stats(struct uds_index *index, struct uds_index_stats *counters);
diff --git a/drivers/md/dm-vdo/io-factory.c b/drivers/md/dm-vdo/io-factory.c
index 4a550c90af9ab5..3bf20231a8720c 100644
--- a/drivers/md/dm-vdo/io-factory.c
+++ b/drivers/md/dm-vdo/io-factory.c
@@ -61,51 +61,14 @@ static void uds_get_io_factory(struct io_factory *factory)
atomic_inc(&factory->ref_count);
}
-static int get_block_device_from_name(const char *name, struct block_device **bdev)
-{
- 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 = NULL;
- return uds_log_error_strerror(UDS_INVALID_ARGUMENT,
- "%s is not a valid block device",
- name);
- }
- *bdev = blkdev_get_by_dev(device, BLK_FMODE, NULL, &hops);
- } else {
- *bdev = blkdev_get_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);
- *bdev = NULL;
- return UDS_INVALID_ARGUMENT;
- }
-
- return UDS_SUCCESS;
-}
-
-int uds_make_io_factory(const char *path, struct io_factory **factory_ptr)
+int uds_make_io_factory(struct block_device *bdev, struct io_factory **factory_ptr)
{
int result;
- struct block_device *bdev;
struct io_factory *factory;
- result = get_block_device_from_name(path, &bdev);
- if (result != UDS_SUCCESS)
- return result;
-
result = UDS_ALLOCATE(1, struct io_factory, __func__, &factory);
- if (result != UDS_SUCCESS) {
- blkdev_put(bdev, NULL);
+ if (result != UDS_SUCCESS)
return result;
- }
factory->bdev = bdev;
atomic_set_release(&factory->ref_count, 1);
@@ -114,16 +77,8 @@ int uds_make_io_factory(const char *path, struct io_factory **factory_ptr)
return UDS_SUCCESS;
}
-int uds_replace_storage(struct io_factory *factory, const char *path)
+int uds_replace_storage(struct io_factory *factory, struct block_device *bdev)
{
- int result;
- struct block_device *bdev;
-
- result = get_block_device_from_name(path, &bdev);
- if (result != UDS_SUCCESS)
- return result;
-
- blkdev_put(factory->bdev, NULL);
factory->bdev = bdev;
return UDS_SUCCESS;
}
@@ -131,10 +86,8 @@ int uds_replace_storage(struct io_factory *factory, const char *path)
/* Free an I/O factory once all references have been released. */
void uds_put_io_factory(struct io_factory *factory)
{
- if (atomic_add_return(-1, &factory->ref_count) <= 0) {
- blkdev_put(factory->bdev, NULL);
+ if (atomic_add_return(-1, &factory->ref_count) <= 0)
UDS_FREE(factory);
- }
}
size_t uds_get_writable_size(struct io_factory *factory)
diff --git a/drivers/md/dm-vdo/io-factory.h b/drivers/md/dm-vdo/io-factory.h
index 41d8c7e9b10a48..ad648297815959 100644
--- a/drivers/md/dm-vdo/io-factory.h
+++ b/drivers/md/dm-vdo/io-factory.h
@@ -24,9 +24,9 @@ enum {
SECTORS_PER_BLOCK = UDS_BLOCK_SIZE >> SECTOR_SHIFT,
};
-int __must_check uds_make_io_factory(const char *path, struct io_factory **factory_ptr);
+int __must_check uds_make_io_factory(struct block_device *bdev, struct io_factory **factory_ptr);
-int __must_check uds_replace_storage(struct io_factory *factory, const char *path);
+int __must_check uds_replace_storage(struct io_factory *factory, struct block_device *bdev);
void uds_put_io_factory(struct io_factory *factory);
diff --git a/drivers/md/dm-vdo/uds.h b/drivers/md/dm-vdo/uds.h
index 71580c4098ce2b..cc791d45077bb2 100644
--- a/drivers/md/dm-vdo/uds.h
+++ b/drivers/md/dm-vdo/uds.h
@@ -125,8 +125,8 @@ struct uds_volume_record {
};
struct uds_parameters {
- /* A string describing the storage device (a name or path) */
- const char *name;
+ /* index block_device */
+ struct block_device *bdev;
/* The maximum allowable size of the index on storage */
size_t size;
/* The offset where the index should start */
@@ -306,10 +306,10 @@ int __must_check uds_suspend_index_session(struct uds_index_session *session, bo
/*
* Allow new index operations for an index, whether it was suspended or not. If the index is
- * suspended and the supplied name differs from the current backing store, the index will start
+ * suspended and the supplied bdev differs from the current backing store, the index will start
* using the new backing store instead.
*/
-int __must_check uds_resume_index_session(struct uds_index_session *session, const char *name);
+int __must_check uds_resume_index_session(struct uds_index_session *session, struct block_device *bdev);
/* Wait until all outstanding index operations are complete. */
int __must_check uds_flush_index_session(struct uds_index_session *session);
diff --git a/drivers/md/dm-vdo/volume.c b/drivers/md/dm-vdo/volume.c
index 00dc217392b8c2..d32260e350ed54 100644
--- a/drivers/md/dm-vdo/volume.c
+++ b/drivers/md/dm-vdo/volume.c
@@ -1529,12 +1529,13 @@ int uds_find_volume_chapter_boundaries(struct volume *volume,
}
int __must_check
-uds_replace_volume_storage(struct volume *volume, struct index_layout *layout, const char *name)
+uds_replace_volume_storage(struct volume *volume, struct index_layout *layout,
+ struct block_device *bdev)
{
int result;
u32 i;
- result = uds_replace_index_layout_storage(layout, name);
+ result = uds_replace_index_layout_storage(layout, bdev);
if (result != UDS_SUCCESS)
return result;
diff --git a/drivers/md/dm-vdo/volume.h b/drivers/md/dm-vdo/volume.h
index b01541814ed7f3..c8933f9505c4f4 100644
--- a/drivers/md/dm-vdo/volume.h
+++ b/drivers/md/dm-vdo/volume.h
@@ -128,7 +128,8 @@ int __must_check uds_make_volume(const struct configuration *config,
void uds_free_volume(struct volume *volume);
int __must_check
-uds_replace_volume_storage(struct volume *volume, struct index_layout *layout, const char *path);
+uds_replace_volume_storage(struct volume *volume, struct index_layout *layout,
+ struct block_device *bdev);
int __must_check uds_find_volume_chapter_boundaries(struct volume *volume,
u64 *lowest_vcn,