Skip to content

Commit

Permalink
zfs
Browse files Browse the repository at this point in the history
  • Loading branch information
tedsta committed Jan 4, 2016
1 parent 9b570f1 commit d65f42d
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 131 deletions.
91 changes: 0 additions & 91 deletions filesystem/apps/zfs/block_ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,97 +36,6 @@ impl BlockPtr {
pub fn psize(&self) -> u64 {
((self.flags_size >> 16) & 0xFFFF) + 1
}

#define BP_GET_LSIZE(bp) \
(BP_IS_EMBEDDED(bp) ? \
(BPE_GET_ETYPE(bp) == BP_EMBEDDED_TYPE_DATA ? BPE_GET_LSIZE(bp) : 0): \
BF64_GET_SB((bp)->blk_prop, 0, SPA_LSIZEBITS, SPA_MINBLOCKSHIFT, 1))
#define BP_SET_LSIZE(bp, x) do { \
ASSERT(!BP_IS_EMBEDDED(bp)); \
BF64_SET_SB((bp)->blk_prop, \
0, SPA_LSIZEBITS, SPA_MINBLOCKSHIFT, 1, x); \
_NOTE(CONSTCOND) } while (0)

#define BP_GET_PSIZE(bp) \
(BP_IS_EMBEDDED(bp) ? 0 : \
BF64_GET_SB((bp)->blk_prop, 16, SPA_PSIZEBITS, SPA_MINBLOCKSHIFT, 1))
#define BP_SET_PSIZE(bp, x) do { \
ASSERT(!BP_IS_EMBEDDED(bp)); \
BF64_SET_SB((bp)->blk_prop, \
16, SPA_PSIZEBITS, SPA_MINBLOCKSHIFT, 1, x); \
_NOTE(CONSTCOND) } while (0)

#define BP_GET_COMPRESS(bp) BF64_GET((bp)->blk_prop, 32, 7)
#define BP_SET_COMPRESS(bp, x) BF64_SET((bp)->blk_prop, 32, 7, x)

#define BP_IS_EMBEDDED(bp) BF64_GET((bp)->blk_prop, 39, 1)
#define BP_SET_EMBEDDED(bp, x) BF64_SET((bp)->blk_prop, 39, 1, x)

#define BP_GET_CHECKSUM(bp) \
(BP_IS_EMBEDDED(bp) ? ZIO_CHECKSUM_OFF : \
BF64_GET((bp)->blk_prop, 40, 8))
#define BP_SET_CHECKSUM(bp, x) do { \
ASSERT(!BP_IS_EMBEDDED(bp)); \
BF64_SET((bp)->blk_prop, 40, 8, x); \
_NOTE(CONSTCOND) } while (0)

#define BP_GET_TYPE(bp) BF64_GET((bp)->blk_prop, 48, 8)
#define BP_SET_TYPE(bp, x) BF64_SET((bp)->blk_prop, 48, 8, x)

#define BP_GET_LEVEL(bp) BF64_GET((bp)->blk_prop, 56, 5)
#define BP_SET_LEVEL(bp, x) BF64_SET((bp)->blk_prop, 56, 5, x)

#define BP_GET_DEDUP(bp) BF64_GET((bp)->blk_prop, 62, 1)
#define BP_SET_DEDUP(bp, x) BF64_SET((bp)->blk_prop, 62, 1, x)

#define BP_GET_BYTEORDER(bp) BF64_GET((bp)->blk_prop, 63, 1)
#define BP_SET_BYTEORDER(bp, x) BF64_SET((bp)->blk_prop, 63, 1, x)

#define BP_PHYSICAL_BIRTH(bp) \
(BP_IS_EMBEDDED(bp) ? 0 : \
(bp)->blk_phys_birth ? (bp)->blk_phys_birth : (bp)->blk_birth)

#define BP_SET_BIRTH(bp, logical, physical) \
{ \
ASSERT(!BP_IS_EMBEDDED(bp)); \
(bp)->blk_birth = (logical); \
(bp)->blk_phys_birth = ((logical) == (physical) ? 0 : (physical)); \
}

#define BP_GET_FILL(bp) (BP_IS_EMBEDDED(bp) ? 1 : (bp)->blk_fill)

#define BP_GET_ASIZE(bp) \
(BP_IS_EMBEDDED(bp) ? 0 : \
DVA_GET_ASIZE(&(bp)->blk_dva[0]) + \
DVA_GET_ASIZE(&(bp)->blk_dva[1]) + \
DVA_GET_ASIZE(&(bp)->blk_dva[2]))

#define BP_GET_UCSIZE(bp) \
((BP_GET_LEVEL(bp) > 0 || DMU_OT_IS_METADATA(BP_GET_TYPE(bp))) ? \
BP_GET_PSIZE(bp) : BP_GET_LSIZE(bp))

#define BP_GET_NDVAS(bp) \
(BP_IS_EMBEDDED(bp) ? 0 : \
!!DVA_GET_ASIZE(&(bp)->blk_dva[0]) + \
!!DVA_GET_ASIZE(&(bp)->blk_dva[1]) + \
!!DVA_GET_ASIZE(&(bp)->blk_dva[2]))

#define BP_COUNT_GANG(bp) \
(BP_IS_EMBEDDED(bp) ? 0 : \
(DVA_GET_GANG(&(bp)->blk_dva[0]) + \
DVA_GET_GANG(&(bp)->blk_dva[1]) + \
DVA_GET_GANG(&(bp)->blk_dva[2])))

#define DVA_EQUAL(dva1, dva2) \
((dva1)->dva_word[1] == (dva2)->dva_word[1] && \
(dva1)->dva_word[0] == (dva2)->dva_word[0])

#define BP_EQUAL(bp1, bp2) \
(BP_PHYSICAL_BIRTH(bp1) == BP_PHYSICAL_BIRTH(bp2) && \
(bp1)->blk_birth == (bp2)->blk_birth && \
DVA_EQUAL(&(bp1)->blk_dva[0], &(bp2)->blk_dva[0]) && \
DVA_EQUAL(&(bp1)->blk_dva[1], &(bp2)->blk_dva[1]) && \
DVA_EQUAL(&(bp1)->blk_dva[2], &(bp2)->blk_dva[2]))
}

impl FromBytes for BlockPtr { }
Expand Down
7 changes: 3 additions & 4 deletions filesystem/apps/zfs/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -494,13 +494,12 @@ impl Zfs {
space_map_phys);
// println!("got space map: {:?}", &space_map.unwrap()[0..64]);

let mut range_tree: avl::Tree<space_map::Entry,
u64> =
let mut range_tree: avl::Tree<space_map::Entry, u64> =
avl::Tree::new(Box::new(|x| x.offset()));
space_map::load_space_map_avl(&space_map::SpaceMap { size: 30 },
/*space_map::load_space_map_avl(&space_map::SpaceMap { size: 30 },
&mut range_tree,
&space_map.unwrap(),
space_map::MapType::Alloc).unwrap();
space_map::MapType::Alloc).unwrap();*/
} else {
println!("Invalid metaslab_array NvValue \
type. Expected Uint64.");
Expand Down
69 changes: 63 additions & 6 deletions filesystem/apps/zfs/metaslab.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::cmp;

use super::avl;
use super::space_map;
use super::taskq::{self, Taskq};
Expand Down Expand Up @@ -53,7 +55,7 @@ struct MetaslabGroup {
bias: i64,
activation_count: i64,
ms_class: MetaslabClass,
vdev: vdev::TreeIndex,
//vdev: vdev::TreeIndex,
taskq: Taskq,
//prev: *MetaslabGroup,
//next: *MetaslabGroup,
Expand All @@ -62,7 +64,7 @@ struct MetaslabGroup {
}

impl MetaslabGroup {
pub fn create(ms_class: metaslab_class_t, vdev: vdev::TreeIndex) -> Self {
pub fn create(ms_class: MetaslabClass) -> Self {
let metaslab_key = Box::new(|ms| (ms.weight, ms.start));
let taskq = Taskq::new("metaslab_group_taskq".to_string(), metaslab_load_pct,
maxclsyspri, 10, std::u64::MAX, TASKQ_THREADS_CPU_PCT | TASKQ_DYNAMIC);
Expand All @@ -76,7 +78,7 @@ impl MetaslabGroup {
bias: 0,
activation_count: 0,
ms_class: ms_class,
vdev: vdev,
//vdev: vdev,
taskq: taskq,
//prev: *MetaslabGroup,
//next: *MetaslabGroup,
Expand All @@ -90,6 +92,36 @@ impl MetaslabGroup {
start: m.start,
weight: m.weight });
}

pub fn activate(&mut self) {
/*metaslab_class_t *mc = self.class;
metaslab_group_t *mgprev, *mgnext;
//assert!(spa_config_held(ms_class.spa, SCL_ALLOC, RW_WRITER));
assert!(ms_class.rotor != mg);
assert!(self.prev == NULL);
assert!(self.next == NULL);
assert!(self.activation_count <= 0);
if (++self.activation_count <= 0)
return;
self.aliquot = metaslab_aliquot * cmp::max(1, self.vdev->vdev_children);
metaslab_group_alloc_update(mg);
if (mgprev = ms_class.rotor) == NULL {
self.prev = mg;
self.next = mg;
} else {
mgnext = mgprev->mg_next;
self.prev = mgprev;
self.next = mgnext;
mgprev->mg_next = mg;
mgnext->mg_prev = mg;
}
ms_class.rotor = mg;*/
}
}

////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -309,6 +341,26 @@ impl Metaslab {
//cv_wait(&msp->ms_load_cv, &msp->ms_lock);
}
}

fn activate(&mut self, activation_weight: u64) -> zfs::Result<()> {
assert!(MUTEX_HELD(&self.lock));

if self.weight & METASLAB_ACTIVE_MASK == 0 {
self.load_wait();
if !self.loaded {
if let Err(e) = self.load() {
metaslab_group_sort(self.group, msp, 0);
return e;
}
}

metaslab_group_sort(self.group, self, self.weight | activation_weight);
}
assert!(self.loaded);
assert!(self.weight & METASLAB_ACTIVE_MASK);

Ok(())
}
}

////////////////////////////////////////////////////////////////////////////////////////////////////
Expand All @@ -321,7 +373,7 @@ struct MetaslabOps {
////////////////////////////////////////////////////////////////////////////////////////////////////

// The first-fit block allocator
/*fn metaslab_ff_alloc(ms: &mut Metaslab, size: u64) -> u64 {
fn metaslab_ff_alloc(ms: &mut Metaslab, size: u64) -> u64 {
// Find the largest power of 2 block size that evenly divides the
// requested size. This is used to try to allocate blocks with similar
// alignment from the same area of the metaslab (i.e. same cursor
Expand All @@ -331,8 +383,13 @@ struct MetaslabOps {
let ref mut cursor = ms.lbas[util::highbit64(align) - 1];
let ref mut tree = ms.tree;

return metaslab_block_picker(tree, cursor, size, align);
}*/
//return metaslab_block_picker(tree, cursor, size, align);
return 0;
}

static metaslab_ff_ops: MetaslabOps = MetaslabOps { alloc: metaslab_ff_alloc };

static zfs_metaslab_ops: MetaslabOps = metaslab_ff_ops;

////////////////////////////////////////////////////////////////////////////////////////////////////

Expand Down
13 changes: 10 additions & 3 deletions filesystem/apps/zfs/spa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::{Box, String, ToString, Vec};
use std::cmp;

use super::avl;
use super::dsl_pool;
use super::nvpair::{NvList, NvValue};
use super::txg;
use super::uberblock::Uberblock;
Expand All @@ -21,6 +22,9 @@ pub struct Spa {
state: zfs::PoolState,
load_state: zfs::SpaLoadState,
zio_taskq: [[SpaTaskqs; zio::NUM_TASKQ_TYPES]; zio::NUM_TYPES],
//dsl_pool: DslPool,
normal_class: MetaslabClass, // normal data class
log_class: MetaslabClass, // intent log data class
first_txg: u64,
vdev_tree: vdev::Tree,
root_vdev: vdev::TreeIndex,
Expand Down Expand Up @@ -67,12 +71,18 @@ impl Spa {
let nvroot: &NvList = try!(config.get("vdev_tree").ok_or(zfs::Error::Invalid));
try!(vdev_tree.parse(nvroot, None, vdev_alloc_type))
};

let normal_class = MetaslabClass::create(self, metaslab::zfs_metaslab_ops);
let log_class = MetaslabClass::create(self, metaslab::zfs_metaslab_ops);

Ok(Spa {
name: name,
config: config,
state: zfs::PoolState::Uninitialized,
load_state: zfs::SpaLoadState::None,
//dsl_pool: blah,
normal_class: normal_class,
log_class: log_class,
first_txg: 0,
vdev_tree: vdev_tree,
root_vdev: root_vdev,
Expand Down Expand Up @@ -163,9 +173,6 @@ impl Spa {

self.state = zfs::PoolState::Active;

// self.normal_class = MetaslabClass::create(self, zfs_metaslab_ops);
// self.log_class = MetaslabClass::create(self, zfs_metaslab_ops);

// TODO: maybe start the spa thread

self.create_zio_taskqs();
Expand Down
6 changes: 4 additions & 2 deletions filesystem/apps/zfs/taskq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ use std::cmp;
//use std::sync::mpsc::{channel, Sender, Receiver};
use std::thread;

use super::zfs;

const TQENT_FLAG_PREALLOC: u64 = 0x1; // taskq_dispatch_ent used

const TASKQ_PREPOPULATE: u64 = 0x0001;
Expand Down Expand Up @@ -203,9 +205,9 @@ impl Taskq {
return 0;
}*/

pub fn empty_ent(&self) -> bool {
/*pub fn empty_ent(&self) -> bool {
self.next == NULL
}
}*/

/*fn taskq_init_ent(taskq_ent_t *t) {
t.next = NULL;
Expand Down
Loading

1 comment on commit d65f42d

@ticki
Copy link
Contributor

@ticki ticki commented on d65f42d Jan 15, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yo, @tedsta. Remember that you can rebase to reword the commit messages :)

Please sign in to comment.