Skip to content

Commit

Permalink
feat(csi-driver): add expansion logs
Browse files Browse the repository at this point in the history
Signed-off-by: Niladri Halder <niladri.halder26@gmail.com>
  • Loading branch information
niladrih committed Mar 1, 2024
1 parent 4fcc8a8 commit 67061c0
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 24 deletions.
23 changes: 14 additions & 9 deletions control-plane/csi-driver/src/bin/controller/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -978,23 +978,24 @@ impl rpc::csi::controller_server::Controller for CsiControllerSvc {
#[instrument(err, skip(self))]
async fn controller_expand_volume(
&self,
request: tonic::Request<ControllerExpandVolumeRequest>,
) -> Result<tonic::Response<ControllerExpandVolumeResponse>, tonic::Status> {
let request = request.into_inner();
request: Request<ControllerExpandVolumeRequest>,
) -> Result<Response<ControllerExpandVolumeResponse>, Status> {
let args = request.into_inner();
trace!(volume.uuid = %args.volume_id, request = ?args);

let vol_uuid = Uuid::parse_str(&request.volume_id).map_err(|error| {
let vol_uuid = Uuid::parse_str(&args.volume_id).map_err(|error| {
Status::invalid_argument(format!(
"Malformed volume UUID '{}': {error}",
request.volume_id
args.volume_id
))
})?;

let requested_size = request
let requested_size = args
.capacity_range
.as_ref()
.ok_or(Status::invalid_argument(format!(
"Cannot expand volume '{}': invalid request {request:?}: missing CapacityRange",
request.volume_id
"Cannot expand volume '{}': invalid request {args:?}: missing CapacityRange",
args.volume_id
)))?
.required_bytes;

Expand All @@ -1003,7 +1004,7 @@ impl rpc::csi::controller_server::Controller for CsiControllerSvc {
// assume NodeExpandVolume is required if it is not clearly defined that the volume is
// Block type volume.
let node_expansion_required = !matches!(
request.volume_capability.as_ref(),
args.volume_capability.as_ref(),
Some(vc) if matches!(vc.access_type, Some(AccessType::Block(_)))
);

Expand All @@ -1020,6 +1021,10 @@ impl rpc::csi::controller_server::Controller for CsiControllerSvc {
error => Status::from(error),
})?;

debug!(
size_bytes = requested_size,
"Expansion succeeded for volume {vol_uuid}"
);
Ok(tonic::Response::new(ControllerExpandVolumeResponse {
capacity_bytes: vol.spec.size as i64,
node_expansion_required,
Expand Down
41 changes: 26 additions & 15 deletions control-plane/csi-driver/src/bin/node/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,9 @@ impl node_server::Node for Node {
&self,
request: Request<NodeExpandVolumeRequest>,
) -> Result<Response<NodeExpandVolumeResponse>, Status> {
let args = request.into_inner();
trace!(volume.uuid = %args.volume_id, request = ?args);

//===============================CsiAccessType=============================================
// A type alias for better readability, and also easier conversions
// amongst the various error types in this crate.
Expand Down Expand Up @@ -474,30 +477,28 @@ impl node_server::Node for Node {
}
//===============================CsiAccessType=============================================

let request = request.into_inner();

let vol_uuid = Uuid::parse_str(request.volume_id.as_str()).map_err(|error| {
let vol_uuid = Uuid::parse_str(args.volume_id.as_str()).map_err(|error| {
failure!(
Code::InvalidArgument,
"Malformed volume UUID '{}': {}",
request.volume_id,
args.volume_id,
error
)
})?;

if request.volume_path.is_empty() {
if args.volume_path.is_empty() {
return Err(failure!(Code::InvalidArgument, "'volume_path' is empty"));
}

let required_bytes = request
let required_bytes = args
.capacity_range
.as_ref()
.ok_or_else(|| {
failure!(
Code::InvalidArgument,
"Cannot expand volume '{}': invalid request {:?}: missing CapacityRange",
request.volume_id,
request
args.volume_id,
args
)
})?
.required_bytes;
Expand Down Expand Up @@ -543,7 +544,7 @@ impl node_server::Node for Node {
// 10MiB includes addition leeway on top of the 5MiB required.
const MAX_NEXUS_CAPACITY_DIFFERENCE: i64 = 10 * 1024 * 1024;
// Ensure device_capacity is greater than or equal to required_bytes.
if (device_capacity + MAX_NEXUS_CAPACITY_DIFFERENCE) < required_bytes {
if device_capacity < (required_bytes - MAX_NEXUS_CAPACITY_DIFFERENCE) {
return Err(failure!(
Code::FailedPrecondition,
"block device capacity is lower than the required"
Expand All @@ -560,20 +561,26 @@ impl node_server::Node for Node {
// The CSI spec, as of v1.8.0, treats volume_capability as an optional field, so
// in an attempt to be as spec-compliant as possible, we must have a plan-B for the
// filesystem identification part.
let filesystem_handle = match CsiAccessType::from(&request.volume_capability) {
let filesystem_handle = match CsiAccessType::from(&args.volume_capability) {
// volume_capability AccessType says this is not a 'Mount' type. Nothing to do.
CsiAccessType::NotAFilesystem => return success_result,
CsiAccessType::NotAFilesystem => {
debug!(
"Filesystem expansion not required as volume {vol_uuid} \
is not a Filesystem type volume",
);
return success_result;
}
// volume_capability says that the filesystem is something we don't know about.
CsiAccessType::UnsupportedFilesystem(fs_err) => {
return Err(Status::invalid_argument(fs_err))
error!("Cannot expand filesystem: {}", &fs_err);
return Err(Status::invalid_argument(fs_err));
}
// volume_capability has identified a supported filesystem 🎉.
CsiAccessType::SupportedFilesystem(fs_type) => fs_type,
// volume_capability hasn't come through for us, we're on our own.
// Try to find the mount path at volume_path. As an extension, also validates that
// volume_path is in fact a filesystem.
CsiAccessType::Unknown(_) => match find_mount(None, Some(request.volume_path.as_str()))
{
CsiAccessType::Unknown(_) => match find_mount(None, Some(args.volume_path.as_str())) {
// Not a filesystem.
None => return success_result,
// Try to generate a supported filesystem type.
Expand All @@ -591,10 +598,14 @@ impl node_server::Node for Node {
filesystem_handle
.fs_ops()
.map_err(|err| failure!(Code::InvalidArgument, "{}", err))?
.expand(&request.volume_path)
.expand(&args.volume_path)
.await
.map_err(|err| failure!(Code::Internal, "{}", err))?;

debug!(
size_bytes = required_bytes,
"Expansion succeeded for volume {vol_uuid}"
);
success_result
}

Expand Down

0 comments on commit 67061c0

Please sign in to comment.