From patchwork Thu Jun 5 13:55:44 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Weston Andros Adamson X-Patchwork-Id: 4305661 Return-Path: X-Original-To: patchwork-linux-nfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 88EEA9F26E for ; Thu, 5 Jun 2014 13:56:26 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8F9F3200D0 for ; Thu, 5 Jun 2014 13:56:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2E0662034F for ; Thu, 5 Jun 2014 13:56:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751894AbaFEN4I (ORCPT ); Thu, 5 Jun 2014 09:56:08 -0400 Received: from mail-ie0-f170.google.com ([209.85.223.170]:61313 "EHLO mail-ie0-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751677AbaFEN4D (ORCPT ); Thu, 5 Jun 2014 09:56:03 -0400 Received: by mail-ie0-f170.google.com with SMTP id to1so912820ieb.15 for ; Thu, 05 Jun 2014 06:56:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=28SzuRROuGoOH+8La6+PqU9MKBlrC1P7KIjiGZRFuJw=; b=gtS6PryvZxOgTPVZzGKsG9sIEtXdtqW4hy8FwGn9kOMvpwT/vUHz3Ik2bn7Umyxq/z X5BQAPLuC1uPGzeCB1knKcRFl77DOqoXOFxN9kBM9KQq3PITe5uXZzlLgvgV5Ad+/iJE fQo8B6hpUbCgrxjg+F5ST100iO41dM5X3IRV7MbN6YdjFNE3UeyeIB3L1b4z2/P5XbeY zDKGldpKLZ3MqkP3/7+R0o7txZtOapzlLSbfuujEtNziFt7eYD1Aelrz4t7enfDIPzi6 mEA+VvyBP9m0ArmmqSJbTV3o/+q07w07rXgyN2MCTNuft+upn9vsmmKrKEh+/wsBGOYJ +zYQ== X-Gm-Message-State: ALoCoQnhq8vIlaVHtxFvDGR86fsK8SSq0ZhlIP4pY+nDQ9lxQbs880X2fGfwGHy3at+zpAVL/HQM X-Received: by 10.50.253.195 with SMTP id ac3mr19997936igd.1.1401976563135; Thu, 05 Jun 2014 06:56:03 -0700 (PDT) Received: from gavrio-wifi.robotsandstuff.fake (c-98-209-19-144.hsd1.mi.comcast.net. [98.209.19.144]) by mx.google.com with ESMTPSA id c8sm30697482igx.8.2014.06.05.06.56.02 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 05 Jun 2014 06:56:02 -0700 (PDT) From: Weston Andros Adamson To: bfields@fieldses.org Cc: linux-nfs@vger.kernel.org, Weston Andros Adamson Subject: [PATCH pynfs v2 16/16] nfs3clnt: reconnect when sending on inactive pipe Date: Thu, 5 Jun 2014 09:55:44 -0400 Message-Id: <1401976544-36374-17-git-send-email-dros@primarydata.com> X-Mailer: git-send-email 1.8.5.2 (Apple Git-48) In-Reply-To: <1401976544-36374-1-git-send-email-dros@primarydata.com> References: <1401976544-36374-1-git-send-email-dros@primarydata.com> Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Weston Andros Adamson --- 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)