From: wessels <> Date: Wed, 30 Apr 1997 05:34:46 +0000 (+0000) Subject: moving FD things to common fd.h X-Git-Tag: SQUID_3_0_PRE1~5041 X-Git-Url: http://git.ipfire.org/gitweb/?a=commitdiff_plain;h=95d15928422453dc90b7c4d51dec52126ca4982a;p=thirdparty%2Fsquid.git moving FD things to common fd.h --- diff --git a/src/comm.cc b/src/comm.cc index 5f924c2d37..e266a0efb1 100644 --- a/src/comm.cc +++ b/src/comm.cc @@ -1,6 +1,6 @@ /* - * $Id: comm.cc,v 1.143 1997/04/29 22:12:50 wessels Exp $ + * $Id: comm.cc,v 1.144 1997/04/29 23:34:46 wessels Exp $ * * DEBUG: section 5 Socket Functions * AUTHOR: Harvest Derived @@ -201,7 +201,7 @@ comm_local_port(int fd) FD_ENTRY *fde = &fd_table[fd]; /* If the fd is closed already, just return */ - if (!fde->openned) { + if (!fde->open) { debug(5, 0, "comm_local_port: FD %d has been closed.\n", fd); return 0; } @@ -247,7 +247,7 @@ comm_open(int sock_type, const char *note) { int new_socket; - FD_ENTRY *conn = NULL; + FD_ENTRY *fde = NULL; int tcp_rcv_bufsz = Config.tcpRcvBufsz; /* Create socket for accepting new connections. */ @@ -269,12 +269,12 @@ comm_open(int sock_type, /* update fdstat */ fdstat_open(new_socket, FD_SOCKET); - conn = &fd_table[new_socket]; - memset(conn, '\0', sizeof(FD_ENTRY)); + fde = &fd_table[new_socket]; + memset(fde, '\0', sizeof(FD_ENTRY)); if (note) fd_note(new_socket, note); - conn->openned = 1; - conn->lifetime = -1; + fde->open = 1; + fde->lifetime = -1; if (!BIT_TEST(flags, COMM_NOCLOEXEC)) commSetCloseOnExec(new_socket); if (port > (u_short) 0) { @@ -285,7 +285,7 @@ comm_open(int sock_type, if (addr.s_addr != no_addr.s_addr) if (commBind(new_socket, addr, port) != COMM_OK) return COMM_ERROR; - conn->local_port = port; + fde->local_port = port; if (BIT_TEST(flags, COMM_NONBLOCKING)) if (commSetNonBlocking(new_socket) == COMM_ERROR) @@ -296,7 +296,6 @@ comm_open(int sock_type, #endif if (tcp_rcv_bufsz > 0 && sock_type == SOCK_STREAM) commSetTcpRcvbuf(new_socket, tcp_rcv_bufsz); - conn->comm_type = sock_type; return new_socket; } @@ -405,7 +404,7 @@ int comm_connect_addr(int sock, const struct sockaddr_in *address) { int status = COMM_OK; - FD_ENTRY *conn = &fd_table[sock]; + FD_ENTRY *fde = &fd_table[sock]; int len; int x; int lft; @@ -446,20 +445,19 @@ comm_connect_addr(int sock, const struct sockaddr_in *address) return COMM_ERROR; } } - strcpy(conn->ipaddr, inet_ntoa(address->sin_addr)); - conn->remote_port = ntohs(address->sin_port); + xstrncpy(fde->ipaddr, inet_ntoa(address->sin_addr), 16); + fde->remote_port = ntohs(address->sin_port); /* set the lifetime for this client */ if (status == COMM_OK) { lft = comm_set_fd_lifetime(sock, Config.lifetimeDefault); debug(5, 10, "comm_connect_addr: FD %d connected to %s:%d, lifetime %d.\n", - sock, conn->ipaddr, conn->remote_port, lft); + sock, fde->ipaddr, fde->remote_port, lft); } else if (status == COMM_INPROGRESS) { lft = comm_set_fd_lifetime(sock, Config.connectTimeout); debug(5, 10, "comm_connect_addr: FD %d connection pending, lifetime %d\n", sock, lft); } /* Add new socket to list of open sockets. */ - conn->sender = 1; return status; } @@ -472,8 +470,7 @@ comm_accept(int fd, struct sockaddr_in *peer, struct sockaddr_in *me) struct sockaddr_in P; struct sockaddr_in M; int Slen; - FD_ENTRY *conn = NULL; - FD_ENTRY *listener = &fd_table[fd]; + FD_ENTRY *fde = NULL; Slen = sizeof(P); while ((sock = accept(fd, (struct sockaddr *) &P, &Slen)) < 0) { @@ -505,13 +502,11 @@ comm_accept(int fd, struct sockaddr_in *peer, struct sockaddr_in *me) commSetCloseOnExec(sock); /* fdstat update */ fdstat_open(sock, FD_SOCKET); - conn = &fd_table[sock]; - conn->openned = 1; - conn->sender = 0; /* This is an accept, therefore receiver. */ - conn->comm_type = listener->comm_type; - strcpy(conn->ipaddr, inet_ntoa(P.sin_addr)); - conn->remote_port = htons(P.sin_port); - conn->local_port = htons(M.sin_port); + fde = &fd_table[sock]; + fde->open = 1; + strcpy(fde->ipaddr, inet_ntoa(P.sin_addr)); + fde->remote_port = htons(P.sin_port); + fde->local_port = htons(M.sin_port); commSetNonBlocking(sock); return sock; } @@ -519,11 +514,11 @@ comm_accept(int fd, struct sockaddr_in *peer, struct sockaddr_in *me) void commCallCloseHandlers(int fd) { - FD_ENTRY *conn = &fd_table[fd]; + FD_ENTRY *fde = &fd_table[fd]; struct close_handler *ch; debug(5, 5, "commCallCloseHandlers: FD %d\n", fd); - while ((ch = conn->close_handler) != NULL) { - conn->close_handler = ch->next; + while ((ch = fde->close_handler) != NULL) { + fde->close_handler = ch->next; ch->handler(fd, ch->data); safe_free(ch); } @@ -532,26 +527,26 @@ commCallCloseHandlers(int fd) void comm_close(int fd) { - FD_ENTRY *conn = NULL; + FD_ENTRY *fde = NULL; debug(5, 5, "comm_close: FD %d\n", fd); - if (fd < 0 || fd >= Squid_MaxFD) - return; - conn = &fd_table[fd]; - if (!conn->openned) + if (fd < 0) + fatal_dump("comm_close: bad FD"); + if (fd >= Squid_MaxFD) + fatal_dump("comm_close: bad FD"); + fde = &fd_table[fd]; + if (!fde->open) return; - if (fdstatGetType(fd) == FD_FILE) { - debug(5, 0, "FD %d: Someone called comm_close() on a File\n", fd); - fatal_dump(NULL); - } - conn->openned = 0; + if (fd_table[fd].type == FD_FILE) + fatal_dump("comm_close: not a SOCKET"); + fde->open = 0; RWStateCallbackAndFree(fd, COMM_ERROR); fdstat_close(fd); /* update fdstat */ commCallCloseHandlers(fd); - memset(conn, '\0', sizeof(FD_ENTRY)); + memset(fde, '\0', sizeof(FD_ENTRY)); #if USE_ASYNC_IO aioClose(fd); #else - conn->lifetime = -1; + fde->lifetime = -1; close(fd); #endif } @@ -561,9 +556,9 @@ comm_close(int fd) static int comm_cleanup_fd_entry(int fd) { - FD_ENTRY *conn = &fd_table[fd]; + FD_ENTRY *fde = &fd_table[fd]; RWStateCallbackAndFree(fd, COMM_ERROR); - memset(conn, 0, sizeof(FD_ENTRY)); + memset(fde, 0, sizeof(FD_ENTRY)); return 0; } @@ -820,7 +815,7 @@ comm_select(time_t sec) for (i = 1; i < maxfd; i++) { if ((fd = pfds[i].fd) < 0) continue; - if (fdstatGetType(fd) == FD_FILE) + if (fd_table[fd].type == FD_FILE) file_must_close(fd); else comm_close(fd); @@ -900,7 +895,7 @@ comm_select(time_t sec) struct close_handler *next; FD_ENTRY *f = &fd_table[fd]; debug(5, 0, "WARNING: FD %d has handlers, but it's invalid.\n", fd); - debug(5, 0, "FD %d is a %s\n", fd, fdstatTypeStr[fdstatGetType(fd)]); + debug(5, 0, "FD %d is a %s\n", fd, fdstatTypeStr[fd_table[fd].type]); debug(5, 0, "--> %s\n", fd_note(fd, NULL)); debug(5, 0, "lifetm:%p tmout:%p read:%p write:%p\n", f->lifetime_handler, @@ -1362,7 +1357,7 @@ examine_select(fd_set * readfds, fd_set * writefds) debug(5, 0, "WARNING: FD %d has handlers, but it's invalid.\n", fd); debug(5, 0, "FD %d is a %s called '%s'\n", fd, - fdstatTypeStr[fdstatGetType(fd)], + fdstatTypeStr[fd_table[fd].type], fd_note(fd, NULL)); debug(5, 0, "lifetm:%p tmout:%p read:%p write:%p\n", f->lifetime_handler, @@ -1415,7 +1410,7 @@ checkTimeouts(void) /* scan for timeout */ for (fd = 0; fd <= Biggest_FD; fd++) { f = &fd_table[fd]; - if (!f->openned) + if (!f->open) continue; if ((hdl = f->timeout_handler) == NULL) continue; @@ -1439,7 +1434,7 @@ checkLifetimes(void) for (fd = 0; fd <= Biggest_FD; fd++) { fde = &fd_table[fd]; - if (!fde->openned) + if (!fde->open) continue; if (fde->lifetime < 0) continue; @@ -1463,7 +1458,7 @@ checkLifetimes(void) comm_close(fd); comm_cleanup_fd_entry(fd); } - if (fde->openned) { + if (fde->open) { /* still opened */ debug(5, 5, "checkLifetimes: FD %d: Forcing comm_close()\n", fd); comm_close(fd); diff --git a/src/disk.cc b/src/disk.cc index 15d8138711..39fc6d90b2 100644 --- a/src/disk.cc +++ b/src/disk.cc @@ -1,5 +1,5 @@ /* - * $Id: disk.cc,v 1.60 1997/04/29 22:12:52 wessels Exp $ + * $Id: disk.cc,v 1.61 1997/04/29 23:34:47 wessels Exp $ * * DEBUG: section 6 Disk I/O Routines * AUTHOR: Harvest Derived @@ -131,34 +131,18 @@ typedef struct _dwalk_ctrl { void *line_data; } dwalk_ctrl; -/* table for FILE variable, write lock and queue. Indexed by fd. */ -FileEntry *file_table; - static int diskHandleWriteComplete _PARAMS((void *, int, int)); static int diskHandleReadComplete _PARAMS((void *, int, int)); static int diskHandleWalkComplete _PARAMS((void *, int, int)); -static void diskHandleWalk _PARAMS((int, void *)); -static void diskHandleRead _PARAMS((int, void *)); -static void diskHandleWrite _PARAMS((int, void *)); +static PF diskHandleWalk; +static PF diskHandleRead; +static PF diskHandleWrite; static void file_open_complete _PARAMS((void *, int, int)); /* initialize table */ int disk_init(void) { - int fd; - - file_table = xcalloc(Squid_MaxFD, sizeof(FileEntry)); - meta_data.misc += Squid_MaxFD * sizeof(FileEntry); - for (fd = 0; fd < Squid_MaxFD; fd++) { - file_table[fd].filename[0] = '\0'; - file_table[fd].at_eof = NO; - file_table[fd].open_stat = FILE_NOT_OPEN; - file_table[fd].close_request = NOT_REQUEST; - file_table[fd].write_daemon = NOT_PRESENT; - file_table[fd].write_pending = NO_WRT_PENDING; - file_table[fd].write_q = file_table[fd].write_q_tail = NULL; - } return 0; } @@ -204,13 +188,10 @@ file_open(const char *path, int (*handler) _PARAMS((void)), int mode, void (*cal static void -file_open_complete(void *data, int retcode, int errcode) +file_open_complete(void *data, int fd, int errcode) { open_ctrl_t *ctrlp = (open_ctrl_t *) data; - FD_ENTRY *conn; - int fd; - - fd = retcode; + FD_ENTRY *fde; if (fd < 0) { errno = errcode; debug(50, 0, "file_open: error opening file %s: %s\n", ctrlp->path, @@ -221,21 +202,11 @@ file_open_complete(void *data, int retcode, int errcode) xfree(ctrlp); return; } - /* update fdstat */ - fdstat_open(fd, FD_FILE); commSetCloseOnExec(fd); - - /* init table */ - xstrncpy(file_table[fd].filename, ctrlp->path, SQUID_MAXPATHLEN); - file_table[fd].at_eof = NO; - file_table[fd].open_stat = FILE_OPEN; - file_table[fd].close_request = NOT_REQUEST; - file_table[fd].write_pending = NO_WRT_PENDING; - file_table[fd].write_daemon = NOT_PRESENT; - file_table[fd].write_q = NULL; - - conn = &fd_table[fd]; - memset(conn, '\0', sizeof(FD_ENTRY)); + fde = &fd_table[fd]; + memset(fde, '\0', sizeof(FD_ENTRY)); + fdstat_open(fd, FD_FILE); + xstrncpy(fde->disk.filename, ctrlp->path, SQUID_MAXPATHLEN); if (ctrlp->callback) (ctrlp->callback) (ctrlp->callback_data, fd); xfree(ctrlp->path); @@ -244,117 +215,95 @@ file_open_complete(void *data, int retcode, int errcode) /* must close a disk file */ -int +void file_must_close(int fd) { - FileEntry *entry; dwrite_q *q = NULL; - if (fdstatGetType(fd) != FD_FILE) - fatal_dump("file_must_close: NOT A FILE"); - entry = &file_table[fd]; - if (entry->open_stat == FILE_NOT_OPEN) - return DISK_OK; - entry->close_request = REQUEST; - entry->write_daemon = NOT_PRESENT; - entry->write_pending = NO_WRT_PENDING; + FD_ENTRY *fde = &fd_table[fd]; + if (fde->type != FD_FILE) + fatal_dump("file_must_close: type != FD_FILE"); + if (!fde->open) + fatal_dump("file_must_close: FD not opened"); + BIT_SET(fde->flags, FD_CLOSE_REQUEST); + BIT_RESET(fde->flags, FD_WRITE_DAEMON); + BIT_RESET(fde->flags, FD_WRITE_PENDING); /* Drain queue */ - while (entry->write_q) { - q = entry->write_q; - entry->write_q = q->next; + while (fde->disk.write_q) { + q = fde->disk.write_q; + fde->disk.write_q = q->next; if (q->free) (q->free) (q->buf); safe_free(q); } - entry->write_q_tail = NULL; - if (entry->wrt_handle) - entry->wrt_handle(fd, DISK_ERROR, entry->wrt_handle_data); + fde->disk.write_q_tail = NULL; + if (fde->disk.wrt_handle) + fde->disk.wrt_handle(fd, DISK_ERROR, fde->disk.wrt_handle_data); commSetSelect(fd, COMM_SELECT_READ, NULL, NULL, 0); commSetSelect(fd, COMM_SELECT_WRITE, NULL, NULL, 0); file_close(fd); - return DISK_OK; } void -file_open_fd(int fd, const char *name, File_Desc_Type type) +file_open_fd(int fd, const char *name, unsigned int type) { - FileEntry *f = &file_table[fd]; + FD_ENTRY *fde = &fd_table[fd]; + if (fde->open) + fatal_dump("file_open_fd: already open"); + memset(fde, '\0', sizeof(FD_ENTRY)); fdstat_open(fd, type); commSetCloseOnExec(fd); - xstrncpy(f->filename, name, SQUID_MAXPATHLEN); - f->at_eof = NO; - f->open_stat = FILE_OPEN; - f->close_request = NOT_REQUEST; - f->write_pending = NO_WRT_PENDING; - f->write_daemon = NOT_PRESENT; - f->write_q = NULL; - memset(&fd_table[fd], '\0', sizeof(FD_ENTRY)); + xstrncpy(fde->disk.filename, name, SQUID_MAXPATHLEN); } /* close a disk file. */ -int +void file_close(int fd) { - FD_ENTRY *conn = NULL; - if (fd < 0) { - debug_trap("file_close: bad file number"); - return DISK_ERROR; + FD_ENTRY *fde = NULL; + if (fd < 0) + fatal_dump("file_close: bad file number"); + fde = &fd_table[fd]; + if (!fde->open) + fatal_dump("file_close: already closed"); + if (fde->type != FD_FILE) + fatal_dump("file_close: called for non-FILE"); + if (BIT_TEST(fde->flags, FD_WRITE_DAEMON)) { + BIT_SET(fde->flags, FD_CLOSE_REQUEST); + return; } - /* we might have to flush all the write back queue before we can - * close it */ - /* save it for later */ - - if (file_table[fd].open_stat == FILE_NOT_OPEN) { - debug(6, 3, "file_close: FD %d is not OPEN\n", fd); - } else if (file_table[fd].write_daemon == PRESENT) { - debug(6, 3, "file_close: FD %d has a write daemon PRESENT\n", fd); - } else if (file_table[fd].write_pending == WRT_PENDING) { - debug(6, 3, "file_close: FD %d has a write PENDING\n", fd); - } else { - file_table[fd].open_stat = FILE_NOT_OPEN; - file_table[fd].write_daemon = NOT_PRESENT; - file_table[fd].filename[0] = '\0'; - - if (fdstatGetType(fd) == FD_SOCKET) { - debug(6, 0, "FD %d: Someone called file_close() on a socket\n", fd); - fatal_dump(NULL); - } - /* update fdstat */ - fdstat_close(fd); - conn = &fd_table[fd]; - memset(conn, '\0', sizeof(FD_ENTRY)); - comm_set_fd_lifetime(fd, -1); /* invalidate the lifetime */ + if (BIT_TEST(fde->flags, FD_WRITE_PENDING)) { + BIT_SET(fde->flags, FD_CLOSE_REQUEST); + return; + } + /* update fdstat */ + fdstat_close(fd); + memset(fde, '\0', sizeof(FD_ENTRY)); + comm_set_fd_lifetime(fd, -1); /* invalidate the lifetime */ #if USE_ASYNC_IO - aioClose(fd); + aioClose(fd); #else - close(fd); + close(fd); #endif - return DISK_OK; - } - - /* refused to close file if there is a daemon running */ - /* have pending flag set */ - file_table[fd].close_request = REQUEST; - return DISK_ERROR; } /* write handler */ static void -diskHandleWrite(int fd, void *data) +diskHandleWrite(int fd, void *unused) { - FileEntry *entry = data; int len = 0; disk_ctrl_t *ctrlp; dwrite_q *q = NULL; dwrite_q *wq = NULL; - if (!entry->write_q) + FD_ENTRY *fde = &fd_table[fd]; + if (!fde->disk.write_q) return; - if (file_table[fd].at_eof == NO) + if (!BIT_TEST(fde->flags, FD_AT_EOF)) lseek(fd, 0, SEEK_END); /* We need to combine subsequent write requests after the first */ - if (entry->write_q->next != NULL && entry->write_q->next->next != NULL) { - for (len = 0, q = entry->write_q->next; q != NULL; q = q->next) + if (fde->disk.write_q->next != NULL && fde->disk.write_q->next->next != NULL) { + for (len = 0, q = fde->disk.write_q->next; q != NULL; q = q->next) len += q->len - q->cur_offset; wq = xcalloc(1, sizeof(dwrite_q)); wq->buf = xmalloc(len); @@ -363,31 +312,30 @@ diskHandleWrite(int fd, void *data) wq->next = NULL; wq->free = xfree; do { - q = entry->write_q->next; + q = fde->disk.write_q->next; len = q->len - q->cur_offset; memcpy(wq->buf + wq->len, q->buf + q->cur_offset, len); wq->len += len; - entry->write_q->next = q->next; + fde->disk.write_q->next = q->next; if (q->free) (q->free) (q->buf); safe_free(q); - } while (entry->write_q->next != NULL); - entry->write_q_tail = wq; - entry->write_q->next = wq; + } while (fde->disk.write_q->next != NULL); + fde->disk.write_q_tail = wq; + fde->disk.write_q->next = wq; } ctrlp = xcalloc(1, sizeof(disk_ctrl_t)); ctrlp->fd = fd; - ctrlp->data = entry; #if USE_ASYNC_IO aioWrite(fd, - entry->write_q->buf + entry->write_q->cur_offset, - entry->write_q->len - entry->write_q->cur_offset, + fde->disk.write_q->buf + fde->disk.write_q->cur_offset, + fde->disk.write_q->len - fde->disk.write_q->cur_offset, diskHandleWriteComplete, ctrlp); #else len = write(fd, - entry->write_q->buf + entry->write_q->cur_offset, - entry->write_q->len - entry->write_q->cur_offset); + fde->disk.write_q->buf + fde->disk.write_q->cur_offset, + fde->disk.write_q->len - fde->disk.write_q->cur_offset); diskHandleWriteComplete(ctrlp, len, errno); #endif } @@ -396,15 +344,15 @@ static int diskHandleWriteComplete(void *data, int retcode, int errcode) { disk_ctrl_t *ctrlp = data; - FileEntry *entry = ctrlp->data; - dwrite_q *q = entry->write_q; int fd = ctrlp->fd; + FD_ENTRY *fde = &fd_table[fd]; + dwrite_q *q = fde->disk.write_q; int len = retcode; errno = errcode; safe_free(data); if (q == NULL) /* Someone aborted and then the write */ return DISK_ERROR; /* completed anyway. :( */ - file_table[fd].at_eof = YES; + BIT_SET(fde->flags, FD_AT_EOF); if (len < 0) { if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR) { len = 0; @@ -412,19 +360,19 @@ diskHandleWriteComplete(void *data, int retcode, int errcode) /* disk i/o failure--flushing all outstanding writes */ debug(50, 1, "diskHandleWrite: FD %d: disk write error: %s\n", fd, xstrerror()); - entry->write_daemon = NOT_PRESENT; - entry->write_pending = NO_WRT_PENDING; + BIT_RESET(fde->flags, FD_WRITE_DAEMON); + BIT_RESET(fde->flags, FD_WRITE_PENDING); /* call finish handler */ do { - entry->write_q = q->next; + fde->disk.write_q = q->next; if (q->free) (q->free) (q->buf); safe_free(q); - } while ((q = entry->write_q)); - if (entry->wrt_handle) { - entry->wrt_handle(fd, + } while ((q = fde->disk.write_q)); + if (fde->disk.wrt_handle) { + fde->disk.wrt_handle(fd, errno == ENOSPC ? DISK_NO_SPACE_LEFT : DISK_ERROR, - entry->wrt_handle_data); + fde->disk.wrt_handle_data); } return DISK_ERROR; } @@ -434,27 +382,27 @@ diskHandleWriteComplete(void *data, int retcode, int errcode) fatal_dump("diskHandleWriteComplete: offset > len"); if (q->cur_offset == q->len) { /* complete write */ - entry->write_q = q->next; + fde->disk.write_q = q->next; if (q->free) (q->free) (q->buf); safe_free(q); } - if (entry->write_q != NULL) { + if (fde->disk.write_q != NULL) { /* another block is queued */ commSetSelect(fd, COMM_SELECT_WRITE, diskHandleWrite, - entry, + NULL, 0); return DISK_OK; } /* no more data */ - entry->write_q = entry->write_q_tail = NULL; - entry->write_pending = NO_WRT_PENDING; - entry->write_daemon = NOT_PRESENT; - if (entry->wrt_handle) - entry->wrt_handle(fd, DISK_OK, entry->wrt_handle_data); - if (file_table[fd].close_request == REQUEST) + fde->disk.write_q = fde->disk.write_q_tail = NULL; + BIT_RESET(fde->flags, FD_WRITE_PENDING); + BIT_RESET(fde->flags, FD_WRITE_DAEMON); + if (fde->disk.wrt_handle) + fde->disk.wrt_handle(fd, DISK_OK, fde->disk.wrt_handle_data); + if (BIT_TEST(fde->flags, FD_CLOSE_REQUEST)) file_close(fd); return DISK_OK; } @@ -472,8 +420,9 @@ file_write(int fd, void (*free_func) _PARAMS((void *))) { dwrite_q *wq = NULL; + FD_ENTRY *fde = &fd_table[fd]; - if (file_table[fd].open_stat == FILE_NOT_OPEN) { + if (!fde->open) { debug_trap("file_write: FILE_NOT_OPEN"); return DISK_ERROR; } @@ -484,30 +433,26 @@ file_write(int fd, wq->cur_offset = 0; wq->next = NULL; wq->free = free_func; - file_table[fd].wrt_handle = handle; - file_table[fd].wrt_handle_data = handle_data; + fde->disk.wrt_handle = handle; + fde->disk.wrt_handle_data = handle_data; /* add to queue */ - file_table[fd].write_pending = WRT_PENDING; - if (!(file_table[fd].write_q)) { + BIT_SET(fde->flags, FD_WRITE_PENDING); + if (!(fde->disk.write_q)) { /* empty queue */ - file_table[fd].write_q = file_table[fd].write_q_tail = wq; + fde->disk.write_q = fde->disk.write_q_tail = wq; } else { - file_table[fd].write_q_tail->next = wq; - file_table[fd].write_q_tail = wq; + fde->disk.write_q_tail->next = wq; + fde->disk.write_q_tail = wq; } - if (file_table[fd].write_daemon != PRESENT) { + if (!BIT_TEST(fde->flags, FD_WRITE_DAEMON)) { #if USE_ASYNC_IO - diskHandleWrite(fd, &file_table[fd]); + diskHandleWrite(fd, NULL); #else - commSetSelect(fd, - COMM_SELECT_WRITE, - diskHandleWrite, - &file_table[fd], - 0); + commSetSelect(fd, COMM_SELECT_WRITE, diskHandleWrite, NULL, 0); #endif - file_table[fd].write_daemon = PRESENT; + BIT_SET(fde->flags, FD_WRITE_DAEMON); } return DISK_OK; } @@ -518,6 +463,7 @@ file_write(int fd, static void diskHandleRead(int fd, void *data) { + FD_ENTRY *fde = &fd_table[fd]; dread_ctrl *ctrl_dat = data; int len; disk_ctrl_t *ctrlp; @@ -526,7 +472,7 @@ diskHandleRead(int fd, void *data) ctrlp->data = ctrl_dat; /* go to requested position. */ lseek(fd, ctrl_dat->offset, SEEK_SET); - file_table[fd].at_eof = NO; + BIT_RESET(fde->flags, FD_AT_EOF); #if USE_ASYNC_IO aioRead(fd, ctrl_dat->buf + ctrl_dat->cur_len, @@ -640,15 +586,15 @@ file_read(int fd, char *buf, int req_len, int offset, FILE_READ_HD * handler, vo static void diskHandleWalk(int fd, void *data) { + FD_ENTRY *fde = &fd_table[fd]; dwalk_ctrl *walk_dat = data; int len; disk_ctrl_t *ctrlp; ctrlp = xcalloc(1, sizeof(disk_ctrl_t)); ctrlp->fd = fd; ctrlp->data = walk_dat; - lseek(fd, walk_dat->offset, SEEK_SET); - file_table[fd].at_eof = NO; + BIT_RESET(fde->flags, FD_AT_EOF); #if USE_ASYNC_IO aioRead(fd, walk_dat->buf, DISK_LINE_LEN - 1, @@ -720,9 +666,7 @@ diskHandleWalkComplete(void *data, int retcode, int errcode) walk_dat->offset += used_bytes; /* reschedule it for next line. */ - commSetSelect(fd, COMM_SELECT_READ, diskHandleWalk, - walk_dat, - 0); + commSetSelect(fd, COMM_SELECT_READ, diskHandleWalk, walk_dat, 0); return DISK_OK; } @@ -753,30 +697,13 @@ file_walk(int fd, #if USE_ASYNC_IO diskHandleWalk(fd, walk_dat); #else - commSetSelect(fd, COMM_SELECT_READ, diskHandleWalk, - walk_dat, - 0); + commSetSelect(fd, COMM_SELECT_READ, diskHandleWalk, walk_dat, 0); #endif return DISK_OK; } -char * -diskFileName(int fd) -{ - if (file_table[fd].filename[0]) - return (file_table[fd].filename); - else - return (0); -} - int diskWriteIsComplete(int fd) { - return file_table[fd].write_q ? 0 : 1; -} - -void -diskFreeMemory(void) -{ - safe_free(file_table); + return fd_table[fd].disk.write_q ? 0 : 1; } diff --git a/src/squid.h b/src/squid.h index a82609a1d7..6cd2e74f48 100644 --- a/src/squid.h +++ b/src/squid.h @@ -1,6 +1,6 @@ /* - * $Id: squid.h,v 1.105 1997/04/29 22:13:07 wessels Exp $ + * $Id: squid.h,v 1.106 1997/04/29 23:34:52 wessels Exp $ * * AUTHOR: Duane Wessels * @@ -270,6 +270,8 @@ typedef int QS _PARAMS((const void *, const void *)); /* qsort */ #include "cache_cf.h" #include "comm.h" +#include "disk.h" +#include "fd.h" #include "debug.h" #include "fdstat.h" #include "hash.h" @@ -305,7 +307,6 @@ typedef int QS _PARAMS((const void *, const void *)); /* qsort */ #include "objcache.h" #include "refresh.h" #include "unlinkd.h" -#include "disk.h" #if !HAVE_TEMPNAM #include "tempnam.h" diff --git a/src/stat.cc b/src/stat.cc index 0f43989422..87ab25cf6c 100644 --- a/src/stat.cc +++ b/src/stat.cc @@ -1,6 +1,6 @@ /* - * $Id: stat.cc,v 1.135 1997/04/29 22:13:08 wessels Exp $ + * $Id: stat.cc,v 1.136 1997/04/29 23:34:53 wessels Exp $ * * DEBUG: section 18 Cache Manager Statistics * AUTHOR: Harvest Derived @@ -631,8 +631,6 @@ static void statFiledescriptors(StoreEntry * sentry) { int i; - int j; - char *s = NULL; int lft; int to; FD_ENTRY *f; @@ -651,11 +649,10 @@ statFiledescriptors(StoreEntry * sentry) f = &fd_table[i]; if (!fdstat_isopen(i)) continue; - j = fdstatGetType(i); storeAppendPrintf(sentry, "{%4d %-6s ", i, - fdstatTypeStr[j]); - switch (j) { + fdstatTypeStr[f->type]); + switch (f->type) { case FD_SOCKET: if ((lft = f->lifetime) < 0) lft = 0; @@ -664,18 +661,18 @@ statFiledescriptors(StoreEntry * sentry) lft = (lft - squid_curtime) / 60; if (to > 0) to = (to - squid_curtime) / 60; - if (fd_table[i].timeout_handler == NULL) + if (f->timeout_handler == NULL) to = 0; storeAppendPrintf(sentry, "%4d %4d %-21s %s}\n", lft, to, - host_port_fmt(fd_table[i].ipaddr, fd_table[i].remote_port), + host_port_fmt(f->ipaddr, f->remote_port), fd_note(i, NULL)); break; case FD_FILE: storeAppendPrintf(sentry, "%31s %s}\n", null_string, - (s = diskFileName(i)) ? s : "-"); + f->disk.filename); break; case FD_PIPE: storeAppendPrintf(sentry, "%31s %s}\n", null_string, fd_note(i, NULL)); diff --git a/src/store_dir.cc b/src/store_dir.cc index b25cbeb823..dd5c25da49 100644 --- a/src/store_dir.cc +++ b/src/store_dir.cc @@ -76,6 +76,7 @@ storeAddSwapDisk(const char *path, int size, int l1, int l2, int read_only) tmp->l2 = l2; tmp->read_only = read_only; tmp->map = file_map_create(MAX_FILES_PER_DIR); + tmp->swaplog_fd = -1; return ++ncache_dirs; } @@ -308,7 +309,8 @@ storeDirOpenTmpSwapLog(int dirn, int *clean_flag) } debug(20, 1, "Rebuilding storage from %s\n", swaplog_path); /* close the existing write-only FD */ - file_close(SD->swaplog_fd); + if (SD->swaplog_fd >= 0) + file_close(SD->swaplog_fd); /* open a write-only FD for the new log */ fd = file_open(new_path, NULL, O_WRONLY | O_CREAT, NULL, NULL); if (fd < 0) { diff --git a/src/tools.cc b/src/tools.cc index f12a98af87..af77e10c56 100644 --- a/src/tools.cc +++ b/src/tools.cc @@ -1,6 +1,6 @@ /* - * $Id: tools.cc,v 1.99 1997/04/28 04:23:32 wessels Exp $ + * $Id: tools.cc,v 1.100 1997/04/29 23:34:54 wessels Exp $ * * DEBUG: section 21 Misc Functions * AUTHOR: Harvest Derived @@ -324,7 +324,7 @@ setSocketShutdownLifetimes(int lft) f = &fd_table[i]; if (!f->read_handler && !f->write_handler) continue; - if (fdstatGetType(i) != FD_SOCKET) + if (fd_table[i].type != FD_SOCKET) continue; if (f->lifetime > 0 && (f->lifetime - squid_curtime) <= lft) continue; @@ -355,7 +355,6 @@ normal_shutdown(void) filemapFreeMemory(); dnsFreeMemory(); redirectFreeMemory(); - fdstatFreeMemory(); errorpageFreeMemory(); stmemFreeMemory(); netdbFreeMemory();