Sunday, May 16, 2010

NFS version 3 on FreeBSD using unfsd

Introduction


I have had some problems reading files larger than 2 gb through nfs2. It is afaik a limitation of the standard it self. Therefore it is necessary to look at some of the later versions of this protocol for file operations on larger files.

I am not sure what the current standard in FreeBSD is (version 7.x.x) since I am still using the version 6 of FreeBSD. However this setup should also work with later versions of the OS.

Software installation

You should add the unfsd daemon using the ports collection or add it via a precompiled package. If you follow the attached link to this blog entry, it links to the installation page on freshports.org.

Subsequent configuration

The installation package does not include a rc script to start and stop the daemon, so i modified the system one in /etc/rc.d/nfsd to fit unfsd in /usr/local/etc/rc.d.

This is the rc file

# PROVIDE: unfsd
# REQUIRE: mountd
# KEYWORD: nojail

. /etc/rc.subr

name="unfsd"
rcvar=`set_rcvar unfs_server`
command="/usr/local/sbin/${name}"

load_rc_config $name
command_args="${unfs_server_flags}"
exports="${unfs_server_exports}"
pidfile=/var/run/${name}.pid
start_precmd="unfsd_precmd"
stop_cmd="unfsd_stop_cmd"
start_cmd="unfsd_start_cmd"
sig_stop="USR1"

unfsd_precmd()
{
    if ! sysctl vfs.nfsrv >/dev/null 2>&1; then
        force_depend nfsserver || return 1
    fi

    if ! checkyesno rpcbind_enable  && \
        ! /etc/rc.d/rpcbind forcestatus 1>/dev/null 2>&1
    then
        force_depend rpcbind || return 1
    fi

    if ! checkyesno mountd_enable  && \
        ! /etc/rc.d/mountd forcestatus 1>/dev/null 2>&1
    then
        force_depend mountd || return 1
    fi

    if checkyesno nfs_reserved_port_only; then
        echo 'NFS on reserved port only=YES'
        sysctl vfs.nfsrv.nfs_privport=1 > /dev/null
    fi
    return 0
}

unfsd_start_cmd()
{
    $command -e $exports -i $pidfile $command_args
}

unfsd_stop_cmd()
{
    if [ -f "$pidfile" ] ; then
        kill `cat ${pidfile}`
    fi
}

run_rc_command "$1"

This is the entries needed in /etc/rc.conf

unfs_server_enable="YES"
unfs_server_exports="/etc/uexports"

You should then add a /etc/uexports file to fit the format of unfsd. It is different from the system supplied nfsd from FreeBSD, so I suggest using a seperate file for this. In that way a rollback to the old version is a matter of re enabling it in rc.conf.

If you do not specify a named export file the unfsd will parse /etc/exports, and that will not work unless you edit it to fit the unfsd format.

Man unfsd will give you some examples of the format.

Conclusion

This will make it possible for you to use 2 gig plus files with nfs. In addition you will be able to use larger read and write sizes if you so choose.

No comments:

Post a Comment