Skip to content

Commit

Permalink
Merge pull request #2359 from subspace/fix-farm-info-locking
Browse files Browse the repository at this point in the history
Fix farm info locking
  • Loading branch information
nazar-pc authored Dec 20, 2023
2 parents 4972daf + e3daa7c commit 65317f4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
13 changes: 11 additions & 2 deletions crates/subspace-farmer/src/bin/subspace-farmer/commands/farm.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
mod dsn;

use crate::commands::farm::dsn::configure_dsn;
use crate::commands::shared::print_disk_farm_info;
use crate::utils::shutdown_signal;
use anyhow::anyhow;
use bytesize::ByteSize;
Expand Down Expand Up @@ -493,7 +492,17 @@ where
};

if !no_info {
print_disk_farm_info(disk_farm.directory, disk_farm_index);
let info = single_disk_farm.info();
println!("Single disk farm {disk_farm_index}:");
println!(" ID: {}", info.id());
println!(" Genesis hash: 0x{}", hex::encode(info.genesis_hash()));
println!(" Public key: 0x{}", hex::encode(info.public_key()));
println!(
" Allocated space: {} ({})",
bytesize::to_string(info.allocated_space(), true),
bytesize::to_string(info.allocated_space(), false)
);
println!(" Directory: {}", disk_farm.directory.display());
}

single_disk_farms.push(single_disk_farm);
Expand Down
20 changes: 8 additions & 12 deletions crates/subspace-farmer/src/single_disk_farm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,7 @@ impl SingleDiskFarmId {
/// Exclusive lock for single disk farm info file, ensuring no concurrent edits by cooperating processes is done
#[must_use = "Lock file must be kept around or as long as farm is used"]
pub struct SingleDiskFarmInfoLock {
file: File,
}

impl Drop for SingleDiskFarmInfoLock {
fn drop(&mut self) {
use fs4::FileExt;

if let Err(error) = self.file.unlock() {
error!(%error, "Failed to unlock single disk farm lock");
}
}
_file: File,
}

/// Important information about the contents of the `SingleDiskFarm`
Expand Down Expand Up @@ -184,7 +174,7 @@ impl SingleDiskFarmInfo {
let file = File::open(directory.join(Self::FILE_NAME))?;
fs4::FileExt::try_lock_exclusive(&file)?;

Ok(SingleDiskFarmInfoLock { file })
Ok(SingleDiskFarmInfoLock { _file: file })
}

// ID of the farm
Expand Down Expand Up @@ -223,6 +213,7 @@ impl SingleDiskFarmInfo {
}

/// Summary of single disk farm for presentational purposes
#[derive(Debug)]
pub enum SingleDiskFarmSummary {
/// Farm was found and read successfully
Found {
Expand Down Expand Up @@ -1312,6 +1303,11 @@ impl SingleDiskFarm {
self.single_disk_farm_info.id()
}

/// Info of this farm
pub fn info(&self) -> &SingleDiskFarmInfo {
&self.single_disk_farm_info
}

/// Number of sectors in this farm
pub fn total_sectors_count(&self) -> SectorIndex {
self.total_sectors_count
Expand Down

0 comments on commit 65317f4

Please sign in to comment.