cluster/gfs/gfs_fsck fs_dir.c fs_dir.h metawal ...
CVSROOT: /cvs/cluster
Module name: cluster
Changes by: rpeterso at sourceware.org 2007-05-04 14:03:56
Modified files:
gfs/gfs_fsck : fs_dir.c fs_dir.h metawalk.c metawalk.h pass1.c pass2.c
Log message:
Resolves: bz 229484: gfs_fsck not good at fixing corrupt directory entries
Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/gfs/gfs_fsck/fs_dir.c.diff?cvsroot=cluster&r1=1.10&r2=1.11
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/gfs/gfs_fsck/fs_dir.h.diff?cvsroot=cluster&r1=1.3&r2=1.4
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/gfs/gfs_fsck/metawalk.c.diff?cvsroot=cluster&r1=1.9&r2=1.10
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/gfs/gfs_fsck/metawalk.h.diff?cvsroot=cluster&r1=1.3&r2=1.4
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/gfs/gfs_fsck/pass1.c.diff?cvsroot=cluster&r1=1.15&r2=1.16
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/gfs/gfs_fsck/pass2.c.diff?cvsroot=cluster&r1=1.14&r2=1.15
gfs/gfs_fsck/fs_dir.c +80 -2
@@ -2,7 +2,7 @@ ******************************************************************************* ** ** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. -** Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. +** Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved. ** ** This copyrighted material is made available to anyone wishing to use, ** modify, copy, or redistribute it subject to the terms and conditions
@@ -18,7 +18,8 @@#include "fs_inode.h" #include "bio.h" #include "link.h" - +#include "limits.h" +#include "metawalk.h" #include "fs_dir.h" #define IS_LEAF (1)
@@ -1633,6 +1634,34 @@/** +* put_leaf_nr - Put a leaf number associated with the index +* @dip: The GFS inode +* @index: +* @leaf_out: +* +* Returns: 0 on success, error code otherwise +*/ + +int put_leaf_nr (struct fsck_inode *dip,uint32 index,uint64 leaf_out) +{ +uint64 leaf_no; +int error =-1 ; + + leaf_no =cpu_to_gfs64 (leaf_out); + + error =writei (dip, (char *)&leaf_no, + index *sizeof (uint64),sizeof (uint64)); +if (error !=sizeof (uint64)){ +log_debug ("put_leaf_nr: Bad internal write. (rtn = %d)\n" , + error); +return (error <0 ) ? error : -EIO ; + } + +return 0 ; +} + + +/** * fs_filecmp - Compare two filenames * @file1: The first filename * @file2: The second filename
@@ -1685,3 +1714,52 @@return error; } + +/** +* dirent_repair - attempt to repair a corrupt directory entry. +* @bh - The buffer header that contains the bad dirent +* @de - The directory entry in native format +* @dent - The directory entry in on-disk format +* @type - Type of directory (DIR_LINEAR or DIR_EXHASH) +* @first - TRUE if this is the first dirent in the buffer +* +* This function tries to repair a corrupt directory entry. All we +* know@this point is that the length field is wrong. +*/ +int dirent_repair (struct fsck_inode *ip,osi_buf_t *bh,struct gfs_dirent *de, +struct gfs_dirent *dent,int type,int first) +{ +char *bh_end, *p; +int calc_de_name_len =0 ; + +/* If this is a sentinel, just fix the length and move on */ +if (first && !de->de_inum.no_formal_ino) {/* Is it a sentinel? */ +if (type ==DIR_LINEAR ) + de->de_rec_len =BH_SIZE (bh) - +sizeof (struct gfs_dinode ); +else + de->de_rec_len =BH_SIZE (bh) -sizeof (struct gfs_leaf ); + } +else { + bh_end =BH_DATA (bh) +BH_SIZE (bh); +/* first, figure out a probable name length */ + p = (char *)dent +sizeof (struct gfs_dirent ); +while (*p &&/* while there's a non-zero char and */ + p < bh_end) {/* not past end of buffer */ + calc_de_name_len++; + p++; + } +if (!calc_de_name_len) +return 1 ; +/* There can often be noise@the end, so only */ +/* Trust the shorter of the two in case we have too much */ +/* Or rather, only trust ours if it's shorter. */ +if (!de->de_name_len || de->de_name_len >NAME_MAX || + calc_de_name_len < de->de_name_len)/* if dent is hosed */ + de->de_name_len = calc_de_name_len;/* use ours */ + de->de_rec_len =GFS_DIRENT_SIZE (de->de_name_len); + } +gfs_dirent_out (de, (char *)dent); +write_buf (ip->i_sbd, bh,0 ); +return 0 ; +}
gfs/gfs_fsck/fs_dir.h +4 -1
@@ -2,7 +2,7 @@ ******************************************************************************* ** ** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. -** Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. +** Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved. ** ** This copyrighted material is made available to anyone wishing to use, ** modify, copy, or redistribute it subject to the terms and conditions
@@ -31,6 +31,7 @@int fsck_inode_is_stuffed (struct fsck_inode *ip);int dirent_first (osi_buf_t *bh,struct gfs_dirent **dent);int get_leaf_nr (struct fsck_inode *dip,uint32 index,uint64 *leaf_out); +int put_leaf_nr (struct fsck_inode *dip,uint32 index,uint64 leaf_out);int fs_filecmp (osi_filename_t *file1,char *file2,int len_of_file2);int fs_dirent_del (struct fsck_inode *dip,osi_buf_t *bh,osi_filename_t *filename); int fs_dir_add(struct fsck_inode *dip, osi_filename_t *filename,
@@ -39,5 +40,7 @@ int name_len, struct gfs_dirent **dent_out);int fs_dir_search (struct fsck_inode *dip,identifier_t *id,unsigned int *type); +int dirent_repair (struct fsck_inode *ip,osi_buf_t *bh,struct gfs_dirent *de, +struct gfs_dirent *dent,int type,int first);#endif /* __FS_DIR_H__ */
gfs/gfs_fsck/metawalk.c +104 -49
223 lines not on this page · raw message
gfs/gfs_fsck/metawalk.h +2 -2
@@ -1,7 +1,7 @@/***************************************************************************** ******************************************************************************* ** -** Copyright (C) 2005 Red Hat, Inc. All rights reserved. +** Copyright (C) 2005-2007 Red Hat, Inc. All rights reserved. ** ** This copyrighted material is made available to anyone wishing to use, ** modify, copy, or redistribute it subject to the terms and conditions
@@ -45,7 +45,7 @@struct metawalk_fxns {void *private;int (*check_leaf) (struct fsck_inode *ip,uint64_t block, -osi_buf_t **bh,void *private); +osi_buf_t *bh,void *private);int (*check_metalist) (struct fsck_inode *ip,uint64_t block,osi_buf_t **bh,void *private); int (*check_data) (struct fsck_inode *ip, uint64_t block,
gfs/gfs_fsck/pass1.c +5 -43
77 lines not on this page · raw message
gfs/gfs_fsck/pass2.c +4 -60
88 lines not on this page · raw message