3 * $Id: store_swapin.cc,v 1.17 1999/01/21 21:10:38 wessels Exp $
5 * DEBUG: section 20 Storage Manager Swapin Functions
6 * AUTHOR: Duane Wessels
8 * SQUID Internet Object Cache http://squid.nlanr.net/Squid/
9 * ----------------------------------------------------------
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.
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.
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.
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.
38 typedef struct swapin_ctrl_t
{
46 /* start swapping in */
47 /* callback_data will become the tag on which the stat/open can be aborted */
49 storeSwapInStart(StoreEntry
* e
, SIH
* callback
, void *callback_data
)
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
);
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
));
65 ctrlp
->callback
= callback
;
66 ctrlp
->callback_data
= callback_data
;
67 if (EBIT_TEST(e
->flags
, ENTRY_VALIDATED
))
68 storeSwapInValidateComplete(ctrlp
, 0, 0);
70 storeValidate(e
, storeSwapInValidateComplete
, ctrlp
, callback_data
);
74 storeSwapInValidateComplete(void *data
, int retcode
, int errcode
)
76 swapin_ctrl_t
*ctrlp
= (swapin_ctrl_t
*) data
;
78 if (retcode
== -2 && errcode
== -2) {
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
);
90 ctrlp
->path
= xstrdup(storeSwapFullPath(e
->swap_file_number
, NULL
));
91 debug(20, 3) ("storeSwapInValidateComplete: Opening %s\n", ctrlp
->path
);
93 file_open(ctrlp
->path
,
95 storeSwapInFileOpened
,
97 ctrlp
->callback_data
);
101 storeSwapInFileOpened(void *data
, int fd
, int errcode
)
103 swapin_ctrl_t
*ctrlp
= data
;
104 StoreEntry
*e
= ctrlp
->e
;
105 MemObject
*mem
= e
->mem_obj
;
107 if (fd
== -2 && errcode
== -2) {
110 store_open_disk_fd
--;
114 assert(e
->mem_status
== NOT_IN_MEMORY
);
115 assert(e
->swap_status
== SWAPOUT_WRITING
|| e
->swap_status
== SWAPOUT_DONE
);
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
) {
124 } else if (fstat(fd
, &sb
) < 0) {
125 debug(20, 1) ("storeSwapInFileOpened: fstat() FD %d: %s\n", fd
, xstrerror());
127 store_open_disk_fd
--;
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
);
132 store_open_disk_fd
--;
136 storeReleaseRequest(e
);
138 debug(20, 5) ("storeSwapInFileOpened: initialized '%s' for '%s'\n",
139 ctrlp
->path
, storeUrl(e
));
141 (ctrlp
->callback
) (fd
, ctrlp
->callback_data
);