2 * Copyright (C) 1996-2016 The Squid Software Foundation and contributors
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
9 /* DEBUG: section 20 Storage Manager Swapin Functions */
13 #include "StatCounters.h"
15 #include "store_swapin.h"
16 #include "StoreClient.h"
18 static StoreIOState::STIOCB storeSwapInFileClosed
;
19 static StoreIOState::STFNCB storeSwapInFileNotify
;
22 storeSwapInStart(store_client
* sc
)
24 StoreEntry
*e
= sc
->entry
;
26 if (!EBIT_TEST(e
->flags
, ENTRY_VALIDATED
)) {
27 /* We're still reloading and haven't validated this entry yet */
31 if (e
->mem_status
!= NOT_IN_MEMORY
)
32 debugs(20, 3, HERE
<< "already IN_MEMORY");
34 debugs(20, 3, "storeSwapInStart: called for : " << e
->swap_dirn
<< " " <<
35 std::hex
<< std::setw(8) << std::setfill('0') << std::uppercase
<<
36 e
->swap_filen
<< " " << e
->getMD5Text());
38 if (e
->swap_status
!= SWAPOUT_WRITING
&& e
->swap_status
!= SWAPOUT_DONE
) {
39 debugs(20, DBG_IMPORTANT
, "storeSwapInStart: bad swap_status (" << swapStatusStr
[e
->swap_status
] << ")");
43 if (e
->swap_filen
< 0) {
44 debugs(20, DBG_IMPORTANT
, "storeSwapInStart: swap_filen < 0");
48 assert(e
->mem_obj
!= NULL
);
49 debugs(20, 3, "storeSwapInStart: Opening fileno " << std::hex
<< std::setw(8) << std::setfill('0') << std::uppercase
<< e
->swap_filen
);
50 sc
->swapin_sio
= storeOpen(e
, storeSwapInFileNotify
, storeSwapInFileClosed
, sc
);
54 storeSwapInFileClosed(void *data
, int errflag
, StoreIOState::Pointer
)
56 store_client
*sc
= (store_client
*)data
;
57 debugs(20, 3, "storeSwapInFileClosed: sio=" << sc
->swapin_sio
.getRaw() << ", errflag=" << errflag
);
58 sc
->swapin_sio
= NULL
;
60 if (sc
->_callback
.pending()) {
61 assert (errflag
<= 0);
62 sc
->callback(0, errflag
? true : false);
65 ++statCounter
.swap
.ins
;
69 storeSwapInFileNotify(void *data
, int, StoreIOState::Pointer
)
71 store_client
*sc
= (store_client
*)data
;
72 StoreEntry
*e
= sc
->entry
;
74 debugs(1, 3, "storeSwapInFileNotify: changing " << e
->swap_filen
<< "/" <<
75 e
->swap_dirn
<< " to " << sc
->swapin_sio
->swap_filen
<< "/" <<
76 sc
->swapin_sio
->swap_dirn
);
78 assert(e
->swap_filen
< 0); // if this fails, call SwapDir::disconnect(e)
79 e
->swap_filen
= sc
->swapin_sio
->swap_filen
;
80 e
->swap_dirn
= sc
->swapin_sio
->swap_dirn
;