| 363 | |
| 364 | |
| 365 | Future<string> CSIServerProcess::publishVolume(const Volume& volume) |
| 366 | { |
| 367 | CHECK(volume.has_source() && |
| 368 | volume.source().has_type() && |
| 369 | volume.source().type() == Volume::Source::CSI_VOLUME); |
| 370 | |
| 371 | CHECK(volume.source().has_csi_volume() && |
| 372 | volume.source().csi_volume().has_static_provisioning()); |
| 373 | |
| 374 | const Volume::Source::CSIVolume& csiVolume = volume.source().csi_volume(); |
| 375 | |
| 376 | const string& name = csiVolume.plugin_name(); |
| 377 | |
| 378 | if (!plugins.contains(name)) { |
| 379 | // This will attempt to load the plugin's configuration, initialize the |
| 380 | // plugin, and insert it into the `plugins` map. |
| 381 | Try<Nothing> pluginInit = initializePlugin(name); |
| 382 | if (pluginInit.isError()) { |
| 383 | return Failure( |
| 384 | "Failed to initialize CSI plugin '" + |
| 385 | name + "': " + pluginInit.error()); |
| 386 | } |
| 387 | } |
| 388 | |
| 389 | CHECK(plugins.contains(name)); |
| 390 | |
| 391 | return plugins.at(name).initialized.future() |
| 392 | .then(defer(self(), [=]() { |
| 393 | CHECK(plugins.contains(name)); |
| 394 | |
| 395 | return plugins.at(name).volumeManager->publishVolume( |
| 396 | csiVolume.static_provisioning().volume_id(), |
| 397 | createVolumeState(volume)); |
| 398 | })) |
| 399 | .then(defer(self(), [=]() { |
| 400 | CHECK(plugins.contains(name)); |
| 401 | |
| 402 | const CSIPluginInfo& info = plugins.at(csiVolume.plugin_name()).info; |
| 403 | |
| 404 | const string mountRootDir = info.has_target_path_root() |
| 405 | ? info.target_path_root() |
| 406 | : csi::paths::getMountRootDir(rootDir, info.type(), info.name()); |
| 407 | |
| 408 | return csi::paths::getMountTargetPath( |
| 409 | mountRootDir, |
| 410 | csiVolume.static_provisioning().volume_id()); |
| 411 | })); |
| 412 | } |
| 413 | |
| 414 | |
| 415 | Future<Nothing> CSIServerProcess::unpublishVolume( |