Skip to content

Commit

Permalink
Merge #1670
Browse files Browse the repository at this point in the history
1670: feat: expose bugfixes through grpc host api r=tiagolobocastro a=tiagolobocastro

This will allow control-plane to make better decisions, example: don't allow rebuilds if bugfix is not present.

Co-authored-by: Tiago Castro <[email protected]>
  • Loading branch information
mayastor-bors and tiagolobocastro committed Jun 12, 2024
2 parents b9cfe02 + bf2f9fd commit da78f93
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 46 deletions.
6 changes: 3 additions & 3 deletions io-engine/src/core/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,8 @@ impl MayastorFeatures {
snapshot_rebuild,
}
}

pub fn get_features() -> Self {
/// Get all the supported and enabled features.
pub fn get() -> Self {
MAYASTOR_FEATURES.get_or_init(Self::init_features).clone()
}
}
Expand Down Expand Up @@ -513,7 +513,7 @@ async fn do_shutdown(arg: *mut c_void) {
nexus::shutdown_nexuses().await;
crate::rebuild::shutdown_snapshot_rebuilds().await;
crate::lvs::Lvs::export_all().await;
if MayastorFeatures::get_features().lvm() {
if MayastorFeatures::get().lvm() {
crate::lvm::VolumeGroup::export_all().await;
}

Expand Down
17 changes: 17 additions & 0 deletions io-engine/src/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,24 @@ pub struct MayastorFeatures {
pub snapshot_rebuild: bool,
}
impl MayastorFeatures {
/// Check if LVM feature is enabled.
pub fn lvm(&self) -> bool {
self.logical_volume_manager
}
}

/// Bugfix information to expose to the control-plane.
#[derive(Debug, Clone)]
pub(crate) struct MayastorBugFixes {
/// Nexus Rebuild rebuilds all the clusters allocated to the replica and
/// its ancestors.
pub nexus_rebuild_replica_ancestry: bool,
}
impl MayastorBugFixes {
/// Get all the bug fixes.
pub fn get() -> Self {
Self {
nexus_rebuild_replica_ancestry: true,
}
}
}
2 changes: 1 addition & 1 deletion io-engine/src/grpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ pub fn get_request_timeout<T>(req: &Request<T>) -> Duration {
}

fn lvm_enabled() -> Result<(), Status> {
if !MayastorFeatures::get_features().lvm() {
if !MayastorFeatures::get().lvm() {
return Err(Status::failed_precondition("lvm support not enabled"));
}
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion io-engine/src/grpc/v0/mayastor_grpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1836,7 +1836,7 @@ impl mayastor_server::Mayastor for MayastorSvc {
&self,
_request: Request<Null>,
) -> GrpcResult<MayastorInfoRequest> {
let features = MayastorFeatures::get_features().into();
let features = MayastorFeatures::get().into();

let reply = MayastorInfoRequest {
version: raw_version_string(),
Expand Down
38 changes: 27 additions & 11 deletions io-engine/src/grpc/v1/host.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
bdev::{nexus, NvmeControllerState},
core::{BlockDeviceIoStats, CoreError, MayastorFeatures},
core::{BlockDeviceIoStats, CoreError, MayastorBugFixes, MayastorFeatures},
grpc::{
controller_grpc::{
controller_stats,
Expand All @@ -17,7 +17,10 @@ use crate::{
};
use ::function_name::named;
use futures::FutureExt;
use io_engine_api::v1::{host as host_rpc, registration::RegisterRequest};
use io_engine_api::{
v1,
v1::{host as host_rpc, registration::RegisterRequest},
};
use std::panic::AssertUnwindSafe;
use tonic::{Request, Response, Status};
use version_info::raw_version_string;
Expand Down Expand Up @@ -99,8 +102,23 @@ impl From<MayastorFeatures> for host_rpc::MayastorFeatures {
fn from(f: MayastorFeatures) -> Self {
Self {
asymmetric_namespace_access: f.asymmetric_namespace_access,
logical_volume_manager: f.logical_volume_manager,
snapshot_rebuild: f.snapshot_rebuild,
logical_volume_manager: Some(f.logical_volume_manager),
snapshot_rebuild: Some(f.snapshot_rebuild),
}
}
}
impl From<MayastorFeatures> for host_rpc::BackCompatMayastorFeatures {
fn from(f: MayastorFeatures) -> Self {
Self {
asymmetric_namespace_access: f.asymmetric_namespace_access,
}
}
}

impl From<MayastorBugFixes> for host_rpc::MayastorBugFixes {
fn from(f: MayastorBugFixes) -> Self {
Self {
nexus_rebuild_replica_ancestry: f.nexus_rebuild_replica_ancestry,
}
}
}
Expand Down Expand Up @@ -220,27 +238,25 @@ impl host_rpc::HostRpc for HostService {
&self,
_request: Request<()>,
) -> GrpcResult<host_rpc::MayastorInfoResponse> {
let features = MayastorFeatures::get_features().into();
let api_versions = self
.api_versions
.iter()
.map(|v| {
let api_version: io_engine_api::v1::registration::ApiVersion =
v.clone().into();
api_version as i32
})
.map(|v| v1::registration::ApiVersion::from(*v) as i32)
.collect();

let response = host_rpc::MayastorInfoResponse {
version: raw_version_string(),
supported_features: Some(features),
previous_features: Some(MayastorFeatures::get().into()),
registration_info: Some(RegisterRequest {
id: self.node_name.clone(),
grpc_endpoint: self.grpc_socket.to_string(),
instance_uuid: Registration::get()
.map(|r| r.instance_uuid().to_string()),
api_version: api_versions,
hostnqn: self.node_nqn.clone(),
features: Some(MayastorFeatures::get().into()),
bugfixes: Some(MayastorBugFixes::get().into()),
version: Some(raw_version_string()),
}),
};

Expand Down
6 changes: 3 additions & 3 deletions io-engine/src/lvm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ impl PoolFactory for PoolLvmFactory {
&self,
args: &FindPoolArgs,
) -> Result<Option<Box<dyn PoolOps>>, crate::pool_backend::Error> {
if !crate::core::MayastorFeatures::get_features().lvm() {
if !crate::core::MayastorFeatures::get().lvm() {
return Ok(None);
}
use CmnQueryArgs;
Expand All @@ -291,7 +291,7 @@ impl PoolFactory for PoolLvmFactory {
&self,
args: &ListPoolArgs,
) -> Result<Vec<Box<dyn PoolOps>>, crate::pool_backend::Error> {
if !crate::core::MayastorFeatures::get_features().lvm() {
if !crate::core::MayastorFeatures::get().lvm() {
return Ok(vec![]);
}
if matches!(args.backend, Some(p) if p != PoolBackend::Lvm) {
Expand Down Expand Up @@ -340,7 +340,7 @@ impl ReplicaFactory for ReplLvmFactory {
&self,
args: &ListReplicaArgs,
) -> Result<Vec<Box<dyn ReplicaOps>>, crate::pool_backend::Error> {
if !crate::core::MayastorFeatures::get_features().lvm() {
if !crate::core::MayastorFeatures::get().lvm() {
return Ok(vec![]);
}
let replicas = LogicalVolume::list(
Expand Down
45 changes: 20 additions & 25 deletions io-engine/src/subsys/registration/registration_grpc.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
#![warn(missing_docs)]

use crate::core::{MayastorBugFixes, MayastorFeatures};
use futures::{select, FutureExt, StreamExt};
use http::Uri;
use io_engine_api::v1::registration::{
registration_client,
ApiVersion as ApiVersionGrpc,
DeregisterRequest,
RegisterRequest,
};
use once_cell::sync::OnceCell;
use std::{env, str::FromStr, time::Duration};
use version_info::raw_version_string;

/// Mayastor sends registration messages in this interval (kind of heart-beat)
const HB_INTERVAL_SEC: Duration = Duration::from_secs(5);
Expand All @@ -19,7 +22,7 @@ const HTTP_KEEP_ALIVE_INTERVAL: Duration = Duration::from_secs(10);
/// The http2 keep alive TIMEOUT.
const HTTP_KEEP_ALIVE_TIMEOUT: Duration = Duration::from_secs(20);

#[derive(Clone, Debug, PartialEq)]
#[derive(Copy, Clone, Debug, PartialEq)]
/// ApiVersion to be supported
pub enum ApiVersion {
/// V0 Version of api
Expand Down Expand Up @@ -152,31 +155,23 @@ impl Registration {

/// Register a new node over rpc
pub async fn register(&mut self) -> Result<(), tonic::Status> {
let api_versions = self
.config
.api_versions
.clone()
.into_iter()
.map(|v| {
let api_version: io_engine_api::v1::registration::ApiVersion =
v.into();
api_version as i32
})
.collect();
match self
.client
.register(tonic::Request::new(RegisterRequest {
id: self.config.node.to_string(),
grpc_endpoint: self.config.grpc_endpoint.clone(),
instance_uuid: Some(self.config.instance_uuid.to_string()),
api_version: api_versions,
hostnqn: self.config.node_nqn.clone(),
}))
let api_versions = self.config.api_versions.iter();
let api_versions =
api_versions.map(|v| ApiVersionGrpc::from(*v) as i32);
let register = RegisterRequest {
id: self.config.node.to_string(),
grpc_endpoint: self.config.grpc_endpoint.clone(),
instance_uuid: Some(self.config.instance_uuid.to_string()),
api_version: api_versions.collect(),
hostnqn: self.config.node_nqn.clone(),
features: Some(MayastorFeatures::get().into()),
bugfixes: Some(MayastorBugFixes::get().into()),
version: Some(raw_version_string()),
};
self.client
.register(tonic::Request::new(register))
.await
{
Ok(_) => Ok(()),
Err(e) => Err(e),
}
.map(|_| ())
}

/// Deregister a node over rpc
Expand Down
2 changes: 1 addition & 1 deletion test/python/v1/pool/test_bdd_lvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def find(name):

@when("the user calls the gRPC mayastor info request", target_fixture="get_lvm_feature")
def get_lvm_feature(get_mayastor_instance, get_mayastor_info):
return get_mayastor_info.supportedFeatures.logicalVolumeManager
return get_mayastor_info.registration_info.features.logicalVolumeManager


@then("the instance shall report if it supports the LVM feature")
Expand Down

0 comments on commit da78f93

Please sign in to comment.