[Gluster-devel] Why to fork so many times?
Pavan T C
tcp at gluster.com
Tue Jun 7 09:14:23 UTC 2011
On Tuesday 07 June 2011 02:08 PM, Daniel wrote:
> Thank you, Pavan. It clarifies most of my doubts.
>
> Only I can't find the branch of 'if sync-mtab == 1'. And I thought it
> was without "YES fork()". Could you explain more about that, please?
>
Oh, the variable mtab_pid is what indicates whether the sync-mtab option
is set or not. Trace back the caller of fuse_mnt_add_mount(). The call
stack looks like below;
fuse_bridge.c:init() -> gf_fuse_mount() -> fuse_mount_sys() ->
fuse_mnt_add_mount().
In gf_fuse_mount(), the last parameter is passed as :
sync_mtab ? &ctx->mtab_pid : NULL
So, if the "sync-mtab" option is set, mtab_pid will be non-NULL.
Otherwise it will be NULL.
Now you can relate back to the condition in fuse_mnt_add_mount().
If mtab_pid is NULL, the "NO" condition in the flow-chart I provided
comes into picture. Otherwise the code follows the YES condition.
Pavan
> Thanks a lot.
>
> Dan
>
> On Tue, 2011-06-07 at 12:29 +0530, Pavan T C wrote:
>> On Tuesday 07 June 2011 10:54 AM, Daniel wrote:
>>> Hello hackers:
>>>
>>> I am learning glusterfs and get one question when I reading
>>> contrib/fuse-lib/mount.c fuse_mnt_add_mount(). Why does it fork four
>>> times and the grand-grand-child exec("/bin/mount")? What is the benefit
>>> and the consideration?
>>
>> As I see it, it forks thrice. Here is what I understand from the code:
>>
>> +---------------------+
>> | fuse_mnt_add_mount()|<------------------------------+
>> | fork and wait for | |
>> | child to return | |
>> +-----+---------------+ |
>> | |
>> | |
>> X |
>> / \ |
>> /if \ |
>> /sync-\ NO +---------------------------+ |
>> X mtab X-------->| Do async ops by returning | |
>> \ == 1/ fork() | from here so that parent | |
>> \ / | does not wait. But before | |
>> \ / | doing that, create a dummy| |
>> X | parent to wait for child | |
>> | YES | that does the /bin/mount | |
>> | +------------+--------------+ |
>> | fork() | |
>> V | |
>> +-----+----------+ | fork() -> Parent returns here.
>> | Child: execl | v
>> | /bin/mount with| +---------------+
>> | -f option to | |dummy parent: |
>> | only populate | fork() | fork and wait |
>> | mtab but don't |<--------+ for /bin/mount|
>> | actually mount | | to return |
>> | anything. | +---------------+
>> +----------------+
>>
>> HTH,
>> Pavan
>>
>>>
>>> Thank you
>>>
>>> Daniel
>>>
>>>
>>> _______________________________________________
>>> Gluster-devel mailing list
>>> Gluster-devel at nongnu.org
>>> https://lists.nongnu.org/mailman/listinfo/gluster-devel
>>
>
>
More information about the Gluster-devel
mailing list