Skip to content

Commit

Permalink
Don't let fuse enter in background because we loose our workers.
Browse files Browse the repository at this point in the history
Instead, use Sys_Daemon and enter in background ourselves so that
we create the worker pool while in background
  • Loading branch information
stcarrez committed Dec 24, 2020
1 parent e574dbb commit f3bc9ca
Showing 1 changed file with 35 additions and 4 deletions.
39 changes: 35 additions & 4 deletions tools/fuse/akt-commands-mount.adb
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,17 @@
-- See the License for the specific language governing permissions and
-- limitations under the License.
-----------------------------------------------------------------------
with System;
with Fuse;
with AKT.Filesystem;
package body AKT.Commands.Mount is

use type System.Address;

function Sys_Daemon (No_Chdir : in Integer; No_Close : in Integer) return Integer
with Import => True, Convention => C, Link_Name => "daemon";
pragma Weak_External (Sys_Daemon);

Mount_Command : aliased Command_Type;

-- ------------------------------
Expand All @@ -37,11 +44,35 @@ package body AKT.Commands.Mount is
Data.Wallet := Context.Wallet'Unchecked_Access;
Data.Direct_IO := not Command.Enable_Cache;

Context.Open_Keystore (Args, Use_Worker => True);
-- We can open the keystore before going in background
-- but don't create the worker tasks.
Context.Open_Keystore (Args, Use_Worker => False);

-- If daemon(3) is available and -d is defined, run it so that the parent
-- process terminates and the child process continues.
if not Command.Foreground and Sys_Daemon'Address /= System.Null_Address then
declare
Result : constant Integer := Sys_Daemon (1, 0);
begin
if Result /= 0 then
AKT.Commands.Log.Error ("Cannot run in background");
end if;
end;
end if;

if Command.Foreground then
Mount_Arguments.Append ("-f");
-- Now we can start the workers.
if Context.Worker_Count > 1 then
Context.Workers := new Keystore.Task_Manager (Context.Worker_Count);
Keystore.Start (Context.Workers);
Context.Wallet.Set_Work_Manager (Context.Workers);
end if;

-- Always run in foreground because Open_Keystore has started some tasks
-- and we need them (they will dead in the child if fuse runs as daemon).
Mount_Arguments.Append ("-f");

-- Even if the Keystore is thread-safe, run only one thread in fuse.
Mount_Arguments.Append ("-s");
if Command.Verbose_Fuse then
Mount_Arguments.Append ("-d");
end if;
Expand All @@ -67,7 +98,7 @@ package body AKT.Commands.Mount is
Long_Switch => "--foreground",
Help => -("Run as foreground (no daemonize)"));
GC.Define_Switch (Config => Config,
Output => Command.Foreground'Access,
Output => Command.Verbose_Fuse'Access,
Long_Switch => "--debug-fuse",
Help => -("Enable debug output of fuse library"));
GC.Define_Switch (Config => Config,
Expand Down

0 comments on commit f3bc9ca

Please sign in to comment.