]> git.ipfire.org Git - thirdparty/squid.git/blob - src/store_swapin.cc
removed EBIT macros for StoreEntry->flag
[thirdparty/squid.git] / src / store_swapin.cc
1
2 /*
3 * $Id: store_swapin.cc,v 1.13 1998/09/14 21:28:16 wessels Exp $
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
36 #include "squid.h"
37
38 typedef 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 */
48 void
49 storeSwapInStart(StoreEntry * e, SIH * callback, void *callback_data)
50 {
51 swapin_ctrl_t *ctrlp;
52 assert(e->mem_status == NOT_IN_MEMORY);
53 if (!e->flags.entry_validated) {
54 /* We're still reloading and haven't validated this entry yet */
55 callback(-1, callback_data);
56 return;
57 }
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;
67 if (e->flags.entry_validated)
68 storeSwapInValidateComplete(ctrlp, 0, 0);
69 else
70 storeValidate(e, storeSwapInValidateComplete, ctrlp, callback_data);
71 }
72
73 void
74 storeSwapInValidateComplete(void *data, int retcode, int errcode)
75 {
76 swapin_ctrl_t *ctrlp = (swapin_ctrl_t *) data;
77 StoreEntry *e;
78 if (retcode == -2 && errcode == -2) {
79 xfree(ctrlp);
80 return;
81 }
82 e = ctrlp->e;
83 assert(e->mem_status == NOT_IN_MEMORY);
84 if (!e->flags.entry_validated) {
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);
92 file_open(ctrlp->path,
93 O_RDONLY,
94 storeSwapInFileOpened,
95 ctrlp,
96 ctrlp->callback_data);
97 }
98
99 void
100 storeSwapInFileOpened(void *data, int fd, int errcode)
101 {
102 swapin_ctrl_t *ctrlp = data;
103 StoreEntry *e = ctrlp->e;
104 MemObject *mem = e->mem_obj;
105 struct stat sb;
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);
114 if (fd < 0) {
115 debug(20, 3) ("storeSwapInFileOpened: Failed\n"
116 "\tFile:\t'%s'\n\t URL:\t'%s'\n",
117 ctrlp->path, storeUrl(e));
118 storeEntryDump(e, 3);
119 } else if (e->swap_status != SWAPOUT_DONE) {
120 (void) 0;
121 } else if (fstat(fd, &sb) < 0) {
122 debug(20, 1) ("storeSwapInFileOpened: fstat() FD %d: %s\n", fd, xstrerror());
123 file_close(fd);
124 fd = -1;
125 } else if (sb.st_size == 0 || sb.st_size != e->swap_file_sz) {
126 debug(20, 1) ("storeSwapInFileOpened: %s: Size mismatch: %d(fstat) != %d(object)\n", ctrlp->path, (int) sb.st_size, e->swap_file_sz);
127 file_close(fd);
128 fd = -1;
129 }
130 if (fd < 0) {
131 storeReleaseRequest(e);
132 } else {
133 debug(20, 5) ("storeSwapInFileOpened: initialized '%s' for '%s'\n",
134 ctrlp->path, storeUrl(e));
135 }
136 (ctrlp->callback) (fd, ctrlp->callback_data);
137 xfree(ctrlp->path);
138 xfree(ctrlp);
139 }