linux/include/linux/dlm.h
<<
>>
Prefs
   1/* SPDX-License-Identifier: GPL-2.0-only */
   2/******************************************************************************
   3*******************************************************************************
   4**
   5**  Copyright (C) Sistina Software, Inc.  1997-2003  All rights reserved.
   6**  Copyright (C) 2004-2011 Red Hat, Inc.  All rights reserved.
   7**
   8**
   9*******************************************************************************
  10******************************************************************************/
  11#ifndef __DLM_DOT_H__
  12#define __DLM_DOT_H__
  13
  14#include <uapi/linux/dlm.h>
  15
  16
  17struct dlm_slot {
  18        int nodeid; /* 1 to MAX_INT */
  19        int slot;   /* 1 to MAX_INT */
  20};
  21
  22/*
  23 * recover_prep: called before the dlm begins lock recovery.
  24 *   Notfies lockspace user that locks from failed members will be granted.
  25 * recover_slot: called after recover_prep and before recover_done.
  26 *   Identifies a failed lockspace member.
  27 * recover_done: called after the dlm completes lock recovery.
  28 *   Identifies lockspace members and lockspace generation number.
  29 */
  30
  31struct dlm_lockspace_ops {
  32        void (*recover_prep) (void *ops_arg);
  33        void (*recover_slot) (void *ops_arg, struct dlm_slot *slot);
  34        void (*recover_done) (void *ops_arg, struct dlm_slot *slots,
  35                              int num_slots, int our_slot, uint32_t generation);
  36};
  37
  38/*
  39 * dlm_new_lockspace
  40 *
  41 * Create/join a lockspace.
  42 *
  43 * name: lockspace name, null terminated, up to DLM_LOCKSPACE_LEN (not
  44 *   including terminating null).
  45 *
  46 * cluster: cluster name, null terminated, up to DLM_LOCKSPACE_LEN (not
  47 *   including terminating null).  Optional.  When cluster is null, it
  48 *   is not used.  When set, dlm_new_lockspace() returns -EBADR if cluster
  49 *   is not equal to the dlm cluster name.
  50 *
  51 * flags:
  52 * DLM_LSFL_NODIR
  53 *   The dlm should not use a resource directory, but statically assign
  54 *   resource mastery to nodes based on the name hash that is otherwise
  55 *   used to select the directory node.  Must be the same on all nodes.
  56 * DLM_LSFL_TIMEWARN
  57 *   The dlm should emit netlink messages if locks have been waiting
  58 *   for a configurable amount of time.  (Unused.)
  59 * DLM_LSFL_FS
  60 *   The lockspace user is in the kernel (i.e. filesystem).  Enables
  61 *   direct bast/cast callbacks.
  62 * DLM_LSFL_NEWEXCL
  63 *   dlm_new_lockspace() should return -EEXIST if the lockspace exists.
  64 *
  65 * lvblen: length of lvb in bytes.  Must be multiple of 8.
  66 *   dlm_new_lockspace() returns an error if this does not match
  67 *   what other nodes are using.
  68 *
  69 * ops: callbacks that indicate lockspace recovery points so the
  70 *   caller can coordinate its recovery and know lockspace members.
  71 *   This is only used by the initial dlm_new_lockspace() call.
  72 *   Optional.
  73 *
  74 * ops_arg: arg for ops callbacks.
  75 *
  76 * ops_result: tells caller if the ops callbacks (if provided) will
  77 *   be used or not.  0: will be used, -EXXX will not be used.
  78 *   -EOPNOTSUPP: the dlm does not have recovery_callbacks enabled.
  79 *
  80 * lockspace: handle for dlm functions
  81 */
  82
  83int dlm_new_lockspace(const char *name, const char *cluster,
  84                      uint32_t flags, int lvblen,
  85                      const struct dlm_lockspace_ops *ops, void *ops_arg,
  86                      int *ops_result, dlm_lockspace_t **lockspace);
  87
  88/*
  89 * dlm_release_lockspace
  90 *
  91 * Stop a lockspace.
  92 */
  93
  94int dlm_release_lockspace(dlm_lockspace_t *lockspace, int force);
  95
  96/*
  97 * dlm_lock
  98 *
  99 * Make an asynchronous request to acquire or convert a lock on a named
 100 * resource.
 101 *
 102 * lockspace: context for the request
 103 * mode: the requested mode of the lock (DLM_LOCK_)
 104 * lksb: lock status block for input and async return values
 105 * flags: input flags (DLM_LKF_)
 106 * name: name of the resource to lock, can be binary
 107 * namelen: the length in bytes of the resource name (MAX_RESNAME_LEN)
 108 * parent: the lock ID of a parent lock or 0 if none
 109 * lockast: function DLM executes when it completes processing the request
 110 * astarg: argument passed to lockast and bast functions
 111 * bast: function DLM executes when this lock later blocks another request
 112 *
 113 * Returns:
 114 * 0 if request is successfully queued for processing
 115 * -EINVAL if any input parameters are invalid
 116 * -EAGAIN if request would block and is flagged DLM_LKF_NOQUEUE
 117 * -ENOMEM if there is no memory to process request
 118 * -ENOTCONN if there is a communication error
 119 *
 120 * If the call to dlm_lock returns an error then the operation has failed and
 121 * the AST routine will not be called.  If dlm_lock returns 0 it is still
 122 * possible that the lock operation will fail. The AST routine will be called
 123 * when the locking is complete and the status is returned in the lksb.
 124 *
 125 * If the AST routines or parameter are passed to a conversion operation then
 126 * they will overwrite those values that were passed to a previous dlm_lock
 127 * call.
 128 *
 129 * AST routines should not block (at least not for long), but may make
 130 * any locking calls they please.
 131 */
 132
 133int dlm_lock(dlm_lockspace_t *lockspace,
 134             int mode,
 135             struct dlm_lksb *lksb,
 136             uint32_t flags,
 137             void *name,
 138             unsigned int namelen,
 139             uint32_t parent_lkid,
 140             void (*lockast) (void *astarg),
 141             void *astarg,
 142             void (*bast) (void *astarg, int mode));
 143
 144/*
 145 * dlm_unlock
 146 *
 147 * Asynchronously release a lock on a resource.  The AST routine is called
 148 * when the resource is successfully unlocked.
 149 *
 150 * lockspace: context for the request
 151 * lkid: the lock ID as returned in the lksb
 152 * flags: input flags (DLM_LKF_)
 153 * lksb: if NULL the lksb parameter passed to last lock request is used
 154 * astarg: the arg used with the completion ast for the unlock
 155 *
 156 * Returns:
 157 * 0 if request is successfully queued for processing
 158 * -EINVAL if any input parameters are invalid
 159 * -ENOTEMPTY if the lock still has sublocks
 160 * -EBUSY if the lock is waiting for a remote lock operation
 161 * -ENOTCONN if there is a communication error
 162 */
 163
 164int dlm_unlock(dlm_lockspace_t *lockspace,
 165               uint32_t lkid,
 166               uint32_t flags,
 167               struct dlm_lksb *lksb,
 168               void *astarg);
 169
 170#endif                          /* __DLM_DOT_H__ */
 171