[Prev][Next][Index][Thread]
Corrected netboot patch
I accidentally sent out a non-context patch for netboot. Here's a context
version which should apply much more cleanly.
-Dave
--
work: danderse@cs.utah.edu me: angio@pobox.com
University of Utah http://www.angio.net/
Computer Science - Flux Research Group
Index: GNUmakerules
===================================================================
RCS file: /n/fast/usr/lsrc/flux/CVS/oskit/boot/net/GNUmakerules,v
retrieving revision 1.34
retrieving revision 1.35
diff -c -r1.34 -r1.35
*** GNUmakerules 1999/01/26 20:52:52 1.34
--- GNUmakerules 1999/02/18 18:11:09 1.35
***************
*** 38,44 ****
DEPS = $(OBJDIR)/lib/multiboot.o $(OBJFILES) $(DEPENDLIBS) $(OBJDIR)/lib/crtn.o
version.c: $(filter-out version.o,$(DEPS))
! echo >$@ "char version[] = \"NetBoot metakernel v2.5.1\";"
echo >>$@ "char build_info[] = \"Built `date +%d-%b-%Y` by `id -nu`@`hostname | sed 's/\..*//'`:`pwd`\nwith options: $(OSKIT_OPTIONS)\";"
CLEAN_FILES += version.c
--- 38,44 ----
DEPS = $(OBJDIR)/lib/multiboot.o $(OBJFILES) $(DEPENDLIBS) $(OBJDIR)/lib/crtn.o
version.c: $(filter-out version.o,$(DEPS))
! echo >$@ "char version[] = \"NetBoot metakernel v2.6.0\";"
echo >>$@ "char build_info[] = \"Built `date +%d-%b-%Y` by `id -nu`@`hostname | sed 's/\..*//'`:`pwd`\nwith options: $(OSKIT_OPTIONS)\";"
CLEAN_FILES += version.c
Index: await.c
===================================================================
RCS file: /n/fast/usr/lsrc/flux/CVS/oskit/boot/net/await.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -c -r1.12 -r1.13
*** await.c 1998/04/08 22:42:14 1.12
--- await.c 1999/02/18 18:11:09 1.13
***************
*** 81,87 ****
rpc = (struct rpc_t *)&packet[ETHER_HDR_SIZE];
if ((type == AWAIT_RPC) &&
(ntohs(udp->dest) == RPC_SOCKET) &&
! (ntohl(rpc->u.reply.id) == ival) &&
(ntohl(rpc->u.reply.type) == MSG_REPLY)) {
rpc_id++;
return(1);
--- 81,87 ----
rpc = (struct rpc_t *)&packet[ETHER_HDR_SIZE];
if ((type == AWAIT_RPC) &&
(ntohs(udp->dest) == RPC_SOCKET) &&
! (!ival || (ntohl(rpc->u.reply.id) == ival)) &&
(ntohl(rpc->u.reply.type) == MSG_REPLY)) {
rpc_id++;
return(1);
Index: getkernel_net.c
===================================================================
RCS file: /n/fast/usr/lsrc/flux/CVS/oskit/boot/net/getkernel_net.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -c -r1.9 -r1.10
*** getkernel_net.c 1998/04/08 22:42:18 1.9
--- getkernel_net.c 1999/02/18 18:11:09 1.10
***************
*** 1,5 ****
/*
! * Copyright (c) 1996-1998 University of Utah and the Flux Group.
* All rights reserved.
* @OSKIT-FLUX-GPLUS@
*/
--- 1,5 ----
/*
! * Copyright (c) 1996-1999 University of Utah and the Flux Group.
* All rights reserved.
* @OSKIT-FLUX-GPLUS@
*/
***************
*** 37,42 ****
--- 37,43 ----
int offset;
char *bufp = buf;
int chunk_size;
+ int readahead;
#if 0
printf("kimg_read: file_ofs %x, size %x\n", file_ofs, size);
#endif
***************
*** 44,51 ****
offset = file_ofs;
while (size > 0) {
chunk_size = min(NFS_READ_SIZE, size);
n = nfs_read(ARP_ROOTSERVER, nfs_port, filefh,
! offset, chunk_size, bufp);
if (n < 0) {
printf("Unable to read text: %s\n", nfs_strerror(n));
return 1; /* XXX Should be an EX_ constant */
--- 45,53 ----
offset = file_ofs;
while (size > 0) {
chunk_size = min(NFS_READ_SIZE, size);
+ readahead = (size / NFS_READ_SIZE) - 1;
n = nfs_read(ARP_ROOTSERVER, nfs_port, filefh,
! offset, chunk_size, bufp, readahead);
if (n < 0) {
printf("Unable to read text: %s\n", nfs_strerror(n));
return 1; /* XXX Should be an EX_ constant */
Index: rpc.c
===================================================================
RCS file: /n/fast/usr/lsrc/flux/CVS/oskit/boot/net/rpc.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -c -r1.7 -r1.8
*** rpc.c 1998/04/07 01:27:59 1.7
--- rpc.c 1999/02/18 18:11:09 1.8
***************
*** 21,32 ****
--- 21,46 ----
#include "rpc.h"
+ #undef min
+ #define min(a,b) ((a) < (b)? (a) : (b))
+
+ #define BUFMAX 4
+
+ struct rpc_buf read_cache[BUFMAX];
+ int read_cache_size = 0;
+
int rpc_id;
void
rpc_init()
{
+ int i;
rpc_id = currticks();
+ for (i = 0; i < BUFMAX; i++) {
+ read_cache[i].valid = 0;
+ read_cache[i].offset = 0;
+ read_cache[i].len = 0;
+ }
}
/***************************************************************************
***************
*** 129,150 ****
/***************************************************************************
NFS_READ: Read File
***************************************************************************/
int
! nfs_read(int server, int port, char *fh, int offset, int len, char *buffer)
{
struct rpc_t buf, *rpc;
char *rpcptr;
int retries = MAX_RPC_RETRIES;
int rlen;
! rpcptr = netsprintf(buf.u.data,
! "%L%L%L%L%L%L%L%L%L%S%L%L%L%L%L%L%L%M%L%L%L",
! rpc_id, MSG_CALL, 2, PROG_NFS, 2, NFS_READ,
! 1, hostnamelen + 28,0,hostname,0,0,2,0,0,0,0,
! 32, fh, offset, len, 0);
while(retries--) {
udp_transmit(arptable[server].ipaddr, RPC_SOCKET,
port, rpcptr - (char *)&buf, &buf);
if (await_reply(AWAIT_RPC, rpc_id, NULL)) {
--- 143,278 ----
/***************************************************************************
+ CHECK_READ_CACHE: Determine if a block is in the read cache
+
+ ***************************************************************************/
+
+ int
+ check_read_cache(offset, len, buffer)
+ {
+ int i;
+ struct rpc_buf *cache;
+ int rlen = 0;
+
+ for (i = 0; i < BUFMAX; i++) {
+ cache = &(read_cache[i]);
+ if (cache->valid &&
+ cache->offset == offset &&
+ cache->len >= len) {
+ memcpy(buffer, cache->buffer, len);
+ rlen = len;
+ }
+ }
+ return rlen;
+ }
+
+ /***************************************************************************
+
NFS_READ: Read File
***************************************************************************/
int
! nfs_read(int server, int port, char *fh, int offset, int len, char *buffer,
! int readahead)
{
struct rpc_t buf, *rpc;
char *rpcptr;
int retries = MAX_RPC_RETRIES;
int rlen;
! int i, curoff, pktcount = 0;
! int saved_rpc_id;
! int rid;
! struct rpc_buf *cache;
!
! rlen = check_read_cache(offset, len, buffer);
! if (rlen) {
! return rlen;
! }
!
! /*
! * Since the cache is purely readahead, fill 'er up if we
! * miss. It's not going to be as efficient as it could
! * in the face of packet loss, but we're not doing
! * this in a particularly smart way anyway. :)
! */
!
! readahead = min(readahead, BUFMAX);
! saved_rpc_id = rpc_id;
!
! if (readahead < 1) readahead = 1;
!
! curoff = offset;
! while (readahead) {
! cache = &(read_cache[rpc_id - saved_rpc_id]);
! cache->valid = 0;
! cache->offset = curoff;
! cache->len = len;
! cache->id = rpc_id;
!
! rpcptr = netsprintf(buf.u.data,
! "%L%L%L%L%L%L%L%L%L%S%L%L%L%L%L%L%L%M%L%L%L",
! rpc_id, MSG_CALL, 2, PROG_NFS, 2, NFS_READ,
! 1, hostnamelen + 28,0,hostname,0,0,2,0,0,0,0,
! 32, fh, curoff, len, 0);
! curoff += len;
! readahead--;
! pktcount++;
! rpc_id++;
! udp_transmit(arptable[server].ipaddr, RPC_SOCKET,
! port, rpcptr - (char *)&buf, &buf);
! }
!
! while (pktcount) {
! if (await_reply(AWAIT_RPC, 0, NULL)) {
! rpc = (struct rpc_t *)&packet[ETHER_HDR_SIZE];
! if (rpc->u.reply.rstatus || rpc->u.reply.verifier ||
! rpc->u.reply.astatus || rpc->u.reply.data[0]) {
! printf("%s\n", rpc_strerror(rpc));
! return(-(ntohl(rpc->u.reply.data[0])));
! } else {
! rid = ntohl(rpc->u.reply.id);
! cache = NULL;
! for (i = 0; i < BUFMAX; i++) {
! if (read_cache[i].id == rid) {
! cache = &(read_cache[i]);
! }
! }
! if (cache == NULL) {
! #if 0
! printf("unexpected reply id 0x%lx\n",
! rid);
! #endif
! continue;
! }
! rlen = ntohl(rpc->u.reply.data[18]);
! if (len < rlen) rlen = len;
! if (len > rlen) netprintf("short read\r\n");
! memcpy(cache->buffer, &rpc->u.reply.data[19],
! rlen);
! cache->valid = 1;
! }
! }
! pktcount--;
! }
!
! rlen = check_read_cache(offset, len, buffer);
! if (rlen) {
! return rlen;
! }
!
! /*
! * Okay - fall back to normal behavior. We missed the
! * packet somehow.
! */
!
! printf("nfs_read: lost packet\n");
!
while(retries--) {
+ rpcptr = netsprintf(buf.u.data,
+ "%L%L%L%L%L%L%L%L%L%S%L%L%L%L%L%L%L%M%L%L%L",
+ rpc_id, MSG_CALL, 2, PROG_NFS, 2, NFS_READ,
+ 1, hostnamelen + 28,0,hostname,0,0,2,0,0,0,0,
+ 32, fh, offset, len, 0);
udp_transmit(arptable[server].ipaddr, RPC_SOCKET,
port, rpcptr - (char *)&buf, &buf);
if (await_reply(AWAIT_RPC, rpc_id, NULL)) {
***************
*** 158,163 ****
--- 286,292 ----
if (len < rlen) rlen = len;
if (len > rlen) netprintf("short read\r\n");
memcpy(buffer, &rpc->u.reply.data[19], rlen);
+
return(rlen);
}
}
Index: rpc.h
===================================================================
RCS file: /n/fast/usr/lsrc/flux/CVS/oskit/boot/net/rpc.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -c -r1.3 -r1.4
*** rpc.h 1997/05/31 23:32:07 1.3
--- rpc.h 1999/02/18 18:11:09 1.4
***************
*** 31,36 ****
--- 31,45 ----
} u;
};
+ struct rpc_buf {
+ int valid;
+ int sent; /* Is the request on the wire? */
+ unsigned long offset;
+ unsigned long len;
+ unsigned long id;
+ char buffer[1400];
+ };
+
#define SUNRPC 111
#define RPC_SOCKET 620 /* Arbitrary */
***************
*** 60,66 ****
int rpc_lookup(int addr, int prog, int ver);
int nfs_mount(int server, int port, char *path, char *fh);
int nfs_lookup(int server, int port, char *fh, char *path, char *file_fh);
! int nfs_read(int server, int port, char *fh, int offset, int len, char *buffer);
char *rpc_strerror(struct rpc_t *rpc);
char *nfs_strerror(int err);
--- 69,76 ----
int rpc_lookup(int addr, int prog, int ver);
int nfs_mount(int server, int port, char *path, char *fh);
int nfs_lookup(int server, int port, char *fh, char *path, char *file_fh);
! int nfs_read(int server, int port, char *fh, int offset, int len,
! char *buffer, int readahead);
char *rpc_strerror(struct rpc_t *rpc);
char *nfs_strerror(int err);