From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id 38A748205E; Sun, 24 Jan 2021 19:29:07 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 38A748205E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1611505747; bh=p0+cxO887VqygszkOen/7UI38NG/vxCdHayDhJFsXPg=; h=To:References:Date:In-Reply-To:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=D0Bs3wlPXavzuxedOpQbdRnyZQJUd4ZyRg8wAH6eYISnFozzzqWdLJMStZcn6pPCn mbo3f8SmctrHJKY0JZEPKeH65xWwBGIH6zyKYT3/+O6Bw2U0c5iYmdCcw1pWNdRsyL LFxR9dfghwSdlTydPLjzN4C8RPR2AvEe+wT3ro9c= Received: from smtpng3.m.smailru.net (smtpng3.m.smailru.net [94.100.177.149]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 3D9E88205E for ; Sun, 24 Jan 2021 19:28:22 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 3D9E88205E Received: by smtpng3.m.smailru.net with esmtpa (envelope-from ) id 1l3iFR-0003Lm-PV; Sun, 24 Jan 2021 19:28:22 +0300 To: Cyrill Gorcunov , tml References: <20210118203556.281700-1-gorcunov@gmail.com> <20210118203556.281700-7-gorcunov@gmail.com> Message-ID: Date: Sun, 24 Jan 2021 17:28:20 +0100 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.6.1 MIME-Version: 1.0 In-Reply-To: <20210118203556.281700-7-gorcunov@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD9F0E84CC1954AA43822D0E69C8207B07BF48BAF577699426D00894C459B0CD1B9E76091F87109F91AE62B96D8638C7548E677AB1C9F20D3C8E230A8568C332C38 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE716FAD50E497B9C14EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F790063745476ED688D943148638F802B75D45FF5571747095F342E8C7A0BC55FA0FE5FC520051DBA2F12A100E7A864DE92943FA0EE06BB2D42ADF2D389733CBF5DBD5E913377AFFFEAFD269A417C69337E82CC2CC7F00164DA146DAFE8445B8C89999729449624AB7ADAF37F6B57BC7E64490611E7FA7ABCAF51C92A417C69337E82CC2CC7F00164DA146DA6F5DAA56C3B73B23C77107234E2CFBA567F23339F89546C55F5C1EE8F4F765FC9BFB91CAEB05C77775ECD9A6C639B01BBD4B6F7A4D31EC0BC0CAF46E325F83A522CA9DD8327EE4930A3850AC1BE2E735E5B2F3A2B87CD4C8C4224003CC836476C0CAF46E325F83A50BF2EBBBDD9D6B0FECB2555BB02FD5A93B503F486389A921A5CC5B56E945C8DA X-C1DE0DAB: 0D63561A33F958A541CE587AB3D202A7A66BDA9A9C4A9E3FF55B1281C70B2CB3D59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA75448CF9D3A7B2C848410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D347341ACA13FB8BDD9168C4B5C7B4AA736233FAB6E553B7C227BF5DEDE0942175E037465A0643074D01D7E09C32AA3244CE6D3D678AE0C9C502A704A844A89C34CF2F5F14F68F1805B729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojEcKN7r9rK/3hAG+vOk11Xw== X-Mailru-Sender: 689FA8AB762F73936BC43F508A06382220525BEFF9BEA7D4E36BE3018724C5E43841015FED1DE5223CC9A89AB576DD93FB559BB5D741EB963CF37A108A312F5C27E8A8C3839CE0E267EA787935ED9F1B X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH v12 6/8] module_cache: provide helpers to load and unload modules X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Vladislav Shpilevoy via Tarantool-patches Reply-To: Vladislav Shpilevoy Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" 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.