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 * dlmapi.h 68c2ecf20Sopenharmony_ci * 78c2ecf20Sopenharmony_ci * externally exported dlm interfaces 88c2ecf20Sopenharmony_ci * 98c2ecf20Sopenharmony_ci * Copyright (C) 2004 Oracle. All rights reserved. 108c2ecf20Sopenharmony_ci */ 118c2ecf20Sopenharmony_ci 128c2ecf20Sopenharmony_ci#ifndef DLMAPI_H 138c2ecf20Sopenharmony_ci#define DLMAPI_H 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_cistruct dlm_lock; 168c2ecf20Sopenharmony_cistruct dlm_ctxt; 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_ci/* NOTE: changes made to this enum should be reflected in dlmdebug.c */ 198c2ecf20Sopenharmony_cienum dlm_status { 208c2ecf20Sopenharmony_ci DLM_NORMAL = 0, /* 0: request in progress */ 218c2ecf20Sopenharmony_ci DLM_GRANTED, /* 1: request granted */ 228c2ecf20Sopenharmony_ci DLM_DENIED, /* 2: request denied */ 238c2ecf20Sopenharmony_ci DLM_DENIED_NOLOCKS, /* 3: request denied, out of system resources */ 248c2ecf20Sopenharmony_ci DLM_WORKING, /* 4: async request in progress */ 258c2ecf20Sopenharmony_ci DLM_BLOCKED, /* 5: lock request blocked */ 268c2ecf20Sopenharmony_ci DLM_BLOCKED_ORPHAN, /* 6: lock request blocked by a orphan lock*/ 278c2ecf20Sopenharmony_ci DLM_DENIED_GRACE_PERIOD, /* 7: topological change in progress */ 288c2ecf20Sopenharmony_ci DLM_SYSERR, /* 8: system error */ 298c2ecf20Sopenharmony_ci DLM_NOSUPPORT, /* 9: unsupported */ 308c2ecf20Sopenharmony_ci DLM_CANCELGRANT, /* 10: can't cancel convert: already granted */ 318c2ecf20Sopenharmony_ci DLM_IVLOCKID, /* 11: bad lockid */ 328c2ecf20Sopenharmony_ci DLM_SYNC, /* 12: synchronous request granted */ 338c2ecf20Sopenharmony_ci DLM_BADTYPE, /* 13: bad resource type */ 348c2ecf20Sopenharmony_ci DLM_BADRESOURCE, /* 14: bad resource handle */ 358c2ecf20Sopenharmony_ci DLM_MAXHANDLES, /* 15: no more resource handles */ 368c2ecf20Sopenharmony_ci DLM_NOCLINFO, /* 16: can't contact cluster manager */ 378c2ecf20Sopenharmony_ci DLM_NOLOCKMGR, /* 17: can't contact lock manager */ 388c2ecf20Sopenharmony_ci DLM_NOPURGED, /* 18: can't contact purge daemon */ 398c2ecf20Sopenharmony_ci DLM_BADARGS, /* 19: bad api args */ 408c2ecf20Sopenharmony_ci DLM_VOID, /* 20: no status */ 418c2ecf20Sopenharmony_ci DLM_NOTQUEUED, /* 21: NOQUEUE was specified and request failed */ 428c2ecf20Sopenharmony_ci DLM_IVBUFLEN, /* 22: invalid resource name length */ 438c2ecf20Sopenharmony_ci DLM_CVTUNGRANT, /* 23: attempted to convert ungranted lock */ 448c2ecf20Sopenharmony_ci DLM_BADPARAM, /* 24: invalid lock mode specified */ 458c2ecf20Sopenharmony_ci DLM_VALNOTVALID, /* 25: value block has been invalidated */ 468c2ecf20Sopenharmony_ci DLM_REJECTED, /* 26: request rejected, unrecognized client */ 478c2ecf20Sopenharmony_ci DLM_ABORT, /* 27: blocked lock request cancelled */ 488c2ecf20Sopenharmony_ci DLM_CANCEL, /* 28: conversion request cancelled */ 498c2ecf20Sopenharmony_ci DLM_IVRESHANDLE, /* 29: invalid resource handle */ 508c2ecf20Sopenharmony_ci DLM_DEADLOCK, /* 30: deadlock recovery refused this request */ 518c2ecf20Sopenharmony_ci DLM_DENIED_NOASTS, /* 31: failed to allocate AST */ 528c2ecf20Sopenharmony_ci DLM_FORWARD, /* 32: request must wait for primary's response */ 538c2ecf20Sopenharmony_ci DLM_TIMEOUT, /* 33: timeout value for lock has expired */ 548c2ecf20Sopenharmony_ci DLM_IVGROUPID, /* 34: invalid group specification */ 558c2ecf20Sopenharmony_ci DLM_VERS_CONFLICT, /* 35: version conflicts prevent request handling */ 568c2ecf20Sopenharmony_ci DLM_BAD_DEVICE_PATH, /* 36: Locks device does not exist or path wrong */ 578c2ecf20Sopenharmony_ci DLM_NO_DEVICE_PERMISSION, /* 37: Client has insufficient pers for device */ 588c2ecf20Sopenharmony_ci DLM_NO_CONTROL_DEVICE, /* 38: Cannot set options on opened device */ 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_ci DLM_RECOVERING, /* 39: extension, allows caller to fail a lock 618c2ecf20Sopenharmony_ci request if it is being recovered */ 628c2ecf20Sopenharmony_ci DLM_MIGRATING, /* 40: extension, allows caller to fail a lock 638c2ecf20Sopenharmony_ci request if it is being migrated */ 648c2ecf20Sopenharmony_ci DLM_MAXSTATS, /* 41: upper limit for return code validation */ 658c2ecf20Sopenharmony_ci}; 668c2ecf20Sopenharmony_ci 678c2ecf20Sopenharmony_ci/* for pretty-printing dlm_status error messages */ 688c2ecf20Sopenharmony_ciconst char *dlm_errmsg(enum dlm_status err); 698c2ecf20Sopenharmony_ci/* for pretty-printing dlm_status error names */ 708c2ecf20Sopenharmony_ciconst char *dlm_errname(enum dlm_status err); 718c2ecf20Sopenharmony_ci 728c2ecf20Sopenharmony_ci/* Eventually the DLM will use standard errno values, but in the 738c2ecf20Sopenharmony_ci * meantime this lets us track dlm errors as they bubble up. When we 748c2ecf20Sopenharmony_ci * bring its error reporting into line with the rest of the stack, 758c2ecf20Sopenharmony_ci * these can just be replaced with calls to mlog_errno. */ 768c2ecf20Sopenharmony_ci#define dlm_error(st) do { \ 778c2ecf20Sopenharmony_ci if ((st) != DLM_RECOVERING && \ 788c2ecf20Sopenharmony_ci (st) != DLM_MIGRATING && \ 798c2ecf20Sopenharmony_ci (st) != DLM_FORWARD) \ 808c2ecf20Sopenharmony_ci mlog(ML_ERROR, "dlm status = %s\n", dlm_errname((st))); \ 818c2ecf20Sopenharmony_ci} while (0) 828c2ecf20Sopenharmony_ci 838c2ecf20Sopenharmony_ci#define DLM_LKSB_UNUSED1 0x01 848c2ecf20Sopenharmony_ci#define DLM_LKSB_PUT_LVB 0x02 858c2ecf20Sopenharmony_ci#define DLM_LKSB_GET_LVB 0x04 868c2ecf20Sopenharmony_ci#define DLM_LKSB_UNUSED2 0x08 878c2ecf20Sopenharmony_ci#define DLM_LKSB_UNUSED3 0x10 888c2ecf20Sopenharmony_ci#define DLM_LKSB_UNUSED4 0x20 898c2ecf20Sopenharmony_ci#define DLM_LKSB_UNUSED5 0x40 908c2ecf20Sopenharmony_ci#define DLM_LKSB_UNUSED6 0x80 918c2ecf20Sopenharmony_ci 928c2ecf20Sopenharmony_ci#define DLM_LVB_LEN 64 938c2ecf20Sopenharmony_ci 948c2ecf20Sopenharmony_ci/* Callers are only allowed access to the lvb and status members of 958c2ecf20Sopenharmony_ci * this struct. */ 968c2ecf20Sopenharmony_cistruct dlm_lockstatus { 978c2ecf20Sopenharmony_ci enum dlm_status status; 988c2ecf20Sopenharmony_ci u32 flags; 998c2ecf20Sopenharmony_ci struct dlm_lock *lockid; 1008c2ecf20Sopenharmony_ci char lvb[DLM_LVB_LEN]; 1018c2ecf20Sopenharmony_ci}; 1028c2ecf20Sopenharmony_ci 1038c2ecf20Sopenharmony_ci/* Valid lock modes. */ 1048c2ecf20Sopenharmony_ci#define LKM_IVMODE (-1) /* invalid mode */ 1058c2ecf20Sopenharmony_ci#define LKM_NLMODE 0 /* null lock */ 1068c2ecf20Sopenharmony_ci#define LKM_CRMODE 1 /* concurrent read unsupported */ 1078c2ecf20Sopenharmony_ci#define LKM_CWMODE 2 /* concurrent write unsupported */ 1088c2ecf20Sopenharmony_ci#define LKM_PRMODE 3 /* protected read */ 1098c2ecf20Sopenharmony_ci#define LKM_PWMODE 4 /* protected write unsupported */ 1108c2ecf20Sopenharmony_ci#define LKM_EXMODE 5 /* exclusive */ 1118c2ecf20Sopenharmony_ci#define LKM_MAXMODE 5 1128c2ecf20Sopenharmony_ci#define LKM_MODEMASK 0xff 1138c2ecf20Sopenharmony_ci 1148c2ecf20Sopenharmony_ci/* Flags passed to dlmlock and dlmunlock: 1158c2ecf20Sopenharmony_ci * reserved: flags used by the "real" dlm 1168c2ecf20Sopenharmony_ci * only a few are supported by this dlm 1178c2ecf20Sopenharmony_ci * (U) = unsupported by ocfs2 dlm */ 1188c2ecf20Sopenharmony_ci#define LKM_ORPHAN 0x00000010 /* this lock is orphanable (U) */ 1198c2ecf20Sopenharmony_ci#define LKM_PARENTABLE 0x00000020 /* this lock was orphaned (U) */ 1208c2ecf20Sopenharmony_ci#define LKM_BLOCK 0x00000040 /* blocking lock request (U) */ 1218c2ecf20Sopenharmony_ci#define LKM_LOCAL 0x00000080 /* local lock request */ 1228c2ecf20Sopenharmony_ci#define LKM_VALBLK 0x00000100 /* lock value block request */ 1238c2ecf20Sopenharmony_ci#define LKM_NOQUEUE 0x00000200 /* non blocking request */ 1248c2ecf20Sopenharmony_ci#define LKM_CONVERT 0x00000400 /* conversion request */ 1258c2ecf20Sopenharmony_ci#define LKM_NODLCKWT 0x00000800 /* this lock wont deadlock (U) */ 1268c2ecf20Sopenharmony_ci#define LKM_UNLOCK 0x00001000 /* deallocate this lock */ 1278c2ecf20Sopenharmony_ci#define LKM_CANCEL 0x00002000 /* cancel conversion request */ 1288c2ecf20Sopenharmony_ci#define LKM_DEQALL 0x00004000 /* remove all locks held by proc (U) */ 1298c2ecf20Sopenharmony_ci#define LKM_INVVALBLK 0x00008000 /* invalidate lock value block */ 1308c2ecf20Sopenharmony_ci#define LKM_SYNCSTS 0x00010000 /* return synchronous status if poss (U) */ 1318c2ecf20Sopenharmony_ci#define LKM_TIMEOUT 0x00020000 /* lock request contains timeout (U) */ 1328c2ecf20Sopenharmony_ci#define LKM_SNGLDLCK 0x00040000 /* request can self-deadlock (U) */ 1338c2ecf20Sopenharmony_ci#define LKM_FINDLOCAL 0x00080000 /* find local lock request (U) */ 1348c2ecf20Sopenharmony_ci#define LKM_PROC_OWNED 0x00100000 /* owned by process, not group (U) */ 1358c2ecf20Sopenharmony_ci#define LKM_XID 0x00200000 /* use transaction id for deadlock (U) */ 1368c2ecf20Sopenharmony_ci#define LKM_XID_CONFLICT 0x00400000 /* do not allow lock inheritance (U) */ 1378c2ecf20Sopenharmony_ci#define LKM_FORCE 0x00800000 /* force unlock flag */ 1388c2ecf20Sopenharmony_ci#define LKM_REVVALBLK 0x01000000 /* temporary solution: re-validate 1398c2ecf20Sopenharmony_ci lock value block (U) */ 1408c2ecf20Sopenharmony_ci/* unused */ 1418c2ecf20Sopenharmony_ci#define LKM_UNUSED1 0x00000001 /* unused */ 1428c2ecf20Sopenharmony_ci#define LKM_UNUSED2 0x00000002 /* unused */ 1438c2ecf20Sopenharmony_ci#define LKM_UNUSED3 0x00000004 /* unused */ 1448c2ecf20Sopenharmony_ci#define LKM_UNUSED4 0x00000008 /* unused */ 1458c2ecf20Sopenharmony_ci#define LKM_UNUSED5 0x02000000 /* unused */ 1468c2ecf20Sopenharmony_ci#define LKM_UNUSED6 0x04000000 /* unused */ 1478c2ecf20Sopenharmony_ci#define LKM_UNUSED7 0x08000000 /* unused */ 1488c2ecf20Sopenharmony_ci 1498c2ecf20Sopenharmony_ci/* ocfs2 extensions: internal only 1508c2ecf20Sopenharmony_ci * should never be used by caller */ 1518c2ecf20Sopenharmony_ci#define LKM_MIGRATION 0x10000000 /* extension: lockres is to be migrated 1528c2ecf20Sopenharmony_ci to another node */ 1538c2ecf20Sopenharmony_ci#define LKM_PUT_LVB 0x20000000 /* extension: lvb is being passed 1548c2ecf20Sopenharmony_ci should be applied to lockres */ 1558c2ecf20Sopenharmony_ci#define LKM_GET_LVB 0x40000000 /* extension: lvb should be copied 1568c2ecf20Sopenharmony_ci from lockres when lock is granted */ 1578c2ecf20Sopenharmony_ci#define LKM_RECOVERY 0x80000000 /* extension: flag for recovery lock 1588c2ecf20Sopenharmony_ci used to avoid recovery rwsem */ 1598c2ecf20Sopenharmony_ci 1608c2ecf20Sopenharmony_ci 1618c2ecf20Sopenharmony_citypedef void (dlm_astlockfunc_t)(void *); 1628c2ecf20Sopenharmony_citypedef void (dlm_bastlockfunc_t)(void *, int); 1638c2ecf20Sopenharmony_citypedef void (dlm_astunlockfunc_t)(void *, enum dlm_status); 1648c2ecf20Sopenharmony_ci 1658c2ecf20Sopenharmony_cienum dlm_status dlmlock(struct dlm_ctxt *dlm, 1668c2ecf20Sopenharmony_ci int mode, 1678c2ecf20Sopenharmony_ci struct dlm_lockstatus *lksb, 1688c2ecf20Sopenharmony_ci int flags, 1698c2ecf20Sopenharmony_ci const char *name, 1708c2ecf20Sopenharmony_ci int namelen, 1718c2ecf20Sopenharmony_ci dlm_astlockfunc_t *ast, 1728c2ecf20Sopenharmony_ci void *data, 1738c2ecf20Sopenharmony_ci dlm_bastlockfunc_t *bast); 1748c2ecf20Sopenharmony_ci 1758c2ecf20Sopenharmony_cienum dlm_status dlmunlock(struct dlm_ctxt *dlm, 1768c2ecf20Sopenharmony_ci struct dlm_lockstatus *lksb, 1778c2ecf20Sopenharmony_ci int flags, 1788c2ecf20Sopenharmony_ci dlm_astunlockfunc_t *unlockast, 1798c2ecf20Sopenharmony_ci void *data); 1808c2ecf20Sopenharmony_ci 1818c2ecf20Sopenharmony_cistruct dlm_protocol_version { 1828c2ecf20Sopenharmony_ci u8 pv_major; 1838c2ecf20Sopenharmony_ci u8 pv_minor; 1848c2ecf20Sopenharmony_ci}; 1858c2ecf20Sopenharmony_cistruct dlm_ctxt * dlm_register_domain(const char *domain, u32 key, 1868c2ecf20Sopenharmony_ci struct dlm_protocol_version *fs_proto); 1878c2ecf20Sopenharmony_ci 1888c2ecf20Sopenharmony_civoid dlm_unregister_domain(struct dlm_ctxt *dlm); 1898c2ecf20Sopenharmony_ci 1908c2ecf20Sopenharmony_civoid dlm_print_one_lock(struct dlm_lock *lockid); 1918c2ecf20Sopenharmony_ci 1928c2ecf20Sopenharmony_citypedef void (dlm_eviction_func)(int, void *); 1938c2ecf20Sopenharmony_cistruct dlm_eviction_cb { 1948c2ecf20Sopenharmony_ci struct list_head ec_item; 1958c2ecf20Sopenharmony_ci dlm_eviction_func *ec_func; 1968c2ecf20Sopenharmony_ci void *ec_data; 1978c2ecf20Sopenharmony_ci}; 1988c2ecf20Sopenharmony_civoid dlm_setup_eviction_cb(struct dlm_eviction_cb *cb, 1998c2ecf20Sopenharmony_ci dlm_eviction_func *f, 2008c2ecf20Sopenharmony_ci void *data); 2018c2ecf20Sopenharmony_civoid dlm_register_eviction_cb(struct dlm_ctxt *dlm, 2028c2ecf20Sopenharmony_ci struct dlm_eviction_cb *cb); 2038c2ecf20Sopenharmony_civoid dlm_unregister_eviction_cb(struct dlm_eviction_cb *cb); 2048c2ecf20Sopenharmony_ci 2058c2ecf20Sopenharmony_ci#endif /* DLMAPI_H */ 206