mirror of
https://github.com/ibm-s390-linux/s390-tools.git
synced 2026-08-05 02:14:52 +00:00
zdev: limit the derivation of ZDEV_SITE_ID
Currently ZDEV_SITE_ID is derived with the help of an additional udev-rule, 40-zdev-id.rules. The sole purpose of this rule is to determine the ZDEV_SITE_ID environment value with the help of zdev_id binary. This solution is minimal, but this has some unwanted side- effects. The zdev_id logic get executed for all the events, even those completely unrelated to zdev/or site, and imports the unneeded envionment values to the udev-db. Instead of having an additional rule file, add this logic as part of the udev-rule of those devices which are configured with site-support. The logic will then be available on all those rules with the site-supported devices only. Signed-off-by: Vineeth Vijayan <vneethv@linux.ibm.com> Reviewed-by: Peter Oberparleiter <oberpar@linux.ibm.com> Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
This commit is contained in:
committed by
Jan Höppner
parent
5637799c92
commit
07ff9e1da0
@@ -18,7 +18,6 @@
|
||||
#define MODPROBE_PREFIX "s390x"
|
||||
#define UDEV_PREFIX "41"
|
||||
#define UDEV_SUFFIX ".rules"
|
||||
#define ZDEV_PREFIX "40"
|
||||
|
||||
#define PATH_MODPROBE_CONF "/etc/modprobe.d"
|
||||
#define PATH_MODPROBE "/sbin/modprobe"
|
||||
@@ -66,7 +65,6 @@ char *path_get_zfcp_lun_dev(struct zfcp_lun_devid *);
|
||||
char *path_get_zfcp_port_dev(struct zfcp_lun_devid *);
|
||||
char *path_get_scsi_hctl_dev(const char *);
|
||||
char *path_get_bus_attr(const char *, const char *);
|
||||
char *path_get_zdev_rule(const char *name);
|
||||
|
||||
exit_code_t path_for_each(const char *,
|
||||
exit_code_t (*callback)(const char *, const char *,
|
||||
|
||||
@@ -34,7 +34,6 @@ void udev_add_internal_from_entry(struct setting_list *list,
|
||||
struct util_udev_entry_node *entry,
|
||||
struct attrib **attribs);
|
||||
|
||||
exit_code_t udev_write_site_rule(void);
|
||||
bool is_legacy_rule(struct util_udev_file *file);
|
||||
|
||||
#endif /* UDEV_H */
|
||||
|
||||
@@ -404,13 +404,3 @@ char *path_get_bus_attr(const char *bus, const char *attr)
|
||||
{
|
||||
return path_get("/sys/bus/%s/%s", bus, attr);
|
||||
}
|
||||
|
||||
/* Return path will be with ZDEV_PREFIX oon PATH_UDEV_RULES */
|
||||
char *path_get_zdev_rule(const char *name)
|
||||
{
|
||||
const char *path = PATH_UDEV_RULES;
|
||||
|
||||
/* Create file. */
|
||||
return path_get("%s/%s-%s%s", path,
|
||||
ZDEV_PREFIX, name, UDEV_SUFFIX);
|
||||
}
|
||||
|
||||
@@ -139,53 +139,6 @@ out:
|
||||
free(copy);
|
||||
}
|
||||
|
||||
/*
|
||||
* Write the UDEV rule that determines the active SITE_ID
|
||||
*/
|
||||
exit_code_t udev_write_site_rule(void)
|
||||
{
|
||||
char *path, *name = "zdev-id";
|
||||
exit_code_t rc = EXIT_OK;
|
||||
FILE *fd;
|
||||
|
||||
/* Create file. */
|
||||
path = path_get_zdev_rule(name);
|
||||
|
||||
if (!util_path_exists(path)) {
|
||||
rc = path_create(path);
|
||||
if (rc)
|
||||
goto out;
|
||||
}
|
||||
|
||||
fd = misc_fopen(path, "w");
|
||||
if (!fd) {
|
||||
error("Could not write to file %s: %s\n", path,
|
||||
strerror(errno));
|
||||
rc = EXIT_RUNTIME_ERROR;
|
||||
goto out;
|
||||
}
|
||||
fprintf(fd, "# Generated by chzdev\n");
|
||||
fprintf(fd, "\n");
|
||||
/* We have to make sure that we are not trying to determine the SITE_ID
|
||||
* for all the corresponding uevent. Check if the SITE_ID is already
|
||||
* determined by reading the file /run/zdev_site_id; and if it is not
|
||||
* available, execute the zdev_id program and determine the SITE_ID and
|
||||
* create the new zdev_site_id file for next run.
|
||||
*/
|
||||
fprintf(fd, "TEST!=\"%s\", IMPORT{program}="
|
||||
"\"%s/zdev_id\",GOTO=\"end\"\n", ZDEV_SITE_ID_FILE,
|
||||
TOOLS_LIBDIR);
|
||||
fprintf(fd, "IMPORT{file}=\"%s\"\n", ZDEV_SITE_ID_FILE);
|
||||
fprintf(fd, "LABEL=\"end\"\n");
|
||||
|
||||
if (misc_fclose(fd))
|
||||
warn("Could not close file %s: %s\n", path, strerror(errno));
|
||||
|
||||
out:
|
||||
free(path);
|
||||
return rc;
|
||||
}
|
||||
|
||||
bool is_legacy_rule(struct util_udev_file *file)
|
||||
{
|
||||
struct util_udev_line_node *line;
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include "setting.h"
|
||||
#include "udev.h"
|
||||
#include "udev_ccw.h"
|
||||
#include "zdev_id.h"
|
||||
|
||||
#define SITE_FALLBACK_SUFFIX "fb"
|
||||
|
||||
@@ -323,7 +324,7 @@ static exit_code_t udev_ccw_write_device_new(struct device *dev)
|
||||
char *path, *cfg_label = NULL, *end_label = NULL;
|
||||
exit_code_t rc = EXIT_OK;
|
||||
FILE *fd;
|
||||
int i, configured = 0;
|
||||
int i, configured = 0, site_configured = 0;
|
||||
|
||||
/*
|
||||
* Remove the previous file; The new udev rule will be created based on the
|
||||
@@ -340,6 +341,8 @@ static exit_code_t udev_ccw_write_device_new(struct device *dev)
|
||||
for (i = 0; i < NUM_SITES; i++) {
|
||||
configured += dev_site_configured(dev, i) ? 1 : 0;
|
||||
}
|
||||
site_configured = configured - (dev_site_configured(dev, SITE_FALLBACK) ?
|
||||
1 : 0);
|
||||
|
||||
/*
|
||||
* If there is no configuration settings available, do not create the new
|
||||
@@ -385,6 +388,20 @@ static exit_code_t udev_ccw_write_device_new(struct device *dev)
|
||||
fprintf(fd, "\n");
|
||||
|
||||
fprintf(fd, "LABEL=\"%s\"\n", cfg_label);
|
||||
|
||||
/*
|
||||
* Determine the ZDEV_SITE_ID here. If ZDEV_SITE_ID_FILE available,
|
||||
* simply import the content. If not, execute zdev_id and import the
|
||||
* output of the same.
|
||||
*/
|
||||
if (site_configured) {
|
||||
fprintf(fd, "# Determine ZDEV_SITE_ID to continue\n");
|
||||
fprintf(fd, "TEST==\"%s\",IMPORT{file}=\"%s\"\n",
|
||||
ZDEV_SITE_ID_FILE, ZDEV_SITE_ID_FILE);
|
||||
fprintf(fd, "TEST!=\"%s\",IMPORT{program}=\"%s/zdev_id\"\n\n",
|
||||
ZDEV_SITE_ID_FILE, TOOLS_LIBDIR);
|
||||
}
|
||||
|
||||
/* site comparison block */
|
||||
for (i = 0; i < NUM_USER_SITES; i++) {
|
||||
if (dev_site_configured(dev, i)) {
|
||||
@@ -393,6 +410,14 @@ static exit_code_t udev_ccw_write_device_new(struct device *dev)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* If no site configurations are available, then we need to make sure that
|
||||
* the udev-rule stays as compact as possible. We do not want to add any
|
||||
* extra labels on it.
|
||||
*/
|
||||
if (!site_configured)
|
||||
goto fallback;
|
||||
|
||||
/*
|
||||
* If we have a generic configuration available, then use that setting as a
|
||||
* fail-over incase of no site-id information in LOADPARM
|
||||
@@ -416,10 +441,12 @@ static exit_code_t udev_ccw_write_device_new(struct device *dev)
|
||||
fprintf(fd, "\n");
|
||||
}
|
||||
}
|
||||
|
||||
fallback:
|
||||
if (dev_site_configured(dev, SITE_FALLBACK)) {
|
||||
fprintf(fd, "# site_start_fb\n");
|
||||
fprintf(fd, "LABEL=\"%s_site_fb\"\n", cfg_label);
|
||||
|
||||
if (site_configured)
|
||||
fprintf(fd, "LABEL=\"%s_site_fb\"\n", cfg_label);
|
||||
write_attr_to_file(fd, &dev->site_specific[i], id);
|
||||
/* Write udev rule epilog. */
|
||||
fprintf(fd, "GOTO=\"%s\"\n", end_label);
|
||||
@@ -434,9 +461,6 @@ static exit_code_t udev_ccw_write_device_new(struct device *dev)
|
||||
if (misc_fclose(fd))
|
||||
warn("Could not close file %s: %s\n", path, strerror(errno));
|
||||
|
||||
rc = udev_write_site_rule();
|
||||
if (rc)
|
||||
goto out;
|
||||
out:
|
||||
free(end_label);
|
||||
free(cfg_label);
|
||||
|
||||
Reference in New Issue
Block a user