在 7/1/2025 9:56 PM, Jonathan Cameron 写道:
On Tue, 24 Jun 2025 07:33:49 +0000
Dongsheng Yang <dongsheng.y...@linux.dev> wrote:

This patch introduces *backing_dev.{c,h}*, a self-contained layer that
handles all interaction with the *backing block device* where cache
write-back and cache-miss reads are serviced.  Isolating this logic
keeps the core dm-pcache code free of low-level bio plumbing.

* Device setup / teardown
   - Opens the target with `dm_get_device()`, stores `bdev`, file and
     size, and initialises a dedicated `bioset`.
   - Gracefully releases resources via `backing_dev_stop()`.

* Request object (`struct pcache_backing_dev_req`)
   - Two request flavours:
     - REQ-type – cloned from an upper `struct bio` issued to
       dm-pcache; trimmed and re-targeted to the backing LBA.
     - KMEM-type – maps an arbitrary kernel memory buffer
       into a freshly built.
   - Private completion callback (`end_req`) propagates status to the
     upper layer and handles resource recycling.

* Submission & completion path
   - Lock-protected submit queue + worker (`req_submit_work`) let pcache
     push many requests asynchronously, at the same time, allow caller
     to submit backing_dev_req in atomic context.
   - End-io handler moves finished requests to a completion list processed
     by `req_complete_work`, ensuring callbacks run in process context.
   - Direct-submit option for non-atomic context.

* Flush
   - `backing_dev_flush()` issues a flush to persist backing-device data.

Signed-off-by: Dongsheng Yang <dongsheng.y...@linux.dev>
---
  drivers/md/dm-pcache/backing_dev.c | 292 +++++++++++++++++++++++++++++
  drivers/md/dm-pcache/backing_dev.h |  88 +++++++++
  2 files changed, 380 insertions(+)
  create mode 100644 drivers/md/dm-pcache/backing_dev.c
  create mode 100644 drivers/md/dm-pcache/backing_dev.h
+
+struct pcache_backing_dev_req *backing_dev_req_create(struct 
pcache_backing_dev *backing_dev,
+                                               struct 
pcache_backing_dev_req_opts *opts)
+{
+       if (opts->type == BACKING_DEV_REQ_TYPE_REQ)
+               return req_type_req_create(backing_dev, opts);
+       else if (opts->type == BACKING_DEV_REQ_TYPE_KMEM)

returned in earlier branch so go with simpler

        if (opts->type..)

Hi Jonathan,

This looks good, I am willing to do this change.


Thanx

Dongsheng

Or use a switch statement if you expect to get more entries in this over time.

+               return kmem_type_req_create(backing_dev, opts);
+
+       return NULL;
+}
+
+void backing_dev_flush(struct pcache_backing_dev *backing_dev)
+{
+       blkdev_issue_flush(backing_dev->dm_dev->bdev);
+}


Reply via email to