From: Dai Ngo <dai.ngo@oracle.com>
To: bfields@fieldses.org
Cc: linux-nfs@vger.kernel.org
Subject: [PATCH 2/2] st_courtesy.py: add more tests for Courteous Server
Date: Tue, 5 Oct 2021 19:41:23 -0400 [thread overview]
Message-ID: <20211005234123.41053-3-dai.ngo@oracle.com> (raw)
In-Reply-To: <20211005234123.41053-1-dai.ngo@oracle.com>
COUR3: Test OPEN file with OPEN4_SHARE_DENY_WRITE
COUR4: Test Share Reservation. Test 2 clients with same deny mode
COUR5: Test Share Reservation. Test Courtesy client's file access mode
conflicts with deny mode
COUR6: Test Share Reservation. Test Courtesy client's deny mode conflicts
with file access mode
Signed-off-by: Dai Ngo <dai.ngo@oracle.com>
---
nfs4.1/server41tests/st_courtesy.py | 204 ++++++++++++++++++++++++++++++++++++
1 file changed, 204 insertions(+)
diff --git a/nfs4.1/server41tests/st_courtesy.py b/nfs4.1/server41tests/st_courtesy.py
index a38ba30b6133..c98a82b26fc9 100644
--- a/nfs4.1/server41tests/st_courtesy.py
+++ b/nfs4.1/server41tests/st_courtesy.py
@@ -9,7 +9,9 @@ from xdrdef.nfs4_type import open_to_lock_owner4
import nfs_ops
op = nfs_ops.NFS4ops()
import threading
+import logging
+log = logging.getLogger("test.env")
def _getleasetime(sess):
res = sess.compound([op.putrootfh(), op.getattr(1 << FATTR4_LEASE_TIME)])
@@ -80,3 +82,205 @@ def testLockSleepLock(t, env):
stateid = res.resarray[-2].stateid
res = sess2.compound(cour_lockargs(fh, stateid))
check(res, NFS4_OK)
+
+def testShareReservation00(t, env):
+ """Test OPEN file with OPEN4_SHARE_DENY_WRITE
+ 1st client opens file with OPEN4_SHARE_DENY_WRITE
+ 1st client opens same file with OPEN4_SHARE_ACCESS_BOTH and OPEN4_SHARE_DENY_NONE
+ expected reply is NFS4ERR_SHARE_DENIED
+ 2nd client opens file with OPEN4_SHARE_ACCESS_WRITE
+ expected reply is NFS4ERR_SHARE_DENIED
+ sleep to force lease of client 1 to expire
+ 3rd client opens file with OPEN4_SHARE_ACCESS_WRITE
+ expected reply is NFS4_OK
+
+ FLAGS: courteous all
+ CODE: COUR3
+ """
+
+ sess1 = env.c1.new_client_session(env.testname(t))
+ res = create_file(sess1, env.testname(t), want_deleg=False, deny=OPEN4_SHARE_DENY_WRITE)
+ check(res)
+ fh = res.resarray[-1].object
+ stateid = res.resarray[-2].stateid
+
+ claim = open_claim4(CLAIM_FH)
+ how = openflag4(OPEN4_NOCREATE)
+ oowner = open_owner4(0, b"My Open Owner 2")
+ access = OPEN4_SHARE_ACCESS_BOTH|OPEN4_SHARE_ACCESS_WANT_NO_DELEG
+ open_op = op.open(0, access, OPEN4_SHARE_DENY_NONE,
+ oowner, how, claim)
+ res = sess1.compound([op.putfh(fh), open_op])
+ check(res, NFS4ERR_SHARE_DENIED)
+ log.info("local open conflict detected - PASSED\n")
+
+ """ 2nd client """
+ sess2 = env.c1.new_client_session(b"%s_2" % env.testname(t))
+
+ name = env.testname(t)
+ owner = b"owner_%s" % name
+ path = sess1.c.homedir + [name]
+ res = open_file(sess2, owner, path, access=OPEN4_SHARE_ACCESS_WRITE)
+ check(res, NFS4ERR_SHARE_DENIED)
+ log.info("2nd client open conflict detected - PASSED\n")
+
+ """ force lease of both c1 to expire """
+ log.info("force lease to expire...\n")
+ lease_time = _getleasetime(sess1)
+ env.sleep(lease_time + 10, "the lease period + 10 secs")
+
+ """ 3rd client """
+ sess3 = env.c1.new_client_session(b"%s_3" % env.testname(t))
+
+ """ should succeed """
+ name = env.testname(t)
+ owner = b"owner_%s" % name
+ path = sess3.c.homedir + [name]
+ res = open_file(sess3, owner, path, access=OPEN4_SHARE_ACCESS_WRITE)
+ check(res)
+ log.info("3nd client opened OK - no conflict detected - PASSED\n")
+
+ fh = res.resarray[-1].object
+ stateid = res.resarray[-2].stateid
+
+ res = close_file(sess3, fh, stateid=stateid)
+ check(res)
+
+def testShareReservationDB01(t, env):
+ """ Test 2 clients with same deny mode
+ Client 1 opens file with OPEN4_SHARE_ACCESS_WRITE & OPEN4_SHARE_DENY_READ
+ Client 2 opens file with OPEN4_SHARE_ACCESS_WRITE & OPEN4_SHARE_DENY_READ
+ Client 2 open should succeed
+
+ FLAGS: courteous all
+ CODE: COUR4
+ """
+
+ """ client1 creates file with OPEN4_SHARE_ACCESS_WRITE & OPEN4_SHARE_DENY_READ """
+
+ sess1 = env.c1.new_client_session(env.testname(t))
+ res = create_file(sess1, env.testname(t), want_deleg=False,
+ access=OPEN4_SHARE_ACCESS_WRITE, deny=OPEN4_SHARE_DENY_READ)
+ check(res)
+ fh = res.resarray[-1].object
+ stateid = res.resarray[-2].stateid
+
+ """ create 2nd client """
+ sess2 = env.c1.new_client_session(b"%s_2" % env.testname(t))
+
+ """ client2 open file with OPEN4_SHARE_ACCESS_WRITE & OPEN4_SHARE_DENY_READ """
+ name = env.testname(t)
+ owner = b"owner_%s" % name
+ path = sess2.c.homedir + [name]
+ res = open_file(sess2, owner, path, deny=OPEN4_SHARE_DENY_READ,
+ access=OPEN4_SHARE_ACCESS_WRITE|OPEN4_SHARE_ACCESS_WANT_NO_DELEG)
+ check(res)
+ fh2 = res.resarray[-1].object
+ stateid2 = res.resarray[-2].stateid
+
+ log.info("2nd client open OK - PASSED\n")
+
+ res = close_file(sess1, fh, stateid=stateid)
+ check(res)
+
+ res = close_file(sess2, fh2, stateid=stateid2)
+ check(res)
+
+def testShareReservationDB02(t, env):
+ """ Test courtesy clients' file access mode conflicts with deny mode
+ client 1 creates file with OPEN4_SHARE_ACCESS_WRITE
+ sleep to force lease of client 1 to expire
+ client 2 opens file with OPEN4_SHARE_ACCESS_READ & OPEN4_SHARE_DENY_WRITE
+ expected reply is NFS4_OK
+
+ FLAGS: courteous all
+ CODE: COUR5
+ """
+
+ """ client1 creates file with OPEN4_SHARE_ACCESS_WRITE """
+
+ sess1 = env.c1.new_client_session(env.testname(t))
+ res = create_file(sess1, env.testname(t), want_deleg=False,
+ access=OPEN4_SHARE_ACCESS_WRITE)
+ check(res)
+ log.info("client 1 creates file OK\n")
+
+ """ force lease of client1 to expire """
+ log.info("force lease to expire...\n")
+ lease_time = _getleasetime(sess1)
+ env.sleep(lease_time + 10, "the lease period + 10 secs")
+
+ """ create 2nd client """
+ sess2 = env.c1.new_client_session(b"%s_2" % env.testname(t))
+
+ """ 2nd client open file with OPEN4_SHARE_ACCESS_READ & OPEN4_SHARE_DENY_WRITE """
+ name = env.testname(t)
+ owner = b"owner_%s" % name
+ path = sess2.c.homedir + [name]
+ res = open_file(sess2, owner, path,
+ access=OPEN4_SHARE_ACCESS_READ|OPEN4_SHARE_ACCESS_WANT_NO_DELEG,
+ deny=OPEN4_SHARE_DENY_WRITE)
+ check(res)
+ fh = res.resarray[-1].object
+ stateid = res.resarray[-2].stateid
+
+ log.info("2nd client open OK - PASSED\n")
+
+ res = close_file(sess2, fh, stateid=stateid)
+ check(res)
+
+def testShareReservationDB03(t, env):
+ """ Test courtesy clients' deny mode conflicts with file access mode
+ Client 1 opens file with with OPEN4_SHARE_ACCESS_WRITE & OPEN4_SHARE_DENY_READ
+ Client 2 opens same file with with OPEN4_SHARE_ACCESS_WRITE & OPEN4_SHARE_DENY_READ
+ expected reply is NFS4_OK
+ sleep to force lease of client 1 and client 2 to expire
+ client 3 opens same file with OPEN4_SHARE_ACCESS_READ
+ expected reply is NFS4_OK
+
+ FLAGS: courteous all
+ CODE: COUR6
+ """
+
+ """ client1 creates file with OPEN4_SHARE_ACCESS_WRITE & OPEN4_SHARE_DENY_READ """
+ sess1 = env.c1.new_client_session(env.testname(t))
+ res = create_file(sess1, env.testname(t), want_deleg=False,
+ access=OPEN4_SHARE_ACCESS_WRITE, deny=OPEN4_SHARE_DENY_READ)
+ check(res)
+ log.info("client 1 creates file OK\n")
+
+ """ create 2nd client """
+ sess2 = env.c1.new_client_session(b"%s_2" % env.testname(t))
+
+ name = env.testname(t)
+ owner = b"owner_%s" % name
+ path = sess2.c.homedir + [name]
+
+ res = open_file(sess2, owner, path,
+ access=OPEN4_SHARE_ACCESS_WRITE|OPEN4_SHARE_ACCESS_WANT_NO_DELEG,
+ deny=OPEN4_SHARE_DENY_READ)
+ check(res)
+ log.info("client 2 open file OK\n")
+
+ """ force lease of client1 and client2 to expire """
+ log.info("force lease to expire...\n")
+ lease_time = _getleasetime(sess1)
+ env.sleep(lease_time + 10, "the lease period + 10 secs")
+
+ """ create 3nd client """
+ sess3 = env.c1.new_client_session(b"%s_3" % env.testname(t))
+
+ """ client3 open file with OPEN4_SHARE_ACCESS_READ """
+ name = env.testname(t)
+ owner = b"owner_%s" % name
+ path = sess3.c.homedir + [name]
+ res = open_file(sess3, owner, path,
+ access=OPEN4_SHARE_ACCESS_READ|OPEN4_SHARE_ACCESS_WANT_NO_DELEG)
+ check(res)
+ fh = res.resarray[-1].object
+ stateid = res.resarray[-2].stateid
+
+ log.info("3rd client open OK - PASSED\n")
+
+ res = close_file(sess3, fh, stateid=stateid)
+ check(res)
--
2.9.5
next prev parent reply other threads:[~2021-10-05 23:41 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-05 23:41 [PATCH 0/2] st_courtesy.py: fix bug in COUR2 and add more tests for Courteous Server Dai Ngo
2021-10-05 23:41 ` [PATCH 1/2] st_courtesy.py: Fix problem of missing RECLAIM_COMPLETE in COUR2 Dai Ngo
2021-10-05 23:41 ` Dai Ngo [this message]
2021-10-06 15:05 ` [PATCH 0/2] st_courtesy.py: fix bug in COUR2 and add more tests for Courteous Server J. Bruce Fields
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=20211005234123.41053-3-dai.ngo@oracle.com \
--to=dai.ngo@oracle.com \
--cc=bfields@fieldses.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).