linux/fs/dlm/dlm_internal.h

/* SPDX-License-Identifier: GPL-2.0-only */
/******************************************************************************
*******************************************************************************
**
**  Copyright (C) Sistina Software, Inc.  1997-2003  All rights reserved.
**  Copyright (C) 2004-2011 Red Hat, Inc.  All rights reserved.
**
**
*******************************************************************************
******************************************************************************/

#ifndef __DLM_INTERNAL_DOT_H__
#define __DLM_INTERNAL_DOT_H__

/*
 * This is the main header file to be included in each DLM source file.
 */

#include <uapi/linux/dlm_device.h>
#include <linux/slab.h>
#include <linux/sched.h>
#include <linux/types.h>
#include <linux/ctype.h>
#include <linux/spinlock.h>
#include <linux/vmalloc.h>
#include <linux/list.h>
#include <linux/errno.h>
#include <linux/random.h>
#include <linux/delay.h>
#include <linux/socket.h>
#include <linux/kthread.h>
#include <linux/kobject.h>
#include <linux/kref.h>
#include <linux/kernel.h>
#include <linux/jhash.h>
#include <linux/miscdevice.h>
#include <linux/rhashtable.h>
#include <linux/mutex.h>
#include <linux/xarray.h>
#include <linux/ratelimit.h>
#include <linux/uaccess.h>

#include <linux/dlm.h>
#include "config.h"

struct dlm_ls;
struct dlm_lkb;
struct dlm_rsb;
struct dlm_member;
struct dlm_rsbtable;
struct dlm_recover;
struct dlm_header;
struct dlm_message;
struct dlm_rcom;
struct dlm_mhandle;
struct dlm_msg;

#define log_print(fmt, args...)
#define log_print_ratelimited(fmt, args...)
#define log_error(ls, fmt, args...)

#define log_rinfo(ls, fmt, args...)

#define log_debug(ls, fmt, args...)

#define log_limit(ls, fmt, args...)

#define DLM_ASSERT(x, do)

/*
 * Lockspace member (per node in a ls)
 */

struct dlm_member {};

/*
 * Save and manage recovery state for a lockspace.
 */

struct dlm_recover {};

/*
 * Pass input args to second stage locking function.
 */

struct dlm_args {};


/*
 * Lock block
 *
 * A lock can be one of three types:
 *
 * local copy      lock is mastered locally
 *                 (lkb_nodeid is zero and DLM_LKF_MSTCPY is not set)
 * process copy    lock is mastered on a remote node
 *                 (lkb_nodeid is non-zero and DLM_LKF_MSTCPY is not set)
 * master copy     master node's copy of a lock owned by remote node
 *                 (lkb_nodeid is non-zero and DLM_LKF_MSTCPY is set)
 *
 * lkb_exflags: a copy of the most recent flags arg provided to dlm_lock or
 * dlm_unlock.  The dlm does not modify these or use any private flags in
 * this field; it only contains DLM_LKF_ flags from dlm.h.  These flags
 * are sent as-is to the remote master when the lock is remote.
 *
 * lkb_flags: internal dlm flags (DLM_IFL_ prefix) from dlm_internal.h.
 * Some internal flags are shared between the master and process nodes;
 * these shared flags are kept in the lower two bytes.  One of these
 * flags set on the master copy will be propagated to the process copy
 * and v.v.  Other internal flags are private to the master or process
 * node (e.g. DLM_IFL_MSTCPY).  These are kept in the high two bytes.
 *
 * lkb_sbflags: status block flags.  These flags are copied directly into
 * the caller's lksb.sb_flags prior to the dlm_lock/dlm_unlock completion
 * ast.  All defined in dlm.h with DLM_SBF_ prefix.
 *
 * lkb_status: the lock status indicates which rsb queue the lock is
 * on, grant, convert, or wait.  DLM_LKSTS_ WAITING/GRANTED/CONVERT
 *
 * lkb_wait_type: the dlm message type (DLM_MSG_ prefix) for which a
 * reply is needed.  Only set when the lkb is on the lockspace waiters
 * list awaiting a reply from a remote node.
 *
 * lkb_nodeid: when the lkb is a local copy, nodeid is 0; when the lkb
 * is a master copy, nodeid specifies the remote lock holder, when the
 * lkb is a process copy, the nodeid specifies the lock master.
 */

/* lkb_status */

#define DLM_LKSTS_WAITING
#define DLM_LKSTS_GRANTED
#define DLM_LKSTS_CONVERT

/* lkb_iflags */

#define DLM_IFL_MSTCPY_BIT
#define __DLM_IFL_MIN_BIT
#define DLM_IFL_RESEND_BIT
#define DLM_IFL_DEAD_BIT
#define DLM_IFL_OVERLAP_UNLOCK_BIT
#define DLM_IFL_OVERLAP_CANCEL_BIT
#define DLM_IFL_ENDOFLIFE_BIT
#define DLM_IFL_DEADLOCK_CANCEL_BIT
#define __DLM_IFL_MAX_BIT

/* lkb_dflags */

#define DLM_DFL_USER_BIT
#define __DLM_DFL_MIN_BIT
#define DLM_DFL_ORPHAN_BIT
#define __DLM_DFL_MAX_BIT

#define DLM_CB_CAST
#define DLM_CB_BAST

/* much of this is just saving user space pointers associated with the
 * lock that we pass back to the user lib with an ast
 */

struct dlm_user_args {};

struct dlm_callback {};

struct dlm_lkb {};

/*
 * res_master_nodeid is "normal": 0 is unset/invalid, non-zero is the real
 * nodeid, even when nodeid is our_nodeid.
 *
 * res_nodeid is "odd": -1 is unset/invalid, zero means our_nodeid,
 * greater than zero when another nodeid.
 *
 * (TODO: remove res_nodeid and only use res_master_nodeid)
 */

struct dlm_rsb {};

/* dlm_master_lookup() flags */

#define DLM_LU_RECOVER_DIR
#define DLM_LU_RECOVER_MASTER

/* dlm_master_lookup() results */

#define DLM_LU_MATCH
#define DLM_LU_ADD

/* find_rsb() flags */

#define R_REQUEST
#define R_RECEIVE_REQUEST
#define R_RECEIVE_RECOVER

/* rsb_flags */

enum rsb_flags {};

static inline void rsb_set_flag(struct dlm_rsb *r, enum rsb_flags flag)
{}

static inline void rsb_clear_flag(struct dlm_rsb *r, enum rsb_flags flag)
{}

static inline int rsb_flag(struct dlm_rsb *r, enum rsb_flags flag)
{}


/* dlm_header is first element of all structs sent between nodes */

#define DLM_HEADER_MAJOR
#define DLM_HEADER_MINOR

#define DLM_VERSION_3_1
#define DLM_VERSION_3_2

#define DLM_HEADER_SLOTS

#define DLM_MSG
#define DLM_RCOM
#define DLM_OPTS
#define DLM_ACK
#define DLM_FIN

struct dlm_header {};

#define DLM_MSG_REQUEST
#define DLM_MSG_CONVERT
#define DLM_MSG_UNLOCK
#define DLM_MSG_CANCEL
#define DLM_MSG_REQUEST_REPLY
#define DLM_MSG_CONVERT_REPLY
#define DLM_MSG_UNLOCK_REPLY
#define DLM_MSG_CANCEL_REPLY
#define DLM_MSG_GRANT
#define DLM_MSG_BAST
#define DLM_MSG_LOOKUP
#define DLM_MSG_REMOVE
#define DLM_MSG_LOOKUP_REPLY
#define DLM_MSG_PURGE

struct dlm_message {};


#define DLM_RS_NODES
#define DLM_RS_NODES_ALL
#define DLM_RS_DIR
#define DLM_RS_DIR_ALL
#define DLM_RS_LOCKS
#define DLM_RS_LOCKS_ALL
#define DLM_RS_DONE
#define DLM_RS_DONE_ALL

#define DLM_RCOM_STATUS
#define DLM_RCOM_NAMES
#define DLM_RCOM_LOOKUP
#define DLM_RCOM_LOCK
#define DLM_RCOM_STATUS_REPLY
#define DLM_RCOM_NAMES_REPLY
#define DLM_RCOM_LOOKUP_REPLY
#define DLM_RCOM_LOCK_REPLY

struct dlm_rcom {};

struct dlm_opt_header {};

/* encapsulation header */
struct dlm_opts {};

dlm_packet;

#define DLM_RSF_NEED_SLOTS

/* RCOM_STATUS data */
struct rcom_status {};

/* RCOM_STATUS_REPLY data */
struct rcom_config {};

struct rcom_slot {};

struct rcom_lock {};

struct dlm_ls {};

/*
 * LSFL_RECOVER_STOP - dlm_ls_stop() sets this to tell dlm recovery routines
 * that they should abort what they're doing so new recovery can be started.
 *
 * LSFL_RECOVER_DOWN - dlm_ls_stop() sets this to tell dlm_recoverd that it
 * should do down_write() on the in_recovery rw_semaphore. (doing down_write
 * within dlm_ls_stop causes complaints about the lock acquired/released
 * in different contexts.)
 *
 * LSFL_RECOVER_LOCK - dlm_recoverd holds the in_recovery rw_semaphore.
 * It sets this after it is done with down_write() on the in_recovery
 * rw_semaphore and clears it after it has released the rw_semaphore.
 *
 * LSFL_RECOVER_WORK - dlm_ls_start() sets this to tell dlm_recoverd that it
 * should begin recovery of the lockspace.
 *
 * LSFL_RUNNING - set when normal locking activity is enabled.
 * dlm_ls_stop() clears this to tell dlm locking routines that they should
 * quit what they are doing so recovery can run.  dlm_recoverd sets
 * this after recovery is finished.
 */

#define LSFL_RECOVER_STOP
#define LSFL_RECOVER_DOWN
#define LSFL_RECOVER_LOCK
#define LSFL_RECOVER_WORK
#define LSFL_RUNNING

#define LSFL_RCOM_READY
#define LSFL_RCOM_WAIT
#define LSFL_UEVENT_WAIT
#define LSFL_CB_DELAY
#define LSFL_NODIR
#define LSFL_RECV_MSG_BLOCKED
#define LSFL_FS
#define LSFL_SOFTIRQ

#define DLM_PROC_FLAGS_CLOSING
#define DLM_PROC_FLAGS_COMPAT

/* locks list is kept so we can remove all a process's locks when it
   exits (or orphan those that are persistent) */

struct dlm_user_proc {};

static inline int dlm_locking_stopped(struct dlm_ls *ls)
{}

static inline int dlm_recovery_stopped(struct dlm_ls *ls)
{}

static inline int dlm_no_directory(struct dlm_ls *ls)
{}

/* takes a snapshot from dlm atomic flags */
static inline uint32_t dlm_flags_val(const unsigned long *addr,
				     uint32_t min, uint32_t max)
{}

static inline uint32_t dlm_iflags_val(const struct dlm_lkb *lkb)
{}

static inline uint32_t dlm_dflags_val(const struct dlm_lkb *lkb)
{}

/* coming from UAPI header
 *
 * TODO:
 * Move this to UAPI header and let other values point to them and use BIT()
 */
#define DLM_SBF_DEMOTED_BIT
#define __DLM_SBF_MIN_BIT
#define DLM_SBF_VALNOTVALID_BIT
#define DLM_SBF_ALTMODE_BIT
#define __DLM_SBF_MAX_BIT

static inline uint32_t dlm_sbflags_val(const struct dlm_lkb *lkb)
{}

static inline void dlm_set_flags_val(unsigned long *addr, uint32_t val,
				     uint32_t min, uint32_t max)
{}

static inline void dlm_set_dflags_val(struct dlm_lkb *lkb, uint32_t val)
{}

static inline void dlm_set_sbflags_val(struct dlm_lkb *lkb, uint32_t val)
{}

int dlm_plock_init(void);
void dlm_plock_exit(void);

#ifdef CONFIG_DLM_DEBUG
void dlm_register_debugfs(void);
void dlm_unregister_debugfs(void);
void dlm_create_debug_file(struct dlm_ls *ls);
void dlm_delete_debug_file(struct dlm_ls *ls);
void *dlm_create_debug_comms_file(int nodeid, void *data);
void dlm_delete_debug_comms_file(void *ctx);
#else
static inline void dlm_register_debugfs(void) { }
static inline void dlm_unregister_debugfs(void) { }
static inline void dlm_create_debug_file(struct dlm_ls *ls) { }
static inline void dlm_delete_debug_file(struct dlm_ls *ls) { }
static inline void *dlm_create_debug_comms_file(int nodeid, void *data) { return NULL; }
static inline void dlm_delete_debug_comms_file(void *ctx) { }
#endif

#endif				/* __DLM_INTERNAL_DOT_H__ */