]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
dm vdo: add geometry block initialization to encodings.c
authorBruce Johnston <bjohnsto@redhat.com>
Tue, 24 Mar 2026 18:06:44 +0000 (14:06 -0400)
committerMikulas Patocka <mpatocka@redhat.com>
Thu, 26 Mar 2026 17:17:31 +0000 (18:17 +0100)
Add vdo_initialize_volume_geometry() to populate the geometry block,
computing the space required for the two main regions on disk.

Add uds_compute_index_size() to calculate the space required for the
UDS indexer from the UDS configuration.

Signed-off-by: Bruce Johnston <bjohnsto@redhat.com>
Reviewed-by: Matthew Sakai <msakai@redhat.com>
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
drivers/md/dm-vdo/encodings.c
drivers/md/dm-vdo/encodings.h
drivers/md/dm-vdo/indexer/index-layout.c
drivers/md/dm-vdo/indexer/indexer.h

index ec98c539701e3b7dd5558aca1c74d5da6cf0dca8..9961cb40f8908212bb273441bd81631669e1ded1 100644 (file)
@@ -12,6 +12,7 @@
 #include "permassert.h"
 
 #include "constants.h"
+#include "indexer.h"
 #include "status-codes.h"
 #include "types.h"
 
@@ -1486,3 +1487,71 @@ int vdo_decode_super_block(u8 *buffer)
 
        return ((checksum != saved_checksum) ? VDO_CHECKSUM_MISMATCH : VDO_SUCCESS);
 }
+
+/**
+ * vdo_compute_index_blocks() - Compute the number of blocks that the indexer will use.
+ * @config: The index config from which the blocks are calculated.
+ * @index_blocks_ptr: The number of blocks the index will use.
+ *
+ * Return: VDO_SUCCESS or an error code.
+ */
+static int vdo_compute_index_blocks(const struct index_config *config,
+                                   block_count_t *index_blocks_ptr)
+{
+       int result;
+       u64 index_bytes;
+       struct uds_parameters uds_parameters = {
+               .memory_size = config->mem,
+               .sparse = config->sparse,
+       };
+
+       result = uds_compute_index_size(&uds_parameters, &index_bytes);
+       if (result != UDS_SUCCESS)
+               return vdo_log_error_strerror(result, "error computing index size");
+
+       *index_blocks_ptr = index_bytes / VDO_BLOCK_SIZE;
+       return VDO_SUCCESS;
+}
+
+/**
+ * vdo_initialize_volume_geometry() - Initialize the volume geometry so it can be written out.
+ * @nonce: The nonce to use to identify the vdo.
+ * @uuid: The uuid to use to identify the vdo.
+ * @index_config: The config used for structure initialization.
+ * @geometry: The volume geometry to initialize.
+ *
+ * Return: VDO_SUCCESS or an error code.
+ */
+int vdo_initialize_volume_geometry(nonce_t nonce, uuid_t *uuid,
+                                  const struct index_config *index_config,
+                                  struct volume_geometry *geometry)
+{
+       int result;
+       block_count_t index_blocks = 0;
+
+       result = vdo_compute_index_blocks(index_config, &index_blocks);
+       if (result != VDO_SUCCESS)
+               return result;
+
+       *geometry = (struct volume_geometry) {
+               /* This is for backwards compatibility. */
+               .unused = 0,
+               .nonce = nonce,
+               .bio_offset = 0,
+               .regions = {
+                       [VDO_INDEX_REGION] = {
+                               .id = VDO_INDEX_REGION,
+                               .start_block = 1,
+                       },
+                       [VDO_DATA_REGION] = {
+                               .id = VDO_DATA_REGION,
+                               .start_block = 1 + index_blocks,
+                       }
+               }
+       };
+
+       memcpy(&(geometry->uuid), uuid, sizeof(uuid_t));
+       memcpy(&geometry->index_config, index_config, sizeof(struct index_config));
+
+       return VDO_SUCCESS;
+}
index 87b7d2f3b545d5ac94e968f47020e92424ed48eb..0bc5ae696a6a343365a63b93e6fcca4411d077c2 100644 (file)
@@ -803,6 +803,10 @@ vdo_get_index_region_size(struct volume_geometry geometry)
                vdo_get_index_region_start(geometry);
 }
 
+int vdo_initialize_volume_geometry(nonce_t nonce, uuid_t *uuid,
+                                  const struct index_config *index_config,
+                                  struct volume_geometry *geometry);
+
 int __must_check vdo_parse_geometry_block(unsigned char *block,
                                          struct volume_geometry *geometry);
 
index 7a1209b21c03c0b3490aaae4593851b716e24c5b..5f4ce4ab1b1ea8e978d08dc261d287d22c845bc7 100644 (file)
@@ -249,6 +249,32 @@ static int __must_check compute_sizes(const struct uds_configuration *config,
        return UDS_SUCCESS;
 }
 
+int uds_compute_index_size(const struct uds_parameters *parameters, u64 *index_size)
+{
+       int result;
+       struct uds_configuration *index_config;
+       struct save_layout_sizes sizes;
+
+       if (index_size == NULL) {
+               vdo_log_error("Missing output size pointer");
+               return -EINVAL;
+       }
+
+       result = uds_make_configuration(parameters, &index_config);
+       if (result != UDS_SUCCESS) {
+               vdo_log_error_strerror(result, "cannot compute index size");
+               return result;
+       }
+
+       result = compute_sizes(index_config, &sizes);
+       uds_free_configuration(index_config);
+       if (result != UDS_SUCCESS)
+               return result;
+
+       *index_size = sizes.total_size;
+       return UDS_SUCCESS;
+}
+
 /* Create unique data using the current time and a pseudorandom number. */
 static void create_unique_nonce_data(u8 *buffer)
 {
index 7c1fc4577f5bcfc7c0e5ecb7e872b0c10b66fa23..d765f24328ebc2df1f3884954be0a83bc9e8e667 100644 (file)
@@ -282,6 +282,10 @@ struct uds_request {
                     );
 };
 
+/* Compute the number of bytes needed to store an index. */
+int __must_check uds_compute_index_size(const struct uds_parameters *parameters,
+                                       u64 *index_size);
+
 /* A session is required for most index operations. */
 int __must_check uds_create_index_session(struct uds_index_session **session);