Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/rpc.lockd Supports nlm version 4 (for use with nfsv3).



details:   https://anonhg.NetBSD.org/src/rev/fe443958c9a2
branches:  trunk
changeset: 481619:fe443958c9a2
user:      bouyer <bouyer%NetBSD.org@localhost>
date:      Wed Feb 02 18:17:42 2000 +0000

description:
Supports nlm version 4 (for use with nfsv3).

diffstat:

 usr.sbin/rpc.lockd/lock_proc.c |  473 ++++++++++++++++++++++++++++++++++++++++-
 usr.sbin/rpc.lockd/lockd.c     |   16 +-
 2 files changed, 485 insertions(+), 4 deletions(-)

diffs (truncated from 563 to 300 lines):

diff -r ee262d03eb7a -r fe443958c9a2 usr.sbin/rpc.lockd/lock_proc.c
--- a/usr.sbin/rpc.lockd/lock_proc.c    Wed Feb 02 18:15:12 2000 +0000
+++ b/usr.sbin/rpc.lockd/lock_proc.c    Wed Feb 02 18:17:42 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lock_proc.c,v 1.2 1997/10/18 04:01:15 lukem Exp $      */
+/*     $NetBSD: lock_proc.c,v 1.3 2000/02/02 18:17:42 bouyer Exp $     */
 
 /*
  * Copyright (c) 1995
@@ -35,7 +35,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: lock_proc.c,v 1.2 1997/10/18 04:01:15 lukem Exp $");
+__RCSID("$NetBSD: lock_proc.c,v 1.3 2000/02/02 18:17:42 bouyer Exp $");
 #endif
 
 #include <sys/param.h>
@@ -62,6 +62,7 @@
 static CLIENT  *get_client __P((struct sockaddr_in *));
 static void    log_from_addr __P((char *, struct svc_req *));
 static void    transmit_result __P((int, nlm_res *, struct svc_req *));
+static void    transmit4_result __P((int, nlm4_res *, struct svc_req *));
 
 /* log_from_addr ----------------------------------------------------------- */
 /*
@@ -234,6 +235,38 @@
                        syslog(LOG_DEBUG, "clnt_call returns %d\n", success);
        }
 }
+/* transmit4_result --------------------------------------------------------- */
+/*
+ * Purpose:    Transmit result for nlm4_xxx_msg pseudo-RPCs
+ * Returns:    Nothing - we have no idea if the datagram got there
+ * Notes:      clnt_call() will always fail (with timeout) as we are
+ *             calling it with timeout 0 as a hack to just issue a datagram
+ *             without expecting a result
+ */
+static void 
+transmit4_result(opcode, result, req)
+       int opcode;
+       nlm4_res *result;
+       struct svc_req *req;
+{
+       static char dummy;
+       struct sockaddr_in *addr;
+       CLIENT *cli;
+       struct timeval timeo;
+       int success;
+
+       addr = svc_getcaller(req->rq_xprt);
+       if ((cli = get_client(addr)) != NULL) {
+               timeo.tv_sec = 0; /* No timeout - not expecting response */
+               timeo.tv_usec = 0;
+
+               success = clnt_call(cli, opcode, xdr_nlm4_res, result, xdr_void,
+                   &dummy, timeo);
+
+               if (debug_level > 2)
+                       syslog(LOG_DEBUG, "clnt_call returns %d\n", success);
+       }
+}
 /* ------------------------------------------------------------------------- */
 /*
  * Functions for Unix<->Unix locking (ie. monitored locking, with rpc.statd
@@ -680,3 +713,439 @@
                log_from_addr("nlm_free_all", rqstp);
        return (&dummy);
 }
+
+/* calls for nlm version 4 (NFSv3) */
+/* nlm_test ---------------------------------------------------------------- */
+/*
+ * Purpose:    Test whether a specified lock would be granted if requested
+ * Returns:    nlm_granted (or error code)
+ * Notes:
+ */
+nlm4_testres *
+nlm4_test_4_svc(arg, rqstp)
+       nlm4_testargs *arg;
+       struct svc_req *rqstp;
+{
+       static nlm4_testres res;
+
+       if (debug_level)
+               log_from_addr("nlm4_test", rqstp);
+
+       /*
+        * Copy the cookie from the argument into the result.  Note that this
+        * is slightly hazardous, as the structure contains a pointer to a
+        * malloc()ed buffer that will get freed by the caller.  However, the
+        * main function transmits the result before freeing the argument
+        * so it is in fact safe.
+        */
+       res.cookie = arg->cookie;
+       res.stat.stat = nlm4_granted;
+       return (&res);
+}
+
+void *
+nlm4_test_msg_4_svc(arg, rqstp)
+       nlm4_testargs *arg;
+       struct svc_req *rqstp;
+{
+       nlm4_testres res;
+       static char dummy;
+       struct sockaddr_in *addr;
+       CLIENT *cli;
+       int success;
+       struct timeval timeo;
+
+       if (debug_level)
+               log_from_addr("nlm4_test_msg", rqstp);
+
+       res.cookie = arg->cookie;
+       res.stat.stat = nlm4_granted;
+
+       /*
+        * nlm_test has different result type to the other operations, so
+        * can't use transmit4_result() in this case
+        */
+       addr = svc_getcaller(rqstp->rq_xprt);
+       if ((cli = get_client(addr)) != NULL) {
+               timeo.tv_sec = 0; /* No timeout - not expecting response */
+               timeo.tv_usec = 0;
+
+               success = clnt_call(cli, NLM4_TEST_RES, xdr_nlm4_testres,
+                   &res, xdr_void, &dummy, timeo);
+
+               if (debug_level > 2)
+                       syslog(LOG_DEBUG, "clnt_call returns %d\n", success);
+       }
+       return (NULL);
+}
+
+/* nlm_lock ---------------------------------------------------------------- */
+/*
+ * Purposes:   Establish a lock
+ * Returns:    granted, denied or blocked
+ * Notes:      *** grace period support missing
+ */
+nlm4_res *
+nlm4_lock_4_svc(arg, rqstp)
+       nlm4_lockargs *arg;
+       struct svc_req *rqstp;
+{
+       static nlm4_res res;
+
+       if (debug_level)
+               log_from_addr("nlm4_lock", rqstp);
+
+       /* copy cookie from arg to result.  See comment in nlm_test_4() */
+       res.cookie = arg->cookie;
+
+       res.stat.stat = nlm4_granted;
+       return (&res);
+}
+
+void *
+nlm4_lock_msg_4_svc(arg, rqstp)
+       nlm4_lockargs *arg;
+       struct svc_req *rqstp;
+{
+       static nlm4_res res;
+
+       if (debug_level)
+               log_from_addr("nlm4_lock_msg", rqstp);
+
+       res.cookie = arg->cookie;
+       res.stat.stat = nlm4_granted;
+       transmit4_result(NLM4_LOCK_RES, &res, rqstp);
+
+       return (NULL);
+}
+
+/* nlm_cancel -------------------------------------------------------------- */
+/*
+ * Purpose:    Cancel a blocked lock request
+ * Returns:    granted or denied
+ * Notes:
+ */
+nlm4_res *
+nlm4_cancel_4_svc(arg, rqstp)
+       nlm4_cancargs *arg;
+       struct svc_req *rqstp;
+{
+       static nlm4_res res;
+
+       if (debug_level)
+               log_from_addr("nlm4_cancel", rqstp);
+
+       /* copy cookie from arg to result.  See comment in nlm_test_1() */
+       res.cookie = arg->cookie;
+
+       /*
+        * Since at present we never return 'nlm_blocked', there can never be
+        * a lock to cancel, so this call always fails.
+        */
+       res.stat.stat = nlm4_denied;
+       return (&res);
+}
+
+void *
+nlm4_cancel_msg_4_svc(arg, rqstp)
+       nlm4_cancargs *arg;
+       struct svc_req *rqstp;
+{
+       static nlm4_res res;
+
+       if (debug_level)
+               log_from_addr("nlm4_cancel_msg", rqstp);
+
+       res.cookie = arg->cookie;
+       /*
+        * Since at present we never return 'nlm_blocked', there can never be
+        * a lock to cancel, so this call always fails.
+        */
+       res.stat.stat = nlm4_denied;
+       transmit4_result(NLM4_CANCEL_RES, &res, rqstp);
+       return (NULL);
+}
+
+/* nlm_unlock -------------------------------------------------------------- */
+/*
+ * Purpose:    Release an existing lock
+ * Returns:    Always granted, unless during grace period
+ * Notes:      "no such lock" error condition is ignored, as the
+ *             protocol uses unreliable UDP datagrams, and may well
+ *             re-try an unlock that has already succeeded.
+ */
+nlm4_res *
+nlm4_unlock_4_svc(arg, rqstp)
+       nlm4_unlockargs *arg;
+       struct svc_req *rqstp;
+{
+       static nlm4_res res;
+
+       if (debug_level)
+               log_from_addr("nlm4_unlock", rqstp);
+
+       res.stat.stat = nlm4_granted;
+       res.cookie = arg->cookie;
+
+       return (&res);
+}
+
+void *
+nlm4_unlock_msg_4_svc(arg, rqstp)
+       nlm4_unlockargs *arg;
+       struct svc_req *rqstp;
+{
+       static nlm4_res res;
+
+       if (debug_level)
+               log_from_addr("nlm4_unlock_msg", rqstp);
+
+       res.stat.stat = nlm4_granted;
+       res.cookie = arg->cookie;
+
+       transmit4_result(NLM4_UNLOCK_RES, &res, rqstp);
+       return (NULL);
+}
+
+/* ------------------------------------------------------------------------- */
+/*
+ * Client-side pseudo-RPCs for results.  Note that for the client there
+ * are only nlm_xxx_msg() versions of each call, since the 'real RPC'
+ * version returns the results in the RPC result, and so the client
+ * does not normally receive incoming RPCs.
+ *
+ * The exception to this is nlm_granted(), which is genuinely an RPC
+ * call from the server to the client - a 'call-back' in normal procedure
+ * call terms.
+ */
+
+/* nlm_granted ------------------------------------------------------------- */
+/*
+ * Purpose:    Receive notification that formerly blocked lock now granted
+ * Returns:    always success ('granted')
+ * Notes:
+ */
+nlm4_res *
+nlm4_granted_4_svc(arg, rqstp)
+       nlm4_testargs *arg;
+       struct svc_req *rqstp;
+{
+       static nlm4_res res;
+
+       if (debug_level)
+               log_from_addr("nlm4_granted", rqstp);
+
+       /* copy cookie from arg to result.  See comment in nlm_test_1() */
+       res.cookie = arg->cookie;
+
+       res.stat.stat = nlm4_granted;
+       return (&res);
+}
+
+void *
+nlm4_granted_msg_4_svc(arg, rqstp)



Home | Main Index | Thread Index | Old Index