All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH pynfs 1/2] st_flex: Fix comparison operator, compare int
@ 2021-05-21  5:46 Petr Vorel
  2021-05-21  5:46 ` [PATCH pynfs 2/2] 4.1 server: Compare with int variable instead of string Petr Vorel
  0 siblings, 1 reply; 3+ messages in thread
From: Petr Vorel @ 2021-05-21  5:46 UTC (permalink / raw)
  To: linux-nfs; +Cc: Petr Vorel, J . Bruce Fields, Tom Haynes, Yong Sun (Sero)

It fixes Python 3 warning:
    nfs4.1/server41tests/st_flex.py:618: SyntaxWarning: "is not" with a literal. Did you mean "!="?
      if nfsstat4[res.status] is not 'NFS4_OK':

0bfa03c correctly changed NFS4_OK to string, as nfsstat4 dictionary
values are strings, but comparator was not changed.

But instead of just changing operator to '!=' also use res.status
directly thus we can compare with NFS4_OK (int variable) instead of
"NFS4_OK" (string literal => typos not detected).

Fixes: 0bfa03c ("st_flex: Fixup check for error in layoutget_return()")

Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
 nfs4.1/server41tests/st_flex.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/nfs4.1/server41tests/st_flex.py b/nfs4.1/server41tests/st_flex.py
index 169db69..766b213 100644
--- a/nfs4.1/server41tests/st_flex.py
+++ b/nfs4.1/server41tests/st_flex.py
@@ -615,7 +615,7 @@ def layoutget_return(sess, fh, open_stateid, allowed_errors=NFS4_OK,
                         0, NFS4_MAXFILELEN, 4196, open_stateid, 0xffff)]
     res = sess.compound(ops)
     check(res, allowed_errors)
-    if nfsstat4[res.status] is not 'NFS4_OK':
+    if res.status != NFS4_OK:
         return [res] # We can't return the layout without a stateid!
     layout_stateid = res.resarray[-1].logr_stateid
 
-- 
2.31.1


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

* [PATCH pynfs 2/2] 4.1 server: Compare with int variable instead of string
  2021-05-21  5:46 [PATCH pynfs 1/2] st_flex: Fix comparison operator, compare int Petr Vorel
@ 2021-05-21  5:46 ` Petr Vorel
  2021-05-21 18:07   ` J. Bruce Fields
  0 siblings, 1 reply; 3+ messages in thread
From: Petr Vorel @ 2021-05-21  5:46 UTC (permalink / raw)
  To: linux-nfs; +Cc: Petr Vorel, J . Bruce Fields, Tom Haynes, Yong Sun (Sero)

Similarly to previous commit prefer using int variables
(e.g. NFS4_OK) than string literals (e.g. "NFS4_OK"),
which don't detect typos.

This requires to change status parameter of show_op()
from string to int.

Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
 nfs4.1/nfs4server.py | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/nfs4.1/nfs4server.py b/nfs4.1/nfs4server.py
index 6f7d10c..9422481 100755
--- a/nfs4.1/nfs4server.py
+++ b/nfs4.1/nfs4server.py
@@ -515,8 +515,8 @@ class SummaryOutput:
 
         summary_line = "  %s" % ', '.join(opnames)
 
-        if status != "NFS4_OK" and status != "NFS3_OK":
-            summary_line += " -> %s" % (status,)
+        if status != NFS4_OK and status != NFS3_OK:
+            summary_line += " -> %s" % nfsstat4[status]
 
         print_summary_line = True
         if summary_line != self._last or role != self._last_role:
@@ -850,7 +850,7 @@ class NFS4Server(rpc.Server):
         log_41.info("Replying.  Status %s (%d)" % (nfsstat4[status], status))
         client_addr = '%s:%s' % cred.connection._s.getpeername()[:2]
         self.summary.show_op('handle v4.1 %s' % client_addr,
-                             opnames, nfsstat4[status])
+                             opnames, status)
         return env
 
     def delete_session(self, session, sessionid):
-- 
2.31.1


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

* Re: [PATCH pynfs 2/2] 4.1 server: Compare with int variable instead of string
  2021-05-21  5:46 ` [PATCH pynfs 2/2] 4.1 server: Compare with int variable instead of string Petr Vorel
@ 2021-05-21 18:07   ` J. Bruce Fields
  0 siblings, 0 replies; 3+ messages in thread
From: J. Bruce Fields @ 2021-05-21 18:07 UTC (permalink / raw)
  To: Petr Vorel; +Cc: linux-nfs, Tom Haynes, Yong Sun (Sero)

Both applied, thanks.--b.

On Fri, May 21, 2021 at 07:46:33AM +0200, Petr Vorel wrote:
> Similarly to previous commit prefer using int variables
> (e.g. NFS4_OK) than string literals (e.g. "NFS4_OK"),
> which don't detect typos.
> 
> This requires to change status parameter of show_op()
> from string to int.
> 
> Signed-off-by: Petr Vorel <pvorel@suse.cz>
> ---
>  nfs4.1/nfs4server.py | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/nfs4.1/nfs4server.py b/nfs4.1/nfs4server.py
> index 6f7d10c..9422481 100755
> --- a/nfs4.1/nfs4server.py
> +++ b/nfs4.1/nfs4server.py
> @@ -515,8 +515,8 @@ class SummaryOutput:
>  
>          summary_line = "  %s" % ', '.join(opnames)
>  
> -        if status != "NFS4_OK" and status != "NFS3_OK":
> -            summary_line += " -> %s" % (status,)
> +        if status != NFS4_OK and status != NFS3_OK:
> +            summary_line += " -> %s" % nfsstat4[status]
>  
>          print_summary_line = True
>          if summary_line != self._last or role != self._last_role:
> @@ -850,7 +850,7 @@ class NFS4Server(rpc.Server):
>          log_41.info("Replying.  Status %s (%d)" % (nfsstat4[status], status))
>          client_addr = '%s:%s' % cred.connection._s.getpeername()[:2]
>          self.summary.show_op('handle v4.1 %s' % client_addr,
> -                             opnames, nfsstat4[status])
> +                             opnames, status)
>          return env
>  
>      def delete_session(self, session, sessionid):
> -- 
> 2.31.1
> 


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

end of thread, other threads:[~2021-05-21 18:07 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-21  5:46 [PATCH pynfs 1/2] st_flex: Fix comparison operator, compare int Petr Vorel
2021-05-21  5:46 ` [PATCH pynfs 2/2] 4.1 server: Compare with int variable instead of string Petr Vorel
2021-05-21 18:07   ` J. Bruce Fields

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.