drivers/block/drbd/drbd_bitmap.c
Source file repositories/reference/linux-study-clean/drivers/block/drbd/drbd_bitmap.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/block/drbd/drbd_bitmap.c- Extension
.c- Size
- 49055 bytes
- Lines
- 1698
- 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/bitmap.hlinux/vmalloc.hlinux/string.hlinux/drbd.hlinux/slab.hlinux/highmem.hdrbd_int.h
Detected Declarations
struct drbd_bitmapfunction __bm_print_lock_infofunction drbd_bm_lockfunction drbd_bm_unlockfunction bm_store_page_idxfunction bm_page_to_idxfunction bm_page_lock_iofunction bm_page_unlock_iofunction bm_set_page_unchangedfunction bm_set_page_need_writeoutfunction drbd_bm_reset_al_hintsfunction drbd_bm_mark_for_writeoutfunction bm_test_page_unchangedfunction bm_set_page_io_errfunction bm_clear_page_io_errfunction bm_set_page_lazy_writeoutfunction bm_test_page_lazy_writeoutfunction bm_word_to_page_idxfunction bm_bit_to_page_idxfunction __bm_unmapfunction bm_unmapfunction bm_free_pagesfunction bm_vk_freefunction drbd_bm_initfunction drbd_bm_capacityfunction drbd_bm_cleanupfunction sincefunction bm_set_surplusfunction bm_count_bitsfunction bm_memsetfunction drbd_md_on_disk_bitsfunction drbd_bm_resizefunction _drbd_bm_total_weightfunction drbd_bm_total_weightfunction drbd_bm_wordsfunction drbd_bm_bitsfunction drbd_bm_merge_lelfunction drbd_bm_get_lelfunction drbd_bm_set_allfunction drbd_bm_clear_allfunction drbd_bm_aio_ctx_destroyfunction drbd_bm_endiofunction drbd_md_last_bitmap_sectorfunction bm_page_io_asyncfunction bm_rwfunction drbd_bm_readfunction drbd_bm_writefunction drbd_bm_write_all
Annotated Snippet
struct drbd_bitmap {
struct page **bm_pages;
spinlock_t bm_lock;
/* exclusively to be used by __al_write_transaction(),
* drbd_bm_mark_for_writeout() and
* and drbd_bm_write_hinted() -> bm_rw() called from there.
*/
unsigned int n_bitmap_hints;
unsigned int al_bitmap_hints[AL_UPDATES_PER_TRANSACTION];
/* see LIMITATIONS: above */
unsigned long bm_set; /* nr of set bits; THINK maybe atomic_t? */
unsigned long bm_bits;
size_t bm_words;
size_t bm_number_of_pages;
sector_t bm_dev_capacity;
struct mutex bm_change; /* serializes resize operations */
wait_queue_head_t bm_io_wait; /* used to serialize IO of single pages */
enum bm_flag bm_flags;
/* debugging aid, in case we are still racy somewhere */
char *bm_why;
struct task_struct *bm_task;
};
#define bm_print_lock_info(m) __bm_print_lock_info(m, __func__)
static void __bm_print_lock_info(struct drbd_device *device, const char *func)
{
struct drbd_bitmap *b = device->bitmap;
if (!drbd_ratelimit())
return;
drbd_err(device, "FIXME %s[%d] in %s, bitmap locked for '%s' by %s[%d]\n",
current->comm, task_pid_nr(current),
func, b->bm_why ?: "?",
b->bm_task->comm, task_pid_nr(b->bm_task));
}
void drbd_bm_lock(struct drbd_device *device, char *why, enum bm_flag flags)
{
struct drbd_bitmap *b = device->bitmap;
int trylock_failed;
if (!b) {
drbd_err(device, "FIXME no bitmap in drbd_bm_lock!?\n");
return;
}
trylock_failed = !mutex_trylock(&b->bm_change);
if (trylock_failed) {
drbd_warn(device, "%s[%d] going to '%s' but bitmap already locked for '%s' by %s[%d]\n",
current->comm, task_pid_nr(current),
why, b->bm_why ?: "?",
b->bm_task->comm, task_pid_nr(b->bm_task));
mutex_lock(&b->bm_change);
}
if (BM_LOCKED_MASK & b->bm_flags)
drbd_err(device, "FIXME bitmap already locked in bm_lock\n");
b->bm_flags |= flags & BM_LOCKED_MASK;
b->bm_why = why;
b->bm_task = current;
}
void drbd_bm_unlock(struct drbd_device *device)
{
struct drbd_bitmap *b = device->bitmap;
if (!b) {
drbd_err(device, "FIXME no bitmap in drbd_bm_unlock!?\n");
return;
}
if (!(BM_LOCKED_MASK & device->bitmap->bm_flags))
drbd_err(device, "FIXME bitmap not locked in bm_unlock\n");
b->bm_flags &= ~BM_LOCKED_MASK;
b->bm_why = NULL;
b->bm_task = NULL;
mutex_unlock(&b->bm_change);
}
/* we store some "meta" info about our pages in page->private */
/* at a granularity of 4k storage per bitmap bit:
* one peta byte storage: 1<<50 byte, 1<<38 * 4k storage blocks
* 1<<38 bits,
* 1<<23 4k bitmap pages.
Annotation
- Immediate include surface: `linux/bitmap.h`, `linux/vmalloc.h`, `linux/string.h`, `linux/drbd.h`, `linux/slab.h`, `linux/highmem.h`, `drbd_int.h`.
- Detected declarations: `struct drbd_bitmap`, `function __bm_print_lock_info`, `function drbd_bm_lock`, `function drbd_bm_unlock`, `function bm_store_page_idx`, `function bm_page_to_idx`, `function bm_page_lock_io`, `function bm_page_unlock_io`, `function bm_set_page_unchanged`, `function bm_set_page_need_writeout`.
- 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.