]> git.ipfire.org Git - thirdparty/squid.git/blob - src/store_swapin.cc
changed open_disk_fd to store_open_disk_fd.
[thirdparty/squid.git] / src / store_swapin.cc
1
2 /*
3 * $Id: store_swapin.cc,v 1.17 1999/01/21 21:10:38 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 (!EBIT_TEST(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 (EBIT_TEST(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 (!EBIT_TEST(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 store_open_disk_fd++;
93 file_open(ctrlp->path,
94 O_RDONLY,
95 storeSwapInFileOpened,
96 ctrlp,
97 ctrlp->callback_data);
98 }
99
100 void
101 storeSwapInFileOpened(void *data, int fd, int errcode)
102 {
103 swapin_ctrl_t *ctrlp = data;
104 StoreEntry *e = ctrlp->e;
105 MemObject *mem = e->mem_obj;
106 struct stat sb;
107 if (fd == -2 && errcode == -2) {
108 xfree(ctrlp->path);
109 xfree(ctrlp);
110 store_open_disk_fd--;
111 return;
112 }
113 assert(mem != NULL);
114 assert(e->mem_status == NOT_IN_MEMORY);
115 assert(e->swap_status == SWAPOUT_WRITING || e->swap_status == SWAPOUT_DONE);
116 if (fd < 0) {
117 debug(20, 3) ("storeSwapInFileOpened: Failed\n"
118 "\tFile:\t'%s'\n\t URL:\t'%s'\n",
119 ctrlp->path, storeUrl(e));
120 storeEntryDump(e, 3);
121 store_open_disk_fd--;
122 } else if (e->swap_status != SWAPOUT_DONE) {
123 (void) 0;
124 } else if (fstat(fd, &sb) < 0) {
125 debug(20, 1) ("storeSwapInFileOpened: fstat() FD %d: %s\n", fd, xstrerror());
126 file_close(fd);
127 store_open_disk_fd--;
128 fd = -1;
129 } else if (sb.st_size == 0 || sb.st_size != e->swap_file_sz) {
130 debug(20, 1) ("storeSwapInFileOpened: %s: Size mismatch: %d(fstat) != %d(object)\n", ctrlp->path, (int) sb.st_size, e->swap_file_sz);
131 file_close(fd);
132 store_open_disk_fd--;
133 fd = -1;
134 }
135 if (fd < 0) {
136 storeReleaseRequest(e);
137 } else {
138 debug(20, 5) ("storeSwapInFileOpened: initialized '%s' for '%s'\n",
139 ctrlp->path, storeUrl(e));
140 }
141 (ctrlp->callback) (fd, ctrlp->callback_data);
142 xfree(ctrlp->path);
143 xfree(ctrlp);
144 }