fs/ceph/locks.c
Source file repositories/reference/linux-study-clean/fs/ceph/locks.c
File Facts
- System
- Linux kernel
- Corpus path
fs/ceph/locks.c- Extension
.c- Size
- 13724 bytes
- Lines
- 525
- Domain
- Core OS
- Bucket
- VFS And Filesystem Core
- Inferred role
- Core OS: implementation source
- Status
- source implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/ceph/ceph_debug.hlinux/file.hlinux/namei.hlinux/random.hsuper.hmds_client.hlinux/filelock.hlinux/ceph/pagelist.h
Detected Declarations
function secure_addrfunction ceph_flock_initfunction ceph_fl_copy_lockfunction ceph_fl_release_lockfunction ceph_lock_messagefunction ceph_lock_wait_for_completionfunction try_unlock_filefunction ceph_lockfunction ceph_flockfunction ceph_count_locksfunction lock_to_ceph_filelockfunction ceph_encode_locks_to_bufferfunction ceph_locks_to_pagelist
Annotated Snippet
if (!req->r_session) {
// haven't sent the request
err = 0;
}
}
mutex_unlock(&mdsc->mutex);
if (!err)
return 0;
intr_req = ceph_mdsc_create_request(mdsc, CEPH_MDS_OP_SETFILELOCK,
USE_AUTH_MDS);
if (IS_ERR(intr_req))
return PTR_ERR(intr_req);
intr_req->r_inode = inode;
ihold(inode);
intr_req->r_num_caps = 1;
intr_req->r_args.filelock_change = req->r_args.filelock_change;
intr_req->r_args.filelock_change.rule = lock_type;
intr_req->r_args.filelock_change.type = CEPH_LOCK_UNLOCK;
err = ceph_mdsc_do_request(mdsc, inode, intr_req);
ceph_mdsc_put_request(intr_req);
if (err && err != -ERESTARTSYS)
return err;
err = wait_for_completion_killable(&req->r_safe_completion);
if (err)
return err;
return 0;
}
static int try_unlock_file(struct file *file, struct file_lock *fl)
{
int err;
unsigned int orig_flags = fl->c.flc_flags;
fl->c.flc_flags |= FL_EXISTS;
err = locks_lock_file_wait(file, fl);
fl->c.flc_flags = orig_flags;
if (err == -ENOENT) {
if (!(orig_flags & FL_EXISTS))
err = 0;
return err;
}
return 1;
}
/*
* Attempt to set an fcntl lock.
* For now, this just goes away to the server. Later it may be more awesome.
*/
int ceph_lock(struct file *file, int cmd, struct file_lock *fl)
{
struct inode *inode = file_inode(file);
struct ceph_inode_info *ci = ceph_inode(inode);
struct ceph_client *cl = ceph_inode_to_client(inode);
int err = 0;
u16 op = CEPH_MDS_OP_SETFILELOCK;
u8 wait = 0;
u8 lock_cmd;
if (!(fl->c.flc_flags & FL_POSIX))
return -ENOLCK;
if (ceph_inode_is_shutdown(inode))
return -ESTALE;
doutc(cl, "fl_owner: %p\n", fl->c.flc_owner);
/* set wait bit as appropriate, then make command as Ceph expects it*/
if (IS_GETLK(cmd))
op = CEPH_MDS_OP_GETFILELOCK;
else if (IS_SETLKW(cmd))
wait = 1;
spin_lock(&ci->i_ceph_lock);
if (ci->i_ceph_flags & CEPH_I_ERROR_FILELOCK) {
err = -EIO;
}
spin_unlock(&ci->i_ceph_lock);
if (err < 0) {
if (op == CEPH_MDS_OP_SETFILELOCK && lock_is_unlock(fl))
posix_lock_file(file, fl, NULL);
return err;
}
if (lock_is_read(fl))
Annotation
- Immediate include surface: `linux/ceph/ceph_debug.h`, `linux/file.h`, `linux/namei.h`, `linux/random.h`, `super.h`, `mds_client.h`, `linux/filelock.h`, `linux/ceph/pagelist.h`.
- Detected declarations: `function secure_addr`, `function ceph_flock_init`, `function ceph_fl_copy_lock`, `function ceph_fl_release_lock`, `function ceph_lock_message`, `function ceph_lock_wait_for_completion`, `function try_unlock_file`, `function ceph_lock`, `function ceph_flock`, `function ceph_count_locks`.
- Atlas domain: Core OS / VFS And Filesystem Core.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.