summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOndrej Kozina <okozina@redhat.com>2015-04-10 16:31:28 +0200
committerOndrej Kozina <okozina@redhat.com>2015-05-05 20:52:17 +0200
commit81c038934c61f4c2afe159460b04dbccdda2a721 (patch)
tree0a95e684731de5b8fda5ed03d09ea82024aaeedd
parent76a0dffe6f4869de9ca457119c9d7ced837d4e0b (diff)
downloadlvm2-81c038934c61f4c2afe159460b04dbccdda2a721.tar.gz
polldaemon: introduce _nanosleep function
querying future lvmpolld with zero wait time is highly undesirable and can cause serious performance drop of the future daemon. The new wrapper function may avoid immediate return from syscal by introducing minimal wait time on demand.
-rw-r--r--tools/polldaemon.c21
1 files changed, 18 insertions, 3 deletions
diff --git a/tools/polldaemon.c b/tools/polldaemon.c
index 4c010f564..a311e24f5 100644
--- a/tools/polldaemon.c
+++ b/tools/polldaemon.c
@@ -13,10 +13,14 @@
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
+#include <time.h>
+
#include "tools.h"
#include "polldaemon.h"
#include "lvm2cmdline.h"
+#define WAIT_AT_LEAST_NANOSECS 100000
+
progress_t poll_mirror_progress(struct cmd_context *cmd,
struct logical_volume *lv, const char *name,
struct daemon_parms *parms)
@@ -133,11 +137,22 @@ static int _check_lv_status(struct cmd_context *cmd,
return 1;
}
+static void _nanosleep(unsigned secs, unsigned allow_zero_time)
+{
+ struct timespec wtime = {
+ .tv_sec = secs,
+ };
+
+ if (!secs && !allow_zero_time)
+ wtime.tv_nsec = WAIT_AT_LEAST_NANOSECS;
+
+ while (!nanosleep(&wtime, &wtime) && errno == EINTR) {}
+}
+
static void _sleep_and_rescan_devices(struct daemon_parms *parms)
{
- /* FIXME Use alarm for regular intervals instead */
if (parms->interval && !parms->aborting) {
- sleep(parms->interval);
+ _nanosleep(parms->interval, 1);
/* Devices might have changed while we slept */
init_full_scan_done(0);
}
@@ -346,7 +361,7 @@ static void _poll_for_all_vgs(struct cmd_context *cmd,
process_each_vg(cmd, 0, NULL, READ_FOR_UPDATE, handle, _poll_vg);
if (!parms->outstanding_count)
break;
- sleep(parms->interval);
+ _nanosleep(parms->interval, 1);
}
}