]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
client: cleanup client callback registration
authorYan, Zheng <zyan@redhat.com>
Tue, 9 Dec 2014 03:22:29 +0000 (11:22 +0800)
committerYan, Zheng <zyan@redhat.com>
Tue, 9 Dec 2014 06:26:25 +0000 (14:26 +0800)
Signed-off-by: Yan, Zheng <zyan@redhat.com>
src/client/Client.cc
src/client/Client.h
src/client/fuse_ll.cc

index bcff69de1e0220c896749f68a1c6634b8dd5219e..d67172ae643c90348bfdb095aeec957727638336 100644 (file)
@@ -156,13 +156,11 @@ Client::Client(Messenger *m, MonClient *mc)
     logger(NULL),
     m_command_hook(this),
     timer(m->cct, client_lock),
+    callback_handle(NULL),
     switch_interrupt_cb(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),
     interrupt_finisher(m->cct),
@@ -2968,7 +2966,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)
@@ -3965,7 +3963,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)
@@ -4103,7 +4101,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;
@@ -7593,43 +7591,31 @@ 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)
-    return;
-  dentry_invalidate_cb = cb;
-  dentry_invalidate_cb_handle = handle;
-  async_dentry_invalidator.start();
-}
-
-void Client::ll_register_switch_interrupt_cb(client_switch_interrupt_callback_t cb)
-{
-  Mutex::Locker l(client_lock);
-  ldout(cct, 10) << "ll_register_switch_interrupt_cb cb " << (void*)cb << dendl;
-  if (cb == NULL)
+  if (!args)
     return;
-  switch_interrupt_cb = cb;
-  interrupt_finisher.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 cb " << args->handle
+                << " invalidate_ino_cb " << args->ino_cb
+                << " invalidate_dentry_cb " << args->dentry_cb
+                << " getgroups_cb" << args->getgroups_cb
+                << " switch_interrupt_cb " << args->switch_intr_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();
+  }
+  if (args->switch_intr_cb) {
+    switch_interrupt_cb = args->switch_intr_cb;
+    interrupt_finisher.start();
+  }
+  getgroups_cb = args->getgroups_cb;
 }
 
 int Client::_sync_fs()
index 4afc206077d530150f2907fa2d4a8f84259c3f41..8d00037324f237438e96495538319b1abf47fa91 100644 (file)
@@ -140,6 +140,14 @@ 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);
 typedef void(*client_switch_interrupt_callback_t)(void *req, void *data);
 
+struct client_callback_args {
+  void *handle;
+  client_ino_callback_t ino_cb;
+  client_dentry_callback_t dentry_cb;
+  client_switch_interrupt_callback_t switch_intr_cb;
+  client_getgroups_callback_t getgroups_cb;
+};
+
 // ========================================================
 // client interface
 
@@ -226,16 +234,11 @@ class Client : public Dispatcher {
 
   SafeTimer timer;
 
+  void *callback_handle;
   client_switch_interrupt_callback_t switch_interrupt_cb;
-
   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;
@@ -922,10 +925,7 @@ public:
   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_switch_interrupt_cb(client_switch_interrupt_callback_t cb);
+  void ll_register_callbacks(struct client_callback_args *args);
 };
 
 #endif
index 8161485dc7511872a7cd2d444c55776a0203e81c..1f43530572080c71ed5600b0d442aaa35bbf666d 100644 (file)
@@ -852,7 +852,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);
@@ -938,25 +938,25 @@ int CephFuse::Handle::start()
 
   fuse_session_add_chan(se, ch);
 
-  client->ll_register_switch_interrupt_cb(switch_interrupt_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...
-
-  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,
+    switch_intr_cb: switch_interrupt_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;
 }