Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752743AbbL1Uvk (ORCPT ); Mon, 28 Dec 2015 15:51:40 -0500 Received: from mail-ob0-f178.google.com ([209.85.214.178]:32978 "EHLO mail-ob0-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752437AbbL1Uvd (ORCPT ); Mon, 28 Dec 2015 15:51:33 -0500 MIME-Version: 1.0 Reply-To: rajatxjain@gmail.com In-Reply-To: <20151228203121.GA19753@kroah.com> References: <20151228203121.GA19753@kroah.com> Date: Mon, 28 Dec 2015 12:51:32 -0800 Message-ID: Subject: Re: debugfs_remove_recursive() while a file is in use by userspace From: Rajat Jain To: Greg Kroah-Hartman Cc: "linux-kernel@vger.kernel.org" , linux-newbie@vger.kernel.org Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2167 Lines: 63 Thanks Greg and Al for the quick turnaround. Essentially I have a device that supports something called "contexts" that can be "created" and "destroyed" during the life of the device. I want to expose some debug files for the context when it is created, and destroy the files when the context is destroyed. However, I'm not sure how do I ensure that the user is not in the middle of reading / writing / mmaping to those files. Also how do I know that user is still not holding a reference to the file structure. It seems like debugfs is currently not a good choice for this? Would you recommend me to any other fs or subsystem that I should use for this? Would hanging those files under the sysfs node for the device sound any better (by representing each "context" using an embedded kobject)? Thanks, Rajat On Mon, Dec 28, 2015 at 12:31 PM, Greg Kroah-Hartman wrote: > On Mon, Dec 28, 2015 at 12:27:22PM -0800, Rajat Jain wrote: >> Hi, >> >> I wanted to understand the behavior taken when a module calls >> debugfs_remove_recursive() on a directory, while files under that >> directory may still be in use by the userspace (for instance an >> ongoing read / write operation). > > Bad things :( > >> Does the function wait >> >> (1) until all the currently executing file operation methods >> (read/write/map etc) have returned? > > Nope. > >> OR >> (2) until the user has given up all references (descriptors) to the >> files under the directory (i.e. until release() method has been >> called)? > > Nope. > > There are some patches on the mailing list that I need to review that > hopefully should resolve this problem, as it's been known for a very > long time. > > In short, just don't remove debugfs files unless your module is > unloading, and all should be good as modules are never auto-unloaded. > If you remove debugfs files when a device is removed, be careful. > > thanks, > > greg k-h -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/