Skip to content

Commit f2c4b12

Browse files
authored
Remove unused async (#943)
This PR enables the `clippy::unused_async` lint, then fixes everything it complains about. There should be no performance or correctness change, because the functions being edited here – by definition – do not contain a yield point. There's also a drive-by change of adding `#[derive(Clone)]` to `ExtentInfo`, since it's POD and this removes some boilerplate.
1 parent df7a2f4 commit f2c4b12

File tree

11 files changed

+129
-187
lines changed

11 files changed

+129
-187
lines changed

.cargo/config.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[build]
2+
# Workaround to enable this lint for all packages in the workspace
3+
#
4+
# Once https://github.com/rust-lang/cargo/issues/12115 makes it to our
5+
# toolchain, we'll be able to put this in the `Cargo.toml` manifest instead.
6+
rustflags = ["-Wclippy::unused-async"]

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,4 +124,3 @@ repair-client = { path = "./repair-client" }
124124

125125
[profile.dev]
126126
panic = 'abort'
127-

downstairs/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1981,7 +1981,7 @@ impl Downstairs {
19811981
) -> Result<Option<Message>> {
19821982
let job = {
19831983
let mut work = self.work_lock(upstairs_connection).await?;
1984-
let job = work.get_ready_job(job_id).await;
1984+
let job = work.get_ready_job(job_id);
19851985

19861986
// `promote_to_active` can clear out the Work struct for this
19871987
// UpstairsConnection, but the tasks can still be working on
@@ -2913,7 +2913,7 @@ impl Work {
29132913
}
29142914

29152915
// Return a job that's ready to have the work done
2916-
async fn get_ready_job(&mut self, job_id: JobId) -> Option<DownstairsWork> {
2916+
fn get_ready_job(&mut self, job_id: JobId) -> Option<DownstairsWork> {
29172917
match self.active.get(&job_id) {
29182918
Some(job) => {
29192919
assert_eq!(job.state, WorkState::InProgress);

downstairs/src/repair.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ async fn get_files_for_extent(
211211
format!("Expected {:?} to be a directory", extent_dir),
212212
))
213213
} else {
214-
let files = extent_file_list(extent_dir, eid).await?;
214+
let files = extent_file_list(extent_dir, eid)?;
215215
Ok(HttpResponseOk(files))
216216
}
217217
}
@@ -221,7 +221,7 @@ async fn get_files_for_extent(
221221
* that correspond to the given extent. Return an error if any
222222
* of the required files are missing.
223223
*/
224-
async fn extent_file_list(
224+
fn extent_file_list(
225225
extent_dir: PathBuf,
226226
eid: u32,
227227
) -> Result<Vec<String>, HttpError> {
@@ -281,7 +281,7 @@ mod test {
281281

282282
// Determine the directory and name for expected extent files.
283283
let ed = extent_dir(&dir, 1);
284-
let mut ex_files = extent_file_list(ed, 1).await.unwrap();
284+
let mut ex_files = extent_file_list(ed, 1).unwrap();
285285
ex_files.sort();
286286
let expected = vec!["001", "001.db", "001.db-shm", "001.db-wal"];
287287
println!("files: {:?}", ex_files);
@@ -311,7 +311,7 @@ mod test {
311311
rm_file.set_extension("db-shm");
312312
std::fs::remove_file(rm_file).unwrap();
313313

314-
let mut ex_files = extent_file_list(extent_dir, 1).await.unwrap();
314+
let mut ex_files = extent_file_list(extent_dir, 1).unwrap();
315315
ex_files.sort();
316316
let expected = vec!["001", "001.db"];
317317
println!("files: {:?}", ex_files);
@@ -346,7 +346,7 @@ mod test {
346346
rm_file.set_extension("db-shm");
347347
let _ = std::fs::remove_file(rm_file);
348348

349-
let mut ex_files = extent_file_list(extent_dir, 1).await.unwrap();
349+
let mut ex_files = extent_file_list(extent_dir, 1).unwrap();
350350
ex_files.sort();
351351
let expected = vec!["001", "001.db"];
352352
println!("files: {:?}", ex_files);
@@ -373,7 +373,7 @@ mod test {
373373
rm_file.set_extension("db");
374374
std::fs::remove_file(&rm_file).unwrap();
375375

376-
assert!(extent_file_list(extent_dir, 2).await.is_err());
376+
assert!(extent_file_list(extent_dir, 2).is_err());
377377

378378
Ok(())
379379
}
@@ -395,7 +395,7 @@ mod test {
395395
rm_file.push(extent_file_name(1, ExtentType::Data));
396396
std::fs::remove_file(&rm_file).unwrap();
397397

398-
assert!(extent_file_list(extent_dir, 1).await.is_err());
398+
assert!(extent_file_list(extent_dir, 1).is_err());
399399

400400
Ok(())
401401
}

integration_tests/src/lib.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3395,13 +3395,12 @@ mod test {
33953395

33963396
// Start a new pantry
33973397

3398-
let (log, pantry) = crucible_pantry::initialize_pantry().await.unwrap();
3398+
let (log, pantry) = crucible_pantry::initialize_pantry().unwrap();
33993399
let (pantry_addr, _join_handle) = crucible_pantry::server::run_server(
34003400
&log,
34013401
"127.0.0.1:0".parse().unwrap(),
34023402
&pantry,
34033403
)
3404-
.await
34053404
.unwrap();
34063405

34073406
// Create a Volume out of it, and attach a CruciblePantryClient
@@ -3929,13 +3928,12 @@ mod test {
39293928

39303929
// Start the pantry, then use it to scrub
39313930

3932-
let (log, pantry) = crucible_pantry::initialize_pantry().await.unwrap();
3931+
let (log, pantry) = crucible_pantry::initialize_pantry().unwrap();
39333932
let (pantry_addr, _join_handle) = crucible_pantry::server::run_server(
39343933
&log,
39353934
"127.0.0.1:0".parse().unwrap(),
39363935
&pantry,
39373936
)
3938-
.await
39393937
.unwrap();
39403938

39413939
let client =

pantry/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub const PROG: &str = "crucible-pantry";
1111
pub mod pantry;
1212
pub mod server;
1313

14-
pub async fn initialize_pantry() -> Result<(Logger, Arc<pantry::Pantry>)> {
14+
pub fn initialize_pantry() -> Result<(Logger, Arc<pantry::Pantry>)> {
1515
let log = ConfigLogging::File {
1616
level: ConfigLoggingLevel::Info,
1717
path: "/dev/stdout".into(),

pantry/src/main.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,9 @@ async fn main() -> Result<()> {
4545
write_openapi(&mut f)
4646
}
4747
Args::Run { listen } => {
48-
let (log, pantry) = initialize_pantry().await?;
48+
let (log, pantry) = initialize_pantry()?;
4949

50-
let (_, join_handle) =
51-
server::run_server(&log, listen, &pantry).await?;
50+
let (_, join_handle) = server::run_server(&log, listen, &pantry)?;
5251

5352
join_handle.await?.map_err(|e| anyhow!(e))
5453
}

pantry/src/server.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ pub fn make_api() -> Result<dropshot::ApiDescription<Arc<Pantry>>, String> {
349349
Ok(api)
350350
}
351351

352-
pub async fn run_server(
352+
pub fn run_server(
353353
log: &Logger,
354354
bind_address: SocketAddr,
355355
df: &Arc<Pantry>,

upstairs/src/lib.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3716,7 +3716,7 @@ impl Downstairs {
37163716
/**
37173717
* Enqueue a new downstairs live repair request.
37183718
*/
3719-
async fn enqueue_repair(&mut self, mut io: DownstairsIO) {
3719+
fn enqueue_repair(&mut self, mut io: DownstairsIO) {
37203720
// Puts the repair IO onto the downstairs work queue.
37213721
for cid in ClientId::iter() {
37223722
assert_eq!(io.state[cid], IOState::New);
@@ -5042,7 +5042,7 @@ impl UpstairsState {
50425042
* that happens on initial startup. This is because the running
50435043
* upstairs has some state it can use to re-verify a downstairs.
50445044
*/
5045-
async fn set_active(&mut self) -> Result<(), CrucibleError> {
5045+
fn set_active(&mut self) -> Result<(), CrucibleError> {
50465046
if self.up_state == UpState::Active {
50475047
crucible_bail!(UpstairsAlreadyActive);
50485048
} else if self.up_state == UpState::Deactivating {
@@ -5359,7 +5359,7 @@ impl Upstairs {
53595359
async fn set_active(&self) -> Result<(), CrucibleError> {
53605360
let mut active = self.active.lock().await;
53615361
self.stats.add_activation().await;
5362-
active.set_active().await?;
5362+
active.set_active()?;
53635363
info!(
53645364
self.log,
53655365
"{} is now active with session: {}", self.uuid, self.session_id
@@ -6614,7 +6614,7 @@ impl Upstairs {
66146614
* Verify the guest given gen number is highest.
66156615
* Decide if we need repair, and if so create the repair list
66166616
*/
6617-
async fn collate_downstairs(
6617+
fn collate_downstairs(
66186618
&self,
66196619
ds: &mut Downstairs,
66206620
) -> Result<bool, CrucibleError> {
@@ -6939,7 +6939,7 @@ impl Upstairs {
69396939
* downstairs out, forget any activation requests, and the
69406940
* upstairs goes back to waiting for another activation request.
69416941
*/
6942-
self.collate_downstairs(&mut ds).await
6942+
self.collate_downstairs(&mut ds)
69436943
};
69446944

69456945
match collate_status {
@@ -7048,7 +7048,7 @@ impl Upstairs {
70487048
for s in ds.ds_state.iter_mut() {
70497049
*s = DsState::Active;
70507050
}
7051-
active.set_active().await?;
7051+
active.set_active()?;
70527052
info!(
70537053
self.log,
70547054
"{} is now active with session: {}",
@@ -7084,7 +7084,7 @@ impl Upstairs {
70847084
for s in ds.ds_state.iter_mut() {
70857085
*s = DsState::Active;
70867086
}
7087-
active.set_active().await?;
7087+
active.set_active()?;
70887088
info!(
70897089
self.log,
70907090
"{} is now active with session: {}",
@@ -8822,7 +8822,7 @@ impl GtoS {
88228822
/*
88238823
* Notify corresponding BlockReqWaiter
88248824
*/
8825-
pub async fn notify(self, result: Result<(), CrucibleError>) {
8825+
pub fn notify(self, result: Result<(), CrucibleError>) {
88268826
/*
88278827
* If present, send the result to the guest. If this is a flush
88288828
* issued on behalf of crucible, then there is no place to send
@@ -8943,7 +8943,7 @@ impl GuestWork {
89438943
gtos_job.transfer().await;
89448944
}
89458945

8946-
gtos_job.notify(result).await;
8946+
gtos_job.notify(result);
89478947

89488948
self.completed.push(gw_id);
89498949
} else {
@@ -9503,7 +9503,7 @@ struct Condition {
95039503
* Send work to all the targets.
95049504
* If a send fails, report an error.
95059505
*/
9506-
async fn send_work(t: &[Target], val: u64, log: &Logger) {
9506+
fn send_work(t: &[Target], val: u64, log: &Logger) {
95079507
for (client_id, d_client) in t.iter().enumerate() {
95089508
let res = d_client.ds_work_tx.try_send(val);
95099509
if let Err(e) = res {
@@ -9754,7 +9754,7 @@ async fn process_new_io(
97549754
return;
97559755
}
97569756

9757-
send_work(dst, *lastcast, &up.log).await;
9757+
send_work(dst, *lastcast, &up.log);
97589758
*lastcast += 1;
97599759
}
97609760
BlockOp::Read { offset, data } => {
@@ -9765,7 +9765,7 @@ async fn process_new_io(
97659765
{
97669766
return;
97679767
}
9768-
send_work(dst, *lastcast, &up.log).await;
9768+
send_work(dst, *lastcast, &up.log);
97699769
*lastcast += 1;
97709770
}
97719771
BlockOp::Write { offset, data } => {
@@ -9776,7 +9776,7 @@ async fn process_new_io(
97769776
{
97779777
return;
97789778
}
9779-
send_work(dst, *lastcast, &up.log).await;
9779+
send_work(dst, *lastcast, &up.log);
97809780
*lastcast += 1;
97819781
}
97829782
BlockOp::WriteUnwritten { offset, data } => {
@@ -9787,7 +9787,7 @@ async fn process_new_io(
97879787
{
97889788
return;
97899789
}
9790-
send_work(dst, *lastcast, &up.log).await;
9790+
send_work(dst, *lastcast, &up.log);
97919791
*lastcast += 1;
97929792
}
97939793
BlockOp::Flush { snapshot_details } => {
@@ -9811,7 +9811,7 @@ async fn process_new_io(
98119811
return;
98129812
}
98139813

9814-
send_work(dst, *lastcast, &up.log).await;
9814+
send_work(dst, *lastcast, &up.log);
98159815
*lastcast += 1;
98169816
}
98179817
BlockOp::RepairOp => {
@@ -9915,7 +9915,7 @@ async fn process_new_io(
99159915
req.send_err(CrucibleError::UpstairsInactive);
99169916
return;
99179917
}
9918-
send_work(dst, *lastcast, &up.log).await;
9918+
send_work(dst, *lastcast, &up.log);
99199919
*lastcast += 1;
99209920
}
99219921
}
@@ -10133,7 +10133,7 @@ async fn up_listen(
1013310133
error!(up.log, "flush send failed:{:?}", e);
1013410134
// XXX What to do here?
1013510135
} else {
10136-
send_work(&dst, 1, &up.log).await;
10136+
send_work(&dst, 1, &up.log);
1013710137
}
1013810138
}
1013910139

0 commit comments

Comments
 (0)