Subject: Re: SETATTR and guard

From: Eric Werme USG <[email-masked]>
Date: Tue, 19 Jun 2001 15:12:18 -0400

Spencer Emailed me:

     Would you mind sharing with the NFSv4 WG what your OS does with
   respect to atomicity between the guard check and SETATTR?
   
The VOP_ calls the Tru64 server makes for a guarded setattr are:

	VOP_RWLOCK(vp, 1, lerror);
	VOP_GETATTR(vp, &bva, u.u_cred, bverror);
	if (args->guard.check) {
		[check guard data, error out if mismatch]
	}
	VOP_SETATTR(vp, &ava, u.u_cred, error);
	VOP_FSYNC(vp, FWRITE | FWRITE_METADATA, u.u_cred, MNT_WAIT, error);
	VOP_GETATTR(vp, &ava, u.u_cred, averror);

      done:
	VOP_RWUNLOCK(vp, 1, lerror);

The RWLOCK/RWUNLOCK stuff was added for this and to make the pre & post
op attributes accurate for writes and the other ops that use weak
cache consistancy.

Warts:

  UFS supports RWLOCK/RWUNLOCK, AdvFS doesn't.  Every so often they notice
  that and mutter about implementing it.  If RWLOCK fails, we don't
  return pre-op attributes.

  We don't use it with write gathering as several writes over time get
  mashed together and the file would be locked for quite a while.  (That
  may be a bogus argument.)  We don't return pre-op attributes on gathered
  writes either.

  Local VFS calls (write(2), etc) don't call RWLOCK, so we only support
  the guarded setattr well in a pure NFS server environment.

I haven't heard complaints about the warts, so I haven't pushed to clean
them up.

	-Ric Werme

---

From: Neil Brown <[email-masked]>
Date: Wed, 20 Jun 2001 16:04:52 +1000 (EST)

>    respect to atomicity between the guard check and SETATTR?

Hmmm.  I thought to see what the Linux NFSv3 server does.
And the answer is: Nothing.  It completely ignores the sattrguard.  It
xdr-decodes it and nothing else  :-(

I have a patch which will go to Linus shortly.  It assures that the
test is atomic with the setattr only for size changes, which is
probably the only case that really matters.  It is not possible to be
atomic wrt othe attributes except for nfs-only activity, and there
doesn't seem much point.

The Linux NFS client doesn't seem to use the guard at all either....

NeilBrown