]>
Commit | Line | Data |
---|---|---|
b9ae18aa | 1 | /* |
4ac4a490 | 2 | * Copyright (C) 1996-2017 The Squid Software Foundation and contributors |
b9ae18aa | 3 | * |
bbc27441 AJ |
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. | |
b9ae18aa | 7 | */ |
8 | ||
bbc27441 AJ |
9 | /* DEBUG: section 92 Storage File System */ |
10 | ||
582c2af2 | 11 | #include "squid.h" |
b9ae18aa | 12 | #include "DiskIOModule.h" |
d9691f09 AJ |
13 | #if HAVE_DISKIO_MODULE_AIO |
14 | #include "DiskIO/AIO/AIODiskIOModule.h" | |
15 | #endif | |
16 | #if HAVE_DISKIO_MODULE_BLOCKING | |
17 | #include "DiskIO/Blocking/BlockingDiskIOModule.h" | |
18 | #endif | |
19 | #if HAVE_DISKIO_MODULE_DISKDAEMON | |
20 | #include "DiskIO/DiskDaemon/DiskDaemonDiskIOModule.h" | |
21 | #endif | |
22 | #if HAVE_DISKIO_MODULE_DISKTHREADS | |
23 | #include "DiskIO/DiskThreads/DiskThreadsDiskIOModule.h" | |
24 | #endif | |
25 | #if HAVE_DISKIO_MODULE_IPCIO | |
26 | #include "DiskIO/IpcIo/IpcIoDiskIOModule.h" | |
27 | #endif | |
23ee12fb | 28 | #if HAVE_DISKIO_MODULE_MMAPPED |
d9691f09 AJ |
29 | #include "DiskIO/Mmapped/MmappedDiskIOModule.h" |
30 | #endif | |
b9ae18aa | 31 | |
c8ea3cc0 | 32 | std::vector<DiskIOModule*> *DiskIOModule::_Modules = NULL; |
b9ae18aa | 33 | |
34 | //DiskIOModule() : initialised (false) {} | |
09c5ae5a | 35 | |
b9ae18aa | 36 | DiskIOModule::DiskIOModule() |
37 | { | |
09c5ae5a AJ |
38 | /** We cannot call ModuleAdd(*this) |
39 | * here as the virtual methods are not yet available. | |
d9691f09 | 40 | * We leave that to SetupAllModules() later. |
b9ae18aa | 41 | */ |
42 | } | |
43 | ||
44 | void | |
45 | DiskIOModule::SetupAllModules() | |
46 | { | |
d9691f09 AJ |
47 | #if HAVE_DISKIO_MODULE_AIO |
48 | AIODiskIOModule::GetInstance(); | |
49 | #endif | |
50 | #if HAVE_DISKIO_MODULE_BLOCKING | |
51 | BlockingDiskIOModule::GetInstance(); | |
52 | #endif | |
53 | #if HAVE_DISKIO_MODULE_DISKDAEMON | |
54 | DiskDaemonDiskIOModule::GetInstance(); | |
55 | #endif | |
56 | #if HAVE_DISKIO_MODULE_DISKTHREADS | |
57 | DiskThreadsDiskIOModule::GetInstance(); | |
58 | #endif | |
59 | #if HAVE_DISKIO_MODULE_IPCIO | |
60 | IpcIoDiskIOModule::GetInstance(); | |
61 | #endif | |
62 | #if HAVE_DISKIO_MODULE_MMAPPED | |
63 | MmappedDiskIOModule::GetInstance(); | |
64 | #endif | |
09c5ae5a | 65 | |
b9ae18aa | 66 | for (iterator i = GetModules().begin(); i != GetModules().end(); ++i) |
67 | /* Call the FS to set up capabilities and initialize the FS driver */ | |
68 | (*i)->init(); | |
69 | } | |
70 | ||
71 | void | |
72 | DiskIOModule::ModuleAdd(DiskIOModule &instance) | |
73 | { | |
74 | iterator i = GetModules().begin(); | |
75 | ||
76 | while (i != GetModules().end()) { | |
77 | assert(strcmp((*i)->type(), instance.type()) != 0); | |
78 | ++i; | |
79 | } | |
80 | ||
81 | GetModules().push_back (&instance); | |
82 | } | |
83 | ||
c8ea3cc0 | 84 | std::vector<DiskIOModule *> const & |
b9ae18aa | 85 | DiskIOModule::Modules() |
86 | { | |
87 | return GetModules(); | |
88 | } | |
89 | ||
c8ea3cc0 | 90 | std::vector<DiskIOModule*> & |
b9ae18aa | 91 | DiskIOModule::GetModules() |
92 | { | |
93 | if (!_Modules) | |
c8ea3cc0 | 94 | _Modules = new std::vector<DiskIOModule *>; |
b9ae18aa | 95 | |
96 | return *_Modules; | |
97 | } | |
98 | ||
09c5ae5a AJ |
99 | /** |
100 | * Called when a graceful shutdown is to occur | |
b9ae18aa | 101 | * of each fs module. |
102 | */ | |
103 | void | |
104 | DiskIOModule::FreeAllModules() | |
105 | { | |
385acf91 | 106 | while (!GetModules().empty()) { |
b9ae18aa | 107 | DiskIOModule *fs = GetModules().back(); |
108 | GetModules().pop_back(); | |
1e1a9021 | 109 | fs->gracefulShutdown(); |
b9ae18aa | 110 | } |
111 | } | |
112 | ||
113 | DiskIOModule * | |
114 | DiskIOModule::Find(char const *type) | |
115 | { | |
116 | for (iterator i = GetModules().begin(); i != GetModules().end(); ++i) | |
117 | if (strcasecmp(type, (*i)->type()) == 0) | |
118 | return *i; | |
119 | ||
120 | return NULL; | |
121 | } | |
62ee09ca | 122 | |
b7717b61 | 123 | DiskIOModule * |
124 | DiskIOModule::FindDefault() | |
125 | { | |
09c5ae5a | 126 | /** Best IO options are in order: */ |
b7717b61 | 127 | DiskIOModule * result; |
128 | result = Find("DiskThreads"); | |
129 | if (NULL == result) | |
130 | result = Find("DiskDaemon"); | |
131 | if (NULL == result) | |
132 | result = Find("AIO"); | |
133 | if (NULL == result) | |
134 | result = Find("Blocking"); | |
135 | return result; | |
136 | } | |
f53969cc | 137 |