Re: Question regarding CIFS cache=loose behavior.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, 20 Mar 2014 21:03:03 +0900
Tetsuo Handa <penguin-kernel@xxxxxxxxxxxxxxxxxxx> wrote:

> Is the behavior described below ( "read() returns 0 unless stat() detects the
> growth of file size" and "read() returns non-0 when stat() detects the growth
> of file size but the data actually read is '\0'" ) a feature of cache=loose
> option?
> 
> Steps to reproduce:
> 
> ---------- Start of writer1.c ----------
> #include <unistd.h>
> int main(int argc, char *argv[])
> {
>     while (write(1, ".", 1) == 1)
>         sleep(1);
>     return 0;
> }
> ---------- End of writer1.c ----------
> 
> ---------- Start of reader1.c ----------
> #include <unistd.h>
> int main(int argc, char *argv[])
> {
>     while (1) {
>         char c;
>         if (read(0, &c, 1) == 1) {
>             if (c)
>                 write(1, &c, 1);
>             else
>                 write(1, "!", 1);
>         } else {
>             sleep(1);
>         }
>     }
>     return 0;
> }
> ---------- End of reader1.c ----------
> 
> ---------- Start of reader2.c ----------
> #include <sys/stat.h>
> #include <unistd.h>
> int main(int argc, char *argv[])
> {
>     while (1) {
>         struct stat buf;
>         char c;
>         fstat(0, &buf);
>         if (read(0, &c, 1) == 1) {
>             if (c)
>                 write(1, &c, 1);
>             else
>                 write(1, "!", 1);
>         } else {
>             sleep(1);
>         }
>     }
>     return 0;
> }
> ---------- End of reader2.c ----------
> 
> Run the following commands on the Samba server side.
> 
>   $ cc -Wall -O3 -o writer1 writer1.c
>   $ ./writer1 > shared_file
> 
> Run the following commands on the Samba client side.
> 
>   $ cc -Wall -O3 -o reader1 reader1.c
>   $ strace -tt -o /tmp/log1 ./reader1 < shared_file
>   ..........     (<= Makes no progress by default)
> 
> The shared_file shown above is a regular file shared via CIFS mounted with
> cache=loose option. (e.g. "mount -t cifs -o cache=loose //server/path /mnt" )
> 
> I expect that the reader1 process reads one byte whenever the writer1
> process writes one byte. But we can observe via /tmp/log1 that the read()
> continues returning 0 until the growth of file size of shared_file is
> recognized by stat() using programs like /bin/ls and /usr/bin/stat .
> 
> Then, terminate the reader1 process using Ctrl-C and run the following
> commands on the Samba client side.
> 
>   $ cc -Wall -O3 -o reader2 reader2.c
>   $ strace -tt -o /tmp/log2 ./reader2 < shared_file
>   ......................!!!!!!     (<= Makes progress with wrong data)
> 
> We can observe via /tmp/log2 that the read() returns 1 because fstat()
> detects the growth of file size of shared_file . However, the data
> returned by read() is not '.' but '\0'.

That's expected behavior. The kernel believes that the file is frozen in
length so it returns short read() calls until the size is updated.

cache=loose is very much not recommended for use when you have multiple
hosts accessing files on the server (or access by processes on the
server itself). It only gives you "loose" cache coherency. The whole
point of it is to allow the client to cache data even when the protocol
says that it shouldn't.

cache=strict is what is recommended and that's the default these days.
-- 
Jeff Layton <jlayton@xxxxxxxxxx>
--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Ext4 Filesystem]     [Union Filesystem]     [Filesystem Testing]     [Ceph Users]     [Ecryptfs]     [AutoFS]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux Cachefs]     [Reiser Filesystem]     [Linux RAID]     [Samba]     [Device Mapper]     [CEPH Development]
  Powered by Linux