summaryrefslogtreecommitdiffstats
path: root/mapfile.c
diff options
context:
space:
mode:
authorNeilBrown <neilb@suse.de>2010-01-29 16:20:08 +1100
committerNeilBrown <neilb@suse.de>2010-01-29 16:20:08 +1100
commitfc7e81e54ec37ece4f1a8ec1729933fc22ec25ff (patch)
tree43c375e4db15bf5f18c49afbcafc473792c89cdb /mapfile.c
parentd998adc316299efc44cb6e70ecc2e04bffb76d17 (diff)
downloadmdadm-fc7e81e54ec37ece4f1a8ec1729933fc22ec25ff.tar.gz
mdadm-fc7e81e54ec37ece4f1a8ec1729933fc22ec25ff.tar.xz
mdadm-fc7e81e54ec37ece4f1a8ec1729933fc22ec25ff.zip
mapfile: fix locking.
The current locking uses lockf, and is completely broken. When you hold a lockf lock, any close of any fd on that file will release the lock. So map_read() call which is made as soon as we get the lock, will immediately drop the lock. So change to flock locking which isn't so badly designed. Signed-off-by: NeilBrown <neilb@suse.de>
Diffstat (limited to 'mapfile.c')
-rw-r--r--mapfile.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/mapfile.c b/mapfile.c
index ed59db5..5444452 100644
--- a/mapfile.c
+++ b/mapfile.c
@@ -48,6 +48,7 @@
* one that we can.
*/
#include "mdadm.h"
+#include <sys/file.h>
#include <ctype.h>
#define mapnames(base) { #base, #base ".new", #base ".lock"}
@@ -115,7 +116,7 @@ int map_lock(struct map_ent **melp)
lf = open_map(2, &lwhich);
if (lf == NULL)
return -1;
- if (lockf(fileno(lf), F_LOCK, 0) != 0) {
+ if (flock(fileno(lf), LOCK_EX) != 0) {
fclose(lf);
lf = NULL;
return -1;
@@ -129,8 +130,10 @@ int map_lock(struct map_ent **melp)
void map_unlock(struct map_ent **melp)
{
- if (lf)
+ if (lf) {
+ flock(fileno(lf), LOCK_UN);
fclose(lf);
+ }
unlink(mapname[lwhich][2]);
lf = NULL;
}