[gfs2-utils] 01/01: gfs2_edit: truncate to filesystem size at end of
restoremeta()
by pagure@pagure.io
This is an automated email from the git hooks/post-receive script.
andyp pushed a commit to branch RHEL9
in repository gfs2-utils.
commit f837169ab53dc915e10bdb480eaeb5bbb52c0c09
Author: Paul Evans <pevans(a)redhat.com>
AuthorDate: Wed Mar 6 12:28:16 2024 +0000
gfs2_edit: truncate to filesystem size at end of restoremeta()
Truncate to metadata header's filesystem size at the end of restore if
a header is present.
Resolves: RHEL-26661
Signed-off-by: Paul Evans <pevans(a)redhat.com>
---
gfs2/edit/savemeta.c | 32 +++++++++++++++++++++++++-------
tests/edit.at | 10 ++++++++++
2 files changed, 35 insertions(+), 7 deletions(-)
diff --git a/gfs2/edit/savemeta.c b/gfs2/edit/savemeta.c
index 4ee76be0..f5448974 100644
--- a/gfs2/edit/savemeta.c
+++ b/gfs2/edit/savemeta.c
@@ -1327,9 +1327,8 @@ static void restoremeta_usage(void)
fprintf(stderr, "gfs2_edit restoremeta <metadata_file> <block_device>\n");
}
-static int restore_init(const char *path, struct metafd *mfd, int printonly)
+static int restore_init(const char *path, struct metafd *mfd, struct savemeta *sm, int printonly)
{
- struct savemeta sm = {0};
struct gfs2_sb rsb;
uint16_t sb_siglen;
char *end;
@@ -1357,7 +1356,7 @@ static int restore_init(const char *path, struct metafd *mfd, int printonly)
return -1;
}
bp = restore_buf;
- ret = parse_header(bp, &sm);
+ ret = parse_header(bp, sm);
if (ret == 0) {
bp = restore_buf + sizeof(struct savemeta_header);
restore_off = sizeof(struct savemeta_header);
@@ -1383,10 +1382,10 @@ static int restore_init(const char *path, struct metafd *mfd, int printonly)
if (ret != 0)
return ret;
- if (sm.sm_fs_bytes > 0) {
- sbd.fssize = sm.sm_fs_bytes / sbd.sd_bsize;
+ if (sm->sm_fs_bytes > 0) {
+ sbd.fssize = sm->sm_fs_bytes / sbd.sd_bsize;
printf("Saved file system size is %"PRIu64" blocks, %.2fGB\n",
- sbd.fssize, sm.sm_fs_bytes / ((float)(1 << 30)));
+ sbd.fssize, sm->sm_fs_bytes / ((float)(1 << 30)));
}
printf("Block size is %uB\n", sbd.sd_bsize);
printf("This is gfs%c metadata.\n", sbd.gfs1 ? '1': '2');
@@ -1406,6 +1405,8 @@ static int restore_init(const char *path, struct metafd *mfd, int printonly)
void restoremeta(const char *in_fn, const char *out_device, uint64_t printonly)
{
struct metafd mfd = {0};
+ struct savemeta sm = {0};
+ struct stat st;
int error;
termlines = 0;
@@ -1430,7 +1431,7 @@ void restoremeta(const char *in_fn, const char *out_device, uint64_t printonly)
optional block no */
printonly = check_keywords(out_device);
- error = restore_init(in_fn, &mfd, printonly);
+ error = restore_init(in_fn, &mfd, &sm, printonly);
if (error != 0)
exit(error);
@@ -1440,6 +1441,23 @@ void restoremeta(const char *in_fn, const char *out_device, uint64_t printonly)
}
error = restore_data(sbd.device_fd, &mfd, printonly);
+
+ /* When there is a metadata header available, truncate to filesystem
+ size if our device_fd is a regular file */
+ if (!printonly) {
+ if (fstat(sbd.device_fd, &st) == -1) {
+ fprintf(stderr, "Failed to stat %s: %s\n", out_device, strerror(errno));
+ error = errno;
+ }
+
+ if (sm.sm_fs_bytes > 0 && S_ISREG(st.st_mode)) {
+ if (ftruncate(sbd.device_fd, sm.sm_fs_bytes) != 0) {
+ fprintf(stderr, "Failed to truncate: %s, %s\n", out_device, strerror(errno));
+ error = errno;
+ }
+ }
+ }
+
printf("File %s %s %s.\n", in_fn,
(printonly ? "print" : "restore"),
(error ? "error" : "successful"));
diff --git a/tests/edit.at b/tests/edit.at
index d6795218..29835df0 100644
--- a/tests/edit.at
+++ b/tests/edit.at
@@ -61,3 +61,13 @@ AT_CHECK([$GFS_MKFS -p lock_nolock $GFS_TGT], 0, [ignore], [ignore])
AT_CHECK([gfs2_edit savemeta -z0 $GFS_TGT /dev/null], 0, [ignore], [ignore])
AT_CHECK([gfs2_edit savemeta $GFS_TGT /dev/null], 0, [ignore], [ignore])
AT_CLEANUP
+
+AT_SETUP([Truncate on restoremeta])
+AT_KEYWORDS(gfs2_edit edit)
+GFS_TGT_REGEN
+AT_CHECK([$GFS_MKFS -p lock_nolock $GFS_TGT], 0, [ignore], [ignore])
+AT_CHECK([gfs2_edit savemeta $GFS_TGT test.meta], 0, [ignore], [ignore])
+AT_CHECK([truncate -s 10K test.file], 0, [ignore], [ignore])
+AT_CHECK([gfs2_edit restoremeta test.meta test.file], 0, [ignore], [ignore])
+AT_CHECK([fsck.gfs2 -n test.file], 0, [ignore], [ignore])
+AT_CLEANUP
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
1 day, 10 hours
[gfs2-utils] branch RHEL9 created (now f837169a)
by pagure@pagure.io
This is an automated email from the git hooks/post-receive script.
andyp pushed a change to branch RHEL9
in repository gfs2-utils.
at f837169a gfs2_edit: truncate to filesystem size at end of restoremeta()
This branch includes the following new commits:
new f837169a gfs2_edit: truncate to filesystem size at end of restoremeta()
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
1 day, 10 hours
[gfs2-utils] branch main updated (6137e458 -> 4bda97c1)
by pagure@pagure.io
This is an automated email from the git hooks/post-receive script.
andyp pushed a change to branch main
in repository gfs2-utils.
from 6137e458 make rpm: Don't use rpmbuild --buildroot
add 4bda97c1 libgfs2: Add function to map block states to names
No new revisions were added by this update.
Summary of changes:
gfs2/edit/hexedit.c | 17 +++++------------
gfs2/edit/hexedit.h | 1 -
gfs2/edit/journal.c | 3 +--
gfs2/fsck/metawalk.c | 5 ++---
gfs2/libgfs2/fs_bits.c | 18 +++++++++++++++++-
gfs2/libgfs2/libgfs2.h | 3 +++
6 files changed, 28 insertions(+), 19 deletions(-)
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
4 days, 12 hours