2017-09-14 16:17:23 +05:30
|
|
|
(library
|
|
|
|
(thin metadata)
|
|
|
|
|
|
|
|
(export ThinSuperblock
|
2017-10-04 15:10:25 +05:30
|
|
|
ThinDeviceDetails
|
|
|
|
|
|
|
|
block->superblock
|
|
|
|
|
|
|
|
mapping-tree-lookup
|
|
|
|
mapping-tree-each
|
|
|
|
unpack-block-time
|
|
|
|
|
2018-01-25 21:41:43 +05:30
|
|
|
device-details-vt
|
2017-10-04 15:10:25 +05:30
|
|
|
device-tree-lookup
|
|
|
|
device-tree-each)
|
2017-09-14 16:17:23 +05:30
|
|
|
|
2017-09-14 20:39:43 +05:30
|
|
|
(import (chezscheme)
|
|
|
|
(bcache block-manager)
|
2017-10-04 15:10:25 +05:30
|
|
|
(persistent-data btree)
|
|
|
|
(srfi s8 receive))
|
2017-09-14 16:17:23 +05:30
|
|
|
|
|
|
|
(define $superblock-magic 27022010)
|
|
|
|
(define $superblock-salt 160774)
|
|
|
|
(define $uuid-size 16)
|
|
|
|
(define $space-map-root-size 128)
|
|
|
|
|
|
|
|
(define (block->superblock b)
|
2017-11-24 16:34:57 +05:30
|
|
|
(make-ftype-pointer ThinSuperblock (block-data b)))
|
2017-09-14 16:17:23 +05:30
|
|
|
|
|
|
|
(define-ftype ThinSuperblock
|
2017-10-04 15:10:25 +05:30
|
|
|
(packed
|
|
|
|
(endian little
|
|
|
|
(struct
|
|
|
|
(csum unsigned-32)
|
|
|
|
(flags unsigned-32)
|
|
|
|
(block-nr unsigned-64)
|
|
|
|
(uuid (array 16 unsigned-8))
|
|
|
|
(magic unsigned-64)
|
|
|
|
(version unsigned-32)
|
|
|
|
(time unsigned-32)
|
|
|
|
(trans-id unsigned-64)
|
|
|
|
(metadata-snap unsigned-64)
|
|
|
|
(data-space-map-root (array 128 unsigned-8))
|
|
|
|
(metadata-space-map-root (array 128 unsigned-8))
|
|
|
|
(data-mapping-root unsigned-64)
|
|
|
|
(device-details-root unsigned-64)
|
|
|
|
(data-block-size unsigned-32)
|
|
|
|
(metadata-block-size unsigned-32)
|
|
|
|
(metadata-nr-blocks unsigned-64)
|
|
|
|
(compat-flags unsigned-32)
|
|
|
|
(compat-ro-flags unsigned-32)
|
|
|
|
(incompat-flags unsigned-32)))))
|
2017-09-14 16:17:23 +05:30
|
|
|
|
|
|
|
(define-ftype ThinDeviceDetails
|
2017-10-04 15:10:25 +05:30
|
|
|
(packed
|
|
|
|
(endian little
|
|
|
|
(struct
|
|
|
|
(mapped-blocks unsigned-64)
|
|
|
|
(transaction-id unsigned-64)
|
|
|
|
(creation-time unsigned-32)
|
|
|
|
(snapshotted-time unsigned-32)))))
|
|
|
|
|
|
|
|
;; (values <block> <time>)
|
|
|
|
(define time-mask (- (fxsll 1 24) 1))
|
|
|
|
|
|
|
|
(define (unpack-block-time bt)
|
|
|
|
(values (fxsrl bt 24) (fxlogand bt time-mask)))
|
|
|
|
|
|
|
|
;; FIXME: unpack the block time
|
|
|
|
(define (mapping-tree-lookup cache root dev-id vblock default)
|
|
|
|
(with-spine (sp cache 1)
|
|
|
|
(let* ((unique (gensym))
|
|
|
|
(dev-tree (btree-open le64-vt root))
|
|
|
|
(root2 (btree-lookup dev-tree sp dev-id unique)))
|
|
|
|
(if (eq? unique root2)
|
|
|
|
default
|
|
|
|
(btree-lookup (btree-open le64-vt root2) sp vblock default)))))
|
|
|
|
|
|
|
|
;;; Visits every entry in the mapping tree calling (fn dev-id vblock pblock time).
|
|
|
|
(define (mapping-tree-each cache root fn)
|
2018-01-25 21:41:43 +05:30
|
|
|
(let ((dev-tree (btree-open le64-vt root)))
|
2017-10-04 15:10:25 +05:30
|
|
|
|
2018-01-25 21:41:43 +05:30
|
|
|
(define (visit-dev dev-id mapping-root)
|
|
|
|
(btree-each (btree-open le64-vt mapping-root)
|
|
|
|
cache
|
|
|
|
(lambda (vblock mapping)
|
|
|
|
(receive (block time) (unpack-block-time mapping)
|
|
|
|
(fn dev-id vblock block time)))))
|
2017-10-04 15:10:25 +05:30
|
|
|
|
2018-01-25 21:41:43 +05:30
|
|
|
(btree-each dev-tree cache visit-dev)))
|
2017-10-04 15:10:25 +05:30
|
|
|
|
|
|
|
(define-compound-value-type device-details-vt ThinDeviceDetails)
|
|
|
|
|
|
|
|
(define (device-tree-lookup cache root dev-id default)
|
2018-01-25 21:41:43 +05:30
|
|
|
(with-spine (sp cache 1)
|
|
|
|
(btree-lookup (btree-open device-details-vt root) sp dev-id default)))
|
2017-09-14 16:17:23 +05:30
|
|
|
|
2017-10-04 15:10:25 +05:30
|
|
|
(define (device-tree-each cache root fn)
|
2018-01-25 21:41:43 +05:30
|
|
|
(btree-each (btree-open device-details-vt root) cache fn))
|
2017-09-14 16:17:23 +05:30
|
|
|
)
|
|
|
|
|