From: Jan Pokorny japokorn@redhat.com
Only specified RPM file is now installed when specified by inst.dd and using NFS. Added a feature that enables to install all RPMs in directory when using NFS. (e.g. inst.dd=nfs://server/path/directory_with_rpms)
Resolves: rhbz#1269915 --- dracut/driver_updates.py | 8 ++--- dracut/fetch-driver-net.sh | 50 +++++++++++++++++++++++--- tests/dracut_tests/test_driver_updates.py | 2 +- utils/dd/dd_list.c | 58 ++++++++++++++++++++----------- 4 files changed, 87 insertions(+), 31 deletions(-)
diff --git a/dracut/driver_updates.py b/dracut/driver_updates.py index f5af220..b9110b3 100755 --- a/dracut/driver_updates.py +++ b/dracut/driver_updates.py @@ -358,7 +358,7 @@ def _process_driver_rpm(rpm): rpm for Anaconda to install on the target system. """ log.info("Examining %s", rpm) - new_modules = extract_drivers(repos=[os.path.dirname(rpm)]) + new_modules = extract_drivers(repos=[rpm]) if new_modules: modules = grab_driver_files() load_drivers(modules) @@ -605,10 +605,10 @@ def main(args):
if mode in ('--disk', '--net'): request, dev = args - if dev.endswith(".rpm"): - process_driver_rpm(dev) - else: + if dev.endswith(".iso"): process_driver_disk(dev) + else: + process_driver_rpm(dev)
elif mode == '--interactive': log.info("starting interactive mode") diff --git a/dracut/fetch-driver-net.sh b/dracut/fetch-driver-net.sh index 1632d00..38f75eb 100755 --- a/dracut/fetch-driver-net.sh +++ b/dracut/fetch-driver-net.sh @@ -14,11 +14,51 @@ while read dd; do # If we already fetched this URL, skip it grep -Fqx "$dd" /tmp/dd_net.done && continue # Otherwise try to fetch it - info "Fetching driverdisk from $dd" - if driver=$(fetch_url "$dd"); then - echo "$dd" >> /tmp/dd_net.done # mark it done so we don't fetch it again - driver-updates --net "$dd" "$driver" + + if [[ $dd == *.rpm ]] || [[ $dd == *.iso ]]; then + # Path in $dd leads to a file + info "Fetching driverdisk from $dd file" + + if driver=$(fetch_url "$dd"); then + echo "$dd" >> /tmp/dd_net.done # mark it done so we don't fetch it again + driver-updates --net "$dd" "$driver" + else + warn "Failed to fetch driver from $dd" + fi + else - warn "Failed to fetch driver from $dd" + # Path in $dd leads to a directory + + # Only nfs supports processing of the whole directories + if [[ $dd == nfs://* ]]; then + + info "Fetching RPM driverdisks from $dd directory" + + # Following variables are set by nfs_to_var: + local nfs="" server="" path="" options="" + nfs_to_var "$dd" + + # Obtain mount directory and mount it + # (new unique name is generated if not already mounted) + mntdir=$(nfs_already_mounted "$server" "$path") + if [ -z "$mntdir" ]; then + local mntdir="$(mkuniqdir /run nfs_mnt)" + mount_nfs "$nfs:$server:$path$(options:+:$options)" "$mntdir" + fi + + # Get and process all rpm files in the mounted directory + for rpm_file in $mntdir/*.rpm; do + # If no file is found bash still loops once + # Hence to prevent this: + if [[ ! -e "$rpm_file" ]]; then + warn "No RPM driverdisks found in $dd." + continue + fi + driver-updates --net "$dd" "$rpm_file" + done + echo "$dd" >> /tmp/dd_net.done # mark it done so we don't fetch it again + else + warn "Failed to fetch drivers from $dd. Processing of directories supported only by NFS." + fi fi done < /tmp/dd_net diff --git a/tests/dracut_tests/test_driver_updates.py b/tests/dracut_tests/test_driver_updates.py index 79d735b..f43ff44 100644 --- a/tests/dracut_tests/test_driver_updates.py +++ b/tests/dracut_tests/test_driver_updates.py @@ -507,7 +507,7 @@ def test_basic(self): """process_driver_rpm: extract RPM, grab + load driver""" rpm = '/tmp/fake/driver.rpm' process_driver_rpm(rpm) - self.mocks['extract_drivers'].assert_called_once_with(repos=["/tmp/fake"]) + self.mocks['extract_drivers'].assert_called_once_with(repos=["/tmp/fake/driver.rpm"]) self.mocks['grab_driver_files'].assert_called_once_with() self.mocks['load_drivers'].assert_called_once_with(self.modlist)
diff --git a/utils/dd/dd_list.c b/utils/dd/dd_list.c index 28ce8d5..cb30cfb 100644 --- a/utils/dd/dd_list.c +++ b/utils/dd/dd_list.c @@ -171,11 +171,16 @@ int main(int argc, char *argv[]) int option; int option_index;
- char *directory = NULL; + char *path = NULL; + int path_len; int verbose = 0;
struct _version_struct versions = {NULL, NULL};
+ char *globpattern; + glob_t globres; + char** globitem; + while ((option = getopt_long(argc, argv, shortopts, longopts, &option_index)) != -1) { switch (option) { case 0: @@ -183,7 +188,7 @@ int main(int argc, char *argv[]) break;
case 'd': - directory = strdup(optarg); + path = strdup(optarg); break;
case 'k': @@ -206,38 +211,49 @@ int main(int argc, char *argv[])
}
- if (!directory || !versions.kernel || !versions.anaconda) { + if (!path || !versions.kernel || !versions.anaconda) { show_help(); rc = 1; goto cleanup; }
- if (verbose) { - printf("Listing DD dir %s\n", directory); - } - init_rpm();
- char *globpattern; - checked_asprintf(&globpattern, "%s/*.rpm", directory); + path_len = strlen(path);
- glob_t globres; - char** globitem; + /* determine if the path is rpm filename or directory */ + if ((path_len > 5) && (strcmp(path + path_len - 4, ".rpm") == 0)) { + if (verbose) { + /* careful - standard output is being parsed */ + printf("Listing DD file %s\n", path); + } + + checkDDRPM(path, dlabelProvides, NULL, dlabelOK, &versions); + + } else { + if (verbose) { + /* careful - standard output is being parsed */ + printf("Listing DD dir %s\n", path); + }
- if (!glob(globpattern, GLOB_NOSORT|GLOB_NOESCAPE, globErrFunc, &globres)) { - /* iterate over all rpm files */ - globitem = globres.gl_pathv; - while (globres.gl_pathc>0 && globitem != NULL && *globitem != NULL) { - checkDDRPM(*globitem, dlabelProvides, NULL, dlabelOK, &versions); - globitem++; + /* look for all .rpm files in a given direcory */ + checked_asprintf(&globpattern, "%s/*.rpm", path); + + if (!glob(globpattern, GLOB_NOSORT|GLOB_NOESCAPE, globErrFunc, &globres)) { + /* iterate over all rpm files */ + globitem = globres.gl_pathv; + while (globres.gl_pathc>0 && globitem != NULL && *globitem != NULL) { + checkDDRPM(*globitem, dlabelProvides, NULL, dlabelOK, &versions); + globitem++; + } + globfree(&globres); + /* end of iteration */ } - globfree(&globres); - /* end of iteration */ + free(globpattern); } - free(globpattern);
cleanup: - free(directory); + free(path); free(versions.kernel); free(versions.anaconda);
anaconda-patches@lists.fedorahosted.org