xref: /openbmc/linux/fs/ocfs2/ocfs2_lockid.h (revision 37744fee)
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /* -*- mode: c; c-basic-offset: 8; -*-
3  * vim: noexpandtab sw=8 ts=8 sts=0:
4  *
5  * ocfs2_lockid.h
6  *
7  * Defines OCFS2 lockid bits.
8  *
9  * Copyright (C) 2002, 2005 Oracle.  All rights reserved.
10  */
11 
12 #ifndef OCFS2_LOCKID_H
13 #define OCFS2_LOCKID_H
14 
15 /* lock ids are made up in the following manner:
16  * name[0]     --> type
17  * name[1-6]   --> 6 pad characters, reserved for now
18  * name[7-22]  --> block number, expressed in hex as 16 chars
19  * name[23-30] --> i_generation, expressed in hex 8 chars
20  * name[31]    --> '\0' */
21 #define OCFS2_LOCK_ID_MAX_LEN  32
22 #define OCFS2_LOCK_ID_PAD "000000"
23 
24 #define OCFS2_DENTRY_LOCK_INO_START 18
25 
26 enum ocfs2_lock_type {
27 	OCFS2_LOCK_TYPE_META = 0,
28 	OCFS2_LOCK_TYPE_DATA,
29 	OCFS2_LOCK_TYPE_SUPER,
30 	OCFS2_LOCK_TYPE_RENAME,
31 	OCFS2_LOCK_TYPE_RW,
32 	OCFS2_LOCK_TYPE_DENTRY,
33 	OCFS2_LOCK_TYPE_OPEN,
34 	OCFS2_LOCK_TYPE_FLOCK,
35 	OCFS2_LOCK_TYPE_QINFO,
36 	OCFS2_LOCK_TYPE_NFS_SYNC,
37 	OCFS2_LOCK_TYPE_ORPHAN_SCAN,
38 	OCFS2_LOCK_TYPE_REFCOUNT,
39 	OCFS2_LOCK_TYPE_TRIM_FS,
40 	OCFS2_NUM_LOCK_TYPES
41 };
42 
43 static inline char ocfs2_lock_type_char(enum ocfs2_lock_type type)
44 {
45 	char c;
46 	switch (type) {
47 		case OCFS2_LOCK_TYPE_META:
48 			c = 'M';
49 			break;
50 		case OCFS2_LOCK_TYPE_DATA:
51 			c = 'D';
52 			break;
53 		case OCFS2_LOCK_TYPE_SUPER:
54 			c = 'S';
55 			break;
56 		case OCFS2_LOCK_TYPE_RENAME:
57 			c = 'R';
58 			break;
59 		case OCFS2_LOCK_TYPE_RW:
60 			c = 'W';
61 			break;
62 		case OCFS2_LOCK_TYPE_DENTRY:
63 			c = 'N';
64 			break;
65 		case OCFS2_LOCK_TYPE_OPEN:
66 			c = 'O';
67 			break;
68 		case OCFS2_LOCK_TYPE_FLOCK:
69 			c = 'F';
70 			break;
71 		case OCFS2_LOCK_TYPE_QINFO:
72 			c = 'Q';
73 			break;
74 		case OCFS2_LOCK_TYPE_NFS_SYNC:
75 			c = 'Y';
76 			break;
77 		case OCFS2_LOCK_TYPE_ORPHAN_SCAN:
78 			c = 'P';
79 			break;
80 		case OCFS2_LOCK_TYPE_REFCOUNT:
81 			c = 'T';
82 			break;
83 		case OCFS2_LOCK_TYPE_TRIM_FS:
84 			c = 'I';
85 			break;
86 		default:
87 			c = '\0';
88 	}
89 
90 	return c;
91 }
92 
93 static char *ocfs2_lock_type_strings[] = {
94 	[OCFS2_LOCK_TYPE_META] = "Meta",
95 	[OCFS2_LOCK_TYPE_DATA] = "Data",
96 	[OCFS2_LOCK_TYPE_SUPER] = "Super",
97 	[OCFS2_LOCK_TYPE_RENAME] = "Rename",
98 	/* Need to differntiate from [R]ename.. serializing writes is the
99 	 * important job it does, anyway. */
100 	[OCFS2_LOCK_TYPE_RW] = "Write/Read",
101 	[OCFS2_LOCK_TYPE_DENTRY] = "Dentry",
102 	[OCFS2_LOCK_TYPE_OPEN] = "Open",
103 	[OCFS2_LOCK_TYPE_FLOCK] = "Flock",
104 	[OCFS2_LOCK_TYPE_QINFO] = "Quota",
105 	[OCFS2_LOCK_TYPE_NFS_SYNC] = "NFSSync",
106 	[OCFS2_LOCK_TYPE_ORPHAN_SCAN] = "OrphanScan",
107 	[OCFS2_LOCK_TYPE_REFCOUNT] = "Refcount",
108 	[OCFS2_LOCK_TYPE_TRIM_FS] = "TrimFs",
109 };
110 
111 static inline const char *ocfs2_lock_type_string(enum ocfs2_lock_type type)
112 {
113 #ifdef __KERNEL__
114 	BUG_ON(type >= OCFS2_NUM_LOCK_TYPES);
115 #endif
116 	return ocfs2_lock_type_strings[type];
117 }
118 
119 #endif  /* OCFS2_LOCKID_H */
120