From patchwork Mon Mar 14 12:57:39 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever III X-Patchwork-Id: 633031 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p2ECvR39019764 for ; Mon, 14 Mar 2011 12:57:43 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752716Ab1CNM5m (ORCPT ); Mon, 14 Mar 2011 08:57:42 -0400 Received: from mail-iy0-f174.google.com ([209.85.210.174]:52145 "EHLO mail-iy0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752092Ab1CNM5m (ORCPT ); Mon, 14 Mar 2011 08:57:42 -0400 Received: by mail-iy0-f174.google.com with SMTP id 26so4900509iyb.19 for ; Mon, 14 Mar 2011 05:57:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:sender:from:subject:to:cc:date:message-id :in-reply-to:references:user-agent:mime-version:content-type :content-transfer-encoding; bh=ooQ4FFY8SiHvQDENzfeVJ8pk5HB5lSpt45DZkiTMjhg=; b=AXIA5klTrfA/MKYaqLST8ZepDl+HZMiPpUPZD9/obK/v73e0RprropulDPIJa2V2mn YHC+lsosBB0Cij8U7Sc7OC3+ps4Gv/Lhez0Qcvo8jxx4L0MIEFyxPnPImTrQC4rJn4kZ Qe9mNXXf6Fxu+P9RB1kH+zedBncGQNrxFIcsI= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=sender:from:subject:to:cc:date:message-id:in-reply-to:references :user-agent:mime-version:content-type:content-transfer-encoding; b=n6SB6awvqo/gdaT88Ug6n5LMzzdeFYMwpSvnGb2dmGly7hMK/0TLTafkP584lGl30P aJqTdfQk4j7YHI/9g6l0L2lOl1N+Op/roaZfyxHANJYXZIheHWYzQHAzlFthDtVKzmzk MwNzoqww2FriMYDcJ/S2SdPmFa+zs28HH1BK4= Received: by 10.231.194.87 with SMTP id dx23mr2717382ibb.133.1300107461843; Mon, 14 Mar 2011 05:57:41 -0700 (PDT) Received: from matisse.1015granger.net (adsl-99-26-161-222.dsl.sfldmi.sbcglobal.net [99.26.161.222]) by mx.google.com with ESMTPS id d21sm6666582ibg.15.2011.03.14.05.57.40 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 14 Mar 2011 05:57:40 -0700 (PDT) From: Chuck Lever Subject: [PATCH 08/12] NFS: Add functions to swap transports during migration recovery To: trond.myklebust@netapp.com Cc: linux-nfs@vger.kernel.org Date: Mon, 14 Mar 2011 08:57:39 -0400 Message-ID: <20110314125739.2413.28519.stgit@matisse.1015granger.net> In-Reply-To: <20110314125204.2413.8870.stgit@matisse.1015granger.net> References: <20110314125204.2413.8870.stgit@matisse.1015granger.net> User-Agent: StGIT/0.14.3 MIME-Version: 1.0 Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Mon, 14 Mar 2011 12:57:43 +0000 (UTC) diff --git a/fs/nfs/internal.h b/fs/nfs/internal.h index 58a9ad7..bf2a4e7 100644 --- a/fs/nfs/internal.h +++ b/fs/nfs/internal.h @@ -164,6 +164,8 @@ static inline void nfs_fs_proc_exit(void) /* nfs4namespace.c */ #ifdef CONFIG_NFS_V4 extern struct vfsmount *nfs_do_refmount(const struct vfsmount *mnt_parent, struct dentry *dentry); +extern int nfs4_replace_transport(struct nfs_server *server, + const struct nfs4_fs_locations *locations); #else static inline struct vfsmount *nfs_do_refmount(const struct vfsmount *mnt_parent, struct dentry *dentry) diff --git a/fs/nfs/nfs4namespace.c b/fs/nfs/nfs4namespace.c index 3c2a172..ea591ff 100644 --- a/fs/nfs/nfs4namespace.c +++ b/fs/nfs/nfs4namespace.c @@ -270,3 +270,165 @@ out: dprintk("%s: done\n", __func__); return mnt; } + +#undef NFSDBG_FACILITY +#define NFSDBG_FACILITY NFSDBG_CLIENT + +/* + * Returns zero on success, or a negative errno value. + */ +static int nfs4_update_server(struct nfs_server *server, const char *hostname, + struct sockaddr *sap, size_t salen) +{ + struct nfs_client *clp = server->nfs_client; + struct rpc_clnt *clnt = server->client; + struct xprt_create xargs = { + .ident = clp->cl_proto, + .net = &init_net, + .dstaddr = sap, + .addrlen = salen, + .servername = hostname, + }; + int error; + + dprintk("--> %s: move FSID %llx:%llx to \"%s\")\n", __func__, + (unsigned long long)server->fsid.major, + (unsigned long long)server->fsid.minor, + hostname); + + /* + * rpc_lock_client() deadlocks here. This is because the tasks + * that received NFS4ERR_MOVED are waiting for us to wake them + * when we are done recovering. But they have bumped active_tasks, + * so rpc_lock_client() can't make any progress. + */ +#if 0 + error = rpc_lock_client(clnt, clnt->cl_timeout->to_maxval); + if (error != 0) + goto out; +#endif + + error = rpc_switch_client_transport(clnt, &xargs, clnt->cl_timeout); + +out: +#if 0 + rpc_unlock_client(clnt); +#endif + dprintk("<-- %s() = %d\n", __func__, error); + return error; +} + +/* + * Try one location from the fs_locations array. + * + * Returns zero on success, or a negative errno value. + */ +static int nfs4_try_replacing_one_location(struct nfs_server *server, + char *page, char *page2, + const struct nfs4_fs_location *location) +{ + const size_t addr_bufsize = sizeof(struct sockaddr_storage); + struct sockaddr *sap; + unsigned int s; + size_t salen; + int error; + + dprintk("--> %s(%llx:%llx)\n", __func__, + (unsigned long long)server->fsid.major, + (unsigned long long)server->fsid.minor); + + error = -ENOMEM; + sap = kmalloc(addr_bufsize, GFP_KERNEL); + if (sap == NULL) + goto out; + + error = -ENOENT; + for (s = 0; s < location->nservers; s++) { + const struct nfs4_string *buf = &location->servers[s]; + char *hostname; + + if (buf->len <= 0 || buf->len > PAGE_SIZE) + continue; + + /* XXX: IPv6 not supported? */ + if (memchr(buf->data, IPV6_SCOPE_DELIMITER, buf->len) != NULL) + continue; + + salen = nfs_parse_server_name(buf->data, buf->len, + sap, addr_bufsize); + if (salen == 0) + continue; + rpc_set_port(sap, NFS_PORT); + + error = -ENOMEM; + hostname = kstrndup(buf->data, buf->len, GFP_KERNEL); + if (hostname == NULL) + break; + + error = nfs4_update_server(server, hostname, sap, salen); + kfree(hostname); + if (error == 0) + break; + } + + kfree(sap); +out: + dprintk("<-- %s() = %d\n", __func__, error); + return error; +} + +/** + * nfs4_replace_transport - set up transport to destination server + * + * @server: export being migrated + * @locations: fs_locations array + * + * Returns zero on success, or a negative errno value. + * + * The client tries all the entries in the "locations" array, in the + * order returned by the server, until one works or the end of the + * array is reached. + */ +int nfs4_replace_transport(struct nfs_server *server, + const struct nfs4_fs_locations *locations) +{ + char *page = NULL, *page2 = NULL; + int loc, error; + + dprintk("--> %s(%llx:%llx)\n", __func__, + (unsigned long long)server->fsid.major, + (unsigned long long)server->fsid.minor); + + error = -ENOENT; + if (locations == NULL || locations->nlocations <= 0) + goto out; + + error = -ENOMEM; + page = (char *) __get_free_page(GFP_USER); + if (!page) + goto out; + page2 = (char *) __get_free_page(GFP_USER); + if (!page2) + goto out; + + for (loc = 0; loc < locations->nlocations; loc++) { + const struct nfs4_fs_location *location = + &locations->locations[loc]; + + if (location == NULL || location->nservers <= 0 || + location->rootpath.ncomponents == 0) + continue; + + error = nfs4_try_replacing_one_location(server, page, + page2, location); + if (error == 0) + break; + } + +out: + free_page((unsigned long)page); + free_page((unsigned long)page2); + + dprintk("<-- %s() = %d\n", __func__, error); + return error; +}