]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
client: cleanup client callback registration
authorYan, Zheng <zyan@redhat.com>
Wed, 17 Dec 2014 07:46:49 +0000 (15:46 +0800)
committerYan, Zheng <zyan@redhat.com>
Wed, 17 Dec 2014 07:59:20 +0000 (15:59 +0800)
Signed-off-by: Yan, Zheng <zyan@redhat.com>
src/client/Client.cc
src/client/Client.h
src/client/fuse_ll.cc

index eb183a34fff67fc973e721256e4da4bd97b0a4b4..a258a37720315cfc460da1c3ea08400fb00cf430 100644 (file)
@@ -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()
index 2d28a84baa646544d2335f7483c5d1ca1e7bedd5..41212779c0a70ebec5baef36f0aaf9e5d5f967a3 100644 (file)
@@ -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
index c97c6df5d4fb80f0387d552e7dd4612127f1a848..891bc32fb7610f68995d9e827d34f71d6591dce4 100644 (file)
@@ -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;
 }