History

Merge branch 'nfs-for-2.6.40' of git://git.linux-nfs.org/projects/trondmy/nfs-2.6

* 'nfs-for-2.6.40' of git://git.linux-nfs.org/projects/trondmy/nfs-2.6: SUNRPC: Support for RPC over AF_LOCAL transports SUNRPC: Remove obsolete comment SUNRPC: Use AF_LOCAL for rpcbind upcalls SUNRPC: Clean up use of curly braces in switch cases NFS: Revert NFSROOT default mount options SUNRPC: Rename xs_encode_tcp_fragment_header() nfs,rcu: convert call_rcu(nfs_free_delegation_callback) to kfree_rcu() nfs41: Correct offset for LAYOUTCOMMIT NFS: nfs_update_inode: print current and new inode size in debug output NFSv4.1: Fix the handling of NFS4ERR_SEQ_MISORDERED errors NFSv4: Handle expired stateids when the lease is still valid SUNRPC: Deal with the lack of a SYN_SENT sk->sk_state_change callback...

Linus Torvalds committed 15 years ago

Commit f1d1c9f2 parents 2ff55e9 176e21e12 files · +542 −66Browse files

Unified · Split

12 files
  1. fs/nfs/delegation.c +1 −13
  2. fs/nfs/inode.c +6 −2
  3. fs/nfs/nfs4proc.c +7 −2
  4. fs/nfs/nfs4state.c +5 −1
  5. fs/nfs/nfsroot.c +1 −1
  6. fs/nfs/pnfs.c +1 −1
  7. include/linux/sunrpc/msg_prot.h +1 −0
  8. include/linux/sunrpc/xprt.h +2 −1
  9. net/sunrpc/clnt.c +16 −13
  10. net/sunrpc/rpcb_clnt.c +83 −14
  11. net/sunrpc/svc.c +2 −0
  12. net/sunrpc/xprtsock.c +417 −18
fs/nfs/delegation.c+1−13
@@ -21,25 +21,13 @@ · 20 unmodified lines
2121 #include "delegation.h"
2222 #include "internal.h"
2323
24−static void nfs_do_free_delegation(struct nfs_delegation *delegation)
25−{
26− kfree(delegation);
27−}
28−
29−static void nfs_free_delegation_callback(struct rcu_head *head)
30−{
31− struct nfs_delegation *delegation = container_of(head, struct nfs_delegation, rcu);
32−
33− nfs_do_free_delegation(delegation);
34−}
35−
3624 static void nfs_free_delegation(struct nfs_delegation *delegation)
3725 {
3826 if (delegation->cred) {
3927 put_rpccred(delegation->cred);
4028 delegation->cred = NULL;
4129 }
42− call_rcu(&delegation->rcu, nfs_free_delegation_callback);
30+ kfree_rcu(delegation, rcu);
4331 }
4432
4533 /**
fs/nfs/inode.c+6−2
@@ -1298,8 +1298,12 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr) · 1297 unmodified lines
12981298 i_size_write(inode, new_isize);
12991299 invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA;
13001300 }
1301− dprintk("NFS: isize change on server for file %s/%ld\n",
1302− inode->i_sb->s_id, inode->i_ino);
1301+ dprintk("NFS: isize change on server for file %s/%ld "
1302+ "(%Ld to %Ld)\n",
1303+ inode->i_sb->s_id,
1304+ inode->i_ino,
1305+ (long long)cur_isize,
1306+ (long long)new_isize);
13031307 }
13041308 } else
13051309 invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR
fs/nfs/nfs4proc.c+7−2
@@ -267,9 +267,11 @@ static int nfs4_handle_exception(struct nfs_server *server, int errorcode, struc · 266 unmodified lines
267267 break;
268268 nfs4_schedule_stateid_recovery(server, state);
269269 goto wait_on_recovery;
270+ case -NFS4ERR_EXPIRED:
271+ if (state != NULL)
272+ nfs4_schedule_stateid_recovery(server, state);
270273 case -NFS4ERR_STALE_STATEID:
271274 case -NFS4ERR_STALE_CLIENTID:
272− case -NFS4ERR_EXPIRED:
273275 nfs4_schedule_lease_recovery(clp);
274276 goto wait_on_recovery;
275277 #if defined(CONFIG_NFS_V4_1)
@@ -3670,9 +3672,11 @@ nfs4_async_handle_error(struct rpc_task *task, const struct nfs_server *server, · 3394 unmodified lines
36703672 break;
36713673 nfs4_schedule_stateid_recovery(server, state);
36723674 goto wait_on_recovery;
3675+ case -NFS4ERR_EXPIRED:
3676+ if (state != NULL)
3677+ nfs4_schedule_stateid_recovery(server, state);
36733678 case -NFS4ERR_STALE_STATEID:
36743679 case -NFS4ERR_STALE_CLIENTID:
3675− case -NFS4ERR_EXPIRED:
36763680 nfs4_schedule_lease_recovery(clp);
36773681 goto wait_on_recovery;
36783682 #if defined(CONFIG_NFS_V4_1)
@@ -4543,6 +4547,7 @@ int nfs4_lock_delegation_recall(struct nfs4_state *state, struct file_lock *fl) · 864 unmodified lines
45434547 case -ESTALE:
45444548 goto out;
45454549 case -NFS4ERR_EXPIRED:
4550+ nfs4_schedule_stateid_recovery(server, state);
45464551 case -NFS4ERR_STALE_CLIENTID:
45474552 case -NFS4ERR_STALE_STATEID:
45484553 nfs4_schedule_lease_recovery(server->nfs_client);
fs/nfs/nfs4state.c+5−1
@@ -1466,7 +1466,10 @@ static int nfs4_reclaim_lease(struct nfs_client *clp) · 1465 unmodified lines
14661466 #ifdef CONFIG_NFS_V4_1
14671467 void nfs4_schedule_session_recovery(struct nfs4_session *session)
14681468 {
1469− nfs4_schedule_lease_recovery(session->clp);
1469+ struct nfs_client *clp = session->clp;
1470+
1471+ set_bit(NFS4CLNT_SESSION_RESET, &clp->cl_state);
1472+ nfs4_schedule_lease_recovery(clp);
14701473 }
14711474 EXPORT_SYMBOL_GPL(nfs4_schedule_session_recovery);
14721475
@@ -1549,6 +1552,7 @@ static int nfs4_reset_session(struct nfs_client *clp) · 76 unmodified lines
15491552 status = nfs4_recovery_handle_error(clp, status);
15501553 goto out;
15511554 }
1555+ clear_bit(NFS4CLNT_SESSION_RESET, &clp->cl_state);
15521556 /* create_session negotiated new slot table */
15531557 clear_bit(NFS4CLNT_RECALL_SLOT, &clp->cl_state);
15541558
fs/nfs/nfsroot.c+1−1
@@ -87,7 +87,7 @@ · 86 unmodified lines
8787 #define NFS_ROOT "/tftpboot/%s"
8888
8989 /* Default NFSROOT mount options. */
90−#define NFS_DEF_OPTIONS "udp"
90+#define NFS_DEF_OPTIONS "vers=2,udp,rsize=4096,wsize=4096"
9191
9292 /* Parameters passed from the kernel command line */
9393 static char nfs_root_parms[256] __initdata = "";
fs/nfs/pnfs.c+1−1
@@ -1009,7 +1009,7 @@ void · 1008 unmodified lines
10091009 pnfs_set_layoutcommit(struct nfs_write_data *wdata)
10101010 {
10111011 struct nfs_inode *nfsi = NFS_I(wdata->inode);
1012− loff_t end_pos = wdata->args.offset + wdata->res.count;
1012+ loff_t end_pos = wdata->mds_offset + wdata->res.count;
10131013 bool mark_as_dirty = false;
10141014
10151015 spin_lock(&nfsi->vfs_inode.i_lock);
include/linux/sunrpc/msg_prot.h+1−0
@@ -145,6 +145,7 @@ typedef __be32 rpc_fraghdr; · 144 unmodified lines
145145 #define RPCBIND_NETID_TCP "tcp"
146146 #define RPCBIND_NETID_UDP6 "udp6"
147147 #define RPCBIND_NETID_TCP6 "tcp6"
148+#define RPCBIND_NETID_LOCAL "local"
148149
149150 /*
150151 * Note that RFC 1833 does not put any size restrictions on the
include/linux/sunrpc/xprt.h+2−1
@@ -141,7 +141,8 @@ enum xprt_transports { · 140 unmodified lines
141141 XPRT_TRANSPORT_UDP = IPPROTO_UDP,
142142 XPRT_TRANSPORT_TCP = IPPROTO_TCP,
143143 XPRT_TRANSPORT_BC_TCP = IPPROTO_TCP | XPRT_TRANSPORT_BC,
144− XPRT_TRANSPORT_RDMA = 256
144+ XPRT_TRANSPORT_RDMA = 256,
145+ XPRT_TRANSPORT_LOCAL = 257,
145146 };
146147
147148 struct rpc_xprt {
net/sunrpc/clnt.c+16−13
@@ -13,10 +13,6 @@ · 12 unmodified lines
1313 * and need to be refreshed, or when a packet was damaged in transit.
1414 * This may be have to be moved to the VFS layer.
1515 *
16− * NB: BSD uses a more intelligent approach to guessing when a request
17− * or reply has been lost by keeping the RTO estimate for each procedure.
18− * We currently make do with a constant timeout value.
19− *
2016 * Copyright (C) 1992,1993 Rick Sladkey <jrs@world.std.com>
2117 * Copyright (C) 1995,1996 Olaf Kirch <okir@monad.swb.de>
2218 */
@@ -32,7 +28,9 @@ · 9 unmodified lines
3228 #include <linux/slab.h>
3329 #include <linux/utsname.h>
3430 #include <linux/workqueue.h>
31+#include <linux/in.h>
3532 #include <linux/in6.h>
33+#include <linux/un.h>
3634
3735 #include <linux/sunrpc/clnt.h>
3836 #include <linux/sunrpc/rpc_pipe_fs.h>
@@ -298,22 +296,27 @@ struct rpc_clnt *rpc_create(struct rpc_create_args *args) · 259 unmodified lines
298296 * up a string representation of the passed-in address.
299297 */
300298 if (args->servername == NULL) {
299+ struct sockaddr_un *sun =
300+ (struct sockaddr_un *)args->address;
301+ struct sockaddr_in *sin =
302+ (struct sockaddr_in *)args->address;
303+ struct sockaddr_in6 *sin6 =
304+ (struct sockaddr_in6 *)args->address;
305+
301306 servername[0] = '\0';
302307 switch (args->address->sa_family) {
303− case AF_INET: {
304− struct sockaddr_in *sin =
305− (struct sockaddr_in *)args->address;
308+ case AF_LOCAL:
309+ snprintf(servername, sizeof(servername), "%s",
310+ sun->sun_path);
311+ break;
312+ case AF_INET:
306313 snprintf(servername, sizeof(servername), "%pI4",
307314 &sin->sin_addr.s_addr);
308315 break;
309− }
310− case AF_INET6: {
311− struct sockaddr_in6 *sin =
312− (struct sockaddr_in6 *)args->address;
316+ case AF_INET6:
313317 snprintf(servername, sizeof(servername), "%pI6",
314− &sin->sin6_addr);
318+ &sin6->sin6_addr);
315319 break;
316− }
317320 default:
318321 /* caller wants default server name, but
319322 * address family isn't recognized. */
net/sunrpc/rpcb_clnt.c+83−14
@@ -16,6 +16,7 @@ · 15 unmodified lines
1616
1717 #include <linux/types.h>
1818 #include <linux/socket.h>
19+#include <linux/un.h>
1920 #include <linux/in.h>
2021 #include <linux/in6.h>
2122 #include <linux/kernel.h>
@@ -32,6 +33,8 @@ · 10 unmodified lines
3233 # define RPCDBG_FACILITY RPCDBG_BIND
3334 #endif
3435
36+#define RPCBIND_SOCK_PATHNAME "/var/run/rpcbind.sock"
37+
3538 #define RPCBIND_PROGRAM (100000u)
3639 #define RPCBIND_PORT (111u)
3740
@@ -158,20 +161,69 @@ static void rpcb_map_release(void *data) · 120 unmodified lines
158161 kfree(map);
159162 }
160163
161−static const struct sockaddr_in rpcb_inaddr_loopback = {
162− .sin_family = AF_INET,
163− .sin_addr.s_addr = htonl(INADDR_LOOPBACK),
164− .sin_port = htons(RPCBIND_PORT),
165−};
164+/*
165+ * Returns zero on success, otherwise a negative errno value
166+ * is returned.
167+ */
168+static int rpcb_create_local_unix(void)
169+{
170+ static const struct sockaddr_un rpcb_localaddr_rpcbind = {
171+ .sun_family = AF_LOCAL,
172+ .sun_path = RPCBIND_SOCK_PATHNAME,
173+ };
174+ struct rpc_create_args args = {
175+ .net = &init_net,
176+ .protocol = XPRT_TRANSPORT_LOCAL,
177+ .address = (struct sockaddr *)&rpcb_localaddr_rpcbind,
178+ .addrsize = sizeof(rpcb_localaddr_rpcbind),
179+ .servername = "localhost",
180+ .program = &rpcb_program,
181+ .version = RPCBVERS_2,
182+ .authflavor = RPC_AUTH_NULL,
183+ };
184+ struct rpc_clnt *clnt, *clnt4;
185+ int result = 0;
186+
187+ /*
188+ * Because we requested an RPC PING at transport creation time,
189+ * this works only if the user space portmapper is rpcbind, and
190+ * it's listening on AF_LOCAL on the named socket.
191+ */
192+ clnt = rpc_create(&args);
193+ if (IS_ERR(clnt)) {
194+ dprintk("RPC: failed to create AF_LOCAL rpcbind "
195+ "client (errno %ld).\n", PTR_ERR(clnt));
196+ result = -PTR_ERR(clnt);
197+ goto out;
198+ }
199+
200+ clnt4 = rpc_bind_new_program(clnt, &rpcb_program, RPCBVERS_4);
201+ if (IS_ERR(clnt4)) {
202+ dprintk("RPC: failed to bind second program to "
203+ "rpcbind v4 client (errno %ld).\n",
204+ PTR_ERR(clnt4));
205+ clnt4 = NULL;
206+ }
207+
208+ /* Protected by rpcb_create_local_mutex */
209+ rpcb_local_clnt = clnt;
210+ rpcb_local_clnt4 = clnt4;
166211
167−static DEFINE_MUTEX(rpcb_create_local_mutex);
212+out:
213+ return result;
214+}
168215
169216 /*
170217 * Returns zero on success, otherwise a negative errno value
171218 * is returned.
172219 */
173−static int rpcb_create_local(void)
220+static int rpcb_create_local_net(void)
174221 {
222+ static const struct sockaddr_in rpcb_inaddr_loopback = {
223+ .sin_family = AF_INET,
224+ .sin_addr.s_addr = htonl(INADDR_LOOPBACK),
225+ .sin_port = htons(RPCBIND_PORT),
226+ };
175227 struct rpc_create_args args = {
176228 .net = &init_net,
177229 .protocol = XPRT_TRANSPORT_TCP,
@@ -186,13 +238,6 @@ static int rpcb_create_local(void) · 8 unmodified lines
186238 struct rpc_clnt *clnt, *clnt4;
187239 int result = 0;
188240
189− if (rpcb_local_clnt)
190− return result;
191−
192− mutex_lock(&rpcb_create_local_mutex);
193− if (rpcb_local_clnt)
194− goto out;
195−
196241 clnt = rpc_create(&args);
197242 if (IS_ERR(clnt)) {
198243 dprintk("RPC: failed to create local rpcbind "
@@ -214,9 +259,33 @@ static int rpcb_create_local(void) · 15 unmodified lines
214259 clnt4 = NULL;
215260 }
216261
262+ /* Protected by rpcb_create_local_mutex */
217263 rpcb_local_clnt = clnt;
218264 rpcb_local_clnt4 = clnt4;
219265
266+out:
267+ return result;
268+}
269+
270+/*
271+ * Returns zero on success, otherwise a negative errno value
272+ * is returned.
273+ */
274+static int rpcb_create_local(void)
275+{
276+ static DEFINE_MUTEX(rpcb_create_local_mutex);
277+ int result = 0;
278+
279+ if (rpcb_local_clnt)
280+ return result;
281+
282+ mutex_lock(&rpcb_create_local_mutex);
283+ if (rpcb_local_clnt)
284+ goto out;
285+
286+ if (rpcb_create_local_unix() != 0)
287+ result = rpcb_create_local_net();
288+
220289 out:
221290 mutex_unlock(&rpcb_create_local_mutex);
222291 return result;
net/sunrpc/svc.c+2−0
@@ -942,6 +942,8 @@ static void svc_unregister(const struct svc_serv *serv) · 941 unmodified lines
942942 if (progp->pg_vers[i]->vs_hidden)
943943 continue;
944944
945+ dprintk("svc: attempting to unregister %sv%u\n",
946+ progp->pg_name, i);
945947 __svc_unregister(progp->pg_prog, i, progp->pg_name);
946948 }
947949 }
net/sunrpc/xprtsock.c+417−18
@@ -19,6 +19,7 @@ · 18 unmodified lines
1919 */
2020
2121 #include <linux/types.h>
22+#include <linux/string.h>
2223 #include <linux/slab.h>
2324 #include <linux/module.h>
2425 #include <linux/capability.h>
@@ -28,6 +29,7 @@ · 3 unmodified lines
2829 #include <linux/in.h>
2930 #include <linux/net.h>
3031 #include <linux/mm.h>
32+#include <linux/un.h>
3133 #include <linux/udp.h>
3234 #include <linux/tcp.h>
3335 #include <linux/sunrpc/clnt.h>
@@ -45,6 +47,9 @@ · 11 unmodified lines
4547 #include <net/tcp.h>
4648
4749 #include "sunrpc.h"
50+
51+static void xs_close(struct rpc_xprt *xprt);
52+
4853 /*
4954 * xprtsock tunables
5055 */
@@ -261,6 +266,11 @@ static inline struct sockaddr *xs_addr(struct rpc_xprt *xprt) · 210 unmodified lines
261266 return (struct sockaddr *) &xprt->addr;
262267 }
263268
269+static inline struct sockaddr_un *xs_addr_un(struct rpc_xprt *xprt)
270+{
271+ return (struct sockaddr_un *) &xprt->addr;
272+}
273+
264274 static inline struct sockaddr_in *xs_addr_in(struct rpc_xprt *xprt)
265275 {
266276 return (struct sockaddr_in *) &xprt->addr;
@@ -276,23 +286,34 @@ static void xs_format_common_peer_addresses(struct rpc_xprt *xprt) · 9 unmodified lines
276286 struct sockaddr *sap = xs_addr(xprt);
277287 struct sockaddr_in6 *sin6;
278288 struct sockaddr_in *sin;
289+ struct sockaddr_un *sun;
279290 char buf[128];
280291
281− (void)rpc_ntop(sap, buf, sizeof(buf));
282− xprt->address_strings[RPC_DISPLAY_ADDR] = kstrdup(buf, GFP_KERNEL);
283−
284292 switch (sap->sa_family) {
293+ case AF_LOCAL:
294+ sun = xs_addr_un(xprt);
295+ strlcpy(buf, sun->sun_path, sizeof(buf));
296+ xprt->address_strings[RPC_DISPLAY_ADDR] =
297+ kstrdup(buf, GFP_KERNEL);
298+ break;
285299 case AF_INET:
300+ (void)rpc_ntop(sap, buf, sizeof(buf));
301+ xprt->address_strings[RPC_DISPLAY_ADDR] =
302+ kstrdup(buf, GFP_KERNEL);
286303 sin = xs_addr_in(xprt);
287304 snprintf(buf, sizeof(buf), "%08x", ntohl(sin->sin_addr.s_addr));
288305 break;
289306 case AF_INET6:
307+ (void)rpc_ntop(sap, buf, sizeof(buf));
308+ xprt->address_strings[RPC_DISPLAY_ADDR] =
309+ kstrdup(buf, GFP_KERNEL);
290310 sin6 = xs_addr_in6(xprt);
291311 snprintf(buf, sizeof(buf), "%pi6", &sin6->sin6_addr);
292312 break;
293313 default:
294314 BUG();
295315 }
316+
296317 xprt->address_strings[RPC_DISPLAY_HEX_ADDR] = kstrdup(buf, GFP_KERNEL);
297318 }
298319
@@ -495,6 +516,70 @@ static int xs_nospace(struct rpc_task *task) · 196 unmodified lines
495516 return ret;
496517 }
497518
519+/*
520+ * Construct a stream transport record marker in @buf.
521+ */
522+static inline void xs_encode_stream_record_marker(struct xdr_buf *buf)
523+{
524+ u32 reclen = buf->len - sizeof(rpc_fraghdr);
525+ rpc_fraghdr *base = buf->head[0].iov_base;
526+ *base = cpu_to_be32(RPC_LAST_STREAM_FRAGMENT | reclen);
527+}
528+
529+/**
530+ * xs_local_send_request - write an RPC request to an AF_LOCAL socket
531+ * @task: RPC task that manages the state of an RPC request
532+ *
533+ * Return values:
534+ * 0: The request has been sent
535+ * EAGAIN: The socket was blocked, please call again later to
536+ * complete the request
537+ * ENOTCONN: Caller needs to invoke connect logic then call again
538+ * other: Some other error occured, the request was not sent
539+ */
540+static int xs_local_send_request(struct rpc_task *task)
541+{
542+ struct rpc_rqst *req = task->tk_rqstp;
543+ struct rpc_xprt *xprt = req->rq_xprt;
544+ struct sock_xprt *transport =
545+ container_of(xprt, struct sock_xprt, xprt);
546+ struct xdr_buf *xdr = &req->rq_snd_buf;
547+ int status;
548+
549+ xs_encode_stream_record_marker(&req->rq_snd_buf);
550+
551+ xs_pktdump("packet data:",
552+ req->rq_svec->iov_base, req->rq_svec->iov_len);
553+
554+ status = xs_sendpages(transport->sock, NULL, 0,
555+ xdr, req->rq_bytes_sent);
556+ dprintk("RPC: %s(%u) = %d\n",
557+ __func__, xdr->len - req->rq_bytes_sent, status);
558+ if (likely(status >= 0)) {
559+ req->rq_bytes_sent += status;
560+ req->rq_xmit_bytes_sent += status;
561+ if (likely(req->rq_bytes_sent >= req->rq_slen)) {
562+ req->rq_bytes_sent = 0;
563+ return 0;
564+ }
565+ status = -EAGAIN;
566+ }
567+
568+ switch (status) {
569+ case -EAGAIN:
570+ status = xs_nospace(task);
571+ break;
572+ default:
573+ dprintk("RPC: sendmsg returned unrecognized error %d\n",
574+ -status);
575+ case -EPIPE:
576+ xs_close(xprt);
577+ status = -ENOTCONN;
578+ }
579+
580+ return status;
581+}
582+
498583 /**
499584 * xs_udp_send_request - write an RPC request to a UDP socket
500585 * @task: address of RPC task that manages the state of an RPC request
@@ -574,13 +659,6 @@ static void xs_tcp_shutdown(struct rpc_xprt *xprt) · 73 unmodified lines
574659 kernel_sock_shutdown(sock, SHUT_WR);
575660 }
576661
577−static inline void xs_encode_tcp_record_marker(struct xdr_buf *buf)
578−{
579− u32 reclen = buf->len - sizeof(rpc_fraghdr);
580− rpc_fraghdr *base = buf->head[0].iov_base;
581− *base = htonl(RPC_LAST_STREAM_FRAGMENT | reclen);
582−}
583−
584662 /**
585663 * xs_tcp_send_request - write an RPC request to a TCP socket
586664 * @task: address of RPC task that manages the state of an RPC request
@@ -603,7 +681,7 @@ static int xs_tcp_send_request(struct rpc_task *task) · 16 unmodified lines
603681 struct xdr_buf *xdr = &req->rq_snd_buf;
604682 int status;
605683
606− xs_encode_tcp_record_marker(&req->rq_snd_buf);
684+ xs_encode_stream_record_marker(&req->rq_snd_buf);
607685
608686 xs_pktdump("packet data:",
609687 req->rq_svec->iov_base,
@@ -785,6 +863,88 @@ static inline struct rpc_xprt *xprt_from_sock(struct sock *sk) · 175 unmodified lines
785863 return (struct rpc_xprt *) sk->sk_user_data;
786864 }
787865
866+static int xs_local_copy_to_xdr(struct xdr_buf *xdr, struct sk_buff *skb)
867+{
868+ struct xdr_skb_reader desc = {
869+ .skb = skb,
870+ .offset = sizeof(rpc_fraghdr),
871+ .count = skb->len - sizeof(rpc_fraghdr),
872+ };
873+
874+ if (xdr_partial_copy_from_skb(xdr, 0, &desc, xdr_skb_read_bits) < 0)
875+ return -1;
876+ if (desc.count)
877+ return -1;
878+ return 0;
879+}
880+
881+/**
882+ * xs_local_data_ready - "data ready" callback for AF_LOCAL sockets
883+ * @sk: socket with data to read
884+ * @len: how much data to read
885+ *
886+ * Currently this assumes we can read the whole reply in a single gulp.
887+ */
888+static void xs_local_data_ready(struct sock *sk, int len)
889+{
890+ struct rpc_task *task;
891+ struct rpc_xprt *xprt;
892+ struct rpc_rqst *rovr;
893+ struct sk_buff *skb;
894+ int err, repsize, copied;
895+ u32 _xid;
896+ __be32 *xp;
897+
898+ read_lock_bh(&sk->sk_callback_lock);
899+ dprintk("RPC: %s...\n", __func__);
900+ xprt = xprt_from_sock(sk);
901+ if (xprt == NULL)
902+ goto out;
903+
904+ skb = skb_recv_datagram(sk, 0, 1, &err);
905+ if (skb == NULL)
906+ goto out;
907+
908+ if (xprt->shutdown)
909+ goto dropit;
910+
911+ repsize = skb->len - sizeof(rpc_fraghdr);
912+ if (repsize < 4) {
913+ dprintk("RPC: impossible RPC reply size %d\n", repsize);
914+ goto dropit;
915+ }
916+
917+ /* Copy the XID from the skb... */
918+ xp = skb_header_pointer(skb, sizeof(rpc_fraghdr), sizeof(_xid), &_xid);
919+ if (xp == NULL)
920+ goto dropit;
921+
922+ /* Look up and lock the request corresponding to the given XID */
923+ spin_lock(&xprt->transport_lock);
924+ rovr = xprt_lookup_rqst(xprt, *xp);
925+ if (!rovr)
926+ goto out_unlock;
927+ task = rovr->rq_task;
928+
929+ copied = rovr->rq_private_buf.buflen;
930+ if (copied > repsize)
931+ copied = repsize;
932+
933+ if (xs_local_copy_to_xdr(&rovr->rq_private_buf, skb)) {
934+ dprintk("RPC: sk_buff copy failed\n");
935+ goto out_unlock;
936+ }
937+
938+ xprt_complete_rqst(task, copied);
939+
940+ out_unlock:
941+ spin_unlock(&xprt->transport_lock);
942+ dropit:
943+ skb_free_datagram(sk, skb);
944+ out:
945+ read_unlock_bh(&sk->sk_callback_lock);
946+}
947+
788948 /**
789949 * xs_udp_data_ready - "data ready" callback for UDP sockets
790950 * @sk: socket with data to read
@@ -1344,7 +1504,6 @@ static void xs_tcp_state_change(struct sock *sk) · 553 unmodified lines
13441504 case TCP_CLOSE_WAIT:
13451505 /* The server initiated a shutdown of the socket */
13461506 xprt_force_disconnect(xprt);
1347− case TCP_SYN_SENT:
13481507 xprt->connect_cookie++;
13491508 case TCP_CLOSING:
13501509 /*
@@ -1571,11 +1730,31 @@ static int xs_bind(struct sock_xprt *transport, struct socket *sock) · 220 unmodified lines
15711730 return err;
15721731 }
15731732
1733+/*
1734+ * We don't support autobind on AF_LOCAL sockets
1735+ */
1736+static void xs_local_rpcbind(struct rpc_task *task)
1737+{
1738+ xprt_set_bound(task->tk_xprt);
1739+}
1740+
1741+static void xs_local_set_port(struct rpc_xprt *xprt, unsigned short port)
1742+{
1743+}
15741744
15751745 #ifdef CONFIG_DEBUG_LOCK_ALLOC
15761746 static struct lock_class_key xs_key[2];
15771747 static struct lock_class_key xs_slock_key[2];
15781748
1749+static inline void xs_reclassify_socketu(struct socket *sock)
1750+{
1751+ struct sock *sk = sock->sk;
1752+
1753+ BUG_ON(sock_owned_by_user(sk));
1754+ sock_lock_init_class_and_name(sk, "slock-AF_LOCAL-RPC",
1755+ &xs_slock_key[1], "sk_lock-AF_LOCAL-RPC", &xs_key[1]);
1756+}
1757+
15791758 static inline void xs_reclassify_socket4(struct socket *sock)
15801759 {
15811760 struct sock *sk = sock->sk;
@@ -1597,6 +1776,9 @@ static inline void xs_reclassify_socket6(struct socket *sock) · 15 unmodified lines
15971776 static inline void xs_reclassify_socket(int family, struct socket *sock)
15981777 {
15991778 switch (family) {
1779+ case AF_LOCAL:
1780+ xs_reclassify_socketu(sock);
1781+ break;
16001782 case AF_INET:
16011783 xs_reclassify_socket4(sock);
16021784 break;
@@ -1606,6 +1788,10 @@ static inline void xs_reclassify_socket(int family, struct socket *sock) · 3 unmodified lines
16061788 }
16071789 }
16081790 #else
1791+static inline void xs_reclassify_socketu(struct socket *sock)
1792+{
1793+}
1794+
16091795 static inline void xs_reclassify_socket4(struct socket *sock)
16101796 {
16111797 }
@@ -1644,6 +1830,94 @@ out: · 32 unmodified lines
16441830 return ERR_PTR(err);
16451831 }
16461832
1833+static int xs_local_finish_connecting(struct rpc_xprt *xprt,
1834+ struct socket *sock)
1835+{
1836+ struct sock_xprt *transport = container_of(xprt, struct sock_xprt,
1837+ xprt);
1838+
1839+ if (!transport->inet) {
1840+ struct sock *sk = sock->sk;
1841+
1842+ write_lock_bh(&sk->sk_callback_lock);
1843+
1844+ xs_save_old_callbacks(transport, sk);
1845+
1846+ sk->sk_user_data = xprt;
1847+ sk->sk_data_ready = xs_local_data_ready;
1848+ sk->sk_write_space = xs_udp_write_space;
1849+ sk->sk_error_report = xs_error_report;
1850+ sk->sk_allocation = GFP_ATOMIC;
1851+
1852+ xprt_clear_connected(xprt);
1853+
1854+ /* Reset to new socket */
1855+ transport->sock = sock;
1856+ transport->inet = sk;
1857+
1858+ write_unlock_bh(&sk->sk_callback_lock);
1859+ }
1860+
1861+ /* Tell the socket layer to start connecting... */
1862+ xprt->stat.connect_count++;
1863+ xprt->stat.connect_start = jiffies;
1864+ return kernel_connect(sock, xs_addr(xprt), xprt->addrlen, 0);
1865+}
1866+
1867+/**
1868+ * xs_local_setup_socket - create AF_LOCAL socket, connect to a local endpoint
1869+ * @xprt: RPC transport to connect
1870+ * @transport: socket transport to connect
1871+ * @create_sock: function to create a socket of the correct type
1872+ *
1873+ * Invoked by a work queue tasklet.
1874+ */
1875+static void xs_local_setup_socket(struct work_struct *work)
1876+{
1877+ struct sock_xprt *transport =
1878+ container_of(work, struct sock_xprt, connect_worker.work);
1879+ struct rpc_xprt *xprt = &transport->xprt;
1880+ struct socket *sock;
1881+ int status = -EIO;
1882+
1883+ if (xprt->shutdown)
1884+ goto out;
1885+
1886+ clear_bit(XPRT_CONNECTION_ABORT, &xprt->state);
1887+ status = __sock_create(xprt->xprt_net, AF_LOCAL,
1888+ SOCK_STREAM, 0, &sock, 1);
1889+ if (status < 0) {
1890+ dprintk("RPC: can't create AF_LOCAL "
1891+ "transport socket (%d).\n", -status);
1892+ goto out;
1893+ }
1894+ xs_reclassify_socketu(sock);
1895+
1896+ dprintk("RPC: worker connecting xprt %p via AF_LOCAL to %s\n",
1897+ xprt, xprt->address_strings[RPC_DISPLAY_ADDR]);
1898+
1899+ status = xs_local_finish_connecting(xprt, sock);
1900+ switch (status) {
1901+ case 0:
1902+ dprintk("RPC: xprt %p connected to %s\n",
1903+ xprt, xprt->address_strings[RPC_DISPLAY_ADDR]);
1904+ xprt_set_connected(xprt);
1905+ break;
1906+ case -ENOENT:
1907+ dprintk("RPC: xprt %p: socket %s does not exist\n",
1908+ xprt, xprt->address_strings[RPC_DISPLAY_ADDR]);
1909+ break;
1910+ default:
1911+ printk(KERN_ERR "%s: unhandled error (%d) connecting to %s\n",
1912+ __func__, -status,
1913+ xprt->address_strings[RPC_DISPLAY_ADDR]);
1914+ }
1915+
1916+out:
1917+ xprt_clear_connecting(xprt);
1918+ xprt_wake_pending_tasks(xprt, status);
1919+}
1920+
16471921 static void xs_udp_finish_connecting(struct rpc_xprt *xprt, struct socket *sock)
16481922 {
16491923 struct sock_xprt *transport = container_of(xprt, struct sock_xprt, xprt);
@@ -1758,6 +2032,7 @@ static void xs_tcp_reuse_connection(struct sock_xprt *transport) · 108 unmodified lines
17582032 static int xs_tcp_finish_connecting(struct rpc_xprt *xprt, struct socket *sock)
17592033 {
17602034 struct sock_xprt *transport = container_of(xprt, struct sock_xprt, xprt);
2035+ int ret = -ENOTCONN;
17612036
17622037 if (!transport->inet) {
17632038 struct sock *sk = sock->sk;
@@ -1789,12 +2064,22 @@ static int xs_tcp_finish_connecting(struct rpc_xprt *xprt, struct socket *sock) · 25 unmodified lines
17892064 }
17902065
17912066 if (!xprt_bound(xprt))
1792− return -ENOTCONN;
2067+ goto out;
17932068
17942069 /* Tell the socket layer to start connecting... */
17952070 xprt->stat.connect_count++;
17962071 xprt->stat.connect_start = jiffies;
1797− return kernel_connect(sock, xs_addr(xprt), xprt->addrlen, O_NONBLOCK);
2072+ ret = kernel_connect(sock, xs_addr(xprt), xprt->addrlen, O_NONBLOCK);
2073+ switch (ret) {
2074+ case 0:
2075+ case -EINPROGRESS:
2076+ /* SYN_SENT! */
2077+ xprt->connect_cookie++;
2078+ if (xprt->reestablish_timeout < XS_TCP_INIT_REEST_TO)
2079+ xprt->reestablish_timeout = XS_TCP_INIT_REEST_TO;
2080+ }
2081+out:
2082+ return ret;
17982083 }
17992084
18002085 /**
@@ -1916,6 +2201,32 @@ static void xs_connect(struct rpc_task *task) · 115 unmodified lines
19162201 }
19172202 }
19182203
2204+/**
2205+ * xs_local_print_stats - display AF_LOCAL socket-specifc stats
2206+ * @xprt: rpc_xprt struct containing statistics
2207+ * @seq: output file
2208+ *
2209+ */
2210+static void xs_local_print_stats(struct rpc_xprt *xprt, struct seq_file *seq)
2211+{
2212+ long idle_time = 0;
2213+
2214+ if (xprt_connected(xprt))
2215+ idle_time = (long)(jiffies - xprt->last_used) / HZ;
2216+
2217+ seq_printf(seq, "\txprt:\tlocal %lu %lu %lu %ld %lu %lu %lu "
2218+ "%llu %llu\n",
2219+ xprt->stat.bind_count,
2220+ xprt->stat.connect_count,
2221+ xprt->stat.connect_time,
2222+ idle_time,
2223+ xprt->stat.sends,
2224+ xprt->stat.recvs,
2225+ xprt->stat.bad_xids,
2226+ xprt->stat.req_u,
2227+ xprt->stat.bklog_u);
2228+}
2229+
19192230 /**
19202231 * xs_udp_print_stats - display UDP socket-specifc stats
19212232 * @xprt: rpc_xprt struct containing statistics
@@ -2014,10 +2325,7 @@ static int bc_sendto(struct rpc_rqst *req) · 92 unmodified lines
20142325 unsigned long headoff;
20152326 unsigned long tailoff;
20162327
2017− /*
2018− * Set up the rpc header and record marker stuff
2019− */
2020− xs_encode_tcp_record_marker(xbufp);
2328+ xs_encode_stream_record_marker(xbufp);
20212329
20222330 tailoff = (unsigned long)xbufp->tail[0].iov_base & ~PAGE_MASK;
20232331 headoff = (unsigned long)xbufp->head[0].iov_base & ~PAGE_MASK;
@@ -2089,6 +2397,21 @@ static void bc_destroy(struct rpc_xprt *xprt) · 65 unmodified lines
20892397 {
20902398 }
20912399
2400+static struct rpc_xprt_ops xs_local_ops = {
2401+ .reserve_xprt = xprt_reserve_xprt,
2402+ .release_xprt = xs_tcp_release_xprt,
2403+ .rpcbind = xs_local_rpcbind,
2404+ .set_port = xs_local_set_port,
2405+ .connect = xs_connect,
2406+ .buf_alloc = rpc_malloc,
2407+ .buf_free = rpc_free,
2408+ .send_request = xs_local_send_request,
2409+ .set_retrans_timeout = xprt_set_retrans_timeout_def,
2410+ .close = xs_close,
2411+ .destroy = xs_destroy,
2412+ .print_stats = xs_local_print_stats,
2413+};
2414+
20922415 static struct rpc_xprt_ops xs_udp_ops = {
20932416 .set_buffer_size = xs_udp_set_buffer_size,
20942417 .reserve_xprt = xprt_reserve_xprt_cong,
@@ -2150,6 +2473,8 @@ static int xs_init_anyaddr(const int family, struct sockaddr *sap) · 55 unmodified lines
21502473 };
21512474
21522475 switch (family) {
2476+ case AF_LOCAL:
2477+ break;
21532478 case AF_INET:
21542479 memcpy(sap, &sin, sizeof(sin));
21552480 break;
@@ -2197,6 +2522,70 @@ static struct rpc_xprt *xs_setup_xprt(struct xprt_create *args, · 41 unmodified lines
21972522 return xprt;
21982523 }
21992524
2525+static const struct rpc_timeout xs_local_default_timeout = {
2526+ .to_initval = 10 * HZ,
2527+ .to_maxval = 10 * HZ,
2528+ .to_retries = 2,
2529+};
2530+
2531+/**
2532+ * xs_setup_local - Set up transport to use an AF_LOCAL socket
2533+ * @args: rpc transport creation arguments
2534+ *
2535+ * AF_LOCAL is a "tpi_cots_ord" transport, just like TCP
2536+ */
2537+static struct rpc_xprt *xs_setup_local(struct xprt_create *args)
2538+{
2539+ struct sockaddr_un *sun = (struct sockaddr_un *)args->dstaddr;
2540+ struct sock_xprt *transport;
2541+ struct rpc_xprt *xprt;
2542+ struct rpc_xprt *ret;
2543+
2544+ xprt = xs_setup_xprt(args, xprt_tcp_slot_table_entries);
2545+ if (IS_ERR(xprt))
2546+ return xprt;
2547+ transport = container_of(xprt, struct sock_xprt, xprt);
2548+
2549+ xprt->prot = 0;
2550+ xprt->tsh_size = sizeof(rpc_fraghdr) / sizeof(u32);
2551+ xprt->max_payload = RPC_MAX_FRAGMENT_SIZE;
2552+
2553+ xprt->bind_timeout = XS_BIND_TO;
2554+ xprt->reestablish_timeout = XS_TCP_INIT_REEST_TO;
2555+ xprt->idle_timeout = XS_IDLE_DISC_TO;
2556+
2557+ xprt->ops = &xs_local_ops;
2558+ xprt->timeout = &xs_local_default_timeout;
2559+
2560+ switch (sun->sun_family) {
2561+ case AF_LOCAL:
2562+ if (sun->sun_path[0] != '/') {
2563+ dprintk("RPC: bad AF_LOCAL address: %s\n",
2564+ sun->sun_path);
2565+ ret = ERR_PTR(-EINVAL);
2566+ goto out_err;
2567+ }
2568+ xprt_set_bound(xprt);
2569+ INIT_DELAYED_WORK(&transport->connect_worker,
2570+ xs_local_setup_socket);
2571+ xs_format_peer_addresses(xprt, "local", RPCBIND_NETID_LOCAL);
2572+ break;
2573+ default:
2574+ ret = ERR_PTR(-EAFNOSUPPORT);
2575+ goto out_err;
2576+ }
2577+
2578+ dprintk("RPC: set up xprt to %s via AF_LOCAL\n",
2579+ xprt->address_strings[RPC_DISPLAY_ADDR]);
2580+
2581+ if (try_module_get(THIS_MODULE))
2582+ return xprt;
2583+ ret = ERR_PTR(-EINVAL);
2584+out_err:
2585+ xprt_free(xprt);
2586+ return ret;
2587+}
2588+
22002589 static const struct rpc_timeout xs_udp_default_timeout = {
22012590 .to_initval = 5 * HZ,
22022591 .to_maxval = 30 * HZ,
@@ -2438,6 +2827,14 @@ out_err: · 235 unmodified lines
24382827 return ret;
24392828 }
24402829
2830+static struct xprt_class xs_local_transport = {
2831+ .list = LIST_HEAD_INIT(xs_local_transport.list),
2832+ .name = "named UNIX socket",
2833+ .owner = THIS_MODULE,
2834+ .ident = XPRT_TRANSPORT_LOCAL,
2835+ .setup = xs_setup_local,
2836+};
2837+
24412838 static struct xprt_class xs_udp_transport = {
24422839 .list = LIST_HEAD_INIT(xs_udp_transport.list),
24432840 .name = "udp",
@@ -2473,6 +2870,7 @@ int init_socket_xprt(void) · 29 unmodified lines
24732870 sunrpc_table_header = register_sysctl_table(sunrpc_table);
24742871 #endif
24752872
2873+ xprt_register_transport(&xs_local_transport);
24762874 xprt_register_transport(&xs_udp_transport);
24772875 xprt_register_transport(&xs_tcp_transport);
24782876 xprt_register_transport(&xs_bc_tcp_transport);
@@ -2493,6 +2891,7 @@ void cleanup_socket_xprt(void) · 14 unmodified lines
24932891 }
24942892 #endif
24952893
2894+ xprt_unregister_transport(&xs_local_transport);
24962895 xprt_unregister_transport(&xs_udp_transport);
24972896 xprt_unregister_transport(&xs_tcp_transport);
24982897 xprt_unregister_transport(&xs_bc_tcp_transport);