From owner-svn-src-all@FreeBSD.ORG Thu Dec 18 08:43:37 2014 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 8FB1CFB; Thu, 18 Dec 2014 08:43:37 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 618341A24; Thu, 18 Dec 2014 08:43:37 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id sBI8hbIm030079; Thu, 18 Dec 2014 08:43:37 GMT (envelope-from mav@FreeBSD.org) Received: (from mav@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id sBI8hb7f030078; Thu, 18 Dec 2014 08:43:37 GMT (envelope-from mav@FreeBSD.org) Message-Id: <201412180843.sBI8hb7f030078@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: mav set sender to mav@FreeBSD.org using -f From: Alexander Motin Date: Thu, 18 Dec 2014 08:43:37 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r275893 - stable/10/sys/cam/ctl X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 18 Dec 2014 08:43:37 -0000 Author: mav Date: Thu Dec 18 08:43:36 2014 New Revision: 275893 URL: https://svnweb.freebsd.org/changeset/base/275893 Log: MFC r275481: Add to CTL support for threshold notifications for file-backed LUNs. Previously it was supported only for ZVOL-backed LUNs, but now should work for file-backed LUNs too. Used value in this case is a space occupied by the backing file, while available value is an available space on file system. Pool thresholds are still not implemented in this case. Sponsored by: iXsystems, Inc. Modified: stable/10/sys/cam/ctl/ctl_backend_block.c Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/cam/ctl/ctl_backend_block.c ============================================================================== --- stable/10/sys/cam/ctl/ctl_backend_block.c Thu Dec 18 08:38:07 2014 (r275892) +++ stable/10/sys/cam/ctl/ctl_backend_block.c Thu Dec 18 08:43:36 2014 (r275893) @@ -245,6 +245,8 @@ static void ctl_be_block_dispatch_file(s struct ctl_be_block_io *beio); static void ctl_be_block_gls_file(struct ctl_be_block_lun *be_lun, struct ctl_be_block_io *beio); +static uint64_t ctl_be_block_getattr_file(struct ctl_be_block_lun *be_lun, + const char *attrname); static void ctl_be_block_flush_dev(struct ctl_be_block_lun *be_lun, struct ctl_be_block_io *beio); static void ctl_be_block_unmap_dev(struct ctl_be_block_lun *be_lun, @@ -802,6 +804,31 @@ ctl_be_block_gls_file(struct ctl_be_bloc ctl_complete_beio(beio); } +static uint64_t +ctl_be_block_getattr_file(struct ctl_be_block_lun *be_lun, const char *attrname) +{ + struct vattr vattr; + struct statfs statfs; + int error; + + if (be_lun->vn == NULL) + return (UINT64_MAX); + if (strcmp(attrname, "blocksused") == 0) { + error = VOP_GETATTR(be_lun->vn, &vattr, curthread->td_ucred); + if (error != 0) + return (UINT64_MAX); + return (vattr.va_bytes >> be_lun->blocksize_shift); + } + if (strcmp(attrname, "blocksavail") == 0) { + error = VFS_STATFS(be_lun->vn->v_mount, &statfs); + if (error != 0) + return (UINT64_MAX); + return ((statfs.f_bavail * statfs.f_bsize) >> + be_lun->blocksize_shift); + } + return (UINT64_MAX); +} + static void ctl_be_block_dispatch_zvol(struct ctl_be_block_lun *be_lun, struct ctl_be_block_io *beio) @@ -1727,6 +1754,7 @@ ctl_be_block_open_file(struct ctl_be_blo be_lun->dispatch = ctl_be_block_dispatch_file; be_lun->lun_flush = ctl_be_block_flush_file; be_lun->get_lba_status = ctl_be_block_gls_file; + be_lun->getattr = ctl_be_block_getattr_file; error = VOP_GETATTR(be_lun->vn, &vattr, curthread->td_ucred); if (error != 0) {