drivers/block/rbd.c
Source file repositories/reference/linux-study-clean/drivers/block/rbd.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/block/rbd.c- Extension
.c- Size
- 190786 bytes
- Lines
- 7450
- Domain
- Driver Families
- Bucket
- drivers/block
- Inferred role
- Driver Families: operation-table or driver-model contract
- Status
- pattern 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.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- 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/libceph.hlinux/ceph/osd_client.hlinux/ceph/mon_client.hlinux/ceph/cls_lock_client.hlinux/ceph/striper.hlinux/ceph/decode.hlinux/fs_parser.hlinux/bsearch.hlinux/kernel.hlinux/device.hlinux/module.hlinux/blk-mq.hlinux/fs.hlinux/blkdev.hlinux/slab.hlinux/idr.hlinux/workqueue.hrbd_types.h
Detected Declarations
struct rbd_image_headerstruct rbd_specstruct rbd_clientstruct pending_resultstruct rbd_img_requeststruct rbd_obj_requeststruct rbd_img_requeststruct rbd_client_idstruct rbd_mappingstruct rbd_devicestruct rbd_optionsstruct rbd_parse_opts_ctxstruct rbd_img_fill_ctxstruct parent_image_infoenum obj_request_typeenum obj_operation_typeenum rbd_obj_read_stateenum rbd_obj_write_stateenum rbd_obj_copyup_stateenum img_req_flagsenum rbd_img_stateenum rbd_watch_stateenum rbd_lock_stateenum rbd_dev_flagsfunction atomic_inc_return_safefunction atomic_dec_return_safefunction rbd_dev_id_to_minorfunction minor_to_rbd_dev_idfunction rbd_is_rofunction rbd_is_snapfunction __rbd_is_lock_ownerfunction rbd_is_lock_ownerfunction supported_features_showfunction rbd_bus_is_visiblefunction rbd_root_dev_releasefunction __printffunction pending_result_decfunction rbd_openfunction rbd_releasefunction obj_op_namefunction rbd_client_releasefunction rbd_put_clientfunction rbd_image_format_validfunction rbd_dev_ondisk_validfunction rbd_obj_bytesfunction rbd_init_layoutfunction rbd_image_header_cleanupfunction rbd_header_from_disk
Annotated Snippet
static ssize_t add_store(const struct bus_type *bus, const char *buf, size_t count);
static ssize_t remove_store(const struct bus_type *bus, const char *buf,
size_t count);
static ssize_t add_single_major_store(const struct bus_type *bus, const char *buf,
size_t count);
static ssize_t remove_single_major_store(const struct bus_type *bus, const char *buf,
size_t count);
static int rbd_dev_image_probe(struct rbd_device *rbd_dev, int depth);
static int rbd_dev_id_to_minor(int dev_id)
{
return dev_id << RBD_SINGLE_MAJOR_PART_SHIFT;
}
static int minor_to_rbd_dev_id(int minor)
{
return minor >> RBD_SINGLE_MAJOR_PART_SHIFT;
}
static bool rbd_is_ro(struct rbd_device *rbd_dev)
{
return test_bit(RBD_DEV_FLAG_READONLY, &rbd_dev->flags);
}
static bool rbd_is_snap(struct rbd_device *rbd_dev)
{
return rbd_dev->spec->snap_id != CEPH_NOSNAP;
}
static bool __rbd_is_lock_owner(struct rbd_device *rbd_dev)
{
lockdep_assert_held(&rbd_dev->lock_rwsem);
return rbd_dev->lock_state == RBD_LOCK_STATE_LOCKED ||
rbd_dev->lock_state == RBD_LOCK_STATE_QUIESCING;
}
static bool rbd_is_lock_owner(struct rbd_device *rbd_dev)
{
bool is_lock_owner;
down_read(&rbd_dev->lock_rwsem);
is_lock_owner = __rbd_is_lock_owner(rbd_dev);
up_read(&rbd_dev->lock_rwsem);
return is_lock_owner;
}
static ssize_t supported_features_show(const struct bus_type *bus, char *buf)
{
return sprintf(buf, "0x%llx\n", RBD_FEATURES_SUPPORTED);
}
static BUS_ATTR_WO(add);
static BUS_ATTR_WO(remove);
static BUS_ATTR_WO(add_single_major);
static BUS_ATTR_WO(remove_single_major);
static BUS_ATTR_RO(supported_features);
static struct attribute *rbd_bus_attrs[] = {
&bus_attr_add.attr,
&bus_attr_remove.attr,
&bus_attr_add_single_major.attr,
&bus_attr_remove_single_major.attr,
&bus_attr_supported_features.attr,
NULL,
};
static umode_t rbd_bus_is_visible(struct kobject *kobj,
struct attribute *attr, int index)
{
if (!single_major &&
(attr == &bus_attr_add_single_major.attr ||
attr == &bus_attr_remove_single_major.attr))
return 0;
return attr->mode;
}
static const struct attribute_group rbd_bus_group = {
.attrs = rbd_bus_attrs,
.is_visible = rbd_bus_is_visible,
};
__ATTRIBUTE_GROUPS(rbd_bus);
static const struct bus_type rbd_bus_type = {
.name = "rbd",
.bus_groups = rbd_bus_groups,
};
static void rbd_root_dev_release(struct device *dev)
Annotation
- Immediate include surface: `linux/ceph/libceph.h`, `linux/ceph/osd_client.h`, `linux/ceph/mon_client.h`, `linux/ceph/cls_lock_client.h`, `linux/ceph/striper.h`, `linux/ceph/decode.h`, `linux/fs_parser.h`, `linux/bsearch.h`.
- Detected declarations: `struct rbd_image_header`, `struct rbd_spec`, `struct rbd_client`, `struct pending_result`, `struct rbd_img_request`, `struct rbd_obj_request`, `struct rbd_img_request`, `struct rbd_client_id`, `struct rbd_mapping`, `struct rbd_device`.
- Atlas domain: Driver Families / drivers/block.
- Implementation status: pattern 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.