From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jan Hudec Subject: Re: changing d_parent Date: Mon, 19 May 2003 08:07:11 +0200 Sender: linux-fsdevel-owner@vger.kernel.org Message-ID: <20030519060711.GA944@vagabond> References: <3EC7C605.DB4BA3ED@free.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: linux-fsdevel@vger.kernel.org Return-path: Received: from cimice4.lam.cz ([212.71.168.94]:46583 "EHLO vagabond.cybernet.cz") by vger.kernel.org with ESMTP id S261959AbTESFy2 (ORCPT ); Mon, 19 May 2003 01:54:28 -0400 To: Jerome de Vivie Content-Disposition: inline In-Reply-To: <3EC7C605.DB4BA3ED@free.fr> List-Id: linux-fsdevel.vger.kernel.org On Sun, May 18, 2003 at 07:42:29PM +0200, Jerome de Vivie wrote: > > I would like to change the "d_parent" field of a dentry. This is for > shrinking entry equivalent to a "./" in my filesystem namespace. > > The dentry has just been allocated and has no child. I'm new to the > dcache and i would like to know if thoses lines are is safe: > > spin_lock(&dcache_lock); > list_del(&dentry->d_child); > dput(dentry->d_parent); > dentry->d_parent = dget(newparent); > list_add(&dentry->d_child, &newparent->d_subdirs); > spin_unlock(&dcache_lock); One thing that comes to mind, the dentry must not be hashed and you need to hash it at some point (d_rehash()) (IIRC it does not work on hashed dentries). Another thing is, that dput may lock dcache_lock, so it must be only called after you release it. Also note the difference of dget and dget_locked. None of them locks dcache_lock, but dget only gets a dentry you already hold (remember, you are not expected to hold dcache_lock), while dget_locked can get a dentry you just found in child list/hash. I wonder what you are really doing. You should never ever need to mess with . and .., since lookup deals with them for you. ------------------------------------------------------------------------------- Jan 'Bulb' Hudec