summaryrefslogtreecommitdiff
path: root/nfs/rpc.c
diff options
context:
space:
mode:
authorMarcus Brinkmann <marcus@gnu.org>2002-09-29 15:11:59 +0000
committerMarcus Brinkmann <marcus@gnu.org>2002-09-29 15:11:59 +0000
commit5942bd6f73499f198b23975b8d7b8df1383934d8 (patch)
tree3494bab9ac5bc1fc0be29906ec508e393b01f106 /nfs/rpc.c
parent253348bac2dced91688712d909059a035d5b9b0c (diff)
2002-09-29 Marcus Brinkmann <marcus@gnu.org>
* mount.c (mount_root): Add parenthesis for post-decrement (even though it is only used as an lvalue here). Increment P after using it in the macro, not within. * rpc.c (initialize_rpc, conduct_rpc): Likewise. * ops.c (process_returned_stat, process_wcc_stat, netfs_validate_stat, netfs_attempt_chown, netfs_attempt_chmod, netfs_attempt_utimes, netfs_attempt_set_size, netfs_attempt_statfs, netfs_attempt_read, netfs_attempt_write, verify_nonexistent, netfs_attempt_lookup, netfs_attempt_mkdir, netfs_attempt_rmdir, netfs_attempt_link, netfs_attempt_create_file, netfs_attempt_unlink, netfs_attempt_rename, netfs_attempt_readlink, netfs_report_access, netfs_check_open_permissions): Likewise. (fetch_directory): Likewise. Also use memcpy instead bcopy. * cache.c (recache_handle): Likewise. * nfs.c (xdr_encode_data, xdr_encode_sattr_mode, xdr_encode_sattr_ids, xdr_encode_sattr_size, xdr_encode_sattr_times, xdr_encode_create_state, xdr_encode_sattr_stat, xdr_decode_64bit, xdr_decode_fattr): Likewise. (xdr_decode_string): Likewise. Also use memcpy instead bcopy. (xdr_decode_fhandle): Likewise. Also use memcpy instead bcopy.
Diffstat (limited to 'nfs/rpc.c')
-rw-r--r--nfs/rpc.c110
1 files changed, 58 insertions, 52 deletions
diff --git a/nfs/rpc.c b/nfs/rpc.c
index 252acfa3..f5e19066 100644
--- a/nfs/rpc.c
+++ b/nfs/rpc.c
@@ -1,4 +1,4 @@
-/* SunRPC management for NFS client
+/* rpc.c - SunRPC management for NFS client.
Copyright (C) 1994, 1995, 1996, 1997, 2002 Free Software Foundation
This program is free software; you can redistribute it and/or
@@ -17,10 +17,10 @@
#include "nfs.h"
-/* Needed in order to get the RPC header files to include correctly */
+/* Needed in order to get the RPC header files to include correctly. */
#undef TRUE
#undef FALSE
-#define malloc spoiufasdf /* Avoid bogus definition in rpc/types.h */
+#define malloc spoiufasdf /* Avoid bogus definition in rpc/types.h. */
#include <rpc/types.h>
#include <rpc/xdr.h>
@@ -28,7 +28,7 @@
#include <rpc/rpc_msg.h>
#include <rpc/auth_unix.h>
-#undef malloc /* Get rid of the sun block */
+#undef malloc /* Get rid of the sun block. */
#include <netinet/in.h>
#include <assert.h>
@@ -37,26 +37,26 @@
#include <unistd.h>
#include <stdio.h>
-/* One of these exists for each pending RPC. */
+/* One of these exists for each pending RPC. */
struct rpc_list
{
struct rpc_list *next, **prevp;
void *reply;
};
-/* A list of all pending RPCs. */
+/* A list of all pending RPCs. */
static struct rpc_list *outstanding_rpcs;
/* Wake up this condition when an outstanding RPC has received a reply
- or we should check for timeouts. */
+ or we should check for timeouts. */
static struct condition rpc_wakeup = CONDITION_INITIALIZER;
-/* Lock the global data and the REPLY fields of outstanding RPC's. */
+/* Lock the global data and the REPLY fields of outstanding RPC's. */
static struct mutex outstanding_lock = MUTEX_INITIALIZER;
-/* Generate and return a new transaction ID. */
+/* Generate and return a new transaction ID. */
static inline int
generate_xid ()
{
@@ -76,7 +76,7 @@ generate_xid ()
may be -1 to indicate that it does not apply, however, exactly zero
or two of UID and GID must be -1. The returned address is a pointer
to the start of the payload. If NULL is returned, an error occured
- and the code is set in errno. */
+ and the code is set in errno. */
int *
initialize_rpc (int program, int version, int rpc_proc,
size_t len, void **bufp,
@@ -100,52 +100,52 @@ initialize_rpc (int program, int version, int rpc_proc,
p = buf + sizeof (struct rpc_list);
/* RPC header */
- *p++ = htonl (generate_xid ());
- *p++ = htonl (CALL);
- *p++ = htonl (RPC_MSG_VERSION);
- *p++ = htonl (program);
- *p++ = htonl (version);
- *p++ = htonl (rpc_proc);
+ *(p++) = htonl (generate_xid ());
+ *(p++) = htonl (CALL);
+ *(p++) = htonl (RPC_MSG_VERSION);
+ *(p++) = htonl (program);
+ *(p++) = htonl (version);
+ *(p++) = htonl (rpc_proc);
assert ((uid == -1) == (gid == -1));
if (uid == -1)
{
/* No authentication */
- *p++ = htonl (AUTH_NONE);
- *p++ = 0;
+ *(p++) = htonl (AUTH_NONE);
+ *(p++) = 0;
}
else
{
/* Unixy authentication */
- *p++ = htonl (AUTH_UNIX);
+ *(p++) = htonl (AUTH_UNIX);
/* The length of the message. We do not yet know what this
is, so, just remember where we should put it when we know */
lenaddr = p++;
- *p++ = htonl (mapped_time->seconds);
+ *(p++) = htonl (mapped_time->seconds);
p = xdr_encode_string (p, hostname);
- *p++ = htonl (uid);
- *p++ = htonl (gid);
+ *(p++) = htonl (uid);
+ *(p++) = htonl (gid);
if (second_gid == -1)
- *p++ = 0;
+ *(p++) = 0;
else
{
- *p++ = htonl (1);
- *p++ = htonl (second_gid);
+ *(p++) = htonl (1);
+ *(p++) = htonl (second_gid);
}
*lenaddr = htonl ((p - (lenaddr + 1)) * sizeof (int));
}
/* VERF field */
- *p++ = htonl (AUTH_NONE);
- *p++ = 0;
+ *(p++) = htonl (AUTH_NONE);
+ *(p++) = 0;
*bufp = buf;
return p;
}
/* Remove HDR from the list of pending RPC's. The rpc_list's lock
- (OUTSTANDING_LOCK) must be held */
+ (OUTSTANDING_LOCK) must be held. */
static inline void
unlink_rpc (struct rpc_list *hdr)
{
@@ -155,7 +155,7 @@ unlink_rpc (struct rpc_list *hdr)
}
/* Insert HDR at the head of the LIST. The rpc_list's lock
- (OUTSTANDING_LOCK) must be held */
+ (OUTSTANDING_LOCK) must be held. */
static inline void
link_rpc (struct rpc_list **list, struct rpc_list *hdr)
{
@@ -171,7 +171,7 @@ link_rpc (struct rpc_list **list, struct rpc_list *hdr)
the filledin args. Set *PP to the address of the reply contents
themselves. The user will be expected to free *RPCBUF (which will
have changed) when done with the reply contents. The old value of
- *RPCBUF will be freed by this routine. */
+ *RPCBUF will be freed by this routine. */
error_t
conduct_rpc (void **rpcbuf, int **pp)
{
@@ -194,7 +194,7 @@ conduct_rpc (void **rpcbuf, int **pp)
do
{
- /* If we've sent enough, give up */
+ /* If we've sent enough, give up. */
if (mounted_soft && ntransmit == soft_retries)
{
unlink_rpc (hdr);
@@ -202,7 +202,7 @@ conduct_rpc (void **rpcbuf, int **pp)
return ETIMEDOUT;
}
- /* Issue the RPC */
+ /* Issue the RPC. */
lasttrans = mapped_time->seconds;
ntransmit++;
nc = (void *) *pp - *rpcbuf - sizeof (struct rpc_list);
@@ -216,7 +216,7 @@ conduct_rpc (void **rpcbuf, int **pp)
else
assert (cc == nc);
- /* Wait for reply */
+ /* Wait for reply. */
cancel = 0;
while (!hdr->reply
&& (mapped_time->seconds - lasttrans < timeout)
@@ -232,7 +232,7 @@ conduct_rpc (void **rpcbuf, int **pp)
/* hdr->reply will have been filled in by rpc_receive_thread,
if it has been filled in, then the rpc has been fulfilled,
- otherwise, retransmit and continue to wait */
+ otherwise, retransmit and continue to wait. */
if (!hdr->reply)
{
timeout *= 2;
@@ -244,34 +244,36 @@ conduct_rpc (void **rpcbuf, int **pp)
mutex_unlock (&outstanding_lock);
- /* Switch to the reply buffer. */
+ /* Switch to the reply buffer. */
*rpcbuf = hdr->reply;
free (hdr);
/* Process the reply, dissecting errors. When we're done and if
- there is no error, set *PP to the rpc return contents */
+ there is no error, set *PP to the rpc return contents. */
p = (int *) *rpcbuf;
/* If the transmition id does not match that in the message,
- something strange happened in rpc_receive_thread */
+ something strange happened in rpc_receive_thread. */
assert (*p == xid);
p++;
- switch (ntohl (*p++))
+ switch (ntohl (*p))
{
default:
err = EBADRPC;
break;
case REPLY:
- switch (ntohl (*p++))
+ p++;
+ switch (ntohl (*p))
{
default:
err = EBADRPC;
break;
case MSG_DENIED:
- switch (ntohl (*p++))
+ p++;
+ switch (ntohl (*p))
{
default:
err = EBADRPC;
@@ -282,7 +284,8 @@ conduct_rpc (void **rpcbuf, int **pp)
break;
case AUTH_ERROR:
- switch (ntohl (*p++))
+ p++;
+ switch (ntohl (*p))
{
case AUTH_BADCRED:
case AUTH_REJECTEDCRED:
@@ -304,13 +307,15 @@ conduct_rpc (void **rpcbuf, int **pp)
break;
case MSG_ACCEPTED:
+ p++;
- /* Process VERF field. */
- p++; /* skip verf type */
- n = ntohl (*p++); /* size of verf */
- p += INTSIZE (n); /* skip verf itself */
+ /* Process VERF field. */
+ p++; /* Skip verf type. */
+ n = ntohl (*p); /* Size of verf. */
+ p++;
+ p += INTSIZE (n); /* Skip verf itself. */
- switch (ntohl (*p++))
+ switch (ntohl (*p))
{
default:
case GARBAGE_ARGS:
@@ -330,6 +335,7 @@ conduct_rpc (void **rpcbuf, int **pp)
break;
case SUCCESS:
+ p++;
*pp = p;
err = 0;
break;
@@ -342,7 +348,7 @@ conduct_rpc (void **rpcbuf, int **pp)
}
/* Dedicated thread to signal those waiting on rpc_wakeup
- once a second. */
+ once a second. */
void
timeout_service_thread ()
{
@@ -356,13 +362,13 @@ timeout_service_thread ()
}
/* Dedicate thread to receive RPC replies, register them on the queue
- of pending wakeups, and deal appropriately. */
+ of pending wakeups, and deal appropriately. */
void
rpc_receive_thread ()
{
void *buf;
- /* Allocate a receive buffer */
+ /* Allocate a receive buffer. */
buf = malloc (1024 + read_size);
assert (buf);
@@ -381,7 +387,7 @@ rpc_receive_thread ()
mutex_lock (&outstanding_lock);
- /* Find the rpc that we just fulfilled */
+ /* Find the rpc that we just fulfilled. */
for (r = outstanding_rpcs; r; r = r->next)
{
if (* (int *) &r[1] == xid)
@@ -399,8 +405,8 @@ rpc_receive_thread ()
mutex_unlock (&outstanding_lock);
/* If r is not null then we had a message from a pending
- (i.e. known) rpc. Thus, it was fulfilled and if we
- want to get another request, a new buffer is needed */
+ (i.e. known) rpc. Thus, it was fulfilled and if we want
+ to get another request, a new buffer is needed. */
if (r)
{
buf = malloc (1024 + read_size);