📄 kern_preloadobsource.cxx
字号:
/* * Copyright (C) 2001, Jonathan S. Shapiro. * * This file is part of the EROS Operating System. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2, * or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *//* ObjectRange driver for preloaded ram ranges */#include <kerninc/kernel.hxx>#include <kerninc/Thread.hxx>#include <kerninc/Machine.hxx>#include <kerninc/util.h>#include <kerninc/ObjectCache.hxx>#include <kerninc/ObjectSource.hxx>#include <eros/Device.h>#include <disk/PagePot.hxx>#include <disk/DiskNode.hxx>#include <kerninc/BootInfo.h>/* The current implementation isn't quite kosher, as the current * implementation is built to assume a preloaded ramdisk, and the * ramdisk boot sector is inherently machine dependent. At some point * in the (near) future, I am going to implement the range preload * flag, and the need for this hack will go away. */#include <disk/LowVolume.hxx>PreloadObSource::PreloadObSource(DivisionInfo *div) : ObjectSource("preload", div->startOid, div->endOid){ base = div->where;}struct FrameInfo { uint32_t obFrameNdx; uint64_t obFrameNo; uint32_t clusterNo; uint32_t tagEntry; FrameInfo(OID oid);};FrameInfo::FrameInfo(OID oid){ obFrameNdx = oid % EROS_OBJECTS_PER_FRAME; obFrameNo = oid / EROS_OBJECTS_PER_FRAME; clusterNo = obFrameNo / DATA_PAGES_PER_PAGE_CLUSTER; tagEntry = obFrameNo % DATA_PAGES_PER_PAGE_CLUSTER; obFrameNo += clusterNo; obFrameNo++; /* add one for cluster pot in first cluster */}static boolFetchPage(PreloadObSource *src, ObjectHeader *pObj){ OID oid = pObj->ob.oid; assert(src->start <= oid && oid < src->end); void *dest = (uint8_t *) ObjectCache::ObHdrToPage(pObj); OID relOid = oid - src->start; /* convert to relative terms */ FrameInfo fi(relOid); assert(fi.obFrameNdx < DISK_NODES_PER_PAGE); kva_t ppaddr = src->base; ppaddr += (fi.clusterNo * PAGES_PER_PAGE_CLUSTER * EROS_PAGE_SIZE); PagePot * pp = (PagePot *) ppaddr; if (pp->type[fi.tagEntry] == FRM_TYPE_NODE || pp->type[fi.tagEntry] == FRM_TYPE_ZNODE) { /* Retag the existing frame to be a page frame. Do not bump the * allocation count when converting TO pages. * * Note an assumption here: when WriteObject(obj) is called it will * preserve the invariant that the count field in the page pot * will be max(pp->count[x], obj->ob.allocCount, obj->callCount). */ pp->type[fi.tagEntry] = FRM_TYPE_ZDPAGE; } if (pp->type[fi.tagEntry] == FRM_TYPE_DPAGE) { kva_t pageBase = src->base; pageBase += (fi.obFrameNo * EROS_PAGE_SIZE); bcopy((void *) pageBase, dest, EROS_PAGE_SIZE); return true; } else if (pp->type[fi.tagEntry] == FRM_TYPE_ZDPAGE) { bzero(dest, EROS_PAGE_SIZE); return true; } pObj->ob.allocCount = pp->count[fi.tagEntry]; return false;}static boolFetchNode(PreloadObSource *src, ObjectHeader *pObj){ OID oid = pObj->ob.oid; assert(src->start <= oid && oid < src->end); OID relOid = oid - src->start; /* convert to relative terms */ FrameInfo fi(relOid); assert(fi.obFrameNdx < DISK_NODES_PER_PAGE); kva_t ppaddr = src->base; ppaddr += (fi.clusterNo * PAGES_PER_PAGE_CLUSTER * EROS_PAGE_SIZE); PagePot * pp = (PagePot *) ppaddr; if (pp->type[fi.tagEntry] == FRM_TYPE_DPAGE || pp->type[fi.tagEntry] == FRM_TYPE_ZDPAGE) { /* Retag the existing frame to be a node frame. When converting * from pages to something else, we MUST bump the allocation * count. * * Note an assumption here: when WriteObject(obj) is called it will * preserve the invariant that the count field in the page pot * will be max(pp->count[x], obj->ob.allocCount, obj->callCount). */ pp->type[fi.tagEntry] = FRM_TYPE_ZNODE; } /* The first time we actually touch a ZNODE frame, convert it to a * proper node frame. */ if (pp->type[fi.tagEntry] == FRM_TYPE_ZNODE) { kva_t pageBase = src->base; pageBase += (fi.obFrameNo * EROS_PAGE_SIZE); DiskNode *dn = (DiskNode *) pageBase; OID frameOid = EROS_FRAME_FROM_OID(oid); for (unsigned i = 0; i < DISK_NODES_PER_PAGE; i++) { DiskNode *pNode = dn + i; pNode->allocCount = pp->count[fi.tagEntry]; pNode->callCount = pp->count[fi.tagEntry]; pNode->oid = frameOid + i; for (uint32_t ndx = 0; ndx < EROS_NODE_SIZE; ndx++) { assert ((*pNode)[ndx].IsUnprepared()); /* not hazarded because newly loaded node */ (*pNode)[ndx].KS_VoidInitKey(); } } pp->type[fi.tagEntry] = FRM_TYPE_NODE; } assert(pp->type[fi.tagEntry] == FRM_TYPE_NODE); kva_t pageBase = src->base; pageBase += (fi.obFrameNo * EROS_PAGE_SIZE); DiskNode *dn = (DiskNode *) pageBase; dn += fi.obFrameNdx; *((Node *)pObj) = *dn; return true;}ObjectHeader *PreloadObSource::GetObject(OID oid, ObType::Type obType, ObCount count, bool useCount){ ObjectHeader * pObj; bool result; if (obType == ObType::PtDataPage) { pObj = ObjectCache::GrabPageFrame(); pObj->ob.oid = oid; result = FetchPage(this, pObj); } else { assert(obType == ObType::NtUnprepared); pObj = ObjectCache::GrabNodeFrame(); pObj->ob.oid = oid; result = FetchNode(this, pObj); } if (!result || (useCount && pObj->ob.allocCount != count)) { ObjectCache::ReleaseFrame(pObj); return 0; } assert (pObj->ob.oid == oid); pObj->age = Age::NewBorn; pObj->SetFlags(OFLG_CURRENT|OFLG_DISKCAPS); assert (pObj->GetFlags(OFLG_CKPT|OFLG_DIRTY|OFLG_REDIRTY|OFLG_IO) == 0); pObj->ob.ioCount = 0; pObj->obType = obType;#ifdef OPTION_OB_MOD_CHECK pObj->ob.check = pObj->CalcCheck();#endif pObj->ResetKeyRing(); pObj->Intern(); return pObj;}boolPreloadObSource::Invalidate(ObjectHeader *){ fatal("PreloadObSource::Evict() unimplemented\n"); return false;}boolPreloadObSource::Detach(){ fatal("PreloadObSource::Detach() unimplemented\n"); return false;}boolPreloadObSource::WriteBack(ObjectHeader *, bool){ fatal("PreloadObSource::Write() unimplemented\n"); return false;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -