All of lore.kernel.org
 help / color / mirror / Atom feed
* Question regarding CIFS cache=loose behavior.
@ 2014-03-20 12:03 Tetsuo Handa
       [not found] ` <201403202103.EIE87056.QVtLHSFMFOOFOJ-JPay3/Yim36HaxMnTkn67Xf5DAMn2ifp@public.gmane.org>
  0 siblings, 1 reply; 14+ messages in thread
From: Tetsuo Handa @ 2014-03-20 12:03 UTC (permalink / raw)
  To: linux-cifs, linux-fsdevel

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'.

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2014-03-31 17:48 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-03-20 12:03 Question regarding CIFS cache=loose behavior Tetsuo Handa
     [not found] ` <201403202103.EIE87056.QVtLHSFMFOOFOJ-JPay3/Yim36HaxMnTkn67Xf5DAMn2ifp@public.gmane.org>
2014-03-20 20:19   ` Jeff Layton
     [not found]     ` <20140320161943.60890dd4-9yPaYZwiELC+kQycOl6kW4xkIHaj4LzF@public.gmane.org>
2014-03-20 20:56       ` Tetsuo Handa
     [not found]         ` <201403210556.FEI21354.FLJOQMHtSVOFFO-JPay3/Yim36HaxMnTkn67Xf5DAMn2ifp@public.gmane.org>
2014-03-20 21:04           ` Steve French
2014-03-20 23:10           ` Jeff Layton
     [not found]             ` <20140320191013.110276c0-9yPaYZwiELC+kQycOl6kW4xkIHaj4LzF@public.gmane.org>
2014-03-21  8:56               ` Pavel Shilovsky
     [not found]                 ` <CAKywueTNDHSGia58AcKwuDtZA2zc_yOQR-iFTPq3XTrYm6bNLQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-03-21 11:40                   ` Jeff Layton
2014-03-26 12:04               ` Tetsuo Handa
     [not found]                 ` <201403262104.AGG86982.StVMOJOHFOQFLF-JPay3/Yim36HaxMnTkn67Xf5DAMn2ifp@public.gmane.org>
2014-03-26 12:21                   ` Jeffrey Layton
     [not found]                     ` <20140326052119.32405279-uvzPfv+vNdB0Ogp0/tUwVOTW4wlIGRCZ@public.gmane.org>
2014-03-26 13:03                       ` Jeffrey Layton
2014-03-26 13:06                         ` Tetsuo Handa
     [not found]                         ` <20140326060305.3226a08c-uvzPfv+vNdB0Ogp0/tUwVOTW4wlIGRCZ@public.gmane.org>
2014-03-26 14:05                           ` Tetsuo Handa
     [not found]                             ` <201403262305.GBG17639.MOJLVOOSFHFtQF-JPay3/Yim36HaxMnTkn67Xf5DAMn2ifp@public.gmane.org>
2014-03-26 14:12                               ` Jeffrey Layton
2014-03-31 17:48   ` Jeff Layton

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.