X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=lib%2Flockfile.c;h=771ad70c5d48d68c0ff784af315a455f5c28fa21;hb=007948177581f3b3dad188221593d0e4bdca6ba0;hp=9bb7c6b18af76a08b8159cb0a57c4a9e04208102;hpb=a4af00400a835eb87569ba40e21874c05e872c0f;p=sliver-openvswitch.git diff --git a/lib/lockfile.c b/lib/lockfile.c index 9bb7c6b18..771ad70c5 100644 --- a/lib/lockfile.c +++ b/lib/lockfile.c @@ -1,4 +1,4 @@ - /* Copyright (c) 2008, 2009 Nicira Networks + /* Copyright (c) 2008, 2009, 2010 Nicira Networks * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,10 +29,15 @@ #include "hmap.h" #include "timeval.h" #include "util.h" - -#define THIS_MODULE VLM_lockfile #include "vlog.h" +VLOG_DEFINE_THIS_MODULE(lockfile); + +COVERAGE_DEFINE(lockfile_lock); +COVERAGE_DEFINE(lockfile_timeout); +COVERAGE_DEFINE(lockfile_error); +COVERAGE_DEFINE(lockfile_unlock); + struct lockfile { struct hmap_node hmap_node; char *name; @@ -84,6 +89,7 @@ lockfile_lock(const char *file, int timeout, struct lockfile **lockfilep) * because the Open vSwitch code that currently uses lock files does so in * stylized ways such that any number of readers may access a file while it * is being written. */ + long long int warn_elapsed = 1000; long long int start, elapsed; char *lock_name; int error; @@ -98,6 +104,11 @@ lockfile_lock(const char *file, int timeout, struct lockfile **lockfilep) error = lockfile_try_lock(lock_name, timeout > 0, lockfilep); time_refresh(); elapsed = time_msec() - start; + if (elapsed > warn_elapsed) { + warn_elapsed *= 2; + VLOG_WARN("%s: waiting for lock file, %lld ms elapsed", + lock_name, elapsed); + } } while (error == EINTR && (timeout == INT_MAX || elapsed < timeout)); if (!error) { @@ -145,7 +156,7 @@ lockfile_postfork(void) { struct lockfile *lockfile; - HMAP_FOR_EACH (lockfile, struct lockfile, hmap_node, &lock_table) { + HMAP_FOR_EACH (lockfile, hmap_node, &lock_table) { if (lockfile->fd >= 0) { VLOG_WARN("%s: child does not inherit lock", lockfile->name); lockfile_unhash(lockfile); @@ -165,7 +176,7 @@ lockfile_find(dev_t device, ino_t inode) { struct lockfile *lockfile; - HMAP_FOR_EACH_WITH_HASH (lockfile, struct lockfile, hmap_node, + HMAP_FOR_EACH_WITH_HASH (lockfile, hmap_node, lockfile_hash(device, inode), &lock_table) { if (lockfile->device == device && lockfile->inode == inode) { return lockfile;