How to do nonblocking writes to CIFS networkshares?

Shirish Pargaonkar shirishpargaonkar at gmail.com
Sat Jan 24 16:59:57 MST 2015


On Wed, Jan 21, 2015 at 8:50 AM, Sebastian Rasmussen
<sebastian.rasmussen at axis.com> wrote:
> Hi!
>
> I'm new to this mailing list, so please help out if I'm adressing the wrong
> forum. :)
>
> I'm working on an application accessing a mounted networkshare. Under normal
> circumstances there is no problem accessing reading and writing to the
> networkshare using POSIX open(2)/read(2)/write(2) etc. However if there is
> intermittent connectivity problems to the networkshare my application
> experiences calls blocking for long periods of time when accessing the
> missing networkshare. I have e.g. observed write(2) calls being blocked for
> up to 5 minutes.

Not sure why your writes should be blocking, they should return as soon as they
write data to page-cache. Can you run crash on this live system and
see where this
write call/process is blocked?

>
> Worth noting is that my samba 4.1.13-based networkshare is running on a
> Linux 3.14.15 server and is mounted from a Linux-3.14 client system like so:
> mount -t cifs -o nounix,noserverino,nobrl //192.168.0.42/myshare
> /tmp/mountpoint
>
> In order not to block in these POSIX calls I attempted to open(2) the file
> for writing using O_NONBLOCK and then use select(2) to try to determine if
> the file descriptor was writable before attemping to call write(2). The idea
> being that if the fd claims not to be writable the application then has a
> chance to both wait in the select(2) call for a reasonable time and also try
> to timeout and let the application fail gracefully, should it detect that it
> cannot write to the fd. I assume that any previously successful writes may
> not have been transferred to the networkshare, but instead have been cached
> in the page cache to be transferred if the networkshare responds again
> (within the ~5 minut timeout).
>
> My attempt resulted in the application being able to write lots of data to
> the share while it was unavailable, and the timeout in select(2) was never
> triggered. This was a surprise to me as I expected the fd to indicate that
> it was blocking at some point and that the timeout would be triggered.
>
> Now, I need some advice: Have I glossed over something fundamental about how
> CIFS networkshares work? Is it possible to write applications that will not
> block indefinitely (5 minuts would be considered indefinitely in my
> application)? If yes, then what alternatives exists to O_NONBLOCK to do
> this?
>
>  / Sebastian
>
> PS. I contemplated fusesmb but it doesn't look like it handles O_NONBLOCK or
> similar either, so I think that is not viable.
>


More information about the samba-technical mailing list