mount.nfs: mtab corruption when RLIMIT_FSIZE causes a partial write
Subsystems (2)
PATCH 1/1 mount.nfs: mtab corruption when RLIMIT_FSIZE causes a partial write
This patch is a following on to commit 7a802337. Using the tool in https://bugzilla.redhat.com/show_bug.cgi?id=695916
caused the fflush() and fclose() to fail in turn causing corruption in the mtab.
The failures were in the internals of both calls. Switch those calls with the actual system calls eliminated the failures.
--- support/nfs/nfs_mntent.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
support/nfs/nfs_mntent.c +2 -2
@@ -117,7 +117,7 @@ void nfs_endmntent (mntFILE *mfp) {if (mfp) {if (mfp->mntent_fp) -fclose (mfp->mntent_fp); +close (fileno (mfp->mntent_fp));if (mfp->mntent_file)free (mfp->mntent_file);free (mfp);
@@ -147,7 +147,7 @@ nfs_addmntent (mntFILE *mfp, struct mntent *mnt) {free (m3);free (m4);if (res >=0 ) { - res =fflush (mfp->mntent_fp); + res =fsync (fileno (mfp->mntent_fp));if (res <0 )/* Avoid leaving a corrupt mtab file */ ftruncate (fileno (mfp->mntent_fp), length);
Signature · 1 line
1.7.6.2
Quoted 27 lines · On Wed, 19 Oct 2011 11:34:30 -0400 Steve Dickson <[email protected]> wrote:
This patch is a following on to commit
7a802337. Using the tool in https://bugzilla.redhat.com/show_bug.cgi?id=695916
caused thefflush()andfclose()to fail in turn causing corruption in the mtab.The failures were in the internals of both calls. Switch those calls with the actual system calls eliminated the failures.
Signed-off-by Steve Dickson <[email protected]>--- support/nfs/nfs_mntent.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)support/nfs/nfs_mntent.c +1
-1@@ -117,7 +117,7 @@ void nfs_endmntent (mntFILE *mfp) {if (mfp) {if (mfp->mntent_fp) -fclose (mfp->mntent_fp); +close (fileno (mfp->mntent_fp));if (mfp->mntent_file)free (mfp->mntent_file);free (mfp);
support/nfs/nfs_mntent.c nfs_addmntent (mntFILE *mfp, struct mntent *mnt) { · line 150
Quoted 5 lines
support/nfs/nfs_mntent.c +1
-1@@ -147,7 +147,7 @@ nfs_addmntent (mntFILE *mfp, struct mntent *mnt) {free (m3);free (m4);if (res >=0 ) { - res =fflush (mfp->mntent_fp); + res =fsync (fileno (mfp->mntent_fp));
fsync doesn't imply an fflush. With this, I think you may end up without everything being committed to disk if part or all of it is still in the file stream buffer. You probably want to do an fflush() and then an fsync here.
Quoted 3 lines
support/nfs/nfs_mntent.c +0
-0if (res <0 )/* Avoid leaving a corrupt mtab file */ ftruncate (fileno (mfp->mntent_fp), length);
Signature · 1 line
Jeff Layton <[email protected]>
Quoted 32 lines · Jeff Layton
Quoted 29 lines · On Wed, 19 Oct 2011 11:34:30 -0400 Steve Dickson <[email protected]> wrote:
This patch is a following on to commit
7a802337. Using the tool in https://bugzilla.redhat.com/show_bug.cgi?id=695916
caused thefflush()andfclose()to fail in turn causing corruption in the mtab.The failures were in the internals of both calls. Switch those calls with the actual system calls eliminated the failures.
Signed-off-by Steve Dickson <[email protected]>--- support/nfs/nfs_mntent.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)support/nfs/nfs_mntent.c +1
-1@@ -117,7 +117,7 @@ void nfs_endmntent (mntFILE *mfp) {if (mfp) {if (mfp->mntent_fp) -fclose (mfp->mntent_fp); +close (fileno (mfp->mntent_fp));if (mfp->mntent_file)free (mfp->mntent_file);free (mfp);@@ -147,7 +147,7 @@ nfs_addmntent (mntFILE *mfp, struct mntent *mnt) {free (m3);free (m4);
Quoted 8 lines
support/nfs/nfs_mntent.c nfs_addmntent (mntFILE *mfp, struct mntent *mnt) { · line 150
Quoted 3 lines
support/nfs/nfs_mntent.c +1
-1if (res >=0 ) { - res =fflush (mfp->mntent_fp); + res =fsync (fileno (mfp->mntent_fp));fsync doesn't imply an fflush. With this, I think you may end up without everything being committed to disk if part or all of it is still in the file stream buffer. You probably want to do an
fflush()and then an fsync here.
The problem was with the fflush() call. The call was causing the mount to drop core in turn causing mtab corruption. Changing that call to a fsync() worked just fine... no corruption... every time!
steved.
Quoted 6 lines
Quoted 4 lines
support/nfs/nfs_mntent.c +0
-0if (res <0 )/* Avoid leaving a corrupt mtab file */ ftruncate (fileno (mfp->mntent_fp), length);
Quoted 43 lines · On Wed, 19 Oct 2011 13:10:19 -0400 Steve Dickson <[email protected]> wrote:
Quoted 32 lines · Jeff Layton
Quoted 29 lines · On Wed, 19 Oct 2011 11:34:30 -0400 Steve Dickson <[email protected]> wrote:
This patch is a following on to commit
7a802337. Using the tool in https://bugzilla.redhat.com/show_bug.cgi?id=695916
caused thefflush()andfclose()to fail in turn causing corruption in the mtab.The failures were in the internals of both calls. Switch those calls with the actual system calls eliminated the failures.
Signed-off-by Steve Dickson <[email protected]>--- support/nfs/nfs_mntent.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)support/nfs/nfs_mntent.c +1
-1@@ -117,7 +117,7 @@ void nfs_endmntent (mntFILE *mfp) {if (mfp) {if (mfp->mntent_fp) -fclose (mfp->mntent_fp); +close (fileno (mfp->mntent_fp));if (mfp->mntent_file)free (mfp->mntent_file);free (mfp);@@ -147,7 +147,7 @@ nfs_addmntent (mntFILE *mfp, struct mntent *mnt) {free (m3);free (m4);Quoted 8 lines
support/nfs/nfs_mntent.c nfs_addmntent (mntFILE *mfp, struct mntent *mnt) { · line 150
Quoted 3 lines
support/nfs/nfs_mntent.c +1
-1if (res >=0 ) { - res =fflush (mfp->mntent_fp); + res =fsync (fileno (mfp->mntent_fp));fsync doesn't imply an fflush. With this, I think you may end up without everything being committed to disk if part or all of it is still in the file stream buffer. You probably want to do an
fflush()and then an fsync here.
Quoted 4 lines
The problem was with the
fflush()call. The call was causing the mount to drop core in turn causing mtab corruption. Changing that call to afsync()worked just fine... no corruption... every time!
Ahh, then you have another problem here too then. Most likely it was crashing because it caught a SIGXFSZ. Writing out the mtab should not be affected by signals.
In the mount.cifs helper, I have it do the following before altering the mtab (with appropriate error handling):
rc = setreuid(geteuid(), -1);
rc = sigfillset(&mask);
rc = sigprocmask(SIG_SETMASK, &mask, &oldmask);IOW, set the real uid to the effective UID to ensure that an unprivileged user can't signal the process if it was run as a setuid root program and the real UID isn't root. It then masks off all signals. That leaves SIGKILL by root as a way to interrupt it but there's really nothing you can do about that.
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
support/nfs/nfs_mntent.c +0
-0if (res <0 )/* Avoid leaving a corrupt mtab file */ ftruncate (fileno (mfp->mntent_fp), length);
Signature · 1 line
Jeff Layton <[email protected]>
Quoted 43 lines · Steve Dickson
Quoted 32 lines · Jeff Layton
Quoted 29 lines · On Wed, 19 Oct 2011 11:34:30 -0400 Steve Dickson <[email protected]> wrote:
This patch is a following on to commit
7a802337. Using the tool in https://bugzilla.redhat.com/show_bug.cgi?id=695916
caused thefflush()andfclose()to fail in turn causing corruption in the mtab.The failures were in the internals of both calls. Switch those calls with the actual system calls eliminated the failures.
Signed-off-by Steve Dickson <[email protected]>--- support/nfs/nfs_mntent.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)support/nfs/nfs_mntent.c +1
-1@@ -117,7 +117,7 @@ void nfs_endmntent (mntFILE *mfp) {if (mfp) {if (mfp->mntent_fp) -fclose (mfp->mntent_fp); +close (fileno (mfp->mntent_fp));if (mfp->mntent_file)free (mfp->mntent_file);free (mfp);@@ -147,7 +147,7 @@ nfs_addmntent (mntFILE *mfp, struct mntent *mnt) {free (m3);free (m4);Quoted 8 lines
support/nfs/nfs_mntent.c nfs_addmntent (mntFILE *mfp, struct mntent *mnt) { · line 150
Quoted 3 lines
support/nfs/nfs_mntent.c +1
-1if (res >=0 ) { - res =fflush (mfp->mntent_fp); + res =fsync (fileno (mfp->mntent_fp));fsync doesn't imply an fflush. With this, I think you may end up without everything being committed to disk if part or all of it is still in the file stream buffer. You probably want to do an
fflush()and then an fsync here.
Quoted 3 lines
The problem was with the
fflush()call. The call was causing the mount to drop core in turn causing mtab corruption. Changing that call to afsync()worked just fine... no corruption... every time!
Looking at man setrlimit.... If you're worried about RLIMIT_FSIZE, then I guess you need to handle SIGXFSZ and EFBIG returns from write().
It looks like lock_mtab() already sets SIGXFSZ to be ignored. Is a libc bug crashing fflush on EFBIG? Or maybe the ftruncate is a problem? Maybe you just want to do away with stream IO completely?
--b.
Quoted 13 lines
steved.
Quoted 6 lines
support/nfs/nfs_mntent.c nfs_addmntent (mntFILE *mfp, struct mntent *mnt) { · line 153
Quoted 4 lines
support/nfs/nfs_mntent.c +0
-0if (res <0 )/* Avoid leaving a corrupt mtab file */ ftruncate (fileno (mfp->mntent_fp), length);--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 46 lines · Jeff Layton
Quoted 43 lines · On Wed, 19 Oct 2011 13:10:19 -0400 Steve Dickson <[email protected]> wrote:
Quoted 40 lines · Jeff Layton
Quoted 27 lines · On Wed, 19 Oct 2011 11:34:30 -0400 Steve Dickson <[email protected]> wrote:
This patch is a following on to commit
7a802337. Using the tool in https://bugzilla.redhat.com/show_bug.cgi?id=695916
caused thefflush()andfclose()to fail in turn causing corruption in the mtab.The failures were in the internals of both calls. Switch those calls with the actual system calls eliminated the failures.
Signed-off-by Steve Dickson <[email protected]>--- support/nfs/nfs_mntent.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)support/nfs/nfs_mntent.c +1
-1@@ -117,7 +117,7 @@ void nfs_endmntent (mntFILE *mfp) {if (mfp) {if (mfp->mntent_fp) -fclose (mfp->mntent_fp); +close (fileno (mfp->mntent_fp));if (mfp->mntent_file)free (mfp->mntent_file);free (mfp);support/nfs/nfs_mntent.c nfs_addmntent (mntFILE *mfp, struct mntent *mnt) { · line 150
Quoted 5 lines
support/nfs/nfs_mntent.c +1
-1@@ -147,7 +147,7 @@ nfs_addmntent (mntFILE *mfp, struct mntent *mnt) {free (m3);free (m4);if (res >=0 ) { - res =fflush (mfp->mntent_fp); + res =fsync (fileno (mfp->mntent_fp));fsync doesn't imply an fflush. With this, I think you may end up without everything being committed to disk if part or all of it is still in the file stream buffer. You probably want to do an
fflush()and then an fsync here.
Quoted 8 lines
Quoted 4 lines
The problem was with the
fflush()call. The call was causing the mount to drop core in turn causing mtab corruption. Changing that call to afsync()worked just fine... no corruption... every time!Ahh, then you have another problem here too then. Most likely it was crashing because it caught a SIGXFSZ. Writing out the mtab should not be affected by signals.
So calling fflush() generates a SIGXFSZ and call fsync() does not... I really don't see what the problem is is call simply calling fsync() which clearly works?
steved.
Quoted 24 lines
In the mount.cifs helper, I have it do the following before altering the mtab (with appropriate error handling):
rc = setreuid(geteuid(), -1); rc = sigfillset(&mask); rc = sigprocmask(SIG_SETMASK, &mask, &oldmask);IOW, set the real uid to the effective UID to ensure that an unprivileged user can't signal the process if it was run as a setuid root program and the real UID isn't root. It then masks off all signals. That leaves SIGKILL by root as a way to interrupt it but there's really nothing you can do about that.
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
support/nfs/nfs_mntent.c +0
-0if (res <0 )/* Avoid leaving a corrupt mtab file */ ftruncate (fileno (mfp->mntent_fp), length);
Quoted 48 lines · J. Bruce Fields
Quoted 43 lines · Steve Dickson
Quoted 32 lines · Jeff Layton
Quoted 29 lines · On Wed, 19 Oct 2011 11:34:30 -0400 Steve Dickson <[email protected]> wrote:
This patch is a following on to commit
7a802337. Using the tool in https://bugzilla.redhat.com/show_bug.cgi?id=695916
caused thefflush()andfclose()to fail in turn causing corruption in the mtab.The failures were in the internals of both calls. Switch those calls with the actual system calls eliminated the failures.
Signed-off-by Steve Dickson <[email protected]>--- support/nfs/nfs_mntent.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)support/nfs/nfs_mntent.c +1
-1@@ -117,7 +117,7 @@ void nfs_endmntent (mntFILE *mfp) {if (mfp) {if (mfp->mntent_fp) -fclose (mfp->mntent_fp); +close (fileno (mfp->mntent_fp));if (mfp->mntent_file)free (mfp->mntent_file);free (mfp);@@ -147,7 +147,7 @@ nfs_addmntent (mntFILE *mfp, struct mntent *mnt) {free (m3);free (m4);Quoted 8 lines
support/nfs/nfs_mntent.c nfs_addmntent (mntFILE *mfp, struct mntent *mnt) { · line 150
Quoted 3 lines
support/nfs/nfs_mntent.c +1
-1if (res >=0 ) { - res =fflush (mfp->mntent_fp); + res =fsync (fileno (mfp->mntent_fp));fsync doesn't imply an fflush. With this, I think you may end up without everything being committed to disk if part or all of it is still in the file stream buffer. You probably want to do an
fflush()and then an fsync here.Quoted 3 lines
The problem was with the
fflush()call. The call was causing the mount to drop core in turn causing mtab corruption. Changing that call to afsync()worked just fine... no corruption... every time!
Quoted 6 lines
Looking at man setrlimit.... If you're worried about
RLIMIT_FSIZE, then I guess you need to handle SIGXFSZ and EFBIG returns fromwrite().It looks like
lock_mtab()already sets SIGXFSZ to be ignored. Is a libc bug crashing fflush on EFBIG? Or maybe the ftruncate is a problem? Maybe you just want to do away with stream IO completely?
Calling fsync() clearly works. So why are looking for alternative solutions??
steved.
Quoted 54 lines · Steve Dickson
Quoted 51 lines · Jeff Layton
Quoted 47 lines · On Wed, 19 Oct 2011 13:10:19 -0400 Steve Dickson <[email protected]> wrote:
Quoted 32 lines · Jeff Layton
Quoted 29 lines · On Wed, 19 Oct 2011 11:34:30 -0400 Steve Dickson <[email protected]> wrote:
This patch is a following on to commit
7a802337. Using the tool in https://bugzilla.redhat.com/show_bug.cgi?id=695916
caused thefflush()andfclose()to fail in turn causing corruption in the mtab.The failures were in the internals of both calls. Switch those calls with the actual system calls eliminated the failures.
Signed-off-by Steve Dickson <[email protected]>--- support/nfs/nfs_mntent.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)support/nfs/nfs_mntent.c +1
-1@@ -117,7 +117,7 @@ void nfs_endmntent (mntFILE *mfp) {if (mfp) {if (mfp->mntent_fp) -fclose (mfp->mntent_fp); +close (fileno (mfp->mntent_fp));if (mfp->mntent_file)free (mfp->mntent_file);free (mfp);@@ -147,7 +147,7 @@ nfs_addmntent (mntFILE *mfp, struct mntent *mnt) {free (m3);free (m4);Quoted 8 lines
support/nfs/nfs_mntent.c nfs_addmntent (mntFILE *mfp, struct mntent *mnt) { · line 150
Quoted 3 lines
support/nfs/nfs_mntent.c +1
-1if (res >=0 ) { - res =fflush (mfp->mntent_fp); + res =fsync (fileno (mfp->mntent_fp));fsync doesn't imply an fflush. With this, I think you may end up without everything being committed to disk if part or all of it is still in the file stream buffer. You probably want to do an
fflush()and then an fsync here.The problem was with the
fflush()call. The call was causing the mount to drop core in turn causing mtab corruption. Changing that call to afsync()worked just fine... no corruption... every time!
Quoted 4 lines
Quoted 3 lines
Ahh, then you have another problem here too then. Most likely it was crashing because it caught a SIGXFSZ. Writing out the mtab should not be affected by signals.
So calling
fflush()generates a SIGXFSZ and callfsync()does not...
fflush() must hit this because it's calling write() to write out the stream buffer....
But lock_mtab() should have set SIGXFSZ to be ignored; is that not happening?
Quoted 2 lines
I really don't see what the problem is is call simply calling
fsync()which clearly works?
We want to make sure the problem's really fixed.
--b.
Quoted 51 lines · Steve Dickson
Quoted 48 lines · J. Bruce Fields
Quoted 46 lines · Steve Dickson
Quoted 32 lines · Jeff Layton
Quoted 29 lines · On Wed, 19 Oct 2011 11:34:30 -0400 Steve Dickson <[email protected]> wrote:
This patch is a following on to commit
7a802337. Using the tool in https://bugzilla.redhat.com/show_bug.cgi?id=695916
caused thefflush()andfclose()to fail in turn causing corruption in the mtab.The failures were in the internals of both calls. Switch those calls with the actual system calls eliminated the failures.
Signed-off-by Steve Dickson <[email protected]>--- support/nfs/nfs_mntent.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)support/nfs/nfs_mntent.c +1
-1@@ -117,7 +117,7 @@ void nfs_endmntent (mntFILE *mfp) {if (mfp) {if (mfp->mntent_fp) -fclose (mfp->mntent_fp); +close (fileno (mfp->mntent_fp));if (mfp->mntent_file)free (mfp->mntent_file);free (mfp);@@ -147,7 +147,7 @@ nfs_addmntent (mntFILE *mfp, struct mntent *mnt) {free (m3);free (m4);Quoted 8 lines
support/nfs/nfs_mntent.c nfs_addmntent (mntFILE *mfp, struct mntent *mnt) { · line 150
Quoted 3 lines
support/nfs/nfs_mntent.c +1
-1if (res >=0 ) { - res =fflush (mfp->mntent_fp); + res =fsync (fileno (mfp->mntent_fp));fsync doesn't imply an fflush. With this, I think you may end up without everything being committed to disk if part or all of it is still in the file stream buffer. You probably want to do an
fflush()and then an fsync here.The problem was with the
fflush()call. The call was causing the mount to drop core in turn causing mtab corruption. Changing that call to afsync()worked just fine... no corruption... every time!
Quoted 7 lines
Quoted 6 lines
Looking at man setrlimit.... If you're worried about
RLIMIT_FSIZE, then I guess you need to handle SIGXFSZ and EFBIG returns fromwrite().It looks like
lock_mtab()already sets SIGXFSZ to be ignored. Is a libc bug crashing fflush on EFBIG? Or maybe the ftruncate is a problem? Maybe you just want to do away with stream IO completely?Calling
fsync()clearly works.
Until we understand why it works, it may be just luck.
--b.
Quoted 2 lines
So why are looking for alternative
solutions??
Quoted 54 lines · On Wed, 19 Oct 2011 13:30:58 -0400 Steve Dickson <[email protected]> wrote:
Quoted 51 lines · Jeff Layton
Quoted 47 lines · On Wed, 19 Oct 2011 13:10:19 -0400 Steve Dickson <[email protected]> wrote:
Quoted 32 lines · Jeff Layton
Quoted 29 lines · On Wed, 19 Oct 2011 11:34:30 -0400 Steve Dickson <[email protected]> wrote:
This patch is a following on to commit
7a802337. Using the tool in https://bugzilla.redhat.com/show_bug.cgi?id=695916
caused thefflush()andfclose()to fail in turn causing corruption in the mtab.The failures were in the internals of both calls. Switch those calls with the actual system calls eliminated the failures.
Signed-off-by Steve Dickson <[email protected]>--- support/nfs/nfs_mntent.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)support/nfs/nfs_mntent.c +1
-1@@ -117,7 +117,7 @@ void nfs_endmntent (mntFILE *mfp) {if (mfp) {if (mfp->mntent_fp) -fclose (mfp->mntent_fp); +close (fileno (mfp->mntent_fp));if (mfp->mntent_file)free (mfp->mntent_file);free (mfp);@@ -147,7 +147,7 @@ nfs_addmntent (mntFILE *mfp, struct mntent *mnt) {free (m3);free (m4);Quoted 8 lines
support/nfs/nfs_mntent.c nfs_addmntent (mntFILE *mfp, struct mntent *mnt) { · line 150
Quoted 3 lines
support/nfs/nfs_mntent.c +1
-1if (res >=0 ) { - res =fflush (mfp->mntent_fp); + res =fsync (fileno (mfp->mntent_fp));fsync doesn't imply an fflush. With this, I think you may end up without everything being committed to disk if part or all of it is still in the file stream buffer. You probably want to do an
fflush()and then an fsync here.The problem was with the
fflush()call. The call was causing the mount to drop core in turn causing mtab corruption. Changing that call to afsync()worked just fine... no corruption... every time!
Quoted 7 lines
Quoted 3 lines
Ahh, then you have another problem here too then. Most likely it was crashing because it caught a SIGXFSZ. Writing out the mtab should not be affected by signals.
So calling
fflush()generates a SIGXFSZ and callfsync()does not... I really don't see what the problem is is call simply callingfsync()which clearly works?
Because they do different things. fflush() flushes out the (userspace) stream buffer to the kernel's pagecache. fsync() forces the pagecache to be written out and committed to disk.
If you call fsync() while the data is still in the userspace buffer then it doesn't really do you any good. The data you wrote via fwrite() won't be committed to disk.
Signature · 1 line
Jeff Layton <[email protected]>
Quoted 60 lines · Jeff Layton
Quoted 57 lines · On Wed, 19 Oct 2011 13:30:58 -0400 Steve Dickson <[email protected]> wrote:
Quoted 54 lines · Jeff Layton
Quoted 43 lines · On Wed, 19 Oct 2011 13:10:19 -0400 Steve Dickson <[email protected]> wrote:
Quoted 32 lines · Jeff Layton
Quoted 29 lines · On Wed, 19 Oct 2011 11:34:30 -0400 Steve Dickson <[email protected]> wrote:
This patch is a following on to commit
7a802337. Using the tool in https://bugzilla.redhat.com/show_bug.cgi?id=695916
caused thefflush()andfclose()to fail in turn causing corruption in the mtab.The failures were in the internals of both calls. Switch those calls with the actual system calls eliminated the failures.
Signed-off-by Steve Dickson <[email protected]>--- support/nfs/nfs_mntent.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)support/nfs/nfs_mntent.c +1
-1@@ -117,7 +117,7 @@ void nfs_endmntent (mntFILE *mfp) {if (mfp) {if (mfp->mntent_fp) -fclose (mfp->mntent_fp); +close (fileno (mfp->mntent_fp));if (mfp->mntent_file)free (mfp->mntent_file);free (mfp);@@ -147,7 +147,7 @@ nfs_addmntent (mntFILE *mfp, struct mntent *mnt) {free (m3);free (m4);Quoted 8 lines
support/nfs/nfs_mntent.c nfs_addmntent (mntFILE *mfp, struct mntent *mnt) { · line 150
Quoted 3 lines
support/nfs/nfs_mntent.c +1
-1if (res >=0 ) { - res =fflush (mfp->mntent_fp); + res =fsync (fileno (mfp->mntent_fp));fsync doesn't imply an fflush. With this, I think you may end up without everything being committed to disk if part or all of it is still in the file stream buffer. You probably want to do an
fflush()and then an fsync here.Quoted 4 lines
The problem was with the
fflush()call. The call was causing the mount to drop core in turn causing mtab corruption. Changing that call to afsync()worked just fine... no corruption... every time!Ahh, then you have another problem here too then. Most likely it was crashing because it caught a SIGXFSZ. Writing out the mtab should not be affected by signals.
Quoted 8 lines
Quoted 4 lines
So calling
fflush()generates a SIGXFSZ and callfsync()does not... I really don't see what the problem is is call simply callingfsync()which clearly works?Because they do different things.
fflush()flushes out the (userspace) stream buffer to the kernel's pagecache.fsync()forces the pagecache to be written out and committed to disk.
Believe I understand the code......
Quoted 5 lines
If you call
fsync()while the data is still in the userspace buffer then it doesn't really do you any good. The data you wrote viafwrite()won't be committed to disk.
So I'm thinking the reason the data makes it the disk is its already in the pagecache when the fsync() is called... but to agree with Bruce, the might just be luck...
steved.
Quoted 58 lines · J. Bruce Fields
Quoted 57 lines · Steve Dickson
Quoted 54 lines · Jeff Layton
Quoted 43 lines · On Wed, 19 Oct 2011 13:10:19 -0400 Steve Dickson <[email protected]> wrote:
Quoted 32 lines · Jeff Layton
Quoted 29 lines · On Wed, 19 Oct 2011 11:34:30 -0400 Steve Dickson <[email protected]> wrote:
This patch is a following on to commit
7a802337. Using the tool in https://bugzilla.redhat.com/show_bug.cgi?id=695916
caused thefflush()andfclose()to fail in turn causing corruption in the mtab.The failures were in the internals of both calls. Switch those calls with the actual system calls eliminated the failures.
Signed-off-by Steve Dickson <[email protected]>--- support/nfs/nfs_mntent.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)support/nfs/nfs_mntent.c +1
-1@@ -117,7 +117,7 @@ void nfs_endmntent (mntFILE *mfp) {if (mfp) {if (mfp->mntent_fp) -fclose (mfp->mntent_fp); +close (fileno (mfp->mntent_fp));if (mfp->mntent_file)free (mfp->mntent_file);free (mfp);@@ -147,7 +147,7 @@ nfs_addmntent (mntFILE *mfp, struct mntent *mnt) {free (m3);free (m4);Quoted 8 lines
support/nfs/nfs_mntent.c nfs_addmntent (mntFILE *mfp, struct mntent *mnt) { · line 150
Quoted 3 lines
support/nfs/nfs_mntent.c +1
-1if (res >=0 ) { - res =fflush (mfp->mntent_fp); + res =fsync (fileno (mfp->mntent_fp));fsync doesn't imply an fflush. With this, I think you may end up without everything being committed to disk if part or all of it is still in the file stream buffer. You probably want to do an
fflush()and then an fsync here.Quoted 4 lines
The problem was with the
fflush()call. The call was causing the mount to drop core in turn causing mtab corruption. Changing that call to afsync()worked just fine... no corruption... every time!Ahh, then you have another problem here too then. Most likely it was crashing because it caught a SIGXFSZ. Writing out the mtab should not be affected by signals.
Quoted 7 lines
Quoted 1 line
So calling
fflush()generates a SIGXFSZ and callfsync()does not...
fflush()must hit this because it's callingwrite()to write out the stream buffer....But
lock_mtab()should have set SIGXFSZ to be ignored; is that not happening?
This is the case. The following patch cause SIGXFSZ to be ignored.
utils/mount/fstab.c renamed from utils/mount/fstab.c.orig +3 -2
@@ -387,8 +387,9 @@ lock_mtab (void) { sa.sa_flags =0 ;sigfillset (&sa.sa_mask); -while (sigismember (&sa.sa_mask, ++sig) !=-1 - && sig !=SIGCHLD ) { +while (sigismember (&sa.sa_mask, ++sig) !=-1 ) { +if (sig ==SIGCHLD ) +continue ;if (sig ==SIGALRM ) sa.sa_handler = setlkw_timeout;else
Now all this does is cause mount to ignore the fact that the write() during the fflush() fails, which causes the following warning during the umount.
[mntent]: warning: no final newline at the end of /etc/mtab [mntent]: warning: no final newline at the end of /etc/mtab [mntent]: warning: no final newline at the end of /etc/mtab
I can live with those warnings....
steved.
Quoted 7 lines
Quoted 3 lines
I really don't see what the problem is is call simply calling
fsync()which clearly works?We want to make sure the problem's really fixed.
--b.
It turns out this is only a RHEL6 bug. I (stupidly) made the assumption that since the RHEL6 patch cleanly applied to upstream, both streams worked in the same way... which is not the case.
With upstream, this mtab code is not even compiled when the libmount code is enabled. Secondly, with later systems /etc/mtab is symbolically linked to /proc/mounts, making the file read-only. Finally when /etc/mtabs is a regular file and is writeable, the SIGXFSZ signal is handled properly in lock_mtab() so there is no corruption.
Sorry for the noise.
steved.
Quoted 35 lines · Steve Dickson
This patch is a following on to commit
7a802337. Using the tool in https://bugzilla.redhat.com/show_bug.cgi?id=695916
caused thefflush()andfclose()to fail in turn causing corruption in the mtab.The failures were in the internals of both calls. Switch those calls with the actual system calls eliminated the failures.
Signed-off-by Steve Dickson <[email protected]>--- support/nfs/nfs_mntent.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)support/nfs/nfs_mntent.c +2
-2@@ -117,7 +117,7 @@ void nfs_endmntent (mntFILE *mfp) {if (mfp) {if (mfp->mntent_fp) -fclose (mfp->mntent_fp); +close (fileno (mfp->mntent_fp));if (mfp->mntent_file)free (mfp->mntent_file);free (mfp);@@ -147,7 +147,7 @@ nfs_addmntent (mntFILE *mfp, struct mntent *mnt) {free (m3);free (m4);if (res >=0 ) { - res =fflush (mfp->mntent_fp); + res =fsync (fileno (mfp->mntent_fp));if (res <0 )/* Avoid leaving a corrupt mtab file */ ftruncate (fileno (mfp->mntent_fp), length);
Quoted 74 lines · Steve Dickson
Quoted 58 lines · J. Bruce Fields
Quoted 57 lines · Steve Dickson
Quoted 54 lines · Jeff Layton
Quoted 43 lines · On Wed, 19 Oct 2011 13:10:19 -0400 Steve Dickson <[email protected]> wrote:
Quoted 32 lines · Jeff Layton
Quoted 29 lines · On Wed, 19 Oct 2011 11:34:30 -0400 Steve Dickson <[email protected]> wrote:
This patch is a following on to commit
7a802337. Using the tool in https://bugzilla.redhat.com/show_bug.cgi?id=695916
caused thefflush()andfclose()to fail in turn causing corruption in the mtab.The failures were in the internals of both calls. Switch those calls with the actual system calls eliminated the failures.
Signed-off-by Steve Dickson <[email protected]>--- support/nfs/nfs_mntent.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)support/nfs/nfs_mntent.c +1
-1@@ -117,7 +117,7 @@ void nfs_endmntent (mntFILE *mfp) {if (mfp) {if (mfp->mntent_fp) -fclose (mfp->mntent_fp); +close (fileno (mfp->mntent_fp));if (mfp->mntent_file)free (mfp->mntent_file);free (mfp);@@ -147,7 +147,7 @@ nfs_addmntent (mntFILE *mfp, struct mntent *mnt) {free (m3);free (m4);Quoted 8 lines
support/nfs/nfs_mntent.c nfs_addmntent (mntFILE *mfp, struct mntent *mnt) { · line 150
Quoted 3 lines
support/nfs/nfs_mntent.c +1
-1if (res >=0 ) { - res =fflush (mfp->mntent_fp); + res =fsync (fileno (mfp->mntent_fp));fsync doesn't imply an fflush. With this, I think you may end up without everything being committed to disk if part or all of it is still in the file stream buffer. You probably want to do an
fflush()and then an fsync here.Quoted 4 lines
The problem was with the
fflush()call. The call was causing the mount to drop core in turn causing mtab corruption. Changing that call to afsync()worked just fine... no corruption... every time!Ahh, then you have another problem here too then. Most likely it was crashing because it caught a SIGXFSZ. Writing out the mtab should not be affected by signals.
Quoted 7 lines
Quoted 1 line
So calling
fflush()generates a SIGXFSZ and callfsync()does not...
fflush()must hit this because it's callingwrite()to write out the stream buffer....But
lock_mtab()should have set SIGXFSZ to be ignored; is that not happening?This is the case. The following patch cause SIGXFSZ to be ignored.
diff -up ./utils/mount/fstab.c.orig
./utils/mount/fstab.c
utils/mount/fstab.c lock_mtab (void) { · line 391
Quoted 5 lines
utils/mount/fstab.c renamed from utils/mount/fstab.c.orig +0
-2@@ -387,8 +387,9 @@ lock_mtab (void) { sa.sa_flags =0 ;sigfillset (&sa.sa_mask); -while (sigismember (&sa.sa_mask, ++sig) !=-1 - && sig !=SIGCHLD ) {
I'm very confused--the latest nfs-utils doesn't have this.
Oh, I see: it was fixed by b3e190c4adfc9ec47567c968bd000d282d07b05e "mount: improve signal management when locking mtab".
So if you're working with an older version then you probably want to backport that patch.
--b.
Quoted 26 lines
utils/mount/fstab.c renamed from utils/mount/fstab.c.orig +3
-0+while (sigismember (&sa.sa_mask, ++sig) !=-1 ) { +if (sig ==SIGCHLD ) +continue ;if (sig ==SIGALRM ) sa.sa_handler = setlkw_timeout;else Now all this does is cause mount to ignore the fact that the
write()during thefflush()fails, which causes the following warning during the umount.[mntent]: warning: no final newline at the end of
/etc/mtab[mntent]: warning: no final newline at the end of/etc/mtab[mntent]: warning: no final newline at the end of/etc/mtabI can live with those warnings....
steved.
Quoted 7 lines
Quoted 3 lines
I really don't see what the problem is is call simply calling
fsync()which clearly works?We want to make sure the problem's really fixed.
--b.
Quoted 83 lines · J. Bruce Fields
Quoted 74 lines · Steve Dickson
Quoted 58 lines · J. Bruce Fields
Quoted 57 lines · Steve Dickson
Quoted 54 lines · Jeff Layton
Quoted 43 lines · On Wed, 19 Oct 2011 13:10:19 -0400 Steve Dickson <[email protected]> wrote:
Quoted 32 lines · Jeff Layton
Quoted 29 lines · On Wed, 19 Oct 2011 11:34:30 -0400 Steve Dickson <[email protected]> wrote:
This patch is a following on to commit
7a802337. Using the tool in https://bugzilla.redhat.com/show_bug.cgi?id=695916
caused thefflush()andfclose()to fail in turn causing corruption in the mtab.The failures were in the internals of both calls. Switch those calls with the actual system calls eliminated the failures.
Signed-off-by Steve Dickson <[email protected]>--- support/nfs/nfs_mntent.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)support/nfs/nfs_mntent.c +1
-1@@ -117,7 +117,7 @@ void nfs_endmntent (mntFILE *mfp) {if (mfp) {if (mfp->mntent_fp) -fclose (mfp->mntent_fp); +close (fileno (mfp->mntent_fp));if (mfp->mntent_file)free (mfp->mntent_file);free (mfp);@@ -147,7 +147,7 @@ nfs_addmntent (mntFILE *mfp, struct mntent *mnt) {free (m3);free (m4);Quoted 8 lines
support/nfs/nfs_mntent.c nfs_addmntent (mntFILE *mfp, struct mntent *mnt) { · line 150
Quoted 3 lines
support/nfs/nfs_mntent.c +1
-1if (res >=0 ) { - res =fflush (mfp->mntent_fp); + res =fsync (fileno (mfp->mntent_fp));fsync doesn't imply an fflush. With this, I think you may end up without everything being committed to disk if part or all of it is still in the file stream buffer. You probably want to do an
fflush()and then an fsync here.Quoted 4 lines
The problem was with the
fflush()call. The call was causing the mount to drop core in turn causing mtab corruption. Changing that call to afsync()worked just fine... no corruption... every time!Ahh, then you have another problem here too then. Most likely it was crashing because it caught a SIGXFSZ. Writing out the mtab should not be affected by signals.
Quoted 7 lines
Quoted 1 line
So calling
fflush()generates a SIGXFSZ and callfsync()does not...
fflush()must hit this because it's callingwrite()to write out the stream buffer....But
lock_mtab()should have set SIGXFSZ to be ignored; is that not happening?This is the case. The following patch cause SIGXFSZ to be ignored.
diff -up ./utils/mount/fstab.c.orig
./utils/mount/fstab.cutils/mount/fstab.c lock_mtab (void) { · line 391
Quoted 5 lines
utils/mount/fstab.c renamed from utils/mount/fstab.c.orig +0
-2@@ -387,8 +387,9 @@ lock_mtab (void) { sa.sa_flags =0 ;sigfillset (&sa.sa_mask); -while (sigismember (&sa.sa_mask, ++sig) !=-1 - && sig !=SIGCHLD ) {I'm very confused--the latest nfs-utils doesn't have this.
Quoted 5 lines
Oh, I see: it was fixed by
b3e190c4adfc9ec47567c968bd000d282d07b05e"mount: improve signal management when locking mtab".So if you're working with an older version then you probably want to backport that patch.
Exactly... Read my last posting...
steved.
Quoted 29 lines
--b.
Quoted 26 lines
utils/mount/fstab.c renamed from utils/mount/fstab.c.orig +3
-0+while (sigismember (&sa.sa_mask, ++sig) !=-1 ) { +if (sig ==SIGCHLD ) +continue ;if (sig ==SIGALRM ) sa.sa_handler = setlkw_timeout;else Now all this does is cause mount to ignore the fact that the
write()during thefflush()fails, which causes the following warning during the umount.[mntent]: warning: no final newline at the end of
/etc/mtab[mntent]: warning: no final newline at the end of/etc/mtab[mntent]: warning: no final newline at the end of/etc/mtabI can live with those warnings....
steved.
Quoted 7 lines
Quoted 3 lines
I really don't see what the problem is is call simply calling
fsync()which clearly works?We want to make sure the problem's really fixed.
--b.
Quoted 18 lines · Steve Dickson
Quoted 15 lines · J. Bruce Fields
utils/mount/fstab.c lock_mtab (void) { · line 391
Quoted 11 lines · Steve Dickson
This is the case. The following patch cause SIGXFSZ to be ignored.
diff -up ./utils/mount/fstab.c.orig
./utils/mount/fstab.cutils/mount/fstab.c renamed from utils/mount/fstab.c.orig +0
-2@@ -387,8 +387,9 @@ lock_mtab (void) { sa.sa_flags =0 ;sigfillset (&sa.sa_mask); -while (sigismember (&sa.sa_mask, ++sig) !=-1 - && sig !=SIGCHLD ) {I'm very confused--the latest nfs-utils doesn't have this.
Quoted 6 lines
Quoted 5 lines
Oh, I see: it was fixed by
b3e190c4adfc9ec47567c968bd000d282d07b05e"mount: improve signal management when locking mtab".So if you're working with an older version then you probably want to backport that patch.
Exactly... Read my last posting...
I'm way behind! Thanks--b.