From: Peter Rajnoha <prajnoha@redhat.com>
To: lvm-devel@redhat.com
Subject: [PATCH 0/7] Add memory pool for format instance and fix memory leaks
Date: Wed, 09 Mar 2011 13:40:34 +0100 [thread overview]
Message-ID: <4D777542.8070705@redhat.com> (raw)
In-Reply-To: <1299673359-6784-1-git-send-email-prajnoha@redhat.com>
On 03/09/2011 01:22 PM +0100, Peter Rajnoha wrote:
> Add memory pool and reference counting for format instances.
> Move text_context allocation inside create_instance fn.
> Use vg_set_fid and new pv_set_fid throughout.
> Add new free_pv_fid fn and use it throughout.
> Call destroy_instance for all PVs in a VG while calling free_vg.
> Various cleanups for fid mem and ref_count changes.
> 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(-)
diff --git a/lib/format1/format1.c b/lib/format1/format1.c
index 9011982..8550a1e 100644
--- a/lib/format1/format1.c
+++ b/lib/format1/format1.c
@@ -530,15 +530,9 @@ static struct format_instance *_format1_create_instance(const struct format_type
struct 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);
diff --git a/lib/format_pool/format_pool.c b/lib/format_pool/format_pool.c
index 4252dad..482d79a 100644
--- a/lib/format_pool/format_pool.c
+++ b/lib/format_pool/format_pool.c
@@ -256,17 +256,8 @@ static struct format_instance *_pool_create_instance(const struct format_type *f
struct 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)))) {
diff --git a/lib/format_text/format-text.c b/lib/format_text/format-text.c
index c5db278..e5156f8 100644
--- a/lib/format_text/format-text.c
+++ b/lib/format_text/format-text.c
@@ -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);
diff --git a/lib/metadata/metadata.c b/lib/metadata/metadata.c
index ff61cbb..3cfbce6 100644
--- a/lib/metadata/metadata.c
+++ b/lib/metadata/metadata.c
@@ -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)
{
diff --git a/lib/metadata/metadata.h b/lib/metadata/metadata.h
index 1982711..8f0a6b1 100644
--- a/lib/metadata/metadata.h
+++ b/lib/metadata/metadata.h
@@ -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.
*/
--
1.7.4
prev parent reply other threads:[~2011-03-09 12:40 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-03-09 12:22 [PATCH 0/7] Add memory pool for format instance and fix memory leaks Peter Rajnoha
2011-03-09 12:22 ` [PATCH 1/7] Add memory pool and reference counting for format instances Peter Rajnoha
2011-03-09 12:22 ` [PATCH 2/7] Move text_context allocation inside create_instance fn Peter Rajnoha
2011-03-09 12:22 ` [PATCH 3/7] Use vg_set_fid and new pv_set_fid throughout Peter Rajnoha
2011-03-09 12:22 ` [PATCH 4/7] Add new free_pv_fid fn and use it throughout Peter Rajnoha
2011-03-09 12:22 ` [PATCH 5/7] Call destroy_instance for all PVs in a VG while calling free_vg Peter Rajnoha
2011-03-09 12:22 ` [PATCH 6/7] Various cleanups for fid mem and ref_count changes Peter Rajnoha
2011-03-09 12:22 ` [PATCH 7/7] Switch over to format instance mempool use where possible Peter Rajnoha
2011-03-09 12:40 ` Peter Rajnoha [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4D777542.8070705@redhat.com \
--to=prajnoha@redhat.com \
--cc=lvm-devel@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.