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> 14f057f6cdSSteven Whitehouse #include <linux/parser.h> 15f2f7ba52SSteven Whitehouse #include "incore.h" 16f2f7ba52SSteven Whitehouse 17f057f6cdSSteven Whitehouse /* Options for hostdata parser */ 18f057f6cdSSteven Whitehouse 19f057f6cdSSteven Whitehouse enum { 20f057f6cdSSteven Whitehouse Opt_jid, 21f057f6cdSSteven Whitehouse Opt_id, 22f057f6cdSSteven Whitehouse Opt_first, 23f057f6cdSSteven Whitehouse Opt_nodir, 24f057f6cdSSteven Whitehouse Opt_err, 25f057f6cdSSteven Whitehouse }; 26f057f6cdSSteven Whitehouse 27f057f6cdSSteven Whitehouse /* 28f057f6cdSSteven Whitehouse * lm_lockname types 29f057f6cdSSteven Whitehouse */ 30f057f6cdSSteven Whitehouse 31f057f6cdSSteven Whitehouse #define LM_TYPE_RESERVED 0x00 32f057f6cdSSteven Whitehouse #define LM_TYPE_NONDISK 0x01 33f057f6cdSSteven Whitehouse #define LM_TYPE_INODE 0x02 34f057f6cdSSteven Whitehouse #define LM_TYPE_RGRP 0x03 35f057f6cdSSteven Whitehouse #define LM_TYPE_META 0x04 36f057f6cdSSteven Whitehouse #define LM_TYPE_IOPEN 0x05 37f057f6cdSSteven Whitehouse #define LM_TYPE_FLOCK 0x06 38f057f6cdSSteven Whitehouse #define LM_TYPE_PLOCK 0x07 39f057f6cdSSteven Whitehouse #define LM_TYPE_QUOTA 0x08 40f057f6cdSSteven Whitehouse #define LM_TYPE_JOURNAL 0x09 41f057f6cdSSteven Whitehouse 42f057f6cdSSteven Whitehouse /* 43f057f6cdSSteven Whitehouse * lm_lock() states 44f057f6cdSSteven Whitehouse * 45f057f6cdSSteven Whitehouse * SHARED is compatible with SHARED, not with DEFERRED or EX. 46f057f6cdSSteven Whitehouse * DEFERRED is compatible with DEFERRED, not with SHARED or EX. 47f057f6cdSSteven Whitehouse */ 48f057f6cdSSteven Whitehouse 49f057f6cdSSteven Whitehouse #define LM_ST_UNLOCKED 0 50f057f6cdSSteven Whitehouse #define LM_ST_EXCLUSIVE 1 51f057f6cdSSteven Whitehouse #define LM_ST_DEFERRED 2 52f057f6cdSSteven Whitehouse #define LM_ST_SHARED 3 53f057f6cdSSteven Whitehouse 54f057f6cdSSteven Whitehouse /* 55f057f6cdSSteven Whitehouse * lm_lock() flags 56f057f6cdSSteven Whitehouse * 57f057f6cdSSteven Whitehouse * LM_FLAG_TRY 58f057f6cdSSteven Whitehouse * Don't wait to acquire the lock if it can't be granted immediately. 59f057f6cdSSteven Whitehouse * 60f057f6cdSSteven Whitehouse * LM_FLAG_TRY_1CB 61f057f6cdSSteven Whitehouse * Send one blocking callback if TRY is set and the lock is not granted. 62f057f6cdSSteven Whitehouse * 63f057f6cdSSteven Whitehouse * LM_FLAG_NOEXP 64f057f6cdSSteven Whitehouse * GFS sets this flag on lock requests it makes while doing journal recovery. 65f057f6cdSSteven Whitehouse * These special requests should not be blocked due to the recovery like 66f057f6cdSSteven Whitehouse * ordinary locks would be. 67f057f6cdSSteven Whitehouse * 68f057f6cdSSteven Whitehouse * LM_FLAG_ANY 69f057f6cdSSteven Whitehouse * A SHARED request may also be granted in DEFERRED, or a DEFERRED request may 70f057f6cdSSteven Whitehouse * also be granted in SHARED. The preferred state is whichever is compatible 71f057f6cdSSteven Whitehouse * with other granted locks, or the specified state if no other locks exist. 72f057f6cdSSteven Whitehouse * 73f057f6cdSSteven Whitehouse * LM_FLAG_PRIORITY 74f057f6cdSSteven Whitehouse * Override fairness considerations. Suppose a lock is held in a shared state 75f057f6cdSSteven Whitehouse * and there is a pending request for the deferred state. A shared lock 76f057f6cdSSteven Whitehouse * request with the priority flag would be allowed to bypass the deferred 77f057f6cdSSteven Whitehouse * request and directly join the other shared lock. A shared lock request 78f057f6cdSSteven Whitehouse * without the priority flag might be forced to wait until the deferred 79f057f6cdSSteven Whitehouse * requested had acquired and released the lock. 80f057f6cdSSteven Whitehouse */ 81f057f6cdSSteven Whitehouse 82b3b94faaSDavid Teigland #define LM_FLAG_TRY 0x00000001 83b3b94faaSDavid Teigland #define LM_FLAG_TRY_1CB 0x00000002 84b3b94faaSDavid Teigland #define LM_FLAG_NOEXP 0x00000004 85b3b94faaSDavid Teigland #define LM_FLAG_ANY 0x00000008 86f057f6cdSSteven Whitehouse #define LM_FLAG_PRIORITY 0x00000010 87f057f6cdSSteven Whitehouse #define GL_ASYNC 0x00000040 88f057f6cdSSteven Whitehouse #define GL_EXACT 0x00000080 89f057f6cdSSteven Whitehouse #define GL_SKIP 0x00000100 90f057f6cdSSteven Whitehouse #define GL_ATIME 0x00000200 91f057f6cdSSteven Whitehouse #define GL_NOCACHE 0x00000400 92f057f6cdSSteven Whitehouse 93f057f6cdSSteven Whitehouse /* 94f057f6cdSSteven Whitehouse * lm_lock() and lm_async_cb return flags 95f057f6cdSSteven Whitehouse * 96f057f6cdSSteven Whitehouse * LM_OUT_ST_MASK 97f057f6cdSSteven Whitehouse * Masks the lower two bits of lock state in the returned value. 98f057f6cdSSteven Whitehouse * 99f057f6cdSSteven Whitehouse * LM_OUT_CANCELED 100f057f6cdSSteven Whitehouse * The lock request was canceled. 101f057f6cdSSteven Whitehouse * 102f057f6cdSSteven Whitehouse * LM_OUT_ASYNC 103f057f6cdSSteven Whitehouse * The result of the request will be returned in an LM_CB_ASYNC callback. 104f057f6cdSSteven Whitehouse * 105f057f6cdSSteven Whitehouse */ 106f057f6cdSSteven Whitehouse 107f057f6cdSSteven Whitehouse #define LM_OUT_ST_MASK 0x00000003 108f057f6cdSSteven Whitehouse #define LM_OUT_CANCELED 0x00000008 109f057f6cdSSteven Whitehouse #define LM_OUT_ASYNC 0x00000080 110f057f6cdSSteven Whitehouse #define LM_OUT_ERROR 0x00000100 111f057f6cdSSteven Whitehouse 112f057f6cdSSteven Whitehouse /* 113f057f6cdSSteven Whitehouse * lm_recovery_done() messages 114f057f6cdSSteven Whitehouse */ 115f057f6cdSSteven Whitehouse 116f057f6cdSSteven Whitehouse #define LM_RD_GAVEUP 308 117f057f6cdSSteven Whitehouse #define LM_RD_SUCCESS 309 118f057f6cdSSteven Whitehouse 119f057f6cdSSteven Whitehouse #define GLR_TRYFAILED 13 120f057f6cdSSteven Whitehouse 121f057f6cdSSteven Whitehouse struct lm_lockops { 122f057f6cdSSteven Whitehouse const char *lm_proto_name; 123f057f6cdSSteven Whitehouse int (*lm_mount) (struct gfs2_sbd *sdp, const char *fsname); 124f057f6cdSSteven Whitehouse void (*lm_unmount) (struct gfs2_sbd *sdp); 125f057f6cdSSteven Whitehouse void (*lm_withdraw) (struct gfs2_sbd *sdp); 1268f05228eSSteven Whitehouse void (*lm_put_lock) (struct kmem_cache *cachep, struct gfs2_glock *gl); 127f057f6cdSSteven Whitehouse unsigned int (*lm_lock) (struct gfs2_glock *gl, 128f057f6cdSSteven Whitehouse unsigned int req_state, unsigned int flags); 129f057f6cdSSteven Whitehouse void (*lm_cancel) (struct gfs2_glock *gl); 130f057f6cdSSteven Whitehouse const match_table_t *lm_tokens; 131f057f6cdSSteven Whitehouse }; 132f057f6cdSSteven Whitehouse 133f057f6cdSSteven Whitehouse #define LM_FLAG_TRY 0x00000001 134f057f6cdSSteven Whitehouse #define LM_FLAG_TRY_1CB 0x00000002 135f057f6cdSSteven Whitehouse #define LM_FLAG_NOEXP 0x00000004 136f057f6cdSSteven Whitehouse #define LM_FLAG_ANY 0x00000008 137f057f6cdSSteven Whitehouse #define LM_FLAG_PRIORITY 0x00000010 138b3b94faaSDavid Teigland 139b3b94faaSDavid Teigland #define GL_ASYNC 0x00000040 140b3b94faaSDavid Teigland #define GL_EXACT 0x00000080 141b3b94faaSDavid Teigland #define GL_SKIP 0x00000100 142b3b94faaSDavid Teigland #define GL_NOCACHE 0x00000400 143b3b94faaSDavid Teigland 144b3b94faaSDavid Teigland #define GLR_TRYFAILED 13 145b3b94faaSDavid Teigland 146b94a170eSBenjamin Marzinski extern struct workqueue_struct *gfs2_delete_workqueue; 1477afd88d9SSteven Whitehouse static inline struct gfs2_holder *gfs2_glock_is_locked_by_me(struct gfs2_glock *gl) 148b3b94faaSDavid Teigland { 149b3b94faaSDavid Teigland struct gfs2_holder *gh; 150b1e058daSPavel Emelyanov struct pid *pid; 151b3b94faaSDavid Teigland 152b3b94faaSDavid Teigland /* Look in glock's list of holders for one with current task as owner */ 153b3b94faaSDavid Teigland spin_lock(&gl->gl_spin); 154b1e058daSPavel Emelyanov pid = task_pid(current); 155b3b94faaSDavid Teigland list_for_each_entry(gh, &gl->gl_holders, gh_list) { 1566802e340SSteven Whitehouse if (!test_bit(HIF_HOLDER, &gh->gh_iflags)) 1576802e340SSteven Whitehouse break; 1587afd88d9SSteven Whitehouse if (gh->gh_owner_pid == pid) 1597afd88d9SSteven Whitehouse goto out; 160b3b94faaSDavid Teigland } 1617afd88d9SSteven Whitehouse gh = NULL; 1627afd88d9SSteven Whitehouse out: 163b3b94faaSDavid Teigland spin_unlock(&gl->gl_spin); 164b3b94faaSDavid Teigland 1657afd88d9SSteven Whitehouse return gh; 166b3b94faaSDavid Teigland } 167b3b94faaSDavid Teigland 168b3b94faaSDavid Teigland static inline int gfs2_glock_is_held_excl(struct gfs2_glock *gl) 169b3b94faaSDavid Teigland { 17050299965SSteven Whitehouse return gl->gl_state == LM_ST_EXCLUSIVE; 171b3b94faaSDavid Teigland } 172b3b94faaSDavid Teigland 173b3b94faaSDavid Teigland static inline int gfs2_glock_is_held_dfrd(struct gfs2_glock *gl) 174b3b94faaSDavid Teigland { 17550299965SSteven Whitehouse return gl->gl_state == LM_ST_DEFERRED; 176b3b94faaSDavid Teigland } 177b3b94faaSDavid Teigland 178b3b94faaSDavid Teigland static inline int gfs2_glock_is_held_shrd(struct gfs2_glock *gl) 179b3b94faaSDavid Teigland { 18050299965SSteven Whitehouse return gl->gl_state == LM_ST_SHARED; 181b3b94faaSDavid Teigland } 182b3b94faaSDavid Teigland 183009d8518SSteven Whitehouse static inline struct address_space *gfs2_glock2aspace(struct gfs2_glock *gl) 184009d8518SSteven Whitehouse { 185009d8518SSteven Whitehouse if (gl->gl_ops->go_flags & GLOF_ASPACE) 186009d8518SSteven Whitehouse return (struct address_space *)(gl + 1); 187009d8518SSteven Whitehouse return NULL; 188009d8518SSteven Whitehouse } 189009d8518SSteven Whitehouse 190b3b94faaSDavid Teigland int gfs2_glock_get(struct gfs2_sbd *sdp, 191cd915493SSteven Whitehouse u64 number, const struct gfs2_glock_operations *glops, 192b3b94faaSDavid Teigland int create, struct gfs2_glock **glp); 193b94a170eSBenjamin Marzinski void gfs2_glock_hold(struct gfs2_glock *gl); 194b94a170eSBenjamin Marzinski void gfs2_glock_put_nolock(struct gfs2_glock *gl); 195b3b94faaSDavid Teigland int gfs2_glock_put(struct gfs2_glock *gl); 196190562bdSSteven Whitehouse void gfs2_holder_init(struct gfs2_glock *gl, unsigned int state, unsigned flags, 197b3b94faaSDavid Teigland struct gfs2_holder *gh); 198190562bdSSteven Whitehouse void gfs2_holder_reinit(unsigned int state, unsigned flags, 199190562bdSSteven Whitehouse struct gfs2_holder *gh); 200b3b94faaSDavid Teigland void gfs2_holder_uninit(struct gfs2_holder *gh); 201b3b94faaSDavid Teigland int gfs2_glock_nq(struct gfs2_holder *gh); 202b3b94faaSDavid Teigland int gfs2_glock_poll(struct gfs2_holder *gh); 203b3b94faaSDavid Teigland int gfs2_glock_wait(struct gfs2_holder *gh); 204b3b94faaSDavid Teigland void gfs2_glock_dq(struct gfs2_holder *gh); 205d93cfa98SAbhijith Das void gfs2_glock_dq_wait(struct gfs2_holder *gh); 206b3b94faaSDavid Teigland 207b3b94faaSDavid Teigland void gfs2_glock_dq_uninit(struct gfs2_holder *gh); 208b3b94faaSDavid Teigland int gfs2_glock_nq_num(struct gfs2_sbd *sdp, 209cd915493SSteven Whitehouse u64 number, const struct gfs2_glock_operations *glops, 210b3b94faaSDavid Teigland unsigned int state, int flags, struct gfs2_holder *gh); 211b3b94faaSDavid Teigland 212b3b94faaSDavid Teigland int gfs2_glock_nq_m(unsigned int num_gh, struct gfs2_holder *ghs); 213b3b94faaSDavid Teigland void gfs2_glock_dq_m(unsigned int num_gh, struct gfs2_holder *ghs); 214b3b94faaSDavid Teigland void gfs2_glock_dq_uninit_m(unsigned int num_gh, struct gfs2_holder *ghs); 215edc221d0SJoe Perches 216edc221d0SJoe Perches __attribute__ ((format(printf, 2, 3))) 2176802e340SSteven Whitehouse void gfs2_print_dbg(struct seq_file *seq, const char *fmt, ...); 218b3b94faaSDavid Teigland 219d0dc80dbSSteven Whitehouse /** 22033027af6SAndrea Gelmini * gfs2_glock_nq_init - initialize a holder and enqueue it on a glock 221d0dc80dbSSteven Whitehouse * @gl: the glock 222d0dc80dbSSteven Whitehouse * @state: the state we're requesting 223d0dc80dbSSteven Whitehouse * @flags: the modifier flags 224d0dc80dbSSteven Whitehouse * @gh: the holder structure 225d0dc80dbSSteven Whitehouse * 226d0dc80dbSSteven Whitehouse * Returns: 0, GLR_*, or errno 227d0dc80dbSSteven Whitehouse */ 228d0dc80dbSSteven Whitehouse 229d0dc80dbSSteven Whitehouse static inline int gfs2_glock_nq_init(struct gfs2_glock *gl, 230d0dc80dbSSteven Whitehouse unsigned int state, int flags, 231d0dc80dbSSteven Whitehouse struct gfs2_holder *gh) 232d0dc80dbSSteven Whitehouse { 233d0dc80dbSSteven Whitehouse int error; 234d0dc80dbSSteven Whitehouse 235d0dc80dbSSteven Whitehouse gfs2_holder_init(gl, state, flags, gh); 236d0dc80dbSSteven Whitehouse 237d0dc80dbSSteven Whitehouse error = gfs2_glock_nq(gh); 238d0dc80dbSSteven Whitehouse if (error) 239d0dc80dbSSteven Whitehouse gfs2_holder_uninit(gh); 240d0dc80dbSSteven Whitehouse 241d0dc80dbSSteven Whitehouse return error; 242d0dc80dbSSteven Whitehouse } 243d0dc80dbSSteven Whitehouse 244b3b94faaSDavid Teigland /* Lock Value Block functions */ 245b3b94faaSDavid Teigland 246b3b94faaSDavid Teigland int gfs2_lvb_hold(struct gfs2_glock *gl); 247b3b94faaSDavid Teigland void gfs2_lvb_unhold(struct gfs2_glock *gl); 248b3b94faaSDavid Teigland 249f057f6cdSSteven Whitehouse void gfs2_glock_cb(struct gfs2_glock *gl, unsigned int state); 250f057f6cdSSteven Whitehouse void gfs2_glock_complete(struct gfs2_glock *gl, int ret); 251b3b94faaSDavid Teigland void gfs2_reclaim_glock(struct gfs2_sbd *sdp); 252fefc03bfSSteven Whitehouse void gfs2_gl_hash_clear(struct gfs2_sbd *sdp); 253813e0c46SSteven Whitehouse void gfs2_glock_finish_truncate(struct gfs2_inode *ip); 254f057f6cdSSteven Whitehouse void gfs2_glock_thaw(struct gfs2_sbd *sdp); 255b3b94faaSDavid Teigland 25685d1da67SSteven Whitehouse int __init gfs2_glock_init(void); 2578fbbfd21SSteven Whitehouse void gfs2_glock_exit(void); 2588fbbfd21SSteven Whitehouse 2597c52b166SRobert Peterson int gfs2_create_debugfs_file(struct gfs2_sbd *sdp); 2607c52b166SRobert Peterson void gfs2_delete_debugfs_file(struct gfs2_sbd *sdp); 2617c52b166SRobert Peterson int gfs2_register_debugfs(void); 2627c52b166SRobert Peterson void gfs2_unregister_debugfs(void); 26385d1da67SSteven Whitehouse 264f057f6cdSSteven Whitehouse extern const struct lm_lockops gfs2_dlm_ops; 265f057f6cdSSteven Whitehouse 266b3b94faaSDavid Teigland #endif /* __GLOCK_DOT_H__ */ 267