fs/smb/smbdirect/mr.c
Source file repositories/reference/linux-study-clean/fs/smb/smbdirect/mr.c
File Facts
- System
- Linux kernel
- Corpus path
fs/smb/smbdirect/mr.c- Extension
.c- Size
- 14231 bytes
- Lines
- 497
- Domain
- Core OS
- Bucket
- VFS And Filesystem Core
- Inferred role
- Core OS: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- 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
internal.h
Detected Declarations
function Copyrightfunction smbdirect_mr_io_disable_lockedfunction smbdirect_mr_io_free_lockedfunction smbdirect_connection_destroy_mr_listfunction list_for_each_entry_safefunction smbdirect_connection_get_mr_iofunction smbdirect_connection_mr_io_register_donefunction smbdirect_connection_mr_io_local_inv_donefunction smbdirect_iter_to_sgtfunction smbdirect_connection_register_mr_iofunction smbdirect_mr_io_fill_buffer_descriptorfunction smbdirect_connection_deregister_mr_ioexport smbdirect_connection_register_mr_ioexport smbdirect_mr_io_fill_buffer_descriptorexport smbdirect_connection_deregister_mr_io
Annotated Snippet
if (!mr) {
ret = -ENOMEM;
goto kzalloc_mr_failed;
}
kref_init(&mr->kref);
mutex_init(&mr->mutex);
mr->mr = ib_alloc_mr(sc->ib.pd,
sc->mr_io.type,
sp->max_frmr_depth);
if (IS_ERR(mr->mr)) {
ret = PTR_ERR(mr->mr);
smbdirect_log_rdma_mr(sc, SMBDIRECT_LOG_ERR,
"ib_alloc_mr failed ret=%d (%1pe) type=0x%x max_frmr_depth=%u\n",
ret, SMBDIRECT_DEBUG_ERR_PTR(ret),
sc->mr_io.type, sp->max_frmr_depth);
goto ib_alloc_mr_failed;
}
mr->sgt.sgl = kzalloc_objs(struct scatterlist, sp->max_frmr_depth);
if (!mr->sgt.sgl) {
ret = -ENOMEM;
smbdirect_log_rdma_mr(sc, SMBDIRECT_LOG_ERR,
"failed to allocate sgl, max_frmr_depth=%u\n",
sp->max_frmr_depth);
goto kcalloc_sgl_failed;
}
mr->state = SMBDIRECT_MR_READY;
mr->socket = sc;
list_add_tail(&mr->list, &sc->mr_io.all.list);
atomic_inc(&sc->mr_io.ready.count);
}
return 0;
kcalloc_sgl_failed:
ib_dereg_mr(mr->mr);
ib_alloc_mr_failed:
mutex_destroy(&mr->mutex);
kfree(mr);
kzalloc_mr_failed:
smbdirect_connection_destroy_mr_list(sc);
return ret;
}
static void smbdirect_mr_io_disable_locked(struct smbdirect_mr_io *mr)
{
struct smbdirect_socket *sc = mr->socket;
lockdep_assert_held(&mr->mutex);
if (mr->state == SMBDIRECT_MR_DISABLED)
return;
if (mr->mr)
ib_dereg_mr(mr->mr);
if (mr->sgt.nents)
ib_dma_unmap_sg(sc->ib.dev, mr->sgt.sgl, mr->sgt.nents, mr->dir);
kfree(mr->sgt.sgl);
mr->mr = NULL;
mr->sgt.sgl = NULL;
mr->sgt.nents = 0;
mr->state = SMBDIRECT_MR_DISABLED;
}
static void smbdirect_mr_io_free_locked(struct kref *kref)
{
struct smbdirect_mr_io *mr =
container_of(kref, struct smbdirect_mr_io, kref);
lockdep_assert_held(&mr->mutex);
/*
* smbdirect_mr_io_disable_locked() should already be called!
*/
if (WARN_ON_ONCE(mr->state != SMBDIRECT_MR_DISABLED))
smbdirect_mr_io_disable_locked(mr);
mutex_unlock(&mr->mutex);
mutex_destroy(&mr->mutex);
kfree(mr);
}
void smbdirect_connection_destroy_mr_list(struct smbdirect_socket *sc)
{
struct smbdirect_mr_io *mr, *tmp;
LIST_HEAD(all_list);
Annotation
- Immediate include surface: `internal.h`.
- Detected declarations: `function Copyright`, `function smbdirect_mr_io_disable_locked`, `function smbdirect_mr_io_free_locked`, `function smbdirect_connection_destroy_mr_list`, `function list_for_each_entry_safe`, `function smbdirect_connection_get_mr_io`, `function smbdirect_connection_mr_io_register_done`, `function smbdirect_connection_mr_io_local_inv_done`, `function smbdirect_iter_to_sgt`, `function smbdirect_connection_register_mr_io`.
- Atlas domain: Core OS / VFS And Filesystem Core.
- Implementation status: integration 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.