summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOndrej Kozina <okozina@redhat.com>2015-03-02 10:13:35 +0100
committerOndrej Kozina <okozina@redhat.com>2015-04-01 11:01:22 +0200
commit83def84504a545a32da1c6ebd71bd2c9d99f3c71 (patch)
tree306d519b7a381217a7f8bceda922d306d015f111
parentf1c027bfadb71061c793e49db810ce7c531ad8fc (diff)
downloadlvm2-83def84504a545a32da1c6ebd71bd2c9d99f3c71.tar.gz
lvmpolld: move construct_id function to utils
also fixes wrong check of return value from dm_snprintf
-rw-r--r--daemons/lvmpolld/lvmpolld-core.c22
-rw-r--r--daemons/lvmpolld/lvmpolld-data-utils.c22
-rw-r--r--daemons/lvmpolld/lvmpolld-data-utils.h2
3 files changed, 24 insertions, 22 deletions
diff --git a/daemons/lvmpolld/lvmpolld-core.c b/daemons/lvmpolld/lvmpolld-core.c
index bdf131758..e6cee2469 100644
--- a/daemons/lvmpolld/lvmpolld-core.c
+++ b/daemons/lvmpolld/lvmpolld-core.c
@@ -421,28 +421,6 @@ err:
return NULL;
}
-static char *construct_id(const char *sysdir, const char *uuid)
-{
- char *id;
- int r;
- size_t l;
-
- l = strlen(uuid) + (sysdir ? strlen(sysdir) : 0) + 1;
- id = (char *) dm_malloc(l * sizeof(char));
- if (!id)
- return NULL;
-
- r = sysdir ? dm_snprintf(id, l, "%s%s", sysdir, uuid) :
- dm_snprintf(id, l, "%s", uuid);
-
- if (!r) {
- dm_free(id);
- id = NULL;
- }
-
- return id;
-}
-
static response progress_info(client_handle h, lvmpolld_state_t *ls, request req)
{
char *id;
diff --git a/daemons/lvmpolld/lvmpolld-data-utils.c b/daemons/lvmpolld/lvmpolld-data-utils.c
index 4719e5d88..80c0ef4d3 100644
--- a/daemons/lvmpolld/lvmpolld-data-utils.c
+++ b/daemons/lvmpolld/lvmpolld-data-utils.c
@@ -61,6 +61,28 @@ static inline const char *_get_lvid(const char *lvmpolld_id, const char *sysdir)
return lvmpolld_id ? (lvmpolld_id + (sysdir ? strlen(sysdir) : 0)) : NULL;
}
+char *construct_id(const char *sysdir, const char *uuid)
+{
+ char *id;
+ int r;
+ size_t l;
+
+ l = strlen(uuid) + (sysdir ? strlen(sysdir) : 0) + 1;
+ id = (char *) dm_malloc(l * sizeof(char));
+ if (!id)
+ return NULL;
+
+ r = sysdir ? dm_snprintf(id, l, "%s%s", sysdir, uuid) :
+ dm_snprintf(id, l, "%s", uuid);
+
+ if (r < 0) {
+ dm_free(id);
+ id = NULL;
+ }
+
+ return id;
+}
+
lvmpolld_lv_t *pdlv_create(lvmpolld_state_t *ls, const char *id,
const char *vgname, const char *lvname,
const char *sysdir, enum poll_type type,
diff --git a/daemons/lvmpolld/lvmpolld-data-utils.h b/daemons/lvmpolld/lvmpolld-data-utils.h
index 7fe0d1927..67a0aa798 100644
--- a/daemons/lvmpolld/lvmpolld-data-utils.h
+++ b/daemons/lvmpolld/lvmpolld-data-utils.h
@@ -80,6 +80,8 @@ typedef struct lvmpolld_lv {
unsigned internal_error:1; /* unrecoverable error occured in lvmpolld */
} lvmpolld_lv_t;
+char *construct_id(const char *sysdir, const char *lvid);
+
/* LVMPOLLD_LV_T section */
/* only call with appropriate lvmpolld_store_t lock held */