syntax = "proto3";

package talos.resource.definitions.block;

option go_package = "github.com/siderolabs/talos/pkg/machinery/api/resource/definitions/block";
option java_package = "dev.talos.api.resource.definitions.block";

import "google/api/expr/v1alpha1/checked.proto";
import "resource/definitions/enums/enums.proto";

// DeviceSpec is the spec for devices status.
message DeviceSpec {
  string type = 1;
  int64 major = 2;
  int64 minor = 3;
  string partition_name = 4;
  int64 partition_number = 5;
  int64 generation = 6;
  string device_path = 7;
  string parent = 8;
  repeated string secondaries = 9;
}

// DiscoveredVolumeSpec is the spec for DiscoveredVolumes resource.
message DiscoveredVolumeSpec {
  uint64 size = 1;
  uint64 sector_size = 2;
  uint64 io_size = 3;
  string name = 4;
  string uuid = 5;
  string label = 6;
  uint32 block_size = 7;
  uint32 filesystem_block_size = 8;
  uint64 probed_size = 9;
  string partition_uuid = 10;
  string partition_type = 11;
  string partition_label = 12;
  uint64 partition_index = 13;
  string type = 14;
  string device_path = 15;
  string parent = 16;
  string dev_path = 17;
  string parent_dev_path = 18;
  string pretty_size = 19;
  uint64 offset = 20;
}

// DiscoveryRefreshRequestSpec is the spec for DiscoveryRefreshRequest.
message DiscoveryRefreshRequestSpec {
  int64 request = 1;
}

// DiscoveryRefreshStatusSpec is the spec for DiscoveryRefreshStatus status.
message DiscoveryRefreshStatusSpec {
  int64 request = 1;
}

// DiskSelector selects a disk for the volume.
message DiskSelector {
  google.api.expr.v1alpha1.CheckedExpr match = 1;
  string external = 2;
}

// DiskSpec is the spec for Disks status.
message DiskSpec {
  uint64 size = 1;
  uint64 io_size = 2;
  uint64 sector_size = 3;
  bool readonly = 4;
  string model = 5;
  string serial = 6;
  string modalias = 7;
  string wwid = 8;
  string bus_path = 9;
  string sub_system = 10;
  string transport = 11;
  bool rotational = 12;
  bool cdrom = 13;
  string dev_path = 14;
  string pretty_size = 15;
  repeated string secondary_disks = 16;
  string uuid = 17;
  repeated string symlinks = 18;
}

// EncryptionKey is the spec for volume encryption key.
message EncryptionKey {
  int64 slot = 1;
  talos.resource.definitions.enums.BlockEncryptionKeyType type = 2;
  bytes static_passphrase = 3;
  string kms_endpoint = 4;
  bool tpm_check_secureboot_status_on_enroll = 5;
  bool lock_to_state = 6;
  repeated int64 tpmpc_rs = 7;
  repeated int64 tpm_pub_key_pc_rs = 8;
}

// EncryptionSpec is the spec for volume encryption.
message EncryptionSpec {
  talos.resource.definitions.enums.BlockEncryptionProviderType provider = 1;
  repeated EncryptionKey keys = 2;
  string cipher = 3;
  uint64 key_size = 4;
  uint64 block_size = 5;
  repeated string perf_options = 6;
}

// FilesystemSpec is the spec for volume filesystem.
message FilesystemSpec {
  talos.resource.definitions.enums.BlockFilesystemType type = 1;
  string label = 2;
}

// LocatorSpec is the spec for volume locator.
message LocatorSpec {
  google.api.expr.v1alpha1.CheckedExpr match = 1;
  google.api.expr.v1alpha1.CheckedExpr disk_match = 2;
}

// MountRequestSpec is the spec for MountRequest.
message MountRequestSpec {
  string volume_id = 1;
  string parent_mount_id = 2;
  repeated string requesters = 3;
  repeated string requester_i_ds = 4;
  bool read_only = 5;
  bool detached = 6;
  bool disable_access_time = 7;
  bool secure = 8;
}

// MountSpec is the spec for volume mount.
message MountSpec {
  string target_path = 1;
  string selinux_label = 2;
  bool project_quota_support = 3;
  string parent_id = 4;
  uint32 file_mode = 5;
  int64 uid = 6;
  int64 gid = 7;
  bool recursive_relabel = 8;
  string bind_target = 9;
  repeated ParameterSpec parameters = 10;
}

// MountStatusSpec is the spec for MountStatus.
message MountStatusSpec {
  MountRequestSpec spec = 1;
  string target = 2;
  string source = 3;
  talos.resource.definitions.enums.BlockFilesystemType filesystem = 4;
  bool read_only = 5;
  bool project_quota_support = 6;
  talos.resource.definitions.enums.BlockEncryptionProviderType encryption_provider = 7;
  bool detached = 8;
}

// ParameterSpec is a mount parameter.
message ParameterSpec {
  talos.resource.definitions.enums.BlockFSParameterType type = 1;
  string name = 2;
  string string = 3;
  bytes binary = 5;
}

// PartitionSpec is the spec for volume partitioning.
message PartitionSpec {
  uint64 min_size = 1;
  uint64 max_size = 2;
  bool grow = 3;
  string label = 4;
  string type_uuid = 5;
  uint64 relative_max_size = 6;
  bool negative_max_size = 7;
}

// ProvisioningSpec is the spec for volume provisioning.
message ProvisioningSpec {
  DiskSelector disk_selector = 1;
  PartitionSpec partition_spec = 2;
  int64 wave = 3;
  FilesystemSpec filesystem_spec = 4;
}

// SwapStatusSpec is the spec for SwapStatuss resource.
message SwapStatusSpec {
  string device = 1;
  uint64 size_bytes = 2;
  string size_human = 3;
  uint64 used_bytes = 4;
  string used_human = 5;
  int32 priority = 6;
  string type = 7;
}

// SymlinkProvisioningSpec is the spec for volume symlink.
message SymlinkProvisioningSpec {
  string symlink_target_path = 1;
  bool force = 2;
}

// SymlinkSpec is the spec for Symlinks resource.
message SymlinkSpec {
  repeated string paths = 1;
}

// SystemDiskSpec is the spec for SystemDisks resource.
message SystemDiskSpec {
  string disk_id = 1;
  string dev_path = 2;
}

// TPMEncryptionOptionsInfo is the options for TPM-based encryption.
message TPMEncryptionOptionsInfo {
  repeated int64 pc_rs = 1;
  repeated int64 pub_key_pc_rs = 2;
}

// UserDiskConfigStatusSpec is the spec for UserDiskConfigStatus resource.
message UserDiskConfigStatusSpec {
  bool ready = 1;
  bool torn_down = 2;
}

// VolumeConfigSpec is the spec for VolumeConfig resource.
message VolumeConfigSpec {
  string parent_id = 1;
  talos.resource.definitions.enums.BlockVolumeType type = 2;
  ProvisioningSpec provisioning = 3;
  LocatorSpec locator = 4;
  MountSpec mount = 5;
  EncryptionSpec encryption = 6;
  SymlinkProvisioningSpec symlink = 7;
}

// VolumeMountRequestSpec is the spec for VolumeMountRequest.
message VolumeMountRequestSpec {
  string volume_id = 1;
  string requester = 2;
  bool read_only = 3;
  bool detached = 4;
  bool disable_access_time = 5;
  bool secure = 6;
}

// VolumeMountStatusSpec is the spec for VolumeMountStatus.
message VolumeMountStatusSpec {
  string volume_id = 1;
  string requester = 2;
  string target = 3;
  bool read_only = 4;
  bool detached = 5;
  bool disable_access_time = 6;
  bool secure = 7;
}

// VolumeStatusSpec is the spec for VolumeStatus resource.
message VolumeStatusSpec {
  talos.resource.definitions.enums.BlockVolumePhase phase = 1;
  string location = 2;
  string error_message = 3;
  string uuid = 4;
  string partition_uuid = 5;
  talos.resource.definitions.enums.BlockVolumePhase pre_fail_phase = 6;
  string parent_location = 7;
  int64 partition_index = 8;
  uint64 size = 9;
  talos.resource.definitions.enums.BlockFilesystemType filesystem = 10;
  string mount_location = 11;
  talos.resource.definitions.enums.BlockEncryptionProviderType encryption_provider = 12;
  string pretty_size = 13;
  repeated string encryption_failed_syncs = 14;
  MountSpec mount_spec = 15;
  talos.resource.definitions.enums.BlockVolumeType type = 16;
  repeated string configured_encryption_keys = 17;
  SymlinkProvisioningSpec symlink_spec = 18;
  string parent_id = 19;
  bool encryption_locked_to_state = 20;
  int64 encryption_slot = 21;
  TPMEncryptionOptionsInfo tpm_encryption_options = 22;
}

// ZswapStatusSpec is the spec for ZswapStatus resource.
message ZswapStatusSpec {
  uint64 total_size_bytes = 1;
  string total_size_human = 2;
  uint64 stored_pages = 3;
  uint64 pool_limit_hit = 4;
  uint64 reject_reclaim_fail = 5;
  uint64 reject_alloc_fail = 6;
  uint64 reject_kmemcache_fail = 7;
  uint64 reject_compress_fail = 8;
  uint64 reject_compress_poor = 9;
  uint64 written_back_pages = 10;
}

