glock.c (e9fc2aa091ab8fa46e60d4c9d06a89305c441652) glock.c (5029996547a9f3988459e11955c13259495308ef)
1/*
2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
3 * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved.
4 *
5 * This copyrighted material is made available to anyone wishing to use,
6 * modify, copy, or redistribute it subject to the terms and conditions
7 * of the GNU General Public License version 2.
8 */

--- 286 unchanged lines hidden (view full) ---

295 gl->gl_object = NULL;
296 gl->gl_bucket = bucket;
297 gl->gl_sbd = sdp;
298 gl->gl_aspace = NULL;
299 lops_init_le(&gl->gl_le, &gfs2_glock_lops);
300
301 /* If this glock protects actual on-disk data or metadata blocks,
302 create a VFS inode to manage the pages/buffers holding them. */
1/*
2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
3 * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved.
4 *
5 * This copyrighted material is made available to anyone wishing to use,
6 * modify, copy, or redistribute it subject to the terms and conditions
7 * of the GNU General Public License version 2.
8 */

--- 286 unchanged lines hidden (view full) ---

295 gl->gl_object = NULL;
296 gl->gl_bucket = bucket;
297 gl->gl_sbd = sdp;
298 gl->gl_aspace = NULL;
299 lops_init_le(&gl->gl_le, &gfs2_glock_lops);
300
301 /* If this glock protects actual on-disk data or metadata blocks,
302 create a VFS inode to manage the pages/buffers holding them. */
303 if (glops == &gfs2_inode_glops ||
304 glops == &gfs2_rgrp_glops) {
303 if (glops == &gfs2_inode_glops || glops == &gfs2_rgrp_glops) {
305 gl->gl_aspace = gfs2_aspace_get(sdp);
306 if (!gl->gl_aspace) {
307 error = -ENOMEM;
308 goto fail;
309 }
310 }
311
312 error = gfs2_lm_get_lock(sdp, &name, &gl->gl_lock);

--- 502 unchanged lines hidden (view full) ---

815 if (glops->go_inval)
816 glops->go_inval(gl, DIO_DATA);
817 }
818
819 /* Deal with each possible exit condition */
820
821 if (!gh)
822 gl->gl_stamp = jiffies;
304 gl->gl_aspace = gfs2_aspace_get(sdp);
305 if (!gl->gl_aspace) {
306 error = -ENOMEM;
307 goto fail;
308 }
309 }
310
311 error = gfs2_lm_get_lock(sdp, &name, &gl->gl_lock);

--- 502 unchanged lines hidden (view full) ---

814 if (glops->go_inval)
815 glops->go_inval(gl, DIO_DATA);
816 }
817
818 /* Deal with each possible exit condition */
819
820 if (!gh)
821 gl->gl_stamp = jiffies;
823
824 else if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) {
825 spin_lock(&gl->gl_spin);
826 list_del_init(&gh->gh_list);
827 gh->gh_error = -EIO;
828 spin_unlock(&gl->gl_spin);
822 else if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) {
823 spin_lock(&gl->gl_spin);
824 list_del_init(&gh->gh_list);
825 gh->gh_error = -EIO;
826 spin_unlock(&gl->gl_spin);
829
830 } else if (test_bit(HIF_DEMOTE, &gh->gh_iflags)) {
831 spin_lock(&gl->gl_spin);
832 list_del_init(&gh->gh_list);
833 if (gl->gl_state == gh->gh_state ||
834 gl->gl_state == LM_ST_UNLOCKED)
835 gh->gh_error = 0;
836 else {
837 if (gfs2_assert_warn(sdp, gh->gh_flags &
838 (LM_FLAG_TRY | LM_FLAG_TRY_1CB)) == -1)
839 fs_warn(sdp, "ret = 0x%.8X\n", ret);
840 gh->gh_error = GLR_TRYFAILED;
841 }
842 spin_unlock(&gl->gl_spin);
843
844 if (ret & LM_OUT_CANCELED)
827 } else if (test_bit(HIF_DEMOTE, &gh->gh_iflags)) {
828 spin_lock(&gl->gl_spin);
829 list_del_init(&gh->gh_list);
830 if (gl->gl_state == gh->gh_state ||
831 gl->gl_state == LM_ST_UNLOCKED)
832 gh->gh_error = 0;
833 else {
834 if (gfs2_assert_warn(sdp, gh->gh_flags &
835 (LM_FLAG_TRY | LM_FLAG_TRY_1CB)) == -1)
836 fs_warn(sdp, "ret = 0x%.8X\n", ret);
837 gh->gh_error = GLR_TRYFAILED;
838 }
839 spin_unlock(&gl->gl_spin);
840
841 if (ret & LM_OUT_CANCELED)
845 handle_callback(gl, LM_ST_UNLOCKED); /* Lame */
842 handle_callback(gl, LM_ST_UNLOCKED);
846
847 } else if (ret & LM_OUT_CANCELED) {
848 spin_lock(&gl->gl_spin);
849 list_del_init(&gh->gh_list);
850 gh->gh_error = GLR_CANCELED;
851 spin_unlock(&gl->gl_spin);
852
853 } else if (relaxed_state_ok(gl->gl_state, gh->gh_state, gh->gh_flags)) {

--- 57 unchanged lines hidden (view full) ---

911 LM_FLAG_PRIORITY);
912 unsigned int lck_ret;
913
914 gfs2_assert_warn(sdp, test_bit(GLF_LOCK, &gl->gl_flags));
915 gfs2_assert_warn(sdp, queue_empty(gl, &gl->gl_holders));
916 gfs2_assert_warn(sdp, state != LM_ST_UNLOCKED);
917 gfs2_assert_warn(sdp, state != gl->gl_state);
918
843
844 } else if (ret & LM_OUT_CANCELED) {
845 spin_lock(&gl->gl_spin);
846 list_del_init(&gh->gh_list);
847 gh->gh_error = GLR_CANCELED;
848 spin_unlock(&gl->gl_spin);
849
850 } else if (relaxed_state_ok(gl->gl_state, gh->gh_state, gh->gh_flags)) {

--- 57 unchanged lines hidden (view full) ---

908 LM_FLAG_PRIORITY);
909 unsigned int lck_ret;
910
911 gfs2_assert_warn(sdp, test_bit(GLF_LOCK, &gl->gl_flags));
912 gfs2_assert_warn(sdp, queue_empty(gl, &gl->gl_holders));
913 gfs2_assert_warn(sdp, state != LM_ST_UNLOCKED);
914 gfs2_assert_warn(sdp, state != gl->gl_state);
915
919 if (gl->gl_state == LM_ST_EXCLUSIVE) {
920 if (glops->go_sync)
921 glops->go_sync(gl,
922 DIO_METADATA | DIO_DATA | DIO_RELEASE);
923 }
916 if (gl->gl_state == LM_ST_EXCLUSIVE && glops->go_sync)
917 glops->go_sync(gl, DIO_METADATA | DIO_DATA | DIO_RELEASE);
924
925 gfs2_glock_hold(gl);
926 gl->gl_req_bh = xmote_bh;
927
928 lck_ret = gfs2_lm_lock(sdp, gl->gl_lock, gl->gl_state, state, lck_flags);
929
930 if (gfs2_assert_withdraw(sdp, !(lck_ret & LM_OUT_ERROR)))
931 return;

--- 69 unchanged lines hidden (view full) ---

1001 struct gfs2_sbd *sdp = gl->gl_sbd;
1002 const struct gfs2_glock_operations *glops = gl->gl_ops;
1003 unsigned int ret;
1004
1005 gfs2_assert_warn(sdp, test_bit(GLF_LOCK, &gl->gl_flags));
1006 gfs2_assert_warn(sdp, queue_empty(gl, &gl->gl_holders));
1007 gfs2_assert_warn(sdp, gl->gl_state != LM_ST_UNLOCKED);
1008
918
919 gfs2_glock_hold(gl);
920 gl->gl_req_bh = xmote_bh;
921
922 lck_ret = gfs2_lm_lock(sdp, gl->gl_lock, gl->gl_state, state, lck_flags);
923
924 if (gfs2_assert_withdraw(sdp, !(lck_ret & LM_OUT_ERROR)))
925 return;

--- 69 unchanged lines hidden (view full) ---

995 struct gfs2_sbd *sdp = gl->gl_sbd;
996 const struct gfs2_glock_operations *glops = gl->gl_ops;
997 unsigned int ret;
998
999 gfs2_assert_warn(sdp, test_bit(GLF_LOCK, &gl->gl_flags));
1000 gfs2_assert_warn(sdp, queue_empty(gl, &gl->gl_holders));
1001 gfs2_assert_warn(sdp, gl->gl_state != LM_ST_UNLOCKED);
1002
1009 if (gl->gl_state == LM_ST_EXCLUSIVE) {
1010 if (glops->go_sync)
1011 glops->go_sync(gl, DIO_METADATA | DIO_DATA | DIO_RELEASE);
1012 }
1003 if (gl->gl_state == LM_ST_EXCLUSIVE && glops->go_sync)
1004 glops->go_sync(gl, DIO_METADATA | DIO_DATA | DIO_RELEASE);
1013
1014 gfs2_glock_hold(gl);
1015 gl->gl_req_bh = drop_bh;
1016
1017 ret = gfs2_lm_unlock(sdp, gl->gl_lock, gl->gl_state);
1018
1019 if (gfs2_assert_withdraw(sdp, !(ret & LM_OUT_ERROR)))
1020 return;

--- 15 unchanged lines hidden (view full) ---

1036{
1037 struct gfs2_glock *gl = gh->gh_gl;
1038
1039 spin_lock(&gl->gl_spin);
1040
1041 while (gl->gl_req_gh != gh &&
1042 !test_bit(HIF_HOLDER, &gh->gh_iflags) &&
1043 !list_empty(&gh->gh_list)) {
1005
1006 gfs2_glock_hold(gl);
1007 gl->gl_req_bh = drop_bh;
1008
1009 ret = gfs2_lm_unlock(sdp, gl->gl_lock, gl->gl_state);
1010
1011 if (gfs2_assert_withdraw(sdp, !(ret & LM_OUT_ERROR)))
1012 return;

--- 15 unchanged lines hidden (view full) ---

1028{
1029 struct gfs2_glock *gl = gh->gh_gl;
1030
1031 spin_lock(&gl->gl_spin);
1032
1033 while (gl->gl_req_gh != gh &&
1034 !test_bit(HIF_HOLDER, &gh->gh_iflags) &&
1035 !list_empty(&gh->gh_list)) {
1044 if (gl->gl_req_bh &&
1045 !(gl->gl_req_gh &&
1046 (gl->gl_req_gh->gh_flags & GL_NOCANCEL))) {
1036 if (gl->gl_req_bh && !(gl->gl_req_gh &&
1037 (gl->gl_req_gh->gh_flags & GL_NOCANCEL))) {
1047 spin_unlock(&gl->gl_spin);
1048 gfs2_lm_cancel(gl->gl_sbd, gl->gl_lock);
1049 msleep(100);
1050 spin_lock(&gl->gl_spin);
1051 } else {
1052 spin_unlock(&gl->gl_spin);
1053 msleep(100);
1054 spin_lock(&gl->gl_spin);

--- 263 unchanged lines hidden (view full) ---

1318
1319static void gfs2_glock_prefetch(struct gfs2_glock *gl, unsigned int state,
1320 int flags)
1321{
1322 const struct gfs2_glock_operations *glops = gl->gl_ops;
1323
1324 spin_lock(&gl->gl_spin);
1325
1038 spin_unlock(&gl->gl_spin);
1039 gfs2_lm_cancel(gl->gl_sbd, gl->gl_lock);
1040 msleep(100);
1041 spin_lock(&gl->gl_spin);
1042 } else {
1043 spin_unlock(&gl->gl_spin);
1044 msleep(100);
1045 spin_lock(&gl->gl_spin);

--- 263 unchanged lines hidden (view full) ---

1309
1310static void gfs2_glock_prefetch(struct gfs2_glock *gl, unsigned int state,
1311 int flags)
1312{
1313 const struct gfs2_glock_operations *glops = gl->gl_ops;
1314
1315 spin_lock(&gl->gl_spin);
1316
1326 if (test_bit(GLF_LOCK, &gl->gl_flags) ||
1327 !list_empty(&gl->gl_holders) ||
1328 !list_empty(&gl->gl_waiters1) ||
1329 !list_empty(&gl->gl_waiters2) ||
1317 if (test_bit(GLF_LOCK, &gl->gl_flags) || !list_empty(&gl->gl_holders) ||
1318 !list_empty(&gl->gl_waiters1) || !list_empty(&gl->gl_waiters2) ||
1330 !list_empty(&gl->gl_waiters3) ||
1331 relaxed_state_ok(gl->gl_state, state, flags)) {
1332 spin_unlock(&gl->gl_spin);
1333 return;
1334 }
1335
1336 set_bit(GLF_PREFETCH, &gl->gl_flags);
1337 set_bit(GLF_LOCK, &gl->gl_flags);

--- 347 unchanged lines hidden (view full) ---

1685 gl->gl_lvb = NULL;
1686 gfs2_glock_put(gl);
1687 }
1688
1689 gfs2_glmutex_unlock(gl);
1690 gfs2_glock_put(gl);
1691}
1692
1319 !list_empty(&gl->gl_waiters3) ||
1320 relaxed_state_ok(gl->gl_state, state, flags)) {
1321 spin_unlock(&gl->gl_spin);
1322 return;
1323 }
1324
1325 set_bit(GLF_PREFETCH, &gl->gl_flags);
1326 set_bit(GLF_LOCK, &gl->gl_flags);

--- 347 unchanged lines hidden (view full) ---

1674 gl->gl_lvb = NULL;
1675 gfs2_glock_put(gl);
1676 }
1677
1678 gfs2_glmutex_unlock(gl);
1679 gfs2_glock_put(gl);
1680}
1681
1693#if 0
1694void gfs2_lvb_sync(struct gfs2_glock *gl)
1695{
1696 gfs2_glmutex_lock(gl);
1697
1698 gfs2_assert(gl->gl_sbd, atomic_read(&gl->gl_lvb_count));
1699 if (!gfs2_assert_warn(gl->gl_sbd, gfs2_glock_is_held_excl(gl)))
1700 gfs2_lm_sync_lvb(gl->gl_sbd, gl->gl_lock, gl->gl_lvb);
1701
1702 gfs2_glmutex_unlock(gl);
1703}
1704#endif /* 0 */
1705
1706static void blocking_cb(struct gfs2_sbd *sdp, struct lm_lockname *name,
1707 unsigned int state)
1708{
1709 struct gfs2_glock *gl;
1710
1711 gl = gfs2_glock_find(sdp, name);
1712 if (!gl)
1713 return;

--- 94 unchanged lines hidden (view full) ---

1808{
1809 struct gfs2_sbd *sdp = gl->gl_sbd;
1810 const struct gfs2_glock_operations *glops = gl->gl_ops;
1811 int demote = 1;
1812
1813 if (test_bit(GLF_STICKY, &gl->gl_flags))
1814 demote = 0;
1815 else if (test_bit(GLF_PREFETCH, &gl->gl_flags))
1682static void blocking_cb(struct gfs2_sbd *sdp, struct lm_lockname *name,
1683 unsigned int state)
1684{
1685 struct gfs2_glock *gl;
1686
1687 gl = gfs2_glock_find(sdp, name);
1688 if (!gl)
1689 return;

--- 94 unchanged lines hidden (view full) ---

1784{
1785 struct gfs2_sbd *sdp = gl->gl_sbd;
1786 const struct gfs2_glock_operations *glops = gl->gl_ops;
1787 int demote = 1;
1788
1789 if (test_bit(GLF_STICKY, &gl->gl_flags))
1790 demote = 0;
1791 else if (test_bit(GLF_PREFETCH, &gl->gl_flags))
1816 demote = time_after_eq(jiffies,
1817 gl->gl_stamp +
1792 demote = time_after_eq(jiffies, gl->gl_stamp +
1818 gfs2_tune_get(sdp, gt_prefetch_secs) * HZ);
1819 else if (glops->go_demote_ok)
1820 demote = glops->go_demote_ok(gl);
1821
1822 return demote;
1823}
1824
1825/**

--- 41 unchanged lines hidden (view full) ---

1867 list_del_init(&gl->gl_reclaim);
1868 spin_unlock(&sdp->sd_reclaim_lock);
1869
1870 atomic_dec(&sdp->sd_reclaim_count);
1871 atomic_inc(&sdp->sd_reclaimed);
1872
1873 if (gfs2_glmutex_trylock(gl)) {
1874 if (queue_empty(gl, &gl->gl_holders) &&
1793 gfs2_tune_get(sdp, gt_prefetch_secs) * HZ);
1794 else if (glops->go_demote_ok)
1795 demote = glops->go_demote_ok(gl);
1796
1797 return demote;
1798}
1799
1800/**

--- 41 unchanged lines hidden (view full) ---

1842 list_del_init(&gl->gl_reclaim);
1843 spin_unlock(&sdp->sd_reclaim_lock);
1844
1845 atomic_dec(&sdp->sd_reclaim_count);
1846 atomic_inc(&sdp->sd_reclaimed);
1847
1848 if (gfs2_glmutex_trylock(gl)) {
1849 if (queue_empty(gl, &gl->gl_holders) &&
1875 gl->gl_state != LM_ST_UNLOCKED &&
1876 demote_ok(gl))
1850 gl->gl_state != LM_ST_UNLOCKED && demote_ok(gl))
1877 handle_callback(gl, LM_ST_UNLOCKED);
1878 gfs2_glmutex_unlock(gl);
1879 }
1880
1881 gfs2_glock_put(gl);
1882}
1883
1884/**

--- 146 unchanged lines hidden (view full) ---

2031 int cont;
2032
2033 t = jiffies;
2034
2035 for (;;) {
2036 cont = 0;
2037
2038 for (x = 0; x < GFS2_GL_HASH_SIZE; x++)
1851 handle_callback(gl, LM_ST_UNLOCKED);
1852 gfs2_glmutex_unlock(gl);
1853 }
1854
1855 gfs2_glock_put(gl);
1856}
1857
1858/**

--- 146 unchanged lines hidden (view full) ---

2005 int cont;
2006
2007 t = jiffies;
2008
2009 for (;;) {
2010 cont = 0;
2011
2012 for (x = 0; x < GFS2_GL_HASH_SIZE; x++)
2039 if (examine_bucket(clear_glock, sdp,
2040 &sdp->sd_gl_hash[x]))
2013 if (examine_bucket(clear_glock, sdp, &sdp->sd_gl_hash[x]))
2041 cont = 1;
2042
2043 if (!wait || !cont)
2044 break;
2045
2046 if (time_after_eq(jiffies,
2047 t + gfs2_tune_get(sdp, gt_stall_secs) * HZ)) {
2048 fs_warn(sdp, "Unmount seems to be stalled. "

--- 206 unchanged lines hidden ---
2014 cont = 1;
2015
2016 if (!wait || !cont)
2017 break;
2018
2019 if (time_after_eq(jiffies,
2020 t + gfs2_tune_get(sdp, gt_stall_secs) * HZ)) {
2021 fs_warn(sdp, "Unmount seems to be stalled. "

--- 206 unchanged lines hidden ---