mirror of
https://github.com/ibm-s390-linux/s390-tools.git
synced 2026-08-05 02:14:52 +00:00
libdasd: Move get_host_access_count() to libdasd
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 <hoeppner@linux.ibm.com>
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -13,9 +13,9 @@
|
||||
#define LIB_DASD_SYS_H
|
||||
|
||||
#include <stdio.h>
|
||||
#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 */
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
42
libu2s/u2s.c
42
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;
|
||||
}
|
||||
|
||||
@@ -20,8 +20,8 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
#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,
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user