Blame SOURCES/0003-xfsrestore-fix-on-media-inventory-media-unpacking.patch

4c97d8
From 06dd184d3a689dcb33a50b6e3576e48055e48133 Mon Sep 17 00:00:00 2001
4c97d8
From: Donald Douwsma <ddouwsma@redhat.com>
4c97d8
Date: Fri, 14 Oct 2022 18:58:44 +1100
4c97d8
Subject: [PATCH 3/7] xfsrestore: fix on-media inventory media unpacking
4c97d8
4c97d8
When xfsrestore reads the inventory from tape media it fails to convert
4c97d8
media file records from bigendian. If the xfsdump inventory is not
4c97d8
available xfsrestore will write this invalid record to the on-line
4c97d8
inventory.
4c97d8
4c97d8
[root@rhel8 ~]# xfsdump -L Test1 -M "" -f /dev/st0 /boot > /dev/null
4c97d8
[root@rhel8 ~]# xfsdump -L Test2 -M "" -f /dev/st0 /boot > /dev/null
4c97d8
[root@rhel8 ~]# rm -rf /var/lib/xfsdump/inventory/
4c97d8
[root@rhel8 ~]# mt -f /dev/nst0 asf 2
4c97d8
[root@rhel8 ~]# xfsrestore -f /dev/nst0 -L Test2 /tmp/test2
4c97d8
xfsrestore: using scsi tape (drive_scsitape) strategy
4c97d8
xfsrestore: version 3.1.8 (dump format 3.0) - type ^C for status and control
4c97d8
xfsrestore: searching media for dump
4c97d8
xfsrestore: preparing drive
4c97d8
xfsrestore: examining media file 3
4c97d8
xfsrestore: found dump matching specified label:
4c97d8
xfsrestore: hostname: rhel8
4c97d8
xfsrestore: mount point: /boot
4c97d8
xfsrestore: volume: /dev/sda1
4c97d8
xfsrestore: session time: Tue Sep 27 16:05:28 2022
4c97d8
xfsrestore: level: 0
4c97d8
xfsrestore: session label: "Test2"
4c97d8
xfsrestore: media label: ""
4c97d8
xfsrestore: file system id: 26dd5aa0-b901-4cf5-9b68-0c5753cb3ab8
4c97d8
xfsrestore: session id: 62402423-7ae0-49ed-8ecb-9e5bc7642b91
4c97d8
xfsrestore: media id: 47ba45ca-3417-4006-ab10-3dc6419b83e2
4c97d8
xfsrestore: incorporating on-media session inventory into online inventory
4c97d8
xfsrestore: /var/lib/xfsdump/inventory created
4c97d8
xfsrestore: using on-media session inventory
4c97d8
xfsrestore: searching media for directory dump
4c97d8
xfsrestore: rewinding
4c97d8
xfsrestore: examining media file 0
4c97d8
xfsrestore: inventory session uuid (62402423-7ae0-49ed-8ecb-9e5bc7642b91) does not match the media header's session uuid (1771d9e8-a1ba-4e87-a61e-f6be97e41b45)
4c97d8
xfsrestore: examining media file 1
4c97d8
xfsrestore: inventory session uuid (62402423-7ae0-49ed-8ecb-9e5bc7642b91) does not match the media header's session uuid (1771d9e8-a1ba-4e87-a61e-f6be97e41b45)
4c97d8
xfsrestore: examining media file 2
4c97d8
xfsrestore: reading directories
4c97d8
xfsrestore: 9 directories and 320 entries processed
4c97d8
xfsrestore: directory post-processing
4c97d8
xfsrestore: restore complete: 0 seconds elapsed
4c97d8
xfsrestore: Restore Summary:
4c97d8
xfsrestore:   stream 0 /dev/nst0 OK (success)
4c97d8
xfsrestore: Restore Status: SUCCESS
4c97d8
[root@rhel8 ~]# xfsdump -I
4c97d8
file system 0:
4c97d8
        fs id:          26dd5aa0-b901-4cf5-9b68-0c5753cb3ab8
4c97d8
        session 0:
4c97d8
                mount point:    rhel8:/boot
4c97d8
                device:         rhel8:/dev/sda1
4c97d8
                time:           Tue Sep 27 16:05:28 2022
4c97d8
                session label:  "Test2"
4c97d8
                session id:     62402423-7ae0-49ed-8ecb-9e5bc7642b91
4c97d8
                level:          0
4c97d8
                resumed:        NO
4c97d8
                subtree:        NO
4c97d8
                streams:        1
4c97d8
                stream 0:
4c97d8
                        pathname:       /dev/st0
4c97d8
                        start:          ino 133 offset 0
4c97d8
                        end:            ino 1572997 offset 0
4c97d8
                        interrupted:    YES
4c97d8
                        media files:    1
4c97d8
                        media file 0:
4c97d8
                                mfile index:    33554432
4c97d8
                                mfile type:     data
4c97d8
                                mfile size:     211187836911616
4c97d8
                                mfile start:    ino 9583660007044415488 offset 0
4c97d8
                                mfile end:      ino 9583686395323482112 offset 0
4c97d8
                                media label:    ""
4c97d8
                                media id:       47ba45ca-3417-4006-ab10-3dc6419b83e2
4c97d8
xfsdump: Dump Status: SUCCESS
4c97d8
[root@rhel8 ~]#
4c97d8
[root@rhel8 ~]# ls /tmp/test2
4c97d8
efi  grub2  loader
4c97d8
4c97d8
The invalid start and end inode information cause xfsrestore to consider
4c97d8
that non-directory files do not reside in the current media and will
4c97d8
fail to restore them.
4c97d8
4c97d8
The behaviour of an initial restore may succeed if the position of the
4c97d8
tape is such that the data file is encountered before the inventory
4c97d8
file, or if there is only one dump session on tape, xfsrestore is
4c97d8
somewhat inconsistent in this regard. Subsequent restores will use the
4c97d8
invalid on-line inventory and fail to restore files.
4c97d8
4c97d8
Fix this by correctly unpacking the inventory data.
4c97d8
4c97d8
Signed-off-by: Donald Douwsma <ddouwsma@redhat.com>
4c97d8
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
4c97d8
Signed-off-by: Carlos Maiolino <cem@kernel.org>
4c97d8
---
4c97d8
4c97d8
diff --git a/inventory/inv_stobj.c b/inventory/inv_stobj.c
4c97d8
index e2e8767..cdf3300 100644
4c97d8
--- a/inventory/inv_stobj.c
4c97d8
+++ b/inventory/inv_stobj.c
4c97d8
@@ -1008,7 +1008,7 @@ stobj_unpack_sessinfo(
4c97d8
         size_t             bufsz,
4c97d8
 	invt_sessinfo_t   *s )
4c97d8
 {
4c97d8
-	uint 		 i;
4c97d8
+	uint 		 i, j;
4c97d8
 	char	         *tmpbuf;
4c97d8
 	char 		 *p = (char *)bufp;
4c97d8
 	
4c97d8
@@ -1087,28 +1087,15 @@ stobj_unpack_sessinfo(
4c97d8
 
4c97d8
 	/* all the media files */
4c97d8
 	s->mfiles = (invt_mediafile_t *)p;
4c97d8
-
4c97d8
-#ifdef INVT_DELETION
4c97d8
-	{
4c97d8
-		int tmpfd = open( "moids", O_RDWR | O_CREAT, S_IRUSR|S_IWUSR );
4c97d8
-		uint j;
4c97d8
-		invt_mediafile_t *mmf = s->mfiles;
4c97d8
-		for (i=0; i< s->ses->s_cur_nstreams; i++ ) {
4c97d8
-			for (j=0; j< s->strms[ i ].st_nmediafiles; 
4c97d8
-			     j++, mmf++ )
4c97d8
-				xlate_invt_mediafile((invt_mediafile_t *)mmf, (invt_mediafile_t *)tmpbuf, 1);
4c97d8
-				bcopy(tmpbuf, mmf, sizeof(invt_mediafile_t));
4c97d8
-				put_invtrecord( tmpfd, &mmf->mf_moid, 
4c97d8
-					 sizeof( uuid_t ), 0, SEEK_END, 0 );
4c97d8
+	for (i = 0; i < s->ses->s_cur_nstreams; i++) {
4c97d8
+		for(j = 0; j < s->strms[i].st_nmediafiles; j++) {
4c97d8
+			xlate_invt_mediafile((invt_mediafile_t *)p,
4c97d8
+					     (invt_mediafile_t *)tmpbuf, 1);
4c97d8
+			bcopy(tmpbuf, p, sizeof(invt_mediafile_t));
4c97d8
+			p +=  sizeof(invt_mediafile_t);
4c97d8
 		}
4c97d8
-		close( tmpfd );
4c97d8
-	}
4c97d8
-#endif
4c97d8
-	for ( i = 0; i < s->ses->s_cur_nstreams; i++ ) {
4c97d8
-		p += (size_t) ( s->strms[ i ].st_nmediafiles )
4c97d8
-			* sizeof( invt_mediafile_t );
4c97d8
 	}
4c97d8
-	
4c97d8
+
4c97d8
 	/* sanity check the size of the buffer given to us vs. the size it 
4c97d8
 	   should be */
4c97d8
 	if ( (size_t) ( p - (char *) bufp ) != bufsz ) {