kernel: clunk the cache when removing cache flag on a channel, only call cread() chen CCACHE flag is set

to avoid double caching, attachimage() and setswapchan() clear
the CCACHE flag on the channel but this keeps the read ahread
state of the cache arround (until the chan gets closed), so also
call cclunk() to detach the mcp and free the read ahead state.

avoid the call to cread() when CCACHE flag is clear.
This commit is contained in:
cinap_lenrek 2015-07-27 06:42:41 +02:00
parent ff494b954f
commit 652a641704
3 changed files with 5 additions and 2 deletions

View file

@ -706,7 +706,7 @@ mntrdwr(int type, Chan *c, void *buf, long n, vlong off)
if(nreq > c->iounit)
nreq = c->iounit;
if(type == Tread) {
if(type == Tread && (c->flag&CCACHE) != 0) {
nr = cread(c, (uchar*)uba, nreq, off);
if(nr > 0) {
nreq = nr;

View file

@ -232,6 +232,9 @@ attachimage(int type, Chan *c, uintptr base, ulong len)
{
Image *i, **l;
c->flag &= ~CCACHE;
cclunk(c);
lock(&imagealloc);
/*
@ -272,7 +275,6 @@ found:
unlock(&imagealloc);
if(i->c == nil){
i->c = c;
c->flag &= ~CCACHE;
incref(c);
}

View file

@ -424,6 +424,7 @@ setswapchan(Chan *c)
}
}
c->flag &= ~CCACHE;
cclunk(c);
swapimage.c = c;
poperror();
}