drivers/block/drbd/drbd_state.c
Source file repositories/reference/linux-study-clean/drivers/block/drbd/drbd_state.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/block/drbd/drbd_state.c- Extension
.c- Size
- 75346 bytes
- Lines
- 2398
- 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/drbd_limits.hdrbd_int.hdrbd_protocol.hdrbd_req.hdrbd_state_change.h
Detected Declarations
struct after_state_chg_workstruct after_conn_state_chg_workenum sanitize_state_warningsfunction count_objectsfunction for_each_connectionfunction remember_new_statefunction copy_old_to_new_state_changefunction forget_state_changefunction is_suspfunction conn_all_vols_unconffunction max_rolefunction min_rolefunction conn_highest_rolefunction conn_highest_peerfunction conn_highest_diskfunction conn_lowest_diskfunction conn_highest_pdskfunction conn_lowest_connfunction no_peer_wf_report_paramsfunction wake_up_all_devicesfunction cl_wide_st_chgfunction apply_mask_valfunction drbd_change_statefunction drbd_force_statefunction _req_st_condfunction drbd_req_statefunction _drbd_request_statefunction drbd_md_get_bufferfunction drbd_request_detach_interruptiblefunction _drbd_request_state_holding_state_mutexfunction print_stfunction print_st_errfunction print_state_changefunction drbd_pr_state_changefunction conn_pr_state_changefunction is_valid_statefunction is_valid_soft_transitionfunction is_valid_conn_transitionfunction is_valid_transitionfunction print_sanitize_warningsfunction sanitize_statefunction get_ldev_if_statefunction drbd_resume_alfunction set_ov_positionfunction _drbd_set_statefunction no_peer_wf_report_paramsfunction w_after_state_chfunction abw_start_sync
Annotated Snippet
struct after_state_chg_work {
struct drbd_work w;
struct drbd_device *device;
union drbd_state os;
union drbd_state ns;
enum chg_state_flags flags;
struct completion *done;
struct drbd_state_change *state_change;
};
enum sanitize_state_warnings {
NO_WARNING,
ABORTED_ONLINE_VERIFY,
ABORTED_RESYNC,
CONNECTION_LOST_NEGOTIATING,
IMPLICITLY_UPGRADED_DISK,
IMPLICITLY_UPGRADED_PDSK,
};
static void count_objects(struct drbd_resource *resource,
unsigned int *n_devices,
unsigned int *n_connections)
{
struct drbd_device *device;
struct drbd_connection *connection;
int vnr;
*n_devices = 0;
*n_connections = 0;
idr_for_each_entry(&resource->devices, device, vnr)
(*n_devices)++;
for_each_connection(connection, resource)
(*n_connections)++;
}
static struct drbd_state_change *alloc_state_change(unsigned int n_devices, unsigned int n_connections, gfp_t gfp)
{
struct drbd_state_change *state_change;
unsigned int size, n;
size = sizeof(struct drbd_state_change) +
n_devices * sizeof(struct drbd_device_state_change) +
n_connections * sizeof(struct drbd_connection_state_change) +
n_devices * n_connections * sizeof(struct drbd_peer_device_state_change);
state_change = kmalloc(size, gfp);
if (!state_change)
return NULL;
state_change->n_devices = n_devices;
state_change->n_connections = n_connections;
state_change->devices = (void *)(state_change + 1);
state_change->connections = (void *)&state_change->devices[n_devices];
state_change->peer_devices = (void *)&state_change->connections[n_connections];
state_change->resource->resource = NULL;
for (n = 0; n < n_devices; n++)
state_change->devices[n].device = NULL;
for (n = 0; n < n_connections; n++)
state_change->connections[n].connection = NULL;
return state_change;
}
struct drbd_state_change *remember_old_state(struct drbd_resource *resource, gfp_t gfp)
{
struct drbd_state_change *state_change;
struct drbd_device *device;
unsigned int n_devices;
struct drbd_connection *connection;
unsigned int n_connections;
int vnr;
struct drbd_device_state_change *device_state_change;
struct drbd_peer_device_state_change *peer_device_state_change;
struct drbd_connection_state_change *connection_state_change;
/* Caller holds req_lock spinlock.
* No state, no device IDR, no connections lists can change. */
count_objects(resource, &n_devices, &n_connections);
state_change = alloc_state_change(n_devices, n_connections, gfp);
if (!state_change)
return NULL;
kref_get(&resource->kref);
state_change->resource->resource = resource;
state_change->resource->role[OLD] =
conn_highest_role(first_connection(resource));
state_change->resource->susp[OLD] = resource->susp;
state_change->resource->susp_nod[OLD] = resource->susp_nod;
state_change->resource->susp_fen[OLD] = resource->susp_fen;
connection_state_change = state_change->connections;
Annotation
- Immediate include surface: `linux/drbd_limits.h`, `drbd_int.h`, `drbd_protocol.h`, `drbd_req.h`, `drbd_state_change.h`.
- Detected declarations: `struct after_state_chg_work`, `struct after_conn_state_chg_work`, `enum sanitize_state_warnings`, `function count_objects`, `function for_each_connection`, `function remember_new_state`, `function copy_old_to_new_state_change`, `function forget_state_change`, `function is_susp`, `function conn_all_vols_unconf`.
- 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.