]> arthur.barton.de Git - netatalk.git/commitdiff
Add locking RPC to afpd
authorFrank Lahm <franklahm@googlemail.com>
Tue, 25 Jan 2011 10:27:51 +0000 (11:27 +0100)
committerFrank Lahm <franklahm@googlemail.com>
Tue, 25 Jan 2011 10:27:51 +0000 (11:27 +0100)
etc/afpd/Makefile.am
etc/afpd/main.c
etc/netalockd/main.c
include/atalk/Makefile.am
include/atalk/adouble.h
include/atalk/locking.h [new file with mode: 0644]
libatalk/Makefile.am
libatalk/rpc/locking.c

index 7e93dec2b5b42ab59c6de70dcc5bb2a03914ddb1..03b8e34f5dc98af0559560d5b76a98efbd90dd0d 100644 (file)
@@ -44,9 +44,10 @@ afpd_SOURCES = \
 afpd_LDADD =  \
        $(top_builddir)/libatalk/cnid/libcnid.la \
        $(top_builddir)/libatalk/libatalk.la \
+       $(top_builddir)/libevent/libevent.la \
        @QUOTA_LIBS@ @SLP_LIBS@ @WRAP_LIBS@ @LIBADD_DL@ @ACL_LIBS@ @ZEROCONF_LIBS@ @PTHREAD_LIBS@
 
-afpd_LDFLAGS = -export-dynamic 
+afpd_LDFLAGS = -export-dynamic -static
 
 afpd_CFLAGS = \
        -I$(top_srcdir)/include \
index 30a32346238aefc4425c0ba14062ef18dd21aa26..8c30392b6ea284118969f5f49462f7285b826b4d 100644 (file)
 #include <stdlib.h>
 #include <string.h>
 #include <signal.h>
-
 #include <sys/param.h>
 #include <sys/uio.h>
-#include <atalk/logger.h>
 #include <sys/time.h>
 #include <sys/socket.h>
-
 #include <errno.h>
 
+#include <atalk/logger.h>
 #include <atalk/adouble.h>
-
 #include <netatalk/at.h>
 #include <atalk/compat.h>
 #include <atalk/dsi.h>
 #include <atalk/util.h>
 #include <atalk/server_child.h>
 #include <atalk/server_ipc.h>
+#include <atalk/errchk.h>
+#include <atalk/locking.h>
+
+#include "event2/event.h"
+#include "event2/http.h"
+#include "event2/rpc.h"
 
 #include "globals.h"
 #include "afp_config.h"
@@ -52,6 +55,7 @@ static char **argv = NULL;
 unsigned char  nologin = 0;
 
 struct afp_options default_options;
+
 static AFPConfig *configs;
 static server_child *server_children;
 static fd_set save_rfds;
@@ -267,9 +271,11 @@ int main(int ac, char **av)
     }
     pthread_sigmask(SIG_UNBLOCK, &sigs, NULL);
 
-    /* Register CNID  */
+    /* Initialize */
     cnid_init();
-
+    if (rpc_init("127.0.0.1", 4701) != 0)
+        afp_exit(EXITERR_SYS);
+    
     /* watch atp, dsi sockets and ipc parent/child file descriptor. */
     if ((ipc = server_ipc_create())) {
         Ipc_fd = server_ipc_parent(ipc);
index 77a195a5f74d01d25e8fbd65d88ea981e9f108e9..533e14b3c35dc3a6258805e08cd6eafed3571b55 100644 (file)
@@ -19,6 +19,7 @@
 #include <atalk/logger.h>
 #include <atalk/paths.h>
 #include <atalk/util.h>
+#include <atalk/compat.h>
 
 #include "event2/event.h"
 #include "event2/http.h"
@@ -112,10 +113,16 @@ static void lock_msg_cb(EVRPC_STRUCT(lock_msg)* rpc, void *arg _U_)
        EVRPC_REQUEST_DONE(rpc);
 }
 
+static void ev_log_cb(int severity, const char *msg)
+{
+    LOG(log_warning, logtype_default, (char *)msg);
+}
+
 static int rpc_setup(const char *addr, uint16_t port)
 {
     eventbase = event_base_new();
-    
+    event_set_log_callback(ev_log_cb);
+
        if ((http = evhttp_new(eventbase)) == NULL) {
         LOG(log_error, logtype_default, "rpc_setup: error in evhttp_new: %s", strerror(errno));
         return -1;
@@ -139,13 +146,12 @@ static void rpc_teardown(struct evrpc_base *rpcbase)
        evrpc_free(rpcbase);
 }
 
-int main(int ac, char **av)
+int main(int argc, char **argv)
 {
     int ret;
 
     /* Default log setup: log to syslog */
     set_processname("netalockd");
-    setuplog("default log_note");
 
     /* Check lockfile and daemonize */
     switch(server_lock("netalockd", _PATH_NETALOCKD_LOCK, 0)) {
@@ -157,6 +163,32 @@ int main(int ac, char **av)
         exit(0);
     }
 
+    char c;
+    static char logconfig[MAXPATHLEN + 21 + 1] = "default log_note";
+    char *loglevel, *logfile;
+    while ((c = getopt(argc, argv, "l:f:")) != -1 ) {
+        switch (c) {
+        case 'l':
+            loglevel = strdup(optarg);
+            break;
+        case 'f':
+            logfile = strdup(optarg);
+            break;
+        }
+    }
+
+    /* Setup logging */
+    if (loglevel) {
+        strlcpy(logconfig + 8, loglevel, 13);
+        free(loglevel);
+        strcat(logconfig, " ");
+    }
+    if (logfile) {
+        strlcat(logconfig, logfile, MAXPATHLEN);
+        free(logfile);
+    }
+    setuplog(logconfig);
+
     /* Setup signal stuff */
     set_signal();
 
index 57bf12137d5f76c26990b88016b577f3bc77a63a..0e0039135e5cf2f07f902c90789d14ccbdb9edab 100644 (file)
@@ -7,6 +7,7 @@ atalkinclude_HEADERS = \
        afp.h \
        vfs.h \
        cnid.h \
+       locking.h \
        logger.h \
        paths.h \
        unicode.h \
index 7c6f485d952e7697606aff1f791d2383f4f8107a..60032780c321caa9aebba006352ff11037163818 100644 (file)
@@ -366,9 +366,16 @@ extern int ad_testlock      (struct adouble * /*adp*/, int /*eid*/, off_t /*off*
 extern u_int16_t ad_openforks (struct adouble * /*adp*/, u_int16_t);
 extern int ad_excl_lock     (struct adouble * /*adp*/, const u_int32_t /*eid*/);
 
+#if 0
 #define ad_lock ad_fcntl_lock
 #define ad_tmplock ad_fcntl_tmplock
 #define ad_unlock ad_fcntl_unlock
+#endif
+
+#define ad_lock rpc_lock
+#define ad_tmplock rpc_tmplock
+#define ad_unlock rpc_unlock
+
 
 /* ad_open.c */
 extern const char *oflags2logstr(int oflags);
diff --git a/include/atalk/locking.h b/include/atalk/locking.h
new file mode 100644 (file)
index 0000000..5f88d88
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2010 Frank Lahm
+ * All Rights Reserved.  See COPYRIGHT.
+ */
+
+#ifndef ATALK_LOCKING_H
+#define ATALK_LOCKING_H
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <sys/types.h>
+#include <inttypes.h>
+
+#include <atalk/adouble.h>
+#include <atalk/lockrpc.gen.h>
+
+#include "event2/event.h"
+#include "event2/http.h"
+#include "event2/rpc.h"
+
+extern int rpc_init(const char *addr, unsigned short port);
+extern int rpc_lock(struct adouble *, uint32_t eid, int type, off_t off, off_t len, int user);
+extern void rpc_unlock(struct adouble *, int user);
+extern int rpc_tmplock(struct adouble *, uint32_t eid, int type, off_t off, off_t len, int user);
+
+
+#endif  /* ATALK_LOCKING_H */
index 52a5516983acedb5c3b2ad701fa7040318631b00..5cf561d9dfc9339e3f79eb3487bc752f63411cb9 100644 (file)
@@ -20,7 +20,8 @@ libatalk_la_LIBADD  = \
        tsocket/libtsocket.la \
        unicode/libunicode.la \
        util/libutil.la         \
-       vfs/libvfs.la
+       vfs/libvfs.la           \
+       $(top_builddir)/libevent/libevent.la
 
 libatalk_la_DEPENDENCIES = \
        acl/libacl.la \
@@ -35,7 +36,8 @@ libatalk_la_DEPENDENCIES = \
        tsocket/libtsocket.la \
        unicode/libunicode.la \
        util/libutil.la         \
-       vfs/libvfs.la
+       vfs/libvfs.la           \
+       $(top_builddir)/libevent/libevent.la
 
 libatalk_la_LDFLAGS = -static
 
index 6c36597f2328aa199bfc60b84de6b4e44477a668..0aedaf532093bc38c80ebb83cb44361496cb8195 100644 (file)
@@ -1,3 +1,103 @@
-static void dummy(void)
+/*
+ * Copyright (c) 2010 Frank Lahm
+ * All Rights Reserved.  See COPYRIGHT.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif /* HAVE_CONFIG_H */
+
+#include <sys/queue.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+
+#include "event2/event-config.h"
+
+#include "event2/event.h"
+#include "event2/http.h"
+#include "event2/rpc.h"
+#include "event2/rpc_struct.h"
+
+#include <atalk/logger.h>
+#include <atalk/errchk.h>
+#include <atalk/locking.h>
+#include <atalk/adouble.h>
+#include <atalk/bstrlib.h>
+#include <atalk/bstradd.h>
+
+EVRPC_HEADER(lock_msg, lock_req, lock_rep)
+EVRPC_GENERATE(lock_msg, lock_req, lock_rep)
+
+static struct evrpc_pool *rpc_pool;
+static struct event_base *ev_base;
+
+static void ev_log_cb(int severity, const char *msg)
 {
+    LOG(log_warning, logtype_default, (char *)msg);
+}
+
+static void msg_rep_cb(struct evrpc_status *status,
+                       struct lock_req *req,
+                       struct lock_rep *rep,
+                       void *arg)
+{
+       if (status->error != EVRPC_STATUS_ERR_NONE)
+               goto done;
+
+done:
+    event_base_loopexit(ev_base, NULL);
+}
+
+static void rpc_dummy(const char *name)
+{
+       struct lock_req *lock_req = NULL;
+       struct lock_rep *lock_rep = NULL;
+
+    lock_req = lock_req_new();
+    lock_rep = lock_rep_new();
+
+    EVTAG_ASSIGN(lock_req, req_filename, name);
+
+    EVRPC_MAKE_REQUEST(lock_msg, rpc_pool, lock_req, lock_rep, msg_rep_cb, NULL);
+
+    event_base_dispatch(ev_base);
+}
+
+int rpc_lock(struct adouble *ad, uint32_t eid, int type, off_t off, off_t len, int user)
+{
+    rpc_dummy(cfrombstr(ad->ad_fullpath));
+    return 0;
+}
+
+void rpc_unlock(struct adouble *ad, int user)
+{
+    rpc_dummy(cfrombstr(ad->ad_fullpath));
+}
+
+int rpc_tmplock(struct adouble *ad, uint32_t eid, int type, off_t off, off_t len, int user)
+{
+    rpc_dummy(cfrombstr(ad->ad_fullpath));
+    return 0;
+}
+
+/**************************************************************************************
+ * Public functions
+ **************************************************************************************/
+
+int rpc_init(const char *addr, unsigned short port)
+{
+    EC_INIT;
+       struct evhttp_connection *evcon;
+
+    EC_NULL_LOG(ev_base = event_base_new());
+    event_set_log_callback(ev_log_cb);
+       EC_NULL_LOG(rpc_pool = evrpc_pool_new(ev_base));
+       EC_NULL_LOG(evcon = evhttp_connection_base_new(NULL, NULL, addr, port));
+
+       evrpc_pool_add_connection(rpc_pool, evcon);
+
+EC_CLEANUP:
+    EC_EXIT;
 }