From 75e3afb6a0c71d2ba90e7a8f5d54309a8c31a343 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20H=C3=B6ppner?= Date: Wed, 3 Apr 2019 14:44:35 +0200 Subject: [PATCH] libdasd: Move get_host_access_count() to libdasd MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reading DASD specific sysfs attributes should be collected in one library. Move get_host_access_count() to libdasd/dasd_sys. Remove the old implementation and update any user accordingly. Also, fix the build order for zdsfs. Signed-off-by: Jan Höppner --- dasdfmt/Makefile | 1 - dasdfmt/dasdfmt.c | 2 +- dasdview/Makefile | 1 - dasdview/dasdview.c | 1 - fdasd/fdasd.c | 2 +- include/lib/dasd_sys.h | 2 +- include/lib/u2s.h | 2 -- libdasd/dasd_sys.c | 31 +++++++++++++++++++++++++++++++ libu2s/u2s.c | 42 ------------------------------------------ libzds/libzds.c | 4 ++-- zdsfs/Makefile | 2 +- 11 files changed, 37 insertions(+), 53 deletions(-) diff --git a/dasdfmt/Makefile b/dasdfmt/Makefile index 03877b39..98d9d3ea 100644 --- a/dasdfmt/Makefile +++ b/dasdfmt/Makefile @@ -4,7 +4,6 @@ all: dasdfmt libs = $(rootdir)/libdasd/libdasd.a \ $(rootdir)/libvtoc/libvtoc.a \ - $(rootdir)/libu2s/libu2s.a \ $(rootdir)/libutil/libutil.a dasdfmt: dasdfmt.o $(libs) diff --git a/dasdfmt/dasdfmt.c b/dasdfmt/dasdfmt.c index a34d79bc..944376d9 100644 --- a/dasdfmt/dasdfmt.c +++ b/dasdfmt/dasdfmt.c @@ -1394,7 +1394,7 @@ static void do_format_dasd(dasdfmt_info_t *info, char *devname, if ((info->verbosity > 0) || !info->withoutprompt || info->testmode) dasdfmt_print_info(info, devname, vlabel, cylinders, heads, p); - count = u2s_get_host_access_count(devname); + count = dasd_get_host_access_count(devname); if (info->force_host) { if (count > 1) { ERRMSG_EXIT(EXIT_FAILURE, diff --git a/dasdview/Makefile b/dasdview/Makefile index b7bdba35..59fda17d 100644 --- a/dasdview/Makefile +++ b/dasdview/Makefile @@ -7,7 +7,6 @@ all: dasdview libs = $(rootdir)/libdasd/libdasd.a \ $(rootdir)/libzds/libzds.a \ $(rootdir)/libvtoc/libvtoc.a \ - $(rootdir)/libu2s/libu2s.a \ $(rootdir)/libutil/libutil.a dasdview: dasdview.o $(libs) diff --git a/dasdview/dasdview.c b/dasdview/dasdview.c index 61bed640..89041655 100644 --- a/dasdview/dasdview.c +++ b/dasdview/dasdview.c @@ -28,7 +28,6 @@ #include "lib/dasd_base.h" #include "lib/dasd_sys.h" #include "lib/libzds.h" -#include "lib/u2s.h" #include "lib/util_base.h" #include "lib/util_opt.h" #include "lib/util_prg.h" diff --git a/fdasd/fdasd.c b/fdasd/fdasd.c index 7c1a1a74..8f4ddf01 100644 --- a/fdasd/fdasd.c +++ b/fdasd/fdasd.c @@ -935,7 +935,7 @@ static void fdasd_verify_device(fdasd_anchor_t *anc, char *name) fdasd_error(anc, device_verification_failed, err_str); } - count = u2s_get_host_access_count(name); + count = dasd_get_host_access_count(name); if (anc->force_host) { if (count > 1) { snprintf(err_str, ERROR_STRING_SIZE, diff --git a/include/lib/dasd_sys.h b/include/lib/dasd_sys.h index 54381720..0f5e5773 100644 --- a/include/lib/dasd_sys.h +++ b/include/lib/dasd_sys.h @@ -13,9 +13,9 @@ #define LIB_DASD_SYS_H #include -#include "u2s.h" int dasd_sys_raw_track_access(char *); int dasd_reset_chpid(char *, char *); +int dasd_get_host_access_count(char *device); #endif /* LIB_DASD_SYS_H */ diff --git a/include/lib/u2s.h b/include/lib/u2s.h index fe5d6731..f383a0bc 100644 --- a/include/lib/u2s.h +++ b/include/lib/u2s.h @@ -15,7 +15,5 @@ #define U2S_BUS_ID_SIZE 32 int u2s_getbusid(char *, char *); -int u2s_read_attribute(char *, char *, char *, size_t); -int u2s_get_host_access_count(char *); #endif /* LIB_U2S_H */ diff --git a/libdasd/dasd_sys.c b/libdasd/dasd_sys.c index 5ca46945..7d303519 100644 --- a/libdasd/dasd_sys.c +++ b/libdasd/dasd_sys.c @@ -14,6 +14,7 @@ #include "lib/dasd_base.h" #include "lib/dasd_sys.h" +#include "lib/util_file.h" #include "lib/util_path.h" #include "lib/util_sys.h" @@ -155,3 +156,33 @@ int dasd_reset_chpid(char *devnode, char *chpid_char) return 0; } + +/** + * Read amount of host with access to \p device + * + * The \p device can be any valid relative or absolute path to a DASD device + * node, for example: + * + * - /dev/dasda + * - /dev/disk/by-path/ccw-0.0.bf20 + * + * @param[in] device Device node of interest + * + * @retval n Number of hosts with access to \p device + * @retval 0 Value could not be determined + */ +int dasd_get_host_access_count(char *device) +{ + char busid[9]; + char *path; + long value; + + if (!util_sys_get_dev_addr(device, busid)) + return 0; + + path = util_path_sysfs("bus/ccw/devices/%s/host_access_count", busid); + util_file_read_l(&value, 10, path); + free(path); + + return value; +} diff --git a/libu2s/u2s.c b/libu2s/u2s.c index 90819622..56ed7d1e 100644 --- a/libu2s/u2s.c +++ b/libu2s/u2s.c @@ -290,45 +290,3 @@ int u2s_getbusid(char *devicenode, char *busid) return rc; } - -/* - * Attempts to find the sysfs entry for the given busid and reads - * the contents of a specified attribute to the buffer - */ -int u2s_read_attribute(char *busid, char *attribute, char *buffer, - size_t count) -{ - char path[100]; - int rc, fd; - ssize_t rcount; - - rc = 0; - snprintf(path, sizeof(path), "/sys/bus/ccw/devices/%s/%s", - busid, attribute); - fd = open(path, O_RDONLY); - if (fd < 0) - return errno; - rcount = read(fd, buffer, count); - if (rcount < 0) - rc = errno; - close(fd); - return rc; -} - -int u2s_get_host_access_count(char *devicenode) -{ - char busid[BUSIDSIZE]; - unsigned long value; - char buffer[10]; - char *endp; - - u2s_getbusid(devicenode, busid); - u2s_read_attribute(busid, "host_access_count", buffer, sizeof(buffer)); - - value = strtoul(buffer, &endp, 0); - - if (endp == buffer) - return -EINVAL; - - return value; -} diff --git a/libzds/libzds.c b/libzds/libzds.c index 9032b5b1..c4447690 100644 --- a/libzds/libzds.c +++ b/libzds/libzds.c @@ -20,8 +20,8 @@ #include #include "lib/dasd_base.h" +#include "lib/dasd_sys.h" #include "lib/libzds.h" -#include "lib/u2s.h" #include "lib/vtoc.h" /** @cond PRIVATE */ @@ -3701,7 +3701,7 @@ int lzds_analyse_open_count(struct zdsroot *root, int warn) int rc = 0; util_list_iterate(root->dasdlist, dasd) { - value = u2s_get_host_access_count(dasd->device); + value = dasd_get_host_access_count(dasd->device); if (value < 0) { fprintf(stderr, diff --git a/zdsfs/Makefile b/zdsfs/Makefile index 579ce4b7..f12515ee 100644 --- a/zdsfs/Makefile +++ b/zdsfs/Makefile @@ -2,9 +2,9 @@ include ../common.mak libs = $(rootdir)/libzds/libzds.a \ $(rootdir)/libvtoc/libvtoc.a \ + $(rootdir)/libdasd/libdasd.a \ $(rootdir)/libu2s/libu2s.a \ $(rootdir)/libutil/libutil.a \ - $(rootdir)/libdasd/libdasd.a ifeq (${HAVE_FUSE},0)