Message ID | 20230606092806.1604491-17-chandan.babu@oracle.com (mailing list archive) |
---|---|
State | Superseded, archived |
Headers | show |
Series | Metadump v2 | expand |
On Tue, Jun 06, 2023 at 02:57:59PM +0530, Chandan Babu R wrote: > In order to support both v1 and v2 versions of metadump, mdrestore will have > to detect the format in which the metadump file has been stored on the disk > and then read the ondisk structures accordingly. In a step in that direction, > this commit splits the work of reading the metadump header from disk into two > parts > 1. Read the first 4 bytes containing the metadump magic code. > 2. Read the remaining part of the header. > > A future commit will take appropriate action based on the value of the magic > code. > > Signed-off-by: Chandan Babu R <chandan.babu@oracle.com> Seems reasonable to me, Reviewed-by: Darrick J. Wong <djwong@kernel.org> --D > --- > mdrestore/xfs_mdrestore.c | 17 ++++++++++++++--- > 1 file changed, 14 insertions(+), 3 deletions(-) > > diff --git a/mdrestore/xfs_mdrestore.c b/mdrestore/xfs_mdrestore.c > index 564630f7..2a9527b9 100644 > --- a/mdrestore/xfs_mdrestore.c > +++ b/mdrestore/xfs_mdrestore.c > @@ -198,6 +198,7 @@ main( > int open_flags; > struct stat statbuf; > int is_target_file; > + uint32_t magic; > struct xfs_metablock mb; > > mdrestore.show_progress = false; > @@ -245,10 +246,20 @@ main( > fatal("cannot open source dump file\n"); > } > > - if (fread(&mb, sizeof(mb), 1, src_f) != 1) > - fatal("error reading from metadump file\n"); > - if (mb.mb_magic != cpu_to_be32(XFS_MD_MAGIC_V1)) > + if (fread(&magic, sizeof(magic), 1, src_f) != 1) > + fatal("Unable to read metadump magic from metadump file\n"); > + > + switch (be32_to_cpu(magic)) { > + case XFS_MD_MAGIC_V1: > + mb.mb_magic = cpu_to_be32(XFS_MD_MAGIC_V1); > + if (fread((uint8_t *)&mb + sizeof(mb.mb_magic), > + sizeof(mb) - sizeof(mb.mb_magic), 1, src_f) != 1) > + fatal("error reading from metadump file\n"); > + break; > + default: > fatal("specified file is not a metadata dump\n"); > + break; > + } > > if (mdrestore.show_info) { > if (mb.mb_info & XFS_METADUMP_INFO_FLAGS) { > -- > 2.39.1 >
diff --git a/mdrestore/xfs_mdrestore.c b/mdrestore/xfs_mdrestore.c index 564630f7..2a9527b9 100644 --- a/mdrestore/xfs_mdrestore.c +++ b/mdrestore/xfs_mdrestore.c @@ -198,6 +198,7 @@ main( int open_flags; struct stat statbuf; int is_target_file; + uint32_t magic; struct xfs_metablock mb; mdrestore.show_progress = false; @@ -245,10 +246,20 @@ main( fatal("cannot open source dump file\n"); } - if (fread(&mb, sizeof(mb), 1, src_f) != 1) - fatal("error reading from metadump file\n"); - if (mb.mb_magic != cpu_to_be32(XFS_MD_MAGIC_V1)) + if (fread(&magic, sizeof(magic), 1, src_f) != 1) + fatal("Unable to read metadump magic from metadump file\n"); + + switch (be32_to_cpu(magic)) { + case XFS_MD_MAGIC_V1: + mb.mb_magic = cpu_to_be32(XFS_MD_MAGIC_V1); + if (fread((uint8_t *)&mb + sizeof(mb.mb_magic), + sizeof(mb) - sizeof(mb.mb_magic), 1, src_f) != 1) + fatal("error reading from metadump file\n"); + break; + default: fatal("specified file is not a metadata dump\n"); + break; + } if (mdrestore.show_info) { if (mb.mb_info & XFS_METADUMP_INFO_FLAGS) {
In order to support both v1 and v2 versions of metadump, mdrestore will have to detect the format in which the metadump file has been stored on the disk and then read the ondisk structures accordingly. In a step in that direction, this commit splits the work of reading the metadump header from disk into two parts 1. Read the first 4 bytes containing the metadump magic code. 2. Read the remaining part of the header. A future commit will take appropriate action based on the value of the magic code. Signed-off-by: Chandan Babu R <chandan.babu@oracle.com> --- mdrestore/xfs_mdrestore.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-)