linux-nfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Weston Andros Adamson <dros@primarydata.com>
To: bfields@fieldses.org
Cc: linux-nfs@vger.kernel.org, Weston Andros Adamson <dros@primarydata.com>
Subject: [PATCH pynfs v2 16/16] nfs3clnt: reconnect when sending on inactive pipe
Date: Thu,  5 Jun 2014 09:55:44 -0400	[thread overview]
Message-ID: <1401976544-36374-17-git-send-email-dros@primarydata.com> (raw)
In-Reply-To: <1401976544-36374-1-git-send-email-dros@primarydata.com>

Signed-off-by: Weston Andros Adamson <dros@primarydata.com>
---
 nfs4.1/nfs3client.py | 45 +++++++++++++++++++++++++--------------------
 1 file changed, 25 insertions(+), 20 deletions(-)

diff --git a/nfs4.1/nfs3client.py b/nfs4.1/nfs3client.py
index 79a6f0e..176765c 100644
--- a/nfs4.1/nfs3client.py
+++ b/nfs4.1/nfs3client.py
@@ -30,14 +30,19 @@ class PORTMAPClient(rpc.Client):
     def __init__(self, host='localhost', port=PMAP_PORT):
         rpc.Client.__init__(self, PMAP_PROG, PMAP_VERS)
         self.server_address = (host, port)
-        self.c1 = self.connect(self.server_address)
+        self._pipe = None
+
+    def get_pipe(self):
+        if not self._pipe or not self._pipe.is_active():
+           self._pipe = self.connect(self.server_address)
+        return self._pipe
 
     def proc_async(self, procnum, procarg, credinfo=None, pipe=None,
                    checks=True, packer=PORTMAPPacker):
         if credinfo is None:
             credinfo = self.default_cred
         if pipe is None:
-            pipe = self.c1
+            pipe = self.get_pipe()
         p = packer(check_enum=checks, check_array=checks)
         arg_packer = getattr(p, 'pack_%s' % procarg.__class__.__name__)
         arg_packer(procarg)
@@ -51,7 +56,7 @@ class PORTMAPClient(rpc.Client):
 
     def listen(self, xid, restypename, pipe=None, timeout=10.0):
         if pipe is None:
-            pipe = self.c1
+            pipe = self.get_pipe()
         header, data = pipe.listen(xid, timeout)
         if data:
             p = PORTMAPUnpacker(data)
@@ -69,14 +74,19 @@ class Mnt3Client(rpc.Client):
     def __init__(self, host='localhost', port=None):
         rpc.Client.__init__(self, MOUNT_PROGRAM, MOUNT_V3)
         self.server_address = (host, port)
-        self.c1 = self.connect(self.server_address)
+        self._pipe = None
+
+    def get_pipe(self):
+        if not self._pipe or not self._pipe.is_active():
+            self._pipe = self.connect(self.server_address)
+        return self._pipe
 
     def proc_async(self, procnum, procarg, credinfo=None, pipe=None,
                    checks=True, packer=MNT3Packer):
         if credinfo is None:
             credinfo = self.default_cred
         if pipe is None:
-            pipe = self.c1
+            pipe = self.get_pipe()
         p = packer(check_enum=checks, check_array=checks)
         arg_packer = getattr(p, 'pack_%s' % procarg.__class__.__name__)
         arg_packer(procarg)
@@ -90,7 +100,7 @@ class Mnt3Client(rpc.Client):
 
     def listen(self, xid, restypename, pipe=None, timeout=10.0):
         if pipe is None:
-            pipe = self.c1
+            pipe = self.get_pipe()
         header, data = pipe.listen(xid, timeout)
         if data:
             p = MNT3Unpacker(data)
@@ -110,15 +120,6 @@ class Mnt3Client(rpc.Client):
 class NFS3Client(rpc.Client):
     def __init__(self, host='localhost', port=None, ctrl_proc=16, summary=None):
         rpc.Client.__init__(self, 100003, 3)
-        #self.prog = 0x40000000
-        #self.versions = [1] # List of supported versions of prog
-
-        #self.minorversion = minorversion
-        #self.minor_versions = [minorversion]
-        #self.tag = "default tag"
-        #self.impl_id = nfs_impl_id4("citi.umich.edu", "pynfs X.X",
-        #                            nfs4lib.get_nfstime())
-
         self.portmap = PORTMAPClient(host=host)
         self.mntport = self.portmap.get_port(MOUNT_PROGRAM, MOUNT_V3)
         if not port:
@@ -128,17 +129,21 @@ class NFS3Client(rpc.Client):
 
         self.verifier = struct.pack('>d', time.time())
         self.server_address = (host, self.port)
-        self.c1 = self.connect(self.server_address)
-        #self.sessions = {} # XXX Really, this should be per server
         self.ctrl_proc = ctrl_proc
         self.summary = summary
+        self._pipe = None
         self.mntclnt = Mnt3Client(host=host, port=self.mntport)
 
+    def get_pipe(self):
+        if not self._pipe or not self._pipe.is_active():
+            self._pipe = self.connect(self.server_address)
+        return self._pipe
+
     def set_cred(self, credinfo):
         self.default_cred = credinfo
 
     def null_async(self, data=""):
-        return self.send_call(self.c1, 0, data)
+        return self.send_call(self.get_pipe(), 0, data)
 
     def null(self, *args, **kwargs):
         xid = self.null_async(*args, **kwargs)
@@ -149,7 +154,7 @@ class NFS3Client(rpc.Client):
         if credinfo is None:
             credinfo = self.default_cred
         if pipe is None:
-            pipe = self.c1
+            pipe = self.get_pipe()
         p = packer(check_enum=checks, check_array=checks)
         arg_packer = getattr(p, 'pack_%s' % procarg.__class__.__name__)
         arg_packer(procarg)
@@ -167,7 +172,7 @@ class NFS3Client(rpc.Client):
 
     def listen(self, xid, procarg=None, pipe=None, timeout=10.0):
         if pipe is None:
-            pipe = self.c1
+            pipe = self.get_pipe()
         header, data = pipe.listen(xid, timeout)
         if data:
             p = NFS3Unpacker(data)
-- 
1.8.5.2 (Apple Git-48)


  parent reply	other threads:[~2014-06-05 13:56 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-05 13:55 [PATCH pynfs v2 00/16] prep for flex file layout server Weston Andros Adamson
2014-06-05 13:55 ` [PATCH pynfs v2 01/16] dataserver: reclaim_complete after create_session Weston Andros Adamson
2014-06-05 13:55 ` [PATCH pynfs v2 02/16] dataserver: only catch connection error Weston Andros Adamson
2014-06-05 13:55 ` [PATCH pynfs v2 03/16] 4.1 server: avoid traceback in DS disconnect() Weston Andros Adamson
2014-06-05 13:55 ` [PATCH pynfs v2 04/16] move .x files to subdir 'xdrdef' Weston Andros Adamson
2014-06-05 13:55 ` [PATCH pynfs v2 05/16] 4.1 client: remove unused imports Weston Andros Adamson
2014-06-05 13:55 ` [PATCH pynfs v2 06/16] 4.1 server: add -v flag & silence random output Weston Andros Adamson
2014-06-05 13:55 ` [PATCH pynfs v2 07/16] 4.1 server: add -s option to print summary of ops Weston Andros Adamson
2014-06-05 13:55 ` [PATCH pynfs v2 08/16] dataserver: make generic interface to ops Weston Andros Adamson
2014-06-05 13:55 ` [PATCH pynfs v2 09/16] dataserver: don't import * from nfs4 specific mods Weston Andros Adamson
2014-06-05 13:55 ` [PATCH pynfs v2 10/16] 4.1 server: move nfs4_ops.py to nfs_ops.py Weston Andros Adamson
2014-06-05 13:55 ` [PATCH pynfs v2 11/16] add mntv3, portmapv2 and nfsv3 .x files Weston Andros Adamson
2014-06-05 13:55 ` [PATCH pynfs v2 12/16] dataserver: separate generic and 4.1 code Weston Andros Adamson
2014-06-05 13:55 ` [PATCH pynfs v2 13/16] 4.1 server: add support for NFSv3 data servers Weston Andros Adamson
2014-06-05 13:55 ` [PATCH pynfs v2 14/16] 4.1 server: get rid of old op_getdeviceinfo Weston Andros Adamson
2014-06-05 13:55 ` [PATCH pynfs v2 15/16] rpc: on socket error, close and mark pipe inactive Weston Andros Adamson
2014-06-05 13:55 ` Weston Andros Adamson [this message]
2014-06-05 14:19 ` [PATCH pynfs v2 00/16] prep for flex file layout server J. Bruce Fields
2014-06-05 14:22   ` Weston Andros Adamson
2014-06-05 14:24     ` J. Bruce Fields
2014-06-09 21:25 ` J. Bruce Fields
2014-06-10  1:41   ` Weston Andros Adamson

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=1401976544-36374-17-git-send-email-dros@primarydata.com \
    --to=dros@primarydata.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).