File s390-tools-sles15sp1-02-zdev-Prepare-for-firmware-configuration-file-support.patch of Package s390-tools.14411

Subject: zdev: Prepare for firmware configuration file support
From: Peter Oberparleiter <oberpar@linux.ibm.com>

Summary:     zdev: Add support for handling I/O configuration data
Description: LPARs that are running in IBM Dynamic Partition Manager (DPM) mode
             can access a firmware-generated I/O configuration data file that
             contains s390-specific information about available I/O devices
             such as qeth device numbers and parameters, and FCP device IDs.

             This data file is intended to remove the need for users to
             manually enter the corresponding device data during installation.

             Linux kernels with the corresponding support make the I/O
             configuration data available at the following location:

               /sys/firmware/sclp_sd/config/data

             This patch set adds support for handling this data file using the
             chzdev and lszdev tools:

               - I/O configuration data can be applied using chzdev's --import
                 option
               - Initial RAM-Disk scripts automatically apply the
                 I/O configuration data to the system configuration
               - lszdev can be used to display the applied auto-configuration
                 data
               - chzdev can be used to manually override the
                 auto-configuration data

Upstream-ID: ab4445c261749caa7aee2154e3b26c767b6c5e60
Problem-ID:  LS1604

Upstream-Description:

             zdev: Prepare for firmware configuration file support

             Apply some changes to existing functions and data structures to simplify
             the firmware configuration file support implementation.

              - Make qeth and dasd subtype objects non-static
              - Change the existing helper functions for reading file contents into
                memory to also support binary functions
              - Move some configuration file import functions to make them available
                for use in other source files

             Signed-off-by: Peter Oberparleiter <oberpar@linux.vnet.ibm.com>
             Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>


Signed-off-by: Peter Oberparleiter <oberpar@linux.ibm.com>
---
 zdev/include/dasd.h   |    3 ++
 zdev/include/device.h |    2 +
 zdev/include/export.h |    1 
 zdev/include/misc.h   |    1 
 zdev/include/qeth.h   |    2 +
 zdev/src/dasd.c       |    4 +--
 zdev/src/device.c     |   13 +++++++++++
 zdev/src/export.c     |   17 +-------------
 zdev/src/misc.c       |   48 ++++++++++++++++++++++++++++++------------
 zdev/src/qeth.c       |    2 -
 10 files changed, 62 insertions(+), 31 deletions(-)

--- a/zdev/include/dasd.h
+++ b/zdev/include/dasd.h
@@ -11,7 +11,10 @@
 #define DASD_H
 
 struct devtype;
+struct subtype;
 
 extern struct devtype dasd_devtype;
+extern struct subtype dasd_subtype_eckd;
+extern struct subtype dasd_subtype_fba;
 
 #endif /* DASD_H */
--- a/zdev/include/device.h
+++ b/zdev/include/device.h
@@ -94,5 +94,7 @@ void device_list_add(struct device_list
 struct device *device_list_find(struct device_list *, const char *,
 				struct device *);
 void device_list_print(struct device_list *, int);
+struct setting_list *device_get_setting_list(struct device *dev,
+					     config_t config);
 
 #endif /* DEVICE_H */
--- a/zdev/include/export.h
+++ b/zdev/include/export.h
@@ -31,6 +31,7 @@ struct export_object {
 	} ptr;
 };
 
+struct export_object *object_new(export_t type, void *ptr);
 exit_code_t export_write_device(FILE *, struct device *, config_t, int *);
 exit_code_t export_write_devtype(FILE *, struct devtype *, config_t, int *);
 exit_code_t export_read(FILE *, const char *, struct util_list *);
--- a/zdev/include/misc.h
+++ b/zdev/include/misc.h
@@ -159,6 +159,7 @@ bool misc_read_dir(const char *, struct
 		       bool (*)(const char *, void *), void *);
 bool file_is_devnode(const char *);
 exit_code_t remove_file(const char *);
+exit_code_t misc_read_fd(FILE *fd, void **buffer, size_t *size_ptr);
 char *misc_read_text_file(const char *, int, err_t);
 char *misc_read_cmd_output(const char *, int, err_t);
 char *config_read_cmd_output(const char *, int, err_t);
--- a/zdev/include/qeth.h
+++ b/zdev/include/qeth.h
@@ -17,9 +17,11 @@
 #define	QETH_NUM_DEVS		3
 
 struct devtype;
+struct subtype;
 struct namespace;
 
 extern struct devtype qeth_devtype;
+extern struct subtype qeth_subtype_qeth;
 extern struct namespace qeth_namespace;
 
 #endif /* QETH_H */
--- a/zdev/src/dasd.c
+++ b/zdev/src/dasd.c
@@ -589,7 +589,7 @@ static struct ccw_subtype_data dasd_eckd
 	.mod		= "dasd_eckd_mod",
 };
 
-static struct subtype dasd_subtype_eckd = {
+struct subtype dasd_subtype_eckd = {
 	.super		= &ccw_subtype,
 	.devtype	= &dasd_devtype,
 	.name		= "dasd-eckd",
@@ -626,7 +626,7 @@ static struct ccw_subtype_data dasd_fba_
 	.mod		= "dasd_fba_mod",
 };
 
-static struct subtype dasd_subtype_fba = {
+struct subtype dasd_subtype_fba = {
 	.super		= &ccw_subtype,
 	.devtype	= &dasd_devtype,
 	.name		= "dasd-fba",
--- a/zdev/src/device.c
+++ b/zdev/src/device.c
@@ -570,3 +570,16 @@ exit_code_t device_check_settings(struct
 
 	return EXIT_OK;
 }
+
+struct setting_list *device_get_setting_list(struct device *dev,
+					     config_t config)
+{
+	struct setting_list *settings = NULL;
+
+	if (config == config_active)
+		settings = dev->active.settings;
+	else
+		settings = dev->persistent.settings;
+
+	return settings;
+}
--- a/zdev/src/export.c
+++ b/zdev/src/export.c
@@ -282,19 +282,6 @@ static bool parse_setting(const char *li
 	return true;
 }
 
-static struct setting_list *dev_get_setting_list(struct device *dev,
-						 config_t config)
-{
-	struct setting_list *settings = NULL;
-
-	if (config == config_active)
-		settings = dev->active.settings;
-	else
-		settings = dev->persistent.settings;
-
-	return settings;
-}
-
 static struct setting_list *dt_get_setting_list(struct devtype *dt,
 						config_t config)
 {
@@ -426,7 +413,7 @@ static exit_code_t handle_setting(const
 	} else if (dev) {
 		/* We're inside a device section. */
 		attribs = dev->subtype->dev_attribs;
-		list = dev_get_setting_list(dev, config);
+		list = device_get_setting_list(dev, config);
 	} else
 		return EXIT_OK;
 
@@ -444,7 +431,7 @@ static exit_code_t handle_setting(const
 	return EXIT_OK;
 }
 
-static struct export_object *object_new(export_t type, void *ptr)
+struct export_object *object_new(export_t type, void *ptr)
 {
 	struct export_object *obj;
 
--- a/zdev/src/misc.c
+++ b/zdev/src/misc.c
@@ -98,26 +98,47 @@ static void dryrun_end_data(void)
 
 #define READ_CHUNK_SIZE		4096
 
-/* Read text from @fd and return resulting NULL-terminated text buffer.
- * If @chomp is non-zero, remove trailing newline character. Return %NULL
- * on error or when unprintable characters are read. */
-static char *read_fd(FILE *fd, int chomp)
+/* Read all data from @fd and return address of resulting buffer in
+ * @buffer_ptr. If @size_ptr is non-zero, use it to store the size of the
+ * resulting buffer. Return %EXIT_OK on success. */
+exit_code_t misc_read_fd(FILE *fd, void **buffer_ptr, size_t *size_ptr)
 {
 	char *buffer = NULL;
-	size_t done, i;
+	size_t done = 0;
 
-	done = 0;
 	while (!feof(fd)) {
-		buffer = realloc(buffer, done + READ_CHUNK_SIZE + 1);
+		buffer = realloc(buffer, done + READ_CHUNK_SIZE);
 		if (!buffer)
 			oom();
 		done += fread(&buffer[done], 1, READ_CHUNK_SIZE, fd);
 		if (ferror(fd)) {
 			free(buffer);
-			return NULL;
+			return EXIT_RUNTIME_ERROR;
 		}
 	}
 
+	buffer = realloc(buffer, done);
+	if (!buffer && done > 0)
+		oom();
+
+	*buffer_ptr = buffer;
+	if (size_ptr)
+		*size_ptr = done;
+
+	return EXIT_OK;
+}
+
+/* Read text from @fd and return resulting NULL-terminated text buffer.
+ * If @chomp is non-zero, remove trailing newline character. Return %NULL
+ * on error or when unprintable characters are read. */
+static char *read_fd(FILE *fd, int chomp)
+{
+	char *buffer;
+	size_t done, i;
+
+	if (misc_read_fd(fd, (void **) &buffer, &done))
+		return NULL;
+
 	/* Check if this is a text file at all (required to filter out
 	 * binary sysfs attributes). */
 	for (i = 0; i < done; i++) {
@@ -131,12 +152,13 @@ static char *read_fd(FILE *fd, int chomp
 	if (chomp && done > 0 && buffer[done - 1] == '\n')
 		done--;
 
-	if (buffer) {
-		/* NULL-terminate. */
-		buffer[done++] = 0;
-	}
+	/* NULL-terminate. */
+	buffer = realloc(buffer, done + 1);
+	if (!buffer)
+		oom();
+	buffer[done] = 0;
 
-	return realloc(buffer, done);
+	return buffer;
 }
 
 static int count_newline(const char *str)
--- a/zdev/src/qeth.c
+++ b/zdev/src/qeth.c
@@ -1369,7 +1369,7 @@ static struct ccwgroup_subtype_data qeth
 	.num_devs	= QETH_NUM_DEVS,
 };
 
-static struct subtype qeth_subtype_qeth = {
+struct subtype qeth_subtype_qeth = {
 	.super		= &ccwgroup_subtype,
 	.devtype	= &qeth_devtype,
 	.name		= "qeth",
openSUSE Build Service is sponsored by