]> git.ipfire.org Git - thirdparty/squid.git/blame - src/store_swapin.cc
assertions to trap some apparent bugs earlier than they are now being
[thirdparty/squid.git] / src / store_swapin.cc
CommitLineData
9cef6668 1
2/*
415e0dd2 3 * $Id: store_swapin.cc,v 1.13 1998/09/14 21:28:16 wessels Exp $
9cef6668 4 *
5 * DEBUG: section 20 Storage Manager Swapin Functions
6 * AUTHOR: Duane Wessels
7 *
8 * SQUID Internet Object Cache http://squid.nlanr.net/Squid/
9 * ----------------------------------------------------------
10 *
11 * Squid is the result of efforts by numerous individuals from the
12 * Internet community. Development is led by Duane Wessels of the
13 * National Laboratory for Applied Network Research and funded by the
14 * National Science Foundation. Squid is Copyrighted (C) 1998 by
15 * Duane Wessels and the University of California San Diego. Please
16 * see the COPYRIGHT file for full details. Squid incorporates
17 * software developed and/or copyrighted by other sources. Please see
18 * the CREDITS file for full details.
19 *
20 * This program is free software; you can redistribute it and/or modify
21 * it under the terms of the GNU General Public License as published by
22 * the Free Software Foundation; either version 2 of the License, or
23 * (at your option) any later version.
24 *
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
29 *
30 * You should have received a copy of the GNU General Public License
31 * along with this program; if not, write to the Free Software
32 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
33 *
34 */
35
f09f5b26 36#include "squid.h"
37
38typedef struct swapin_ctrl_t {
39 StoreEntry *e;
40 char *path;
41 SIH *callback;
42 void *callback_data;
43 store_client *sc;
44} swapin_ctrl_t;
45
46/* start swapping in */
47/* callback_data will become the tag on which the stat/open can be aborted */
48void
49storeSwapInStart(StoreEntry * e, SIH * callback, void *callback_data)
50{
51 swapin_ctrl_t *ctrlp;
52 assert(e->mem_status == NOT_IN_MEMORY);
415e0dd2 53 if (!e->flags.entry_validated) {
d9584b35 54 /* We're still reloading and haven't validated this entry yet */
55 callback(-1, callback_data);
56 return;
f09f5b26 57 }
f09f5b26 58 debug(20, 3) ("storeSwapInStart: called for %08X %s \n",
59 e->swap_file_number, storeKeyText(e->key));
60 assert(e->swap_status == SWAPOUT_WRITING || e->swap_status == SWAPOUT_DONE);
61 assert(e->swap_file_number >= 0);
62 assert(e->mem_obj != NULL);
63 ctrlp = xmalloc(sizeof(swapin_ctrl_t));
64 ctrlp->e = e;
65 ctrlp->callback = callback;
66 ctrlp->callback_data = callback_data;
415e0dd2 67 if (e->flags.entry_validated)
f09f5b26 68 storeSwapInValidateComplete(ctrlp, 0, 0);
69 else
70 storeValidate(e, storeSwapInValidateComplete, ctrlp, callback_data);
71}
72
f09f5b26 73void
74storeSwapInValidateComplete(void *data, int retcode, int errcode)
75{
76 swapin_ctrl_t *ctrlp = (swapin_ctrl_t *) data;
77 StoreEntry *e;
f09f5b26 78 if (retcode == -2 && errcode == -2) {
79 xfree(ctrlp);
80 return;
81 }
82 e = ctrlp->e;
83 assert(e->mem_status == NOT_IN_MEMORY);
415e0dd2 84 if (!e->flags.entry_validated) {
f09f5b26 85 /* Invoke a store abort that should free the memory object */
86 (ctrlp->callback) (-1, ctrlp->callback_data);
87 xfree(ctrlp);
88 return;
89 }
90 ctrlp->path = xstrdup(storeSwapFullPath(e->swap_file_number, NULL));
91 debug(20, 3) ("storeSwapInValidateComplete: Opening %s\n", ctrlp->path);
e3ef2b09 92 file_open(ctrlp->path,
93 O_RDONLY,
94 storeSwapInFileOpened,
95 ctrlp,
96 ctrlp->callback_data);
f09f5b26 97}
98
99void
100storeSwapInFileOpened(void *data, int fd, int errcode)
101{
9d33ad04 102 swapin_ctrl_t *ctrlp = data;
f09f5b26 103 StoreEntry *e = ctrlp->e;
104 MemObject *mem = e->mem_obj;
07304bf9 105 struct stat sb;
f09f5b26 106 if (fd == -2 && errcode == -2) {
107 xfree(ctrlp->path);
108 xfree(ctrlp);
109 return;
110 }
111 assert(mem != NULL);
112 assert(e->mem_status == NOT_IN_MEMORY);
113 assert(e->swap_status == SWAPOUT_WRITING || e->swap_status == SWAPOUT_DONE);
f09f5b26 114 if (fd < 0) {
9d33ad04 115 debug(20, 3) ("storeSwapInFileOpened: Failed\n"
d6f51e3c 116 "\tFile:\t'%s'\n\t URL:\t'%s'\n",
e3ef2b09 117 ctrlp->path, storeUrl(e));
9d33ad04 118 storeEntryDump(e, 3);
119 } else if (e->swap_status != SWAPOUT_DONE) {
120 (void) 0;
121 } else if (fstat(fd, &sb) < 0) {
a60f7062 122 debug(20, 1) ("storeSwapInFileOpened: fstat() FD %d: %s\n", fd, xstrerror());
9d33ad04 123 file_close(fd);
124 fd = -1;
125 } else if (sb.st_size == 0 || sb.st_size != e->swap_file_sz) {
a60f7062 126 debug(20, 1) ("storeSwapInFileOpened: %s: Size mismatch: %d(fstat) != %d(object)\n", ctrlp->path, (int) sb.st_size, e->swap_file_sz);
9d33ad04 127 file_close(fd);
128 fd = -1;
f09f5b26 129 }
9d33ad04 130 if (fd < 0) {
131 storeReleaseRequest(e);
132 } else {
5999b776 133 debug(20, 5) ("storeSwapInFileOpened: initialized '%s' for '%s'\n",
9d33ad04 134 ctrlp->path, storeUrl(e));
e3ef2b09 135 }
f09f5b26 136 (ctrlp->callback) (fd, ctrlp->callback_data);
137 xfree(ctrlp->path);
138 xfree(ctrlp);
139}