backport gfs2_jadd: Use fallocate to preallocate journals
From Signed-off-by: Andrew Price <anprice@redhat.com> commit 2010383c860ef8ca2a80e6394b9cb89942a426e0 Signed-off-by: Guangzhong Yao <yaoguangzhong@xfusion.com>
This commit is contained in:
parent
5508a3ad68
commit
e04748d57b
82
0003-gfs2_jadd-Use-fallocate-to-preallocate-journals.patch
Normal file
82
0003-gfs2_jadd-Use-fallocate-to-preallocate-journals.patch
Normal file
@ -0,0 +1,82 @@
|
||||
From 2010383c860ef8ca2a80e6394b9cb89942a426e0 Mon Sep 17 00:00:00 2001
|
||||
From: Andrew Price <anprice@redhat.com>
|
||||
Date: Thu, 18 Mar 2021 17:30:53 +0000
|
||||
Subject: [PATCH] gfs2_jadd: Use fallocate to preallocate journals
|
||||
|
||||
Fall back to writes for ancient kernels and use larger writes in that
|
||||
case to reduce the chance of fragmentation.
|
||||
|
||||
Signed-off-by: Andrew Price <anprice@redhat.com>
|
||||
---
|
||||
gfs2/mkfs/main_jadd.c | 48 +++++++++++++++++++++++++++++++++++--------
|
||||
1 file changed, 40 insertions(+), 8 deletions(-)
|
||||
|
||||
diff --git a/gfs2/mkfs/main_jadd.c b/gfs2/mkfs/main_jadd.c
|
||||
index 7583ba0f..0a18bfb2 100644
|
||||
--- a/gfs2/mkfs/main_jadd.c
|
||||
+++ b/gfs2/mkfs/main_jadd.c
|
||||
@@ -480,6 +480,43 @@ static uint64_t find_block_address(int fd, off_t offset, unsigned bsize)
|
||||
}
|
||||
#endif
|
||||
|
||||
+static int alloc_new_journal(int fd, unsigned bytes)
|
||||
+{
|
||||
+#define ALLOC_BUF_SIZE (4 << 20)
|
||||
+ unsigned left = bytes;
|
||||
+ int error;
|
||||
+ char *buf;
|
||||
+
|
||||
+ error = fallocate(fd, 0, 0, bytes);
|
||||
+ if (error == 0)
|
||||
+ return 0;
|
||||
+ if (errno != EOPNOTSUPP)
|
||||
+ goto out_errno;
|
||||
+
|
||||
+ /* No fallocate support, fall back to writes */
|
||||
+ buf = calloc(1, ALLOC_BUF_SIZE);
|
||||
+ if (buf == NULL)
|
||||
+ goto out_errno;
|
||||
+
|
||||
+ while (left > 0) {
|
||||
+ unsigned sz = ALLOC_BUF_SIZE;
|
||||
+
|
||||
+ if (left < ALLOC_BUF_SIZE)
|
||||
+ sz = left;
|
||||
+
|
||||
+ if (pwrite(fd, buf, sz, bytes - left) != sz) {
|
||||
+ free(buf);
|
||||
+ goto out_errno;
|
||||
+ }
|
||||
+ left -= sz;
|
||||
+ }
|
||||
+ free(buf);
|
||||
+ return 0;
|
||||
+out_errno:
|
||||
+ perror("Failed to allocate space for new journal");
|
||||
+ return -1;
|
||||
+}
|
||||
+
|
||||
static int add_j(struct gfs2_sbd *sdp, struct jadd_opts *opts)
|
||||
{
|
||||
int fd, error = 0;
|
||||
@@ -496,14 +533,9 @@ static int add_j(struct gfs2_sbd *sdp, struct jadd_opts *opts)
|
||||
if ((error = set_flags(fd, JA_FL_CLEAR, FS_JOURNAL_DATA_FL)))
|
||||
goto close_fd;
|
||||
|
||||
- memset(buf, 0, sdp->bsize);
|
||||
- for (x=0; x<blocks; x++) {
|
||||
- if (write(fd, buf, sdp->bsize) != sdp->bsize) {
|
||||
- perror("add_j write");
|
||||
- error = -1;
|
||||
- goto close_fd;
|
||||
- }
|
||||
- }
|
||||
+ error = alloc_new_journal(fd, sdp->jsize << 20);
|
||||
+ if (error != 0)
|
||||
+ goto close_fd;
|
||||
|
||||
if ((error = lseek(fd, 0, SEEK_SET)) < 0) {
|
||||
perror("add_j lseek");
|
||||
--
|
||||
2.27.0
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
Name: gfs2-utils
|
||||
Version: 3.4.1
|
||||
Release: 2
|
||||
Release: 3
|
||||
Summary: Utilities for managing the global file system (GFS2)
|
||||
|
||||
License: GPLv2+ and LGPLv2+
|
||||
@ -9,6 +9,7 @@ Source0: https://releases.pagure.org/gfs2-utils/gfs2-utils-%{version}.tar
|
||||
# https://github.com/andyprice/gfs2-utils/commit/17fb470
|
||||
Patch0: 0001-gfs2-edit-always-use-s-style-format-for-printf-style.patch
|
||||
Patch1: 0002-fix-error-format-in-gfs2hex.patch
|
||||
Patch2: 0003-gfs2_jadd-Use-fallocate-to-preallocate-journals.patch
|
||||
|
||||
BuildRequires: ncurses-devel kernel-headers automake libtool zlib-devel gettext-devel
|
||||
BuildRequires: bison flex libblkid-devel libuuid-devel check-devel bzip2-devel make
|
||||
@ -54,6 +55,9 @@ rm -f %{buildroot}%{_mandir}/man8/gfs2_lockcapture.8
|
||||
|
||||
|
||||
%changelog
|
||||
* Sat Jan 7 2023 yaoguangzhong <yaoguangzhong@xfusion.com> - 3.4.1-3
|
||||
- backport gfs2_jadd: Use fallocate to preallocate journals
|
||||
|
||||
* Thu Apr 07 2022 wangkai <wangkai@h-partners.com> - 3.4.1-2
|
||||
- fix build error
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user