mirror of
https://github.com/ibm-s390-linux/s390-tools.git
synced 2026-08-05 02:14:52 +00:00
libap: use custom wait time for file locks
If many invocations of mdevctl occur simultaneously (as can happen with libvirt) then waiting for 5-60 seconds per lock retry is simply too long. Anticipating this possibility, retry more frequently but also attempt significantly more retries than before. Reported-by: Marc Hartmayer <mhartmay@linux.ibm.com> Reviewed-by: Boris Fiuczynski <fiuczy@linux.ibm.com> Reviewed-by: Marc Hartmayer <marc@linux.ibm.com> Tested-by: Marc Hartmayer <marc@linux.ibm.com> Signed-off-by: Matthew Rosato <mjrosato@linux.ibm.com> Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
This commit is contained in:
committed by
Steffen Eiden
parent
f5f806af06
commit
474c6adf8f
@@ -21,7 +21,9 @@
|
||||
#define AP_UDEV_FILE "/etc/udev/rules.d/41-ap.rules"
|
||||
#define AP_LOCKFILE "/run/lock/s390apconfig.lock"
|
||||
|
||||
#define AP_LOCK_RETRIES 15
|
||||
#define AP_LOCK_RETRIES 3000
|
||||
#define AP_LOCK_DELAY_US 30000 /* wait at least 30ms between lock retries */
|
||||
#define AP_LOCK_VARIANCE_US 3000 /* or as much as 33ms */
|
||||
|
||||
/* apmask and aqmask are each represented as 67 character strings with:
|
||||
* '0x' leading characters
|
||||
|
||||
26
libap/ap.c
26
libap/ap.c
@@ -11,12 +11,15 @@
|
||||
#include <dirent.h>
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#ifdef HAVE_JSONC
|
||||
#include <json-c/json.h>
|
||||
@@ -698,6 +701,20 @@ void ap_list_remove_all(struct util_list *list)
|
||||
}
|
||||
}
|
||||
|
||||
static unsigned int random_delay(void)
|
||||
{
|
||||
static bool libap_seed = true;
|
||||
struct timeval t;
|
||||
|
||||
if (libap_seed) {
|
||||
gettimeofday(&t, NULL);
|
||||
srand((unsigned int)((t.tv_sec + t.tv_usec) % UINT_MAX));
|
||||
libap_seed = false;
|
||||
}
|
||||
|
||||
return AP_LOCK_DELAY_US + (rand() % AP_LOCK_VARIANCE_US);
|
||||
}
|
||||
|
||||
/**
|
||||
* Acquire the ap config lock using this Process ID
|
||||
*
|
||||
@@ -707,7 +724,9 @@ void ap_list_remove_all(struct util_list *list)
|
||||
*/
|
||||
int ap_get_lock(void)
|
||||
{
|
||||
return util_lockfile_lock(AP_LOCKFILE, AP_LOCK_RETRIES);
|
||||
unsigned int delay = random_delay();
|
||||
|
||||
return util_lockfile_lock_cw(AP_LOCKFILE, AP_LOCK_RETRIES, delay, delay);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -719,7 +738,10 @@ int ap_get_lock(void)
|
||||
*/
|
||||
int ap_get_lock_callout(void)
|
||||
{
|
||||
return util_lockfile_parent_lock(AP_LOCKFILE, AP_LOCK_RETRIES);
|
||||
unsigned int delay = random_delay();
|
||||
|
||||
return util_lockfile_parent_lock_cw(AP_LOCKFILE, AP_LOCK_RETRIES, delay,
|
||||
delay);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user