xref: /linux/fs/ocfs2/ocfs2_lockid.h (revision 8f318311faf57481452895448e6ffaec7c38a146)
1ccd979bdSMark Fasheh /* -*- mode: c; c-basic-offset: 8; -*-
2ccd979bdSMark Fasheh  * vim: noexpandtab sw=8 ts=8 sts=0:
3ccd979bdSMark Fasheh  *
4ccd979bdSMark Fasheh  * ocfs2_lockid.h
5ccd979bdSMark Fasheh  *
6ccd979bdSMark Fasheh  * Defines OCFS2 lockid bits.
7ccd979bdSMark Fasheh  *
8ccd979bdSMark Fasheh  * Copyright (C) 2002, 2005 Oracle.  All rights reserved.
9ccd979bdSMark Fasheh  *
10ccd979bdSMark Fasheh  * This program is free software; you can redistribute it and/or
11ccd979bdSMark Fasheh  * modify it under the terms of the GNU General Public
12ccd979bdSMark Fasheh  * License as published by the Free Software Foundation; either
13ccd979bdSMark Fasheh  * version 2 of the License, or (at your option) any later version.
14ccd979bdSMark Fasheh  *
15ccd979bdSMark Fasheh  * This program is distributed in the hope that it will be useful,
16ccd979bdSMark Fasheh  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17ccd979bdSMark Fasheh  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18ccd979bdSMark Fasheh  * General Public License for more details.
19ccd979bdSMark Fasheh  *
20ccd979bdSMark Fasheh  * You should have received a copy of the GNU General Public
21ccd979bdSMark Fasheh  * License along with this program; if not, write to the
22ccd979bdSMark Fasheh  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23ccd979bdSMark Fasheh  * Boston, MA 021110-1307, USA.
24ccd979bdSMark Fasheh  */
25ccd979bdSMark Fasheh 
26ccd979bdSMark Fasheh #ifndef OCFS2_LOCKID_H
27ccd979bdSMark Fasheh #define OCFS2_LOCKID_H
28ccd979bdSMark Fasheh 
29ccd979bdSMark Fasheh /* lock ids are made up in the following manner:
30ccd979bdSMark Fasheh  * name[0]     --> type
31ccd979bdSMark Fasheh  * name[1-6]   --> 6 pad characters, reserved for now
32ccd979bdSMark Fasheh  * name[7-22]  --> block number, expressed in hex as 16 chars
33ccd979bdSMark Fasheh  * name[23-30] --> i_generation, expressed in hex 8 chars
34ccd979bdSMark Fasheh  * name[31]    --> '\0' */
35ccd979bdSMark Fasheh #define OCFS2_LOCK_ID_MAX_LEN  32
36ccd979bdSMark Fasheh #define OCFS2_LOCK_ID_PAD "000000"
37ccd979bdSMark Fasheh 
38d680efe9SMark Fasheh #define OCFS2_DENTRY_LOCK_INO_START 18
39d680efe9SMark Fasheh 
40ccd979bdSMark Fasheh enum ocfs2_lock_type {
41ccd979bdSMark Fasheh 	OCFS2_LOCK_TYPE_META = 0,
42ccd979bdSMark Fasheh 	OCFS2_LOCK_TYPE_DATA,
43ccd979bdSMark Fasheh 	OCFS2_LOCK_TYPE_SUPER,
44ccd979bdSMark Fasheh 	OCFS2_LOCK_TYPE_RENAME,
45ccd979bdSMark Fasheh 	OCFS2_LOCK_TYPE_RW,
46d680efe9SMark Fasheh 	OCFS2_LOCK_TYPE_DENTRY,
4750008630STiger Yang 	OCFS2_LOCK_TYPE_OPEN,
48cf8e06f1SMark Fasheh 	OCFS2_LOCK_TYPE_FLOCK,
49ccd979bdSMark Fasheh 	OCFS2_NUM_LOCK_TYPES
50ccd979bdSMark Fasheh };
51ccd979bdSMark Fasheh 
52ccd979bdSMark Fasheh static inline char ocfs2_lock_type_char(enum ocfs2_lock_type type)
53ccd979bdSMark Fasheh {
54ccd979bdSMark Fasheh 	char c;
55ccd979bdSMark Fasheh 	switch (type) {
56ccd979bdSMark Fasheh 		case OCFS2_LOCK_TYPE_META:
57ccd979bdSMark Fasheh 			c = 'M';
58ccd979bdSMark Fasheh 			break;
59ccd979bdSMark Fasheh 		case OCFS2_LOCK_TYPE_DATA:
60ccd979bdSMark Fasheh 			c = 'D';
61ccd979bdSMark Fasheh 			break;
62ccd979bdSMark Fasheh 		case OCFS2_LOCK_TYPE_SUPER:
63ccd979bdSMark Fasheh 			c = 'S';
64ccd979bdSMark Fasheh 			break;
65ccd979bdSMark Fasheh 		case OCFS2_LOCK_TYPE_RENAME:
66ccd979bdSMark Fasheh 			c = 'R';
67ccd979bdSMark Fasheh 			break;
68ccd979bdSMark Fasheh 		case OCFS2_LOCK_TYPE_RW:
69ccd979bdSMark Fasheh 			c = 'W';
70ccd979bdSMark Fasheh 			break;
71d680efe9SMark Fasheh 		case OCFS2_LOCK_TYPE_DENTRY:
72d680efe9SMark Fasheh 			c = 'N';
73d680efe9SMark Fasheh 			break;
7450008630STiger Yang 		case OCFS2_LOCK_TYPE_OPEN:
7550008630STiger Yang 			c = 'O';
7650008630STiger Yang 			break;
77cf8e06f1SMark Fasheh 		case OCFS2_LOCK_TYPE_FLOCK:
78cf8e06f1SMark Fasheh 			c = 'F';
79cf8e06f1SMark Fasheh 			break;
80ccd979bdSMark Fasheh 		default:
81ccd979bdSMark Fasheh 			c = '\0';
82ccd979bdSMark Fasheh 	}
83ccd979bdSMark Fasheh 
84ccd979bdSMark Fasheh 	return c;
85ccd979bdSMark Fasheh }
86ccd979bdSMark Fasheh 
87d680efe9SMark Fasheh static char *ocfs2_lock_type_strings[] = {
88d680efe9SMark Fasheh 	[OCFS2_LOCK_TYPE_META] = "Meta",
89d680efe9SMark Fasheh 	[OCFS2_LOCK_TYPE_DATA] = "Data",
90d680efe9SMark Fasheh 	[OCFS2_LOCK_TYPE_SUPER] = "Super",
91d680efe9SMark Fasheh 	[OCFS2_LOCK_TYPE_RENAME] = "Rename",
92d680efe9SMark Fasheh 	/* Need to differntiate from [R]ename.. serializing writes is the
93d680efe9SMark Fasheh 	 * important job it does, anyway. */
94d680efe9SMark Fasheh 	[OCFS2_LOCK_TYPE_RW] = "Write/Read",
95d680efe9SMark Fasheh 	[OCFS2_LOCK_TYPE_DENTRY] = "Dentry",
9650008630STiger Yang 	[OCFS2_LOCK_TYPE_OPEN] = "Open",
97cf8e06f1SMark Fasheh 	[OCFS2_LOCK_TYPE_FLOCK] = "Flock",
98d680efe9SMark Fasheh };
99d680efe9SMark Fasheh 
100d680efe9SMark Fasheh static inline const char *ocfs2_lock_type_string(enum ocfs2_lock_type type)
101d680efe9SMark Fasheh {
102d680efe9SMark Fasheh #ifdef __KERNEL__
103*8f318311SJoel Becker 	BUG_ON(type >= OCFS2_NUM_LOCK_TYPES);
104d680efe9SMark Fasheh #endif
105d680efe9SMark Fasheh 	return ocfs2_lock_type_strings[type];
106d680efe9SMark Fasheh }
107d680efe9SMark Fasheh 
108ccd979bdSMark Fasheh #endif  /* OCFS2_LOCKID_H */
109