libap: use util_lockfile and remove liblockfile dependency

Now that we have a utility library for file locking, remove all
calls to liblockfile functions from libap and remove all links to
the library from the current users of the libap liblockfile
implementation (ap_tools/ap-check and zdev).

Fixes: https://github.com/ibm-s390-linux/s390-tools/issues/142
Suggested-by: Luca BRUNO <luca.bruno@coreos.com>
Signed-off-by: Matthew Rosato <mjrosato@linux.ibm.com>
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
This commit is contained in:
Matthew Rosato
2022-09-08 11:23:59 -04:00
committed by Jan Höppner
parent 6235a51d7c
commit 25a70ac5a8
7 changed files with 22 additions and 65 deletions

View File

@@ -2,17 +2,6 @@ include ../common.mak
lib = libap.a
check-dep-lock:
touch check-dep-lock
ifneq (${HAVE_LOCKFILE},0)
$(call check_dep, \
"libap", \
"lockfile.h", \
"liblockfile-devel", \
"HAVE_LOCKFILE=0")
ALL_CPPFLAGS += -DHAVE_LOCKFILE
endif
check-dep-json:
touch check-dep-json
ifneq (${HAVE_JSONC},0)
@@ -29,7 +18,7 @@ objects = ap.o
$(lib): $(objects)
$(objects): check-dep-lock check-dep-json
$(objects): check-dep-json
install: all

View File

@@ -22,13 +22,10 @@
#include <json-c/json.h>
#endif /* HAVE_JSONC */
#ifdef HAVE_LOCKFILE
#include <lockfile.h>
#endif /* HAVE_LOCKFILE */
#include "lib/ap.h"
#include "lib/util_file.h"
#include "lib/util_libc.h"
#include "lib/util_lockfile.h"
#include "lib/util_panic.h"
#include "lib/util_path.h"
#include "lib/util_udev.h"
@@ -701,33 +698,28 @@ void ap_list_remove_all(struct util_list *list)
}
}
#ifdef HAVE_LOCKFILE
static int ap_lockfile_create(int flags)
{
return lockfile_create(AP_LOCKFILE, AP_LOCK_RETRIES, flags);
}
/**
* Acquire the ap config lock using this process PID (L_PID)
* Acquire the ap config lock using this Process ID
*
* @retval 0 Lock acquired on behalf of this process
*
* @retval 0 Lock successfully acquired on behalf of L_PID
* @retval != 0 Error, lock was not obtained
*/
int ap_get_lock(void)
{
return ap_lockfile_create(L_PID);
return util_lockfile_lock(AP_LOCKFILE, AP_LOCK_RETRIES);
}
/**
* Acquire the ap config lock using the parent process PID (L_PPID) -- intended
* for use by the mdevctl callout ap-check utility
* Acquire the ap config lock using the Parent Process ID -- intended for use
* by the mdevctl callout ap-check utility
*
* @retval 0 Lock successfully acquired on behalf of L_PPID
* @retval 0 Lock acquired on behalf of parent process
* @retval != 0 Error, lock was not obtained
*/
int ap_get_lock_callout(void)
{
return ap_lockfile_create(L_PPID);
return util_lockfile_parent_lock(AP_LOCKFILE, AP_LOCK_RETRIES);
}
/**
@@ -738,23 +730,10 @@ int ap_get_lock_callout(void)
*/
int ap_release_lock(void)
{
return lockfile_remove(AP_LOCKFILE);
}
#else
/* If no liblockfile, actions are performed without acquiring the file lock */
int ap_get_lock(void)
{
return 0;
return util_lockfile_release(AP_LOCKFILE);
}
int ap_get_lock_callout(void)
int ap_release_lock_callout(void)
{
return 0;
return util_lockfile_parent_release(AP_LOCKFILE);
}
int ap_release_lock(void)
{
return 0;
}
#endif /* HAVE_LOCKFILE */