18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
28c2ecf20Sopenharmony_ci/* -*- mode: c; c-basic-offset: 8; -*-
38c2ecf20Sopenharmony_ci * vim: noexpandtab sw=8 ts=8 sts=0:
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * userdlm.h
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci * Userspace dlm defines
88c2ecf20Sopenharmony_ci *
98c2ecf20Sopenharmony_ci * Copyright (C) 2002, 2004 Oracle.  All rights reserved.
108c2ecf20Sopenharmony_ci */
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ci#ifndef USERDLM_H
148c2ecf20Sopenharmony_ci#define USERDLM_H
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_ci#include <linux/module.h>
178c2ecf20Sopenharmony_ci#include <linux/fs.h>
188c2ecf20Sopenharmony_ci#include <linux/types.h>
198c2ecf20Sopenharmony_ci#include <linux/workqueue.h>
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci/* user_lock_res->l_flags flags. */
228c2ecf20Sopenharmony_ci#define USER_LOCK_ATTACHED      (0x00000001) /* we have initialized
238c2ecf20Sopenharmony_ci					       * the lvb */
248c2ecf20Sopenharmony_ci#define USER_LOCK_BUSY          (0x00000002) /* we are currently in
258c2ecf20Sopenharmony_ci					       * dlm_lock */
268c2ecf20Sopenharmony_ci#define USER_LOCK_BLOCKED       (0x00000004) /* blocked waiting to
278c2ecf20Sopenharmony_ci					      * downconvert*/
288c2ecf20Sopenharmony_ci#define USER_LOCK_IN_TEARDOWN   (0x00000008) /* we're currently
298c2ecf20Sopenharmony_ci					      * destroying this
308c2ecf20Sopenharmony_ci					      * lock. */
318c2ecf20Sopenharmony_ci#define USER_LOCK_QUEUED        (0x00000010) /* lock is on the
328c2ecf20Sopenharmony_ci					      * workqueue */
338c2ecf20Sopenharmony_ci#define USER_LOCK_IN_CANCEL     (0x00000020)
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_cistruct user_lock_res {
368c2ecf20Sopenharmony_ci	spinlock_t               l_lock;
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci	int                      l_flags;
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_ci#define USER_DLM_LOCK_ID_MAX_LEN  32
418c2ecf20Sopenharmony_ci	char                     l_name[USER_DLM_LOCK_ID_MAX_LEN];
428c2ecf20Sopenharmony_ci	int                      l_namelen;
438c2ecf20Sopenharmony_ci	int                      l_level;
448c2ecf20Sopenharmony_ci	unsigned int             l_ro_holders;
458c2ecf20Sopenharmony_ci	unsigned int             l_ex_holders;
468c2ecf20Sopenharmony_ci	struct ocfs2_dlm_lksb    l_lksb;
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_ci	int                      l_requested;
498c2ecf20Sopenharmony_ci	int                      l_blocking;
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_ci	wait_queue_head_t        l_event;
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_ci	struct work_struct       l_work;
548c2ecf20Sopenharmony_ci};
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_ciextern struct workqueue_struct *user_dlm_worker;
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_civoid user_dlm_lock_res_init(struct user_lock_res *lockres,
598c2ecf20Sopenharmony_ci			    struct dentry *dentry);
608c2ecf20Sopenharmony_ciint user_dlm_destroy_lock(struct user_lock_res *lockres);
618c2ecf20Sopenharmony_ciint user_dlm_cluster_lock(struct user_lock_res *lockres,
628c2ecf20Sopenharmony_ci			  int level,
638c2ecf20Sopenharmony_ci			  int lkm_flags);
648c2ecf20Sopenharmony_civoid user_dlm_cluster_unlock(struct user_lock_res *lockres,
658c2ecf20Sopenharmony_ci			     int level);
668c2ecf20Sopenharmony_civoid user_dlm_write_lvb(struct inode *inode,
678c2ecf20Sopenharmony_ci			const char *val,
688c2ecf20Sopenharmony_ci			unsigned int len);
698c2ecf20Sopenharmony_cibool user_dlm_read_lvb(struct inode *inode, char *val);
708c2ecf20Sopenharmony_cistruct ocfs2_cluster_connection *user_dlm_register(const struct qstr *name);
718c2ecf20Sopenharmony_civoid user_dlm_unregister(struct ocfs2_cluster_connection *conn);
728c2ecf20Sopenharmony_civoid user_dlm_set_locking_protocol(void);
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_cistruct dlmfs_inode_private {
758c2ecf20Sopenharmony_ci	struct ocfs2_cluster_connection	*ip_conn;
768c2ecf20Sopenharmony_ci
778c2ecf20Sopenharmony_ci	struct user_lock_res ip_lockres; /* unused for directories. */
788c2ecf20Sopenharmony_ci	struct inode         *ip_parent;
798c2ecf20Sopenharmony_ci
808c2ecf20Sopenharmony_ci	struct inode         ip_vfs_inode;
818c2ecf20Sopenharmony_ci};
828c2ecf20Sopenharmony_ci
838c2ecf20Sopenharmony_cistatic inline struct dlmfs_inode_private *
848c2ecf20Sopenharmony_ciDLMFS_I(struct inode *inode)
858c2ecf20Sopenharmony_ci{
868c2ecf20Sopenharmony_ci        return container_of(inode,
878c2ecf20Sopenharmony_ci			    struct dlmfs_inode_private,
888c2ecf20Sopenharmony_ci			    ip_vfs_inode);
898c2ecf20Sopenharmony_ci}
908c2ecf20Sopenharmony_ci
918c2ecf20Sopenharmony_cistruct dlmfs_filp_private {
928c2ecf20Sopenharmony_ci	int                  fp_lock_level;
938c2ecf20Sopenharmony_ci};
948c2ecf20Sopenharmony_ci
958c2ecf20Sopenharmony_ci#define DLMFS_MAGIC	0x76a9f425
968c2ecf20Sopenharmony_ci
978c2ecf20Sopenharmony_ci#endif /* USERDLM_H */
98