Skip to content

Commit

Permalink
chore(bors): merge pull request openebs#750
Browse files Browse the repository at this point in the history
750: feat(snapshot): coreagent change for setvolumeattributes r=hrudaya21 a=hrudaya21



Co-authored-by: Hrudaya <[email protected]>
  • Loading branch information
mayastor-bors and hrudaya21 committed Feb 23, 2024
2 parents 7559c7f + 96c8a20 commit 18a6fde
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,19 @@ pub(crate) trait ResourceReplicas {
) -> Result<Self::MoveResp, SvcError>;
}

/// Resource Property Operations.
#[async_trait::async_trait]
pub(crate) trait ResourceProperty {
type Request: Sync + Send;

/// Set property values for the resource.
async fn set_property(
&mut self,
registry: &Registry,
request: &Self::Request,
) -> Result<(), SvcError>;
}

/// Resource Children/Offspring Operations.
#[async_trait::async_trait]
pub(crate) trait ResourceOffspring {
Expand Down
25 changes: 21 additions & 4 deletions control-plane/agents/src/bin/core/volume/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use crate::{
resources::{
operations::{
ResourceLifecycle, ResourceLifecycleExt, ResourceLifecycleWithLifetime,
ResourceOwnerUpdate, ResourcePublishing, ResourceReplicas, ResourceResize,
ResourceSharing, ResourceShutdownOperations,
ResourceOwnerUpdate, ResourceProperty, ResourcePublishing, ResourceReplicas,
ResourceResize, ResourceSharing, ResourceShutdownOperations,
},
operations_helper::{
GuardedOperationsHelper, OnCreateFail, OperationSequenceGuard, ResourceSpecsLocked,
Expand Down Expand Up @@ -37,8 +37,8 @@ use stor_port::{
transport::{
CreateVolume, DestroyNexus, DestroyReplica, DestroyShutdownTargets, DestroyVolume,
Protocol, PublishVolume, Replica, ReplicaId, ReplicaOwners, RepublishVolume,
ResizeVolume, SetVolumeReplica, ShareNexus, ShareVolume, ShutdownNexus,
UnpublishVolume, UnshareNexus, UnshareVolume, Volume,
ResizeVolume, SetVolumeProperty, SetVolumeReplica, ShareNexus, ShareVolume,
ShutdownNexus, UnpublishVolume, UnshareNexus, UnshareVolume, Volume,
},
},
};
Expand Down Expand Up @@ -645,6 +645,23 @@ impl ResourceReplicas for OperationGuardArc<VolumeSpec> {
}
}

#[async_trait::async_trait]
impl ResourceProperty for OperationGuardArc<VolumeSpec> {
type Request = SetVolumeProperty;

async fn set_property(
&mut self,
registry: &Registry,
request: &Self::Request,
) -> Result<(), SvcError> {
let state = registry.volume_state(&request.uuid).await?;
let operation = VolumeOperation::SetVolumeProperty(request.property.clone());
let spec_clone = self.start_update(registry, &state, operation).await?;

self.complete_update(registry, Ok(()), spec_clone).await?;
Ok(())
}
}
#[async_trait::async_trait]
impl ResourceShutdownOperations for OperationGuardArc<VolumeSpec> {
type RemoveShutdownTargets = DestroyShutdownTargets;
Expand Down
1 change: 1 addition & 0 deletions control-plane/agents/src/bin/core/volume/specs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1113,6 +1113,7 @@ impl SpecOperationsHelper for VolumeSpec {
VolumeOperation::CreateSnapshot(_) => Ok(()),
VolumeOperation::DestroySnapshot(_) => Ok(()),
VolumeOperation::Resize(_) => Ok(()),
VolumeOperation::SetVolumeProperty(_) => Ok(()),
}?;
self.start_op(operation);
Ok(())
Expand Down
23 changes: 11 additions & 12 deletions control-plane/stor-port/src/types/v0/store/volume.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,16 @@ use crate::{
},
transport::{
self, AffinityGroup, CreateVolume, HostNqn, NexusId, NexusNvmfConfig, NodeId,
ReplicaId, SnapshotId, Topology, VolumeId, VolumeLabels, VolumePolicy,
ReplicaId, SnapshotId, Topology, VolumeId, VolumeLabels, VolumePolicy, VolumeProperty,
VolumeShareProtocol, VolumeStatus,
},
},
IntoOption,
};

use pstor::ApiVersion;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use strum_macros::{EnumCount as EnumCountMacro, EnumIter, EnumString};

/// Volume properties.
#[derive(
Serialize, Deserialize, EnumString, Debug, EnumCountMacro, EnumIter, PartialEq, Clone, Copy,
)]
pub enum VolumeAttr {
/// Max number of snapshots allowed per volume.
#[strum(serialize = "max_snapshots")]
MaxSnapshots,
}

/// Key used by the store to uniquely identify a VolumeState structure.
pub struct VolumeStateKey(VolumeId);
Expand Down Expand Up @@ -519,6 +509,11 @@ impl SpecTransaction<VolumeOperation> for VolumeSpec {
VolumeOperation::Resize(size) => {
self.size = size;
}
VolumeOperation::SetVolumeProperty(property) => match property {
VolumeProperty::MaxSnapshots(max_snapshots) => {
self.max_snapshots = Some(max_snapshots);
}
},
}
}
self.clear_op();
Expand Down Expand Up @@ -583,6 +578,7 @@ pub enum VolumeOperation {
CreateSnapshot(SnapshotId),
DestroySnapshot(SnapshotId),
Resize(u64),
SetVolumeProperty(VolumeProperty),
}

#[test]
Expand Down Expand Up @@ -681,6 +677,9 @@ impl From<VolumeOperation> for models::volume_spec_operation::Operation {
VolumeOperation::DestroySnapshot(_) => {
models::volume_spec_operation::Operation::DestroySnapshot
}
VolumeOperation::SetVolumeProperty(_) => {
todo!()
}
VolumeOperation::Resize(_) => todo!(),
}
}
Expand Down
23 changes: 23 additions & 0 deletions control-plane/stor-port/src/types/v0/transport/volume.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ pub struct VolumeState {
pub usage: Option<VolumeUsage>,
}

/// Volume properties.
#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
pub enum VolumeProperty {
/// Max number of snapshots allowed per volume.
MaxSnapshots(u32),
}

#[derive(Default, Debug, Clone, Eq, PartialEq)]
pub struct VolumeUsage {
/// Capacity of the volume in bytes.
Expand Down Expand Up @@ -703,6 +710,22 @@ impl SetVolumeReplica {
}
}

/// Set the volume property.
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct SetVolumeProperty {
/// The uuid of the volume.
pub uuid: VolumeId,
/// The property to set.
pub property: VolumeProperty,
}
impl SetVolumeProperty {
/// Create new `Self` based on the provided arguments.
pub fn new(uuid: VolumeId, property: VolumeProperty) -> Self {
Self { uuid, property }
}
}

/// Delete volume request.
#[derive(Serialize, Deserialize, Default, Debug, Clone)]
#[serde(rename_all = "camelCase")]
Expand Down

0 comments on commit 18a6fde

Please sign in to comment.