From patchwork Tue May 23 09:00:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Babu R X-Patchwork-Id: 13251923 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1E698C7EE26 for ; Tue, 23 May 2023 09:01:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235835AbjEWJBP (ORCPT ); Tue, 23 May 2023 05:01:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35890 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236216AbjEWJBM (ORCPT ); Tue, 23 May 2023 05:01:12 -0400 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8A590118 for ; Tue, 23 May 2023 02:01:11 -0700 (PDT) Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 34N6ECWX024675; Tue, 23 May 2023 09:01:06 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=corp-2023-03-30; bh=LJTMmG0ek1MTW2XB20wSQuCtnZYkPFTg87U5pQUa3SU=; b=E0OSHI6GB7Vum6Ls0HQQqkiQzA9hAyNo/lhwPX4qzlC9XvpGxfun97KLZesH43KWvy/i u+msNaE+5DAG4dHMlq8JMsTukDs59emGhnQovz8LEgcchO38dHy+A+ww7YtwElVkaY9X 8yGjwFT8QaMOA2Ik0NS6iTRYtvBIKcBuAzKlbRzZKiecAmtFw4Z4yTdNOPL+Klak5neF QfePNSt/HsFKa5Nx264/xnJIXqMZ6hX0a/t1bHm004sKnJZWqvUikye8mqdMLzPtY36+ VHdVSaSkKkNr6Rw83LCttKR/9cQHJ3gRQYsjCbwjn3K8fLIY/tq3ouyi4jtFhzLIHxBy 1Q== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3qpp7yvkwb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 23 May 2023 09:01:05 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 34N8v8oH029531; Tue, 23 May 2023 09:01:04 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3qqk2aj78d-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 23 May 2023 09:01:04 +0000 Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 34N8xwrP007681; Tue, 23 May 2023 09:01:04 GMT Received: from chanbabu-fstest.osdevelopmeniad.oraclevcn.com (chanbabu-fstesting.allregionaliads.osdevelopmeniad.oraclevcn.com [100.100.250.50]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3qqk2aj76a-2; Tue, 23 May 2023 09:01:04 +0000 From: Chandan Babu R To: cem@kernel.org Cc: Chandan Babu R , linux-xfs@vger.kernel.org Subject: [PATCH 01/24] metadump: Use boolean values true/false instead of 1/0 Date: Tue, 23 May 2023 14:30:27 +0530 Message-Id: <20230523090050.373545-2-chandan.babu@oracle.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230523090050.373545-1-chandan.babu@oracle.com> References: <20230523090050.373545-1-chandan.babu@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.573,FMLib:17.11.176.26 definitions=2023-05-23_05,2023-05-22_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 mlxscore=0 mlxlogscore=999 phishscore=0 bulkscore=0 suspectscore=0 adultscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2304280000 definitions=main-2305230074 X-Proofpoint-ORIG-GUID: PtkSGQZIde4hWCWVpgiCIO2ILTW9aTcI X-Proofpoint-GUID: PtkSGQZIde4hWCWVpgiCIO2ILTW9aTcI Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org Signed-off-by: Chandan Babu R Reviewed-by: Darrick J. Wong --- db/metadump.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/db/metadump.c b/db/metadump.c index 27d1df432..6bcfd5bba 100644 --- a/db/metadump.c +++ b/db/metadump.c @@ -2421,12 +2421,12 @@ process_inode( case S_IFDIR: rval = process_inode_data(dip, TYP_DIR2); if (dip->di_format == XFS_DINODE_FMT_LOCAL) - need_new_crc = 1; + need_new_crc = true; break; case S_IFLNK: rval = process_inode_data(dip, TYP_SYMLINK); if (dip->di_format == XFS_DINODE_FMT_LOCAL) - need_new_crc = 1; + need_new_crc = true; break; case S_IFREG: rval = process_inode_data(dip, TYP_DATA); @@ -2436,7 +2436,7 @@ process_inode( case S_IFBLK: case S_IFSOCK: process_dev_inode(dip); - need_new_crc = 1; + need_new_crc = true; break; default: break; @@ -2450,7 +2450,7 @@ process_inode( attr_data.remote_val_count = 0; switch (dip->di_aformat) { case XFS_DINODE_FMT_LOCAL: - need_new_crc = 1; + need_new_crc = true; if (obfuscate || zero_stale_data) process_sf_attr(dip); break; @@ -2469,7 +2469,7 @@ process_inode( done: /* Heavy handed but low cost; just do it as a catch-all. */ if (zero_stale_data) - need_new_crc = 1; + need_new_crc = true; if (crc_was_ok && need_new_crc) libxfs_dinode_calc_crc(mp, dip); From patchwork Tue May 23 09:00:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Babu R X-Patchwork-Id: 13251925 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 67595C7EE2A for ; Tue, 23 May 2023 09:01:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236216AbjEWJBQ (ORCPT ); Tue, 23 May 2023 05:01:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35876 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236241AbjEWJBM (ORCPT ); Tue, 23 May 2023 05:01:12 -0400 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A5F50100 for ; Tue, 23 May 2023 02:01:10 -0700 (PDT) Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 34N6E76i024594; Tue, 23 May 2023 09:01:06 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=corp-2023-03-30; bh=KJkDGVJOXmrl5iGEvfYj3Ybc32jXyhfjugjTtkqJuPE=; b=4VE44iMHlOcRxUZfdYHIw2AU13JSLRUjp5Z2Rtosfbd71o3jz1qh+N5l36qJ0rRm+0iJ Ht+tVHo9Zubny48BBCeYPyiNsxS4RMZ6zaiH4/dygU3lFcGGpxQEN7Dijn3dSRgGFcvN X+luQB8iD9p68S1tif4ldqPFTEQTgEIXPJh+hEHs4MLWovn4UGPvnpVQ/YWg9pdYT2aM 8TjM85Bqftdq+qEYRtNvOyJ9JObJIDpe1rwnXcxwUOMSmfcnMUORkPZow2L1AXasIjpd BospuG2/UPFAYPZ8iasOQuPfs3T+KLG6RjpoX2MO8Q04M1Rgmhx9tqwb0MRumH/xwR5A AQ== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3qpp7yvkwd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 23 May 2023 09:01:06 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 34N6u8aC029064; Tue, 23 May 2023 09:01:05 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3qqk2aj797-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 23 May 2023 09:01:05 +0000 Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 34N8xwrR007681; Tue, 23 May 2023 09:01:05 GMT Received: from chanbabu-fstest.osdevelopmeniad.oraclevcn.com (chanbabu-fstesting.allregionaliads.osdevelopmeniad.oraclevcn.com [100.100.250.50]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3qqk2aj76a-3; Tue, 23 May 2023 09:01:05 +0000 From: Chandan Babu R To: cem@kernel.org Cc: Chandan Babu R , linux-xfs@vger.kernel.org Subject: [PATCH 02/24] mdrestore: Fix logic used to check if target device is large enough Date: Tue, 23 May 2023 14:30:28 +0530 Message-Id: <20230523090050.373545-3-chandan.babu@oracle.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230523090050.373545-1-chandan.babu@oracle.com> References: <20230523090050.373545-1-chandan.babu@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.573,FMLib:17.11.176.26 definitions=2023-05-23_05,2023-05-22_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 mlxscore=0 mlxlogscore=969 phishscore=0 bulkscore=0 suspectscore=0 adultscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2304280000 definitions=main-2305230074 X-Proofpoint-ORIG-GUID: T7jfGyR8amLBbQtVli-FO7ez-yr9rgPf X-Proofpoint-GUID: T7jfGyR8amLBbQtVli-FO7ez-yr9rgPf Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org The device size verification code should be writing XFS_MAX_SECTORSIZE bytes to the end of the device rather than "sizeof(char *) * XFS_MAX_SECTORSIZE" bytes. Signed-off-by: Chandan Babu R Reviewed-by: Darrick J. Wong --- mdrestore/xfs_mdrestore.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mdrestore/xfs_mdrestore.c b/mdrestore/xfs_mdrestore.c index 7c1a66c40..333282ed2 100644 --- a/mdrestore/xfs_mdrestore.c +++ b/mdrestore/xfs_mdrestore.c @@ -115,7 +115,7 @@ perform_restore( } else { /* ensure device is sufficiently large enough */ - char *lb[XFS_MAX_SECTORSIZE] = { NULL }; + char lb[XFS_MAX_SECTORSIZE] = { 0 }; off64_t off; off = sb.sb_dblocks * sb.sb_blocksize - sizeof(lb); From patchwork Tue May 23 09:00:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Babu R X-Patchwork-Id: 13251934 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DED06C7EE2E for ; Tue, 23 May 2023 09:01:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236268AbjEWJBU (ORCPT ); Tue, 23 May 2023 05:01:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35990 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236248AbjEWJBQ (ORCPT ); Tue, 23 May 2023 05:01:16 -0400 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BDEE3FF for ; Tue, 23 May 2023 02:01:12 -0700 (PDT) Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 34N6EBVN032759; Tue, 23 May 2023 09:01:08 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=corp-2023-03-30; bh=FTjim/WjMHe74B0RHIEEIuPNGDHN0xygW9VRfWcDcZo=; b=pcTsMg5NQ2rKGpa9zpqcitlr9FEemSn3ZNal7za4EX0igVyRWsWAih/+c3QOfiLwFF2L psU/gJ/S03vfsduUerUkmrvCOZgNns8Qt2Cp+obR7Jnvpx7GSqHOOmnqVEoPmVnvifFo IukVzTeuZjFPJldyqVeiP20kVT0FFZd9ItX/0Qz8jN5aU3Qx47raRGJIO+06tFJuD+V7 +yz0TOkJL6cTDfJo2dmxysN4lESdY99D9Ixjv8YZqGRGmbE/ACHgWMIQ2hiQaBwR+lPK A0QEkLugw92lVMHXFKriZFOKCEOzuR82FgJopxb0uHoMj+5LUN+InEm7HRitdSP3QQSO hA== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3qpp44mjgw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 23 May 2023 09:01:07 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 34N8snoQ029043; Tue, 23 May 2023 09:01:06 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3qqk2aj7a6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 23 May 2023 09:01:06 +0000 Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 34N8xwrT007681; Tue, 23 May 2023 09:01:06 GMT Received: from chanbabu-fstest.osdevelopmeniad.oraclevcn.com (chanbabu-fstesting.allregionaliads.osdevelopmeniad.oraclevcn.com [100.100.250.50]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3qqk2aj76a-4; Tue, 23 May 2023 09:01:06 +0000 From: Chandan Babu R To: cem@kernel.org Cc: Chandan Babu R , linux-xfs@vger.kernel.org Subject: [PATCH 03/24] metadump: Define and use struct metadump Date: Tue, 23 May 2023 14:30:29 +0530 Message-Id: <20230523090050.373545-4-chandan.babu@oracle.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230523090050.373545-1-chandan.babu@oracle.com> References: <20230523090050.373545-1-chandan.babu@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.573,FMLib:17.11.176.26 definitions=2023-05-23_05,2023-05-22_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 mlxscore=0 mlxlogscore=999 phishscore=0 bulkscore=0 suspectscore=0 adultscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2304280000 definitions=main-2305230074 X-Proofpoint-GUID: tDmxoaA-ax76jcMIG6e9-LXmhaj1n9J7 X-Proofpoint-ORIG-GUID: tDmxoaA-ax76jcMIG6e9-LXmhaj1n9J7 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org This commit collects all state tracking variables in a new "struct metadump" structure. Signed-off-by: Chandan Babu R --- db/metadump.c | 459 +++++++++++++++++++++++++++----------------------- 1 file changed, 244 insertions(+), 215 deletions(-) diff --git a/db/metadump.c b/db/metadump.c index 6bcfd5bba..806cdfd68 100644 --- a/db/metadump.c +++ b/db/metadump.c @@ -40,25 +40,27 @@ static const cmdinfo_t metadump_cmd = N_("[-a] [-e] [-g] [-m max_extent] [-w] [-o] filename"), N_("dump metadata to a file"), metadump_help }; -static FILE *outf; /* metadump file */ - -static xfs_metablock_t *metablock; /* header + index + buffers */ -static __be64 *block_index; -static char *block_buffer; - -static int num_indices; -static int cur_index; - -static xfs_ino_t cur_ino; - -static int show_progress = 0; -static int stop_on_read_error = 0; -static int max_extent_size = DEFAULT_MAX_EXT_SIZE; -static int obfuscate = 1; -static int zero_stale_data = 1; -static int show_warnings = 0; -static int progress_since_warning = 0; -static bool stdout_metadump; +static struct metadump { + int version; + int show_progress; + int stop_on_read_error; + int max_extent_size; + int show_warnings; + int obfuscate; + int zero_stale_data; + int progress_since_warning; + bool dirty_log; + bool stdout_metadump; + xfs_ino_t cur_ino; + /* Metadump file */ + FILE *outf; + /* header + index + buffers */ + struct xfs_metablock *metablock; + __be64 *block_index; + char *block_buffer; + int num_indices; + int cur_index; +} metadump; void metadump_init(void) @@ -98,9 +100,9 @@ print_warning(const char *fmt, ...) va_end(ap); buf[sizeof(buf)-1] = '\0'; - fprintf(stderr, "%s%s: %s\n", progress_since_warning ? "\n" : "", - progname, buf); - progress_since_warning = 0; + fprintf(stderr, "%s%s: %s\n", + metadump.progress_since_warning ? "\n" : "", progname, buf); + metadump.progress_since_warning = 0; } static void @@ -118,10 +120,10 @@ print_progress(const char *fmt, ...) va_end(ap); buf[sizeof(buf)-1] = '\0'; - f = stdout_metadump ? stderr : stdout; + f = metadump.stdout_metadump ? stderr : stdout; fprintf(f, "\r%-59s", buf); fflush(f); - progress_since_warning = 1; + metadump.progress_since_warning = 1; } /* @@ -136,17 +138,19 @@ print_progress(const char *fmt, ...) static int write_index(void) { + struct xfs_metablock *metablock = metadump.metablock; /* * write index block and following data blocks (streaming) */ - metablock->mb_count = cpu_to_be16(cur_index); - if (fwrite(metablock, (cur_index + 1) << BBSHIFT, 1, outf) != 1) { + metablock->mb_count = cpu_to_be16(metadump.cur_index); + if (fwrite(metablock, (metadump.cur_index + 1) << BBSHIFT, 1, + metadump.outf) != 1) { print_warning("error writing to target file"); return -1; } - memset(block_index, 0, num_indices * sizeof(__be64)); - cur_index = 0; + memset(metadump.block_index, 0, metadump.num_indices * sizeof(__be64)); + metadump.cur_index = 0; return 0; } @@ -163,9 +167,10 @@ write_buf_segment( int ret; for (i = 0; i < len; i++, off++, data += BBSIZE) { - block_index[cur_index] = cpu_to_be64(off); - memcpy(&block_buffer[cur_index << BBSHIFT], data, BBSIZE); - if (++cur_index == num_indices) { + metadump.block_index[metadump.cur_index] = cpu_to_be64(off); + memcpy(&metadump.block_buffer[metadump.cur_index << BBSHIFT], + data, BBSIZE); + if (++metadump.cur_index == metadump.num_indices) { ret = write_index(); if (ret) return -EIO; @@ -388,11 +393,11 @@ scan_btree( if (iocur_top->data == NULL) { print_warning("cannot read %s block %u/%u", typtab[btype].name, agno, agbno); - rval = !stop_on_read_error; + rval = !metadump.stop_on_read_error; goto pop_out; } - if (zero_stale_data) { + if (metadump.zero_stale_data) { zero_btree_block(iocur_top->data, btype); iocur_top->need_crc = 1; } @@ -446,7 +451,7 @@ scanfunc_freesp( numrecs = be16_to_cpu(block->bb_numrecs); if (numrecs > mp->m_alloc_mxr[1]) { - if (show_warnings) + if (metadump.show_warnings) print_warning("invalid numrecs (%u) in %s block %u/%u", numrecs, typtab[btype].name, agno, agbno); return 1; @@ -455,7 +460,7 @@ scanfunc_freesp( pp = XFS_ALLOC_PTR_ADDR(mp, block, 1, mp->m_alloc_mxr[1]); for (i = 0; i < numrecs; i++) { if (!valid_bno(agno, be32_to_cpu(pp[i]))) { - if (show_warnings) + if (metadump.show_warnings) print_warning("invalid block number (%u/%u) " "in %s block %u/%u", agno, be32_to_cpu(pp[i]), @@ -482,13 +487,13 @@ copy_free_bno_btree( /* validate root and levels before processing the tree */ if (root == 0 || root > mp->m_sb.sb_agblocks) { - if (show_warnings) + if (metadump.show_warnings) print_warning("invalid block number (%u) in bnobt " "root in agf %u", root, agno); return 1; } if (levels > mp->m_alloc_maxlevels) { - if (show_warnings) + if (metadump.show_warnings) print_warning("invalid level (%u) in bnobt root " "in agf %u", levels, agno); return 1; @@ -510,13 +515,13 @@ copy_free_cnt_btree( /* validate root and levels before processing the tree */ if (root == 0 || root > mp->m_sb.sb_agblocks) { - if (show_warnings) + if (metadump.show_warnings) print_warning("invalid block number (%u) in cntbt " "root in agf %u", root, agno); return 1; } if (levels > mp->m_alloc_maxlevels) { - if (show_warnings) + if (metadump.show_warnings) print_warning("invalid level (%u) in cntbt root " "in agf %u", levels, agno); return 1; @@ -543,7 +548,7 @@ scanfunc_rmapbt( numrecs = be16_to_cpu(block->bb_numrecs); if (numrecs > mp->m_rmap_mxr[1]) { - if (show_warnings) + if (metadump.show_warnings) print_warning("invalid numrecs (%u) in %s block %u/%u", numrecs, typtab[btype].name, agno, agbno); return 1; @@ -552,7 +557,7 @@ scanfunc_rmapbt( pp = XFS_RMAP_PTR_ADDR(block, 1, mp->m_rmap_mxr[1]); for (i = 0; i < numrecs; i++) { if (!valid_bno(agno, be32_to_cpu(pp[i]))) { - if (show_warnings) + if (metadump.show_warnings) print_warning("invalid block number (%u/%u) " "in %s block %u/%u", agno, be32_to_cpu(pp[i]), @@ -582,13 +587,13 @@ copy_rmap_btree( /* validate root and levels before processing the tree */ if (root == 0 || root > mp->m_sb.sb_agblocks) { - if (show_warnings) + if (metadump.show_warnings) print_warning("invalid block number (%u) in rmapbt " "root in agf %u", root, agno); return 1; } if (levels > mp->m_rmap_maxlevels) { - if (show_warnings) + if (metadump.show_warnings) print_warning("invalid level (%u) in rmapbt root " "in agf %u", levels, agno); return 1; @@ -615,7 +620,7 @@ scanfunc_refcntbt( numrecs = be16_to_cpu(block->bb_numrecs); if (numrecs > mp->m_refc_mxr[1]) { - if (show_warnings) + if (metadump.show_warnings) print_warning("invalid numrecs (%u) in %s block %u/%u", numrecs, typtab[btype].name, agno, agbno); return 1; @@ -624,7 +629,7 @@ scanfunc_refcntbt( pp = XFS_REFCOUNT_PTR_ADDR(block, 1, mp->m_refc_mxr[1]); for (i = 0; i < numrecs; i++) { if (!valid_bno(agno, be32_to_cpu(pp[i]))) { - if (show_warnings) + if (metadump.show_warnings) print_warning("invalid block number (%u/%u) " "in %s block %u/%u", agno, be32_to_cpu(pp[i]), @@ -654,13 +659,13 @@ copy_refcount_btree( /* validate root and levels before processing the tree */ if (root == 0 || root > mp->m_sb.sb_agblocks) { - if (show_warnings) + if (metadump.show_warnings) print_warning("invalid block number (%u) in refcntbt " "root in agf %u", root, agno); return 1; } if (levels > mp->m_refc_maxlevels) { - if (show_warnings) + if (metadump.show_warnings) print_warning("invalid level (%u) in refcntbt root " "in agf %u", levels, agno); return 1; @@ -785,7 +790,8 @@ in_lost_found( /* Record the "lost+found" inode if we haven't done so already */ ASSERT(ino != 0); - if (!orphanage_ino && is_orphanage_dir(mp, cur_ino, namelen, name)) + if (!orphanage_ino && is_orphanage_dir(mp, metadump.cur_ino, namelen, + name)) orphanage_ino = ino; /* We don't obfuscate the "lost+found" directory itself */ @@ -795,7 +801,7 @@ in_lost_found( /* Most files aren't in "lost+found" at all */ - if (cur_ino != orphanage_ino) + if (metadump.cur_ino != orphanage_ino) return 0; /* @@ -1219,7 +1225,7 @@ generate_obfuscated_name( print_warning("duplicate name for inode %llu " "in dir inode %llu\n", (unsigned long long) ino, - (unsigned long long) cur_ino); + (unsigned long long) metadump.cur_ino); return; } @@ -1229,7 +1235,7 @@ generate_obfuscated_name( print_warning("unable to record name for inode %llu " "in dir inode %llu\n", (unsigned long long) ino, - (unsigned long long) cur_ino); + (unsigned long long) metadump.cur_ino); } static void @@ -1245,9 +1251,9 @@ process_sf_dir( ino_dir_size = be64_to_cpu(dip->di_size); if (ino_dir_size > XFS_DFORK_DSIZE(dip, mp)) { ino_dir_size = XFS_DFORK_DSIZE(dip, mp); - if (show_warnings) + if (metadump.show_warnings) print_warning("invalid size in dir inode %llu", - (long long)cur_ino); + (long long)metadump.cur_ino); } sfep = xfs_dir2_sf_firstentry(sfp); @@ -1261,9 +1267,9 @@ process_sf_dir( int namelen = sfep->namelen; if (namelen == 0) { - if (show_warnings) + if (metadump.show_warnings) print_warning("zero length entry in dir inode " - "%llu", (long long)cur_ino); + "%llu", (long long)metadump.cur_ino); if (i != sfp->count - 1) break; namelen = ino_dir_size - ((char *)&sfep->name[0] - @@ -1271,16 +1277,17 @@ process_sf_dir( } else if ((char *)sfep - (char *)sfp + libxfs_dir2_sf_entsize(mp, sfp, sfep->namelen) > ino_dir_size) { - if (show_warnings) + if (metadump.show_warnings) print_warning("entry length in dir inode %llu " - "overflows space", (long long)cur_ino); + "overflows space", + (long long)metadump.cur_ino); if (i != sfp->count - 1) break; namelen = ino_dir_size - ((char *)&sfep->name[0] - (char *)sfp); } - if (obfuscate) + if (metadump.obfuscate) generate_obfuscated_name( libxfs_dir2_sf_get_ino(mp, sfp, sfep), namelen, &sfep->name[0]); @@ -1290,7 +1297,8 @@ process_sf_dir( } /* zero stale data in rest of space in data fork, if any */ - if (zero_stale_data && (ino_dir_size < XFS_DFORK_DSIZE(dip, mp))) + if (metadump.zero_stale_data && + (ino_dir_size < XFS_DFORK_DSIZE(dip, mp))) memset(sfep, 0, XFS_DFORK_DSIZE(dip, mp) - ino_dir_size); } @@ -1346,18 +1354,18 @@ process_sf_symlink( len = be64_to_cpu(dip->di_size); if (len > XFS_DFORK_DSIZE(dip, mp)) { - if (show_warnings) + if (metadump.show_warnings) print_warning("invalid size (%d) in symlink inode %llu", - len, (long long)cur_ino); + len, (long long)metadump.cur_ino); len = XFS_DFORK_DSIZE(dip, mp); } buf = (char *)XFS_DFORK_DPTR(dip); - if (obfuscate) + if (metadump.obfuscate) obfuscate_path_components(buf, len); /* zero stale data in rest of space in data fork, if any */ - if (zero_stale_data && len < XFS_DFORK_DSIZE(dip, mp)) + if (metadump.zero_stale_data && len < XFS_DFORK_DSIZE(dip, mp)) memset(&buf[len], 0, XFS_DFORK_DSIZE(dip, mp) - len); } @@ -1382,9 +1390,9 @@ process_sf_attr( ino_attr_size = be16_to_cpu(asfp->hdr.totsize); if (ino_attr_size > XFS_DFORK_ASIZE(dip, mp)) { ino_attr_size = XFS_DFORK_ASIZE(dip, mp); - if (show_warnings) + if (metadump.show_warnings) print_warning("invalid attr size in inode %llu", - (long long)cur_ino); + (long long)metadump.cur_ino); } asfep = &asfp->list[0]; @@ -1394,19 +1402,20 @@ process_sf_attr( int namelen = asfep->namelen; if (namelen == 0) { - if (show_warnings) + if (metadump.show_warnings) print_warning("zero length attr entry in inode " - "%llu", (long long)cur_ino); + "%llu", (long long)metadump.cur_ino); break; } else if ((char *)asfep - (char *)asfp + xfs_attr_sf_entsize(asfep) > ino_attr_size) { - if (show_warnings) + if (metadump.show_warnings) print_warning("attr entry length in inode %llu " - "overflows space", (long long)cur_ino); + "overflows space", + (long long)metadump.cur_ino); break; } - if (obfuscate) { + if (metadump.obfuscate) { generate_obfuscated_name(0, asfep->namelen, &asfep->nameval[0]); memset(&asfep->nameval[asfep->namelen], 'v', @@ -1418,7 +1427,8 @@ process_sf_attr( } /* zero stale data in rest of space in attr fork, if any */ - if (zero_stale_data && (ino_attr_size < XFS_DFORK_ASIZE(dip, mp))) + if (metadump.zero_stale_data && + (ino_attr_size < XFS_DFORK_ASIZE(dip, mp))) memset(asfep, 0, XFS_DFORK_ASIZE(dip, mp) - ino_attr_size); } @@ -1429,7 +1439,7 @@ process_dir_free_block( struct xfs_dir2_free *free; struct xfs_dir3_icfree_hdr freehdr; - if (!zero_stale_data) + if (!metadump.zero_stale_data) return; free = (struct xfs_dir2_free *)block; @@ -1451,10 +1461,10 @@ process_dir_free_block( break; } default: - if (show_warnings) + if (metadump.show_warnings) print_warning("invalid magic in dir inode %llu " "free block", - (unsigned long long)cur_ino); + (unsigned long long)metadump.cur_ino); break; } } @@ -1466,7 +1476,7 @@ process_dir_leaf_block( struct xfs_dir2_leaf *leaf; struct xfs_dir3_icleaf_hdr leafhdr; - if (!zero_stale_data) + if (!metadump.zero_stale_data) return; /* Yes, this works for dir2 & dir3. Difference is padding. */ @@ -1549,10 +1559,10 @@ process_dir_data_block( } if (be32_to_cpu(datahdr->magic) != wantmagic) { - if (show_warnings) + if (metadump.show_warnings) print_warning( "invalid magic in dir inode %llu block %ld", - (unsigned long long)cur_ino, (long)offset); + (unsigned long long)metadump.cur_ino, (long)offset); return; } @@ -1572,10 +1582,10 @@ process_dir_data_block( if (dir_offset + free_length > end_of_data || !free_length || (free_length & (XFS_DIR2_DATA_ALIGN - 1))) { - if (show_warnings) + if (metadump.show_warnings) print_warning( "invalid length for dir free space in inode %llu", - (long long)cur_ino); + (long long)metadump.cur_ino); return; } if (be16_to_cpu(*xfs_dir2_data_unused_tag_p(dup)) != @@ -1588,7 +1598,7 @@ process_dir_data_block( * actually at a variable offset, so zeroing &dup->tag * is zeroing the free space in between */ - if (zero_stale_data) { + if (metadump.zero_stale_data) { int zlen = free_length - sizeof(xfs_dir2_data_unused_t); @@ -1606,23 +1616,23 @@ process_dir_data_block( if (dir_offset + length > end_of_data || ptr + length > endptr) { - if (show_warnings) + if (metadump.show_warnings) print_warning( "invalid length for dir entry name in inode %llu", - (long long)cur_ino); + (long long)metadump.cur_ino); return; } if (be16_to_cpu(*libxfs_dir2_data_entry_tag_p(mp, dep)) != dir_offset) return; - if (obfuscate) + if (metadump.obfuscate) generate_obfuscated_name(be64_to_cpu(dep->inumber), dep->namelen, &dep->name[0]); dir_offset += length; ptr += length; /* Zero the unused space after name, up to the tag */ - if (zero_stale_data) { + if (metadump.zero_stale_data) { /* 1 byte for ftype; don't bother with conditional */ int zlen = (char *)libxfs_dir2_data_entry_tag_p(mp, dep) - @@ -1658,7 +1668,7 @@ process_symlink_block( print_warning("cannot read %s block %u/%u (%llu)", typtab[btype].name, agno, agbno, s); - rval = !stop_on_read_error; + rval = !metadump.stop_on_read_error; goto out_pop; } link = iocur_top->data; @@ -1666,10 +1676,10 @@ process_symlink_block( if (xfs_has_crc((mp))) link += sizeof(struct xfs_dsymlink_hdr); - if (obfuscate) + if (metadump.obfuscate) obfuscate_path_components(link, XFS_SYMLINK_BUF_SPACE(mp, mp->m_sb.sb_blocksize)); - if (zero_stale_data) { + if (metadump.zero_stale_data) { size_t linklen, zlen; linklen = strlen(link); @@ -1736,7 +1746,8 @@ process_attr_block( if ((be16_to_cpu(leaf->hdr.info.magic) != XFS_ATTR_LEAF_MAGIC) && (be16_to_cpu(leaf->hdr.info.magic) != XFS_ATTR3_LEAF_MAGIC)) { for (i = 0; i < attr_data.remote_val_count; i++) { - if (obfuscate && attr_data.remote_vals[i] == offset) + if (metadump.obfuscate && + attr_data.remote_vals[i] == offset) /* Macros to handle both attr and attr3 */ memset(block + (bs - XFS_ATTR3_RMT_BUF_SPACE(mp, bs)), @@ -1753,9 +1764,9 @@ process_attr_block( nentries * sizeof(xfs_attr_leaf_entry_t) + xfs_attr3_leaf_hdr_size(leaf) > XFS_ATTR3_RMT_BUF_SPACE(mp, bs)) { - if (show_warnings) + if (metadump.show_warnings) print_warning("invalid attr count in inode %llu", - (long long)cur_ino); + (long long)metadump.cur_ino); return; } @@ -1770,22 +1781,22 @@ process_attr_block( first_name = xfs_attr3_leaf_name(leaf, i); if (be16_to_cpu(entry->nameidx) > mp->m_sb.sb_blocksize) { - if (show_warnings) + if (metadump.show_warnings) print_warning( "invalid attr nameidx in inode %llu", - (long long)cur_ino); + (long long)metadump.cur_ino); break; } if (entry->flags & XFS_ATTR_LOCAL) { local = xfs_attr3_leaf_name_local(leaf, i); if (local->namelen == 0) { - if (show_warnings) + if (metadump.show_warnings) print_warning( "zero length for attr name in inode %llu", - (long long)cur_ino); + (long long)metadump.cur_ino); break; } - if (obfuscate) { + if (metadump.obfuscate) { generate_obfuscated_name(0, local->namelen, &local->nameval[0]); memset(&local->nameval[local->namelen], 'v', @@ -1797,18 +1808,18 @@ process_attr_block( zlen = xfs_attr_leaf_entsize_local(nlen, vlen) - (sizeof(xfs_attr_leaf_name_local_t) - 1 + nlen + vlen); - if (zero_stale_data) + if (metadump.zero_stale_data) memset(&local->nameval[nlen + vlen], 0, zlen); } else { remote = xfs_attr3_leaf_name_remote(leaf, i); if (remote->namelen == 0 || remote->valueblk == 0) { - if (show_warnings) + if (metadump.show_warnings) print_warning( "invalid attr entry in inode %llu", - (long long)cur_ino); + (long long)metadump.cur_ino); break; } - if (obfuscate) { + if (metadump.obfuscate) { generate_obfuscated_name(0, remote->namelen, &remote->name[0]); add_remote_vals(be32_to_cpu(remote->valueblk), @@ -1819,13 +1830,13 @@ process_attr_block( zlen = xfs_attr_leaf_entsize_remote(nlen) - (sizeof(xfs_attr_leaf_name_remote_t) - 1 + nlen); - if (zero_stale_data) + if (metadump.zero_stale_data) memset(&remote->name[nlen], 0, zlen); } } /* Zero from end of entries array to the first name/val */ - if (zero_stale_data) { + if (metadump.zero_stale_data) { struct xfs_attr_leaf_entry *entries; entries = xfs_attr3_leaf_entryp(leaf); @@ -1858,16 +1869,16 @@ process_single_fsb_objects( print_warning("cannot read %s block %u/%u (%llu)", typtab[btype].name, agno, agbno, s); - rval = !stop_on_read_error; + rval = !metadump.stop_on_read_error; goto out_pop; } - if (!obfuscate && !zero_stale_data) + if (!metadump.obfuscate && !metadump.zero_stale_data) goto write; /* Zero unused part of interior nodes */ - if (zero_stale_data) { + if (metadump.zero_stale_data) { xfs_da_intnode_t *node = iocur_top->data; int magic = be16_to_cpu(node->hdr.info.magic); @@ -1978,12 +1989,12 @@ process_multi_fsb_dir( print_warning("cannot read %s block %u/%u (%llu)", typtab[btype].name, agno, agbno, s); - rval = !stop_on_read_error; + rval = !metadump.stop_on_read_error; goto out_pop; } - if (!obfuscate && !zero_stale_data) + if (!metadump.obfuscate && !metadump.zero_stale_data) goto write; dp = iocur_top->data; @@ -2075,25 +2086,27 @@ process_bmbt_reclist( * one is found, stop processing remaining extents */ if (i > 0 && op + cp > o) { - if (show_warnings) + if (metadump.show_warnings) print_warning("bmap extent %d in %s ino %llu " "starts at %llu, previous extent " "ended at %llu", i, - typtab[btype].name, (long long)cur_ino, + typtab[btype].name, + (long long)metadump.cur_ino, o, op + cp - 1); break; } - if (c > max_extent_size) { + if (c > metadump.max_extent_size) { /* * since we are only processing non-data extents, * large numbers of blocks in a metadata extent is * extremely rare and more than likely to be corrupt. */ - if (show_warnings) + if (metadump.show_warnings) print_warning("suspicious count %u in bmap " "extent %d in %s ino %llu", c, i, - typtab[btype].name, (long long)cur_ino); + typtab[btype].name, + (long long)metadump.cur_ino); break; } @@ -2104,19 +2117,21 @@ process_bmbt_reclist( agbno = XFS_FSB_TO_AGBNO(mp, s); if (!valid_bno(agno, agbno)) { - if (show_warnings) + if (metadump.show_warnings) print_warning("invalid block number %u/%u " "(%llu) in bmap extent %d in %s ino " "%llu", agno, agbno, s, i, - typtab[btype].name, (long long)cur_ino); + typtab[btype].name, + (long long)metadump.cur_ino); break; } if (!valid_bno(agno, agbno + c - 1)) { - if (show_warnings) + if (metadump.show_warnings) print_warning("bmap extent %i in %s inode %llu " "overflows AG (end is %u/%u)", i, - typtab[btype].name, (long long)cur_ino, + typtab[btype].name, + (long long)metadump.cur_ino, agno, agbno + c - 1); break; } @@ -2152,7 +2167,7 @@ scanfunc_bmap( if (level == 0) { if (nrecs > mp->m_bmap_dmxr[0]) { - if (show_warnings) + if (metadump.show_warnings) print_warning("invalid numrecs (%u) in %s " "block %u/%u", nrecs, typtab[btype].name, agno, agbno); @@ -2163,7 +2178,7 @@ scanfunc_bmap( } if (nrecs > mp->m_bmap_dmxr[1]) { - if (show_warnings) + if (metadump.show_warnings) print_warning("invalid numrecs (%u) in %s block %u/%u", nrecs, typtab[btype].name, agno, agbno); return 1; @@ -2178,7 +2193,7 @@ scanfunc_bmap( if (bno == 0 || bno > mp->m_sb.sb_agblocks || ag > mp->m_sb.sb_agcount) { - if (show_warnings) + if (metadump.show_warnings) print_warning("invalid block number (%u/%u) " "in %s block %u/%u", ag, bno, typtab[btype].name, agno, agbno); @@ -2213,10 +2228,10 @@ process_btinode( nrecs = be16_to_cpu(dib->bb_numrecs); if (level > XFS_BM_MAXLEVELS(mp, whichfork)) { - if (show_warnings) + if (metadump.show_warnings) print_warning("invalid level (%u) in inode %lld %s " - "root", level, (long long)cur_ino, - typtab[btype].name); + "root", level, (long long)metadump.cur_ino, + typtab[btype].name); return 1; } @@ -2227,16 +2242,16 @@ process_btinode( maxrecs = libxfs_bmdr_maxrecs(XFS_DFORK_SIZE(dip, mp, whichfork), 0); if (nrecs > maxrecs) { - if (show_warnings) + if (metadump.show_warnings) print_warning("invalid numrecs (%u) in inode %lld %s " - "root", nrecs, (long long)cur_ino, - typtab[btype].name); + "root", nrecs, (long long)metadump.cur_ino, + typtab[btype].name); return 1; } pp = XFS_BMDR_PTR_ADDR(dib, 1, maxrecs); - if (zero_stale_data) { + if (metadump.zero_stale_data) { char *top; /* Unused btree key space */ @@ -2257,11 +2272,11 @@ process_btinode( if (bno == 0 || bno > mp->m_sb.sb_agblocks || ag > mp->m_sb.sb_agcount) { - if (show_warnings) + if (metadump.show_warnings) print_warning("invalid block number (%u/%u) " - "in inode %llu %s root", ag, - bno, (long long)cur_ino, - typtab[btype].name); + "in inode %llu %s root", ag, bno, + (long long)metadump.cur_ino, + typtab[btype].name); continue; } @@ -2288,14 +2303,16 @@ process_exinode( whichfork); used = nex * sizeof(xfs_bmbt_rec_t); if (nex > max_nex || used > XFS_DFORK_SIZE(dip, mp, whichfork)) { - if (show_warnings) + if (metadump.show_warnings) print_warning("bad number of extents %llu in inode %lld", - (unsigned long long)nex, (long long)cur_ino); + (unsigned long long)nex, + (long long)metadump.cur_ino); return 1; } /* Zero unused data fork past used extents */ - if (zero_stale_data && (used < XFS_DFORK_SIZE(dip, mp, whichfork))) + if (metadump.zero_stale_data && + (used < XFS_DFORK_SIZE(dip, mp, whichfork))) memset(XFS_DFORK_PTR(dip, whichfork) + used, 0, XFS_DFORK_SIZE(dip, mp, whichfork) - used); @@ -2311,7 +2328,7 @@ process_inode_data( { switch (dip->di_format) { case XFS_DINODE_FMT_LOCAL: - if (!(obfuscate || zero_stale_data)) + if (!(metadump.obfuscate || metadump.zero_stale_data)) break; /* @@ -2323,7 +2340,7 @@ process_inode_data( print_warning( "Invalid data fork size (%d) in inode %llu, preserving contents!", XFS_DFORK_DSIZE(dip, mp), - (long long)cur_ino); + (long long)metadump.cur_ino); break; } @@ -2355,9 +2372,9 @@ process_dev_inode( struct xfs_dinode *dip) { if (xfs_dfork_data_extents(dip)) { - if (show_warnings) + if (metadump.show_warnings) print_warning("inode %llu has unexpected extents", - (unsigned long long)cur_ino); + (unsigned long long)metadump.cur_ino); return; } @@ -2369,11 +2386,11 @@ process_dev_inode( if (XFS_DFORK_DSIZE(dip, mp) > XFS_LITINO(mp)) { print_warning( "Invalid data fork size (%d) in inode %llu, preserving contents!", - XFS_DFORK_DSIZE(dip, mp), (long long)cur_ino); + XFS_DFORK_DSIZE(dip, mp), (long long)metadump.cur_ino); return; } - if (zero_stale_data) { + if (metadump.zero_stale_data) { unsigned int size = sizeof(xfs_dev_t); memset(XFS_DFORK_DPTR(dip) + size, 0, @@ -2399,17 +2416,17 @@ process_inode( bool crc_was_ok = false; /* no recalc by default */ bool need_new_crc = false; - cur_ino = XFS_AGINO_TO_INO(mp, agno, agino); + metadump.cur_ino = XFS_AGINO_TO_INO(mp, agno, agino); /* we only care about crc recalculation if we will modify the inode. */ - if (obfuscate || zero_stale_data) { + if (metadump.obfuscate || metadump.zero_stale_data) { crc_was_ok = libxfs_verify_cksum((char *)dip, mp->m_sb.sb_inodesize, offsetof(struct xfs_dinode, di_crc)); } if (free_inode) { - if (zero_stale_data) { + if (metadump.zero_stale_data) { /* Zero all of the inode literal area */ memset(XFS_DFORK_DPTR(dip), 0, XFS_LITINO(mp)); } @@ -2451,7 +2468,8 @@ process_inode( switch (dip->di_aformat) { case XFS_DINODE_FMT_LOCAL: need_new_crc = true; - if (obfuscate || zero_stale_data) + if (metadump.obfuscate || + metadump.zero_stale_data) process_sf_attr(dip); break; @@ -2468,7 +2486,7 @@ process_inode( done: /* Heavy handed but low cost; just do it as a catch-all. */ - if (zero_stale_data) + if (metadump.zero_stale_data) need_new_crc = true; if (crc_was_ok && need_new_crc) @@ -2528,7 +2546,7 @@ copy_inode_chunk( if (agino == 0 || agino == NULLAGINO || !valid_bno(agno, agbno) || !valid_bno(agno, XFS_AGINO_TO_AGBNO(mp, agino + XFS_INODES_PER_CHUNK - 1))) { - if (show_warnings) + if (metadump.show_warnings) print_warning("bad inode number %llu (%u/%u)", XFS_AGINO_TO_INO(mp, agno, agino), agno, agino); return 1; @@ -2544,7 +2562,7 @@ copy_inode_chunk( (xfs_has_align(mp) && mp->m_sb.sb_inoalignmt != 0 && agbno % mp->m_sb.sb_inoalignmt != 0)) { - if (show_warnings) + if (metadump.show_warnings) print_warning("badly aligned inode (start = %llu)", XFS_AGINO_TO_INO(mp, agno, agino)); return 1; @@ -2561,7 +2579,7 @@ copy_inode_chunk( if (iocur_top->data == NULL) { print_warning("cannot read inode block %u/%u", agno, agbno); - rval = !stop_on_read_error; + rval = !metadump.stop_on_read_error; goto pop_out; } @@ -2587,7 +2605,7 @@ next_bp: ioff += inodes_per_buf; } - if (show_progress) + if (metadump.show_progress) print_progress("Copied %u of %u inodes (%u of %u AGs)", inodes_copied, mp->m_sb.sb_icount, agno, mp->m_sb.sb_agcount); @@ -2617,7 +2635,7 @@ scanfunc_ino( if (level == 0) { if (numrecs > igeo->inobt_mxr[0]) { - if (show_warnings) + if (metadump.show_warnings) print_warning("invalid numrecs %d in %s " "block %u/%u", numrecs, typtab[btype].name, agno, agbno); @@ -2640,7 +2658,7 @@ scanfunc_ino( } if (numrecs > igeo->inobt_mxr[1]) { - if (show_warnings) + if (metadump.show_warnings) print_warning("invalid numrecs %d in %s block %u/%u", numrecs, typtab[btype].name, agno, agbno); numrecs = igeo->inobt_mxr[1]; @@ -2649,7 +2667,7 @@ scanfunc_ino( pp = XFS_INOBT_PTR_ADDR(mp, block, 1, igeo->inobt_mxr[1]); for (i = 0; i < numrecs; i++) { if (!valid_bno(agno, be32_to_cpu(pp[i]))) { - if (show_warnings) + if (metadump.show_warnings) print_warning("invalid block number (%u/%u) " "in %s block %u/%u", agno, be32_to_cpu(pp[i]), @@ -2677,13 +2695,13 @@ copy_inodes( /* validate root and levels before processing the tree */ if (root == 0 || root > mp->m_sb.sb_agblocks) { - if (show_warnings) + if (metadump.show_warnings) print_warning("invalid block number (%u) in inobt " "root in agi %u", root, agno); return 1; } if (levels > M_IGEO(mp)->inobt_maxlevels) { - if (show_warnings) + if (metadump.show_warnings) print_warning("invalid level (%u) in inobt root " "in agi %u", levels, agno); return 1; @@ -2697,7 +2715,7 @@ copy_inodes( levels = be32_to_cpu(agi->agi_free_level); if (root == 0 || root > mp->m_sb.sb_agblocks) { - if (show_warnings) + if (metadump.show_warnings) print_warning("invalid block number (%u) in " "finobt root in agi %u", root, agno); @@ -2705,7 +2723,7 @@ copy_inodes( } if (levels > M_IGEO(mp)->inobt_maxlevels) { - if (show_warnings) + if (metadump.show_warnings) print_warning("invalid level (%u) in finobt " "root in agi %u", levels, agno); return 1; @@ -2736,11 +2754,11 @@ scan_ag( XFS_FSS_TO_BB(mp, 1), DB_RING_IGN, NULL); if (!iocur_top->data) { print_warning("cannot read superblock for ag %u", agno); - if (stop_on_read_error) + if (metadump.stop_on_read_error) goto pop_out; } else { /* Replace any filesystem label with "L's" */ - if (obfuscate) { + if (metadump.obfuscate) { struct xfs_sb *sb = iocur_top->data; memset(sb->sb_fname, 'L', min(strlen(sb->sb_fname), sizeof(sb->sb_fname))); @@ -2758,7 +2776,7 @@ scan_ag( agf = iocur_top->data; if (iocur_top->data == NULL) { print_warning("cannot read agf block for ag %u", agno); - if (stop_on_read_error) + if (metadump.stop_on_read_error) goto pop_out; } else { if (write_buf(iocur_top)) @@ -2773,7 +2791,7 @@ scan_ag( agi = iocur_top->data; if (iocur_top->data == NULL) { print_warning("cannot read agi block for ag %u", agno); - if (stop_on_read_error) + if (metadump.stop_on_read_error) goto pop_out; } else { if (write_buf(iocur_top)) @@ -2787,10 +2805,10 @@ scan_ag( XFS_FSS_TO_BB(mp, 1), DB_RING_IGN, NULL); if (iocur_top->data == NULL) { print_warning("cannot read agfl block for ag %u", agno); - if (stop_on_read_error) + if (metadump.stop_on_read_error) goto pop_out; } else { - if (agf && zero_stale_data) { + if (agf && metadump.zero_stale_data) { /* Zero out unused bits of agfl */ int i; __be32 *agfl_bno; @@ -2813,7 +2831,7 @@ scan_ag( /* copy AG free space btrees */ if (agf) { - if (show_progress) + if (metadump.show_progress) print_progress("Copying free space trees of AG %u", agno); if (!copy_free_bno_btree(agno, agf)) @@ -2859,7 +2877,7 @@ copy_ino( if (agno >= mp->m_sb.sb_agcount || agbno >= mp->m_sb.sb_agblocks || offset >= mp->m_sb.sb_inopblock) { - if (show_warnings) + if (metadump.show_warnings) print_warning("invalid %s inode number (%lld)", typtab[itype].name, (long long)ino); return 1; @@ -2871,12 +2889,12 @@ copy_ino( if (iocur_top->data == NULL) { print_warning("cannot read %s inode %lld", typtab[itype].name, (long long)ino); - rval = !stop_on_read_error; + rval = !metadump.stop_on_read_error; goto pop_out; } off_cur(offset << mp->m_sb.sb_inodelog, mp->m_sb.sb_inodesize); - cur_ino = ino; + metadump.cur_ino = ino; rval = process_inode_data(iocur_top->data, itype); pop_out: pop_cur(); @@ -2912,7 +2930,7 @@ copy_log(void) int logversion; int cycle = XLOG_INIT_CYCLE; - if (show_progress) + if (metadump.show_progress) print_progress("Copying log"); push_cur(); @@ -2921,11 +2939,11 @@ copy_log(void) if (iocur_top->data == NULL) { pop_cur(); print_warning("cannot read log"); - return !stop_on_read_error; + return !metadump.stop_on_read_error; } /* If not obfuscating or zeroing, just copy the log as it is */ - if (!obfuscate && !zero_stale_data) + if (!metadump.obfuscate && !metadump.zero_stale_data) goto done; dirty = xlog_is_dirty(mp, &log, &x, 0); @@ -2933,7 +2951,7 @@ copy_log(void) switch (dirty) { case 0: /* clear out a clean log */ - if (show_progress) + if (metadump.show_progress) print_progress("Zeroing clean log"); logstart = XFS_FSB_TO_DADDR(mp, mp->m_sb.sb_logstart); @@ -2948,7 +2966,7 @@ copy_log(void) break; case 1: /* keep the dirty log */ - if (obfuscate) + if (metadump.obfuscate) print_warning( _("Warning: log recovery of an obfuscated metadata image can leak " "unobfuscated metadata and/or cause image corruption. If possible, " @@ -2956,7 +2974,7 @@ _("Warning: log recovery of an obfuscated metadata image can leak " break; case -1: /* log detection error */ - if (obfuscate) + if (metadump.obfuscate) print_warning( _("Could not discern log; image will contain unobfuscated metadata in log.")); break; @@ -2979,9 +2997,15 @@ metadump_f( char *p; exitcode = 1; - show_progress = 0; - show_warnings = 0; - stop_on_read_error = 0; + + metadump.version = 1; + metadump.show_progress = 0; + metadump.stop_on_read_error = 0; + metadump.max_extent_size = DEFAULT_MAX_EXT_SIZE; + metadump.show_warnings = 0; + metadump.obfuscate = 1; + metadump.zero_stale_data = 1; + metadump.dirty_log = false; if (mp->m_sb.sb_magicnum != XFS_SB_MAGIC) { print_warning("bad superblock magic number %x, giving up", @@ -3002,27 +3026,29 @@ metadump_f( while ((c = getopt(argc, argv, "aegm:ow")) != EOF) { switch (c) { case 'a': - zero_stale_data = 0; + metadump.zero_stale_data = 0; break; case 'e': - stop_on_read_error = 1; + metadump.stop_on_read_error = 1; break; case 'g': - show_progress = 1; + metadump.show_progress = 1; break; case 'm': - max_extent_size = (int)strtol(optarg, &p, 0); - if (*p != '\0' || max_extent_size <= 0) { + metadump.max_extent_size = + (int)strtol(optarg, &p, 0); + if (*p != '\0' || + metadump.max_extent_size <= 0) { print_warning("bad max extent size %s", optarg); return 0; } break; case 'o': - obfuscate = 0; + metadump.obfuscate = 0; break; case 'w': - show_warnings = 1; + metadump.show_warnings = 1; break; default: print_warning("bad option for metadump command"); @@ -3035,21 +3061,6 @@ metadump_f( return 0; } - metablock = (xfs_metablock_t *)calloc(BBSIZE + 1, BBSIZE); - if (metablock == NULL) { - print_warning("memory allocation failure"); - return 0; - } - metablock->mb_blocklog = BBSHIFT; - metablock->mb_magic = cpu_to_be32(XFS_MD_MAGIC); - - /* Set flags about state of metadump */ - metablock->mb_info = XFS_METADUMP_INFO_FLAGS; - if (obfuscate) - metablock->mb_info |= XFS_METADUMP_OBFUSCATED; - if (!zero_stale_data) - metablock->mb_info |= XFS_METADUMP_FULLBLOCKS; - /* If we'll copy the log, see if the log is dirty */ if (mp->m_sb.sb_logstart) { push_cur(); @@ -3060,34 +3071,52 @@ metadump_f( struct xlog log; if (xlog_is_dirty(mp, &log, &x, 0)) - metablock->mb_info |= XFS_METADUMP_DIRTYLOG; + metadump.dirty_log = true; } pop_cur(); } - block_index = (__be64 *)((char *)metablock + sizeof(xfs_metablock_t)); - block_buffer = (char *)metablock + BBSIZE; - num_indices = (BBSIZE - sizeof(xfs_metablock_t)) / sizeof(__be64); + metadump.metablock = (xfs_metablock_t *)calloc(BBSIZE + 1, BBSIZE); + if (metadump.metablock == NULL) { + print_warning("memory allocation failure"); + return -1; + } + metadump.metablock->mb_blocklog = BBSHIFT; + metadump.metablock->mb_magic = cpu_to_be32(XFS_MD_MAGIC); + + /* Set flags about state of metadump */ + metadump.metablock->mb_info = XFS_METADUMP_INFO_FLAGS; + if (metadump.obfuscate) + metadump.metablock->mb_info |= XFS_METADUMP_OBFUSCATED; + if (!metadump.zero_stale_data) + metadump.metablock->mb_info |= XFS_METADUMP_FULLBLOCKS; + if (metadump.dirty_log) + metadump.metablock->mb_info |= XFS_METADUMP_DIRTYLOG; + + metadump.block_index = (__be64 *)((char *)metadump.metablock + + sizeof(xfs_metablock_t)); + metadump.block_buffer = (char *)metadump.metablock + BBSIZE; + metadump.num_indices = (BBSIZE - sizeof(xfs_metablock_t)) / + sizeof(__be64); /* * A metadump block can hold at most num_indices of BBSIZE sectors; * do not try to dump a filesystem with a sector size which does not * fit within num_indices (i.e. within a single metablock). */ - if (mp->m_sb.sb_sectsize > num_indices * BBSIZE) { + if (mp->m_sb.sb_sectsize > metadump.num_indices * BBSIZE) { print_warning("Cannot dump filesystem with sector size %u", mp->m_sb.sb_sectsize); - free(metablock); + free(metadump.metablock); return 0; } - cur_index = 0; start_iocur_sp = iocur_sp; if (strcmp(argv[optind], "-") == 0) { if (isatty(fileno(stdout))) { print_warning("cannot write to a terminal"); - free(metablock); + free(metadump.metablock); return 0; } /* @@ -3111,17 +3140,17 @@ metadump_f( close(outfd); goto out; } - outf = fdopen(outfd, "a"); - if (outf == NULL) { + metadump.outf = fdopen(outfd, "a"); + if (metadump.outf == NULL) { fprintf(stderr, "cannot create dump stream\n"); dup2(outfd, STDOUT_FILENO); close(outfd); goto out; } - stdout_metadump = true; + metadump.stdout_metadump = true; } else { - outf = fopen(argv[optind], "wb"); - if (outf == NULL) { + metadump.outf = fopen(argv[optind], "wb"); + if (metadump.outf == NULL) { print_warning("cannot create dump file"); goto out; } @@ -3148,24 +3177,24 @@ metadump_f( if (!exitcode) exitcode = write_index() < 0; - if (progress_since_warning) - fputc('\n', stdout_metadump ? stderr : stdout); + if (metadump.progress_since_warning) + fputc('\n', metadump.stdout_metadump ? stderr : stdout); - if (stdout_metadump) { - fflush(outf); + if (metadump.stdout_metadump) { + fflush(metadump.outf); fflush(stdout); ret = dup2(outfd, STDOUT_FILENO); if (ret < 0) perror("un-redirecting stdout"); - stdout_metadump = false; + metadump.stdout_metadump = false; } - fclose(outf); + fclose(metadump.outf); /* cleanup iocur stack */ while (iocur_sp > start_iocur_sp) pop_cur(); out: - free(metablock); + free(metadump.metablock); return 0; } From patchwork Tue May 23 09:00:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Babu R X-Patchwork-Id: 13251924 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A32C4C7EE29 for ; Tue, 23 May 2023 09:01:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236055AbjEWJBP (ORCPT ); Tue, 23 May 2023 05:01:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35922 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236245AbjEWJBM (ORCPT ); Tue, 23 May 2023 05:01:12 -0400 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9F35A121 for ; Tue, 23 May 2023 02:01:11 -0700 (PDT) Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 34N6E7fg024604; Tue, 23 May 2023 09:01:08 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=corp-2023-03-30; bh=HVj0Vur7L3aHcILUSMuz4/pjMpNEnP1voyfXidwocOQ=; b=nAQ9Pa+0RsY5jDOQjnV7fb3zUOVfar4qpwmNmqsLPHNHcDlh7GeeKKEZOJ5INg6un16Z DwZWQp1pSGXgNC2ei2u9wZsTT1Aldv4APhjnn847VYxi7aWCmjIbpBrSwfVwlSoNGw8N dmc0kVqY8sTIRz15+0jPldV3RrUkGn/73FgEEo+k06uN2t5vaVIiimEXstHn06ikqgeZ qnU4ob9Y9nB0GeYqt8BDNMXMjcKb9iX+dwiLV2zmFCvVn0yACq6oV85zJMi3TJqeDAgc 1fZejLxwIelfCgMMJOX/jrAUwloFWFdT0xHFgfNmEwTKTvs1xqUbd+LnloRVr1WIg4OV yw== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3qpp7yvkwh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 23 May 2023 09:01:08 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 34N8l5Qq028926; Tue, 23 May 2023 09:01:07 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3qqk2aj7bg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 23 May 2023 09:01:07 +0000 Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 34N8xwrV007681; Tue, 23 May 2023 09:01:07 GMT Received: from chanbabu-fstest.osdevelopmeniad.oraclevcn.com (chanbabu-fstesting.allregionaliads.osdevelopmeniad.oraclevcn.com [100.100.250.50]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3qqk2aj76a-5; Tue, 23 May 2023 09:01:06 +0000 From: Chandan Babu R To: cem@kernel.org Cc: Chandan Babu R , linux-xfs@vger.kernel.org Subject: [PATCH 04/24] metadump: Add initialization and release functions Date: Tue, 23 May 2023 14:30:30 +0530 Message-Id: <20230523090050.373545-5-chandan.babu@oracle.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230523090050.373545-1-chandan.babu@oracle.com> References: <20230523090050.373545-1-chandan.babu@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.573,FMLib:17.11.176.26 definitions=2023-05-23_05,2023-05-22_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 mlxscore=0 mlxlogscore=831 phishscore=0 bulkscore=0 suspectscore=0 adultscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2304280000 definitions=main-2305230074 X-Proofpoint-ORIG-GUID: YGgPNYVj0rdZ3M6MBgyp7x5awJeEwhaI X-Proofpoint-GUID: YGgPNYVj0rdZ3M6MBgyp7x5awJeEwhaI Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org Move metadump initialization and release functionality into corresponding functions. Signed-off-by: Chandan Babu R Reviewed-by: Darrick J. Wong --- db/metadump.c | 88 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 52 insertions(+), 36 deletions(-) diff --git a/db/metadump.c b/db/metadump.c index 806cdfd68..e7a433c21 100644 --- a/db/metadump.c +++ b/db/metadump.c @@ -2984,6 +2984,54 @@ done: return !write_buf(iocur_top); } +static int +init_metadump(void) +{ + metadump.metablock = (xfs_metablock_t *)calloc(BBSIZE + 1, BBSIZE); + if (metadump.metablock == NULL) { + print_warning("memory allocation failure"); + return -1; + } + metadump.metablock->mb_blocklog = BBSHIFT; + metadump.metablock->mb_magic = cpu_to_be32(XFS_MD_MAGIC); + + /* Set flags about state of metadump */ + metadump.metablock->mb_info = XFS_METADUMP_INFO_FLAGS; + if (metadump.obfuscate) + metadump.metablock->mb_info |= XFS_METADUMP_OBFUSCATED; + if (!metadump.zero_stale_data) + metadump.metablock->mb_info |= XFS_METADUMP_FULLBLOCKS; + if (metadump.dirty_log) + metadump.metablock->mb_info |= XFS_METADUMP_DIRTYLOG; + + metadump.block_index = (__be64 *)((char *)metadump.metablock + + sizeof(xfs_metablock_t)); + metadump.block_buffer = (char *)(metadump.metablock) + BBSIZE; + metadump.num_indices = (BBSIZE - sizeof(xfs_metablock_t)) / sizeof(__be64); + + /* + * A metadump block can hold at most num_indices of BBSIZE sectors; + * do not try to dump a filesystem with a sector size which does not + * fit within num_indices (i.e. within a single metablock). + */ + if (mp->m_sb.sb_sectsize > metadump.num_indices * BBSIZE) { + print_warning("Cannot dump filesystem with sector size %u", + mp->m_sb.sb_sectsize); + free(metadump.metablock); + return -1; + } + + metadump.cur_index = 0; + + return 0; +} + +static void +release_metadump(void) +{ + free(metadump.metablock); +} + static int metadump_f( int argc, @@ -3076,48 +3124,16 @@ metadump_f( pop_cur(); } - metadump.metablock = (xfs_metablock_t *)calloc(BBSIZE + 1, BBSIZE); - if (metadump.metablock == NULL) { - print_warning("memory allocation failure"); - return -1; - } - metadump.metablock->mb_blocklog = BBSHIFT; - metadump.metablock->mb_magic = cpu_to_be32(XFS_MD_MAGIC); - - /* Set flags about state of metadump */ - metadump.metablock->mb_info = XFS_METADUMP_INFO_FLAGS; - if (metadump.obfuscate) - metadump.metablock->mb_info |= XFS_METADUMP_OBFUSCATED; - if (!metadump.zero_stale_data) - metadump.metablock->mb_info |= XFS_METADUMP_FULLBLOCKS; - if (metadump.dirty_log) - metadump.metablock->mb_info |= XFS_METADUMP_DIRTYLOG; - - metadump.block_index = (__be64 *)((char *)metadump.metablock + - sizeof(xfs_metablock_t)); - metadump.block_buffer = (char *)metadump.metablock + BBSIZE; - metadump.num_indices = (BBSIZE - sizeof(xfs_metablock_t)) / - sizeof(__be64); - - /* - * A metadump block can hold at most num_indices of BBSIZE sectors; - * do not try to dump a filesystem with a sector size which does not - * fit within num_indices (i.e. within a single metablock). - */ - if (mp->m_sb.sb_sectsize > metadump.num_indices * BBSIZE) { - print_warning("Cannot dump filesystem with sector size %u", - mp->m_sb.sb_sectsize); - free(metadump.metablock); + ret = init_metadump(); + if (ret) return 0; - } start_iocur_sp = iocur_sp; if (strcmp(argv[optind], "-") == 0) { if (isatty(fileno(stdout))) { print_warning("cannot write to a terminal"); - free(metadump.metablock); - return 0; + goto out; } /* * Redirect stdout to stderr for the duration of the @@ -3194,7 +3210,7 @@ metadump_f( while (iocur_sp > start_iocur_sp) pop_cur(); out: - free(metadump.metablock); + release_metadump(); return 0; } From patchwork Tue May 23 09:00:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Babu R X-Patchwork-Id: 13251927 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DF249C7EE26 for ; Tue, 23 May 2023 09:01:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236256AbjEWJBR (ORCPT ); Tue, 23 May 2023 05:01:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35960 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235827AbjEWJBO (ORCPT ); Tue, 23 May 2023 05:01:14 -0400 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0AE0A109 for ; Tue, 23 May 2023 02:01:13 -0700 (PDT) Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 34N6E87j018838; Tue, 23 May 2023 09:01:09 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=corp-2023-03-30; bh=sUdgl5UAhQH+c06U7m1qU0bIy/BRWiheyrHyGx1gbDY=; b=uJdQaY1q1B4OKYQaLZOXTwQqYFQxSWo/POgXy3Tw19lsVUnmccOEYaeBGq4oeh2cbEm9 xv8IzoPU5KWiaoO+tjoi3sc6Ma456hNBk8UpjYhtE4Dq7CngDF/KzYWEGZJPr1gR8z5A a4dDQJIa2usJSqkXWIPDS07DhNmzryZufXC1eUaCSS62MHE1NMqVUgTFk0G6I93t8A8o YjIKf+Mx9HFYrOP6gvkdeYB2xBtUDT6eXZZK9IqVQyPQuohWacMFR9Kd5+qnyAMK75W4 nSnu5kkWRXF/7tFKYp9KqaFtkfLed5E9Qy5jJ54JT9wNpYOVIllnsd7kGDHI9LedLdIJ Tw== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3qpp3qmku2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 23 May 2023 09:01:09 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 34N8KSV8029007; Tue, 23 May 2023 09:01:08 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3qqk2aj7c9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 23 May 2023 09:01:08 +0000 Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 34N8xwrX007681; Tue, 23 May 2023 09:01:07 GMT Received: from chanbabu-fstest.osdevelopmeniad.oraclevcn.com (chanbabu-fstesting.allregionaliads.osdevelopmeniad.oraclevcn.com [100.100.250.50]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3qqk2aj76a-6; Tue, 23 May 2023 09:01:07 +0000 From: Chandan Babu R To: cem@kernel.org Cc: Chandan Babu R , linux-xfs@vger.kernel.org Subject: [PATCH 05/24] set_cur: Add support to read from external log device Date: Tue, 23 May 2023 14:30:31 +0530 Message-Id: <20230523090050.373545-6-chandan.babu@oracle.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230523090050.373545-1-chandan.babu@oracle.com> References: <20230523090050.373545-1-chandan.babu@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.573,FMLib:17.11.176.26 definitions=2023-05-23_05,2023-05-22_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 mlxscore=0 mlxlogscore=999 phishscore=0 bulkscore=0 suspectscore=0 adultscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2304280000 definitions=main-2305230074 X-Proofpoint-GUID: hEak6Q2aiE-12P52W-GRczpbfVz7VXV_ X-Proofpoint-ORIG-GUID: hEak6Q2aiE-12P52W-GRczpbfVz7VXV_ Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org This commit changes set_cur() to be able to read from external log devices. This is required by a future commit which will add the ability to dump metadata from external log devices. Signed-off-by: Chandan Babu R --- db/io.c | 22 +++++++++++++++------- db/type.c | 2 ++ db/type.h | 2 +- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/db/io.c b/db/io.c index 3d2572364..e8c8f57e2 100644 --- a/db/io.c +++ b/db/io.c @@ -516,12 +516,13 @@ set_cur( int ring_flag, bbmap_t *bbmap) { - struct xfs_buf *bp; - xfs_ino_t dirino; - xfs_ino_t ino; - uint16_t mode; + struct xfs_buftarg *btargp; + struct xfs_buf *bp; + xfs_ino_t dirino; + xfs_ino_t ino; + uint16_t mode; const struct xfs_buf_ops *ops = type ? type->bops : NULL; - int error; + int error; if (iocur_sp < 0) { dbprintf(_("set_cur no stack element to set\n")); @@ -534,7 +535,14 @@ set_cur( pop_cur(); push_cur(); + btargp = mp->m_ddev_targp; + if (type->typnm == TYP_ELOG) { + ASSERT(mp->m_ddev_targp != mp->m_logdev_targp); + btargp = mp->m_logdev_targp; + } + if (bbmap) { + ASSERT(btargp == mp->m_ddev_targp); #ifdef DEBUG_BBMAP int i; printf(_("xfs_db got a bbmap for %lld\n"), (long long)blknum); @@ -548,11 +556,11 @@ set_cur( if (!iocur_top->bbmap) return; memcpy(iocur_top->bbmap, bbmap, sizeof(struct bbmap)); - error = -libxfs_buf_read_map(mp->m_ddev_targp, bbmap->b, + error = -libxfs_buf_read_map(btargp, bbmap->b, bbmap->nmaps, LIBXFS_READBUF_SALVAGE, &bp, ops); } else { - error = -libxfs_buf_read(mp->m_ddev_targp, blknum, len, + error = -libxfs_buf_read(btargp, blknum, len, LIBXFS_READBUF_SALVAGE, &bp, ops); iocur_top->bbmap = NULL; } diff --git a/db/type.c b/db/type.c index efe704456..cc406ae4c 100644 --- a/db/type.c +++ b/db/type.c @@ -100,6 +100,7 @@ static const typ_t __typtab_crc[] = { { TYP_INODE, "inode", handle_struct, inode_crc_hfld, &xfs_inode_buf_ops, TYP_F_CRC_FUNC, xfs_inode_set_crc }, { TYP_LOG, "log", NULL, NULL, NULL, TYP_F_NO_CRC_OFF }, + { TYP_ELOG, "elog", NULL, NULL, NULL, TYP_F_NO_CRC_OFF }, { TYP_RTBITMAP, "rtbitmap", handle_text, NULL, NULL, TYP_F_NO_CRC_OFF }, { TYP_RTSUMMARY, "rtsummary", handle_text, NULL, NULL, TYP_F_NO_CRC_OFF }, { TYP_SB, "sb", handle_struct, sb_hfld, &xfs_sb_buf_ops, @@ -144,6 +145,7 @@ static const typ_t __typtab_spcrc[] = { { TYP_INODE, "inode", handle_struct, inode_crc_hfld, &xfs_inode_buf_ops, TYP_F_CRC_FUNC, xfs_inode_set_crc }, { TYP_LOG, "log", NULL, NULL, NULL, TYP_F_NO_CRC_OFF }, + { TYP_ELOG, "elog", NULL, NULL, NULL, TYP_F_NO_CRC_OFF }, { TYP_RTBITMAP, "rtbitmap", handle_text, NULL, NULL, TYP_F_NO_CRC_OFF }, { TYP_RTSUMMARY, "rtsummary", handle_text, NULL, NULL, TYP_F_NO_CRC_OFF }, { TYP_SB, "sb", handle_struct, sb_hfld, &xfs_sb_buf_ops, diff --git a/db/type.h b/db/type.h index 411bfe90d..feb5c8219 100644 --- a/db/type.h +++ b/db/type.h @@ -14,7 +14,7 @@ typedef enum typnm TYP_AGF, TYP_AGFL, TYP_AGI, TYP_ATTR, TYP_BMAPBTA, TYP_BMAPBTD, TYP_BNOBT, TYP_CNTBT, TYP_RMAPBT, TYP_REFCBT, TYP_DATA, TYP_DIR2, TYP_DQBLK, TYP_INOBT, TYP_INODATA, TYP_INODE, - TYP_LOG, TYP_RTBITMAP, TYP_RTSUMMARY, TYP_SB, TYP_SYMLINK, + TYP_LOG, TYP_ELOG, TYP_RTBITMAP, TYP_RTSUMMARY, TYP_SB, TYP_SYMLINK, TYP_TEXT, TYP_FINOBT, TYP_NONE } typnm_t; From patchwork Tue May 23 09:00:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Babu R X-Patchwork-Id: 13251926 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 41644C7EE2F for ; Tue, 23 May 2023 09:01:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236253AbjEWJBQ (ORCPT ); Tue, 23 May 2023 05:01:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35958 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235537AbjEWJBO (ORCPT ); Tue, 23 May 2023 05:01:14 -0400 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E3A86102 for ; Tue, 23 May 2023 02:01:13 -0700 (PDT) Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 34N6EBVQ032759; Tue, 23 May 2023 09:01:11 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=corp-2023-03-30; bh=/8u15Jh1AadZ7uP9o0wFKSIhTaau/NjPrOnsopZcqUI=; b=owXEqL88evE/Q65fzgWEjP7aNO5W5MdP+/A6WJWTnFxUo83b+D5JZLqp7o7+73hVm5kG aSzmU8ePqq8EQsQRZqyCv3lLECjtxVnrwnwmKxDQpJOGxKl1aqtrAwke0YHg/fOSGusO 8CWYMScNjzWgJif3Flzqxdkk+I7Fv+kQ34z+rmaGrs4n7uz5v3DEijWHd0sjl4nnrmSZ ydzuoZV/e8L1TUa9AxOTJYnJP8FjO7KcYT8chUT7kZ5iP4cKviKvydFdNCW7IKoyrQ68 Bx1lwzTKOeSGqnnFsLHZAWii+xTbhFEpRag19vfM9fc4puMDRkk+wnttSSPWSNjbDBZh sg== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3qpp44mjh4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 23 May 2023 09:01:10 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 34N6wqRN028906; Tue, 23 May 2023 09:01:10 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3qqk2aj7d4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 23 May 2023 09:01:09 +0000 Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 34N8xwrZ007681; Tue, 23 May 2023 09:01:08 GMT Received: from chanbabu-fstest.osdevelopmeniad.oraclevcn.com (chanbabu-fstesting.allregionaliads.osdevelopmeniad.oraclevcn.com [100.100.250.50]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3qqk2aj76a-7; Tue, 23 May 2023 09:01:08 +0000 From: Chandan Babu R To: cem@kernel.org Cc: Chandan Babu R , linux-xfs@vger.kernel.org Subject: [PATCH 06/24] metadump: Dump external log device contents Date: Tue, 23 May 2023 14:30:32 +0530 Message-Id: <20230523090050.373545-7-chandan.babu@oracle.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230523090050.373545-1-chandan.babu@oracle.com> References: <20230523090050.373545-1-chandan.babu@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.573,FMLib:17.11.176.26 definitions=2023-05-23_05,2023-05-22_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 mlxscore=0 mlxlogscore=999 phishscore=0 bulkscore=0 suspectscore=0 adultscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2304280000 definitions=main-2305230074 X-Proofpoint-GUID: uj-Wg4MaFFPwiEwLXnNW3i2czRn4DnOT X-Proofpoint-ORIG-GUID: uj-Wg4MaFFPwiEwLXnNW3i2czRn4DnOT Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org metadump will now read and dump from external log device when the log is placed on an external device and metadump v2 is supported by xfsprogs. Signed-off-by: Chandan Babu R --- db/metadump.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/db/metadump.c b/db/metadump.c index e7a433c21..62a36427d 100644 --- a/db/metadump.c +++ b/db/metadump.c @@ -2921,7 +2921,7 @@ copy_sb_inodes(void) } static int -copy_log(void) +copy_log(enum typnm log_type) { struct xlog log; int dirty; @@ -2934,7 +2934,7 @@ copy_log(void) print_progress("Copying log"); push_cur(); - set_cur(&typtab[TYP_LOG], XFS_FSB_TO_DADDR(mp, mp->m_sb.sb_logstart), + set_cur(&typtab[log_type], XFS_FSB_TO_DADDR(mp, mp->m_sb.sb_logstart), mp->m_sb.sb_logblocks * blkbb, DB_RING_IGN, NULL); if (iocur_top->data == NULL) { pop_cur(); @@ -3038,6 +3038,7 @@ metadump_f( char **argv) { xfs_agnumber_t agno; + enum typnm log_type; int c; int start_iocur_sp; int outfd = -1; @@ -3110,9 +3111,13 @@ metadump_f( } /* If we'll copy the log, see if the log is dirty */ - if (mp->m_sb.sb_logstart) { + if (mp->m_logdev_targp == mp->m_ddev_targp || metadump.version == 2) { + log_type = TYP_LOG; + if (mp->m_logdev_targp != mp->m_ddev_targp) + log_type = TYP_ELOG; + push_cur(); - set_cur(&typtab[TYP_LOG], + set_cur(&typtab[log_type], XFS_FSB_TO_DADDR(mp, mp->m_sb.sb_logstart), mp->m_sb.sb_logblocks * blkbb, DB_RING_IGN, NULL); if (iocur_top->data) { /* best effort */ @@ -3185,9 +3190,10 @@ metadump_f( if (!exitcode) exitcode = !copy_sb_inodes(); - /* copy log if it's internal */ - if ((mp->m_sb.sb_logstart != 0) && !exitcode) - exitcode = !copy_log(); + /* copy log */ + if (!exitcode && (mp->m_logdev_targp == mp->m_ddev_targp || + metadump.version == 2)) + exitcode = !copy_log(log_type); /* write the remaining index */ if (!exitcode) From patchwork Tue May 23 09:00:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Babu R X-Patchwork-Id: 13251929 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9C03FC7EE2A for ; Tue, 23 May 2023 09:01:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236134AbjEWJBT (ORCPT ); Tue, 23 May 2023 05:01:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35984 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236245AbjEWJBQ (ORCPT ); Tue, 23 May 2023 05:01:16 -0400 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7F846102 for ; Tue, 23 May 2023 02:01:15 -0700 (PDT) Received: from pps.filterd (m0333520.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 34N6EH2I027651; Tue, 23 May 2023 09:01:11 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=corp-2023-03-30; bh=5OFkoXsQTRnwt3MwZi2MvSdGy1qxNFC37HDKMj1/AcM=; b=OuykondSwfHHk1LCzjB6fKzu/9yv9iAljEqooB16TLHQhvN+kyRkRh83pFmvF2GqSkUE ebWRrOmLGP6wyHTkIMYksHowcBVBOC9nnlAhn0emRqYRO3n7ImycLPJvuSCUuamUwOuY tRPL437KNH0Kv4q+3qwuD67Zht6IjQwL+rGcLaHq7M6hJy9kObCRDGXAeB1W7ork64gS V9ZpnoTK4owZ369gZlLEubZ43VCwWfpgcP5Fiire4jtbAcVK4QA/k0Xod6FJnx/JbTaD Z0OuHy8tZkPKm78iBHp08uhkDHpfLzXhYN4HJn5mUkNWg80t8aPvlp0GgL0N1mX0OUda dQ== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3qpp8ccp8f-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 23 May 2023 09:01:11 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 34N8ZZVu029026; Tue, 23 May 2023 09:01:10 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3qqk2aj7e1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 23 May 2023 09:01:09 +0000 Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 34N8xwrb007681; Tue, 23 May 2023 09:01:09 GMT Received: from chanbabu-fstest.osdevelopmeniad.oraclevcn.com (chanbabu-fstesting.allregionaliads.osdevelopmeniad.oraclevcn.com [100.100.250.50]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3qqk2aj76a-8; Tue, 23 May 2023 09:01:09 +0000 From: Chandan Babu R To: cem@kernel.org Cc: Chandan Babu R , linux-xfs@vger.kernel.org Subject: [PATCH 07/24] metadump: Postpone invocation of init_metadump() Date: Tue, 23 May 2023 14:30:33 +0530 Message-Id: <20230523090050.373545-8-chandan.babu@oracle.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230523090050.373545-1-chandan.babu@oracle.com> References: <20230523090050.373545-1-chandan.babu@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.573,FMLib:17.11.176.26 definitions=2023-05-23_05,2023-05-22_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 mlxscore=0 mlxlogscore=999 phishscore=0 bulkscore=0 suspectscore=0 adultscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2304280000 definitions=main-2305230074 X-Proofpoint-ORIG-GUID: M7_jvOkTnxcIfIsGIymDQ8NEwIlhzwnd X-Proofpoint-GUID: M7_jvOkTnxcIfIsGIymDQ8NEwIlhzwnd Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org A future commit will require that the metadump file be opened before execution of init_metadump(). Signed-off-by: Chandan Babu R --- db/metadump.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/db/metadump.c b/db/metadump.c index 62a36427d..212b484a2 100644 --- a/db/metadump.c +++ b/db/metadump.c @@ -3129,10 +3129,6 @@ metadump_f( pop_cur(); } - ret = init_metadump(); - if (ret) - return 0; - start_iocur_sp = iocur_sp; if (strcmp(argv[optind], "-") == 0) { @@ -3177,6 +3173,10 @@ metadump_f( } } + ret = init_metadump(); + if (ret) + return 0; + exitcode = 0; for (agno = 0; agno < mp->m_sb.sb_agcount; agno++) { @@ -3215,8 +3215,9 @@ metadump_f( /* cleanup iocur stack */ while (iocur_sp > start_iocur_sp) pop_cur(); -out: + release_metadump(); +out: return 0; } From patchwork Tue May 23 09:00:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Babu R X-Patchwork-Id: 13251928 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E01DFC7EE23 for ; Tue, 23 May 2023 09:01:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232838AbjEWJBS (ORCPT ); Tue, 23 May 2023 05:01:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35970 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236134AbjEWJBP (ORCPT ); Tue, 23 May 2023 05:01:15 -0400 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8A381100 for ; Tue, 23 May 2023 02:01:14 -0700 (PDT) Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 34N6E88n018876; Tue, 23 May 2023 09:01:11 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=corp-2023-03-30; bh=6dhCd2tVnD1SQjBVOzOqe6QmEgT6ggmALxTywv95LNY=; b=HWcwWGl/amOqccxXq5II8+glVqBwlbE+Ex+Lc8Mlb3jYmaS+WznSr+A1CNv+pTkD5qlz Yc5i//05nyoILtrP2KO+PjWvwrDmfMRna4iYqSQc8heD9mCIGGgUeaqB76qcnj7nb/PX wozQOzftXzadQguqqZiy2Sv8bjBgHg60z//z2N1i2V1eyKh/NsmrnfBQJBcK5oWVE9YI 2lIAquuzwY/9QX0jpODj/QrhHTqpqukvz9dYXdwE2elEKfrIcGRydRRysV4TrhnxiS4Y ya3bRoYa1l4PuyRQFQ0HShJc4wj+5o3C+0YTRUnno7EaR2i6qvpt7RCjHVhMbmv2uoRh oA== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3qpp3qmku9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 23 May 2023 09:01:11 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 34N8dwG8029050; Tue, 23 May 2023 09:01:10 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3qqk2aj7eu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 23 May 2023 09:01:10 +0000 Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 34N8xwrd007681; Tue, 23 May 2023 09:01:10 GMT Received: from chanbabu-fstest.osdevelopmeniad.oraclevcn.com (chanbabu-fstesting.allregionaliads.osdevelopmeniad.oraclevcn.com [100.100.250.50]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3qqk2aj76a-9; Tue, 23 May 2023 09:01:10 +0000 From: Chandan Babu R To: cem@kernel.org Cc: Chandan Babu R , linux-xfs@vger.kernel.org Subject: [PATCH 08/24] metadump: Introduce struct metadump_ops Date: Tue, 23 May 2023 14:30:34 +0530 Message-Id: <20230523090050.373545-9-chandan.babu@oracle.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230523090050.373545-1-chandan.babu@oracle.com> References: <20230523090050.373545-1-chandan.babu@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.573,FMLib:17.11.176.26 definitions=2023-05-23_05,2023-05-22_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 mlxscore=0 mlxlogscore=999 phishscore=0 bulkscore=0 suspectscore=0 adultscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2304280000 definitions=main-2305230074 X-Proofpoint-GUID: JXZf6Evf4Eq6xahoJDN4ib29kcRrApvW X-Proofpoint-ORIG-GUID: JXZf6Evf4Eq6xahoJDN4ib29kcRrApvW Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org We will need two sets of functions to implement two versions of metadump. This commit adds the definition for 'struct metadump_ops' to hold pointers to version specific metadump functions. Signed-off-by: Chandan Babu R --- db/metadump.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/db/metadump.c b/db/metadump.c index 212b484a2..56d8c3bdf 100644 --- a/db/metadump.c +++ b/db/metadump.c @@ -40,6 +40,14 @@ static const cmdinfo_t metadump_cmd = N_("[-a] [-e] [-g] [-m max_extent] [-w] [-o] filename"), N_("dump metadata to a file"), metadump_help }; +struct metadump_ops { + int (*init_metadump)(void); + int (*write_metadump)(enum typnm type, char *data, int64_t off, + int len); + int (*end_write_metadump)(void); + void (*release_metadump)(void); +}; + static struct metadump { int version; int show_progress; @@ -54,6 +62,7 @@ static struct metadump { xfs_ino_t cur_ino; /* Metadump file */ FILE *outf; + struct metadump_ops *mdops; /* header + index + buffers */ struct xfs_metablock *metablock; __be64 *block_index; From patchwork Tue May 23 09:00:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Babu R X-Patchwork-Id: 13251930 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4AF64C7EE26 for ; Tue, 23 May 2023 09:01:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236266AbjEWJBU (ORCPT ); Tue, 23 May 2023 05:01:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35992 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236241AbjEWJBQ (ORCPT ); Tue, 23 May 2023 05:01:16 -0400 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D03A8109 for ; Tue, 23 May 2023 02:01:15 -0700 (PDT) Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 34N6E7tF024581; Tue, 23 May 2023 09:01:12 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=corp-2023-03-30; bh=wTsdLbgC0mtKQFX6G0zvNlufcDBEAudO9GKzyPdksPE=; b=wdIVXjVeimx0LyOrggnm4sqGHkQpwXGx1yt5wzvqCyzvvSAW79zHkJL8ad66kaY9Fjj7 WDf53jp2eF2gNBoULCh0OlUuJvkyvv0nVsdVrW8f5X4wAqF07rCbYTI7saHIzah/KqUO wtowPvavHk7k9KQiKK5Iu7vTTMbTEuEuLD+BuoZaUT11V+E5xv/ZBPRVZ89dRki8ZR6X l4n4y6D8LuVNJsmVvmLW6WMmnqDuxpHBPTTwxXMeSKtFlnjb3b/89VYJ8VFE6RAsLPgT HVqdvOnYd0I1WXomLRPtKgE+a8yxoS6Trd+CKS250d/KrBzaKQyFwC0jy7drcS5NQKZw FQ== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3qpp7yvkws-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 23 May 2023 09:01:12 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 34N747hp028892; Tue, 23 May 2023 09:01:11 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3qqk2aj7fd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 23 May 2023 09:01:11 +0000 Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 34N8xwrf007681; Tue, 23 May 2023 09:01:11 GMT Received: from chanbabu-fstest.osdevelopmeniad.oraclevcn.com (chanbabu-fstesting.allregionaliads.osdevelopmeniad.oraclevcn.com [100.100.250.50]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3qqk2aj76a-10; Tue, 23 May 2023 09:01:11 +0000 From: Chandan Babu R To: cem@kernel.org Cc: Chandan Babu R , linux-xfs@vger.kernel.org Subject: [PATCH 09/24] metadump: Introduce metadump v1 operations Date: Tue, 23 May 2023 14:30:35 +0530 Message-Id: <20230523090050.373545-10-chandan.babu@oracle.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230523090050.373545-1-chandan.babu@oracle.com> References: <20230523090050.373545-1-chandan.babu@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.573,FMLib:17.11.176.26 definitions=2023-05-23_05,2023-05-22_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 mlxscore=0 mlxlogscore=999 phishscore=0 bulkscore=0 suspectscore=0 adultscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2304280000 definitions=main-2305230074 X-Proofpoint-ORIG-GUID: wgEHke315t0Hdehwn-yVhL9QpfCWpbOr X-Proofpoint-GUID: wgEHke315t0Hdehwn-yVhL9QpfCWpbOr Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org This commit moves functionality associated with writing metadump to disk into a new function. It also renames metadump initialization, write and release functions to reflect the fact that they work with v1 metadump files. The metadump initialization, write and release functions are now invoked via metadump_ops->init_metadump(), metadump_ops->write_metadump() and metadump_ops->release_metadump() respectively. Signed-off-by: Chandan Babu R --- db/metadump.c | 124 +++++++++++++++++++++++++------------------------- 1 file changed, 61 insertions(+), 63 deletions(-) diff --git a/db/metadump.c b/db/metadump.c index 56d8c3bdf..7265f73ec 100644 --- a/db/metadump.c +++ b/db/metadump.c @@ -135,59 +135,6 @@ print_progress(const char *fmt, ...) metadump.progress_since_warning = 1; } -/* - * A complete dump file will have a "zero" entry in the last index block, - * even if the dump is exactly aligned, the last index will be full of - * zeros. If the last index entry is non-zero, the dump is incomplete. - * Correspondingly, the last chunk will have a count < num_indices. - * - * Return 0 for success, -1 for failure. - */ - -static int -write_index(void) -{ - struct xfs_metablock *metablock = metadump.metablock; - /* - * write index block and following data blocks (streaming) - */ - metablock->mb_count = cpu_to_be16(metadump.cur_index); - if (fwrite(metablock, (metadump.cur_index + 1) << BBSHIFT, 1, - metadump.outf) != 1) { - print_warning("error writing to target file"); - return -1; - } - - memset(metadump.block_index, 0, metadump.num_indices * sizeof(__be64)); - metadump.cur_index = 0; - return 0; -} - -/* - * Return 0 for success, -errno for failure. - */ -static int -write_buf_segment( - char *data, - int64_t off, - int len) -{ - int i; - int ret; - - for (i = 0; i < len; i++, off++, data += BBSIZE) { - metadump.block_index[metadump.cur_index] = cpu_to_be64(off); - memcpy(&metadump.block_buffer[metadump.cur_index << BBSHIFT], - data, BBSIZE); - if (++metadump.cur_index == metadump.num_indices) { - ret = write_index(); - if (ret) - return -EIO; - } - } - return 0; -} - /* * we want to preserve the state of the metadata in the dump - whether it is * intact or corrupt, so even if the buffer has a verifier attached to it we @@ -224,15 +171,16 @@ write_buf( /* handle discontiguous buffers */ if (!buf->bbmap) { - ret = write_buf_segment(buf->data, buf->bb, buf->blen); + ret = metadump.mdops->write_metadump(buf->typ->typnm, buf->data, + buf->bb, buf->blen); if (ret) return ret; } else { int len = 0; for (i = 0; i < buf->bbmap->nmaps; i++) { - ret = write_buf_segment(buf->data + BBTOB(len), - buf->bbmap->b[i].bm_bn, - buf->bbmap->b[i].bm_len); + ret = metadump.mdops->write_metadump(buf->typ->typnm, + buf->data + BBTOB(len), buf->bbmap->b[i].bm_bn, + buf->bbmap->b[i].bm_len); if (ret) return ret; len += buf->bbmap->b[i].bm_len; @@ -2994,7 +2942,7 @@ done: } static int -init_metadump(void) +init_metadump_v1(void) { metadump.metablock = (xfs_metablock_t *)calloc(BBSIZE + 1, BBSIZE); if (metadump.metablock == NULL) { @@ -3035,12 +2983,60 @@ init_metadump(void) return 0; } +static int +end_write_metadump_v1(void) +{ + /* + * write index block and following data blocks (streaming) + */ + metadump.metablock->mb_count = cpu_to_be16(metadump.cur_index); + if (fwrite(metadump.metablock, (metadump.cur_index + 1) << BBSHIFT, 1, metadump.outf) != 1) { + print_warning("error writing to target file"); + return -1; + } + + memset(metadump.block_index, 0, metadump.num_indices * sizeof(__be64)); + metadump.cur_index = 0; + return 0; +} + +static int +write_metadump_v1( + enum typnm type, + char *data, + int64_t off, + int len) +{ + int i; + int ret; + + for (i = 0; i < len; i++, off++, data += BBSIZE) { + metadump.block_index[metadump.cur_index] = cpu_to_be64(off); + memcpy(&metadump.block_buffer[metadump.cur_index << BBSHIFT], + data, BBSIZE); + if (++metadump.cur_index == metadump.num_indices) { + ret = end_write_metadump_v1(); + if (ret) + return -EIO; + } + } + + return 0; +} + static void -release_metadump(void) +release_metadump_v1(void) { free(metadump.metablock); } +static struct metadump_ops metadump1_ops = { + .init_metadump = init_metadump_v1, + .write_metadump = write_metadump_v1, + .end_write_metadump = end_write_metadump_v1, + .release_metadump = release_metadump_v1, +}; + static int metadump_f( int argc, @@ -3182,9 +3178,11 @@ metadump_f( } } - ret = init_metadump(); + metadump.mdops = &metadump1_ops; + + ret = metadump.mdops->init_metadump(); if (ret) - return 0; + goto out; exitcode = 0; @@ -3206,7 +3204,7 @@ metadump_f( /* write the remaining index */ if (!exitcode) - exitcode = write_index() < 0; + exitcode = metadump.mdops->end_write_metadump() < 0; if (metadump.progress_since_warning) fputc('\n', metadump.stdout_metadump ? stderr : stdout); @@ -3225,7 +3223,7 @@ metadump_f( while (iocur_sp > start_iocur_sp) pop_cur(); - release_metadump(); + metadump.mdops->release_metadump(); out: return 0; From patchwork Tue May 23 09:00:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Babu R X-Patchwork-Id: 13251931 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 599F8C7EE29 for ; Tue, 23 May 2023 09:01:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236248AbjEWJBV (ORCPT ); Tue, 23 May 2023 05:01:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35998 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235537AbjEWJBR (ORCPT ); Tue, 23 May 2023 05:01:17 -0400 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 855CBFE for ; Tue, 23 May 2023 02:01:16 -0700 (PDT) Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 34N6E8CB018853; Tue, 23 May 2023 09:01:13 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=corp-2023-03-30; bh=v66R6aeiwdDhCLF3mKEo6Hk/QM8vHhRl9tk1RgkNLRQ=; b=Nso/54bWU2KvF796Y05baqyOcM+X82FmzNRL0prMzFI5mJf32ary8Ug5HCN2cN5YhiA7 MplEV/Kvj0HHCqpC7hpMLxXB9TqY/l3Xu63SUfoiI8caWwc9mFFycTrjMP8azx4TA+dW ktudYp42ko12zsu/nlXCoWYmZYO0CEmElEal5PBpRTlQYJE53ObT0kaEYeeP5+qp4gL5 xeuiZzllOfjooFwXHN4YTyH0XoO7ed1t2Xtpfa2+GKkL/e7QJoLl2rcaev8TV2pn39TX ibdExlcXpHq3o3SXJafiSqCaG/vwbOogQZaPGp2zuoHEvU4RvdZ8bo8aSmYxpn88Iuz0 aA== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3qpp3qmkuc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 23 May 2023 09:01:13 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 34N6tA9N028916; Tue, 23 May 2023 09:01:12 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3qqk2aj7g1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 23 May 2023 09:01:12 +0000 Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 34N8xwrh007681; Tue, 23 May 2023 09:01:11 GMT Received: from chanbabu-fstest.osdevelopmeniad.oraclevcn.com (chanbabu-fstesting.allregionaliads.osdevelopmeniad.oraclevcn.com [100.100.250.50]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3qqk2aj76a-11; Tue, 23 May 2023 09:01:11 +0000 From: Chandan Babu R To: cem@kernel.org Cc: Chandan Babu R , linux-xfs@vger.kernel.org Subject: [PATCH 10/24] metadump: Rename XFS_MD_MAGIC to XFS_MD_MAGIC_V1 Date: Tue, 23 May 2023 14:30:36 +0530 Message-Id: <20230523090050.373545-11-chandan.babu@oracle.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230523090050.373545-1-chandan.babu@oracle.com> References: <20230523090050.373545-1-chandan.babu@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.573,FMLib:17.11.176.26 definitions=2023-05-23_05,2023-05-22_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 mlxscore=0 mlxlogscore=999 phishscore=0 bulkscore=0 suspectscore=0 adultscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2304280000 definitions=main-2305230074 X-Proofpoint-GUID: nEkQqNaPJO5Hc0VpzFSWaN_CnsM0SkPD X-Proofpoint-ORIG-GUID: nEkQqNaPJO5Hc0VpzFSWaN_CnsM0SkPD Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org Signed-off-by: Chandan Babu R Reviewed-by: Darrick J. Wong --- db/metadump.c | 2 +- include/xfs_metadump.h | 2 +- mdrestore/xfs_mdrestore.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/db/metadump.c b/db/metadump.c index 7265f73ec..9d7ad76ae 100644 --- a/db/metadump.c +++ b/db/metadump.c @@ -2950,7 +2950,7 @@ init_metadump_v1(void) return -1; } metadump.metablock->mb_blocklog = BBSHIFT; - metadump.metablock->mb_magic = cpu_to_be32(XFS_MD_MAGIC); + metadump.metablock->mb_magic = cpu_to_be32(XFS_MD_MAGIC_V1); /* Set flags about state of metadump */ metadump.metablock->mb_info = XFS_METADUMP_INFO_FLAGS; diff --git a/include/xfs_metadump.h b/include/xfs_metadump.h index fbd990232..a4dca25cb 100644 --- a/include/xfs_metadump.h +++ b/include/xfs_metadump.h @@ -7,7 +7,7 @@ #ifndef _XFS_METADUMP_H_ #define _XFS_METADUMP_H_ -#define XFS_MD_MAGIC 0x5846534d /* 'XFSM' */ +#define XFS_MD_MAGIC_V1 0x5846534d /* 'XFSM' */ typedef struct xfs_metablock { __be32 mb_magic; diff --git a/mdrestore/xfs_mdrestore.c b/mdrestore/xfs_mdrestore.c index 333282ed2..481dd00c2 100644 --- a/mdrestore/xfs_mdrestore.c +++ b/mdrestore/xfs_mdrestore.c @@ -240,7 +240,7 @@ main( 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)) + if (mb.mb_magic != cpu_to_be32(XFS_MD_MAGIC_V1)) fatal("specified file is not a metadata dump\n"); if (show_info) { From patchwork Tue May 23 09:00:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Babu R X-Patchwork-Id: 13251932 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 888B3C7EE23 for ; Tue, 23 May 2023 09:01:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232996AbjEWJBW (ORCPT ); Tue, 23 May 2023 05:01:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36000 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236259AbjEWJBR (ORCPT ); Tue, 23 May 2023 05:01:17 -0400 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 005FC100 for ; Tue, 23 May 2023 02:01:16 -0700 (PDT) Received: from pps.filterd (m0333520.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 34N6EF50027123; Tue, 23 May 2023 09:01:14 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=corp-2023-03-30; bh=Tiq59H3WNYtrILpA3KGek33W1g+uwqBzFWm+PtgfqQw=; b=lha6QxZuhvTdxOTQwXHtHsO6kC4dyWZkjKBVYJgF30r0njSt6qxkHQM2M/BVlqZg6R8E diCoCGBGfFz2u1wsJ6mFrNOptiQ86SI79MOOkXPqh54iaD2bUHH+QQbdbyLwEJd1MLLe 99CxALZNmqeuJ7SPkrkIdFuq9JOHteZsQneg1MTugRL4R60KTSSnHGBe04XtBAjbKmmK +/wZgAoFhmYvSXGvM14vv8Fz2nryb9ufQnFpRCzZOyK5crg7YrFqVgkjBpUqJy5wY0Pf vcUqPPcrbSj8UGZWw7USFTXf3SykW7fix/NGWYEjWirUVDw9WMbgEJ3jQ2noYLz5Wewx 2g== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3qpp8ccp8q-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 23 May 2023 09:01:14 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 34N916T4029019; Tue, 23 May 2023 09:01:13 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3qqk2aj7h3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 23 May 2023 09:01:13 +0000 Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 34N8xwrj007681; Tue, 23 May 2023 09:01:12 GMT Received: from chanbabu-fstest.osdevelopmeniad.oraclevcn.com (chanbabu-fstesting.allregionaliads.osdevelopmeniad.oraclevcn.com [100.100.250.50]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3qqk2aj76a-12; Tue, 23 May 2023 09:01:12 +0000 From: Chandan Babu R To: cem@kernel.org Cc: Chandan Babu R , linux-xfs@vger.kernel.org Subject: [PATCH 11/24] metadump: Define metadump v2 ondisk format structures and macros Date: Tue, 23 May 2023 14:30:37 +0530 Message-Id: <20230523090050.373545-12-chandan.babu@oracle.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230523090050.373545-1-chandan.babu@oracle.com> References: <20230523090050.373545-1-chandan.babu@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.573,FMLib:17.11.176.26 definitions=2023-05-23_05,2023-05-22_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 mlxscore=0 mlxlogscore=999 phishscore=0 bulkscore=0 suspectscore=0 adultscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2304280000 definitions=main-2305230074 X-Proofpoint-ORIG-GUID: Xv0cPAumugli8ityBiygUHb0g0FhGT24 X-Proofpoint-GUID: Xv0cPAumugli8ityBiygUHb0g0FhGT24 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org Signed-off-by: Chandan Babu R --- include/xfs_metadump.h | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/include/xfs_metadump.h b/include/xfs_metadump.h index a4dca25cb..1d8d7008c 100644 --- a/include/xfs_metadump.h +++ b/include/xfs_metadump.h @@ -8,7 +8,9 @@ #define _XFS_METADUMP_H_ #define XFS_MD_MAGIC_V1 0x5846534d /* 'XFSM' */ +#define XFS_MD_MAGIC_V2 0x584D4432 /* 'XMD2' */ +/* Metadump v1 */ typedef struct xfs_metablock { __be32 mb_magic; __be16 mb_count; @@ -23,4 +25,34 @@ typedef struct xfs_metablock { #define XFS_METADUMP_FULLBLOCKS (1 << 2) #define XFS_METADUMP_DIRTYLOG (1 << 3) +/* Metadump v2 */ +struct xfs_metadump_header { + __be32 xmh_magic; + __be32 xmh_version; + __be32 xmh_compat_flags; + __be32 xmh_incompat_flags; + __be64 xmh_reserved; +} __packed; + +#define XFS_MD2_INCOMPAT_OBFUSCATED (1 << 0) +#define XFS_MD2_INCOMPAT_FULLBLOCKS (1 << 1) +#define XFS_MD2_INCOMPAT_DIRTYLOG (1 << 2) + +struct xfs_meta_extent { + /* + * Lowest 54 bits are used to store 512 byte addresses. + * Next 2 bits is used for indicating the device. + * 00 - Data device + * 01 - External log + */ + __be64 xme_addr; + /* In units of 512 byte blocks */ + __be32 xme_len; +} __packed; + +#define XME_ADDR_DATA_DEVICE (1UL << 54) +#define XME_ADDR_LOG_DEVICE (1UL << 55) + +#define XME_ADDR_DEVICE_MASK (~(XME_ADDR_DATA_DEVICE | XME_ADDR_LOG_DEVICE)) + #endif /* _XFS_METADUMP_H_ */ From patchwork Tue May 23 09:00:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Babu R X-Patchwork-Id: 13251933 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9A7ABC7EE2A for ; Tue, 23 May 2023 09:01:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235537AbjEWJBW (ORCPT ); Tue, 23 May 2023 05:01:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36012 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235827AbjEWJBT (ORCPT ); Tue, 23 May 2023 05:01:19 -0400 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CFF0B109 for ; Tue, 23 May 2023 02:01:17 -0700 (PDT) Received: from pps.filterd (m0333520.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 34N6EF9o027118; Tue, 23 May 2023 09:01:15 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=corp-2023-03-30; bh=Lwr5U15JmUjh17Ts8ZhFj0Kqpr/F6zbqkmi9G0yk9As=; b=3X2mJ0sOnuFSC3mvuS2uGkZH0TaojPty0Red/8J196MHjhcsOpHgHygL/65Djf4ABTrX kRuyHyzYgjWtUwgPkwyQcrR6iyKrF57qENQKyELRCqynovirLIWfyQ1HaS1tfIgNvBb6 MBqBwDy36mQVr5amZUIKk0WE6TSr189V3gFAGcdaiyWSca7xyCYU1dVGAeMP5rLVJygF ZnJf9kB8240NE+eCRMykAl8b3fDuobUVpCmNfZfTt0DXHEOIJ3pD1u3V5rDGuiQrgNZu +owCE2NQXgCyKTDZ7n71Vl5iBVwHCj0KEXr6FDiTZrZ3ZgodN9bEBuNME1p+TaANLtmP GA== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3qpp8ccp8s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 23 May 2023 09:01:14 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 34N8v8oO029531; Tue, 23 May 2023 09:01:14 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3qqk2aj7j2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 23 May 2023 09:01:14 +0000 Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 34N8xwrl007681; Tue, 23 May 2023 09:01:13 GMT Received: from chanbabu-fstest.osdevelopmeniad.oraclevcn.com (chanbabu-fstesting.allregionaliads.osdevelopmeniad.oraclevcn.com [100.100.250.50]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3qqk2aj76a-13; Tue, 23 May 2023 09:01:13 +0000 From: Chandan Babu R To: cem@kernel.org Cc: Chandan Babu R , linux-xfs@vger.kernel.org Subject: [PATCH 12/24] metadump: Define metadump ops for v2 format Date: Tue, 23 May 2023 14:30:38 +0530 Message-Id: <20230523090050.373545-13-chandan.babu@oracle.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230523090050.373545-1-chandan.babu@oracle.com> References: <20230523090050.373545-1-chandan.babu@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.573,FMLib:17.11.176.26 definitions=2023-05-23_05,2023-05-22_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 mlxscore=0 mlxlogscore=999 phishscore=0 bulkscore=0 suspectscore=0 adultscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2304280000 definitions=main-2305230074 X-Proofpoint-ORIG-GUID: knDoZdKgI-4LwYePe3RnwcF-1vkugHj5 X-Proofpoint-GUID: knDoZdKgI-4LwYePe3RnwcF-1vkugHj5 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org This commit adds functionality to dump metadata from an XFS filesystem in newly introduced v2 format. Signed-off-by: Chandan Babu R --- db/metadump.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 70 insertions(+), 3 deletions(-) diff --git a/db/metadump.c b/db/metadump.c index 9d7ad76ae..627436e68 100644 --- a/db/metadump.c +++ b/db/metadump.c @@ -3037,6 +3037,69 @@ static struct metadump_ops metadump1_ops = { .release_metadump = 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, + int64_t off, + int len) +{ + struct xfs_meta_extent xme; + uint64_t addr; + + addr = off; + if (type == TYP_ELOG) + 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_metadump = init_metadump_v2, + .write_metadump = write_metadump_v2, +}; + static int metadump_f( int argc, @@ -3178,7 +3241,10 @@ metadump_f( } } - metadump.mdops = &metadump1_ops; + if (metadump.version == 1) + metadump.mdops = &metadump1_ops; + else + metadump.mdops = &metadump2_ops; ret = metadump.mdops->init_metadump(); if (ret) @@ -3203,7 +3269,7 @@ metadump_f( exitcode = !copy_log(log_type); /* write the remaining index */ - if (!exitcode) + if (!exitcode && metadump.mdops->end_write_metadump) exitcode = metadump.mdops->end_write_metadump() < 0; if (metadump.progress_since_warning) @@ -3223,7 +3289,8 @@ metadump_f( while (iocur_sp > start_iocur_sp) pop_cur(); - metadump.mdops->release_metadump(); + if (metadump.mdops->release_metadump) + metadump.mdops->release_metadump(); out: return 0; From patchwork Tue May 23 09:00:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Babu R X-Patchwork-Id: 13251935 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C9AD6C7EE29 for ; Tue, 23 May 2023 09:01:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235827AbjEWJBX (ORCPT ); Tue, 23 May 2023 05:01:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36034 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236245AbjEWJBU (ORCPT ); Tue, 23 May 2023 05:01:20 -0400 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2FC88FE for ; Tue, 23 May 2023 02:01:19 -0700 (PDT) Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 34N6E7KL018830; Tue, 23 May 2023 09:01:16 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=corp-2023-03-30; bh=BRmTfGYqBT84VMTSDOA5n6aX34AoTwePLwN1BvYiyjM=; b=QzgwFyzfTOHc00SZqr+0slRYa9vD6JfE2uNmv9Nom3z1nor2/TLQg5i3sCSQMvmiIlaq fo6uWuMLFJm5ddOIcWrv8bXlKchLUORXFAsUgyYu6efhnYtjwdz7UNwtD1yr2nFfGgtw Enkw5r/UqszijPLMgdebr5Hzy5g4czgob2qImiUlUvYF6fjVdUmvicg/cZPDrosYaePk ZZ4BmUhhFgJdEzFvStKrac7N6v/ixIBBrBrnx7st7XvxjaTwr47LI0/apDCCCazb8Lnu EdxVcNw7WFNq9WKTTYJelRxOWGO1F2v2Aa/5n82WhWQ019+d9jxWx+QtqgOsJmB7A5Be eA== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3qpp3qmkug-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 23 May 2023 09:01:15 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 34N6tBgU029028; Tue, 23 May 2023 09:01:15 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3qqk2aj7jm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 23 May 2023 09:01:14 +0000 Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 34N8xwrn007681; Tue, 23 May 2023 09:01:14 GMT Received: from chanbabu-fstest.osdevelopmeniad.oraclevcn.com (chanbabu-fstesting.allregionaliads.osdevelopmeniad.oraclevcn.com [100.100.250.50]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3qqk2aj76a-14; Tue, 23 May 2023 09:01:14 +0000 From: Chandan Babu R To: cem@kernel.org Cc: Chandan Babu R , linux-xfs@vger.kernel.org Subject: [PATCH 13/24] metadump: Add support for passing version option Date: Tue, 23 May 2023 14:30:39 +0530 Message-Id: <20230523090050.373545-14-chandan.babu@oracle.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230523090050.373545-1-chandan.babu@oracle.com> References: <20230523090050.373545-1-chandan.babu@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.573,FMLib:17.11.176.26 definitions=2023-05-23_05,2023-05-22_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 mlxscore=0 mlxlogscore=999 phishscore=0 bulkscore=0 suspectscore=0 adultscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2304280000 definitions=main-2305230074 X-Proofpoint-GUID: xQ2x5igoy_vz4vsEfuY2Q0v6Sm8wbJhO X-Proofpoint-ORIG-GUID: xQ2x5igoy_vz4vsEfuY2Q0v6Sm8wbJhO Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org The new option allows the user to explicitly specify the version of metadump to use. However, we will default to using the v1 format. Signed-off-by: Chandan Babu R Reviewed-by: Darrick J. Wong --- db/metadump.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/db/metadump.c b/db/metadump.c index 627436e68..df508b987 100644 --- a/db/metadump.c +++ b/db/metadump.c @@ -37,7 +37,7 @@ static void metadump_help(void); static const cmdinfo_t metadump_cmd = { "metadump", NULL, metadump_f, 0, -1, 0, - N_("[-a] [-e] [-g] [-m max_extent] [-w] [-o] filename"), + N_("[-a] [-e] [-g] [-m max_extent] [-w] [-o] [-v 1|2] filename"), N_("dump metadata to a file"), metadump_help }; struct metadump_ops { @@ -91,6 +91,7 @@ metadump_help(void) " -g -- Display dump progress\n" " -m -- Specify max extent size in blocks to copy (default = %d blocks)\n" " -o -- Don't obfuscate names and extended attributes\n" +" -v -- Metadump version to be used\n" " -w -- Show warnings of bad metadata information\n" "\n"), DEFAULT_MAX_EXT_SIZE); } @@ -3112,6 +3113,7 @@ metadump_f( int outfd = -1; int ret; char *p; + bool version_opt_set = false; exitcode = 1; @@ -3140,7 +3142,7 @@ metadump_f( return 0; } - while ((c = getopt(argc, argv, "aegm:ow")) != EOF) { + while ((c = getopt(argc, argv, "aegm:ov:w")) != EOF) { switch (c) { case 'a': metadump.zero_stale_data = 0; @@ -3164,6 +3166,15 @@ metadump_f( case 'o': metadump.obfuscate = 0; break; + case 'v': + metadump.version = (int)strtol(optarg, &p, 0); + if (*p != '\0' || (metadump.version != 1 && metadump.version != 2)) { + print_warning("bad metadump version: %s", + optarg); + return 0; + } + version_opt_set = true; + break; case 'w': metadump.show_warnings = 1; break; @@ -3178,6 +3189,9 @@ metadump_f( return 0; } + if (mp->m_logdev_targp != mp->m_ddev_targp && version_opt_set == false) + metadump.version = 2; + /* If we'll copy the log, see if the log is dirty */ if (mp->m_logdev_targp == mp->m_ddev_targp || metadump.version == 2) { log_type = TYP_LOG; From patchwork Tue May 23 09:00:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Babu R X-Patchwork-Id: 13251936 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EF04AC7EE26 for ; Tue, 23 May 2023 09:01:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236245AbjEWJBX (ORCPT ); Tue, 23 May 2023 05:01:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36040 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236264AbjEWJBU (ORCPT ); Tue, 23 May 2023 05:01:20 -0400 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9BCC8100 for ; Tue, 23 May 2023 02:01:19 -0700 (PDT) Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 34N6EAXx032748; Tue, 23 May 2023 09:01:17 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=corp-2023-03-30; bh=/UVOcU7V7ZRcDiy0xGb3XDmv/lxe0NxEU1WtBDKoKD0=; b=MpY30gvsCiUj1ImspXh3T7j2o5P3d9EnDpyi6vfFCKYK/pykVJm+23MX/DFAuqNVe8lG GNMkbWM047Pn2VOS+lzRtT/QXF7ckWM4272zhVRq5uO4LlDaUoQpoH+Jnx6cpjq4rjvz Y30BEsphYluBFU7mYMYxoYz9g6v6iVkuEGe5zsJ8DJcqXi4mpamsDG1CUpuTVKKa9TRk hKWK7JQ+W2lkXIuLyW/8ZHm5DTusX+Pbf3miFdx/exxzP0nByhFvMg2ZUEfPkDslsSgP fG6+1b6iRcAzRPoBiCxfMpbbocu/y2e1jI5UAxVAQW3Kg46GsjGzCX2NlWT4r5aSPfNX zw== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3qpp44mjhm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 23 May 2023 09:01:16 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 34N8ZZVw029026; Tue, 23 May 2023 09:01:15 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3qqk2aj7kv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 23 May 2023 09:01:15 +0000 Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 34N8xwrp007681; Tue, 23 May 2023 09:01:15 GMT Received: from chanbabu-fstest.osdevelopmeniad.oraclevcn.com (chanbabu-fstesting.allregionaliads.osdevelopmeniad.oraclevcn.com [100.100.250.50]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3qqk2aj76a-15; Tue, 23 May 2023 09:01:15 +0000 From: Chandan Babu R To: cem@kernel.org Cc: Chandan Babu R , linux-xfs@vger.kernel.org Subject: [PATCH 14/24] xfs_metadump.sh: Add support for passing version option Date: Tue, 23 May 2023 14:30:40 +0530 Message-Id: <20230523090050.373545-15-chandan.babu@oracle.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230523090050.373545-1-chandan.babu@oracle.com> References: <20230523090050.373545-1-chandan.babu@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.573,FMLib:17.11.176.26 definitions=2023-05-23_05,2023-05-22_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 mlxscore=0 mlxlogscore=860 phishscore=0 bulkscore=0 suspectscore=0 adultscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2304280000 definitions=main-2305230074 X-Proofpoint-GUID: nAWi5XYX68XNbxX4kwgA8RuZFaFYq7Eh X-Proofpoint-ORIG-GUID: nAWi5XYX68XNbxX4kwgA8RuZFaFYq7Eh Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org The new option allows the user to explicitly specify which version of metadump to use. However, we will default to using the v1 format. --- db/xfs_metadump.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/db/xfs_metadump.sh b/db/xfs_metadump.sh index 9852a5bc2..9e8f86e53 100755 --- a/db/xfs_metadump.sh +++ b/db/xfs_metadump.sh @@ -8,7 +8,7 @@ OPTS=" " DBOPTS=" " USAGE="Usage: xfs_metadump [-aefFogwV] [-m max_extents] [-l logdev] source target" -while getopts "aefgl:m:owFV" c +while getopts "aefgl:m:owFv:V" c do case $c in a) OPTS=$OPTS"-a ";; @@ -20,6 +20,7 @@ do f) DBOPTS=$DBOPTS" -f";; l) DBOPTS=$DBOPTS" -l "$OPTARG" ";; F) DBOPTS=$DBOPTS" -F";; + v) OPTS=$OPTS"-v "$OPTARG" ";; V) xfs_db -p xfs_metadump -V status=$? exit $status From patchwork Tue May 23 09:00:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Babu R X-Patchwork-Id: 13251937 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CF28BC7EE23 for ; Tue, 23 May 2023 09:01:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236264AbjEWJBY (ORCPT ); Tue, 23 May 2023 05:01:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36042 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236241AbjEWJBU (ORCPT ); Tue, 23 May 2023 05:01:20 -0400 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AAF2D109 for ; Tue, 23 May 2023 02:01:19 -0700 (PDT) Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 34N6Emb3031422; Tue, 23 May 2023 09:01:17 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=corp-2023-03-30; bh=E3kt5PJ/E5m7tyz+3l8qR0zaYihD6MltzUPUtcZ3kGs=; b=y0bNaqvptAQ/REqDgQrCodUQ3ZpWIljfJOdd5kdtGYKLYx9AF9Je0IdQtfueVeMofQC+ wURn/mwW3XAYurY24dBLqTxfUsJvcZmljt/9TZbYndXeRKQap+cnKeuDIJElQnXuG3fI Oh+zkcMmZm+P29hX+/QltzW/AVWUTUIDJw+G8wqTgIWw+ygwQIhvZjOwTDEs6dtHAVBp PILMBk31wCMaUip9Q67XP7EdfrLtTedCE3wZhc2jO+GOIPsNlSNdJeXkNGFu14OvKsx6 Xad6WNlAx4r0Zc6zY8+OQEs8+Kpg0K2TD7inKwqoirwHamRFLbjOn63DFVyMRll8Fy9/ Tg== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3qpp3mmn3t-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 23 May 2023 09:01:17 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 34N8Yj96029074; Tue, 23 May 2023 09:01:16 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3qqk2aj7mh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 23 May 2023 09:01:16 +0000 Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 34N8xwrr007681; Tue, 23 May 2023 09:01:16 GMT Received: from chanbabu-fstest.osdevelopmeniad.oraclevcn.com (chanbabu-fstesting.allregionaliads.osdevelopmeniad.oraclevcn.com [100.100.250.50]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3qqk2aj76a-16; Tue, 23 May 2023 09:01:16 +0000 From: Chandan Babu R To: cem@kernel.org Cc: Chandan Babu R , linux-xfs@vger.kernel.org Subject: [PATCH 15/24] xfs_metadump.8: Add description for the newly introduced -v option Date: Tue, 23 May 2023 14:30:41 +0530 Message-Id: <20230523090050.373545-16-chandan.babu@oracle.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230523090050.373545-1-chandan.babu@oracle.com> References: <20230523090050.373545-1-chandan.babu@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.573,FMLib:17.11.176.26 definitions=2023-05-23_05,2023-05-22_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 mlxscore=0 mlxlogscore=999 phishscore=0 bulkscore=0 suspectscore=0 adultscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2304280000 definitions=main-2305230074 X-Proofpoint-ORIG-GUID: LqehGBj-8i9prZTgm4rS31IOHIhydtDI X-Proofpoint-GUID: LqehGBj-8i9prZTgm4rS31IOHIhydtDI Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org Signed-off-by: Chandan Babu R --- man/man8/xfs_metadump.8 | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/man/man8/xfs_metadump.8 b/man/man8/xfs_metadump.8 index c0e79d779..23695c768 100644 --- a/man/man8/xfs_metadump.8 +++ b/man/man8/xfs_metadump.8 @@ -11,6 +11,9 @@ xfs_metadump \- copy XFS filesystem metadata to a file ] [ .B \-l .I logdev +] [ +.B \-v +.I version ] .I source .I target @@ -74,6 +77,9 @@ metadata such as filenames is not considered sensitive. If obfuscation is required on a metadump with a dirty log, please inform the recipient of the metadump image about this situation. .PP +The contents of an external log device can be dumped only when using the v2 +format. Metadump in v2 format can be generated by passing the "-v 2" option. +.PP .B xfs_metadump should not be used for any purposes other than for debugging and reporting filesystem problems. The most common usage scenario for this tool is when @@ -134,6 +140,10 @@ this value. The default size is 2097151 blocks. .B \-o Disables obfuscation of file names and extended attributes. .TP +.B \-v +The format of the metadump file to be produced. Valid values are 1 and 2. The +default metadump format is 1. +.TP .B \-w Prints warnings of inconsistent metadata encountered to stderr. Bad metadata is still copied. From patchwork Tue May 23 09:00:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Babu R X-Patchwork-Id: 13251938 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D57AFC7EE2A for ; Tue, 23 May 2023 09:01:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236277AbjEWJBZ (ORCPT ); Tue, 23 May 2023 05:01:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36046 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236274AbjEWJBU (ORCPT ); Tue, 23 May 2023 05:01:20 -0400 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1C198102 for ; Tue, 23 May 2023 02:01:20 -0700 (PDT) Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 34N6Ekg1000590; Tue, 23 May 2023 09:01:18 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=corp-2023-03-30; bh=UsDYO47QK9Kg7k9t55ama0/d3Ve0h35bjE6jzwved5Y=; b=lUNpP+yZSh5Ms6CGSYTOFVsFIDLORFdb4SXO6qKZy5GkSFIgLE4LTe0ZXutYLGtoK7In 632LD1fCK4gZoo9NWcD0vi8Je/+8gSxZH63qJ5TLiStE8xE8k0/pfztxUH5Tg0RCMakk H6aWwVKIlfzPjWSv8mUFo3PU1EVDoXFQUcGL19ufzuTArv0+bffBmKhVP1wQRp6zjoWl Ic+tR9+mwISXr/4jBVMnwBGHQEmp9CPP0x0mM+UAY0AHve09a2/8RxAI5mCdra4CT+1h Nlh56H0pbxzWZYo6SlMieGTfiyIjOsbbRQ9Agf4Z/HUDVfberKF+4JUT9x3ESaQ6tCQW sw== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3qpprtmku4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 23 May 2023 09:01:18 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 34N8dwGD029050; Tue, 23 May 2023 09:01:17 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3qqk2aj7n8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 23 May 2023 09:01:17 +0000 Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 34N8xwrt007681; Tue, 23 May 2023 09:01:17 GMT Received: from chanbabu-fstest.osdevelopmeniad.oraclevcn.com (chanbabu-fstesting.allregionaliads.osdevelopmeniad.oraclevcn.com [100.100.250.50]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3qqk2aj76a-17; Tue, 23 May 2023 09:01:16 +0000 From: Chandan Babu R To: cem@kernel.org Cc: Chandan Babu R , linux-xfs@vger.kernel.org Subject: [PATCH 16/24] mdrestore: Define and use struct mdrestore Date: Tue, 23 May 2023 14:30:42 +0530 Message-Id: <20230523090050.373545-17-chandan.babu@oracle.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230523090050.373545-1-chandan.babu@oracle.com> References: <20230523090050.373545-1-chandan.babu@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.573,FMLib:17.11.176.26 definitions=2023-05-23_05,2023-05-22_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 mlxscore=0 mlxlogscore=999 phishscore=0 bulkscore=0 suspectscore=0 adultscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2304280000 definitions=main-2305230074 X-Proofpoint-GUID: IgqKqv7KAyjbfXPxrOUH6kI4cCpaSZc8 X-Proofpoint-ORIG-GUID: IgqKqv7KAyjbfXPxrOUH6kI4cCpaSZc8 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org This commit collects all state tracking variables in a new "struct mdrestore" structure. Signed-off-by: Chandan Babu R --- mdrestore/xfs_mdrestore.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/mdrestore/xfs_mdrestore.c b/mdrestore/xfs_mdrestore.c index 481dd00c2..de9175a08 100644 --- a/mdrestore/xfs_mdrestore.c +++ b/mdrestore/xfs_mdrestore.c @@ -7,9 +7,11 @@ #include "libxfs.h" #include "xfs_metadump.h" -static int show_progress = 0; -static int show_info = 0; -static int progress_since_warning = 0; +static struct mdrestore { + int show_progress; + int show_info; + int progress_since_warning; +} mdrestore; static void fatal(const char *msg, ...) @@ -35,7 +37,7 @@ print_progress(const char *fmt, ...) printf("\r%-59s", buf); fflush(stdout); - progress_since_warning = 1; + mdrestore.progress_since_warning = 1; } /* @@ -127,7 +129,8 @@ perform_restore( bytes_read = 0; for (;;) { - if (show_progress && (bytes_read & ((1 << 20) - 1)) == 0) + if (mdrestore.show_progress && + (bytes_read & ((1 << 20) - 1)) == 0) print_progress("%lld MB read", bytes_read >> 20); for (cur_index = 0; cur_index < mb_count; cur_index++) { @@ -158,7 +161,7 @@ perform_restore( bytes_read += block_size + (mb_count << mbp->mb_blocklog); } - if (progress_since_warning) + if (mdrestore.progress_since_warning) putchar('\n'); memset(block_buffer, 0, sb.sb_sectsize); @@ -197,15 +200,19 @@ main( int is_target_file; struct xfs_metablock mb; + mdrestore.show_progress = 0; + mdrestore.show_info = 0; + mdrestore.progress_since_warning = 0; + progname = basename(argv[0]); while ((c = getopt(argc, argv, "giV")) != EOF) { switch (c) { case 'g': - show_progress = 1; + mdrestore.show_progress = 1; break; case 'i': - show_info = 1; + mdrestore.show_info = 1; break; case 'V': printf("%s version %s\n", progname, VERSION); @@ -219,7 +226,7 @@ main( usage(); /* show_info without a target is ok */ - if (!show_info && argc - optind != 2) + if (!mdrestore.show_info && argc - optind != 2) usage(); /* @@ -243,7 +250,7 @@ main( if (mb.mb_magic != cpu_to_be32(XFS_MD_MAGIC_V1)) fatal("specified file is not a metadata dump\n"); - if (show_info) { + if (mdrestore.show_info) { if (mb.mb_info & XFS_METADUMP_INFO_FLAGS) { printf("%s: %sobfuscated, %s log, %s metadata blocks\n", argv[optind], From patchwork Tue May 23 09:00:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Babu R X-Patchwork-Id: 13251941 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8AB5CC7EE29 for ; Tue, 23 May 2023 09:01:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236284AbjEWJB1 (ORCPT ); Tue, 23 May 2023 05:01:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36074 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236276AbjEWJBY (ORCPT ); Tue, 23 May 2023 05:01:24 -0400 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7ED09100 for ; Tue, 23 May 2023 02:01:22 -0700 (PDT) Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 34N6F2r7000880; Tue, 23 May 2023 09:01:19 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=corp-2023-03-30; bh=1SvyFrvXMkutq3oTOiS4kl3JHWz6LSpseg8obJbTAyg=; b=V1Ez4uivoG4z4UPJXrsAlxDLBPpwmgb/KqTXtd2MEw82fQVmlwdKZYp9PxoU0yx7EzoB Mxhc/9D+UzehKr69gSVf3w07huWUtTflpl9pdlp3i38ZWYP7fxhBsKt05fa9PP671jX4 hezbRJWkhvgHDmqVzS3Moz5CBWVYcAJF0Z4HFMyIOuysDgNcv2XQwBcDEKWJwNOYfGC8 n5201KW7wWc+KsYtk8eUz6S34Sf2HFTwWy4pxso2HQpCnFzm7USoo5tCnOPsobqx6I2w E7Xfgs1UDfDk+XQcflOunZ6YWNENsi255y9wZELNYod+CB8DKFOGwbBa8C6MTd7v0jkI 1A== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3qpprtmku6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 23 May 2023 09:01:18 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 34N8rh3N028933; Tue, 23 May 2023 09:01:18 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3qqk2aj7p1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 23 May 2023 09:01:18 +0000 Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 34N8xwrv007681; Tue, 23 May 2023 09:01:17 GMT Received: from chanbabu-fstest.osdevelopmeniad.oraclevcn.com (chanbabu-fstesting.allregionaliads.osdevelopmeniad.oraclevcn.com [100.100.250.50]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3qqk2aj76a-18; Tue, 23 May 2023 09:01:17 +0000 From: Chandan Babu R To: cem@kernel.org Cc: Chandan Babu R , linux-xfs@vger.kernel.org Subject: [PATCH 17/24] mdrestore: Add open_device(), read_header() and show_info() functions Date: Tue, 23 May 2023 14:30:43 +0530 Message-Id: <20230523090050.373545-18-chandan.babu@oracle.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230523090050.373545-1-chandan.babu@oracle.com> References: <20230523090050.373545-1-chandan.babu@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.573,FMLib:17.11.176.26 definitions=2023-05-23_05,2023-05-22_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 mlxscore=0 mlxlogscore=999 phishscore=0 bulkscore=0 suspectscore=0 adultscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2304280000 definitions=main-2305230074 X-Proofpoint-GUID: EBsJ8mQ-VKiAT95LJjtUNRbtUIC9iTiq X-Proofpoint-ORIG-GUID: EBsJ8mQ-VKiAT95LJjtUNRbtUIC9iTiq Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org This commit moves functionality associated with opening the target device, reading metadump header information and printing information about the metadump into their respective functions. Signed-off-by: Chandan Babu R --- mdrestore/xfs_mdrestore.c | 114 +++++++++++++++++++++++--------------- 1 file changed, 68 insertions(+), 46 deletions(-) diff --git a/mdrestore/xfs_mdrestore.c b/mdrestore/xfs_mdrestore.c index de9175a08..8c847c5a3 100644 --- a/mdrestore/xfs_mdrestore.c +++ b/mdrestore/xfs_mdrestore.c @@ -40,8 +40,67 @@ print_progress(const char *fmt, ...) mdrestore.progress_since_warning = 1; } +extern int platform_check_ismounted(char *, char *, struct stat *, int); + +static int +open_device( + char *path, + bool *is_file) +{ + struct stat statbuf; + int open_flags; + int fd; + + open_flags = O_RDWR; + *is_file = false; + + if (stat(path, &statbuf) < 0) { + /* ok, assume it's a file and create it */ + open_flags |= O_CREAT; + *is_file = true; + } else if (S_ISREG(statbuf.st_mode)) { + open_flags |= O_TRUNC; + *is_file = true; + } else { + /* + * check to make sure a filesystem isn't mounted on the device + */ + if (platform_check_ismounted(path, NULL, &statbuf, 0)) + fatal("a filesystem is mounted on target device \"%s\"," + " cannot restore to a mounted filesystem.\n", + path); + } + + fd = open(path, open_flags, 0644); + if (fd < 0) + fatal("couldn't open \"%s\"\n", path); + + return fd; +} + +static void read_header(struct xfs_metablock *mb, FILE *src_f) +{ + 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)) + fatal("specified file is not a metadata dump\n"); +} + +static void show_info(struct xfs_metablock *mb, const char *mdfile) +{ + if (mb->mb_info & XFS_METADUMP_INFO_FLAGS) { + printf("%s: %sobfuscated, %s log, %s metadata blocks\n", + mdfile, + mb->mb_info & XFS_METADUMP_OBFUSCATED ? "":"not ", + mb->mb_info & XFS_METADUMP_DIRTYLOG ? "dirty":"clean", + mb->mb_info & XFS_METADUMP_FULLBLOCKS ? "full":"zeroed"); + } else { + printf("%s: no informational flags present\n", mdfile); + } +} + /* - * perform_restore() -- do the actual work to restore the metadump + * restore() -- do the actual work to restore the metadump * * @src_f: A FILE pointer to the source metadump * @dst_fd: the file descriptor for the target file @@ -51,7 +110,7 @@ print_progress(const char *fmt, ...) * src_f should be positioned just past a read the previously validated metablock */ static void -perform_restore( +restore( FILE *src_f, int dst_fd, int is_target_file, @@ -185,8 +244,6 @@ usage(void) exit(1); } -extern int platform_check_ismounted(char *, char *, struct stat *, int); - int main( int argc, @@ -195,9 +252,7 @@ main( FILE *src_f; int dst_fd; int c; - int open_flags; - struct stat statbuf; - int is_target_file; + bool is_target_file; struct xfs_metablock mb; mdrestore.show_progress = 0; @@ -230,8 +285,8 @@ main( usage(); /* - * open source and test if this really is a dump. The first metadump block - * will be passed to perform_restore() which will continue to read the + * open source and test if this really is a dump. The first metadump + * block will be passed to restore() which will continue to read the * file from this point. This avoids rewind the stream, which causes * restore to fail when source was being read from stdin. */ @@ -245,22 +300,10 @@ 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)) - fatal("specified file is not a metadata dump\n"); + read_header(&mb, src_f); if (mdrestore.show_info) { - if (mb.mb_info & XFS_METADUMP_INFO_FLAGS) { - printf("%s: %sobfuscated, %s log, %s metadata blocks\n", - argv[optind], - mb.mb_info & XFS_METADUMP_OBFUSCATED ? "":"not ", - mb.mb_info & XFS_METADUMP_DIRTYLOG ? "dirty":"clean", - mb.mb_info & XFS_METADUMP_FULLBLOCKS ? "full":"zeroed"); - } else { - printf("%s: no informational flags present\n", - argv[optind]); - } + show_info(&mb, argv[optind]); if (argc - optind == 1) exit(0); @@ -269,30 +312,9 @@ main( optind++; /* check and open target */ - open_flags = O_RDWR; - is_target_file = 0; - if (stat(argv[optind], &statbuf) < 0) { - /* ok, assume it's a file and create it */ - open_flags |= O_CREAT; - is_target_file = 1; - } else if (S_ISREG(statbuf.st_mode)) { - open_flags |= O_TRUNC; - is_target_file = 1; - } else { - /* - * check to make sure a filesystem isn't mounted on the device - */ - if (platform_check_ismounted(argv[optind], NULL, &statbuf, 0)) - fatal("a filesystem is mounted on target device \"%s\"," - " cannot restore to a mounted filesystem.\n", - argv[optind]); - } - - dst_fd = open(argv[optind], open_flags, 0644); - if (dst_fd < 0) - fatal("couldn't open target \"%s\"\n", argv[optind]); + dst_fd = open_device(argv[optind], &is_target_file); - perform_restore(src_f, dst_fd, is_target_file, &mb); + restore(src_f, dst_fd, is_target_file, &mb); close(dst_fd); if (src_f != stdin) From patchwork Tue May 23 09:00:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Babu R X-Patchwork-Id: 13251939 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 93AEEC7EE26 for ; Tue, 23 May 2023 09:01:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236274AbjEWJB0 (ORCPT ); Tue, 23 May 2023 05:01:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36060 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236259AbjEWJBW (ORCPT ); Tue, 23 May 2023 05:01:22 -0400 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 347F5FF for ; Tue, 23 May 2023 02:01:22 -0700 (PDT) Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 34N6Emb4031422; Tue, 23 May 2023 09:01:20 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=corp-2023-03-30; bh=9umQXpUT71+kSXH7mck7+o/L2LiQCN5JiptwDu9MxJA=; b=MThOjPUwU+azY4gKmmp4AgbDViQr9kIcfo9JsZ7lX4PKr9kD7aYSk/p8FqUhR6x02XrY 8GhU6KFUbi4AO53FeXg8np+2QaFYGE+YAA/DJD4axSA3bQRxdD0f0hQq9VR+lWQ4VI4O NlnDNunVf5fdCNB3B4zaTPWYkA9Cfygx01WR6GCMLsrtCk6L6oWTDXGz7wL1gEbrescV i4Og846xZ+1xbneckjmLtAHJLZlFdNbL6gsFhex4z5hH2mJNVETyFOzQY7RqUvAEh3zb FYZZFepKRDOWQ/1Hau8ofZnlH90CwCn1m1pl3ECHJ+UCoBKis9SpNqxpXkrXUuY/CWLX Uw== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3qpp3mmn40-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 23 May 2023 09:01:19 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 34N8wvPD029361; Tue, 23 May 2023 09:01:19 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3qqk2aj7q5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 23 May 2023 09:01:19 +0000 Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 34N8xwrx007681; Tue, 23 May 2023 09:01:18 GMT Received: from chanbabu-fstest.osdevelopmeniad.oraclevcn.com (chanbabu-fstesting.allregionaliads.osdevelopmeniad.oraclevcn.com [100.100.250.50]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3qqk2aj76a-19; Tue, 23 May 2023 09:01:18 +0000 From: Chandan Babu R To: cem@kernel.org Cc: Chandan Babu R , linux-xfs@vger.kernel.org Subject: [PATCH 18/24] mdrestore: Introduce struct mdrestore_ops Date: Tue, 23 May 2023 14:30:44 +0530 Message-Id: <20230523090050.373545-19-chandan.babu@oracle.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230523090050.373545-1-chandan.babu@oracle.com> References: <20230523090050.373545-1-chandan.babu@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.573,FMLib:17.11.176.26 definitions=2023-05-23_05,2023-05-22_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 mlxscore=0 mlxlogscore=999 phishscore=0 bulkscore=0 suspectscore=0 adultscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2304280000 definitions=main-2305230074 X-Proofpoint-ORIG-GUID: Y8k6Usy0rSjlG43iUlT5AFEPLZ5sJ_5c X-Proofpoint-GUID: Y8k6Usy0rSjlG43iUlT5AFEPLZ5sJ_5c Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org We will need two sets of functions to work with two versions of metadump formats. This commit adds the definition for 'struct mdrestore_ops' to hold pointers to version specific mdrestore functions. Signed-off-by: Chandan Babu R Reviewed-by: Darrick J. Wong --- mdrestore/xfs_mdrestore.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/mdrestore/xfs_mdrestore.c b/mdrestore/xfs_mdrestore.c index 8c847c5a3..895e5cdab 100644 --- a/mdrestore/xfs_mdrestore.c +++ b/mdrestore/xfs_mdrestore.c @@ -7,10 +7,18 @@ #include "libxfs.h" #include "xfs_metadump.h" +struct mdrestore_ops { + void (*read_header)(void *header, FILE *mdfp); + void (*show_info)(void *header, const char *mdfile); + void (*restore)(void *header, FILE *mdfp, int data_fd, + bool is_target_file); +}; + static struct mdrestore { - int show_progress; - int show_info; - int progress_since_warning; + struct mdrestore_ops *mdrops; + int show_progress; + int show_info; + int progress_since_warning; } mdrestore; static void From patchwork Tue May 23 09:00:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Babu R X-Patchwork-Id: 13251942 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 21941C7EE26 for ; Tue, 23 May 2023 09:01:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236288AbjEWJB2 (ORCPT ); Tue, 23 May 2023 05:01:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36090 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236241AbjEWJBZ (ORCPT ); Tue, 23 May 2023 05:01:25 -0400 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E0ED7109 for ; Tue, 23 May 2023 02:01:23 -0700 (PDT) Received: from pps.filterd (m0333521.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 34N6ElTZ032489; Tue, 23 May 2023 09:01:21 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=corp-2023-03-30; bh=pytTGB1l4OFgcfUHTFl2Nyv1AwW4714yCeUjB6vtviE=; b=Yraxi2UUHZfJ0PleitWmcBruCI6V13SJbV2NbTaVubgtHat4ymvd4EG/Pfv0BS5MieiK q3xdhvcuqVVIKir4Rk2lI3bVStzzQToVSm/Zh6udTeHp+EIopAQqGk1EdfyB6WpMFR7V e0noSqU2UBhagr3WtzjVJg9jd0SoGu0f1C/ACrQNXojMjn2T1W5+hXFs0GNn/K1EW1tG alhvzG3PprajPiJYgZssnUmqTqM+ovnZsQ2pWJx5HBZ0hnQ0gPfTK0Ds/DYkgztNZJ1L bdBJo0lvrLdT4t5iT8cOr//E7xS10PS3V7tnKX1WuBwR6cwpz59DGWMFmgDa6EWN1juP qQ== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3qpp5bmmdm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 23 May 2023 09:01:20 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 34N6oEtL028934; Tue, 23 May 2023 09:01:20 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3qqk2aj7r7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 23 May 2023 09:01:20 +0000 Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 34N8xws1007681; Tue, 23 May 2023 09:01:19 GMT Received: from chanbabu-fstest.osdevelopmeniad.oraclevcn.com (chanbabu-fstesting.allregionaliads.osdevelopmeniad.oraclevcn.com [100.100.250.50]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3qqk2aj76a-20; Tue, 23 May 2023 09:01:19 +0000 From: Chandan Babu R To: cem@kernel.org Cc: Chandan Babu R , linux-xfs@vger.kernel.org Subject: [PATCH 19/24] mdrestore: Introduce mdrestore v1 operations Date: Tue, 23 May 2023 14:30:45 +0530 Message-Id: <20230523090050.373545-20-chandan.babu@oracle.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230523090050.373545-1-chandan.babu@oracle.com> References: <20230523090050.373545-1-chandan.babu@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.573,FMLib:17.11.176.26 definitions=2023-05-23_05,2023-05-22_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 mlxscore=0 mlxlogscore=999 phishscore=0 bulkscore=0 suspectscore=0 adultscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2304280000 definitions=main-2305230074 X-Proofpoint-GUID: Eq7iB3DqkUGr4GqEnJtGkM-D_u87_Olc X-Proofpoint-ORIG-GUID: Eq7iB3DqkUGr4GqEnJtGkM-D_u87_Olc Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org In order to indicate the version of metadump files that they can work with, this commit renames read_header(), show_info() and restore() functions to read_header_v1(), show_info_v1() and restore_v1() respectively. Signed-off-by: Chandan Babu R --- mdrestore/xfs_mdrestore.c | 76 ++++++++++++++++++++++----------------- 1 file changed, 43 insertions(+), 33 deletions(-) diff --git a/mdrestore/xfs_mdrestore.c b/mdrestore/xfs_mdrestore.c index 895e5cdab..5ec1a47b0 100644 --- a/mdrestore/xfs_mdrestore.c +++ b/mdrestore/xfs_mdrestore.c @@ -86,16 +86,26 @@ open_device( return fd; } -static void read_header(struct xfs_metablock *mb, FILE *src_f) +static void +read_header_v1( + void *header, + FILE *mdfp) { - if (fread(mb, sizeof(*mb), 1, src_f) != 1) + struct xfs_metablock *mb = header; + + if (fread(mb, sizeof(*mb), 1, mdfp) != 1) fatal("error reading from metadump file\n"); if (mb->mb_magic != cpu_to_be32(XFS_MD_MAGIC_V1)) fatal("specified file is not a metadata dump\n"); } -static void show_info(struct xfs_metablock *mb, const char *mdfile) +static void +show_info_v1( + void *header, + const char *mdfile) { + struct xfs_metablock *mb = header; + if (mb->mb_info & XFS_METADUMP_INFO_FLAGS) { printf("%s: %sobfuscated, %s log, %s metadata blocks\n", mdfile, @@ -107,24 +117,15 @@ static void show_info(struct xfs_metablock *mb, const char *mdfile) } } -/* - * restore() -- do the actual work to restore the metadump - * - * @src_f: A FILE pointer to the source metadump - * @dst_fd: the file descriptor for the target file - * @is_target_file: designates whether the target is a regular file - * @mbp: pointer to metadump's first xfs_metablock, read and verified by the caller - * - * src_f should be positioned just past a read the previously validated metablock - */ static void -restore( - FILE *src_f, - int dst_fd, - int is_target_file, - const struct xfs_metablock *mbp) +restore_v1( + void *header, + FILE *mdfp, + int data_fd, + bool is_target_file) { - struct xfs_metablock *metablock; /* header + index + blocks */ + struct xfs_metablock *mbp = header; + struct xfs_metablock *metablock; __be64 *block_index; char *block_buffer; int block_size; @@ -148,14 +149,15 @@ restore( block_index = (__be64 *)((char *)metablock + sizeof(xfs_metablock_t)); block_buffer = (char *)metablock + block_size; - if (fread(block_index, block_size - sizeof(struct xfs_metablock), 1, src_f) != 1) + if (fread(block_index, block_size - sizeof(struct xfs_metablock), 1, + mdfp) != 1) fatal("error reading from metadump file\n"); if (block_index[0] != 0) fatal("first block is not the primary superblock\n"); - if (fread(block_buffer, mb_count << mbp->mb_blocklog, 1, src_f) != 1) + if (fread(block_buffer, mb_count << mbp->mb_blocklog, 1, mdfp) != 1) fatal("error reading from metadump file\n"); libxfs_sb_from_disk(&sb, (struct xfs_dsb *)block_buffer); @@ -178,7 +180,7 @@ restore( if (is_target_file) { /* ensure regular files are correctly sized */ - if (ftruncate(dst_fd, sb.sb_dblocks * sb.sb_blocksize)) + if (ftruncate(data_fd, sb.sb_dblocks * sb.sb_blocksize)) fatal("cannot set filesystem image size: %s\n", strerror(errno)); } else { @@ -188,7 +190,7 @@ restore( off64_t off; off = sb.sb_dblocks * sb.sb_blocksize - sizeof(lb); - if (pwrite(dst_fd, lb, sizeof(lb), off) < 0) + if (pwrite(data_fd, lb, sizeof(lb), off) < 0) fatal("failed to write last block, is target too " "small? (error: %s)\n", strerror(errno)); } @@ -201,7 +203,7 @@ restore( print_progress("%lld MB read", bytes_read >> 20); for (cur_index = 0; cur_index < mb_count; cur_index++) { - if (pwrite(dst_fd, &block_buffer[cur_index << + if (pwrite(data_fd, &block_buffer[cur_index << mbp->mb_blocklog], block_size, be64_to_cpu(block_index[cur_index]) << BBSHIFT) < 0) @@ -212,7 +214,7 @@ restore( if (mb_count < max_indices) break; - if (fread(metablock, block_size, 1, src_f) != 1) + if (fread(metablock, block_size, 1, mdfp) != 1) fatal("error reading from metadump file\n"); mb_count = be16_to_cpu(metablock->mb_count); @@ -222,7 +224,7 @@ restore( fatal("bad block count: %u\n", mb_count); if (fread(block_buffer, mb_count << mbp->mb_blocklog, - 1, src_f) != 1) + 1, mdfp) != 1) fatal("error reading from metadump file\n"); bytes_read += block_size + (mb_count << mbp->mb_blocklog); @@ -239,12 +241,18 @@ restore( offsetof(struct xfs_sb, sb_crc)); } - if (pwrite(dst_fd, block_buffer, sb.sb_sectsize, 0) < 0) + if (pwrite(data_fd, block_buffer, sb.sb_sectsize, 0) < 0) fatal("error writing primary superblock: %s\n", strerror(errno)); free(metablock); } +static struct mdrestore_ops mdrestore_ops_v1 = { + .read_header = read_header_v1, + .show_info = show_info_v1, + .restore = restore_v1, +}; + static void usage(void) { @@ -294,9 +302,9 @@ main( /* * open source and test if this really is a dump. The first metadump - * block will be passed to restore() which will continue to read the - * file from this point. This avoids rewind the stream, which causes - * restore to fail when source was being read from stdin. + * block will be passed to mdrestore_ops->restore() which will continue + * to read the file from this point. This avoids rewind the stream, + * which causes restore to fail when source was being read from stdin. */ if (strcmp(argv[optind], "-") == 0) { src_f = stdin; @@ -308,10 +316,12 @@ main( fatal("cannot open source dump file\n"); } - read_header(&mb, src_f); + mdrestore.mdrops = &mdrestore_ops_v1; + + mdrestore.mdrops->read_header(&mb, src_f); if (mdrestore.show_info) { - show_info(&mb, argv[optind]); + mdrestore.mdrops->show_info(&mb, argv[optind]); if (argc - optind == 1) exit(0); @@ -322,7 +332,7 @@ main( /* check and open target */ dst_fd = open_device(argv[optind], &is_target_file); - restore(src_f, dst_fd, is_target_file, &mb); + mdrestore.mdrops->restore(&mb, src_f, dst_fd, is_target_file); close(dst_fd); if (src_f != stdin) From patchwork Tue May 23 09:00:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Babu R X-Patchwork-Id: 13251940 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 19D8BC7EE23 for ; Tue, 23 May 2023 09:01:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236259AbjEWJB1 (ORCPT ); Tue, 23 May 2023 05:01:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36080 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236284AbjEWJBY (ORCPT ); Tue, 23 May 2023 05:01:24 -0400 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9E146FF for ; Tue, 23 May 2023 02:01:23 -0700 (PDT) Received: from pps.filterd (m0333521.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 34N6Ef9X032465; Tue, 23 May 2023 09:01:21 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=corp-2023-03-30; bh=vVYfWCBntFnE2W/QIo75dbdfeZ0DEBLjOePuT1zGYjA=; b=ZJWITo2NeHkPtv2Xp1Qbrylpq/gA1XaGAt0eCzQ2jQuU/si7MpBtKZuHwSxGwnZro3GR gODPnFK9r4yTaoPWK+TMLJonv85AdnyRrwXRD0LtlVZpCkR27wZelHBaz1PxhLYrXaNt 8NzUD1Jzcl1R705iBc5FL3HgMEnwq0SNuQg6Zuyz8ThFZrGSIAsfDbz9cW3FWodJ1yLJ II7GDMeMVIZjG5ddy2lLLqygdBeGjuIkkku4yb4xmPVJZ2mCdf/QjPOe5wwi/xpVi5Os XTJlNVbgwUEA7lKap0PPFvU4UnDkRMPdleGACLer7nVGYUNCrS3zZYcT9k06aYkw5f4z vQ== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3qpp5bmmdp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 23 May 2023 09:01:21 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 34N8rh3S028933; Tue, 23 May 2023 09:01:21 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3qqk2aj7s8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 23 May 2023 09:01:21 +0000 Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 34N8xws3007681; Tue, 23 May 2023 09:01:20 GMT Received: from chanbabu-fstest.osdevelopmeniad.oraclevcn.com (chanbabu-fstesting.allregionaliads.osdevelopmeniad.oraclevcn.com [100.100.250.50]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3qqk2aj76a-21; Tue, 23 May 2023 09:01:20 +0000 From: Chandan Babu R To: cem@kernel.org Cc: Chandan Babu R , linux-xfs@vger.kernel.org Subject: [PATCH 20/24] mdrestore: Detect metadump version from metadump image Date: Tue, 23 May 2023 14:30:46 +0530 Message-Id: <20230523090050.373545-21-chandan.babu@oracle.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230523090050.373545-1-chandan.babu@oracle.com> References: <20230523090050.373545-1-chandan.babu@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.573,FMLib:17.11.176.26 definitions=2023-05-23_05,2023-05-22_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 mlxscore=0 mlxlogscore=999 phishscore=0 bulkscore=0 suspectscore=0 adultscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2304280000 definitions=main-2305230074 X-Proofpoint-GUID: Q9dLgGKxEbO6_bZuzZU7zBI_RHyGklBc X-Proofpoint-ORIG-GUID: Q9dLgGKxEbO6_bZuzZU7zBI_RHyGklBc Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org Signed-off-by: Chandan Babu R --- mdrestore/xfs_mdrestore.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/mdrestore/xfs_mdrestore.c b/mdrestore/xfs_mdrestore.c index 5ec1a47b0..52081a6ca 100644 --- a/mdrestore/xfs_mdrestore.c +++ b/mdrestore/xfs_mdrestore.c @@ -8,7 +8,7 @@ #include "xfs_metadump.h" struct mdrestore_ops { - void (*read_header)(void *header, FILE *mdfp); + int (*read_header)(void *header, FILE *mdfp); void (*show_info)(void *header, const char *mdfile); void (*restore)(void *header, FILE *mdfp, int data_fd, bool is_target_file); @@ -86,7 +86,7 @@ open_device( return fd; } -static void +static int read_header_v1( void *header, FILE *mdfp) @@ -96,7 +96,9 @@ read_header_v1( if (fread(mb, sizeof(*mb), 1, mdfp) != 1) fatal("error reading from metadump file\n"); if (mb->mb_magic != cpu_to_be32(XFS_MD_MAGIC_V1)) - fatal("specified file is not a metadata dump\n"); + return -1; + + return 0; } static void @@ -316,9 +318,10 @@ main( fatal("cannot open source dump file\n"); } - mdrestore.mdrops = &mdrestore_ops_v1; - - mdrestore.mdrops->read_header(&mb, src_f); + if (mdrestore_ops_v1.read_header(&mb, src_f) == 0) + mdrestore.mdrops = &mdrestore_ops_v1; + else + fatal("Invalid metadump format\n"); if (mdrestore.show_info) { mdrestore.mdrops->show_info(&mb, argv[optind]); From patchwork Tue May 23 09:00:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Babu R X-Patchwork-Id: 13251943 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 38613C7EE29 for ; Tue, 23 May 2023 09:01:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236241AbjEWJBa (ORCPT ); Tue, 23 May 2023 05:01:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36092 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236286AbjEWJBZ (ORCPT ); Tue, 23 May 2023 05:01:25 -0400 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A3114102 for ; Tue, 23 May 2023 02:01:24 -0700 (PDT) Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 34N6EgoW000558; Tue, 23 May 2023 09:01:23 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=corp-2023-03-30; bh=SnThpmzanunCluFeNjqPbhi17uDttUC74+5qoCJDqAI=; b=ekjxO6/bzooqm8AXWpuAFJnHnR4Ibvw0O1idwUDJkN+2hFhH4g63WWIBS/M71LU8jjH/ tpWbiNnd+T3wibD+pOVW0mhfBqa5QL3smCAPCFDyBiZnepAYcS4ouXa9bCYalPg0EdZB fojs1MGR0EJVrYMw1We9Rl+X5UVu8uBM2bOZfw9wwE0AWTGYOGiB32PZuT2fMGVxvRYV erX2a1B9aD49nU9mOXb0Y5mTvhs7NJOEL7ojqCs6ts1b9eeQA+YPSKBMu5aL+PUZ/m/u eArIuCFFH/Doodld90T0iLBqobk6zQBV8eFAEtwkNepuEiGOkwL9QzFPwjVGNUsrATCU OQ== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3qpprtmkug-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 23 May 2023 09:01:22 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 34N8KSVQ029007; Tue, 23 May 2023 09:01:22 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3qqk2aj7t6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 23 May 2023 09:01:22 +0000 Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 34N8xws5007681; Tue, 23 May 2023 09:01:21 GMT Received: from chanbabu-fstest.osdevelopmeniad.oraclevcn.com (chanbabu-fstesting.allregionaliads.osdevelopmeniad.oraclevcn.com [100.100.250.50]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3qqk2aj76a-22; Tue, 23 May 2023 09:01:21 +0000 From: Chandan Babu R To: cem@kernel.org Cc: Chandan Babu R , linux-xfs@vger.kernel.org Subject: [PATCH 21/24] mdrestore: Extract target device size verification into a function Date: Tue, 23 May 2023 14:30:47 +0530 Message-Id: <20230523090050.373545-22-chandan.babu@oracle.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230523090050.373545-1-chandan.babu@oracle.com> References: <20230523090050.373545-1-chandan.babu@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.573,FMLib:17.11.176.26 definitions=2023-05-23_05,2023-05-22_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 mlxscore=0 mlxlogscore=999 phishscore=0 bulkscore=0 suspectscore=0 adultscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2304280000 definitions=main-2305230074 X-Proofpoint-GUID: 4DbyqoIK9n4aD9N0LS8Rgk3cbMIFFVx5 X-Proofpoint-ORIG-GUID: 4DbyqoIK9n4aD9N0LS8Rgk3cbMIFFVx5 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org Signed-off-by: Chandan Babu R Reviewed-by: Darrick J. Wong --- mdrestore/xfs_mdrestore.c | 43 +++++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/mdrestore/xfs_mdrestore.c b/mdrestore/xfs_mdrestore.c index 52081a6ca..615ecdc77 100644 --- a/mdrestore/xfs_mdrestore.c +++ b/mdrestore/xfs_mdrestore.c @@ -86,6 +86,30 @@ open_device( return fd; } +static void +verify_device_size( + int dev_fd, + bool is_file, + xfs_rfsblock_t nr_blocks, + uint32_t blocksize) +{ + if (is_file) { + /* ensure regular files are correctly sized */ + if (ftruncate(dev_fd, nr_blocks * blocksize)) + fatal("cannot set filesystem image size: %s\n", + strerror(errno)); + } else { + /* ensure device is sufficiently large enough */ + char lb[XFS_MAX_SECTORSIZE] = { 0 }; + off64_t off; + + off = nr_blocks * blocksize - sizeof(lb); + if (pwrite(dev_fd, lb, sizeof(lb), off) < 0) + fatal("failed to write last block, is target too " + "small? (error: %s)\n", strerror(errno)); + } +} + static int read_header_v1( void *header, @@ -179,23 +203,8 @@ restore_v1( ((struct xfs_dsb*)block_buffer)->sb_inprogress = 1; - if (is_target_file) { - /* ensure regular files are correctly sized */ - - if (ftruncate(data_fd, sb.sb_dblocks * sb.sb_blocksize)) - fatal("cannot set filesystem image size: %s\n", - strerror(errno)); - } else { - /* ensure device is sufficiently large enough */ - - char lb[XFS_MAX_SECTORSIZE] = { 0 }; - off64_t off; - - off = sb.sb_dblocks * sb.sb_blocksize - sizeof(lb); - if (pwrite(data_fd, lb, sizeof(lb), off) < 0) - fatal("failed to write last block, is target too " - "small? (error: %s)\n", strerror(errno)); - } + verify_device_size(data_fd, is_target_file, sb.sb_dblocks, + sb.sb_blocksize); bytes_read = 0; From patchwork Tue May 23 09:00:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Babu R X-Patchwork-Id: 13251946 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 58CE3C7EE2A for ; Tue, 23 May 2023 09:01:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236276AbjEWJBd (ORCPT ); Tue, 23 May 2023 05:01:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36122 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236289AbjEWJB2 (ORCPT ); Tue, 23 May 2023 05:01:28 -0400 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 776ED100 for ; Tue, 23 May 2023 02:01:26 -0700 (PDT) Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 34N6EdCP031370; Tue, 23 May 2023 09:01:23 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=corp-2023-03-30; bh=yGeEcD3s5TZmhmVzU4PTOjtr4di0yDyS1F6FHEviNm4=; b=PJ30Anh4ovPXinTxDgbtXEQKcWIk9EHNEjVyBCWwzCeUbFThJvYVbekFvK4yuYeApQEp fX3GExpV2oRQN/qtsk7i1WJLdGzcmHA/zeW3JIYNEVGOTHMxJaAJuFKZeAa4FkOM4LQQ ZnciQCpVB9G4MBSTdW7tfKcTDez4aZYr5BqLvZt+H9fF5Hd4Jp32dPVDYxUmG4O1E2QE gLbE5sdOUZZrpoeZcOrzRKuoTu4vsvYj+RTmqDDz7Gwa9L6YBLfoIqMXG81BhR3EiLTt 9bX7N8/1ATZKco3BCCW+JLYjFowCy/W4lnoBhOlGgBaoAyjpNjQaBsQh5NV6yJXATbZk 6Q== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3qpp3mmn4d-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 23 May 2023 09:01:23 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 34N71J16029055; Tue, 23 May 2023 09:01:22 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3qqk2aj7u0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 23 May 2023 09:01:22 +0000 Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 34N8xws7007681; Tue, 23 May 2023 09:01:22 GMT Received: from chanbabu-fstest.osdevelopmeniad.oraclevcn.com (chanbabu-fstesting.allregionaliads.osdevelopmeniad.oraclevcn.com [100.100.250.50]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3qqk2aj76a-23; Tue, 23 May 2023 09:01:22 +0000 From: Chandan Babu R To: cem@kernel.org Cc: Chandan Babu R , linux-xfs@vger.kernel.org Subject: [PATCH 22/24] mdrestore: Define mdrestore ops for v2 format Date: Tue, 23 May 2023 14:30:48 +0530 Message-Id: <20230523090050.373545-23-chandan.babu@oracle.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230523090050.373545-1-chandan.babu@oracle.com> References: <20230523090050.373545-1-chandan.babu@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.573,FMLib:17.11.176.26 definitions=2023-05-23_05,2023-05-22_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 mlxscore=0 mlxlogscore=999 phishscore=0 bulkscore=0 suspectscore=0 adultscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2304280000 definitions=main-2305230074 X-Proofpoint-ORIG-GUID: Q9daB8SDOltDlLvxUb_dj8mHwouNTe1V X-Proofpoint-GUID: Q9daB8SDOltDlLvxUb_dj8mHwouNTe1V Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org This commit adds functionality to restore metadump stored in v2 format. Signed-off-by: Chandan Babu R --- mdrestore/xfs_mdrestore.c | 209 +++++++++++++++++++++++++++++++++++--- 1 file changed, 194 insertions(+), 15 deletions(-) diff --git a/mdrestore/xfs_mdrestore.c b/mdrestore/xfs_mdrestore.c index 615ecdc77..9e06d37dc 100644 --- a/mdrestore/xfs_mdrestore.c +++ b/mdrestore/xfs_mdrestore.c @@ -11,7 +11,8 @@ struct mdrestore_ops { int (*read_header)(void *header, FILE *mdfp); void (*show_info)(void *header, const char *mdfile); void (*restore)(void *header, FILE *mdfp, int data_fd, - bool is_target_file); + bool is_data_target_file, int log_fd, + bool is_log_target_file); }; static struct mdrestore { @@ -148,7 +149,9 @@ restore_v1( void *header, FILE *mdfp, int data_fd, - bool is_target_file) + bool is_data_target_file, + int log_fd, + bool is_log_target_file) { struct xfs_metablock *mbp = header; struct xfs_metablock *metablock; @@ -203,7 +206,7 @@ restore_v1( ((struct xfs_dsb*)block_buffer)->sb_inprogress = 1; - verify_device_size(data_fd, is_target_file, sb.sb_dblocks, + verify_device_size(data_fd, is_data_target_file, sb.sb_dblocks, sb.sb_blocksize); bytes_read = 0; @@ -264,6 +267,163 @@ static struct mdrestore_ops mdrestore_ops_v1 = { .restore = restore_v1, }; +static int +read_header_v2( + void *header, + FILE *mdfp) +{ + struct xfs_metadump_header *xmh = header; + + rewind(mdfp); + + if (fread(xmh, sizeof(*xmh), 1, mdfp) != 1) + fatal("error reading from metadump file\n"); + if (xmh->xmh_magic != cpu_to_be32(XFS_MD_MAGIC_V2)) + return -1; + + return 0; +} + +static void +show_info_v2( + void *header, + const char *mdfile) +{ + struct xfs_metadump_header *xmh; + uint32_t incompat_flags; + + xmh = header; + incompat_flags = be32_to_cpu(xmh->xmh_incompat_flags); + + printf("%s: %sobfuscated, %s log, %s metadata blocks\n", + mdfile, + incompat_flags & XFS_MD2_INCOMPAT_OBFUSCATED ? "":"not ", + incompat_flags & XFS_MD2_INCOMPAT_DIRTYLOG ? "dirty":"clean", + incompat_flags & XFS_MD2_INCOMPAT_FULLBLOCKS ? "full":"zeroed"); +} + +static void +restore_v2( + void *header, + FILE *mdfp, + int data_fd, + bool is_data_target_file, + int log_fd, + bool is_log_target_file) +{ + struct xfs_sb sb; + struct xfs_meta_extent xme; + char *block_buffer; + int64_t bytes_read; + uint64_t offset; + int prev_len; + int len; + + if (fread(&xme, sizeof(xme), 1, mdfp) != 1) + fatal("error reading from metadump file\n"); + + len = be32_to_cpu(xme.xme_len); + len <<= BBSHIFT; + + block_buffer = calloc(1, len); + if (block_buffer == NULL) + fatal("memory allocation failure\n"); + + if (fread(block_buffer, len, 1, mdfp) != 1) + fatal("error reading from metadump file\n"); + + libxfs_sb_from_disk(&sb, (struct xfs_dsb *)block_buffer); + + if (sb.sb_magicnum != XFS_SB_MAGIC) + fatal("bad magic number for primary superblock\n"); + + if (sb.sb_logstart == 0 && log_fd == -1) + fatal("External Log device is required\n"); + + ((struct xfs_dsb *)block_buffer)->sb_inprogress = 1; + + verify_device_size(data_fd, is_data_target_file, sb.sb_dblocks, + sb.sb_blocksize); + + if (sb.sb_logstart == 0) + verify_device_size(log_fd, is_log_target_file, sb.sb_logblocks, + sb.sb_blocksize); + + bytes_read = 0; + + do { + int fd; + + if (mdrestore.show_progress && + (bytes_read & ((1 << 20) - 1)) == 0) + print_progress("%lld MB read", bytes_read >> 20); + + offset = be64_to_cpu(xme.xme_addr) & XME_ADDR_DEVICE_MASK; + offset <<= BBSHIFT; + + if (be64_to_cpu(xme.xme_addr) & XME_ADDR_DATA_DEVICE) + fd = data_fd; + else if (be64_to_cpu(xme.xme_addr) & XME_ADDR_LOG_DEVICE) + fd = log_fd; + else + ASSERT(0); + + if (pwrite(fd, block_buffer, len, offset) < 0) + fatal("error writing to %s device at offset %llu: %s\n", + fd == data_fd ? "data": "log", offset, + strerror(errno)); + + if (fread(&xme, sizeof(xme), 1, mdfp) != 1) { + if (feof(mdfp)) + break; + fatal("error reading from metadump file\n"); + } + + prev_len = len; + len = be32_to_cpu(xme.xme_len); + len <<= BBSHIFT; + if (len > prev_len) { + void *p; + p = realloc(block_buffer, len); + if (p == NULL) { + free(block_buffer); + fatal("memory allocation failure\n"); + } + block_buffer = p; + } + + if (fread(block_buffer, len, 1, mdfp) != 1) + fatal("error reading from metadump file\n"); + + bytes_read += len; + } while (1); + + if (mdrestore.progress_since_warning) + putchar('\n'); + + memset(block_buffer, 0, sb.sb_sectsize); + sb.sb_inprogress = 0; + libxfs_sb_to_disk((struct xfs_dsb *)block_buffer, &sb); + if (xfs_sb_version_hascrc(&sb)) { + xfs_update_cksum(block_buffer, sb.sb_sectsize, + offsetof(struct xfs_sb, sb_crc)); + } + + if (pwrite(data_fd, block_buffer, sb.sb_sectsize, 0) < 0) + fatal("error writing primary superblock: %s\n", + strerror(errno)); + + free(block_buffer); + + return; +} + +static struct mdrestore_ops mdrestore_ops_v2 = { + .read_header = read_header_v2, + .show_info = show_info_v2, + .restore = restore_v2, +}; + static void usage(void) { @@ -276,11 +436,16 @@ main( int argc, char **argv) { - FILE *src_f; - int dst_fd; - int c; - bool is_target_file; - struct xfs_metablock mb; + struct xfs_metadump_header xmh; + struct xfs_metablock mb; + FILE *src_f; + char *logdev = NULL; + void *header; + int data_dev_fd; + int log_dev_fd; + int c; + bool is_data_dev_file; + bool is_log_dev_file; mdrestore.show_progress = 0; mdrestore.show_info = 0; @@ -327,13 +492,18 @@ main( fatal("cannot open source dump file\n"); } - if (mdrestore_ops_v1.read_header(&mb, src_f) == 0) + if (mdrestore_ops_v1.read_header(&mb, src_f) == 0) { mdrestore.mdrops = &mdrestore_ops_v1; - else + header = &mb; + } else if (mdrestore_ops_v2.read_header(&xmh, src_f) == 0) { + mdrestore.mdrops = &mdrestore_ops_v2; + header = &xmh; + } else { fatal("Invalid metadump format\n"); + } if (mdrestore.show_info) { - mdrestore.mdrops->show_info(&mb, argv[optind]); + mdrestore.mdrops->show_info(header, argv[optind]); if (argc - optind == 1) exit(0); @@ -341,12 +511,21 @@ main( optind++; - /* check and open target */ - dst_fd = open_device(argv[optind], &is_target_file); + /* check and open data device */ + data_dev_fd = open_device(argv[optind], &is_data_dev_file); + + log_dev_fd = -1; + if (logdev) + /* check and open log device */ + log_dev_fd = open_device(logdev, &is_log_dev_file); + + mdrestore.mdrops->restore(header, src_f, data_dev_fd, is_data_dev_file, + log_dev_fd, is_log_dev_file); - mdrestore.mdrops->restore(&mb, src_f, dst_fd, is_target_file); + close(data_dev_fd); + if (logdev) + close(log_dev_fd); - close(dst_fd); if (src_f != stdin) fclose(src_f); From patchwork Tue May 23 09:00:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Babu R X-Patchwork-Id: 13251944 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8ECB4C7EE26 for ; Tue, 23 May 2023 09:01:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236286AbjEWJBb (ORCPT ); Tue, 23 May 2023 05:01:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36108 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236287AbjEWJB1 (ORCPT ); Tue, 23 May 2023 05:01:27 -0400 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3B681FF for ; Tue, 23 May 2023 02:01:26 -0700 (PDT) Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 34N6EfMb031379; Tue, 23 May 2023 09:01:24 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=corp-2023-03-30; bh=v/411W+AiNZBeY1UvLwKA3UpDZKjNd31N64sJAYu6Ng=; b=tLbMzbrGaeJ8YAHG8nP5veJuDflEmJQLQ/eNf0gS9ZaJwq2oRhv4JieeSTEMjUT8kgyB 55ZEvVp5HvJ1vZib6KJEX3UE/REATTQfl301dXlVqDeoWgxGrE8w0fyxv5TEUJ3nAang cW64AdC2QhVLW4LPvw4J3xjnl5bxniHAyKwK+tZ0GEtdULVvQpYSWeV7Fqot2phoJMjr BfMt5fW5m9TFLgTxaP2YTK99FvBVHXt2jaAgQYf07/ePOjF/Dgswk1uOY3ar+N3SK+vU dx23LZyiXjKv709PSLpb35Dlzzc4LBSu1vGqUi8TfI2TNrUCcXsAzM8nrhB4eKYOCPfw 0g== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3qpp3mmn4h-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 23 May 2023 09:01:24 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 34N6tBgb029028; Tue, 23 May 2023 09:01:23 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3qqk2aj7us-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 23 May 2023 09:01:23 +0000 Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 34N8xws9007681; Tue, 23 May 2023 09:01:23 GMT Received: from chanbabu-fstest.osdevelopmeniad.oraclevcn.com (chanbabu-fstesting.allregionaliads.osdevelopmeniad.oraclevcn.com [100.100.250.50]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3qqk2aj76a-24; Tue, 23 May 2023 09:01:22 +0000 From: Chandan Babu R To: cem@kernel.org Cc: Chandan Babu R , linux-xfs@vger.kernel.org Subject: [PATCH 23/24] mdrestore: Add support for passing log device as an argument Date: Tue, 23 May 2023 14:30:49 +0530 Message-Id: <20230523090050.373545-24-chandan.babu@oracle.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230523090050.373545-1-chandan.babu@oracle.com> References: <20230523090050.373545-1-chandan.babu@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.573,FMLib:17.11.176.26 definitions=2023-05-23_05,2023-05-22_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 mlxscore=0 mlxlogscore=999 phishscore=0 bulkscore=0 suspectscore=0 adultscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2304280000 definitions=main-2305230074 X-Proofpoint-ORIG-GUID: eRxvOlX4l_lnLJOKQ7mFfPCqg-deQnpS X-Proofpoint-GUID: eRxvOlX4l_lnLJOKQ7mFfPCqg-deQnpS Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org metadump v2 format allows dumping metadata from external log devices. This commit allows passing the device file to which log data must be restored from the corresponding metadump file. Signed-off-by: Chandan Babu R --- mdrestore/xfs_mdrestore.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/mdrestore/xfs_mdrestore.c b/mdrestore/xfs_mdrestore.c index 9e06d37dc..f5eff62ef 100644 --- a/mdrestore/xfs_mdrestore.c +++ b/mdrestore/xfs_mdrestore.c @@ -427,7 +427,8 @@ static struct mdrestore_ops mdrestore_ops_v2 = { static void usage(void) { - fprintf(stderr, "Usage: %s [-V] [-g] [-i] source target\n", progname); + fprintf(stderr, "Usage: %s [-V] [-g] [-i] [-l logdev] source target\n", + progname); exit(1); } @@ -453,7 +454,7 @@ main( progname = basename(argv[0]); - while ((c = getopt(argc, argv, "giV")) != EOF) { + while ((c = getopt(argc, argv, "gil:V")) != EOF) { switch (c) { case 'g': mdrestore.show_progress = 1; @@ -461,6 +462,9 @@ main( case 'i': mdrestore.show_info = 1; break; + case 'l': + logdev = optarg; + break; case 'V': printf("%s version %s\n", progname, VERSION); exit(0); @@ -493,6 +497,8 @@ main( } if (mdrestore_ops_v1.read_header(&mb, src_f) == 0) { + if (logdev != NULL) + usage(); mdrestore.mdrops = &mdrestore_ops_v1; header = &mb; } else if (mdrestore_ops_v2.read_header(&xmh, src_f) == 0) { From patchwork Tue May 23 09:00:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Babu R X-Patchwork-Id: 13251945 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id ABED3C7EE23 for ; Tue, 23 May 2023 09:01:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236287AbjEWJBc (ORCPT ); Tue, 23 May 2023 05:01:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36120 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236276AbjEWJB2 (ORCPT ); Tue, 23 May 2023 05:01:28 -0400 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2E4E0102 for ; Tue, 23 May 2023 02:01:27 -0700 (PDT) Received: from pps.filterd (m0333521.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 34N6Eq8L032516; Tue, 23 May 2023 09:01:25 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=corp-2023-03-30; bh=17RjFe98fYH9lhA9/P4hVFVbpRpMBKdb+Oj2+Sl8c1M=; b=Rw4+5kzf62Z1tH0T2A6MmBruPSmdmukagjf3FtqY/b6wd53FC19KQSCzPm545chP3SmN FARfuGmGQwZpNdgkdaDMtyWX32eyScZcYVHTMNgC5jQDHHwHnM+1G91XDRzNmuqOVx9s r4b4jT5viOz5gcIdH+WHosDGkd4kKd3+Qy/OZfnj/mgi7MV90GtSrhLosHHuZi/9oxfe C0QO/3/jy42GbLzOfCRJPcJ4mKbk4qC3MXTIVkH2PRalhzgrVFoir0OWBxI3k1inRpN1 aYgqk6Qf6m0XlUiRRt8wfeuL44pPCGEQF7EfDvadcgJjEmIASxsjiICXcInsYOPiqxjC FQ== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3qpp5bmmea-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 23 May 2023 09:01:25 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 34N918F4029093; Tue, 23 May 2023 09:01:24 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3qqk2aj7vj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 23 May 2023 09:01:24 +0000 Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 34N8xwsB007681; Tue, 23 May 2023 09:01:24 GMT Received: from chanbabu-fstest.osdevelopmeniad.oraclevcn.com (chanbabu-fstesting.allregionaliads.osdevelopmeniad.oraclevcn.com [100.100.250.50]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3qqk2aj76a-25; Tue, 23 May 2023 09:01:23 +0000 From: Chandan Babu R To: cem@kernel.org Cc: Chandan Babu R , linux-xfs@vger.kernel.org Subject: [PATCH 24/24] xfs_mdrestore.8: Add description for the newly introduced -l option Date: Tue, 23 May 2023 14:30:50 +0530 Message-Id: <20230523090050.373545-25-chandan.babu@oracle.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230523090050.373545-1-chandan.babu@oracle.com> References: <20230523090050.373545-1-chandan.babu@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.573,FMLib:17.11.176.26 definitions=2023-05-23_05,2023-05-22_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 mlxscore=0 mlxlogscore=999 phishscore=0 bulkscore=0 suspectscore=0 adultscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2304280000 definitions=main-2305230074 X-Proofpoint-GUID: pqBNt5mlZlcy6pahrEhZCVG8DPcCW7kE X-Proofpoint-ORIG-GUID: pqBNt5mlZlcy6pahrEhZCVG8DPcCW7kE Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org Signed-off-by: Chandan Babu R --- man/man8/xfs_mdrestore.8 | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/man/man8/xfs_mdrestore.8 b/man/man8/xfs_mdrestore.8 index 72f3b2977..a53ac84d0 100644 --- a/man/man8/xfs_mdrestore.8 +++ b/man/man8/xfs_mdrestore.8 @@ -5,6 +5,9 @@ xfs_mdrestore \- restores an XFS metadump image to a filesystem image .B xfs_mdrestore [ .B \-gi +] [ +.B \-l +.I logdev ] .I source .I target @@ -49,6 +52,11 @@ Shows metadump information on stdout. If no is specified, exits after displaying information. Older metadumps man not include any descriptive information. .TP +.B \-l " logdev" +Metadump in v2 format can contain metadata dumped from an external log. In +such a scenario, the user has to provide a device to which the log device +contents from the metadump file are copied. +.TP .B \-V Prints the version number and exits. .SH DIAGNOSTICS