@@ -14,9 +14,6 @@ use fn_error_context::context;
14
14
use regex:: Regex ;
15
15
use serde:: Deserialize ;
16
16
17
- #[ cfg( feature = "install-to-disk" ) ]
18
- use crate :: install:: run_in_host_mountns;
19
- use crate :: task:: Task ;
20
17
use bootc_utils:: CommandRunExt ;
21
18
22
19
#[ derive( Debug , Deserialize ) ]
@@ -91,16 +88,6 @@ impl Device {
91
88
}
92
89
}
93
90
94
- #[ context( "Failed to wipe {dev}" ) ]
95
- #[ cfg( feature = "install-to-disk" ) ]
96
- pub ( crate ) fn wipefs ( dev : & Utf8Path ) -> Result < ( ) > {
97
- Task :: new_and_run (
98
- format ! ( "Wiping device {dev}" ) ,
99
- "wipefs" ,
100
- [ "-a" , dev. as_str ( ) ] ,
101
- )
102
- }
103
-
104
91
#[ context( "Listing device {dev}" ) ]
105
92
pub ( crate ) fn list_dev ( dev : & Utf8Path ) -> Result < Device > {
106
93
let mut devs: DevicesOutput = Command :: new ( "lsblk" )
@@ -187,10 +174,9 @@ impl Partition {
187
174
188
175
#[ context( "Listing partitions of {dev}" ) ]
189
176
pub ( crate ) fn partitions_of ( dev : & Utf8Path ) -> Result < PartitionTable > {
190
- let o = Task :: new_quiet ( "sfdisk" )
177
+ let o: SfDiskOutput = Command :: new ( "sfdisk" )
191
178
. args ( [ "-J" , dev. as_str ( ) ] )
192
- . read ( ) ?;
193
- let o: SfDiskOutput = serde_json:: from_str ( & o) . context ( "Parsing sfdisk output" ) ?;
179
+ . run_and_parse_json ( ) ?;
194
180
Ok ( o. partitiontable )
195
181
}
196
182
@@ -214,16 +200,15 @@ impl LoopbackDevice {
214
200
Err ( _e) => "off" ,
215
201
} ;
216
202
217
- let dev = Task :: new ( "losetup" , "losetup" )
203
+ let dev = Command :: new ( "losetup" )
218
204
. args ( [
219
205
"--show" ,
220
206
format ! ( "--direct-io={direct_io}" ) . as_str ( ) ,
221
207
"-P" ,
222
208
"--find" ,
223
209
] )
224
210
. arg ( path)
225
- . quiet ( )
226
- . read ( ) ?;
211
+ . run_get_string ( ) ?;
227
212
let dev = Utf8PathBuf :: from ( dev. trim ( ) ) ;
228
213
tracing:: debug!( "Allocated loopback {dev}" ) ;
229
214
Ok ( Self { dev : Some ( dev) } )
@@ -242,10 +227,7 @@ impl LoopbackDevice {
242
227
tracing:: trace!( "loopback device already deallocated" ) ;
243
228
return Ok ( ( ) ) ;
244
229
} ;
245
- Task :: new ( "losetup" , "losetup" )
246
- . args ( [ "-d" , dev. as_str ( ) ] )
247
- . quiet ( )
248
- . run ( )
230
+ Command :: new ( "losetup" ) . args ( [ "-d" , dev. as_str ( ) ] ) . run ( )
249
231
}
250
232
251
233
/// Consume this device, unmounting it.
@@ -262,21 +244,6 @@ impl Drop for LoopbackDevice {
262
244
}
263
245
}
264
246
265
- #[ cfg( feature = "install-to-disk" ) ]
266
- pub ( crate ) fn udev_settle ( ) -> Result < ( ) > {
267
- // There's a potential window after rereading the partition table where
268
- // udevd hasn't yet received updates from the kernel, settle will return
269
- // immediately, and lsblk won't pick up partition labels. Try to sleep
270
- // our way out of this.
271
- std:: thread:: sleep ( std:: time:: Duration :: from_millis ( 200 ) ) ;
272
-
273
- let st = run_in_host_mountns ( "udevadm" ) . arg ( "settle" ) . status ( ) ?;
274
- if !st. success ( ) {
275
- anyhow:: bail!( "Failed to run udevadm settle: {st:?}" ) ;
276
- }
277
- Ok ( ( ) )
278
- }
279
-
280
247
/// Parse key-value pairs from lsblk --pairs.
281
248
/// Newer versions of lsblk support JSON but the one in CentOS 7 doesn't.
282
249
fn split_lsblk_line ( line : & str ) -> HashMap < String , String > {
@@ -293,15 +260,15 @@ fn split_lsblk_line(line: &str) -> HashMap<String, String> {
293
260
/// hierarchy of `device` capable of containing other partitions. So e.g. parent devices of type
294
261
/// "part" doesn't match, but "disk" and "mpath" does.
295
262
pub ( crate ) fn find_parent_devices ( device : & str ) -> Result < Vec < String > > {
296
- let output = Task :: new_quiet ( "lsblk" )
263
+ let output = Command :: new ( "lsblk" )
297
264
// Older lsblk, e.g. in CentOS 7.6, doesn't support PATH, but --paths option
298
265
. arg ( "--pairs" )
299
266
. arg ( "--paths" )
300
267
. arg ( "--inverse" )
301
268
. arg ( "--output" )
302
269
. arg ( "NAME,TYPE" )
303
270
. arg ( device)
304
- . read ( ) ?;
271
+ . run_get_string ( ) ?;
305
272
let mut parents = Vec :: new ( ) ;
306
273
// skip first line, which is the device itself
307
274
for line in output. lines ( ) . skip ( 1 ) {
0 commit comments