diff --git a/dist/libblockdev.spec.in b/dist/libblockdev.spec.in index 0261f4dc5..d52604895 100644 --- a/dist/libblockdev.spec.in +++ b/dist/libblockdev.spec.in @@ -378,8 +378,6 @@ BuildRequires: device-mapper-devel Summary: The LVM plugin for the libblockdev library Requires: %{name}-utils%{?_isa} >= 0.11 Requires: lvm2 -# for thin_metadata_size -Requires: device-mapper-persistent-data %description lvm The libblockdev library plugin (and in the same time a standalone library) @@ -402,8 +400,6 @@ BuildRequires: device-mapper-devel Summary: The LVM plugin for the libblockdev library Requires: %{name}-utils%{?_isa} >= 1.4 Requires: lvm2-dbusd >= 2.02.156 -# for thin_metadata_size -Requires: device-mapper-persistent-data %description lvm-dbus The libblockdev library plugin (and in the same time a standalone library) diff --git a/src/lib/plugin_apis/lvm.api b/src/lib/plugin_apis/lvm.api index 1b3cf4df6..5313c2027 100644 --- a/src/lib/plugin_apis/lvm.api +++ b/src/lib/plugin_apis/lvm.api @@ -19,8 +19,8 @@ #define BD_LVM_DEFAULT_PE_SIZE G_GUINT64_CONSTANT (4194304ULL) // 4 MiB #define BD_LVM_MIN_PE_SIZE G_GUINT64_CONSTANT (1024ULL) // 1 KiB #define BD_LVM_MAX_PE_SIZE G_GUINT64_CONSTANT (17179869184ULL) // 16 GiB -#define BD_LVM_MIN_THPOOL_MD_SIZE G_GUINT64_CONSTANT (2097152ULL) // 2 MiB -#define BD_LVM_MAX_THPOOL_MD_SIZE G_GUINT64_CONSTANT (17179869184ULL) // 16 GiB +#define BD_LVM_MIN_THPOOL_MD_SIZE G_GUINT64_CONSTANT (4194304ULL) // 4 MiB +#define BD_LVM_MAX_THPOOL_MD_SIZE G_GUINT64_CONSTANT (33957085184ULL) // 31.62 GiB #define BD_LVM_MIN_THPOOL_CHUNK_SIZE G_GUINT64_CONSTANT (65536ULL) // 64 KiB #define BD_LVM_MAX_THPOOL_CHUNK_SIZE G_GUINT64_CONSTANT (1073741824ULL) // 1 GiB #define BD_LVM_DEFAULT_CHUNK_SIZE G_GUINT64_CONSTANT (65536ULL) // 64 KiB @@ -738,11 +738,13 @@ guint64 bd_lvm_get_thpool_padding (guint64 size, guint64 pe_size, gboolean inclu * bd_lvm_get_thpool_meta_size: * @size: size of the thin pool * @chunk_size: chunk size of the thin pool or 0 to use the default (%BD_LVM_DEFAULT_CHUNK_SIZE) - * @n_snapshots: number of snapshots that will be created in the pool + * @n_snapshots: ignored * @error: (out): place to store error (if any) * - * Returns: recommended size of the metadata space for the specified pool or 0 - * in case of error + * Note: This function will be changed in 3.0: the @n_snapshots parameter + * is currently not used and will be removed. + * + * Returns: recommended size of the metadata space for the specified pool * * Tech category: %BD_LVM_TECH_THIN_CALCS no mode (it is ignored) */ diff --git a/src/plugins/lvm-dbus.c b/src/plugins/lvm-dbus.c index d8648bce3..2144caa99 100644 --- a/src/plugins/lvm-dbus.c +++ b/src/plugins/lvm-dbus.c @@ -20,7 +20,6 @@ #include #include #include -#include #include #include #include @@ -256,14 +255,6 @@ static volatile guint avail_features = 0; static volatile guint avail_module_deps = 0; static GMutex deps_check_lock; -#define DEPS_THMS 0 -#define DEPS_THMS_MASK (1 << DEPS_THMS) -#define DEPS_LAST 1 - -static const UtilDep deps[DEPS_LAST] = { - {"thin_metadata_size", NULL, NULL, NULL}, -}; - #define DBUS_DEPS_LVMDBUSD 0 #define DBUS_DEPS_LVMDBUSD_MASK (1 << DBUS_DEPS_LVMDBUSD) #define DBUS_DEPS_LVMDBUSD_WRITECACHE 1 @@ -315,17 +306,6 @@ gboolean bd_lvm_check_deps (void) { check_ret = check_ret && success; } - for (i=0; i < DEPS_LAST; i++) { - success = bd_utils_check_util_version (deps[i].name, deps[i].version, - deps[i].ver_arg, deps[i].ver_regexp, &error); - if (!success) - bd_utils_log_format (BD_UTILS_LOG_WARNING, "%s", error->message); - else - g_atomic_int_or (&avail_deps, 1 << i); - g_clear_error (&error); - check_ret = check_ret && success; - } - if (!check_ret) bd_utils_log_format (BD_UTILS_LOG_WARNING, "Cannot load the LVM plugin"); @@ -396,10 +376,7 @@ gboolean bd_lvm_is_tech_avail (BDLVMTech tech, guint64 mode, GError **error) { g_set_error (error, BD_LVM_ERROR, BD_LVM_ERROR_TECH_UNAVAIL, "Only 'query' supported for thin calculations"); return FALSE; - } else if ((mode & BD_LVM_TECH_MODE_QUERY) && - !check_deps (&avail_deps, DEPS_THMS_MASK, deps, DEPS_LAST, &deps_check_lock, error)) - return FALSE; - else + } else return TRUE; case BD_LVM_TECH_CALCS: if (mode & ~BD_LVM_TECH_MODE_QUERY) { @@ -1010,7 +987,7 @@ static BDLVMPVdata* get_pv_data_from_props (GVariant *props, GError **error) { return data; } -static BDLVMVGdata* get_vg_data_from_props (GVariant *props, GError **error __attribute__((unused))) { +static BDLVMVGdata* get_vg_data_from_props (GVariant *props, GError **error UNUSED) { BDLVMVGdata *data = g_new0 (BDLVMVGdata, 1); GVariantDict dict; GVariant *value = NULL; @@ -1232,7 +1209,7 @@ static BDLVMLVdata* get_lv_data_from_props (GVariant *props, GError **error) { return data; } -static BDLVMVDOPooldata* get_vdo_data_from_props (GVariant *props, GError **error __attribute__((unused))) { +static BDLVMVDOPooldata* get_vdo_data_from_props (GVariant *props, GError **error UNUSED) { BDLVMVDOPooldata *data = g_new0 (BDLVMVDOPooldata, 1); GVariantDict dict; gchar *value = NULL; @@ -1336,7 +1313,7 @@ static GVariant* create_size_str_param (guint64 size, const gchar *unit) { * * Tech category: %BD_LVM_TECH_CALCS no mode (it is ignored) */ -gboolean bd_lvm_is_supported_pe_size (guint64 size, GError **error __attribute__((unused))) { +gboolean bd_lvm_is_supported_pe_size (guint64 size, GError **error UNUSED) { return (((size % 2) == 0) && (size >= (BD_LVM_MIN_PE_SIZE)) && (size <= (BD_LVM_MAX_PE_SIZE))); } @@ -1348,7 +1325,7 @@ gboolean bd_lvm_is_supported_pe_size (guint64 size, GError **error __attribute__ * * Tech category: %BD_LVM_TECH_CALCS no mode (it is ignored) */ -guint64 *bd_lvm_get_supported_pe_sizes (GError **error __attribute__((unused))) { +guint64 *bd_lvm_get_supported_pe_sizes (GError **error UNUSED) { guint8 i; guint64 val = BD_LVM_MIN_PE_SIZE; guint8 num_items = ((guint8) round (log2 ((double) BD_LVM_MAX_PE_SIZE))) - ((guint8) round (log2 ((double) BD_LVM_MIN_PE_SIZE))) + 2; @@ -1370,7 +1347,7 @@ guint64 *bd_lvm_get_supported_pe_sizes (GError **error __attribute__((unused))) * * Tech category: %BD_LVM_TECH_CALCS no mode (it is ignored) */ -guint64 bd_lvm_get_max_lv_size (GError **error __attribute__((unused))) { +guint64 bd_lvm_get_max_lv_size (GError **error UNUSED) { return BD_LVM_MAX_LV_SIZE; } @@ -1390,7 +1367,7 @@ guint64 bd_lvm_get_max_lv_size (GError **error __attribute__((unused))) { * * Tech category: %BD_LVM_TECH_CALCS no mode (it is ignored) */ -guint64 bd_lvm_round_size_to_pe (guint64 size, guint64 pe_size, gboolean roundup, GError **error __attribute__((unused))) { +guint64 bd_lvm_round_size_to_pe (guint64 size, guint64 pe_size, gboolean roundup, GError **error UNUSED) { pe_size = RESOLVE_PE_SIZE(pe_size); guint64 delta = size % pe_size; if (delta == 0) @@ -1451,53 +1428,28 @@ guint64 bd_lvm_get_thpool_padding (guint64 size, guint64 pe_size, gboolean inclu * bd_lvm_get_thpool_meta_size: * @size: size of the thin pool * @chunk_size: chunk size of the thin pool or 0 to use the default (%BD_LVM_DEFAULT_CHUNK_SIZE) - * @n_snapshots: number of snapshots that will be created in the pool + * @n_snapshots: ignored * @error: (out): place to store error (if any) * - * Returns: recommended size of the metadata space for the specified pool or 0 - * in case of error + * Note: This function will be changed in 3.0: the @n_snapshots parameter + * is currently not used and will be removed. + * + * Returns: recommended size of the metadata space for the specified pool * * Tech category: %BD_LVM_TECH_THIN_CALCS no mode (it is ignored) */ -guint64 bd_lvm_get_thpool_meta_size (guint64 size, guint64 chunk_size, guint64 n_snapshots, GError **error) { - /* ub - output in bytes, n - output just the number */ - const gchar* args[7] = {"thin_metadata_size", "-ub", "-n", NULL, NULL, NULL, NULL}; - gchar *output = NULL; - gboolean success = FALSE; - guint64 ret = 0; - - if (!check_deps (&avail_deps, DEPS_THMS_MASK, deps, DEPS_LAST, &deps_check_lock, error)) - return 0; +guint64 bd_lvm_get_thpool_meta_size (guint64 size, guint64 chunk_size, guint64 n_snapshots UNUSED, GError **error UNUSED) { + guint64 md_size = 0; - /* s - total size, b - chunk size, m - number of snapshots */ - args[3] = g_strdup_printf ("-s%"G_GUINT64_FORMAT, size); - args[4] = g_strdup_printf ("-b%"G_GUINT64_FORMAT, - chunk_size != 0 ? chunk_size : (guint64) BD_LVM_DEFAULT_CHUNK_SIZE); - args[5] = g_strdup_printf ("-m%"G_GUINT64_FORMAT, n_snapshots); - - success = bd_utils_exec_and_capture_output (args, NULL, &output, error); - g_free ((gchar*) args[3]); - g_free ((gchar*) args[4]); - g_free ((gchar*) args[5]); - - if (!success) { - /* error is already set */ - g_free (output); - return 0; - } - - ret = g_ascii_strtoull (output, NULL, 0); - if (ret == 0) { - g_set_error (error, BD_LVM_ERROR, BD_LVM_ERROR_PARSE, - "Failed to parse number from thin_metadata_size's output: '%s'", - output); - g_free (output); - return 0; - } + /* based on lvcreate metadata size calculation */ + md_size = UINT64_C(64) * size / (chunk_size ? chunk_size : BD_LVM_DEFAULT_CHUNK_SIZE); - g_free (output); + if (md_size > BD_LVM_MAX_THPOOL_MD_SIZE) + md_size = BD_LVM_MAX_THPOOL_MD_SIZE; + else if (md_size < BD_LVM_MIN_THPOOL_MD_SIZE) + md_size = BD_LVM_MIN_THPOOL_MD_SIZE; - return MAX (ret, BD_LVM_MIN_THPOOL_MD_SIZE); + return md_size; } /** @@ -1509,7 +1461,7 @@ guint64 bd_lvm_get_thpool_meta_size (guint64 size, guint64 chunk_size, guint64 n * * Tech category: %BD_LVM_TECH_THIN_CALCS no mode (it is ignored) */ -gboolean bd_lvm_is_valid_thpool_md_size (guint64 size, GError **error __attribute__((unused))) { +gboolean bd_lvm_is_valid_thpool_md_size (guint64 size, GError **error UNUSED) { return ((BD_LVM_MIN_THPOOL_MD_SIZE <= size) && (size <= BD_LVM_MAX_THPOOL_MD_SIZE)); } @@ -1523,7 +1475,7 @@ gboolean bd_lvm_is_valid_thpool_md_size (guint64 size, GError **error __attribut * * Tech category: %BD_LVM_TECH_THIN_CALCS no mode (it is ignored) */ -gboolean bd_lvm_is_valid_thpool_chunk_size (guint64 size, gboolean discard, GError **error __attribute__((unused))) { +gboolean bd_lvm_is_valid_thpool_chunk_size (guint64 size, gboolean discard, GError **error UNUSED) { gdouble size_log2 = 0.0; if ((size < BD_LVM_MIN_THPOOL_CHUNK_SIZE) || (size > BD_LVM_MAX_THPOOL_CHUNK_SIZE)) @@ -3001,7 +2953,7 @@ gboolean bd_lvm_thsnapshotcreate (const gchar *vg_name, const gchar *origin_name * * Tech category: %BD_LVM_TECH_GLOB_CONF no mode (it is ignored) */ -gboolean bd_lvm_set_global_config (const gchar *new_config, GError **error __attribute__((unused))) { +gboolean bd_lvm_set_global_config (const gchar *new_config, GError **error UNUSED) { /* XXX: the error attribute will likely be used in the future when some validation comes into the game */ @@ -3026,7 +2978,7 @@ gboolean bd_lvm_set_global_config (const gchar *new_config, GError **error __att * * Tech category: %BD_LVM_TECH_GLOB_CONF no mode (it is ignored) */ -gchar* bd_lvm_get_global_config (GError **error __attribute__((unused))) { +gchar* bd_lvm_get_global_config (GError **error UNUSED) { gchar *ret = NULL; g_mutex_lock (&global_config_lock); @@ -3045,7 +2997,7 @@ gchar* bd_lvm_get_global_config (GError **error __attribute__((unused))) { * * Tech category: %BD_LVM_TECH_CACHE_CALCS no mode (it is ignored) */ -guint64 bd_lvm_cache_get_default_md_size (guint64 cache_size, GError **error __attribute__((unused))) { +guint64 bd_lvm_cache_get_default_md_size (guint64 cache_size, GError **error UNUSED) { return MAX ((guint64) cache_size / 1000, BD_LVM_MIN_CACHE_MD_SIZE); } @@ -3055,7 +3007,7 @@ guint64 bd_lvm_cache_get_default_md_size (guint64 cache_size, GError **error __a * * Get LV type string from flags. */ -static const gchar* get_lv_type_from_flags (BDLVMCachePoolFlags flags, gboolean meta, GError **error __attribute__((unused))) { +static const gchar* get_lv_type_from_flags (BDLVMCachePoolFlags flags, gboolean meta, GError **error UNUSED) { if (!meta) { if (flags & BD_LVM_CACHE_POOL_STRIPED) return "striped"; diff --git a/src/plugins/lvm.c b/src/plugins/lvm.c index 786af0d4d..45c136bfe 100644 --- a/src/plugins/lvm.c +++ b/src/plugins/lvm.c @@ -20,7 +20,6 @@ #include #include #include -#include #include #include @@ -226,13 +225,10 @@ static GMutex deps_check_lock; #define DEPS_LVM 0 #define DEPS_LVM_MASK (1 << DEPS_LVM) -#define DEPS_THMS 1 -#define DEPS_THMS_MASK (1 << DEPS_THMS) -#define DEPS_LAST 2 +#define DEPS_LAST 1 static const UtilDep deps[DEPS_LAST] = { {"lvm", LVM_MIN_VERSION, "version", "LVM version:\\s+([\\d\\.]+)"}, - {"thin_metadata_size", NULL, NULL, NULL}, }; #define FEATURES_VDO 0 @@ -252,6 +248,8 @@ static const UtilFeatureDep features[FEATURES_LAST] = { static const gchar*const module_deps[MODULE_DEPS_LAST] = { "kvdo" }; +#define UNUSED __attribute__((unused)) + /** * bd_lvm_check_deps: * @@ -329,10 +327,7 @@ gboolean bd_lvm_is_tech_avail (BDLVMTech tech, guint64 mode, GError **error) { g_set_error (error, BD_LVM_ERROR, BD_LVM_ERROR_TECH_UNAVAIL, "Only 'query' supported for thin calculations"); return FALSE; - } else if ((mode & BD_LVM_TECH_MODE_QUERY) && - !check_deps (&avail_deps, DEPS_THMS_MASK, deps, DEPS_LAST, &deps_check_lock, error)) - return FALSE; - else + } else return TRUE; case BD_LVM_TECH_CALCS: if (mode & ~BD_LVM_TECH_MODE_QUERY) { @@ -745,7 +740,7 @@ static BDLVMVDOPooldata* get_vdo_data_from_table (GHashTable *table, gboolean fr * * Tech category: %BD_LVM_TECH_CALCS no mode (it is ignored) */ -gboolean bd_lvm_is_supported_pe_size (guint64 size, GError **error __attribute__((unused))) { +gboolean bd_lvm_is_supported_pe_size (guint64 size, GError **error UNUSED) { return (((size % 2) == 0) && (size >= (BD_LVM_MIN_PE_SIZE)) && (size <= (BD_LVM_MAX_PE_SIZE))); } @@ -757,7 +752,7 @@ gboolean bd_lvm_is_supported_pe_size (guint64 size, GError **error __attribute__ * * Tech category: %BD_LVM_TECH_CALCS no mode (it is ignored) */ -guint64 *bd_lvm_get_supported_pe_sizes (GError **error __attribute__((unused))) { +guint64 *bd_lvm_get_supported_pe_sizes (GError **error UNUSED) { guint8 i; guint64 val = BD_LVM_MIN_PE_SIZE; guint8 num_items = ((guint8) round (log2 ((double) BD_LVM_MAX_PE_SIZE))) - ((guint8) round (log2 ((double) BD_LVM_MIN_PE_SIZE))) + 2; @@ -779,7 +774,7 @@ guint64 *bd_lvm_get_supported_pe_sizes (GError **error __attribute__((unused))) * * Tech category: %BD_LVM_TECH_CALCS no mode (it is ignored) */ -guint64 bd_lvm_get_max_lv_size (GError **error __attribute__((unused))) { +guint64 bd_lvm_get_max_lv_size (GError **error UNUSED) { return BD_LVM_MAX_LV_SIZE; } @@ -799,7 +794,7 @@ guint64 bd_lvm_get_max_lv_size (GError **error __attribute__((unused))) { * * Tech category: %BD_LVM_TECH_CALCS no mode (it is ignored) */ -guint64 bd_lvm_round_size_to_pe (guint64 size, guint64 pe_size, gboolean roundup, GError **error __attribute__((unused))) { +guint64 bd_lvm_round_size_to_pe (guint64 size, guint64 pe_size, gboolean roundup, GError **error UNUSED) { pe_size = RESOLVE_PE_SIZE(pe_size); guint64 delta = size % pe_size; if (delta == 0) @@ -860,53 +855,28 @@ guint64 bd_lvm_get_thpool_padding (guint64 size, guint64 pe_size, gboolean inclu * bd_lvm_get_thpool_meta_size: * @size: size of the thin pool * @chunk_size: chunk size of the thin pool or 0 to use the default (%BD_LVM_DEFAULT_CHUNK_SIZE) - * @n_snapshots: number of snapshots that will be created in the pool + * @n_snapshots: ignored * @error: (out): place to store error (if any) * - * Returns: recommended size of the metadata space for the specified pool or 0 - * in case of error + * Note: This function will be changed in 3.0: the @n_snapshots parameter + * is currently not used and will be removed. + * + * Returns: recommended size of the metadata space for the specified pool * * Tech category: %BD_LVM_TECH_THIN_CALCS no mode (it is ignored) */ -guint64 bd_lvm_get_thpool_meta_size (guint64 size, guint64 chunk_size, guint64 n_snapshots, GError **error) { - /* ub - output in bytes, n - output just the number */ - const gchar* args[7] = {"thin_metadata_size", "-ub", "-n", NULL, NULL, NULL, NULL}; - gchar *output = NULL; - gboolean success = FALSE; - guint64 ret = 0; - - if (!check_deps (&avail_deps, DEPS_THMS_MASK, deps, DEPS_LAST, &deps_check_lock, error)) - return 0; +guint64 bd_lvm_get_thpool_meta_size (guint64 size, guint64 chunk_size, guint64 n_snapshots UNUSED, GError **error UNUSED) { + guint64 md_size = 0; - /* s - total size, b - chunk size, m - number of snapshots */ - args[3] = g_strdup_printf ("-s%"G_GUINT64_FORMAT, size); - args[4] = g_strdup_printf ("-b%"G_GUINT64_FORMAT, - chunk_size != 0 ? chunk_size : (guint64) BD_LVM_DEFAULT_CHUNK_SIZE); - args[5] = g_strdup_printf ("-m%"G_GUINT64_FORMAT, n_snapshots); + /* based on lvcreate metadata size calculation */ + md_size = UINT64_C(64) * size / (chunk_size ? chunk_size : BD_LVM_DEFAULT_CHUNK_SIZE); - success = bd_utils_exec_and_capture_output (args, NULL, &output, error); - g_free ((gchar*) args[3]); - g_free ((gchar*) args[4]); - g_free ((gchar*) args[5]); - - if (!success) { - /* error is already set */ - g_free (output); - return 0; - } - - ret = g_ascii_strtoull (output, NULL, 0); - if (ret == 0) { - g_set_error (error, BD_LVM_ERROR, BD_LVM_ERROR_PARSE, - "Failed to parse number from thin_metadata_size's output: '%s'", - output); - g_free (output); - return 0; - } - - g_free (output); + if (md_size > BD_LVM_MAX_THPOOL_MD_SIZE) + md_size = BD_LVM_MAX_THPOOL_MD_SIZE; + else if (md_size < BD_LVM_MIN_THPOOL_MD_SIZE) + md_size = BD_LVM_MIN_THPOOL_MD_SIZE; - return MAX (ret, BD_LVM_MIN_THPOOL_MD_SIZE); + return md_size; } /** @@ -918,7 +888,7 @@ guint64 bd_lvm_get_thpool_meta_size (guint64 size, guint64 chunk_size, guint64 n * * Tech category: %BD_LVM_TECH_THIN_CALCS no mode (it is ignored) */ -gboolean bd_lvm_is_valid_thpool_md_size (guint64 size, GError **error __attribute__((unused))) { +gboolean bd_lvm_is_valid_thpool_md_size (guint64 size, GError **error UNUSED) { return ((BD_LVM_MIN_THPOOL_MD_SIZE <= size) && (size <= BD_LVM_MAX_THPOOL_MD_SIZE)); } @@ -932,7 +902,7 @@ gboolean bd_lvm_is_valid_thpool_md_size (guint64 size, GError **error __attribut * * Tech category: %BD_LVM_TECH_THIN_CALCS no mode (it is ignored) */ -gboolean bd_lvm_is_valid_thpool_chunk_size (guint64 size, gboolean discard, GError **error __attribute__((unused))) { +gboolean bd_lvm_is_valid_thpool_chunk_size (guint64 size, gboolean discard, GError **error UNUSED) { gdouble size_log2 = 0.0; if ((size < BD_LVM_MIN_THPOOL_CHUNK_SIZE) || (size > BD_LVM_MAX_THPOOL_CHUNK_SIZE)) @@ -2160,7 +2130,7 @@ gboolean bd_lvm_thsnapshotcreate (const gchar *vg_name, const gchar *origin_name * * Tech category: %BD_LVM_TECH_GLOB_CONF no mode (it is ignored) */ -gboolean bd_lvm_set_global_config (const gchar *new_config, GError **error __attribute__((unused))) { +gboolean bd_lvm_set_global_config (const gchar *new_config, GError **error UNUSED) { /* XXX: the error attribute will likely be used in the future when some validation comes into the game */ @@ -2185,7 +2155,7 @@ gboolean bd_lvm_set_global_config (const gchar *new_config, GError **error __att * * Tech category: %BD_LVM_TECH_GLOB_CONF no mode (it is ignored) */ -gchar* bd_lvm_get_global_config (GError **error __attribute__((unused))) { +gchar* bd_lvm_get_global_config (GError **error UNUSED) { gchar *ret = NULL; g_mutex_lock (&global_config_lock); @@ -2204,7 +2174,7 @@ gchar* bd_lvm_get_global_config (GError **error __attribute__((unused))) { * * Tech category: %BD_LVM_TECH_CACHE_CALCS no mode (it is ignored) */ -guint64 bd_lvm_cache_get_default_md_size (guint64 cache_size, GError **error __attribute__((unused))) { +guint64 bd_lvm_cache_get_default_md_size (guint64 cache_size, GError **error UNUSED) { return MAX ((guint64) cache_size / 1000, BD_LVM_MIN_CACHE_MD_SIZE); } @@ -2214,7 +2184,7 @@ guint64 bd_lvm_cache_get_default_md_size (guint64 cache_size, GError **error __a * * Get LV type string from flags. */ -static const gchar* get_lv_type_from_flags (BDLVMCachePoolFlags flags, gboolean meta, GError **error __attribute__((unused))) { +static const gchar* get_lv_type_from_flags (BDLVMCachePoolFlags flags, gboolean meta, GError **error UNUSED) { if (!meta) { if (flags & BD_LVM_CACHE_POOL_STRIPED) return "striped"; diff --git a/src/plugins/lvm.h b/src/plugins/lvm.h index 05cedd078..af31ecd02 100644 --- a/src/plugins/lvm.h +++ b/src/plugins/lvm.h @@ -1,5 +1,6 @@ #include #include +#include #ifndef BD_LVM #define BD_LVM @@ -17,8 +18,12 @@ #define BD_LVM_MIN_PE_SIZE (1 KiB) #define BD_LVM_MAX_PE_SIZE (16 GiB) -#define BD_LVM_MIN_THPOOL_MD_SIZE (2 MiB) -#define BD_LVM_MAX_THPOOL_MD_SIZE (16 GiB) +/* lvm constants for thin pool metadata size are actually half of these + but when they calculate the actual metadata size they double the limits + so lets just double the limits here too */ +#define BD_LVM_MIN_THPOOL_MD_SIZE (4 MiB) +#define BD_LVM_MAX_THPOOL_MD_SIZE (DM_THIN_MAX_METADATA_SIZE KiB) + #define BD_LVM_MIN_THPOOL_CHUNK_SIZE (64 KiB) #define BD_LVM_MAX_THPOOL_CHUNK_SIZE (1 GiB) #define BD_LVM_DEFAULT_CHUNK_SIZE (64 KiB) diff --git a/src/python/gi/overrides/BlockDev.py b/src/python/gi/overrides/BlockDev.py index 221bd33bb..540444565 100644 --- a/src/python/gi/overrides/BlockDev.py +++ b/src/python/gi/overrides/BlockDev.py @@ -582,6 +582,12 @@ def lvm_get_thpool_padding(size, pe_size=0, included=False): return _lvm_get_thpool_padding(size, pe_size, included) __all__.append("lvm_get_thpool_padding") +_lvm_get_thpool_meta_size = BlockDev.lvm_get_thpool_meta_size +@override(BlockDev.lvm_get_thpool_meta_size) +def lvm_get_thpool_meta_size(size, chunk_size=0, n_snapshots=0): + return _lvm_get_thpool_meta_size(size, chunk_size, n_snapshots) +__all__.append("lvm_get_thpool_meta_size") + _lvm_pvcreate = BlockDev.lvm_pvcreate @override(BlockDev.lvm_pvcreate) def lvm_pvcreate(device, data_alignment=0, metadata_size=0, extra=None, **kwargs): diff --git a/tests/library_test.py b/tests/library_test.py index e079dde9b..511f820f4 100644 --- a/tests/library_test.py +++ b/tests/library_test.py @@ -352,8 +352,7 @@ def test_try_reinit(self): # try reinitializing with only some utilities being available and thus # only some plugins able to load - with fake_path("tests/fake_utils/lib_missing_utils", keep_utils=["swapon", "swapoff", "mkswap", "lvm", - "thin_metadata_size", "swaplabel"]): + with fake_path("tests/fake_utils/lib_missing_utils", keep_utils=["swapon", "swapoff", "mkswap", "lvm", "swaplabel"]): succ, loaded = BlockDev.try_reinit(self.requested_plugins, True, None) self.assertFalse(succ) for plug_name in ("swap", "lvm", "crypto"): @@ -364,8 +363,7 @@ def test_try_reinit(self): # now the same with a subset of plugins requested plugins = BlockDev.plugin_specs_from_names(["lvm", "swap", "crypto"]) - with fake_path("tests/fake_utils/lib_missing_utils", keep_utils=["swapon", "swapoff", "mkswap", "lvm", - "thin_metadata_size", "swaplabel"]): + with fake_path("tests/fake_utils/lib_missing_utils", keep_utils=["swapon", "swapoff", "mkswap", "lvm", "swaplabel"]): succ, loaded = BlockDev.try_reinit(plugins, True, None) self.assertTrue(succ) self.assertEqual(set(loaded), set(["swap", "lvm", "crypto"])) diff --git a/tests/lvm_dbus_tests.py b/tests/lvm_dbus_tests.py index 855702974..9039c7012 100644 --- a/tests/lvm_dbus_tests.py +++ b/tests/lvm_dbus_tests.py @@ -160,31 +160,30 @@ def test_get_thpool_padding(self): def test_get_thpool_meta_size(self): """Verify that getting recommended thin pool metadata size works as expected""" - # no idea how thin_metadata_size works, but let's at least check that - # the function works and returns what thin_metadata_size says - out1 = subprocess.check_output(["thin_metadata_size", "-ub", "-n", "-b64k", "-s1t", "-m100"]) - self.assertEqual(int(out1), BlockDev.lvm_get_thpool_meta_size (1 * 1024**4, 64 * 1024, 100)) + # metadata size is calculated as 64 * pool_size / chunk_size + self.assertEqual(BlockDev.lvm_get_thpool_meta_size(1 * 1024**4, 64 * 1024), 1 * 1024**3) - out2 = subprocess.check_output(["thin_metadata_size", "-ub", "-n", "-b128k", "-s1t", "-m100"]) - self.assertEqual(int(out2), BlockDev.lvm_get_thpool_meta_size (1 * 1024**4, 128 * 1024, 100)) + self.assertEqual(BlockDev.lvm_get_thpool_meta_size(1 * 1024**4, 128 * 1024), 512 * 1024**2) - # twice the chunk_size -> roughly half the metadata needed - self.assertAlmostEqual(float(out1) / float(out2), 2, places=2) - - # unless thin_metadata_size gives a value that is not valid (too small) - self.assertEqual(BlockDev.lvm_get_thpool_meta_size (100 * 1024**2, 128 * 1024, 100), + # lower limit is 4 MiB + self.assertEqual(BlockDev.lvm_get_thpool_meta_size(100 * 1024**2, 128 * 1024), BlockDev.LVM_MIN_THPOOL_MD_SIZE) + # upper limit is 31.62 GiB + self.assertEqual(BlockDev.lvm_get_thpool_meta_size(100 * 1024**4, 64 * 1024), + BlockDev.LVM_MAX_THPOOL_MD_SIZE) + @tag_test(TestTags.NOSTORAGE) def test_is_valid_thpool_md_size(self): """Verify that is_valid_thpool_md_size works as expected""" - self.assertTrue(BlockDev.lvm_is_valid_thpool_md_size(2 * 1024**2)) - self.assertTrue(BlockDev.lvm_is_valid_thpool_md_size(3 * 1024**2)) + self.assertTrue(BlockDev.lvm_is_valid_thpool_md_size(4 * 1024**2)) + self.assertTrue(BlockDev.lvm_is_valid_thpool_md_size(5 * 1024**2)) self.assertTrue(BlockDev.lvm_is_valid_thpool_md_size(16 * 1024**3)) self.assertFalse(BlockDev.lvm_is_valid_thpool_md_size(1 * 1024**2)) - self.assertFalse(BlockDev.lvm_is_valid_thpool_md_size(17 * 1024**3)) + self.assertFalse(BlockDev.lvm_is_valid_thpool_md_size(3 * 1024**2)) + self.assertFalse(BlockDev.lvm_is_valid_thpool_md_size(32 * 1024**3)) @tag_test(TestTags.NOSTORAGE) def test_is_valid_thpool_chunk_size(self): diff --git a/tests/lvm_test.py b/tests/lvm_test.py index 725c4bed0..ad1c49a7b 100644 --- a/tests/lvm_test.py +++ b/tests/lvm_test.py @@ -153,31 +153,27 @@ def test_get_thpool_padding(self): def test_get_thpool_meta_size(self): """Verify that getting recommended thin pool metadata size works as expected""" - # no idea how thin_metadata_size works, but let's at least check that - # the function works and returns what thin_metadata_size says - out1 = subprocess.check_output(["thin_metadata_size", "-ub", "-n", "-b64k", "-s1t", "-m100"]) - self.assertEqual(int(out1), BlockDev.lvm_get_thpool_meta_size (1 * 1024**4, 64 * 1024, 100)) - out2 = subprocess.check_output(["thin_metadata_size", "-ub", "-n", "-b128k", "-s1t", "-m100"]) - self.assertEqual(int(out2), BlockDev.lvm_get_thpool_meta_size (1 * 1024**4, 128 * 1024, 100)) + self.assertEqual(BlockDev.lvm_get_thpool_meta_size(1 * 1024**4, 64 * 1024), + 1 * 1024**3) - # twice the chunk_size -> roughly half the metadata needed - self.assertAlmostEqual(float(out1) / float(out2), 2, places=2) + self.assertEqual(BlockDev.lvm_get_thpool_meta_size(1 * 1024**4, 128 * 1024), + 512 * 1024**2) - # unless thin_metadata_size gives a value that is not valid (too small) - self.assertEqual(BlockDev.lvm_get_thpool_meta_size (100 * 1024**2, 128 * 1024, 100), + self.assertEqual(BlockDev.lvm_get_thpool_meta_size(100 * 1024**2, 128 * 1024), BlockDev.LVM_MIN_THPOOL_MD_SIZE) @tag_test(TestTags.NOSTORAGE) def test_is_valid_thpool_md_size(self): """Verify that is_valid_thpool_md_size works as expected""" - self.assertTrue(BlockDev.lvm_is_valid_thpool_md_size(2 * 1024**2)) - self.assertTrue(BlockDev.lvm_is_valid_thpool_md_size(3 * 1024**2)) + self.assertTrue(BlockDev.lvm_is_valid_thpool_md_size(4 * 1024**2)) + self.assertTrue(BlockDev.lvm_is_valid_thpool_md_size(5 * 1024**2)) self.assertTrue(BlockDev.lvm_is_valid_thpool_md_size(16 * 1024**3)) self.assertFalse(BlockDev.lvm_is_valid_thpool_md_size(1 * 1024**2)) - self.assertFalse(BlockDev.lvm_is_valid_thpool_md_size(17 * 1024**3)) + self.assertFalse(BlockDev.lvm_is_valid_thpool_md_size(3 * 1024**2)) + self.assertFalse(BlockDev.lvm_is_valid_thpool_md_size(32 * 1024**3)) @tag_test(TestTags.NOSTORAGE) def test_is_valid_thpool_chunk_size(self): diff --git a/tests/utils.py b/tests/utils.py index 7d1e47378..89cd46648 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -70,7 +70,7 @@ def fake_utils(path="."): finally: os.environ["PATH"] = old_path -ALL_UTILS = {"lvm", "thin_metadata_size", "btrfs", "mkswap", "swaplabel", "multipath", "mpathconf", "dmsetup", "mdadm", "make-bcache", +ALL_UTILS = {"lvm", "btrfs", "mkswap", "swaplabel", "multipath", "mpathconf", "dmsetup", "mdadm", "make-bcache", "mkfs.exfat", "fsck.exfat", "tune.exfat", "mke2fs", "e2fsck", "tune2fs", "dumpe2fs", "resize2fs", "mkfs.f2fs", "fsck.f2fs", "fsck.f2fs", "dump.f2fs", "resize.f2fs",