All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
To: linux-cifs@vger.kernel.org, linux-fsdevel@vger.kernel.org
Subject: Question regarding CIFS cache=loose behavior.
Date: Thu, 20 Mar 2014 21:03:03 +0900	[thread overview]
Message-ID: <201403202103.EIE87056.QVtLHSFMFOOFOJ@I-love.SAKURA.ne.jp> (raw)

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

             reply	other threads:[~2014-03-20 12:03 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-20 12:03 Tetsuo Handa [this message]
     [not found] ` <201403202103.EIE87056.QVtLHSFMFOOFOJ-JPay3/Yim36HaxMnTkn67Xf5DAMn2ifp@public.gmane.org>
2014-03-20 20:19   ` Question regarding CIFS cache=loose behavior 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=201403202103.EIE87056.QVtLHSFMFOOFOJ@I-love.SAKURA.ne.jp \
    --to=penguin-kernel@i-love.sakura.ne.jp \
    --cc=linux-cifs@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.