* [PATCH v2] iogen: upgrade to fallocate
@ 2022-01-18 18:29 Darrick J. Wong
2022-01-23 13:19 ` Eryu Guan
0 siblings, 1 reply; 3+ messages in thread
From: Darrick J. Wong @ 2022-01-18 18:29 UTC (permalink / raw)
To: guaneryu; +Cc: linux-xfs, fstests, guan
From: Darrick J. Wong <djwong@kernel.org>
Update this utility to use fallocate to preallocate/reserve space to a
file so that we're not so dependent on legacy XFS ioctls. Fix a minor
whitespace error while we're at it.
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
---
v2: fix the fallocate flags for the resvsp replacement code
---
ltp/iogen.c | 34 +++++++++++++++++++++++-----------
1 file changed, 23 insertions(+), 11 deletions(-)
diff --git a/ltp/iogen.c b/ltp/iogen.c
index 2b6644d5..c43cc1d0 100644
--- a/ltp/iogen.c
+++ b/ltp/iogen.c
@@ -922,13 +922,21 @@ bozo!
f.l_whence = SEEK_SET;
f.l_start = 0;
f.l_len = nbytes;
-
+
/*fprintf(stderr,
"create_file: xfsctl(%d, RESVSP, { %d, %lld, %lld })\n",
fd, f.l_whence, (long long)f.l_start, (long long)f.l_len);*/
/* non-zeroing reservation */
-#ifdef XFS_IOC_RESVSP
+#if defined(FALLOCATE)
+ if (fallocate(fd, FALLOC_FL_KEEP_SIZE, 0, nbytes) == -1) {
+ fprintf(stderr,
+ "iogen%s: Could not fallocate %d bytes in file %s: %s (%d)\n",
+ TagName, nbytes, path, SYSERR, errno);
+ close(fd);
+ return -1;
+ }
+#elif defined(XFS_IOC_RESVSP)
if( xfsctl( path, fd, XFS_IOC_RESVSP, &f ) == -1) {
fprintf(stderr,
"iogen%s: Could not xfsctl(XFS_IOC_RESVSP) %d bytes in file %s: %s (%d)\n",
@@ -936,8 +944,7 @@ bozo!
close(fd);
return -1;
}
-#else
-#ifdef F_RESVSP
+#elif defined(F_RESVSP)
if( fcntl( fd, F_RESVSP, &f ) == -1) {
fprintf(stderr,
"iogen%s: Could not fcntl(F_RESVSP) %d bytes in file %s: %s (%d)\n",
@@ -946,8 +953,7 @@ bozo!
return -1;
}
#else
-bozo!
-#endif
+# error Dont know how to reserve space!
#endif
}
@@ -962,7 +968,15 @@ bozo!
(long long)f.l_len);*/
/* zeroing reservation */
-#ifdef XFS_IOC_ALLOCSP
+#if defined(FALLOCATE)
+ if (fallocate(fd, 0, sbuf.st_size, nbytes - sbuf.st_size) == -1) {
+ fprintf(stderr,
+ "iogen%s: Could not fallocate %d bytes in file %s: %s (%d)\n",
+ TagName, nbytes, path, SYSERR, errno);
+ close(fd);
+ return -1;
+ }
+#elif defined(XFS_IOC_ALLOCSP)
if( xfsctl( path, fd, XFS_IOC_ALLOCSP, &f ) == -1) {
fprintf(stderr,
"iogen%s: Could not xfsctl(XFS_IOC_ALLOCSP) %d bytes in file %s: %s (%d)\n",
@@ -970,8 +984,7 @@ bozo!
close(fd);
return -1;
}
-#else
-#ifdef F_ALLOCSP
+#elif defined(F_ALLOCSP)
if ( fcntl(fd, F_ALLOCSP, &f) < 0) {
fprintf(stderr,
"iogen%s: Could not fcntl(F_ALLOCSP) %d bytes in file %s: %s (%d)\n",
@@ -980,8 +993,7 @@ bozo!
return -1;
}
#else
-bozo!
-#endif
+# error Dont know how to (pre)allocate space!
#endif
}
#endif
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] iogen: upgrade to fallocate
2022-01-18 18:29 [PATCH v2] iogen: upgrade to fallocate Darrick J. Wong
@ 2022-01-23 13:19 ` Eryu Guan
2022-01-24 18:40 ` Darrick J. Wong
0 siblings, 1 reply; 3+ messages in thread
From: Eryu Guan @ 2022-01-23 13:19 UTC (permalink / raw)
To: Darrick J. Wong; +Cc: guaneryu, linux-xfs, fstests
On Tue, Jan 18, 2022 at 10:29:10AM -0800, Darrick J. Wong wrote:
> From: Darrick J. Wong <djwong@kernel.org>
>
> Update this utility to use fallocate to preallocate/reserve space to a
> file so that we're not so dependent on legacy XFS ioctls. Fix a minor
> whitespace error while we're at it.
>
> Signed-off-by: Darrick J. Wong <djwong@kernel.org>
> ---
> v2: fix the fallocate flags for the resvsp replacement code
> ---
> ltp/iogen.c | 34 +++++++++++++++++++++++-----------
> 1 file changed, 23 insertions(+), 11 deletions(-)
>
> diff --git a/ltp/iogen.c b/ltp/iogen.c
> index 2b6644d5..c43cc1d0 100644
> --- a/ltp/iogen.c
> +++ b/ltp/iogen.c
> @@ -922,13 +922,21 @@ bozo!
> f.l_whence = SEEK_SET;
> f.l_start = 0;
> f.l_len = nbytes;
> -
> +
> /*fprintf(stderr,
> "create_file: xfsctl(%d, RESVSP, { %d, %lld, %lld })\n",
> fd, f.l_whence, (long long)f.l_start, (long long)f.l_len);*/
>
> /* non-zeroing reservation */
> -#ifdef XFS_IOC_RESVSP
> +#if defined(FALLOCATE)
> + if (fallocate(fd, FALLOC_FL_KEEP_SIZE, 0, nbytes) == -1) {
gcc warns about
iogen.c: In function 'create_file':
iogen.c:820:20: warning: variable 'f' set but not used [-Wunused-but-set-variable]
820 | struct flock64 f;
| ^
So I replaced 'nbytes' with 'f.l_len' in above fallocate(2) call.
Thanks,
Eryu
> + fprintf(stderr,
> + "iogen%s: Could not fallocate %d bytes in file %s: %s (%d)\n",
> + TagName, nbytes, path, SYSERR, errno);
> + close(fd);
> + return -1;
> + }
> +#elif defined(XFS_IOC_RESVSP)
> if( xfsctl( path, fd, XFS_IOC_RESVSP, &f ) == -1) {
> fprintf(stderr,
> "iogen%s: Could not xfsctl(XFS_IOC_RESVSP) %d bytes in file %s: %s (%d)\n",
> @@ -936,8 +944,7 @@ bozo!
> close(fd);
> return -1;
> }
> -#else
> -#ifdef F_RESVSP
> +#elif defined(F_RESVSP)
> if( fcntl( fd, F_RESVSP, &f ) == -1) {
> fprintf(stderr,
> "iogen%s: Could not fcntl(F_RESVSP) %d bytes in file %s: %s (%d)\n",
> @@ -946,8 +953,7 @@ bozo!
> return -1;
> }
> #else
> -bozo!
> -#endif
> +# error Dont know how to reserve space!
> #endif
> }
>
> @@ -962,7 +968,15 @@ bozo!
> (long long)f.l_len);*/
>
> /* zeroing reservation */
> -#ifdef XFS_IOC_ALLOCSP
> +#if defined(FALLOCATE)
> + if (fallocate(fd, 0, sbuf.st_size, nbytes - sbuf.st_size) == -1) {
> + fprintf(stderr,
> + "iogen%s: Could not fallocate %d bytes in file %s: %s (%d)\n",
> + TagName, nbytes, path, SYSERR, errno);
> + close(fd);
> + return -1;
> + }
> +#elif defined(XFS_IOC_ALLOCSP)
> if( xfsctl( path, fd, XFS_IOC_ALLOCSP, &f ) == -1) {
> fprintf(stderr,
> "iogen%s: Could not xfsctl(XFS_IOC_ALLOCSP) %d bytes in file %s: %s (%d)\n",
> @@ -970,8 +984,7 @@ bozo!
> close(fd);
> return -1;
> }
> -#else
> -#ifdef F_ALLOCSP
> +#elif defined(F_ALLOCSP)
> if ( fcntl(fd, F_ALLOCSP, &f) < 0) {
> fprintf(stderr,
> "iogen%s: Could not fcntl(F_ALLOCSP) %d bytes in file %s: %s (%d)\n",
> @@ -980,8 +993,7 @@ bozo!
> return -1;
> }
> #else
> -bozo!
> -#endif
> +# error Dont know how to (pre)allocate space!
> #endif
> }
> #endif
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] iogen: upgrade to fallocate
2022-01-23 13:19 ` Eryu Guan
@ 2022-01-24 18:40 ` Darrick J. Wong
0 siblings, 0 replies; 3+ messages in thread
From: Darrick J. Wong @ 2022-01-24 18:40 UTC (permalink / raw)
To: Eryu Guan; +Cc: guaneryu, linux-xfs, fstests
On Sun, Jan 23, 2022 at 09:19:08PM +0800, Eryu Guan wrote:
> On Tue, Jan 18, 2022 at 10:29:10AM -0800, Darrick J. Wong wrote:
> > From: Darrick J. Wong <djwong@kernel.org>
> >
> > Update this utility to use fallocate to preallocate/reserve space to a
> > file so that we're not so dependent on legacy XFS ioctls. Fix a minor
> > whitespace error while we're at it.
> >
> > Signed-off-by: Darrick J. Wong <djwong@kernel.org>
> > ---
> > v2: fix the fallocate flags for the resvsp replacement code
> > ---
> > ltp/iogen.c | 34 +++++++++++++++++++++++-----------
> > 1 file changed, 23 insertions(+), 11 deletions(-)
> >
> > diff --git a/ltp/iogen.c b/ltp/iogen.c
> > index 2b6644d5..c43cc1d0 100644
> > --- a/ltp/iogen.c
> > +++ b/ltp/iogen.c
> > @@ -922,13 +922,21 @@ bozo!
> > f.l_whence = SEEK_SET;
> > f.l_start = 0;
> > f.l_len = nbytes;
> > -
> > +
> > /*fprintf(stderr,
> > "create_file: xfsctl(%d, RESVSP, { %d, %lld, %lld })\n",
> > fd, f.l_whence, (long long)f.l_start, (long long)f.l_len);*/
> >
> > /* non-zeroing reservation */
> > -#ifdef XFS_IOC_RESVSP
> > +#if defined(FALLOCATE)
> > + if (fallocate(fd, FALLOC_FL_KEEP_SIZE, 0, nbytes) == -1) {
>
> gcc warns about
>
> iogen.c: In function 'create_file':
> iogen.c:820:20: warning: variable 'f' set but not used [-Wunused-but-set-variable]
> 820 | struct flock64 f;
> | ^
>
> So I replaced 'nbytes' with 'f.l_len' in above fallocate(2) call.
Oh, thank you for fixing that!
--D
> Thanks,
> Eryu
>
> > + fprintf(stderr,
> > + "iogen%s: Could not fallocate %d bytes in file %s: %s (%d)\n",
> > + TagName, nbytes, path, SYSERR, errno);
> > + close(fd);
> > + return -1;
> > + }
> > +#elif defined(XFS_IOC_RESVSP)
> > if( xfsctl( path, fd, XFS_IOC_RESVSP, &f ) == -1) {
> > fprintf(stderr,
> > "iogen%s: Could not xfsctl(XFS_IOC_RESVSP) %d bytes in file %s: %s (%d)\n",
> > @@ -936,8 +944,7 @@ bozo!
> > close(fd);
> > return -1;
> > }
> > -#else
> > -#ifdef F_RESVSP
> > +#elif defined(F_RESVSP)
> > if( fcntl( fd, F_RESVSP, &f ) == -1) {
> > fprintf(stderr,
> > "iogen%s: Could not fcntl(F_RESVSP) %d bytes in file %s: %s (%d)\n",
> > @@ -946,8 +953,7 @@ bozo!
> > return -1;
> > }
> > #else
> > -bozo!
> > -#endif
> > +# error Dont know how to reserve space!
> > #endif
> > }
> >
> > @@ -962,7 +968,15 @@ bozo!
> > (long long)f.l_len);*/
> >
> > /* zeroing reservation */
> > -#ifdef XFS_IOC_ALLOCSP
> > +#if defined(FALLOCATE)
> > + if (fallocate(fd, 0, sbuf.st_size, nbytes - sbuf.st_size) == -1) {
> > + fprintf(stderr,
> > + "iogen%s: Could not fallocate %d bytes in file %s: %s (%d)\n",
> > + TagName, nbytes, path, SYSERR, errno);
> > + close(fd);
> > + return -1;
> > + }
> > +#elif defined(XFS_IOC_ALLOCSP)
> > if( xfsctl( path, fd, XFS_IOC_ALLOCSP, &f ) == -1) {
> > fprintf(stderr,
> > "iogen%s: Could not xfsctl(XFS_IOC_ALLOCSP) %d bytes in file %s: %s (%d)\n",
> > @@ -970,8 +984,7 @@ bozo!
> > close(fd);
> > return -1;
> > }
> > -#else
> > -#ifdef F_ALLOCSP
> > +#elif defined(F_ALLOCSP)
> > if ( fcntl(fd, F_ALLOCSP, &f) < 0) {
> > fprintf(stderr,
> > "iogen%s: Could not fcntl(F_ALLOCSP) %d bytes in file %s: %s (%d)\n",
> > @@ -980,8 +993,7 @@ bozo!
> > return -1;
> > }
> > #else
> > -bozo!
> > -#endif
> > +# error Dont know how to (pre)allocate space!
> > #endif
> > }
> > #endif
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-01-24 18:40 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-01-18 18:29 [PATCH v2] iogen: upgrade to fallocate Darrick J. Wong
2022-01-23 13:19 ` Eryu Guan
2022-01-24 18:40 ` Darrick J. Wong
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).