* [Cluster-devel] [PATCH] mkfs.gfs2: Follow symlinks before checking device contents
@ 2012-06-20 15:47 Andrew Price
2012-06-20 16:15 ` Bob Peterson
2012-06-28 9:16 ` Steven Whitehouse
0 siblings, 2 replies; 10+ messages in thread
From: Andrew Price @ 2012-06-20 15:47 UTC (permalink / raw)
To: cluster-devel.redhat.com
When using symlinks with mkfs.gfs2 it reports what the symlink points
to instead of the contents of the device, like so:
# ./mkfs.gfs2 -p lock_nolock /dev/vg/test
This will destroy any data on /dev/vg/test.
It appears to contain: symbolic link to `../dm-3'
This patch resolves symlinks before checking the device contents to make
the output more informative:
# ./mkfs.gfs2 -p lock_nolock /dev/vg/test
This will destroy any data on /dev/vg/test.
It appears to contain: GFS2 Filesystem (blocksize 4096, lockproto lock_nolock)
Signed-off-by: Andrew Price <anprice@redhat.com>
---
gfs2/mkfs/main_mkfs.c | 9 ++++++++-
1 files changed, 8 insertions(+), 1 deletions(-)
diff --git a/gfs2/mkfs/main_mkfs.c b/gfs2/mkfs/main_mkfs.c
index e6b00a0..f8e4741 100644
--- a/gfs2/mkfs/main_mkfs.c
+++ b/gfs2/mkfs/main_mkfs.c
@@ -531,6 +531,7 @@ void main_mkfs(int argc, char *argv[])
int error;
int rgsize_specified = 0;
unsigned char uuid[16];
+ char *absname;
memset(sdp, 0, sizeof(struct gfs2_sbd));
sdp->bsize = -1;
@@ -560,11 +561,17 @@ void main_mkfs(int argc, char *argv[])
exit(EXIT_FAILURE);
}
+ absname = canonicalize_file_name(sdp->device_name);
+ if (absname == NULL) {
+ perror(_("Could not find the absolute path of the device"));
+ exit(EXIT_FAILURE);
+ }
if (!sdp->override) {
printf( _("This will destroy any data on %s.\n"), sdp->device_name);
- check_dev_content(sdp->device_name);
+ check_dev_content(absname);
are_you_sure();
}
+ free(absname);
if (sdp->bsize == -1) {
if (S_ISREG(sdp->dinfo.stat.st_mode))
--
1.7.7.6
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [Cluster-devel] [PATCH] mkfs.gfs2: Follow symlinks before checking device contents
2012-06-20 15:47 [Cluster-devel] [PATCH] mkfs.gfs2: Follow symlinks before checking device contents Andrew Price
@ 2012-06-20 16:15 ` Bob Peterson
2012-06-20 17:27 ` Fabio M. Di Nitto
2012-06-20 17:42 ` Andrew Price
2012-06-28 9:16 ` Steven Whitehouse
1 sibling, 2 replies; 10+ messages in thread
From: Bob Peterson @ 2012-06-20 16:15 UTC (permalink / raw)
To: cluster-devel.redhat.com
----- Original Message -----
| + absname = canonicalize_file_name(sdp->device_name);
Hi Andy,
Thanks for the patch. I just wanted to point out that in the past we've
used realpath rather than canonicalize_file_name. For example, see this patch
we did a long time ago to gfs2_tool:
http://git.fedorahosted.org/git/?p=cluster.git;a=commitdiff;h=e70898cfa09939a7100a057433fff3a4ad666bdd
It would be nice if our use was consistent. I'm not sure if there's an
advantage of one over the other. If canonicalize_file_name is now preferred
upstream over realpath, we should probably replace all occurrences of that.
On the other hand, if realpath is now preferred upstream, we should adjust
this patch to use it instead. AFAIK, they are the same, and I don't have a
personal preference; whatever is most favoured by the upstream community. :)
Otherwise, the patch looks good.
Regards,
Bob Peterson
Red Hat File Systems
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Cluster-devel] [PATCH] mkfs.gfs2: Follow symlinks before checking device contents
2012-06-20 16:15 ` Bob Peterson
@ 2012-06-20 17:27 ` Fabio M. Di Nitto
2012-06-20 17:42 ` Andrew Price
1 sibling, 0 replies; 10+ messages in thread
From: Fabio M. Di Nitto @ 2012-06-20 17:27 UTC (permalink / raw)
To: cluster-devel.redhat.com
Hi,
On 6/20/2012 6:15 PM, Bob Peterson wrote:
> ----- Original Message -----
> | + absname = canonicalize_file_name(sdp->device_name);
>
> Hi Andy,
>
> Thanks for the patch. I just wanted to point out that in the past we've
> used realpath rather than canonicalize_file_name. For example, see this patch
> we did a long time ago to gfs2_tool:
>
> http://git.fedorahosted.org/git/?p=cluster.git;a=commitdiff;h=e70898cfa09939a7100a057433fff3a4ad666bdd
>
> It would be nice if our use was consistent. I'm not sure if there's an
> advantage of one over the other. If canonicalize_file_name is now preferred
> upstream over realpath, we should probably replace all occurrences of that.
>
> On the other hand, if realpath is now preferred upstream, we should adjust
> this patch to use it instead. AFAIK, they are the same, and I don't have a
> personal preference; whatever is most favoured by the upstream community. :)
>
> Otherwise, the patch looks good.
I don?t remember what other mkfs.* tools do, but if I would prefer to
see something like:
# ./mkfs.gfs2 -p lock_nolock /dev/vg/test
WARNING: /dev/vg/test appears to be a symlink to /dev/real/device
This will destroy any data on /dev/real/device
It appears to contain: RANDOM_FS_OF_DOOM (blocksize......)
Fabio
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Cluster-devel] [PATCH] mkfs.gfs2: Follow symlinks before checking device contents
2012-06-20 16:15 ` Bob Peterson
2012-06-20 17:27 ` Fabio M. Di Nitto
@ 2012-06-20 17:42 ` Andrew Price
1 sibling, 0 replies; 10+ messages in thread
From: Andrew Price @ 2012-06-20 17:42 UTC (permalink / raw)
To: cluster-devel.redhat.com
Hi Bob,
On 20/06/12 17:15, Bob Peterson wrote:
> ----- Original Message -----
> | + absname = canonicalize_file_name(sdp->device_name);
>
> Hi Andy,
>
> Thanks for the patch. I just wanted to point out that in the past we've
> used realpath rather than canonicalize_file_name. For example, see this patch
> we did a long time ago to gfs2_tool:
>
> http://git.fedorahosted.org/git/?p=cluster.git;a=commitdiff;h=e70898cfa09939a7100a057433fff3a4ad666bdd
Hmm those uses of realpath seem to have disappeared since.
> It would be nice if our use was consistent. I'm not sure if there's an
> advantage of one over the other. If canonicalize_file_name is now preferred
> upstream over realpath, we should probably replace all occurrences of that.
>
> On the other hand, if realpath is now preferred upstream, we should adjust
> this patch to use it instead. AFAIK, they are the same, and I don't have a
> personal preference; whatever is most favoured by the upstream community. :)
I couldn't find any strong arguments in preference of either function
and we're already using _GNU_SOURCE extensions so there's no added
portability issue. In the current state of gfs2-utils.git we're only
using realpath twice, in gfs2_quota, so I don't think there's a strong
consistency argument either. I'll push this one as-is in the morning
unless someone can provide a convincing reason to use realpath :)
> Otherwise, the patch looks good.
Thanks for the review,
Andy
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Cluster-devel] [PATCH] mkfs.gfs2: Follow symlinks before checking device contents
2012-06-20 15:47 [Cluster-devel] [PATCH] mkfs.gfs2: Follow symlinks before checking device contents Andrew Price
2012-06-20 16:15 ` Bob Peterson
@ 2012-06-28 9:16 ` Steven Whitehouse
2012-06-28 9:58 ` Andrew Price
1 sibling, 1 reply; 10+ messages in thread
From: Steven Whitehouse @ 2012-06-28 9:16 UTC (permalink / raw)
To: cluster-devel.redhat.com
Hi,
Looks good. ACK,
Steve.
On Wed, 2012-06-20 at 16:47 +0100, Andrew Price wrote:
> When using symlinks with mkfs.gfs2 it reports what the symlink points
> to instead of the contents of the device, like so:
>
> # ./mkfs.gfs2 -p lock_nolock /dev/vg/test
> This will destroy any data on /dev/vg/test.
> It appears to contain: symbolic link to `../dm-3'
>
> This patch resolves symlinks before checking the device contents to make
> the output more informative:
>
> # ./mkfs.gfs2 -p lock_nolock /dev/vg/test
> This will destroy any data on /dev/vg/test.
> It appears to contain: GFS2 Filesystem (blocksize 4096, lockproto lock_nolock)
>
> Signed-off-by: Andrew Price <anprice@redhat.com>
> ---
> gfs2/mkfs/main_mkfs.c | 9 ++++++++-
> 1 files changed, 8 insertions(+), 1 deletions(-)
>
> diff --git a/gfs2/mkfs/main_mkfs.c b/gfs2/mkfs/main_mkfs.c
> index e6b00a0..f8e4741 100644
> --- a/gfs2/mkfs/main_mkfs.c
> +++ b/gfs2/mkfs/main_mkfs.c
> @@ -531,6 +531,7 @@ void main_mkfs(int argc, char *argv[])
> int error;
> int rgsize_specified = 0;
> unsigned char uuid[16];
> + char *absname;
>
> memset(sdp, 0, sizeof(struct gfs2_sbd));
> sdp->bsize = -1;
> @@ -560,11 +561,17 @@ void main_mkfs(int argc, char *argv[])
> exit(EXIT_FAILURE);
> }
>
> + absname = canonicalize_file_name(sdp->device_name);
> + if (absname == NULL) {
> + perror(_("Could not find the absolute path of the device"));
> + exit(EXIT_FAILURE);
> + }
> if (!sdp->override) {
> printf( _("This will destroy any data on %s.\n"), sdp->device_name);
> - check_dev_content(sdp->device_name);
> + check_dev_content(absname);
> are_you_sure();
> }
> + free(absname);
>
> if (sdp->bsize == -1) {
> if (S_ISREG(sdp->dinfo.stat.st_mode))
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Cluster-devel] [PATCH] mkfs.gfs2: Follow symlinks before checking device contents
2012-06-28 9:16 ` Steven Whitehouse
@ 2012-06-28 9:58 ` Andrew Price
2012-06-28 10:01 ` Steven Whitehouse
0 siblings, 1 reply; 10+ messages in thread
From: Andrew Price @ 2012-06-28 9:58 UTC (permalink / raw)
To: cluster-devel.redhat.com
Hi Steve,
On 06/28/2012 10:16 AM, Steven Whitehouse wrote:
> Hi,
>
> Looks good. ACK,
This one was obsoleted by the v2 patch I posted on the 21st. If you
prefer this one though I can push it instead.
Andy
>
> Steve.
>
> On Wed, 2012-06-20 at 16:47 +0100, Andrew Price wrote:
>> When using symlinks with mkfs.gfs2 it reports what the symlink points
>> to instead of the contents of the device, like so:
>>
>> # ./mkfs.gfs2 -p lock_nolock /dev/vg/test
>> This will destroy any data on /dev/vg/test.
>> It appears to contain: symbolic link to `../dm-3'
>>
>> This patch resolves symlinks before checking the device contents to make
>> the output more informative:
>>
>> # ./mkfs.gfs2 -p lock_nolock /dev/vg/test
>> This will destroy any data on /dev/vg/test.
>> It appears to contain: GFS2 Filesystem (blocksize 4096, lockproto lock_nolock)
>>
>> Signed-off-by: Andrew Price <anprice@redhat.com>
>> ---
>> gfs2/mkfs/main_mkfs.c | 9 ++++++++-
>> 1 files changed, 8 insertions(+), 1 deletions(-)
>>
>> diff --git a/gfs2/mkfs/main_mkfs.c b/gfs2/mkfs/main_mkfs.c
>> index e6b00a0..f8e4741 100644
>> --- a/gfs2/mkfs/main_mkfs.c
>> +++ b/gfs2/mkfs/main_mkfs.c
>> @@ -531,6 +531,7 @@ void main_mkfs(int argc, char *argv[])
>> int error;
>> int rgsize_specified = 0;
>> unsigned char uuid[16];
>> + char *absname;
>>
>> memset(sdp, 0, sizeof(struct gfs2_sbd));
>> sdp->bsize = -1;
>> @@ -560,11 +561,17 @@ void main_mkfs(int argc, char *argv[])
>> exit(EXIT_FAILURE);
>> }
>>
>> + absname = canonicalize_file_name(sdp->device_name);
>> + if (absname == NULL) {
>> + perror(_("Could not find the absolute path of the device"));
>> + exit(EXIT_FAILURE);
>> + }
>> if (!sdp->override) {
>> printf( _("This will destroy any data on %s.\n"), sdp->device_name);
>> - check_dev_content(sdp->device_name);
>> + check_dev_content(absname);
>> are_you_sure();
>> }
>> + free(absname);
>>
>> if (sdp->bsize == -1) {
>> if (S_ISREG(sdp->dinfo.stat.st_mode))
>
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Cluster-devel] [PATCH] mkfs.gfs2: Follow symlinks before checking device contents
2012-06-28 9:58 ` Andrew Price
@ 2012-06-28 10:01 ` Steven Whitehouse
2012-06-28 17:52 ` Andrew Price
0 siblings, 1 reply; 10+ messages in thread
From: Steven Whitehouse @ 2012-06-28 10:01 UTC (permalink / raw)
To: cluster-devel.redhat.com
Hi,
Yes, v2 is ok too. I think I missed that in my first pass over my email
today. To do this properly, we should be opening the path that we are
passed, and then doing the remaining operations with just the fd. We
could do that with "file" if we used the -f - option and passed the fd
as standard input to the process.
That way we also remove any possible race conditions too, but this is
good enough for now,
Steve.
On Thu, 2012-06-28 at 10:58 +0100, Andrew Price wrote:
> Hi Steve,
>
> On 06/28/2012 10:16 AM, Steven Whitehouse wrote:
> > Hi,
> >
> > Looks good. ACK,
>
> This one was obsoleted by the v2 patch I posted on the 21st. If you
> prefer this one though I can push it instead.
>
> Andy
>
> >
> > Steve.
> >
> > On Wed, 2012-06-20 at 16:47 +0100, Andrew Price wrote:
> >> When using symlinks with mkfs.gfs2 it reports what the symlink points
> >> to instead of the contents of the device, like so:
> >>
> >> # ./mkfs.gfs2 -p lock_nolock /dev/vg/test
> >> This will destroy any data on /dev/vg/test.
> >> It appears to contain: symbolic link to `../dm-3'
> >>
> >> This patch resolves symlinks before checking the device contents to make
> >> the output more informative:
> >>
> >> # ./mkfs.gfs2 -p lock_nolock /dev/vg/test
> >> This will destroy any data on /dev/vg/test.
> >> It appears to contain: GFS2 Filesystem (blocksize 4096, lockproto lock_nolock)
> >>
> >> Signed-off-by: Andrew Price <anprice@redhat.com>
> >> ---
> >> gfs2/mkfs/main_mkfs.c | 9 ++++++++-
> >> 1 files changed, 8 insertions(+), 1 deletions(-)
> >>
> >> diff --git a/gfs2/mkfs/main_mkfs.c b/gfs2/mkfs/main_mkfs.c
> >> index e6b00a0..f8e4741 100644
> >> --- a/gfs2/mkfs/main_mkfs.c
> >> +++ b/gfs2/mkfs/main_mkfs.c
> >> @@ -531,6 +531,7 @@ void main_mkfs(int argc, char *argv[])
> >> int error;
> >> int rgsize_specified = 0;
> >> unsigned char uuid[16];
> >> + char *absname;
> >>
> >> memset(sdp, 0, sizeof(struct gfs2_sbd));
> >> sdp->bsize = -1;
> >> @@ -560,11 +561,17 @@ void main_mkfs(int argc, char *argv[])
> >> exit(EXIT_FAILURE);
> >> }
> >>
> >> + absname = canonicalize_file_name(sdp->device_name);
> >> + if (absname == NULL) {
> >> + perror(_("Could not find the absolute path of the device"));
> >> + exit(EXIT_FAILURE);
> >> + }
> >> if (!sdp->override) {
> >> printf( _("This will destroy any data on %s.\n"), sdp->device_name);
> >> - check_dev_content(sdp->device_name);
> >> + check_dev_content(absname);
> >> are_you_sure();
> >> }
> >> + free(absname);
> >>
> >> if (sdp->bsize == -1) {
> >> if (S_ISREG(sdp->dinfo.stat.st_mode))
> >
> >
>
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Cluster-devel] [PATCH] mkfs.gfs2: Follow symlinks before checking device contents
2012-06-28 10:01 ` Steven Whitehouse
@ 2012-06-28 17:52 ` Andrew Price
2012-07-04 11:02 ` Andrew Price
0 siblings, 1 reply; 10+ messages in thread
From: Andrew Price @ 2012-06-28 17:52 UTC (permalink / raw)
To: cluster-devel.redhat.com
On 06/28/2012 11:01 AM, Steven Whitehouse wrote:
> Hi,
>
> Yes, v2 is ok too. I think I missed that in my first pass over my email
> today. To do this properly, we should be opening the path that we are
> passed, and then doing the remaining operations with just the fd. We
> could do that with "file" if we used the -f - option and passed the fd
> as standard input to the process.
The only way I can think of passing the fd to file -f - would be the C
equivalent of:
printf "/proc/$pid/fd/$fd" | file -f -
Which would mean adding another pipe() and fork(). So we might as well
just shorten it to:
file "/proc/$pid/fd/$fd"
Would this solve the race condition problem? Or am I misunderstanding
how you intended it to be done?
Andy
> That way we also remove any possible race conditions too, but this is
> good enough for now,
>
> Steve.
>
>
> On Thu, 2012-06-28 at 10:58 +0100, Andrew Price wrote:
>> Hi Steve,
>>
>> On 06/28/2012 10:16 AM, Steven Whitehouse wrote:
>>> Hi,
>>>
>>> Looks good. ACK,
>>
>> This one was obsoleted by the v2 patch I posted on the 21st. If you
>> prefer this one though I can push it instead.
>>
>> Andy
>>
>>>
>>> Steve.
>>>
>>> On Wed, 2012-06-20 at 16:47 +0100, Andrew Price wrote:
>>>> When using symlinks with mkfs.gfs2 it reports what the symlink points
>>>> to instead of the contents of the device, like so:
>>>>
>>>> # ./mkfs.gfs2 -p lock_nolock /dev/vg/test
>>>> This will destroy any data on /dev/vg/test.
>>>> It appears to contain: symbolic link to `../dm-3'
>>>>
>>>> This patch resolves symlinks before checking the device contents to make
>>>> the output more informative:
>>>>
>>>> # ./mkfs.gfs2 -p lock_nolock /dev/vg/test
>>>> This will destroy any data on /dev/vg/test.
>>>> It appears to contain: GFS2 Filesystem (blocksize 4096, lockproto lock_nolock)
>>>>
>>>> Signed-off-by: Andrew Price <anprice@redhat.com>
>>>> ---
>>>> gfs2/mkfs/main_mkfs.c | 9 ++++++++-
>>>> 1 files changed, 8 insertions(+), 1 deletions(-)
>>>>
>>>> diff --git a/gfs2/mkfs/main_mkfs.c b/gfs2/mkfs/main_mkfs.c
>>>> index e6b00a0..f8e4741 100644
>>>> --- a/gfs2/mkfs/main_mkfs.c
>>>> +++ b/gfs2/mkfs/main_mkfs.c
>>>> @@ -531,6 +531,7 @@ void main_mkfs(int argc, char *argv[])
>>>> int error;
>>>> int rgsize_specified = 0;
>>>> unsigned char uuid[16];
>>>> + char *absname;
>>>>
>>>> memset(sdp, 0, sizeof(struct gfs2_sbd));
>>>> sdp->bsize = -1;
>>>> @@ -560,11 +561,17 @@ void main_mkfs(int argc, char *argv[])
>>>> exit(EXIT_FAILURE);
>>>> }
>>>>
>>>> + absname = canonicalize_file_name(sdp->device_name);
>>>> + if (absname == NULL) {
>>>> + perror(_("Could not find the absolute path of the device"));
>>>> + exit(EXIT_FAILURE);
>>>> + }
>>>> if (!sdp->override) {
>>>> printf( _("This will destroy any data on %s.\n"), sdp->device_name);
>>>> - check_dev_content(sdp->device_name);
>>>> + check_dev_content(absname);
>>>> are_you_sure();
>>>> }
>>>> + free(absname);
>>>>
>>>> if (sdp->bsize == -1) {
>>>> if (S_ISREG(sdp->dinfo.stat.st_mode))
>>>
>>>
>>
>>
>
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Cluster-devel] [PATCH] mkfs.gfs2: Follow symlinks before checking device contents
2012-06-28 17:52 ` Andrew Price
@ 2012-07-04 11:02 ` Andrew Price
2012-07-04 11:15 ` Steven Whitehouse
0 siblings, 1 reply; 10+ messages in thread
From: Andrew Price @ 2012-07-04 11:02 UTC (permalink / raw)
To: cluster-devel.redhat.com
On 06/28/2012 06:52 PM, Andrew Price wrote:
> On 06/28/2012 11:01 AM, Steven Whitehouse wrote:
>> Hi,
>>
>> Yes, v2 is ok too. I think I missed that in my first pass over my email
>> today. To do this properly, we should be opening the path that we are
>> passed, and then doing the remaining operations with just the fd. We
>> could do that with "file" if we used the -f - option and passed the fd
>> as standard input to the process.
>
> The only way I can think of passing the fd to file -f - would be the C
> equivalent of:
>
> printf "/proc/$pid/fd/$fd" | file -f -
>
> Which would mean adding another pipe() and fork(). So we might as well
> just shorten it to:
>
> file "/proc/$pid/fd/$fd"
>
> Would this solve the race condition problem? Or am I misunderstanding
> how you intended it to be done?
I didn't get a reply to this. Does the above method seem sensible or
would we need to read the start of the file/device ourselves and pipe it
into 'file -' to avoid opening the file twice?
Andy
>> That way we also remove any possible race conditions too, but this is
>> good enough for now,
>>
>> Steve.
>>
>>
>> On Thu, 2012-06-28 at 10:58 +0100, Andrew Price wrote:
>>> Hi Steve,
>>>
>>> On 06/28/2012 10:16 AM, Steven Whitehouse wrote:
>>>> Hi,
>>>>
>>>> Looks good. ACK,
>>>
>>> This one was obsoleted by the v2 patch I posted on the 21st. If you
>>> prefer this one though I can push it instead.
>>>
>>> Andy
>>>
>>>>
>>>> Steve.
>>>>
>>>> On Wed, 2012-06-20 at 16:47 +0100, Andrew Price wrote:
>>>>> When using symlinks with mkfs.gfs2 it reports what the symlink points
>>>>> to instead of the contents of the device, like so:
>>>>>
>>>>> # ./mkfs.gfs2 -p lock_nolock /dev/vg/test
>>>>> This will destroy any data on /dev/vg/test.
>>>>> It appears to contain: symbolic link to `../dm-3'
>>>>>
>>>>> This patch resolves symlinks before checking the device contents to
>>>>> make
>>>>> the output more informative:
>>>>>
>>>>> # ./mkfs.gfs2 -p lock_nolock /dev/vg/test
>>>>> This will destroy any data on /dev/vg/test.
>>>>> It appears to contain: GFS2 Filesystem (blocksize 4096,
>>>>> lockproto lock_nolock)
>>>>>
>>>>> Signed-off-by: Andrew Price <anprice@redhat.com>
>>>>> ---
>>>>> gfs2/mkfs/main_mkfs.c | 9 ++++++++-
>>>>> 1 files changed, 8 insertions(+), 1 deletions(-)
>>>>>
>>>>> diff --git a/gfs2/mkfs/main_mkfs.c b/gfs2/mkfs/main_mkfs.c
>>>>> index e6b00a0..f8e4741 100644
>>>>> --- a/gfs2/mkfs/main_mkfs.c
>>>>> +++ b/gfs2/mkfs/main_mkfs.c
>>>>> @@ -531,6 +531,7 @@ void main_mkfs(int argc, char *argv[])
>>>>> int error;
>>>>> int rgsize_specified = 0;
>>>>> unsigned char uuid[16];
>>>>> + char *absname;
>>>>>
>>>>> memset(sdp, 0, sizeof(struct gfs2_sbd));
>>>>> sdp->bsize = -1;
>>>>> @@ -560,11 +561,17 @@ void main_mkfs(int argc, char *argv[])
>>>>> exit(EXIT_FAILURE);
>>>>> }
>>>>>
>>>>> + absname = canonicalize_file_name(sdp->device_name);
>>>>> + if (absname == NULL) {
>>>>> + perror(_("Could not find the absolute path of the device"));
>>>>> + exit(EXIT_FAILURE);
>>>>> + }
>>>>> if (!sdp->override) {
>>>>> printf( _("This will destroy any data on %s.\n"),
>>>>> sdp->device_name);
>>>>> - check_dev_content(sdp->device_name);
>>>>> + check_dev_content(absname);
>>>>> are_you_sure();
>>>>> }
>>>>> + free(absname);
>>>>>
>>>>> if (sdp->bsize == -1) {
>>>>> if (S_ISREG(sdp->dinfo.stat.st_mode))
>>>>
>>>>
>>>
>>>
>>
>>
>
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Cluster-devel] [PATCH] mkfs.gfs2: Follow symlinks before checking device contents
2012-07-04 11:02 ` Andrew Price
@ 2012-07-04 11:15 ` Steven Whitehouse
0 siblings, 0 replies; 10+ messages in thread
From: Steven Whitehouse @ 2012-07-04 11:15 UTC (permalink / raw)
To: cluster-devel.redhat.com
Hi,
On Wed, 2012-07-04 at 12:02 +0100, Andrew Price wrote:
> On 06/28/2012 06:52 PM, Andrew Price wrote:
> > On 06/28/2012 11:01 AM, Steven Whitehouse wrote:
> >> Hi,
> >>
> >> Yes, v2 is ok too. I think I missed that in my first pass over my email
> >> today. To do this properly, we should be opening the path that we are
> >> passed, and then doing the remaining operations with just the fd. We
> >> could do that with "file" if we used the -f - option and passed the fd
> >> as standard input to the process.
> >
> > The only way I can think of passing the fd to file -f - would be the C
> > equivalent of:
> >
> > printf "/proc/$pid/fd/$fd" | file -f -
> >
> > Which would mean adding another pipe() and fork(). So we might as well
> > just shorten it to:
> >
> > file "/proc/$pid/fd/$fd"
> >
> > Would this solve the race condition problem? Or am I misunderstanding
> > how you intended it to be done?
>
> I didn't get a reply to this. Does the above method seem sensible or
> would we need to read the start of the file/device ourselves and pipe it
> into 'file -' to avoid opening the file twice?
>
> Andy
>
Yes, that should work too. The intent is to avoid any issues with the
name changing from when mkfs opens the device to when the device is
checked, so any method based on using the open fd, rather than parsing
the path a second time is ok,
Steve.
> >> That way we also remove any possible race conditions too, but this is
> >> good enough for now,
> >>
> >> Steve.
> >>
> >>
> >> On Thu, 2012-06-28 at 10:58 +0100, Andrew Price wrote:
> >>> Hi Steve,
> >>>
> >>> On 06/28/2012 10:16 AM, Steven Whitehouse wrote:
> >>>> Hi,
> >>>>
> >>>> Looks good. ACK,
> >>>
> >>> This one was obsoleted by the v2 patch I posted on the 21st. If you
> >>> prefer this one though I can push it instead.
> >>>
> >>> Andy
> >>>
> >>>>
> >>>> Steve.
> >>>>
> >>>> On Wed, 2012-06-20 at 16:47 +0100, Andrew Price wrote:
> >>>>> When using symlinks with mkfs.gfs2 it reports what the symlink points
> >>>>> to instead of the contents of the device, like so:
> >>>>>
> >>>>> # ./mkfs.gfs2 -p lock_nolock /dev/vg/test
> >>>>> This will destroy any data on /dev/vg/test.
> >>>>> It appears to contain: symbolic link to `../dm-3'
> >>>>>
> >>>>> This patch resolves symlinks before checking the device contents to
> >>>>> make
> >>>>> the output more informative:
> >>>>>
> >>>>> # ./mkfs.gfs2 -p lock_nolock /dev/vg/test
> >>>>> This will destroy any data on /dev/vg/test.
> >>>>> It appears to contain: GFS2 Filesystem (blocksize 4096,
> >>>>> lockproto lock_nolock)
> >>>>>
> >>>>> Signed-off-by: Andrew Price <anprice@redhat.com>
> >>>>> ---
> >>>>> gfs2/mkfs/main_mkfs.c | 9 ++++++++-
> >>>>> 1 files changed, 8 insertions(+), 1 deletions(-)
> >>>>>
> >>>>> diff --git a/gfs2/mkfs/main_mkfs.c b/gfs2/mkfs/main_mkfs.c
> >>>>> index e6b00a0..f8e4741 100644
> >>>>> --- a/gfs2/mkfs/main_mkfs.c
> >>>>> +++ b/gfs2/mkfs/main_mkfs.c
> >>>>> @@ -531,6 +531,7 @@ void main_mkfs(int argc, char *argv[])
> >>>>> int error;
> >>>>> int rgsize_specified = 0;
> >>>>> unsigned char uuid[16];
> >>>>> + char *absname;
> >>>>>
> >>>>> memset(sdp, 0, sizeof(struct gfs2_sbd));
> >>>>> sdp->bsize = -1;
> >>>>> @@ -560,11 +561,17 @@ void main_mkfs(int argc, char *argv[])
> >>>>> exit(EXIT_FAILURE);
> >>>>> }
> >>>>>
> >>>>> + absname = canonicalize_file_name(sdp->device_name);
> >>>>> + if (absname == NULL) {
> >>>>> + perror(_("Could not find the absolute path of the device"));
> >>>>> + exit(EXIT_FAILURE);
> >>>>> + }
> >>>>> if (!sdp->override) {
> >>>>> printf( _("This will destroy any data on %s.\n"),
> >>>>> sdp->device_name);
> >>>>> - check_dev_content(sdp->device_name);
> >>>>> + check_dev_content(absname);
> >>>>> are_you_sure();
> >>>>> }
> >>>>> + free(absname);
> >>>>>
> >>>>> if (sdp->bsize == -1) {
> >>>>> if (S_ISREG(sdp->dinfo.stat.st_mode))
> >>>>
> >>>>
> >>>
> >>>
> >>
> >>
> >
> >
>
>
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2012-07-04 11:15 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-06-20 15:47 [Cluster-devel] [PATCH] mkfs.gfs2: Follow symlinks before checking device contents Andrew Price
2012-06-20 16:15 ` Bob Peterson
2012-06-20 17:27 ` Fabio M. Di Nitto
2012-06-20 17:42 ` Andrew Price
2012-06-28 9:16 ` Steven Whitehouse
2012-06-28 9:58 ` Andrew Price
2012-06-28 10:01 ` Steven Whitehouse
2012-06-28 17:52 ` Andrew Price
2012-07-04 11:02 ` Andrew Price
2012-07-04 11:15 ` Steven Whitehouse
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).