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 + 1 >= 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 bigblocks 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 * Bigblock count changed so recompute the total number of blocks.
187 mp->mnt_stat.f_blocks = trans->rootvol->ondisk->vol0_stat_bigblocks *
188 (HAMMER_LARGEBLOCK_SIZE / HAMMER_BUFSIZE);
189 mp->mnt_vstat.f_blocks = trans->rootvol->ondisk->vol0_stat_bigblocks *
190 (HAMMER_LARGEBLOCK_SIZE / HAMMER_BUFSIZE);
193 * Increase the number of free bigblocks
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);
278 hmp->volume_to_remove = volume->vol_no;
280 struct hammer_ioc_reblock reblock;
281 bzero(&reblock, sizeof(reblock));
283 reblock.key_beg.localization = HAMMER_MIN_LOCALIZATION;
284 reblock.key_beg.obj_id = HAMMER_MIN_OBJID;
285 reblock.key_end.localization = HAMMER_MAX_LOCALIZATION;
286 reblock.key_end.obj_id = HAMMER_MAX_OBJID;
287 reblock.head.flags = HAMMER_IOC_DO_FLAGS;
288 reblock.free_level = 0;
290 error = hammer_ioc_reblock(trans, ip, &reblock);
292 if (reblock.head.flags & HAMMER_IOC_HEAD_INTR) {
297 if (error == EINTR) {
298 kprintf("reblock was interrupted\n");
300 kprintf("reblock failed: %d\n", error);
302 hmp->volume_to_remove = -1;
303 hammer_rel_volume(volume, 0);
311 while (hammer_flusher_haswork(hmp)) {
312 hammer_flusher_sync(hmp);
316 kprintf("HAMMER: flushing.");
319 tsleep(&count, 0, "hmrufl", hz);
322 kprintf("giving up");
328 hammer_sync_lock_sh(trans);
329 hammer_lock_ex(&hmp->blkmap_lock);
332 * We use stat later to update rootvol's bigblock stats
334 struct bigblock_stat stat;
335 error = hammer_free_freemap(trans, volume, &stat);
337 kprintf("Failed to free volume. Volume not empty!\n");
338 hmp->volume_to_remove = -1;
339 hammer_rel_volume(volume, 0);
340 hammer_unlock(&hmp->blkmap_lock);
341 hammer_sync_unlock(trans);
345 hmp->volume_to_remove = -1;
347 hammer_rel_volume(volume, 0);
352 RB_SCAN(hammer_buf_rb_tree, &hmp->rb_bufs_root, NULL,
353 hammer_unload_buffer, volume);
355 error = hammer_unload_volume(volume, NULL);
357 kprintf("Failed to unload volume\n");
358 hammer_unlock(&hmp->blkmap_lock);
359 hammer_sync_unlock(trans);
367 * Set each volume's new value of the vol_count field.
369 for (int vol_no = 0; vol_no < HAMMER_MAX_VOLUMES; ++vol_no) {
370 volume = hammer_get_volume(hmp, vol_no, &error);
371 if (volume == NULL && error == ENOENT) {
373 * Skip unused volume numbers
379 KKASSERT(volume != NULL && error == 0);
380 hammer_modify_volume_field(trans, volume, vol_count);
381 volume->ondisk->vol_count = hmp->nvolumes;
382 hammer_modify_volume_done(volume);
385 * Only changes to the header of the root volume
386 * are automatically flushed to disk. For all
387 * other volumes that we modify we do it here.
389 * No interlock is needed, volume buffers are not
390 * messed with by bioops.
392 if (volume != trans->rootvol && volume->io.modified) {
393 hammer_crc_set_volume(volume->ondisk);
394 hammer_io_flush(&volume->io, 0);
397 hammer_rel_volume(volume, 0);
401 * Update the total number of bigblocks
403 hammer_modify_volume_field(trans, trans->rootvol,
404 vol0_stat_bigblocks);
405 trans->rootvol->ondisk->vol0_stat_bigblocks -= stat.total_bigblocks;
406 hammer_modify_volume_done(trans->rootvol);
409 * Update the number of free bigblocks
410 * (including the copy in hmp)
412 hammer_modify_volume_field(trans, trans->rootvol,
413 vol0_stat_freebigblocks);
414 trans->rootvol->ondisk->vol0_stat_freebigblocks -= stat.total_free_bigblocks;
415 hmp->copy_stat_freebigblocks =
416 trans->rootvol->ondisk->vol0_stat_freebigblocks;
417 hammer_modify_volume_done(trans->rootvol);
419 * Bigblock count changed so recompute the total number of blocks.
421 mp->mnt_stat.f_blocks = trans->rootvol->ondisk->vol0_stat_bigblocks *
422 (HAMMER_LARGEBLOCK_SIZE / HAMMER_BUFSIZE);
423 mp->mnt_vstat.f_blocks = trans->rootvol->ondisk->vol0_stat_bigblocks *
424 (HAMMER_LARGEBLOCK_SIZE / HAMMER_BUFSIZE);
426 hammer_unlock(&hmp->blkmap_lock);
427 hammer_sync_unlock(trans);
430 * Erase the volume header of the removed device.
432 * This is to not accidentally mount the volume again.
434 struct vnode *devvp = NULL;
435 error = hammer_setup_device(&devvp, ioc->device_name, 0);
437 kprintf("Failed to open device: %s\n", ioc->device_name);
441 error = hammer_clear_volume_header(devvp);
443 kprintf("Failed to clear volume header of device: %s\n",
447 hammer_close_device(&devvp, 0);
449 KKASSERT(error == 0);
451 hammer_unlock(&hmp->volume_lock);
457 hammer_ioc_volume_list(hammer_transaction_t trans, hammer_inode_t ip,
458 struct hammer_ioc_volume_list *ioc)
460 struct hammer_mount *hmp = trans->hmp;
461 hammer_volume_t volume;
465 for (i = 0, cnt = 0; i < HAMMER_MAX_VOLUMES && cnt < ioc->nvols; i++) {
466 volume = hammer_get_volume(hmp, i, &error);
467 if (volume == NULL && error == ENOENT) {
471 KKASSERT(volume != NULL && error == 0);
473 len = strlen(volume->vol_name) + 1;
474 KKASSERT(len <= MAXPATHLEN);
476 error = copyout(volume->vol_name, ioc->vols[cnt].device_name,
479 hammer_rel_volume(volume, 0);
483 hammer_rel_volume(volume, 0);
491 * Iterate over all usable L1 entries of the volume and
492 * the corresponding L2 entries.
495 hammer_iterate_l1l2_entries(hammer_transaction_t trans, hammer_volume_t volume,
496 int (*callback)(hammer_transaction_t, hammer_volume_t, hammer_buffer_t*,
497 struct hammer_blockmap_layer1*, struct hammer_blockmap_layer2*,
498 hammer_off_t, hammer_off_t, void*),
501 struct hammer_mount *hmp = trans->hmp;
502 hammer_blockmap_t freemap = &hmp->blockmap[HAMMER_ZONE_FREEMAP_INDEX];
503 hammer_buffer_t buffer = NULL;
506 hammer_off_t phys_off;
507 hammer_off_t block_off;
508 hammer_off_t layer1_off;
509 hammer_off_t layer2_off;
510 hammer_off_t aligned_buf_end_off;
511 struct hammer_blockmap_layer1 *layer1;
512 struct hammer_blockmap_layer2 *layer2;
515 * Calculate the usable size of the volume, which
516 * must be aligned at a bigblock (8 MB) boundary.
518 aligned_buf_end_off = (HAMMER_ENCODE_RAW_BUFFER(volume->ondisk->vol_no,
519 (volume->ondisk->vol_buf_end - volume->ondisk->vol_buf_beg)
520 & ~HAMMER_LARGEBLOCK_MASK64));
523 * Iterate the volume's address space in chunks of 4 TB, where each
524 * chunk consists of at least one physically available 8 MB bigblock.
526 * For each chunk we need one L1 entry and one L2 bigblock.
527 * We use the first bigblock of each chunk as L2 block.
529 for (phys_off = HAMMER_ENCODE_RAW_BUFFER(volume->ondisk->vol_no, 0);
530 phys_off < aligned_buf_end_off;
531 phys_off += HAMMER_BLOCKMAP_LAYER2) {
533 block_off < HAMMER_BLOCKMAP_LAYER2;
534 block_off += HAMMER_LARGEBLOCK_SIZE) {
535 layer2_off = phys_off +
536 HAMMER_BLOCKMAP_LAYER2_OFFSET(block_off);
537 layer2 = hammer_bread(hmp, layer2_off, &error, &buffer);
541 error = callback(trans, volume, &buffer, NULL,
542 layer2, phys_off, block_off, data);
547 layer1_off = freemap->phys_offset +
548 HAMMER_BLOCKMAP_LAYER1_OFFSET(phys_off);
549 layer1 = hammer_bread(hmp, layer1_off, &error, &buffer);
553 error = callback(trans, volume, &buffer, layer1, NULL,
561 hammer_rel_buffer(buffer, 0);
570 format_callback(hammer_transaction_t trans, hammer_volume_t volume,
571 hammer_buffer_t *bufferp,
572 struct hammer_blockmap_layer1 *layer1,
573 struct hammer_blockmap_layer2 *layer2,
574 hammer_off_t phys_off,
575 hammer_off_t block_off,
578 struct bigblock_stat *stat = (struct bigblock_stat*)data;
581 * Calculate the usable size of the volume, which must be aligned
582 * at a bigblock (8 MB) boundary.
584 hammer_off_t aligned_buf_end_off;
585 aligned_buf_end_off = (HAMMER_ENCODE_RAW_BUFFER(volume->ondisk->vol_no,
586 (volume->ondisk->vol_buf_end - volume->ondisk->vol_buf_beg)
587 & ~HAMMER_LARGEBLOCK_MASK64));
590 KKASSERT(layer1->phys_offset == HAMMER_BLOCKMAP_UNAVAIL);
592 hammer_modify_buffer(trans, *bufferp, layer1, sizeof(*layer1));
593 bzero(layer1, sizeof(*layer1));
594 layer1->phys_offset = phys_off;
595 layer1->blocks_free = stat->counter;
596 layer1->layer1_crc = crc32(layer1, HAMMER_LAYER1_CRCSIZE);
597 hammer_modify_buffer_done(*bufferp);
599 stat->total_free_bigblocks += stat->counter;
600 stat->counter = 0; /* reset */
602 hammer_modify_buffer(trans, *bufferp, layer2, sizeof(*layer2));
603 bzero(layer2, sizeof(*layer2));
605 if (block_off == 0) {
607 * The first entry represents the L2 bigblock itself.
609 layer2->zone = HAMMER_ZONE_FREEMAP_INDEX;
610 layer2->append_off = HAMMER_LARGEBLOCK_SIZE;
611 layer2->bytes_free = 0;
612 ++stat->total_bigblocks;
613 } else if (phys_off + block_off < aligned_buf_end_off) {
618 layer2->append_off = 0;
619 layer2->bytes_free = HAMMER_LARGEBLOCK_SIZE;
620 ++stat->total_bigblocks;
624 * Bigblock outside of physically available
627 layer2->zone = HAMMER_ZONE_UNAVAIL_INDEX;
628 layer2->append_off = HAMMER_LARGEBLOCK_SIZE;
629 layer2->bytes_free = 0;
632 layer2->entry_crc = crc32(layer2, HAMMER_LAYER2_CRCSIZE);
633 hammer_modify_buffer_done(*bufferp);
642 hammer_format_freemap(hammer_transaction_t trans, hammer_volume_t volume,
643 struct bigblock_stat *stat)
645 stat->total_bigblocks = 0;
646 stat->total_free_bigblocks = 0;
648 return hammer_iterate_l1l2_entries(trans, volume, format_callback, stat);
652 free_callback(hammer_transaction_t trans, hammer_volume_t volume __unused,
653 hammer_buffer_t *bufferp,
654 struct hammer_blockmap_layer1 *layer1,
655 struct hammer_blockmap_layer2 *layer2,
656 hammer_off_t phys_off,
657 hammer_off_t block_off __unused,
660 struct bigblock_stat *stat = (struct bigblock_stat*)data;
663 * No modifications to ondisk structures
665 int testonly = (stat == NULL);
668 if (layer1->phys_offset == HAMMER_BLOCKMAP_UNAVAIL) {
670 * This layer1 entry is already free.
675 KKASSERT((int)HAMMER_VOL_DECODE(layer1->phys_offset) ==
676 trans->hmp->volume_to_remove);
684 hammer_modify_buffer(trans, *bufferp, layer1, sizeof(*layer1));
685 bzero(layer1, sizeof(*layer1));
686 layer1->phys_offset = HAMMER_BLOCKMAP_UNAVAIL;
687 layer1->layer1_crc = crc32(layer1, HAMMER_LAYER1_CRCSIZE);
688 hammer_modify_buffer_done(*bufferp);
692 if (layer2->zone == HAMMER_ZONE_UNAVAIL_INDEX) {
696 if (layer2->zone == HAMMER_ZONE_FREEMAP_INDEX) {
698 ++stat->total_bigblocks;
703 if (layer2->append_off == 0 &&
704 layer2->bytes_free == HAMMER_LARGEBLOCK_SIZE) {
706 ++stat->total_bigblocks;
707 ++stat->total_free_bigblocks;
713 * We found a layer2 entry that is not empty!
724 hammer_free_freemap(hammer_transaction_t trans, hammer_volume_t volume,
725 struct bigblock_stat *stat)
729 stat->total_bigblocks = 0;
730 stat->total_free_bigblocks = 0;
733 error = hammer_iterate_l1l2_entries(trans, volume, free_callback, NULL);
737 error = hammer_iterate_l1l2_entries(trans, volume, free_callback, stat);
741 /************************************************************************
743 ************************************************************************
747 hammer_setup_device(struct vnode **devvpp, const char *dev_path, int ronly)
750 struct nlookupdata nd;
753 * Get the device vnode
755 if (*devvpp == NULL) {
756 error = nlookup_init(&nd, dev_path, UIO_SYSSPACE, NLC_FOLLOW);
758 error = nlookup(&nd);
760 error = cache_vref(&nd.nl_nch, nd.nl_cred, devvpp);
767 if (vn_isdisk(*devvpp, &error)) {
768 error = vfs_mountedon(*devvpp);
771 if (error == 0 && vcount(*devvpp) > 0)
774 vn_lock(*devvpp, LK_EXCLUSIVE | LK_RETRY);
775 error = vinvalbuf(*devvpp, V_SAVE, 0, 0);
777 error = VOP_OPEN(*devvpp,
778 (ronly ? FREAD : FREAD|FWRITE),
783 if (error && *devvpp) {
791 hammer_close_device(struct vnode **devvpp, int ronly)
794 vn_lock(*devvpp, LK_EXCLUSIVE | LK_RETRY);
795 vinvalbuf(*devvpp, ronly ? 0 : V_SAVE, 0, 0);
796 VOP_CLOSE(*devvpp, (ronly ? FREAD : FREAD|FWRITE), NULL);
804 hammer_format_volume_header(struct hammer_mount *hmp, struct vnode *devvp,
805 const char *vol_name, int vol_no, int vol_count,
806 int64_t vol_size, int64_t boot_area_size, int64_t mem_area_size)
808 struct buf *bp = NULL;
809 struct hammer_volume_ondisk *ondisk;
813 * Extract the volume number from the volume header and do various
816 KKASSERT(HAMMER_BUFSIZE >= sizeof(struct hammer_volume_ondisk));
817 error = bread(devvp, 0LL, HAMMER_BUFSIZE, &bp);
818 if (error || bp->b_bcount < sizeof(struct hammer_volume_ondisk))
821 ondisk = (struct hammer_volume_ondisk*) bp->b_data;
824 * Note that we do NOT allow to use a device that contains
825 * a valid HAMMER signature. It has to be cleaned up with dd
828 if (ondisk->vol_signature == HAMMER_FSBUF_VOLUME) {
829 kprintf("hammer_volume_add: Formatting of valid HAMMER volume "
830 "%s denied. Erase with dd!\n", vol_name);
835 bzero(ondisk, sizeof(struct hammer_volume_ondisk));
836 ksnprintf(ondisk->vol_name, sizeof(ondisk->vol_name), "%s", vol_name);
837 ondisk->vol_fstype = hmp->rootvol->ondisk->vol_fstype;
838 ondisk->vol_signature = HAMMER_FSBUF_VOLUME;
839 ondisk->vol_fsid = hmp->fsid;
840 ondisk->vol_rootvol = hmp->rootvol->vol_no;
841 ondisk->vol_no = vol_no;
842 ondisk->vol_count = vol_count;
843 ondisk->vol_version = hmp->version;
846 * Reserve space for (future) header junk, setup our poor-man's
847 * bigblock allocator.
849 int64_t vol_alloc = HAMMER_BUFSIZE * 16;
851 ondisk->vol_bot_beg = vol_alloc;
852 vol_alloc += boot_area_size;
853 ondisk->vol_mem_beg = vol_alloc;
854 vol_alloc += mem_area_size;
857 * The remaining area is the zone 2 buffer allocation area. These
860 ondisk->vol_buf_beg = vol_alloc;
861 ondisk->vol_buf_end = vol_size & ~(int64_t)HAMMER_BUFMASK;
863 if (ondisk->vol_buf_end < ondisk->vol_buf_beg) {
864 kprintf("volume %d %s is too small to hold the volume header",
865 ondisk->vol_no, ondisk->vol_name);
870 ondisk->vol_nblocks = (ondisk->vol_buf_end - ondisk->vol_buf_beg) /
872 ondisk->vol_blocksize = HAMMER_BUFSIZE;
875 * Write volume header to disk
887 * Invalidates the volume header. Used by volume-del.
890 hammer_clear_volume_header(struct vnode *devvp)
892 struct buf *bp = NULL;
893 struct hammer_volume_ondisk *ondisk;
896 KKASSERT(HAMMER_BUFSIZE >= sizeof(struct hammer_volume_ondisk));
897 error = bread(devvp, 0LL, HAMMER_BUFSIZE, &bp);
898 if (error || bp->b_bcount < sizeof(struct hammer_volume_ondisk))
901 ondisk = (struct hammer_volume_ondisk*) bp->b_data;
902 bzero(ondisk, sizeof(struct hammer_volume_ondisk));