Skip to content

Commit 45d4dfe

Browse files
committed
mgr: load persistent device metadata on mgr stat
Prune DeviceState when there is no persistent metadata and no daemon references. Load persistent metadata from config-key. Signed-off-by: Sage Weil <[email protected]>
1 parent 8986e10 commit 45d4dfe

4 files changed

Lines changed: 34 additions & 4 deletions

File tree

‎src/mgr/DaemonState.cc‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ void DaemonStateIndex::_erase(const DaemonKey& dmk)
5050
auto d = _get_or_create_device(devid);
5151
assert(d->daemons.count(dmk));
5252
d->daemons.erase(dmk);
53-
if (d->daemons.empty()) {
53+
if (d->empty()) {
5454
_erase_device(d);
5555
}
5656
}

‎src/mgr/DaemonState.h‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,16 @@ struct DeviceState : public RefCountedObject
191191
std::string server;
192192
std::set<DaemonKey> daemons;
193193

194+
std::map<string,string> metadata; ///< persistent metadata
195+
194196
DeviceState(const std::string& n) : devid(n) {}
197+
198+
void set_metadata(map<string,string>&& m);
199+
200+
/// true of we can be safely forgotten/removed from memory
201+
bool empty() const {
202+
return daemons.empty() && metadata.empty();
203+
}
195204
};
196205

197206
typedef boost::intrusive_ptr<DeviceState> DeviceStateRef;

‎src/mgr/Mgr.cc‎

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,10 @@ std::map<std::string, std::string> Mgr::load_store()
174174
dout(20) << "saw key '" << key << "'" << dendl;
175175

176176
const std::string config_prefix = PyModule::config_prefix;
177+
const std::string device_prefix = "device/";
177178

178-
if (key.substr(0, config_prefix.size()) == config_prefix) {
179+
if (key.substr(0, config_prefix.size()) == config_prefix ||
180+
key.substr(0, device_prefix.size()) == device_prefix) {
179181
dout(20) << "fetching '" << key << "'" << dendl;
180182
Command get_cmd;
181183
std::ostringstream cmd_json;
@@ -185,7 +187,26 @@ std::map<std::string, std::string> Mgr::load_store()
185187
get_cmd.wait();
186188
lock.Lock();
187189
if (get_cmd.r == 0) { // tolerate racing config-key change
188-
loaded[key] = get_cmd.outbl.to_str();
190+
if (key.substr(0, device_prefix.size()) == device_prefix) {
191+
// device/
192+
string devid = key.substr(device_prefix.size());
193+
map<string,string> meta;
194+
ostringstream ss;
195+
string val = get_cmd.outbl.to_str();
196+
int r = get_json_str_map(val, ss, &meta, false);
197+
if (r < 0) {
198+
derr << __func__ << " failed to parse " << val << ": " << ss.str()
199+
<< dendl;
200+
} else {
201+
daemon_state.with_device_create(
202+
devid, [&meta] (DeviceState& dev) {
203+
dev.set_metadata(std::move(meta));
204+
});
205+
}
206+
} else {
207+
// config/
208+
loaded[key] = get_cmd.outbl.to_str();
209+
}
189210
}
190211
}
191212
}

‎src/mgr/PyModuleRegistry.cc‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ void PyModuleRegistry::upgrade_config(
412412
dout(1) << "Upgrading module configuration for Mimic" << dendl;
413413
// Upgrade luminous->mimic: migrate config-key configuration
414414
// into main configuration store
415-
for(auto &i : old_config) {
415+
for (auto &i : old_config) {
416416
auto last_slash = i.first.rfind('/');
417417
const std::string module_name = i.first.substr(4, i.first.substr(4).find('/'));
418418
const std::string key = i.first.substr(last_slash + 1);

0 commit comments

Comments
 (0)