1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00

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.
This commit is contained in:
Ondrej Kozina 2015-04-10 16:31:28 +02:00
parent 76a0dffe6f
commit 81c038934c

View File

@ -13,10 +13,14 @@
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#include <time.h>
#include "tools.h" #include "tools.h"
#include "polldaemon.h" #include "polldaemon.h"
#include "lvm2cmdline.h" #include "lvm2cmdline.h"
#define WAIT_AT_LEAST_NANOSECS 100000
progress_t poll_mirror_progress(struct cmd_context *cmd, progress_t poll_mirror_progress(struct cmd_context *cmd,
struct logical_volume *lv, const char *name, struct logical_volume *lv, const char *name,
struct daemon_parms *parms) struct daemon_parms *parms)
@ -133,11 +137,22 @@ static int _check_lv_status(struct cmd_context *cmd,
return 1; 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) static void _sleep_and_rescan_devices(struct daemon_parms *parms)
{ {
/* FIXME Use alarm for regular intervals instead */
if (parms->interval && !parms->aborting) { if (parms->interval && !parms->aborting) {
sleep(parms->interval); _nanosleep(parms->interval, 1);
/* Devices might have changed while we slept */ /* Devices might have changed while we slept */
init_full_scan_done(0); 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); process_each_vg(cmd, 0, NULL, READ_FOR_UPDATE, handle, _poll_vg);
if (!parms->outstanding_count) if (!parms->outstanding_count)
break; break;
sleep(parms->interval); _nanosleep(parms->interval, 1);
} }
} }