ceph: fix memory leak when destroying osdmap with pg_temp mappings
Also move _lookup_pg_mapping into a helper. Signed-off-by: Sage Weil <sage@newdream.net>
This commit is contained in:
@@ -321,8 +321,13 @@ void ceph_osdmap_destroy(struct ceph_osdmap *map)
|
|||||||
dout("osdmap_destroy %p\n", map);
|
dout("osdmap_destroy %p\n", map);
|
||||||
if (map->crush)
|
if (map->crush)
|
||||||
crush_destroy(map->crush);
|
crush_destroy(map->crush);
|
||||||
while (!RB_EMPTY_ROOT(&map->pg_temp))
|
while (!RB_EMPTY_ROOT(&map->pg_temp)) {
|
||||||
rb_erase(rb_first(&map->pg_temp), &map->pg_temp);
|
struct ceph_pg_mapping *pg =
|
||||||
|
rb_entry(rb_first(&map->pg_temp),
|
||||||
|
struct ceph_pg_mapping, node);
|
||||||
|
rb_erase(&pg->node, &map->pg_temp);
|
||||||
|
kfree(pg);
|
||||||
|
}
|
||||||
kfree(map->osd_state);
|
kfree(map->osd_state);
|
||||||
kfree(map->osd_weight);
|
kfree(map->osd_weight);
|
||||||
kfree(map->pg_pool);
|
kfree(map->pg_pool);
|
||||||
@@ -367,7 +372,8 @@ static int osdmap_set_max_osd(struct ceph_osdmap *map, int max)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Insert a new pg_temp mapping
|
* rbtree of pg_mapping for handling pg_temp (explicit mapping of pgid
|
||||||
|
* to a set of osds)
|
||||||
*/
|
*/
|
||||||
static int pgid_cmp(struct ceph_pg l, struct ceph_pg r)
|
static int pgid_cmp(struct ceph_pg l, struct ceph_pg r)
|
||||||
{
|
{
|
||||||
@@ -406,6 +412,26 @@ static int __insert_pg_mapping(struct ceph_pg_mapping *new,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static struct ceph_pg_mapping *__lookup_pg_mapping(struct rb_root *root,
|
||||||
|
struct ceph_pg pgid)
|
||||||
|
{
|
||||||
|
struct rb_node *n = root->rb_node;
|
||||||
|
struct ceph_pg_mapping *pg;
|
||||||
|
int c;
|
||||||
|
|
||||||
|
while (n) {
|
||||||
|
pg = rb_entry(n, struct ceph_pg_mapping, node);
|
||||||
|
c = pgid_cmp(pgid, pg->pgid);
|
||||||
|
if (c < 0)
|
||||||
|
n = n->rb_left;
|
||||||
|
else if (c > 0)
|
||||||
|
n = n->rb_right;
|
||||||
|
else
|
||||||
|
return pg;
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* decode a full map.
|
* decode a full map.
|
||||||
*/
|
*/
|
||||||
@@ -870,26 +896,17 @@ int ceph_calc_object_layout(struct ceph_object_layout *ol,
|
|||||||
static int *calc_pg_raw(struct ceph_osdmap *osdmap, struct ceph_pg pgid,
|
static int *calc_pg_raw(struct ceph_osdmap *osdmap, struct ceph_pg pgid,
|
||||||
int *osds, int *num)
|
int *osds, int *num)
|
||||||
{
|
{
|
||||||
struct rb_node *n = osdmap->pg_temp.rb_node;
|
|
||||||
struct ceph_pg_mapping *pg;
|
struct ceph_pg_mapping *pg;
|
||||||
struct ceph_pg_pool_info *pool;
|
struct ceph_pg_pool_info *pool;
|
||||||
int ruleno;
|
int ruleno;
|
||||||
unsigned poolid, ps, pps;
|
unsigned poolid, ps, pps;
|
||||||
int preferred;
|
int preferred;
|
||||||
int c;
|
|
||||||
|
|
||||||
/* pg_temp? */
|
/* pg_temp? */
|
||||||
while (n) {
|
pg = __lookup_pg_mapping(&osdmap->pg_temp, pgid);
|
||||||
pg = rb_entry(n, struct ceph_pg_mapping, node);
|
if (pg) {
|
||||||
c = pgid_cmp(pgid, pg->pgid);
|
*num = pg->len;
|
||||||
if (c < 0)
|
return pg->osds;
|
||||||
n = n->rb_left;
|
|
||||||
else if (c > 0)
|
|
||||||
n = n->rb_right;
|
|
||||||
else {
|
|
||||||
*num = pg->len;
|
|
||||||
return pg->osds;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* crush */
|
/* crush */
|
||||||
|
Reference in New Issue
Block a user