On Fri, 21 Oct 2005, Joseph V Moss wrote:

> > 
> > What, exactly, do you think is broken about the mtab locking?  I remember
> > spending a few hours with that code, and it looked sane to me.
> 
> We used to see the problem of the mtab getting corrupted due to too
> many filesystems getting mounted within a short time frame.  We started
> using this patch a while ago and have continued to do so, even though
> autofs now has locking.  The mtab problems stopped after making this
> change.
> 
> ===============================================================================
> If there are lots of mounts happening simultaneously (usually due to autofs),
> the locking of /etc/mtab could fail, in which case, the mount succeeds, but
> doesn't get properly recorded in the mount table.  This patch greatly
> increases the number of tries to lock the mtab, before giving up.  The chance
> that the lock will fail due to contention from lots of other mount processes
> should be very close to nil.
> 
>  -- Joseph Moss <[EMAIL PROTECTED]> 13-Nov-2002
> 
> --- util-linux-2.11g/mount/fstab.c.waitlock   Wed Nov 13 11:45:40 2002
> +++ util-linux-2.11g/mount/fstab.c    Wed Nov 13 12:04:55 2002
> @@ -441,8 +441,12 @@
>                       alarm(0);
>                       /* Limit the number of iterations - maybe there
>                          still is some old /etc/mtab~ */
> -                     if (tries++ > 3) {
> -                             if (tries > 5)
> +                     if (tries++ > 2) {
> +                             if ((tries % 20) == 0)
> +                                 printf(_("Warning: Unable to create link %s"
> +                                             " after %d tries\n"),
> +                                        MOUNTED_LOCK, tries);
> +                             if (tries > 115)
>                                       die (EX_FILEIO, _("Cannot create link 
> %s\n"
>                                           "Perhaps there is a stale lock 
> file?\n"),
>                                            MOUNTED_LOCK);
> 
> 

Yes, I can see how that would help. I think you have identified the 
symptom but I may have stumbled onto the cause.

This is the mail I sent to Adrain the other day regarding this problem.

>From [EMAIL PROTECTED] Sat Sep 24 17:35:46 2005
Date: Sat, 24 Sep 2005 17:32:58 +0800 (WST)
From: Ian Kent <[EMAIL PROTECTED]>
To: Adrian Bunk <[EMAIL PROTECTED]>
Subject: Re: mtab locking - who wants to talk abou this

On Fri, 23 Sep 2005, Adrian Bunk wrote:

> On Tue, Sep 20, 2005 at 09:32:28AM +0800, Ian Kent wrote:
> > 
> > Hi Adrian,
> 
> Hi Ian,
> 
> > I'm looking for someone that is involved in maintaining util-linux.
> > 
> > I have been looking, on and of, for quite a while now without any 
> > success, at least I haven't found anyone willing to reply. Well that's a 
> > bit of an exaggeration. I sent mail to Andries Bouwer and got no reply.
> 
> Andries passed maintainership of util-linux to me last year, so I'm the 
> right contact.

Cool.

I've had trouble with mtab corruption for a long time now.
With rapid mounting requests from autofs.

I have not been able to see what the problem was with the locking until I 
had another look the other day.

I'm not sure if I'm right but hopefully another set of eyes will sort that 
out.

What I think is happening is, in mount/fstab.c:lock_mtab when there is a 
lock held and another process attempts to wait for it, it doesn't. The 
tries are rapidly exhausted resulting in a lock failure. 

I believe the reason is because the code assumes that, when attempting 
to wait for the lock file a flock is held on it by the owner, which is not 
the case. The culprit is the position of the close, which releases any 
locks held by the process when called.

I made a little patch but haven't had time to test it yet. I'll have to 
rip out the locking I introduced to autofs to do that so it will likely 
be little while before I can. The close at the exit is probably not 
needed as the flock will also be released at process termination. I 
included it for completeness. I had some difficulty patching different 
versions of util-linux so I'm not sure it will apply cleanly to your tree. 
The patch is straight forward though.

Please let me know what you think.

Ian

--- util-linux-2.12q/mount/fstab.c.flock        2005-09-17 01:10:37.000000000 
+0800
+++ util-linux-2.12q/mount/fstab.c      2005-09-17 01:16:51.000000000 +0800
@@ -417,6 +417,7 @@
 unlock_mtab (void) {
        if (we_created_lockfile) {
                unlink (MOUNTED_LOCK);
+               close(we_created_lock_file);
                we_created_lockfile = 0;
        }
 }
@@ -528,6 +529,7 @@
                                }
                                /* proceed anyway */
                        }
+                       we_created_lock_file = fd;
                } else {
                        static int tries = 0;
 
@@ -549,9 +551,8 @@
                                             MOUNTED_LOCK);
                                sleep(1);
                        }
+                       close(fd);
                }
-
-               close(fd);
        }
 }
 

_______________________________________________
autofs mailing list
[email protected]
http://linux.kernel.org/mailman/listinfo/autofs

Reply via email to