From: Tsutomu Itoh <t-itoh@jp.fujitsu.com>
To: linux-btrfs@vger.kernel.org
Cc: Zach Brown <zab@redhat.com>, 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: Wed, 13 Feb 2013 13:38:21 +0900 [thread overview]
Message-ID: <511B18BD.7070706@jp.fujitsu.com> (raw)
In-Reply-To: <20130212205731.GA11872@lenny.home.zabbo.net>
Hi, All,
Thanks for advice.
On 2013/02/13 5:57, Zach Brown wrote:
>>>
>>> So, I chose this one. (read /proc/swaps)
>>
>> Sure, I think your change is good. I just think perhaps mkfs should also try
>> to open O_EXCL after all those other tests, as a last safety check.
>
> I think mkfs should first try an O_EXCL open. If that works it doesn't
> need to do any of this work to try and predict if the open will fail.
>
> After it fails it can poke around a bit to try and give nice context for
> 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...
>
>>>>> file = av[optind++];
>>>>> + ret = is_swap_device(file);
>
> The input string is a CWD-realtive path. You'd at least want to use
> realpath() to get it to a canonical name. So it's not full of junk like
> "./" and "../../.." which won't be present in /proc/swaps.
>
>>>>> + char buf[1024];
>
> Use PATH_MAX so it doesn't fail on absurd but allowed file names.
> (Where on earth does 1024 come from?)
>
>>>>> + if ((f = fopen("/proc/swaps", "r")) == NULL)
>>>>> + return -errno;
>
> As was pointed out, there's no reason this failure should stop mkfs.
> /proc/swaps might not be available or allowed and I should still be able
> to do an unpriviledged "./mkfs ./myfile; ./btrfs-debug-tree ./myfile".
>
>>>>> + if (strcmp(file, buf) == 0) {
>>>>> + ret = 1;
>>>>> + break;
>>>>> + }
>
> The command line path that lead to the inode might not be the path for
> the inode that is in /proc/swaps. Bind mounts, chroot, name spaces,
> hard links, etc, all make it possible -- though unlikely -- that mkfs
> simply won't be able to tell if the path names are related.
OK. I agree.
>
> Also, /proc/swaps escapes whitespace in file names. So you could be
> comparing "swap file" with "swap\040file".
I had forgotten this. Thank you for pointing it out.
>
>>>>> + if ((stat(buf, &st_buf) == 0) && S_ISBLK(st_buf.st_mode) &&
>>>>> + rdev == st_buf.st_rdev) {
>>>>> + ret = 1;
>>>>> + break;
>>>>> + }
>
> One possible alternative is to then try and open every swap file path to
> see if it points to the same inode as the path mkfs was given. But you
> might not have access to the paths and we're back to the unpriviledged
> failure case.
I want to think about a new patch later. and, I will post it again if it
seems to make a sense.
Thanks,
Tsutomu
next prev parent reply other threads:[~2013-02-13 4:38 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 [this message]
2013-02-13 21:58 ` Zach Brown
2013-02-14 0:03 ` Tsutomu Itoh
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=511B18BD.7070706@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.