From patchwork Fri May 26 16:13:58 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Sandeen X-Patchwork-Id: 9750779 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 3DEEA6032C for ; Fri, 26 May 2017 16:14:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2F9F728323 for ; Fri, 26 May 2017 16:14:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 23E2828210; Fri, 26 May 2017 16:14:05 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 85B1628210 for ; Fri, 26 May 2017 16:14:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1948249AbdEZQOC (ORCPT ); Fri, 26 May 2017 12:14:02 -0400 Received: from sandeen.net ([63.231.237.45]:58584 "EHLO sandeen.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S944034AbdEZQN7 (ORCPT ); Fri, 26 May 2017 12:13:59 -0400 Received: from [10.0.0.4] (liberator [10.0.0.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by sandeen.net (Postfix) with ESMTPSA id CA1C52AB4; Fri, 26 May 2017 11:13:58 -0500 (CDT) Subject: [PATCH V2] xfs_metadump: tag metadump image with informational flags To: Eric Sandeen , linux-xfs References: <402504cb-1632-85b6-a745-1334ccf0ee8f@redhat.com> From: Eric Sandeen Message-ID: Date: Fri, 26 May 2017 11:13:58 -0500 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:52.0) Gecko/20100101 Thunderbird/52.1.1 MIME-Version: 1.0 In-Reply-To: <402504cb-1632-85b6-a745-1334ccf0ee8f@redhat.com> Content-Language: en-US Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP After the long discussion about warning the user and/or consumer of xfs_metadumps about dirty logs, it crossed my mind that we could use the reserved slot in the metadump header to tag the file with attributes, so the consumer of the metadump knows how it was created. This patch adds 4 flags to describe the metadump: The first simply indicates the presence of any (or no) informational flags. The old mb_reserved field has been 0 on disk since inception, so the presence of XFS_METADUMP_INFO_FLAGS indicates that this metadump may contain the informational flags: - dirty log - obfuscated - full blocks (unused portions of metadata blocks are not zeroed out). It then adds a new option to xfs_mdrestore, "-i" to show info, which can be used with or without a target file: # xfs_mdrestore -i metadumpfile metadumpfile: not obfuscated, clean log, full metadata blocks Signed-off-by: Eric Sandeen Reviewed-by: Darrick J. Wong --- V2: rename to mb_info, add the "we have flags" flag -- To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/db/metadump.c b/db/metadump.c index fe068ef..2f5b5b5 100644 --- a/db/metadump.c +++ b/db/metadump.c @@ -2820,6 +2820,28 @@ metadump_f( 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(); + set_cur(&typtab[TYP_LOG], + 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 */ + struct xlog log; + + if (xlog_is_dirty(mp, &log, &x, 0)) + metablock->mb_info |= XFS_METADUMP_DIRTYLOG; + } + 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); diff --git a/include/xfs_metadump.h b/include/xfs_metadump.h index f4be51b..7f3039e 100644 --- a/include/xfs_metadump.h +++ b/include/xfs_metadump.h @@ -25,8 +25,14 @@ typedef struct xfs_metablock { __be32 mb_magic; __be16 mb_count; __uint8_t mb_blocklog; - __uint8_t mb_reserved; + __uint8_t mb_info; /* followed by an array of xfs_daddr_t */ } xfs_metablock_t; +/* These flags are informational only, not backwards compatible */ +#define XFS_METADUMP_INFO_FLAGS (1 << 0) /* This image has informative flags */ +#define XFS_METADUMP_OBFUSCATED (1 << 1) +#define XFS_METADUMP_FULLBLOCKS (1 << 2) +#define XFS_METADUMP_DIRTYLOG (1 << 3) + #endif /* _XFS_METADUMP_H_ */ diff --git a/man/man8/xfs_mdrestore.8 b/man/man8/xfs_mdrestore.8 index 2095f15..72f3b29 100644 --- a/man/man8/xfs_mdrestore.8 +++ b/man/man8/xfs_mdrestore.8 @@ -4,11 +4,15 @@ xfs_mdrestore \- restores an XFS metadump image to a filesystem image .SH SYNOPSIS .B xfs_mdrestore [ -.B \-g +.B \-gi ] .I source .I target .br +.B xfs_mdrestore +.B \-i +.I source +.br .B xfs_mdrestore \-V .SH DESCRIPTION .B xfs_mdrestore @@ -39,6 +43,12 @@ can be destroyed. .B \-g Shows restore progress on stdout. .TP +.B \-i +Shows metadump information on stdout. If no +.I target +is specified, exits after displaying information. Older metadumps man not +include any descriptive information. +.TP .B \-V Prints the version number and exits. .SH DIAGNOSTICS diff --git a/mdrestore/xfs_mdrestore.c b/mdrestore/xfs_mdrestore.c index 0d399f1..9d1b4e8 100644 --- a/mdrestore/xfs_mdrestore.c +++ b/mdrestore/xfs_mdrestore.c @@ -21,6 +21,7 @@ char *progname; int show_progress = 0; +int show_info = 0; int progress_since_warning = 0; static void @@ -213,11 +214,14 @@ main( progname = basename(argv[0]); - while ((c = getopt(argc, argv, "gV")) != EOF) { + while ((c = getopt(argc, argv, "giV")) != EOF) { switch (c) { case 'g': show_progress = 1; break; + case 'i': + show_info = 1; + break; case 'V': printf("%s version %s\n", progname, VERSION); exit(0); @@ -226,7 +230,11 @@ main( } } - if (argc - optind != 2) + if (argc - optind < 1 || argc - optind > 2) + usage(); + + /* show_info without a target is ok */ + if (!show_info && argc - optind != 2) usage(); /* open source */ @@ -239,6 +247,34 @@ main( if (src_f == NULL) fatal("cannot open source dump file\n"); } + + if (show_info) { + xfs_metablock_t mb; + + if (fread(&mb, sizeof(mb), 1, src_f) != 1) + fatal("error reading from file: %s\n", strerror(errno)); + + if (be32_to_cpu(mb.mb_magic) != XFS_MD_MAGIC) + fatal("specified file is not a metadata dump\n"); + + 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]); + } + + if (argc - optind == 1) + exit(0); + + /* Go back to the beginning for the restore function */ + fseek(src_f, 0L, SEEK_SET); + } + optind++; /* check and open target */