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