blob: 8ac357ce6a30a8e70955fd46fdca1ab581323f6c [file] [log] [blame]
Thomas Gleixner328970d2019-05-24 12:04:05 +02001/* SPDX-License-Identifier: GPL-2.0-or-later */
Masahiro Yamadafa60ce22021-05-06 18:06:44 -07002/*
Mark Fashehccd979b2005-12-15 14:31:24 -08003 * ocfs2_lockid.h
4 *
5 * Defines OCFS2 lockid bits.
6 *
7 * Copyright (C) 2002, 2005 Oracle. All rights reserved.
Mark Fashehccd979b2005-12-15 14:31:24 -08008 */
9
10#ifndef OCFS2_LOCKID_H
11#define OCFS2_LOCKID_H
12
13/* lock ids are made up in the following manner:
14 * name[0] --> type
15 * name[1-6] --> 6 pad characters, reserved for now
16 * name[7-22] --> block number, expressed in hex as 16 chars
17 * name[23-30] --> i_generation, expressed in hex 8 chars
18 * name[31] --> '\0' */
19#define OCFS2_LOCK_ID_MAX_LEN 32
20#define OCFS2_LOCK_ID_PAD "000000"
21
Mark Fashehd680efe2006-09-08 14:14:34 -070022#define OCFS2_DENTRY_LOCK_INO_START 18
23
Mark Fashehccd979b2005-12-15 14:31:24 -080024enum ocfs2_lock_type {
25 OCFS2_LOCK_TYPE_META = 0,
26 OCFS2_LOCK_TYPE_DATA,
27 OCFS2_LOCK_TYPE_SUPER,
28 OCFS2_LOCK_TYPE_RENAME,
29 OCFS2_LOCK_TYPE_RW,
Mark Fashehd680efe2006-09-08 14:14:34 -070030 OCFS2_LOCK_TYPE_DENTRY,
Tiger Yang50008632007-03-20 16:01:38 -070031 OCFS2_LOCK_TYPE_OPEN,
Mark Fashehcf8e06f2007-12-20 16:43:10 -080032 OCFS2_LOCK_TYPE_FLOCK,
Jan Kara9e33d692008-08-25 19:56:50 +020033 OCFS2_LOCK_TYPE_QINFO,
wengang wang6ca497a2009-03-06 21:29:10 +080034 OCFS2_LOCK_TYPE_NFS_SYNC,
Srinivas Eeda83273932009-06-03 17:02:55 -070035 OCFS2_LOCK_TYPE_ORPHAN_SCAN,
Tao Ma8dec98e2009-08-18 11:19:58 +080036 OCFS2_LOCK_TYPE_REFCOUNT,
Gang He4882abe2018-01-31 16:15:10 -080037 OCFS2_LOCK_TYPE_TRIM_FS,
Mark Fashehccd979b2005-12-15 14:31:24 -080038 OCFS2_NUM_LOCK_TYPES
39};
40
41static inline char ocfs2_lock_type_char(enum ocfs2_lock_type type)
42{
43 char c;
44 switch (type) {
45 case OCFS2_LOCK_TYPE_META:
46 c = 'M';
47 break;
48 case OCFS2_LOCK_TYPE_DATA:
49 c = 'D';
50 break;
51 case OCFS2_LOCK_TYPE_SUPER:
52 c = 'S';
53 break;
54 case OCFS2_LOCK_TYPE_RENAME:
55 c = 'R';
56 break;
57 case OCFS2_LOCK_TYPE_RW:
58 c = 'W';
59 break;
Mark Fashehd680efe2006-09-08 14:14:34 -070060 case OCFS2_LOCK_TYPE_DENTRY:
61 c = 'N';
62 break;
Tiger Yang50008632007-03-20 16:01:38 -070063 case OCFS2_LOCK_TYPE_OPEN:
64 c = 'O';
65 break;
Mark Fashehcf8e06f2007-12-20 16:43:10 -080066 case OCFS2_LOCK_TYPE_FLOCK:
67 c = 'F';
68 break;
Jan Kara9e33d692008-08-25 19:56:50 +020069 case OCFS2_LOCK_TYPE_QINFO:
70 c = 'Q';
71 break;
wengang wang6ca497a2009-03-06 21:29:10 +080072 case OCFS2_LOCK_TYPE_NFS_SYNC:
73 c = 'Y';
74 break;
Srinivas Eeda83273932009-06-03 17:02:55 -070075 case OCFS2_LOCK_TYPE_ORPHAN_SCAN:
76 c = 'P';
77 break;
Tao Ma8dec98e2009-08-18 11:19:58 +080078 case OCFS2_LOCK_TYPE_REFCOUNT:
79 c = 'T';
80 break;
Gang He4882abe2018-01-31 16:15:10 -080081 case OCFS2_LOCK_TYPE_TRIM_FS:
82 c = 'I';
83 break;
Mark Fashehccd979b2005-12-15 14:31:24 -080084 default:
85 c = '\0';
86 }
87
88 return c;
89}
90
Mark Fashehd680efe2006-09-08 14:14:34 -070091static char *ocfs2_lock_type_strings[] = {
92 [OCFS2_LOCK_TYPE_META] = "Meta",
93 [OCFS2_LOCK_TYPE_DATA] = "Data",
94 [OCFS2_LOCK_TYPE_SUPER] = "Super",
95 [OCFS2_LOCK_TYPE_RENAME] = "Rename",
96 /* Need to differntiate from [R]ename.. serializing writes is the
97 * important job it does, anyway. */
98 [OCFS2_LOCK_TYPE_RW] = "Write/Read",
99 [OCFS2_LOCK_TYPE_DENTRY] = "Dentry",
Tiger Yang50008632007-03-20 16:01:38 -0700100 [OCFS2_LOCK_TYPE_OPEN] = "Open",
Mark Fashehcf8e06f2007-12-20 16:43:10 -0800101 [OCFS2_LOCK_TYPE_FLOCK] = "Flock",
Jan Kara9e33d692008-08-25 19:56:50 +0200102 [OCFS2_LOCK_TYPE_QINFO] = "Quota",
Jan Karaa8b88d32009-08-20 18:26:52 +0200103 [OCFS2_LOCK_TYPE_NFS_SYNC] = "NFSSync",
Srinivas Eeda83273932009-06-03 17:02:55 -0700104 [OCFS2_LOCK_TYPE_ORPHAN_SCAN] = "OrphanScan",
Tao Ma8dec98e2009-08-18 11:19:58 +0800105 [OCFS2_LOCK_TYPE_REFCOUNT] = "Refcount",
Gang He4882abe2018-01-31 16:15:10 -0800106 [OCFS2_LOCK_TYPE_TRIM_FS] = "TrimFs",
Mark Fashehd680efe2006-09-08 14:14:34 -0700107};
108
109static inline const char *ocfs2_lock_type_string(enum ocfs2_lock_type type)
110{
111#ifdef __KERNEL__
Joel Becker8f318312008-03-04 16:09:39 -0800112 BUG_ON(type >= OCFS2_NUM_LOCK_TYPES);
Mark Fashehd680efe2006-09-08 14:14:34 -0700113#endif
114 return ocfs2_lock_type_strings[type];
115}
116
Mark Fashehccd979b2005-12-15 14:31:24 -0800117#endif /* OCFS2_LOCKID_H */