1328970deSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-or-later */
2*fa60ce2cSMasahiro Yamada /*
334a9dd7eSJoel Becker * userdlm.h
434a9dd7eSJoel Becker *
534a9dd7eSJoel Becker * Userspace dlm defines
634a9dd7eSJoel Becker *
734a9dd7eSJoel Becker * Copyright (C) 2002, 2004 Oracle. All rights reserved.
834a9dd7eSJoel Becker */
934a9dd7eSJoel Becker
1034a9dd7eSJoel Becker
1134a9dd7eSJoel Becker #ifndef USERDLM_H
1234a9dd7eSJoel Becker #define USERDLM_H
1334a9dd7eSJoel Becker
1434a9dd7eSJoel Becker #include <linux/module.h>
1534a9dd7eSJoel Becker #include <linux/fs.h>
1634a9dd7eSJoel Becker #include <linux/types.h>
1734a9dd7eSJoel Becker #include <linux/workqueue.h>
1834a9dd7eSJoel Becker
1934a9dd7eSJoel Becker /* user_lock_res->l_flags flags. */
2034a9dd7eSJoel Becker #define USER_LOCK_ATTACHED (0x00000001) /* we have initialized
2134a9dd7eSJoel Becker * the lvb */
2234a9dd7eSJoel Becker #define USER_LOCK_BUSY (0x00000002) /* we are currently in
2334a9dd7eSJoel Becker * dlm_lock */
2434a9dd7eSJoel Becker #define USER_LOCK_BLOCKED (0x00000004) /* blocked waiting to
2534a9dd7eSJoel Becker * downconvert*/
2634a9dd7eSJoel Becker #define USER_LOCK_IN_TEARDOWN (0x00000008) /* we're currently
2734a9dd7eSJoel Becker * destroying this
2834a9dd7eSJoel Becker * lock. */
2934a9dd7eSJoel Becker #define USER_LOCK_QUEUED (0x00000010) /* lock is on the
3034a9dd7eSJoel Becker * workqueue */
3134a9dd7eSJoel Becker #define USER_LOCK_IN_CANCEL (0x00000020)
3234a9dd7eSJoel Becker
3334a9dd7eSJoel Becker struct user_lock_res {
3434a9dd7eSJoel Becker spinlock_t l_lock;
3534a9dd7eSJoel Becker
3634a9dd7eSJoel Becker int l_flags;
3734a9dd7eSJoel Becker
3834a9dd7eSJoel Becker #define USER_DLM_LOCK_ID_MAX_LEN 32
3934a9dd7eSJoel Becker char l_name[USER_DLM_LOCK_ID_MAX_LEN];
4034a9dd7eSJoel Becker int l_namelen;
4134a9dd7eSJoel Becker int l_level;
4234a9dd7eSJoel Becker unsigned int l_ro_holders;
4334a9dd7eSJoel Becker unsigned int l_ex_holders;
440016eedcSJoel Becker struct ocfs2_dlm_lksb l_lksb;
4534a9dd7eSJoel Becker
4634a9dd7eSJoel Becker int l_requested;
4734a9dd7eSJoel Becker int l_blocking;
4834a9dd7eSJoel Becker
4934a9dd7eSJoel Becker wait_queue_head_t l_event;
5034a9dd7eSJoel Becker
5134a9dd7eSJoel Becker struct work_struct l_work;
5234a9dd7eSJoel Becker };
5334a9dd7eSJoel Becker
5434a9dd7eSJoel Becker extern struct workqueue_struct *user_dlm_worker;
5534a9dd7eSJoel Becker
5634a9dd7eSJoel Becker void user_dlm_lock_res_init(struct user_lock_res *lockres,
5734a9dd7eSJoel Becker struct dentry *dentry);
5834a9dd7eSJoel Becker int user_dlm_destroy_lock(struct user_lock_res *lockres);
5934a9dd7eSJoel Becker int user_dlm_cluster_lock(struct user_lock_res *lockres,
6034a9dd7eSJoel Becker int level,
6134a9dd7eSJoel Becker int lkm_flags);
6234a9dd7eSJoel Becker void user_dlm_cluster_unlock(struct user_lock_res *lockres,
6334a9dd7eSJoel Becker int level);
6434a9dd7eSJoel Becker void user_dlm_write_lvb(struct inode *inode,
6534a9dd7eSJoel Becker const char *val,
6634a9dd7eSJoel Becker unsigned int len);
67067c054fSAl Viro bool user_dlm_read_lvb(struct inode *inode, char *val);
68612645f7SAl Viro struct ocfs2_cluster_connection *user_dlm_register(const struct qstr *name);
690016eedcSJoel Becker void user_dlm_unregister(struct ocfs2_cluster_connection *conn);
700016eedcSJoel Becker void user_dlm_set_locking_protocol(void);
7134a9dd7eSJoel Becker
7234a9dd7eSJoel Becker struct dlmfs_inode_private {
730016eedcSJoel Becker struct ocfs2_cluster_connection *ip_conn;
7434a9dd7eSJoel Becker
7534a9dd7eSJoel Becker struct user_lock_res ip_lockres; /* unused for directories. */
7634a9dd7eSJoel Becker struct inode *ip_parent;
7734a9dd7eSJoel Becker
7834a9dd7eSJoel Becker struct inode ip_vfs_inode;
7934a9dd7eSJoel Becker };
8034a9dd7eSJoel Becker
8134a9dd7eSJoel Becker static inline struct dlmfs_inode_private *
DLMFS_I(struct inode * inode)8234a9dd7eSJoel Becker DLMFS_I(struct inode *inode)
8334a9dd7eSJoel Becker {
8434a9dd7eSJoel Becker return container_of(inode,
8534a9dd7eSJoel Becker struct dlmfs_inode_private,
8634a9dd7eSJoel Becker ip_vfs_inode);
8734a9dd7eSJoel Becker }
8834a9dd7eSJoel Becker
8934a9dd7eSJoel Becker struct dlmfs_filp_private {
9034a9dd7eSJoel Becker int fp_lock_level;
9134a9dd7eSJoel Becker };
9234a9dd7eSJoel Becker
9334a9dd7eSJoel Becker #define DLMFS_MAGIC 0x76a9f425
9434a9dd7eSJoel Becker
9534a9dd7eSJoel Becker #endif /* USERDLM_H */
96