@@ -6,8 +6,8 @@ use std::fs::File;
66use std:: io:: { Read , Write } ;
77use std:: path:: PathBuf ;
88
9- use crate :: error:: * ;
109use crate :: error:: ErrorKind :: * ;
10+ use crate :: error:: * ;
1111
1212use crate :: {
1313 BlkIoResources , ControllIdentifier , ControllerInternal , Controllers , Resources , Subsystem ,
@@ -279,7 +279,8 @@ impl ControllerInternal for BlkIoController {
279279
280280 for dev in & res. weight_device {
281281 let _ = self . set_weight_for_device ( dev. major , dev. minor , dev. weight as u64 ) ;
282- let _ = self . set_leaf_weight_for_device ( dev. major , dev. minor , dev. leaf_weight as u64 ) ;
282+ let _ =
283+ self . set_leaf_weight_for_device ( dev. major , dev. minor , dev. leaf_weight as u64 ) ;
283284 }
284285
285286 for dev in & res. throttle_read_bps_device {
@@ -309,19 +310,7 @@ impl ControllIdentifier for BlkIoController {
309310 }
310311}
311312
312- impl < ' a > From < & ' a Subsystem > for & ' a BlkIoController {
313- fn from ( sub : & ' a Subsystem ) -> & ' a BlkIoController {
314- unsafe {
315- match sub {
316- Subsystem :: BlkIo ( c) => c,
317- _ => {
318- assert_eq ! ( 1 , 0 ) ;
319- :: std:: mem:: uninitialized ( )
320- }
321- }
322- }
323- }
324- }
313+ impl_from_subsystem_for_controller ! ( Subsystem :: BlkIo , BlkIoController ) ;
325314
326315fn read_string_from ( mut file : File ) -> Result < String > {
327316 let mut string = String :: new ( ) ;
@@ -334,7 +323,10 @@ fn read_string_from(mut file: File) -> Result<String> {
334323fn read_u64_from ( mut file : File ) -> Result < u64 > {
335324 let mut string = String :: new ( ) ;
336325 match file. read_to_string ( & mut string) {
337- Ok ( _) => string. trim ( ) . parse ( ) . map_err ( |e| Error :: with_cause ( ParseError , e) ) ,
326+ Ok ( _) => string
327+ . trim ( )
328+ . parse ( )
329+ . map_err ( |e| Error :: with_cause ( ParseError , e) ) ,
338330 Err ( e) => Err ( Error :: with_cause ( ReadFailed , e) ) ,
339331 }
340332}
@@ -588,12 +580,7 @@ impl BlkIoController {
588580 }
589581
590582 /// Same as `set_leaf_weight()`, but settable per each block device.
591- pub fn set_leaf_weight_for_device (
592- & self ,
593- major : u64 ,
594- minor : u64 ,
595- weight : u64 ,
596- ) -> Result < ( ) > {
583+ pub fn set_leaf_weight_for_device ( & self , major : u64 , minor : u64 , weight : u64 ) -> Result < ( ) > {
597584 self . open_path ( "blkio.leaf_weight_device" , true )
598585 . and_then ( |mut file| {
599586 file. write_all ( format ! ( "{}:{} {}" , major, minor, weight) . as_ref ( ) )
@@ -612,12 +599,7 @@ impl BlkIoController {
612599
613600 /// Throttle the bytes per second rate of read operation affecting the block device
614601 /// `major:minor` to `bps`.
615- pub fn throttle_read_bps_for_device (
616- & self ,
617- major : u64 ,
618- minor : u64 ,
619- bps : u64 ,
620- ) -> Result < ( ) > {
602+ pub fn throttle_read_bps_for_device ( & self , major : u64 , minor : u64 , bps : u64 ) -> Result < ( ) > {
621603 self . open_path ( "blkio.throttle.read_bps_device" , true )
622604 . and_then ( |mut file| {
623605 file. write_all ( format ! ( "{}:{} {}" , major, minor, bps) . to_string ( ) . as_ref ( ) )
@@ -627,12 +609,7 @@ impl BlkIoController {
627609
628610 /// Throttle the I/O operations per second rate of read operation affecting the block device
629611 /// `major:minor` to `bps`.
630- pub fn throttle_read_iops_for_device (
631- & self ,
632- major : u64 ,
633- minor : u64 ,
634- iops : u64 ,
635- ) -> Result < ( ) > {
612+ pub fn throttle_read_iops_for_device ( & self , major : u64 , minor : u64 , iops : u64 ) -> Result < ( ) > {
636613 self . open_path ( "blkio.throttle.read_iops_device" , true )
637614 . and_then ( |mut file| {
638615 file. write_all ( format ! ( "{}:{} {}" , major, minor, iops) . to_string ( ) . as_ref ( ) )
@@ -641,12 +618,7 @@ impl BlkIoController {
641618 }
642619 /// Throttle the bytes per second rate of write operation affecting the block device
643620 /// `major:minor` to `bps`.
644- pub fn throttle_write_bps_for_device (
645- & self ,
646- major : u64 ,
647- minor : u64 ,
648- bps : u64 ,
649- ) -> Result < ( ) > {
621+ pub fn throttle_write_bps_for_device ( & self , major : u64 , minor : u64 , bps : u64 ) -> Result < ( ) > {
650622 self . open_path ( "blkio.throttle.write_bps_device" , true )
651623 . and_then ( |mut file| {
652624 file. write_all ( format ! ( "{}:{} {}" , major, minor, bps) . to_string ( ) . as_ref ( ) )
@@ -656,12 +628,7 @@ impl BlkIoController {
656628
657629 /// Throttle the I/O operations per second rate of write operation affecting the block device
658630 /// `major:minor` to `bps`.
659- pub fn throttle_write_iops_for_device (
660- & self ,
661- major : u64 ,
662- minor : u64 ,
663- iops : u64 ,
664- ) -> Result < ( ) > {
631+ pub fn throttle_write_iops_for_device ( & self , major : u64 , minor : u64 , iops : u64 ) -> Result < ( ) > {
665632 self . open_path ( "blkio.throttle.write_iops_device" , true )
666633 . and_then ( |mut file| {
667634 file. write_all ( format ! ( "{}:{} {}" , major, minor, iops) . to_string ( ) . as_ref ( ) )
@@ -671,20 +638,14 @@ impl BlkIoController {
671638
672639 /// Set the weight of the control group's tasks.
673640 pub fn set_weight ( & self , w : u64 ) -> Result < ( ) > {
674- self . open_path ( "blkio.weight" , true )
675- . and_then ( |mut file| {
676- file. write_all ( w. to_string ( ) . as_ref ( ) )
677- . map_err ( |e| Error :: with_cause ( WriteFailed , e) )
678- } )
641+ self . open_path ( "blkio.weight" , true ) . and_then ( |mut file| {
642+ file. write_all ( w. to_string ( ) . as_ref ( ) )
643+ . map_err ( |e| Error :: with_cause ( WriteFailed , e) )
644+ } )
679645 }
680646
681647 /// Same as `set_weight()`, but settable per each block device.
682- pub fn set_weight_for_device (
683- & self ,
684- major : u64 ,
685- minor : u64 ,
686- weight : u64 ,
687- ) -> Result < ( ) > {
648+ pub fn set_weight_for_device ( & self , major : u64 , minor : u64 , weight : u64 ) -> Result < ( ) > {
688649 self . open_path ( "blkio.weight_device" , true )
689650 . and_then ( |mut file| {
690651 file. write_all ( format ! ( "{}:{} {}" , major, minor, weight) . as_ref ( ) )
@@ -755,10 +716,7 @@ Total 61823067136
755716 #[ test]
756717 fn test_parse_io_service_total ( ) {
757718 let ok = parse_io_service_total ( TEST_VALUE . to_string ( ) ) . unwrap ( ) ;
758- assert_eq ! (
759- ok,
760- 61823067136
761- ) ;
719+ assert_eq ! ( ok, 61823067136 ) ;
762720 }
763721
764722 #[ test]
@@ -806,10 +764,7 @@ Total 61823067136
806764 ]
807765 ) ;
808766 let err = parse_io_service ( TEST_WRONG_VALUE . to_string ( ) ) . unwrap_err ( ) ;
809- assert_eq ! (
810- err. kind( ) ,
811- & ErrorKind :: ParseError ,
812- ) ;
767+ assert_eq ! ( err. kind( ) , & ErrorKind :: ParseError , ) ;
813768 }
814769
815770 #[ test]
0 commit comments