Bug 450646

Summary: /sbin/mount.nfs fails with read-only /etc
Product: Red Hat Enterprise Linux 5 Reporter: Istvan Marko <istvan+rhbugs>
Component: nfs-utilsAssignee: Steve Dickson <steved>
Status: CLOSED ERRATA QA Contact:
Severity: medium Docs Contact:
Priority: low    
Version: 5.2CC: bmr, cward, jscotka, ondrejv, pasteur, tao
Target Milestone: rc   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2009-09-02 10:03:19 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 457524    
Attachments:
Description Flags
Patch against mount.c which resolves the problem.
none
Patch for RO /etc/mtab none

Description Istvan Marko 2008-06-10 05:57:03 UTC
Description of problem:

/sbin/mount.nfs from nfs-utils-1.0.9-33 as shipped with RHEL 5.2
doesn't work with a read-only /etc (which you would find on nfsroot
or stateless installations).

It's the following patch that broke things:

Patch25: nfs-utils-1.0.10-mount-mtablock.patch
# 227985: /sbin/mount.nfs mtab lock

Before that patch the mtab mangling code ignored the failed
lock. That's obviously not the right behavior either but it allowed
for a working nfsroot/stateless installation.

The proper fix is to make mount.nfs check if /etc/mtab a symlink to
/proc/mounts (as it typically is on systems with a r/o /etc) and don't
try to lock or modify it if it is. /bin/mount already does this,
mount.nfs should match that behavior. Ditto for umount.nfs and
(u)mount.nfs4.

Version-Release number of selected component (if applicable):
nfs-utils-1.0.9-33

How reproducible:
always

Steps to Reproduce:
1. Bring up a system that has the filesystem containing /etc mounted read-only.
2. Try to mount an NFS volume:
   # mount filer:/path /mnt

Actual results:
can't create lock file /etc/mtab~19675: Read-only file system (use -n flag to override)

Expected results:
a mounted filesystem

Additional info:

Comment 1 Ondrej Valousek 2008-08-02 08:47:32 UTC
I can reproduce this as well. The problem is at line 541 of utils/mount/mount.c:
        if (!nomtab) {
                add_mtab(spec, mount_point, nfs_mount_vers == 4 ? "nfs4" : "nfs",
                         flags, extra_opts, 0, 0);
        }
It should probably read somehing like
        if (!nomtab && mtab_is_writable()) {
                add_mtab(spec, mount_point, nfs_mount_vers == 4 ? "nfs4" : "nfs",
                         flags, extra_opts, 0, 0);
        }


Comment 2 Ondrej Valousek 2008-10-08 08:51:10 UTC
Created attachment 319735 [details]
Patch against mount.c which resolves the problem.

Hi,
Please find the attached patch which resolves my problem.
I have verified it and it works OK.
Can this go into the mainstream?
Thanks.
Ondrej

Comment 3 Bryn M. Reeves 2008-10-22 11:54:31 UTC
The patch doesn't seem unreasonable to me, although I wonder if it's better to place the call to mtab_is_writable() inside add_mtab(), as this would be more in keeping with what is currently done for update_mtab() in support/nfs/fstab.c:

update_mtab (const char *dir, nfs_mntent_t *instead) {
        mntFILE *mfp, *mftmp;
        const char *fnam = MOUNTED;
        struct mntentchn mtabhead;      /* dummy */
        struct mntentchn *mc, *mc0, *absent = NULL;

        if (mtab_does_not_exist() || !mtab_is_writable())
                return;

I.e. make the check on the mtab file inside the routine that updates it, rather than in each caller of that function.

Comment 4 Ondrej Valousek 2008-10-22 13:03:49 UTC
Well yes, you are right. But if you want to do it this way I would do it cleanly in 2 steps:
1. remove the condition "if(!nomtab)" from mount.c so that add_mtab is called every time (even when -n option is passed)
2. add this:
        if (nomtab || !mtab_is_writable())
              return;
  in the add_mtab function.

This way it would look more like the update_mtab_entry() from mount.c in the util-linux package which is providing the /bin/mount command.

But essentially you are right - your solution would do as well.

Comment 5 Bryn M. Reeves 2008-10-22 13:10:10 UTC
Agreed - I think this would be the best approach. It keeps things consistent with other parts of the code & seems more logical/clean to me.

Comment 6 Shane Bradley 2008-11-07 18:39:40 UTC
Created attachment 322880 [details]
Patch for RO /etc/mtab

Comment 9 Steve Dickson 2009-04-29 17:31:46 UTC
Fixed in nfs-utils-1.0.9-42.el5

Comment 11 Chris Ward 2009-07-03 18:03:34 UTC
~~ Attention - RHEL 5.4 Beta Released! ~~

RHEL 5.4 Beta has been released! There should be a fix present in the Beta release that addresses this particular request. Please test and report back results here, at your earliest convenience. RHEL 5.4 General Availability release is just around the corner!

If you encounter any issues while testing Beta, please describe the issues you have encountered and set the bug into NEED_INFO. If you encounter new issues, please clone this bug to open a new issue and request it be reviewed for inclusion in RHEL 5.4 or a later update, if it is not of urgent severity.

Please do not flip the bug status to VERIFIED. Only post your verification results, and if available, update Verified field with the appropriate value.

Questions can be posted to this bug or your customer or partner representative.

Comment 12 Ondrej Valousek 2009-07-08 09:09:46 UTC
I can confirm that nfs-utils-1.0.9-42 package shipped in RHEL 5.4 Beta fixes this issue (tested with both nfs and nfs4).

Comment 15 errata-xmlrpc 2009-09-02 10:03:19 UTC
An advisory has been issued which should help the problem
described in this bug report. This report is therefore being
closed with a resolution of ERRATA. For more information
on therefore solution and/or where to find the updated files,
please follow the link below. You may reopen this bug report
if the solution does not work for you.

http://rhn.redhat.com/errata/RHSA-2009-1321.html