|
|
1.1 root 1: /* dskqopt.c - dskqopt */
2:
3: #include <conf.h>
4: #include <kernel.h>
5: #include <disk.h>
6:
7: /*------------------------------------------------------------------------
8: * dskqopt -- optimize requests to read/write/seek to the same block
9: *------------------------------------------------------------------------
10: */
11: dskqopt(p, q, drptr)
12: struct dreq *p, *q, *drptr;
13: {
14: char *to, *from;
15: int i;
16: DBADDR block;
17:
18: /* By definition, sync requests cannot be optimized. Also, */
19: /* cannot optimize read requests if already reading. */
20:
21: if (drptr->drop==DSYNC || (drptr->drop==DREAD && p->drop==DREAD))
22: return(SYSERR);
23:
24: if (drptr->drop == DSEEK) { /* ignore extraneous seeks */
25: freebuf(drptr);
26: return(OK);
27: }
28:
29: if (p->drop == DSEEK) { /* replace existing seeks */
30: drptr->drnext = p->drnext;
31: q->drnext = drptr;
32: freebuf(p);
33: return(OK);
34: }
35:
36: if (p->drop==DWRITE && drptr->drop==DWRITE) { /* dup write */
37: drptr->drnext = p->drnext;
38: q->drnext = drptr;
39: freebuf(p->drbuff);
40: freebuf(p);
41: return(OK);
42: }
43:
44: if (drptr->drop==DREAD && p->drop==DWRITE) { /* satisfy read */
45: to = drptr->drbuff;
46: from = p->drbuff;
47: for (i=0 ; i<DBUFSIZ ; i++)
48: *to++ = *from++;
49: return(OK);
50: }
51:
52: if (drptr->drop==DWRITE && p->drop==DREAD) { /* sat. old read*/
53: block = drptr->drdba;
54: from = drptr->drbuff;
55: for (; p!=DRNULL && p->drdba==block ; p=p->drnext) {
56: q->drnext = p->drnext;
57: to = p->drbuff;
58: for (i=0 ; i<DBUFSIZ ; i++)
59: *to++ = *from++;
60: p->drstat = OK;
61: ready(p->drpid, RESCHNO);
62: }
63: drptr->drnext = p;
64: q->drnext = drptr;
65: resched();
66: return(OK);
67: }
68: return(SYSERR);
69: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.