* [Cluster-devel] [GFS2 PATCH] GFS2: Request demote when a "try" flock fails [not found] <459014530.9252412.1408552959180.JavaMail.zimbra@redhat.com> @ 2014-08-20 16:44 ` Bob Peterson 2014-08-21 15:51 ` Steven Whitehouse 0 siblings, 1 reply; 2+ messages in thread From: Bob Peterson @ 2014-08-20 16:44 UTC (permalink / raw) To: cluster-devel.redhat.com Hi, This patch changes the flock code so that it uses the TRY_1CB flag instead of the TRY flag on the first attempt. That forces any holding nodes to issue a dlm callback, which requests a demote of the glock. Then, if the "try" failed, it sleeps a small amount of time for the demote to occur. Then it tries again, for an increasing amount of time. Subsequent attempts to gain the "try" lock don't use "_1CB" so that only one callback is issued. Regards, Bob Peterson Red Hat File Systems Signed-off-by: Bob Peterson <rpeterso@redhat.com> --- diff --git a/fs/gfs2/file.c b/fs/gfs2/file.c index 26b3f95..7f4ed3d 100644 --- a/fs/gfs2/file.c +++ b/fs/gfs2/file.c @@ -26,6 +26,7 @@ #include <linux/dlm.h> #include <linux/dlm_plock.h> #include <linux/aio.h> +#include <linux/delay.h> #include "gfs2.h" #include "incore.h" @@ -979,9 +980,10 @@ static int do_flock(struct file *file, int cmd, struct file_lock *fl) unsigned int state; int flags; int error = 0; + int sleeptime; state = (fl->fl_type == F_WRLCK) ? LM_ST_EXCLUSIVE : LM_ST_SHARED; - flags = (IS_SETLKW(cmd) ? 0 : LM_FLAG_TRY) | GL_EXACT; + flags = (IS_SETLKW(cmd) ? 0 : LM_FLAG_TRY_1CB) | GL_EXACT; mutex_lock(&fp->f_fl_mutex); @@ -1001,7 +1003,14 @@ static int do_flock(struct file *file, int cmd, struct file_lock *fl) gfs2_holder_init(gl, state, flags, fl_gh); gfs2_glock_put(gl); } - error = gfs2_glock_nq(fl_gh); + for (sleeptime = 1; sleeptime <= 4; sleeptime <<= 1) { + error = gfs2_glock_nq(fl_gh); + if (error != GLR_TRYFAILED) + break; + fl_gh->gh_flags = LM_FLAG_TRY | GL_EXACT; + fl_gh->gh_error = 0; + msleep(sleeptime); + } if (error) { gfs2_holder_uninit(fl_gh); if (error == GLR_TRYFAILED) @@ -1024,7 +1033,7 @@ static void do_unflock(struct file *file, struct file_lock *fl) mutex_lock(&fp->f_fl_mutex); flock_lock_file_wait(file, fl); if (fl_gh->gh_gl) { - gfs2_glock_dq_wait(fl_gh); + gfs2_glock_dq(fl_gh); gfs2_holder_uninit(fl_gh); } mutex_unlock(&fp->f_fl_mutex); ^ permalink raw reply related [flat|nested] 2+ messages in thread
* [Cluster-devel] [GFS2 PATCH] GFS2: Request demote when a "try" flock fails 2014-08-20 16:44 ` [Cluster-devel] [GFS2 PATCH] GFS2: Request demote when a "try" flock fails Bob Peterson @ 2014-08-21 15:51 ` Steven Whitehouse 0 siblings, 0 replies; 2+ messages in thread From: Steven Whitehouse @ 2014-08-21 15:51 UTC (permalink / raw) To: cluster-devel.redhat.com Hi, Now in the -nmw git tree. Thanks, Steve. On 20/08/14 17:44, Bob Peterson wrote: > Hi, > > This patch changes the flock code so that it uses the TRY_1CB flag > instead of the TRY flag on the first attempt. That forces any holding > nodes to issue a dlm callback, which requests a demote of the glock. > Then, if the "try" failed, it sleeps a small amount of time for the > demote to occur. Then it tries again, for an increasing amount of time. > Subsequent attempts to gain the "try" lock don't use "_1CB" so that > only one callback is issued. > > Regards, > > Bob Peterson > Red Hat File Systems > > Signed-off-by: Bob Peterson <rpeterso@redhat.com> > --- > diff --git a/fs/gfs2/file.c b/fs/gfs2/file.c > index 26b3f95..7f4ed3d 100644 > --- a/fs/gfs2/file.c > +++ b/fs/gfs2/file.c > @@ -26,6 +26,7 @@ > #include <linux/dlm.h> > #include <linux/dlm_plock.h> > #include <linux/aio.h> > +#include <linux/delay.h> > > #include "gfs2.h" > #include "incore.h" > @@ -979,9 +980,10 @@ static int do_flock(struct file *file, int cmd, struct file_lock *fl) > unsigned int state; > int flags; > int error = 0; > + int sleeptime; > > state = (fl->fl_type == F_WRLCK) ? LM_ST_EXCLUSIVE : LM_ST_SHARED; > - flags = (IS_SETLKW(cmd) ? 0 : LM_FLAG_TRY) | GL_EXACT; > + flags = (IS_SETLKW(cmd) ? 0 : LM_FLAG_TRY_1CB) | GL_EXACT; > > mutex_lock(&fp->f_fl_mutex); > > @@ -1001,7 +1003,14 @@ static int do_flock(struct file *file, int cmd, struct file_lock *fl) > gfs2_holder_init(gl, state, flags, fl_gh); > gfs2_glock_put(gl); > } > - error = gfs2_glock_nq(fl_gh); > + for (sleeptime = 1; sleeptime <= 4; sleeptime <<= 1) { > + error = gfs2_glock_nq(fl_gh); > + if (error != GLR_TRYFAILED) > + break; > + fl_gh->gh_flags = LM_FLAG_TRY | GL_EXACT; > + fl_gh->gh_error = 0; > + msleep(sleeptime); > + } > if (error) { > gfs2_holder_uninit(fl_gh); > if (error == GLR_TRYFAILED) > @@ -1024,7 +1033,7 @@ static void do_unflock(struct file *file, struct file_lock *fl) > mutex_lock(&fp->f_fl_mutex); > flock_lock_file_wait(file, fl); > if (fl_gh->gh_gl) { > - gfs2_glock_dq_wait(fl_gh); > + gfs2_glock_dq(fl_gh); > gfs2_holder_uninit(fl_gh); > } > mutex_unlock(&fp->f_fl_mutex); > ^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2014-08-21 15:51 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <459014530.9252412.1408552959180.JavaMail.zimbra@redhat.com>
2014-08-20 16:44 ` [Cluster-devel] [GFS2 PATCH] GFS2: Request demote when a "try" flock fails Bob Peterson
2014-08-21 15:51 ` Steven Whitehouse
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.