* Copyright (c) 2000-2015 Apple Inc. All rights reserved.
*
* @APPLE_OSREFERENCE_LICENSE_HEADER_START@
- *
+ *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* unlawful or unlicensed copies of an Apple operating system, or to
* circumvent, violate, or enable the circumvention or violation of, any
* terms of an Apple operating system software license agreement.
- *
+ *
* Please obtain a copy of the License at
* http://www.opensource.apple.com/apsl/ and read it before using this file.
- *
+ *
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
* Please see the License for the specific language governing rights and
* limitations under the License.
- *
+ *
* @APPLE_OSREFERENCE_LICENSE_HEADER_END@
*/
/* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
#define NFS_SOCK_DBG(...) NFS_DBG(NFS_FAC_SOCK, 7, ## __VA_ARGS__)
/* XXX */
-boolean_t current_thread_aborted(void);
-kern_return_t thread_terminate(thread_t);
+boolean_t current_thread_aborted(void);
+kern_return_t thread_terminate(thread_t);
#if NFSSERVER
int nfsrv_sock_max_rec_queue_length = 128; /* max # RPC records queued on (UDP) socket */
-int nfsrv_getstream(struct nfsrv_sock *,int);
+int nfsrv_getstream(struct nfsrv_sock *, int);
int nfsrv_getreq(struct nfsrv_descript *);
extern int nfsv3_procid[NFS_NPROCS];
#endif /* NFSSERVER */
int
nfs_sockaddr_cmp(struct sockaddr *sa1, struct sockaddr *sa2)
{
- if (!sa1)
- return (-1);
- if (!sa2)
- return (1);
- if (sa1->sa_family != sa2->sa_family)
- return ((sa1->sa_family < sa2->sa_family) ? -1 : 1);
- if (sa1->sa_len != sa2->sa_len)
- return ((sa1->sa_len < sa2->sa_len) ? -1 : 1);
- if (sa1->sa_family == AF_INET)
- return (bcmp(&((struct sockaddr_in*)sa1)->sin_addr,
- &((struct sockaddr_in*)sa2)->sin_addr, sizeof(((struct sockaddr_in*)sa1)->sin_addr)));
- if (sa1->sa_family == AF_INET6)
- return (bcmp(&((struct sockaddr_in6*)sa1)->sin6_addr,
- &((struct sockaddr_in6*)sa2)->sin6_addr, sizeof(((struct sockaddr_in6*)sa1)->sin6_addr)));
- return (-1);
+ if (!sa1) {
+ return -1;
+ }
+ if (!sa2) {
+ return 1;
+ }
+ if (sa1->sa_family != sa2->sa_family) {
+ return (sa1->sa_family < sa2->sa_family) ? -1 : 1;
+ }
+ if (sa1->sa_len != sa2->sa_len) {
+ return (sa1->sa_len < sa2->sa_len) ? -1 : 1;
+ }
+ if (sa1->sa_family == AF_INET) {
+ return bcmp(&((struct sockaddr_in*)sa1)->sin_addr,
+ &((struct sockaddr_in*)sa2)->sin_addr, sizeof(((struct sockaddr_in*)sa1)->sin_addr));
+ }
+ if (sa1->sa_family == AF_INET6) {
+ return bcmp(&((struct sockaddr_in6*)sa1)->sin6_addr,
+ &((struct sockaddr_in6*)sa2)->sin6_addr, sizeof(((struct sockaddr_in6*)sa1)->sin6_addr));
+ }
+ return -1;
}
#if NFSCLIENT
-int nfs_connect_search_new_socket(struct nfsmount *, struct nfs_socket_search *, struct timeval *);
-int nfs_connect_search_socket_connect(struct nfsmount *, struct nfs_socket *, int);
-int nfs_connect_search_ping(struct nfsmount *, struct nfs_socket *, struct timeval *);
-void nfs_connect_search_socket_found(struct nfsmount *, struct nfs_socket_search *, struct nfs_socket *);
-void nfs_connect_search_socket_reap(struct nfsmount *, struct nfs_socket_search *, struct timeval *);
-int nfs_connect_search_check(struct nfsmount *, struct nfs_socket_search *, struct timeval *);
-int nfs_reconnect(struct nfsmount *);
-int nfs_connect_setup(struct nfsmount *);
-void nfs_mount_sock_thread(void *, wait_result_t);
-void nfs_udp_rcv(socket_t, void*, int);
-void nfs_tcp_rcv(socket_t, void*, int);
-void nfs_sock_poke(struct nfsmount *);
-void nfs_request_match_reply(struct nfsmount *, mbuf_t);
-void nfs_reqdequeue(struct nfsreq *);
-void nfs_reqbusy(struct nfsreq *);
+int nfs_connect_search_new_socket(struct nfsmount *, struct nfs_socket_search *, struct timeval *);
+int nfs_connect_search_socket_connect(struct nfsmount *, struct nfs_socket *, int);
+int nfs_connect_search_ping(struct nfsmount *, struct nfs_socket *, struct timeval *);
+void nfs_connect_search_socket_found(struct nfsmount *, struct nfs_socket_search *, struct nfs_socket *);
+void nfs_connect_search_socket_reap(struct nfsmount *, struct nfs_socket_search *, struct timeval *);
+int nfs_connect_search_check(struct nfsmount *, struct nfs_socket_search *, struct timeval *);
+int nfs_reconnect(struct nfsmount *);
+int nfs_connect_setup(struct nfsmount *);
+void nfs_mount_sock_thread(void *, wait_result_t);
+void nfs_udp_rcv(socket_t, void*, int);
+void nfs_tcp_rcv(socket_t, void*, int);
+void nfs_sock_poke(struct nfsmount *);
+void nfs_request_match_reply(struct nfsmount *, mbuf_t);
+void nfs_reqdequeue(struct nfsreq *);
+void nfs_reqbusy(struct nfsreq *);
struct nfsreq *nfs_reqnext(struct nfsreq *);
-int nfs_wait_reply(struct nfsreq *);
-void nfs_softterm(struct nfsreq *);
-int nfs_can_squish(struct nfsmount *);
-int nfs_is_squishy(struct nfsmount *);
-int nfs_is_dead(int, struct nfsmount *);
+int nfs_wait_reply(struct nfsreq *);
+void nfs_softterm(struct nfsreq *);
+int nfs_can_squish(struct nfsmount *);
+int nfs_is_squishy(struct nfsmount *);
+int nfs_is_dead(int, struct nfsmount *);
/*
* Estimate rto for an nfs rpc sent via. an unreliable datagram.
* read, write - A+4D
* other - nm_timeo
*/
-#define NFS_RTO(n, t) \
+#define NFS_RTO(n, t) \
((t) == 0 ? (n)->nm_timeo : \
((t) < 3 ? \
(((((n)->nm_srtt[t-1] + 3) >> 2) + (n)->nm_sdrtt[t-1] + 1) >> 1) : \
((((n)->nm_srtt[t-1] + 7) >> 3) + (n)->nm_sdrtt[t-1] + 1)))
-#define NFS_SRTT(r) (r)->r_nmp->nm_srtt[proct[(r)->r_procnum] - 1]
-#define NFS_SDRTT(r) (r)->r_nmp->nm_sdrtt[proct[(r)->r_procnum] - 1]
+#define NFS_SRTT(r) (r)->r_nmp->nm_srtt[proct[(r)->r_procnum] - 1]
+#define NFS_SDRTT(r) (r)->r_nmp->nm_sdrtt[proct[(r)->r_procnum] - 1]
/*
* Defines which timer to use for the procnum.
* performance hit (ave. rtt 3 times larger),
* I suspect due to the large rtt that nfs rpcs have.
*/
-#define NFS_CWNDSCALE 256
-#define NFS_MAXCWND (NFS_CWNDSCALE * 32)
+#define NFS_CWNDSCALE 256
+#define NFS_MAXCWND (NFS_CWNDSCALE * 32)
static int nfs_backoff[8] = { 2, 4, 8, 16, 32, 64, 128, 256, };
/*
/* no more servers on current location, go to first server of next location */
serv = 0;
loc++;
- if (loc >= nlp->nl_numlocs)
+ if (loc >= nlp->nl_numlocs) {
loc = 0; /* after last location, wrap back around to first location */
+ }
}
}
/*
* location that was passed in. (That would mean no servers had any
* addresses. And we don't want to spin here forever.)
*/
- if ((loc == nlip->nli_loc) && (serv == nlip->nli_serv) && (addr == nlip->nli_addr))
+ if ((loc == nlip->nli_loc) && (serv == nlip->nli_serv) && (addr == nlip->nli_addr)) {
return;
- if (addr >= nlp->nl_locations[loc]->nl_servers[serv]->ns_addrcount)
+ }
+ if (addr >= nlp->nl_locations[loc]->nl_servers[serv]->ns_addrcount) {
goto next_server;
+ }
nlip->nli_loc = loc;
nlip->nli_serv = serv;
int
nfs_location_index_cmp(struct nfs_location_index *nlip1, struct nfs_location_index *nlip2)
{
- if (nlip1->nli_loc != nlip2->nli_loc)
- return (nlip1->nli_loc - nlip2->nli_loc);
- if (nlip1->nli_serv != nlip2->nli_serv)
- return (nlip1->nli_serv - nlip2->nli_serv);
- return (nlip1->nli_addr - nlip2->nli_addr);
+ if (nlip1->nli_loc != nlip2->nli_loc) {
+ return nlip1->nli_loc - nlip2->nli_loc;
+ }
+ if (nlip1->nli_serv != nlip2->nli_serv) {
+ return nlip1->nli_serv - nlip2->nli_serv;
+ }
+ return nlip1->nli_addr - nlip2->nli_addr;
}
/*
return;
}
/* append each server path component */
- for (i=0; (size > 0) && (i < (int)fsl->nl_path.np_compcount); i++) {
+ for (i = 0; (size > 0) && (i < (int)fsl->nl_path.np_compcount); i++) {
cnt = snprintf(p, size, "/%s", fsl->nl_path.np_components[i]);
p += cnt;
size -= cnt;
}
lck_mtx_lock(&nso->nso_lock);
- if ((nso->nso_flags & (NSO_UPCALL|NSO_DISCONNECTING|NSO_DEAD)) || !(nso->nso_flags & NSO_PINGING)) {
+ if ((nso->nso_flags & (NSO_UPCALL | NSO_DISCONNECTING | NSO_DEAD)) || !(nso->nso_flags & NSO_PINGING)) {
NFS_SOCK_DBG("nfs connect - socket %p upcall - nevermind\n", nso);
lck_mtx_unlock(&nso->nso_lock);
return;
/* loop while we make error-free progress */
while (!error && recv) {
/* make sure we're still interested in this socket */
- if (nso->nso_flags & (NSO_DISCONNECTING|NSO_DEAD))
+ if (nso->nso_flags & (NSO_DISCONNECTING | NSO_DEAD)) {
break;
+ }
lck_mtx_unlock(&nso->nso_lock);
m = NULL;
if (nso->nso_sotype == SOCK_STREAM) {
nfsm_chain_dissect_init(error, &nmrep, m);
nfsm_chain_get_32(error, &nmrep, rxid);
nfsm_chain_get_32(error, &nmrep, reply);
- if (!error && ((reply != RPC_REPLY) || (rxid != nso->nso_pingxid)))
+ if (!error && ((reply != RPC_REPLY) || (rxid != nso->nso_pingxid))) {
error = EBADRPC;
+ }
nfsm_chain_get_32(error, &nmrep, reply_status);
if (!error && (reply_status == RPC_MSGDENIED)) {
nfsm_chain_get_32(error, &nmrep, rejected_status);
- if (!error)
+ if (!error) {
error = (rejected_status == RPC_MISMATCH) ? ERPCMISMATCH : EACCES;
+ }
}
nfsm_chain_get_32(error, &nmrep, verf_type); /* verifier flavor */
nfsm_chain_get_32(error, &nmrep, verf_len); /* verifier length */
nfsmout_if(error);
- if (verf_len)
+ if (verf_len) {
nfsm_chain_adv(error, &nmrep, nfsm_rndup(verf_len));
+ }
nfsm_chain_get_32(error, &nmrep, accepted_status);
nfsmout_if(error);
if ((accepted_status == RPC_PROGMISMATCH) && !nso->nso_version) {
nfsm_chain_get_32(error, &nmrep, maxvers);
nfsmout_if(error);
if (nso->nso_protocol == PMAPPROG) {
- if ((minvers > RPCBVERS4) || (maxvers < PMAPVERS))
+ if ((minvers > RPCBVERS4) || (maxvers < PMAPVERS)) {
error = EPROGMISMATCH;
- else if ((nso->nso_saddr->sa_family == AF_INET) &&
- (PMAPVERS >= minvers) && (PMAPVERS <= maxvers))
+ } else if ((nso->nso_saddr->sa_family == AF_INET) &&
+ (PMAPVERS >= minvers) && (PMAPVERS <= maxvers)) {
nso->nso_version = PMAPVERS;
- else if (nso->nso_saddr->sa_family == AF_INET6) {
- if ((RPCBVERS4 >= minvers) && (RPCBVERS4 <= maxvers))
+ } else if (nso->nso_saddr->sa_family == AF_INET6) {
+ if ((RPCBVERS4 >= minvers) && (RPCBVERS4 <= maxvers)) {
nso->nso_version = RPCBVERS4;
- else if ((RPCBVERS3 >= minvers) && (RPCBVERS3 <= maxvers))
+ } else if ((RPCBVERS3 >= minvers) && (RPCBVERS3 <= maxvers)) {
nso->nso_version = RPCBVERS3;
+ }
}
} else if (nso->nso_protocol == NFS_PROG) {
int vers;
* here if that was successful.
*/
for (vers = nso->nso_nfs_max_vers; vers >= (int)nso->nso_nfs_min_vers; vers--) {
- if (vers >= (int)minvers && vers <= (int)maxvers)
- break;
+ if (vers >= (int)minvers && vers <= (int)maxvers) {
+ break;
+ }
}
nso->nso_version = (vers < (int)nso->nso_nfs_min_vers) ? 0 : vers;
}
- if (!error && nso->nso_version)
+ if (!error && nso->nso_version) {
accepted_status = RPC_SUCCESS;
+ }
}
if (!error) {
switch (accepted_status) {
nso->nso_flags |= NSO_DEAD;
wakeup(nso->nso_wake);
}
- if (nso->nso_flags & NSO_DISCONNECTING)
+ if (nso->nso_flags & NSO_DISCONNECTING) {
wakeup(&nso->nso_flags);
+ }
lck_mtx_unlock(&nso->nso_lock);
}
char naddr[MAX_IPv6_STR_LEN];
void *sinaddr;
- if (sa->sa_family == AF_INET)
+ if (sa->sa_family == AF_INET) {
sinaddr = &((struct sockaddr_in*)sa)->sin_addr;
- else
+ } else {
sinaddr = &((struct sockaddr_in6*)sa)->sin6_addr;
- if (inet_ntop(sa->sa_family, sinaddr, naddr, sizeof(naddr)) != naddr)
+ }
+ if (inet_ntop(sa->sa_family, sinaddr, naddr, sizeof(naddr)) != naddr) {
strlcpy(naddr, "<unknown>", sizeof(naddr));
+ }
#else
char naddr[1] = { 0 };
#endif
*nsop = NULL;
/* Create the socket. */
- MALLOC(nso, struct nfs_socket *, sizeof(struct nfs_socket), M_TEMP, M_WAITOK|M_ZERO);
- if (nso)
- MALLOC(nso->nso_saddr, struct sockaddr *, sa->sa_len, M_SONAME, M_WAITOK|M_ZERO);
+ MALLOC(nso, struct nfs_socket *, sizeof(struct nfs_socket), M_TEMP, M_WAITOK | M_ZERO);
+ if (nso) {
+ MALLOC(nso->nso_saddr, struct sockaddr *, sa->sa_len, M_SONAME, M_WAITOK | M_ZERO);
+ }
if (!nso || !nso->nso_saddr) {
- if (nso)
+ if (nso) {
FREE(nso, M_TEMP);
- return (ENOMEM);
+ }
+ return ENOMEM;
}
lck_mtx_init(&nso->nso_lock, nfs_request_grp, LCK_ATTR_NULL);
nso->nso_sotype = sotype;
- if (nso->nso_sotype == SOCK_STREAM)
+ if (nso->nso_sotype == SOCK_STREAM) {
nfs_rpc_record_state_init(&nso->nso_rrs);
+ }
microuptime(&now);
nso->nso_timestamp = now.tv_sec;
bcopy(sa, nso->nso_saddr, sa->sa_len);
- if (sa->sa_family == AF_INET)
+ if (sa->sa_family == AF_INET) {
((struct sockaddr_in*)nso->nso_saddr)->sin_port = htons(port);
- else if (sa->sa_family == AF_INET6)
+ } else if (sa->sa_family == AF_INET6) {
((struct sockaddr_in6*)nso->nso_saddr)->sin6_port = htons(port);
+ }
nso->nso_protocol = protocol;
nso->nso_version = vers;
nso->nso_nfs_min_vers = PVER2MAJOR(nmp->nm_min_vers);
int portrange = IP_PORTRANGE_LOW;
error = sock_setsockopt(nso->nso_so, level, optname, &portrange, sizeof(portrange));
- if (!error) { /* bind now to check for failure */
+ if (!error) { /* bind now to check for failure */
ss.ss_len = sa->sa_len;
ss.ss_family = sa->sa_family;
if (ss.ss_family == AF_INET) {
} else {
error = EINVAL;
}
- if (!error)
+ if (!error) {
error = sock_bind(nso->nso_so, (struct sockaddr*)&ss);
+ }
}
}
if (error) {
NFS_SOCK_DBG("nfs connect %s error %d creating socket %p %s type %d%s port %d prot %d %d\n",
- vfs_statfs(nmp->nm_mountp)->f_mntfromname, error, nso, naddr, sotype,
- resvport ? "r" : "", port, protocol, vers);
+ vfs_statfs(nmp->nm_mountp)->f_mntfromname, error, nso, naddr, sotype,
+ resvport ? "r" : "", port, protocol, vers);
nfs_socket_destroy(nso);
} else {
NFS_SOCK_DBG("nfs connect %s created socket %p %s type %d%s port %d prot %d %d\n",
- vfs_statfs(nmp->nm_mountp)->f_mntfromname, nso, naddr,
- sotype, resvport ? "r" : "", port, protocol, vers);
+ vfs_statfs(nmp->nm_mountp)->f_mntfromname, nso, naddr,
+ sotype, resvport ? "r" : "", port, protocol, vers);
*nsop = nso;
}
- return (error);
+ return error;
}
/*
lck_mtx_lock(&nso->nso_lock);
nso->nso_flags |= NSO_DISCONNECTING;
- if (nso->nso_flags & NSO_UPCALL) /* give upcall a chance to complete */
- msleep(&nso->nso_flags, &nso->nso_lock, PZERO-1, "nfswaitupcall", &ts);
+ if (nso->nso_flags & NSO_UPCALL) { /* give upcall a chance to complete */
+ msleep(&nso->nso_flags, &nso->nso_lock, PZERO - 1, "nfswaitupcall", &ts);
+ }
lck_mtx_unlock(&nso->nso_lock);
sock_shutdown(nso->nso_so, SHUT_RDWR);
sock_close(nso->nso_so);
- if (nso->nso_sotype == SOCK_STREAM)
+ if (nso->nso_sotype == SOCK_STREAM) {
nfs_rpc_record_state_cleanup(&nso->nso_rrs);
+ }
lck_mtx_destroy(&nso->nso_lock, nfs_request_grp);
- if (nso->nso_saddr)
+ if (nso->nso_saddr) {
FREE(nso->nso_saddr, M_SONAME);
- if (nso->nso_saddr2)
+ }
+ if (nso->nso_saddr2) {
FREE(nso->nso_saddr2, M_SONAME);
+ }
NFS_SOCK_DBG("nfs connect - socket %p destroyed\n", nso);
FREE(nso, M_TEMP);
}
sock_setsockopt(nso->nso_so, SOL_SOCKET, SO_KEEPALIVE, &on, sizeof(on));
/* set nodelay for TCP */
sock_gettype(nso->nso_so, NULL, NULL, &proto);
- if (proto == IPPROTO_TCP)
+ if (proto == IPPROTO_TCP) {
sock_setsockopt(nso->nso_so, IPPROTO_TCP, TCP_NODELAY, &on, sizeof(on));
+ }
}
if (nso->nso_sotype == SOCK_DGRAM) { /* set socket buffer sizes for UDP */
int reserve = NFS_UDPSOCKBUF;
/* just playin' it safe with upcalls */
sock_setsockopt(nso->nso_so, SOL_SOCKET, SO_UPCALLCLOSEWAIT, &on, sizeof(on));
/* socket should be interruptible if the mount is */
- if (!NMFLAG(nmp, INTR))
+ if (!NMFLAG(nmp, INTR)) {
sock_nointerrupt(nso->nso_so, 1);
+ }
}
/*
{
switch (error) {
case 0:
- return (0);
+ return 0;
case ETIMEDOUT:
case EAGAIN:
- return (1);
+ return 1;
case EPIPE:
case EADDRNOTAVAIL:
case ENETDOWN:
case ECONNREFUSED:
case EHOSTDOWN:
case EHOSTUNREACH:
- return (2);
+ return 2;
case ERPCMISMATCH:
case EPROCUNAVAIL:
case EPROGMISMATCH:
case EPROGUNAVAIL:
- return (3);
+ return 3;
case EBADRPC:
- return (4);
+ return 4;
default:
- return (5);
+ return 5;
}
}
void
nfs_socket_search_update_error(struct nfs_socket_search *nss, int error)
{
- if (nfs_connect_error_class(error) >= nfs_connect_error_class(nss->nss_error))
+ if (nfs_connect_error_class(error) >= nfs_connect_error_class(nss->nss_error)) {
nss->nss_error = error;
+ }
}
/* nfs_connect_search_new_socket:
- * Given a socket search structure for an nfs mount try to find a new socket from the set of addresses specified
+ * Given a socket search structure for an nfs mount try to find a new socket from the set of addresses specified
* by nss.
*
* nss_last is set to -1 at initialization to indicate the first time. Its set to -2 if address was found but
struct nfs_socket *nso;
char *addrstr;
int error = 0;
-
+
NFS_SOCK_DBG("nfs connect %s nss_addrcnt = %d\n",
- vfs_statfs(nmp->nm_mountp)->f_mntfromname, nss->nss_addrcnt);
+ vfs_statfs(nmp->nm_mountp)->f_mntfromname, nss->nss_addrcnt);
/*
* while there are addresses and:
* then attempt to create a socket with the current address.
*/
while (nss->nss_addrcnt > 0 && ((nss->nss_last < 0) || (nss->nss_sockcnt == 0) ||
- ((nss->nss_sockcnt < 4) && (now->tv_sec >= (nss->nss_last + 2))))) {
- if (nmp->nm_sockflags & NMSOCK_UNMOUNT)
- return (EINTR);
+ ((nss->nss_sockcnt < 4) && (now->tv_sec >= (nss->nss_last + 2))))) {
+ if (nmp->nm_sockflags & NMSOCK_UNMOUNT) {
+ return EINTR;
+ }
/* Can we convert the address to a sockaddr? */
fsl = nmp->nm_locations.nl_locations[nss->nss_nextloc.nli_loc];
fss = fsl->nl_servers[nss->nss_nextloc.nli_serv];
/* Create the socket. */
error = nfs_socket_create(nmp, (struct sockaddr*)&ss, nss->nss_sotype,
- nss->nss_port, nss->nss_protocol, nss->nss_version,
- ((nss->nss_protocol == NFS_PROG) && NMFLAG(nmp, RESVPORT)), &nso);
- if (error)
- return (error);
+ nss->nss_port, nss->nss_protocol, nss->nss_version,
+ ((nss->nss_protocol == NFS_PROG) && NMFLAG(nmp, RESVPORT)), &nso);
+ if (error) {
+ return error;
+ }
nso->nso_location = nss->nss_nextloc;
nso->nso_wake = nss;
nss->nss_sockcnt++;
nfs_location_next(&nmp->nm_locations, &nss->nss_nextloc);
nss->nss_addrcnt -= 1;
-
+
nss->nss_last = now->tv_sec;
}
- if (nss->nss_addrcnt == 0 && nss->nss_last < 0)
+ if (nss->nss_addrcnt == 0 && nss->nss_last < 0) {
nss->nss_last = now->tv_sec;
-
- return (error);
+ }
+
+ return error;
}
/*
nfs_connect_search_socket_connect(struct nfsmount *nmp, struct nfs_socket *nso, int verbose)
{
int error;
-
+
if ((nso->nso_sotype != SOCK_STREAM) && NMFLAG(nmp, NOCONNECT)) {
/* no connection needed, just say it's already connected */
NFS_SOCK_DBG("nfs connect %s UDP socket %p noconnect\n",
- vfs_statfs(nmp->nm_mountp)->f_mntfromname, nso);
+ vfs_statfs(nmp->nm_mountp)->f_mntfromname, nso);
nso->nso_flags |= NSO_CONNECTED;
nfs_socket_options(nmp, nso);
- return (1); /* Socket is connected and setup */
+ return 1; /* Socket is connected and setup */
} else if (!(nso->nso_flags & NSO_CONNECTING)) {
/* initiate the connection */
nso->nso_flags |= NSO_CONNECTING;
lck_mtx_unlock(&nso->nso_lock);
NFS_SOCK_DBG("nfs connect %s connecting socket %p\n",
- vfs_statfs(nmp->nm_mountp)->f_mntfromname, nso);
+ vfs_statfs(nmp->nm_mountp)->f_mntfromname, nso);
error = sock_connect(nso->nso_so, nso->nso_saddr, MSG_DONTWAIT);
lck_mtx_lock(&nso->nso_lock);
if (error && (error != EINPROGRESS)) {
nso->nso_error = error;
nso->nso_flags |= NSO_DEAD;
- return (0);
+ return 0;
}
}
if (nso->nso_flags & NSO_CONNECTING) {
/* check the connection */
if (sock_isconnected(nso->nso_so)) {
NFS_SOCK_DBG("nfs connect %s socket %p is connected\n",
- vfs_statfs(nmp->nm_mountp)->f_mntfromname, nso);
+ vfs_statfs(nmp->nm_mountp)->f_mntfromname, nso);
nso->nso_flags &= ~NSO_CONNECTING;
nso->nso_flags |= NSO_CONNECTED;
nfs_socket_options(nmp, nso);
- return (1); /* Socket is connected and setup */
+ return 1; /* Socket is connected and setup */
} else {
int optlen = sizeof(error);
error = 0;
sock_getsockopt(nso->nso_so, SOL_SOCKET, SO_ERROR, &error, &optlen);
if (error) { /* we got an error on the socket */
NFS_SOCK_DBG("nfs connect %s socket %p connection error %d\n",
- vfs_statfs(nmp->nm_mountp)->f_mntfromname, nso, error);
- if (verbose)
+ vfs_statfs(nmp->nm_mountp)->f_mntfromname, nso, error);
+ if (verbose) {
printf("nfs connect socket error %d for %s\n",
error, vfs_statfs(nmp->nm_mountp)->f_mntfromname);
+ }
nso->nso_error = error;
nso->nso_flags |= NSO_DEAD;
- return (0);
+ return 0;
}
}
}
-
- return (0); /* Waiting to be connected */
+
+ return 0; /* Waiting to be connected */
}
/*
int error;
if (!vers) {
- if (nso->nso_protocol == PMAPPROG)
+ if (nso->nso_protocol == PMAPPROG) {
vers = (nso->nso_saddr->sa_family == AF_INET) ? PMAPVERS : RPCBVERS4;
- else if (nso->nso_protocol == NFS_PROG)
+ } else if (nso->nso_protocol == NFS_PROG) {
vers = PVER2MAJOR(nmp->nm_max_vers);
+ }
}
lck_mtx_unlock(&nso->nso_lock);
error = nfsm_rpchead2(nmp, nso->nso_sotype, nso->nso_protocol, vers, 0, RPCAUTH_SYS,
- vfs_context_ucred(vfs_context_kernel()), NULL, NULL, &xid, &mreq);
+ vfs_context_ucred(vfs_context_kernel()), NULL, NULL, &xid, &mreq);
lck_mtx_lock(&nso->nso_lock);
if (!error) {
nso->nso_flags |= NSO_PINGING;
msg.msg_name = nso->nso_saddr;
msg.msg_namelen = nso->nso_saddr->sa_len;
}
- for (reqlen=0, m=mreq; m; m = mbuf_next(m))
+ for (reqlen = 0, m = mreq; m; m = mbuf_next(m)) {
reqlen += mbuf_len(m);
+ }
lck_mtx_unlock(&nso->nso_lock);
error = sock_sendmbuf(nso->nso_so, &msg, mreq, 0, &sentlen);
NFS_SOCK_DBG("nfs connect %s verifying socket %p send rv %d\n",
- vfs_statfs(nmp->nm_mountp)->f_mntfromname, nso, error);
+ vfs_statfs(nmp->nm_mountp)->f_mntfromname, nso, error);
lck_mtx_lock(&nso->nso_lock);
- if (!error && (sentlen != reqlen))
+ if (!error && (sentlen != reqlen)) {
error = ETIMEDOUT;
+ }
}
if (error) {
nso->nso_error = error;
nso->nso_flags |= NSO_DEAD;
- return (0);
+ return 0;
}
- return (1);
+ return 1;
}
/*
* nfs_connect_search_socket_found: Take the found socket of the socket search list and assign it to the searched socket.
- * Set the nfs socket protocol and version if needed.
+ * Set the nfs socket protocol and version if needed.
*/
void
nfs_connect_search_socket_found(struct nfsmount *nmp, struct nfs_socket_search *nss, struct nfs_socket *nso)
{
NFS_SOCK_DBG("nfs connect %s socket %p verified\n",
- vfs_statfs(nmp->nm_mountp)->f_mntfromname, nso);
+ vfs_statfs(nmp->nm_mountp)->f_mntfromname, nso);
if (!nso->nso_version) {
/* If the version isn't set, the default must have worked. */
- if (nso->nso_protocol == PMAPPROG)
+ if (nso->nso_protocol == PMAPPROG) {
nso->nso_version = (nso->nso_saddr->sa_family == AF_INET) ? PMAPVERS : RPCBVERS4;
- if (nso->nso_protocol == NFS_PROG)
+ }
+ if (nso->nso_protocol == NFS_PROG) {
nso->nso_version = PVER2MAJOR(nmp->nm_max_vers);
+ }
}
TAILQ_REMOVE(&nss->nss_socklist, nso, nso_link);
nss->nss_sockcnt--;
nfs_connect_search_socket_reap(struct nfsmount *nmp __unused, struct nfs_socket_search *nss, struct timeval *now)
{
struct nfs_socket *nso, *nsonext;
-
+
TAILQ_FOREACH_SAFE(nso, &nss->nss_socklist, nso_link, nsonext) {
lck_mtx_lock(&nso->nso_lock);
if (now->tv_sec >= (nso->nso_timestamp + nss->nss_timeo)) {
/* took too long */
NFS_SOCK_DBG("nfs connect %s socket %p timed out\n",
- vfs_statfs(nmp->nm_mountp)->f_mntfromname, nso);
+ vfs_statfs(nmp->nm_mountp)->f_mntfromname, nso);
nso->nso_error = ETIMEDOUT;
nso->nso_flags |= NSO_DEAD;
}
}
lck_mtx_unlock(&nso->nso_lock);
NFS_SOCK_DBG("nfs connect %s reaping socket %p %d\n",
- vfs_statfs(nmp->nm_mountp)->f_mntfromname, nso, nso->nso_error);
+ vfs_statfs(nmp->nm_mountp)->f_mntfromname, nso, nso->nso_error);
nfs_socket_search_update_error(nss, nso->nso_error);
TAILQ_REMOVE(&nss->nss_socklist, nso, nso_link);
nss->nss_sockcnt--;
nfs_socket_destroy(nso);
/* If there are more sockets to try, force the starting of another socket */
- if (nss->nss_addrcnt > 0)
+ if (nss->nss_addrcnt > 0) {
nss->nss_last = -2;
+ }
}
}
int error;
/* log a warning if connect is taking a while */
- if (((now->tv_sec - nss->nss_timestamp) >= 8) && ((nss->nss_flags & (NSS_VERBOSE|NSS_WARNED)) == NSS_VERBOSE)) {
+ if (((now->tv_sec - nss->nss_timestamp) >= 8) && ((nss->nss_flags & (NSS_VERBOSE | NSS_WARNED)) == NSS_VERBOSE)) {
printf("nfs_connect: socket connect taking a while for %s\n", vfs_statfs(nmp->nm_mountp)->f_mntfromname);
nss->nss_flags |= NSS_WARNED;
}
- if (nmp->nm_sockflags & NMSOCK_UNMOUNT)
- return (EINTR);
- if ((error = nfs_sigintr(nmp, NULL, current_thread(), 0)))
- return (error);
+ if (nmp->nm_sockflags & NMSOCK_UNMOUNT) {
+ return EINTR;
+ }
+ if ((error = nfs_sigintr(nmp, NULL, current_thread(), 0))) {
+ return error;
+ }
/* If we were succesfull at sending a ping, wait up to a second for a reply */
- if (nss->nss_last >= 0)
+ if (nss->nss_last >= 0) {
tsleep(nss, PSOCK, "nfs_connect_search_wait", hz);
-
- return (0);
+ }
+
+ return 0;
}
struct timeval now;
int error;
int verbose = (nss->nss_flags & NSS_VERBOSE);
-
+
loop:
microuptime(&now);
NFS_SOCK_DBG("nfs connect %s search %ld\n", vfs_statfs(nmp->nm_mountp)->f_mntfromname, now.tv_sec);
error = nfs_connect_search_new_socket(nmp, nss, &now);
if (error) {
NFS_SOCK_DBG("nfs connect returned %d\n", error);
- return (error);
+ return error;
}
-
+
/* check each active socket on the list and try to push it along */
TAILQ_FOREACH(nso, &nss->nss_socklist, nso_link) {
lck_mtx_lock(&nso->nso_lock);
}
/* If the socket hasn't been verified or in a ping, ping it. We also handle UDP retransmits */
- if (!(nso->nso_flags & (NSO_PINGING|NSO_VERIFIED)) ||
- ((nso->nso_sotype == SOCK_DGRAM) && (now.tv_sec >= nso->nso_reqtimestamp+2))) {
+ if (!(nso->nso_flags & (NSO_PINGING | NSO_VERIFIED)) ||
+ ((nso->nso_sotype == SOCK_DGRAM) && (now.tv_sec >= nso->nso_reqtimestamp + 2))) {
if (!nfs_connect_search_ping(nmp, nso, &now)) {
lck_mtx_unlock(&nso->nso_lock);
continue;
}
lck_mtx_unlock(&nso->nso_lock);
}
-
+
/* Check for timed out sockets and mark as dead and then remove all dead sockets. */
nfs_connect_search_socket_reap(nmp, nss, &now);
-
+
/*
* Keep looping if we haven't found a socket yet and we have more
* sockets to (continue to) try.
error = 0;
if (!nss->nss_sock && (!TAILQ_EMPTY(&nss->nss_socklist) || nss->nss_addrcnt)) {
error = nfs_connect_search_check(nmp, nss, &now);
- if (!error)
+ if (!error) {
goto loop;
+ }
}
NFS_SOCK_DBG("nfs connect %s returning %d\n", vfs_statfs(nmp->nm_mountp)->f_mntfromname, error);
- return (error);
+ return error;
}
/*
struct timeval now, start;
int error, savederror, nfsvers;
int tryv4 = 1;
- uint8_t sotype = nmp->nm_sotype ? nmp->nm_sotype : SOCK_STREAM;
+ uint8_t sotype = nmp->nm_sotype ? nmp->nm_sotype : SOCK_STREAM;
fhandle_t *fh = NULL;
char *path = NULL;
in_port_t port;
int addrtotal = 0;
-
+
/* paranoia... check that we have at least one address in the locations */
uint32_t loc, serv;
- for (loc=0; loc < nmp->nm_locations.nl_numlocs; loc++) {
- for (serv=0; serv < nmp->nm_locations.nl_locations[loc]->nl_servcount; serv++) {
+ for (loc = 0; loc < nmp->nm_locations.nl_numlocs; loc++) {
+ for (serv = 0; serv < nmp->nm_locations.nl_locations[loc]->nl_servcount; serv++) {
addrtotal += nmp->nm_locations.nl_locations[loc]->nl_servers[serv]->ns_addrcount;
- if (nmp->nm_locations.nl_locations[loc]->nl_servers[serv]->ns_addrcount == 0)
+ if (nmp->nm_locations.nl_locations[loc]->nl_servers[serv]->ns_addrcount == 0) {
NFS_SOCK_DBG("nfs connect %s search, server %s has no addresses\n",
- vfs_statfs(nmp->nm_mountp)->f_mntfromname,
- nmp->nm_locations.nl_locations[loc]->nl_servers[serv]->ns_name);
+ vfs_statfs(nmp->nm_mountp)->f_mntfromname,
+ nmp->nm_locations.nl_locations[loc]->nl_servers[serv]->ns_name);
+ }
}
}
if (addrtotal == 0) {
NFS_SOCK_DBG("nfs connect %s search failed, no addresses\n",
- vfs_statfs(nmp->nm_mountp)->f_mntfromname);
- return (EINVAL);
- } else
+ vfs_statfs(nmp->nm_mountp)->f_mntfromname);
+ return EINVAL;
+ } else {
NFS_SOCK_DBG("nfs connect %s has %d addresses\n",
- vfs_statfs(nmp->nm_mountp)->f_mntfromname, addrtotal);
+ vfs_statfs(nmp->nm_mountp)->f_mntfromname, addrtotal);
+ }
lck_mtx_lock(&nmp->nm_lock);
nmp->nm_sockflags |= NMSOCK_CONNECTING;
nss.nss_startloc = nmp->nm_locations.nl_current;
nss.nss_timestamp = start.tv_sec;
nss.nss_timeo = timeo;
- if (verbose)
+ if (verbose) {
nss.nss_flags |= NSS_VERBOSE;
+ }
/* First time connecting, we may need to negotiate some things */
if (!(nmp->nm_sockflags & NMSOCK_HASCONNECTED)) {
* if no port is specified on the mount;
* Note nm_vers is set so we will only try NFS_VER4.
*/
- if (!nmp->nm_nfsport)
+ if (!nmp->nm_nfsport) {
nss.nss_flags |= NSS_FALLBACK2PMAP;
+ }
} else {
nss.nss_port = PMAPPORT;
nss.nss_protocol = PMAPPROG;
}
}
NFS_SOCK_DBG("nfs connect first %s, so type %d port %d prot %d %d\n",
- vfs_statfs(nmp->nm_mountp)->f_mntfromname, nss.nss_sotype, nss.nss_port,
- nss.nss_protocol, nss.nss_version);
+ vfs_statfs(nmp->nm_mountp)->f_mntfromname, nss.nss_sotype, nss.nss_port,
+ nss.nss_protocol, nss.nss_version);
} else {
/* we've connected before, just connect to NFS port */
if (!nmp->nm_nfsport) {
nss.nss_version = nmp->nm_vers;
}
NFS_SOCK_DBG("nfs connect %s, so type %d port %d prot %d %d\n",
- vfs_statfs(nmp->nm_mountp)->f_mntfromname, nss.nss_sotype, nss.nss_port,
- nss.nss_protocol, nss.nss_version);
+ vfs_statfs(nmp->nm_mountp)->f_mntfromname, nss.nss_sotype, nss.nss_port,
+ nss.nss_protocol, nss.nss_version);
}
/* Set next location to first valid location. */
nfs_location_next(&nmp->nm_locations, &nss.nss_nextloc);
if (!nfs_location_index_cmp(&nss.nss_nextloc, &nss.nss_startloc)) {
NFS_SOCK_DBG("nfs connect %s search failed, couldn't find a valid location index\n",
- vfs_statfs(nmp->nm_mountp)->f_mntfromname);
- return (ENOENT);
+ vfs_statfs(nmp->nm_mountp)->f_mntfromname);
+ return ENOENT;
}
}
nss.nss_last = -1;
if (nss.nss_flags & NSS_FALLBACK2PMAP) {
tryv4 = 0;
NFS_SOCK_DBG("nfs connect %s TCP failed for V4 %d %d, trying PORTMAP\n",
- vfs_statfs(nmp->nm_mountp)->f_mntfromname, error, nss.nss_error);
+ vfs_statfs(nmp->nm_mountp)->f_mntfromname, error, nss.nss_error);
goto tryagain;
}
sotype = SOCK_DGRAM;
savederror = nss.nss_error;
NFS_SOCK_DBG("nfs connect %s TCP failed %d %d, trying UDP\n",
- vfs_statfs(nmp->nm_mountp)->f_mntfromname, error, nss.nss_error);
+ vfs_statfs(nmp->nm_mountp)->f_mntfromname, error, nss.nss_error);
goto tryagain;
}
- if (!error)
+ if (!error) {
error = nss.nss_error ? nss.nss_error : ETIMEDOUT;
+ }
lck_mtx_lock(&nmp->nm_lock);
nmp->nm_sockflags &= ~NMSOCK_CONNECTING;
nmp->nm_nss = NULL;
lck_mtx_unlock(&nmp->nm_lock);
- if (nss.nss_flags & NSS_WARNED)
+ if (nss.nss_flags & NSS_WARNED) {
log(LOG_INFO, "nfs_connect: socket connect aborted for %s\n",
- vfs_statfs(nmp->nm_mountp)->f_mntfromname);
- if (fh)
+ vfs_statfs(nmp->nm_mountp)->f_mntfromname);
+ }
+ if (fh) {
FREE(fh, M_TEMP);
- if (path)
+ }
+ if (path) {
FREE_ZONE(path, MAXPATHLEN, M_NAMEI);
+ }
NFS_SOCK_DBG("nfs connect %s search failed, returning %d\n",
- vfs_statfs(nmp->nm_mountp)->f_mntfromname, error);
- return (error);
+ vfs_statfs(nmp->nm_mountp)->f_mntfromname, error);
+ return error;
}
/* try to use nss_sock */
nss.nss_sock = NULL;
/* We may be speaking to portmap first... to determine port(s). */
- if (nso->nso_saddr->sa_family == AF_INET)
+ if (nso->nso_saddr->sa_family == AF_INET) {
port = ntohs(((struct sockaddr_in*)nso->nso_saddr)->sin_port);
- else
+ } else {
port = ntohs(((struct sockaddr_in6*)nso->nso_saddr)->sin6_port);
+ }
if (port == PMAPPORT) {
/* Use this portmapper port to get the port #s we need. */
NFS_SOCK_DBG("nfs connect %s got portmapper socket %p\n",
- vfs_statfs(nmp->nm_mountp)->f_mntfromname, nso);
+ vfs_statfs(nmp->nm_mountp)->f_mntfromname, nso);
/* remove the connect upcall so nfs_portmap_lookup() can use this socket */
sock_setupcall(nso->nso_so, NULL, NULL);
/* If NFS version not set, try nm_max_vers down to nm_min_vers */
nfsvers = nmp->nm_vers ? nmp->nm_vers : PVER2MAJOR(nmp->nm_max_vers);
if (!(port = nmp->nm_nfsport)) {
- if (ss.ss_family == AF_INET)
+ if (ss.ss_family == AF_INET) {
((struct sockaddr_in*)&ss)->sin_port = htons(0);
- else if (ss.ss_family == AF_INET6)
+ } else if (ss.ss_family == AF_INET6) {
((struct sockaddr_in6*)&ss)->sin6_port = htons(0);
+ }
for (; nfsvers >= (int)PVER2MAJOR(nmp->nm_min_vers); nfsvers--) {
- if (nmp->nm_vers && nmp->nm_vers != nfsvers)
+ if (nmp->nm_vers && nmp->nm_vers != nfsvers) {
continue; /* Wrong version */
- if (nfsvers == NFS_VER4 && nso->nso_sotype == SOCK_DGRAM)
+ }
+ if (nfsvers == NFS_VER4 && nso->nso_sotype == SOCK_DGRAM) {
continue; /* NFSv4 does not do UDP */
+ }
error = nfs_portmap_lookup(nmp, vfs_context_current(), (struct sockaddr*)&ss,
- nso->nso_so, NFS_PROG, nfsvers,
- (nso->nso_sotype == SOCK_DGRAM) ? IPPROTO_UDP : IPPROTO_TCP, timeo);
+ nso->nso_so, NFS_PROG, nfsvers,
+ (nso->nso_sotype == SOCK_DGRAM) ? IPPROTO_UDP : IPPROTO_TCP, timeo);
if (!error) {
- if (ss.ss_family == AF_INET)
+ if (ss.ss_family == AF_INET) {
port = ntohs(((struct sockaddr_in*)&ss)->sin_port);
- else if (ss.ss_family == AF_INET6)
+ } else if (ss.ss_family == AF_INET6) {
port = ntohs(((struct sockaddr_in6*)&ss)->sin6_port);
- if (!port)
+ }
+ if (!port) {
error = EPROGUNAVAIL;
- if (port == NFS_PORT && nfsvers == NFS_VER4 && tryv4 == 0)
+ }
+ if (port == NFS_PORT && nfsvers == NFS_VER4 && tryv4 == 0) {
continue; /* We already tried this */
+ }
}
- if (!error)
+ if (!error) {
break;
+ }
}
- if (nfsvers < (int)PVER2MAJOR(nmp->nm_min_vers) && error == 0)
+ if (nfsvers < (int)PVER2MAJOR(nmp->nm_min_vers) && error == 0) {
error = EPROGUNAVAIL;
+ }
if (error) {
nfs_socket_search_update_error(&nss, error);
nfs_socket_destroy(nso);
/* Create NFS protocol socket and add it to the list of sockets. */
/* N.B. If nfsvers is NFS_VER4 at this point then we're on a non standard port */
error = nfs_socket_create(nmp, (struct sockaddr*)&ss, nso->nso_sotype, port,
- NFS_PROG, nfsvers, NMFLAG(nmp, RESVPORT), &nsonfs);
+ NFS_PROG, nfsvers, NMFLAG(nmp, RESVPORT), &nsonfs);
if (error) {
nfs_socket_search_update_error(&nss, error);
nfs_socket_destroy(nso);
error = 0;
bcopy(nso->nso_saddr, &ss, nso->nso_saddr->sa_len);
port = nmp->nm_mountport;
- if (ss.ss_family == AF_INET)
+ if (ss.ss_family == AF_INET) {
((struct sockaddr_in*)&ss)->sin_port = htons(port);
- else if (ss.ss_family == AF_INET6)
+ } else if (ss.ss_family == AF_INET6) {
((struct sockaddr_in6*)&ss)->sin6_port = htons(port);
+ }
if (!port) {
/* Get port/sockaddr for MOUNT version corresponding to NFS version. */
/* If NFS version is unknown, optimistically choose for NFSv3. */
int mntvers = (nfsvers == NFS_VER2) ? RPCMNT_VER1 : RPCMNT_VER3;
int mntproto = (NM_OMFLAG(nmp, MNTUDP) || (nso->nso_sotype == SOCK_DGRAM)) ? IPPROTO_UDP : IPPROTO_TCP;
error = nfs_portmap_lookup(nmp, vfs_context_current(), (struct sockaddr*)&ss,
- nso->nso_so, RPCPROG_MNT, mntvers, mntproto, timeo);
+ nso->nso_so, RPCPROG_MNT, mntvers, mntproto, timeo);
}
if (!error) {
- if (ss.ss_family == AF_INET)
+ if (ss.ss_family == AF_INET) {
port = ntohs(((struct sockaddr_in*)&ss)->sin_port);
- else if (ss.ss_family == AF_INET6)
+ } else if (ss.ss_family == AF_INET6) {
port = ntohs(((struct sockaddr_in6*)&ss)->sin6_port);
- if (!port)
+ }
+ if (!port) {
error = EPROGUNAVAIL;
+ }
}
/* create sockaddr for MOUNT */
- if (!error)
- MALLOC(nsonfs->nso_saddr2, struct sockaddr *, ss.ss_len, M_SONAME, M_WAITOK|M_ZERO);
- if (!error && !nsonfs->nso_saddr2)
+ if (!error) {
+ MALLOC(nsonfs->nso_saddr2, struct sockaddr *, ss.ss_len, M_SONAME, M_WAITOK | M_ZERO);
+ }
+ if (!error && !nsonfs->nso_saddr2) {
error = ENOMEM;
- if (!error)
+ }
+ if (!error) {
bcopy(&ss, nsonfs->nso_saddr2, ss.ss_len);
+ }
if (error) {
lck_mtx_lock(&nsonfs->nso_lock);
nsonfs->nso_error = error;
/* Need sockaddr for MOUNT port */
bcopy(nso->nso_saddr, &ss, nso->nso_saddr->sa_len);
port = nmp->nm_mountport;
- if (ss.ss_family == AF_INET)
+ if (ss.ss_family == AF_INET) {
((struct sockaddr_in*)&ss)->sin_port = htons(port);
- else if (ss.ss_family == AF_INET6)
+ } else if (ss.ss_family == AF_INET6) {
((struct sockaddr_in6*)&ss)->sin6_port = htons(port);
+ }
if (!port) {
/* Get port/sockaddr for MOUNT version corresponding to NFS version. */
int mntvers = (nfsvers == NFS_VER2) ? RPCMNT_VER1 : RPCMNT_VER3;
int mntproto = (NM_OMFLAG(nmp, MNTUDP) || (nso->nso_sotype == SOCK_DGRAM)) ? IPPROTO_UDP : IPPROTO_TCP;
error = nfs_portmap_lookup(nmp, vfs_context_current(), (struct sockaddr*)&ss,
- NULL, RPCPROG_MNT, mntvers, mntproto, timeo);
- if (ss.ss_family == AF_INET)
+ NULL, RPCPROG_MNT, mntvers, mntproto, timeo);
+ if (ss.ss_family == AF_INET) {
port = ntohs(((struct sockaddr_in*)&ss)->sin_port);
- else if (ss.ss_family == AF_INET6)
+ } else if (ss.ss_family == AF_INET6) {
port = ntohs(((struct sockaddr_in6*)&ss)->sin6_port);
+ }
}
if (!error) {
- if (port)
+ if (port) {
saddr = (struct sockaddr*)&ss;
- else
+ } else {
error = EPROGUNAVAIL;
+ }
}
}
- if (saddr)
- MALLOC(fh, fhandle_t *, sizeof(fhandle_t), M_TEMP, M_WAITOK|M_ZERO);
- if (saddr && fh)
+ if (saddr) {
+ MALLOC(fh, fhandle_t *, sizeof(fhandle_t), M_TEMP, M_WAITOK | M_ZERO);
+ }
+ if (saddr && fh) {
MALLOC_ZONE(path, char *, MAXPATHLEN, M_NAMEI, M_WAITOK);
+ }
if (!saddr || !fh || !path) {
- if (!error)
+ if (!error) {
error = ENOMEM;
- if (fh)
+ }
+ if (fh) {
FREE(fh, M_TEMP);
- if (path)
+ }
+ if (path) {
FREE_ZONE(path, MAXPATHLEN, M_NAMEI);
+ }
fh = NULL;
path = NULL;
nfs_socket_search_update_error(&nss, error);
}
nfs_location_mntfromname(&nmp->nm_locations, nso->nso_location, path, MAXPATHLEN, 1);
error = nfs3_mount_rpc(nmp, saddr, nso->nso_sotype, nfsvers,
- path, vfs_context_current(), timeo, fh, &nmp->nm_servsec);
+ path, vfs_context_current(), timeo, fh, &nmp->nm_servsec);
NFS_SOCK_DBG("nfs connect %s socket %p mount %d\n",
- vfs_statfs(nmp->nm_mountp)->f_mntfromname, nso, error);
+ vfs_statfs(nmp->nm_mountp)->f_mntfromname, nso, error);
if (!error) {
/* Make sure we can agree on a security flavor. */
int o, s; /* indices into mount option and server security flavor lists */
nmp->nm_auth = nmp->nm_sec.flavors[0];
found = 1;
}
- for (o=0; !found && (o < nmp->nm_sec.count); o++)
- for (s=0; !found && (s < nmp->nm_servsec.count); s++)
+ for (o = 0; !found && (o < nmp->nm_sec.count); o++) {
+ for (s = 0; !found && (s < nmp->nm_servsec.count); s++) {
if (nmp->nm_sec.flavors[o] == nmp->nm_servsec.flavors[s]) {
nmp->nm_auth = nmp->nm_sec.flavors[o];
found = 1;
}
+ }
+ }
} else {
/* Choose the first one we support from the server's list. */
if (!nmp->nm_servsec.count) {
nmp->nm_auth = RPCAUTH_SYS;
found = 1;
}
- for (s=0; s < nmp->nm_servsec.count; s++)
+ for (s = 0; s < nmp->nm_servsec.count; s++) {
switch (nmp->nm_servsec.flavors[s]) {
case RPCAUTH_SYS:
/* prefer RPCAUTH_SYS to RPCAUTH_NONE */
- if (found && (nmp->nm_auth == RPCAUTH_NONE))
+ if (found && (nmp->nm_auth == RPCAUTH_NONE)) {
found = 0;
+ }
case RPCAUTH_NONE:
case RPCAUTH_KRB5:
case RPCAUTH_KRB5I:
}
break;
}
+ }
}
error = !found ? EAUTH : 0;
}
nfs_socket_destroy(nso);
goto keepsearching;
}
- if (nmp->nm_fh)
+ if (nmp->nm_fh) {
FREE(nmp->nm_fh, M_TEMP);
+ }
nmp->nm_fh = fh;
fh = NULL;
NFS_BITMAP_SET(nmp->nm_flags, NFS_MFLAG_CALLUMNT);
if (!(nmp->nm_sockflags & NMSOCK_HASCONNECTED)) {
/* set mntfromname to this location */
- if (!NM_OMATTR_GIVEN(nmp, MNTFROM))
+ if (!NM_OMATTR_GIVEN(nmp, MNTFROM)) {
nfs_location_mntfromname(&nmp->nm_locations, nso->nso_location,
- vfs_statfs(nmp->nm_mountp)->f_mntfromname,
- sizeof(vfs_statfs(nmp->nm_mountp)->f_mntfromname), 0);
+ vfs_statfs(nmp->nm_mountp)->f_mntfromname,
+ sizeof(vfs_statfs(nmp->nm_mountp)->f_mntfromname), 0);
+ }
/* some negotiated values need to remain unchanged for the life of the mount */
- if (!nmp->nm_sotype)
+ if (!nmp->nm_sotype) {
nmp->nm_sotype = nso->nso_sotype;
+ }
if (!nmp->nm_vers) {
nmp->nm_vers = nfsvers;
/* If we negotiated NFSv4, set nm_nfsport if we ended up on the standard NFS port */
if ((nfsvers >= NFS_VER4) && !NFS_BITMAP_ISSET(nmp->nm_mattrs, NFS_MATTR_NFS_PORT)) {
- if (nso->nso_saddr->sa_family == AF_INET)
+ if (nso->nso_saddr->sa_family == AF_INET) {
port = ((struct sockaddr_in*)nso->nso_saddr)->sin_port = htons(port);
- else if (nso->nso_saddr->sa_family == AF_INET6)
+ } else if (nso->nso_saddr->sa_family == AF_INET6) {
port = ((struct sockaddr_in6*)nso->nso_saddr)->sin6_port = htons(port);
- else
+ } else {
port = 0;
- if (port == NFS_PORT)
+ }
+ if (port == NFS_PORT) {
nmp->nm_nfsport = NFS_PORT;
+ }
}
}
/* do some version-specific pre-mount set up */
if (nmp->nm_vers >= NFS_VER4) {
microtime(&now);
nmp->nm_mounttime = ((uint64_t)now.tv_sec << 32) | now.tv_usec;
- if (!NMFLAG(nmp, NOCALLBACK))
+ if (!NMFLAG(nmp, NOCALLBACK)) {
nfs4_mount_callback_setup(nmp);
+ }
}
}
/* Initialize NFS socket state variables */
lck_mtx_lock(&nmp->nm_lock);
nmp->nm_srtt[0] = nmp->nm_srtt[1] = nmp->nm_srtt[2] =
- nmp->nm_srtt[3] = (NFS_TIMEO << 3);
+ nmp->nm_srtt[3] = (NFS_TIMEO << 3);
nmp->nm_sdrtt[0] = nmp->nm_sdrtt[1] = nmp->nm_sdrtt[2] =
- nmp->nm_sdrtt[3] = 0;
+ nmp->nm_sdrtt[3] = 0;
if (nso->nso_sotype == SOCK_DGRAM) {
- nmp->nm_cwnd = NFS_MAXCWND / 2; /* Initial send window */
+ nmp->nm_cwnd = NFS_MAXCWND / 2; /* Initial send window */
nmp->nm_sent = 0;
} else if (nso->nso_sotype == SOCK_STREAM) {
nmp->nm_timeouts = 0;
}
if (error) {
NFS_SOCK_DBG("nfs connect %s socket %p setup failed %d\n",
- vfs_statfs(nmp->nm_mountp)->f_mntfromname, nso, error);
+ vfs_statfs(nmp->nm_mountp)->f_mntfromname, nso, error);
nfs_socket_search_update_error(&nss, error);
nmp->nm_saddr = oldsaddr;
if (!(nmp->nm_sockflags & NMSOCK_HASCONNECTED)) {
/* undo settings made prior to setup */
- if (!NFS_BITMAP_ISSET(nmp->nm_mattrs, NFS_MATTR_SOCKET_TYPE))
+ if (!NFS_BITMAP_ISSET(nmp->nm_mattrs, NFS_MATTR_SOCKET_TYPE)) {
nmp->nm_sotype = 0;
+ }
if (!NFS_BITMAP_ISSET(nmp->nm_mattrs, NFS_MATTR_NFS_VERSION)) {
if (nmp->nm_vers >= NFS_VER4) {
- if (!NFS_BITMAP_ISSET(nmp->nm_mattrs, NFS_MATTR_NFS_PORT))
+ if (!NFS_BITMAP_ISSET(nmp->nm_mattrs, NFS_MATTR_NFS_PORT)) {
nmp->nm_nfsport = 0;
- if (nmp->nm_cbid)
+ }
+ if (nmp->nm_cbid) {
nfs4_mount_callback_shutdown(nmp);
- if (IS_VALID_CRED(nmp->nm_mcred))
+ }
+ if (IS_VALID_CRED(nmp->nm_mcred)) {
kauth_cred_unref(&nmp->nm_mcred);
+ }
bzero(&nmp->nm_un, sizeof(nmp->nm_un));
}
nmp->nm_vers = 0;
}
lck_mtx_unlock(&nmp->nm_lock);
- if (oldsaddr)
+ if (oldsaddr) {
FREE(oldsaddr, M_SONAME);
+ }
- if (nss.nss_flags & NSS_WARNED)
+ if (nss.nss_flags & NSS_WARNED) {
log(LOG_INFO, "nfs_connect: socket connect completed for %s\n",
- vfs_statfs(nmp->nm_mountp)->f_mntfromname);
+ vfs_statfs(nmp->nm_mountp)->f_mntfromname);
+ }
nmp->nm_nss = NULL;
nfs_socket_search_cleanup(&nss);
- if (fh)
+ if (fh) {
FREE(fh, M_TEMP);
- if (path)
+ }
+ if (path) {
FREE_ZONE(path, MAXPATHLEN, M_NAMEI);
+ }
NFS_SOCK_DBG("nfs connect %s success\n", vfs_statfs(nmp->nm_mountp)->f_mntfromname);
- return (0);
+ return 0;
}
}
error = nfs4_setclientid(nmp);
}
- return (error);
+ return error;
}
/*
while ((error = nfs_connect(nmp, verbose, timeo))) {
verbose = 0;
nfs_disconnect(nmp);
- if ((error == EINTR) || (error == ERESTART))
- return (EINTR);
- if (error == EIO)
- return (EIO);
+ if ((error == EINTR) || (error == ERESTART)) {
+ return EINTR;
+ }
+ if (error == EIO) {
+ return EIO;
+ }
microuptime(&now);
if ((lastmsg + nmp->nm_tprintf_delay) < now.tv_sec) {
lastmsg = now.tv_sec;
/* we can't reconnect, so we fail */
lck_mtx_unlock(&nmp->nm_lock);
NFS_SOCK_DBG("Not mounted returning %d\n", error);
- return (error);
+ return error;
}
if (nfs_mount_check_dead_timeout(nmp)) {
nfs_mount_make_zombie(nmp);
lck_mtx_unlock(&nmp->nm_lock);
- return (ENXIO);
+ return ENXIO;
}
-
+
if ((error = nfs_sigintr(nmp, NULL, thd, 1))) {
lck_mtx_unlock(&nmp->nm_lock);
- return (error);
+ return error;
}
lck_mtx_unlock(&nmp->nm_lock);
- tsleep(nfs_reconnect, PSOCK, "nfs_reconnect_delay", 2*hz);
- if ((error = nfs_sigintr(nmp, NULL, thd, 0)))
- return (error);
+ tsleep(nfs_reconnect, PSOCK, "nfs_reconnect_delay", 2 * hz);
+ if ((error = nfs_sigintr(nmp, NULL, thd, 0))) {
+ return error;
+ }
}
- if (wentdown)
+ if (wentdown) {
nfs_up(nmp, thd, NFSSTA_TIMEO, "connected");
+ }
/*
* Loop through outstanding request list and mark all requests
rq->r_flags |= R_MUSTRESEND;
rq->r_rtt = -1;
wakeup(rq);
- if ((rq->r_flags & (R_IOD|R_ASYNC|R_ASYNCWAIT|R_SENDING)) == R_ASYNC)
+ if ((rq->r_flags & (R_IOD | R_ASYNC | R_ASYNCWAIT | R_SENDING)) == R_ASYNC) {
nfs_asyncio_resend(rq);
+ }
}
lck_mtx_unlock(&rq->r_mtx);
}
}
lck_mtx_unlock(nfs_request_mutex);
- return (0);
+ return 0;
}
/*
struct timespec ts = { 1, 0 };
if (nmp->nm_state & NFSSTA_SENDING) { /* wait for sending to complete */
nmp->nm_state |= NFSSTA_WANTSND;
- msleep(&nmp->nm_state, &nmp->nm_lock, PZERO-1, "nfswaitsending", &ts);
+ msleep(&nmp->nm_state, &nmp->nm_lock, PZERO - 1, "nfswaitsending", &ts);
goto tryagain;
}
if (nmp->nm_sockflags & NMSOCK_POKE) { /* wait for poking to complete */
- msleep(&nmp->nm_sockflags, &nmp->nm_lock, PZERO-1, "nfswaitpoke", &ts);
+ msleep(&nmp->nm_sockflags, &nmp->nm_lock, PZERO - 1, "nfswaitpoke", &ts);
goto tryagain;
}
nmp->nm_sockflags |= NMSOCK_DISCONNECTING;
nmp->nm_sockflags &= ~NMSOCK_READY;
nso = nmp->nm_nso;
nmp->nm_nso = NULL;
- if (nso->nso_saddr == nmp->nm_saddr)
+ if (nso->nso_saddr == nmp->nm_saddr) {
nso->nso_saddr = NULL;
+ }
lck_mtx_unlock(&nmp->nm_lock);
nfs_socket_destroy(nso);
lck_mtx_lock(&nmp->nm_lock);
struct nfsreq *rq;
lck_mtx_lock(&nmp->nm_lock);
- nmp->nm_sockflags &= ~(NMSOCK_READY|NMSOCK_SETUP);
+ nmp->nm_sockflags &= ~(NMSOCK_READY | NMSOCK_SETUP);
lck_mtx_unlock(&nmp->nm_lock);
/*
rq->r_flags |= R_MUSTRESEND;
rq->r_rtt = -1;
wakeup(rq);
- if ((rq->r_flags & (R_IOD|R_ASYNC|R_ASYNCWAIT|R_SENDING)) == R_ASYNC)
+ if ((rq->r_flags & (R_IOD | R_ASYNC | R_ASYNCWAIT | R_SENDING)) == R_ASYNC) {
nfs_asyncio_resend(rq);
+ }
}
lck_mtx_unlock(&rq->r_mtx);
}
lck_mtx_lock(&nmp->nm_lock);
while (!(nmp->nm_sockflags & NMSOCK_READY) ||
- !TAILQ_EMPTY(&nmp->nm_resendq) ||
- !LIST_EMPTY(&nmp->nm_monlist) ||
- nmp->nm_deadto_start ||
- (nmp->nm_state & NFSSTA_RECOVER) ||
- ((nmp->nm_vers >= NFS_VER4) && !TAILQ_EMPTY(&nmp->nm_dreturnq)))
- {
- if (nmp->nm_sockflags & NMSOCK_UNMOUNT)
+ !TAILQ_EMPTY(&nmp->nm_resendq) ||
+ !LIST_EMPTY(&nmp->nm_monlist) ||
+ nmp->nm_deadto_start ||
+ (nmp->nm_state & NFSSTA_RECOVER) ||
+ ((nmp->nm_vers >= NFS_VER4) && !TAILQ_EMPTY(&nmp->nm_dreturnq))) {
+ if (nmp->nm_sockflags & NMSOCK_UNMOUNT) {
break;
+ }
/* do reconnect, if necessary */
- if (!(nmp->nm_sockflags & NMSOCK_READY) && !(nmp->nm_state & (NFSSTA_FORCE|NFSSTA_DEAD))) {
+ if (!(nmp->nm_sockflags & NMSOCK_READY) && !(nmp->nm_state & (NFSSTA_FORCE | NFSSTA_DEAD))) {
if (nmp->nm_reconnect_start <= 0) {
microuptime(&now);
nmp->nm_reconnect_start = now.tv_sec;
lck_mtx_unlock(&nmp->nm_lock);
NFS_SOCK_DBG("nfs reconnect %s\n", vfs_statfs(nmp->nm_mountp)->f_mntfromname);
/*
- * XXX We don't want to call reconnect again right away if returned errors
+ * XXX We don't want to call reconnect again right away if returned errors
* before that may not have blocked. This has caused spamming null procs
* from machines in the pass.
*/
- if (do_reconnect_sleep)
+ if (do_reconnect_sleep) {
tsleep(nfs_mount_sock_thread, PSOCK, "nfs_reconnect_sock_thread_delay", hz);
+ }
error = nfs_reconnect(nmp);
if (error) {
int lvl = 7;
lvl = (do_reconnect_sleep++ % 600) ? 7 : 0;
}
nfs_printf(NFS_FAC_SOCK, lvl, "nfs reconnect %s: returned %d\n",
- vfs_statfs(nmp->nm_mountp)->f_mntfromname, error);
+ vfs_statfs(nmp->nm_mountp)->f_mntfromname, error);
} else {
nmp->nm_reconnect_start = 0;
do_reconnect_sleep = 0;
if ((nmp->nm_sockflags & NMSOCK_READY) &&
(nmp->nm_state & NFSSTA_RECOVER) &&
!(nmp->nm_sockflags & NMSOCK_UNMOUNT) &&
- !(nmp->nm_state & (NFSSTA_FORCE|NFSSTA_DEAD))) {
+ !(nmp->nm_state & (NFSSTA_FORCE | NFSSTA_DEAD))) {
/* perform state recovery */
lck_mtx_unlock(&nmp->nm_lock);
nfs_recover(nmp);
lck_mtx_lock(&nmp->nm_lock);
}
/* handle NFSv4 delegation returns */
- while ((nmp->nm_vers >= NFS_VER4) && !(nmp->nm_state & (NFSSTA_FORCE|NFSSTA_DEAD)) &&
- (nmp->nm_sockflags & NMSOCK_READY) && !(nmp->nm_state & NFSSTA_RECOVER) &&
- ((np = TAILQ_FIRST(&nmp->nm_dreturnq)))) {
+ while ((nmp->nm_vers >= NFS_VER4) && !(nmp->nm_state & (NFSSTA_FORCE | NFSSTA_DEAD)) &&
+ (nmp->nm_sockflags & NMSOCK_READY) && !(nmp->nm_state & NFSSTA_RECOVER) &&
+ ((np = TAILQ_FIRST(&nmp->nm_dreturnq)))) {
lck_mtx_unlock(&nmp->nm_lock);
nfs4_delegation_return(np, R_RECOVER, thd, nmp->nm_mcred);
lck_mtx_lock(&nmp->nm_lock);
}
/* do resends, if necessary/possible */
while ((((nmp->nm_sockflags & NMSOCK_READY) && !(nmp->nm_state & NFSSTA_RECOVER)) ||
- (nmp->nm_state & (NFSSTA_FORCE|NFSSTA_DEAD))) &&
- ((req = TAILQ_FIRST(&nmp->nm_resendq)))) {
- if (req->r_resendtime)
+ (nmp->nm_state & (NFSSTA_FORCE | NFSSTA_DEAD))) &&
+ ((req = TAILQ_FIRST(&nmp->nm_resendq)))) {
+ if (req->r_resendtime) {
microuptime(&now);
- while (req && !(nmp->nm_state & (NFSSTA_FORCE|NFSSTA_DEAD)) && req->r_resendtime && (now.tv_sec < req->r_resendtime))
+ }
+ while (req && !(nmp->nm_state & (NFSSTA_FORCE | NFSSTA_DEAD)) && req->r_resendtime && (now.tv_sec < req->r_resendtime)) {
req = TAILQ_NEXT(req, r_rchain);
- if (!req)
+ }
+ if (!req) {
break;
+ }
TAILQ_REMOVE(&nmp->nm_resendq, req, r_rchain);
req->r_rchain.tqe_next = NFSREQNOLIST;
lck_mtx_unlock(&nmp->nm_lock);
req->r_flags &= ~R_RESENDQ;
wakeup(req);
lck_mtx_unlock(&req->r_mtx);
- if (dofinish)
+ if (dofinish) {
nfs_asyncio_finish(req);
+ }
nfs_request_rele(req);
lck_mtx_lock(&nmp->nm_lock);
continue;
if (nfs_request_using_gss(req)) {
nfs_gss_clnt_rpcdone(req);
error = nfs_gss_clnt_args_restore(req);
- if (error == ENEEDAUTH)
+ if (error == ENEEDAUTH) {
req->r_xid = 0;
+ }
}
NFS_SOCK_DBG("nfs async%s restart: p %d x 0x%llx f 0x%x rtt %d\n",
- nfs_request_using_gss(req) ? " gss" : "", req->r_procnum, req->r_xid,
- req->r_flags, req->r_rtt);
+ nfs_request_using_gss(req) ? " gss" : "", req->r_procnum, req->r_xid,
+ req->r_flags, req->r_rtt);
error = nfs_sigintr(nmp, req, req->r_thread, 0);
- if (!error)
+ if (!error) {
error = nfs_request_add_header(req);
- if (!error)
+ }
+ if (!error) {
error = nfs_request_send(req, 0);
+ }
lck_mtx_lock(&req->r_mtx);
- if (req->r_flags & R_RESENDQ)
+ if (req->r_flags & R_RESENDQ) {
req->r_flags &= ~R_RESENDQ;
- if (error)
+ }
+ if (error) {
req->r_error = error;
+ }
wakeup(req);
dofinish = error && req->r_callback.rcb_func && !(req->r_flags & R_WAITSENT);
lck_mtx_unlock(&req->r_mtx);
- if (dofinish)
+ if (dofinish) {
nfs_asyncio_finish(req);
+ }
nfs_request_rele(req);
lck_mtx_lock(&nmp->nm_lock);
error = 0;
continue;
}
NFS_SOCK_DBG("nfs async resend: p %d x 0x%llx f 0x%x rtt %d\n",
- req->r_procnum, req->r_xid, req->r_flags, req->r_rtt);
+ req->r_procnum, req->r_xid, req->r_flags, req->r_rtt);
error = nfs_sigintr(nmp, req, req->r_thread, 0);
if (!error) {
req->r_flags |= R_SENDING;
error = nfs_send(req, 0);
lck_mtx_lock(&req->r_mtx);
if (!error) {
- if (req->r_flags & R_RESENDQ)
+ if (req->r_flags & R_RESENDQ) {
req->r_flags &= ~R_RESENDQ;
+ }
wakeup(req);
lck_mtx_unlock(&req->r_mtx);
nfs_request_rele(req);
}
}
req->r_error = error;
- if (req->r_flags & R_RESENDQ)
+ if (req->r_flags & R_RESENDQ) {
req->r_flags &= ~R_RESENDQ;
+ }
wakeup(req);
dofinish = req->r_callback.rcb_func && !(req->r_flags & R_WAITSENT);
lck_mtx_unlock(&req->r_mtx);
- if (dofinish)
+ if (dofinish) {
nfs_asyncio_finish(req);
+ }
nfs_request_rele(req);
lck_mtx_lock(&nmp->nm_lock);
}
nfs_mount_make_zombie(nmp);
break;
}
-
- if (nmp->nm_state & (NFSSTA_FORCE|NFSSTA_DEAD))
+
+ if (nmp->nm_state & (NFSSTA_FORCE | NFSSTA_DEAD)) {
break;
+ }
/* check monitored nodes, if necessary/possible */
if (!LIST_EMPTY(&nmp->nm_monlist)) {
nmp->nm_state |= NFSSTA_MONITOR_SCAN;
LIST_FOREACH(np, &nmp->nm_monlist, n_monlink) {
if (!(nmp->nm_sockflags & NMSOCK_READY) ||
- (nmp->nm_state & (NFSSTA_RECOVER|NFSSTA_UNMOUNTING|NFSSTA_FORCE|NFSSTA_DEAD)))
+ (nmp->nm_state & (NFSSTA_RECOVER | NFSSTA_UNMOUNTING | NFSSTA_FORCE | NFSSTA_DEAD))) {
break;
+ }
np->n_mflag |= NMMONSCANINPROG;
lck_mtx_unlock(&nmp->nm_lock);
- error = nfs_getattr(np, NULL, vfs_context_kernel(), (NGA_UNCACHED|NGA_MONITOR));
- if (!error && ISSET(np->n_flag, NUPDATESIZE)) /* update quickly to avoid multiple events */
+ error = nfs_getattr(np, NULL, vfs_context_kernel(), (NGA_UNCACHED | NGA_MONITOR));
+ if (!error && ISSET(np->n_flag, NUPDATESIZE)) { /* update quickly to avoid multiple events */
nfs_data_update_size(np, 0);
+ }
lck_mtx_lock(&nmp->nm_lock);
np->n_mflag &= ~NMMONSCANINPROG;
if (np->n_mflag & NMMONSCANWANT) {
wakeup(&np->n_mflag);
}
if (error || !(nmp->nm_sockflags & NMSOCK_READY) ||
- (nmp->nm_state & (NFSSTA_RECOVER|NFSSTA_UNMOUNTING|NFSSTA_FORCE|NFSSTA_DEAD)))
+ (nmp->nm_state & (NFSSTA_RECOVER | NFSSTA_UNMOUNTING | NFSSTA_FORCE | NFSSTA_DEAD))) {
break;
+ }
}
nmp->nm_state &= ~NFSSTA_MONITOR_SCAN;
- if (nmp->nm_state & NFSSTA_UNMOUNTING)
+ if (nmp->nm_state & NFSSTA_UNMOUNTING) {
wakeup(&nmp->nm_state); /* let unmounting thread know scan is done */
+ }
}
- if ((nmp->nm_sockflags & NMSOCK_READY) || (nmp->nm_state & (NFSSTA_RECOVER|NFSSTA_UNMOUNTING))) {
+ if ((nmp->nm_sockflags & NMSOCK_READY) || (nmp->nm_state & (NFSSTA_RECOVER | NFSSTA_UNMOUNTING))) {
if (nmp->nm_deadto_start || !TAILQ_EMPTY(&nmp->nm_resendq) ||
- (nmp->nm_state & NFSSTA_RECOVER))
+ (nmp->nm_state & NFSSTA_RECOVER)) {
ts.tv_sec = 1;
- else
+ } else {
ts.tv_sec = 5;
+ }
msleep(&nmp->nm_sockthd, &nmp->nm_lock, PSOCK, "nfssockthread", &ts);
}
}
/* If we're unmounting, send the unmount RPC, if requested/appropriate. */
if ((nmp->nm_sockflags & NMSOCK_UNMOUNT) &&
(nmp->nm_state & NFSSTA_MOUNTED) && NMFLAG(nmp, CALLUMNT) &&
- (nmp->nm_vers < NFS_VER4) && !(nmp->nm_state & (NFSSTA_FORCE|NFSSTA_DEAD))) {
+ (nmp->nm_vers < NFS_VER4) && !(nmp->nm_state & (NFSSTA_FORCE | NFSSTA_DEAD))) {
lck_mtx_unlock(&nmp->nm_lock);
nfs3_umount_rpc(nmp, vfs_context_kernel(),
- (nmp->nm_sockflags & NMSOCK_READY) ? 6 : 2);
+ (nmp->nm_sockflags & NMSOCK_READY) ? 6 : 2);
lck_mtx_lock(&nmp->nm_lock);
}
- if (nmp->nm_sockthd == thd)
+ if (nmp->nm_sockthd == thd) {
nmp->nm_sockthd = NULL;
+ }
lck_mtx_unlock(&nmp->nm_lock);
wakeup(&nmp->nm_sockthd);
thread_terminate(thd);
void
nfs_mount_sock_thread_wake(struct nfsmount *nmp)
{
- if (nmp->nm_sockthd)
+ if (nmp->nm_sockthd) {
wakeup(&nmp->nm_sockthd);
- else if (kernel_thread_start(nfs_mount_sock_thread, nmp, &nmp->nm_sockthd) == KERN_SUCCESS)
+ } else if (kernel_thread_start(nfs_mount_sock_thread, nmp, &nmp->nm_sockthd) == KERN_SUCCESS) {
thread_deallocate(nmp->nm_sockthd);
+ }
}
/*
{
struct timeval now;
- if (nmp->nm_state & NFSSTA_DEAD)
+ if (nmp->nm_state & NFSSTA_DEAD) {
return 1;
- if (nmp->nm_deadto_start == 0)
+ }
+ if (nmp->nm_deadto_start == 0) {
return 0;
+ }
nfs_is_squishy(nmp);
- if (nmp->nm_curdeadtimeout <= 0)
+ if (nmp->nm_curdeadtimeout <= 0) {
return 0;
+ }
microuptime(&now);
- if ((now.tv_sec - nmp->nm_deadto_start) < nmp->nm_curdeadtimeout)
+ if ((now.tv_sec - nmp->nm_deadto_start) < nmp->nm_curdeadtimeout) {
return 0;
+ }
return 1;
}
nfs_mount_make_zombie(struct nfsmount *nmp)
{
fsid_t fsid;
-
- if (!nmp)
+
+ if (!nmp) {
return;
+ }
- if (nmp->nm_state & NFSSTA_DEAD)
+ if (nmp->nm_state & NFSSTA_DEAD) {
return;
+ }
printf("nfs server %s: %sdead\n", vfs_statfs(nmp->nm_mountp)->f_mntfromname,
- (nmp->nm_curdeadtimeout != nmp->nm_deadtimeout) ? "squished " : "");
+ (nmp->nm_curdeadtimeout != nmp->nm_deadtimeout) ? "squished " : "");
fsid = vfs_statfs(nmp->nm_mountp)->f_fsid;
lck_mtx_unlock(&nmp->nm_lock);
nfs_mount_zombie(nmp, NFSSTA_DEAD);
/*
* NFS callback channel socket state
*/
-struct nfs_callback_socket
-{
+struct nfs_callback_socket {
TAILQ_ENTRY(nfs_callback_socket) ncbs_link;
- socket_t ncbs_so; /* the socket */
- struct sockaddr_storage ncbs_saddr; /* socket address */
- struct nfs_rpc_record_state ncbs_rrs; /* RPC record parsing state */
- time_t ncbs_stamp; /* last accessed at */
- uint32_t ncbs_flags; /* see below */
+ socket_t ncbs_so; /* the socket */
+ struct sockaddr_storage ncbs_saddr; /* socket address */
+ struct nfs_rpc_record_state ncbs_rrs; /* RPC record parsing state */
+ time_t ncbs_stamp; /* last accessed at */
+ uint32_t ncbs_flags; /* see below */
};
-#define NCBSOCK_UPCALL 0x0001
-#define NCBSOCK_UPCALLWANT 0x0002
-#define NCBSOCK_DEAD 0x0004
+#define NCBSOCK_UPCALL 0x0001
+#define NCBSOCK_UPCALLWANT 0x0002
+#define NCBSOCK_DEAD 0x0004
/*
* NFS callback channel state
in_port_t nfs4_cb_port6 = 0;
uint32_t nfs4_cb_id = 0;
uint32_t nfs4_cb_so_usecount = 0;
-TAILQ_HEAD(nfs4_cb_sock_list,nfs_callback_socket) nfs4_cb_socks;
-TAILQ_HEAD(nfs4_cb_mount_list,nfsmount) nfs4_cb_mounts;
+TAILQ_HEAD(nfs4_cb_sock_list, nfs_callback_socket) nfs4_cb_socks;
+TAILQ_HEAD(nfs4_cb_mount_list, nfsmount) nfs4_cb_mounts;
int nfs4_cb_handler(struct nfs_callback_socket *, mbuf_t);
nfs4_cb_id++;
}
nmp->nm_cbid = nfs4_cb_id++;
- if (nmp->nm_cbid == 0)
+ if (nmp->nm_cbid == 0) {
nmp->nm_cbid = nfs4_cb_id++;
+ }
nfs4_cb_so_usecount++;
TAILQ_INSERT_HEAD(&nfs4_cb_mounts, nmp, nm_cblink);
timeo.tv_usec = 0;
timeo.tv_sec = 60;
error = sock_setsockopt(so, SOL_SOCKET, SO_RCVTIMEO, &timeo, sizeof(timeo));
- if (error)
+ if (error) {
log(LOG_INFO, "nfs callback setup: error %d setting IPv4 socket rx timeout\n", error);
+ }
error = sock_setsockopt(so, SOL_SOCKET, SO_SNDTIMEO, &timeo, sizeof(timeo));
- if (error)
+ if (error) {
log(LOG_INFO, "nfs callback setup: error %d setting IPv4 socket tx timeout\n", error);
+ }
sock_setsockopt(so, IPPROTO_TCP, TCP_NODELAY, &on, sizeof(on));
sock_setsockopt(so, SOL_SOCKET, SO_NOADDRERR, &on, sizeof(on));
sock_setsockopt(so, SOL_SOCKET, SO_UPCALLCLOSEWAIT, &on, sizeof(on));
timeo.tv_usec = 0;
timeo.tv_sec = 60;
error = sock_setsockopt(so6, SOL_SOCKET, SO_RCVTIMEO, &timeo, sizeof(timeo));
- if (error)
+ if (error) {
log(LOG_INFO, "nfs callback setup: error %d setting IPv6 socket rx timeout\n", error);
+ }
error = sock_setsockopt(so6, SOL_SOCKET, SO_SNDTIMEO, &timeo, sizeof(timeo));
- if (error)
+ if (error) {
log(LOG_INFO, "nfs callback setup: error %d setting IPv6 socket tx timeout\n", error);
+ }
sock_setsockopt(so6, IPPROTO_TCP, TCP_NODELAY, &on, sizeof(on));
sock_setsockopt(so6, SOL_SOCKET, SO_NOADDRERR, &on, sizeof(on));
sock_setsockopt(so6, SOL_SOCKET, SO_UPCALLCLOSEWAIT, &on, sizeof(on));
struct nfs_callback_socket *ncbsp;
socket_t so, so6;
struct nfs4_cb_sock_list cb_socks;
- struct timespec ts = {1,0};
+ struct timespec ts = {1, 0};
lck_mtx_lock(nfs_global_mutex);
TAILQ_REMOVE(&nfs4_cb_mounts, nmp, nm_cblink);
/* wait for any callbacks in progress to complete */
- while (nmp->nm_cbrefs)
+ while (nmp->nm_cbrefs) {
msleep(&nmp->nm_cbrefs, nfs_global_mutex, PSOCK, "cbshutwait", &ts);
+ }
nmp->nm_cbid = 0;
if (--nfs4_cb_so_usecount) {
lck_mtx_unlock(nfs_global_mutex);
/*
* Check periodically for stale/unused nfs callback sockets
*/
-#define NFS4_CB_TIMER_PERIOD 30
-#define NFS4_CB_IDLE_MAX 300
+#define NFS4_CB_TIMER_PERIOD 30
+#define NFS4_CB_IDLE_MAX 300
void
nfs4_callback_timer(__unused void *param0, __unused void *param1)
{
microuptime(&now);
TAILQ_FOREACH_SAFE(ncbsp, &nfs4_cb_socks, ncbs_link, nextncbsp) {
if (!(ncbsp->ncbs_flags & NCBSOCK_DEAD) &&
- (now.tv_sec < (ncbsp->ncbs_stamp + NFS4_CB_IDLE_MAX)))
+ (now.tv_sec < (ncbsp->ncbs_stamp + NFS4_CB_IDLE_MAX))) {
continue;
+ }
TAILQ_REMOVE(&nfs4_cb_socks, ncbsp, ncbs_link);
lck_mtx_unlock(nfs_global_mutex);
sock_shutdown(ncbsp->ncbs_so, SHUT_RDWR);
}
nfs4_callback_timer_on = 1;
nfs_interval_timer_start(nfs4_callback_timer_call,
- NFS4_CB_TIMER_PERIOD * 1000);
+ NFS4_CB_TIMER_PERIOD * 1000);
lck_mtx_unlock(nfs_global_mutex);
}
struct timeval timeo, now;
int error, on = 1, ip;
- if (so == nfs4_cb_so)
+ if (so == nfs4_cb_so) {
ip = 4;
- else if (so == nfs4_cb_so6)
+ } else if (so == nfs4_cb_so6) {
ip = 6;
- else
+ } else {
return;
+ }
/* allocate/initialize a new nfs_callback_socket */
MALLOC(ncbsp, struct nfs_callback_socket *, sizeof(struct nfs_callback_socket), M_TEMP, M_WAITOK);
/* accept a new socket */
error = sock_accept(so, (struct sockaddr*)&ncbsp->ncbs_saddr,
- ncbsp->ncbs_saddr.ss_len, MSG_DONTWAIT,
- nfs4_cb_rcv, ncbsp, &newso);
+ ncbsp->ncbs_saddr.ss_len, MSG_DONTWAIT,
+ nfs4_cb_rcv, ncbsp, &newso);
if (error) {
log(LOG_INFO, "nfs callback accept: error %d accepting IPv%d socket\n", error, ip);
FREE(ncbsp, M_TEMP);
timeo.tv_usec = 0;
timeo.tv_sec = 60;
error = sock_setsockopt(newso, SOL_SOCKET, SO_RCVTIMEO, &timeo, sizeof(timeo));
- if (error)
+ if (error) {
log(LOG_INFO, "nfs callback socket: error %d setting IPv%d socket rx timeout\n", error, ip);
+ }
error = sock_setsockopt(newso, SOL_SOCKET, SO_SNDTIMEO, &timeo, sizeof(timeo));
- if (error)
+ if (error) {
log(LOG_INFO, "nfs callback socket: error %d setting IPv%d socket tx timeout\n", error, ip);
+ }
sock_setsockopt(newso, IPPROTO_TCP, TCP_NODELAY, &on, sizeof(on));
sock_setsockopt(newso, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
sock_setsockopt(newso, SOL_SOCKET, SO_NOADDRERR, &on, sizeof(on));
/* verify it's from a host we have mounted */
TAILQ_FOREACH(nmp, &nfs4_cb_mounts, nm_cblink) {
/* check if socket's source address matches this mount's server address */
- if (!nmp->nm_saddr)
+ if (!nmp->nm_saddr) {
continue;
- if (nfs_sockaddr_cmp((struct sockaddr*)&ncbsp->ncbs_saddr, nmp->nm_saddr) == 0)
+ }
+ if (nfs_sockaddr_cmp((struct sockaddr*)&ncbsp->ncbs_saddr, nmp->nm_saddr) == 0) {
break;
+ }
}
- if (!nmp) /* we don't want this socket, mark it dead */
+ if (!nmp) { /* we don't want this socket, mark it dead */
ncbsp->ncbs_flags |= NCBSOCK_DEAD;
+ }
/* make sure the callback socket cleanup timer is running */
/* (shorten the timer if we've got a socket we don't want) */
if (!nfs4_callback_timer_on) {
nfs4_callback_timer_on = 1;
nfs_interval_timer_start(nfs4_callback_timer_call,
- !nmp ? 500 : (NFS4_CB_TIMER_PERIOD * 1000));
+ !nmp ? 500 : (NFS4_CB_TIMER_PERIOD * 1000));
} else if (!nmp && (nfs4_callback_timer_on < 2)) {
nfs4_callback_timer_on = 2;
thread_call_cancel(nfs4_callback_timer_call);
nfs4_cb_rcv(socket_t so, void *arg, __unused int waitflag)
{
struct nfs_callback_socket *ncbsp = arg;
- struct timespec ts = {1,0};
+ struct timespec ts = {1, 0};
struct timeval now;
mbuf_t m;
int error = 0, recv = 1;
/* loop while we make error-free progress */
while (!error && recv) {
error = nfs_rpc_record_read(so, &ncbsp->ncbs_rrs, MSG_DONTWAIT, &recv, &m);
- if (m) /* handle the request */
+ if (m) { /* handle the request */
error = nfs4_cb_handler(ncbsp, m);
+ }
}
/* note: no error and no data indicates server closed its end */
xid = numops = op = status = procnum = taglen = cbid = 0;
nfsm_chain_dissect_init(error, &nmreq, mreq);
- nfsm_chain_get_32(error, &nmreq, xid); // RPC XID
- nfsm_chain_get_32(error, &nmreq, val); // RPC Call
+ nfsm_chain_get_32(error, &nmreq, xid); // RPC XID
+ nfsm_chain_get_32(error, &nmreq, val); // RPC Call
nfsm_assert(error, (val == RPC_CALL), EBADRPC);
- nfsm_chain_get_32(error, &nmreq, val); // RPC Version
+ nfsm_chain_get_32(error, &nmreq, val); // RPC Version
nfsm_assert(error, (val == RPC_VER2), ERPCMISMATCH);
- nfsm_chain_get_32(error, &nmreq, val); // RPC Program Number
+ nfsm_chain_get_32(error, &nmreq, val); // RPC Program Number
nfsm_assert(error, (val == NFS4_CALLBACK_PROG), EPROGUNAVAIL);
- nfsm_chain_get_32(error, &nmreq, val); // NFS Callback Program Version Number
+ nfsm_chain_get_32(error, &nmreq, val); // NFS Callback Program Version Number
nfsm_assert(error, (val == NFS4_CALLBACK_PROG_VERSION), EPROGMISMATCH);
- nfsm_chain_get_32(error, &nmreq, procnum); // NFS Callback Procedure Number
+ nfsm_chain_get_32(error, &nmreq, procnum); // NFS Callback Procedure Number
nfsm_assert(error, (procnum <= NFSPROC4_CB_COMPOUND), EPROCUNAVAIL);
/* Handle authentication */
/* XXX just ignore auth for now - handling kerberos may be tricky */
- nfsm_chain_get_32(error, &nmreq, auth_type); // RPC Auth Flavor
- nfsm_chain_get_32(error, &nmreq, auth_len); // RPC Auth Length
+ nfsm_chain_get_32(error, &nmreq, auth_type); // RPC Auth Flavor
+ nfsm_chain_get_32(error, &nmreq, auth_len); // RPC Auth Length
nfsm_assert(error, (auth_len <= RPCAUTH_MAXSIZ), EBADRPC);
- if (!error && (auth_len > 0))
+ if (!error && (auth_len > 0)) {
nfsm_chain_adv(error, &nmreq, nfsm_rndup(auth_len));
- nfsm_chain_adv(error, &nmreq, NFSX_UNSIGNED); // verifier flavor (should be AUTH_NONE)
- nfsm_chain_get_32(error, &nmreq, auth_len); // verifier length
+ }
+ nfsm_chain_adv(error, &nmreq, NFSX_UNSIGNED); // verifier flavor (should be AUTH_NONE)
+ nfsm_chain_get_32(error, &nmreq, auth_len); // verifier length
nfsm_assert(error, (auth_len <= RPCAUTH_MAXSIZ), EBADRPC);
- if (!error && (auth_len > 0))
+ if (!error && (auth_len > 0)) {
nfsm_chain_adv(error, &nmreq, nfsm_rndup(auth_len));
+ }
if (error) {
status = error;
error = 0;
break;
case NFSPROC4_CB_COMPOUND:
/* tag, minorversion, cb ident, numops, op array */
- nfsm_chain_get_32(error, &nmreq, taglen); /* tag length */
+ nfsm_chain_get_32(error, &nmreq, taglen); /* tag length */
nfsm_assert(error, (val <= NFS4_OPAQUE_LIMIT), EBADRPC);
/* start building the body of the response */
- nfsm_mbuf_get(error, &mrest, nfsm_rndup(taglen) + 5*NFSX_UNSIGNED);
+ nfsm_mbuf_get(error, &mrest, nfsm_rndup(taglen) + 5 * NFSX_UNSIGNED);
nfsm_chain_init(&nmrep, mrest);
/* copy tag from request to response */
- nfsm_chain_add_32(error, &nmrep, taglen); /* tag length */
+ nfsm_chain_add_32(error, &nmrep, taglen); /* tag length */
for (len = (int)taglen; !error && (len > 0); len -= NFSX_UNSIGNED) {
nfsm_chain_get_32(error, &nmreq, val);
nfsm_chain_add_32(error, &nmrep, val);
nfsm_chain_add_32(error, &nmrep, numres);
pnumres = (uint32_t*)(nmrep.nmc_ptr - NFSX_UNSIGNED);
- nfsm_chain_get_32(error, &nmreq, val); /* minorversion */
+ nfsm_chain_get_32(error, &nmreq, val); /* minorversion */
nfsm_assert(error, (val == 0), NFSERR_MINOR_VERS_MISMATCH);
- nfsm_chain_get_32(error, &nmreq, cbid); /* callback ID */
- nfsm_chain_get_32(error, &nmreq, numops); /* number of operations */
+ nfsm_chain_get_32(error, &nmreq, cbid); /* callback ID */
+ nfsm_chain_get_32(error, &nmreq, numops); /* number of operations */
if (error) {
- if ((error == EBADRPC) || (error == NFSERR_MINOR_VERS_MISMATCH))
+ if ((error == EBADRPC) || (error == NFSERR_MINOR_VERS_MISMATCH)) {
status = error;
- else if ((error == ENOBUFS) || (error == ENOMEM))
+ } else if ((error == ENOBUFS) || (error == ENOMEM)) {
status = NFSERR_RESOURCE;
- else
+ } else {
status = NFSERR_SERVERFAULT;
+ }
error = 0;
nfsm_chain_null(&nmrep);
goto nfsmout;
/* match the callback ID to a registered mount */
lck_mtx_lock(nfs_global_mutex);
TAILQ_FOREACH(nmp, &nfs4_cb_mounts, nm_cblink) {
- if (nmp->nm_cbid != cbid)
+ if (nmp->nm_cbid != cbid) {
continue;
+ }
/* verify socket's source address matches this mount's server address */
- if (!nmp->nm_saddr)
+ if (!nmp->nm_saddr) {
continue;
- if (nfs_sockaddr_cmp((struct sockaddr*)&ncbsp->ncbs_saddr, nmp->nm_saddr) == 0)
+ }
+ if (nfs_sockaddr_cmp((struct sockaddr*)&ncbsp->ncbs_saddr, nmp->nm_saddr) == 0) {
break;
+ }
}
/* mark the NFS mount as busy */
- if (nmp)
+ if (nmp) {
nmp->nm_cbrefs++;
+ }
lck_mtx_unlock(nfs_global_mutex);
if (!nmp) {
/* if no mount match, just drop socket. */
while (numops > 0) {
numops--;
nfsm_chain_get_32(error, &nmreq, op);
- if (error)
+ if (error) {
break;
+ }
switch (op) {
case NFS_OP_CB_GETATTR:
// (FH, BITMAP) -> (STATUS, BITMAP, ATTRS)
}
nfsm_chain_add_32(error, &nmrep, op);
nfsm_chain_add_32(error, &nmrep, status);
- if (!error && (status == EBADRPC))
+ if (!error && (status == EBADRPC)) {
error = status;
+ }
if (np) {
/* only allow returning size, change, and mtime attrs */
NFS_CLEAR_ATTRIBUTES(&rbitmap);
}
nfsm_chain_add_bitmap(error, &nmrep, rbitmap, NFS_ATTR_BITMAP_LEN);
nfsm_chain_add_32(error, &nmrep, attrbytes);
- if (NFS_BITMAP_ISSET(&bitmap, NFS_FATTR_CHANGE))
+ if (NFS_BITMAP_ISSET(&bitmap, NFS_FATTR_CHANGE)) {
nfsm_chain_add_64(error, &nmrep,
- np->n_vattr.nva_change + ((np->n_flag & NMODIFIED) ? 1 : 0));
- if (NFS_BITMAP_ISSET(&bitmap, NFS_FATTR_SIZE))
+ np->n_vattr.nva_change + ((np->n_flag & NMODIFIED) ? 1 : 0));
+ }
+ if (NFS_BITMAP_ISSET(&bitmap, NFS_FATTR_SIZE)) {
nfsm_chain_add_64(error, &nmrep, np->n_size);
+ }
if (NFS_BITMAP_ISSET(&bitmap, NFS_FATTR_TIME_MODIFY)) {
nfsm_chain_add_64(error, &nmrep, np->n_vattr.nva_timesec[NFSTIME_MODIFY]);
nfsm_chain_add_32(error, &nmrep, np->n_vattr.nva_timensec[NFSTIME_MODIFY]);
np = NULL;
numops = 0; /* don't process any more ops */
} else if (!(np->n_openflags & N_DELEG_MASK) ||
- bcmp(&np->n_dstateid, &stateid, sizeof(stateid))) {
+ bcmp(&np->n_dstateid, &stateid, sizeof(stateid))) {
/* delegation stateid state doesn't match */
status = NFSERR_BAD_STATEID;
numops = 0; /* don't process any more ops */
}
- if (!status) /* add node to recall queue, and wake socket thread */
+ if (!status) { /* add node to recall queue, and wake socket thread */
nfs4_delegation_return_enqueue(np);
+ }
if (np) {
nfs_node_unlock(np);
vnode_put(NFSTOV(np));
}
nfsm_chain_add_32(error, &nmrep, op);
nfsm_chain_add_32(error, &nmrep, status);
- if (!error && (status == EBADRPC))
+ if (!error && (status == EBADRPC)) {
error = status;
+ }
break;
case NFS_OP_CB_ILLEGAL:
default:
}
if (!status && error) {
- if (error == EBADRPC)
+ if (error == EBADRPC) {
status = error;
- else if ((error == ENOBUFS) || (error == ENOMEM))
+ } else if ((error == ENOBUFS) || (error == ENOMEM)) {
status = NFSERR_RESOURCE;
- else
+ } else {
status = NFSERR_SERVERFAULT;
+ }
error = 0;
}
/* drop the callback reference on the mount */
lck_mtx_lock(nfs_global_mutex);
nmp->nm_cbrefs--;
- if (!nmp->nm_cbid)
+ if (!nmp->nm_cbid) {
wakeup(&nmp->nm_cbrefs);
+ }
lck_mtx_unlock(nfs_global_mutex);
break;
}
nfsmout:
- if (status == EBADRPC)
+ if (status == EBADRPC) {
OSAddAtomic64(1, &nfsstats.rpcinvalid);
+ }
/* build reply header */
error = mbuf_gethdr(MBUF_WAITOK, MBUF_TYPE_DATA, &mhead);
break;
default:
nfsm_chain_add_32(error, &nmrep, RPC_SUCCESS);
- if (status != NFSERR_RETVOID)
+ if (status != NFSERR_RETVOID) {
nfsm_chain_add_32(error, &nmrep, status);
+ }
break;
}
}
mrest = NULL;
/* Calculate the size of the reply */
replen = 0;
- for (m = nmrep.nmc_mhead; m; m = mbuf_next(m))
+ for (m = nmrep.nmc_mhead; m; m = mbuf_next(m)) {
replen += mbuf_len(m);
+ }
mbuf_pkthdr_setlen(mhead, replen);
error = mbuf_pkthdr_setrcvif(mhead, NULL);
nfsm_chain_set_recmark(error, &nmrep, (replen - NFSX_UNSIGNED) | 0x80000000);
bzero(&msg, sizeof(msg));
error = sock_sendmbuf(so, &msg, mhead, 0, &sentlen);
mhead = NULL;
- if (!error && ((int)sentlen != replen))
+ if (!error && ((int)sentlen != replen)) {
error = EWOULDBLOCK;
- if (error == EWOULDBLOCK) /* inability to send response is considered fatal */
+ }
+ if (error == EWOULDBLOCK) { /* inability to send response is considered fatal */
error = ETIMEDOUT;
+ }
out:
- if (error)
+ if (error) {
nfsm_chain_cleanup(&nmrep);
- if (mhead)
+ }
+ if (mhead) {
mbuf_freem(mhead);
- if (mrest)
+ }
+ if (mrest) {
mbuf_freem(mrest);
- if (mreq)
+ }
+ if (mreq) {
mbuf_freem(mreq);
- return (error);
+ }
+ return error;
}
/* read the TCP RPC record marker */
while (!error && nrrsp->nrrs_markerleft) {
aio.iov_base = ((char*)&nrrsp->nrrs_fragleft +
- sizeof(nrrsp->nrrs_fragleft) - nrrsp->nrrs_markerleft);
+ sizeof(nrrsp->nrrs_fragleft) - nrrsp->nrrs_markerleft);
aio.iov_len = nrrsp->nrrs_markerleft;
bzero(&msg, sizeof(msg));
msg.msg_iov = &aio;
msg.msg_iovlen = 1;
error = sock_receive(so, &msg, flags, &rcvlen);
- if (error || !rcvlen)
+ if (error || !rcvlen) {
break;
+ }
*recvp = 1;
nrrsp->nrrs_markerleft -= rcvlen;
- if (nrrsp->nrrs_markerleft)
+ if (nrrsp->nrrs_markerleft) {
continue;
+ }
/* record marker complete */
nrrsp->nrrs_fragleft = ntohl(nrrsp->nrrs_fragleft);
if (nrrsp->nrrs_fragleft & 0x80000000) {
m = NULL;
rcvlen = nrrsp->nrrs_fragleft;
error = sock_receivembuf(so, NULL, &m, flags, &rcvlen);
- if (error || !rcvlen || !m)
+ if (error || !rcvlen || !m) {
break;
+ }
*recvp = 1;
/* append mbufs to list */
nrrsp->nrrs_fragleft -= rcvlen;
break;
}
}
- while (mbuf_next(m))
+ while (mbuf_next(m)) {
m = mbuf_next(m);
+ }
nrrsp->nrrs_mlast = m;
}
}
}
- return (error);
+ return error;
}
req->r_error = error;
req->r_flags &= ~R_SENDING;
lck_mtx_unlock(&req->r_mtx);
- return (error);
+ return error;
}
error = nfs_sigintr(req->r_nmp, req, NULL, 0);
req->r_error = error;
req->r_flags &= ~R_SENDING;
lck_mtx_unlock(&req->r_mtx);
- return (error);
+ return error;
}
nmp = req->r_nmp;
sotype = nmp->nm_sotype;
req->r_error = error;
req->r_flags &= ~R_SENDING;
lck_mtx_unlock(&req->r_mtx);
- return (error);
+ return error;
}
/* If the socket needs reconnection, do that now. */
lck_mtx_lock(&nmp->nm_lock);
if (!(nmp->nm_sockflags & NMSOCK_READY) &&
!((nmp->nm_sockflags & NMSOCK_SETUP) && (req->r_flags & R_SETUP))) {
- if (NMFLAG(nmp, INTR) && !(req->r_flags & R_NOINTR))
+ if (NMFLAG(nmp, INTR) && !(req->r_flags & R_NOINTR)) {
slpflag |= PCATCH;
+ }
lck_mtx_unlock(&nmp->nm_lock);
nfs_sndunlock(req);
if (!wait) {
req->r_flags |= R_MUSTRESEND;
req->r_rtt = 0;
lck_mtx_unlock(&req->r_mtx);
- return (0);
+ return 0;
}
NFS_SOCK_DBG("nfs_send: 0x%llx wait reconnect\n", req->r_xid);
lck_mtx_lock(&req->r_mtx);
lck_mtx_lock(&nmp->nm_lock);
while (!(nmp->nm_sockflags & NMSOCK_READY)) {
/* don't bother waiting if the socket thread won't be reconnecting it */
- if (nmp->nm_state & (NFSSTA_FORCE|NFSSTA_DEAD)) {
+ if (nmp->nm_state & (NFSSTA_FORCE | NFSSTA_DEAD)) {
error = EIO;
break;
}
}
/* make sure socket thread is running, then wait */
nfs_mount_sock_thread_wake(nmp);
- if ((error = nfs_sigintr(req->r_nmp, req, req->r_thread, 1)))
+ if ((error = nfs_sigintr(req->r_nmp, req, req->r_thread, 1))) {
break;
- msleep(req, &nmp->nm_lock, slpflag|PSOCK, "nfsconnectwait", &ts);
+ }
+ msleep(req, &nmp->nm_lock, slpflag | PSOCK, "nfsconnectwait", &ts);
slpflag = 0;
}
lck_mtx_unlock(&nmp->nm_lock);
req->r_error = error;
req->r_flags &= ~R_SENDING;
lck_mtx_unlock(&req->r_mtx);
- return (error);
+ return error;
}
goto again;
}
req->r_flags |= R_MUSTRESEND;
req->r_rtt = 0;
lck_mtx_unlock(&req->r_mtx);
- return (0);
+ return 0;
}
lck_mtx_lock(&req->r_mtx);
lck_mtx_unlock(&req->r_mtx);
if (!wait) {
req->r_rtt = 0;
- return (0);
+ return 0;
}
lck_mtx_lock(&nmp->nm_lock);
while (nmp->nm_sent >= nmp->nm_cwnd) {
- if ((error = nfs_sigintr(req->r_nmp, req, req->r_thread, 1)))
+ if ((error = nfs_sigintr(req->r_nmp, req, req->r_thread, 1))) {
break;
+ }
TAILQ_INSERT_TAIL(&nmp->nm_cwndq, req, r_cchain);
msleep(req, &nmp->nm_lock, slpflag | (PZERO - 1), "nfswaitcwnd", &ts);
slpflag = 0;
*/
req->r_flags &= ~R_TIMING;
nmp->nm_cwnd >>= 1;
- if (nmp->nm_cwnd < NFS_CWNDSCALE)
+ if (nmp->nm_cwnd < NFS_CWNDSCALE) {
nmp->nm_cwnd = NFS_CWNDSCALE;
+ }
}
lck_mtx_unlock(&nmp->nm_lock);
}
lck_mtx_unlock(&req->r_mtx);
error = mbuf_copym(req->r_mhead, 0, MBUF_COPYALL,
- wait ? MBUF_WAITOK : MBUF_DONTWAIT, &mreqcopy);
+ wait ? MBUF_WAITOK : MBUF_DONTWAIT, &mreqcopy);
if (error) {
- if (wait)
+ if (wait) {
log(LOG_INFO, "nfs_send: mbuf copy failed %d\n", error);
+ }
nfs_sndunlock(req);
lck_mtx_lock(&req->r_mtx);
req->r_flags &= ~R_SENDING;
req->r_flags |= R_MUSTRESEND;
req->r_rtt = 0;
lck_mtx_unlock(&req->r_mtx);
- return (0);
+ return 0;
}
bzero(&msg, sizeof(msg));
error = sock_sendmbuf(nso->nso_so, &msg, mreqcopy, 0, &sentlen);
if (error || (sentlen != req->r_mreqlen)) {
NFS_SOCK_DBG("nfs_send: 0x%llx sent %d/%d error %d\n",
- req->r_xid, (int)sentlen, (int)req->r_mreqlen, error);
+ req->r_xid, (int)sentlen, (int)req->r_mreqlen, error);
}
-
- if (!error && (sentlen != req->r_mreqlen))
+
+ if (!error && (sentlen != req->r_mreqlen)) {
error = EWOULDBLOCK;
+ }
needrecon = ((sotype == SOCK_STREAM) && sentlen && (sentlen != req->r_mreqlen));
lck_mtx_lock(&req->r_mtx);
req->r_flags &= ~R_SENDING;
req->r_rtt = 0;
- if (rexmit && (++req->r_rexmit > NFS_MAXREXMIT))
+ if (rexmit && (++req->r_rexmit > NFS_MAXREXMIT)) {
req->r_rexmit = NFS_MAXREXMIT;
+ }
if (!error) {
/* SUCCESS */
req->r_flags &= ~R_RESENDERR;
- if (rexmit)
+ if (rexmit) {
OSAddAtomic64(1, &nfsstats.rpcretries);
+ }
req->r_flags |= R_SENT;
if (req->r_flags & R_WAITSENT) {
req->r_flags &= ~R_WAITSENT;
}
nfs_sndunlock(req);
lck_mtx_unlock(&req->r_mtx);
- return (0);
+ return 0;
}
/* send failed */
req->r_flags |= R_MUSTRESEND;
- if (rexmit)
+ if (rexmit) {
req->r_flags |= R_RESENDERR;
- if ((error == EINTR) || (error == ERESTART))
+ }
+ if ((error == EINTR) || (error == ERESTART)) {
req->r_error = error;
+ }
lck_mtx_unlock(&req->r_mtx);
if (sotype == SOCK_DGRAM) {
int clearerror = 0, optlen = sizeof(clearerror);
sock_getsockopt(nso->nso_so, SOL_SOCKET, SO_ERROR, &clearerror, &optlen);
#ifdef NFS_SOCKET_DEBUGGING
- if (clearerror)
+ if (clearerror) {
NFS_SOCK_DBG("nfs_send: ignoring UDP socket error %d so %d\n",
- error, clearerror);
+ error, clearerror);
+ }
#endif
}
}
switch (error) {
case EWOULDBLOCK:
/* if send timed out, reconnect if on TCP */
- if (sotype != SOCK_STREAM)
+ if (sotype != SOCK_STREAM) {
break;
+ }
case EPIPE:
case EADDRNOTAVAIL:
case ENETDOWN:
case ECONNREFUSED:
case EHOSTDOWN:
case EHOSTUNREACH:
- /* case ECANCELED??? */
+ /* case ECANCELED??? */
needrecon = 1;
break;
}
nfs_sndunlock(req);
- if (nfs_is_dead(error, nmp))
+ if (nfs_is_dead(error, nmp)) {
error = EIO;
+ }
/*
* Don't log some errors:
* EADDRNOTAVAIL may occur on network transitions.
* ENOTCONN may occur under some network conditions.
*/
- if ((error == EPIPE) || (error == EADDRNOTAVAIL) || (error == ENOTCONN))
+ if ((error == EPIPE) || (error == EADDRNOTAVAIL) || (error == ENOTCONN)) {
error = 0;
- if (error && (error != EINTR) && (error != ERESTART))
+ }
+ if (error && (error != EINTR) && (error != ERESTART)) {
log(LOG_INFO, "nfs send error %d for server %s\n", error,
- !req->r_nmp ? "<unmounted>" :
- vfs_statfs(req->r_nmp->nm_mountp)->f_mntfromname);
+ !req->r_nmp ? "<unmounted>" :
+ vfs_statfs(req->r_nmp->nm_mountp)->f_mntfromname);
+ }
/* prefer request termination error over other errors */
error2 = nfs_sigintr(req->r_nmp, req, req->r_thread, 0);
- if (error2)
+ if (error2) {
error = error2;
+ }
/* only allow the following errors to be returned */
if ((error != EINTR) && (error != ERESTART) && (error != EIO) &&
- (error != ENXIO) && (error != ETIMEDOUT))
+ (error != ENXIO) && (error != ETIMEDOUT)) {
/*
* We got some error we don't know what do do with,
* i.e., we're not reconnecting, we map it to
* return 0 and the request will be resent.
*/
error = needrecon ? 0 : EIO;
- return (error);
+ }
+ return error;
}
/*
mbuf_t m;
int error = 0;
- if (nmp->nm_sockflags & NMSOCK_CONNECTING)
+ if (nmp->nm_sockflags & NMSOCK_CONNECTING) {
return;
+ }
do {
/* make sure we're on the current socket */
- if (!nso || (nso->nso_so != so))
+ if (!nso || (nso->nso_so != so)) {
return;
+ }
m = NULL;
rcvlen = 1000000;
error = sock_receivembuf(so, NULL, &m, MSG_DONTWAIT, &rcvlen);
- if (m)
+ if (m) {
nfs_request_match_reply(nmp, m);
+ }
} while (m && !error);
if (error && (error != EWOULDBLOCK)) {
int recv = 1;
int wup = 0;
- if (nmp->nm_sockflags & NMSOCK_CONNECTING)
+ if (nmp->nm_sockflags & NMSOCK_CONNECTING) {
return;
+ }
/* make sure we're on the current socket */
lck_mtx_lock(&nmp->nm_lock);
/* make sure this upcall should be trying to do work */
lck_mtx_lock(&nso->nso_lock);
- if (nso->nso_flags & (NSO_UPCALL|NSO_DISCONNECTING|NSO_DEAD)) {
+ if (nso->nso_flags & (NSO_UPCALL | NSO_DISCONNECTING | NSO_DEAD)) {
lck_mtx_unlock(&nso->nso_lock);
return;
}
/* loop while we make error-free progress */
while (!error && recv) {
error = nfs_rpc_record_read(so, &nrrs, MSG_DONTWAIT, &recv, &m);
- if (m) /* match completed response with request */
+ if (m) { /* match completed response with request */
nfs_request_match_reply(nmp, m);
+ }
}
/* Update the sockets's rpc parsing state */
lck_mtx_lock(&nso->nso_lock);
nso->nso_rrs = nrrs;
- if (nso->nso_flags & NSO_DISCONNECTING)
+ if (nso->nso_flags & NSO_DISCONNECTING) {
wup = 1;
+ }
nso->nso_flags &= ~NSO_UPCALL;
lck_mtx_unlock(&nso->nso_lock);
- if (wup)
+ if (wup) {
wakeup(&nso->nso_flags);
+ }
#ifdef NFS_SOCKET_DEBUGGING
- if (!recv && (error != EWOULDBLOCK))
+ if (!recv && (error != EWOULDBLOCK)) {
NFS_SOCK_DBG("nfs_tcp_rcv: got nothing, error %d, got FIN?\n", error);
+ }
#endif
/* note: no error and no data indicates server closed its end */
if ((error != EWOULDBLOCK) && (error || !recv)) {
*/
lck_mtx_lock(nfs_request_mutex);
TAILQ_FOREACH(req, &nfs_reqq, r_chain) {
- if (req->r_nmrep.nmc_mhead || (rxid != R_XID32(req->r_xid)))
+ if (req->r_nmrep.nmc_mhead || (rxid != R_XID32(req->r_xid))) {
continue;
+ }
/* looks like we have it, grab lock and double check */
lck_mtx_lock(&req->r_mtx);
if (req->r_nmrep.nmc_mhead || (rxid != R_XID32(req->r_xid))) {
FSDBG(530, R_XID32(req->r_xid), req, nmp->nm_sent, nmp->nm_cwnd);
if (nmp->nm_cwnd <= nmp->nm_sent) {
nmp->nm_cwnd +=
- ((NFS_CWNDSCALE * NFS_CWNDSCALE) +
+ ((NFS_CWNDSCALE * NFS_CWNDSCALE) +
(nmp->nm_cwnd >> 1)) / nmp->nm_cwnd;
- if (nmp->nm_cwnd > NFS_MAXCWND)
+ if (nmp->nm_cwnd > NFS_MAXCWND) {
nmp->nm_cwnd = NFS_MAXCWND;
+ }
}
if (req->r_flags & R_CWND) {
nmp->nm_sent -= NFS_CWNDSCALE;
* rtt is between N+dt and N+2-dt ticks,
* add 1.
*/
- if (proct[req->r_procnum] == 0)
+ if (proct[req->r_procnum] == 0) {
panic("nfs_request_match_reply: proct[%d] is zero", req->r_procnum);
+ }
t1 = req->r_rtt + 1;
t1 -= (NFS_SRTT(req) >> 3);
NFS_SRTT(req) += t1;
- if (t1 < 0)
+ if (t1 < 0) {
t1 = -t1;
+ }
t1 -= (NFS_SDRTT(req) >> 2);
NFS_SDRTT(req) += t1;
}
/* signal anyone waiting on this request */
wakeup(req);
asyncioq = (req->r_callback.rcb_func != NULL);
- if (nfs_request_using_gss(req))
+ if (nfs_request_using_gss(req)) {
nfs_gss_clnt_rpcdone(req);
+ }
lck_mtx_unlock(&req->r_mtx);
lck_mtx_unlock(nfs_request_mutex);
/* if it's an async RPC with a callback, queue it up */
- if (asyncioq)
+ if (asyncioq) {
nfs_asyncio_finish(req);
+ }
break;
}
struct timespec ts = { 2, 0 };
int error = 0, slpflag, first = 1;
- if (req->r_nmp && NMFLAG(req->r_nmp, INTR) && req->r_thread && !(req->r_flags & R_NOINTR))
+ if (req->r_nmp && NMFLAG(req->r_nmp, INTR) && req->r_thread && !(req->r_flags & R_NOINTR)) {
slpflag = PCATCH;
- else
+ } else {
slpflag = 0;
+ }
lck_mtx_lock(&req->r_mtx);
while (!req->r_nmrep.nmc_mhead) {
- if ((error = nfs_sigintr(req->r_nmp, req, first ? NULL : req->r_thread, 0)))
+ if ((error = nfs_sigintr(req->r_nmp, req, first ? NULL : req->r_thread, 0))) {
break;
- if (((error = req->r_error)) || req->r_nmrep.nmc_mhead)
+ }
+ if (((error = req->r_error)) || req->r_nmrep.nmc_mhead) {
break;
+ }
/* check if we need to resend */
if (req->r_flags & R_MUSTRESEND) {
NFS_SOCK_DBG("nfs wait resend: p %d x 0x%llx f 0x%x rtt %d\n",
- req->r_procnum, req->r_xid, req->r_flags, req->r_rtt);
+ req->r_procnum, req->r_xid, req->r_flags, req->r_rtt);
req->r_flags |= R_SENDING;
lck_mtx_unlock(&req->r_mtx);
if (nfs_request_using_gss(req)) {
lck_mtx_lock(&req->r_mtx);
req->r_flags &= ~R_SENDING;
lck_mtx_unlock(&req->r_mtx);
- return (EAGAIN);
+ return EAGAIN;
}
error = nfs_send(req, 1);
lck_mtx_lock(&req->r_mtx);
NFS_SOCK_DBG("nfs wait resend: p %d x 0x%llx f 0x%x rtt %d err %d\n",
- req->r_procnum, req->r_xid, req->r_flags, req->r_rtt, error);
- if (error)
+ req->r_procnum, req->r_xid, req->r_flags, req->r_rtt, error);
+ if (error) {
break;
- if (((error = req->r_error)) || req->r_nmrep.nmc_mhead)
+ }
+ if (((error = req->r_error)) || req->r_nmrep.nmc_mhead) {
break;
+ }
}
/* need to poll if we're P_NOREMOTEHANG */
- if (nfs_noremotehang(req->r_thread))
+ if (nfs_noremotehang(req->r_thread)) {
ts.tv_sec = 1;
+ }
msleep(req, &req->r_mtx, slpflag | (PZERO - 1), "nfswaitreply", &ts);
first = slpflag = 0;
}
lck_mtx_unlock(&req->r_mtx);
- return (error);
+ return error;
}
/*
int
nfs_request_create(
nfsnode_t np,
- mount_t mp, /* used only if !np */
+ mount_t mp, /* used only if !np */
struct nfsm_chain *nmrest,
int procnum,
thread_t thd,
if (!newreq) {
mbuf_freem(nmrest->nmc_mhead);
nmrest->nmc_mhead = NULL;
- return (ENOMEM);
+ return ENOMEM;
}
req = newreq;
}
bzero(req, sizeof(*req));
- if (req == newreq)
+ if (req == newreq) {
req->r_flags = R_ALLOCATED;
+ }
nmp = VFSTONFS(np ? NFSTOMP(np) : mp);
if (nfs_mount_gone(nmp)) {
- if (newreq)
+ if (newreq) {
FREE_ZONE(newreq, sizeof(*newreq), M_NFSREQ);
- return (ENXIO);
+ }
+ return ENXIO;
}
lck_mtx_lock(&nmp->nm_lock);
- if ((nmp->nm_state & (NFSSTA_FORCE|NFSSTA_DEAD)) &&
+ if ((nmp->nm_state & (NFSSTA_FORCE | NFSSTA_DEAD)) &&
(nmp->nm_state & NFSSTA_TIMEO)) {
lck_mtx_unlock(&nmp->nm_lock);
mbuf_freem(nmrest->nmc_mhead);
nmrest->nmc_mhead = NULL;
- if (newreq)
+ if (newreq) {
FREE_ZONE(newreq, sizeof(*newreq), M_NFSREQ);
- return (ENXIO);
+ }
+ return ENXIO;
}
-
- if ((nmp->nm_vers != NFS_VER4) && (procnum >= 0) && (procnum < NFS_NPROCS))
+
+ if ((nmp->nm_vers != NFS_VER4) && (procnum >= 0) && (procnum < NFS_NPROCS)) {
OSAddAtomic64(1, &nfsstats.rpccnt[procnum]);
- if ((nmp->nm_vers == NFS_VER4) && (procnum != NFSPROC4_COMPOUND) && (procnum != NFSPROC4_NULL))
+ }
+ if ((nmp->nm_vers == NFS_VER4) && (procnum != NFSPROC4_COMPOUND) && (procnum != NFSPROC4_NULL)) {
panic("nfs_request: invalid NFSv4 RPC request %d\n", procnum);
+ }
lck_mtx_init(&req->r_mtx, nfs_request_grp, LCK_ATTR_NULL);
req->r_nmp = nmp;
nmp->nm_ref++;
req->r_np = np;
req->r_thread = thd;
- if (!thd)
+ if (!thd) {
req->r_flags |= R_NOINTR;
+ }
if (IS_VALID_CRED(cred)) {
kauth_cred_ref(cred);
req->r_cred = cred;
}
req->r_procnum = procnum;
- if (proct[procnum] > 0)
+ if (proct[procnum] > 0) {
req->r_flags |= R_TIMING;
+ }
req->r_nmrep.nmc_mhead = NULL;
SLIST_INIT(&req->r_gss_seqlist);
req->r_achain.tqe_next = NFSREQNOLIST;
req->r_cchain.tqe_next = NFSREQNOLIST;
/* set auth flavor to use for request */
- if (!req->r_cred)
+ if (!req->r_cred) {
req->r_auth = RPCAUTH_NONE;
- else if (req->r_np && (req->r_np->n_auth != RPCAUTH_INVALID))
+ } else if (req->r_np && (req->r_np->n_auth != RPCAUTH_INVALID)) {
req->r_auth = req->r_np->n_auth;
- else
+ } else {
req->r_auth = nmp->nm_auth;
+ }
lck_mtx_unlock(&nmp->nm_lock);
req->r_flags |= R_INITTED;
req->r_refs = 1;
- if (newreq)
+ if (newreq) {
*reqp = req;
- return (0);
+ }
+ return 0;
}
/*
struct gss_seq *gsp, *ngsp;
int clearjbtimeo = 0;
- if (!req || !(req->r_flags & R_INITTED))
+ if (!req || !(req->r_flags & R_INITTED)) {
return;
+ }
nmp = req->r_nmp;
req->r_flags &= ~R_INITTED;
- if (req->r_lflags & RL_QUEUED)
+ if (req->r_lflags & RL_QUEUED) {
nfs_reqdequeue(req);
+ }
if (req->r_achain.tqe_next != NFSREQNOLIST) {
- /*
+ /*
* Still on an async I/O queue?
* %%% But which one, we may be on a local iod.
*/
if (req->r_rchain.tqe_next != NFSREQNOLIST) {
TAILQ_REMOVE(&nmp->nm_resendq, req, r_rchain);
req->r_rchain.tqe_next = NFSREQNOLIST;
- if (req->r_flags & R_RESENDQ)
+ if (req->r_flags & R_RESENDQ) {
req->r_flags &= ~R_RESENDQ;
+ }
}
if (req->r_cchain.tqe_next != NFSREQNOLIST) {
TAILQ_REMOVE(&nmp->nm_cwndq, req, r_cchain);
}
lck_mtx_unlock(&req->r_mtx);
- if (clearjbtimeo)
+ if (clearjbtimeo) {
nfs_up(nmp, req->r_thread, clearjbtimeo, NULL);
- if (req->r_mhead)
+ }
+ if (req->r_mhead) {
mbuf_freem(req->r_mhead);
- else if (req->r_mrest)
+ } else if (req->r_mrest) {
mbuf_freem(req->r_mrest);
- if (req->r_nmrep.nmc_mhead)
+ }
+ if (req->r_nmrep.nmc_mhead) {
mbuf_freem(req->r_nmrep.nmc_mhead);
- if (IS_VALID_CRED(req->r_cred))
+ }
+ if (IS_VALID_CRED(req->r_cred)) {
kauth_cred_unref(&req->r_cred);
- if (nfs_request_using_gss(req))
+ }
+ if (nfs_request_using_gss(req)) {
nfs_gss_clnt_rpcdone(req);
+ }
SLIST_FOREACH_SAFE(gsp, &req->r_gss_seqlist, gss_seqnext, ngsp)
- FREE(gsp, M_TEMP);
- if (req->r_gss_ctx)
+ FREE(gsp, M_TEMP);
+ if (req->r_gss_ctx) {
nfs_gss_clnt_ctx_unref(req);
- if (req->r_wrongsec)
+ }
+ if (req->r_wrongsec) {
FREE(req->r_wrongsec, M_TEMP);
- if (nmp)
+ }
+ if (nmp) {
nfs_mount_rele(nmp);
+ }
lck_mtx_destroy(&req->r_mtx, nfs_request_grp);
- if (req->r_flags & R_ALLOCATED)
+ if (req->r_flags & R_ALLOCATED) {
FREE_ZONE(req, sizeof(*req), M_NFSREQ);
+ }
}
void
nfs_request_ref(struct nfsreq *req, int locked)
{
- if (!locked)
+ if (!locked) {
lck_mtx_lock(&req->r_mtx);
- if (req->r_refs <= 0)
+ }
+ if (req->r_refs <= 0) {
panic("nfsreq reference error");
+ }
req->r_refs++;
- if (!locked)
+ if (!locked) {
lck_mtx_unlock(&req->r_mtx);
+ }
}
void
int destroy;
lck_mtx_lock(&req->r_mtx);
- if (req->r_refs <= 0)
+ if (req->r_refs <= 0) {
panic("nfsreq reference underflow");
+ }
req->r_refs--;
destroy = (req->r_refs == 0);
lck_mtx_unlock(&req->r_mtx);
- if (destroy)
+ if (destroy) {
nfs_request_destroy(req);
+ }
}
/* free up any previous header */
if ((m = req->r_mhead)) {
- while (m && (m != req->r_mrest))
+ while (m && (m != req->r_mrest)) {
m = mbuf_free(m);
+ }
req->r_mhead = NULL;
}
nmp = req->r_nmp;
- if (nfs_mount_gone(nmp))
- return (ENXIO);
+ if (nfs_mount_gone(nmp)) {
+ return ENXIO;
+ }
error = nfsm_rpchead(req, req->r_mrest, &req->r_xid, &req->r_mhead);
- if (error)
- return (error);
+ if (error) {
+ return error;
+ }
req->r_mreqlen = mbuf_pkthdr_len(req->r_mhead);
nmp = req->r_nmp;
- if (nfs_mount_gone(nmp))
- return (ENXIO);
+ if (nfs_mount_gone(nmp)) {
+ return ENXIO;
+ }
lck_mtx_lock(&nmp->nm_lock);
- if (NMFLAG(nmp, SOFT) || (req->r_flags & R_SOFT))
+ if (NMFLAG(nmp, SOFT) || (req->r_flags & R_SOFT)) {
req->r_retry = nmp->nm_retry;
- else
- req->r_retry = NFS_MAXREXMIT + 1; /* past clip limit */
+ } else {
+ req->r_retry = NFS_MAXREXMIT + 1; /* past clip limit */
+ }
lck_mtx_unlock(&nmp->nm_lock);
- return (error);
+ return error;
}
nmp = req->r_nmp;
if (nfs_mount_gone(nmp)) {
lck_mtx_unlock(nfs_request_mutex);
- return (ENXIO);
+ return ENXIO;
}
microuptime(&now);
if (!nfs_request_timer_on) {
nfs_request_timer_on = 1;
nfs_interval_timer_start(nfs_request_timer_call,
- NFS_REQUESTDELAY);
+ NFS_REQUESTDELAY);
}
lck_mtx_unlock(nfs_request_mutex);
/* Send the request... */
- return (nfs_send(req, wait));
+ return nfs_send(req, wait);
}
/*
error = req->r_error;
- if (nmrepp)
+ if (nmrepp) {
nmrepp->nmc_mhead = NULL;
+ }
/* RPC done, unlink the request. */
nfs_reqdequeue(req);
*/
if (error == EAGAIN) {
req->r_error = 0;
- if (mrep)
+ if (mrep) {
mbuf_freem(mrep);
- error = nfs_gss_clnt_args_restore(req); // remove any trailer mbufs
+ }
+ error = nfs_gss_clnt_args_restore(req); // remove any trailer mbufs
req->r_nmrep.nmc_mhead = NULL;
req->r_flags |= R_RESTART;
if (error == ENEEDAUTH) {
- req->r_xid = 0; // get a new XID
+ req->r_xid = 0; // get a new XID
error = 0;
}
goto nfsmout;
if (!error) {
if ((req->r_flags & R_TPRINTFMSG) ||
(nmp && (NMFLAG(nmp, SOFT) || (req->r_flags & R_SOFT)) &&
- ((nmp->nm_state & (NFSSTA_TIMEO|NFSSTA_FORCE|NFSSTA_DEAD)) == NFSSTA_TIMEO)))
+ ((nmp->nm_state & (NFSSTA_TIMEO | NFSSTA_FORCE | NFSSTA_DEAD)) == NFSSTA_TIMEO))) {
nfs_up(nmp, req->r_thread, NFSSTA_TIMEO, "is alive again");
- else
+ } else {
nfs_up(nmp, req->r_thread, NFSSTA_TIMEO, NULL);
+ }
}
- if (!error && !nmp)
+ if (!error && !nmp) {
error = ENXIO;
+ }
nfsmout_if(error);
/*
* and set up for a resend.
*/
error = nfs_gss_clnt_args_restore(req);
- if (error && error != ENEEDAUTH)
+ if (error && error != ENEEDAUTH) {
break;
+ }
if (!error) {
error = nfs_gss_clnt_ctx_renew(req);
- if (error)
+ if (error) {
break;
+ }
}
mbuf_freem(mrep);
req->r_nmrep.nmc_mhead = NULL;
- req->r_xid = 0; // get a new XID
+ req->r_xid = 0; // get a new XID
req->r_flags |= R_RESTART;
goto nfsmout;
default:
case RPCAUTH_NONE:
case RPCAUTH_SYS:
/* Any AUTH_SYS verifier is ignored */
- if (verf_len > 0)
+ if (verf_len > 0) {
nfsm_chain_adv(error, &nmrep, nfsm_rndup(verf_len));
+ }
nfsm_chain_get_32(error, &nmrep, accepted_status);
break;
case RPCAUTH_KRB5:
case RPCAUTH_KRB5I:
case RPCAUTH_KRB5P:
error = nfs_gss_clnt_verf_get(req, &nmrep,
- verf_type, verf_len, &accepted_status);
+ verf_type, verf_len, &accepted_status);
break;
}
nfsmout_if(error);
goto nfsmout;
}
req->r_delay = !req->r_delay ? NFS_TRYLATERDEL : (req->r_delay * 2);
- if (req->r_delay > 30)
+ if (req->r_delay > 30) {
req->r_delay = 30;
+ }
if (nmp->nm_tprintf_initial_delay && (req->r_delay >= nmp->nm_tprintf_initial_delay)) {
if (!(req->r_flags & R_JBTPRINTFMSG)) {
req->r_flags |= R_JBTPRINTFMSG;
lck_mtx_unlock(&nmp->nm_lock);
}
nfs_down(req->r_nmp, req->r_thread, 0, NFSSTA_JUKEBOXTIMEO,
- "resource temporarily unavailable (jukebox)", 0);
+ "resource temporarily unavailable (jukebox)", 0);
}
if ((NMFLAG(nmp, SOFT) || (req->r_flags & R_SOFT)) && (req->r_delay == 30) &&
- !(req->r_flags & R_NOINTR)) {
+ !(req->r_flags & R_NOINTR)) {
/* for soft mounts, just give up after a short while */
OSAddAtomic64(1, &nfsstats.rpctimeouts);
nfs_softterm(req);
req->r_resendtime = now.tv_sec + delay;
} else {
do {
- if ((error = nfs_sigintr(req->r_nmp, req, req->r_thread, 0)))
+ if ((error = nfs_sigintr(req->r_nmp, req, req->r_thread, 0))) {
goto nfsmout;
- tsleep(nfs_request_finish, PSOCK|slpflag, "nfs_jukebox_trylater", hz);
+ }
+ tsleep(nfs_request_finish, PSOCK | slpflag, "nfs_jukebox_trylater", hz);
slpflag = 0;
} while (--delay > 0);
}
- req->r_xid = 0; // get a new XID
+ req->r_xid = 0; // get a new XID
req->r_flags |= R_RESTART;
req->r_start = 0;
FSDBG(273, R_XID32(req->r_xid), nmp, req, NFSERR_TRYLATER);
- return (0);
+ return 0;
}
if (req->r_flags & R_JBTPRINTFMSG) {
if (!req->r_wrongsec) {
/* first time... set up flavor array */
- MALLOC(req->r_wrongsec, uint32_t*, NX_MAX_SEC_FLAVORS*sizeof(uint32_t), M_TEMP, M_WAITOK);
+ MALLOC(req->r_wrongsec, uint32_t*, NX_MAX_SEC_FLAVORS * sizeof(uint32_t), M_TEMP, M_WAITOK);
if (!req->r_wrongsec) {
error = EACCES;
goto nfsmout;
}
- i=0;
+ i = 0;
if (nmp->nm_sec.count) { /* use the mount's preferred list of flavors */
- for(; i < nmp->nm_sec.count; i++)
+ for (; i < nmp->nm_sec.count; i++) {
req->r_wrongsec[i] = nmp->nm_sec.flavors[i];
+ }
} else if (srvcount) { /* otherwise use the server's list of flavors */
- for(; i < srvcount; i++)
+ for (; i < srvcount; i++) {
req->r_wrongsec[i] = srvflavors[i];
+ }
} else { /* otherwise, just try the flavors we support. */
req->r_wrongsec[i++] = RPCAUTH_KRB5P;
req->r_wrongsec[i++] = RPCAUTH_KRB5I;
req->r_wrongsec[i++] = RPCAUTH_SYS;
req->r_wrongsec[i++] = RPCAUTH_NONE;
}
- for(; i < NX_MAX_SEC_FLAVORS; i++) /* invalidate any remaining slots */
+ for (; i < NX_MAX_SEC_FLAVORS; i++) { /* invalidate any remaining slots */
req->r_wrongsec[i] = RPCAUTH_INVALID;
+ }
}
/* clear the current flavor from the list */
- for(i=0; i < NX_MAX_SEC_FLAVORS; i++)
- if (req->r_wrongsec[i] == req->r_auth)
+ for (i = 0; i < NX_MAX_SEC_FLAVORS; i++) {
+ if (req->r_wrongsec[i] == req->r_auth) {
req->r_wrongsec[i] = RPCAUTH_INVALID;
+ }
+ }
/* find the next flavor to try */
- for(i=0; i < NX_MAX_SEC_FLAVORS; i++)
+ for (i = 0; i < NX_MAX_SEC_FLAVORS; i++) {
if (req->r_wrongsec[i] != RPCAUTH_INVALID) {
- if (!srvcount) /* no server list, just try it */
+ if (!srvcount) { /* no server list, just try it */
break;
+ }
/* check that it's in the server's list */
- for(j=0; j < srvcount; j++)
- if (req->r_wrongsec[i] == srvflavors[j])
+ for (j = 0; j < srvcount; j++) {
+ if (req->r_wrongsec[i] == srvflavors[j]) {
break;
- if (j < srvcount) /* found */
+ }
+ }
+ if (j < srvcount) { /* found */
break;
+ }
/* not found in server list */
req->r_wrongsec[i] = RPCAUTH_INVALID;
}
+ }
if (i == NX_MAX_SEC_FLAVORS) {
/* nothing left to try! */
error = EACCES;
/* retry with the next auth flavor */
req->r_auth = req->r_wrongsec[i];
- req->r_xid = 0; // get a new XID
+ req->r_xid = 0; // get a new XID
req->r_flags |= R_RESTART;
req->r_start = 0;
FSDBG(273, R_XID32(req->r_xid), nmp, req, NFSERR_WRONGSEC);
- return (0);
+ return 0;
}
if ((nmp->nm_vers >= NFS_VER4) && req->r_wrongsec) {
/*
* We renegotiated security for this request; so update the
* default security flavor for the associated node.
*/
- if (req->r_np)
+ if (req->r_np) {
req->r_np->n_auth = req->r_auth;
+ }
}
if (*status == NFS_OK) {
if ((*status == ESTALE) && req->r_np) {
cache_purge(NFSTOV(req->r_np));
/* if monitored, also send delete event */
- if (vnode_ismonitored(NFSTOV(req->r_np)))
- nfs_vnode_notify(req->r_np, (VNODE_EVENT_ATTRIB|VNODE_EVENT_DELETE));
+ if (vnode_ismonitored(NFSTOV(req->r_np))) {
+ nfs_vnode_notify(req->r_np, (VNODE_EVENT_ATTRIB | VNODE_EVENT_DELETE));
+ }
}
- if (nmp->nm_vers == NFS_VER2)
+ if (nmp->nm_vers == NFS_VER2) {
mbuf_freem(mrep);
- else
+ } else {
*nmrepp = nmrep;
+ }
req->r_nmrep.nmc_mhead = NULL;
error = 0;
break;
nmp->nm_jbreqs--;
clearjbtimeo = (nmp->nm_jbreqs == 0) ? NFSSTA_JUKEBOXTIMEO : 0;
lck_mtx_unlock(&nmp->nm_lock);
- if (clearjbtimeo)
+ if (clearjbtimeo) {
nfs_up(nmp, req->r_thread, clearjbtimeo, NULL);
+ }
}
FSDBG(273, R_XID32(req->r_xid), nmp, req,
- (!error && (*status == NFS_OK)) ? 0xf0f0f0f0 : error);
- return (error);
+ (!error && (*status == NFS_OK)) ? 0xf0f0f0f0 : error);
+ return error;
}
/*
int
nfs_request_using_gss(struct nfsreq *req)
{
- if (!req->r_gss_ctx)
- return (0);
+ if (!req->r_gss_ctx) {
+ return 0;
+ }
switch (req->r_auth) {
- case RPCAUTH_KRB5:
- case RPCAUTH_KRB5I:
- case RPCAUTH_KRB5P:
- return (1);
+ case RPCAUTH_KRB5:
+ case RPCAUTH_KRB5I:
+ case RPCAUTH_KRB5P:
+ return 1;
}
- return (0);
+ return 0;
}
/*
int
nfs_request(
nfsnode_t np,
- mount_t mp, /* used only if !np */
+ mount_t mp, /* used only if !np */
struct nfsm_chain *nmrest,
int procnum,
vfs_context_t ctx,
int *status)
{
return nfs_request2(np, mp, nmrest, procnum,
- vfs_context_thread(ctx), vfs_context_ucred(ctx),
- si, 0, nmrepp, xidp, status);
+ vfs_context_thread(ctx), vfs_context_ucred(ctx),
+ si, 0, nmrepp, xidp, status);
}
int
nfs_request2(
nfsnode_t np,
- mount_t mp, /* used only if !np */
+ mount_t mp, /* used only if !np */
struct nfsm_chain *nmrest,
int procnum,
thread_t thd,
struct nfsreq rq, *req = &rq;
int error;
- if ((error = nfs_request_create(np, mp, nmrest, procnum, thd, cred, &req)))
- return (error);
+ if ((error = nfs_request_create(np, mp, nmrest, procnum, thd, cred, &req))) {
+ return error;
+ }
req->r_flags |= (flags & (R_OPTMASK | R_SOFT));
- if (si)
+ if (si) {
req->r_secinfo = *si;
+ }
FSDBG_TOP(273, R_XID32(req->r_xid), np, procnum, 0);
do {
req->r_error = 0;
req->r_flags &= ~R_RESTART;
- if ((error = nfs_request_add_header(req)))
+ if ((error = nfs_request_add_header(req))) {
break;
- if (xidp)
+ }
+ if (xidp) {
*xidp = req->r_xid;
- if ((error = nfs_request_send(req, 1)))
+ }
+ if ((error = nfs_request_send(req, 1))) {
break;
+ }
nfs_request_wait(req);
- if ((error = nfs_request_finish(req, nmrepp, status)))
+ if ((error = nfs_request_finish(req, nmrepp, status))) {
break;
+ }
} while (req->r_flags & R_RESTART);
FSDBG_BOT(273, R_XID32(req->r_xid), np, procnum, error);
nfs_request_rele(req);
- return (error);
+ return error;
}
int
nfs_request_gss(
- mount_t mp,
- struct nfsm_chain *nmrest,
- thread_t thd,
- kauth_cred_t cred,
- int flags,
- struct nfs_gss_clnt_ctx *cp, /* Set to gss context to renew or setup */
- struct nfsm_chain *nmrepp,
- int *status)
+ mount_t mp,
+ struct nfsm_chain *nmrest,
+ thread_t thd,
+ kauth_cred_t cred,
+ int flags,
+ struct nfs_gss_clnt_ctx *cp, /* Set to gss context to renew or setup */
+ struct nfsm_chain *nmrepp,
+ int *status)
{
struct nfsreq rq, *req = &rq;
int error, wait = 1;
- if ((error = nfs_request_create(NULL, mp, nmrest, NFSPROC_NULL, thd, cred, &req)))
- return (error);
+ if ((error = nfs_request_create(NULL, mp, nmrest, NFSPROC_NULL, thd, cred, &req))) {
+ return error;
+ }
req->r_flags |= (flags & R_OPTMASK);
if (cp == NULL) {
printf("nfs_request_gss request has no context\n");
nfs_request_rele(req);
- return (NFSERR_EAUTH);
+ return NFSERR_EAUTH;
}
nfs_gss_clnt_ctx_ref(req, cp);
* Don't wait for a reply to a context destroy advisory
* to avoid hanging on a dead server.
*/
- if (cp->gss_clnt_proc == RPCSEC_GSS_DESTROY)
+ if (cp->gss_clnt_proc == RPCSEC_GSS_DESTROY) {
wait = 0;
+ }
FSDBG_TOP(273, R_XID32(req->r_xid), NULL, NFSPROC_NULL, 0);
do {
req->r_error = 0;
req->r_flags &= ~R_RESTART;
- if ((error = nfs_request_add_header(req)))
+ if ((error = nfs_request_add_header(req))) {
break;
+ }
- if ((error = nfs_request_send(req, wait)))
+ if ((error = nfs_request_send(req, wait))) {
break;
- if (!wait)
+ }
+ if (!wait) {
break;
+ }
nfs_request_wait(req);
- if ((error = nfs_request_finish(req, nmrepp, status)))
+ if ((error = nfs_request_finish(req, nmrepp, status))) {
break;
+ }
} while (req->r_flags & R_RESTART);
FSDBG_BOT(273, R_XID32(req->r_xid), NULL, NFSPROC_NULL, error);
nfs_gss_clnt_ctx_unref(req);
nfs_request_rele(req);
- return (error);
+ return error;
}
/*
int
nfs_request_async(
nfsnode_t np,
- mount_t mp, /* used only if !np */
+ mount_t mp, /* used only if !np */
struct nfsm_chain *nmrest,
int procnum,
thread_t thd,
error = nfs_request_create(np, mp, nmrest, procnum, thd, cred, reqp);
req = *reqp;
FSDBG(274, (req ? R_XID32(req->r_xid) : 0), np, procnum, error);
- if (error)
- return (error);
+ if (error) {
+ return error;
+ }
req->r_flags |= (flags & R_OPTMASK);
req->r_flags |= R_ASYNC;
- if (si)
+ if (si) {
req->r_secinfo = *si;
- if (cb)
+ }
+ if (cb) {
req->r_callback = *cb;
+ }
error = nfs_request_add_header(req);
if (!error) {
req->r_flags |= R_WAITSENT;
- if (req->r_callback.rcb_func)
+ if (req->r_callback.rcb_func) {
nfs_request_ref(req, 0);
+ }
error = nfs_request_send(req, 1);
lck_mtx_lock(&req->r_mtx);
if (!error && !(req->r_flags & R_SENT) && req->r_callback.rcb_func) {
*/
TAILQ_REMOVE(&nmp->nm_resendq, req, r_rchain);
req->r_rchain.tqe_next = NFSREQNOLIST;
- if (req->r_flags & R_RESENDQ)
+ if (req->r_flags & R_RESENDQ) {
req->r_flags &= ~R_RESENDQ;
+ }
lck_mtx_unlock(&nmp->nm_lock);
req->r_flags |= R_SENDING;
lck_mtx_unlock(&req->r_mtx);
/* Remove the R_RESENDQ reference */
nfs_request_rele(req);
lck_mtx_lock(&req->r_mtx);
- if (error)
+ if (error) {
break;
+ }
continue;
}
lck_mtx_unlock(&nmp->nm_lock);
}
- if ((error = nfs_sigintr(req->r_nmp, req, req->r_thread, 0)))
+ if ((error = nfs_sigintr(req->r_nmp, req, req->r_thread, 0))) {
break;
+ }
msleep(req, &req->r_mtx, slpflag | (PZERO - 1), "nfswaitsent", &ts);
slpflag = 0;
}
}
}
FSDBG(274, R_XID32(req->r_xid), np, procnum, error);
- if (error || req->r_callback.rcb_func)
+ if (error || req->r_callback.rcb_func) {
nfs_request_rele(req);
+ }
- return (error);
+ return error;
}
/*
struct nfsmount *nmp;
lck_mtx_lock(&req->r_mtx);
- if (!asyncio)
+ if (!asyncio) {
req->r_flags |= R_ASYNCWAIT;
+ }
while (req->r_flags & R_RESENDQ) { /* wait until the request is off the resend queue */
struct timespec ts = { 2, 0 };
*/
TAILQ_REMOVE(&nmp->nm_resendq, req, r_rchain);
req->r_rchain.tqe_next = NFSREQNOLIST;
- if (req->r_flags & R_RESENDQ)
+ if (req->r_flags & R_RESENDQ) {
req->r_flags &= ~R_RESENDQ;
+ }
/* Remove the R_RESENDQ reference */
assert(req->r_refs > 0);
req->r_refs--;
}
lck_mtx_unlock(&nmp->nm_lock);
}
- if ((error = nfs_sigintr(req->r_nmp, req, req->r_thread, 0)))
+ if ((error = nfs_sigintr(req->r_nmp, req, req->r_thread, 0))) {
break;
- msleep(req, &req->r_mtx, PZERO-1, "nfsresendqwait", &ts);
+ }
+ msleep(req, &req->r_mtx, PZERO - 1, "nfsresendqwait", &ts);
}
lck_mtx_unlock(&req->r_mtx);
if (req->r_resendtime) { /* send later */
nfs_asyncio_resend(req);
lck_mtx_unlock(&req->r_mtx);
- return (EINPROGRESS);
+ return EINPROGRESS;
}
lck_mtx_unlock(&req->r_mtx);
}
req->r_error = 0;
req->r_flags &= ~R_RESTART;
- if ((error = nfs_request_add_header(req)))
+ if ((error = nfs_request_add_header(req))) {
break;
- if ((error = nfs_request_send(req, !asyncio)))
+ }
+ if ((error = nfs_request_send(req, !asyncio))) {
break;
- if (asyncio)
- return (EINPROGRESS);
+ }
+ if (asyncio) {
+ return EINPROGRESS;
+ }
nfs_request_wait(req);
- if ((error = nfs_request_finish(req, nmrepp, status)))
+ if ((error = nfs_request_finish(req, nmrepp, status))) {
break;
+ }
}
- if (xidp)
+ if (xidp) {
*xidp = req->r_xid;
+ }
FSDBG(275, R_XID32(req->r_xid), req->r_np, req->r_procnum, error);
nfs_request_rele(req);
- return (error);
+ return error;
}
/*
struct nfsmount *nmp = req->r_nmp;
req->r_flags |= R_SOFTTERM;
req->r_error = ETIMEDOUT;
- if (!(req->r_flags & R_CWND) || nfs_mount_gone(nmp))
+ if (!(req->r_flags & R_CWND) || nfs_mount_gone(nmp)) {
return;
+ }
/* update congestion window */
req->r_flags &= ~R_CWND;
lck_mtx_lock(&nmp->nm_lock);
void
nfs_reqbusy(struct nfsreq *req)
{
- if (req->r_lflags & RL_BUSY)
+ if (req->r_lflags & RL_BUSY) {
panic("req locked");
+ }
req->r_lflags |= RL_BUSY;
}
{
struct nfsreq * nextreq;
- if (req == NULL)
- return (NULL);
+ if (req == NULL) {
+ return NULL;
+ }
/*
* We need to get and busy the next req before signalling the
* current one, otherwise wakeup() may block us and we'll race to
* grab the next req.
*/
nextreq = TAILQ_NEXT(req, r_chain);
- if (nextreq != NULL)
+ if (nextreq != NULL) {
nfs_reqbusy(nextreq);
+ }
/* unbusy and signal. */
req->r_lflags &= ~RL_BUSY;
if (req->r_lflags & RL_WAITING) {
req->r_lflags &= ~RL_WAITING;
wakeup(&req->r_lflags);
}
- return (nextreq);
+ return nextreq;
}
/*
restart:
lck_mtx_lock(nfs_request_mutex);
req = TAILQ_FIRST(&nfs_reqq);
- if (req == NULL) { /* no requests - turn timer off */
+ if (req == NULL) { /* no requests - turn timer off */
nfs_request_timer_on = 0;
lck_mtx_unlock(nfs_request_mutex);
return;
nfs_reqbusy(req);
microuptime(&now);
- for ( ; req != NULL ; req = nfs_reqnext(req)) {
+ for (; req != NULL; req = nfs_reqnext(req)) {
nmp = req->r_nmp;
if (nmp == NULL) {
NFS_SOCK_DBG("Found a request with out a mount!\n");
continue;
}
- if (req->r_error || req->r_nmrep.nmc_mhead)
+ if (req->r_error || req->r_nmrep.nmc_mhead) {
continue;
+ }
if ((error = nfs_sigintr(nmp, req, req->r_thread, 0))) {
if (req->r_callback.rcb_func != NULL) {
/* async I/O RPC needs to be finished */
finish_asyncio = !(req->r_flags & R_WAITSENT);
wakeup(req);
lck_mtx_unlock(&req->r_mtx);
- if (finish_asyncio)
+ if (finish_asyncio) {
nfs_asyncio_finish(req);
+ }
}
continue;
}
((req->r_lastmsg + nmp->nm_tprintf_delay) < now.tv_sec)) {
req->r_lastmsg = now.tv_sec;
nfs_down(req->r_nmp, req->r_thread, 0, NFSSTA_TIMEO,
- "not responding", 1);
+ "not responding", 1);
req->r_flags |= R_TPRINTFMSG;
lck_mtx_lock(&nmp->nm_lock);
if (!(nmp->nm_state & NFSSTA_MOUNTED)) {
finish_asyncio = ((req->r_callback.rcb_func != NULL) && !(req->r_flags & R_WAITSENT));
wakeup(req);
lck_mtx_unlock(&req->r_mtx);
- if (finish_asyncio)
+ if (finish_asyncio) {
nfs_asyncio_finish(req);
+ }
continue;
}
lck_mtx_unlock(&nmp->nm_lock);
* Put a reasonable limit on the maximum timeout,
* and reduce that limit when soft mounts get timeouts or are in reconnect.
*/
- if (!(NMFLAG(nmp, SOFT) || (req->r_flags & R_SOFT)) && !nfs_can_squish(nmp))
+ if (!(NMFLAG(nmp, SOFT) || (req->r_flags & R_SOFT)) && !nfs_can_squish(nmp)) {
maxtime = NFS_MAXTIMEO;
- else if ((req->r_flags & (R_SETUP|R_RECOVER)) ||
- ((nmp->nm_reconnect_start <= 0) || ((now.tv_sec - nmp->nm_reconnect_start) < 8)))
- maxtime = (NFS_MAXTIMEO / (nmp->nm_timeouts+1))/2;
- else
- maxtime = NFS_MINTIMEO/4;
+ } else if ((req->r_flags & (R_SETUP | R_RECOVER)) ||
+ ((nmp->nm_reconnect_start <= 0) || ((now.tv_sec - nmp->nm_reconnect_start) < 8))) {
+ maxtime = (NFS_MAXTIMEO / (nmp->nm_timeouts + 1)) / 2;
+ } else {
+ maxtime = NFS_MINTIMEO / 4;
+ }
/*
* Check for request timeout.
lck_mtx_lock(&nmp->nm_lock);
if (req->r_flags & R_RESENDERR) {
/* with resend errors, retry every few seconds */
- timeo = 4*hz;
+ timeo = 4 * hz;
} else {
- if (req->r_procnum == NFSPROC_NULL && req->r_gss_ctx != NULL)
+ if (req->r_procnum == NFSPROC_NULL && req->r_gss_ctx != NULL) {
timeo = NFS_MINIDEMTIMEO; // gss context setup
- else if (NMFLAG(nmp, DUMBTIMER))
+ } else if (NMFLAG(nmp, DUMBTIMER)) {
timeo = nmp->nm_timeo;
- else
+ } else {
timeo = NFS_RTO(nmp, proct[req->r_procnum]);
+ }
/* ensure 62.5 ms floor */
- while (16 * timeo < hz)
+ while (16 * timeo < hz) {
timeo *= 2;
- if (nmp->nm_timeouts > 0)
+ }
+ if (nmp->nm_timeouts > 0) {
timeo *= nfs_backoff[nmp->nm_timeouts - 1];
+ }
}
/* limit timeout to max */
- if (timeo > maxtime)
+ if (timeo > maxtime) {
timeo = maxtime;
+ }
if (req->r_rtt <= timeo) {
NFS_SOCK_DBG("nfs timeout: req time %d and timeo is %d continue\n", req->r_rtt, timeo);
lck_mtx_unlock(&nmp->nm_lock);
}
/* The request has timed out */
NFS_SOCK_DBG("nfs timeout: proc %d %d xid %llx rtt %d to %d # %d, t %ld/%d\n",
- req->r_procnum, proct[req->r_procnum],
- req->r_xid, req->r_rtt, timeo, nmp->nm_timeouts,
- (now.tv_sec - req->r_start)*NFS_HZ, maxtime);
- if (nmp->nm_timeouts < 8)
+ req->r_procnum, proct[req->r_procnum],
+ req->r_xid, req->r_rtt, timeo, nmp->nm_timeouts,
+ (now.tv_sec - req->r_start) * NFS_HZ, maxtime);
+ if (nmp->nm_timeouts < 8) {
nmp->nm_timeouts++;
+ }
if (nfs_mount_check_dead_timeout(nmp)) {
/* Unbusy this request */
req->r_lflags &= ~RL_BUSY;
}
lck_mtx_unlock(&req->r_mtx);
- /* No need to poke this mount */
+ /* No need to poke this mount */
if (nmp->nm_sockflags & NMSOCK_POKE) {
nmp->nm_sockflags &= ~NMSOCK_POKE;
TAILQ_REMOVE(&nfs_mount_poke_queue, nmp, nm_pokeq);
*/
goto restart;
}
-
+
/* if it's been a few seconds, try poking the socket */
if ((nmp->nm_sotype == SOCK_STREAM) &&
((now.tv_sec - req->r_start) >= 3) &&
- !(nmp->nm_sockflags & (NMSOCK_POKE|NMSOCK_UNMOUNT)) &&
+ !(nmp->nm_sockflags & (NMSOCK_POKE | NMSOCK_UNMOUNT)) &&
(nmp->nm_sockflags & NMSOCK_READY)) {
nmp->nm_sockflags |= NMSOCK_POKE;
/*
}
/* For soft mounts (& SETUPs/RECOVERs), check for too many retransmits/timeout. */
- if ((NMFLAG(nmp, SOFT) || (req->r_flags & (R_SETUP|R_RECOVER|R_SOFT))) &&
+ if ((NMFLAG(nmp, SOFT) || (req->r_flags & (R_SETUP | R_RECOVER | R_SOFT))) &&
((req->r_rexmit >= req->r_retry) || /* too many */
- ((now.tv_sec - req->r_start)*NFS_HZ > maxtime))) { /* too long */
+ ((now.tv_sec - req->r_start) * NFS_HZ > maxtime))) { /* too long */
OSAddAtomic64(1, &nfsstats.rpctimeouts);
lck_mtx_lock(&nmp->nm_lock);
if (!(nmp->nm_state & NFSSTA_TIMEO)) {
/* make sure we note the unresponsive server */
/* (maxtime may be less than tprintf delay) */
nfs_down(req->r_nmp, req->r_thread, 0, NFSSTA_TIMEO,
- "not responding", 1);
+ "not responding", 1);
req->r_lastmsg = now.tv_sec;
req->r_flags |= R_TPRINTFMSG;
} else {
continue;
}
NFS_SOCK_DBG("nfs timer TERMINATE: p %d x 0x%llx f 0x%x rtt %d t %ld\n",
- req->r_procnum, req->r_xid, req->r_flags, req->r_rtt,
- now.tv_sec - req->r_start);
+ req->r_procnum, req->r_xid, req->r_flags, req->r_rtt,
+ now.tv_sec - req->r_start);
nfs_softterm(req);
finish_asyncio = ((req->r_callback.rcb_func != NULL) && !(req->r_flags & R_WAITSENT));
wakeup(req);
lck_mtx_unlock(&req->r_mtx);
- if (finish_asyncio)
+ if (finish_asyncio) {
nfs_asyncio_finish(req);
+ }
continue;
}
/* for TCP, only resend if explicitly requested */
if ((nmp->nm_sotype == SOCK_STREAM) && !(req->r_flags & R_MUSTRESEND)) {
- if (++req->r_rexmit > NFS_MAXREXMIT)
+ if (++req->r_rexmit > NFS_MAXREXMIT) {
req->r_rexmit = NFS_MAXREXMIT;
+ }
req->r_rtt = 0;
lck_mtx_unlock(&req->r_mtx);
continue;
continue;
}
NFS_SOCK_DBG("nfs timer mark resend: p %d x 0x%llx f 0x%x rtt %d\n",
- req->r_procnum, req->r_xid, req->r_flags, req->r_rtt);
+ req->r_procnum, req->r_xid, req->r_flags, req->r_rtt);
req->r_flags |= R_MUSTRESEND;
req->r_rtt = -1;
wakeup(req);
- if ((req->r_flags & (R_IOD|R_ASYNC|R_ASYNCWAIT|R_SENDING)) == R_ASYNC)
+ if ((req->r_flags & (R_IOD | R_ASYNC | R_ASYNCWAIT | R_SENDING)) == R_ASYNC) {
nfs_asyncio_resend(req);
+ }
lck_mtx_unlock(&req->r_mtx);
}
nfs_noremotehang(thread_t thd)
{
proc_t p = thd ? get_bsdthreadtask_info(thd) : NULL;
- return (p && proc_noremotehang(p));
+ return p && proc_noremotehang(p);
}
/*
* and the mount is interruptable, or if we are a thread that is in the process
* of cancellation (also SIGKILL posted).
*/
-extern int sigprop[NSIG+1];
+extern int sigprop[NSIG + 1];
int
nfs_sigintr(struct nfsmount *nmp, struct nfsreq *req, thread_t thd, int nmplocked)
{
proc_t p;
int error = 0;
- if (!nmp)
- return (ENXIO);
+ if (!nmp) {
+ return ENXIO;
+ }
- if (req && (req->r_flags & R_SOFTTERM))
- return (ETIMEDOUT); /* request has been terminated. */
- if (req && (req->r_flags & R_NOINTR))
+ if (req && (req->r_flags & R_SOFTTERM)) {
+ return ETIMEDOUT; /* request has been terminated. */
+ }
+ if (req && (req->r_flags & R_NOINTR)) {
thd = NULL; /* don't check for signal on R_NOINTR */
-
- if (!nmplocked)
+ }
+ if (!nmplocked) {
lck_mtx_lock(&nmp->nm_lock);
+ }
if (nmp->nm_state & NFSSTA_FORCE) {
/* If a force unmount is in progress then fail. */
error = EIO;
}
/* Check if the mount is marked dead. */
- if (!error && (nmp->nm_state & NFSSTA_DEAD))
+ if (!error && (nmp->nm_state & NFSSTA_DEAD)) {
error = ENXIO;
+ }
/*
* If the mount is hung and we've requested not to hang
* on remote filesystems, then bail now.
*/
if (current_proc() != kernproc &&
- !error && (nmp->nm_state & NFSSTA_TIMEO) && nfs_noremotehang(thd))
+ !error && (nmp->nm_state & NFSSTA_TIMEO) && nfs_noremotehang(thd)) {
error = EIO;
+ }
- if (!nmplocked)
+ if (!nmplocked) {
lck_mtx_unlock(&nmp->nm_lock);
- if (error)
- return (error);
+ }
+ if (error) {
+ return error;
+ }
/* may not have a thread for async I/O */
- if (thd == NULL || current_proc() == kernproc)
- return (0);
+ if (thd == NULL || current_proc() == kernproc) {
+ return 0;
+ }
/*
* Check if the process is aborted, but don't interrupt if we
*/
if (((p = current_proc()) != kernproc) && current_thread_aborted() &&
(!(p->p_acflag & AXSIG) || (p->exit_thread != current_thread()) ||
- (p->p_sigacts == NULL) ||
- (p->p_sigacts->ps_sig < 1) || (p->p_sigacts->ps_sig > NSIG) ||
- !(sigprop[p->p_sigacts->ps_sig] & SA_CORE)))
- return (EINTR);
+ (p->p_sigacts == NULL) ||
+ (p->p_sigacts->ps_sig < 1) || (p->p_sigacts->ps_sig > NSIG) ||
+ !(sigprop[p->p_sigacts->ps_sig] & SA_CORE))) {
+ return EINTR;
+ }
/* mask off thread and process blocked signals. */
if (NMFLAG(nmp, INTR) && ((p = get_bsdthreadtask_info(thd))) &&
- proc_pendingsignals(p, NFSINT_SIGMASK))
- return (EINTR);
- return (0);
+ proc_pendingsignals(p, NFSINT_SIGMASK)) {
+ return EINTR;
+ }
+ return 0;
}
/*
int error = 0, slpflag = 0;
struct timespec ts = { 0, 0 };
- if (nfs_mount_gone(nmp))
- return (ENXIO);
+ if (nfs_mount_gone(nmp)) {
+ return ENXIO;
+ }
lck_mtx_lock(&nmp->nm_lock);
statep = &nmp->nm_state;
- if (NMFLAG(nmp, INTR) && req->r_thread && !(req->r_flags & R_NOINTR))
+ if (NMFLAG(nmp, INTR) && req->r_thread && !(req->r_flags & R_NOINTR)) {
slpflag = PCATCH;
+ }
while (*statep & NFSSTA_SNDLOCK) {
- if ((error = nfs_sigintr(nmp, req, req->r_thread, 1)))
+ if ((error = nfs_sigintr(nmp, req, req->r_thread, 1))) {
break;
+ }
*statep |= NFSSTA_WANTSND;
- if (nfs_noremotehang(req->r_thread))
+ if (nfs_noremotehang(req->r_thread)) {
ts.tv_sec = 1;
+ }
msleep(statep, &nmp->nm_lock, slpflag | (PZERO - 1), "nfsndlck", &ts);
if (slpflag == PCATCH) {
slpflag = 0;
ts.tv_sec = 2;
}
}
- if (!error)
+ if (!error) {
*statep |= NFSSTA_SNDLOCK;
+ }
lck_mtx_unlock(&nmp->nm_lock);
- return (error);
+ return error;
}
/*
struct nfsmount *nmp = req->r_nmp;
int *statep, wake = 0;
- if (!nmp)
+ if (!nmp) {
return;
+ }
lck_mtx_lock(&nmp->nm_lock);
statep = &nmp->nm_state;
- if ((*statep & NFSSTA_SNDLOCK) == 0)
+ if ((*statep & NFSSTA_SNDLOCK) == 0) {
panic("nfs sndunlock");
- *statep &= ~(NFSSTA_SNDLOCK|NFSSTA_SENDING);
+ }
+ *statep &= ~(NFSSTA_SNDLOCK | NFSSTA_SENDING);
if (*statep & NFSSTA_WANTSND) {
*statep &= ~NFSSTA_WANTSND;
wake = 1;
}
lck_mtx_unlock(&nmp->nm_lock);
- if (wake)
+ if (wake) {
wakeup(statep);
+ }
}
int
if (!so) {
/* create socket and set options */
soproto = (sotype == SOCK_DGRAM) ? IPPROTO_UDP : IPPROTO_TCP;
- if ((error = sock_socket(saddr->sa_family, sotype, soproto, NULL, NULL, &newso)))
+ if ((error = sock_socket(saddr->sa_family, sotype, soproto, NULL, NULL, &newso))) {
goto nfsmout;
+ }
if (bindresv) {
int level = (saddr->sa_family == AF_INET) ? IPPROTO_IP : IPPROTO_IPV6;
} else {
error = EINVAL;
}
- if (!error)
+ if (!error) {
error = sock_bind(newso, (struct sockaddr *)&ss);
+ }
nfsmout_if(error);
}
if (sotype == SOCK_STREAM) {
-# define NFS_AUX_CONNECTION_TIMEOUT 4 /* 4 second timeout for connections */
+# define NFS_AUX_CONNECTION_TIMEOUT 4 /* 4 second timeout for connections */
int count = 0;
-
+
error = sock_connect(newso, saddr, MSG_DONTWAIT);
- if (error == EINPROGRESS)
+ if (error == EINPROGRESS) {
error = 0;
+ }
nfsmout_if(error);
while ((error = sock_connectwait(newso, &tv)) == EINPROGRESS) {
}
if (((error = sock_setsockopt(newso, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)))) ||
((error = sock_setsockopt(newso, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv)))) ||
- ((error = sock_setsockopt(newso, SOL_SOCKET, SO_NOADDRERR, &on, sizeof(on)))))
+ ((error = sock_setsockopt(newso, SOL_SOCKET, SO_NOADDRERR, &on, sizeof(on))))) {
goto nfsmout;
+ }
so = newso;
} else {
/* make sure socket is using a one second timeout in this function */
nfs_rpc_record_state_init(&nrrs);
}
- for (try=0; try < timeo; try++) {
- if ((error = nfs_sigintr(nmp, NULL, !try ? NULL : thd, 0)))
+ for (try = 0; try < timeo; try++) {
+ if ((error = nfs_sigintr(nmp, NULL, !try ? NULL : thd, 0))) {
break;
+ }
if (!try || (try == sendat)) {
/* send the request (resending periodically for UDP) */
- if ((error = mbuf_copym(mreq, 0, MBUF_COPYALL, MBUF_WAITOK, &m)))
+ if ((error = mbuf_copym(mreq, 0, MBUF_COPYALL, MBUF_WAITOK, &m))) {
goto nfsmout;
+ }
bzero(&msg, sizeof(msg));
if ((sotype == SOCK_DGRAM) && !sock_isconnected(so)) {
msg.msg_name = saddr;
msg.msg_namelen = saddr->sa_len;
}
- if ((error = sock_sendmbuf(so, &msg, m, 0, &sentlen)))
+ if ((error = sock_sendmbuf(so, &msg, m, 0, &sentlen))) {
goto nfsmout;
+ }
sendat *= 2;
- if (sendat > 30)
+ if (sendat > 30) {
sendat = 30;
+ }
}
/* wait for the response */
if (sotype == SOCK_STREAM) {
error = nfs_rpc_record_read(so, &nrrs, 0, &recv, &mrep);
/* if we don't have the whole record yet, we'll keep trying */
} else {
- readlen = 1<<18;
+ readlen = 1 << 18;
bzero(&msg, sizeof(msg));
error = sock_receivembuf(so, &msg, &mrep, 0, &readlen);
}
- if (error == EWOULDBLOCK)
+ if (error == EWOULDBLOCK) {
continue;
+ }
nfsmout_if(error);
/* parse the response */
nfsm_chain_dissect_init(error, nmrep, mrep);
nfsm_chain_get_32(error, nmrep, rxid);
nfsm_chain_get_32(error, nmrep, reply);
nfsmout_if(error);
- if ((rxid != xid) || (reply != RPC_REPLY))
+ if ((rxid != xid) || (reply != RPC_REPLY)) {
error = EBADRPC;
+ }
nfsm_chain_get_32(error, nmrep, reply_status);
nfsmout_if(error);
if (reply_status == RPC_MSGDENIED) {
nfsm_chain_get_32(error, nmrep, verf_type); /* verifier flavor */
nfsm_chain_get_32(error, nmrep, verf_len); /* verifier length */
nfsmout_if(error);
- if (verf_len)
+ if (verf_len) {
nfsm_chain_adv(error, nmrep, nfsm_rndup(verf_len));
+ }
nfsm_chain_get_32(error, nmrep, accepted_status);
nfsmout_if(error);
switch (accepted_status) {
sock_close(newso);
}
mbuf_freem(mreq);
- return (error);
+ return error;
}
int
uint32_t ualen = 0;
uint32_t port;
uint64_t xid = 0;
- char uaddr[MAX_IPv6_STR_LEN+16];
+ char uaddr[MAX_IPv6_STR_LEN + 16];
bcopy(sa, saddr, min(sizeof(ss), sa->sa_len));
if (saddr->sa_family == AF_INET) {
pmvers = RPCBVERS4;
pmproc = RPCBPROC_GETVERSADDR;
} else {
- return (EINVAL);
+ return EINVAL;
}
nfsm_chain_null(&nmreq);
nfsm_chain_null(&nmrep);
tryagain:
/* send portmapper request to get port/uaddr */
- if (ip == 4)
+ if (ip == 4) {
((struct sockaddr_in*)saddr)->sin_port = htons(PMAPPORT);
- else
+ } else {
((struct sockaddr_in6*)saddr)->sin6_port = htons(PMAPPORT);
- nfsm_chain_build_alloc_init(error, &nmreq, 8*NFSX_UNSIGNED);
+ }
+ nfsm_chain_build_alloc_init(error, &nmreq, 8 * NFSX_UNSIGNED);
nfsm_chain_add_32(error, &nmreq, protocol);
nfsm_chain_add_32(error, &nmreq, vers);
if (ip == 4) {
nfsm_chain_add_32(error, &nmreq, ipproto);
nfsm_chain_add_32(error, &nmreq, 0);
} else {
- if (ipproto == IPPROTO_TCP)
+ if (ipproto == IPPROTO_TCP) {
nfsm_chain_add_string(error, &nmreq, "tcp6", 4);
- else
+ } else {
nfsm_chain_add_string(error, &nmreq, "udp6", 4);
+ }
nfsm_chain_add_string(error, &nmreq, "", 0); /* uaddr */
nfsm_chain_add_string(error, &nmreq, "", 0); /* owner */
}
nfsm_chain_build_done(error, &nmreq);
nfsmout_if(error);
error = nfsm_rpchead2(nmp, (ipproto == IPPROTO_UDP) ? SOCK_DGRAM : SOCK_STREAM,
- pmprog, pmvers, pmproc, RPCAUTH_SYS, cred, NULL, nmreq.nmc_mhead,
- &xid, &mreq);
+ pmprog, pmvers, pmproc, RPCAUTH_SYS, cred, NULL, nmreq.nmc_mhead,
+ &xid, &mreq);
nfsmout_if(error);
nmreq.nmc_mhead = NULL;
error = nfs_aux_request(nmp, thd, saddr, so, (ipproto == IPPROTO_UDP) ? SOCK_DGRAM : SOCK_STREAM,
- mreq, R_XID32(xid), 0, timeo, &nmrep);
+ mreq, R_XID32(xid), 0, timeo, &nmrep);
/* grab port from portmap response */
if (ip == 4) {
nfsm_chain_get_32(error, &nmrep, port);
- if (!error)
+ if (!error) {
((struct sockaddr_in*)sa)->sin_port = htons(port);
+ }
} else {
/* get uaddr string and convert to sockaddr */
nfsm_chain_get_32(error, &nmrep, ualen);
if (!error) {
- if (ualen > (sizeof(uaddr)-1))
+ if (ualen > (sizeof(uaddr) - 1)) {
error = EIO;
+ }
if (ualen < 1) {
/* program is not available, just return a zero port */
bcopy(sa, saddr, min(sizeof(ss), sa->sa_len));
nfsm_chain_get_opaque(error, &nmrep, ualen, uaddr);
if (!error) {
uaddr[ualen] = '\0';
- if (!nfs_uaddr2sockaddr(uaddr, saddr))
+ if (!nfs_uaddr2sockaddr(uaddr, saddr)) {
error = EIO;
+ }
}
}
}
goto tryagain;
}
}
- if (!error)
+ if (!error) {
bcopy(saddr, sa, min(saddr->sa_len, sa->sa_len));
+ }
}
nfsmout:
nfsm_chain_cleanup(&nmreq);
nfsm_chain_cleanup(&nmrep);
- return (error);
+ return error;
}
int
nfs_msg(thread_t thd,
- const char *server,
- const char *msg,
- int error)
+ const char *server,
+ const char *msg,
+ int error)
{
proc_t p = thd ? get_bsdthreadtask_info(thd) : NULL;
tpr_t tpr;
- if (p)
+ if (p) {
tpr = tprintf_open(p);
- else
+ } else {
tpr = NULL;
- if (error)
+ }
+ if (error) {
tprintf(tpr, "nfs server %s: %s, error %d\n", server, msg, error);
- else
+ } else {
tprintf(tpr, "nfs server %s: %s\n", server, msg);
+ }
tprintf_close(tpr);
- return (0);
+ return 0;
}
-#define NFS_SQUISH_MOBILE_ONLY 0x0001 /* Squish mounts only on mobile machines */
-#define NFS_SQUISH_AUTOMOUNTED_ONLY 0x0002 /* Squish mounts only if the are automounted */
-#define NFS_SQUISH_SOFT 0x0004 /* Treat all soft mounts as though they were on a mobile machine */
-#define NFS_SQUISH_QUICK 0x0008 /* Try to squish mounts more quickly. */
-#define NFS_SQUISH_SHUTDOWN 0x1000 /* Squish all mounts on shutdown. Currently not implemented */
+#define NFS_SQUISH_MOBILE_ONLY 0x0001 /* Squish mounts only on mobile machines */
+#define NFS_SQUISH_AUTOMOUNTED_ONLY 0x0002 /* Squish mounts only if the are automounted */
+#define NFS_SQUISH_SOFT 0x0004 /* Treat all soft mounts as though they were on a mobile machine */
+#define NFS_SQUISH_QUICK 0x0008 /* Try to squish mounts more quickly. */
+#define NFS_SQUISH_SHUTDOWN 0x1000 /* Squish all mounts on shutdown. Currently not implemented */
uint32_t nfs_squishy_flags = NFS_SQUISH_MOBILE_ONLY | NFS_SQUISH_AUTOMOUNTED_ONLY | NFS_SQUISH_QUICK;
int32_t nfs_is_mobile;
-#define NFS_SQUISHY_DEADTIMEOUT 8 /* Dead time out for squishy mounts */
-#define NFS_SQUISHY_QUICKTIMEOUT 4 /* Quicker dead time out when nfs_squish_flags NFS_SQUISH_QUICK bit is set*/
+#define NFS_SQUISHY_DEADTIMEOUT 8 /* Dead time out for squishy mounts */
+#define NFS_SQUISHY_QUICKTIMEOUT 4 /* Quicker dead time out when nfs_squish_flags NFS_SQUISH_QUICK bit is set*/
/*
* Could this mount be squished?
uint64_t flags = vfs_flags(nmp->nm_mountp);
int softsquish = ((nfs_squishy_flags & NFS_SQUISH_SOFT) & NMFLAG(nmp, SOFT));
- if (!softsquish && (nfs_squishy_flags & NFS_SQUISH_MOBILE_ONLY) && nfs_is_mobile == 0)
- return (0);
+ if (!softsquish && (nfs_squishy_flags & NFS_SQUISH_MOBILE_ONLY) && nfs_is_mobile == 0) {
+ return 0;
+ }
- if ((nfs_squishy_flags & NFS_SQUISH_AUTOMOUNTED_ONLY) && (flags & MNT_AUTOMOUNTED) == 0)
- return (0);
+ if ((nfs_squishy_flags & NFS_SQUISH_AUTOMOUNTED_ONLY) && (flags & MNT_AUTOMOUNTED) == 0) {
+ return 0;
+ }
- return (1);
+ return 1;
}
/*
int timeo = (nfs_squishy_flags & NFS_SQUISH_QUICK) ? NFS_SQUISHY_QUICKTIMEOUT : NFS_SQUISHY_DEADTIMEOUT;
NFS_SOCK_DBG("%s: nm_curdeadtimeout = %d, nfs_is_mobile = %d\n",
- vfs_statfs(mp)->f_mntfromname, nmp->nm_curdeadtimeout, nfs_is_mobile);
+ vfs_statfs(mp)->f_mntfromname, nmp->nm_curdeadtimeout, nfs_is_mobile);
- if (!nfs_can_squish(nmp))
+ if (!nfs_can_squish(nmp)) {
goto out;
+ }
- timeo = (nmp->nm_deadtimeout > timeo) ? max(nmp->nm_deadtimeout/8, timeo) : timeo;
+ timeo = (nmp->nm_deadtimeout > timeo) ? max(nmp->nm_deadtimeout / 8, timeo) : timeo;
NFS_SOCK_DBG("nm_writers = %d nm_mappers = %d timeo = %d\n", nmp->nm_writers, nmp->nm_mappers, timeo);
if (nmp->nm_writers == 0 && nmp->nm_mappers == 0) {
uint64_t flags = mp ? vfs_flags(mp) : 0;
squishy = 1;
-
- /*
- * Walk the nfs nodes and check for dirty buffers it we're not
+
+ /*
+ * Walk the nfs nodes and check for dirty buffers it we're not
* RDONLY and we've not already been declared as squishy since
* this can be a bit expensive.
*/
- if (!(flags & MNT_RDONLY) && !(nmp->nm_state & NFSSTA_SQUISHY))
+ if (!(flags & MNT_RDONLY) && !(nmp->nm_state & NFSSTA_SQUISHY)) {
squishy = !nfs_mount_is_dirty(mp);
+ }
}
out:
- if (squishy)
+ if (squishy) {
nmp->nm_state |= NFSSTA_SQUISHY;
- else
+ } else {
nmp->nm_state &= ~NFSSTA_SQUISHY;
+ }
nmp->nm_curdeadtimeout = squishy ? timeo : nmp->nm_deadtimeout;
-
+
NFS_SOCK_DBG("nm_curdeadtimeout = %d\n", nmp->nm_curdeadtimeout);
- return (squishy);
+ return squishy;
}
/*
lck_mtx_lock(&nmp->nm_lock);
if (nmp->nm_state & NFSSTA_DEAD) {
lck_mtx_unlock(&nmp->nm_lock);
- return (1);
+ return 1;
}
if ((error != ENETUNREACH && error != EHOSTUNREACH && error != EADDRNOTAVAIL) ||
!(nmp->nm_locations.nl_numlocs == 1 && nmp->nm_locations.nl_locations[0]->nl_servcount == 1)) {
lck_mtx_unlock(&nmp->nm_lock);
- return (0);
+ return 0;
}
if ((nfs_squishy_flags & NFS_SQUISH_QUICK) && nfs_is_squishy(nmp)) {
lck_mtx_unlock(&nmp->nm_lock);
nfs_mount_zombie(nmp, NFSSTA_DEAD);
vfs_event_signal(&fsid, VQ_DEAD, 0);
- return (1);
+ return 1;
}
lck_mtx_unlock(&nmp->nm_lock);
- return (0);
+ return 0;
}
/*
* a timeout?
*/
int cache_ok = (nfs_is_mobile || NMFLAG(nmp, SOFT) ||
- nfs_can_squish(nmp) || nmp->nm_deadtimeout);
+ nfs_can_squish(nmp) || nmp->nm_deadtimeout);
int timeoutmask = NFSSTA_TIMEO | NFSSTA_LOCKTIMEO | NFSSTA_JUKEBOXTIMEO;
* return 1 to not get things out of the cache.
*/
- return ((nmp->nm_state & timeoutmask) && cache_ok);
+ return (nmp->nm_state & timeoutmask) && cache_ok;
}
/*
uint32_t do_vfs_signal = 0;
struct timeval now;
- if (nfs_mount_gone(nmp))
+ if (nfs_mount_gone(nmp)) {
return;
+ }
lck_mtx_lock(&nmp->nm_lock);
timeoutmask = NFSSTA_TIMEO | NFSSTA_LOCKTIMEO | NFSSTA_JUKEBOXTIMEO;
- if (NMFLAG(nmp, MUTEJUKEBOX)) /* jukebox timeouts don't count as unresponsive if muted */
- timeoutmask &= ~NFSSTA_JUKEBOXTIMEO;
+ if (NMFLAG(nmp, MUTEJUKEBOX)) { /* jukebox timeouts don't count as unresponsive if muted */
+ timeoutmask &= ~NFSSTA_JUKEBOXTIMEO;
+ }
wasunresponsive = (nmp->nm_state & timeoutmask);
/* XXX don't allow users to know about/disconnect unresponsive, soft, nobrowse mounts */
softnobrowse = (NMFLAG(nmp, SOFT) && (vfs_flags(nmp->nm_mountp) & MNT_DONTBROWSE));
- if ((flags & NFSSTA_TIMEO) && !(nmp->nm_state & NFSSTA_TIMEO))
+ if ((flags & NFSSTA_TIMEO) && !(nmp->nm_state & NFSSTA_TIMEO)) {
nmp->nm_state |= NFSSTA_TIMEO;
- if ((flags & NFSSTA_LOCKTIMEO) && !(nmp->nm_state & NFSSTA_LOCKTIMEO))
+ }
+ if ((flags & NFSSTA_LOCKTIMEO) && !(nmp->nm_state & NFSSTA_LOCKTIMEO)) {
nmp->nm_state |= NFSSTA_LOCKTIMEO;
- if ((flags & NFSSTA_JUKEBOXTIMEO) && !(nmp->nm_state & NFSSTA_JUKEBOXTIMEO))
+ }
+ if ((flags & NFSSTA_JUKEBOXTIMEO) && !(nmp->nm_state & NFSSTA_JUKEBOXTIMEO)) {
nmp->nm_state |= NFSSTA_JUKEBOXTIMEO;
+ }
unresponsive = (nmp->nm_state & timeoutmask);
nmp->nm_deadto_start = now.tv_sec;
nfs_mount_sock_thread_wake(nmp);
} else if ((now.tv_sec - nmp->nm_deadto_start) > nmp->nm_curdeadtimeout && !holding_state) {
- if (!(nmp->nm_state & NFSSTA_DEAD))
+ if (!(nmp->nm_state & NFSSTA_DEAD)) {
printf("nfs server %s: %sdead\n", vfs_statfs(nmp->nm_mountp)->f_mntfromname,
- (nmp->nm_curdeadtimeout != nmp->nm_deadtimeout) ? "squished " : "");
+ (nmp->nm_curdeadtimeout != nmp->nm_deadtimeout) ? "squished " : "");
+ }
do_vfs_signal = VQ_DEAD;
}
}
lck_mtx_unlock(&nmp->nm_lock);
- if (do_vfs_signal == VQ_DEAD && !(nmp->nm_state & NFSSTA_DEAD))
+ if (do_vfs_signal == VQ_DEAD && !(nmp->nm_state & NFSSTA_DEAD)) {
nfs_mount_zombie(nmp, NFSSTA_DEAD);
- else if (softnobrowse || wasunresponsive || !unresponsive)
+ } else if (softnobrowse || wasunresponsive || !unresponsive) {
do_vfs_signal = 0;
- else
+ } else {
do_vfs_signal = VQ_NOTRESP;
- if (do_vfs_signal)
+ }
+ if (do_vfs_signal) {
vfs_event_signal(&vfs_statfs(nmp->nm_mountp)->f_fsid, do_vfs_signal, 0);
+ }
nfs_msg(thd, vfs_statfs(nmp->nm_mountp)->f_mntfromname, msg, error);
}
int timeoutmask, wasunresponsive, unresponsive, softnobrowse;
int do_vfs_signal;
- if (nfs_mount_gone(nmp))
+ if (nfs_mount_gone(nmp)) {
return;
+ }
- if (msg)
+ if (msg) {
nfs_msg(thd, vfs_statfs(nmp->nm_mountp)->f_mntfromname, msg, 0);
+ }
lck_mtx_lock(&nmp->nm_lock);
timeoutmask = NFSSTA_TIMEO | NFSSTA_LOCKTIMEO | NFSSTA_JUKEBOXTIMEO;
- if (NMFLAG(nmp, MUTEJUKEBOX)) /* jukebox timeouts don't count as unresponsive if muted */
- timeoutmask &= ~NFSSTA_JUKEBOXTIMEO;
+ if (NMFLAG(nmp, MUTEJUKEBOX)) { /* jukebox timeouts don't count as unresponsive if muted */
+ timeoutmask &= ~NFSSTA_JUKEBOXTIMEO;
+ }
wasunresponsive = (nmp->nm_state & timeoutmask);
/* XXX don't allow users to know about/disconnect unresponsive, soft, nobrowse mounts */
softnobrowse = (NMFLAG(nmp, SOFT) && (vfs_flags(nmp->nm_mountp) & MNT_DONTBROWSE));
- if ((flags & NFSSTA_TIMEO) && (nmp->nm_state & NFSSTA_TIMEO))
+ if ((flags & NFSSTA_TIMEO) && (nmp->nm_state & NFSSTA_TIMEO)) {
nmp->nm_state &= ~NFSSTA_TIMEO;
- if ((flags & NFSSTA_LOCKTIMEO) && (nmp->nm_state & NFSSTA_LOCKTIMEO))
+ }
+ if ((flags & NFSSTA_LOCKTIMEO) && (nmp->nm_state & NFSSTA_LOCKTIMEO)) {
nmp->nm_state &= ~NFSSTA_LOCKTIMEO;
- if ((flags & NFSSTA_JUKEBOXTIMEO) && (nmp->nm_state & NFSSTA_JUKEBOXTIMEO))
+ }
+ if ((flags & NFSSTA_JUKEBOXTIMEO) && (nmp->nm_state & NFSSTA_JUKEBOXTIMEO)) {
nmp->nm_state &= ~NFSSTA_JUKEBOXTIMEO;
+ }
unresponsive = (nmp->nm_state & timeoutmask);
nmp->nm_state &= ~NFSSTA_SQUISHY;
lck_mtx_unlock(&nmp->nm_lock);
- if (softnobrowse)
+ if (softnobrowse) {
do_vfs_signal = 0;
- else
+ } else {
do_vfs_signal = (wasunresponsive && !unresponsive);
- if (do_vfs_signal)
+ }
+ if (do_vfs_signal) {
vfs_event_signal(&vfs_statfs(nmp->nm_mountp)->f_fsid, VQ_NOTRESP, 1);
+ }
}
int err, error;
err = nd->nd_repstat;
- if (err && (nd->nd_vers == NFS_VER2))
+ if (err && (nd->nd_vers == NFS_VER2)) {
siz = 0;
+ }
/*
* If this is a big reply, use a cluster else
if (error) {
/* unable to allocate packet */
/* XXX should we keep statistics for these errors? */
- return (error);
+ return error;
}
if (siz < nfs_mbuf_minclsize) {
/* leave space for lower level headers */
tl = mbuf_data(mrep);
- tl += 80/sizeof(*tl); /* XXX max_hdr? XXX */
+ tl += 80 / sizeof(*tl); /* XXX max_hdr? XXX */
mbuf_setdata(mrep, tl, 6 * NFSX_UNSIGNED);
}
nfsm_chain_init(&nmrep, mrep);
break;
default:
nfsm_chain_add_32(error, &nmrep, RPC_SUCCESS);
- if (nd->nd_gss_context != NULL)
+ if (nd->nd_gss_context != NULL) {
error = nfs_gss_svc_prepare_reply(nd, &nmrep);
- if (err != NFSERR_RETVOID)
+ }
+ if (err != NFSERR_RETVOID) {
nfsm_chain_add_32(error, &nmrep,
- (err ? nfsrv_errmap(nd, err) : 0));
+ (err ? nfsrv_errmap(nd, err) : 0));
+ }
break;
}
}
/* error composing reply header */
/* XXX should we keep statistics for these errors? */
mbuf_freem(mrep);
- return (error);
+ return error;
}
*nmrepp = nmrep;
- if ((err != 0) && (err != NFSERR_RETVOID))
+ if ((err != 0) && (err != NFSERR_RETVOID)) {
OSAddAtomic64(1, &nfsstats.srvrpc_errs);
- return (0);
+ }
+ return 0;
}
/*
}
}
error = sock_sendmbuf(so, &msg, top, 0, NULL);
- if (!error)
- return (0);
+ if (!error) {
+ return 0;
+ }
log(LOG_INFO, "nfsd send error %d\n", error);
- if ((error == EWOULDBLOCK) && (slp->ns_sotype == SOCK_STREAM))
+ if ((error == EWOULDBLOCK) && (slp->ns_sotype == SOCK_STREAM)) {
error = EPIPE; /* zap TCP sockets if they time out on send */
-
+ }
/* Handle any recoverable (soft) socket errors here. (???) */
if (error != EINTR && error != ERESTART && error != EIO &&
- error != EWOULDBLOCK && error != EPIPE)
+ error != EWOULDBLOCK && error != EPIPE) {
error = 0;
+ }
- return (error);
+ return error;
}
/*
{
struct nfsrv_sock *slp = arg;
- if (!nfsd_thread_count || !(slp->ns_flag & SLP_VALID))
+ if (!nfsd_thread_count || !(slp->ns_flag & SLP_VALID)) {
return;
+ }
lck_rw_lock_exclusive(&slp->ns_rwlock);
nfsrv_rcv_locked(so, slp, waitflag);
nfsrv_rcv_locked(socket_t so, struct nfsrv_sock *slp, int waitflag)
{
mbuf_t m, mp, mhck, m2;
- int ns_flag=0, error;
- struct msghdr msg;
+ int ns_flag = 0, error;
+ struct msghdr msg;
size_t bytes_read;
if ((slp->ns_flag & SLP_VALID) == 0) {
- if (waitflag == MBUF_DONTWAIT)
+ if (waitflag == MBUF_DONTWAIT) {
lck_rw_done(&slp->ns_rwlock);
+ }
return;
}
bytes_read = 1000000000;
error = sock_receivembuf(so, NULL, &mp, MSG_DONTWAIT, &bytes_read);
if (error || mp == NULL) {
- if (error == EWOULDBLOCK)
+ if (error == EWOULDBLOCK) {
ns_flag = (waitflag == MBUF_DONTWAIT) ? SLP_NEEDQ : 0;
- else
+ } else {
ns_flag = SLP_DISCONN;
+ }
goto dorecs;
}
m = mp;
if (slp->ns_rawend) {
- if ((error = mbuf_setnext(slp->ns_rawend, m)))
+ if ((error = mbuf_setnext(slp->ns_rawend, m))) {
panic("nfsrv_rcv: mbuf_setnext failed %d\n", error);
+ }
slp->ns_cc += bytes_read;
} else {
slp->ns_raw = m;
slp->ns_cc = bytes_read;
}
- while ((m2 = mbuf_next(m)))
+ while ((m2 = mbuf_next(m))) {
m = m2;
+ }
slp->ns_rawend = m;
/*
*/
error = nfsrv_getstream(slp, waitflag);
if (error) {
- if (error == EPERM)
+ if (error == EPERM) {
ns_flag = SLP_DISCONN;
- else
+ } else {
ns_flag = SLP_NEEDQ;
+ }
}
} else {
- struct sockaddr_storage nam;
+ struct sockaddr_storage nam;
if (slp->ns_reccnt >= nfsrv_sock_max_rec_queue_length) {
/* already have max # RPC records queued on this socket */
} else {
m = mp;
}
- if (slp->ns_recend)
+ if (slp->ns_recend) {
mbuf_setnextpkt(slp->ns_recend, m);
- else {
+ } else {
slp->ns_rec = m;
slp->ns_flag |= SLP_DOREC;
}
* Now try and process the request records, non-blocking.
*/
dorecs:
- if (ns_flag)
+ if (ns_flag) {
slp->ns_flag |= ns_flag;
+ }
if (waitflag == MBUF_DONTWAIT) {
int wake = (slp->ns_flag & SLP_WORKTODO);
lck_rw_done(&slp->ns_rwlock);
mbuf_t om, m2, recm;
u_int32_t recmark;
- if (slp->ns_flag & SLP_GETSTREAM)
+ if (slp->ns_flag & SLP_GETSTREAM) {
panic("nfs getstream");
+ }
slp->ns_flag |= SLP_GETSTREAM;
for (;;) {
- if (slp->ns_reclen == 0) {
- if (slp->ns_cc < NFSX_UNSIGNED) {
- slp->ns_flag &= ~SLP_GETSTREAM;
- return (0);
- }
- m = slp->ns_raw;
- mdata = mbuf_data(m);
- mlen = mbuf_len(m);
- if (mlen >= NFSX_UNSIGNED) {
- bcopy(mdata, (caddr_t)&recmark, NFSX_UNSIGNED);
- mdata += NFSX_UNSIGNED;
- mlen -= NFSX_UNSIGNED;
- mbuf_setdata(m, mdata, mlen);
- } else {
- cp1 = (caddr_t)&recmark;
- cp2 = mdata;
- while (cp1 < ((caddr_t)&recmark) + NFSX_UNSIGNED) {
- while (mlen == 0) {
- m = mbuf_next(m);
- cp2 = mbuf_data(m);
- mlen = mbuf_len(m);
- }
- *cp1++ = *cp2++;
- mlen--;
- mbuf_setdata(m, cp2, mlen);
- }
- }
- slp->ns_cc -= NFSX_UNSIGNED;
- recmark = ntohl(recmark);
- slp->ns_reclen = recmark & ~0x80000000;
- if (recmark & 0x80000000)
- slp->ns_flag |= SLP_LASTFRAG;
- else
- slp->ns_flag &= ~SLP_LASTFRAG;
- if (slp->ns_reclen <= 0 || slp->ns_reclen > NFS_MAXPACKET) {
- slp->ns_flag &= ~SLP_GETSTREAM;
- return (EPERM);
- }
- }
-
- /*
- * Now get the record part.
- *
- * Note that slp->ns_reclen may be 0. Linux sometimes
- * generates 0-length RPCs
- */
- recm = NULL;
- if (slp->ns_cc == slp->ns_reclen) {
- recm = slp->ns_raw;
- slp->ns_raw = slp->ns_rawend = NULL;
- slp->ns_cc = slp->ns_reclen = 0;
- } else if (slp->ns_cc > slp->ns_reclen) {
- len = 0;
- m = slp->ns_raw;
- mlen = mbuf_len(m);
- mdata = mbuf_data(m);
- om = NULL;
- while (len < slp->ns_reclen) {
- if ((len + mlen) > slp->ns_reclen) {
- if (mbuf_copym(m, 0, slp->ns_reclen - len, waitflag, &m2)) {
- slp->ns_flag &= ~SLP_GETSTREAM;
- return (EWOULDBLOCK);
+ if (slp->ns_reclen == 0) {
+ if (slp->ns_cc < NFSX_UNSIGNED) {
+ slp->ns_flag &= ~SLP_GETSTREAM;
+ return 0;
+ }
+ m = slp->ns_raw;
+ mdata = mbuf_data(m);
+ mlen = mbuf_len(m);
+ if (mlen >= NFSX_UNSIGNED) {
+ bcopy(mdata, (caddr_t)&recmark, NFSX_UNSIGNED);
+ mdata += NFSX_UNSIGNED;
+ mlen -= NFSX_UNSIGNED;
+ mbuf_setdata(m, mdata, mlen);
+ } else {
+ cp1 = (caddr_t)&recmark;
+ cp2 = mdata;
+ while (cp1 < ((caddr_t)&recmark) + NFSX_UNSIGNED) {
+ while (mlen == 0) {
+ m = mbuf_next(m);
+ cp2 = mbuf_data(m);
+ mlen = mbuf_len(m);
+ }
+ *cp1++ = *cp2++;
+ mlen--;
+ mbuf_setdata(m, cp2, mlen);
}
- if (om) {
- if (mbuf_setnext(om, m2)) {
- /* trouble... just drop it */
- printf("nfsrv_getstream: mbuf_setnext failed\n");
- mbuf_freem(m2);
+ }
+ slp->ns_cc -= NFSX_UNSIGNED;
+ recmark = ntohl(recmark);
+ slp->ns_reclen = recmark & ~0x80000000;
+ if (recmark & 0x80000000) {
+ slp->ns_flag |= SLP_LASTFRAG;
+ } else {
+ slp->ns_flag &= ~SLP_LASTFRAG;
+ }
+ if (slp->ns_reclen <= 0 || slp->ns_reclen > NFS_MAXPACKET) {
+ slp->ns_flag &= ~SLP_GETSTREAM;
+ return EPERM;
+ }
+ }
+
+ /*
+ * Now get the record part.
+ *
+ * Note that slp->ns_reclen may be 0. Linux sometimes
+ * generates 0-length RPCs
+ */
+ recm = NULL;
+ if (slp->ns_cc == slp->ns_reclen) {
+ recm = slp->ns_raw;
+ slp->ns_raw = slp->ns_rawend = NULL;
+ slp->ns_cc = slp->ns_reclen = 0;
+ } else if (slp->ns_cc > slp->ns_reclen) {
+ len = 0;
+ m = slp->ns_raw;
+ mlen = mbuf_len(m);
+ mdata = mbuf_data(m);
+ om = NULL;
+ while (len < slp->ns_reclen) {
+ if ((len + mlen) > slp->ns_reclen) {
+ if (mbuf_copym(m, 0, slp->ns_reclen - len, waitflag, &m2)) {
slp->ns_flag &= ~SLP_GETSTREAM;
- return (EWOULDBLOCK);
+ return EWOULDBLOCK;
+ }
+ if (om) {
+ if (mbuf_setnext(om, m2)) {
+ /* trouble... just drop it */
+ printf("nfsrv_getstream: mbuf_setnext failed\n");
+ mbuf_freem(m2);
+ slp->ns_flag &= ~SLP_GETSTREAM;
+ return EWOULDBLOCK;
+ }
+ recm = slp->ns_raw;
+ } else {
+ recm = m2;
}
+ mdata += slp->ns_reclen - len;
+ mlen -= slp->ns_reclen - len;
+ mbuf_setdata(m, mdata, mlen);
+ len = slp->ns_reclen;
+ } else if ((len + mlen) == slp->ns_reclen) {
+ om = m;
+ len += mlen;
+ m = mbuf_next(m);
recm = slp->ns_raw;
+ if (mbuf_setnext(om, NULL)) {
+ printf("nfsrv_getstream: mbuf_setnext failed 2\n");
+ slp->ns_flag &= ~SLP_GETSTREAM;
+ return EWOULDBLOCK;
+ }
+ mlen = mbuf_len(m);
+ mdata = mbuf_data(m);
} else {
- recm = m2;
- }
- mdata += slp->ns_reclen - len;
- mlen -= slp->ns_reclen - len;
- mbuf_setdata(m, mdata, mlen);
- len = slp->ns_reclen;
- } else if ((len + mlen) == slp->ns_reclen) {
- om = m;
- len += mlen;
- m = mbuf_next(m);
- recm = slp->ns_raw;
- if (mbuf_setnext(om, NULL)) {
- printf("nfsrv_getstream: mbuf_setnext failed 2\n");
- slp->ns_flag &= ~SLP_GETSTREAM;
- return (EWOULDBLOCK);
+ om = m;
+ len += mlen;
+ m = mbuf_next(m);
+ mlen = mbuf_len(m);
+ mdata = mbuf_data(m);
}
- mlen = mbuf_len(m);
- mdata = mbuf_data(m);
+ }
+ slp->ns_raw = m;
+ slp->ns_cc -= len;
+ slp->ns_reclen = 0;
+ } else {
+ slp->ns_flag &= ~SLP_GETSTREAM;
+ return 0;
+ }
+
+ /*
+ * Accumulate the fragments into a record.
+ */
+ if (slp->ns_frag == NULL) {
+ slp->ns_frag = recm;
+ } else {
+ m = slp->ns_frag;
+ while ((m2 = mbuf_next(m))) {
+ m = m2;
+ }
+ if ((error = mbuf_setnext(m, recm))) {
+ panic("nfsrv_getstream: mbuf_setnext failed 3, %d\n", error);
+ }
+ }
+ if (slp->ns_flag & SLP_LASTFRAG) {
+ if (slp->ns_recend) {
+ mbuf_setnextpkt(slp->ns_recend, slp->ns_frag);
} else {
- om = m;
- len += mlen;
- m = mbuf_next(m);
- mlen = mbuf_len(m);
- mdata = mbuf_data(m);
- }
- }
- slp->ns_raw = m;
- slp->ns_cc -= len;
- slp->ns_reclen = 0;
- } else {
- slp->ns_flag &= ~SLP_GETSTREAM;
- return (0);
- }
-
- /*
- * Accumulate the fragments into a record.
- */
- if (slp->ns_frag == NULL) {
- slp->ns_frag = recm;
- } else {
- m = slp->ns_frag;
- while ((m2 = mbuf_next(m)))
- m = m2;
- if ((error = mbuf_setnext(m, recm)))
- panic("nfsrv_getstream: mbuf_setnext failed 3, %d\n", error);
- }
- if (slp->ns_flag & SLP_LASTFRAG) {
- if (slp->ns_recend)
- mbuf_setnextpkt(slp->ns_recend, slp->ns_frag);
- else {
- slp->ns_rec = slp->ns_frag;
- slp->ns_flag |= SLP_DOREC;
- }
- slp->ns_recend = slp->ns_frag;
- slp->ns_frag = NULL;
- }
+ slp->ns_rec = slp->ns_frag;
+ slp->ns_flag |= SLP_DOREC;
+ }
+ slp->ns_recend = slp->ns_frag;
+ slp->ns_frag = NULL;
+ }
}
}
int error = 0;
*ndp = NULL;
- if (!(slp->ns_flag & (SLP_VALID|SLP_DOREC)) || (slp->ns_rec == NULL))
- return (ENOBUFS);
+ if (!(slp->ns_flag & (SLP_VALID | SLP_DOREC)) || (slp->ns_rec == NULL)) {
+ return ENOBUFS;
+ }
MALLOC_ZONE(nd, struct nfsrv_descript *,
- sizeof (struct nfsrv_descript), M_NFSRVDESC, M_WAITOK);
- if (!nd)
- return (ENOMEM);
+ sizeof(struct nfsrv_descript), M_NFSRVDESC, M_WAITOK);
+ if (!nd) {
+ return ENOMEM;
+ }
m = slp->ns_rec;
slp->ns_rec = mbuf_nextpkt(m);
- if (slp->ns_rec)
+ if (slp->ns_rec) {
mbuf_setnextpkt(m, NULL);
- else {
+ } else {
slp->ns_flag &= ~SLP_DOREC;
slp->ns_recend = NULL;
}
if (mbuf_type(m) == MBUF_TYPE_SONAME) {
nam = m;
m = mbuf_next(m);
- if ((error = mbuf_setnext(nam, NULL)))
+ if ((error = mbuf_setnext(nam, NULL))) {
panic("nfsrv_dorec: mbuf_setnext failed %d\n", error);
- } else
+ }
+ } else {
nam = NULL;
+ }
nd->nd_nam2 = nam;
nfsm_chain_dissect_init(error, &nd->nd_nmreq, m);
- if (!error)
+ if (!error) {
error = nfsrv_getreq(nd);
+ }
if (error) {
- if (nam)
+ if (nam) {
mbuf_freem(nam);
- if (nd->nd_gss_context)
+ }
+ if (nd->nd_gss_context) {
nfs_gss_svc_ctx_deref(nd->nd_gss_context);
+ }
FREE_ZONE(nd, sizeof(*nd), M_NFSRVDESC);
- return (error);
+ return error;
}
nd->nd_mrep = NULL;
*ndp = nd;
nfsd->nfsd_nd = nd;
- return (0);
+ return 0;
}
/*
val = auth_type = len = 0;
nmreq = &nd->nd_nmreq;
- nfsm_chain_get_32(error, nmreq, nd->nd_retxid); // XID
- nfsm_chain_get_32(error, nmreq, val); // RPC Call
- if (!error && (val != RPC_CALL))
+ nfsm_chain_get_32(error, nmreq, nd->nd_retxid); // XID
+ nfsm_chain_get_32(error, nmreq, val); // RPC Call
+ if (!error && (val != RPC_CALL)) {
error = EBADRPC;
+ }
nfsmout_if(error);
nd->nd_repstat = 0;
- nfsm_chain_get_32(error, nmreq, val); // RPC Version
+ nfsm_chain_get_32(error, nmreq, val); // RPC Version
nfsmout_if(error);
if (val != RPC_VER2) {
nd->nd_repstat = ERPCMISMATCH;
nd->nd_procnum = NFSPROC_NOOP;
- return (0);
+ return 0;
}
- nfsm_chain_get_32(error, nmreq, val); // RPC Program Number
+ nfsm_chain_get_32(error, nmreq, val); // RPC Program Number
nfsmout_if(error);
if (val != NFS_PROG) {
nd->nd_repstat = EPROGUNAVAIL;
nd->nd_procnum = NFSPROC_NOOP;
- return (0);
+ return 0;
}
nfsm_chain_get_32(error, nmreq, nfsvers);// NFS Version Number
nfsmout_if(error);
if ((nfsvers < NFS_VER2) || (nfsvers > NFS_VER3)) {
nd->nd_repstat = EPROGMISMATCH;
nd->nd_procnum = NFSPROC_NOOP;
- return (0);
+ return 0;
}
nd->nd_vers = nfsvers;
nfsm_chain_get_32(error, nmreq, nd->nd_procnum);// NFS Procedure Number
nfsmout_if(error);
if ((nd->nd_procnum >= NFS_NPROCS) ||
- ((nd->nd_vers == NFS_VER2) && (nd->nd_procnum > NFSV2PROC_STATFS))) {
+ ((nd->nd_vers == NFS_VER2) && (nd->nd_procnum > NFSV2PROC_STATFS))) {
nd->nd_repstat = EPROCUNAVAIL;
nd->nd_procnum = NFSPROC_NOOP;
- return (0);
+ return 0;
}
- if (nfsvers != NFS_VER3)
+ if (nfsvers != NFS_VER3) {
nd->nd_procnum = nfsv3_procid[nd->nd_procnum];
- nfsm_chain_get_32(error, nmreq, auth_type); // Auth Flavor
- nfsm_chain_get_32(error, nmreq, len); // Auth Length
- if (!error && (len < 0 || len > RPCAUTH_MAXSIZ))
+ }
+ nfsm_chain_get_32(error, nmreq, auth_type); // Auth Flavor
+ nfsm_chain_get_32(error, nmreq, len); // Auth Length
+ if (!error && (len < 0 || len > RPCAUTH_MAXSIZ)) {
error = EBADRPC;
+ }
nfsmout_if(error);
/* Handle authentication */
if (auth_type == RPCAUTH_SYS) {
struct posix_cred temp_pcred;
- if (nd->nd_procnum == NFSPROC_NULL)
- return (0);
+ if (nd->nd_procnum == NFSPROC_NULL) {
+ return 0;
+ }
nd->nd_sec = RPCAUTH_SYS;
- nfsm_chain_adv(error, nmreq, NFSX_UNSIGNED); // skip stamp
- nfsm_chain_get_32(error, nmreq, len); // hostname length
- if (len < 0 || len > NFS_MAXNAMLEN)
+ nfsm_chain_adv(error, nmreq, NFSX_UNSIGNED); // skip stamp
+ nfsm_chain_get_32(error, nmreq, len); // hostname length
+ if (len < 0 || len > NFS_MAXNAMLEN) {
error = EBADRPC;
- nfsm_chain_adv(error, nmreq, nfsm_rndup(len)); // skip hostname
+ }
+ nfsm_chain_adv(error, nmreq, nfsm_rndup(len)); // skip hostname
nfsmout_if(error);
/* create a temporary credential using the bits from the wire */
nfsm_chain_get_32(error, nmreq, user_id);
nfsm_chain_get_32(error, nmreq, group_id);
temp_pcred.cr_groups[0] = group_id;
- nfsm_chain_get_32(error, nmreq, len); // extra GID count
- if ((len < 0) || (len > RPCAUTH_UNIXGIDS))
+ nfsm_chain_get_32(error, nmreq, len); // extra GID count
+ if ((len < 0) || (len > RPCAUTH_UNIXGIDS)) {
error = EBADRPC;
+ }
nfsmout_if(error);
- for (i = 1; i <= len; i++)
- if (i < NGROUPS)
+ for (i = 1; i <= len; i++) {
+ if (i < NGROUPS) {
nfsm_chain_get_32(error, nmreq, temp_pcred.cr_groups[i]);
- else
+ } else {
nfsm_chain_adv(error, nmreq, NFSX_UNSIGNED);
+ }
+ }
nfsmout_if(error);
ngroups = (len >= NGROUPS) ? NGROUPS : (len + 1);
- if (ngroups > 1)
+ if (ngroups > 1) {
nfsrv_group_sort(&temp_pcred.cr_groups[0], ngroups);
- nfsm_chain_adv(error, nmreq, NFSX_UNSIGNED); // verifier flavor (should be AUTH_NONE)
- nfsm_chain_get_32(error, nmreq, len); // verifier length
- if (len < 0 || len > RPCAUTH_MAXSIZ)
+ }
+ nfsm_chain_adv(error, nmreq, NFSX_UNSIGNED); // verifier flavor (should be AUTH_NONE)
+ nfsm_chain_get_32(error, nmreq, len); // verifier length
+ if (len < 0 || len > RPCAUTH_MAXSIZ) {
error = EBADRPC;
- if (len > 0)
+ }
+ if (len > 0) {
nfsm_chain_adv(error, nmreq, nfsm_rndup(len));
+ }
/* request creation of a real credential */
temp_pcred.cr_uid = user_id;
if (nd->nd_cr == NULL) {
nd->nd_repstat = ENOMEM;
nd->nd_procnum = NFSPROC_NOOP;
- return (0);
+ return 0;
}
} else if (auth_type == RPCSEC_GSS) {
error = nfs_gss_svc_cred_get(nd, nmreq);
if (error) {
- if (error == EINVAL)
- goto nfsmout; // drop the request
+ if (error == EINVAL) {
+ goto nfsmout; // drop the request
+ }
nd->nd_repstat = error;
nd->nd_procnum = NFSPROC_NOOP;
- return (0);
+ return 0;
}
} else {
- if (nd->nd_procnum == NFSPROC_NULL) // assume it's AUTH_NONE
- return (0);
+ if (nd->nd_procnum == NFSPROC_NULL) { // assume it's AUTH_NONE
+ return 0;
+ }
nd->nd_repstat = (NFSERR_AUTHERR | AUTH_REJECTCRED);
nd->nd_procnum = NFSPROC_NOOP;
- return (0);
+ return 0;
}
- return (0);
+ return 0;
nfsmout:
- if (IS_VALID_CRED(nd->nd_cr))
+ if (IS_VALID_CRED(nd->nd_cr)) {
kauth_cred_unref(&nd->nd_cr);
+ }
nfsm_chain_cleanup(nmreq);
- return (error);
+ return error;
}
/*
{
struct nfsd *nd;
- if ((slp->ns_flag & SLP_VALID) == 0)
+ if ((slp->ns_flag & SLP_VALID) == 0) {
return;
+ }
lck_rw_lock_exclusive(&slp->ns_rwlock);
/* if there's work to do on this socket, make sure it's queued up */
/* wake up a waiting nfsd, if possible */
nd = TAILQ_FIRST(&nfsd_queue);
- if (!nd)
+ if (!nd) {
return;
+ }
TAILQ_REMOVE(&nfsd_queue, nd, nfsd_queue);
nd->nfsd_flag &= ~NFSD_WAITING;