diff mbox

xfsprogs: don't populate fs table with foreign fs paths unless foreign_allowed

Message ID 1472478012-23627-1-git-send-email-billodo@redhat.com (mailing list archive)
State Superseded, archived
Headers show

Commit Message

Bill O'Donnell Aug. 29, 2016, 1:40 p.m. UTC
Commits b20b6c2 and 29647c8 modified xfs_quota for use on
non-XFS filesystems. One modification in fs_initialise_mounts
(paths.c) resulted in an xfstest fail (xfs/261), due to foreign
fs paths entering the fs table.

This patch reverts the behavior in fs_initialise_mounts back
to skip populating the table with foreign paths, unless the
-f flag is thrown in xfs_quota to set foreign_allowed true.

Signed-off-by: Bill O'Donnell <billodo@redhat.com>
---
 libxcmd/paths.c | 5 +++++
 quota/init.c    | 1 -
 2 files changed, 5 insertions(+), 1 deletion(-)

Comments

Darrick J. Wong Aug. 29, 2016, 3:13 p.m. UTC | #1
On Mon, Aug 29, 2016 at 08:40:12AM -0500, Bill O'Donnell wrote:
> Commits b20b6c2 and 29647c8 modified xfs_quota for use on
> non-XFS filesystems. One modification in fs_initialise_mounts
> (paths.c) resulted in an xfstest fail (xfs/261), due to foreign
> fs paths entering the fs table.
> 
> This patch reverts the behavior in fs_initialise_mounts back
> to skip populating the table with foreign paths, unless the
> -f flag is thrown in xfs_quota to set foreign_allowed true.
> 
> Signed-off-by: Bill O'Donnell <billodo@redhat.com>
> ---
>  libxcmd/paths.c | 5 +++++
>  quota/init.c    | 1 -
>  2 files changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/libxcmd/paths.c b/libxcmd/paths.c
> index 4158688..7375c0e 100644
> --- a/libxcmd/paths.c
> +++ b/libxcmd/paths.c
> @@ -34,6 +34,7 @@ extern char *progname;
>  int fs_count;
>  struct fs_path *fs_table;
>  struct fs_path *fs_path;
> +bool foreign_allowed = false;	/* foreign filesystems not allowed (default) */

/me wonders if this would be better as a parameter to
fs_table_initialise_mounts() ?

--D

>  
>  char *mtab_file;
>  #define PROC_MOUNTS	"/proc/self/mounts"
> @@ -311,6 +312,10 @@ fs_table_initialise_mounts(
>  			return errno;
>  
>  	while ((mnt = getmntent(mtp)) != NULL) {
> +		/* don't populate if not XFS, and foreign fs disallowed */
> +		if ((strcmp(mnt->mnt_type, "xfs") != 0) &&
> +		    !foreign_allowed)
> +			continue;
>  		if (!realpath(mnt->mnt_dir, rmnt_dir))
>  			continue;
>  		if (!realpath(mnt->mnt_fsname, rmnt_fsname))
> diff --git a/quota/init.c b/quota/init.c
> index 44be322..65e4dad 100644
> --- a/quota/init.c
> +++ b/quota/init.c
> @@ -24,7 +24,6 @@
>  char	*progname;
>  int	exitcode;
>  int	expert;
> -bool	foreign_allowed = false;
>  
>  static char **projopts;	/* table of project names (cmdline) */
>  static int nprojopts;	/* number of entries in name table. */
> -- 
> 2.7.4
> 
> _______________________________________________
> xfs mailing list
> xfs@oss.sgi.com
> http://oss.sgi.com/mailman/listinfo/xfs
Bill O'Donnell Aug. 29, 2016, 3:43 p.m. UTC | #2
On Mon, Aug 29, 2016 at 08:13:23AM -0700, Darrick J. Wong wrote:
> On Mon, Aug 29, 2016 at 08:40:12AM -0500, Bill O'Donnell wrote:
> > Commits b20b6c2 and 29647c8 modified xfs_quota for use on
> > non-XFS filesystems. One modification in fs_initialise_mounts
> > (paths.c) resulted in an xfstest fail (xfs/261), due to foreign
> > fs paths entering the fs table.
> > 
> > This patch reverts the behavior in fs_initialise_mounts back
> > to skip populating the table with foreign paths, unless the
> > -f flag is thrown in xfs_quota to set foreign_allowed true.
> > 
> > Signed-off-by: Bill O'Donnell <billodo@redhat.com>
> > ---
> >  libxcmd/paths.c | 5 +++++
> >  quota/init.c    | 1 -
> >  2 files changed, 5 insertions(+), 1 deletion(-)
> > 
> > diff --git a/libxcmd/paths.c b/libxcmd/paths.c
> > index 4158688..7375c0e 100644
> > --- a/libxcmd/paths.c
> > +++ b/libxcmd/paths.c
> > @@ -34,6 +34,7 @@ extern char *progname;
> >  int fs_count;
> >  struct fs_path *fs_table;
> >  struct fs_path *fs_path;
> > +bool foreign_allowed = false;	/* foreign filesystems not allowed (default) */
> 
> /me wonders if this would be better as a parameter to
> fs_table_initialise_mounts() ?

Hrmm, it could be, but my notion is that keeping it global
is a bit cleaner than having to add automatics in 4
function calls.
Thanks-
Bill

> 
> --D
> 
> >  
> >  char *mtab_file;
> >  #define PROC_MOUNTS	"/proc/self/mounts"
> > @@ -311,6 +312,10 @@ fs_table_initialise_mounts(
> >  			return errno;
> >  
> >  	while ((mnt = getmntent(mtp)) != NULL) {
> > +		/* don't populate if not XFS, and foreign fs disallowed */
> > +		if ((strcmp(mnt->mnt_type, "xfs") != 0) &&
> > +		    !foreign_allowed)
> > +			continue;
> >  		if (!realpath(mnt->mnt_dir, rmnt_dir))
> >  			continue;
> >  		if (!realpath(mnt->mnt_fsname, rmnt_fsname))
> > diff --git a/quota/init.c b/quota/init.c
> > index 44be322..65e4dad 100644
> > --- a/quota/init.c
> > +++ b/quota/init.c
> > @@ -24,7 +24,6 @@
> >  char	*progname;
> >  int	exitcode;
> >  int	expert;
> > -bool	foreign_allowed = false;
> >  
> >  static char **projopts;	/* table of project names (cmdline) */
> >  static int nprojopts;	/* number of entries in name table. */
> > -- 
> > 2.7.4
> > 
> > _______________________________________________
> > xfs mailing list
> > xfs@oss.sgi.com
> > http://oss.sgi.com/mailman/listinfo/xfs
Dave Chinner Aug. 29, 2016, 11:12 p.m. UTC | #3
On Mon, Aug 29, 2016 at 08:40:12AM -0500, Bill O'Donnell wrote:
> Commits b20b6c2 and 29647c8 modified xfs_quota for use on
> non-XFS filesystems. One modification in fs_initialise_mounts
> (paths.c) resulted in an xfstest fail (xfs/261), due to foreign
> fs paths entering the fs table.

What's the failure? I'm not seeing it here on any of my test
machines...

Cheers,

Dave.
Dave Chinner Aug. 29, 2016, 11:16 p.m. UTC | #4
On Mon, Aug 29, 2016 at 10:43:49AM -0500, Bill O'Donnell wrote:
> On Mon, Aug 29, 2016 at 08:13:23AM -0700, Darrick J. Wong wrote:
> > On Mon, Aug 29, 2016 at 08:40:12AM -0500, Bill O'Donnell wrote:
> > > Commits b20b6c2 and 29647c8 modified xfs_quota for use on
> > > non-XFS filesystems. One modification in fs_initialise_mounts
> > > (paths.c) resulted in an xfstest fail (xfs/261), due to foreign
> > > fs paths entering the fs table.
> > > 
> > > This patch reverts the behavior in fs_initialise_mounts back
> > > to skip populating the table with foreign paths, unless the
> > > -f flag is thrown in xfs_quota to set foreign_allowed true.
> > > 
> > > Signed-off-by: Bill O'Donnell <billodo@redhat.com>
> > > ---
> > >  libxcmd/paths.c | 5 +++++
> > >  quota/init.c    | 1 -
> > >  2 files changed, 5 insertions(+), 1 deletion(-)
> > > 
> > > diff --git a/libxcmd/paths.c b/libxcmd/paths.c
> > > index 4158688..7375c0e 100644
> > > --- a/libxcmd/paths.c
> > > +++ b/libxcmd/paths.c
> > > @@ -34,6 +34,7 @@ extern char *progname;
> > >  int fs_count;
> > >  struct fs_path *fs_table;
> > >  struct fs_path *fs_path;
> > > +bool foreign_allowed = false;	/* foreign filesystems not allowed (default) */
> > 
> > /me wonders if this would be better as a parameter to
> > fs_table_initialise_mounts() ?
> 
> Hrmm, it could be, but my notion is that keeping it global
> is a bit cleaner than having to add automatics in 4
> function calls.

For some definition of "cleaner" (i.e. less code change), yes.

However, hiding behavioural state in library globals hides the
connection between the program code that sets it and the library
code that uses it. It's better to explicitly pass function behaviour
control parameters as function parameters, that way you can just
follow the call chain to know what is supposed to be happening as
you read the source....

Cheers,

Dave.
Bill O'Donnell Aug. 29, 2016, 11:26 p.m. UTC | #5
On Tue, Aug 30, 2016 at 09:12:06AM +1000, Dave Chinner wrote:
> On Mon, Aug 29, 2016 at 08:40:12AM -0500, Bill O'Donnell wrote:
> > Commits b20b6c2 and 29647c8 modified xfs_quota for use on
> > non-XFS filesystems. One modification in fs_initialise_mounts
> > (paths.c) resulted in an xfstest fail (xfs/261), due to foreign
> > fs paths entering the fs table.
> 
> What's the failure? I'm not seeing it here on any of my test
> machines...

On my box, there are a few ext4 mounts, and test xfs/261 
populates the fs table with those paths. So when xfs_quota commands
in 261 are executed, a "foreign filesystem" message is thrown.
My first notion was to add a -f to the xfs_quota command in 261,
but then I decided it was better to change the xfsprogs code back
to the old behavior.

> 
> Cheers,
> 
> Dave.
> -- 
> Dave Chinner
> david@fromorbit.com
Bill O'Donnell Aug. 29, 2016, 11:28 p.m. UTC | #6
On Tue, Aug 30, 2016 at 09:16:49AM +1000, Dave Chinner wrote:
> On Mon, Aug 29, 2016 at 10:43:49AM -0500, Bill O'Donnell wrote:
> > On Mon, Aug 29, 2016 at 08:13:23AM -0700, Darrick J. Wong wrote:
> > > On Mon, Aug 29, 2016 at 08:40:12AM -0500, Bill O'Donnell wrote:
> > > > Commits b20b6c2 and 29647c8 modified xfs_quota for use on
> > > > non-XFS filesystems. One modification in fs_initialise_mounts
> > > > (paths.c) resulted in an xfstest fail (xfs/261), due to foreign
> > > > fs paths entering the fs table.
> > > > 
> > > > This patch reverts the behavior in fs_initialise_mounts back
> > > > to skip populating the table with foreign paths, unless the
> > > > -f flag is thrown in xfs_quota to set foreign_allowed true.
> > > > 
> > > > Signed-off-by: Bill O'Donnell <billodo@redhat.com>
> > > > ---
> > > >  libxcmd/paths.c | 5 +++++
> > > >  quota/init.c    | 1 -
> > > >  2 files changed, 5 insertions(+), 1 deletion(-)
> > > > 
> > > > diff --git a/libxcmd/paths.c b/libxcmd/paths.c
> > > > index 4158688..7375c0e 100644
> > > > --- a/libxcmd/paths.c
> > > > +++ b/libxcmd/paths.c
> > > > @@ -34,6 +34,7 @@ extern char *progname;
> > > >  int fs_count;
> > > >  struct fs_path *fs_table;
> > > >  struct fs_path *fs_path;
> > > > +bool foreign_allowed = false;	/* foreign filesystems not allowed (default) */
> > > 
> > > /me wonders if this would be better as a parameter to
> > > fs_table_initialise_mounts() ?
> > 
> > Hrmm, it could be, but my notion is that keeping it global
> > is a bit cleaner than having to add automatics in 4
> > function calls.
> 
> For some definition of "cleaner" (i.e. less code change), yes.
> 
> However, hiding behavioural state in library globals hides the
> connection between the program code that sets it and the library
> code that uses it. It's better to explicitly pass function behaviour
> control parameters as function parameters, that way you can just
> follow the call chain to know what is supposed to be happening as
> you read the source....

Agreed. I thought about it today, and it is indeed "safer" and better
understood to use arguments instead of an external variable. I'll fix
it.
Thanks-
Bill


> 
> Cheers,
> 
> Dave.
> -- 
> Dave Chinner
> david@fromorbit.com
Dave Chinner Aug. 29, 2016, 11:40 p.m. UTC | #7
On Mon, Aug 29, 2016 at 06:26:15PM -0500, Bill O'Donnell wrote:
> On Tue, Aug 30, 2016 at 09:12:06AM +1000, Dave Chinner wrote:
> > On Mon, Aug 29, 2016 at 08:40:12AM -0500, Bill O'Donnell wrote:
> > > Commits b20b6c2 and 29647c8 modified xfs_quota for use on
> > > non-XFS filesystems. One modification in fs_initialise_mounts
> > > (paths.c) resulted in an xfstest fail (xfs/261), due to foreign
> > > fs paths entering the fs table.
> > 
> > What's the failure? I'm not seeing it here on any of my test
> > machines...
> 
> On my box, there are a few ext4 mounts, and test xfs/261 
> populates the fs table with those paths.

I have ext2 and ext3 mounts on these machines as well, and they
don't throw any errors.

> So when xfs_quota commands
> in 261 are executed, a "foreign filesystem" message is thrown.

What is the output that is causing the failure? When someone
asks you to describe the error that is occurring, please quote the
/exact error/ that is occurring - describing it via paraphrasing
does not tell anything useful about the error as I cannot correlate
that description to the code that is throwing it.

Cheers,

Dave.
Bill O'Donnell Aug. 29, 2016, 11:47 p.m. UTC | #8
On Tue, Aug 30, 2016 at 09:40:44AM +1000, Dave Chinner wrote:
> On Mon, Aug 29, 2016 at 06:26:15PM -0500, Bill O'Donnell wrote:
> > On Tue, Aug 30, 2016 at 09:12:06AM +1000, Dave Chinner wrote:
> > > On Mon, Aug 29, 2016 at 08:40:12AM -0500, Bill O'Donnell wrote:
> > > > Commits b20b6c2 and 29647c8 modified xfs_quota for use on
> > > > non-XFS filesystems. One modification in fs_initialise_mounts
> > > > (paths.c) resulted in an xfstest fail (xfs/261), due to foreign
> > > > fs paths entering the fs table.
> > > 
> > > What's the failure? I'm not seeing it here on any of my test
> > > machines...
> > 
> > On my box, there are a few ext4 mounts, and test xfs/261 
> > populates the fs table with those paths.
> 
> I have ext2 and ext3 mounts on these machines as well, and they
> don't throw any errors.
> 
> > So when xfs_quota commands
> > in 261 are executed, a "foreign filesystem" message is thrown.
> 
> What is the output that is causing the failure? When someone
> asks you to describe the error that is occurring, please quote the
> /exact error/ that is occurring - describing it via paraphrasing
> does not tell anything useful about the error as I cannot correlate
> that description to the code that is throwing it.

Ahh, ok, I'm sorry about that.
[root@dell-pesc440-01 xfstests-dev]# ./check -d tests/xfs/261
FSTYP         -- xfs (debug)
PLATFORM      -- Linux/x86_64 dell-pesc440-01 4.7.0-rc108052016bill02+
MKFS_OPTIONS  -- -f -bsize=4096 /dev/mapper/fedora_dell--pesc440--01-csdf
MOUNT_OPTIONS -- -o context=system_u:object_r:nfs_t:s0 /dev/mapper/fedora_dell--pesc440--01-csdf /mnt/scratch

xfs/261 2s ...QA output created by 261
Silence is golden.
print command is for XFS filesystems only
print command is for XFS filesystems only
print command is for XFS filesystems only
print command is for XFS filesystems only
print command is for XFS filesystems only
print command is for XFS filesystems only
print command is for XFS filesystems only
print command is for XFS filesystems only
 - output mismatch (see /root/xfstests-dev/results//xfs/261.out.bad)
    --- tests/xfs/261.out       2016-08-09 15:45:47.471465224 -0400
    +++ /root/xfstests-dev/results//xfs/261.out.bad     2016-08-29 19:45:58.166965834 -0400
    @@ -1,2 +1,10 @@
     QA output created by 261
     Silence is golden.
    +print command is for XFS filesystems only
    +print command is for XFS filesystems only
    +print command is for XFS filesystems only
    +print command is for XFS filesystems only
    +print command is for XFS filesystems only
    ...
    (Run 'diff -u tests/xfs/261.out /root/xfstests-dev/results//xfs/261.out.bad'  to see the entire diff)
Ran: xfs/261
Failures: xfs/261
Failed 1 of 1 tests



> 
> Cheers,
> 
> Dave.
> -- 
> Dave Chinner
> david@fromorbit.com
Dave Chinner Aug. 30, 2016, 12:25 a.m. UTC | #9
On Mon, Aug 29, 2016 at 06:47:04PM -0500, Bill O'Donnell wrote:
> On Tue, Aug 30, 2016 at 09:40:44AM +1000, Dave Chinner wrote:
> > On Mon, Aug 29, 2016 at 06:26:15PM -0500, Bill O'Donnell wrote:
> > > On Tue, Aug 30, 2016 at 09:12:06AM +1000, Dave Chinner wrote:
> > > > On Mon, Aug 29, 2016 at 08:40:12AM -0500, Bill O'Donnell wrote:
> > > > > Commits b20b6c2 and 29647c8 modified xfs_quota for use on
> > > > > non-XFS filesystems. One modification in fs_initialise_mounts
> > > > > (paths.c) resulted in an xfstest fail (xfs/261), due to foreign
> > > > > fs paths entering the fs table.
> > > > 
> > > > What's the failure? I'm not seeing it here on any of my test
> > > > machines...
> > > 
> > > On my box, there are a few ext4 mounts, and test xfs/261 
> > > populates the fs table with those paths.
> > 
> > I have ext2 and ext3 mounts on these machines as well, and they
> > don't throw any errors.
> > 
> > > So when xfs_quota commands
> > > in 261 are executed, a "foreign filesystem" message is thrown.
> > 
> > What is the output that is causing the failure? When someone
> > asks you to describe the error that is occurring, please quote the
> > /exact error/ that is occurring - describing it via paraphrasing
> > does not tell anything useful about the error as I cannot correlate
> > that description to the code that is throwing it.
> 
> Ahh, ok, I'm sorry about that.
> [root@dell-pesc440-01 xfstests-dev]# ./check -d tests/xfs/261
> FSTYP         -- xfs (debug)
> PLATFORM      -- Linux/x86_64 dell-pesc440-01 4.7.0-rc108052016bill02+
> MKFS_OPTIONS  -- -f -bsize=4096 /dev/mapper/fedora_dell--pesc440--01-csdf
> MOUNT_OPTIONS -- -o context=system_u:object_r:nfs_t:s0 /dev/mapper/fedora_dell--pesc440--01-csdf /mnt/scratch
> 
> xfs/261 2s ...QA output created by 261
> Silence is golden.
> print command is for XFS filesystems only
> print command is for XFS filesystems only
> print command is for XFS filesystems only
> print command is for XFS filesystems only
> print command is for XFS filesystems only
> print command is for XFS filesystems only
> print command is for XFS filesystems only
> print command is for XFS filesystems only

Bill, slow down and work through the code from first principles. I
don't care about getting a fix quickly - I care about the process
you use to find the problem and whether you end up fully
understanding the problem.  Walk through the code in the debugger if
you have to - it will show you the flow and how the pieces connect
together.

The question that needs to be answered is this: what set of initial
conditions is causing this error to occur? We don't really care
about what previous changes caused the issue at this point - working
that out comes /after/ diagnosing the problem when we are trying to
work out a fix.

So, yes, the issue occurs because there are foreign fs types in the
fstable, but that's not the underlying problem nor the problem that
needs to be solved.

Use the debugger and cssope to connect the dots between the fstable
initialisation, the fs_path initialisation, and the function that
prints that error. That should give you a good idea of why the error
is being printed.

Then have a look at print_f() and see what it does with the fstable.
Then tell me whether we should even care about checking for foreign
filesystems before we run the print_f command. At this point, the
fix should be obvious.

And then have a look at printpath() and tell me what the foriegn
filesystem handling bug it contains.

And, yes, I could have written and tested the patch to fix all this
in the time it took to write this email, but then you don't have the
opportunity to learn from doing it....

Cheers,

Dave.
Bill O'Donnell Aug. 30, 2016, 12:53 a.m. UTC | #10
On Tue, Aug 30, 2016 at 10:25:13AM +1000, Dave Chinner wrote:
> On Mon, Aug 29, 2016 at 06:47:04PM -0500, Bill O'Donnell wrote:
> > On Tue, Aug 30, 2016 at 09:40:44AM +1000, Dave Chinner wrote:
> > > On Mon, Aug 29, 2016 at 06:26:15PM -0500, Bill O'Donnell wrote:
> > > > On Tue, Aug 30, 2016 at 09:12:06AM +1000, Dave Chinner wrote:
> > > > > On Mon, Aug 29, 2016 at 08:40:12AM -0500, Bill O'Donnell wrote:
> > > > > > Commits b20b6c2 and 29647c8 modified xfs_quota for use on
> > > > > > non-XFS filesystems. One modification in fs_initialise_mounts
> > > > > > (paths.c) resulted in an xfstest fail (xfs/261), due to foreign
> > > > > > fs paths entering the fs table.
> > > > > 
> > > > > What's the failure? I'm not seeing it here on any of my test
> > > > > machines...
> > > > 
> > > > On my box, there are a few ext4 mounts, and test xfs/261 
> > > > populates the fs table with those paths.
> > > 
> > > I have ext2 and ext3 mounts on these machines as well, and they
> > > don't throw any errors.
> > > 
> > > > So when xfs_quota commands
> > > > in 261 are executed, a "foreign filesystem" message is thrown.
> > > 
> > > What is the output that is causing the failure? When someone
> > > asks you to describe the error that is occurring, please quote the
> > > /exact error/ that is occurring - describing it via paraphrasing
> > > does not tell anything useful about the error as I cannot correlate
> > > that description to the code that is throwing it.
> > 
> > Ahh, ok, I'm sorry about that.
> > [root@dell-pesc440-01 xfstests-dev]# ./check -d tests/xfs/261
> > FSTYP         -- xfs (debug)
> > PLATFORM      -- Linux/x86_64 dell-pesc440-01 4.7.0-rc108052016bill02+
> > MKFS_OPTIONS  -- -f -bsize=4096 /dev/mapper/fedora_dell--pesc440--01-csdf
> > MOUNT_OPTIONS -- -o context=system_u:object_r:nfs_t:s0 /dev/mapper/fedora_dell--pesc440--01-csdf /mnt/scratch
> > 
> > xfs/261 2s ...QA output created by 261
> > Silence is golden.
> > print command is for XFS filesystems only
> > print command is for XFS filesystems only
> > print command is for XFS filesystems only
> > print command is for XFS filesystems only
> > print command is for XFS filesystems only
> > print command is for XFS filesystems only
> > print command is for XFS filesystems only
> > print command is for XFS filesystems only
> 
> Bill, slow down and work through the code from first principles. I
> don't care about getting a fix quickly - I care about the process
> you use to find the problem and whether you end up fully
> understanding the problem.  Walk through the code in the debugger if
> you have to - it will show you the flow and how the pieces connect
> together.
> 
> The question that needs to be answered is this: what set of initial
> conditions is causing this error to occur? We don't really care
> about what previous changes caused the issue at this point - working
> that out comes /after/ diagnosing the problem when we are trying to
> work out a fix.
> 
> So, yes, the issue occurs because there are foreign fs types in the
> fstable, but that's not the underlying problem nor the problem that
> needs to be solved.
> 
> Use the debugger and cssope to connect the dots between the fstable
> initialisation, the fs_path initialisation, and the function that
> prints that error. That should give you a good idea of why the error
> is being printed.
> 
> Then have a look at print_f() and see what it does with the fstable.
> Then tell me whether we should even care about checking for foreign
> filesystems before we run the print_f command. At this point, the
> fix should be obvious.
> 
> And then have a look at printpath() and tell me what the foriegn
> filesystem handling bug it contains.
> 
> And, yes, I could have written and tested the patch to fix all this
> in the time it took to write this email, but then you don't have the
> opportunity to learn from doing it....

OK, will do. Thanks Dave.

-Bill


> 
> Cheers,
> 
> Dave.
> -- 
> Dave Chinner
> david@fromorbit.com
Bill O'Donnell Sept. 1, 2016, 10:07 p.m. UTC | #11
On Tue, Aug 30, 2016 at 10:25:13AM +1000, Dave Chinner wrote:
> On Mon, Aug 29, 2016 at 06:47:04PM -0500, Bill O'Donnell wrote:
> > On Tue, Aug 30, 2016 at 09:40:44AM +1000, Dave Chinner wrote:
> > > On Mon, Aug 29, 2016 at 06:26:15PM -0500, Bill O'Donnell wrote:
> > > > On Tue, Aug 30, 2016 at 09:12:06AM +1000, Dave Chinner wrote:
> > > > > On Mon, Aug 29, 2016 at 08:40:12AM -0500, Bill O'Donnell wrote:
> > > > > > Commits b20b6c2 and 29647c8 modified xfs_quota for use on
> > > > > > non-XFS filesystems. One modification in fs_initialise_mounts
> > > > > > (paths.c) resulted in an xfstest fail (xfs/261), due to foreign
> > > > > > fs paths entering the fs table.
> > > > > 
> > > > > What's the failure? I'm not seeing it here on any of my test
> > > > > machines...
> > > > 
> > > > On my box, there are a few ext4 mounts, and test xfs/261 
> > > > populates the fs table with those paths.
> > > 
> > > I have ext2 and ext3 mounts on these machines as well, and they
> > > don't throw any errors.
> > > 
> > > > So when xfs_quota commands
> > > > in 261 are executed, a "foreign filesystem" message is thrown.
> > > 
> > > What is the output that is causing the failure? When someone
> > > asks you to describe the error that is occurring, please quote the
> > > /exact error/ that is occurring - describing it via paraphrasing
> > > does not tell anything useful about the error as I cannot correlate
> > > that description to the code that is throwing it.
> > 
> > Ahh, ok, I'm sorry about that.
> > [root@dell-pesc440-01 xfstests-dev]# ./check -d tests/xfs/261
> > FSTYP         -- xfs (debug)
> > PLATFORM      -- Linux/x86_64 dell-pesc440-01 4.7.0-rc108052016bill02+
> > MKFS_OPTIONS  -- -f -bsize=4096 /dev/mapper/fedora_dell--pesc440--01-csdf
> > MOUNT_OPTIONS -- -o context=system_u:object_r:nfs_t:s0 /dev/mapper/fedora_dell--pesc440--01-csdf /mnt/scratch
> > 
> > xfs/261 2s ...QA output created by 261
> > Silence is golden.
> > print command is for XFS filesystems only
> > print command is for XFS filesystems only
> > print command is for XFS filesystems only
> > print command is for XFS filesystems only
> > print command is for XFS filesystems only
> > print command is for XFS filesystems only
> > print command is for XFS filesystems only
> > print command is for XFS filesystems only
> 
> Bill, slow down and work through the code from first principles. I
> don't care about getting a fix quickly - I care about the process
> you use to find the problem and whether you end up fully
> understanding the problem.  Walk through the code in the debugger if
> you have to - it will show you the flow and how the pieces connect
> together.
> 
> The question that needs to be answered is this: what set of initial
> conditions is causing this error to occur? We don't really care
> about what previous changes caused the issue at this point - working
> that out comes /after/ diagnosing the problem when we are trying to
> work out a fix.
> 
> So, yes, the issue occurs because there are foreign fs types in the
> fstable, but that's not the underlying problem nor the problem that
> needs to be solved.
> 
> Use the debugger and cssope to connect the dots between the fstable
> initialisation, the fs_path initialisation, and the function that
> prints that error. That should give you a good idea of why the error
> is being printed.
> 
> Then have a look at print_f() and see what it does with the fstable.
> Then tell me whether we should even care about checking for foreign
> filesystems before we run the print_f command. At this point, the
> fix should be obvious.

I used gdb to check the flow, and realized that
instead of modifying paths.c, it makes sense to simply allow the
print (and paths) command regardless of whether or not the fs is
foreign or not. So to that end, no, we shouldn't care about checking
for foreign fs before print_f. This will dispense with the notion of
involving foreign_allowed in libxcmd/paths.c.

That's fine, but I'm still a bit stymied understanding the original
intent for the "-f" flag.  Did we not want to remind the user that one
must use -f when using xfs_quota on a foreign fs (exceptions being
help and quit)?

Also, I had thought adding "-f" was to ensure that the default
behavior of xfs_quota didn't change in the face of other filesystems.
Wouldn't not populating the fs table with foreign fs entries be the
simplest way to ensure that no "print all the info" options which
iterate over the table will change their output?

> 
> And then have a look at printpath() and tell me what the foriegn
> filesystem handling bug it contains.

Other than some minor output formatting issues, I've not been able
to discover a bug in printpath(). I'm obviously missing something ;)

Thanks-
Bill

> 
> And, yes, I could have written and tested the patch to fix all this
> in the time it took to write this email, but then you don't have the
> opportunity to learn from doing it....
> 
> Cheers,
> 
> Dave.
> -- 
> Dave Chinner
> david@fromorbit.com
diff mbox

Patch

diff --git a/libxcmd/paths.c b/libxcmd/paths.c
index 4158688..7375c0e 100644
--- a/libxcmd/paths.c
+++ b/libxcmd/paths.c
@@ -34,6 +34,7 @@  extern char *progname;
 int fs_count;
 struct fs_path *fs_table;
 struct fs_path *fs_path;
+bool foreign_allowed = false;	/* foreign filesystems not allowed (default) */
 
 char *mtab_file;
 #define PROC_MOUNTS	"/proc/self/mounts"
@@ -311,6 +312,10 @@  fs_table_initialise_mounts(
 			return errno;
 
 	while ((mnt = getmntent(mtp)) != NULL) {
+		/* don't populate if not XFS, and foreign fs disallowed */
+		if ((strcmp(mnt->mnt_type, "xfs") != 0) &&
+		    !foreign_allowed)
+			continue;
 		if (!realpath(mnt->mnt_dir, rmnt_dir))
 			continue;
 		if (!realpath(mnt->mnt_fsname, rmnt_fsname))
diff --git a/quota/init.c b/quota/init.c
index 44be322..65e4dad 100644
--- a/quota/init.c
+++ b/quota/init.c
@@ -24,7 +24,6 @@ 
 char	*progname;
 int	exitcode;
 int	expert;
-bool	foreign_allowed = false;
 
 static char **projopts;	/* table of project names (cmdline) */
 static int nprojopts;	/* number of entries in name table. */