Tarantool development patches archive
 help / color / mirror / Atom feed
From: Vladislav Shpilevoy via Tarantool-patches <tarantool-patches@dev.tarantool.org>
To: Cyrill Gorcunov <gorcunov@gmail.com>,
	tml <tarantool-patches@dev.tarantool.org>
Subject: Re: [Tarantool-patches] [PATCH v12 6/8] module_cache: provide helpers to load and unload modules
Date: Sun, 24 Jan 2021 17:28:20 +0100	[thread overview]
Message-ID: <f46c3bbe-f167-0212-f9db-4ad33a4c970c@tarantool.org> (raw)
In-Reply-To: <20210118203556.281700-7-gorcunov@gmail.com>

Thanks for the patch!

> diff --git a/src/box/module_cache.c b/src/box/module_cache.c
> index ae874caab..cb580f342 100644
> --- a/src/box/module_cache.c
> +++ b/src/box/module_cache.c
> @@ -437,6 +431,34 @@ module_cache_update(const char *name, const char *name_end,
>  	return 0;
>  }
>  
> +/**
> + * Load a new module.
> + */
> +struct module *
> +module_load(const char *path, size_t path_len)
> +{
> +	struct module *module = module_cache_find(path, &path[path_len]);
> +	if (module == NULL) {
> +		module = module_dlopen(path, &path[path_len]);
> +		if (module == NULL)
> +			return NULL;
> +		if (module_cache_add(module) != 0) {
> +			module_delete(module);
> +			return NULL;
> +		}
> +	}
> +	return module;
> +}
> +
> +/**
> + * Unload a module.
> + */
> +void
> +module_unload(struct module *module)
> +{
> +	module_gc(module);

From what I see in the main commit, you should increase
the reference counter in load and decrease it in unload.

When you do that - you get another issue: --ref + module_gc() become
a pattern. So it makes sense to move them to a function module_unref().

Also it looks super strange, that the module deletion from the cache
is done in module_sym_unload(). I don't think it should change anything
except its mod_sym argument.

Another issue - module.funcs_list is an implicit reference counter,
which is extra weird. The function list should only be used for
reloads. Each function should increase the counter, so it couldn't happen
that the ref counter is 0, but there are functions keeping a pointer at
the module.

As you can see there is really a pile of issues with the current
reference counting and deletion of modules. Maybe better fix all of
them while you are here. At least the issue in your main patch about
touching ref counter manually.

  reply	other threads:[~2021-01-24 16:29 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-18 20:35 [Tarantool-patches] [PATCH v12 0/8] box: implement cmod Lua module Cyrill Gorcunov via Tarantool-patches
2021-01-18 20:35 ` [Tarantool-patches] [PATCH v12 1/8] box/func: factor out c function entry structure Cyrill Gorcunov via Tarantool-patches
2021-01-18 20:35 ` [Tarantool-patches] [PATCH v12 2/8] module_cache: move module handling into own subsystem Cyrill Gorcunov via Tarantool-patches
2021-01-24 16:26   ` Vladislav Shpilevoy via Tarantool-patches
2021-01-25  8:52     ` Cyrill Gorcunov via Tarantool-patches
2021-01-18 20:35 ` [Tarantool-patches] [PATCH v12 3/8] module_cache: improve naming Cyrill Gorcunov via Tarantool-patches
2021-01-24 16:27   ` Vladislav Shpilevoy via Tarantool-patches
2021-01-24 22:32     ` Cyrill Gorcunov via Tarantool-patches
2021-01-30 18:53       ` Vladislav Shpilevoy via Tarantool-patches
2021-02-01 11:41         ` Cyrill Gorcunov via Tarantool-patches
2021-01-18 20:35 ` [Tarantool-patches] [PATCH v12 4/8] module_cache: direct update a cache value on reload Cyrill Gorcunov via Tarantool-patches
2021-01-19 12:46   ` Cyrill Gorcunov via Tarantool-patches
2021-01-24 16:27     ` Vladislav Shpilevoy via Tarantool-patches
2021-01-24 22:26       ` Cyrill Gorcunov via Tarantool-patches
2021-01-18 20:35 ` [Tarantool-patches] [PATCH v12 5/8] module_cache: rename calls to ref in module structure Cyrill Gorcunov via Tarantool-patches
2021-01-24 16:27   ` Vladislav Shpilevoy via Tarantool-patches
2021-01-25 10:29     ` Cyrill Gorcunov via Tarantool-patches
2021-01-18 20:35 ` [Tarantool-patches] [PATCH v12 6/8] module_cache: provide helpers to load and unload modules Cyrill Gorcunov via Tarantool-patches
2021-01-24 16:28   ` Vladislav Shpilevoy via Tarantool-patches [this message]
2021-01-18 20:35 ` [Tarantool-patches] [PATCH v12 7/8] box/cmod: implement cmod Lua module Cyrill Gorcunov via Tarantool-patches
2021-01-24 16:28   ` Vladislav Shpilevoy via Tarantool-patches
2021-01-25 16:50     ` Cyrill Gorcunov via Tarantool-patches
2021-01-30 18:53       ` Vladislav Shpilevoy via Tarantool-patches
2021-01-18 20:35 ` [Tarantool-patches] [PATCH v12 8/8] test: box/cfunc -- add cmod test Cyrill Gorcunov via Tarantool-patches
2021-01-24 16:28   ` Vladislav Shpilevoy via Tarantool-patches
2021-01-24 16:26 ` [Tarantool-patches] [PATCH v12 0/8] box: implement cmod Lua module Vladislav Shpilevoy via Tarantool-patches

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=f46c3bbe-f167-0212-f9db-4ad33a4c970c@tarantool.org \
    --to=tarantool-patches@dev.tarantool.org \
    --cc=gorcunov@gmail.com \
    --cc=v.shpilevoy@tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH v12 6/8] module_cache: provide helpers to load and unload modules' \
    /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