From 03e5a7800d31173434f98edc315d6e4be0bf13c2 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Fri, 15 Dec 2017 06:20:09 +0100 Subject: NFS: Use self-contained recursive mutex Update #2843. --- cpukit/libfs/src/nfsclient/src/nfs.c | 90 +++++++++------------------------- cpukit/libfs/src/nfsclient/src/rpcio.c | 76 +++++++--------------------- 2 files changed, 41 insertions(+), 125 deletions(-) (limited to 'cpukit/libfs/src') diff --git a/cpukit/libfs/src/nfsclient/src/nfs.c b/cpukit/libfs/src/nfsclient/src/nfs.c index ca4226465a..4eb4249606 100644 --- a/cpukit/libfs/src/nfsclient/src/nfs.c +++ b/cpukit/libfs/src/nfsclient/src/nfs.c @@ -67,6 +67,7 @@ #include #include #include +#include #include #include #include @@ -197,19 +198,9 @@ static struct timeval _nfscalltimeout = { 10, 0 }; /* {secs, us } */ #define STATIC static #endif -#define MUTEX_ATTRIBUTES (RTEMS_LOCAL | \ - RTEMS_PRIORITY | \ - RTEMS_INHERIT_PRIORITY | \ - RTEMS_BINARY_SEMAPHORE) +#define LOCK(s) rtems_recursive_mutex_lock(&(s)) -#define LOCK(s) do { \ - rtems_semaphore_obtain((s), \ - RTEMS_WAIT, \ - RTEMS_NO_TIMEOUT); \ - } while (0) - -#define UNLOCK(s) do { rtems_semaphore_release((s)); \ - } while (0) +#define UNLOCK(s) rtems_recursive_mutex_unlock(&(s)) RTEMS_INTERRUPT_LOCK_DEFINE(static, nfs_global_lock, "NFS") @@ -1036,6 +1027,9 @@ rtems_status_code status; if (0==bigPoolDepth) bigPoolDepth = 10; + rtems_recursive_mutex_init(&nfsGlob.llock, "NFSl"); + rtems_recursive_mutex_init(&nfsGlob.lock, "NFSm"); + /* it's crucial to zero out the 'next' pointer * because it terminates the xdr_entry recursion * @@ -1067,26 +1061,6 @@ rtems_status_code status; goto cleanup; } - status = rtems_semaphore_create( - rtems_build_name('N','F','S','l'), - 1, - MUTEX_ATTRIBUTES, - 0, - &nfsGlob.llock); - if (status != RTEMS_SUCCESSFUL) { - goto cleanup; - } - - status = rtems_semaphore_create( - rtems_build_name('N','F','S','m'), - 1, - MUTEX_ATTRIBUTES, - 0, - &nfsGlob.lock); - if (status != RTEMS_SUCCESSFUL) { - goto cleanup; - } - if (sizeof(ino_t) < sizeof(u_int)) { fprintf(stderr, "WARNING: Using 'short st_ino' hits performance and may fail to access/find correct files\n"); @@ -1112,23 +1086,16 @@ nfsCleanup(void) { int refuse; - if (nfsGlob.llock != 0) { - LOCK(nfsGlob.llock); - if ( (refuse = nfsGlob.num_mounted_fs) ) { - fprintf(stderr,"Refuse to unload NFS; %i filesystems still mounted.\n", - refuse); - nfsMountsShow(stderr); - /* yes, printing is slow - but since you try to unload the driver, - * you assume nobody is using NFS, so what if they have to wait? - */ - UNLOCK(nfsGlob.llock); - return -1; - } - } - - if (nfsGlob.lock != 0) { - rtems_semaphore_delete(nfsGlob.lock); - nfsGlob.lock = 0; + LOCK(nfsGlob.llock); + if ( (refuse = nfsGlob.num_mounted_fs) ) { + fprintf(stderr,"Refuse to unload NFS; %i filesystems still mounted.\n", + refuse); + nfsMountsShow(stderr); + /* yes, printing is slow - but since you try to unload the driver, + * you assume nobody is using NFS, so what if they have to wait? + */ + UNLOCK(nfsGlob.llock); + return -1; } if (nfsGlob.smallPool != NULL) { @@ -1146,10 +1113,10 @@ int refuse; nfsGlob.nfs_major = 0xffffffff; } - if (nfsGlob.llock != 0) { - rtems_semaphore_delete(nfsGlob.llock); - nfsGlob.llock = 0; - } + UNLOCK(nfsGlob.llock); + + rtems_recursive_mutex_destroy(&nfsGlob.lock); + rtems_recursive_mutex_destroy(&nfsGlob.llock); return 0; } @@ -3138,7 +3105,7 @@ rtems_filesystem_location_info_t old; /* must restore the cwd because 'freenode' will be called on it */ rtems_filesystem_current->location = old; } - rtems_semaphore_release(rpa->sync); + rtems_binary_semaphore_post(&rpa->sync); rtems_task_delete(RTEMS_SELF); } @@ -3165,15 +3132,7 @@ rtems_status_code status; arg.len = len; arg.sync = 0; - status = rtems_semaphore_create( - rtems_build_name('r','e','s','s'), - 0, - RTEMS_SIMPLE_BINARY_SEMAPHORE, - 0, - &arg.sync); - - if (RTEMS_SUCCESSFUL != status) - goto cleanup; + rtems_binary_semaphore_init(&arg.sync, "NFSress"); rtems_task_set_priority(RTEMS_SELF, RTEMS_CURRENT_PRIORITY, &pri); @@ -3197,13 +3156,12 @@ rtems_status_code status; /* synchronize with the helper task */ - rtems_semaphore_obtain(arg.sync, RTEMS_WAIT, RTEMS_NO_TIMEOUT); + rtems_binary_semaphore_wait(&arg.sync); status = arg.status; cleanup: - if (arg.sync) - rtems_semaphore_delete(arg.sync); + rtems_binary_semaphore_destroy(&arg.sync); return status; } diff --git a/cpukit/libfs/src/nfsclient/src/rpcio.c b/cpukit/libfs/src/nfsclient/src/rpcio.c index 56e3341a89..f10c0bdd3c 100644 --- a/cpukit/libfs/src/nfsclient/src/rpcio.c +++ b/cpukit/libfs/src/nfsclient/src/rpcio.c @@ -72,6 +72,7 @@ #include #include #include +#include #include #include #include @@ -81,6 +82,7 @@ #include #include #include +#include #include #include #include @@ -199,50 +201,13 @@ static struct timeval _rpc_default_timeout = { 10 /* secs */, 0 /* usecs */ }; #define XACT_HASH_MSK ((XACT_HASHS)-1) /* mask to extract the hash index from a RPC-XID */ -#define MU_LOCK(mutex) do { \ - assert( \ - RTEMS_SUCCESSFUL == \ - rtems_semaphore_obtain( \ - (mutex), \ - RTEMS_WAIT, \ - RTEMS_NO_TIMEOUT \ - ) ); \ - } while(0) - -#define MU_UNLOCK(mutex) do { \ - assert( \ - RTEMS_SUCCESSFUL == \ - rtems_semaphore_release( \ - (mutex) \ - ) ); \ - } while(0) - -#define MU_CREAT(pmutex) do { \ - assert( \ - RTEMS_SUCCESSFUL == \ - rtems_semaphore_create( \ - rtems_build_name( \ - 'R','P','C','l' \ - ), \ - 1, \ - MUTEX_ATTRIBUTES, \ - 0, \ - (pmutex)) ); \ - } while (0) - - -#define MU_DESTROY(mutex) do { \ - assert( \ - RTEMS_SUCCESSFUL == \ - rtems_semaphore_delete( \ - mutex \ - ) ); \ - } while (0) - -#define MUTEX_ATTRIBUTES (RTEMS_LOCAL | \ - RTEMS_PRIORITY | \ - RTEMS_INHERIT_PRIORITY | \ - RTEMS_BINARY_SEMAPHORE) +#define MU_LOCK(mutex) rtems_recursive_mutex_lock(&(mutex)) + +#define MU_UNLOCK(mutex) rtems_recursive_mutex_unlock(&(mutex)) + +#define MU_CREAT(pmutex) rtems_recursive_mutex_init((pmutex), "RPCl") + +#define MU_DESTROY(mutex) rtems_recursive_mutex_destroy(&(mutex)) #define FIRST_ATTEMPT 0x88888888 /* some time that is never reached */ @@ -269,7 +234,7 @@ typedef struct RpcUdpServerRec_ { struct sockaddr sa; } addr; AUTH *auth; - rtems_id authlock; /* must MUTEX the auth object - it's not clear + rtems_recursive_mutex authlock; /* must MUTEX the auth object - it's not clear * what is better: * 1 having one (MUTEXed) auth per server * who is shared among all transactions @@ -397,10 +362,10 @@ static rtems_id msgQ = 0; /* message queue where the daemon picks up * requests */ #ifndef NDEBUG -static rtems_id llock = 0; /* MUTEX protecting the server list */ -static rtems_id hlock = 0; /* MUTEX protecting the hash table and the list of servers */ +static rtems_recursive_mutex llock; /* MUTEX protecting the server list */ +static rtems_recursive_mutex hlock; /* MUTEX protecting the hash table and the list of servers */ #endif -static rtems_id fini = 0; /* a synchronization semaphore we use during +static rtems_binary_semaphore fini = RTEMS_BINARY_SEMAPHORE_INITIALIZER("RPCf"); /* a synchronization semaphore we use during * module cleanup / driver unloading */ static rtems_interval ticksPerSec; /* cached system clock rate (WHO IS ASSUMED NOT @@ -1021,20 +986,13 @@ struct sockwakeup wkup; int rpcUdpCleanup(void) { - rtems_semaphore_create( - rtems_build_name('R','P','C','f'), - 0, - RTEMS_DEFAULT_ATTRIBUTES, - 0, - &fini); rtems_event_send(rpciod, RPCIOD_KILL_EVENT); /* synchronize with daemon */ - rtems_semaphore_obtain(fini, RTEMS_WAIT, 5*ticksPerSec); + rtems_binary_semaphore_wait_timed_ticks(&fini, 5*ticksPerSec); /* if the message queue is still there, something went wrong */ if (!msgQ) { rtems_task_delete(rpciod); } - rtems_semaphore_delete(fini); return (msgQ !=0); } @@ -1228,7 +1186,7 @@ rtems_status_code status; if (i>=0) { fprintf(stderr,"RPCIO There are still transactions circulating; I refuse to go away\n"); fprintf(stderr,"(1st in slot %i)\n",i); - rtems_semaphore_release(fini); + rtems_binary_semaphore_post(&fini); } else { break; } @@ -1349,7 +1307,7 @@ rtems_status_code status; fprintf(stderr,"RPCIO XACT timed out; waking up requestor\n"); #endif if ( rtems_event_send(xact->requestor, RTEMS_RPC_EVENT) ) { - rtems_panic("RPCIO PANIC: requestor id was 0x%08x", + rtems_panic("RPCIO PANIC: requestor id was 0x%08" PRIx32, xact->requestor); } @@ -1527,7 +1485,7 @@ rtems_status_code status; fprintf(stderr,"RPC daemon exited...\n"); - rtems_semaphore_release(fini); + rtems_binary_semaphore_post(&fini); rtems_task_suspend(RTEMS_SELF); } -- cgit v1.2.3