From 6e77a586c48d495f3628a044deb90e4427e9514f Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Tue, 17 Mar 2009 11:30:33 -0700 Subject: [PATCH] kclient: add osd sync that will flush all open osd requests Important for flushing sync write uncommitted requests on syncfs (or shutdown). --- src/kernel/osd_client.c | 32 ++++++++++++++++++++++++++++++++ src/kernel/osd_client.h | 2 +- src/kernel/super.c | 1 + 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/kernel/osd_client.c b/src/kernel/osd_client.c index 144359a944671..affe37993cc9d 100644 --- a/src/kernel/osd_client.c +++ b/src/kernel/osd_client.c @@ -784,6 +784,38 @@ void ceph_osdc_abort_request(struct ceph_osd_client *osdc, } } +void ceph_osdc_sync(struct ceph_osd_client *osdc) +{ + struct ceph_osd_request *req; + u64 last_tid, next_tid = 0; + int got; + + mutex_lock(&osdc->request_mutex); + last_tid = osdc->last_tid; + while (1) { + got = radix_tree_gang_lookup(&osdc->request_tree, (void **)&req, + next_tid, 1); + if (!got) + break; + if (req->r_tid > last_tid) + break; + + next_tid = req->r_tid + 1; + if ((req->r_flags & CEPH_OSD_OP_MODIFY) == 0) + continue; + + ceph_osdc_get_request(req); + mutex_unlock(&osdc->request_mutex); + dout(10, "sync waiting on tid %llu (last is %llu)\n", + req->r_tid, last_tid); + wait_for_completion(&req->r_safe_completion); + mutex_lock(&osdc->request_mutex); + ceph_osdc_put_request(req); + } + mutex_unlock(&osdc->request_mutex); + dout(10, "sync done (thru tid %llu)\n", last_tid); +} + /* * init, shutdown */ diff --git a/src/kernel/osd_client.h b/src/kernel/osd_client.h index 1ffebab69b0b9..75d94aa0a7f95 100644 --- a/src/kernel/osd_client.h +++ b/src/kernel/osd_client.h @@ -128,7 +128,7 @@ extern int ceph_osdc_wait_request(struct ceph_osd_client *osdc, struct ceph_osd_request *req); extern void ceph_osdc_abort_request(struct ceph_osd_client *osdc, struct ceph_osd_request *req); - +extern void ceph_osdc_sync(struct ceph_osd_client *osdc); extern int ceph_osdc_readpages(struct ceph_osd_client *osdc, struct ceph_vino vino, diff --git a/src/kernel/super.c b/src/kernel/super.c index a161c46740f28..2fb731c33c6f5 100644 --- a/src/kernel/super.c +++ b/src/kernel/super.c @@ -117,6 +117,7 @@ static int ceph_statfs(struct dentry *dentry, struct kstatfs *buf) static int ceph_syncfs(struct super_block *sb, int wait) { dout(10, "sync_fs %d\n", wait); + ceph_osdc_sync(&ceph_client(sb)->osdc); return 0; } -- 2.39.5