All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Brian Smith" <brian-kIZgWTxU+gRcxvNqPlePQg@public.gmane.org>
To: <linux-nfs@vger.kernel.org>
Subject: cache revalidation & locking
Date: Wed, 27 Feb 2008 09:12:28 -0800	[thread overview]
Message-ID: <000901c87963$efffefb0$6401a8c0@T60> (raw)

According to http://www.unixcoding.org/NFSCoding#attrcache, the Linux NFS client flushes the attribute cache when a fnctl lock is obtained ("fcntl() locking flushes attribute cache with Linux and Solaris, but not with FreeBSD.") 

1. What is the first version of the client that does this (in terms of Linux kernel version)?

2. Is this a side-effect of the implementation, or is this a guarentee that the Linux client makes?

What I really want to know is "How can I get consistent read access, and perform safe appends, when multiple systems are appending to a file?"

My current locking strategy is:
 Opening the file:
   * fd = open(path, O_RDWR | O_APPEND | O_SYNC)
   * verify file integrity via checksums embedded in it
 Reading:
   * lock the while file (l_type=F_RDLCK, l_len=0, l_off=0)
   * fstat(fd, &st);
   * unlock everything after EOF (l_len=0, l_off=st.st_size)
   * read up to (st.st_size)
   * unlock everything before EOF (l_len=st.st_size, l_off=0)
 Appending:
   * lock the whole file (l_type=F_WRLCK, l_len=0, l_off=0)
   * fstat(fd, &st);
   * read up to (st.st_size)
   * replace write lock with read lock before EOF
     (l_len=st.st_size, l_off=0)
   * append the new data.
   * unlock the whole file (l_len = 0, l_off = 0)
 Protection against partial write failures:
    * checksums are written within the file in every write()

Is this a sound strategy when using the Linux NFS client? Is there a better one (one that reduces lock contention?)

- Brian


                 reply	other threads:[~2008-02-27 17:43 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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='000901c87963$efffefb0$6401a8c0@T60' \
    --to=brian-kizgwtxu+grcxvnqplepqg@public.gmane.org \
    --cc=linux-nfs@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.