Skip to content

Commit b03fcfa

Browse files
committed
Merge tag 'ceph-for-4.14-rc2' of git://github.com/ceph/ceph-client
Pull ceph fixes from Ilya Dryomov: "Two small but important fixes: RADOS semantic change in upcoming v12.2.1 release and a rare NULL dereference in create_session_open_msg()" * tag 'ceph-for-4.14-rc2' of git://github.com/ceph/ceph-client: ceph: avoid panic in create_session_open_msg() if utsname() returns NULL libceph: don't allow bidirectional swap of pg-upmap-items
2 parents e2577d2 + 717e6f2 commit b03fcfa

File tree

3 files changed

+32
-13
lines changed

3 files changed

+32
-13
lines changed

fs/ceph/mds_client.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#include <linux/sched.h>
88
#include <linux/debugfs.h>
99
#include <linux/seq_file.h>
10-
#include <linux/utsname.h>
1110
#include <linux/ratelimit.h>
1211

1312
#include "super.h"
@@ -884,8 +883,8 @@ static struct ceph_msg *create_session_open_msg(struct ceph_mds_client *mdsc, u6
884883
void *p;
885884

886885
const char* metadata[][2] = {
887-
{"hostname", utsname()->nodename},
888-
{"kernel_version", utsname()->release},
886+
{"hostname", mdsc->nodename},
887+
{"kernel_version", init_utsname()->release},
889888
{"entity_id", opt->name ? : ""},
890889
{"root", fsopt->server_path ? : "/"},
891890
{NULL, NULL}
@@ -3539,6 +3538,8 @@ int ceph_mdsc_init(struct ceph_fs_client *fsc)
35393538
init_rwsem(&mdsc->pool_perm_rwsem);
35403539
mdsc->pool_perm_tree = RB_ROOT;
35413540

3541+
strncpy(mdsc->nodename, utsname()->nodename,
3542+
sizeof(mdsc->nodename) - 1);
35423543
return 0;
35433544
}
35443545

fs/ceph/mds_client.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <linux/rbtree.h>
99
#include <linux/spinlock.h>
1010
#include <linux/refcount.h>
11+
#include <linux/utsname.h>
1112

1213
#include <linux/ceph/types.h>
1314
#include <linux/ceph/messenger.h>
@@ -368,6 +369,8 @@ struct ceph_mds_client {
368369

369370
struct rw_semaphore pool_perm_rwsem;
370371
struct rb_root pool_perm_tree;
372+
373+
char nodename[__NEW_UTS_LEN + 1];
371374
};
372375

373376
extern const char *ceph_mds_op_name(int op);

net/ceph/osdmap.c

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2445,19 +2445,34 @@ static void apply_upmap(struct ceph_osdmap *osdmap,
24452445

24462446
pg = lookup_pg_mapping(&osdmap->pg_upmap_items, pgid);
24472447
if (pg) {
2448-
for (i = 0; i < raw->size; i++) {
2449-
for (j = 0; j < pg->pg_upmap_items.len; j++) {
2450-
int from = pg->pg_upmap_items.from_to[j][0];
2451-
int to = pg->pg_upmap_items.from_to[j][1];
2452-
2453-
if (from == raw->osds[i]) {
2454-
if (!(to != CRUSH_ITEM_NONE &&
2455-
to < osdmap->max_osd &&
2456-
osdmap->osd_weight[to] == 0))
2457-
raw->osds[i] = to;
2448+
/*
2449+
* Note: this approach does not allow a bidirectional swap,
2450+
* e.g., [[1,2],[2,1]] applied to [0,1,2] -> [0,2,1].
2451+
*/
2452+
for (i = 0; i < pg->pg_upmap_items.len; i++) {
2453+
int from = pg->pg_upmap_items.from_to[i][0];
2454+
int to = pg->pg_upmap_items.from_to[i][1];
2455+
int pos = -1;
2456+
bool exists = false;
2457+
2458+
/* make sure replacement doesn't already appear */
2459+
for (j = 0; j < raw->size; j++) {
2460+
int osd = raw->osds[j];
2461+
2462+
if (osd == to) {
2463+
exists = true;
24582464
break;
24592465
}
2466+
/* ignore mapping if target is marked out */
2467+
if (osd == from && pos < 0 &&
2468+
!(to != CRUSH_ITEM_NONE &&
2469+
to < osdmap->max_osd &&
2470+
osdmap->osd_weight[to] == 0)) {
2471+
pos = j;
2472+
}
24602473
}
2474+
if (!exists && pos >= 0)
2475+
raw->osds[pos] = to;
24612476
}
24622477
}
24632478
}

0 commit comments

Comments
 (0)