* [PATCH] generic/223: port t_stripealign to FIEMAP
@ 2018-06-13 22:50 Darrick J. Wong
2018-06-15 2:49 ` Eryu Guan
0 siblings, 1 reply; 3+ messages in thread
From: Darrick J. Wong @ 2018-06-13 22:50 UTC (permalink / raw)
To: Eryu Guan; +Cc: fstests, xfs, Ross Zwisler
From: Darrick J. Wong <darrick.wong@oracle.com>
Since XFS has deprecated FIBMAP on FSDAX filesystems, we can't use
FIBMAP to verify stripe alignment anymore. FIEMAP has existed for quite
some time now, so port it to use that instead, and only fall back to
FIBMAP if FIEMAP doesn't exist.
Tested-by: ross.zwisler@linux.intel.com
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
src/t_stripealign.c | 72 +++++++++++++++++++++++++++++++++++++++++++--------
1 file changed, 61 insertions(+), 11 deletions(-)
diff --git a/src/t_stripealign.c b/src/t_stripealign.c
index 05ed36b5..690f743a 100644
--- a/src/t_stripealign.c
+++ b/src/t_stripealign.c
@@ -17,8 +17,13 @@
#include <fcntl.h>
#include <stdio.h>
#include <sys/ioctl.h>
+#include <linux/fiemap.h>
+#include <linux/fs.h>
-#define FIBMAP _IO(0x00, 1) /* bmap access */
+#define FIEMAP_EXTENT_ACCEPTABLE (FIEMAP_EXTENT_LAST | \
+ FIEMAP_EXTENT_DATA_ENCRYPTED | FIEMAP_EXTENT_ENCODED | \
+ FIEMAP_EXTENT_UNWRITTEN | FIEMAP_EXTENT_MERGED | \
+ FIEMAP_EXTENT_SHARED)
/*
* If only filename given, print first block.
@@ -28,11 +33,14 @@
int main(int argc, char ** argv)
{
- int fd;
- int ret;
- int sunit = 0; /* in blocks */
- char *filename;
- unsigned int block = 0;
+ struct stat sb;
+ struct fiemap *fie;
+ struct fiemap_extent *fe;
+ int fd;
+ int ret;
+ int sunit = 0; /* in blocks */
+ char *filename;
+ unsigned long long block;
if (argc < 3) {
printf("Usage: %s <filename> <sunit in blocks>\n", argv[0]);
@@ -48,21 +56,63 @@ int main(int argc, char ** argv)
return 1;
}
- ret = ioctl(fd, FIBMAP, &block);
- if (ret < 0) {
+ ret = fstat(fd, &sb);
+ if (ret) {
+ perror(filename);
close(fd);
- perror("fibmap");
return 1;
}
- close(fd);
+ fie = calloc(1, sizeof(struct fiemap) + sizeof(struct fiemap_extent));
+ if (!fie) {
+ close(fd);
+ perror("malloc");
+ return 1;
+ }
+ fie->fm_length = 1;
+ fie->fm_flags = FIEMAP_FLAG_SYNC;
+ fie->fm_extent_count = 1;
+
+ ret = ioctl(fd, FS_IOC_FIEMAP, fie);
+ if (ret < 0) {
+ unsigned int bmap = 0;
+
+ ret = ioctl(fd, FIBMAP, &bmap);
+ if (ret < 0) {
+ perror("fibmap");
+ free(fie);
+ close(fd);
+ return 1;
+ }
+ block = bmap;
+ goto check;
+ }
+
+ if (fie->fm_mapped_extents != 1) {
+ printf("%s: no extents?\n", filename);
+ free(fie);
+ close(fd);
+ return 1;
+ }
+ fe = &fie->fm_extents[0];
+ if (fe->fe_flags & ~FIEMAP_EXTENT_ACCEPTABLE) {
+ printf("%s: bad flags 0x%x\n", filename, fe->fe_flags);
+ free(fie);
+ close(fd);
+ return 1;
+ }
+
+ block = fie->fm_extents[0].fe_physical / sb.st_blksize;
+check:
if (block % sunit) {
- printf("%s: Start block %u not multiple of sunit %u\n",
+ printf("%s: Start block %llu not multiple of sunit %u\n",
filename, block, sunit);
return 1;
} else
printf("%s: well-aligned\n", filename);
+ free(fie);
+ close(fd);
return 0;
}
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] generic/223: port t_stripealign to FIEMAP
2018-06-13 22:50 [PATCH] generic/223: port t_stripealign to FIEMAP Darrick J. Wong
@ 2018-06-15 2:49 ` Eryu Guan
2018-06-17 14:39 ` Eryu Guan
0 siblings, 1 reply; 3+ messages in thread
From: Eryu Guan @ 2018-06-15 2:49 UTC (permalink / raw)
To: Darrick J. Wong; +Cc: fstests, xfs, Ross Zwisler
On Wed, Jun 13, 2018 at 03:50:57PM -0700, Darrick J. Wong wrote:
> From: Darrick J. Wong <darrick.wong@oracle.com>
>
> Since XFS has deprecated FIBMAP on FSDAX filesystems, we can't use
> FIBMAP to verify stripe alignment anymore. FIEMAP has existed for quite
> some time now, so port it to use that instead, and only fall back to
> FIBMAP if FIEMAP doesn't exist.
>
> Tested-by: ross.zwisler@linux.intel.com
> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
> ---
> src/t_stripealign.c | 72 +++++++++++++++++++++++++++++++++++++++++++--------
> 1 file changed, 61 insertions(+), 11 deletions(-)
>
> diff --git a/src/t_stripealign.c b/src/t_stripealign.c
> index 05ed36b5..690f743a 100644
> --- a/src/t_stripealign.c
> +++ b/src/t_stripealign.c
> @@ -17,8 +17,13 @@
> #include <fcntl.h>
> #include <stdio.h>
> #include <sys/ioctl.h>
> +#include <linux/fiemap.h>
> +#include <linux/fs.h>
As it requires <linux/fiemap.h> now, looks like we should update
src/Makefile too to only compile it when "HAVE_FIEMAP" is true.
ifeq ($(HAVE_FIEMAP), true)
LINUX_TARGETS += fiemap-tester t_stripealign
endif
Thanks,
Eryu
P.S.
LINUX_TARGETS could be cleaned up and merged with TARGETS, it's useless
to have both TARGETS and LINUX_TARGETS defined now, as we only support
Linux platform, but that's a different issue.
>
> -#define FIBMAP _IO(0x00, 1) /* bmap access */
> +#define FIEMAP_EXTENT_ACCEPTABLE (FIEMAP_EXTENT_LAST | \
> + FIEMAP_EXTENT_DATA_ENCRYPTED | FIEMAP_EXTENT_ENCODED | \
> + FIEMAP_EXTENT_UNWRITTEN | FIEMAP_EXTENT_MERGED | \
> + FIEMAP_EXTENT_SHARED)
>
> /*
> * If only filename given, print first block.
> @@ -28,11 +33,14 @@
>
> int main(int argc, char ** argv)
> {
> - int fd;
> - int ret;
> - int sunit = 0; /* in blocks */
> - char *filename;
> - unsigned int block = 0;
> + struct stat sb;
> + struct fiemap *fie;
> + struct fiemap_extent *fe;
> + int fd;
> + int ret;
> + int sunit = 0; /* in blocks */
> + char *filename;
> + unsigned long long block;
>
> if (argc < 3) {
> printf("Usage: %s <filename> <sunit in blocks>\n", argv[0]);
> @@ -48,21 +56,63 @@ int main(int argc, char ** argv)
> return 1;
> }
>
> - ret = ioctl(fd, FIBMAP, &block);
> - if (ret < 0) {
> + ret = fstat(fd, &sb);
> + if (ret) {
> + perror(filename);
> close(fd);
> - perror("fibmap");
> return 1;
> }
>
> - close(fd);
> + fie = calloc(1, sizeof(struct fiemap) + sizeof(struct fiemap_extent));
> + if (!fie) {
> + close(fd);
> + perror("malloc");
> + return 1;
> + }
> + fie->fm_length = 1;
> + fie->fm_flags = FIEMAP_FLAG_SYNC;
> + fie->fm_extent_count = 1;
> +
> + ret = ioctl(fd, FS_IOC_FIEMAP, fie);
> + if (ret < 0) {
> + unsigned int bmap = 0;
> +
> + ret = ioctl(fd, FIBMAP, &bmap);
> + if (ret < 0) {
> + perror("fibmap");
> + free(fie);
> + close(fd);
> + return 1;
> + }
> + block = bmap;
> + goto check;
> + }
>
> +
> + if (fie->fm_mapped_extents != 1) {
> + printf("%s: no extents?\n", filename);
> + free(fie);
> + close(fd);
> + return 1;
> + }
> + fe = &fie->fm_extents[0];
> + if (fe->fe_flags & ~FIEMAP_EXTENT_ACCEPTABLE) {
> + printf("%s: bad flags 0x%x\n", filename, fe->fe_flags);
> + free(fie);
> + close(fd);
> + return 1;
> + }
> +
> + block = fie->fm_extents[0].fe_physical / sb.st_blksize;
> +check:
> if (block % sunit) {
> - printf("%s: Start block %u not multiple of sunit %u\n",
> + printf("%s: Start block %llu not multiple of sunit %u\n",
> filename, block, sunit);
> return 1;
> } else
> printf("%s: well-aligned\n", filename);
> + free(fie);
> + close(fd);
>
> return 0;
> }
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] generic/223: port t_stripealign to FIEMAP
2018-06-15 2:49 ` Eryu Guan
@ 2018-06-17 14:39 ` Eryu Guan
0 siblings, 0 replies; 3+ messages in thread
From: Eryu Guan @ 2018-06-17 14:39 UTC (permalink / raw)
To: Darrick J. Wong; +Cc: fstests, xfs, Ross Zwisler
On Fri, Jun 15, 2018 at 10:49:01AM +0800, Eryu Guan wrote:
> On Wed, Jun 13, 2018 at 03:50:57PM -0700, Darrick J. Wong wrote:
> > From: Darrick J. Wong <darrick.wong@oracle.com>
> >
> > Since XFS has deprecated FIBMAP on FSDAX filesystems, we can't use
> > FIBMAP to verify stripe alignment anymore. FIEMAP has existed for quite
> > some time now, so port it to use that instead, and only fall back to
> > FIBMAP if FIEMAP doesn't exist.
> >
> > Tested-by: ross.zwisler@linux.intel.com
> > Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
> > ---
> > src/t_stripealign.c | 72 +++++++++++++++++++++++++++++++++++++++++++--------
> > 1 file changed, 61 insertions(+), 11 deletions(-)
> >
> > diff --git a/src/t_stripealign.c b/src/t_stripealign.c
> > index 05ed36b5..690f743a 100644
> > --- a/src/t_stripealign.c
> > +++ b/src/t_stripealign.c
> > @@ -17,8 +17,13 @@
> > #include <fcntl.h>
> > #include <stdio.h>
> > #include <sys/ioctl.h>
> > +#include <linux/fiemap.h>
> > +#include <linux/fs.h>
>
> As it requires <linux/fiemap.h> now, looks like we should update
> src/Makefile too to only compile it when "HAVE_FIEMAP" is true.
>
> ifeq ($(HAVE_FIEMAP), true)
> LINUX_TARGETS += fiemap-tester t_stripealign
> endif
JFYI, I fixed it on commit (also remove t_stripealign from TARGETS).
Thanks,
Eryu
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2018-06-17 14:39 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-06-13 22:50 [PATCH] generic/223: port t_stripealign to FIEMAP Darrick J. Wong
2018-06-15 2:49 ` Eryu Guan
2018-06-17 14:39 ` Eryu Guan
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).