NLM: initial support for NLM
authorRonnie Sahlberg <ronniesahlberg@gmail.com>
Sat, 10 Mar 2012 09:46:03 +0000 (20:46 +1100)
committerRonnie Sahlberg <ronniesahlberg@gmail.com>
Sat, 10 Mar 2012 09:46:03 +0000 (20:46 +1100)
Makefile.am
configure.ac
include/libnfs-raw.h
lib/Makefile.am
nlm/Makefile.am [new file with mode: 0644]
nlm/nlm.c [new file with mode: 0644]
nlm/nlm.x [new file with mode: 0644]

index 03e441928c36e1a505d89ed3e08f745028c53d30..18277c0de522792a6e219b78355ce6e840fdbee9 100644 (file)
@@ -1,4 +1,4 @@
-SUBDIRS = mount nfs portmap rquota lib include . $(MAYBE_EXAMPLES)
+SUBDIRS = mount nfs nlm portmap rquota lib include . $(MAYBE_EXAMPLES)
 
 pkgconfigdir = $(libdir)/pkgconfig
 pkgconfig_DATA = libnfs.pc
index 9201a4228a8261e52a6dfa985b0e821b33677bff..48595bd32748a2f8d0860dc9ce0a0578450404bb 100644 (file)
@@ -93,6 +93,7 @@ AC_CONFIG_FILES([Makefile]
                 [lib/Makefile]
                 [mount/Makefile]
                 [nfs/Makefile]
+                [nlm/Makefile]
                 [portmap/Makefile]
                 [rquota/Makefile]
                 [examples/Makefile]
index 423d1d715dc08c96bdc5e3163f63ea38ec11ae32..5c901d18395128da521f65c34aaaf0c22f296659 100644 (file)
@@ -752,6 +752,13 @@ int rpc_rquota2_getactivequota_async(struct rpc_context *rpc, rpc_cb cb, char *e
 
 
 
+
+
+
+/*
+ * NFSACL functions 
+ */
+
 /*
  * Call NFSACL/NULL
  * Call the NULL procedure for the NFSACL
@@ -807,3 +814,29 @@ int rpc_nfsacl_getacl_async(struct rpc_context *rpc, rpc_cb cb, struct GETACL3ar
  */
 struct SETACL3args;
 int rpc_nfsacl_setacl_async(struct rpc_context *rpc, rpc_cb cb, struct SETACL3args *args, void *private_data);
+
+
+
+
+/*
+ * NLM functions
+ */
+char *nlmstat4_to_str(int stat);
+       
+/*
+ * Call NLM/NULL
+ * Call the NULL procedure for the NLM protocol
+ *
+ * Function returns
+ *  0 : The call was initiated. The callback will be invoked when the call completes.
+ * <0 : An error occured when trying to set up the call. The callback will not be invoked.
+ *
+ * When the callback is invoked, status indicates the result:
+ * RPC_STATUS_SUCCESS : We got a successful response from the nlm daemon.
+ *                      data is NULL
+ * RPC_STATUS_ERROR   : An error occured when trying to contact the nlm daemon.
+ *                      data is the error string.
+ * RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
+ *                     data is NULL.
+ */
+int rpc_nlm_null_async(struct rpc_context *rpc, rpc_cb cb, void *private_data);
index 7cb81e8ea90aefa4ddcd61bbe1ff6297f7efcc3f..1f398e2169422bf5ca33b871a5747d727f3a1247 100644 (file)
@@ -3,6 +3,7 @@ lib_LTLIBRARIES = libnfs.la
 libnfs_la_CPPFLAGS = -I$(abs_top_srcdir)/include \
                     -I../mount \
                     -I../nfs \
+                    -I../nlm \
                     -I../portmap \
                     -I../rquota \
                     "-D_U_=__attribute__((unused))"
@@ -18,6 +19,7 @@ libnfs_la_LDFLAGS = -version-info 1:3:0
 libnfs_la_LIBADD = \
        ../mount/libmount.la \
        ../nfs/libnfs.la \
+       ../nlm/libnlm.la \
        ../portmap/libportmap.la \
        ../rquota/librquota.la 
 
diff --git a/nlm/Makefile.am b/nlm/Makefile.am
new file mode 100644 (file)
index 0000000..7ec82da
--- /dev/null
@@ -0,0 +1,20 @@
+noinst_LTLIBRARIES = libnlm.la
+
+nlm_SOURCES_GENERATED = libnfs-raw-nlm.c
+nlm_HEADERS_GENERATED = libnfs-raw-nlm.h
+nlm_GENERATED = $(nlm_SOURCES_GENERATED) $(nlm_HEADERS_GENERATED)
+
+CLEANFILES = $(nlm_GENERATED) nlm-stamp
+
+libnlm_la_CPPFLAGS = -I$(abs_top_srcdir)/include
+libnlm_la_SOURCES = \
+       $(nlm_SOURCES_GENERATED) \
+       nlm.c
+
+$(nlm_GENERATED) : nlm-stamp
+nlm-stamp : nlm.x
+       rm -f $(nlm_GENERATED)
+       rpcgen -h @RPCGENFLAGS@ $< > libnfs-raw-nlm.h
+       rpcgen -c @RPCGENFLAGS@ $< | sed -e "s/#include \".*nlm.h\"/#include \"libnfs-raw-nlm.h\"/" > libnfs-raw-nlm.c
+       touch nlm-stamp
+       
diff --git a/nlm/nlm.c b/nlm/nlm.c
new file mode 100644 (file)
index 0000000..73d5c2d
--- /dev/null
+++ b/nlm/nlm.c
@@ -0,0 +1,72 @@
+/*
+   Copyright (C) 2012 by Ronnie Sahlberg <ronniesahlberg@gmail.com>
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU Lesser General Public License as published by
+   the Free Software Foundation; either version 2.1 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public License
+   along with this program; if not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifdef WIN32
+#include "win32_compat.h"
+#endif/*WIN32*/
+
+#include <stdio.h>
+#include <errno.h>
+#include <rpc/rpc.h>
+#include <rpc/xdr.h>
+#include "libnfs.h"
+#include "libnfs-raw.h"
+#include "libnfs-private.h"
+#include "libnfs-raw-nlm.h"
+
+int rpc_nlm_null_async(struct rpc_context *rpc, rpc_cb cb, void *private_data)
+{
+       struct rpc_pdu *pdu;
+
+       pdu = rpc_allocate_pdu(rpc, NLM_PROGRAM, NLM_V4, NLM4_NULL, cb, private_data, (xdrproc_t)xdr_void, 0);
+       if (pdu == NULL) {
+               rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for nlm/null call");
+               return -1;
+       }
+
+       if (rpc_queue_pdu(rpc, pdu) != 0) {
+               rpc_set_error(rpc, "Out of memory. Failed to queue pdu for nlm/null call");
+               rpc_free_pdu(rpc, pdu);
+               return -1;
+       }
+
+       return 0;
+}
+
+char *nlmstat4_to_str(int st)
+{
+       enum nlmstat4 stat = st;
+
+       char *str = "unknown nlm stat";
+       switch (stat) {
+       case NLM4_GRANTED: str="NLM4_GRANTED";break;
+       case NLM4_DENIED: str="NLM4_DENIED";break;
+       case NLM4_DENIED_NOLOCKS: str="NLM4_DENIED_NOLOCKS";break;
+       case NLM4_BLOCKED: str="NLM4_BLOCKED";break;
+       case NLM4_DENIED_GRACE_PERIOD: str="NLM4_DENIED_GRACE_PERIOD";break;
+       case NLM4_DEADLCK: str="NLM4_DEADLCK";break;
+       case NLM4_ROFS: str="NLM4_ROFS";break;
+       case NLM4_STALE_FH: str="NLM4_STALE_FH";break;
+       case NLM4_FBIG: str="NLM4_FBIG";break;
+       case NLM4_FAILED: str="NLM4_FAILED";break;
+       }
+       return str;
+}
+
+
+
+
diff --git a/nlm/nlm.x b/nlm/nlm.x
new file mode 100644 (file)
index 0000000..ee86df5
--- /dev/null
+++ b/nlm/nlm.x
@@ -0,0 +1,126 @@
+/* based on rfc1813 and wireshark */
+
+const COOKIESIZE = 4;
+typedef opaque nlm_cookie[COOKIESIZE];
+       
+enum nlmstat4 {
+       NLM4_GRANTED = 0,
+       NLM4_DENIED = 1,
+       NLM4_DENIED_NOLOCKS = 2,
+       NLM4_BLOCKED = 3,
+       NLM4_DENIED_GRACE_PERIOD = 4,
+       NLM4_DEADLCK = 5,
+       NLM4_ROFS = 6,
+       NLM4_STALE_FH = 7,
+       NLM4_FBIG = 8,
+       NLM4_FAILED = 9
+};
+
+struct nlm4_holder {
+       bool         exclusive;
+       unsigned int svid;
+       netobj       oh;
+       unsigned hyper l_offset;
+       unsigned hyper l_len;
+};
+
+const NLM_MAXNAME = 256;
+struct nlm4_lock {
+       string       caller_name<NLM_MAXNAME>;
+       netobj       fh;
+       netobj       oh;
+       unsigned int svid;
+       unsigned hyper l_offset;
+       unsigned hyper l_len;
+};
+
+struct nlm4_share {
+       string       caller_name<NLM_MAXNAME>;
+       netobj       fh;
+       netobj       oh;
+       unsigned int mode;
+       unsigned int access;
+};
+
+
+struct nlm4_testres_ok {
+       nlm_cookie  cookie;
+       nlm4_holder holder;
+};
+
+union nlm4_testres switch (nlmstat4 nlm_status) {
+       case NLM4_GRANTED:
+               nlm4_testres_ok  lock;
+       default:
+               void;
+};
+
+struct nlm4_testargs {
+       nlm_cookie cookie;
+       bool       exclusive;
+       nlm4_lock  lock;
+};
+
+program NLM_PROGRAM {
+       version NLM_V4 {
+               void
+               NLM4_NULL(void)                  = 0;
+
+               nlm4_testres
+               NLM4_TEST(nlm4_testargs)         = 1;
+
+/*             nlm4_res                         */
+/*             NLM4_LOCK(nlm4_lockargs)         = 2;   */
+
+/*             nlm4_res                         */
+/*             NLM4_CANCEL(nlm4_cancargs)       = 3;   */
+
+/*             nlm4_res                         */
+/*             NLM4_UNLOCK(nlm4_unlockargs)     = 4;   */
+
+/*             nlm4_res                         */
+/*             NLM4_GRANTED(nlm4_testargs)      = 5;   */
+
+/*             void                             */
+/*             NLM4_TEST_MSG(nlm4_testargs)     = 6;   */
+
+/*             void                             */
+/*             NLM4_LOCK_MSG(nlm4_lockargs)     = 7;   */
+
+/*             void                             */
+/*             NLM4_CANCEL_MSG(nlm4_cancargs)   = 8;   */
+
+/*             void                             */
+/*             NLM4_UNLOCK_MSG(nlm4_unlockargs) = 9;   */
+
+/*             void                             */
+/*             NLM4_GRANTED_MSG(nlm4_testargs) = 10;   */
+
+/*             void                            */
+/*             NLM4_TEST_RES(nlm4_testres)     = 11;   */
+
+/*             void                            */
+/*             NLM4_LOCK_RES(nlm4_res)         = 12;   */
+
+/*             void                            */
+/*             NLM4_CANCEL_RES(nlm4_res)       = 13;   */
+
+/*             void                            */
+/*             NLM4_UNLOCK_RES(nlm4_res)       = 14;   */
+
+/*             void                            */
+/*             NLM4_GRANTED_RES(nlm4_res)      = 15;   */
+
+/*             nlm4_shareres                   */
+/*             NLM4_SHARE(nlm4_shareargs)      = 20;   */
+
+/*             nlm4_shareres                   */
+/*             NLM4_UNSHARE(nlm4_shareargs)    = 21;   */
+
+/*             nlm4_res                        */
+/*             NLM4_NM_LOCK(nlm4_lockargs)     = 22;   */
+
+/*             void                            */
+/*             NLM4_FREE_ALL(nlm4_notify)      = 23;   */
+       } = 4;
+} = 100021;