From c8503e1a71ab992e46940ee5482db01235100d4b Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Thu, 22 May 2025 21:29:44 -0400 Subject: kernel: dcdr: Overwrite existing DCDs if required When writing to a drive, existing cached entries must be written through so DCD reads don't give stale data. Signed-off-by: Ian Moffett --- sys/dev/dcdr/cache.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'sys') diff --git a/sys/dev/dcdr/cache.c b/sys/dev/dcdr/cache.c index c44c8ea..33f977e 100644 --- a/sys/dev/dcdr/cache.c +++ b/sys/dev/dcdr/cache.c @@ -126,6 +126,20 @@ struct dcd * dcdr_cachein(struct dcdr *dcdr, void *block, off_t lba) { struct dcd *dcd, *tmp; + struct dcdr_lookup check; + int status; + + /* + * If there is already a block within this + * DCDR, then we simply need to copy the + * new data into the old DCD. + */ + status = dcdr_lookup(dcdr, lba, &check); + if (status == 0) { + dcd = check.dcd_res; + memcpy(dcd->block, block, dcdr->bsize); + return dcd; + } dcd = dynalloc(sizeof(*dcd)); if (dcd == NULL) { -- cgit v1.2.3