blob: 203a025e30e5a88251d909b263a9b0046dc18d2a [file] [log] [blame]
David Teiglande7fd4172006-01-18 09:30:29 +00001/******************************************************************************
2*******************************************************************************
3**
4** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
David Teigland3ae1acf2007-05-18 08:59:31 -05005** Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved.
David Teiglande7fd4172006-01-18 09:30:29 +00006**
7** This copyrighted material is made available to anyone wishing to use,
8** modify, copy, or redistribute it subject to the terms and conditions
9** of the GNU General Public License v.2.
10**
11*******************************************************************************
12******************************************************************************/
13
14#ifndef __DLM_DOT_H__
15#define __DLM_DOT_H__
16
17/*
18 * Interface to Distributed Lock Manager (DLM)
19 * routines and structures to use DLM lockspaces
20 */
21
Joel Beckerd69a3ad2007-10-05 14:31:44 -070022/* Lock levels and flags are here */
23#include <linux/dlmconstants.h>
Mike Frysingerc1c76742008-04-21 11:35:39 -050024#include <linux/types.h>
David Teiglande7fd4172006-01-18 09:30:29 +000025
David Teiglande7fd4172006-01-18 09:30:29 +000026typedef void dlm_lockspace_t;
27
28/*
David Teiglande7fd4172006-01-18 09:30:29 +000029 * Lock status block
30 *
31 * Use this structure to specify the contents of the lock value block. For a
32 * conversion request, this structure is used to specify the lock ID of the
33 * lock. DLM writes the status of the lock request and the lock ID assigned
34 * to the request in the lock status block.
35 *
36 * sb_lkid: the returned lock ID. It is set on new (non-conversion) requests.
37 * It is available when dlm_lock returns.
38 *
39 * sb_lvbptr: saves or returns the contents of the lock's LVB according to rules
40 * shown for the DLM_LKF_VALBLK flag.
41 *
42 * sb_flags: DLM_SBF_DEMOTED is returned if in the process of promoting a lock,
43 * it was first demoted to NL to avoid conversion deadlock.
44 * DLM_SBF_VALNOTVALID is returned if the resource's LVB is marked invalid.
45 *
46 * sb_status: the returned status of the lock request set prior to AST
47 * execution. Possible return values:
48 *
49 * 0 if lock request was successful
50 * -EAGAIN if request would block and is flagged DLM_LKF_NOQUEUE
51 * -ENOMEM if there is no memory to process request
52 * -EINVAL if there are invalid parameters
53 * -DLM_EUNLOCK if unlock request was successful
54 * -DLM_ECANCEL if a cancel completed successfully
55 */
56
57#define DLM_SBF_DEMOTED 0x01
58#define DLM_SBF_VALNOTVALID 0x02
59#define DLM_SBF_ALTMODE 0x04
60
61struct dlm_lksb {
62 int sb_status;
Mike Frysingerc1c76742008-04-21 11:35:39 -050063 __u32 sb_lkid;
David Teiglande7fd4172006-01-18 09:30:29 +000064 char sb_flags;
65 char * sb_lvbptr;
66};
67
David Teigland3ae1acf2007-05-18 08:59:31 -050068#define DLM_LSFL_NODIR 0x00000001
69#define DLM_LSFL_TIMEWARN 0x00000002
Patrick Caulfield44f487a2007-06-06 09:21:22 -050070#define DLM_LSFL_FS 0x00000004
David Teiglande7fd4172006-01-18 09:30:29 +000071
72#ifdef __KERNEL__
73
David Teiglande7fd4172006-01-18 09:30:29 +000074/*
75 * dlm_new_lockspace
76 *
77 * Starts a lockspace with the given name. If the named lockspace exists in
78 * the cluster, the calling node joins it.
79 */
80
81int dlm_new_lockspace(char *name, int namelen, dlm_lockspace_t **lockspace,
82 uint32_t flags, int lvblen);
83
84/*
85 * dlm_release_lockspace
86 *
87 * Stop a lockspace.
88 */
89
90int dlm_release_lockspace(dlm_lockspace_t *lockspace, int force);
91
92/*
93 * dlm_lock
94 *
95 * Make an asyncronous request to acquire or convert a lock on a named
96 * resource.
97 *
98 * lockspace: context for the request
99 * mode: the requested mode of the lock (DLM_LOCK_)
100 * lksb: lock status block for input and async return values
101 * flags: input flags (DLM_LKF_)
102 * name: name of the resource to lock, can be binary
103 * namelen: the length in bytes of the resource name (MAX_RESNAME_LEN)
104 * parent: the lock ID of a parent lock or 0 if none
105 * lockast: function DLM executes when it completes processing the request
106 * astarg: argument passed to lockast and bast functions
107 * bast: function DLM executes when this lock later blocks another request
108 *
109 * Returns:
110 * 0 if request is successfully queued for processing
111 * -EINVAL if any input parameters are invalid
112 * -EAGAIN if request would block and is flagged DLM_LKF_NOQUEUE
113 * -ENOMEM if there is no memory to process request
114 * -ENOTCONN if there is a communication error
115 *
116 * If the call to dlm_lock returns an error then the operation has failed and
117 * the AST routine will not be called. If dlm_lock returns 0 it is still
118 * possible that the lock operation will fail. The AST routine will be called
119 * when the locking is complete and the status is returned in the lksb.
120 *
121 * If the AST routines or parameter are passed to a conversion operation then
122 * they will overwrite those values that were passed to a previous dlm_lock
123 * call.
124 *
125 * AST routines should not block (at least not for long), but may make
126 * any locking calls they please.
127 */
128
129int dlm_lock(dlm_lockspace_t *lockspace,
130 int mode,
131 struct dlm_lksb *lksb,
132 uint32_t flags,
133 void *name,
134 unsigned int namelen,
135 uint32_t parent_lkid,
136 void (*lockast) (void *astarg),
137 void *astarg,
David Teigland3bcd3682006-02-23 09:56:38 +0000138 void (*bast) (void *astarg, int mode));
David Teiglande7fd4172006-01-18 09:30:29 +0000139
140/*
141 * dlm_unlock
142 *
143 * Asynchronously release a lock on a resource. The AST routine is called
144 * when the resource is successfully unlocked.
145 *
146 * lockspace: context for the request
147 * lkid: the lock ID as returned in the lksb
148 * flags: input flags (DLM_LKF_)
149 * lksb: if NULL the lksb parameter passed to last lock request is used
150 * astarg: the arg used with the completion ast for the unlock
151 *
152 * Returns:
153 * 0 if request is successfully queued for processing
154 * -EINVAL if any input parameters are invalid
155 * -ENOTEMPTY if the lock still has sublocks
156 * -EBUSY if the lock is waiting for a remote lock operation
157 * -ENOTCONN if there is a communication error
158 */
159
160int dlm_unlock(dlm_lockspace_t *lockspace,
161 uint32_t lkid,
162 uint32_t flags,
163 struct dlm_lksb *lksb,
164 void *astarg);
165
166#endif /* __KERNEL__ */
167
168#endif /* __DLM_DOT_H__ */
169