drivers/block/rnbd/rnbd-clt.c
Source file repositories/reference/linux-study-clean/drivers/block/rnbd/rnbd-clt.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/block/rnbd/rnbd-clt.c- Extension
.c- Size
- 46845 bytes
- Lines
- 1836
- 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.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- 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/blkdev.hlinux/hdreg.hlinux/scatterlist.hlinux/idr.hrnbd-clt.h
Detected Declarations
function rnbd_clt_get_sessfunction rnbd_clt_put_sessfunction rnbd_clt_put_devfunction rnbd_clt_get_devfunction rnbd_clt_change_capacityfunction process_msg_open_rspfunction rnbd_clt_resize_diskfunction rnbd_clt_dev_requeuefunction rnbd_get_cpu_qlistfunction nxt_cpufunction rnbd_rerun_if_neededfunction rnbd_rerun_all_if_idlefunction rnbd_put_permitfunction rnbd_put_iufunction rnbd_softirq_done_fnfunction msg_io_conffunction wake_up_iu_compfunction msg_conffunction send_usr_msgfunction msg_close_conffunction send_msg_closefunction msg_open_conffunction msg_sess_info_conffunction send_msg_openfunction send_msg_sess_infofunction set_dev_states_to_disconnectedfunction remap_devsfunction list_for_each_entryfunction rnbd_clt_link_evfunction rnbd_init_cpu_qlistsfunction for_each_possible_cpufunction destroy_mq_tagsfunction wake_up_rtrs_waitersfunction close_rtrsfunction free_sessfunction wait_for_rtrs_connectionfunction wait_for_rtrs_disconnectionfunction rnbd_client_openfunction rnbd_client_releasefunction rnbd_client_getgeofunction diskfunction rnbd_client_xfer_requestfunction rnbd_clt_dev_add_to_requeuefunction rnbd_clt_dev_kick_mq_queuefunction rnbd_queue_rqfunction rnbd_rdma_pollfunction rnbd_rdma_map_queuesfunction setup_mq_tags
Annotated Snippet
static struct blk_mq_ops rnbd_mq_ops = {
.queue_rq = rnbd_queue_rq,
.complete = rnbd_softirq_done_fn,
.map_queues = rnbd_rdma_map_queues,
.poll = rnbd_rdma_poll,
};
static int setup_mq_tags(struct rnbd_clt_session *sess)
{
struct blk_mq_tag_set *tag_set = &sess->tag_set;
memset(tag_set, 0, sizeof(*tag_set));
tag_set->ops = &rnbd_mq_ops;
tag_set->queue_depth = sess->queue_depth;
tag_set->numa_node = NUMA_NO_NODE;
tag_set->flags = BLK_MQ_F_TAG_QUEUE_SHARED;
tag_set->cmd_size = sizeof(struct rnbd_iu) + RNBD_RDMA_SGL_SIZE;
/* for HCTX_TYPE_DEFAULT, HCTX_TYPE_READ, HCTX_TYPE_POLL */
tag_set->nr_maps = sess->nr_poll_queues ? HCTX_MAX_TYPES : 2;
/*
* HCTX_TYPE_DEFAULT and HCTX_TYPE_READ share one set of queues
* others are for HCTX_TYPE_POLL
*/
tag_set->nr_hw_queues = num_online_cpus() + sess->nr_poll_queues;
tag_set->driver_data = sess;
return blk_mq_alloc_tag_set(tag_set);
}
static struct rnbd_clt_session *
find_and_get_or_create_sess(const char *sessname,
const struct rtrs_addr *paths,
size_t path_cnt, u16 port_nr, u32 nr_poll_queues)
{
struct rnbd_clt_session *sess;
struct rtrs_attrs attrs;
int err;
bool first = false;
struct rtrs_clt_ops rtrs_ops;
sess = find_or_create_sess(sessname, &first);
if (sess == ERR_PTR(-ENOMEM)) {
return ERR_PTR(-ENOMEM);
} else if ((nr_poll_queues && !first) || (!nr_poll_queues && sess->nr_poll_queues)) {
/*
* A device MUST have its own session to use the polling-mode.
* It must fail to map new device with the same session.
*/
err = -EINVAL;
goto put_sess;
}
if (!first)
return sess;
if (!path_cnt) {
pr_err("Session %s not found, and path parameter not given", sessname);
err = -ENXIO;
goto put_sess;
}
rtrs_ops = (struct rtrs_clt_ops) {
.priv = sess,
.link_ev = rnbd_clt_link_ev,
};
/*
* Nothing was found, establish rtrs connection and proceed further.
*/
sess->rtrs = rtrs_clt_open(&rtrs_ops, sessname,
paths, path_cnt, port_nr,
0, /* Do not use pdu of rtrs */
RECONNECT_DELAY,
MAX_RECONNECTS, nr_poll_queues);
if (IS_ERR(sess->rtrs)) {
err = PTR_ERR(sess->rtrs);
goto wake_up_and_put;
}
err = rtrs_clt_query(sess->rtrs, &attrs);
if (err)
goto close_rtrs;
sess->max_io_size = attrs.max_io_size;
sess->queue_depth = attrs.queue_depth;
sess->nr_poll_queues = nr_poll_queues;
sess->max_segments = attrs.max_segments;
err = setup_mq_tags(sess);
if (err)
Annotation
- Immediate include surface: `linux/module.h`, `linux/blkdev.h`, `linux/hdreg.h`, `linux/scatterlist.h`, `linux/idr.h`, `rnbd-clt.h`.
- Detected declarations: `function rnbd_clt_get_sess`, `function rnbd_clt_put_sess`, `function rnbd_clt_put_dev`, `function rnbd_clt_get_dev`, `function rnbd_clt_change_capacity`, `function process_msg_open_rsp`, `function rnbd_clt_resize_disk`, `function rnbd_clt_dev_requeue`, `function rnbd_get_cpu_qlist`, `function nxt_cpu`.
- 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.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.