diff mbox series

[RFC,1/3] include/linux.h: Factor out generic platform_test_fs_fd() helper

Message ID 5996d6854a16852daca5977063af6f2af2f0f4ca.1733902742.git.ojaswin@linux.ibm.com (mailing list archive)
State New
Headers show
Series xfs_io: enable extsize and stat -v support for ext4 | expand

Commit Message

Ojaswin Mujoo Dec. 11, 2024, 7:54 a.m. UTC
Factor our the generic code to detect the FS type out of
platform_test_fs_fd(). This can then be used to detect different file
systems types based on magic number.

Also, add a helper to detect if the fd is from an ext4 filesystem.

Signed-off-by: Ojaswin Mujoo <ojaswin@linux.ibm.com>
---
 include/linux.h | 25 +++++++++++++++++--------
 1 file changed, 17 insertions(+), 8 deletions(-)

Comments

Darrick J. Wong Dec. 11, 2024, 6:09 p.m. UTC | #1
On Wed, Dec 11, 2024 at 01:24:02PM +0530, Ojaswin Mujoo wrote:
> Factor our the generic code to detect the FS type out of
> platform_test_fs_fd(). This can then be used to detect different file
> systems types based on magic number.
> 
> Also, add a helper to detect if the fd is from an ext4 filesystem.
> 
> Signed-off-by: Ojaswin Mujoo <ojaswin@linux.ibm.com>
> ---
>  include/linux.h | 25 +++++++++++++++++--------
>  1 file changed, 17 insertions(+), 8 deletions(-)
> 
> diff --git a/include/linux.h b/include/linux.h
> index e9eb7bfb26a1..52c64014c57f 100644
> --- a/include/linux.h
> +++ b/include/linux.h
> @@ -43,13 +43,7 @@ static __inline__ int xfsctl(const char *path, int fd, int cmd, void *p)
>  	return ioctl(fd, cmd, p);
>  }
>  
> -/*
> - * platform_test_xfs_*() implies that xfsctl will succeed on the file;
> - * on Linux, at least, special files don't get xfs file ops,
> - * so return 0 for those
> - */
> -
> -static __inline__ int platform_test_xfs_fd(int fd)
> +static __inline__ int platform_test_fs_fd(int fd, long type)
>  {
>  	struct statfs statfsbuf;
>  	struct stat statbuf;
> @@ -60,7 +54,22 @@ static __inline__ int platform_test_xfs_fd(int fd)
>  		return 0;
>  	if (!S_ISREG(statbuf.st_mode) && !S_ISDIR(statbuf.st_mode))
>  		return 0;
> -	return (statfsbuf.f_type == 0x58465342);	/* XFSB */
> +	return (statfsbuf.f_type == type);
> +}
> +
> +/*
> + * platform_test_xfs_*() implies that xfsctl will succeed on the file;
> + * on Linux, at least, special files don't get xfs file ops,
> + * so return 0 for those
> + */
> +static __inline__ int platform_test_xfs_fd(int fd)
> +{
> +	return platform_test_fs_fd(fd, 0x58465342); /* XFSB */
> +}
> +
> +static __inline__ int platform_test_ext4_fd(int fd)
> +{
> +	return platform_test_fs_fd(fd, 0xef53); /* EXT4 magic number */

Should this be pulling EXT4_SUPER_MAGIC from linux/magic.h?

--D

>  }
>  
>  static __inline__ int platform_test_xfs_path(const char *path)
> -- 
> 2.43.5
> 
>
Ojaswin Mujoo Dec. 12, 2024, 12:05 p.m. UTC | #2
On Wed, Dec 11, 2024 at 10:09:02AM -0800, Darrick J. Wong wrote:
> On Wed, Dec 11, 2024 at 01:24:02PM +0530, Ojaswin Mujoo wrote:
> > Factor our the generic code to detect the FS type out of
> > platform_test_fs_fd(). This can then be used to detect different file
> > systems types based on magic number.
> > 
> > Also, add a helper to detect if the fd is from an ext4 filesystem.
> > 
> > Signed-off-by: Ojaswin Mujoo <ojaswin@linux.ibm.com>
> > ---
> >  include/linux.h | 25 +++++++++++++++++--------
> >  1 file changed, 17 insertions(+), 8 deletions(-)
> > 
> > diff --git a/include/linux.h b/include/linux.h
> > index e9eb7bfb26a1..52c64014c57f 100644
> > --- a/include/linux.h
> > +++ b/include/linux.h
> > @@ -43,13 +43,7 @@ static __inline__ int xfsctl(const char *path, int fd, int cmd, void *p)
> >  	return ioctl(fd, cmd, p);
> >  }
> >  
> > -/*
> > - * platform_test_xfs_*() implies that xfsctl will succeed on the file;
> > - * on Linux, at least, special files don't get xfs file ops,
> > - * so return 0 for those
> > - */
> > -
> > -static __inline__ int platform_test_xfs_fd(int fd)
> > +static __inline__ int platform_test_fs_fd(int fd, long type)
> >  {
> >  	struct statfs statfsbuf;
> >  	struct stat statbuf;
> > @@ -60,7 +54,22 @@ static __inline__ int platform_test_xfs_fd(int fd)
> >  		return 0;
> >  	if (!S_ISREG(statbuf.st_mode) && !S_ISDIR(statbuf.st_mode))
> >  		return 0;
> > -	return (statfsbuf.f_type == 0x58465342);	/* XFSB */
> > +	return (statfsbuf.f_type == type);
> > +}
> > +
> > +/*
> > + * platform_test_xfs_*() implies that xfsctl will succeed on the file;
> > + * on Linux, at least, special files don't get xfs file ops,
> > + * so return 0 for those
> > + */
> > +static __inline__ int platform_test_xfs_fd(int fd)
> > +{
> > +	return platform_test_fs_fd(fd, 0x58465342); /* XFSB */
> > +}
> > +
> > +static __inline__ int platform_test_ext4_fd(int fd)
> > +{
> > +	return platform_test_fs_fd(fd, 0xef53); /* EXT4 magic number */
> 
> Should this be pulling EXT4_SUPER_MAGIC from linux/magic.h?

Oh right, thanks for pointing out. I'll use that for the magic numbers.

Thanks,
ojaswin

> 
> --D
> 
> >  }
> >  
> >  static __inline__ int platform_test_xfs_path(const char *path)
> > -- 
> > 2.43.5
> > 
> >
Christoph Hellwig Dec. 13, 2024, 5:57 a.m. UTC | #3
On Wed, Dec 11, 2024 at 10:09:02AM -0800, Darrick J. Wong wrote:
> > +
> > +static __inline__ int platform_test_ext4_fd(int fd)
> > +{
> > +	return platform_test_fs_fd(fd, 0xef53); /* EXT4 magic number */
> 
> Should this be pulling EXT4_SUPER_MAGIC from linux/magic.h?

I think we can just drop adding platform_test_ext4_fd with the
suggested patches later in the series?  Having ext4-specific code
in xfsprogs would seem pretty odd in xfsprogs anyway over our previous
categories of xfs only or generic.
Ojaswin Mujoo Dec. 13, 2024, 6:37 p.m. UTC | #4
On Thu, Dec 12, 2024 at 09:57:01PM -0800, Christoph Hellwig wrote:
> On Wed, Dec 11, 2024 at 10:09:02AM -0800, Darrick J. Wong wrote:
> > > +
> > > +static __inline__ int platform_test_ext4_fd(int fd)
> > > +{
> > > +	return platform_test_fs_fd(fd, 0xef53); /* EXT4 magic number */
> > 
> > Should this be pulling EXT4_SUPER_MAGIC from linux/magic.h?
> 
> I think we can just drop adding platform_test_ext4_fd with the
> suggested patches later in the series?  Having ext4-specific code
> in xfsprogs would seem pretty odd in xfsprogs anyway over our previous
> categories of xfs only or generic.
> 

Oh right, xfs_io is so widely used across FSes that I missed to consider it 
might not be okay to add special code specific to ext4 :)

Anyways, I agree we don't need to separately handle ext4 anymore.  I'll
drop this patch. (Maybe still get XFS_SUPER_MAGIC from linux/magic.h as
that seems like the right thing to do)

Regards,
ojaswin
diff mbox series

Patch

diff --git a/include/linux.h b/include/linux.h
index e9eb7bfb26a1..52c64014c57f 100644
--- a/include/linux.h
+++ b/include/linux.h
@@ -43,13 +43,7 @@  static __inline__ int xfsctl(const char *path, int fd, int cmd, void *p)
 	return ioctl(fd, cmd, p);
 }
 
-/*
- * platform_test_xfs_*() implies that xfsctl will succeed on the file;
- * on Linux, at least, special files don't get xfs file ops,
- * so return 0 for those
- */
-
-static __inline__ int platform_test_xfs_fd(int fd)
+static __inline__ int platform_test_fs_fd(int fd, long type)
 {
 	struct statfs statfsbuf;
 	struct stat statbuf;
@@ -60,7 +54,22 @@  static __inline__ int platform_test_xfs_fd(int fd)
 		return 0;
 	if (!S_ISREG(statbuf.st_mode) && !S_ISDIR(statbuf.st_mode))
 		return 0;
-	return (statfsbuf.f_type == 0x58465342);	/* XFSB */
+	return (statfsbuf.f_type == type);
+}
+
+/*
+ * platform_test_xfs_*() implies that xfsctl will succeed on the file;
+ * on Linux, at least, special files don't get xfs file ops,
+ * so return 0 for those
+ */
+static __inline__ int platform_test_xfs_fd(int fd)
+{
+	return platform_test_fs_fd(fd, 0x58465342); /* XFSB */
+}
+
+static __inline__ int platform_test_ext4_fd(int fd)
+{
+	return platform_test_fs_fd(fd, 0xef53); /* EXT4 magic number */
 }
 
 static __inline__ int platform_test_xfs_path(const char *path)