Hello Ed and all,

Just for the sake of completeness, I dug out my implementation of
SMF services for iscsi-imported pools. As I said, it is kinda ugly
due to hardcoded things which should rather be in SMF properties
or at least in config files, but this was a single-solution POC.
Here is the client side:

1) Method script to import the "dcpool" over iscsi. It has an
optional config file that I can touch, fill or remove in order
to delay the import of the pool, and another file to disable
the import (perhaps by touching it while the sleep is in effect)
but not fail or reconfigure the SMF instance. If the latter file
is present in advance, the service is temp-disabled (reverse
dependency, see XML below). Finally, export of the pool is
retried with force until success (or SMF timeout):

$ cat /lib/svc/method/iscsi-mount-dcpool
------
#!/bin/sh

DELAY=600

case "$1" in
        start)
                if [ -f /etc/zfs/delay.dcpool ]; then
                        D="`head -1 /etc/zfs/delay.dcpool`"
                        [ "$D" -gt 0 ] 2>/dev/null && DELAY="$D" || D=10
                        echo "`date`: Delay requested... ${DELAY}sec"
                        sleep ${DELAY}
                        echo "`date`: Done sleeping"
                fi

                if [ -f /etc/zfs/noimport-dcpool ]; then
echo "`date`: /etc/zfs/noimport-dcpool block-file reappeared. Aborting."
                        exit 0
                fi

                [ -d /dcpool/export -o -f /etc/zfs/noimport-dcpool ] || \
                        ( echo "`date`: beginning dcpool import..."
                          time zpool import -o cachefile=none dcpool
                          RET=$?
                          echo "`date`: dcpool import complete ($RET)"
                          exit $RET )
                ;;
        stop)
                [ ! -d /dcpool/export ] || \
                        time zpool export dcpool || \
while ! time zpool export -f dcpool; do sleep 1; done
                ;;
esac
------



2) This script just wraps the call to original method (and
adds a small sleep) and allows me to create a separate service
and define dependencies on it - and not touch original services:

$ cat /lib/svc/method/iscsi-initiator-dcpool
-------
#!/bin/sh

case "$1" in
        start) /lib/svc/method/iscsi-initiator "$@" && sleep 10 ;;
        stop)  sleep 10 && /lib/svc/method/iscsi-initiator "$@" ;;
        *) /lib/svc/method/iscsi-initiator "$@" ;;
esac
-------



3) The XML manifests for the services:


NOTE: Startup time is unlimited, because pool processing
(deferred frees, etc.) could take days on my setup, and
the server (target) could be unaccessible for some time too.

$ cat /root/smf/iscsi_mount-dcpool.xml
-------
<?xml version='1.0'?>
<!DOCTYPE service_bundle SYSTEM '/usr/share/lib/xml/dtd/service_bundle.dtd.1'>
<service_bundle type='manifest' name='export'>
  <service name='network/iscsi/mount-dcpool' type='service' version='0'>
<dependency name='loopback' grouping='require_all' restart_on='none' type='service'>
      <service_fmri value='svc:/network/loopback'/>
    </dependency>
<dependency name='initiator-dcpool' grouping='require_all' restart_on='restart' type='service'>
      <service_fmri value='svc:/network/iscsi/initiator-dcpool:default'/>
    </dependency>
<dependency name='noimport-file' grouping='exclude_all' restart_on='refresh' type='path'>
      <service_fmri value='file://localhost/etc/zfs/noimport-dcpool'/>
    </dependency>
    <instance name='default' enabled='false'>
<exec_method name='start' type='method' exec='/lib/svc/method/iscsi-mount-dcpool %m' timeout_seconds='0'/> <exec_method name='stop' type='method' exec='/lib/svc/method/iscsi-mount-dcpool %m' timeout_seconds='600'/>
      <property_group name='startd' type='framework'>
        <propval name='duration' type='astring' value='transient'/>
      </property_group>
      <template>
        <common_name>
<loctext xml:lang='C'>import &apos;dcpool&apos; over iscsi</loctext>
        </common_name>
      </template>
    </instance>
    <stability value='Unstable'/>
  </service>
</service_bundle>
-------



$ cat /root/smf/iscsi_initiator-dcpool.xml
-------
<?xml version='1.0'?>
<!DOCTYPE service_bundle SYSTEM '/usr/share/lib/xml/dtd/service_bundle.dtd.1'>
<service_bundle type='manifest' name='export'>
<service name='network/iscsi/initiator-dcpool' type='service' version='0'>
    <create_default_instance enabled='false'/>
    <single_instance/>
<dependency name='loopback' grouping='require_any' restart_on='error' type='service'>
      <service_fmri value='svc:/network/loopback'/>
    </dependency>
<dependency name='mus' grouping='require_any' restart_on='error' type='service'>
      <service_fmri value='svc:/milestone/multi-user-server:default'/>
    </dependency>
<exec_method name='start' type='method' exec='/lib/svc/method/iscsi-initiator-dcpool %m' timeout_seconds='600'>
      <method_context>
<method_credential user='root' group='root' privileges='basic,sys_devices,sys_mount'/>
      </method_context>
    </exec_method>
<exec_method name='stop' type='method' exec='/lib/svc/method/iscsi-initiator-dcpool %m' timeout_seconds='600'>
      <method_context>
<method_credential user='root' group='root' privileges='basic,sys_devices,sys_mount'/>
      </method_context>
    </exec_method>
    <property_group name='dependents' type='framework'>
      <property name='iscsi-initiator_multi-user' type='fmri'/>
      <property name='iscsi-mount-dcpool' type='fmri'/>
    </property_group>
    <stability value='Evolving'/>
    <template>
      <common_name>
        <loctext xml:lang='C'>iSCSI initiator daemon for dcpool</loctext>
      </common_name>
      <documentation>
        <manpage title='iscsi' section='7D' manpath='/usr/share/man'/>
      </documentation>
    </template>
  </service>
</service_bundle>
-------



Maybe some of the former script's ideas can wind up into your
solution; I'm not sure if the initiator-wrapper is that useful =)

Good luck,
//Jim Klimov

_______________________________________________
zfs-discuss mailing list
zfs-discuss@opensolaris.org
http://mail.opensolaris.org/mailman/listinfo/zfs-discuss
              • ... Richard Elling
              • ... Dan Swartzendruber
              • ... Jim Klimov
              • ... Dan Swartzendruber
              • ... Jim Klimov
              • ... Edward Ned Harvey (opensolarisisdeadlongliveopensolaris)
              • ... Jim Klimov
              • ... Edward Ned Harvey (opensolarisisdeadlongliveopensolaris)
              • ... Edward Ned Harvey (opensolarisisdeadlongliveopensolaris)
              • ... Jim Klimov
              • ... Jim Klimov
              • ... Jim Klimov
              • ... Edward Ned Harvey (opensolarisisdeadlongliveopensolaris)
              • ... Timothy Coalson
              • ... Edward Ned Harvey (opensolarisisdeadlongliveopensolaris)
              • ... Timothy Coalson
  • Re: [zfs-discuss]... matthew patton

Reply via email to