From 27399755fd1b1292cc93f6469162c0855b7231c2 Mon Sep 17 00:00:00 2001 From: Zdenek Kabelac Date: Sat, 10 Feb 2018 20:22:32 +0100 Subject: [PATCH] segtype: better get_monitor_dso_path api Instead of allocating always 4K for dso path, use only real needed size. Also simplify API call and move common functionality into function itself. --- lib/activate/activate.c | 14 +++++--------- lib/activate/activate.h | 2 +- lib/mirror/mirrored.c | 3 +-- lib/raid/raid.c | 3 +-- lib/snapshot/snapshot.c | 3 +-- lib/thin/thin.c | 3 +-- 6 files changed, 10 insertions(+), 18 deletions(-) diff --git a/lib/activate/activate.c b/lib/activate/activate.c index b39f314de..bd1dc18ee 100644 --- a/lib/activate/activate.c +++ b/lib/activate/activate.c @@ -1685,18 +1685,14 @@ bad: return NULL; } -char *get_monitor_dso_path(struct cmd_context *cmd, const char *libpath) +char *get_monitor_dso_path(struct cmd_context *cmd, int id) { - char *path; + const char *libpath = find_config_tree_str(cmd, id, NULL); + char path[PATH_MAX]; - if (!(path = dm_pool_alloc(cmd->mem, PATH_MAX))) { - log_error("Failed to allocate dmeventd library path."); - return NULL; - } + get_shared_library_path(cmd, libpath, path, sizeof(path)); - get_shared_library_path(cmd, libpath, path, PATH_MAX); - - return path; + return dm_pool_strdup(cmd->mem, path); } static char *_build_target_uuid(struct cmd_context *cmd, const struct logical_volume *lv) diff --git a/lib/activate/activate.h b/lib/activate/activate.h index b1cc17617..8d068676b 100644 --- a/lib/activate/activate.h +++ b/lib/activate/activate.h @@ -206,7 +206,7 @@ int monitor_dev_for_events(struct cmd_context *cmd, const struct logical_volume #ifdef DMEVENTD # include "libdevmapper-event.h" -char *get_monitor_dso_path(struct cmd_context *cmd, const char *libpath); +char *get_monitor_dso_path(struct cmd_context *cmd, int id); int target_registered_with_dmeventd(struct cmd_context *cmd, const char *dso, const struct logical_volume *lv, int *pending, int *monitored); int target_register_events(struct cmd_context *cmd, const char *dso, const struct logical_volume *lv, diff --git a/lib/mirror/mirrored.c b/lib/mirror/mirrored.c index 16a58523a..2d9c3de92 100644 --- a/lib/mirror/mirrored.c +++ b/lib/mirror/mirrored.c @@ -572,8 +572,7 @@ struct segment_type *init_segtype(struct cmd_context *cmd) #ifdef DEVMAPPER_SUPPORT # ifdef DMEVENTD - segtype->dso = get_monitor_dso_path(cmd, - find_config_tree_str(cmd, dmeventd_mirror_library_CFG, NULL)); + segtype->dso = get_monitor_dso_path(cmd, dmeventd_mirror_library_CFG); if (segtype->dso) segtype->flags |= SEG_MONITORED; diff --git a/lib/raid/raid.c b/lib/raid/raid.c index eb75c1b37..e8351606b 100644 --- a/lib/raid/raid.c +++ b/lib/raid/raid.c @@ -656,8 +656,7 @@ int init_multiple_segtypes(struct cmd_context *cmd, struct segtype_library *segl #ifdef DEVMAPPER_SUPPORT # ifdef DMEVENTD - dso = get_monitor_dso_path(cmd, - find_config_tree_str(cmd, dmeventd_raid_library_CFG, NULL)); + dso = get_monitor_dso_path(cmd, dmeventd_raid_library_CFG); if (dso) monitored = SEG_MONITORED; diff --git a/lib/snapshot/snapshot.c b/lib/snapshot/snapshot.c index e44a49aba..110520437 100644 --- a/lib/snapshot/snapshot.c +++ b/lib/snapshot/snapshot.c @@ -263,8 +263,7 @@ struct segment_type *init_segtype(struct cmd_context *cmd) #ifdef DEVMAPPER_SUPPORT # ifdef DMEVENTD - segtype->dso = get_monitor_dso_path(cmd, - find_config_tree_str(cmd, dmeventd_snapshot_library_CFG, NULL)); + segtype->dso = get_monitor_dso_path(cmd, dmeventd_snapshot_library_CFG); if (segtype->dso) segtype->flags |= SEG_MONITORED; diff --git a/lib/thin/thin.c b/lib/thin/thin.c index 06854ed23..dad1bf26b 100644 --- a/lib/thin/thin.c +++ b/lib/thin/thin.c @@ -816,8 +816,7 @@ int init_multiple_segtypes(struct cmd_context *cmd, struct segtype_library *segl #ifdef DEVMAPPER_SUPPORT # ifdef DMEVENTD - segtype->dso = get_monitor_dso_path(cmd, - find_config_tree_str(cmd, dmeventd_thin_library_CFG, NULL)); + segtype->dso = get_monitor_dso_path(cmd, dmeventd_thin_library_CFG); if ((reg_segtypes[i].flags & SEG_THIN_POOL) && segtype->dso)