artemb

rpc-xid-fix.diff

Jun 16th, 2011
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 5.73 KB | None | 0 0
  1. diff --git a/sys/rpc/clnt_dg.c b/sys/rpc/clnt_dg.c
  2. index a412c08..6736949 100644
  3. --- a/sys/rpc/clnt_dg.c
  4. +++ b/sys/rpc/clnt_dg.c
  5. @@ -189,7 +189,6 @@ clnt_dg_create(
  6.     struct cu_data *cu = NULL;  /* private data */
  7.     struct cu_socket *cs = NULL;
  8.     struct sockbuf *sb;
  9. -   struct timeval now;
  10.     struct rpc_msg call_msg;
  11.     struct __rpc_sockinfo si;
  12.     XDR xdrs;
  13. @@ -245,8 +244,7 @@ clnt_dg_create(
  14.     cu->cu_cwnd = MAXCWND / 2;
  15.     cu->cu_sent = 0;
  16.     cu->cu_cwnd_wait = FALSE;
  17. -   (void) getmicrotime(&now);
  18. -   cu->cu_xid = __RPC_GETXID(&now);
  19. +   cu->cu_xid = rpc_get_xid();
  20.     call_msg.rm_xid = cu->cu_xid;
  21.     call_msg.rm_call.cb_prog = program;
  22.     call_msg.rm_call.cb_vers = version;
  23. @@ -425,7 +423,7 @@ clnt_dg_call(
  24.  call_again:
  25.     mtx_assert(&cs->cs_lock, MA_OWNED);
  26.  
  27. -   cu->cu_xid++;
  28. +   cu->cu_xid = rpc_get_xid();
  29.     xid = cu->cu_xid;
  30.  
  31.  send_again:
  32. @@ -872,8 +870,7 @@ clnt_dg_control(CLIENT *cl, u_int request, void *info)
  33.  
  34.     case CLSET_XID:
  35.         /* This will set the xid of the NEXT call */
  36. -       /* decrement by 1 as clnt_dg_call() increments once */
  37. -       cu->cu_xid = *(uint32_t *)info - 1;
  38. +       cu->cu_xid = *(uint32_t *)info;
  39.         break;
  40.  
  41.     case CLGET_VERS:
  42. diff --git a/sys/rpc/clnt_rc.c b/sys/rpc/clnt_rc.c
  43. index e263278..44af710 100644
  44. --- a/sys/rpc/clnt_rc.c
  45. +++ b/sys/rpc/clnt_rc.c
  46. @@ -133,6 +133,7 @@ clnt_reconnect_create(
  47.     cl->cl_auth = authnone_create();
  48.     cl->cl_tp = NULL;
  49.     cl->cl_netid = NULL;
  50. +   printf("clnt_rc_create %p\n", cl);
  51.     return (cl);
  52.  }
  53.  
  54. @@ -149,6 +150,7 @@ clnt_reconnect_connect(CLIENT *cl)
  55.     CLIENT *newclient = NULL;
  56.  
  57.     mtx_lock(&rc->rc_lock);
  58. +   printf("clnt_rc_connect %p\n", cl);
  59.     while (rc->rc_connecting) {
  60.         error = msleep(rc, &rc->rc_lock,
  61.             rc->rc_intr ? PCATCH : 0, "rpcrecon", 0);
  62. @@ -166,6 +168,7 @@ clnt_reconnect_connect(CLIENT *cl)
  63.         return (RPC_SUCCESS);
  64.     }
  65.  
  66. +   printf("clnt_rc_call %p - connecting\n", cl);
  67.     /*
  68.      * My turn to attempt a connect. The rc_connecting variable
  69.      * serializes the following code sequence, so it is guaranteed
  70. @@ -197,6 +200,7 @@ clnt_reconnect_connect(CLIENT *cl)
  71.             (struct sockaddr *) &rc->rc_addr, rc->rc_prog, rc->rc_vers,
  72.             rc->rc_sendsz, rc->rc_recvsz, rc->rc_intr);
  73.     td->td_ucred = oldcred;
  74. +   printf("clnt_rc_connect %p dg/vc_clnt=%p\n", cl, newclient);
  75.  
  76.     if (!newclient) {
  77.         soclose(so);
  78. @@ -252,6 +256,7 @@ clnt_reconnect_call(
  79.     enum clnt_stat stat;
  80.     int tries, error;
  81.  
  82. +   printf("clnt_rc_call %p\n", cl);
  83.     tries = 0;
  84.     do {
  85.         mtx_lock(&rc->rc_lock);
  86. @@ -295,6 +300,8 @@ clnt_reconnect_call(
  87.                 CLNT_GETERR(client, &rc->rc_err);
  88.         }
  89.  
  90. +       printf("clnt_rc_connect %p stat=%d\n", cl, stat);
  91. +
  92.         if (stat == RPC_TIMEDOUT) {
  93.             /*
  94.              * Check for async send misfeature for NLM
  95. @@ -503,6 +510,8 @@ clnt_reconnect_destroy(CLIENT *cl)
  96.  {
  97.     struct rc_data *rc = (struct rc_data *)cl->cl_private;
  98.  
  99. +   printf("clnt_rc_destroy %p\n", cl);
  100. +
  101.     if (rc->rc_client)
  102.         CLNT_DESTROY(rc->rc_client);
  103.     crfree(rc->rc_ucred);
  104. diff --git a/sys/rpc/clnt_vc.c b/sys/rpc/clnt_vc.c
  105. index ea3b7d1..588ab31 100644
  106. --- a/sys/rpc/clnt_vc.c
  107. +++ b/sys/rpc/clnt_vc.c
  108. @@ -175,15 +175,11 @@ clnt_vc_create(
  109.     struct ct_data *ct = NULL;  /* client handle */
  110.     struct timeval now;
  111.     struct rpc_msg call_msg;
  112. -   static uint32_t disrupt;
  113.     struct __rpc_sockinfo si;
  114.     XDR xdrs;
  115.     int error, interrupted, one = 1, sleep_flag;
  116.     struct sockopt sopt;
  117.  
  118. -   if (disrupt == 0)
  119. -       disrupt = (uint32_t)(long)raddr;
  120. -
  121.     cl = (CLIENT *)mem_alloc(sizeof (*cl));
  122.     ct = (struct ct_data *)mem_alloc(sizeof (*ct));
  123.  
  124. @@ -261,8 +257,7 @@ clnt_vc_create(
  125.     /*
  126.      * Initialize call message
  127.      */
  128. -   getmicrotime(&now);
  129. -   ct->ct_xid = ((uint32_t)++disrupt) ^ __RPC_GETXID(&now);
  130. +   ct->ct_xid = rpc_get_xid();
  131.     call_msg.rm_xid = ct->ct_xid;
  132.     call_msg.rm_direction = CALL;
  133.     call_msg.rm_call.cb_rpcvers = RPC_MSG_VERSION;
  134. @@ -378,7 +373,7 @@ clnt_vc_call(
  135.  call_again:
  136.     mtx_assert(&ct->ct_lock, MA_OWNED);
  137.  
  138. -   ct->ct_xid++;
  139. +   ct->ct_xid = rpc_get_xid();
  140.     xid = ct->ct_xid;
  141.  
  142.     mtx_unlock(&ct->ct_lock);
  143. @@ -691,8 +686,7 @@ clnt_vc_control(CLIENT *cl, u_int request, void *info)
  144.         break;
  145.     case CLSET_XID:
  146.         /* This will set the xid of the NEXT call */
  147. -       /* decrement by 1 as clnt_vc_call() increments once */
  148. -       ct->ct_xid = *(uint32_t *)info - 1;
  149. +       ct->ct_xid = *(uint32_t *)info;
  150.         break;
  151.     case CLGET_VERS:
  152.         /*
  153. diff --git a/sys/rpc/rpc_com.h b/sys/rpc/rpc_com.h
  154. index 290a289..4a3590a 100644
  155. --- a/sys/rpc/rpc_com.h
  156. +++ b/sys/rpc/rpc_com.h
  157. @@ -58,8 +58,7 @@
  158.  
  159.  #ifdef _KERNEL
  160.  
  161. -#define __RPC_GETXID(now) ((uint32_t)curproc->p_pid ^ (uint32_t)(now)->tv_sec ^ \
  162. -    (uint32_t)(now)->tv_usec)
  163. +uint32_t rpc_get_xid(void);
  164.  
  165.  #else
  166.  
  167. diff --git a/sys/rpc/rpc_prot.c b/sys/rpc/rpc_prot.c
  168. index 294c4e3..1179057 100644
  169. --- a/sys/rpc/rpc_prot.c
  170. +++ b/sys/rpc/rpc_prot.c
  171. @@ -53,12 +53,14 @@ __FBSDID("$FreeBSD$");
  172.  #include <sys/systm.h>
  173.  #include <sys/kernel.h>
  174.  #include <sys/malloc.h>
  175. +#include <machine/atomic.h>
  176.  
  177.  #include <rpc/types.h>
  178.  #include <rpc/xdr.h>
  179.  #include <rpc/auth.h>
  180.  #include <rpc/clnt.h>
  181.  #include <rpc/rpc_msg.h>
  182. +#include <rpc/rpc_com.h>
  183.  
  184.  MALLOC_DEFINE(M_RPC, "rpc", "Remote Procedure Call");
  185.  
  186. @@ -371,3 +373,27 @@ _seterr_reply(struct rpc_msg *msg, struct rpc_err *error)
  187.  
  188.     return (stat);
  189.  }
  190. +
  191. +uint32_t
  192. +rpc_get_xid(void)
  193. +{
  194. +   static volatile uint32_t clnt_xid;
  195. +   static uint32_t clnt_xit_initialized;
  196. +
  197. +   struct timeval now;
  198. +   uint32_t xid;
  199. +
  200. +   if (!clnt_xit_initialized) {
  201. +       getmicrotime(&now);
  202. +       xid = (uint32_t) (now.tv_sec << 20 | now.tv_usec);
  203. +       atomic_store_rel_32(&clnt_xid, xid);
  204. +       clnt_xit_initialized = 1;
  205. +   }
  206. +
  207. +   xid = atomic_fetchadd_32(&clnt_xid,1);
  208. +   /* Don't return zero XID. */
  209. +   if (!xid)
  210. +       xid = atomic_fetchadd_32(&clnt_xid,1);
  211. +
  212. +   return xid;
  213. +}
Advertisement
Add Comment
Please, Sign In to add comment