Lines Matching refs:volume
47 static void hammer_free_volume(hammer_volume_t volume);
48 static int hammer_load_volume(hammer_volume_t volume);
113 hammer_volume_t volume; in hammer_install_volume() local
130 volume = kmalloc(sizeof(*volume), hmp->m_misc, M_WAITOK|M_ZERO); in hammer_install_volume()
131 volume->vol_name = kstrdup(volname, hmp->m_misc); in hammer_install_volume()
132 volume->io.hmp = hmp; /* bootstrap */ in hammer_install_volume()
133 hammer_io_init(&volume->io, volume, HAMMER_IOTYPE_VOLUME); in hammer_install_volume()
134 volume->io.offset = 0LL; in hammer_install_volume()
135 volume->io.bytes = HAMMER_BUFSIZE; in hammer_install_volume()
141 error = nlookup_init(&nd, volume->vol_name, UIO_SYSSPACE, NLC_FOLLOW); in hammer_install_volume()
145 error = cache_vref(&nd.nl_nch, nd.nl_cred, &volume->devvp); in hammer_install_volume()
149 volume->devvp = devvp; in hammer_install_volume()
153 if (vn_isdisk(volume->devvp, &error)) { in hammer_install_volume()
154 error = vfs_mountedon(volume->devvp); in hammer_install_volume()
157 if (error == 0 && vcount(volume->devvp) > 0) in hammer_install_volume()
160 vn_lock(volume->devvp, LK_EXCLUSIVE | LK_RETRY); in hammer_install_volume()
161 error = vinvalbuf(volume->devvp, V_SAVE, 0, 0); in hammer_install_volume()
163 error = VOP_OPEN(volume->devvp, in hammer_install_volume()
167 vn_unlock(volume->devvp); in hammer_install_volume()
170 hammer_free_volume(volume); in hammer_install_volume()
173 volume->devvp->v_rdev->si_mountpoint = mp; in hammer_install_volume()
180 error = bread(volume->devvp, 0LL, HAMMER_BUFSIZE, &bp); in hammer_install_volume()
200 hkprintf("volume %s has an invalid header\n", volume->vol_name); in hammer_install_volume()
210 volume->vol_no = ondisk->vol_no; in hammer_install_volume()
211 volume->vol_flags = ondisk->vol_flags; in hammer_install_volume()
212 volume->maxbuf_off = HAMMER_ENCODE_RAW_BUFFER(volume->vol_no, in hammer_install_volume()
219 volume->vol_name); in hammer_install_volume()
227 if (RB_INSERT(hammer_vol_rb_tree, &hmp->rb_vols_root, volume)) { in hammer_install_volume()
229 volume->vol_name, volume->vol_no); in hammer_install_volume()
234 hammer_volume_number_add(hmp, volume); in hammer_install_volume()
244 volume->vol_name, ondisk->vol_rootvol); in hammer_install_volume()
248 hmp->rootvol = volume; in hammer_install_volume()
265 volume->devvp->v_rdev->si_mountpoint = NULL; in hammer_install_volume()
266 vn_lock(volume->devvp, LK_EXCLUSIVE | LK_RETRY); in hammer_install_volume()
267 VOP_CLOSE(volume->devvp, ronly ? FREAD : FREAD|FWRITE, NULL); in hammer_install_volume()
268 vn_unlock(volume->devvp); in hammer_install_volume()
269 hammer_free_volume(volume); in hammer_install_volume()
279 hammer_adjust_volume_mode(hammer_volume_t volume, void *data __unused) in hammer_adjust_volume_mode() argument
281 if (volume->devvp) { in hammer_adjust_volume_mode()
282 vn_lock(volume->devvp, LK_EXCLUSIVE | LK_RETRY); in hammer_adjust_volume_mode()
283 if (volume->io.hmp->ronly) { in hammer_adjust_volume_mode()
285 VOP_OPEN(volume->devvp, FREAD, FSCRED, NULL); in hammer_adjust_volume_mode()
286 VOP_CLOSE(volume->devvp, FREAD|FWRITE, NULL); in hammer_adjust_volume_mode()
289 VOP_OPEN(volume->devvp, FREAD|FWRITE, FSCRED, NULL); in hammer_adjust_volume_mode()
290 VOP_CLOSE(volume->devvp, FREAD, NULL); in hammer_adjust_volume_mode()
292 vn_unlock(volume->devvp); in hammer_adjust_volume_mode()
302 hammer_unload_volume(hammer_volume_t volume, void *data) in hammer_unload_volume() argument
304 hammer_mount_t hmp = volume->io.hmp; in hammer_unload_volume()
313 if (ronly == 0 && data && volume->devvp) { in hammer_unload_volume()
315 error = bread(volume->devvp, 0LL, HAMMER_BUFSIZE, &bp); in hammer_unload_volume()
331 if (hmp->rootvol == volume) in hammer_unload_volume()
339 hammer_io_clear_modify(&volume->io, 1); in hammer_unload_volume()
340 volume->io.waitdep = 1; in hammer_unload_volume()
345 if (volume->io.ioerror) in hammer_unload_volume()
346 hammer_io_clear_error_noassert(&volume->io); in hammer_unload_volume()
352 hammer_ref_interlock_true(&volume->io.lock); in hammer_unload_volume()
353 hammer_rel_volume(volume, 1); in hammer_unload_volume()
354 KKASSERT(volume->io.bp == NULL); in hammer_unload_volume()
359 KKASSERT(hammer_norefs(&volume->io.lock)); in hammer_unload_volume()
361 volume->ondisk = NULL; in hammer_unload_volume()
362 if (volume->devvp) { in hammer_unload_volume()
363 if (volume->devvp->v_rdev && in hammer_unload_volume()
364 volume->devvp->v_rdev->si_mountpoint == hmp->mp) { in hammer_unload_volume()
365 volume->devvp->v_rdev->si_mountpoint = NULL; in hammer_unload_volume()
374 vn_lock(volume->devvp, LK_EXCLUSIVE | LK_RETRY); in hammer_unload_volume()
375 vinvalbuf(volume->devvp, 0, 0, 0); in hammer_unload_volume()
376 VOP_CLOSE(volume->devvp, FREAD, NULL); in hammer_unload_volume()
377 vn_unlock(volume->devvp); in hammer_unload_volume()
383 vn_lock(volume->devvp, LK_EXCLUSIVE | LK_RETRY); in hammer_unload_volume()
384 vinvalbuf(volume->devvp, V_SAVE, 0, 0); in hammer_unload_volume()
385 VOP_CLOSE(volume->devvp, FREAD|FWRITE, NULL); in hammer_unload_volume()
386 vn_unlock(volume->devvp); in hammer_unload_volume()
393 RB_REMOVE(hammer_vol_rb_tree, &hmp->rb_vols_root, volume); in hammer_unload_volume()
394 hammer_volume_number_del(hmp, volume); in hammer_unload_volume()
395 hammer_free_volume(volume); in hammer_unload_volume()
401 hammer_free_volume(hammer_volume_t volume) in hammer_free_volume() argument
403 hammer_mount_t hmp = volume->io.hmp; in hammer_free_volume()
405 if (volume->vol_name) { in hammer_free_volume()
406 kfree(volume->vol_name, hmp->m_misc); in hammer_free_volume()
407 volume->vol_name = NULL; in hammer_free_volume()
409 if (volume->devvp) { in hammer_free_volume()
410 vrele(volume->devvp); in hammer_free_volume()
411 volume->devvp = NULL; in hammer_free_volume()
414 kfree(volume, hmp->m_misc); in hammer_free_volume()
423 hammer_volume_t volume; in hammer_get_volume() local
428 volume = RB_LOOKUP(hammer_vol_rb_tree, &hmp->rb_vols_root, vol_no); in hammer_get_volume()
429 if (volume == NULL) { in hammer_get_volume()
439 if (hammer_ref_interlock(&volume->io.lock)) { in hammer_get_volume()
440 *errorp = hammer_load_volume(volume); in hammer_get_volume()
442 volume = NULL; in hammer_get_volume()
444 KKASSERT(volume->ondisk); in hammer_get_volume()
447 return(volume); in hammer_get_volume()
451 hammer_ref_volume(hammer_volume_t volume) in hammer_ref_volume() argument
459 if (hammer_ref_interlock(&volume->io.lock)) { in hammer_ref_volume()
460 error = hammer_load_volume(volume); in hammer_ref_volume()
462 KKASSERT(volume->ondisk); in hammer_ref_volume()
474 hammer_volume_t volume; in hammer_get_root_volume() local
476 volume = hmp->rootvol; in hammer_get_root_volume()
477 KKASSERT(volume != NULL); in hammer_get_root_volume()
483 if (hammer_ref_interlock(&volume->io.lock)) { in hammer_get_root_volume()
484 lwkt_gettoken(&volume->io.hmp->fs_token); in hammer_get_root_volume()
485 *errorp = hammer_load_volume(volume); in hammer_get_root_volume()
486 lwkt_reltoken(&volume->io.hmp->fs_token); in hammer_get_root_volume()
488 volume = NULL; in hammer_get_root_volume()
490 KKASSERT(volume->ondisk); in hammer_get_root_volume()
493 return (volume); in hammer_get_root_volume()
502 hammer_load_volume(hammer_volume_t volume) in hammer_load_volume() argument
506 if (volume->ondisk == NULL) { in hammer_load_volume()
507 error = hammer_io_read(volume->devvp, &volume->io, in hammer_load_volume()
510 volume->ondisk = (void *)volume->io.bp->b_data; in hammer_load_volume()
511 hammer_ref_interlock_done(&volume->io.lock); in hammer_load_volume()
513 hammer_rel_volume(volume, 1); in hammer_load_volume()
529 hammer_rel_volume(hammer_volume_t volume, int locked) in hammer_rel_volume() argument
533 if (hammer_rel_interlock(&volume->io.lock, locked)) { in hammer_rel_volume()
534 lwkt_gettoken(&volume->io.hmp->fs_token); in hammer_rel_volume()
535 volume->ondisk = NULL; in hammer_rel_volume()
536 bp = hammer_io_release(&volume->io, locked); in hammer_rel_volume()
537 lwkt_reltoken(&volume->io.hmp->fs_token); in hammer_rel_volume()
538 hammer_rel_interlock_done(&volume->io.lock, locked); in hammer_rel_volume()
602 hammer_volume_t volume; in hammer_get_buffer() local
705 volume = hammer_get_volume(hmp, vol_no, errorp); in hammer_get_buffer()
706 if (volume == NULL) in hammer_get_buffer()
709 KKASSERT(zone2_offset < volume->maxbuf_off); in hammer_get_buffer()
720 hammer_io_init(&buffer->io, volume, hammer_zone_to_iotype(zone)); in hammer_get_buffer()
721 buffer->io.offset = hammer_xlate_to_phys(volume->ondisk, zone2_offset); in hammer_get_buffer()
730 hammer_rel_volume(volume, 0); in hammer_get_buffer()
731 buffer->io.volume = NULL; /* safety */ in hammer_get_buffer()
817 hammer_volume_t volume; in hammer_del_buffers() local
823 volume = hammer_get_volume(hmp, vol_no, &ret_error); in hammer_del_buffers()
846 KKASSERT(buffer->io.volume == volume); in hammer_del_buffers()
850 error = hammer_io_inval(volume, zone2_offset); in hammer_del_buffers()
869 hammer_rel_volume(volume, 0); in hammer_del_buffers()
883 hammer_volume_t volume; in hammer_load_buffer() local
889 volume = buffer->io.volume; in hammer_load_buffer()
909 error = hammer_io_new(volume->devvp, &buffer->io); in hammer_load_buffer()
911 error = hammer_io_read(volume->devvp, &buffer->io, in hammer_load_buffer()
918 error = hammer_io_read(volume->devvp, &buffer->io, in hammer_load_buffer()
924 error = hammer_io_new(volume->devvp, &buffer->io); in hammer_load_buffer()
948 hammer_volume_t volume = (hammer_volume_t)data; in hammer_unload_buffer() local
954 if (volume != NULL && volume != buffer->io.volume) in hammer_unload_buffer()
1041 hammer_volume_t volume; in hammer_rel_buffer() local
1081 volume = buffer->io.volume; in hammer_rel_buffer()
1082 buffer->io.volume = NULL; /* sanity */ in hammer_rel_buffer()
1083 hammer_rel_volume(volume, 0); in hammer_rel_buffer()