ziomon/ziorep_cfgreader: extract PCHID from .config file

Add an ability for ziorep_config tool to extract PCHID additional adapter
parameter from .config file. With this patch device_info structure will have
pchid field, which can be used by different printers classes. Also add
function for querying PCHID by using of devno for providing reports. Translate
"n/a" field from .config file record into invalid PCHID number.

Signed-off-by: Fedor Loshakov <loshakov@linux.ibm.com>
Reviewed-by: Sakshi Singh <005c7w@linux.ibm.com>
Reviewed-by: M Nikhil <nikh1092@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
This commit is contained in:
Fedor Loshakov
2024-12-09 14:50:35 +01:00
committed by Jan Höppner
parent 798bd752cf
commit f340a96fdf
4 changed files with 63 additions and 9 deletions

View File

@@ -3,7 +3,7 @@
*
* Utility classes to read and access FCP configuration information
*
* Copyright IBM Corp. 2008, 2017
* Copyright IBM Corp. 2008, 2024
*
* s390-tools is free software; you can redistribute it and/or modify
* it under the terms of the MIT license. See LICENSE for details.
@@ -32,6 +32,7 @@ ConfigReader::ConfigReader(int *rc, const char *filename)
FILE *fp = NULL;
struct device_info new_elem;
char *line = NULL;
char *cfg_pchid = NULL;
size_t line_len;
int lrc;
int line_idx = 1;
@@ -67,7 +68,8 @@ ConfigReader::ConfigReader(int *rc, const char *filename)
new_elem.device = (char*)malloc(lrc + 1);
new_elem.type = (char*)malloc(lrc + 1);
new_elem.multipath_device = (char*)malloc(lrc + 1);
lrc = sscanf(line, "%x %u:%u:%u:%u %x.%x.%x:%x.%x.%x:%Lx:%Lx %s %u %u:%u %s %u %u:%u %s",
cfg_pchid = (char*)malloc(lrc + 1);
lrc = sscanf(line, "%x %u:%u:%u:%u %x.%x.%x:%x.%x.%x:%Lx:%Lx %s %u %u:%u %s %u %u:%u %s %s",
&new_elem.chpid,
&new_elem.hctl_identifier.host,
&new_elem.hctl_identifier.channel,
@@ -82,10 +84,13 @@ ConfigReader::ConfigReader(int *rc, const char *filename)
&new_elem.mp_minor, new_elem.device,
&new_elem.mm_internal,
&new_elem.major, &new_elem.minor,
new_elem.type);
new_elem.type,
cfg_pchid);
*rc = parse_pchid_str(cfg_pchid, &new_elem.pchid);
free(cfg_pchid);
free(line);
line = NULL;
if (lrc != 22) {
if (lrc != 23 || *rc != 0) {
fprintf(stderr, "%s: Could not parse line %d"
" - configuration file broken?\n", toolname, line_idx);
*rc = -1;
@@ -465,6 +470,14 @@ __u32 ConfigReader::get_chpid_by_host_id(__u32 host, int *rc) const
return 0;
}
__u32 ConfigReader::get_pchid_by_host_id(__u32 host, int *rc) const
{
search_for(hctl_identifier.host, host, pchid);
host_id_not_found_error(host, rc);
return 0;
}
__u32 ConfigReader::get_chpid_by_devno(__u32 d, int *rc) const
{
@@ -861,7 +874,7 @@ void ConfigReader::dump(FILE *fp) const
fprintf(fp, "dumping cfg....\n");
for (list<struct device_info>::const_iterator i = m_devices.begin();
i != m_devices.end(); ++i) {
fprintf(fp, "%x %u %u:%u:%u:%u %x.%x.%04x:%x.%x.%04x:%016Lx:%016Lx %s %u:%u %s %u:%u %s\n",
fprintf(fp, "%x %u %u:%u:%u:%u %x.%x.%04x:%x.%x.%04x:%016Lx:%016Lx %s %u:%u %s %u:%u %s %x\n",
(*i).chpid, (*i).mm_internal,
(*i).hctl_identifier.host,
(*i).hctl_identifier.channel,
@@ -874,7 +887,8 @@ void ConfigReader::dump(FILE *fp) const
((*i).multipath_device ? (*i).multipath_device : "n/a"), (*i).mp_major,
(*i).mp_minor, (*i).device,
(*i).major, (*i).minor,
(*i).type);
(*i).type,
(*i).pchid);
}
}

View File

@@ -3,7 +3,7 @@
*
* Utility classes to read and access FCP configuration information
*
* Copyright IBM Corp. 2008, 2017
* Copyright IBM Corp. 2008, 2024
*
* s390-tools is free software; you can redistribute it and/or modify
* it under the terms of the MIT license. See LICENSE for details.
@@ -39,6 +39,8 @@ public:
/// rc is only set on error!
__u32 get_chpid_by_host_id(__u32 h, int *rc) const;
/// rc is only set on error!
__u32 get_pchid_by_host_id(__u32 h, int *rc) const;
/// rc is only set on error!
__u32 get_chpid_by_devno(__u32 devno, int *rc) const;
/// rc is only set on error!
__u32 get_chpid_by_ident(const struct hctl_ident *ident, int *rc) const;
@@ -153,6 +155,8 @@ private:
bool cached_config_exists(const char *fname);
struct device_info {
// pchid, e.g. 01c0
__u32 pchid;
// chpid, e.g. 43 (hex)
__u32 chpid;

View File

@@ -3,7 +3,7 @@
*
* Utility functions
*
* Copyright IBM Corp. 2008, 2017
* Copyright IBM Corp. 2008, 2024
*
* s390-tools is free software; you can redistribute it and/or modify
* it under the terms of the MIT license. See LICENSE for details.
@@ -552,6 +552,36 @@ FILE* open_csv_output_file(const char *filename, const char *extension,
return fp;
}
/**
* parse_pchid_str - parse PCHID from string to 32-bit number
* @pchid_str: PCHID string
* @pchid: 32-bit PCHID number
*
* Reads PCHID string, checks for corner cases, converts to 32-bit
* PCHID number, checks for errors, writes resulted PCHID to specified
* location.
*/
int parse_pchid_str(const char *const pchid_str, __u32 *const pchid)
{
unsigned long parsed;
char *end;
if (strcmp(pchid_str, "n/a") == 0) {
parsed = ZIOREP_PCHID_NA;
goto out;
}
parsed = strtoul(pchid_str, &end, 16);
if (parsed > 0xffff) {
fprintf(stderr, "%s: PCHID %s exceeds maximum possible value for a PCHID.\n",
toolname, pchid_str);
return -1;
} else if (parsed == 0 && end == &pchid_str[0]) {
fprintf(stderr, "%s: PCHID %s could not be converted.\n", toolname, pchid_str);
return -1;
}
out:
*pchid = (__u32)parsed;
return 0;
}

View File

@@ -3,7 +3,7 @@
*
* Utility functions
*
* Copyright IBM Corp. 2008, 2017
* Copyright IBM Corp. 2008, 2024
*
* s390-tools is free software; you can redistribute it and/or modify
* it under the terms of the MIT license. See LICENSE for details.
@@ -24,6 +24,8 @@ extern "C" {
#include <linux/types.h>
#define ZIOREP_PCHID_NA 65536
/**
* Parse date provided in 'str' and store as seconds since 1970 in 'tgt'. */
int get_datetime_val(const char *str, __u64 *tgt);
@@ -82,6 +84,10 @@ int parse_topline_arg(char *str, __u64 *arg);
FILE* open_csv_output_file(const char *filename, const char *extension,
int *rc);
/**
* Parse PCHID from string to 32-bit number
*/
int parse_pchid_str(const char *const pchid_str, __u32 *const pchid);
/**
* accessors for internal representation of device and subchannel bus-IDs