feat: add readonly information to the disks API response
Forward device readonly info from `go-blockdevice` library. Signed-off-by: Artem Chernyshev <artem.chernyshev@talos-systems.com>
This commit is contained in:
parent
735bf9ed08
commit
2960f93baa
@ -45,6 +45,8 @@ message Disk {
|
||||
bool system_disk = 11;
|
||||
// Subsystem is the symlink path in the `/sys/block/<dev>/subsystem`.
|
||||
string subsystem = 12;
|
||||
// Readonly specifies if the disk is read only.
|
||||
bool readonly = 13;
|
||||
}
|
||||
|
||||
// DisksResponse represents the response of the `Disks` RPC.
|
||||
|
@ -62,6 +62,7 @@ func printDisks(ctx context.Context, c *client.Client) error {
|
||||
"SIZE",
|
||||
"BUS_PATH",
|
||||
"SUBSYSTEM",
|
||||
"READ_ONLY",
|
||||
"SYSTEM_DISK",
|
||||
}, "\t")
|
||||
|
||||
@ -97,6 +98,12 @@ func printDisks(ctx context.Context, c *client.Client) error {
|
||||
args = append(args, node)
|
||||
}
|
||||
|
||||
isReadonly := ""
|
||||
|
||||
if disk.Readonly {
|
||||
isReadonly = "*"
|
||||
}
|
||||
|
||||
isSystemDisk := ""
|
||||
|
||||
if disk.SystemDisk {
|
||||
@ -115,6 +122,7 @@ func printDisks(ctx context.Context, c *client.Client) error {
|
||||
humanize.Bytes(disk.Size),
|
||||
getWithPlaceholder(disk.BusPath),
|
||||
getWithPlaceholder(disk.Subsystem),
|
||||
isReadonly,
|
||||
isSystemDisk,
|
||||
}...)
|
||||
|
||||
|
@ -44,6 +44,7 @@ func (s *Server) Disks(ctx context.Context, in *emptypb.Empty) (reply *storage.D
|
||||
BusPath: d.BusPath,
|
||||
SystemDisk: systemDisk != nil && d.DeviceName == systemDisk.Device().Name(),
|
||||
Subsystem: d.SubSystem,
|
||||
Readonly: d.ReadOnly,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -109,6 +109,8 @@ type Disk struct {
|
||||
SystemDisk bool `protobuf:"varint,11,opt,name=system_disk,json=systemDisk,proto3" json:"system_disk,omitempty"`
|
||||
// Subsystem is the symlink path in the `/sys/block/<dev>/subsystem`.
|
||||
Subsystem string `protobuf:"bytes,12,opt,name=subsystem,proto3" json:"subsystem,omitempty"`
|
||||
// Readonly specifies if the disk is read only.
|
||||
Readonly bool `protobuf:"varint,13,opt,name=readonly,proto3" json:"readonly,omitempty"`
|
||||
}
|
||||
|
||||
func (x *Disk) Reset() {
|
||||
@ -227,6 +229,13 @@ func (x *Disk) GetSubsystem() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *Disk) GetReadonly() bool {
|
||||
if x != nil {
|
||||
return x.Readonly
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// DisksResponse represents the response of the `Disks` RPC.
|
||||
type Disks struct {
|
||||
state protoimpl.MessageState
|
||||
@ -338,7 +347,7 @@ var file_storage_storage_proto_rawDesc = []byte{
|
||||
0x1a, 0x13, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2f, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2e,
|
||||
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1b, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72,
|
||||
0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x65, 0x6d, 0x70, 0x74, 0x79, 0x2e, 0x70, 0x72, 0x6f,
|
||||
0x74, 0x6f, 0x22, 0x84, 0x03, 0x0a, 0x04, 0x44, 0x69, 0x73, 0x6b, 0x12, 0x12, 0x0a, 0x04, 0x73,
|
||||
0x74, 0x6f, 0x22, 0xa0, 0x03, 0x0a, 0x04, 0x44, 0x69, 0x73, 0x6b, 0x12, 0x12, 0x0a, 0x04, 0x73,
|
||||
0x69, 0x7a, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, 0x52, 0x04, 0x73, 0x69, 0x7a, 0x65, 0x12,
|
||||
0x14, 0x0a, 0x05, 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05,
|
||||
0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x12, 0x1f, 0x0a, 0x0b, 0x64, 0x65, 0x76, 0x69, 0x63, 0x65, 0x5f,
|
||||
@ -358,29 +367,31 @@ var file_storage_storage_proto_rawDesc = []byte{
|
||||
0x0b, 0x73, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x5f, 0x64, 0x69, 0x73, 0x6b, 0x18, 0x0b, 0x20, 0x01,
|
||||
0x28, 0x08, 0x52, 0x0a, 0x73, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x44, 0x69, 0x73, 0x6b, 0x12, 0x1c,
|
||||
0x0a, 0x09, 0x73, 0x75, 0x62, 0x73, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x18, 0x0c, 0x20, 0x01, 0x28,
|
||||
0x09, 0x52, 0x09, 0x73, 0x75, 0x62, 0x73, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x22, 0x3b, 0x0a, 0x08,
|
||||
0x44, 0x69, 0x73, 0x6b, 0x54, 0x79, 0x70, 0x65, 0x12, 0x0b, 0x0a, 0x07, 0x55, 0x4e, 0x4b, 0x4e,
|
||||
0x4f, 0x57, 0x4e, 0x10, 0x00, 0x12, 0x07, 0x0a, 0x03, 0x53, 0x53, 0x44, 0x10, 0x01, 0x12, 0x07,
|
||||
0x0a, 0x03, 0x48, 0x44, 0x44, 0x10, 0x02, 0x12, 0x08, 0x0a, 0x04, 0x4e, 0x56, 0x4d, 0x45, 0x10,
|
||||
0x03, 0x12, 0x06, 0x0a, 0x02, 0x53, 0x44, 0x10, 0x04, 0x22, 0x5a, 0x0a, 0x05, 0x44, 0x69, 0x73,
|
||||
0x6b, 0x73, 0x12, 0x2c, 0x0a, 0x08, 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x18, 0x01,
|
||||
0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2e, 0x4d, 0x65,
|
||||
0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x52, 0x08, 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61,
|
||||
0x12, 0x23, 0x0a, 0x05, 0x64, 0x69, 0x73, 0x6b, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32,
|
||||
0x0d, 0x2e, 0x73, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x2e, 0x44, 0x69, 0x73, 0x6b, 0x52, 0x05,
|
||||
0x64, 0x69, 0x73, 0x6b, 0x73, 0x22, 0x3b, 0x0a, 0x0d, 0x44, 0x69, 0x73, 0x6b, 0x73, 0x52, 0x65,
|
||||
0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x2a, 0x0a, 0x08, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67,
|
||||
0x65, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x73, 0x74, 0x6f, 0x72, 0x61,
|
||||
0x67, 0x65, 0x2e, 0x44, 0x69, 0x73, 0x6b, 0x73, 0x52, 0x08, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67,
|
||||
0x65, 0x73, 0x32, 0x49, 0x0a, 0x0e, 0x53, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x53, 0x65, 0x72,
|
||||
0x76, 0x69, 0x63, 0x65, 0x12, 0x37, 0x0a, 0x05, 0x44, 0x69, 0x73, 0x6b, 0x73, 0x12, 0x16, 0x2e,
|
||||
0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e,
|
||||
0x45, 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x16, 0x2e, 0x73, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x2e,
|
||||
0x44, 0x69, 0x73, 0x6b, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x37, 0x5a,
|
||||
0x35, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x73, 0x69, 0x64, 0x65,
|
||||
0x72, 0x6f, 0x6c, 0x61, 0x62, 0x73, 0x2f, 0x74, 0x61, 0x6c, 0x6f, 0x73, 0x2f, 0x70, 0x6b, 0x67,
|
||||
0x2f, 0x6d, 0x61, 0x63, 0x68, 0x69, 0x6e, 0x65, 0x72, 0x79, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x73,
|
||||
0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||
0x09, 0x52, 0x09, 0x73, 0x75, 0x62, 0x73, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x12, 0x1a, 0x0a, 0x08,
|
||||
0x72, 0x65, 0x61, 0x64, 0x6f, 0x6e, 0x6c, 0x79, 0x18, 0x0d, 0x20, 0x01, 0x28, 0x08, 0x52, 0x08,
|
||||
0x72, 0x65, 0x61, 0x64, 0x6f, 0x6e, 0x6c, 0x79, 0x22, 0x3b, 0x0a, 0x08, 0x44, 0x69, 0x73, 0x6b,
|
||||
0x54, 0x79, 0x70, 0x65, 0x12, 0x0b, 0x0a, 0x07, 0x55, 0x4e, 0x4b, 0x4e, 0x4f, 0x57, 0x4e, 0x10,
|
||||
0x00, 0x12, 0x07, 0x0a, 0x03, 0x53, 0x53, 0x44, 0x10, 0x01, 0x12, 0x07, 0x0a, 0x03, 0x48, 0x44,
|
||||
0x44, 0x10, 0x02, 0x12, 0x08, 0x0a, 0x04, 0x4e, 0x56, 0x4d, 0x45, 0x10, 0x03, 0x12, 0x06, 0x0a,
|
||||
0x02, 0x53, 0x44, 0x10, 0x04, 0x22, 0x5a, 0x0a, 0x05, 0x44, 0x69, 0x73, 0x6b, 0x73, 0x12, 0x2c,
|
||||
0x0a, 0x08, 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b,
|
||||
0x32, 0x10, 0x2e, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2e, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61,
|
||||
0x74, 0x61, 0x52, 0x08, 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x12, 0x23, 0x0a, 0x05,
|
||||
0x64, 0x69, 0x73, 0x6b, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0d, 0x2e, 0x73, 0x74,
|
||||
0x6f, 0x72, 0x61, 0x67, 0x65, 0x2e, 0x44, 0x69, 0x73, 0x6b, 0x52, 0x05, 0x64, 0x69, 0x73, 0x6b,
|
||||
0x73, 0x22, 0x3b, 0x0a, 0x0d, 0x44, 0x69, 0x73, 0x6b, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e,
|
||||
0x73, 0x65, 0x12, 0x2a, 0x0a, 0x08, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x73, 0x18, 0x01,
|
||||
0x20, 0x03, 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x73, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x2e, 0x44,
|
||||
0x69, 0x73, 0x6b, 0x73, 0x52, 0x08, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x73, 0x32, 0x49,
|
||||
0x0a, 0x0e, 0x53, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65,
|
||||
0x12, 0x37, 0x0a, 0x05, 0x44, 0x69, 0x73, 0x6b, 0x73, 0x12, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67,
|
||||
0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74,
|
||||
0x79, 0x1a, 0x16, 0x2e, 0x73, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x2e, 0x44, 0x69, 0x73, 0x6b,
|
||||
0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x37, 0x5a, 0x35, 0x67, 0x69, 0x74,
|
||||
0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x73, 0x69, 0x64, 0x65, 0x72, 0x6f, 0x6c, 0x61,
|
||||
0x62, 0x73, 0x2f, 0x74, 0x61, 0x6c, 0x6f, 0x73, 0x2f, 0x70, 0x6b, 0x67, 0x2f, 0x6d, 0x61, 0x63,
|
||||
0x68, 0x69, 0x6e, 0x65, 0x72, 0x79, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x73, 0x74, 0x6f, 0x72, 0x61,
|
||||
0x67, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||
}
|
||||
|
||||
var (
|
||||
|
@ -52,6 +52,16 @@ func (m *Disk) MarshalToSizedBufferVT(dAtA []byte) (int, error) {
|
||||
i -= len(m.unknownFields)
|
||||
copy(dAtA[i:], m.unknownFields)
|
||||
}
|
||||
if m.Readonly {
|
||||
i--
|
||||
if m.Readonly {
|
||||
dAtA[i] = 1
|
||||
} else {
|
||||
dAtA[i] = 0
|
||||
}
|
||||
i--
|
||||
dAtA[i] = 0x68
|
||||
}
|
||||
if len(m.Subsystem) > 0 {
|
||||
i -= len(m.Subsystem)
|
||||
copy(dAtA[i:], m.Subsystem)
|
||||
@ -312,6 +322,9 @@ func (m *Disk) SizeVT() (n int) {
|
||||
if l > 0 {
|
||||
n += 1 + l + sov(uint64(l))
|
||||
}
|
||||
if m.Readonly {
|
||||
n += 2
|
||||
}
|
||||
n += len(m.unknownFields)
|
||||
return n
|
||||
}
|
||||
@ -739,6 +752,26 @@ func (m *Disk) UnmarshalVT(dAtA []byte) error {
|
||||
}
|
||||
m.Subsystem = string(dAtA[iNdEx:postIndex])
|
||||
iNdEx = postIndex
|
||||
case 13:
|
||||
if wireType != 0 {
|
||||
return fmt.Errorf("proto: wrong wireType = %d for field Readonly", wireType)
|
||||
}
|
||||
var v int
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return ErrIntOverflow
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
v |= int(b&0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
m.Readonly = bool(v != 0)
|
||||
default:
|
||||
iNdEx = preIndex
|
||||
skippy, err := skip(dAtA[iNdEx:])
|
||||
|
@ -7357,6 +7357,7 @@ Disk represents a disk.
|
||||
| bus_path | [string](#string) | | BusPath is the bus path of the disk. |
|
||||
| system_disk | [bool](#bool) | | SystemDisk indicates that the disk is used as Talos system disk. |
|
||||
| subsystem | [string](#string) | | Subsystem is the symlink path in the `/sys/block/<dev>/subsystem`. |
|
||||
| readonly | [bool](#bool) | | Readonly specifies if the disk is read only. |
|
||||
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user