ctl_backend_block.c (282565) | ctl_backend_block.c (285030) |
---|---|
1/*- 2 * Copyright (c) 2003 Silicon Graphics International Corp. 3 * Copyright (c) 2009-2011 Spectra Logic Corporation 4 * Copyright (c) 2012 The FreeBSD Foundation 5 * All rights reserved. 6 * 7 * Portions of this software were developed by Edward Tomasz Napierala 8 * under sponsorship from the FreeBSD Foundation. --- 26 unchanged lines hidden (view full) --- 35 * $Id: //depot/users/kenm/FreeBSD-test2/sys/cam/ctl/ctl_backend_block.c#5 $ 36 */ 37/* 38 * CAM Target Layer driver backend for block devices. 39 * 40 * Author: Ken Merry <ken@FreeBSD.org> 41 */ 42#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 2003 Silicon Graphics International Corp. 3 * Copyright (c) 2009-2011 Spectra Logic Corporation 4 * Copyright (c) 2012 The FreeBSD Foundation 5 * All rights reserved. 6 * 7 * Portions of this software were developed by Edward Tomasz Napierala 8 * under sponsorship from the FreeBSD Foundation. --- 26 unchanged lines hidden (view full) --- 35 * $Id: //depot/users/kenm/FreeBSD-test2/sys/cam/ctl/ctl_backend_block.c#5 $ 36 */ 37/* 38 * CAM Target Layer driver backend for block devices. 39 * 40 * Author: Ken Merry <ken@FreeBSD.org> 41 */ 42#include <sys/cdefs.h> |
43__FBSDID("$FreeBSD: head/sys/cam/ctl/ctl_backend_block.c 282565 2015-05-06 19:47:31Z mav $"); | 43__FBSDID("$FreeBSD: head/sys/cam/ctl/ctl_backend_block.c 285030 2015-07-02 12:53:22Z mav $"); |
44 45#include <sys/param.h> 46#include <sys/systm.h> 47#include <sys/kernel.h> 48#include <sys/types.h> 49#include <sys/kthread.h> 50#include <sys/bio.h> 51#include <sys/fcntl.h> --- 753 unchanged lines hidden (view full) --- 805 ctl_complete_beio(beio); 806} 807 808static uint64_t 809ctl_be_block_getattr_file(struct ctl_be_block_lun *be_lun, const char *attrname) 810{ 811 struct vattr vattr; 812 struct statfs statfs; | 44 45#include <sys/param.h> 46#include <sys/systm.h> 47#include <sys/kernel.h> 48#include <sys/types.h> 49#include <sys/kthread.h> 50#include <sys/bio.h> 51#include <sys/fcntl.h> --- 753 unchanged lines hidden (view full) --- 805 ctl_complete_beio(beio); 806} 807 808static uint64_t 809ctl_be_block_getattr_file(struct ctl_be_block_lun *be_lun, const char *attrname) 810{ 811 struct vattr vattr; 812 struct statfs statfs; |
813 uint64_t val; |
|
813 int error; 814 | 814 int error; 815 |
816 val = UINT64_MAX; |
|
815 if (be_lun->vn == NULL) | 817 if (be_lun->vn == NULL) |
816 return (UINT64_MAX); | 818 return (val); 819 vn_lock(be_lun->vn, LK_SHARED | LK_RETRY); |
817 if (strcmp(attrname, "blocksused") == 0) { 818 error = VOP_GETATTR(be_lun->vn, &vattr, curthread->td_ucred); | 820 if (strcmp(attrname, "blocksused") == 0) { 821 error = VOP_GETATTR(be_lun->vn, &vattr, curthread->td_ucred); |
819 if (error != 0) 820 return (UINT64_MAX); 821 return (vattr.va_bytes >> be_lun->blocksize_shift); | 822 if (error == 0) 823 val = vattr.va_bytes >> be_lun->blocksize_shift; |
822 } | 824 } |
823 if (strcmp(attrname, "blocksavail") == 0) { | 825 if (strcmp(attrname, "blocksavail") == 0 && 826 (be_lun->vn->v_iflag & VI_DOOMED) == 0) { |
824 error = VFS_STATFS(be_lun->vn->v_mount, &statfs); | 827 error = VFS_STATFS(be_lun->vn->v_mount, &statfs); |
825 if (error != 0) 826 return (UINT64_MAX); 827 return ((statfs.f_bavail * statfs.f_bsize) >> 828 be_lun->blocksize_shift); | 828 if (error == 0) 829 val = (statfs.f_bavail * statfs.f_bsize) >> 830 be_lun->blocksize_shift; |
829 } | 831 } |
830 return (UINT64_MAX); | 832 VOP_UNLOCK(be_lun->vn, 0); 833 return (val); |
831} 832 833static void 834ctl_be_block_dispatch_zvol(struct ctl_be_block_lun *be_lun, 835 struct ctl_be_block_io *beio) 836{ 837 struct ctl_be_block_devdata *dev_data; 838 union ctl_io *io; --- 1822 unchanged lines hidden (view full) --- 2661 goto bailout_error; 2662 } 2663 2664 be_lun->params.lun_size_bytes = params->lun_size_bytes; 2665 2666 oldsize = be_lun->size_bytes; 2667 if (be_lun->vn == NULL) 2668 error = ctl_be_block_open(softc, be_lun, req); | 834} 835 836static void 837ctl_be_block_dispatch_zvol(struct ctl_be_block_lun *be_lun, 838 struct ctl_be_block_io *beio) 839{ 840 struct ctl_be_block_devdata *dev_data; 841 union ctl_io *io; --- 1822 unchanged lines hidden (view full) --- 2664 goto bailout_error; 2665 } 2666 2667 be_lun->params.lun_size_bytes = params->lun_size_bytes; 2668 2669 oldsize = be_lun->size_bytes; 2670 if (be_lun->vn == NULL) 2671 error = ctl_be_block_open(softc, be_lun, req); |
2672 else if (vn_isdisk(be_lun->vn, &error)) 2673 error = ctl_be_block_modify_dev(be_lun, req); |
|
2669 else if (be_lun->vn->v_type == VREG) 2670 error = ctl_be_block_modify_file(be_lun, req); 2671 else | 2674 else if (be_lun->vn->v_type == VREG) 2675 error = ctl_be_block_modify_file(be_lun, req); 2676 else |
2672 error = ctl_be_block_modify_dev(be_lun, req); | 2677 error = EINVAL; |
2673 2674 if (error == 0 && be_lun->size_bytes != oldsize) { 2675 be_lun->size_blocks = be_lun->size_bytes >> 2676 be_lun->blocksize_shift; 2677 2678 /* 2679 * The maximum LBA is the size - 1. 2680 * --- 267 unchanged lines hidden --- | 2678 2679 if (error == 0 && be_lun->size_bytes != oldsize) { 2680 be_lun->size_blocks = be_lun->size_bytes >> 2681 be_lun->blocksize_shift; 2682 2683 /* 2684 * The maximum LBA is the size - 1. 2685 * --- 267 unchanged lines hidden --- |