fs/ceph/snap.c
Source file repositories/reference/linux-study-clean/fs/ceph/snap.c
File Facts
- System
- Linux kernel
- Corpus path
fs/ceph/snap.c- Extension
.c- Size
- 38067 bytes
- Lines
- 1344
- 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.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/ceph/ceph_debug.hlinux/fs.hlinux/sort.hlinux/slab.hlinux/iversion.hsuper.hmds_client.hlinux/ceph/decode.h
Detected Declarations
function parentfunction __insert_snap_realmfunction snap_rwsemfunction snap_rwsemfunction ceph_put_snap_realmfunction snap_rwsemfunction ceph_cleanup_global_and_empty_realmsfunction adjust_snap_realm_parentfunction cmpu64_revfunction build_snap_contextfunction rebuild_snap_realmsfunction rebuild_snap_realmsfunction list_for_each_entryfunction dup_arrayfunction has_new_snapsfunction ceph_cap_snapfunction ceph_try_drop_cap_snapfunction __ceph_finish_cap_snapfunction queue_realm_cap_snapsfunction ceph_queue_cap_snapfunction ceph_update_snap_tracefunction flush_snapsfunction snaprealmfunction ceph_handle_snapfunction racefunction ceph_get_snapid_mapfunction ceph_put_snapid_mapfunction ceph_trim_snapid_mapfunction ceph_cleanup_snapid_map
Annotated Snippet
if (!parent->cached_context) {
/* add to the queue head */
list_add(&parent->rebuild_item, realm_queue);
return 1;
}
num += parent->cached_context->num_snaps;
}
/* do i actually need to update? not if my context seq
matches realm seq, and my parents' does to. (this works
because we rebuild_snap_realms() works _downward_ in
hierarchy after each update.) */
if (realm->cached_context &&
realm->cached_context->seq == realm->seq &&
(!parent ||
realm->cached_context->seq >= parent->cached_context->seq)) {
doutc(cl, "%llx %p: %p seq %lld (%u snaps) (unchanged)\n",
realm->ino, realm, realm->cached_context,
realm->cached_context->seq,
(unsigned int)realm->cached_context->num_snaps);
return 0;
}
/* alloc new snap context */
err = -ENOMEM;
if ((size_t)num > (SIZE_MAX - sizeof(*snapc)) / sizeof(u64))
goto fail;
snapc = ceph_create_snap_context(num, GFP_NOFS);
if (!snapc)
goto fail;
/* build (reverse sorted) snap vector */
num = 0;
snapc->seq = realm->seq;
if (parent) {
u32 i;
/* include any of parent's snaps occurring _after_ my
parent became my parent */
for (i = 0; i < parent->cached_context->num_snaps; i++)
if (parent->cached_context->snaps[i] >=
realm->parent_since)
snapc->snaps[num++] =
parent->cached_context->snaps[i];
if (parent->cached_context->seq > snapc->seq)
snapc->seq = parent->cached_context->seq;
}
memcpy(snapc->snaps + num, realm->snaps,
sizeof(u64)*realm->num_snaps);
num += realm->num_snaps;
memcpy(snapc->snaps + num, realm->prior_parent_snaps,
sizeof(u64)*realm->num_prior_parent_snaps);
num += realm->num_prior_parent_snaps;
sort(snapc->snaps, num, sizeof(u64), cmpu64_rev, NULL);
snapc->num_snaps = num;
doutc(cl, "%llx %p: %p seq %lld (%u snaps)\n", realm->ino, realm,
snapc, snapc->seq, (unsigned int) snapc->num_snaps);
ceph_put_snap_context(realm->cached_context);
realm->cached_context = snapc;
/* queue realm for cap_snap creation */
list_add_tail(&realm->dirty_item, dirty_realms);
return 0;
fail:
/*
* if we fail, clear old (incorrect) cached_context... hopefully
* we'll have better luck building it later
*/
if (realm->cached_context) {
ceph_put_snap_context(realm->cached_context);
realm->cached_context = NULL;
}
pr_err_client(cl, "%llx %p fail %d\n", realm->ino, realm, err);
return err;
}
/*
* rebuild snap context for the given realm and all of its children.
*/
static void rebuild_snap_realms(struct ceph_mds_client *mdsc,
struct ceph_snap_realm *realm,
struct list_head *dirty_realms)
{
struct ceph_client *cl = mdsc->fsc->client;
LIST_HEAD(realm_queue);
int last = 0;
bool skip = false;
Annotation
- Immediate include surface: `linux/ceph/ceph_debug.h`, `linux/fs.h`, `linux/sort.h`, `linux/slab.h`, `linux/iversion.h`, `super.h`, `mds_client.h`, `linux/ceph/decode.h`.
- Detected declarations: `function parent`, `function __insert_snap_realm`, `function snap_rwsem`, `function snap_rwsem`, `function ceph_put_snap_realm`, `function snap_rwsem`, `function ceph_cleanup_global_and_empty_realms`, `function adjust_snap_realm_parent`, `function cmpu64_rev`, `function build_snap_context`.
- 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.