Add memory pool for format instance and fix memory leaks
Get series with b4
b4 am [email protected]Versions newest first
- v1 Latest0 of 7 patches 0 repliesNew
Patches in v1 No applies recorded yet
None of the 7 patches the cover letter announces are in this archive.
Reviews trailers per patch
No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.
Cover letter [PATCH 0/7] Add memory pool for format instance and fix memory leaks
Quoted 7 lines · Peter Rajnoha
Add memory pool and reference counting for format instances. Move
text_contextallocation insidecreate_instancefn. Usevg_set_fidand newpv_set_fidthroughout.
Add newfree_pv_fidfn and use it throughout.
Calldestroy_instancefor all PVs in a VG while callingfree_vg. Various cleanups for fid mem andref_countchanges. Switch over to format instance mempool use where possible.
+ one more that has to come as the very first one!
Use new alloc_fid fn for common format instance initialisation.
Just a little cleanup for each format's create_instance fn. There's common code that doesn't need to be repeated. Factor it out into a separate "alloc_fid" fn. This makes the code easier to maintain.
--- lib/format1/format1.c | 8 +------- lib/format_pool/format_pool.c | 13 ++----------- lib/format_text/format-text.c | 14 +++----------- lib/metadata/metadata.c | 19 +++++++++++++++++++ lib/metadata/metadata.h | 27 +++++++++++++++------------ 5 files changed, 40 insertions(+), 41 deletions(-)
lib/format1/format1.c +1 -7
@@ -530,15 +530,9 @@ static struct format_instance *_format1_create_instance(const struct format_typestruct format_instance *fid;struct metadata_area *mda; -if (!(fid =dm_pool_alloc (fmt->cmd->mem,sizeof (*fid)))) +if (!(fid =alloc_fid (fmt, fic))) return_NULL; - fid->fmt = fmt; - fid->type = fic->type; - -dm_list_init (&fid->metadata_areas_in_use); -dm_list_init (&fid->metadata_areas_ignored); -/* Define a NULL metadata area */ if (!(mda =dm_pool_zalloc (fmt->cmd->mem,sizeof (*mda)))) {dm_pool_free (fmt->cmd->mem, fid);
lib/format_pool/format_pool.c +2 -11
@@ -256,17 +256,8 @@ static struct format_instance *_pool_create_instance(const struct format_type *fstruct format_instance *fid;struct metadata_area *mda; -if (!(fid =dm_pool_zalloc (fmt->cmd->mem,sizeof (*fid)))) { -log_error ("Unable to allocate format instance structure for " -"pool format" ); -return NULL ; - } - - fid->fmt = fmt; - fid->type = fic->type; - -dm_list_init (&fid->metadata_areas_in_use); -dm_list_init (&fid->metadata_areas_ignored); +if (!(fid =alloc_fid (fmt, fic))) + return_NULL;/* Define a NULL metadata area */ if (!(mda =dm_pool_zalloc (fmt->cmd->mem,sizeof (*mda)))) {
lib/format_text/format-text.c +3 -11
@@ -2190,21 +2190,13 @@ static int _text_pv_resize(const struct format_type *fmt,/* NULL vgname means use only the supplied context e.g. an archive file */ static struct format_instance *_text_create_text_instance (const struct format_type *fmt, -const struct format_instance_ctx *fic) +const struct format_instance_ctx *fic) {struct format_instance *fid;int r; -if (!(fid =dm_pool_alloc (fmt->cmd->mem,sizeof (*fid)))) { -log_error ("Couldn't allocate format instance object." ); -return NULL ; - } - - fid->fmt = fmt; - fid->type = fic->type; - -dm_list_init (&fid->metadata_areas_in_use); -dm_list_init (&fid->metadata_areas_ignored); +if (!(fid =alloc_fid (fmt, fic))) + return_NULL;if (fid->type &FMT_INSTANCE_VG ) r =_create_vg_text_instance (fid, fic);
lib/metadata/metadata.c +19 -0
@@ -3951,6 +3951,25 @@ uint32_t vg_lock_newname(struct cmd_context *cmd, const char *vgname)return FAILED_EXIST ; } +struct format_instance *alloc_fid (const struct format_type *fmt, +const struct format_instance_ctx *fic) +{ +struct format_instance *fid; + +if (!(fid =dm_pool_zalloc (fmt->cmd->mem,sizeof (*fid)))) { +log_error ("Couldn't allocate format_instance object." ); +return NULL ; + } + + fid->fmt = fmt; + fid->type = fic->type; + +dm_list_init (&fid->metadata_areas_in_use); +dm_list_init (&fid->metadata_areas_ignored); + +return fid; +} +void vg_set_fid (struct volume_group *vg,struct format_instance *fid) {
lib/metadata/metadata.h +15 -12
@@ -191,6 +191,21 @@ struct metadata_area *mda_copy(struct dm_pool *mem,unsigned mda_is_ignored (struct metadata_area *mda);void mda_set_ignored (struct metadata_area *mda,unsigned ignored);unsigned mda_locns_match (struct metadata_area *mda1,struct metadata_area *mda2); + +struct format_instance_ctx { +uint32_t type; +union { +const char *pv_id; +struct { +const char *vg_name; +const char *vg_id; + } vg_ref; +void *private; + } context; +}; + +struct format_instance *alloc_fid (const struct format_type *fmt, +const struct format_instance_ctx *fic);void vg_set_fid (struct volume_group *vg,struct format_instance *fid);/* FIXME: Add generic interface for mda counts based on given key. */ int fid_add_mda(struct format_instance *fid, struct metadata_area *mda,
@@ -229,18 +244,6 @@ struct seg_list {struct lv_segment *seg; }; -struct format_instance_ctx { -uint32_t type; -union { -const char *pv_id; -struct { -const char *vg_name; -const char *vg_id; - } vg_ref; -void *private; - } context; -}; -/* * Ownership of objects passes to caller. */
Signature · 1 line
1.7.4