You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@nuttx.apache.org by Petro Karashchenko <pe...@gmail.com> on 2021/12/01 15:45:01 UTC

FS automount: callback when FS is mounted

Hello,

I have a question regarding FS automount functionality. Is there a way 
to get a callback when file system is mounted and ready to be accessed? 
Or the only way is to implement a polling loop like:

while ( access( "/mnt/sdcard0", F_OK ) != 0 )
{
   sleep(1);
}

Best regards,
Petro


Re: FS automount: callback when FS is mounted

Posted by Petro Karashchenko <pe...@gmail.com>.
Hello Gregory,

I made some progress with this activity. Will appreciate your review
https://github.com/apache/incubator-nuttx/pull/5345

Best regards,
Petro

чт, 2 груд. 2021 р. о 01:42 Gregory Nutt <sp...@gmail.com> пише:
>
> > But ai think that the approach with a signal will require turning
> automount
>
> into a complete file based driver with open/close/ioctl support.
>
>
> Yes, it would have to support a minimal character driver interfaces, one
> for each monitored volume.  The are several characters drivers that just do
> IOCTLs and no data transfers.  It would have to be like those.

RE: FS automount: callback when FS is mounted

Posted by Gregory Nutt <sp...@gmail.com>.
> But ai think that the approach with a signal will require turning
automount

into a complete file based driver with open/close/ioctl support.


Yes, it would have to support a minimal character driver interfaces, one
for each monitored volume.  The are several characters drivers that just do
IOCTLs and no data transfers.  It would have to be like those.

Re: FS automount: callback when FS is mounted

Posted by Petro Karashchenko <pe...@gmail.com>.
But ai think that the approach with a signal will require turning automount
into a complete file based driver with open/close/ioctl support.

What do you think?

Best regards,
Petro

On Thu, Dec 2, 2021, 12:37 AM Petro Karashchenko <
petro.karashchenko@gmail.com> wrote:

> Yes. Thank you for pointing me out this.
>
> I was looking into SIGEV_THREAD with a callback posting a semaphore, but
> sigtimedwait() seems to be exactly what I'm looking for.
>
> Best regards,
> Petro
>
> On Thu, Dec 2, 2021, 12:20 AM Gregory Nutt <sp...@gmail.com> wrote:
>
>> > Yeah, I used a wrong term when was asking about "callback". Actually I
>> need
>>
>> asynchronous notification, so I can pend a task on some primitive like a
>>
>> semaphore.
>>
>>
>>
>> Semaphore is not a good choice to OS/application signaling due to memory
>> access issues in some build configurations.  And semapores are not easilty
>> shareable in the case of multiple waiters.
>>
>>
>>
>> Again, a signal is what you want.  Your applications can wait on a signal
>> primitive for any mount related event to occur. This is the strategy used
>> everywhere and is intended just for what you are doing.
>>
>

Re: FS automount: callback when FS is mounted

Posted by Petro Karashchenko <pe...@gmail.com>.
Yes. Thank you for pointing me out this.

I was looking into SIGEV_THREAD with a callback posting a semaphore, but
sigtimedwait() seems to be exactly what I'm looking for.

Best regards,
Petro

On Thu, Dec 2, 2021, 12:20 AM Gregory Nutt <sp...@gmail.com> wrote:

> > Yeah, I used a wrong term when was asking about "callback". Actually I
> need
>
> asynchronous notification, so I can pend a task on some primitive like a
>
> semaphore.
>
>
>
> Semaphore is not a good choice to OS/application signaling due to memory
> access issues in some build configurations.  And semapores are not easilty
> shareable in the case of multiple waiters.
>
>
>
> Again, a signal is what you want.  Your applications can wait on a signal
> primitive for any mount related event to occur. This is the strategy used
> everywhere and is intended just for what you are doing.
>

Re: FS automount: callback when FS is mounted

Posted by Gregory Nutt <sp...@gmail.com>.
> Yeah, I used a wrong term when was asking about "callback". Actually I
need

asynchronous notification, so I can pend a task on some primitive like a

semaphore.



Semaphore is not a good choice to OS/application signaling due to memory
access issues in some build configurations.  And semapores are not easilty
shareable in the case of multiple waiters.



Again, a signal is what you want.  Your applications can wait on a signal
primitive for any mount related event to occur. This is the strategy used
everywhere and is intended just for what you are doing.

Re: FS automount: callback when FS is mounted

Posted by Petro Karashchenko <pe...@gmail.com>.
Hi Greg,

Yeah, I used a wrong term when was asking about "callback". Actually I need
asynchronous notification, so I can pend a task on some primitive like a
semaphore.

Thank you for replying with an example. I will examine it.

Best regards,
Petro


On Wed, Dec 1, 2021, 8:43 PM Gregory Nutt <sp...@gmail.com> wrote:

>
> > I have a question regarding FS automount functionality. Is there a way
> > to get a callback when file system is mounted and ready to be
> > accessed? Or the only way is to implement a polling loop like:
> >
> > while ( access( "/mnt/sdcard0", F_OK ) != 0 )
> > {
> >   sleep(1);
> > }
>
> No, there will never never be callbacks from the OS into application
> code.  That is not the POSIX way.  The POSIX way would use signals for
> things like this.
>
> Look in drivers/, there are many drivers that notify applications of
> events via signals.  Try searching for "notify".
>
> Here is one of many examples that provides a signal when a button is
> pressed:  drivers/input/button_upper.c.  That notification interface is
> described in include/nuttx/buttons.h:
>
>       66 /* Command:     BTNIOC_REGISTER
>       67  * Description: Register to receive a signal whenever there is
>     a change in
>       68  *              the state of button inputs.  This feature, of
>     course, depends
>       69  *              upon interrupt GPIO support from the platform.
>       70  * Argument:    A read-only pointer to an instance of struct
>     btn_notify_s
>       71  * Return:      Zero (OK) on success.  Minus one will be
>     returned on failure
>       72  *              with the errno value set appropriately.
>       73  */
>       74
>       75 #define BTNIOC_REGISTER   _BTNIOC(0x0003)
>
> A similar notification interface could be added to the
> fs/mount/fs_automounter logic to notify an application when a monitored
> volume is mounted or unmounted.
>
>

Re: FS automount: callback when FS is mounted

Posted by Gregory Nutt <sp...@gmail.com>.
> I have a question regarding FS automount functionality. Is there a way 
> to get a callback when file system is mounted and ready to be 
> accessed? Or the only way is to implement a polling loop like:
>
> while ( access( "/mnt/sdcard0", F_OK ) != 0 )
> {
>   sleep(1);
> } 

No, there will never never be callbacks from the OS into application 
code.  That is not the POSIX way.  The POSIX way would use signals for 
things like this.

Look in drivers/, there are many drivers that notify applications of 
events via signals.  Try searching for "notify".

Here is one of many examples that provides a signal when a button is 
pressed:  drivers/input/button_upper.c.  That notification interface is 
described in include/nuttx/buttons.h:

      66 /* Command:     BTNIOC_REGISTER
      67  * Description: Register to receive a signal whenever there is
    a change in
      68  *              the state of button inputs.  This feature, of
    course, depends
      69  *              upon interrupt GPIO support from the platform.
      70  * Argument:    A read-only pointer to an instance of struct
    btn_notify_s
      71  * Return:      Zero (OK) on success.  Minus one will be
    returned on failure
      72  *              with the errno value set appropriately.
      73  */
      74
      75 #define BTNIOC_REGISTER   _BTNIOC(0x0003)

A similar notification interface could be added to the 
fs/mount/fs_automounter logic to notify an application when a monitored 
volume is mounted or unmounted.