Skip to content

Commit 5f44f14

Browse files
committed
ceph: handle errors during osd client init
Unwind initializing if we get ENOMEM during client initialization. Signed-off-by: Sage Weil <sage@newdream.net>
1 parent 71ececd commit 5f44f14

4 files changed

Lines changed: 19 additions & 7 deletions

File tree

‎fs/ceph/mds_client.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2552,7 +2552,7 @@ static void delayed_work(struct work_struct *work)
25522552
}
25532553

25542554

2555-
void ceph_mdsc_init(struct ceph_mds_client *mdsc, struct ceph_client *client)
2555+
int ceph_mdsc_init(struct ceph_mds_client *mdsc, struct ceph_client *client)
25562556
{
25572557
mdsc->client = client;
25582558
mutex_init(&mdsc->mutex);
@@ -2582,6 +2582,7 @@ void ceph_mdsc_init(struct ceph_mds_client *mdsc, struct ceph_client *client)
25822582
init_waitqueue_head(&mdsc->cap_flushing_wq);
25832583
spin_lock_init(&mdsc->dentry_lru_lock);
25842584
INIT_LIST_HEAD(&mdsc->dentry_lru);
2585+
return 0;
25852586
}
25862587

25872588
/*

‎fs/ceph/mds_client.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ extern void ceph_put_mds_session(struct ceph_mds_session *s);
282282
extern int ceph_send_msg_mds(struct ceph_mds_client *mdsc,
283283
struct ceph_msg *msg, int mds);
284284

285-
extern void ceph_mdsc_init(struct ceph_mds_client *mdsc,
285+
extern int ceph_mdsc_init(struct ceph_mds_client *mdsc,
286286
struct ceph_client *client);
287287
extern void ceph_mdsc_close_sessions(struct ceph_mds_client *mdsc);
288288
extern void ceph_mdsc_stop(struct ceph_mds_client *mdsc);

‎fs/ceph/osd_client.c‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,19 +1127,26 @@ int ceph_osdc_init(struct ceph_osd_client *osdc, struct ceph_client *client)
11271127
osdc->num_requests = 0;
11281128
INIT_DELAYED_WORK(&osdc->timeout_work, handle_timeout);
11291129

1130+
err = -ENOMEM;
11301131
osdc->req_mempool = mempool_create_kmalloc_pool(10,
11311132
sizeof(struct ceph_osd_request));
11321133
if (!osdc->req_mempool)
1133-
return -ENOMEM;
1134+
goto out;
11341135

11351136
err = ceph_msgpool_init(&osdc->msgpool_op, 4096, 10, true);
11361137
if (err < 0)
1137-
return -ENOMEM;
1138+
goto out_mempool;
11381139
err = ceph_msgpool_init(&osdc->msgpool_op_reply, 512, 0, false);
11391140
if (err < 0)
1140-
return -ENOMEM;
1141-
1141+
goto out_msgpool;
11421142
return 0;
1143+
1144+
out_msgpool:
1145+
ceph_msgpool_destroy(&osdc->msgpool_op);
1146+
out_mempool:
1147+
mempool_destroy(osdc->req_mempool);
1148+
out:
1149+
return err;
11431150
}
11441151

11451152
void ceph_osdc_stop(struct ceph_osd_client *osdc)

‎fs/ceph/super.c‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,9 +530,13 @@ static struct ceph_client *ceph_create_client(struct ceph_mount_args *args)
530530
err = ceph_osdc_init(&client->osdc, client);
531531
if (err < 0)
532532
goto fail_monc;
533-
ceph_mdsc_init(&client->mdsc, client);
533+
err = ceph_mdsc_init(&client->mdsc, client);
534+
if (err < 0)
535+
goto fail_osdc;
534536
return client;
535537

538+
fail_osdc:
539+
ceph_osdc_stop(&client->osdc);
536540
fail_monc:
537541
ceph_monc_stop(&client->monc);
538542
fail_trunc_wq:

0 commit comments

Comments
 (0)