On 2013/02/14 6:58, Zach Brown wrote:
why it failed.  But it might not be able to because /proc/swaps is
fundamentally unreliable.

Then, how should we do?    I have no idea...

Hmm.  I think I'd do something like:

- First always open with O_EXCL.  If it succeeds then there's no reason
   to check /proc/swaps at all.  (Maybe it doesn't need to try
   check_mounted() there either?  Not sure if it's protecting against
   accidentally mounting mounted shared storage or not.)

check_mounted() is necessary for multiple devices, I think.


- Try stat()ing the /proc/swaps paths and the command line path.  If they
   point to the same inode then print a helpful message that the open
   might have failed because the file is an active swap file.

- Use realpath() to resolve the relative path into an absolute path.
   Copy it and escape control chars ("\n\t\\") with their \0xxx octal
   equivalents.  If the mangled absolute path matches the path in
   /proc/swaps (without opening), print the helpful message.

I think realpath() is unnecessary if it checks it by using only
stat() information. (if do not compare path)

Am I misunderstanding anything?

Thanks,
Tsutomu


- At no point is failure of any of the /proc/swaps parsing fatal.  It'd
   carry on ignoring errors until it doesnt have work to do.  It'd only
   ever print the nice message when it finds a match.

That seems reasonable to me.  It costs nothing in the vast majority of
invocations when nothing goes wrong, it doesn't *cause* problems, and
it'd print helpful messages on boring normal systems when someone really
does accidentally try and mkfs a swapfile.

In very rare cases /proc/swaps won't be of any help.  The user would
only see the open failure.  That's fine, it's just not worth worrying
about.

- z



--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to