Metadump v2
v2 cover Metadump v2
Hi all,
This patch series extends metadump/mdrestore tools to be able to dump and restore contents of an external log device. It also adds the ability to copy larger blocks (e.g. 4096 bytes instead of 512 bytes) into the metadump file. These objectives are accomplished by introducing a new metadump file format.
I have tested the patchset by extending metadump/mdrestore tests in fstests to cover the newly introduced metadump v2 format. The tests can be found at
https://github.com/chandanr/xfstests/commits/metadump-v2.
The patch series can also be obtained from
https://github.com/chandanr/xfsprogs-dev/commits/metadump-v2.
Changelog:
V1 -> V2:
1. Introduce the new incompat flag XFS_MD2_INCOMPAT_EXTERNALLOG to indicate that the metadump file contains data obtained from an external log.
2. Interpret bits 54 and 55 of xfs_meta_extent.xme_addr as a counter such that 00 maps to the data device and 01 maps to the log device.
3. Define the new function set_log_cur() to read from internal/external log device. This allows us to continue using TYP_LOG to read from both internal and external log.
4. In order to support reading metadump from a pipe, mdrestore now reads the first four bytes of the header to determine the metadump version rather than reading the entire header in a single call to fread().
5. Add an ASCII diagram to describe metadump v2's ondisk layout in xfs_metadump.h.
6. Update metadump's man page to indicate that metadump in v2 format is generated by default if the filesystem has an external log and the metadump version to use is not explicitly mentioned on the command line.
7. Remove '_metadump' suffix from function pointer names in "struct metadump_ops".
8. Use xfs_daddr_t type for declaring variables containing disk offset value.
9. Use bool type rather than int for variables holding a boolean value.
11. Remove unnecessary whitespace.
Chandan Babu R (23):
metadump: Use boolean values true/false instead of 1/0
mdrestore: Fix logic used to check if target device is large enough
metadump: Declare boolean variables with bool type
metadump: Define and use struct metadump
metadump: Add initialization and release functions
metadump: Postpone invocation of init_metadump()
metadump: Introduce struct metadump_ops
metadump: Introduce metadump v1 operations
metadump: Rename XFS_MD_MAGIC to XFS_MD_MAGIC_V1
metadump: Define metadump v2 ondisk format structures and macros
metadump: Define metadump ops for v2 format
xfs_db: Add support to read from external log device
metadump: Add support for passing version option
mdrestore: Declare boolean variables with bool type
mdrestore: Define and use struct mdrestore
mdrestore: Detect metadump v1 magic before reading the header
mdrestore: Add open_device(), read_header() and show_info() functions
mdrestore: Introduce struct mdrestore_ops
mdrestore: Replace metadump header pointer argument with generic
pointer type
mdrestore: Introduce mdrestore v1 operations
mdrestore: Extract target device size verification into a function
mdrestore: Define mdrestore ops for v2 format
mdrestore: Add support for passing log device as an argument
db/io.c | 57 ++- db/io.h | 2 + db/metadump.c | 749 +++++++++++++++++++++++--------------- db/xfs_metadump.sh | 3 +- include/xfs_metadump.h | 60 ++- man/man8/xfs_mdrestore.8 | 8 + man/man8/xfs_metadump.8 | 14 + mdrestore/xfs_mdrestore.c | 497 +++++++++++++++++++------ 8 files changed, 985 insertions(+), 405 deletions(-)
Signature · 1 line
2.39.1
PATCH v2 1/23 metadump: Use boolean values true/false instead of 1/0
--- db/metadump.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
db/metadump.c +5 -5
@@ -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);
Signature · 1 line
2.39.1
PATCH v2 2/23 mdrestore: Fix logic used to check if target device is large enough
In reply to Chandan Babu RThe 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.
--- mdrestore/xfs_mdrestore.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mdrestore/xfs_mdrestore.c +1 -1
@@ -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);
Signature · 1 line
2.39.1
PATCH v2 3/23 metadump: Declare boolean variables with bool type
In reply to Chandan Babu R--- db/metadump.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-)
db/metadump.c +16 -16
@@ -51,13 +51,13 @@ static int cur_index;static xfs_ino_t cur_ino; -static int show_progress =0 ; -static int stop_on_read_error =0 ; +static bool show_progress = false; +static bool stop_on_read_error = false;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 obfuscate = true; +static bool zero_stale_data = true; +static bool show_warnings = false; +static bool progress_since_warning = false;static bool stdout_metadump;void
@@ -100,7 +100,7 @@ print_warning(const char *fmt, ...)fprintf (stderr,"%s%s: %s\n" , progress_since_warning ?"\n" :"" , progname, buf); - progress_since_warning =0 ; + progress_since_warning = false; } static void
@@ -121,7 +121,7 @@ print_progress(const char *fmt, ...) f = stdout_metadump ? stderr : stdout;fprintf (f,"\r%-59s" , buf);fflush (f); - progress_since_warning =1 ; + progress_since_warning = true; }/*
@@ -2979,9 +2979,9 @@ metadump_f(char *p; exitcode =1 ; - show_progress =0 ; - show_warnings =0 ; - stop_on_read_error =0 ; + show_progress = false; + show_warnings = false; + stop_on_read_error = false;if (mp->m_sb.sb_magicnum !=XFS_SB_MAGIC ) { print_warning("bad superblock magic number %x, giving up",
@@ -3002,13 +3002,13 @@ metadump_f(while ((c =getopt (argc, argv,"aegm:ow" )) !=EOF ) {switch (c) {case 'a' : - zero_stale_data =0 ; + zero_stale_data = false;break ;case 'e' : - stop_on_read_error =1 ; + stop_on_read_error = true;break ;case 'g' : - show_progress =1 ; + show_progress = true;break ;case 'm' : max_extent_size = (int )strtol (optarg, &p,0 );
@@ -3019,10 +3019,10 @@ metadump_f( }break ;case 'o' : - obfuscate =0 ; + obfuscate = false;break ;case 'w' : - show_warnings =1 ; + show_warnings = true;break ;default :print_warning ("bad option for metadump command" );
Signature · 1 line
2.39.1
Re: [PATCH V2 03/23] metadump: Declare boolean variables with bool type
Quoted 1 line · Chandan Babu R
Signed-off-by Chandan Babu R <[email protected]>
--D
Quoted 92 lines
--- db/metadump.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-)db/metadump.c +16
-16@@ -51,13 +51,13 @@ static int cur_index;static xfs_ino_t cur_ino; -static int show_progress =0 ; -static int stop_on_read_error =0 ; +static bool show_progress = false; +static bool stop_on_read_error = false;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 obfuscate = true; +static bool zero_stale_data = true; +static bool show_warnings = false; +static bool progress_since_warning = false;static bool stdout_metadump;void @@ -100,7 +100,7 @@ print_warning(const char *fmt, ...)fprintf (stderr,"%s%s: %s\n" , progress_since_warning ?"\n" :"" , progname, buf); - progress_since_warning =0 ; + progress_since_warning = false; } static void@@ -121,7 +121,7 @@ print_progress(const char *fmt, ...) f = stdout_metadump ? stderr : stdout;fprintf (f,"\r%-59s" , buf);fflush (f); - progress_since_warning =1 ; + progress_since_warning = true; }/* @@ -2979,9 +2979,9 @@ metadump_f(char *p; exitcode =1 ; - show_progress =0 ; - show_warnings =0 ; - stop_on_read_error =0 ; + show_progress = false; + show_warnings = false; + stop_on_read_error = false;if (mp->m_sb.sb_magicnum !=XFS_SB_MAGIC ) { print_warning("bad superblock magic number %x, giving up",@@ -3002,13 +3002,13 @@ metadump_f(while ((c =getopt (argc, argv,"aegm:ow" )) !=EOF ) {switch (c) {case 'a' : - zero_stale_data =0 ; + zero_stale_data = false;break ;case 'e' : - stop_on_read_error =1 ; + stop_on_read_error = true;break ;case 'g' : - show_progress =1 ; + show_progress = true;break ;case 'm' : max_extent_size = (int )strtol (optarg, &p,0 );@@ -3019,10 +3019,10 @@ metadump_f( }break ;case 'o' : - obfuscate =0 ; + obfuscate = false;break ;case 'w' : - show_warnings =1 ; + show_warnings = true;break ;default :print_warning ("bad option for metadump command" );Signature · 1 line
2.39.1
PATCH v2 4/23 metadump: Define and use struct metadump
In reply to Chandan Babu RThis commit collects all state tracking variables in a new "struct metadump" structure. This is done to collect all the global variables in one place rather than having them spread across the file. A new structure member of type "struct metadump_ops *" will be added by a future commit to support the two versions of metadump.
--- db/metadump.c | 459 +++++++++++++++++++++++++++----------------------- 1 file changed, 244 insertions(+), 215 deletions(-)
db/metadump.c +244 -215
@@ -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 bool show_progress = false; -static bool stop_on_read_error = false; -static int max_extent_size =DEFAULT_MAX_EXT_SIZE ; -static bool obfuscate = true; -static bool zero_stale_data = true; -static bool show_warnings = false; -static bool progress_since_warning = false; -static bool stdout_metadump; +static struct metadump { +int version; +bool show_progress; +bool stop_on_read_error; +int max_extent_size; +bool show_warnings; +bool obfuscate; +bool zero_stale_data; +bool 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 = false; +fprintf (stderr,"%s%s: %s\n" , + metadump.progress_since_warning ?"\n" :"" , progname, buf); + metadump.progress_since_warning = false; } 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 = true; + metadump.progress_since_warning = true; }/*
@@ -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 = false; - show_warnings = false; - stop_on_read_error = false; + + metadump.version =1 ; + metadump.show_progress = false; + metadump.stop_on_read_error = false; + metadump.max_extent_size =DEFAULT_MAX_EXT_SIZE ; + metadump.show_warnings = false; + metadump.obfuscate = true; + metadump.zero_stale_data = true; + 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 = false; + metadump.zero_stale_data = false;break ;case 'e' : - stop_on_read_error = true; + metadump.stop_on_read_error = true;break ;case 'g' : - show_progress = true; + metadump.show_progress = true;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 = false; + metadump.obfuscate = false;break ;case 'w' : - show_warnings = true; + metadump.show_warnings = true;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 ; }
Signature · 1 line
2.39.1
Re: [PATCH V2 04/23] metadump: Define and use struct metadump
Quoted 7 lines · Chandan Babu R
This commit collects all state tracking variables in a new "struct metadump" structure. This is done to collect all the global variables in one place rather than having them spread across the file. A new structure member of type "struct
metadump_ops*" will be added by a future commit to support the two versions of metadump.Signed-off-by Chandan Babu R <[email protected]>
FWIW I still don't see much point in wrapping the global variables in a global struct, but I don't feel like holding up the patchset:
(...but ultimately it's up to Carlos to decide to accept or reject this.)
--D
Quoted 1,317 lines
--- db/metadump.c | 459 +++++++++++++++++++++++++++----------------------- 1 file changed, 244 insertions(+), 215 deletions(-)db/metadump.c +244
-215@@ -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 bool show_progress = false; -static bool stop_on_read_error = false; -static int max_extent_size =DEFAULT_MAX_EXT_SIZE ; -static bool obfuscate = true; -static bool zero_stale_data = true; -static bool show_warnings = false; -static bool progress_since_warning = false; -static bool stdout_metadump; +static struct metadump { +int version; +bool show_progress; +bool stop_on_read_error; +int max_extent_size; +bool show_warnings; +bool obfuscate; +bool zero_stale_data; +bool 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 = false; +fprintf (stderr,"%s%s: %s\n" , + metadump.progress_since_warning ?"\n" :"" , progname, buf); + metadump.progress_since_warning = false; } 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 = true; + metadump.progress_since_warning = true; }/* @@ -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 = false; - show_warnings = false; - stop_on_read_error = false; + + metadump.version =1 ; + metadump.show_progress = false; + metadump.stop_on_read_error = false; + metadump.max_extent_size =DEFAULT_MAX_EXT_SIZE ; + metadump.show_warnings = false; + metadump.obfuscate = true; + metadump.zero_stale_data = true; + 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 = false; + metadump.zero_stale_data = false;break ;case 'e' : - stop_on_read_error = true; + metadump.stop_on_read_error = true;break ;case 'g' : - show_progress = true; + metadump.show_progress = true;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 = false; + metadump.obfuscate = false;break ;case 'w' : - show_warnings = true; + metadump.show_warnings = true;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 ; }Signature · 1 line
2.39.1
Carlos Maiolino
Reviewed-byRe: [PATCH V2 04/23] metadump: Define and use struct metadump
Quoted 9 lines · Darrick J. Wong
Quoted 7 lines · Chandan Babu R
This commit collects all state tracking variables in a new "struct metadump" structure. This is done to collect all the global variables in one place rather than having them spread across the file. A new structure member of type "struct
metadump_ops*" will be added by a future commit to support the two versions of metadump.Signed-off-by Chandan Babu R <[email protected]>
Quoted 7 lines
FWIW I still don't see much point in wrapping the global variables in a global struct, but I don't feel like holding up the patchset:
Reviewed-by Darrick J. Wong <[email protected]>(...but ultimately it's up to Carlos to decide to accept or reject this.)
I don't mind either way (variables or struct), but, having everything within a global struct just seem easier to my eyes tbh, as, at least for me, it's easier to identify some variable has a global scope just by seeing it within the 'global struct'.
Unless you have any big objection to leave it as a struct (as I can see you don't), this seems totally fine to me.
Quoted 1,320 lines
--D
Quoted 1,317 lines
--- db/metadump.c | 459 +++++++++++++++++++++++++++----------------------- 1 file changed, 244 insertions(+), 215 deletions(-)db/metadump.c +244
-216@@ -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 bool show_progress = false; -static bool stop_on_read_error = false; -static int max_extent_size =DEFAULT_MAX_EXT_SIZE ; -static bool obfuscate = true; -static bool zero_stale_data = true; -static bool show_warnings = false; -static bool progress_since_warning = false; -static bool stdout_metadump; +static struct metadump { +int version; +bool show_progress; +bool stop_on_read_error; +int max_extent_size; +bool show_warnings; +bool obfuscate; +bool zero_stale_data; +bool 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 = false; +fprintf (stderr,"%s%s: %s\n" , + metadump.progress_since_warning ?"\n" :"" , progname, buf); + metadump.progress_since_warning = false; } 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 = true; + metadump.progress_since_warning = true; }/* @@ -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 = false; - show_warnings = false; - stop_on_read_error = false; + + metadump.version =1 ; + metadump.show_progress = false; + metadump.stop_on_read_error = false; + metadump.max_extent_size =DEFAULT_MAX_EXT_SIZE ; + metadump.show_warnings = false; + metadump.obfuscate = true; + metadump.zero_stale_data = true; + 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 = false; + metadump.zero_stale_data = false;break ;case 'e' : - stop_on_read_error = true; + metadump.stop_on_read_error = true;break ;case 'g' : - show_progress = true; + metadump.show_progress = true;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 = false; + metadump.obfuscate = false;break ;case 'w' : - show_warnings = true; + metadump.show_warnings = true;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 ; } --2.39.1
Re: [PATCH V2 04/23] metadump: Define and use struct metadump
Quoted 18 lines · Carlos Maiolino
Quoted 9 lines · Darrick J. Wong
Quoted 7 lines · Chandan Babu R
This commit collects all state tracking variables in a new "struct metadump" structure. This is done to collect all the global variables in one place rather than having them spread across the file. A new structure member of type "struct
metadump_ops*" will be added by a future commit to support the two versions of metadump.Signed-off-by Chandan Babu R <[email protected]>Quoted 7 lines
FWIW I still don't see much point in wrapping the global variables in a global struct, but I don't feel like holding up the patchset:
Reviewed-by Darrick J. Wong <[email protected]>(...but ultimately it's up to Carlos to decide to accept or reject this.)
Quoted 7 lines
I don't mind either way (variables or struct), but, having everything within a global struct just seem easier to my eyes tbh, as, at least for me, it's easier to identify some variable has a global scope just by seeing it within the 'global struct'.
Unless you have any big objection to leave it as a struct (as I can see you don't), this seems totally fine to me.
Sounds good to me then. Let our RVBs stand together! :)
--D
Quoted 1,324 lines
Reviewed-by Carlos Maiolino <[email protected]>Quoted 1,320 lines
--D
Quoted 1,317 lines
--- db/metadump.c | 459 +++++++++++++++++++++++++++----------------------- 1 file changed, 244 insertions(+), 215 deletions(-)db/metadump.c +244
-216@@ -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 bool show_progress = false; -static bool stop_on_read_error = false; -static int max_extent_size =DEFAULT_MAX_EXT_SIZE ; -static bool obfuscate = true; -static bool zero_stale_data = true; -static bool show_warnings = false; -static bool progress_since_warning = false; -static bool stdout_metadump; +static struct metadump { +int version; +bool show_progress; +bool stop_on_read_error; +int max_extent_size; +bool show_warnings; +bool obfuscate; +bool zero_stale_data; +bool 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 = false; +fprintf (stderr,"%s%s: %s\n" , + metadump.progress_since_warning ?"\n" :"" , progname, buf); + metadump.progress_since_warning = false; } 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 = true; + metadump.progress_since_warning = true; }/* @@ -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 = false; - show_warnings = false; - stop_on_read_error = false; + + metadump.version =1 ; + metadump.show_progress = false; + metadump.stop_on_read_error = false; + metadump.max_extent_size =DEFAULT_MAX_EXT_SIZE ; + metadump.show_warnings = false; + metadump.obfuscate = true; + metadump.zero_stale_data = true; + 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 = false; + metadump.zero_stale_data = false;break ;case 'e' : - stop_on_read_error = true; + metadump.stop_on_read_error = true;break ;case 'g' : - show_progress = true; + metadump.show_progress = true;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 = false; + metadump.obfuscate = false;break ;case 'w' : - show_warnings = true; + metadump.show_warnings = true;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 ; } --2.39.1
PATCH v2 5/23 metadump: Add initialization and release functions
In reply to Chandan Babu RMove metadump initialization and release functionality into corresponding functions. There are no functional changes made in this commit.
--- db/metadump.c | 88 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 52 insertions(+), 36 deletions(-)
db/metadump.c +52 -36
@@ -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 ; }
Signature · 1 line
2.39.1
PATCH v2 6/23 metadump: Postpone invocation of init_metadump()
In reply to Chandan Babu RThe metadump v2 initialization function (introduced in a later commit) writes the header structure into the metadump file. This will require the program to open the metadump file before the initialization function has been invoked.
--- db/metadump.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
db/metadump.c +6 -5
@@ -3124,10 +3124,6 @@ metadump_f(pop_cur (); } - ret =init_metadump (); -if (ret) -return 0 ; - start_iocur_sp = iocur_sp;if (strcmp (argv[optind],"-" ) ==0 ) {
@@ -3172,6 +3168,10 @@ metadump_f( } } + ret =init_metadump (); +if (ret) + goto out; + exitcode =0 ;for (agno =0 ; agno < mp->m_sb.sb_agcount; agno++) {
@@ -3209,8 +3209,9 @@ metadump_f(/* cleanup iocur stack */ while (iocur_sp > start_iocur_sp)pop_cur (); -out: +release_metadump (); +out:return 0 ; }
Signature · 1 line
2.39.1
Re: [PATCH V2 06/23] metadump: Postpone invocation of init_metadump()
Quoted 5 lines · Chandan Babu R
The metadump v2 initialization function (introduced in a later commit) writes the header structure into the metadump file. This will require the program to open the metadump file before the initialization function has been invoked.
Signed-off-by Chandan Babu R <[email protected]>
--D
Quoted 44 lines
--- db/metadump.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)db/metadump.c +6
-5@@ -3124,10 +3124,6 @@ metadump_f(pop_cur (); } - ret =init_metadump (); -if (ret) -return 0 ; - start_iocur_sp = iocur_sp;if (strcmp (argv[optind],"-" ) ==0 ) {@@ -3172,6 +3168,10 @@ metadump_f( } } + ret =init_metadump (); +if (ret) + goto out; + exitcode =0 ;for (agno =0 ; agno < mp->m_sb.sb_agcount; agno++) {@@ -3209,8 +3209,9 @@ metadump_f(/* cleanup iocur stack */ while (iocur_sp > start_iocur_sp)pop_cur (); -out: +release_metadump (); +out:return 0 ; }Signature · 1 line
2.39.1
PATCH v2 7/23 metadump: Introduce struct metadump_ops
In reply to Chandan Babu RWe 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.
--- db/metadump.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)
db/metadump.c +25 -0
@@ -40,6 +40,30 @@ 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 { +/* +* Initialize Metadump. This may perform actions such as +* 1. Allocating memory for structures required for dumping the +* metadata. +* 2. Writing a header to the beginning of the metadump file. +*/ +int (*init)(void ); +/* +* Write metadata to the metadump file along with the required ancillary +* data. +*/ +int (*write)(enum typnm type,char *data,xfs_daddr_t off, +int len); +/* +* Flush any in-memory remanents of metadata to the metadump file. +*/ +int (*end_write)(void ); +/* +* Free resources allocated during metadump process. +*/ +void (*release)(void ); +}; + static struct metadump { int version; bool show_progress;
@@ -54,6 +78,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;
Signature · 1 line
2.39.1
Re: [PATCH V2 07/23] metadump: Introduce struct metadump_ops
Quoted 21 lines · Chandan Babu R
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 <[email protected]>--- db/metadump.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)db/metadump.c +4
-0@@ -40,6 +40,30 @@ 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 { +/* +* Initialize Metadump. This may perform actions such as +* 1. Allocating memory for structures required for dumping the
db/metadump.c static const cmdinfo_t metadump_cmd = · line 56
Quoted 10 lines
db/metadump.c +10
-0+* metadata. +* 2. Writing a header to the beginning of the metadump file. +*/ +int (*init)(void ); +/* +* Write metadata to the metadump file along with the required ancillary +* data. +*/ +int (*write)(enum typnm type,char *data,xfs_daddr_t off, +int len);
Minor nits: const char *data (since the ->write function doesn't alter the caller's buffer); and please document that @off and @len are both in units of 512b blocks.
With that fixed,
--D
Quoted 24 lines
db/metadump.c +11
-0+/* +* Flush any in-memory remanents of metadata to the metadump file. +*/ +int (*end_write)(void ); +/* +* Free resources allocated during metadump process. +*/ +void (*release)(void ); +}; + static struct metadump { int version; bool show_progress;@@ -54,6 +78,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;Signature · 1 line
2.39.1
PATCH v2 8/23 metadump: Introduce metadump v1 operations
In reply to Chandan Babu RThis 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_ops->write() and metadump_ops->release() respectively.
--- db/metadump.c | 123 +++++++++++++++++++++++++------------------------- 1 file changed, 61 insertions(+), 62 deletions(-)
db/metadump.c +61 -62
@@ -151,59 +151,6 @@ print_progress(const char *fmt, ...) metadump.progress_since_warning = true; } -/* -* 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
@@ -240,15 +187,16 @@ write_buf(/* handle discontiguous buffers */ if (!buf->bbmap) { - ret =write_buf_segment (buf->data, buf->bb, buf->blen); + ret = metadump.mdops->write (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 (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;
@@ -3010,7 +2958,7 @@ done: }static int -init_metadump (void ) +init_metadump_v1 (void ) { metadump.metablock = (xfs_metablock_t *)calloc (BBSIZE +1 ,BBSIZE );if (metadump.metablock ==NULL ) {
@@ -3051,12 +2999,61 @@ 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, +xfs_daddr_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 = init_metadump_v1, + .write = write_metadump_v1, + .end_write = end_write_metadump_v1, + .release = release_metadump_v1, +}; + static int metadump_f( int argc,
@@ -3193,7 +3190,9 @@ metadump_f( } } - ret =init_metadump (); + metadump.mdops = &metadump1_ops; + + ret = metadump.mdops->init ();if (ret) goto out;
@@ -3216,7 +3215,7 @@ metadump_f(/* write the remaining index */ if (!exitcode) - exitcode =write_index () <0 ; + exitcode = metadump.mdops->end_write () <0 ;if (metadump.progress_since_warning)fputc ('\n' , metadump.stdout_metadump ? stderr : stdout);
@@ -3235,7 +3234,7 @@ metadump_f(while (iocur_sp > start_iocur_sp)pop_cur (); -release_metadump (); + metadump.mdops->release (); out:return 0 ;
Signature · 1 line
2.39.1
Re: [PATCH V2 08/23] metadump: Introduce metadump v1 operations
Quoted 182 lines · Chandan Babu R
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_ops->write()andmetadump_ops->release()respectively.Signed-off-by Chandan Babu R <[email protected]>--- db/metadump.c | 123 +++++++++++++++++++++++++------------------------- 1 file changed, 61 insertions(+), 62 deletions(-)db/metadump.c +59
-60@@ -151,59 +151,6 @@ print_progress(const char *fmt, ...) metadump.progress_since_warning = true; } -/* -* 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 @@ -240,15 +187,16 @@ write_buf(/* handle discontiguous buffers */ if (!buf->bbmap) { - ret =write_buf_segment (buf->data, buf->bb, buf->blen); + ret = metadump.mdops->write (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 (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;@@ -3010,7 +2958,7 @@ done: }static int -init_metadump (void ) +init_metadump_v1 (void ) { metadump.metablock = (xfs_metablock_t *)calloc (BBSIZE +1 ,BBSIZE );if (metadump.metablock ==NULL ) {@@ -3051,12 +2999,61 @@ 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, +xfs_daddr_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 = init_metadump_v1, + .write = write_metadump_v1, + .end_write = end_write_metadump_v1, + .release = release_metadump_v1, +}; + static int metadump_f( int argc,@@ -3193,7 +3190,9 @@ metadump_f( } } - ret =init_metadump (); + metadump.mdops = &metadump1_ops; + + ret = metadump.mdops->init ();if (ret) goto out;
db/metadump.c metadump_f( · line 3218
Quoted 5 lines
db/metadump.c +1
-1@@ -3216,7 +3215,7 @@ metadump_f(/* write the remaining index */ if (!exitcode) - exitcode =write_index () <0 ; + exitcode = metadump.mdops->end_write () <0 ;
Now that I see ->end_write in usage, I think it would be better named ->finish_dump or something like that. It's only called once, right?
--D
Quoted 15 lines
db/metadump.c +1
-1if (metadump.progress_since_warning)fputc ('\n' , metadump.stdout_metadump ? stderr : stdout);@@ -3235,7 +3234,7 @@ metadump_f(while (iocur_sp > start_iocur_sp)pop_cur (); -release_metadump (); + metadump.mdops->release (); out:return 0 ;Signature · 1 line
2.39.1
Re: [PATCH V2 08/23] metadump: Introduce metadump v1 operations
Quoted 184 lines · Darrick J. Wong
Quoted 183 lines · Chandan Babu R
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_ops->write()andmetadump_ops->release()respectively.Signed-off-by Chandan Babu R <[email protected]>--- db/metadump.c | 123 +++++++++++++++++++++++++------------------------- 1 file changed, 61 insertions(+), 62 deletions(-)db/metadump.c +59
-60@@ -151,59 +151,6 @@ print_progress(const char *fmt, ...) metadump.progress_since_warning = true; } -/* -* 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 @@ -240,15 +187,16 @@ write_buf(/* handle discontiguous buffers */ if (!buf->bbmap) { - ret =write_buf_segment (buf->data, buf->bb, buf->blen); + ret = metadump.mdops->write (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 (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;@@ -3010,7 +2958,7 @@ done: }static int -init_metadump (void ) +init_metadump_v1 (void ) { metadump.metablock = (xfs_metablock_t *)calloc (BBSIZE +1 ,BBSIZE );if (metadump.metablock ==NULL ) {@@ -3051,12 +2999,61 @@ 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, +xfs_daddr_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 = init_metadump_v1, + .write = write_metadump_v1, + .end_write = end_write_metadump_v1, + .release = release_metadump_v1, +}; + static int metadump_f( int argc,@@ -3193,7 +3190,9 @@ metadump_f( } } - ret =init_metadump (); + metadump.mdops = &metadump1_ops; + + ret = metadump.mdops->init ();if (ret) goto out;@@ -3216,7 +3215,7 @@ metadump_f(
Quoted 8 lines
db/metadump.c metadump_f( · line 3218
Quoted 4 lines
db/metadump.c +1
-1/* write the remaining index */ if (!exitcode) - exitcode =write_index () <0 ; + exitcode = metadump.mdops->end_write () <0 ;Now that I see ->end_write in usage, I think it would be better named ->finish_dump or something like that. It's only called once, right?
finish_dump() is a much better name for the callback. I will make the change before posting the next version of the patchset.
Signature · 1 line
chandan
PATCH v2 9/23 metadump: Rename XFS_MD_MAGIC to XFS_MD_MAGIC_V1
In reply to Chandan Babu R--- db/metadump.c | 2 +- include/xfs_metadump.h | 2 +- mdrestore/xfs_mdrestore.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
db/metadump.c +1 -1
@@ -2966,7 +2966,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 ;
include/xfs_metadump.h +1 -1
@@ -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;
mdrestore/xfs_mdrestore.c +1 -1
@@ -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) {
Signature · 1 line
2.39.1
PATCH v2 10/23 metadump: Define metadump v2 ondisk format structures and macros
In reply to Chandan Babu RThe corresponding metadump file's disk layout is as shown below,
|------------------------------|
| struct xfs_metadump_header |
|------------------------------|
| struct xfs_meta_extent 0 |
| Extent 0's data |
| struct xfs_meta_extent 1 |
| Extent 1's data |
| ... |
| struct xfs_meta_extent (n-1) |
| Extent (n-1)'s data |
|------------------------------|The "struct xfs_metadump_header" is followed by alternating series of "struct xfs_meta_extent" and the extent itself.
--- include/xfs_metadump.h | 58 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+)
include/xfs_metadump.h +58 -0
@@ -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,60 @@ typedef struct xfs_metablock {#define XFS_METADUMP_FULLBLOCKS (1 << 2)#define XFS_METADUMP_DIRTYLOG (1 << 3) +/* +* Metadump v2 +* +* The following diagram depicts the ondisk layout of the metadump v2 format. +* +* |------------------------------| +* | struct xfs_metadump_header | +* |------------------------------| +* | struct xfs_meta_extent 0 | +* | Extent 0's data | +* | struct xfs_meta_extent 1 | +* | Extent 1's data | +* | ... | +* | struct xfs_meta_extent (n-1) | +* | Extent (n-1)'s data | +* |------------------------------| +* +* The "struct xfs_metadump_header" is followed by alternating series of "struct +* xfs_meta_extent" and the extent itself. +*/ +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) +#define XFS_MD2_INCOMPAT_EXTERNALLOG (1 << 3) + +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_DEVICE_SHIFT 54 + +#define XME_ADDR_DADDR_MASK ((1ULL << XME_ADDR_DEVICE_SHIFT) - 1) + +/* Extent was copied from the data device */ +#define XME_ADDR_DATA_DEVICE (0ULL << XME_ADDR_DEVICE_SHIFT) +/* Extent was copied from the log device */ +#define XME_ADDR_LOG_DEVICE (1ULL << XME_ADDR_DEVICE_SHIFT) + +#define XME_ADDR_DEVICE_MASK (3ULL << XME_ADDR_DEVICE_SHIFT) +#endif /* _XFS_METADUMP_H_ */
Signature · 1 line
2.39.1
Re: [PATCH V2 10/23] metadump: Define metadump v2 ondisk format structures and macros
Quoted 62 lines · Chandan Babu R
The corresponding metadump file's disk layout is as shown below,
|------------------------------| | struct xfs_metadump_header | |------------------------------| | struct xfs_meta_extent 0 | | Extent 0's data | | struct xfs_meta_extent 1 | | Extent 1's data | | ... | | struct xfs_meta_extent (n-1) | | Extent (n-1)'s data | |------------------------------|The "struct
xfs_metadump_header" is followed by alternating series of "structxfs_meta_extent" and the extent itself.Signed-off-by Chandan Babu R <[email protected]>--- include/xfs_metadump.h | 58 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+)include/xfs_metadump.h +24
-0@@ -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,60 @@ typedef struct xfs_metablock {#define XFS_METADUMP_FULLBLOCKS (1 << 2)#define XFS_METADUMP_DIRTYLOG (1 << 3) +/* +* Metadump v2 +* +* The following diagram depicts the ondisk layout of the metadump v2 format. +* +* |------------------------------| +* | struct xfs_metadump_header | +* |------------------------------| +* | struct xfs_meta_extent 0 | +* | Extent 0's data | +* | struct xfs_meta_extent 1 | +* | Extent 1's data | +* | ... | +* | struct xfs_meta_extent (n-1) | +* | Extent (n-1)'s data | +* |------------------------------| +* +* The "struct xfs_metadump_header" is followed by alternating series of "struct +* xfs_meta_extent" and the extent itself. +*/ +struct xfs_metadump_header { +__be32 xmh_magic;
include/xfs_metadump.h typedef struct xfs_metablock { · line 59
Quoted 10 lines
include/xfs_metadump.h +10
-0+__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) +#define XFS_MD2_INCOMPAT_EXTERNALLOG (1 << 3)
Please document the meaning of these four flags.
/*
* User-supplied directory entry and extended attribute names have been
* obscured, and extended attribute values are zeroed to protect privacy. */
#define XFS_MD2_INCOMPAT_OBFUSCATED (1 << 0)
/* Full blocks have been dumped. */
#define XFS_MD2_INCOMPAT_FULLBLOCKS (1 << 1)
/* Log was dirty. */
#define XFS_MD2_INCOMPAT_DIRTYLOG (1 << 2)
/* Dump contains external log contents. */
#define XFS_MD2_INCOMPAT_EXTERNALLOG (1 << 3)
Otherwise looks fine to me.
--D
Quoted 28 lines
include/xfs_metadump.h +24
-0+ +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_DEVICE_SHIFT 54 + +#define XME_ADDR_DADDR_MASK ((1ULL << XME_ADDR_DEVICE_SHIFT) - 1) + +/* Extent was copied from the data device */ +#define XME_ADDR_DATA_DEVICE (0ULL << XME_ADDR_DEVICE_SHIFT) +/* Extent was copied from the log device */ +#define XME_ADDR_LOG_DEVICE (1ULL << XME_ADDR_DEVICE_SHIFT) + +#define XME_ADDR_DEVICE_MASK (3ULL << XME_ADDR_DEVICE_SHIFT) +#endif /* _XFS_METADUMP_H_ */ Signature · 1 line
2.39.1
Re: [PATCH V2 10/23] metadump: Define metadump v2 ondisk format structures and macros
Quoted 85 lines · Darrick J. Wong
Quoted 62 lines · Chandan Babu R
The corresponding metadump file's disk layout is as shown below,
|------------------------------| | struct xfs_metadump_header | |------------------------------| | struct xfs_meta_extent 0 | | Extent 0's data | | struct xfs_meta_extent 1 | | Extent 1's data | | ... | | struct xfs_meta_extent (n-1) | | Extent (n-1)'s data | |------------------------------|The "struct
xfs_metadump_header" is followed by alternating series of "structxfs_meta_extent" and the extent itself.Signed-off-by Chandan Babu R <[email protected]>--- include/xfs_metadump.h | 58 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+)include/xfs_metadump.h +24
-0@@ -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,60 @@ typedef struct xfs_metablock {#define XFS_METADUMP_FULLBLOCKS (1 << 2)#define XFS_METADUMP_DIRTYLOG (1 << 3) +/* +* Metadump v2 +* +* The following diagram depicts the ondisk layout of the metadump v2 format. +* +* |------------------------------| +* | struct xfs_metadump_header | +* |------------------------------| +* | struct xfs_meta_extent 0 | +* | Extent 0's data | +* | struct xfs_meta_extent 1 | +* | Extent 1's data | +* | ... | +* | struct xfs_meta_extent (n-1) | +* | Extent (n-1)'s data | +* |------------------------------| +* +* The "struct xfs_metadump_header" is followed by alternating series of "struct +* xfs_meta_extent" and the extent itself. +*/ +struct xfs_metadump_header { +__be32 xmh_magic;include/xfs_metadump.h typedef struct xfs_metablock { · line 59
Quoted 10 lines
include/xfs_metadump.h +10
-0+__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) +#define XFS_MD2_INCOMPAT_EXTERNALLOG (1 << 3)Please document the meaning of these four flags.
/*
* User-supplied directory entry and extended attribute names have been
* obscured, and extended attribute values are zeroed to protect privacy. */
#defineXFS_MD2_INCOMPAT_OBFUSCATED(1 << 0)/* Full blocks have been dumped. */
#defineXFS_MD2_INCOMPAT_FULLBLOCKS(1 << 1)
Quoted 8 lines
/* Log was dirty. */
#defineXFS_MD2_INCOMPAT_DIRTYLOG(1 << 2)/* Dump contains external log contents. */
#defineXFS_MD2_INCOMPAT_EXTERNALLOG(1 << 3)Otherwise looks fine to me.
Sure. I will add the required comments.
Signature · 1 line
chandan
PATCH v2 11/23 metadump: Define metadump ops for v2 format
In reply to Chandan Babu RThis commit adds functionality to dump metadata from an XFS filesystem in newly introduced v2 format.
--- db/metadump.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 71 insertions(+), 3 deletions(-)
db/metadump.c +71 -3
@@ -3054,6 +3054,70 @@ static struct metadump_ops metadump1_ops = { .release = release_metadump_v1, }; +static int +init_metadump_v2 (void ) +{ +struct xfs_metadump_header xmh = {0 }; +uint32_t compat_flags =0 ; + + xmh.xmh_magic =cpu_to_be32 (XFS_MD_MAGIC_V2 ); + xmh.xmh_version =2 ; + +if (metadump.obfuscate) + compat_flags |=XFS_MD2_INCOMPAT_OBFUSCATED ; +if (!metadump.zero_stale_data) + compat_flags |=XFS_MD2_INCOMPAT_FULLBLOCKS ; +if (metadump.dirty_log) + compat_flags |=XFS_MD2_INCOMPAT_DIRTYLOG ; + + xmh.xmh_compat_flags =cpu_to_be32 (compat_flags); + +if (fwrite (&xmh,sizeof (xmh),1 , metadump.outf) !=1 ) { +print_warning ("error writing to target file" ); +return -1 ; + } + +return 0 ; +} + +static int +write_metadump_v2 ( +enum typnm type, +char *data, +xfs_daddr_t off, +int len) +{ +struct xfs_meta_extent xme; +uint64_t addr; + + addr = off; +if (type ==TYP_LOG && + mp->m_logdev_targp->bt_bdev != mp->m_ddev_targp->bt_bdev) + addr |=XME_ADDR_LOG_DEVICE ; +else + addr |=XME_ADDR_DATA_DEVICE ; + + xme.xme_addr =cpu_to_be64 (addr); + xme.xme_len =cpu_to_be32 (len); + +if (fwrite (&xme,sizeof (xme),1 , metadump.outf) !=1 ) { +print_warning ("error writing to target file" ); +return -EIO ; + } + +if (fwrite (data, len <<BBSHIFT ,1 , metadump.outf) !=1 ) { +print_warning ("error writing to target file" ); +return -EIO ; + } + +return 0 ; +} + +static struct metadump_ops metadump2_ops = { + .init = init_metadump_v2, + .write = write_metadump_v2, +}; + static int metadump_f( int argc,
@@ -3190,7 +3254,10 @@ metadump_f( } } - metadump.mdops = &metadump1_ops; +if (metadump.version ==1 ) + metadump.mdops = &metadump1_ops; +else + metadump.mdops = &metadump2_ops; ret = metadump.mdops->init ();if (ret)
@@ -3214,7 +3281,7 @@ metadump_f( exitcode = !copy_log ();/* write the remaining index */ -if (!exitcode) +if (!exitcode && metadump.mdops->end_write) exitcode = metadump.mdops->end_write () <0 ;if (metadump.progress_since_warning)
@@ -3234,7 +3301,8 @@ metadump_f(while (iocur_sp > start_iocur_sp)pop_cur (); - metadump.mdops->release (); +if (metadump.mdops->release) + metadump.mdops->release (); out:return 0 ;
Signature · 1 line
2.39.1
Re: [PATCH V2 11/23] metadump: Define metadump ops for v2 format
Quoted 14 lines · Chandan Babu R
This commit adds functionality to dump metadata from an XFS filesystem in newly introduced v2 format.
Signed-off-by Chandan Babu R <[email protected]>--- db/metadump.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 71 insertions(+), 3 deletions(-)db/metadump.c +0
-0@@ -3054,6 +3054,70 @@ static struct metadump_ops metadump1_ops = { .release = release_metadump_v1,
db/metadump.c static struct metadump_ops metadump1_ops = { · line 3064
Quoted 10 lines
db/metadump.c +8
-0}; +static int +init_metadump_v2 (void ) +{ +struct xfs_metadump_header xmh = {0 }; +uint32_t compat_flags =0 ; + + xmh.xmh_magic =cpu_to_be32 (XFS_MD_MAGIC_V2 ); + xmh.xmh_version =2 ;
Shouldn't this be cpu_to_be32 as well?
--D
Quoted 93 lines
db/metadump.c +63
-3+ +if (metadump.obfuscate) + compat_flags |=XFS_MD2_INCOMPAT_OBFUSCATED ; +if (!metadump.zero_stale_data) + compat_flags |=XFS_MD2_INCOMPAT_FULLBLOCKS ; +if (metadump.dirty_log) + compat_flags |=XFS_MD2_INCOMPAT_DIRTYLOG ; + + xmh.xmh_compat_flags =cpu_to_be32 (compat_flags); + +if (fwrite (&xmh,sizeof (xmh),1 , metadump.outf) !=1 ) { +print_warning ("error writing to target file" ); +return -1 ; + } + +return 0 ; +} + +static int +write_metadump_v2 ( +enum typnm type, +char *data, +xfs_daddr_t off, +int len) +{ +struct xfs_meta_extent xme; +uint64_t addr; + + addr = off; +if (type ==TYP_LOG && + mp->m_logdev_targp->bt_bdev != mp->m_ddev_targp->bt_bdev) + addr |=XME_ADDR_LOG_DEVICE ; +else + addr |=XME_ADDR_DATA_DEVICE ; + + xme.xme_addr =cpu_to_be64 (addr); + xme.xme_len =cpu_to_be32 (len); + +if (fwrite (&xme,sizeof (xme),1 , metadump.outf) !=1 ) { +print_warning ("error writing to target file" ); +return -EIO ; + } + +if (fwrite (data, len <<BBSHIFT ,1 , metadump.outf) !=1 ) { +print_warning ("error writing to target file" ); +return -EIO ; + } + +return 0 ; +} + +static struct metadump_ops metadump2_ops = { + .init = init_metadump_v2, + .write = write_metadump_v2, +}; + static int metadump_f( int argc,@@ -3190,7 +3254,10 @@ metadump_f( } } - metadump.mdops = &metadump1_ops; +if (metadump.version ==1 ) + metadump.mdops = &metadump1_ops; +else + metadump.mdops = &metadump2_ops; ret = metadump.mdops->init ();if (ret)@@ -3214,7 +3281,7 @@ metadump_f( exitcode = !copy_log ();/* write the remaining index */ -if (!exitcode) +if (!exitcode && metadump.mdops->end_write) exitcode = metadump.mdops->end_write () <0 ;if (metadump.progress_since_warning)@@ -3234,7 +3301,8 @@ metadump_f(while (iocur_sp > start_iocur_sp)pop_cur (); - metadump.mdops->release (); +if (metadump.mdops->release) + metadump.mdops->release (); out:return 0 ;Signature · 1 line
2.39.1
Re: [PATCH V2 11/23] metadump: Define metadump ops for v2 format
Quoted 17 lines · Darrick J. Wong
Quoted 16 lines · Chandan Babu R
This commit adds functionality to dump metadata from an XFS filesystem in newly introduced v2 format.
Signed-off-by Chandan Babu R <[email protected]>--- db/metadump.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 71 insertions(+), 3 deletions(-)db/metadump.c +0
-0@@ -3054,6 +3054,70 @@ static struct metadump_ops metadump1_ops = { .release = release_metadump_v1, };
Quoted 11 lines
db/metadump.c static struct metadump_ops metadump1_ops = { · line 3064
Quoted 8 lines
db/metadump.c +8
-0+static int +init_metadump_v2 (void ) +{ +struct xfs_metadump_header xmh = {0 }; +uint32_t compat_flags =0 ; + + xmh.xmh_magic =cpu_to_be32 (XFS_MD_MAGIC_V2 ); + xmh.xmh_version =2 ;Shouldn't this be
cpu_to_be32as well?
Yes, I will fix this before posting the next version of the patchset.
Signature · 1 line
chandan
PATCH v2 12/23 xfs_db: Add support to read from external log device
In reply to Chandan Babu RThis commit introduces a new function set_log_cur() allowing xfs_db to read from an external log device. This is required by a future commit which will add the ability to dump metadata from external log devices.
--- db/io.c | 57 ++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 44 insertions(+), 13 deletions(-)
db/io.c +44 -13
@@ -508,18 +508,19 @@ write_cur(void) } -void -set_cur ( -const typ_t *type, -xfs_daddr_t blknum, -int len, -int ring_flag, -bbmap_t *bbmap) +static void +__set_cur ( +struct xfs_buftarg *btargp, +const typ_t *type, +xfs_daddr_t blknum, +int len, +int ring_flag, +bbmap_t *bbmap) { -struct xfs_buf *bp; -xfs_ino_t dirino; -xfs_ino_t ino; -uint16_t mode; +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;
@@ -548,11 +549,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 ; }
@@ -589,6 +590,36 @@ set_cur(ring_add (); } +void +set_cur ( +const typ_t *type, +xfs_daddr_t blknum, +int len, +int ring_flag, +bbmap_t *bbmap) +{ +__set_cur (mp->m_ddev_targp, type, blknum, len, ring_flag, bbmap); +} + +void +set_log_cur ( +const typ_t *type, +xfs_daddr_t blknum, +int len, +int ring_flag, +bbmap_t *bbmap) +{ +struct xfs_buftarg *btargp = mp->m_ddev_targp; + +if (mp->m_logdev_targp->bt_bdev != mp->m_ddev_targp->bt_bdev) { +ASSERT (mp->m_sb.sb_logstart ==0 ); + btargp = mp->m_logdev_targp; + } + +__set_cur (btargp, type, blknum, len, ring_flag, bbmap); +} + +void set_iocur_type (const typ_t *type)
Signature · 1 line
2.39.1
Re: [PATCH V2 12/23] xfs_db: Add support to read from external log device
Quoted 77 lines · Chandan Babu R
This commit introduces a new function
set_log_cur()allowingxfs_dbto read from an external log device. 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 <[email protected]>--- db/io.c | 57 ++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 44 insertions(+), 13 deletions(-)db/io.c +29
-13@@ -508,18 +508,19 @@ write_cur(void) } -void -set_cur ( -const typ_t *type, -xfs_daddr_t blknum, -int len, -int ring_flag, -bbmap_t *bbmap) +static void +__set_cur ( +struct xfs_buftarg *btargp, +const typ_t *type, +xfs_daddr_t blknum, +int len, +int ring_flag, +bbmap_t *bbmap) { -struct xfs_buf *bp; -xfs_ino_t dirino; -xfs_ino_t ino; -uint16_t mode; +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;@@ -548,11 +549,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 ; }@@ -589,6 +590,36 @@ set_cur(ring_add (); } +void +set_cur ( +const typ_t *type, +xfs_daddr_t blknum, +int len, +int ring_flag, +bbmap_t *bbmap) +{ +__set_cur (mp->m_ddev_targp, type, blknum, len, ring_flag, bbmap); +} + +void +set_log_cur( + const typ_t *type, + xfs_daddr_t blknum,
db/io.c set_cur( · line 617
Quoted 10 lines
db/io.c +10
-0+int len, + int ring_flag, + bbmap_t *bbmap) +{ + struct xfs_buftarg *btargp = mp->m_ddev_targp; + +if (mp->m_logdev_targp->bt_bdev != mp->m_ddev_targp->bt_bdev) { +ASSERT (mp->m_sb.sb_logstart ==0 ); + btargp = mp->m_logdev_targp; + }
I think this should print an error message if there isn't an external log device and then leave iocur_top unchanged:
if (mp->m_logdev_targp->bt_bdev == mp->m_ddev_targp->bt_bdev) {
fprintf(stderr, "no external log specified\n");
exitcode = 1;
return;
}
__set_cur(mp->m_logdev_targp, type, blknum, len, ring_flag, bbmap);because metadump shouldn't crash if there's an external log device but sb_logstart is zero. The superblock fields /could/ be corrupt, or other weird shenanigans are going on.
(Also it's a layering violation for the io cursors to know anything at all about the filesystem stored above them.)
--D
Quoted 11 lines
db/io.c +5
-0+ +__set_cur (btargp, type, blknum, len, ring_flag, bbmap); +} + +void set_iocur_type (const typ_t *type)Signature · 1 line
2.39.1
Re: [PATCH V2 12/23] xfs_db: Add support to read from external log device
Quoted 100 lines · Darrick J. Wong
Quoted 77 lines · Chandan Babu R
This commit introduces a new function
set_log_cur()allowingxfs_dbto read from an external log device. 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 <[email protected]>--- db/io.c | 57 ++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 44 insertions(+), 13 deletions(-)db/io.c +29
-13@@ -508,18 +508,19 @@ write_cur(void) } -void -set_cur ( -const typ_t *type, -xfs_daddr_t blknum, -int len, -int ring_flag, -bbmap_t *bbmap) +static void +__set_cur ( +struct xfs_buftarg *btargp, +const typ_t *type, +xfs_daddr_t blknum, +int len, +int ring_flag, +bbmap_t *bbmap) { -struct xfs_buf *bp; -xfs_ino_t dirino; -xfs_ino_t ino; -uint16_t mode; +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;@@ -548,11 +549,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 ; }@@ -589,6 +590,36 @@ set_cur(ring_add (); } +void +set_cur ( +const typ_t *type, +xfs_daddr_t blknum, +int len, +int ring_flag, +bbmap_t *bbmap) +{ +__set_cur (mp->m_ddev_targp, type, blknum, len, ring_flag, bbmap); +} + +void +set_log_cur( + const typ_t *type, + xfs_daddr_t blknum,db/io.c set_cur( · line 617
Quoted 10 lines
db/io.c +10
-0+int len, + int ring_flag, + bbmap_t *bbmap) +{ + struct xfs_buftarg *btargp = mp->m_ddev_targp; + +if (mp->m_logdev_targp->bt_bdev != mp->m_ddev_targp->bt_bdev) { +ASSERT (mp->m_sb.sb_logstart ==0 ); + btargp = mp->m_logdev_targp; + }I think this should print an error message if there isn't an external log device and then leave
iocur_topunchanged:if (mp->m_logdev_targp->bt_bdev == mp->m_ddev_targp->bt_bdev) { fprintf(stderr, "no external log specified\n"); exitcode = 1; return; } __set_cur(mp->m_logdev_targp, type, blknum, len, ring_flag, bbmap);
Quoted 7 lines
because metadump shouldn't crash if there's an external log device but
sb_logstartis zero. The superblock fields /could/ be corrupt, or other weird shenanigans are going on.(Also it's a layering violation for the io cursors to know anything at all about the filesystem stored above them.)
I agree with your review comment. I will make the required changes.
Signature · 1 line
chandan
PATCH v2 13/23 metadump: Add support for passing version option
In reply to Chandan Babu RThe new option allows the user to explicitly specify the version of metadump to use. However, we will default to using the v1 format.
--- db/io.h | 2 ++ db/metadump.c | 53 ++++++++++++++++++++++++++++++++++------- db/xfs_metadump.sh | 3 ++- man/man8/xfs_metadump.8 | 14 +++++++++++ 4 files changed, 62 insertions(+), 10 deletions(-)
db/io.h +2 -0
@@ -49,6 +49,8 @@ extern void push_cur_and_set_type(void);extern void write_cur (void );extern void set_cur (const struct typ *type,xfs_daddr_t blknum,int len,int ring_add,bbmap_t *bbmap); +extern void set_log_cur (const struct typ *type,xfs_daddr_t blknum, +int len,int ring_add,bbmap_t *bbmap);extern void ring_add (void );extern void set_iocur_type (const struct typ *type);extern void xfs_dummy_verify (struct xfs_buf *bp);
db/metadump.c +44 -9
120 lines not on this page · raw message
db/xfs_metadump.sh +2 -1
@@ -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
man/man8/xfs_metadump.8 +14 -0
@@ -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,12 @@ 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. +Metadump in v2 format is generated by default if the filesystem has an +external log and the metadump version to use is not explicitly mentioned. +.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 +143,11 @@ 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.
Signature · 1 line
2.39.1
PATCH v2 14/23 mdrestore: Declare boolean variables with bool type
In reply to Chandan Babu R--- mdrestore/xfs_mdrestore.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
mdrestore/xfs_mdrestore.c +6 -6
@@ -7,9 +7,9 @@#include "libxfs.h" #include "xfs_metadump.h" -static int show_progress =0 ; -static int show_info =0 ; -static int progress_since_warning =0 ; +static bool show_progress = false; +static bool show_info = false; +static bool progress_since_warning = false;static void fatal (const char *msg, ...)
@@ -35,7 +35,7 @@ print_progress(const char *fmt, ...)printf ("\r%-59s" , buf);fflush (stdout); - progress_since_warning =1 ; + progress_since_warning = true; }/*
@@ -202,10 +202,10 @@ main(while ((c =getopt (argc, argv,"giV" )) !=EOF ) {switch (c) {case 'g' : - show_progress =1 ; + show_progress = true;break ;case 'i' : - show_info =1 ; + show_info = true;break ;case 'V' :printf ("%s version %s\n" , progname,VERSION );
Signature · 1 line
2.39.1
Re: [PATCH V2 14/23] mdrestore: Declare boolean variables with bool type
Quoted 1 line · Chandan Babu R
Signed-off-by Chandan Babu R <[email protected]>
Looks good,
--D
Quoted 46 lines
--- mdrestore/xfs_mdrestore.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)mdrestore/xfs_mdrestore.c +6
-6@@ -7,9 +7,9 @@#include "libxfs.h" #include "xfs_metadump.h" -static int show_progress =0 ; -static int show_info =0 ; -static int progress_since_warning =0 ; +static bool show_progress = false; +static bool show_info = false; +static bool progress_since_warning = false;static void fatal (const char *msg, ...)@@ -35,7 +35,7 @@ print_progress(const char *fmt, ...)printf ("\r%-59s" , buf);fflush (stdout); - progress_since_warning =1 ; + progress_since_warning = true; }/* @@ -202,10 +202,10 @@ main(while ((c =getopt (argc, argv,"giV" )) !=EOF ) {switch (c) {case 'g' : - show_progress =1 ; + show_progress = true;break ;case 'i' : - show_info =1 ; + show_info = true;break ;case 'V' :printf ("%s version %s\n" , progname,VERSION );Signature · 1 line
2.39.1
PATCH v2 15/23 mdrestore: Define and use struct mdrestore
In reply to Chandan Babu RThis commit collects all state tracking variables in a new "struct mdrestore" structure. This is done to collect all the global variables in one place rather than having them spread across the file. A new structure member of type "struct mdrestore_ops *" will be added by a future commit to support the two versions of metadump.
--- mdrestore/xfs_mdrestore.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-)
mdrestore/xfs_mdrestore.c +17 -10
@@ -7,9 +7,11 @@#include "libxfs.h" #include "xfs_metadump.h" -static bool show_progress = false; -static bool show_info = false; -static bool progress_since_warning = false; +static struct mdrestore { +bool show_progress; +bool show_info; +bool 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 = true; + mdrestore.progress_since_warning = true; }/*
@@ -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 = false; + mdrestore.show_info = false; + mdrestore.progress_since_warning = false; + progname =basename (argv[0 ]);while ((c =getopt (argc, argv,"giV" )) !=EOF ) {switch (c) {case 'g' : - show_progress = true; + mdrestore.show_progress = true;break ;case 'i' : - show_info = true; + mdrestore.show_info = true;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],
Signature · 1 line
2.39.1
Re: [PATCH V2 15/23] mdrestore: Define and use struct mdrestore
Quoted 7 lines · Chandan Babu R
This commit collects all state tracking variables in a new "struct mdrestore" structure. This is done to collect all the global variables in one place rather than having them spread across the file. A new structure member of type "struct
mdrestore_ops*" will be added by a future commit to support the two versions of metadump.Signed-off-by Chandan Babu R <[email protected]>
Same comments as patch 4.
--D
Quoted 94 lines
--- mdrestore/xfs_mdrestore.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-)mdrestore/xfs_mdrestore.c +17
-10@@ -7,9 +7,11 @@#include "libxfs.h" #include "xfs_metadump.h" -static bool show_progress = false; -static bool show_info = false; -static bool progress_since_warning = false; +static struct mdrestore { +bool show_progress; +bool show_info; +bool 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 = true; + mdrestore.progress_since_warning = true; }/* @@ -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 = false; + mdrestore.show_info = false; + mdrestore.progress_since_warning = false; + progname =basename (argv[0 ]);while ((c =getopt (argc, argv,"giV" )) !=EOF ) {switch (c) {case 'g' : - show_progress = true; + mdrestore.show_progress = true;break ;case 'i' : - show_info = true; + mdrestore.show_info = true;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],Signature · 1 line
2.39.1
PATCH v2 16/23 mdrestore: Detect metadump v1 magic before reading the header
In reply to Chandan Babu RIn order to support both v1 and v2 versions of metadump, mdrestore will have to detect the format in which the metadump file has been stored on the disk and then read the ondisk structures accordingly. In a step in that direction, this commit splits the work of reading the metadump header from disk into two parts
1. Read the first 4 bytes containing the metadump magic code.
2. Read the remaining part of the header.
A future commit will take appropriate action based on the value of the magic code.
--- mdrestore/xfs_mdrestore.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-)
mdrestore/xfs_mdrestore.c +14 -3
@@ -198,6 +198,7 @@ main(int open_flags;struct stat statbuf;int is_target_file; +uint32_t magic;struct xfs_metablock mb; mdrestore.show_progress = false;
@@ -245,10 +246,20 @@ main(fatal ("cannot open source dump file\n" ); } -if (fread (&mb,sizeof (mb),1 , src_f) !=1 ) -fatal ("error reading from metadump file\n" ); -if (mb.mb_magic !=cpu_to_be32 (XFS_MD_MAGIC_V1 )) +if (fread (&magic,sizeof (magic),1 , src_f) !=1 ) +fatal ("Unable to read metadump magic from metadump file\n" ); + +switch (be32_to_cpu (magic)) { +case XFS_MD_MAGIC_V1 : + mb.mb_magic =cpu_to_be32 (XFS_MD_MAGIC_V1 ); +if (fread ((uint8_t *)&mb +sizeof (mb.mb_magic), +sizeof (mb) -sizeof (mb.mb_magic),1 , src_f) !=1 ) +fatal ("error reading from metadump file\n" ); +break ; +default :fatal ("specified file is not a metadata dump\n" ); +break ; + }if (mdrestore.show_info) {if (mb.mb_info &XFS_METADUMP_INFO_FLAGS ) {
Signature · 1 line
2.39.1
Re: [PATCH V2 16/23] mdrestore: Detect metadump v1 magic before reading the header
Quoted 8 lines · Chandan Babu R
In order to support both v1 and v2 versions of metadump, mdrestore will have to detect the format in which the metadump file has been stored on the disk and then read the ondisk structures accordingly. In a step in that direction, this commit splits the work of reading the metadump header from disk into two parts
1. Read the first 4 bytes containing the metadump magic code.
2. Read the remaining part of the header.
Quoted 4 lines
A future commit will take appropriate action based on the value of the magic code.
Signed-off-by Chandan Babu R <[email protected]>
Seems reasonable to me,
--D
Quoted 43 lines
--- mdrestore/xfs_mdrestore.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-)mdrestore/xfs_mdrestore.c +14
-3@@ -198,6 +198,7 @@ main(int open_flags;struct stat statbuf;int is_target_file; +uint32_t magic;struct xfs_metablock mb; mdrestore.show_progress = false;@@ -245,10 +246,20 @@ main(fatal ("cannot open source dump file\n" ); } -if (fread (&mb,sizeof (mb),1 , src_f) !=1 ) -fatal ("error reading from metadump file\n" ); -if (mb.mb_magic !=cpu_to_be32 (XFS_MD_MAGIC_V1 )) +if (fread (&magic,sizeof (magic),1 , src_f) !=1 ) +fatal ("Unable to read metadump magic from metadump file\n" ); + +switch (be32_to_cpu (magic)) { +case XFS_MD_MAGIC_V1 : + mb.mb_magic =cpu_to_be32 (XFS_MD_MAGIC_V1 ); +if (fread ((uint8_t *)&mb +sizeof (mb.mb_magic), +sizeof (mb) -sizeof (mb.mb_magic),1 , src_f) !=1 ) +fatal ("error reading from metadump file\n" ); +break ; +default :fatal ("specified file is not a metadata dump\n" ); +break ; + }if (mdrestore.show_info) {if (mb.mb_info &XFS_METADUMP_INFO_FLAGS ) {Signature · 1 line
2.39.1
PATCH v2 17/23 mdrestore: Add open_device(), read_header() and show_info() functions
In reply to Chandan Babu RThis commit moves functionality associated with opening the target device, reading metadump header information and printing information about the metadump into their respective functions. There are no functional changes made by this commit.
--- mdrestore/xfs_mdrestore.c | 141 +++++++++++++++++++++++--------------- 1 file changed, 85 insertions(+), 56 deletions(-)
mdrestore/xfs_mdrestore.c +85 -56
@@ -6,6 +6,7 @@#include "libxfs.h" #include "xfs_metadump.h" +#include <libfrog/platform.h> static struct mdrestore { bool show_progress;
@@ -40,8 +41,72 @@ print_progress(const char *fmt, ...) mdrestore.progress_since_warning = true; } +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 *md_fp) +{ + mb->mb_magic =cpu_to_be32 (XFS_MD_MAGIC_V1 ); + +if (fread ((uint8_t *)mb +sizeof (mb->mb_magic), +sizeof (*mb) -sizeof (mb->mb_magic),1 , md_fp) !=1 ) +fatal ("error reading from metadump file\n" ); +} + +static void +show_info ( +struct xfs_metablock *mb, +const char *md_file) +{ +if (mb->mb_info &XFS_METADUMP_INFO_FLAGS ) { +printf ("%s: %sobfuscated, %s log, %s metadata blocks\n" , + md_file, + 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" , md_file); + } +} +/* -* 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,9 +116,9 @@ print_progress(const char *fmt, ...)* src_f should be positioned just past a read the previously validated metablock */ static void -perform_restore ( -FILE *src_f, -int dst_fd, +restore ( +FILE *md_fp, +int ddev_fd,int is_target_file,const struct xfs_metablock *mbp) {
@@ -81,14 +146,15 @@ perform_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 , + md_fp) !=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 , md_fp) !=1 )fatal ("error reading from metadump file\n" );libxfs_sb_from_disk (&sb, (struct xfs_dsb *)block_buffer);
@@ -111,7 +177,7 @@ perform_restore(if (is_target_file) {/* ensure regular files are correctly sized */ -if (ftruncate (dst_fd, sb.sb_dblocks * sb.sb_blocksize)) +if (ftruncate (ddev_fd, sb.sb_dblocks * sb.sb_blocksize))fatal ("cannot set filesystem image size: %s\n" ,strerror (errno)); }else {
@@ -121,7 +187,7 @@ perform_restore(off64_t off; off = sb.sb_dblocks * sb.sb_blocksize -sizeof (lb); -if (pwrite (dst_fd, lb,sizeof (lb), off) <0 ) +if (pwrite (ddev_fd, lb,sizeof (lb), off) <0 )fatal ("failed to write last block, is target too " "small? (error: %s)\n" ,strerror (errno)); }
@@ -134,7 +200,7 @@ perform_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 (ddev_fd, &block_buffer[cur_index << mbp->mb_blocklog], block_size,be64_to_cpu (block_index[cur_index]) <<BBSHIFT ) <0 )
@@ -145,7 +211,7 @@ perform_restore(if (mb_count < max_indices)break ; -if (fread (metablock, block_size,1 , src_f) !=1 ) +if (fread (metablock, block_size,1 , md_fp) !=1 )fatal ("error reading from metadump file\n" ); mb_count =be16_to_cpu (metablock->mb_count);
@@ -155,7 +221,7 @@ perform_restore(fatal ("bad block count: %u\n" , mb_count);if (fread (block_buffer, mb_count << mbp->mb_blocklog, -1 , src_f) !=1 ) +1 , md_fp) !=1 )fatal ("error reading from metadump file\n" ); bytes_read += block_size + (mb_count << mbp->mb_blocklog);
@@ -172,7 +238,7 @@ perform_restore( offsetof(struct xfs_sb, sb_crc)); } -if (pwrite (dst_fd, block_buffer, sb.sb_sectsize,0 ) <0 ) +if (pwrite (ddev_fd, block_buffer, sb.sb_sectsize,0 ) <0 )fatal ("error writing primary superblock: %s\n" ,strerror (errno));free (metablock);
@@ -185,8 +251,6 @@ usage(void)exit (1 ); } -extern int platform_check_ismounted (char *,char *,struct stat *,int ); - int main( int argc,
@@ -195,9 +259,7 @@ main(FILE *src_f;int dst_fd;int c; -int open_flags; -struct stat statbuf; -int is_target_file; +bool is_target_file;uint32_t magic;struct xfs_metablock mb;
@@ -231,8 +293,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. */
@@ -251,10 +313,7 @@ main(switch (be32_to_cpu (magic)) {case XFS_MD_MAGIC_V1 : - mb.mb_magic =cpu_to_be32 (XFS_MD_MAGIC_V1 ); -if (fread ((uint8_t *)&mb +sizeof (mb.mb_magic), -sizeof (mb) -sizeof (mb.mb_magic),1 , src_f) !=1 ) -fatal ("error reading from metadump file\n" ); +read_header (&mb, src_f);break ;default :fatal ("specified file is not a metadata dump\n" );
@@ -262,16 +321,7 @@ main( }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 );
@@ -280,30 +330,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)
Signature · 1 line
2.39.1
Re: [PATCH V2 17/23] mdrestore: Add open_device(), read_header() and show_info() functions
Quoted 40 lines · Chandan Babu R
This commit moves functionality associated with opening the target device, reading metadump header information and printing information about the metadump into their respective functions. There are no functional changes made by this commit.
Signed-off-by Chandan Babu R <[email protected]>--- mdrestore/xfs_mdrestore.c | 141 +++++++++++++++++++++++--------------- 1 file changed, 85 insertions(+), 56 deletions(-)mdrestore/xfs_mdrestore.c +15
-0@@ -6,6 +6,7 @@#include "libxfs.h" #include "xfs_metadump.h" +#include <libfrog/platform.h> static struct mdrestore { bool show_progress;@@ -40,8 +41,72 @@ print_progress(const char *fmt, ...) mdrestore.progress_since_warning = true; } +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 */
mdrestore/xfs_mdrestore.c print_progress(const char *fmt, ...) · line 67
Quoted 10 lines
mdrestore/xfs_mdrestore.c +10
-0+ 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 ))
} else if (platform_check_ismounted(...)) ?
Quoted 60 lines
mdrestore/xfs_mdrestore.c +44
-4+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 *md_fp) +{ + mb->mb_magic =cpu_to_be32 (XFS_MD_MAGIC_V1 ); + +if (fread ((uint8_t *)mb +sizeof (mb->mb_magic), +sizeof (*mb) -sizeof (mb->mb_magic),1 , md_fp) !=1 ) +fatal ("error reading from metadump file\n" ); +} + +static void +show_info ( +struct xfs_metablock *mb, +const char *md_file) +{ +if (mb->mb_info &XFS_METADUMP_INFO_FLAGS ) { +printf ("%s: %sobfuscated, %s log, %s metadata blocks\n" , + md_file, + 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" , md_file); + } +} +/* -* 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,9 +116,9 @@ print_progress(const char *fmt, ...)* src_f should be positioned just past a read the previously validated metablock */ static void -perform_restore ( -FILE *src_f, -int dst_fd, +restore ( +FILE *md_fp, +int ddev_fd,int is_target_file,const struct xfs_metablock *mbp) {
mdrestore/xfs_mdrestore.c perform_restore( · line 150
Quoted 6 lines
mdrestore/xfs_mdrestore.c +2
-1@@ -81,14 +146,15 @@ perform_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 , + md_fp) !=1 )
Something I forgot to comment on in previous patches: Please don't indent the second line of an if test at the same level as the if body. It's much harder for me to distinguish the two. Compare:
if (fread(block_index, block_size - sizeof(struct xfs_metablock), 1,
md_fp) != 1)
fatal("error reading from metadump file\n");vs:
if (fread(block_index, block_size - sizeof(struct xfs_metablock), 1,
md_fp) != 1)
fatal("error reading from metadump file\n");Also, previous patches have done things like:
if (foocondition && barcondition && bazcondition) dosomething();
vs.
if (foocondition && barcondition && bazcondition) dosomething();
The code structure is easier to see at a glance, right? That's why the xfs and kernel style guidelines ask for distinct indentation levels. Please go back and fix all of that in the new code you're adding.
--D
Quoted 162 lines
mdrestore/xfs_mdrestore.c +14
-51fatal ("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 , md_fp) !=1 )fatal ("error reading from metadump file\n" );libxfs_sb_from_disk (&sb, (struct xfs_dsb *)block_buffer);@@ -111,7 +177,7 @@ perform_restore(if (is_target_file) {/* ensure regular files are correctly sized */ -if (ftruncate (dst_fd, sb.sb_dblocks * sb.sb_blocksize)) +if (ftruncate (ddev_fd, sb.sb_dblocks * sb.sb_blocksize))fatal ("cannot set filesystem image size: %s\n" ,strerror (errno)); }else {@@ -121,7 +187,7 @@ perform_restore(off64_t off; off = sb.sb_dblocks * sb.sb_blocksize -sizeof (lb); -if (pwrite (dst_fd, lb,sizeof (lb), off) <0 ) +if (pwrite (ddev_fd, lb,sizeof (lb), off) <0 )fatal ("failed to write last block, is target too " "small? (error: %s)\n" ,strerror (errno)); }@@ -134,7 +200,7 @@ perform_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 (ddev_fd, &block_buffer[cur_index << mbp->mb_blocklog], block_size,be64_to_cpu (block_index[cur_index]) <<BBSHIFT ) <0 )@@ -145,7 +211,7 @@ perform_restore(if (mb_count < max_indices)break ; -if (fread (metablock, block_size,1 , src_f) !=1 ) +if (fread (metablock, block_size,1 , md_fp) !=1 )fatal ("error reading from metadump file\n" ); mb_count =be16_to_cpu (metablock->mb_count);@@ -155,7 +221,7 @@ perform_restore(fatal ("bad block count: %u\n" , mb_count);if (fread (block_buffer, mb_count << mbp->mb_blocklog, -1 , src_f) !=1 ) +1 , md_fp) !=1 )fatal ("error reading from metadump file\n" ); bytes_read += block_size + (mb_count << mbp->mb_blocklog);@@ -172,7 +238,7 @@ perform_restore( offsetof(struct xfs_sb, sb_crc)); } -if (pwrite (dst_fd, block_buffer, sb.sb_sectsize,0 ) <0 ) +if (pwrite (ddev_fd, block_buffer, sb.sb_sectsize,0 ) <0 )fatal ("error writing primary superblock: %s\n" ,strerror (errno));free (metablock);@@ -185,8 +251,6 @@ usage(void)exit (1 ); } -extern int platform_check_ismounted (char *,char *,struct stat *,int ); - int main( int argc,@@ -195,9 +259,7 @@ main(FILE *src_f;int dst_fd;int c; -int open_flags; -struct stat statbuf; -int is_target_file; +bool is_target_file;uint32_t magic;struct xfs_metablock mb;@@ -231,8 +293,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. */ @@ -251,10 +313,7 @@ main(switch (be32_to_cpu (magic)) {case XFS_MD_MAGIC_V1 : - mb.mb_magic =cpu_to_be32 (XFS_MD_MAGIC_V1 ); -if (fread ((uint8_t *)&mb +sizeof (mb.mb_magic), -sizeof (mb) -sizeof (mb.mb_magic),1 , src_f) !=1 ) -fatal ("error reading from metadump file\n" ); +read_header (&mb, src_f);break ;default :fatal ("specified file is not a metadata dump\n" );@@ -262,16 +321,7 @@ main( }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 );@@ -280,30 +330,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)Signature · 1 line
2.39.1
Re: [PATCH V2 17/23] mdrestore: Add open_device(), read_header() and show_info() functions
Quoted 45 lines · Darrick J. Wong
Quoted 44 lines · Chandan Babu R
This commit moves functionality associated with opening the target device, reading metadump header information and printing information about the metadump into their respective functions. There are no functional changes made by this commit.
Signed-off-by Chandan Babu R <[email protected]>--- mdrestore/xfs_mdrestore.c | 141 +++++++++++++++++++++++--------------- 1 file changed, 85 insertions(+), 56 deletions(-)mdrestore/xfs_mdrestore.c +19
-0@@ -6,6 +6,7 @@#include "libxfs.h" #include "xfs_metadump.h" +#include <libfrog/platform.h> static struct mdrestore { bool show_progress;@@ -40,8 +41,72 @@ print_progress(const char *fmt, ...) mdrestore.progress_since_warning = true; } +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 ;
Quoted 9 lines
mdrestore/xfs_mdrestore.c print_progress(const char *fmt, ...) · line 67
Quoted 6 lines
mdrestore/xfs_mdrestore.c +6
-0+ *is_file = true; + }else { +/* +* check to make sure a filesystem isn't mounted on the device +*/ +if (platform_check_ismounted (path,NULL , &statbuf,0 ))} else if (platform_check_ismounted(...)) ?
Ok.
Quoted 89 lines
Quoted 60 lines
mdrestore/xfs_mdrestore.c +44
-4+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 *md_fp) +{ + mb->mb_magic =cpu_to_be32 (XFS_MD_MAGIC_V1 ); + +if (fread ((uint8_t *)mb +sizeof (mb->mb_magic), +sizeof (*mb) -sizeof (mb->mb_magic),1 , md_fp) !=1 ) +fatal ("error reading from metadump file\n" ); +} + +static void +show_info ( +struct xfs_metablock *mb, +const char *md_file) +{ +if (mb->mb_info &XFS_METADUMP_INFO_FLAGS ) { +printf ("%s: %sobfuscated, %s log, %s metadata blocks\n" , + md_file, + 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" , md_file); + } +} +/* -* 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,9 +116,9 @@ print_progress(const char *fmt, ...)* src_f should be positioned just past a read the previously validated metablock */ static void -perform_restore ( -FILE *src_f, -int dst_fd, +restore ( +FILE *md_fp, +int ddev_fd,int is_target_file,const struct xfs_metablock *mbp) {mdrestore/xfs_mdrestore.c perform_restore( · line 150
Quoted 6 lines
mdrestore/xfs_mdrestore.c +2
-1@@ -81,14 +146,15 @@ perform_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 , + md_fp) !=1 )Something I forgot to comment on in previous patches: Please don't indent the second line of an if test at the same level as the if body. It's much harder for me to distinguish the two. Compare:
if (fread(block_index, block_size - sizeof(struct xfs_metablock), 1, md_fp) != 1) fatal("error reading from metadump file\n");vs:
if (fread(block_index, block_size - sizeof(struct xfs_metablock), 1, md_fp) != 1) fatal("error reading from metadump file\n");Also, previous patches have done things like:
if (foocondition && barcondition && bazcondition) dosomething();vs.
Quoted 8 lines
if (foocondition && barcondition && bazcondition) dosomething();The code structure is easier to see at a glance, right? That's why the xfs and kernel style guidelines ask for distinct indentation levels. Please go back and fix all of that in the new code you're adding.
Sorry, I will fix the indentation issues across the patchset.
Signature · 1 line
chandan
PATCH v2 18/23 mdrestore: Introduce struct mdrestore_ops
In reply to Chandan Babu RWe 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.
--- mdrestore/xfs_mdrestore.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-)
mdrestore/xfs_mdrestore.c +11 -3
@@ -8,10 +8,18 @@#include "xfs_metadump.h" #include <libfrog/platform.h> +struct mdrestore_ops { +void (*read_header)(void *header,FILE *md_fp); +void (*show_info)(void *header,const char *md_file); +void (*restore)(void *header,FILE *md_fp,int ddev_fd, +bool is_target_file); +}; +static struct mdrestore { -bool show_progress; -bool show_info; -bool progress_since_warning; +struct mdrestore_ops *mdrops; +bool show_progress; +bool show_info; +bool progress_since_warning; } mdrestore; static void
Signature · 1 line
2.39.1
PATCH v2 19/23 mdrestore: Replace metadump header pointer argument with generic pointer type
In reply to Chandan Babu RWe will need two variants of read_header(), show_info() and restore() helper functions to support two versions of metadump formats. To this end, A future commit will introduce a vector of function pointers to work with the two metadump formats. To have a common function signature for the function pointers, this commit replaces the first argument of the previously listed function pointers from "struct xfs_metablock *" with "void *".
--- mdrestore/xfs_mdrestore.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-)
mdrestore/xfs_mdrestore.c +17 -7
@@ -87,9 +87,11 @@ open_device(static void read_header ( -struct xfs_metablock *mb, +void *header,FILE *md_fp) { +struct xfs_metablock *mb = header; + mb->mb_magic =cpu_to_be32 (XFS_MD_MAGIC_V1 ); if (fread((uint8_t *)mb + sizeof(mb->mb_magic),
@@ -99,9 +101,11 @@ read_header(static void show_info ( -struct xfs_metablock *mb, +void *header,const char *md_file) { +struct xfs_metablock *mb = header; +if (mb->mb_info &XFS_METADUMP_INFO_FLAGS ) { printf("%s: %sobfuscated, %s log, %s metadata blocks\n", md_file,
@@ -125,12 +129,13 @@ show_info(*/ static void restore ( +void *header,FILE *md_fp,int ddev_fd, -int is_target_file, -const struct xfs_metablock *mbp) +int is_target_file) {struct xfs_metablock *metablock;/* header + index + blocks */ +struct xfs_metablock *mbp;__be64 *block_index;char *block_buffer;int block_size;
@@ -140,6 +145,8 @@ restore(xfs_sb_t sb;int64_t bytes_read; + mbp = header; + block_size =1 << mbp->mb_blocklog; max_indices = (block_size -sizeof (xfs_metablock_t)) /sizeof (__be64);
@@ -269,6 +276,7 @@ main(int c;bool is_target_file;uint32_t magic; +void *header;struct xfs_metablock mb; mdrestore.show_progress = false;
@@ -321,15 +329,17 @@ main(switch (be32_to_cpu (magic)) {case XFS_MD_MAGIC_V1 : -read_header (&mb, src_f); + header = &mb;break ;default :fatal ("specified file is not a metadata dump\n" );break ; } +read_header (header, src_f); +if (mdrestore.show_info) { -show_info (&mb, argv[optind]); +show_info (header, argv[optind]);if (argc - optind ==1 )exit (0 );
@@ -340,7 +350,7 @@ main(/* check and open target */ dst_fd =open_device (argv[optind], &is_target_file); -restore (src_f, dst_fd, is_target_file, &mb); +restore (header, src_f, dst_fd, is_target_file);close (dst_fd);if (src_f != stdin)
Signature · 1 line
2.39.1
Re: [PATCH V2 19/23] mdrestore: Replace metadump header pointer argument with generic pointer type
Quoted 17 lines · Chandan Babu R
We will need two variants of
read_header(),show_info()andrestore()helper functions to support two versions of metadump formats. To this end, A future commit will introduce a vector of function pointers to work with the two metadump formats. To have a common function signature for the function pointers, this commit replaces the first argument of the previously listed function pointers from "structxfs_metablock*" with "void *".Signed-off-by Chandan Babu R <[email protected]>--- mdrestore/xfs_mdrestore.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-)mdrestore/xfs_mdrestore.c +0
-0
mdrestore/xfs_mdrestore.c open_device( · line 90
Quoted 5 lines
mdrestore/xfs_mdrestore.c +1
-1@@ -87,9 +87,11 @@ open_device( static void read_header( - struct xfs_metablock *mb, + void *header,
Should we be using a union here instead of a generic void pointer?
union xfs_mdrestore_headers {
__be32 magic;
struct xfs_metablock v1;
struct xfs_metadump_header v2;
};Then you can do:
union xfs_mdrestore_headers headers;
fread(&headers.magic, sizeof(headers.magic), 1, md_fp));
switch (be32_to_cpu(headers.magic)) {
case XFS_MD_MAGIC_V1:
ret = dosomething_v1(&headers, ...);
break;
case XFS_MD_MAGIC_V2:
ret = dosomething_v2(&headers, ...);
break;And there'll be at least *some* typechecking going on here.
mdrestore/xfs_mdrestore.c open_device( · line 95
Quoted 5 lines
mdrestore/xfs_mdrestore.c +2
-0FILE *md_fp) { +struct xfs_metablock *mb = header; + mb->mb_magic =cpu_to_be32 (XFS_MD_MAGIC_V1 );
And no need for the casting:
static void
read_header_v1(
union xfs_mdrestore_headers *h,
FILE *md_fp)
{
fread(&h->v1.mb_count, sizeof(h->v1.mb_count), 1, md_fp);
...
}static void
read_header_v2(
union xfs_mdrestore_headers *h,
FILE *md_fp)
{
fread(&h->v2.xmh_version,
sizeof(struct xfs_metadump_header) - offsetof(struct xfs_metadump_header, xmh_version),
1, md_fp);
...
}--D
Quoted 80 lines
mdrestore/xfs_mdrestore.c +14
-6if (fread((uint8_t *)mb + sizeof(mb->mb_magic),@@ -99,9 +101,11 @@ read_header(static void show_info ( -struct xfs_metablock *mb, +void *header,const char *md_file) { +struct xfs_metablock *mb = header; +if (mb->mb_info &XFS_METADUMP_INFO_FLAGS ) { printf("%s: %sobfuscated, %s log, %s metadata blocks\n", md_file,@@ -125,12 +129,13 @@ show_info(*/ static void restore ( +void *header,FILE *md_fp,int ddev_fd, -int is_target_file, -const struct xfs_metablock *mbp) +int is_target_file) {struct xfs_metablock *metablock;/* header + index + blocks */ +struct xfs_metablock *mbp;__be64 *block_index;char *block_buffer;int block_size;@@ -140,6 +145,8 @@ restore(xfs_sb_t sb;int64_t bytes_read; + mbp = header; + block_size =1 << mbp->mb_blocklog; max_indices = (block_size -sizeof (xfs_metablock_t)) /sizeof (__be64);@@ -269,6 +276,7 @@ main(int c;bool is_target_file;uint32_t magic; +void *header;struct xfs_metablock mb; mdrestore.show_progress = false;@@ -321,15 +329,17 @@ main(switch (be32_to_cpu (magic)) {case XFS_MD_MAGIC_V1 : -read_header (&mb, src_f); + header = &mb;break ;default :fatal ("specified file is not a metadata dump\n" );break ; } +read_header (header, src_f); +if (mdrestore.show_info) { -show_info (&mb, argv[optind]); +show_info (header, argv[optind]);if (argc - optind ==1 )exit (0 );@@ -340,7 +350,7 @@ main(/* check and open target */ dst_fd =open_device (argv[optind], &is_target_file); -restore (src_f, dst_fd, is_target_file, &mb); +restore (header, src_f, dst_fd, is_target_file);close (dst_fd);if (src_f != stdin)Signature · 1 line
2.39.1
Re: [PATCH V2 19/23] mdrestore: Replace metadump header pointer argument with generic pointer type
Quoted 67 lines · Darrick J. Wong
Quoted 17 lines · Chandan Babu R
We will need two variants of
read_header(),show_info()andrestore()helper functions to support two versions of metadump formats. To this end, A future commit will introduce a vector of function pointers to work with the two metadump formats. To have a common function signature for the function pointers, this commit replaces the first argument of the previously listed function pointers from "structxfs_metablock*" with "void *".Signed-off-by Chandan Babu R <[email protected]>--- mdrestore/xfs_mdrestore.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-)mdrestore/xfs_mdrestore.c +0
-0mdrestore/xfs_mdrestore.c open_device( · line 90
Quoted 5 lines
mdrestore/xfs_mdrestore.c +1
-1@@ -87,9 +87,11 @@ open_device( static void read_header( - struct xfs_metablock *mb, + void *header,Should we be using a union here instead of a generic void pointer?
union xfs_mdrestore_headers { __be32 magic; struct xfs_metablock v1; struct xfs_metadump_header v2; };Then you can do:
union xfs_mdrestore_headers headers; fread(&headers.magic, sizeof(headers.magic), 1, md_fp)); switch (be32_to_cpu(headers.magic)) { case XFS_MD_MAGIC_V1: ret = dosomething_v1(&headers, ...); break; case XFS_MD_MAGIC_V2: ret = dosomething_v2(&headers, ...); break;And there'll be at least *some* typechecking going on here.
mdrestore/xfs_mdrestore.c open_device( · line 95
Quoted 5 lines
mdrestore/xfs_mdrestore.c +2
-0FILE *md_fp) { +struct xfs_metablock *mb = header; + mb->mb_magic =cpu_to_be32 (XFS_MD_MAGIC_V1 );And no need for the casting:
static void
read_header_v1(union xfs_mdrestore_headers *h, FILE *md_fp) { fread(&h->v1.mb_count, sizeof(h->v1.mb_count), 1, md_fp); ... }static void
read_header_v2(
Quoted 9 lines
union xfs_mdrestore_headers *h,
FILE *md_fp)
{
fread(&h->v2.xmh_version,
sizeof(struct xfs_metadump_header) - offsetof(struct xfs_metadump_header, xmh_version),
1, md_fp);
...
}I agree with the above suggestions. I will apply them to the patchset.
Signature · 1 line
chandan
PATCH v2 20/23 mdrestore: Introduce mdrestore v1 operations
In reply to Chandan Babu RIn 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.
--- mdrestore/xfs_mdrestore.c | 39 ++++++++++++++++++--------------------- 1 file changed, 18 insertions(+), 21 deletions(-)
mdrestore/xfs_mdrestore.c +18 -21
@@ -86,7 +86,7 @@ open_device( }static void -read_header ( +read_header_v1 (void *header,FILE *md_fp) {
@@ -100,7 +100,7 @@ read_header( }static void -show_info ( +show_info_v1 (void *header,const char *md_file) {
@@ -117,24 +117,14 @@ show_info( } } -/* -* 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 ( +restore_v1 (void *header,FILE *md_fp,int ddev_fd, -int is_target_file) +bool is_target_file) { -struct xfs_metablock *metablock;/* header + index + blocks */ +struct xfs_metablock *metablock;struct xfs_metablock *mbp;__be64 *block_index;char *block_buffer;
@@ -259,6 +249,12 @@ restore(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 ) {
@@ -310,9 +306,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;
@@ -330,16 +326,17 @@ main(switch (be32_to_cpu (magic)) {case XFS_MD_MAGIC_V1 : header = &mb; + mdrestore.mdrops = &mdrestore_ops_v1;break ;default :fatal ("specified file is not a metadata dump\n" );break ; } -read_header (header, src_f); + mdrestore.mdrops->read_header (header, src_f);if (mdrestore.show_info) { -show_info (header, argv[optind]); + mdrestore.mdrops->show_info (header, argv[optind]);if (argc - optind ==1 )exit (0 );
@@ -350,7 +347,7 @@ main(/* check and open target */ dst_fd =open_device (argv[optind], &is_target_file); -restore (header, src_f, dst_fd, is_target_file); + mdrestore.mdrops->restore (header, src_f, dst_fd, is_target_file);close (dst_fd);if (src_f != stdin)
Signature · 1 line
2.39.1
Re: [PATCH V2 20/23] mdrestore: Introduce mdrestore v1 operations
Quoted 5 lines · Chandan Babu R
In order to indicate the version of metadump files that they can work with, this commit renames
read_header(),show_info()andrestore()functions toread_header_v1(),show_info_v1()andrestore_v1()respectively.Signed-off-by Chandan Babu R <[email protected]>
--D
Quoted 112 lines
--- mdrestore/xfs_mdrestore.c | 39 ++++++++++++++++++--------------------- 1 file changed, 18 insertions(+), 21 deletions(-)mdrestore/xfs_mdrestore.c +18
-21@@ -86,7 +86,7 @@ open_device( }static void -read_header ( +read_header_v1 (void *header,FILE *md_fp) {@@ -100,7 +100,7 @@ read_header( }static void -show_info ( +show_info_v1 (void *header,const char *md_file) {@@ -117,24 +117,14 @@ show_info( } } -/* -* 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 ( +restore_v1 (void *header,FILE *md_fp,int ddev_fd, -int is_target_file) +bool is_target_file) { -struct xfs_metablock *metablock;/* header + index + blocks */ +struct xfs_metablock *metablock;struct xfs_metablock *mbp;__be64 *block_index;char *block_buffer;@@ -259,6 +249,12 @@ restore(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 ) {@@ -310,9 +306,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;@@ -330,16 +326,17 @@ main(switch (be32_to_cpu (magic)) {case XFS_MD_MAGIC_V1 : header = &mb; + mdrestore.mdrops = &mdrestore_ops_v1;break ;default :fatal ("specified file is not a metadata dump\n" );break ; } -read_header (header, src_f); + mdrestore.mdrops->read_header (header, src_f);if (mdrestore.show_info) { -show_info (header, argv[optind]); + mdrestore.mdrops->show_info (header, argv[optind]);if (argc - optind ==1 )exit (0 );@@ -350,7 +347,7 @@ main(/* check and open target */ dst_fd =open_device (argv[optind], &is_target_file); -restore (header, src_f, dst_fd, is_target_file); + mdrestore.mdrops->restore (header, src_f, dst_fd, is_target_file);close (dst_fd);if (src_f != stdin)Signature · 1 line
2.39.1
PATCH v2 21/23 mdrestore: Extract target device size verification into a function
In reply to Chandan Babu RA future commit will need to perform the device size verification on an external log device. In preparation for this, this commit extracts the relevant portions into a new function. No functional changes have been introduced.
--- mdrestore/xfs_mdrestore.c | 43 +++++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 17 deletions(-)
mdrestore/xfs_mdrestore.c +26 -17
@@ -85,6 +85,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 void 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 (ddev_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 (ddev_fd, lb,sizeof (lb), off) <0 ) -fatal ("failed to write last block, is target too " -"small? (error: %s)\n" ,strerror (errno)); - } +verify_device_size (ddev_fd, is_target_file, sb.sb_dblocks, + sb.sb_blocksize); bytes_read =0 ;
Signature · 1 line
2.39.1
PATCH v2 22/23 mdrestore: Define mdrestore ops for v2 format
In reply to Chandan Babu RThis commit adds functionality to restore metadump stored in v2 format.
--- mdrestore/xfs_mdrestore.c | 251 +++++++++++++++++++++++++++++++++++--- 1 file changed, 233 insertions(+), 18 deletions(-)
mdrestore/xfs_mdrestore.c +233 -18
@@ -12,7 +12,8 @@ struct mdrestore_ops {void (*read_header)(void *header,FILE *md_fp);void (*show_info)(void *header,const char *md_file);void (*restore)(void *header,FILE *md_fp,int ddev_fd, -bool is_target_file); +bool is_data_target_file,int logdev_fd, +bool is_log_target_file); }; static struct mdrestore {
@@ -20,6 +21,7 @@ static struct mdrestore {bool show_progress;bool show_info;bool progress_since_warning; +bool external_log; } mdrestore; static void
@@ -143,10 +145,12 @@ show_info_v1(static void restore_v1 ( -void *header, -FILE *md_fp, -int ddev_fd, -bool is_target_file) +void *header, +FILE *md_fp, +int ddev_fd, +bool is_data_target_file, +int logdev_fd, +bool is_log_target_file) {struct xfs_metablock *metablock;struct xfs_metablock *mbp;
@@ -203,7 +207,7 @@ restore_v1( ((struct xfs_dsb *)block_buffer)->sb_inprogress =1 ; -verify_device_size (ddev_fd, is_target_file, sb.sb_dblocks, +verify_device_size (ddev_fd, is_data_target_file, sb.sb_dblocks, sb.sb_blocksize); bytes_read =0 ;
@@ -264,6 +268,195 @@ static struct mdrestore_ops mdrestore_ops_v1 = { .restore = restore_v1, }; +static void +read_header_v2 ( +void *header, +FILE *md_fp) +{ +struct xfs_metadump_header *xmh = header; +bool want_external_log; + + xmh->xmh_magic =cpu_to_be32 (XFS_MD_MAGIC_V2 ); + +if (fread ((uint8_t *)xmh +sizeof (xmh->xmh_magic), +sizeof (*xmh) -sizeof (xmh->xmh_magic),1 , md_fp) !=1 ) +fatal ("error reading from metadump file\n" ); + + want_external_log = !!(be32_to_cpu (xmh->xmh_incompat_flags) & +XFS_MD2_INCOMPAT_EXTERNALLOG ); + +if (want_external_log && !mdrestore.external_log) +fatal ("External Log device is required\n" ); +} + +static void +show_info_v2 ( +void *header, +const char *md_file) +{ +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, external log contents are %sdumped, %s metadata blocks,\n" , + md_file, + incompat_flags &XFS_MD2_INCOMPAT_OBFUSCATED ?"" :"not " , + incompat_flags &XFS_MD2_INCOMPAT_DIRTYLOG ?"dirty" :"clean" , + incompat_flags &XFS_MD2_INCOMPAT_EXTERNALLOG ?"" :"not " , + incompat_flags &XFS_MD2_INCOMPAT_FULLBLOCKS ?"full" :"zeroed" ); +} + +#define MDR_IO_BUF_SIZE (8 * 1024 * 1024) + +static void +dump_meta_extent ( +FILE *md_fp, +int dev_fd, +char *device, +void *buf, +uint64_t offset, +int len) +{ +int io_size; + + io_size =min (len,MDR_IO_BUF_SIZE ); + +do { +if (fread (buf, io_size,1 , md_fp) !=1 ) +fatal ("error reading from metadump file\n" ); +if (pwrite (dev_fd, buf, io_size, offset) <0 ) +fatal ("error writing to %s device at offset %llu: %s\n" , + device, offset,strerror (errno)); + len -= io_size; + offset += io_size; + + io_size =min (len, io_size); + }while (len); +} + +static void +restore_v2 ( +void *header, +FILE *md_fp, +int ddev_fd, +bool is_data_target_file, +int logdev_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 len; + + block_buffer =malloc (MDR_IO_BUF_SIZE ); +if (block_buffer ==NULL ) +fatal ("Unable to allocate input buffer memory\n" ); + +if (fread (&xme,sizeof (xme),1 , md_fp) !=1 ) +fatal ("error reading from metadump file\n" ); + +if (xme.xme_addr !=0 || xme.xme_len ==1 ) +fatal ("Invalid superblock disk address/length\n" ); + + len =BBTOB (be32_to_cpu (xme.xme_len)); + +if (fread (block_buffer, len,1 , md_fp) !=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" ); + + ((struct xfs_dsb *)block_buffer)->sb_inprogress =1 ; + +verify_device_size (ddev_fd, is_data_target_file, sb.sb_dblocks, + sb.sb_blocksize); + +if (sb.sb_logstart ==0 ) { +ASSERT (mdrestore.external_log == true); +verify_device_size (logdev_fd, is_log_target_file, sb.sb_logblocks, + sb.sb_blocksize); + } + +if (pwrite (ddev_fd, block_buffer, len,0 ) <0 ) +fatal ("error writing primary superblock: %s\n" , +strerror (errno)); + + bytes_read = len; + +do { +char *device; +int fd; + +if (fread (&xme,sizeof (xme),1 , md_fp) !=1 ) { +if (feof (md_fp)) +break ; +fatal ("error reading from metadump file\n" ); + } + + offset =BBTOB (be64_to_cpu (xme.xme_addr) &XME_ADDR_DADDR_MASK ); +switch (be64_to_cpu (xme.xme_addr) &XME_ADDR_DEVICE_MASK ) { +case XME_ADDR_DATA_DEVICE : + device ="data" ; + fd = ddev_fd; +break ; +case XME_ADDR_LOG_DEVICE : + device ="log" ; + fd = logdev_fd; +break ; +default : +fatal ("Invalid device found in metadump\n" ); +break ; + } + + len =BBTOB (be32_to_cpu (xme.xme_len)); + +dump_meta_extent (md_fp, fd, device, block_buffer, offset, len); + + bytes_read += len; + +if (mdrestore.show_progress) { +static int64_t mb_read; +int64_t mb_now = bytes_read >>20 ; + +if (mb_now != mb_read) { +print_progress ("%lld MB read" , mb_now); + mb_read = mb_now; + } + } + }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 (ddev_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,17 +469,24 @@ main( int argc, char **argv) { - FILE *src_f; -int dst_fd; -int c; -bool is_target_file; -uint32_t magic; -void *header; -struct xfs_metablock mb; +union { +struct xfs_metadump_header xmh; +struct xfs_metablock mb; + } md; +FILE *src_f; +char *logdev =NULL ; +void *header; +uint32_t magic; +int data_dev_fd; +int log_dev_fd; +int c; +bool is_data_dev_file; +bool is_log_dev_file; mdrestore.show_progress = false; mdrestore.show_info = false; mdrestore.progress_since_warning = false; + mdrestore.external_log = false; progname =basename (argv[0 ]);
@@ -332,11 +532,17 @@ main(if (fread (&magic,sizeof (magic),1 , src_f) !=1 )fatal ("Unable to read metadump magic from metadump file\n" ); + header = &md; +switch (be32_to_cpu (magic)) {case XFS_MD_MAGIC_V1 : - header = &mb; mdrestore.mdrops = &mdrestore_ops_v1;break ; + +case XFS_MD_MAGIC_V2 : + mdrestore.mdrops = &mdrestore_ops_v2; +break ; +default :fatal ("specified file is not a metadata dump\n" );break ;
@@ -353,12 +559,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 (mdrestore.external_log) +/* 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 (header, src_f, dst_fd, is_target_file); +close (data_dev_fd); +if (mdrestore.external_log) +close (log_dev_fd); -close (dst_fd);if (src_f != stdin)fclose (src_f);
Signature · 1 line
2.39.1
Re: [PATCH V2 22/23] mdrestore: Define mdrestore ops for v2 format
Quoted 31 lines · Chandan Babu R
This commit adds functionality to restore metadump stored in v2 format.
Signed-off-by Chandan Babu R <[email protected]>--- mdrestore/xfs_mdrestore.c | 251 +++++++++++++++++++++++++++++++++++--- 1 file changed, 233 insertions(+), 18 deletions(-)mdrestore/xfs_mdrestore.c +3
-1@@ -12,7 +12,8 @@ struct mdrestore_ops {void (*read_header)(void *header,FILE *md_fp);void (*show_info)(void *header,const char *md_file);void (*restore)(void *header,FILE *md_fp,int ddev_fd, -bool is_target_file); +bool is_data_target_file,int logdev_fd, +bool is_log_target_file); }; static struct mdrestore {@@ -20,6 +21,7 @@ static struct mdrestore {bool show_progress;bool show_info;bool progress_since_warning; +bool external_log; } mdrestore; static void@@ -143,10 +145,12 @@ show_info_v1(
mdrestore/xfs_mdrestore.c show_info_v1( · line 151
Quoted 10 lines
mdrestore/xfs_mdrestore.c +4
-4static void restore_v1( -void *header, -FILE *md_fp, -int ddev_fd, -bool is_target_file) + void *header, + FILE *md_fp, + int ddev_fd, + bool is_data_target_file,
Why does the indent level change here...
mdrestore/xfs_mdrestore.c show_info_v1( · line 156
Quoted 5 lines
mdrestore/xfs_mdrestore.c +2
-0+ int logdev_fd, + bool is_log_target_file) {struct xfs_metablock *metablock;struct xfs_metablock *mbp;
...but not here?
Quoted 47 lines
mdrestore/xfs_mdrestore.c +35
-1@@ -203,7 +207,7 @@ restore_v1( ((struct xfs_dsb *)block_buffer)->sb_inprogress =1 ; -verify_device_size (ddev_fd, is_target_file, sb.sb_dblocks, +verify_device_size (ddev_fd, is_data_target_file, sb.sb_dblocks, sb.sb_blocksize); bytes_read =0 ;@@ -264,6 +268,195 @@ static struct mdrestore_ops mdrestore_ops_v1 = { .restore = restore_v1, }; +static void +read_header_v2 ( +void *header, +FILE *md_fp) +{ +struct xfs_metadump_header *xmh = header; +bool want_external_log; + + xmh->xmh_magic =cpu_to_be32 (XFS_MD_MAGIC_V2 ); + +if (fread ((uint8_t *)xmh +sizeof (xmh->xmh_magic), +sizeof (*xmh) -sizeof (xmh->xmh_magic),1 , md_fp) !=1 ) +fatal ("error reading from metadump file\n" ); + + want_external_log = !!(be32_to_cpu (xmh->xmh_incompat_flags) & +XFS_MD2_INCOMPAT_EXTERNALLOG ); + +if (want_external_log && !mdrestore.external_log) +fatal ("External Log device is required\n" ); +} + +static void +show_info_v2 ( +void *header, +const char *md_file) +{ +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, external log contents are %sdumped, %s metadata blocks,\n", + md_file,
mdrestore/xfs_mdrestore.c static struct mdrestore_ops mdrestore_ops_v1 = { · line 314
Quoted 10 lines
mdrestore/xfs_mdrestore.c +10
-0+ incompat_flags &XFS_MD2_INCOMPAT_OBFUSCATED ?"" :"not " , + incompat_flags &XFS_MD2_INCOMPAT_DIRTYLOG ?"dirty" :"clean" , + incompat_flags &XFS_MD2_INCOMPAT_EXTERNALLOG ?"" :"not " , + incompat_flags & XFS_MD2_INCOMPAT_FULLBLOCKS ? "full":"zeroed"); +} + +#define MDR_IO_BUF_SIZE (8 * 1024 * 1024) + +static void +dump_meta_extent(
Aren't we restoring here? And not dumping?
Quoted 39 lines
mdrestore/xfs_mdrestore.c +39
-0+FILE *md_fp, + int dev_fd, + char *device, + void *buf, + uint64_t offset, + int len) +{ + int io_size; + + io_size =min (len,MDR_IO_BUF_SIZE ); + +do { +if (fread (buf, io_size,1 , md_fp) !=1 ) +fatal ("error reading from metadump file\n" ); +if (pwrite (dev_fd, buf, io_size, offset) <0 ) +fatal ("error writing to %s device at offset %llu: %s\n" , + device, offset,strerror (errno)); + len -= io_size; + offset += io_size; + + io_size =min (len, io_size); + }while (len); +} + +static void +restore_v2 ( +void *header, +FILE *md_fp, +int ddev_fd, +bool is_data_target_file, +int logdev_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 len;
mdrestore/xfs_mdrestore.c static struct mdrestore_ops mdrestore_ops_v1 = { · line 363
Quoted 10 lines
mdrestore/xfs_mdrestore.c +10
-0+ + block_buffer =malloc (MDR_IO_BUF_SIZE ); +if (block_buffer ==NULL ) +fatal ("Unable to allocate input buffer memory\n" ); + +if (fread (&xme,sizeof (xme),1 , md_fp) !=1 ) +fatal ("error reading from metadump file\n" ); + +if (xme.xme_addr !=0 || xme.xme_len ==1 ) +fatal ("Invalid superblock disk address/length\n" );
Shouldn't we check that xme_addr points to XME_ADDR_DATA_DEVICE?
Quoted 7 lines
mdrestore/xfs_mdrestore.c +7
-0+ len =BBTOB (be32_to_cpu (xme.xme_len)); + +if (fread (block_buffer, len,1 , md_fp) !=1 ) +fatal ("error reading from metadump file\n" ); + +libxfs_sb_from_disk (&sb, (struct xfs_dsb *)block_buffer); +
mdrestore/xfs_mdrestore.c static struct mdrestore_ops mdrestore_ops_v1 = { · line 381
Quoted 10 lines
mdrestore/xfs_mdrestore.c +10
-0+if (sb.sb_magicnum !=XFS_SB_MAGIC ) +fatal ("bad magic number for primary superblock\n" ); + + ((struct xfs_dsb *)block_buffer)->sb_inprogress =1 ; + +verify_device_size (ddev_fd, is_data_target_file, sb.sb_dblocks, + sb.sb_blocksize); + +if (sb.sb_logstart ==0 ) { +ASSERT (mdrestore.external_log == true);
This should be more graceful to users:
if (!mdrestore.external_log)
fatal("Filesystem has external log but -l not specified.\n");The rest looks ok to me.
--D
Quoted 161 lines
mdrestore/xfs_mdrestore.c +112
-12+verify_device_size (logdev_fd, is_log_target_file, sb.sb_logblocks, + sb.sb_blocksize); + } + +if (pwrite (ddev_fd, block_buffer, len,0 ) <0 ) +fatal ("error writing primary superblock: %s\n" , +strerror (errno)); + + bytes_read = len; + +do { +char *device; +int fd; + +if (fread (&xme,sizeof (xme),1 , md_fp) !=1 ) { +if (feof (md_fp)) +break ; +fatal ("error reading from metadump file\n" ); + } + + offset =BBTOB (be64_to_cpu (xme.xme_addr) &XME_ADDR_DADDR_MASK ); +switch (be64_to_cpu (xme.xme_addr) &XME_ADDR_DEVICE_MASK ) { +case XME_ADDR_DATA_DEVICE : + device ="data" ; + fd = ddev_fd; +break ; +case XME_ADDR_LOG_DEVICE : + device ="log" ; + fd = logdev_fd; +break ; +default : +fatal ("Invalid device found in metadump\n" ); +break ; + } + + len =BBTOB (be32_to_cpu (xme.xme_len)); + +dump_meta_extent (md_fp, fd, device, block_buffer, offset, len); + + bytes_read += len; + +if (mdrestore.show_progress) { +static int64_t mb_read; +int64_t mb_now = bytes_read >>20 ; + +if (mb_now != mb_read) { +print_progress ("%lld MB read" , mb_now); + mb_read = mb_now; + } + } + }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 (ddev_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,17 +469,24 @@ main( int argc, char **argv) { - FILE *src_f; -int dst_fd; -int c; -bool is_target_file; -uint32_t magic; -void *header; -struct xfs_metablock mb; +union { +struct xfs_metadump_header xmh; +struct xfs_metablock mb; + } md; +FILE *src_f; +char *logdev =NULL ; +void *header; +uint32_t magic; +int data_dev_fd; +int log_dev_fd; +int c; +bool is_data_dev_file; +bool is_log_dev_file; mdrestore.show_progress = false; mdrestore.show_info = false; mdrestore.progress_since_warning = false; + mdrestore.external_log = false; progname =basename (argv[0 ]);@@ -332,11 +532,17 @@ main(if (fread (&magic,sizeof (magic),1 , src_f) !=1 )fatal ("Unable to read metadump magic from metadump file\n" ); + header = &md; +switch (be32_to_cpu (magic)) {case XFS_MD_MAGIC_V1 : - header = &mb; mdrestore.mdrops = &mdrestore_ops_v1;break ; + +case XFS_MD_MAGIC_V2 : + mdrestore.mdrops = &mdrestore_ops_v2; +break ; +default :fatal ("specified file is not a metadata dump\n" );break ;@@ -353,12 +559,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 (mdrestore.external_log) +/* 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 (header, src_f, dst_fd, is_target_file); +close (data_dev_fd); +if (mdrestore.external_log) +close (log_dev_fd); -close (dst_fd);if (src_f != stdin)fclose (src_f);Signature · 1 line
2.39.1
Re: [PATCH V2 22/23] mdrestore: Define mdrestore ops for v2 format
Quoted 45 lines · Darrick J. Wong
Quoted 31 lines · Chandan Babu R
This commit adds functionality to restore metadump stored in v2 format.
Signed-off-by Chandan Babu R <[email protected]>--- mdrestore/xfs_mdrestore.c | 251 +++++++++++++++++++++++++++++++++++--- 1 file changed, 233 insertions(+), 18 deletions(-)mdrestore/xfs_mdrestore.c +3
-1@@ -12,7 +12,8 @@ struct mdrestore_ops {void (*read_header)(void *header,FILE *md_fp);void (*show_info)(void *header,const char *md_file);void (*restore)(void *header,FILE *md_fp,int ddev_fd, -bool is_target_file); +bool is_data_target_file,int logdev_fd, +bool is_log_target_file); }; static struct mdrestore {@@ -20,6 +21,7 @@ static struct mdrestore {bool show_progress;bool show_info;bool progress_since_warning; +bool external_log; } mdrestore; static void@@ -143,10 +145,12 @@ show_info_v1(mdrestore/xfs_mdrestore.c show_info_v1( · line 151
Quoted 10 lines
mdrestore/xfs_mdrestore.c +4
-4static void restore_v1( -void *header, -FILE *md_fp, -int ddev_fd, -bool is_target_file) + void *header, + FILE *md_fp, + int ddev_fd, + bool is_data_target_file,Why does the indent level change here...
Quoted 8 lines
mdrestore/xfs_mdrestore.c show_info_v1( · line 156
Quoted 5 lines
mdrestore/xfs_mdrestore.c +2
-0+ int logdev_fd, + bool is_log_target_file) {struct xfs_metablock *metablock;struct xfs_metablock *mbp;...but not here?
Sorry, I will fix this.
Quoted 51 lines
Quoted 51 lines
mdrestore/xfs_mdrestore.c +39
-1@@ -203,7 +207,7 @@ restore_v1( ((struct xfs_dsb *)block_buffer)->sb_inprogress =1 ; -verify_device_size (ddev_fd, is_target_file, sb.sb_dblocks, +verify_device_size (ddev_fd, is_data_target_file, sb.sb_dblocks, sb.sb_blocksize); bytes_read =0 ;@@ -264,6 +268,195 @@ static struct mdrestore_ops mdrestore_ops_v1 = { .restore = restore_v1, }; +static void +read_header_v2 ( +void *header, +FILE *md_fp) +{ +struct xfs_metadump_header *xmh = header; +bool want_external_log; + + xmh->xmh_magic =cpu_to_be32 (XFS_MD_MAGIC_V2 ); + +if (fread ((uint8_t *)xmh +sizeof (xmh->xmh_magic), +sizeof (*xmh) -sizeof (xmh->xmh_magic),1 , md_fp) !=1 ) +fatal ("error reading from metadump file\n" ); + + want_external_log = !!(be32_to_cpu (xmh->xmh_incompat_flags) & +XFS_MD2_INCOMPAT_EXTERNALLOG ); + +if (want_external_log && !mdrestore.external_log) +fatal ("External Log device is required\n" ); +} + +static void +show_info_v2 ( +void *header, +const char *md_file) +{ +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, external log contents are %sdumped, %s metadata blocks,\n" , + md_file, + incompat_flags &XFS_MD2_INCOMPAT_OBFUSCATED ?"" :"not " , + incompat_flags &XFS_MD2_INCOMPAT_DIRTYLOG ?"dirty" :"clean" , + incompat_flags &XFS_MD2_INCOMPAT_EXTERNALLOG ?"" :"not " , + incompat_flags &XFS_MD2_INCOMPAT_FULLBLOCKS ?"full" :"zeroed" );
Quoted 9 lines
mdrestore/xfs_mdrestore.c static struct mdrestore_ops mdrestore_ops_v1 = { · line 314
Quoted 6 lines
mdrestore/xfs_mdrestore.c +6
-0+} + +#define MDR_IO_BUF_SIZE (8 * 1024 * 1024) + +static void +dump_meta_extent(Aren't we restoring here? And not dumping?
You are right. I will rename the function to restore_meta_extent().
Quoted 43 lines
Quoted 43 lines
mdrestore/xfs_mdrestore.c +43
-0+FILE *md_fp, + int dev_fd, + char *device, + void *buf, + uint64_t offset, + int len) +{ + int io_size; + + io_size =min (len,MDR_IO_BUF_SIZE ); + +do { +if (fread (buf, io_size,1 , md_fp) !=1 ) +fatal ("error reading from metadump file\n" ); +if (pwrite (dev_fd, buf, io_size, offset) <0 ) +fatal ("error writing to %s device at offset %llu: %s\n" , + device, offset,strerror (errno)); + len -= io_size; + offset += io_size; + + io_size =min (len, io_size); + }while (len); +} + +static void +restore_v2 ( +void *header, +FILE *md_fp, +int ddev_fd, +bool is_data_target_file, +int logdev_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 len; + + block_buffer =malloc (MDR_IO_BUF_SIZE ); +if (block_buffer ==NULL ) +fatal ("Unable to allocate input buffer memory\n" );
Quoted 9 lines
mdrestore/xfs_mdrestore.c static struct mdrestore_ops mdrestore_ops_v1 = { · line 363
Quoted 6 lines
mdrestore/xfs_mdrestore.c +6
-0+ +if (fread (&xme,sizeof (xme),1 , md_fp) !=1 ) +fatal ("error reading from metadump file\n" ); + +if (xme.xme_addr !=0 || xme.xme_len ==1 ) +fatal ("Invalid superblock disk address/length\n" );Shouldn't we check that
xme_addrpoints toXME_ADDR_DATA_DEVICE?
Yes, you are right. I will add the check.
Quoted 20 lines
Quoted 7 lines
mdrestore/xfs_mdrestore.c +7
-0+ len =BBTOB (be32_to_cpu (xme.xme_len)); + +if (fread (block_buffer, len,1 , md_fp) !=1 ) +fatal ("error reading from metadump file\n" ); + +libxfs_sb_from_disk (&sb, (struct xfs_dsb *)block_buffer); +mdrestore/xfs_mdrestore.c static struct mdrestore_ops mdrestore_ops_v1 = { · line 381
Quoted 10 lines
mdrestore/xfs_mdrestore.c +10
-0+if (sb.sb_magicnum !=XFS_SB_MAGIC ) +fatal ("bad magic number for primary superblock\n" ); + + ((struct xfs_dsb *)block_buffer)->sb_inprogress =1 ; + +verify_device_size (ddev_fd, is_data_target_file, sb.sb_dblocks, + sb.sb_blocksize); + +if (sb.sb_logstart ==0 ) { +ASSERT (mdrestore.external_log == true);This should be more graceful to users:
Quoted 2 lines
if (!mdrestore.external_log)
fatal("Filesystem has external log but -l not specified.\n");mdrestore.external_log is set to true only when the user passes the -l option. Also, read_header_v2() would have already verified if the metadump file contains data captured from an external log device and that an external log device was indeed passed to the restore program. It should be impossible to have mdrestore.external_log set to false at this point in restore_v2(). Hence, I think a call to ASSERT() is more appropriate.
Signature · 1 line
chandan
Re: [PATCH V2 22/23] mdrestore: Define mdrestore ops for v2 format
Quoted 198 lines · Chandan Babu R
Quoted 45 lines · Darrick J. Wong
Quoted 31 lines · Chandan Babu R
This commit adds functionality to restore metadump stored in v2 format.
Signed-off-by Chandan Babu R <[email protected]>--- mdrestore/xfs_mdrestore.c | 251 +++++++++++++++++++++++++++++++++++--- 1 file changed, 233 insertions(+), 18 deletions(-)mdrestore/xfs_mdrestore.c +3
-1@@ -12,7 +12,8 @@ struct mdrestore_ops {void (*read_header)(void *header,FILE *md_fp);void (*show_info)(void *header,const char *md_file);void (*restore)(void *header,FILE *md_fp,int ddev_fd, -bool is_target_file); +bool is_data_target_file,int logdev_fd, +bool is_log_target_file); }; static struct mdrestore {@@ -20,6 +21,7 @@ static struct mdrestore {bool show_progress;bool show_info;bool progress_since_warning; +bool external_log; } mdrestore; static void@@ -143,10 +145,12 @@ show_info_v1(mdrestore/xfs_mdrestore.c show_info_v1( · line 151
Quoted 10 lines
mdrestore/xfs_mdrestore.c +4
-4static void restore_v1( -void *header, -FILE *md_fp, -int ddev_fd, -bool is_target_file) + void *header, + FILE *md_fp, + int ddev_fd, + bool is_data_target_file,Why does the indent level change here...
Quoted 8 lines
mdrestore/xfs_mdrestore.c show_info_v1( · line 156
Quoted 5 lines
mdrestore/xfs_mdrestore.c +2
-0+ int logdev_fd, + bool is_log_target_file) {struct xfs_metablock *metablock;struct xfs_metablock *mbp;...but not here?
Sorry, I will fix this.
Quoted 51 lines
Quoted 51 lines
mdrestore/xfs_mdrestore.c +39
-1@@ -203,7 +207,7 @@ restore_v1( ((struct xfs_dsb *)block_buffer)->sb_inprogress =1 ; -verify_device_size (ddev_fd, is_target_file, sb.sb_dblocks, +verify_device_size (ddev_fd, is_data_target_file, sb.sb_dblocks, sb.sb_blocksize); bytes_read =0 ;@@ -264,6 +268,195 @@ static struct mdrestore_ops mdrestore_ops_v1 = { .restore = restore_v1, }; +static void +read_header_v2 ( +void *header, +FILE *md_fp) +{ +struct xfs_metadump_header *xmh = header; +bool want_external_log; + + xmh->xmh_magic =cpu_to_be32 (XFS_MD_MAGIC_V2 ); + +if (fread ((uint8_t *)xmh +sizeof (xmh->xmh_magic), +sizeof (*xmh) -sizeof (xmh->xmh_magic),1 , md_fp) !=1 ) +fatal ("error reading from metadump file\n" ); + + want_external_log = !!(be32_to_cpu (xmh->xmh_incompat_flags) & +XFS_MD2_INCOMPAT_EXTERNALLOG ); + +if (want_external_log && !mdrestore.external_log) +fatal ("External Log device is required\n" ); +} + +static void +show_info_v2 ( +void *header, +const char *md_file) +{ +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, external log contents are %sdumped, %s metadata blocks,\n" , + md_file, + incompat_flags &XFS_MD2_INCOMPAT_OBFUSCATED ?"" :"not " , + incompat_flags &XFS_MD2_INCOMPAT_DIRTYLOG ?"dirty" :"clean" , + incompat_flags &XFS_MD2_INCOMPAT_EXTERNALLOG ?"" :"not " , + incompat_flags &XFS_MD2_INCOMPAT_FULLBLOCKS ?"full" :"zeroed" );Quoted 9 lines
mdrestore/xfs_mdrestore.c static struct mdrestore_ops mdrestore_ops_v1 = { · line 314
Quoted 6 lines
mdrestore/xfs_mdrestore.c +6
-0+} + +#define MDR_IO_BUF_SIZE (8 * 1024 * 1024) + +static void +dump_meta_extent(Aren't we restoring here? And not dumping?
You are right. I will rename the function to
restore_meta_extent().Quoted 43 lines
Quoted 43 lines
mdrestore/xfs_mdrestore.c +43
-0+FILE *md_fp, + int dev_fd, + char *device, + void *buf, + uint64_t offset, + int len) +{ + int io_size; + + io_size =min (len,MDR_IO_BUF_SIZE ); + +do { +if (fread (buf, io_size,1 , md_fp) !=1 ) +fatal ("error reading from metadump file\n" ); +if (pwrite (dev_fd, buf, io_size, offset) <0 ) +fatal ("error writing to %s device at offset %llu: %s\n" , + device, offset,strerror (errno)); + len -= io_size; + offset += io_size; + + io_size =min (len, io_size); + }while (len); +} + +static void +restore_v2 ( +void *header, +FILE *md_fp, +int ddev_fd, +bool is_data_target_file, +int logdev_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 len; + + block_buffer =malloc (MDR_IO_BUF_SIZE ); +if (block_buffer ==NULL ) +fatal ("Unable to allocate input buffer memory\n" );Quoted 9 lines
mdrestore/xfs_mdrestore.c static struct mdrestore_ops mdrestore_ops_v1 = { · line 363
Quoted 6 lines
mdrestore/xfs_mdrestore.c +6
-0+ +if (fread (&xme,sizeof (xme),1 , md_fp) !=1 ) +fatal ("error reading from metadump file\n" ); + +if (xme.xme_addr !=0 || xme.xme_len ==1 ) +fatal ("Invalid superblock disk address/length\n" );Shouldn't we check that
xme_addrpoints toXME_ADDR_DATA_DEVICE?Yes, you are right. I will add the check.
Quoted 20 lines
Quoted 7 lines
mdrestore/xfs_mdrestore.c +7
-0+ len =BBTOB (be32_to_cpu (xme.xme_len)); + +if (fread (block_buffer, len,1 , md_fp) !=1 ) +fatal ("error reading from metadump file\n" ); + +libxfs_sb_from_disk (&sb, (struct xfs_dsb *)block_buffer); +mdrestore/xfs_mdrestore.c static struct mdrestore_ops mdrestore_ops_v1 = { · line 381
Quoted 10 lines
mdrestore/xfs_mdrestore.c +10
-0+if (sb.sb_magicnum !=XFS_SB_MAGIC ) +fatal ("bad magic number for primary superblock\n" ); + + ((struct xfs_dsb *)block_buffer)->sb_inprogress =1 ; + +verify_device_size (ddev_fd, is_data_target_file, sb.sb_dblocks, + sb.sb_blocksize); + +if (sb.sb_logstart ==0 ) { +ASSERT (mdrestore.external_log == true);This should be more graceful to users:
Quoted 2 lines
if (!mdrestore.external_log) fatal("Filesystem has external log but -l not specified.\n");
Quoted 6 lines
mdrestore.external_log is set to true only when the user passes the -l option. Also,
read_header_v2()would have already verified if the metadump file contains data captured from an external log device and that an external log device was indeed passed to the restore program. It should be impossible to have mdrestore.external_log set to false at this point inrestore_v2(). Hence, I think a call toASSERT()is more appropriate.
Ah, ok. I would've expected ASSERT(logstart != 0 || external_log); but it's true that Dave more recently has been asking for conditional assertions to be structured the way you originally wrote it. Withdrawn. :)
--D
Quoted 2 lines
Signature · 1 line
chandan
PATCH v2 23/23 mdrestore: Add support for passing log device as an argument
In reply to Chandan Babu Rmetadump 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.
--- man/man8/xfs_mdrestore.8 | 8 ++++++++ mdrestore/xfs_mdrestore.c | 11 +++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-)
man/man8/xfs_mdrestore.8 +8 -0
@@ -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
mdrestore/xfs_mdrestore.c +9 -2
@@ -460,7 +460,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 ); }
@@ -490,7 +491,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 = true;
@@ -498,6 +499,10 @@ main(case 'i' : mdrestore.show_info = true;break ; +case 'l' : + logdev = optarg; + mdrestore.external_log = true; +break ;case 'V' :printf ("%s version %s\n" , progname,VERSION );exit (0 );
@@ -536,6 +541,8 @@ main(switch (be32_to_cpu (magic)) {case XFS_MD_MAGIC_V1 : +if (logdev !=NULL ) +usage (); mdrestore.mdrops = &mdrestore_ops_v1;break ;
Signature · 1 line
2.39.1
Re: [PATCH V2 23/23] mdrestore: Add support for passing log device as an argument
Quoted 5 lines · Chandan Babu R
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 <[email protected]>
Woot, thanks for working on this!
--D
Quoted 77 lines
--- man/man8/xfs_mdrestore.8 | 8 ++++++++ mdrestore/xfs_mdrestore.c | 11 +++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-)man/man8/xfs_mdrestore.8 +8
-0@@ -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 DIAGNOSTICSmdrestore/xfs_mdrestore.c +9
-2@@ -460,7 +460,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 ); }@@ -490,7 +491,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 = true;@@ -498,6 +499,10 @@ main(case 'i' : mdrestore.show_info = true;break ; +case 'l' : + logdev = optarg; + mdrestore.external_log = true; +break ;case 'V' :printf ("%s version %s\n" , progname,VERSION );exit (0 );@@ -536,6 +541,8 @@ main(switch (be32_to_cpu (magic)) {case XFS_MD_MAGIC_V1 : +if (logdev !=NULL ) +usage (); mdrestore.mdrops = &mdrestore_ops_v1;break ;Signature · 1 line
2.39.1
A message that is not in the archive (sent off-list or not yet received): 181e7cbefa39e2dc59f2564c25966ac0d05aa6530483b7eb5d649de9a3d1cf7f@mu.id
Re: [PATCH V2 23/23] mdrestore: Add support for passing log device as an argument
Quoted 13 lines · Chandan Babu R
Quoted 10 lines · Darrick J. Wong
Quoted 5 lines · Chandan Babu R
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 <[email protected]>Woot, thanks for working on this!
Reviewed-by Darrick J. Wong <[email protected]>Thanks a lot for reviewing the entire patchset.
Signature · 1 line
chandan
Quoted 8 lines · Chandan Babu R
Hi all,
This patch series extends metadump/mdrestore tools to be able to dump and restore contents of an external log device. It also adds the ability to copy larger blocks (e.g. 4096 bytes instead of 512 bytes) into the metadump file. These objectives are accomplished by introducing a new metadump file format.
Quoted 7 lines
I have tested the patchset by extending metadump/mdrestore tests in fstests to cover the newly introduced metadump v2 format. The tests can be found at
https://github.com/chandanr/xfstests/commits/metadump-v2.The patch series can also be obtained from
https://github.com/chandanr/xfsprogs-dev/commits/metadump-v2.
There is already a V2 on the list, why is this also tagged as V2?
Signature · 1 line
Carlos
Quoted 72 lines
Changelog:
V1 -> V2:
1. Introduce the new incompat flagXFS_MD2_INCOMPAT_EXTERNALLOGto indicate that the metadump file contains data obtained from an external log.
2. Interpret bits 54 and 55 of xfs_meta_extent.xme_addr as a counter such that 00 maps to the data device and 01 maps to the log device.
3. Define the new functionset_log_cur()to read from internal/external log device. This allows us to continue usingTYP_LOGto read from both internal and external log.
4. In order to support reading metadump from a pipe, mdrestore now reads the first four bytes of the header to determine the metadump version rather than reading the entire header in a single call tofread().
5. Add an ASCII diagram to describe metadump v2's ondisk layout inxfs_metadump.h.
6. Update metadump's man page to indicate that metadump in v2 format is generated by default if the filesystem has an external log and the metadump version to use is not explicitly mentioned on the command line.
7. Remove '_metadump' suffix from function pointer names in "structmetadump_ops".
8. Usexfs_daddr_ttype for declaring variables containing disk offset value.
9. Use bool type rather than int for variables holding a boolean value.
11. Remove unnecessary whitespace.Chandan Babu R (23):
metadump: Use boolean values true/false instead of 1/0
mdrestore: Fix logic used to check if target device is large enough
metadump: Declare boolean variables with bool type
metadump: Define and use struct metadump
metadump: Add initialization and release functions
metadump: Postpone invocation ofinit_metadump()
metadump: Introduce structmetadump_ops
metadump: Introduce metadump v1 operations
metadump: RenameXFS_MD_MAGICtoXFS_MD_MAGIC_V1
metadump: Define metadump v2 ondisk format structures and macros
metadump: Define metadump ops for v2 format
xfs_db: Add support to read from external log device
metadump: Add support for passing version option
mdrestore: Declare boolean variables with bool type
mdrestore: Define and use struct mdrestore
mdrestore: Detect metadump v1 magic before reading the header
mdrestore: Addopen_device(),read_header()andshow_info()functions
mdrestore: Introduce structmdrestore_ops
mdrestore: Replace metadump header pointer argument with generic
pointer type
mdrestore: Introduce mdrestore v1 operations
mdrestore: Extract target device size verification into a function
mdrestore: Define mdrestore ops for v2 format
mdrestore: Add support for passing log device as an argumentdb/io.c | 57 ++- db/io.h | 2 + db/metadump.c | 749 +++++++++++++++++++++++--------------- db/xfs_metadump.sh | 3 +- include/xfs_metadump.h | 60 ++- man/man8/xfs_mdrestore.8 | 8 + man/man8/xfs_metadump.8 | 14 + mdrestore/xfs_mdrestore.c | 497 +++++++++++++++++++------ 8 files changed, 985 insertions(+), 405 deletions(-)--
2.39.1
Quoted 14 lines · Carlos Maiolino
Quoted 13 lines · Chandan Babu R
Hi all,
This patch series extends metadump/mdrestore tools to be able to dump and restore contents of an external log device. It also adds the ability to copy larger blocks (e.g. 4096 bytes instead of 512 bytes) into the metadump file. These objectives are accomplished by introducing a new metadump file format.
I have tested the patchset by extending metadump/mdrestore tests in fstests to cover the newly introduced metadump v2 format. The tests can be found at
https://github.com/chandanr/xfstests/commits/metadump-v2.
Quoted 4 lines
Quoted 2 lines
The patch series can also be obtained from
https://github.com/chandanr/xfsprogs-dev/commits/metadump-v2.There is already a V2 on the list, why is this also tagged as V2?
The "v2" mentioned in "Metadump v2" refers to the newer version of metadump ondisk layout to support
1. Dumping metadata from external log device and
2. Dumping larger extents (4096 bytes instead of 512 bytes).
Signature · 1 line
chandan
Quoted 15 lines · Chandan Babu R
Quoted 14 lines · Carlos Maiolino
Quoted 13 lines · Chandan Babu R
Hi all,
This patch series extends metadump/mdrestore tools to be able to dump and restore contents of an external log device. It also adds the ability to copy larger blocks (e.g. 4096 bytes instead of 512 bytes) into the metadump file. These objectives are accomplished by introducing a new metadump file format.
I have tested the patchset by extending metadump/mdrestore tests in fstests to cover the newly introduced metadump v2 format. The tests can be found at
https://github.com/chandanr/xfstests/commits/metadump-v2.
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
The patch series can also be obtained from
https://github.com/chandanr/xfsprogs-dev/commits/metadump-v2.There is already a V2 on the list, why is this also tagged as V2?
The "v2" mentioned in "Metadump v2" refers to the newer version of metadump ondisk layout to support
Sorry the noise, I didn't get through the patches yet, just read 2 threads with the same subject (without spotting the actual V2 in the patch metadata). Thanks, my bad. :)
Quoted 5 lines
1. Dumping metadata from external log device and
2. Dumping larger extents (4096 bytes instead of 512 bytes).--
chandan