From 9de9901cacd2ed2c8c5f65a938fb6a996efab4cd Mon Sep 17 00:00:00 2001 From: "Yan, Zheng" Date: Wed, 17 Dec 2014 15:46:49 +0800 Subject: [PATCH] client: cleanup client callback registration Signed-off-by: Yan, Zheng --- src/client/Client.cc | 51 ++++++++++++++++++------------------------- src/client/Client.h | 18 +++++++-------- src/client/fuse_ll.cc | 36 +++++++++++++++--------------- 3 files changed, 48 insertions(+), 57 deletions(-) diff --git a/src/client/Client.cc b/src/client/Client.cc index eb183a34fff67..a258a37720315 100644 --- a/src/client/Client.cc +++ b/src/client/Client.cc @@ -155,12 +155,10 @@ Client::Client(Messenger *m, MonClient *mc) logger(NULL), m_command_hook(this), timer(m->cct, client_lock), + callback_handle(NULL), ino_invalidate_cb(NULL), - ino_invalidate_cb_handle(NULL), dentry_invalidate_cb(NULL), - dentry_invalidate_cb_handle(NULL), getgroups_cb(NULL), - getgroups_cb_handle(NULL), async_ino_invalidator(m->cct), async_dentry_invalidator(m->cct), objecter_finisher(m->cct), @@ -2921,7 +2919,7 @@ public: void Client::_async_invalidate(Inode *in, int64_t off, int64_t len, bool keep_caps) { ldout(cct, 10) << "_async_invalidate " << off << "~" << len << (keep_caps ? " keep_caps" : "") << dendl; - ino_invalidate_cb(ino_invalidate_cb_handle, in->vino(), off, len); + ino_invalidate_cb(callback_handle, in->vino(), off, len); client_lock.Lock(); if (!keep_caps) @@ -3914,7 +3912,7 @@ void Client::_async_dentry_invalidate(vinodeno_t dirino, vinodeno_t ino, string& { ldout(cct, 10) << "_async_dentry_invalidate '" << name << "' ino " << ino << " in dir " << dirino << dendl; - dentry_invalidate_cb(dentry_invalidate_cb_handle, dirino, ino, name); + dentry_invalidate_cb(callback_handle, dirino, ino, name); } void Client::_schedule_invalidate_dentry_callback(Dentry *dn, bool del) @@ -4052,7 +4050,7 @@ int Client::check_permissions(Inode *in, int flags, int uid, int gid) gid_t *sgids = NULL; int sgid_count = 0; if (getgroups_cb) { - sgid_count = getgroups_cb(getgroups_cb_handle, uid, &sgids); + sgid_count = getgroups_cb(callback_handle, uid, &sgids); if (sgid_count < 0) { ldout(cct, 3) << "getgroups failed!" << dendl; return sgid_count; @@ -7065,33 +7063,26 @@ int Client::ll_statfs(Inode *in, struct statvfs *stbuf) return statfs(0, stbuf); } -void Client::ll_register_ino_invalidate_cb(client_ino_callback_t cb, void *handle) +void Client::ll_register_callbacks(struct client_callback_args *args) { - Mutex::Locker l(client_lock); - ldout(cct, 10) << "ll_register_ino_invalidate_cb cb " << (void*)cb << " p " << (void*)handle << dendl; - if (cb == NULL) - return; - ino_invalidate_cb = cb; - ino_invalidate_cb_handle = handle; - async_ino_invalidator.start(); -} - -void Client::ll_register_dentry_invalidate_cb(client_dentry_callback_t cb, void *handle) -{ - Mutex::Locker l(client_lock); - ldout(cct, 10) << "ll_register_dentry_invalidate_cb cb " << (void*)cb << " p " << (void*)handle << dendl; - if (cb == NULL) + if (!args) return; - dentry_invalidate_cb = cb; - dentry_invalidate_cb_handle = handle; - async_dentry_invalidator.start(); -} - -void Client::ll_register_getgroups_cb(client_getgroups_callback_t cb, void *handle) -{ Mutex::Locker l(client_lock); - getgroups_cb = cb; - getgroups_cb_handle = handle; + ldout(cct, 10) << "ll_register_callbacks handle " << args->handle + << " invalidate_ino_cb " << args->ino_cb + << " invalidate_dentry_cb " << args->dentry_cb + << " getgroups_cb" << args->getgroups_cb + << dendl; + callback_handle = args->handle; + if (args->ino_cb) { + ino_invalidate_cb = args->ino_cb; + async_ino_invalidator.start(); + } + if (args->dentry_cb) { + dentry_invalidate_cb = args->dentry_cb; + async_dentry_invalidator.start(); + } + getgroups_cb = args->getgroups_cb; } int Client::_sync_fs() diff --git a/src/client/Client.h b/src/client/Client.h index 2d28a84baa646..41212779c0a70 100644 --- a/src/client/Client.h +++ b/src/client/Client.h @@ -127,6 +127,13 @@ typedef void (*client_dentry_callback_t)(void *handle, vinodeno_t dirino, typedef int (*client_getgroups_callback_t)(void *handle, uid_t uid, gid_t **sgids); +struct client_callback_args { + void *handle; + client_ino_callback_t ino_cb; + client_dentry_callback_t dentry_cb; + client_getgroups_callback_t getgroups_cb; +}; + // ======================================================== // client interface @@ -213,14 +220,10 @@ class Client : public Dispatcher { SafeTimer timer; + void *callback_handle; client_ino_callback_t ino_invalidate_cb; - void *ino_invalidate_cb_handle; - client_dentry_callback_t dentry_invalidate_cb; - void *dentry_invalidate_cb_handle; - client_getgroups_callback_t getgroups_cb; - void *getgroups_cb_handle; Finisher async_ino_invalidator; Finisher async_dentry_invalidator; @@ -880,11 +883,8 @@ public: int ll_num_osds(void); int ll_osdaddr(int osd, uint32_t *addr); int ll_osdaddr(int osd, char* buf, size_t size); - void ll_register_ino_invalidate_cb(client_ino_callback_t cb, void *handle); - - void ll_register_dentry_invalidate_cb(client_dentry_callback_t cb, void *handle); - void ll_register_getgroups_cb(client_getgroups_callback_t cb, void *handle); + void ll_register_callbacks(struct client_callback_args *args); }; #endif diff --git a/src/client/fuse_ll.cc b/src/client/fuse_ll.cc index c97c6df5d4fb8..891bc32fb7610 100644 --- a/src/client/fuse_ll.cc +++ b/src/client/fuse_ll.cc @@ -787,7 +787,7 @@ CephFuse::Handle::~Handle() void CephFuse::Handle::finalize() { - client->ll_register_ino_invalidate_cb(NULL, NULL); + client->ll_register_callbacks(NULL); if (se) fuse_remove_signal_handlers(se); @@ -873,23 +873,23 @@ int CephFuse::Handle::start() fuse_session_add_chan(se, ch); - /* - * this is broken: - * - * - the cb needs the request handle to be useful; we should get the - * gids in the method here in fuse_ll.c and pass the gid list in, - * not use a callback. - * - the callback mallocs the list but it is not free()'d - * - * so disable it for now... - - client->ll_register_getgroups_cb(getgroups_cb, this); - - */ - client->ll_register_dentry_invalidate_cb(dentry_invalidate_cb, this); - - if (client->cct->_conf->fuse_use_invalidate_cb) - client->ll_register_ino_invalidate_cb(ino_invalidate_cb, this); + struct client_callback_args args = { + handle: this, + ino_cb: client->cct->_conf->fuse_use_invalidate_cb ? ino_invalidate_cb : NULL, + dentry_cb: dentry_invalidate_cb, + /* + * this is broken: + * + * - the cb needs the request handle to be useful; we should get the + * gids in the method here in fuse_ll.c and pass the gid list in, + * not use a callback. + * - the callback mallocs the list but it is not free()'d + * + * so disable it for now... + getgroups_cb: getgroups_cb, + */ + }; + client->ll_register_callbacks(&args); return 0; } -- 2.39.5