drivers/block/drbd/drbd_nl.c
Source file repositories/reference/linux-study-clean/drivers/block/drbd/drbd_nl.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/block/drbd/drbd_nl.c- Extension
.c- Size
- 149047 bytes
- Lines
- 5096
- Domain
- Driver Families
- Bucket
- drivers/block
- Inferred role
- Driver Families: implementation source
- Status
- source implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- 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/module.hlinux/drbd.hlinux/in.hlinux/fs.hlinux/file.hlinux/slab.hlinux/blkpg.hlinux/cpumask.hdrbd_int.hdrbd_protocol.hdrbd_req.hdrbd_state_change.hlinux/unaligned.hlinux/drbd_limits.hlinux/kthread.hnet/genetlink.hdrbd_nl_gen.h
Detected Declarations
struct md_offsets_and_sizesstruct cryptoenum mdf_peer_flagfunction Copyrightfunction drbd_adm_send_replyfunction drbd_msg_put_infofunction drbd_msg_sprintf_infofunction drbd_adm_preparefunction drbd_pre_doitfunction drbd_post_doitfunction setup_khelper_envfunction drbd_khelperfunction conn_khelperfunction highest_fencing_policyfunction resource_is_supendedfunction conn_try_outdate_peerfunction _try_outdate_peer_asyncfunction conn_try_outdate_peer_asyncfunction drbd_set_rolefunction drbd_nl_set_rolefunction drbd_nl_primary_doitfunction drbd_nl_secondary_doitfunction drbd_md_set_sector_offsetsfunction receive_sizesfunction drbd_resume_iofunction drbd_determine_dev_sizefunction drbd_new_dev_sizefunction drbd_check_al_sizefunction drbd_max_peer_bio_sizefunction drbd_max_discard_sectorsfunction drbd_discard_supportedfunction drbd_backing_dev_max_segmentsfunction drbd_reconsider_queue_parametersfunction conn_reconfig_startfunction conn_reconfig_donefunction drbd_suspend_alfunction should_set_defaultsfunction drbd_al_extents_maxfunction write_ordering_changedfunction sanitize_disk_conffunction disk_opts_check_al_sizefunction drbd_nl_chg_disk_opts_doitfunction open_backing_devicesfunction close_backing_devfunction drbd_backing_dev_freefunction drbd_nl_attach_doitfunction adm_detachfunction drbd_nl_detach_doit
Annotated Snippet
struct md_offsets_and_sizes {
u64 last_agreed_sect;
u64 md_offset;
s32 al_offset;
s32 bm_offset;
u32 md_size_sect;
u32 al_stripes;
u32 al_stripe_size_4k;
} prev;
sector_t u_size, size;
struct drbd_md *md = &device->ldev->md;
void *buffer;
int md_moved, la_size_changed;
enum determine_dev_size rv = DS_UNCHANGED;
/* We may change the on-disk offsets of our meta data below. Lock out
* anything that may cause meta data IO, to avoid acting on incomplete
* layout changes or scribbling over meta data that is in the process
* of being moved.
*
* Move is not exactly correct, btw, currently we have all our meta
* data in core memory, to "move" it we just write it all out, there
* are no reads. */
drbd_suspend_io(device);
buffer = drbd_md_get_buffer(device, __func__); /* Lock meta-data IO */
if (!buffer) {
drbd_resume_io(device);
return DS_ERROR;
}
/* remember current offset and sizes */
prev.last_agreed_sect = md->la_size_sect;
prev.md_offset = md->md_offset;
prev.al_offset = md->al_offset;
prev.bm_offset = md->bm_offset;
prev.md_size_sect = md->md_size_sect;
prev.al_stripes = md->al_stripes;
prev.al_stripe_size_4k = md->al_stripe_size_4k;
if (rs) {
/* rs is non NULL if we should change the AL layout only */
md->al_stripes = rs->al_stripes;
md->al_stripe_size_4k = rs->al_stripe_size / 4;
md->al_size_4k = (u64)rs->al_stripes * rs->al_stripe_size / 4;
}
drbd_md_set_sector_offsets(device, device->ldev);
rcu_read_lock();
u_size = rcu_dereference(device->ldev->disk_conf)->disk_size;
rcu_read_unlock();
size = drbd_new_dev_size(device, device->ldev, u_size, flags & DDSF_FORCED);
if (size < prev.last_agreed_sect) {
if (rs && u_size == 0) {
/* Remove "rs &&" later. This check should always be active, but
right now the receiver expects the permissive behavior */
drbd_warn(device, "Implicit shrink not allowed. "
"Use --size=%llus for explicit shrink.\n",
(unsigned long long)size);
rv = DS_ERROR_SHRINK;
}
if (u_size > size)
rv = DS_ERROR_SPACE_MD;
if (rv != DS_UNCHANGED)
goto err_out;
}
if (get_capacity(device->vdisk) != size ||
drbd_bm_capacity(device) != size) {
int err;
err = drbd_bm_resize(device, size, !(flags & DDSF_NO_RESYNC));
if (unlikely(err)) {
/* currently there is only one error: ENOMEM! */
size = drbd_bm_capacity(device);
if (size == 0) {
drbd_err(device, "OUT OF MEMORY! "
"Could not allocate bitmap!\n");
} else {
drbd_err(device, "BM resizing failed. "
"Leaving size unchanged\n");
}
rv = DS_ERROR;
}
/* racy, see comments above. */
drbd_set_my_capacity(device, size);
md->la_size_sect = size;
}
Annotation
- Immediate include surface: `linux/module.h`, `linux/drbd.h`, `linux/in.h`, `linux/fs.h`, `linux/file.h`, `linux/slab.h`, `linux/blkpg.h`, `linux/cpumask.h`.
- Detected declarations: `struct md_offsets_and_sizes`, `struct crypto`, `enum mdf_peer_flag`, `function Copyright`, `function drbd_adm_send_reply`, `function drbd_msg_put_info`, `function drbd_msg_sprintf_info`, `function drbd_adm_prepare`, `function drbd_pre_doit`, `function drbd_post_doit`.
- Atlas domain: Driver Families / drivers/block.
- 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.