2 * Copyright (c) 2009 The DragonFly Project. All rights reserved.
4 * This code is derived from software contributed to The DragonFly Project
5 * by Matthew Dillon <dillon@backplane.com> and
6 * Michael Neumann <mneumann@ntecs.de>
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the
18 * 3. Neither the name of The DragonFly Project nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific, prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
30 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
31 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
32 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 #include <sys/fcntl.h>
39 #include <sys/nlookup.h>
45 hammer_setup_device(struct vnode **devvpp, const char *dev_path, int ronly);
48 hammer_close_device(struct vnode **devvpp, int ronly);
51 hammer_format_volume_header(struct hammer_mount *hmp, struct vnode *devvp,
52 const char *vol_name, int vol_no, int vol_count,
53 int64_t vol_size, int64_t boot_area_size, int64_t mem_area_size);
56 hammer_clear_volume_header(struct vnode *devvp);
58 struct bigblock_stat {
59 uint64_t total_bigblocks;
60 uint64_t total_free_bigblocks;
65 hammer_format_freemap(hammer_transaction_t trans, hammer_volume_t volume,
66 struct bigblock_stat *stat);
69 hammer_free_freemap(hammer_transaction_t trans, hammer_volume_t volume,
70 struct bigblock_stat *stat);
73 hammer_ioc_volume_add(hammer_transaction_t trans, hammer_inode_t ip,
74 struct hammer_ioc_volume *ioc)
76 struct hammer_mount *hmp = trans->hmp;
77 struct mount *mp = hmp->mp;
78 hammer_volume_t volume;
81 if (mp->mnt_flag & MNT_RDONLY) {
82 kprintf("Cannot add volume to read-only HAMMER filesystem\n");
86 if (hmp->nvolumes >= HAMMER_MAX_VOLUMES) {
87 kprintf("Max number of HAMMER volumes exceeded\n");
91 if (hammer_lock_ex_try(&hmp->volume_lock) != 0) {
92 kprintf("Another volume operation is in progress!\n");
97 * Find an unused volume number.
100 while (free_vol_no < HAMMER_MAX_VOLUMES &&
101 RB_LOOKUP(hammer_vol_rb_tree, &hmp->rb_vols_root, free_vol_no)) {
104 if (free_vol_no >= HAMMER_MAX_VOLUMES) {
105 kprintf("Max number of HAMMER volumes exceeded\n");
106 hammer_unlock(&hmp->volume_lock);
110 struct vnode *devvp = NULL;
111 error = hammer_setup_device(&devvp, ioc->device_name, 0);
115 error = hammer_format_volume_header(
118 hmp->rootvol->ondisk->vol_name,
124 hammer_close_device(&devvp, 0);
128 error = hammer_install_volume(hmp, ioc->device_name, NULL);
132 hammer_sync_lock_sh(trans);
133 hammer_lock_ex(&hmp->blkmap_lock);
138 * Set each volumes new value of the vol_count field.
140 for (int vol_no = 0; vol_no < HAMMER_MAX_VOLUMES; ++vol_no) {
141 volume = hammer_get_volume(hmp, vol_no, &error);
142 if (volume == NULL && error == ENOENT) {
144 * Skip unused volume numbers
149 KKASSERT(volume != NULL && error == 0);
150 hammer_modify_volume_field(trans, volume, vol_count);
151 volume->ondisk->vol_count = hmp->nvolumes;
152 hammer_modify_volume_done(volume);
155 * Only changes to the header of the root volume
156 * are automatically flushed to disk. For all
157 * other volumes that we modify we do it here.
159 * No interlock is needed, volume buffers are not
160 * messed with by bioops.
162 if (volume != trans->rootvol && volume->io.modified) {
163 hammer_crc_set_volume(volume->ondisk);
164 hammer_io_flush(&volume->io, 0);
167 hammer_rel_volume(volume, 0);
170 volume = hammer_get_volume(hmp, free_vol_no, &error);
171 KKASSERT(volume != NULL && error == 0);
173 struct bigblock_stat stat;
174 error = hammer_format_freemap(trans, volume, &stat);
175 KKASSERT(error == 0);
178 * Increase the total number of big-blocks and update stat/vstat totals.
180 hammer_modify_volume_field(trans, trans->rootvol,
181 vol0_stat_bigblocks);
182 trans->rootvol->ondisk->vol0_stat_bigblocks += stat.total_bigblocks;
183 hammer_modify_volume_done(trans->rootvol);
185 * Big-block count changed so recompute the total number of blocks.
187 mp->mnt_stat.f_blocks = trans->rootvol->ondisk->vol0_stat_bigblocks *
188 (HAMMER_BIGBLOCK_SIZE / HAMMER_BUFSIZE);
189 mp->mnt_vstat.f_blocks = trans->rootvol->ondisk->vol0_stat_bigblocks *
190 (HAMMER_BIGBLOCK_SIZE / HAMMER_BUFSIZE);
193 * Increase the number of free big-blocks
194 * (including the copy in hmp)
196 hammer_modify_volume_field(trans, trans->rootvol,
197 vol0_stat_freebigblocks);
198 trans->rootvol->ondisk->vol0_stat_freebigblocks += stat.total_free_bigblocks;
199 hmp->copy_stat_freebigblocks =
200 trans->rootvol->ondisk->vol0_stat_freebigblocks;
201 hammer_modify_volume_done(trans->rootvol);
203 hammer_rel_volume(volume, 0);
205 hammer_unlock(&hmp->blkmap_lock);
206 hammer_sync_unlock(trans);
208 KKASSERT(error == 0);
210 hammer_unlock(&hmp->volume_lock);
212 kprintf("An error occurred: %d\n", error);
221 hammer_ioc_volume_del(hammer_transaction_t trans, hammer_inode_t ip,
222 struct hammer_ioc_volume *ioc)
224 struct hammer_mount *hmp = trans->hmp;
225 struct mount *mp = hmp->mp;
226 hammer_volume_t volume;
229 if (mp->mnt_flag & MNT_RDONLY) {
230 kprintf("Cannot del volume from read-only HAMMER filesystem\n");
234 if (hammer_lock_ex_try(&hmp->volume_lock) != 0) {
235 kprintf("Another volume operation is in progress!\n");
242 * find volume by volname
244 for (int vol_no = 0; vol_no < HAMMER_MAX_VOLUMES; ++vol_no) {
245 volume = hammer_get_volume(hmp, vol_no, &error);
246 if (volume == NULL && error == ENOENT) {
248 * Skip unused volume numbers
253 KKASSERT(volume != NULL && error == 0);
254 if (strcmp(volume->vol_name, ioc->device_name) == 0) {
257 hammer_rel_volume(volume, 0);
261 if (volume == NULL) {
262 kprintf("Couldn't find volume\n");
267 if (volume == trans->rootvol) {
268 kprintf("Cannot remove root-volume\n");
269 hammer_rel_volume(volume, 0);
277 hmp->volume_to_remove = volume->vol_no;
279 struct hammer_ioc_reblock reblock;
280 bzero(&reblock, sizeof(reblock));
282 reblock.key_beg.localization = HAMMER_MIN_LOCALIZATION;
283 reblock.key_beg.obj_id = HAMMER_MIN_OBJID;
284 reblock.key_end.localization = HAMMER_MAX_LOCALIZATION;
285 reblock.key_end.obj_id = HAMMER_MAX_OBJID;
286 reblock.head.flags = HAMMER_IOC_DO_FLAGS;
287 reblock.free_level = 0;
289 error = hammer_ioc_reblock(trans, ip, &reblock);
291 if (reblock.head.flags & HAMMER_IOC_HEAD_INTR) {
296 if (error == EINTR) {
297 kprintf("reblock was interrupted\n");
299 kprintf("reblock failed: %d\n", error);
301 hmp->volume_to_remove = -1;
302 hammer_rel_volume(volume, 0);
310 while (hammer_flusher_haswork(hmp)) {
311 hammer_flusher_sync(hmp);
315 kprintf("HAMMER: flushing.");
318 tsleep(&count, 0, "hmrufl", hz);
321 kprintf("giving up");
327 hammer_sync_lock_sh(trans);
328 hammer_lock_ex(&hmp->blkmap_lock);
331 * We use stat later to update rootvol's big-block stats
333 struct bigblock_stat stat;
334 error = hammer_free_freemap(trans, volume, &stat);
336 kprintf("Failed to free volume. Volume not empty!\n");
337 hmp->volume_to_remove = -1;
338 hammer_rel_volume(volume, 0);
339 hammer_unlock(&hmp->blkmap_lock);
340 hammer_sync_unlock(trans);
344 hmp->volume_to_remove = -1;
346 hammer_rel_volume(volume, 0);
351 RB_SCAN(hammer_buf_rb_tree, &hmp->rb_bufs_root, NULL,
352 hammer_unload_buffer, volume);
354 error = hammer_unload_volume(volume, NULL);
356 kprintf("Failed to unload volume\n");
357 hammer_unlock(&hmp->blkmap_lock);
358 hammer_sync_unlock(trans);
366 * Set each volume's new value of the vol_count field.
368 for (int vol_no = 0; vol_no < HAMMER_MAX_VOLUMES; ++vol_no) {
369 volume = hammer_get_volume(hmp, vol_no, &error);
370 if (volume == NULL && error == ENOENT) {
372 * Skip unused volume numbers
378 KKASSERT(volume != NULL && error == 0);
379 hammer_modify_volume_field(trans, volume, vol_count);
380 volume->ondisk->vol_count = hmp->nvolumes;
381 hammer_modify_volume_done(volume);
384 * Only changes to the header of the root volume
385 * are automatically flushed to disk. For all
386 * other volumes that we modify we do it here.
388 * No interlock is needed, volume buffers are not
389 * messed with by bioops.
391 if (volume != trans->rootvol && volume->io.modified) {
392 hammer_crc_set_volume(volume->ondisk);
393 hammer_io_flush(&volume->io, 0);
396 hammer_rel_volume(volume, 0);
400 * Update the total number of big-blocks
402 hammer_modify_volume_field(trans, trans->rootvol,
403 vol0_stat_bigblocks);
404 trans->rootvol->ondisk->vol0_stat_bigblocks -= stat.total_bigblocks;
405 hammer_modify_volume_done(trans->rootvol);
408 * Update the number of free big-blocks
409 * (including the copy in hmp)
411 hammer_modify_volume_field(trans, trans->rootvol,
412 vol0_stat_freebigblocks);
413 trans->rootvol->ondisk->vol0_stat_freebigblocks -= stat.total_free_bigblocks;
414 hmp->copy_stat_freebigblocks =
415 trans->rootvol->ondisk->vol0_stat_freebigblocks;
416 hammer_modify_volume_done(trans->rootvol);
418 * Big-block count changed so recompute the total number of blocks.
420 mp->mnt_stat.f_blocks = trans->rootvol->ondisk->vol0_stat_bigblocks *
421 (HAMMER_BIGBLOCK_SIZE / HAMMER_BUFSIZE);
422 mp->mnt_vstat.f_blocks = trans->rootvol->ondisk->vol0_stat_bigblocks *
423 (HAMMER_BIGBLOCK_SIZE / HAMMER_BUFSIZE);
425 hammer_unlock(&hmp->blkmap_lock);
426 hammer_sync_unlock(trans);
429 * Erase the volume header of the removed device.
431 * This is to not accidentally mount the volume again.
433 struct vnode *devvp = NULL;
434 error = hammer_setup_device(&devvp, ioc->device_name, 0);
436 kprintf("Failed to open device: %s\n", ioc->device_name);
440 error = hammer_clear_volume_header(devvp);
442 kprintf("Failed to clear volume header of device: %s\n",
446 hammer_close_device(&devvp, 0);
448 KKASSERT(error == 0);
450 hammer_unlock(&hmp->volume_lock);
456 hammer_ioc_volume_list(hammer_transaction_t trans, hammer_inode_t ip,
457 struct hammer_ioc_volume_list *ioc)
459 struct hammer_mount *hmp = trans->hmp;
460 hammer_volume_t volume;
464 for (i = 0, cnt = 0; i < HAMMER_MAX_VOLUMES && cnt < ioc->nvols; i++) {
465 volume = hammer_get_volume(hmp, i, &error);
466 if (volume == NULL && error == ENOENT) {
470 KKASSERT(volume != NULL && error == 0);
472 len = strlen(volume->vol_name) + 1;
473 KKASSERT(len <= MAXPATHLEN);
475 error = copyout(volume->vol_name, ioc->vols[cnt].device_name,
478 hammer_rel_volume(volume, 0);
482 hammer_rel_volume(volume, 0);
490 * Iterate over all usable L1 entries of the volume and
491 * the corresponding L2 entries.
494 hammer_iterate_l1l2_entries(hammer_transaction_t trans, hammer_volume_t volume,
495 int (*callback)(hammer_transaction_t, hammer_volume_t, hammer_buffer_t*,
496 struct hammer_blockmap_layer1*, struct hammer_blockmap_layer2*,
497 hammer_off_t, hammer_off_t, void*),
500 struct hammer_mount *hmp = trans->hmp;
501 hammer_blockmap_t freemap = &hmp->blockmap[HAMMER_ZONE_FREEMAP_INDEX];
502 hammer_buffer_t buffer = NULL;
505 hammer_off_t phys_off;
506 hammer_off_t block_off;
507 hammer_off_t layer1_off;
508 hammer_off_t layer2_off;
509 hammer_off_t aligned_buf_end_off;
510 struct hammer_blockmap_layer1 *layer1;
511 struct hammer_blockmap_layer2 *layer2;
514 * Calculate the usable size of the volume, which
515 * must be aligned at a big-block (8 MB) boundary.
517 aligned_buf_end_off = (HAMMER_ENCODE_RAW_BUFFER(volume->ondisk->vol_no,
518 (volume->ondisk->vol_buf_end - volume->ondisk->vol_buf_beg)
519 & ~HAMMER_BIGBLOCK_MASK64));
522 * Iterate the volume's address space in chunks of 4 TB, where each
523 * chunk consists of at least one physically available 8 MB big-block.
525 * For each chunk we need one L1 entry and one L2 big-block.
526 * We use the first big-block of each chunk as L2 block.
528 for (phys_off = HAMMER_ENCODE_RAW_BUFFER(volume->ondisk->vol_no, 0);
529 phys_off < aligned_buf_end_off;
530 phys_off += HAMMER_BLOCKMAP_LAYER2) {
532 block_off < HAMMER_BLOCKMAP_LAYER2;
533 block_off += HAMMER_BIGBLOCK_SIZE) {
534 layer2_off = phys_off +
535 HAMMER_BLOCKMAP_LAYER2_OFFSET(block_off);
536 layer2 = hammer_bread(hmp, layer2_off, &error, &buffer);
540 error = callback(trans, volume, &buffer, NULL,
541 layer2, phys_off, block_off, data);
546 layer1_off = freemap->phys_offset +
547 HAMMER_BLOCKMAP_LAYER1_OFFSET(phys_off);
548 layer1 = hammer_bread(hmp, layer1_off, &error, &buffer);
552 error = callback(trans, volume, &buffer, layer1, NULL,
560 hammer_rel_buffer(buffer, 0);
569 format_callback(hammer_transaction_t trans, hammer_volume_t volume,
570 hammer_buffer_t *bufferp,
571 struct hammer_blockmap_layer1 *layer1,
572 struct hammer_blockmap_layer2 *layer2,
573 hammer_off_t phys_off,
574 hammer_off_t block_off,
577 struct bigblock_stat *stat = (struct bigblock_stat*)data;
580 * Calculate the usable size of the volume, which must be aligned
581 * at a big-block (8 MB) boundary.
583 hammer_off_t aligned_buf_end_off;
584 aligned_buf_end_off = (HAMMER_ENCODE_RAW_BUFFER(volume->ondisk->vol_no,
585 (volume->ondisk->vol_buf_end - volume->ondisk->vol_buf_beg)
586 & ~HAMMER_BIGBLOCK_MASK64));
589 KKASSERT(layer1->phys_offset == HAMMER_BLOCKMAP_UNAVAIL);
591 hammer_modify_buffer(trans, *bufferp, layer1, sizeof(*layer1));
592 bzero(layer1, sizeof(*layer1));
593 layer1->phys_offset = phys_off;
594 layer1->blocks_free = stat->counter;
595 layer1->layer1_crc = crc32(layer1, HAMMER_LAYER1_CRCSIZE);
596 hammer_modify_buffer_done(*bufferp);
598 stat->total_free_bigblocks += stat->counter;
599 stat->counter = 0; /* reset */
601 hammer_modify_buffer(trans, *bufferp, layer2, sizeof(*layer2));
602 bzero(layer2, sizeof(*layer2));
604 if (block_off == 0) {
606 * The first entry represents the L2 big-block itself.
608 layer2->zone = HAMMER_ZONE_FREEMAP_INDEX;
609 layer2->append_off = HAMMER_BIGBLOCK_SIZE;
610 layer2->bytes_free = 0;
611 ++stat->total_bigblocks;
612 } else if (phys_off + block_off < aligned_buf_end_off) {
614 * Available big-block
617 layer2->append_off = 0;
618 layer2->bytes_free = HAMMER_BIGBLOCK_SIZE;
619 ++stat->total_bigblocks;
623 * Big-block outside of physically available
626 layer2->zone = HAMMER_ZONE_UNAVAIL_INDEX;
627 layer2->append_off = HAMMER_BIGBLOCK_SIZE;
628 layer2->bytes_free = 0;
631 layer2->entry_crc = crc32(layer2, HAMMER_LAYER2_CRCSIZE);
632 hammer_modify_buffer_done(*bufferp);
641 hammer_format_freemap(hammer_transaction_t trans, hammer_volume_t volume,
642 struct bigblock_stat *stat)
644 stat->total_bigblocks = 0;
645 stat->total_free_bigblocks = 0;
647 return hammer_iterate_l1l2_entries(trans, volume, format_callback, stat);
651 free_callback(hammer_transaction_t trans, hammer_volume_t volume __unused,
652 hammer_buffer_t *bufferp,
653 struct hammer_blockmap_layer1 *layer1,
654 struct hammer_blockmap_layer2 *layer2,
655 hammer_off_t phys_off,
656 hammer_off_t block_off __unused,
659 struct bigblock_stat *stat = (struct bigblock_stat*)data;
662 * No modifications to ondisk structures
664 int testonly = (stat == NULL);
667 if (layer1->phys_offset == HAMMER_BLOCKMAP_UNAVAIL) {
669 * This layer1 entry is already free.
674 KKASSERT((int)HAMMER_VOL_DECODE(layer1->phys_offset) ==
675 trans->hmp->volume_to_remove);
683 hammer_modify_buffer(trans, *bufferp, layer1, sizeof(*layer1));
684 bzero(layer1, sizeof(*layer1));
685 layer1->phys_offset = HAMMER_BLOCKMAP_UNAVAIL;
686 layer1->layer1_crc = crc32(layer1, HAMMER_LAYER1_CRCSIZE);
687 hammer_modify_buffer_done(*bufferp);
691 if (layer2->zone == HAMMER_ZONE_UNAVAIL_INDEX) {
695 if (layer2->zone == HAMMER_ZONE_FREEMAP_INDEX) {
697 ++stat->total_bigblocks;
702 if (layer2->append_off == 0 &&
703 layer2->bytes_free == HAMMER_BIGBLOCK_SIZE) {
705 ++stat->total_bigblocks;
706 ++stat->total_free_bigblocks;
712 * We found a layer2 entry that is not empty!
723 hammer_free_freemap(hammer_transaction_t trans, hammer_volume_t volume,
724 struct bigblock_stat *stat)
728 stat->total_bigblocks = 0;
729 stat->total_free_bigblocks = 0;
732 error = hammer_iterate_l1l2_entries(trans, volume, free_callback, NULL);
736 error = hammer_iterate_l1l2_entries(trans, volume, free_callback, stat);
740 /************************************************************************
742 ************************************************************************
746 hammer_setup_device(struct vnode **devvpp, const char *dev_path, int ronly)
749 struct nlookupdata nd;
752 * Get the device vnode
754 if (*devvpp == NULL) {
755 error = nlookup_init(&nd, dev_path, UIO_SYSSPACE, NLC_FOLLOW);
757 error = nlookup(&nd);
759 error = cache_vref(&nd.nl_nch, nd.nl_cred, devvpp);
766 if (vn_isdisk(*devvpp, &error)) {
767 error = vfs_mountedon(*devvpp);
770 if (error == 0 && vcount(*devvpp) > 0)
773 vn_lock(*devvpp, LK_EXCLUSIVE | LK_RETRY);
774 error = vinvalbuf(*devvpp, V_SAVE, 0, 0);
776 error = VOP_OPEN(*devvpp,
777 (ronly ? FREAD : FREAD|FWRITE),
782 if (error && *devvpp) {
790 hammer_close_device(struct vnode **devvpp, int ronly)
793 vn_lock(*devvpp, LK_EXCLUSIVE | LK_RETRY);
794 vinvalbuf(*devvpp, ronly ? 0 : V_SAVE, 0, 0);
795 VOP_CLOSE(*devvpp, (ronly ? FREAD : FREAD|FWRITE), NULL);
803 hammer_format_volume_header(struct hammer_mount *hmp, struct vnode *devvp,
804 const char *vol_name, int vol_no, int vol_count,
805 int64_t vol_size, int64_t boot_area_size, int64_t mem_area_size)
807 struct buf *bp = NULL;
808 struct hammer_volume_ondisk *ondisk;
812 * Extract the volume number from the volume header and do various
815 KKASSERT(HAMMER_BUFSIZE >= sizeof(struct hammer_volume_ondisk));
816 error = bread(devvp, 0LL, HAMMER_BUFSIZE, &bp);
817 if (error || bp->b_bcount < sizeof(struct hammer_volume_ondisk))
820 ondisk = (struct hammer_volume_ondisk*) bp->b_data;
823 * Note that we do NOT allow to use a device that contains
824 * a valid HAMMER signature. It has to be cleaned up with dd
827 if (ondisk->vol_signature == HAMMER_FSBUF_VOLUME) {
828 kprintf("hammer_volume_add: Formatting of valid HAMMER volume "
829 "%s denied. Erase with dd!\n", vol_name);
834 bzero(ondisk, sizeof(struct hammer_volume_ondisk));
835 ksnprintf(ondisk->vol_name, sizeof(ondisk->vol_name), "%s", vol_name);
836 ondisk->vol_fstype = hmp->rootvol->ondisk->vol_fstype;
837 ondisk->vol_signature = HAMMER_FSBUF_VOLUME;
838 ondisk->vol_fsid = hmp->fsid;
839 ondisk->vol_rootvol = hmp->rootvol->vol_no;
840 ondisk->vol_no = vol_no;
841 ondisk->vol_count = vol_count;
842 ondisk->vol_version = hmp->version;
845 * Reserve space for (future) header junk, setup our poor-man's
846 * big-block allocator.
848 int64_t vol_alloc = HAMMER_BUFSIZE * 16;
850 ondisk->vol_bot_beg = vol_alloc;
851 vol_alloc += boot_area_size;
852 ondisk->vol_mem_beg = vol_alloc;
853 vol_alloc += mem_area_size;
856 * The remaining area is the zone 2 buffer allocation area. These
859 ondisk->vol_buf_beg = vol_alloc;
860 ondisk->vol_buf_end = vol_size & ~(int64_t)HAMMER_BUFMASK;
862 if (ondisk->vol_buf_end < ondisk->vol_buf_beg) {
863 kprintf("volume %d %s is too small to hold the volume header\n",
864 ondisk->vol_no, ondisk->vol_name);
869 ondisk->vol_nblocks = (ondisk->vol_buf_end - ondisk->vol_buf_beg) /
871 ondisk->vol_blocksize = HAMMER_BUFSIZE;
874 * Write volume header to disk
886 * Invalidates the volume header. Used by volume-del.
889 hammer_clear_volume_header(struct vnode *devvp)
891 struct buf *bp = NULL;
892 struct hammer_volume_ondisk *ondisk;
895 KKASSERT(HAMMER_BUFSIZE >= sizeof(struct hammer_volume_ondisk));
896 error = bread(devvp, 0LL, HAMMER_BUFSIZE, &bp);
897 if (error || bp->b_bcount < sizeof(struct hammer_volume_ondisk))
900 ondisk = (struct hammer_volume_ondisk*) bp->b_data;
901 bzero(ondisk, sizeof(struct hammer_volume_ondisk));