Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 09 Apr 2001 13:04:34 -0700 (PDT)
From:      John Baldwin <jhb@FreeBSD.org>
To:        Terry Lambert <tlambert@primenet.com>
Cc:        freebsd-arch@FreeBSD.org, (Matt Dillon) <dillon@earth.backplane.com>, (Robert Watson) <rwatson@FreeBSD.org>
Subject:   Re: Eliminate crget() from nfs kernel code?
Message-ID:  <XFMail.010409130434.jhb@FreeBSD.org>
In-Reply-To: <200104062308.QAA05544@usr01.primenet.com>

next in thread | previous in thread | raw e-mail | index | archive | help

On 06-Apr-01 Terry Lambert wrote:
>>      make the NFS RPC with an existing credential
> 
>       instantiate a credential
>       make the NFS RPC
>       <hang for a long time>
>       <kill the process>
>       <destroy the credential holder entirely>
>       free the credential
> 
>> into the implementation, and it is valid for the durection of the function
>> call.  If the NFS implementation needs to preserve the credential, it will
>> do so by bumping the reference count.
> 
> It was not clear to me from a casual perusal of the code whether
> or not holding a reference to a credential used by a process would
> keep it from going away, or if it always went away on the 1->0
> decrement.

Geez, that must've been _real_ casual, Terry. :)

/*
 * Free a cred structure.
 * Throws away space when ref count gets to 0.
 */
void
crfree(cr)
        struct ucred *cr;
{

        mtx_lock(&cr->cr_mtx);
        if (--cr->cr_ref == 0) {
                mtx_destroy(&cr->cr_mtx);
                ....

                FREE((caddr_t)cr, M_CRED);
        } else {
                mtx_unlock(&cr->cr_mtx);
        }
}

Come on, even the comment indicates that it does that. :)

> It seems to me that credential instantiation becomes a problem, and
> it also seems to me that this is what you are trying to fix with
> your changes elsewhere.
> 
> Eventually, the credential has to come from somewhere, and to come
> from somewhere, it has to be allocated.

Erm, have you worked with refcount'd things before?  :-P  We malloc a new
copy in crdup() (which can be called by crcopy if needed) and we only free when
the refcount goes to zero.  By bumping the refcount around the RPC, the cred
stays valid until the crfree() after the RPC returns, even if the process
terminates and goes away.  Really, this isn't rocket science.

-- 

John Baldwin <jhb@FreeBSD.org> -- http://www.FreeBSD.org/~jhb/
PGP Key: http://www.baldwin.cx/~john/pgpkey.asc
"Power Users Use the Power to Serve!"  -  http://www.FreeBSD.org/

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-arch" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?XFMail.010409130434.jhb>