1328970deSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-or-later */
2*fa60ce2cSMasahiro Yamada /*
3ccd979bdSMark Fasheh * ocfs2_lockid.h
4ccd979bdSMark Fasheh *
5ccd979bdSMark Fasheh * Defines OCFS2 lockid bits.
6ccd979bdSMark Fasheh *
7ccd979bdSMark Fasheh * Copyright (C) 2002, 2005 Oracle. All rights reserved.
8ccd979bdSMark Fasheh */
9ccd979bdSMark Fasheh
10ccd979bdSMark Fasheh #ifndef OCFS2_LOCKID_H
11ccd979bdSMark Fasheh #define OCFS2_LOCKID_H
12ccd979bdSMark Fasheh
13ccd979bdSMark Fasheh /* lock ids are made up in the following manner:
14ccd979bdSMark Fasheh * name[0] --> type
15ccd979bdSMark Fasheh * name[1-6] --> 6 pad characters, reserved for now
16ccd979bdSMark Fasheh * name[7-22] --> block number, expressed in hex as 16 chars
17ccd979bdSMark Fasheh * name[23-30] --> i_generation, expressed in hex 8 chars
18ccd979bdSMark Fasheh * name[31] --> '\0' */
19ccd979bdSMark Fasheh #define OCFS2_LOCK_ID_MAX_LEN 32
20ccd979bdSMark Fasheh #define OCFS2_LOCK_ID_PAD "000000"
21ccd979bdSMark Fasheh
22d680efe9SMark Fasheh #define OCFS2_DENTRY_LOCK_INO_START 18
23d680efe9SMark Fasheh
24ccd979bdSMark Fasheh enum ocfs2_lock_type {
25ccd979bdSMark Fasheh OCFS2_LOCK_TYPE_META = 0,
26ccd979bdSMark Fasheh OCFS2_LOCK_TYPE_DATA,
27ccd979bdSMark Fasheh OCFS2_LOCK_TYPE_SUPER,
28ccd979bdSMark Fasheh OCFS2_LOCK_TYPE_RENAME,
29ccd979bdSMark Fasheh OCFS2_LOCK_TYPE_RW,
30d680efe9SMark Fasheh OCFS2_LOCK_TYPE_DENTRY,
3150008630STiger Yang OCFS2_LOCK_TYPE_OPEN,
32cf8e06f1SMark Fasheh OCFS2_LOCK_TYPE_FLOCK,
339e33d69fSJan Kara OCFS2_LOCK_TYPE_QINFO,
346ca497a8Swengang wang OCFS2_LOCK_TYPE_NFS_SYNC,
3583273932SSrinivas Eeda OCFS2_LOCK_TYPE_ORPHAN_SCAN,
368dec98edSTao Ma OCFS2_LOCK_TYPE_REFCOUNT,
374882abebSGang He OCFS2_LOCK_TYPE_TRIM_FS,
38ccd979bdSMark Fasheh OCFS2_NUM_LOCK_TYPES
39ccd979bdSMark Fasheh };
40ccd979bdSMark Fasheh
ocfs2_lock_type_char(enum ocfs2_lock_type type)41ccd979bdSMark Fasheh static inline char ocfs2_lock_type_char(enum ocfs2_lock_type type)
42ccd979bdSMark Fasheh {
43ccd979bdSMark Fasheh char c;
44ccd979bdSMark Fasheh switch (type) {
45ccd979bdSMark Fasheh case OCFS2_LOCK_TYPE_META:
46ccd979bdSMark Fasheh c = 'M';
47ccd979bdSMark Fasheh break;
48ccd979bdSMark Fasheh case OCFS2_LOCK_TYPE_DATA:
49ccd979bdSMark Fasheh c = 'D';
50ccd979bdSMark Fasheh break;
51ccd979bdSMark Fasheh case OCFS2_LOCK_TYPE_SUPER:
52ccd979bdSMark Fasheh c = 'S';
53ccd979bdSMark Fasheh break;
54ccd979bdSMark Fasheh case OCFS2_LOCK_TYPE_RENAME:
55ccd979bdSMark Fasheh c = 'R';
56ccd979bdSMark Fasheh break;
57ccd979bdSMark Fasheh case OCFS2_LOCK_TYPE_RW:
58ccd979bdSMark Fasheh c = 'W';
59ccd979bdSMark Fasheh break;
60d680efe9SMark Fasheh case OCFS2_LOCK_TYPE_DENTRY:
61d680efe9SMark Fasheh c = 'N';
62d680efe9SMark Fasheh break;
6350008630STiger Yang case OCFS2_LOCK_TYPE_OPEN:
6450008630STiger Yang c = 'O';
6550008630STiger Yang break;
66cf8e06f1SMark Fasheh case OCFS2_LOCK_TYPE_FLOCK:
67cf8e06f1SMark Fasheh c = 'F';
68cf8e06f1SMark Fasheh break;
699e33d69fSJan Kara case OCFS2_LOCK_TYPE_QINFO:
709e33d69fSJan Kara c = 'Q';
719e33d69fSJan Kara break;
726ca497a8Swengang wang case OCFS2_LOCK_TYPE_NFS_SYNC:
736ca497a8Swengang wang c = 'Y';
746ca497a8Swengang wang break;
7583273932SSrinivas Eeda case OCFS2_LOCK_TYPE_ORPHAN_SCAN:
7683273932SSrinivas Eeda c = 'P';
7783273932SSrinivas Eeda break;
788dec98edSTao Ma case OCFS2_LOCK_TYPE_REFCOUNT:
798dec98edSTao Ma c = 'T';
808dec98edSTao Ma break;
814882abebSGang He case OCFS2_LOCK_TYPE_TRIM_FS:
824882abebSGang He c = 'I';
834882abebSGang He break;
84ccd979bdSMark Fasheh default:
85ccd979bdSMark Fasheh c = '\0';
86ccd979bdSMark Fasheh }
87ccd979bdSMark Fasheh
88ccd979bdSMark Fasheh return c;
89ccd979bdSMark Fasheh }
90ccd979bdSMark Fasheh
91d680efe9SMark Fasheh static char *ocfs2_lock_type_strings[] = {
92d680efe9SMark Fasheh [OCFS2_LOCK_TYPE_META] = "Meta",
93d680efe9SMark Fasheh [OCFS2_LOCK_TYPE_DATA] = "Data",
94d680efe9SMark Fasheh [OCFS2_LOCK_TYPE_SUPER] = "Super",
95d680efe9SMark Fasheh [OCFS2_LOCK_TYPE_RENAME] = "Rename",
96d680efe9SMark Fasheh /* Need to differntiate from [R]ename.. serializing writes is the
97d680efe9SMark Fasheh * important job it does, anyway. */
98d680efe9SMark Fasheh [OCFS2_LOCK_TYPE_RW] = "Write/Read",
99d680efe9SMark Fasheh [OCFS2_LOCK_TYPE_DENTRY] = "Dentry",
10050008630STiger Yang [OCFS2_LOCK_TYPE_OPEN] = "Open",
101cf8e06f1SMark Fasheh [OCFS2_LOCK_TYPE_FLOCK] = "Flock",
1029e33d69fSJan Kara [OCFS2_LOCK_TYPE_QINFO] = "Quota",
103a8b88d3dSJan Kara [OCFS2_LOCK_TYPE_NFS_SYNC] = "NFSSync",
10483273932SSrinivas Eeda [OCFS2_LOCK_TYPE_ORPHAN_SCAN] = "OrphanScan",
1058dec98edSTao Ma [OCFS2_LOCK_TYPE_REFCOUNT] = "Refcount",
1064882abebSGang He [OCFS2_LOCK_TYPE_TRIM_FS] = "TrimFs",
107d680efe9SMark Fasheh };
108d680efe9SMark Fasheh
ocfs2_lock_type_string(enum ocfs2_lock_type type)109d680efe9SMark Fasheh static inline const char *ocfs2_lock_type_string(enum ocfs2_lock_type type)
110d680efe9SMark Fasheh {
111d680efe9SMark Fasheh #ifdef __KERNEL__
1128f318311SJoel Becker BUG_ON(type >= OCFS2_NUM_LOCK_TYPES);
113d680efe9SMark Fasheh #endif
114d680efe9SMark Fasheh return ocfs2_lock_type_strings[type];
115d680efe9SMark Fasheh }
116d680efe9SMark Fasheh
117ccd979bdSMark Fasheh #endif /* OCFS2_LOCKID_H */
118