Linux Btrfs filesystem development
 help / color / mirror / Atom feed
From: Tsutomu Itoh <t-itoh@jp.fujitsu.com>
To: Zach Brown <zab@redhat.com>
Cc: linux-btrfs@vger.kernel.org, Eric Sandeen <sandeen@redhat.com>,
	chris.mason@fusionio.com, dsterba@suse.cz, kreijack@gmail.com
Subject: Re: [PATCH] Btrfs-progs: check out if the swap device
Date: Thu, 14 Feb 2013 09:03:03 +0900	[thread overview]
Message-ID: <511C29B7.9060805@jp.fujitsu.com> (raw)
In-Reply-To: <20130213215833.GC22221@lenny.home.zabbo.net>

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




  reply	other threads:[~2013-02-14  0:03 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-02-12  1:25 [PATCH] Btrfs-progs: check out if the swap device Tsutomu Itoh
2013-02-12  4:22 ` Eric Sandeen
2013-02-12  5:50   ` Tsutomu Itoh
2013-02-12 17:55     ` Eric Sandeen
2013-02-12 20:57       ` Zach Brown
2013-02-13  4:38         ` Tsutomu Itoh
2013-02-13 21:58           ` Zach Brown
2013-02-14  0:03             ` Tsutomu Itoh [this message]
2013-02-14  5:35               ` Zach Brown
2013-02-12 15:06 ` David Sterba
2013-02-12 18:14 ` Goffredo Baroncelli

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=511C29B7.9060805@jp.fujitsu.com \
    --to=t-itoh@jp.fujitsu.com \
    --cc=chris.mason@fusionio.com \
    --cc=dsterba@suse.cz \
    --cc=kreijack@gmail.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=sandeen@redhat.com \
    --cc=zab@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox