From 5ea7c55332d12ae9ab3407dc0e82bbc45847e497 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Thu, 17 Apr 2008 20:22:03 -0700 Subject: [PATCH] kclient: umount unregisters with monitor --- src/kernel/client.c | 12 ++- src/kernel/mon_client.c | 162 ++++++++++++++++++++++++---------------- src/kernel/mon_client.h | 18 ++++- 3 files changed, 124 insertions(+), 68 deletions(-) diff --git a/src/kernel/client.c b/src/kernel/client.c index 49dc5c0df0a29..7ca0f5cf10de2 100644 --- a/src/kernel/client.c +++ b/src/kernel/client.c @@ -232,7 +232,14 @@ fail: void ceph_umount_start(struct ceph_client *cl) { + int rc; + int seconds = 15; + ceph_mdsc_stop(&cl->mdsc); + ceph_monc_request_umount(&cl->monc); + rc = wait_event_timeout(cl->mount_wq, (cl->mounting == 0), seconds*HZ); + if (rc == 0) + derr(0, "umount timed out after %d seconds\n", seconds); } void ceph_destroy_client(struct ceph_client *cl) @@ -276,6 +283,9 @@ void ceph_dispatch(void *p, struct ceph_msg *msg) case CEPH_MSG_STATFS_REPLY: ceph_monc_handle_statfs_reply(&client->monc, msg); break; + case CEPH_MSG_CLIENT_UNMOUNT: + ceph_monc_handle_umount(&client->monc, msg); + break; /* mds client */ case CEPH_MSG_MDS_MAP: @@ -312,7 +322,7 @@ void ceph_dispatch(void *p, struct ceph_msg *msg) break; default: - derr(1, "dispatch unknown message type %d\n", type); + derr(0, "received unknown message type %d\n", type); } ceph_msg_put(msg); diff --git a/src/kernel/mon_client.c b/src/kernel/mon_client.c index 0faa1b997936a..fdbd3c05df4f1 100644 --- a/src/kernel/mon_client.c +++ b/src/kernel/mon_client.c @@ -1,6 +1,7 @@ #include #include +#include #include "mon_client.h" int ceph_debug_mon = -1; @@ -69,22 +70,23 @@ static int pick_mon(struct ceph_mon_client *monc, int notmon) /* * delay work with exponential backoff */ -void ceph_monc_delayed_work(struct delayed_work *dwork, unsigned long *delay) +static void delayed_work(struct delayed_work *dwork, unsigned long *delay) { - dout(5, "ceph_monc_delayed_work started\n"); + dout(5, "delayed_work started\n"); schedule_delayed_work(dwork, *delay); if (*delay < MAX_DELAY_INTERVAL) *delay *= 2; else *delay = MAX_DELAY_INTERVAL; - + dout(5, "delayed_work finished\n"); } + /* - * worker function for request mdsmap + * mds map */ -static void work_monc_request_mdsmap(struct work_struct *work) +static void do_request_mdsmap(struct work_struct *work) { struct ceph_msg *msg; struct ceph_mds_getmap *h; @@ -93,8 +95,7 @@ static void work_monc_request_mdsmap(struct work_struct *work) mds_delayed_work.work); int mon = pick_mon(monc, -1); - dout(5, "work_monc_request_mdsmap from mon%d have %u\n", mon, - monc->have_mdsmap); + dout(5, "request_mdsmap from mon%d have %u\n", mon, monc->have_mdsmap); msg = ceph_msg_new(CEPH_MSG_MDS_GETMAP, sizeof(*h), 0, 0, 0); if (IS_ERR(msg)) @@ -108,65 +109,14 @@ static void work_monc_request_mdsmap(struct work_struct *work) /* keep sending request until we receive mds map */ if (monc->have_mdsmap) - ceph_monc_delayed_work(&monc->mds_delayed_work, - &monc->mds_delay); -} - -/* - * worker function for request osdmap - */ -void work_monc_request_osdmap(struct work_struct *work) -{ - struct ceph_msg *msg; - struct ceph_osd_getmap *h; - struct ceph_mon_client *monc = - container_of(work, struct ceph_mon_client, - osd_delayed_work.work); - int mon = pick_mon(monc, -1); - - dout(5, "ceph_monc_request_osdmap from mon%d have %u\n", mon, - monc->have_osdmap); - msg = ceph_msg_new(CEPH_MSG_OSD_GETMAP, sizeof(*h), 0, 0, 0); - if (IS_ERR(msg)) - return; - h = msg->front.iov_base; - h->fsid = monc->monmap->fsid; - h->start = cpu_to_le32(monc->have_osdmap); - h->want = cpu_to_le32(monc->want_osdmap); - msg->hdr.dst = monc->monmap->mon_inst[mon]; - ceph_msg_send(monc->client->msgr, msg, 0); - - /* keep sending request until we receive osd map */ - if (monc->have_osdmap) - ceph_monc_delayed_work(&monc->osd_delayed_work, - &monc->osd_delay); -} - -int ceph_monc_init(struct ceph_mon_client *monc, struct ceph_client *cl) -{ - dout(5, "ceph_monc_init\n"); - memset(monc, 0, sizeof(*monc)); - monc->client = cl; - monc->monmap = kzalloc(sizeof(struct ceph_monmap), GFP_KERNEL); - if (monc->monmap == NULL) - return -ENOMEM; - spin_lock_init(&monc->lock); - INIT_RADIX_TREE(&monc->statfs_request_tree, GFP_KERNEL); - INIT_DELAYED_WORK(&monc->mds_delayed_work, work_monc_request_mdsmap); - INIT_DELAYED_WORK(&monc->osd_delayed_work, work_monc_request_osdmap); - monc->mds_delay = BASE_DELAY_INTERVAL; - monc->osd_delay = BASE_DELAY_INTERVAL; - monc->last_tid = 0; - monc->have_mdsmap = 0; - monc->have_osdmap = 0; - monc->want_osdmap = 0; - return 0; + delayed_work(&monc->mds_delayed_work, &monc->mds_delay); } void ceph_monc_request_mdsmap(struct ceph_mon_client *monc, __u32 have) { + monc->mds_delay = BASE_DELAY_INTERVAL; monc->have_mdsmap = have; - ceph_monc_delayed_work(&monc->mds_delayed_work, &monc->mds_delay); + do_request_mdsmap(&monc->mds_delayed_work.work); } int ceph_monc_got_mdsmap(struct ceph_mon_client *monc, __u32 have) @@ -189,13 +139,43 @@ int ceph_monc_got_mdsmap(struct ceph_mon_client *monc, __u32 have) } } + +/* + * osd map + */ +static void do_request_osdmap(struct work_struct *work) +{ + struct ceph_msg *msg; + struct ceph_osd_getmap *h; + struct ceph_mon_client *monc = + container_of(work, struct ceph_mon_client, + osd_delayed_work.work); + int mon = pick_mon(monc, -1); + + dout(5, "request_osdmap from mon%d have %u\n", mon, monc->have_osdmap); + msg = ceph_msg_new(CEPH_MSG_OSD_GETMAP, sizeof(*h), 0, 0, 0); + if (IS_ERR(msg)) + return; + h = msg->front.iov_base; + h->fsid = monc->monmap->fsid; + h->start = cpu_to_le32(monc->have_osdmap); + h->want = cpu_to_le32(monc->want_osdmap); + msg->hdr.dst = monc->monmap->mon_inst[mon]; + ceph_msg_send(monc->client->msgr, msg, 0); + + /* keep sending request until we receive osd map */ + if (monc->have_osdmap) + delayed_work(&monc->osd_delayed_work, &monc->osd_delay); +} + void ceph_monc_request_osdmap(struct ceph_mon_client *monc, __u32 have, __u32 want) { dout(5, "ceph_monc_request_osdmap have %u want %u\n", have, want); + monc->osd_delay = BASE_DELAY_INTERVAL; monc->have_osdmap = have; monc->want_osdmap = want; - ceph_monc_delayed_work(&monc->osd_delayed_work, &monc->osd_delay); + do_request_osdmap(&monc->osd_delayed_work.work); } int ceph_monc_got_osdmap(struct ceph_mon_client *monc, __u32 have) @@ -220,11 +200,46 @@ int ceph_monc_got_osdmap(struct ceph_mon_client *monc, __u32 have) } +/* + * umount + */ +static void do_request_umount(struct work_struct *work) +{ + struct ceph_msg *msg; + struct ceph_mon_client *monc = + container_of(work, struct ceph_mon_client, + umount_delayed_work.work); + int mon = pick_mon(monc, -1); + + dout(5, "do_request_umount from mon%d\n", mon); + msg = ceph_msg_new(CEPH_MSG_CLIENT_UNMOUNT, 0, 0, 0, 0); + if (IS_ERR(msg)) + return; + msg->hdr.dst = monc->monmap->mon_inst[mon]; + ceph_msg_send(monc->client->msgr, msg, 0); + + delayed_work(&monc->umount_delayed_work, &monc->umount_delay); +} + +void ceph_monc_request_umount(struct ceph_mon_client *monc) +{ + monc->umount_delay = BASE_DELAY_INTERVAL; + do_request_umount(&monc->umount_delayed_work.work); +} + +void ceph_monc_handle_umount(struct ceph_mon_client *monc, + struct ceph_msg *msg) +{ + dout(5, "ceph_monc_handle_umount\n"); + cancel_delayed_work_sync(&monc->umount_delayed_work); + monc->client->mounting = 0; + wake_up(&monc->client->mount_wq); +} + /* * statfs */ - void ceph_monc_handle_statfs_reply(struct ceph_mon_client *monc, struct ceph_msg *msg) { @@ -298,3 +313,24 @@ int ceph_monc_do_statfs(struct ceph_mon_client *monc, struct ceph_statfs *buf) wait_for_completion(&req.completion); return 0; } + + +int ceph_monc_init(struct ceph_mon_client *monc, struct ceph_client *cl) +{ + dout(5, "ceph_monc_init\n"); + memset(monc, 0, sizeof(*monc)); + monc->client = cl; + monc->monmap = kzalloc(sizeof(struct ceph_monmap), GFP_KERNEL); + if (monc->monmap == NULL) + return -ENOMEM; + spin_lock_init(&monc->lock); + INIT_RADIX_TREE(&monc->statfs_request_tree, GFP_KERNEL); + INIT_DELAYED_WORK(&monc->mds_delayed_work, do_request_mdsmap); + INIT_DELAYED_WORK(&monc->osd_delayed_work, do_request_osdmap); + INIT_DELAYED_WORK(&monc->umount_delayed_work, do_request_umount); + monc->last_tid = 0; + monc->have_mdsmap = 0; + monc->have_osdmap = 0; + monc->want_osdmap = 0; + return 0; +} diff --git a/src/kernel/mon_client.h b/src/kernel/mon_client.h index 12926f17a1e47..849653620fb41 100644 --- a/src/kernel/mon_client.h +++ b/src/kernel/mon_client.h @@ -33,8 +33,10 @@ struct ceph_mon_client { struct delayed_work mds_delayed_work; /* mds delayed work */ struct delayed_work osd_delayed_work; /* osd delayed work */ + struct delayed_work umount_delayed_work; unsigned long mds_delay; unsigned long osd_delay; + unsigned long umount_delay; u32 have_mdsmap; /* protected by caller's lock */ u32 want_osdmap; /* protected by caller's lock */ @@ -42,7 +44,8 @@ struct ceph_mon_client { }; extern struct ceph_monmap *ceph_monmap_decode(void *p, void *end); -extern int ceph_monmap_contains(struct ceph_monmap *m, struct ceph_entity_addr *addr); +extern int ceph_monmap_contains(struct ceph_monmap *m, + struct ceph_entity_addr *addr); extern int ceph_monc_init(struct ceph_mon_client *monc, struct ceph_client *cl); @@ -54,9 +57,16 @@ extern void ceph_monc_request_osdmap(struct ceph_mon_client *monc, extern int ceph_monc_got_osdmap(struct ceph_mon_client *monc, __u32 have); extern void ceph_monc_request_umount(struct ceph_mon_client *monc); -extern void ceph_monc_report_failure(struct ceph_mon_client *monc, struct ceph_entity_inst *who); +extern void ceph_monc_report_failure(struct ceph_mon_client *monc, + struct ceph_entity_inst *who); -extern int ceph_monc_do_statfs(struct ceph_mon_client *monc, struct ceph_statfs *buf); -extern void ceph_monc_handle_statfs_reply(struct ceph_mon_client *monc, struct ceph_msg *msg); +extern int ceph_monc_do_statfs(struct ceph_mon_client *monc, + struct ceph_statfs *buf); +extern void ceph_monc_handle_statfs_reply(struct ceph_mon_client *monc, + struct ceph_msg *msg); + +extern void ceph_monc_request_umount(struct ceph_mon_client *monc); +extern void ceph_monc_handle_umount(struct ceph_mon_client *monc, + struct ceph_msg *msg); #endif -- 2.39.5