@@ -293,11 +293,14 @@ static GMutex deps_check_lock;
293293#define DEPS_LVM_MASK (1 << DEPS_LVM)
294294#define DEPS_LVMDEVICES 1
295295#define DEPS_LVMDEVICES_MASK (1 << DEPS_LVMDEVICES)
296- #define DEPS_LAST 2
296+ #define DEPS_LVMCONFIG 2
297+ #define DEPS_LVMCONFIG_MASK (1 << DEPS_LVMCONFIG)
298+ #define DEPS_LAST 3
297299
298300static const UtilDep deps [DEPS_LAST ] = {
299301 {"lvm" , LVM_MIN_VERSION , "version" , "LVM version:\\s+([\\d\\.]+)" },
300302 {"lvmdevices" , NULL , NULL , NULL },
303+ {"lvmconfig" , NULL , NULL , NULL },
301304};
302305
303306#define DBUS_DEPS_LVMDBUSD 0
@@ -415,6 +418,8 @@ gboolean bd_lvm_is_tech_avail (BDLVMTech tech, guint64 mode, GError **error) {
415418 check_features (& avail_features , FEATURES_WRITECACHE_MASK , features , FEATURES_LAST , & deps_check_lock , error );
416419 case BD_LVM_TECH_DEVICES :
417420 return check_deps (& avail_deps , DEPS_LVMDEVICES_MASK , deps , DEPS_LAST , & deps_check_lock , error );
421+ case BD_LVM_TECH_CONFIG :
422+ return check_deps (& avail_deps , DEPS_LVMCONFIG_MASK , deps , DEPS_LAST , & deps_check_lock , error );
418423 default :
419424 /* everything is supported by this implementation of the plugin */
420425 return check_dbus_deps (& avail_dbus_deps , DBUS_DEPS_LVMDBUSD_MASK , dbus_deps , DBUS_DEPS_LAST , & deps_check_lock , error );
@@ -4917,3 +4922,58 @@ gboolean bd_lvm_devices_delete (const gchar *device, const gchar *devices_file,
49174922
49184923 return bd_utils_exec_and_report_error (args , extra , error );
49194924}
4925+
4926+ /**
4927+ * bd_lvm_config_get:
4928+ * @section: (nullable): LVM config section, e.g. 'global' or %NULL to print the entire config
4929+ * @setting: (nullable): name of the specific setting, e.g. 'umask' or %NULL to print the entire @section
4930+ * @type: type of the config, e.g. 'full' or 'current'
4931+ * @values_only: whether to include only values without keys in the output
4932+ * @global_config: whether to include our internal global config in the call or not
4933+ * @extra: (nullable) (array zero-terminated=1): extra options for the lvmconfig command
4934+ * (just passed to LVM as is)
4935+ * @error: (out) (optional): place to store error (if any)
4936+ *
4937+ * Returns: Requested LVM config @section and @setting configuration or %NULL in case of error.
4938+ *
4939+ * Tech category: (transfer full): %BD_LVM_TECH_CONFIG no mode (it is ignored)
4940+ */
4941+ gchar * bd_lvm_config_get (const gchar * section , const gchar * setting , const gchar * type , gboolean values_only , gboolean global_config , const BDExtraArg * * extra , GError * * error ) {
4942+ g_autofree gchar * conf_spec = NULL ;
4943+ g_autofree gchar * config_arg = NULL ;
4944+ const gchar * args [7 ] = {"lvmconfig" , "--typeconfig" , NULL , NULL , NULL , NULL , NULL };
4945+ guint next_arg = 2 ;
4946+ gchar * output = NULL ;
4947+ gboolean success = FALSE;
4948+
4949+ if (!section && setting ) {
4950+ g_set_error (error , BD_LVM_ERROR , BD_LVM_ERROR_FAIL ,
4951+ "Specifying setting without section is not supported." );
4952+ return NULL ;
4953+ }
4954+
4955+ if (section )
4956+ if (setting )
4957+ conf_spec = g_strdup_printf ("%s/%s" , section , setting );
4958+ else
4959+ conf_spec = g_strdup (section );
4960+ else
4961+ conf_spec = NULL ;
4962+
4963+ args [next_arg ++ ] = type ;
4964+ args [next_arg ++ ] = conf_spec ;
4965+ if (values_only )
4966+ args [next_arg ++ ] = "--valuesonly" ;
4967+
4968+ g_mutex_lock (& global_config_lock );
4969+ if (global_config && global_config_str ) {
4970+ config_arg = g_strdup_printf ("--config=%s" , global_config_str );
4971+ args [next_arg ++ ] = config_arg ;
4972+ }
4973+ g_mutex_unlock (& global_config_lock );
4974+
4975+ success = bd_utils_exec_and_capture_output (args , extra , & output , error );
4976+ if (!success )
4977+ return NULL ;
4978+ return g_strchomp (output );
4979+ }
0 commit comments