From 64f1cba2a992656c7f29d23e09004c4be4ce92da Mon Sep 17 00:00:00 2001 From: Derrick Brashear Date: Thu, 8 Feb 2007 23:59:32 +0000 Subject: [PATCH] DEVEL15-use-unix-sockets-20070208 option to use unix socket for fssync (cherry picked from commit a4d52ee772a84212911c52f5d79dd4f02b9a8b2a) --- acinclude.m4 | 10 ++++++++++ src/vol/daemon_com.c | 35 ++++++++++++++++++++++++++++++++--- src/vol/fssync-server.c | 39 +++++++++++++++++++++++++++++++++++++++ src/vol/fssync.h | 2 -- src/vol/salvsync-server.c | 38 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 119 insertions(+), 5 deletions(-) diff --git a/acinclude.m4 b/acinclude.m4 index 857c49cc5..0ff5b5e6f 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -35,6 +35,8 @@ AC_ARG_ENABLE( bitmap-later, [ --enable-bitmap-later enable fast startup of file server by not reading bitmap till needed],, enable_bitmap_later="no") AC_ARG_ENABLE( demand-attach-fs, [ --enable-demand-attach-fs enable Demand Attach Fileserver (please see documentation)],, enable_demand_attach_fs="no") +AC_ARG_ENABLE( unix-sockets, +[ --enable-unix-sockets enable use of unix domain sockets for fssync],, enable_unix_sockets="yes") AC_ARG_ENABLE( full-vos-listvol-switch, [ --disable-full-vos-listvol-switch disable vos full listvol switch for formatted output],, enable_full_vos_listvol_switch="yes") AC_ARG_WITH(dux-kernel-headers, @@ -1055,6 +1057,14 @@ else fi AC_SUBST(DEMAND_ATTACH) +if test "$enable_unix_sockets" = "yes"; then + AC_DEFINE(USE_UNIX_SOCKETS, 1, [define if you want to use UNIX sockets for fssync.]) + USE_UNIX_SOCKETS="yes" +else + USE_UNIX_SOCKETS="no" +fi +AC_SUBST(USE_UNIX_SOCKETS) + if test "$enable_fast_restart" = "yes" && test "$enable_demand_attach_fs" = "yes" ; then AC_MSG_ERROR([The Demand Attach and Fast Restart extensions are mutually exclusive. Demand Attach fileservers automatically salvage volumes in the background, thereby making Fast Restart pointless.]) diff --git a/src/vol/daemon_com.c b/src/vol/daemon_com.c index 26bddbf6c..a14e25cda 100644 --- a/src/vol/daemon_com.c +++ b/src/vol/daemon_com.c @@ -63,6 +63,11 @@ RCSID #include "partition.h" #include +#ifdef USE_UNIX_SOCKETS +#include +#include +#endif + /*@printflike@*/ extern void Log(const char *format, ...); #ifdef osi_Assert @@ -77,7 +82,12 @@ int (*V_BreakVolumeCallbacks) (); #define MAX_BIND_TRIES 5 /* Number of times to retry socket bind */ -static int getport(SYNC_client_state * state, struct sockaddr_in *addr); +#ifdef USE_UNIX_SOCKETS +static getport(SYNC_client_state * state, struct sockaddr_un *addr); +#else /* USE_UNIX_SOCKETS */ +static getport(SYNC_client_state * state, struct sockaddr_in *addr); +#endif /* USE_UNIX_SOCKETS */ + static int SYNC_ask_internal(SYNC_client_state * state, SYNC_command * com, SYNC_response * res); /* daemon com SYNC client interface */ @@ -85,7 +95,11 @@ static int SYNC_ask_internal(SYNC_client_state * state, SYNC_command * com, SYNC int SYNC_connect(SYNC_client_state * state) { +#ifdef USE_UNIX_SOCKETS + struct sockaddr_un addr; +#else /* USE_UNIX_SOCKETS */ struct sockaddr_in addr; +#endif /* USE_UNIX_SOCKETS */ /* I can't believe the following is needed for localhost connections!! */ static time_t backoff[] = { 3, 3, 3, 5, 5, 5, 7, 15, 16, 24, 32, 40, 48, 0 }; @@ -171,11 +185,26 @@ SYNC_reconnect(SYNC_client_state * state) } /* private function to fill in the sockaddr struct for us */ +#ifdef USE_UNIX_SOCKETS static int -getport(SYNC_client_state * state, struct sockaddr_in *addr) +getport(SYNC_client_state * state, struct sockaddr_un *addr) { int sd; + char tbuffer[AFSDIR_PATH_MAX]; + strcompose(tbuffer, AFSDIR_PATH_MAX, AFSDIR_SERVER_LOCAL_DIRPATH, "/", + "fssync.sock", NULL); + memset(addr, 0, sizeof(*addr)); + addr->sun_family = AF_UNIX; + strncpy(addr->sun_path, tbuffer, (sizeof(struct sockaddr_un) - sizeof(short))); + assert((sd = socket(AF_UNIX, SOCK_STREAM, 0)) >= 0); + return sd; +} +#else /* USE_UNIX_SOCKETS */ +static int +getport(SYNC_client_state * state, struct sockaddr_in *addr) +{ + int sd; memset(addr, 0, sizeof(*addr)); assert((sd = socket(AF_INET, SOCK_STREAM, 0)) >= 0); #ifdef STRUCT_SOCKADDR_HAS_SA_LEN @@ -184,9 +213,9 @@ getport(SYNC_client_state * state, struct sockaddr_in *addr) addr->sin_addr.s_addr = htonl(0x7f000001); addr->sin_family = AF_INET; /* was localhost->h_addrtype */ addr->sin_port = htons(state->port); /* XXXX htons not _really_ neccessary */ - return sd; } +#endif /* USE_UNIX_SOCKETS */ afs_int32 SYNC_ask(SYNC_client_state * state, SYNC_command * com, SYNC_response * res) diff --git a/src/vol/fssync-server.c b/src/vol/fssync-server.c index 44494ca73..08c917544 100644 --- a/src/vol/fssync-server.c +++ b/src/vol/fssync-server.c @@ -98,6 +98,10 @@ RCSID #include "volume.h" #include "partition.h" +#ifdef USE_UNIX_SOCKETS +#include +#include +#endif /* USE_UNIX_SOCKETS */ #ifdef FSSYNC_BUILD_SERVER @@ -201,6 +205,23 @@ FSYNC_fsInit(void) static fd_set FSYNC_readfds; +#ifdef USE_UNIX_SOCKETS +static int +getport(struct sockaddr_un *addr) +{ + int sd; + char tbuffer[AFSDIR_PATH_MAX]; + + strcompose(tbuffer, AFSDIR_PATH_MAX, AFSDIR_SERVER_LOCAL_DIRPATH, "/", + "fssync.sock", NULL); + + memset(addr, 0, sizeof(*addr)); + addr->sun_family = AF_UNIX; + strncpy(addr->sun_path, tbuffer, (sizeof(struct sockaddr_un) - sizeof(short))); + assert((sd = socket(AF_UNIX, SOCK_STREAM, 0)) >= 0); + return sd; +} +#else static int getport(struct sockaddr_in *addr) { @@ -217,12 +238,18 @@ getport(struct sockaddr_in *addr) return sd; } +#endif static void FSYNC_sync() { +#ifdef USE_UNIX_SOCKETS + struct sockaddr_un addr; + char tbuffer[AFSDIR_PATH_MAX]; +#else /* USE_UNIX_SOCKETS */ struct sockaddr_in addr; +#endif /* USE_UNIX_SOCKETS */ int on = 1; extern int VInit; int code; @@ -244,6 +271,14 @@ FSYNC_sync() Log("Set thread id %d for FSYNC_sync\n", tid); #endif /* AFS_PTHREAD_ENV */ +#ifdef USE_UNIX_SOCKETS + /* ignore errors */ + strcompose(tbuffer, AFSDIR_PATH_MAX, AFSDIR_SERVER_LOCAL_DIRPATH, "/", + "fssync.sock", NULL); + + remove(tbuffer); +#endif /* USE_UNIX_SOCKETS */ + while (!VInit) { /* Let somebody else run until level > 0. That doesn't mean that * all volumes have been attached. */ @@ -291,7 +326,11 @@ FSYNC_sync() static void FSYNC_newconnection(int afd) { +#ifdef USE_UNIX_SOCKETS + struct sockaddr_un other; +#else /* USE_UNIX_SOCKETS */ struct sockaddr_in other; +#endif int junk, fd; junk = sizeof(other); fd = accept(afd, (struct sockaddr *)&other, &junk); diff --git a/src/vol/fssync.h b/src/vol/fssync.h index 873b27497..c40bb6f19 100644 --- a/src/vol/fssync.h +++ b/src/vol/fssync.h @@ -59,8 +59,6 @@ /* FSYNC flag codes */ - - struct offlineInfo { afs_uint32 volumeID; char partName[16]; diff --git a/src/vol/salvsync-server.c b/src/vol/salvsync-server.c index d9e083b23..e7549e9d3 100644 --- a/src/vol/salvsync-server.c +++ b/src/vol/salvsync-server.c @@ -72,6 +72,12 @@ RCSID #include #endif +#ifdef USE_UNIX_SOCKETS +#include +#include +#endif + + /*@printflike@*/ extern void Log(const char *format, ...); #ifdef osi_Assert @@ -267,6 +273,23 @@ SALVSYNC_salvInit(void) assert(pthread_create(&tid, &tattr, SALVSYNC_syncThread, NULL) == 0); } +#ifdef USE_UNIX_SOCKETS +static int +getport(struct sockaddr_un *addr) +{ + int sd; + char tbuffer[AFSDIR_PATH_MAX]; + + strcompose(tbuffer, AFSDIR_PATH_MAX, AFSDIR_SERVER_LOCAL_DIRPATH, "/", + "fssync.sock", NULL); + + memset(addr, 0, sizeof(*addr)); + addr->sun_family = AF_UNIX; + strncpy(addr->sun_path, tbuffer, (sizeof(struct sockaddr_un) - sizeof(short))); + assert((sd = socket(AF_UNIX, SOCK_STREAM, 0)) >= 0); + return sd; +} +#else static int getport(struct sockaddr_in *addr) { @@ -283,6 +306,7 @@ getport(struct sockaddr_in *addr) return sd; } +#endif static fd_set SALVSYNC_readfds; @@ -294,6 +318,9 @@ SALVSYNC_syncThread(void * args) int code; int numTries; int tid; +#ifdef USE_UNIX_SOCKETS + char tbuffer[AFSDIR_PATH_MAX]; +#endif #ifndef AFS_NT40_ENV (void)signal(SIGPIPE, SIG_IGN); @@ -306,6 +333,13 @@ SALVSYNC_syncThread(void * args) pthread_setspecific(rx_thread_id_key, (void *)tid); Log("Set thread id %d for SALVSYNC_syncThread\n", tid); +#ifdef USE_UNIX_SOCKETS + strcompose(tbuffer, AFSDIR_PATH_MAX, AFSDIR_SERVER_LOCAL_DIRPATH, "/", + "fssync.sock", NULL); + /* ignore errors */ + remove(tbuffer); +#endif /* USE_UNIX_SOCKETS */ + AcceptSd = getport(&addr); /* Reuseaddr needed because system inexplicably leaves crud lying around */ code = @@ -343,7 +377,11 @@ SALVSYNC_syncThread(void * args) static void SALVSYNC_newconnection(int afd) { +#ifdef USE_UNIX_SOCKETS + struct sockaddr_un other; +#else /* USE_UNIX_SOCKETS */ struct sockaddr_in other; +#endif int junk, fd; junk = sizeof(other); fd = accept(afd, (struct sockaddr *)&other, &junk); -- 2.39.5