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

@@ -319,7 +319,6 @@ build options:
| | | pvattest |
| libxml2 | `HAVE_LIBXML2` | libkmipclient |
| systemd | `HAVE_SYSTEMD` | hsavmcore |
| liblockfile | `HAVE_LOCKFILE` | ap-check |
| libudev | `HAVE_LIBUDEV` | cpacfstatsd |
This table lists additional build or install options:
@@ -513,8 +512,7 @@ the different tools are provided:
GNU awk for the build process.
* ap-check:
For building the ap-check mdevctl callout utility you need liblockfile
version 1.14 or newer installed (liblockfile-devel.rpm). Also required is
json-c version 0.13 or newer (json-c-devel.rpm).
Tip: you may skip ap-check build by adding `HAVE_LOCKFILE=0` or `HAVE_JSONC=0`
to the make invocation.
For building the ap-check mdevctl callout utility you need json-c version
0.13 or newer (json-c-devel.rpm).
Tip: you may skip ap-check build by adding `HAVE_JSONC=0` to the make
invocation.

View File

@@ -7,21 +7,14 @@ MDEVCTL_CALLOUTS = /etc/mdevctl.d/scripts.d/callouts/
libs = $(rootdir)/libap/libap.a \
$(rootdir)/libutil/libutil.a
ifeq (${HAVE_LOCKFILE},0)
all:
$(SKIP) HAVE_LOCKFILE=0
install:
$(SKIP) HAVE_LOCKFILE=0
else ifeq (${HAVE_JSONC},0)
ifeq (${HAVE_JSONC},0)
all:
$(SKIP) HAVE_JSONC=0
install:
$(SKIP) HAVE_JSONC=0
else
LDLIBS += -llockfile -ljson-c
LDLIBS += -ljson-c
all: ap-check

View File

@@ -133,7 +133,7 @@ static void ap_check_cleanup(struct ap_check_anchor *anc)
if (anc->dev)
vfio_ap_device_free(anc->dev);
if (anc->cleanup_lock)
ap_release_lock();
ap_release_lock_callout();
}
/*
@@ -775,7 +775,7 @@ out:
*/
static int ap_check_handle_post(void)
{
return ap_release_lock();
return ap_release_lock_callout();
}
/* For the specified device, print the attributes to stdout in JSON format */

View File

@@ -90,5 +90,6 @@ void ap_list_remove_all(struct util_list *list);
int ap_get_lock(void);
int ap_get_lock_callout(void);
int ap_release_lock(void);
int ap_release_lock_callout(void);
#endif /* LIB_AP_H */

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 */

View File

@@ -81,9 +81,6 @@ lszdev_objects += generic_ccw.o
all: chzdev lszdev zdev_id
ifneq (${HAVE_LOCKFILE}, 0)
LDLIBS += -llockfile
endif
ifneq (${HAVE_JSONC}, 0)
LDLIBS += -ljson-c
endif