Documentation/translations/zh_CN/filesystems/gfs2-glocks.rst
Source file repositories/reference/linux-study-clean/Documentation/translations/zh_CN/filesystems/gfs2-glocks.rst
File Facts
- System
- Linux kernel
- Corpus path
Documentation/translations/zh_CN/filesystems/gfs2-glocks.rst- Extension
.rst- Size
- 9169 bytes
- Lines
- 212
- Domain
- Support Tooling And Documentation
- Bucket
- Documentation
- Inferred role
- Support Tooling And Documentation: documentation
- Status
- atlas-only
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
- No C-style include directives detected by the generator.
Detected Declarations
- No top-level syscall, struct, function, initcall, or export declaration detected by the generator.
Annotated Snippet
.. SPDX-License-Identifier: GPL-2.0
.. include:: ../disclaimer-zh_CN.rst
:Original: Documentation/filesystems/gfs2-glocks.rst
:翻译:
邵明寅 Shao Mingyin <shao.mingyin@zte.com.cn>
:校译:
杨涛 yang tao <yang.tao172@zte.com.cn>
==================
Glock 内部加锁规则
==================
本文档阐述 glock 状态机内部运作的基本原理。每个 glock(即
fs/gfs2/incore.h 中的 struct gfs2_glock)包含两把主要的内部锁:
1. 自旋锁(gl_lockref.lock):用于保护内部状态(如
gl_state、gl_target)和持有者列表(gl_holders)
2. 非阻塞的位锁(GLF_LOCK):用于防止其他线程同时调用
DLM 等操作。若某线程获取此锁,则在释放时必须调用
run_queue(通常通过工作队列),以确保所有待处理任务
得以完成。
gl_holders 列表包含与该 glock 关联的所有排队锁请求(不
仅是持有者)。若存在已持有的锁,它们将位于列表开头的连
续条目中。锁的授予严格遵循排队顺序。
glock 层用户可请求三种锁状态:共享(SH)、延迟(DF)和
排他(EX)。它们对应以下 DLM 锁模式:
========== ====== =====================================================
Glock 模式 DLM 锁模式
========== ====== =====================================================
UN IV/NL 未加锁(无关联的 DLM 锁)或 NL
SH PR 受保护读(Protected read)
DF CW 并发写(Concurrent write)
EX EX 排他(Exclusive)
========== ====== =====================================================
因此,DF 本质上是一种与“常规”共享锁模式(SH)互斥的共
享模式。在 GFS2 中,DF 模式专用于直接 I/O 操作。Glock
本质上是锁加缓存管理例程的组合,其缓存规则如下:
========== ============== ========== ========== ==============
Glock 模式 缓存元数据 缓存数据 脏数据 脏元数据
========== ============== ========== ========== ==============
UN 否 否 否 否
DF 是 否 否 否
SH 是 是 否 否
EX 是 是 是 是
========== ============== ========== ========== ==============
这些规则通过为每种 glock 定义的操作函数实现。并非所有
glock 类型都使用全部的模式,例如仅 inode glock 使用 DF 模
式。
glock 操作函数及类型常量说明表:
============== ========================================================
字段 用途
============== ========================================================
go_sync 远程状态变更前调用(如同步脏数据)
go_xmote_bh 远程状态变更后调用(如刷新缓存)
go_inval 远程状态变更需使缓存失效时调用
go_instantiate 获取 glock 时调用
Annotation
- Atlas domain: Support Tooling And Documentation / Documentation.
- Implementation status: atlas-only.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.