This is an automated email from the ASF dual-hosted git repository.

zwoop pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git


The following commit(s) were added to refs/heads/master by this push:
     new 2172e45  This adds a new callback to remap APIs: TSRemapConfigReload
2172e45 is described below

commit 2172e45780bbd3023a618f2d2810b42eb3fb4d5e
Author: Leif Hedstrom <zw...@apache.org>
AuthorDate: Wed May 2 14:11:56 2018 -0600

    This adds a new callback to remap APIs: TSRemapConfigReload
    
    The purpose of this is to send a notification to every remap plugin
    (if they implement this callback) that a remap.config is about to
    be reloaded. This can be useful for some plugin that needs to know
    that it's about to get instantiated one or numerous times.
    
    This new callback is optional, so this should be a compatible
    change. It takes no arguments, and has no return value.
    
    Once this has landed, I'll update the s3_auth plugin with an example
    how this new callback can be useful. But tldr; this plugin has a
    little config state cache, which has to be reset whenever the remap
    rules are reloaded.
---
 doc/developer-guide/api/functions/TSRemap.en.rst |  8 +++++++-
 proxy/ReverseProxy.cc                            |  5 ++---
 proxy/api/ts/remap.h                             |  8 ++++++++
 proxy/http/remap/RemapConfig.cc                  | 21 +++++++++++++++------
 proxy/http/remap/RemapPluginInfo.cc              | 17 +++++++++++++++++
 proxy/http/remap/RemapPluginInfo.h               |  4 ++++
 6 files changed, 53 insertions(+), 10 deletions(-)

diff --git a/doc/developer-guide/api/functions/TSRemap.en.rst 
b/doc/developer-guide/api/functions/TSRemap.en.rst
index 1eb3f579..77b80f8 100644
--- a/doc/developer-guide/api/functions/TSRemap.en.rst
+++ b/doc/developer-guide/api/functions/TSRemap.en.rst
@@ -30,6 +30,7 @@ Synopsis
 `#include <ts/remap.h>`
 
 .. function:: TSReturnCode TSRemapInit(TSRemapInterface * api_info, char * 
errbuf, int errbuf_size)
+.. function:: void TSRemapConfigReload(void)
 .. function:: void TSRemapDone(void)
 .. function:: TSRemapStatus TSRemapDoRemap(void * ih, TSHttpTxn rh, 
TSRemapRequestInfo * rri)
 .. function:: TSReturnCode TSRemapNewInstance(int argc, char * argv[], void ** 
ih, char * errbuf, int errbuf_size)
@@ -57,12 +58,17 @@ the remap plugin.
 A remap plugin may be invoked for different remap rules. Traffic Server
 will call the entry point each time a plugin is specified in a remap
 rule. When a remap plugin instance is no longer required, Traffic Server
-will call :func:`TSRemapDeleteInstance`.
+will call :func:`TSRemapDeleteInstance`. At that point, it's safe to remove
+any data or continuations associated with that instance.
 
 :func:`TSRemapDoRemap` is called for each HTTP transaction. This is a mandatory
 entry point. In this function, the remap plugin may examine and modify
 the HTTP transaction.
 
+:func:`TSRemapConfigReload` is called once for every remap plugin just before 
the
+remap configuration file (:file:`remap.config`) is reloaded. This is an 
optional
+entry point, which takes no arguments and has no return value.
+
 Types
 =====
 
diff --git a/proxy/ReverseProxy.cc b/proxy/ReverseProxy.cc
index 6203dda..3d7e174 100644
--- a/proxy/ReverseProxy.cc
+++ b/proxy/ReverseProxy.cc
@@ -44,8 +44,8 @@
 
 // Global Ptrs
 static Ptr<ProxyMutex> reconfig_mutex;
-UrlRewrite *rewrite_table = nullptr;
-remap_plugin_info *remap_pi_list; // We never reload the remap plugins, just 
append to 'em.
+UrlRewrite *rewrite_table        = nullptr;
+remap_plugin_info *remap_pi_list = nullptr; // We never reload the remap 
plugins, just append to 'em.
 
 // Tokens for the Callback function
 #define FILE_CHANGED 0
@@ -58,7 +58,6 @@ remap_plugin_info *remap_pi_list; // We never reload the 
remap plugins, just app
 //
 // Begin API Functions
 //
-
 int
 init_reverse_proxy()
 {
diff --git a/proxy/api/ts/remap.h b/proxy/api/ts/remap.h
index 70847bd..edc1c23 100644
--- a/proxy/api/ts/remap.h
+++ b/proxy/api/ts/remap.h
@@ -88,6 +88,14 @@ typedef enum {
 */
 tsapi TSReturnCode TSRemapInit(TSRemapInterface *api_info, char *errbuf, int 
errbuf_size);
 
+/* This gets called everytime remap.config is reloaded. This is complementary
+   to TSRemapInit() which gets called when the plugin is first loaded. You can
+   not fail, or cause reload to stop here, it's merely a notification.
+   Optional function.
+   Return: none
+*/
+tsapi void TSRemapConfigReload(void);
+
 /* Remap new request
    Mandatory interface function.
    Remap API plugin can/should use SDK API function calls inside this function!
diff --git a/proxy/http/remap/RemapConfig.cc b/proxy/http/remap/RemapConfig.cc
index 0b508e9..f082374 100644
--- a/proxy/http/remap/RemapConfig.cc
+++ b/proxy/http/remap/RemapConfig.cc
@@ -796,13 +796,17 @@ remap_load_plugin(const char **argv, int argc, 
url_mapping *mp, char *errbuf, in
         snprintf(errbuf, errbufsize, "Can't load plugin \"%s\" - %s", c, err ? 
err : "Unknown dlopen() error");
         return -4;
       }
-      pi->fp_tsremap_init         = (remap_plugin_info::_tsremap_init 
*)dlsym(pi->dlh, TSREMAP_FUNCNAME_INIT);
-      pi->fp_tsremap_done         = (remap_plugin_info::_tsremap_done 
*)dlsym(pi->dlh, TSREMAP_FUNCNAME_DONE);
-      pi->fp_tsremap_new_instance = (remap_plugin_info::_tsremap_new_instance 
*)dlsym(pi->dlh, TSREMAP_FUNCNAME_NEW_INSTANCE);
+      pi->fp_tsremap_init = reinterpret_cast<remap_plugin_info::_tsremap_init 
*>(dlsym(pi->dlh, TSREMAP_FUNCNAME_INIT));
+      pi->fp_tsremap_config_reload =
+        reinterpret_cast<remap_plugin_info::_tsremap_config_reload 
*>(dlsym(pi->dlh, TSREMAP_FUNCNAME_CONFIG_RELOAD));
+      pi->fp_tsremap_done = reinterpret_cast<remap_plugin_info::_tsremap_done 
*>(dlsym(pi->dlh, TSREMAP_FUNCNAME_DONE));
+      pi->fp_tsremap_new_instance =
+        reinterpret_cast<remap_plugin_info::_tsremap_new_instance 
*>(dlsym(pi->dlh, TSREMAP_FUNCNAME_NEW_INSTANCE));
       pi->fp_tsremap_delete_instance =
-        (remap_plugin_info::_tsremap_delete_instance *)dlsym(pi->dlh, 
TSREMAP_FUNCNAME_DELETE_INSTANCE);
-      pi->fp_tsremap_do_remap    = (remap_plugin_info::_tsremap_do_remap 
*)dlsym(pi->dlh, TSREMAP_FUNCNAME_DO_REMAP);
-      pi->fp_tsremap_os_response = (remap_plugin_info::_tsremap_os_response 
*)dlsym(pi->dlh, TSREMAP_FUNCNAME_OS_RESPONSE);
+        reinterpret_cast<remap_plugin_info::_tsremap_delete_instance 
*>(dlsym(pi->dlh, TSREMAP_FUNCNAME_DELETE_INSTANCE));
+      pi->fp_tsremap_do_remap = 
reinterpret_cast<remap_plugin_info::_tsremap_do_remap *>(dlsym(pi->dlh, 
TSREMAP_FUNCNAME_DO_REMAP));
+      pi->fp_tsremap_os_response =
+        reinterpret_cast<remap_plugin_info::_tsremap_os_response 
*>(dlsym(pi->dlh, TSREMAP_FUNCNAME_OS_RESPONSE));
 
       if (!pi->fp_tsremap_init) {
         snprintf(errbuf, errbufsize, R"(Can't find "%s" function in remap 
plugin "%s")", TSREMAP_FUNCNAME_INIT, c);
@@ -1418,6 +1422,11 @@ remap_parse_config(const char *path, UrlRewrite *rewrite)
 {
   BUILD_TABLE_INFO bti;
 
+  // If this happens to be a config reload, the list of loaded remap plugins 
is non-empty, and we
+  // can signal all these plugins that a reload has begun.
+  if (remap_pi_list) {
+    remap_pi_list->indicate_reload();
+  }
   bti.rewrite = rewrite;
   return remap_parse_config_bti(path, &bti);
 }
diff --git a/proxy/http/remap/RemapPluginInfo.cc 
b/proxy/http/remap/RemapPluginInfo.cc
index 9b48c48..8e36374 100644
--- a/proxy/http/remap/RemapPluginInfo.cc
+++ b/proxy/http/remap/RemapPluginInfo.cc
@@ -31,6 +31,7 @@ remap_plugin_info::remap_plugin_info(char *_path)
     path_size(0),
     dlh(nullptr),
     fp_tsremap_init(nullptr),
+    fp_tsremap_config_reload(nullptr),
     fp_tsremap_done(nullptr),
     fp_tsremap_new_instance(nullptr),
     fp_tsremap_delete_instance(nullptr),
@@ -107,3 +108,19 @@ remap_plugin_info::delete_my_list()
 
   delete this;
 }
+
+//
+// Tell all plugins (that so wish) that remap.config is being reloaded
+//
+void
+remap_plugin_info::indicate_reload()
+{
+  remap_plugin_info *p = this;
+
+  while (p) {
+    if (p->fp_tsremap_config_reload) {
+      p->fp_tsremap_config_reload();
+    }
+    p = p->next;
+  }
+}
diff --git a/proxy/http/remap/RemapPluginInfo.h 
b/proxy/http/remap/RemapPluginInfo.h
index ad64ac2..92fdf91 100644
--- a/proxy/http/remap/RemapPluginInfo.h
+++ b/proxy/http/remap/RemapPluginInfo.h
@@ -28,6 +28,7 @@
 #include "api/ts/remap.h"
 
 #define TSREMAP_FUNCNAME_INIT "TSRemapInit"
+#define TSREMAP_FUNCNAME_CONFIG_RELOAD "TSRemapConfigReload"
 #define TSREMAP_FUNCNAME_DONE "TSRemapDone"
 #define TSREMAP_FUNCNAME_NEW_INSTANCE "TSRemapNewInstance"
 #define TSREMAP_FUNCNAME_DELETE_INSTANCE "TSRemapDeleteInstance"
@@ -43,6 +44,7 @@ class remap_plugin_info
 {
 public:
   typedef TSReturnCode _tsremap_init(TSRemapInterface *api_info, char *errbuf, 
int errbuf_size);
+  typedef void _tsremap_config_reload();
   typedef void _tsremap_done(void);
   typedef TSReturnCode _tsremap_new_instance(int argc, char *argv[], void 
**ih, char *errbuf, int errbuf_size);
   typedef void _tsremap_delete_instance(void *);
@@ -54,6 +56,7 @@ public:
   int path_size;
   void *dlh; /* "handle" for the dynamic library */
   _tsremap_init *fp_tsremap_init;
+  _tsremap_config_reload *fp_tsremap_config_reload;
   _tsremap_done *fp_tsremap_done;
   _tsremap_new_instance *fp_tsremap_new_instance;
   _tsremap_delete_instance *fp_tsremap_delete_instance;
@@ -66,6 +69,7 @@ public:
   remap_plugin_info *find_by_path(char *_path);
   void add_to_list(remap_plugin_info *pi);
   void delete_my_list();
+  void indicate_reload();
 };
 
 /**

-- 
To stop receiving notification emails like this one, please contact
zw...@apache.org.

Reply via email to