From owner-svn-src-head@freebsd.org Sat Apr 21 14:56:42 2018 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 8F5C5FAB0BF; Sat, 21 Apr 2018 14:56:42 +0000 (UTC) (envelope-from trasz@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 3C6B788299; Sat, 21 Apr 2018 14:56:42 +0000 (UTC) (envelope-from trasz@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 31658690; Sat, 21 Apr 2018 14:56:42 +0000 (UTC) (envelope-from trasz@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w3LEugo1091533; Sat, 21 Apr 2018 14:56:42 GMT (envelope-from trasz@FreeBSD.org) Received: (from trasz@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w3LEufpK091527; Sat, 21 Apr 2018 14:56:41 GMT (envelope-from trasz@FreeBSD.org) Message-Id: <201804211456.w3LEufpK091527@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: trasz set sender to trasz@FreeBSD.org using -f From: Edward Tomasz Napierala Date: Sat, 21 Apr 2018 14:56:41 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r332857 - in head: etc/defaults etc/rc.d share/man/man4 share/man/man5 X-SVN-Group: head X-SVN-Commit-Author: trasz X-SVN-Commit-Paths: in head: etc/defaults etc/rc.d share/man/man4 share/man/man5 X-SVN-Commit-Revision: 332857 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 21 Apr 2018 14:56:42 -0000 Author: trasz Date: Sat Apr 21 14:56:41 2018 New Revision: 332857 URL: https://svnweb.freebsd.org/changeset/base/332857 Log: Add cfumass rc script, to create a LUN for cfumass(4). MFC after: 2 weeks Relnotes: yes Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D14844 Added: head/etc/rc.d/cfumass (contents, props changed) Modified: head/etc/defaults/rc.conf head/etc/rc.d/Makefile head/share/man/man4/cfumass.4 head/share/man/man5/rc.conf.5 Modified: head/etc/defaults/rc.conf ============================================================================== --- head/etc/defaults/rc.conf Sat Apr 21 13:46:07 2018 (r332856) +++ head/etc/defaults/rc.conf Sat Apr 21 14:56:41 2018 (r332857) @@ -592,6 +592,9 @@ cron_enable="YES" # Run the periodic job daemon. cron_program="/usr/sbin/cron" # Which cron executable to run (if enabled). cron_dst="YES" # Handle DST transitions intelligently (YES/NO) cron_flags="" # Which options to pass to the cron daemon. +cfumass_enable="NO" # Create default LUN for cfumass(4). +cfumass_dir="/var/cfumass" # File to LUN's contents. +cfumass_image="/var/tmp/cfumass.img" # LUN's backing file path. lpd_enable="NO" # Run the line printer daemon. lpd_program="/usr/sbin/lpd" # path to lpd, if you want a different one. lpd_flags="" # Flags to lpd (if enabled). Modified: head/etc/rc.d/Makefile ============================================================================== --- head/etc/rc.d/Makefile Sat Apr 21 13:46:07 2018 (r332856) +++ head/etc/rc.d/Makefile Sat Apr 21 14:56:41 2018 (r332857) @@ -21,6 +21,7 @@ FILES= DAEMON \ ${_bluetooth} \ bridge \ ${_bthidd} \ + cfumass \ cleanvar \ cleartmp \ cron \ Added: head/etc/rc.d/cfumass ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/etc/rc.d/cfumass Sat Apr 21 14:56:41 2018 (r332857) @@ -0,0 +1,125 @@ +#!/bin/sh +# +# $FreeBSD$ +# + +# PROVIDE: cfumass +# REQUIRE: var +# KEYWORD: nojail + +. /etc/rc.subr + +name="cfumass" +desc="Configure the LUN for device mode USB mass storage" +rcvar="cfumass_enable" + +start_cmd="${name}_start" +stop_cmd="${name}_stop" + +extra_commands="reload" +reload_cmd="${name}_start" + +: ${cfumass_dir:=/var/cfumass} +: ${cfumass_image:=/var/tmp/cfumass.img} +: ${cfumass_vendor:="FreeBSD"} +: ${cfumass_product:="cfumass(4)"} + +remove_luns() +{ + local _lun _luns + + _luns=`ctladm devlist -b block -v | awk ' + + $1 ~ /^[0-9]+$/ { + lun = $1 + } + + $1 == "file='"${cfumass_image}"'" { + print lun + }'` + + for _lun in ${_luns}; do + ctladm remove -b block -l "${_lun}" > /dev/null + done +} + +cfumass_start() +{ + local err _files _template + + if [ ! -d "${cfumass_dir}" ]; then + warn "${cfumass_dir} does not exist" + return 1 + fi + + _files=`find "${cfumass_dir}" -newer "${cfumass_image}" -print 2> /dev/null` + if [ ! -e "${cfumass_image}" -o -n "${_files}" ]; then + # The image doesn't exist or is out of date. + makefs -t cd9660 -o rockridge "${cfumass_image}" "${cfumass_dir}" + err=$? + if [ "${err}" -ne 0 ]; then + warn "unable to create ${cfumass_image}" + return "${err}" + fi + fi + + remove_luns + + ctladm create -b block -o file="${cfumass_image}" -o readonly=on \ + -o vendor="${cfumass_vendor}" -o product="${cfumass_product}" \ + -t 5 -S 0 > /dev/null + err=$? + if [ "${err}" -ne 0 ]; then + warn "unable to create CTL LUN" + return "${err}" + fi + + load_kld -e cfumass cfumass + + # If the template is already switched to Mass Storage, then reset + # it to -1 to force the host to reenumerate it; otherwise it might + # not notice the new LUN. + _template=`sysctl -n hw.usb.template` + if [ "${_template}" -eq 0 ]; then + sysctl hw.usb.template=-1 > /dev/null + err=$? + if [ "${err}" -ne 0 ]; then + warn "unable to set hw.usb.template sysctl" + return "${err}" + fi + fi + + _template=`sysctl -n hw.usb.template` + if [ "${_template}" -lt 0 ]; then + sysctl hw.usb.template=0 > /dev/null + err=$? + if [ "${err}" -ne 0 ]; then + warn "unable to set hw.usb.template sysctl" + return "${err}" + fi + else + # Otherwise don't touch the sysctl - we could lock the user + # out of the machine otherwise. + warn "hw.usb.template sysctl set to neither -1 nor 0" + fi +} + +cfumass_stop() +{ + local err _template + + _template=`sysctl -n hw.usb.template` + if [ "${_template}" -eq 0 ]; then + sysctl hw.usb.template=-1 > /dev/null + err=$? + if [ "${err}" -ne 0 ]; then + warn "unable to set hw.usb.template sysctl" + return "${err}" + fi + fi + + remove_luns +} + +load_rc_config $name +run_rc_command "$1" Modified: head/share/man/man4/cfumass.4 ============================================================================== --- head/share/man/man4/cfumass.4 Sat Apr 21 13:46:07 2018 (r332856) +++ head/share/man/man4/cfumass.4 Sat Apr 21 14:56:41 2018 (r332857) @@ -26,7 +26,7 @@ .\" SUCH DAMAGE. .\" .\" $FreeBSD$ -.Dd April 9, 2018 +.Dd April 21, 2018 .Dt CFUMASS 4 .Os .Sh NAME @@ -88,6 +88,14 @@ See and .Xr ctld 8 for details on configuring the LUN. +See the +.Cm cfumass_enable +and +.Cm cfumass_dir +.Xr rc 8 +variables in +.Xr rc.conf 5 +for an automated way to configure it at boot. .Sh SYSCTL VARIABLES These variables are available as both .Xr sysctl 8 Modified: head/share/man/man5/rc.conf.5 ============================================================================== --- head/share/man/man5/rc.conf.5 Sat Apr 21 13:46:07 2018 (r332856) +++ head/share/man/man5/rc.conf.5 Sat Apr 21 14:56:41 2018 (r332857) @@ -24,7 +24,7 @@ .\" .\" $FreeBSD$ .\" -.Dd March 10, 2018 +.Dd April 21, 2018 .Dt RC.CONF 5 .Os .Sh NAME @@ -4482,6 +4482,18 @@ The default is which configures sessions based on the .Pa /etc/iscsi.conf configuration file. +.It Va cfumass_enable +.Pq Vt bool +If set to +.Dq Li YES , +create and export an USB LUN using +.Xr cfumass 4 +at boot time. +.It Va cfumass_dir +.Pq Vt str +The directory where the files exported by USB LUN are located. +The default directory is +.Pa /var/cfumass . .El .Sh FILES .Bl -tag -width ".Pa /etc/defaults/rc.conf" -compact