Skip to content

Commit 6f428df

Browse files
committed
libceph: pg_upmap[_items] infrastructure
pg_temp and pg_upmap encodings are the same (PG -> array of osds), except for the incremental remove: it's an empty mapping in new_pg_temp for pg_temp and a separate old_pg_upmap set for pg_upmap. (This isn't to allow for empty pg_upmap mappings -- apparently, pg_temp just wasn't looked at as an example for pg_upmap encoding.) Reuse __decode_pg_temp() for decoding pg_upmap and new_pg_upmap. __decode_pg_temp() stores into pg_temp union member, but since pg_upmap union member is identical, reading through pg_upmap later is OK. Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
1 parent 278b1d7 commit 6f428df

3 files changed

Lines changed: 164 additions & 4 deletions

File tree

‎include/linux/ceph/osdmap.h‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,14 @@ struct ceph_pg_mapping {
143143
struct {
144144
int len;
145145
int osds[];
146-
} pg_temp;
146+
} pg_temp, pg_upmap;
147147
struct {
148148
int osd;
149149
} primary_temp;
150+
struct {
151+
int len;
152+
int from_to[][2];
153+
} pg_upmap_items;
150154
};
151155
};
152156

@@ -165,6 +169,10 @@ struct ceph_osdmap {
165169
struct rb_root pg_temp;
166170
struct rb_root primary_temp;
167171

172+
/* remap (post-CRUSH, pre-up) */
173+
struct rb_root pg_upmap; /* PG := raw set */
174+
struct rb_root pg_upmap_items; /* from -> to within raw set */
175+
168176
u32 *osd_primary_affinity;
169177

170178
struct rb_root pg_pools;

‎net/ceph/debugfs.c‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,29 @@ static int osdmap_show(struct seq_file *s, void *p)
104104
seq_printf(s, "primary_temp %llu.%x %d\n", pg->pgid.pool,
105105
pg->pgid.seed, pg->primary_temp.osd);
106106
}
107+
for (n = rb_first(&map->pg_upmap); n; n = rb_next(n)) {
108+
struct ceph_pg_mapping *pg =
109+
rb_entry(n, struct ceph_pg_mapping, node);
110+
111+
seq_printf(s, "pg_upmap %llu.%x [", pg->pgid.pool,
112+
pg->pgid.seed);
113+
for (i = 0; i < pg->pg_upmap.len; i++)
114+
seq_printf(s, "%s%d", (i == 0 ? "" : ","),
115+
pg->pg_upmap.osds[i]);
116+
seq_printf(s, "]\n");
117+
}
118+
for (n = rb_first(&map->pg_upmap_items); n; n = rb_next(n)) {
119+
struct ceph_pg_mapping *pg =
120+
rb_entry(n, struct ceph_pg_mapping, node);
121+
122+
seq_printf(s, "pg_upmap_items %llu.%x [", pg->pgid.pool,
123+
pg->pgid.seed);
124+
for (i = 0; i < pg->pg_upmap_items.len; i++)
125+
seq_printf(s, "%s%d->%d", (i == 0 ? "" : ","),
126+
pg->pg_upmap_items.from_to[i][0],
127+
pg->pg_upmap_items.from_to[i][1]);
128+
seq_printf(s, "]\n");
129+
}
107130

108131
up_read(&osdc->lock);
109132
return 0;

‎net/ceph/osdmap.c‎

Lines changed: 132 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -735,6 +735,8 @@ struct ceph_osdmap *ceph_osdmap_alloc(void)
735735
map->pool_max = -1;
736736
map->pg_temp = RB_ROOT;
737737
map->primary_temp = RB_ROOT;
738+
map->pg_upmap = RB_ROOT;
739+
map->pg_upmap_items = RB_ROOT;
738740
mutex_init(&map->crush_workspace_mutex);
739741

740742
return map;
@@ -759,6 +761,20 @@ void ceph_osdmap_destroy(struct ceph_osdmap *map)
759761
erase_pg_mapping(&map->primary_temp, pg);
760762
free_pg_mapping(pg);
761763
}
764+
while (!RB_EMPTY_ROOT(&map->pg_upmap)) {
765+
struct ceph_pg_mapping *pg =
766+
rb_entry(rb_first(&map->pg_upmap),
767+
struct ceph_pg_mapping, node);
768+
rb_erase(&pg->node, &map->pg_upmap);
769+
kfree(pg);
770+
}
771+
while (!RB_EMPTY_ROOT(&map->pg_upmap_items)) {
772+
struct ceph_pg_mapping *pg =
773+
rb_entry(rb_first(&map->pg_upmap_items),
774+
struct ceph_pg_mapping, node);
775+
rb_erase(&pg->node, &map->pg_upmap_items);
776+
kfree(pg);
777+
}
762778
while (!RB_EMPTY_ROOT(&map->pg_pools)) {
763779
struct ceph_pg_pool_info *pi =
764780
rb_entry(rb_first(&map->pg_pools),
@@ -1161,6 +1177,75 @@ static int decode_new_primary_affinity(void **p, void *end,
11611177
return -EINVAL;
11621178
}
11631179

1180+
static struct ceph_pg_mapping *__decode_pg_upmap(void **p, void *end,
1181+
bool __unused)
1182+
{
1183+
return __decode_pg_temp(p, end, false);
1184+
}
1185+
1186+
static int decode_pg_upmap(void **p, void *end, struct ceph_osdmap *map)
1187+
{
1188+
return decode_pg_mapping(p, end, &map->pg_upmap, __decode_pg_upmap,
1189+
false);
1190+
}
1191+
1192+
static int decode_new_pg_upmap(void **p, void *end, struct ceph_osdmap *map)
1193+
{
1194+
return decode_pg_mapping(p, end, &map->pg_upmap, __decode_pg_upmap,
1195+
true);
1196+
}
1197+
1198+
static int decode_old_pg_upmap(void **p, void *end, struct ceph_osdmap *map)
1199+
{
1200+
return decode_pg_mapping(p, end, &map->pg_upmap, NULL, true);
1201+
}
1202+
1203+
static struct ceph_pg_mapping *__decode_pg_upmap_items(void **p, void *end,
1204+
bool __unused)
1205+
{
1206+
struct ceph_pg_mapping *pg;
1207+
u32 len, i;
1208+
1209+
ceph_decode_32_safe(p, end, len, e_inval);
1210+
if (len > (SIZE_MAX - sizeof(*pg)) / (2 * sizeof(u32)))
1211+
return ERR_PTR(-EINVAL);
1212+
1213+
ceph_decode_need(p, end, 2 * len * sizeof(u32), e_inval);
1214+
pg = kzalloc(sizeof(*pg) + 2 * len * sizeof(u32), GFP_NOIO);
1215+
if (!pg)
1216+
return ERR_PTR(-ENOMEM);
1217+
1218+
pg->pg_upmap_items.len = len;
1219+
for (i = 0; i < len; i++) {
1220+
pg->pg_upmap_items.from_to[i][0] = ceph_decode_32(p);
1221+
pg->pg_upmap_items.from_to[i][1] = ceph_decode_32(p);
1222+
}
1223+
1224+
return pg;
1225+
1226+
e_inval:
1227+
return ERR_PTR(-EINVAL);
1228+
}
1229+
1230+
static int decode_pg_upmap_items(void **p, void *end, struct ceph_osdmap *map)
1231+
{
1232+
return decode_pg_mapping(p, end, &map->pg_upmap_items,
1233+
__decode_pg_upmap_items, false);
1234+
}
1235+
1236+
static int decode_new_pg_upmap_items(void **p, void *end,
1237+
struct ceph_osdmap *map)
1238+
{
1239+
return decode_pg_mapping(p, end, &map->pg_upmap_items,
1240+
__decode_pg_upmap_items, true);
1241+
}
1242+
1243+
static int decode_old_pg_upmap_items(void **p, void *end,
1244+
struct ceph_osdmap *map)
1245+
{
1246+
return decode_pg_mapping(p, end, &map->pg_upmap_items, NULL, true);
1247+
}
1248+
11641249
/*
11651250
* decode a full map.
11661251
*/
@@ -1250,9 +1335,7 @@ static int osdmap_decode(void **p, void *end, struct ceph_osdmap *map)
12501335
if (err)
12511336
goto bad;
12521337
} else {
1253-
/* XXX can this happen? */
1254-
kfree(map->osd_primary_affinity);
1255-
map->osd_primary_affinity = NULL;
1338+
WARN_ON(map->osd_primary_affinity);
12561339
}
12571340

12581341
/* crush */
@@ -1261,6 +1344,26 @@ static int osdmap_decode(void **p, void *end, struct ceph_osdmap *map)
12611344
if (err)
12621345
goto bad;
12631346

1347+
*p += len;
1348+
if (struct_v >= 3) {
1349+
/* erasure_code_profiles */
1350+
ceph_decode_skip_map_of_map(p, end, string, string, string,
1351+
bad);
1352+
}
1353+
1354+
if (struct_v >= 4) {
1355+
err = decode_pg_upmap(p, end, map);
1356+
if (err)
1357+
goto bad;
1358+
1359+
err = decode_pg_upmap_items(p, end, map);
1360+
if (err)
1361+
goto bad;
1362+
} else {
1363+
WARN_ON(!RB_EMPTY_ROOT(&map->pg_upmap));
1364+
WARN_ON(!RB_EMPTY_ROOT(&map->pg_upmap_items));
1365+
}
1366+
12641367
/* ignore the rest */
12651368
*p = end;
12661369

@@ -1520,6 +1623,32 @@ struct ceph_osdmap *osdmap_apply_incremental(void **p, void *end,
15201623
goto bad;
15211624
}
15221625

1626+
if (struct_v >= 3) {
1627+
/* new_erasure_code_profiles */
1628+
ceph_decode_skip_map_of_map(p, end, string, string, string,
1629+
bad);
1630+
/* old_erasure_code_profiles */
1631+
ceph_decode_skip_set(p, end, string, bad);
1632+
}
1633+
1634+
if (struct_v >= 4) {
1635+
err = decode_new_pg_upmap(p, end, map);
1636+
if (err)
1637+
goto bad;
1638+
1639+
err = decode_old_pg_upmap(p, end, map);
1640+
if (err)
1641+
goto bad;
1642+
1643+
err = decode_new_pg_upmap_items(p, end, map);
1644+
if (err)
1645+
goto bad;
1646+
1647+
err = decode_old_pg_upmap_items(p, end, map);
1648+
if (err)
1649+
goto bad;
1650+
}
1651+
15231652
/* ignore the rest */
15241653
*p = end;
15251654

0 commit comments

Comments
 (0)