diff --git a/zdev/include/path.h b/zdev/include/path.h index 9d1adcbc..0ed263ca 100644 --- a/zdev/include/path.h +++ b/zdev/include/path.h @@ -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 *, diff --git a/zdev/include/udev.h b/zdev/include/udev.h index e37d7e3a..d8021739 100644 --- a/zdev/include/udev.h +++ b/zdev/include/udev.h @@ -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 */ diff --git a/zdev/src/path.c b/zdev/src/path.c index e1b496d7..e040adbe 100644 --- a/zdev/src/path.c +++ b/zdev/src/path.c @@ -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); -} diff --git a/zdev/src/udev.c b/zdev/src/udev.c index 988a2be7..fa0f26d8 100644 --- a/zdev/src/udev.c +++ b/zdev/src/udev.c @@ -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; diff --git a/zdev/src/udev_ccw.c b/zdev/src/udev_ccw.c index 2c40c05e..69d34467 100644 --- a/zdev/src/udev_ccw.c +++ b/zdev/src/udev_ccw.c @@ -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);