Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(url-lib.sh): nfs_already_mounted() with trailing slash in nfs path #2182

Conversation

mmatsuya
Copy link
Contributor

@mmatsuya mmatsuya commented Feb 3, 2023

nfs_already_mounted() doesn't work when the installation ISO and kickstart file on a same NFS share are specified with inst.repo and inst.ks boot parameter as below.

inst.repo=nfs:192.168.1.1:/home/data/rhel9.iso inst.ks=nfs:192.168.1.1:/home/data/ks.cfg

NOTE: /home/data is configured for nfs share on 192.168.1.1

One problem is a file (not a directory) was passed into nfs_already_mounted(). nfs_already_mounted() is the function to judge if the given directory is already mounted. So, filepath should be passed in nfs_fetch_url().

The other problem is about the trailing slash in the nfs path in /proc/mounts.

The /proc/mounts has an entry after nfs mount of inst.repo.

192.168.1.1:/data/ /run/install/isodir nfs ro,relatime,

In this case, nfs_already_mounted() returns "/run/install/isodir//home/data/ks.cfg" wrongly. The following is from the log.

[ 14.556279] localhost.localdomain dracut-initqueue[1282]: ///lib/url-lib.sh@156(nfs_fetch_url): nfs_already_mounted 192.168.122.1 /home/data/ks.cfg
[ 14.556279] localhost.localdomain dracut-initqueue[1282]: ///lib/url-lib.sh@137(nfs_already_mounted): local server=192.168.122.1 path=/home/data/ks.cfg s= p=
...
[ 14.654966] localhost.localdomain dracut-initqueue[1282]: ///lib/url-lib.sh@140(nfs_already_mounted): '[' 192.168.122.1 = 192.168.122.1 ']'
[ 14.654966] localhost.localdomain dracut-initqueue[1282]: ///lib/url-lib.sh@141(nfs_already_mounted): '[' /home/data/ks.cfg = /home/data/ ']'
[ 14.654966] localhost.localdomain dracut-initqueue[1282]: ///lib/url-lib.sh@143(nfs_already_mounted): str_starts /home/data/ks.cfg /home/data/
[ 14.654966] localhost.localdomain dracut-initqueue[1282]: ///lib/dracut-lib.sh@51(str_starts): '[' ks.cfg '!=' /home/data/ks.cfg ']'
[ 14.654966] localhost.localdomain dracut-initqueue[1282]: ///lib/url-lib.sh@144(nfs_already_mounted): echo /run/install/isodir//home/data/ks.cfg
...
[ 14.658069] localhost.localdomain dracut-initqueue[934]: //lib/url-lib.sh@156(nfs_fetch_url): mntdir=/run/install/isodir//home/data/ks.cfg

This function doesn't expect the trailiing slash of the nfs path in /proc/mounts, so it should be removed before processing it.

This pull request changes...

Changes

Checklist

  • [x ] I have tested it locally
  • I have reviewed and updated any documentation if relevant
  • I am providing new code and test(s) for it

Fixes #

  • RHBZ#2166727

@github-actions github-actions bot added modules Issue tracker for all modules url-lib Issues related to the url-lib module labels Feb 3, 2023
@LaszloGombos LaszloGombos added the bug Our bugs label Feb 5, 2023
@LaszloGombos
Copy link
Collaborator

@mmatsuya Thank you !

Would you consider looking into triggering this bug with a test case ? We have quite extensible test already, perhaps you can just modify it/add a sub-test.

@github-actions github-actions bot added the test Issues related to testing label Feb 7, 2023
@mmatsuya mmatsuya force-pushed the dracut-nfs-already-mounted-trailing-slash branch 3 times, most recently from e38faa5 to c87feac Compare February 7, 2023 11:26
@LaszloGombos
Copy link
Collaborator

@mmatsuya Can you please check the commit message on your latest commit. Perhaps you saw it, but it is easy to miss..

commit_message:1:1: error: use of type tag that's neither 'feat', 'fix' nor whitelisted (build, chore, ci, docs, perf, refactor, revert, style, test, improvement)
trial: adding test for nfs_fetch_url into TEST-20-NFS

commit_message:1:43: error: commit message's subject contains Jira tickets
trial: adding test for nfs_fetch_url into TEST-20-NFS
                                          ^^^^^^^
                                          

@mmatsuya mmatsuya force-pushed the dracut-nfs-already-mounted-trailing-slash branch 2 times, most recently from f624999 to 4a6bee5 Compare February 7, 2023 14:44
@LaszloGombos
Copy link
Collaborator

@mmatsuya you can run the test locally with e.g. docker fairly easily - https://github.com/dracutdevs/dracut/wiki/Dracut-development#running-tests-with-docker

Also, the goal is to make sure that the code you changing gets executed by the test, it does not need to replicate your exact scenario.

@mmatsuya mmatsuya force-pushed the dracut-nfs-already-mounted-trailing-slash branch from fb67160 to d91d84d Compare February 8, 2023 03:18
@mmatsuya
Copy link
Contributor Author

mmatsuya commented Feb 8, 2023

Oh, sorry. I missed your comment. I will stop test it here.

@LaszloGombos
Copy link
Collaborator

Oh, sorry. I missed your comment. I will stop test it here.

Not a problem, just was not sure if this workflow is efficient for you. Use whatever tool makes most sense for you.

@mmatsuya
Copy link
Contributor Author

mmatsuya commented Feb 8, 2023

Also, the goal is to make sure that the code you changing gets executed by the test, it does not need to replicate your exact scenario.

Was it enough to run nfs_already_mounted() and check the result without replicating the problem?
Was it ok even if the test doesn't check the fix of this problem?
nfs_already_mounted() depends on the nfs mount entries in /proc/mounts, and the trailing slash of the nfs path is required to replicate the problem. So, I was trying to make the entry in /proc/mounts by mounting another share from client. if the above question is yes, the change for test case should be simpler:)

@mmatsuya mmatsuya force-pushed the dracut-nfs-already-mounted-trailing-slash branch from d91d84d to 128b3ec Compare February 8, 2023 07:08
nfs_already_mounted() doesn't work when the installation ISO and kickstart file on a same NFS share are specified with inst.repo and inst.ks boot parameter as below.

   inst.repo=nfs:192.168.1.1:/home/data/rhel9.iso inst.ks=nfs:192.168.1.1:/home/data/ks.cfg

   NOTE: /home/data is configured for nfs share on 192.168.1.1

One problem is a file (not a directory) was passed into nfs_already_mounted().
nfs_already_mounted() is the function to judge if the given directory is already mounted.
So, filepath should be passed in nfs_fetch_url().

The other problem is about the trailing slash in the nfs path in /proc/mounts.

The /proc/mounts has an entry after nfs mount of inst.repo.

   192.168.1.1:/data/   /run/install/isodir  nfs  ro,relatime,<snip>

In this case, nfs_already_mounted() returns "/run/install/isodir//home/data/ks.cfg" wrongly. The following is from the log.

[   14.556279] localhost.localdomain dracut-initqueue[1282]: ///lib/url-lib.sh@156(nfs_fetch_url): nfs_already_mounted 192.168.122.1 /home/data/ks.cfg
[   14.556279] localhost.localdomain dracut-initqueue[1282]: ///lib/url-lib.sh@137(nfs_already_mounted): local server=192.168.122.1 path=/home/data/ks.cfg s= p=
...
[   14.654966] localhost.localdomain dracut-initqueue[1282]: ///lib/url-lib.sh@140(nfs_already_mounted): '[' 192.168.122.1 = 192.168.122.1 ']'
[   14.654966] localhost.localdomain dracut-initqueue[1282]: ///lib/url-lib.sh@141(nfs_already_mounted): '[' /home/data/ks.cfg = /home/data/ ']'
[   14.654966] localhost.localdomain dracut-initqueue[1282]: ///lib/url-lib.sh@143(nfs_already_mounted): str_starts /home/data/ks.cfg /home/data/
[   14.654966] localhost.localdomain dracut-initqueue[1282]: ///lib/dracut-lib.sh@51(str_starts): '[' ks.cfg '!=' /home/data/ks.cfg ']'
[   14.654966] localhost.localdomain dracut-initqueue[1282]: ///lib/url-lib.sh@144(nfs_already_mounted): echo /run/install/isodir//home/data/ks.cfg
...
[   14.658069] localhost.localdomain dracut-initqueue[934]: //lib/url-lib.sh@156(nfs_fetch_url): mntdir=/run/install/isodir//home/data/ks.cfg

This function doesn't expect the trailiing slash of the nfs path in /proc/mounts, so it should be removed before processing it.
This is to check the behavior of nfs_fetch_url() in nfs-lib.sh.
nfs_fetch_url() calls nfs_already_mounted() internally.
A file /nfs/client/root/fetchfile is on NFS server, which is fetched
from clients for testing with nfs_fetch_url().
@mmatsuya mmatsuya force-pushed the dracut-nfs-already-mounted-trailing-slash branch from 6d697cd to 3cf092d Compare February 8, 2023 08:49
@mmatsuya
Copy link
Contributor Author

mmatsuya commented Feb 8, 2023

As a result, I added a test to check the behavior of nfs_fetch_url() into TEST-20-NFS. nfs_already_mounted() is called in it. I didn't make any additional nfs mounts, but I just used the existing mount for the nfs root. /nfs/client/root/fetchfile was located on the nfs server. And if a nfs client can fetch the file with nfs_already_mounted(), the result is written into marker2.img. And, the result in the marker2.img is checked in client_test().

Hopefully, this meets what you expected.

Copy link
Collaborator

@johannbg johannbg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Collaborator

@LaszloGombos LaszloGombos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks !

@LaszloGombos LaszloGombos merged commit 8f9ad06 into dracutdevs:master Feb 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Our bugs modules Issue tracker for all modules test Issues related to testing url-lib Issues related to the url-lib module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants