From mboxrd@z Thu Jan 1 00:00:00 1970 From: Greg KH Subject: Re: Some way of telling which block devices are in use (and how) Date: Sun, 29 Apr 2012 13:18:30 -0700 Message-ID: <20120429201830.GA10188@kroah.com> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: linux-fsdevel@vger.kernel.org, Al Viro To: Theodore Ts'o Return-path: Received: from mail-pz0-f51.google.com ([209.85.210.51]:37253 "EHLO mail-pz0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753762Ab2D2UXl (ORCPT ); Sun, 29 Apr 2012 16:23:41 -0400 Received: by dadz8 with SMTP id z8so3216183dad.10 for ; Sun, 29 Apr 2012 13:23:40 -0700 (PDT) Content-Disposition: inline In-Reply-To: Sender: linux-fsdevel-owner@vger.kernel.org List-ID: On Sun, Apr 29, 2012 at 02:57:11PM -0400, Theodore Ts'o wrote: > > It would be useful if there was a way to be able to determine, > conclusively, whether a partciular block is in device, and how (i.e., > whether some process has the block open, or it is mounted, or it is > being used as part of a device mapper, or md setup, etc.). > > That way when users complain that trying to open a particular device in > exclusive mode returns EBUSY, there's an easy way to figure out why this > might be the case. The lsof program works for the first method, but it > doesn't help for the other cases; and using /proc/mounts doesn't help if > the block device is mounted in some other namespace; you could try to > look at /proc/*/mounts for every single process, but that's exquisitely > painful, and only works for block devices used by mounted file systems. > > So the question is, what's the best way of doing this? Adding a new > flags field after the block device name in /proc/partitions would be the > simplest, but that might break some userspace programs that aren't > expecting it. There's the holders directory in sysfs, i.e., > /sys/dev/block/8:5/holders/*, but that only seems to only record usage > by device mapper. > > Should we extend the holders directory in the block device directory in > sysfs? Add a new directory to record when a file system might be > mounted? Add a new /proc file? Don't we already have a way to do all of this through sysfs today? How does gnome/kde handle this when you try to eject a device with an active mount that is busy? It pops up a dialog telling you why this can't be ejected, and which device it is. I think everything you want is already there, if not, perhaps dm just needs to add a few more sysfs links to tie it all together. And no, no more /proc files for filesystem stuff like this, that way lies madness. thanks, greg k-h