Tarantool development patches archive
 help / color / mirror / Atom feed
From: Kirill Shcherbatov <kshcherbatov@tarantool.org>
To: tarantool-patches@freelists.org, vdavydov.dev@gmail.com
Cc: Kirill Shcherbatov <kshcherbatov@tarantool.org>
Subject: [PATCH v2 2/9] box: move box_module_reload routine to func.c
Date: Thu,  6 Jun 2019 15:03:58 +0300	[thread overview]
Message-ID: <4c036f20e844e4060e37583e85c28fb91d02156c.1559822429.git.kshcherbatov@tarantool.org> (raw)
In-Reply-To: <cover.1559822429.git.kshcherbatov@tarantool.org>

Previously, the box_module_reload function was located in the
box/call module that is wrong. It is moved to a more suitable
place in box/func.
---
 src/box/call.c     | 21 ---------------------
 src/box/call.h     | 10 ----------
 src/box/func.c     | 25 ++++++++++++++++++++++++-
 src/box/func.h     | 12 ++++--------
 src/box/lua/call.c |  1 +
 5 files changed, 29 insertions(+), 40 deletions(-)

diff --git a/src/box/call.c b/src/box/call.c
index 56da53fb3..982c95cbf 100644
--- a/src/box/call.c
+++ b/src/box/call.c
@@ -132,27 +132,6 @@ box_c_call(struct func *func, struct call_request *request, struct port *port)
 	return 0;
 }
 
-int
-box_module_reload(const char *name)
-{
-	struct credentials *credentials = effective_user();
-	if ((credentials->universal_access & (PRIV_X | PRIV_U)) !=
-	    (PRIV_X | PRIV_U)) {
-		struct user *user = user_find(credentials->uid);
-		if (user != NULL)
-			diag_set(AccessDeniedError, priv_name(PRIV_U),
-				 schema_object_name(SC_UNIVERSE), "",
-				 user->def->name);
-		return -1;
-	}
-	struct module *module = NULL;
-	if (module_reload(name, name + strlen(name), &module) == 0 &&
-	    module != NULL)
-		return 0;
-	diag_set(ClientError, ER_NO_SUCH_MODULE, name);
-	return -1;
-}
-
 int
 box_process_call(struct call_request *request, struct port *port)
 {
diff --git a/src/box/call.h b/src/box/call.h
index 1b54551be..4b3b8614c 100644
--- a/src/box/call.h
+++ b/src/box/call.h
@@ -42,16 +42,6 @@ struct box_function_ctx {
 	struct port *port;
 };
 
-/**
- * Reload loadable module by name.
- *
- * @param name of the module to reload.
- * @retval -1 on error.
- * @retval 0 on success.
- */
-int
-box_module_reload(const char *name);
-
 int
 box_process_call(struct call_request *request, struct port *port);
 
diff --git a/src/box/func.c b/src/box/func.c
index a817851fd..098bc02b6 100644
--- a/src/box/func.c
+++ b/src/box/func.c
@@ -31,6 +31,7 @@
 #include "func.h"
 #include "trivia/config.h"
 #include "assoc.h"
+#include "session.h"
 #include "lua/utils.h"
 #include "error.h"
 #include "diag.h"
@@ -298,7 +299,16 @@ module_sym(struct module *module, const char *name)
 	return f;
 }
 
-int
+/**
+ * Reload dynamically loadable module.
+ *
+ * @param package name begin pointer.
+ * @param package_end package_end name end pointer.
+ * @param[out] module a pointer to store module object on success.
+ * @retval -1 on error.
+ * @retval 0 on success.
+ */
+static int
 module_reload(const char *package, const char *package_end, struct module **module)
 {
 	struct module *old_module = module_cache_find(package, package_end);
@@ -355,6 +365,19 @@ restore:
 	return -1;
 }
 
+int
+box_module_reload(const char *name)
+{
+	if (access_check_universe(PRIV_X | PRIV_U) != 0)
+		return -1;
+	struct module *module = NULL;
+	if (module_reload(name, name + strlen(name), &module) == 0 &&
+	    module != NULL)
+		return 0;
+	diag_set(ClientError, ER_NO_SUCH_MODULE, name);
+	return -1;
+}
+
 struct func *
 func_new(struct func_def *def)
 {
diff --git a/src/box/func.h b/src/box/func.h
index 8dcd61d7b..db839a17a 100644
--- a/src/box/func.h
+++ b/src/box/func.h
@@ -114,16 +114,12 @@ func_call(struct func *func, box_function_ctx_t *ctx, const char *args,
 	  const char *args_end);
 
 /**
- * Reload dynamically loadable module.
- *
- * @param package name begin pointer.
- * @param package_end package_end name end pointer.
- * @param[out] module a pointer to store module object on success.
- * @retval -1 on error.
- * @retval 0 on success.
+ * Reload loadable module by a given name.
+ * Returns 0 in case of success and -1 otherwise and sets the
+ * diag message.
  */
 int
-module_reload(const char *package, const char *package_end, struct module **module);
+box_module_reload(const char *name);
 
 #if defined(__cplusplus)
 } /* extern "C" */
diff --git a/src/box/lua/call.c b/src/box/lua/call.c
index c729778c4..9edb5bf7e 100644
--- a/src/box/lua/call.c
+++ b/src/box/lua/call.c
@@ -31,6 +31,7 @@
 #include "box/lua/call.h"
 #include "box/call.h"
 #include "box/error.h"
+#include "box/func.h"
 #include "fiber.h"
 
 #include "lua/utils.h"
-- 
2.21.0

  parent reply	other threads:[~2019-06-06 12:03 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-06 12:03 [PATCH v2 0/9] box: rework functions machinery Kirill Shcherbatov
2019-06-06 12:03 ` [PATCH v2 1/9] box: refactor box_lua_find helper Kirill Shcherbatov
2019-06-10  9:17   ` Vladimir Davydov
2019-06-06 12:03 ` Kirill Shcherbatov [this message]
2019-06-10  9:19   ` [PATCH v2 2/9] box: move box_module_reload routine to func.c Vladimir Davydov
2019-06-06 12:03 ` [PATCH v2 3/9] box: rework func cache update machinery Kirill Shcherbatov
2019-06-10  9:44   ` Vladimir Davydov
2019-06-06 12:04 ` [PATCH v2 4/9] box: rework func object as a function frontend Kirill Shcherbatov
2019-06-10 10:32   ` Vladimir Davydov
2019-06-06 12:04 ` [PATCH v2 5/9] schema: rework _func system space format Kirill Shcherbatov
2019-06-10 12:10   ` Vladimir Davydov
2019-06-06 12:04 ` [PATCH v2 6/9] box: load persistent Lua functions on creation Kirill Shcherbatov
2019-06-10 12:19   ` Vladimir Davydov
2019-06-06 12:04 ` [PATCH v2 7/9] box: sandbox option for persistent functions Kirill Shcherbatov
2019-06-10 14:06   ` Vladimir Davydov
2019-06-10 14:15     ` [tarantool-patches] " Kirill Shcherbatov
2019-06-10 14:41       ` Vladimir Davydov
2019-06-06 12:04 ` [PATCH v2 8/9] box: implement lua_port dump to region and to Lua Kirill Shcherbatov
2019-06-10 14:24   ` Vladimir Davydov
2019-06-06 12:04 ` [PATCH v2 9/9] box: export _func functions with box.func folder Kirill Shcherbatov
2019-06-10 15:18   ` Vladimir Davydov
2019-06-10  9:14 ` [PATCH v2 0/9] box: rework functions machinery Vladimir Davydov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4c036f20e844e4060e37583e85c28fb91d02156c.1559822429.git.kshcherbatov@tarantool.org \
    --to=kshcherbatov@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --cc=vdavydov.dev@gmail.com \
    --subject='Re: [PATCH v2 2/9] box: move box_module_reload routine to func.c' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox