LCOV - code coverage report
Current view: top level - lib/plugin_apis - mpath.c (source / functions) Coverage Total Hit
Test: libblockdev Coverage Report Lines: 60.7 % 84 51
Test Date: 2026-01-26 13:19:28 Functions: 53.8 % 13 7
Legend: Lines: hit not hit

            Line data    Source code
       1            0 : GQuark  bd_mpath_error_quark (void) {
       2            0 :         return g_quark_from_static_string ("g-bd-mpath-error-quark");
       3              : }
       4              : 
       5            0 : static gboolean  bd_mpath_is_tech_avail_stub (BDMpathTech tech G_GNUC_UNUSED, guint64 mode G_GNUC_UNUSED, GError **error) {
       6            0 :     bd_utils_log_format (BD_UTILS_LOG_CRIT, "The function 'bd_mpath_is_tech_avail' called, but not implemented!");
       7            0 :     g_set_error (error, BD_INIT_ERROR, BD_INIT_ERROR_NOT_IMPLEMENTED,
       8              :                 "The function 'bd_mpath_is_tech_avail' called, but not implemented!");
       9            0 :     return FALSE;
      10              : }
      11              : 
      12              : static gboolean  (*_bd_mpath_is_tech_avail) (BDMpathTech tech, guint64 mode, GError **error) = bd_mpath_is_tech_avail_stub;
      13              : 
      14              : /**
      15              :  * bd_mpath_is_tech_avail:
      16              :  * @tech: the queried tech
      17              :  * @mode: a bit mask of queried modes of operation for @tech
      18              :  * @error: (out) (optional): place to store error (details about why the @tech-@mode combination is not available)
      19              :  *
      20              :  * Returns: whether the @tech-@mode combination is available -- supported by the
      21              :  *          plugin implementation and having all the runtime dependencies available
      22              :  */
      23            4 : gboolean  bd_mpath_is_tech_avail (BDMpathTech tech, guint64 mode, GError **error) {
      24            4 :     return _bd_mpath_is_tech_avail (tech, mode, error);
      25              : }
      26              : 
      27              : 
      28            0 : static gboolean  bd_mpath_flush_mpaths_stub (GError **error) {
      29            0 :     bd_utils_log_format (BD_UTILS_LOG_CRIT, "The function 'bd_mpath_flush_mpaths' called, but not implemented!");
      30            0 :     g_set_error (error, BD_INIT_ERROR, BD_INIT_ERROR_NOT_IMPLEMENTED,
      31              :                 "The function 'bd_mpath_flush_mpaths' called, but not implemented!");
      32            0 :     return FALSE;
      33              : }
      34              : 
      35              : static gboolean  (*_bd_mpath_flush_mpaths) (GError **error) = bd_mpath_flush_mpaths_stub;
      36              : 
      37              : /**
      38              :  * bd_mpath_flush_mpaths:
      39              :  * @error: (out) (optional): place to store error (if any)
      40              :  *
      41              :  * Returns: whether multipath device maps were successfully flushed or not
      42              :  *
      43              :  * Flushes all unused multipath device maps.
      44              :  *
      45              :  * Tech category: %BD_MPATH_TECH_BASE-%BD_MPATH_TECH_MODE_MODIFY
      46              :  */
      47            1 : gboolean  bd_mpath_flush_mpaths (GError **error) {
      48            1 :     return _bd_mpath_flush_mpaths (error);
      49              : }
      50              : 
      51              : 
      52            0 : static gboolean  bd_mpath_is_mpath_member_stub (const gchar *device G_GNUC_UNUSED, GError **error) {
      53            0 :     bd_utils_log_format (BD_UTILS_LOG_CRIT, "The function 'bd_mpath_is_mpath_member' called, but not implemented!");
      54            0 :     g_set_error (error, BD_INIT_ERROR, BD_INIT_ERROR_NOT_IMPLEMENTED,
      55              :                 "The function 'bd_mpath_is_mpath_member' called, but not implemented!");
      56            0 :     return FALSE;
      57              : }
      58              : 
      59              : static gboolean  (*_bd_mpath_is_mpath_member) (const gchar *device, GError **error) = bd_mpath_is_mpath_member_stub;
      60              : 
      61              : /**
      62              :  * bd_mpath_is_mpath_member:
      63              :  * @device: device to test
      64              :  * @error: (out) (optional): place to store error (if any)
      65              :  *
      66              :  * Returns: %TRUE if the device is a multipath member, %FALSE if not or an error
      67              :  * appeared when queried (@error is set in those cases)
      68              :  *
      69              :  * Tech category: %BD_MPATH_TECH_BASE-%BD_MPATH_TECH_MODE_QUERY
      70              :  */
      71            1 : gboolean  bd_mpath_is_mpath_member (const gchar *device, GError **error) {
      72            1 :     return _bd_mpath_is_mpath_member (device, error);
      73              : }
      74              : 
      75              : 
      76            0 : static gchar** bd_mpath_get_mpath_members_stub (GError **error) {
      77            0 :     bd_utils_log_format (BD_UTILS_LOG_CRIT, "The function 'bd_mpath_get_mpath_members' called, but not implemented!");
      78            0 :     g_set_error (error, BD_INIT_ERROR, BD_INIT_ERROR_NOT_IMPLEMENTED,
      79              :                 "The function 'bd_mpath_get_mpath_members' called, but not implemented!");
      80            0 :     return NULL;
      81              : }
      82              : 
      83              : static gchar** (*_bd_mpath_get_mpath_members) (GError **error) = bd_mpath_get_mpath_members_stub;
      84              : 
      85              : /**
      86              :  * bd_mpath_get_mpath_members:
      87              :  * @error: (out) (optional): place to store error (if any)
      88              :  *
      89              :  * Returns: (transfer full) (array zero-terminated=1): list of names of all devices that are
      90              :  *                                                     members of the mpath mappings (or %NULL
      91              :  *                                                     in case of error)
      92              :  *
      93              :  * Tech category: %BD_MPATH_TECH_BASE-%BD_MPATH_TECH_MODE_QUERY
      94              :  */
      95            1 : gchar** bd_mpath_get_mpath_members (GError **error) {
      96            1 :     return _bd_mpath_get_mpath_members (error);
      97              : }
      98              : 
      99              : 
     100            0 : static gboolean  bd_mpath_set_friendly_names_stub (gboolean enabled G_GNUC_UNUSED, GError **error) {
     101            0 :     bd_utils_log_format (BD_UTILS_LOG_CRIT, "The function 'bd_mpath_set_friendly_names' called, but not implemented!");
     102            0 :     g_set_error (error, BD_INIT_ERROR, BD_INIT_ERROR_NOT_IMPLEMENTED,
     103              :                 "The function 'bd_mpath_set_friendly_names' called, but not implemented!");
     104            0 :     return FALSE;
     105              : }
     106              : 
     107              : static gboolean  (*_bd_mpath_set_friendly_names) (gboolean enabled, GError **error) = bd_mpath_set_friendly_names_stub;
     108              : 
     109              : /**
     110              :  * bd_mpath_set_friendly_names:
     111              :  * @enabled: whether friendly names should be enabled or not
     112              :  * @error: (out) (optional): place to store error (if any)
     113              :  *
     114              :  * Returns: if successfully set or not
     115              :  *
     116              :  * Tech category: %BD_MPATH_TECH_FRIENDLY_NAMES-%BD_MPATH_TECH_MODE_MODIFY
     117              :  */
     118            1 : gboolean  bd_mpath_set_friendly_names (gboolean enabled, GError **error) {
     119            1 :     return _bd_mpath_set_friendly_names (enabled, error);
     120              : }
     121              : 
     122              : 
     123            3 : static gpointer load_mpath_from_plugin(const gchar *so_name) {
     124            3 :     void *handle = NULL;
     125            3 :     char *error = NULL;
     126            3 :     gboolean (*init_fn) (void) = NULL;
     127              : 
     128            3 :     handle = dlopen(so_name, RTLD_LAZY);
     129            3 :     if (!handle) {
     130            0 :         bd_utils_log_format (BD_UTILS_LOG_WARNING, "failed to load module mpath: %s", dlerror());
     131            0 :         return NULL;
     132              :     }
     133              : 
     134            3 :     dlerror();
     135            3 :     * (void**) (&init_fn) = dlsym(handle, "bd_mpath_init");
     136            3 :     if ((error = dlerror()) != NULL)
     137            0 :         bd_utils_log_format (BD_UTILS_LOG_DEBUG, "failed to load the init() function for mpath: %s", error);
     138              :     /* coverity[dead_error_condition] */
     139            3 :     if (init_fn && !init_fn()) {
     140            0 :         dlclose(handle);
     141            0 :         return NULL;
     142              :     }
     143            3 :     init_fn = NULL;
     144              : 
     145            3 :     dlerror();
     146            3 :     * (void**) (&_bd_mpath_is_tech_avail) = dlsym(handle, "bd_mpath_is_tech_avail");
     147            3 :     if ((error = dlerror()) != NULL)
     148            0 :         bd_utils_log_format (BD_UTILS_LOG_WARNING, "failed to load bd_mpath_is_tech_avail: %s", error);
     149              : 
     150            3 :     dlerror();
     151            3 :     * (void**) (&_bd_mpath_flush_mpaths) = dlsym(handle, "bd_mpath_flush_mpaths");
     152            3 :     if ((error = dlerror()) != NULL)
     153            0 :         bd_utils_log_format (BD_UTILS_LOG_WARNING, "failed to load bd_mpath_flush_mpaths: %s", error);
     154              : 
     155            3 :     dlerror();
     156            3 :     * (void**) (&_bd_mpath_is_mpath_member) = dlsym(handle, "bd_mpath_is_mpath_member");
     157            3 :     if ((error = dlerror()) != NULL)
     158            0 :         bd_utils_log_format (BD_UTILS_LOG_WARNING, "failed to load bd_mpath_is_mpath_member: %s", error);
     159              : 
     160            3 :     dlerror();
     161            3 :     * (void**) (&_bd_mpath_get_mpath_members) = dlsym(handle, "bd_mpath_get_mpath_members");
     162            3 :     if ((error = dlerror()) != NULL)
     163            0 :         bd_utils_log_format (BD_UTILS_LOG_WARNING, "failed to load bd_mpath_get_mpath_members: %s", error);
     164              : 
     165            3 :     dlerror();
     166            3 :     * (void**) (&_bd_mpath_set_friendly_names) = dlsym(handle, "bd_mpath_set_friendly_names");
     167            3 :     if ((error = dlerror()) != NULL)
     168            0 :         bd_utils_log_format (BD_UTILS_LOG_WARNING, "failed to load bd_mpath_set_friendly_names: %s", error);
     169              : 
     170            3 :     return handle;
     171              : }
     172              : 
     173            3 : static gboolean unload_mpath (gpointer handle) {
     174            3 :     char *error = NULL;
     175            3 :     gboolean (*close_fn) (void) = NULL;
     176              : 
     177            3 :     _bd_mpath_is_tech_avail = bd_mpath_is_tech_avail_stub;
     178            3 :     _bd_mpath_flush_mpaths = bd_mpath_flush_mpaths_stub;
     179            3 :     _bd_mpath_is_mpath_member = bd_mpath_is_mpath_member_stub;
     180            3 :     _bd_mpath_get_mpath_members = bd_mpath_get_mpath_members_stub;
     181            3 :     _bd_mpath_set_friendly_names = bd_mpath_set_friendly_names_stub;
     182              : 
     183            3 :     dlerror();
     184            3 :     * (void**) (&close_fn) = dlsym(handle, "bd_mpath_close");
     185            3 :     if (((error = dlerror()) != NULL) || !close_fn)
     186            0 :         bd_utils_log_format (BD_UTILS_LOG_DEBUG, "failed to load the close_plugin() function for mpath: %s", error);
     187              :     /* coverity[dead_error_condition] */
     188            3 :     if (close_fn) {
     189            3 :         close_fn();
     190              :     }
     191              : 
     192            3 :     return dlclose(handle) == 0;
     193              : }
     194              : 
        

Generated by: LCOV version 2.0-1