diff mbox series

[V2,11/23] metadump: Define metadump ops for v2 format

Message ID 20230606092806.1604491-12-chandan.babu@oracle.com (mailing list archive)
State Superseded
Headers show
Series Metadump v2 | expand

Commit Message

Chandan Babu R June 6, 2023, 9:27 a.m. UTC
This commit adds functionality to dump metadata from an XFS filesystem in
newly introduced v2 format.

Signed-off-by: Chandan Babu R <chandan.babu@oracle.com>
---
 db/metadump.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 71 insertions(+), 3 deletions(-)

Comments

Darrick J. Wong July 12, 2023, 5:22 p.m. UTC | #1
On Tue, Jun 06, 2023 at 02:57:54PM +0530, Chandan Babu R wrote:
> This commit adds functionality to dump metadata from an XFS filesystem in
> newly introduced v2 format.
> 
> Signed-off-by: Chandan Babu R <chandan.babu@oracle.com>
> ---
>  db/metadump.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++---
>  1 file changed, 71 insertions(+), 3 deletions(-)
> 
> diff --git a/db/metadump.c b/db/metadump.c
> index b74993c0..537c37f7 100644
> --- a/db/metadump.c
> +++ b/db/metadump.c
> @@ -3054,6 +3054,70 @@ static struct metadump_ops metadump1_ops = {
>  	.release	= release_metadump_v1,
>  };
>  
> +static int
> +init_metadump_v2(void)
> +{
> +	struct xfs_metadump_header xmh = {0};
> +	uint32_t compat_flags = 0;
> +
> +	xmh.xmh_magic = cpu_to_be32(XFS_MD_MAGIC_V2);
> +	xmh.xmh_version = 2;

Shouldn't this be cpu_to_be32 as well?

--D

> +
> +	if (metadump.obfuscate)
> +		compat_flags |= XFS_MD2_INCOMPAT_OBFUSCATED;
> +	if (!metadump.zero_stale_data)
> +		compat_flags |= XFS_MD2_INCOMPAT_FULLBLOCKS;
> +	if (metadump.dirty_log)
> +		compat_flags |= XFS_MD2_INCOMPAT_DIRTYLOG;
> +
> +	xmh.xmh_compat_flags = cpu_to_be32(compat_flags);
> +
> +	if (fwrite(&xmh, sizeof(xmh), 1, metadump.outf) != 1) {
> +		print_warning("error writing to target file");
> +		return -1;
> +	}
> +
> +	return 0;
> +}
> +
> +static int
> +write_metadump_v2(
> +	enum typnm	type,
> +	char		*data,
> +	xfs_daddr_t	off,
> +	int		len)
> +{
> +	struct xfs_meta_extent	xme;
> +	uint64_t		addr;
> +
> +	addr = off;
> +	if (type == TYP_LOG &&
> +		mp->m_logdev_targp->bt_bdev != mp->m_ddev_targp->bt_bdev)
> +		addr |= XME_ADDR_LOG_DEVICE;
> +	else
> +		addr |= XME_ADDR_DATA_DEVICE;
> +
> +	xme.xme_addr = cpu_to_be64(addr);
> +	xme.xme_len = cpu_to_be32(len);
> +
> +	if (fwrite(&xme, sizeof(xme), 1, metadump.outf) != 1) {
> +		print_warning("error writing to target file");
> +		return -EIO;
> +	}
> +
> +	if (fwrite(data, len << BBSHIFT, 1, metadump.outf) != 1) {
> +		print_warning("error writing to target file");
> +		return -EIO;
> +	}
> +
> +	return 0;
> +}
> +
> +static struct metadump_ops metadump2_ops = {
> +	.init	= init_metadump_v2,
> +	.write	= write_metadump_v2,
> +};
> +
>  static int
>  metadump_f(
>  	int 		argc,
> @@ -3190,7 +3254,10 @@ metadump_f(
>  		}
>  	}
>  
> -	metadump.mdops = &metadump1_ops;
> +	if (metadump.version == 1)
> +		metadump.mdops = &metadump1_ops;
> +	else
> +		metadump.mdops = &metadump2_ops;
>  
>  	ret = metadump.mdops->init();
>  	if (ret)
> @@ -3214,7 +3281,7 @@ metadump_f(
>  		exitcode = !copy_log();
>  
>  	/* write the remaining index */
> -	if (!exitcode)
> +	if (!exitcode && metadump.mdops->end_write)
>  		exitcode = metadump.mdops->end_write() < 0;
>  
>  	if (metadump.progress_since_warning)
> @@ -3234,7 +3301,8 @@ metadump_f(
>  	while (iocur_sp > start_iocur_sp)
>  		pop_cur();
>  
> -	metadump.mdops->release();
> +	if (metadump.mdops->release)
> +		metadump.mdops->release();
>  
>  out:
>  	return 0;
> -- 
> 2.39.1
>
Chandan Babu R July 13, 2023, 4:45 a.m. UTC | #2
On Wed, Jul 12, 2023 at 10:22:02 AM -0700, Darrick J. Wong wrote:
> On Tue, Jun 06, 2023 at 02:57:54PM +0530, Chandan Babu R wrote:
>> This commit adds functionality to dump metadata from an XFS filesystem in
>> newly introduced v2 format.
>> 
>> Signed-off-by: Chandan Babu R <chandan.babu@oracle.com>
>> ---
>>  db/metadump.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++---
>>  1 file changed, 71 insertions(+), 3 deletions(-)
>> 
>> diff --git a/db/metadump.c b/db/metadump.c
>> index b74993c0..537c37f7 100644
>> --- a/db/metadump.c
>> +++ b/db/metadump.c
>> @@ -3054,6 +3054,70 @@ static struct metadump_ops metadump1_ops = {
>>  	.release	= release_metadump_v1,
>>  };
>>  
>> +static int
>> +init_metadump_v2(void)
>> +{
>> +	struct xfs_metadump_header xmh = {0};
>> +	uint32_t compat_flags = 0;
>> +
>> +	xmh.xmh_magic = cpu_to_be32(XFS_MD_MAGIC_V2);
>> +	xmh.xmh_version = 2;
>
> Shouldn't this be cpu_to_be32 as well?
>

Yes, I will fix this before posting the next version of the patchset.
diff mbox series

Patch

diff --git a/db/metadump.c b/db/metadump.c
index b74993c0..537c37f7 100644
--- a/db/metadump.c
+++ b/db/metadump.c
@@ -3054,6 +3054,70 @@  static struct metadump_ops metadump1_ops = {
 	.release	= release_metadump_v1,
 };
 
+static int
+init_metadump_v2(void)
+{
+	struct xfs_metadump_header xmh = {0};
+	uint32_t compat_flags = 0;
+
+	xmh.xmh_magic = cpu_to_be32(XFS_MD_MAGIC_V2);
+	xmh.xmh_version = 2;
+
+	if (metadump.obfuscate)
+		compat_flags |= XFS_MD2_INCOMPAT_OBFUSCATED;
+	if (!metadump.zero_stale_data)
+		compat_flags |= XFS_MD2_INCOMPAT_FULLBLOCKS;
+	if (metadump.dirty_log)
+		compat_flags |= XFS_MD2_INCOMPAT_DIRTYLOG;
+
+	xmh.xmh_compat_flags = cpu_to_be32(compat_flags);
+
+	if (fwrite(&xmh, sizeof(xmh), 1, metadump.outf) != 1) {
+		print_warning("error writing to target file");
+		return -1;
+	}
+
+	return 0;
+}
+
+static int
+write_metadump_v2(
+	enum typnm	type,
+	char		*data,
+	xfs_daddr_t	off,
+	int		len)
+{
+	struct xfs_meta_extent	xme;
+	uint64_t		addr;
+
+	addr = off;
+	if (type == TYP_LOG &&
+		mp->m_logdev_targp->bt_bdev != mp->m_ddev_targp->bt_bdev)
+		addr |= XME_ADDR_LOG_DEVICE;
+	else
+		addr |= XME_ADDR_DATA_DEVICE;
+
+	xme.xme_addr = cpu_to_be64(addr);
+	xme.xme_len = cpu_to_be32(len);
+
+	if (fwrite(&xme, sizeof(xme), 1, metadump.outf) != 1) {
+		print_warning("error writing to target file");
+		return -EIO;
+	}
+
+	if (fwrite(data, len << BBSHIFT, 1, metadump.outf) != 1) {
+		print_warning("error writing to target file");
+		return -EIO;
+	}
+
+	return 0;
+}
+
+static struct metadump_ops metadump2_ops = {
+	.init	= init_metadump_v2,
+	.write	= write_metadump_v2,
+};
+
 static int
 metadump_f(
 	int 		argc,
@@ -3190,7 +3254,10 @@  metadump_f(
 		}
 	}
 
-	metadump.mdops = &metadump1_ops;
+	if (metadump.version == 1)
+		metadump.mdops = &metadump1_ops;
+	else
+		metadump.mdops = &metadump2_ops;
 
 	ret = metadump.mdops->init();
 	if (ret)
@@ -3214,7 +3281,7 @@  metadump_f(
 		exitcode = !copy_log();
 
 	/* write the remaining index */
-	if (!exitcode)
+	if (!exitcode && metadump.mdops->end_write)
 		exitcode = metadump.mdops->end_write() < 0;
 
 	if (metadump.progress_since_warning)
@@ -3234,7 +3301,8 @@  metadump_f(
 	while (iocur_sp > start_iocur_sp)
 		pop_cur();
 
-	metadump.mdops->release();
+	if (metadump.mdops->release)
+		metadump.mdops->release();
 
 out:
 	return 0;