1b3b94faaSDavid Teigland /* 2b3b94faaSDavid Teigland * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. 33a8a9a10SSteven Whitehouse * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. 4b3b94faaSDavid Teigland * 5b3b94faaSDavid Teigland * This copyrighted material is made available to anyone wishing to use, 6b3b94faaSDavid Teigland * modify, copy, or redistribute it subject to the terms and conditions 7e9fc2aa0SSteven Whitehouse * of the GNU General Public License version 2. 8b3b94faaSDavid Teigland */ 9b3b94faaSDavid Teigland 10b3b94faaSDavid Teigland #ifndef __GLOCK_DOT_H__ 11b3b94faaSDavid Teigland #define __GLOCK_DOT_H__ 12b3b94faaSDavid Teigland 13e8edc6e0SAlexey Dobriyan #include <linux/sched.h> 14f2f7ba52SSteven Whitehouse #include "incore.h" 15f2f7ba52SSteven Whitehouse 16b3b94faaSDavid Teigland /* Flags for lock requests; used in gfs2_holder gh_flag field. 17b3b94faaSDavid Teigland From lm_interface.h: 18b3b94faaSDavid Teigland #define LM_FLAG_TRY 0x00000001 19b3b94faaSDavid Teigland #define LM_FLAG_TRY_1CB 0x00000002 20b3b94faaSDavid Teigland #define LM_FLAG_NOEXP 0x00000004 21b3b94faaSDavid Teigland #define LM_FLAG_ANY 0x00000008 22b3b94faaSDavid Teigland #define LM_FLAG_PRIORITY 0x00000010 */ 23b3b94faaSDavid Teigland 24b3b94faaSDavid Teigland #define GL_ASYNC 0x00000040 25b3b94faaSDavid Teigland #define GL_EXACT 0x00000080 26b3b94faaSDavid Teigland #define GL_SKIP 0x00000100 27b3b94faaSDavid Teigland #define GL_NOCACHE 0x00000400 28b3b94faaSDavid Teigland 29b3b94faaSDavid Teigland #define GLR_TRYFAILED 13 30b3b94faaSDavid Teigland 317afd88d9SSteven Whitehouse static inline struct gfs2_holder *gfs2_glock_is_locked_by_me(struct gfs2_glock *gl) 32b3b94faaSDavid Teigland { 33b3b94faaSDavid Teigland struct gfs2_holder *gh; 34b1e058daSPavel Emelyanov struct pid *pid; 35b3b94faaSDavid Teigland 36b3b94faaSDavid Teigland /* Look in glock's list of holders for one with current task as owner */ 37b3b94faaSDavid Teigland spin_lock(&gl->gl_spin); 38b1e058daSPavel Emelyanov pid = task_pid(current); 39b3b94faaSDavid Teigland list_for_each_entry(gh, &gl->gl_holders, gh_list) { 406802e340SSteven Whitehouse if (!test_bit(HIF_HOLDER, &gh->gh_iflags)) 416802e340SSteven Whitehouse break; 427afd88d9SSteven Whitehouse if (gh->gh_owner_pid == pid) 437afd88d9SSteven Whitehouse goto out; 44b3b94faaSDavid Teigland } 457afd88d9SSteven Whitehouse gh = NULL; 467afd88d9SSteven Whitehouse out: 47b3b94faaSDavid Teigland spin_unlock(&gl->gl_spin); 48b3b94faaSDavid Teigland 497afd88d9SSteven Whitehouse return gh; 50b3b94faaSDavid Teigland } 51b3b94faaSDavid Teigland 52b3b94faaSDavid Teigland static inline int gfs2_glock_is_held_excl(struct gfs2_glock *gl) 53b3b94faaSDavid Teigland { 5450299965SSteven Whitehouse return gl->gl_state == LM_ST_EXCLUSIVE; 55b3b94faaSDavid Teigland } 56b3b94faaSDavid Teigland 57b3b94faaSDavid Teigland static inline int gfs2_glock_is_held_dfrd(struct gfs2_glock *gl) 58b3b94faaSDavid Teigland { 5950299965SSteven Whitehouse return gl->gl_state == LM_ST_DEFERRED; 60b3b94faaSDavid Teigland } 61b3b94faaSDavid Teigland 62b3b94faaSDavid Teigland static inline int gfs2_glock_is_held_shrd(struct gfs2_glock *gl) 63b3b94faaSDavid Teigland { 6450299965SSteven Whitehouse return gl->gl_state == LM_ST_SHARED; 65b3b94faaSDavid Teigland } 66b3b94faaSDavid Teigland 67b3b94faaSDavid Teigland static inline int gfs2_glock_is_blocking(struct gfs2_glock *gl) 68b3b94faaSDavid Teigland { 69b3b94faaSDavid Teigland int ret; 70b3b94faaSDavid Teigland spin_lock(&gl->gl_spin); 716802e340SSteven Whitehouse ret = test_bit(GLF_DEMOTE, &gl->gl_flags); 72b3b94faaSDavid Teigland spin_unlock(&gl->gl_spin); 73b3b94faaSDavid Teigland return ret; 74b3b94faaSDavid Teigland } 75b3b94faaSDavid Teigland 76b3b94faaSDavid Teigland int gfs2_glock_get(struct gfs2_sbd *sdp, 77cd915493SSteven Whitehouse u64 number, const struct gfs2_glock_operations *glops, 78b3b94faaSDavid Teigland int create, struct gfs2_glock **glp); 79b3b94faaSDavid Teigland int gfs2_glock_put(struct gfs2_glock *gl); 80190562bdSSteven Whitehouse void gfs2_holder_init(struct gfs2_glock *gl, unsigned int state, unsigned flags, 81b3b94faaSDavid Teigland struct gfs2_holder *gh); 82190562bdSSteven Whitehouse void gfs2_holder_reinit(unsigned int state, unsigned flags, 83190562bdSSteven Whitehouse struct gfs2_holder *gh); 84b3b94faaSDavid Teigland void gfs2_holder_uninit(struct gfs2_holder *gh); 85b3b94faaSDavid Teigland int gfs2_glock_nq(struct gfs2_holder *gh); 86b3b94faaSDavid Teigland int gfs2_glock_poll(struct gfs2_holder *gh); 87b3b94faaSDavid Teigland int gfs2_glock_wait(struct gfs2_holder *gh); 88b3b94faaSDavid Teigland void gfs2_glock_dq(struct gfs2_holder *gh); 89d93cfa98SAbhijith Das void gfs2_glock_dq_wait(struct gfs2_holder *gh); 90b3b94faaSDavid Teigland 91b3b94faaSDavid Teigland void gfs2_glock_dq_uninit(struct gfs2_holder *gh); 92b3b94faaSDavid Teigland int gfs2_glock_nq_num(struct gfs2_sbd *sdp, 93cd915493SSteven Whitehouse u64 number, const struct gfs2_glock_operations *glops, 94b3b94faaSDavid Teigland unsigned int state, int flags, struct gfs2_holder *gh); 95b3b94faaSDavid Teigland 96b3b94faaSDavid Teigland int gfs2_glock_nq_m(unsigned int num_gh, struct gfs2_holder *ghs); 97b3b94faaSDavid Teigland void gfs2_glock_dq_m(unsigned int num_gh, struct gfs2_holder *ghs); 98b3b94faaSDavid Teigland void gfs2_glock_dq_uninit_m(unsigned int num_gh, struct gfs2_holder *ghs); 996802e340SSteven Whitehouse void gfs2_print_dbg(struct seq_file *seq, const char *fmt, ...); 100b3b94faaSDavid Teigland 101d0dc80dbSSteven Whitehouse /** 102d0dc80dbSSteven Whitehouse * gfs2_glock_nq_init - intialize a holder and enqueue it on a glock 103d0dc80dbSSteven Whitehouse * @gl: the glock 104d0dc80dbSSteven Whitehouse * @state: the state we're requesting 105d0dc80dbSSteven Whitehouse * @flags: the modifier flags 106d0dc80dbSSteven Whitehouse * @gh: the holder structure 107d0dc80dbSSteven Whitehouse * 108d0dc80dbSSteven Whitehouse * Returns: 0, GLR_*, or errno 109d0dc80dbSSteven Whitehouse */ 110d0dc80dbSSteven Whitehouse 111d0dc80dbSSteven Whitehouse static inline int gfs2_glock_nq_init(struct gfs2_glock *gl, 112d0dc80dbSSteven Whitehouse unsigned int state, int flags, 113d0dc80dbSSteven Whitehouse struct gfs2_holder *gh) 114d0dc80dbSSteven Whitehouse { 115d0dc80dbSSteven Whitehouse int error; 116d0dc80dbSSteven Whitehouse 117d0dc80dbSSteven Whitehouse gfs2_holder_init(gl, state, flags, gh); 118d0dc80dbSSteven Whitehouse 119d0dc80dbSSteven Whitehouse error = gfs2_glock_nq(gh); 120d0dc80dbSSteven Whitehouse if (error) 121d0dc80dbSSteven Whitehouse gfs2_holder_uninit(gh); 122d0dc80dbSSteven Whitehouse 123d0dc80dbSSteven Whitehouse return error; 124d0dc80dbSSteven Whitehouse } 125d0dc80dbSSteven Whitehouse 126b3b94faaSDavid Teigland /* Lock Value Block functions */ 127b3b94faaSDavid Teigland 128b3b94faaSDavid Teigland int gfs2_lvb_hold(struct gfs2_glock *gl); 129b3b94faaSDavid Teigland void gfs2_lvb_unhold(struct gfs2_glock *gl); 130b3b94faaSDavid Teigland 1319b47c11dSSteven Whitehouse void gfs2_glock_cb(void *cb_data, unsigned int type, void *data); 132b3b94faaSDavid Teigland void gfs2_reclaim_glock(struct gfs2_sbd *sdp); 133*fefc03bfSSteven Whitehouse void gfs2_gl_hash_clear(struct gfs2_sbd *sdp); 134813e0c46SSteven Whitehouse void gfs2_glock_finish_truncate(struct gfs2_inode *ip); 135b3b94faaSDavid Teigland 13685d1da67SSteven Whitehouse int __init gfs2_glock_init(void); 1378fbbfd21SSteven Whitehouse void gfs2_glock_exit(void); 1388fbbfd21SSteven Whitehouse 1397c52b166SRobert Peterson int gfs2_create_debugfs_file(struct gfs2_sbd *sdp); 1407c52b166SRobert Peterson void gfs2_delete_debugfs_file(struct gfs2_sbd *sdp); 1417c52b166SRobert Peterson int gfs2_register_debugfs(void); 1427c52b166SRobert Peterson void gfs2_unregister_debugfs(void); 14385d1da67SSteven Whitehouse 144b3b94faaSDavid Teigland #endif /* __GLOCK_DOT_H__ */ 145