From cbd800c2df2676e1ee5d600d8b6b4c25522cc933 Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Thu, 24 Jan 2008 02:16:47 +0000 Subject: [PATCH] HAMMER utilities: Features and sync with VFS. * Add 'namekey' and 'namekey32' directives. These generate a directory hash key from a path component. * Adjust for minor API changes. --- sbin/hammer/hammer.8 | 9 ++++++++- sbin/hammer/hammer.c | 24 +++++++++++++++++++++++- sbin/hammer/hammer_util.h | 5 +++-- sbin/hammer/ondisk.c | 28 +++++++++++++++------------- 4 files changed, 49 insertions(+), 17 deletions(-) diff --git a/sbin/hammer/hammer.8 b/sbin/hammer/hammer.8 index 6540ca06cb..27f5806f03 100644 --- a/sbin/hammer/hammer.8 +++ b/sbin/hammer/hammer.8 @@ -30,7 +30,7 @@ .\" OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" $DragonFly: src/sbin/hammer/hammer.8,v 1.2 2008/01/17 04:59:48 dillon Exp $ +.\" $DragonFly: src/sbin/hammer/hammer.8,v 1.3 2008/01/24 02:16:47 dillon Exp $ .Dd December 31, 2007 .Dt HAMMER 8 .Os @@ -78,6 +78,13 @@ at the root volume if not specified. The B-Tree is dumped recursively if the .Fl r option is specified. +.It Ar namekey Ar filename +Generate a HAMMER 64 bit directory hash for the specified file name. +The low 32 bits are used as an iterator for hash collisions and will be +output as 0. +.It Ar namekey32 Ar filename +Generate the top 32 bits of a HAMMER 64 bit directory hash for the specified +file name. .El .Sh EXAMPLES .Sh DIAGNOSTICS diff --git a/sbin/hammer/hammer.c b/sbin/hammer/hammer.c index 4a3261e577..8ae3fc852f 100644 --- a/sbin/hammer/hammer.c +++ b/sbin/hammer/hammer.c @@ -31,7 +31,7 @@ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $DragonFly: src/sbin/hammer/hammer.c,v 1.4 2008/01/18 19:38:29 dillon Exp $ + * $DragonFly: src/sbin/hammer/hammer.c,v 1.5 2008/01/24 02:16:47 dillon Exp $ */ #include "hammer.h" @@ -85,6 +85,28 @@ main(int ac, char **av) printf("0x%08x\n", (int)(tid / 1000000000LL)); exit(0); } + if (strcmp(av[0], "namekey") == 0) { + int64_t key; + + if (av[1] == NULL) + usage(1); + key = (int64_t)(crc32(av[1], strlen(av[1])) & 0x7FFFFFFF) << 32; + if (key == 0) + key |= 0x100000000LL; + printf("0x%016llx\n", key); + exit(0); + } + if (strcmp(av[0], "namekey32") == 0) { + int32_t key; + + if (av[1] == NULL) + usage(1); + key = crc32(av[1], strlen(av[1])) & 0x7FFFFFFF; + if (key == 0) + ++key; + printf("0x%08x\n", key); + exit(0); + } uuid_name_lookup(&Hammer_FSType, "DragonFly HAMMER", &status); if (status != uuid_s_ok) { diff --git a/sbin/hammer/hammer_util.h b/sbin/hammer/hammer_util.h index ee61be5e69..651d4ed017 100644 --- a/sbin/hammer/hammer_util.h +++ b/sbin/hammer/hammer_util.h @@ -31,7 +31,7 @@ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $DragonFly: src/sbin/hammer/hammer_util.h,v 1.6 2008/01/21 00:03:31 dillon Exp $ + * $DragonFly: src/sbin/hammer/hammer_util.h,v 1.7 2008/01/24 02:16:47 dillon Exp $ */ #include @@ -173,7 +173,8 @@ void rel_buffer(struct buffer_info *buffer); void *alloc_btree_element(struct cluster_info *cluster, int32_t *offp); void *alloc_data_element(struct cluster_info *cluster, int32_t bytes, int32_t *offp); -void *alloc_record_element(struct cluster_info *cluster, int32_t *offp); +void *alloc_record_element(struct cluster_info *cluster, int32_t *offp, + u_int8_t rec_type); int hammer_btree_cmp(hammer_base_elm_t key1, hammer_base_elm_t key2); diff --git a/sbin/hammer/ondisk.c b/sbin/hammer/ondisk.c index c0fc725276..c287db1fc2 100644 --- a/sbin/hammer/ondisk.c +++ b/sbin/hammer/ondisk.c @@ -31,7 +31,7 @@ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $DragonFly: src/sbin/hammer/ondisk.c,v 1.8 2008/01/17 04:59:48 dillon Exp $ + * $DragonFly: src/sbin/hammer/ondisk.c,v 1.9 2008/01/24 02:16:47 dillon Exp $ */ #include @@ -79,20 +79,22 @@ init_alist_templates(void) * Initialize the alist templates we will be using */ hammer_alist_template(&Buf_alist_config, HAMMER_FSBUF_MAXBLKS, - 1, HAMMER_FSBUF_METAELMS); + 1, HAMMER_FSBUF_METAELMS, 0); hammer_alist_template(&Vol_normal_alist_config, HAMMER_VOL_MAXCLUSTERS, - 1, HAMMER_VOL_METAELMS_1LYR); + 1, HAMMER_VOL_METAELMS_1LYR, 0); hammer_alist_template(&Vol_super_alist_config, HAMMER_VOL_MAXSUPERCLUSTERS * HAMMER_SCL_MAXCLUSTERS, - HAMMER_SCL_MAXCLUSTERS, HAMMER_VOL_METAELMS_2LYR); + HAMMER_SCL_MAXCLUSTERS, HAMMER_VOL_METAELMS_2LYR, + 0); hammer_super_alist_template(&Vol_super_alist_config); hammer_alist_template(&Supercl_alist_config, HAMMER_VOL_MAXCLUSTERS, - 1, HAMMER_SUPERCL_METAELMS); + 1, HAMMER_SUPERCL_METAELMS, 0); hammer_alist_template(&Clu_master_alist_config, HAMMER_CLU_MAXBUFFERS, - 1, HAMMER_CLU_MASTER_METAELMS); + 1, HAMMER_CLU_MASTER_METAELMS, 0); hammer_alist_template(&Clu_slave_alist_config, HAMMER_CLU_MAXBUFFERS * HAMMER_FSBUF_MAXBLKS, - HAMMER_FSBUF_MAXBLKS, HAMMER_CLU_SLAVE_METAELMS); + HAMMER_FSBUF_MAXBLKS, HAMMER_CLU_SLAVE_METAELMS, + 1); hammer_buffer_alist_template(&Clu_slave_alist_config); } @@ -595,7 +597,8 @@ alloc_data_element(struct cluster_info *cluster, int32_t bytes, int32_t *offp) } void * -alloc_record_element(struct cluster_info *cluster, int32_t *offp) +alloc_record_element(struct cluster_info *cluster, int32_t *offp, + u_int8_t rec_type) { struct buffer_info *buf; hammer_alist_t live; @@ -621,6 +624,9 @@ alloc_record_element(struct cluster_info *cluster, int32_t *offp) item = &buf->ondisk->record.recs[elm_no & HAMMER_FSBUF_BLKMASK]; *offp = buf->buf_no * HAMMER_BUFSIZE + ((char *)item - (char *)buf->ondisk); + ++cluster->ondisk->stat_records; + if (rec_type == HAMMER_RECTYPE_CLUSTER) + ++cluster->ondisk->stat_records; return(item); } @@ -641,11 +647,7 @@ alloc_new_buffer(struct cluster_info *cluster, hammer_alist_t live, assert(buf_no != HAMMER_ALIST_BLOCK_NONE); buf = get_buffer(cluster, buf_no, type); hammer_alist_free(live, buf_no * HAMMER_FSBUF_MAXBLKS, nelements); - if (type == HAMMER_FSBUF_RECORDS) { - cluster->ondisk->clu_record_buf_bitmap[buf_no >> 5] |= - 1 << (buf_no & 31); - } -/* rel_buffer(buffer);XXX modified bit for multiple gets/rels */ + /* XXX modified bit for multiple gets/rels */ } /* -- 2.41.0