From: Nathan Scott Date: Thu, 27 Apr 2006 15:40:54 +0000 (+0000) Subject: Backport xfs_repair from the xfs-cmds tree to IRIX to aid parallel repair merging... X-Git-Tag: v2.8.0~16 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=1552a82031e1682b34c92032ccba06eac662ae6a;p=thirdparty%2Fxfsprogs-dev.git Backport xfs_repair from the xfs-cmds tree to IRIX to aid parallel repair merging later. Merge of master-melb:xfs-cmds:25838a by kenmcd. --- diff --git a/doc/CHANGES b/doc/CHANGES index 83317b105..f31138781 100644 --- a/doc/CHANGES +++ b/doc/CHANGES @@ -1,3 +1,9 @@ +[cvs] + - Fix a case where xfs_repair could incorrectly flag extent + b+tree nodes as corrupt. + - Portability changes, get xfs_repair compiling on IRIX. + - Parent pointer updates in xfs_io checker command. + xfsprogs-2.7.17 (05 April 2006) - Fix libxfs access(2) check on /proc/mounts, which was causing issues when xfs_check/xfs_repair run on readonly diff --git a/include/darwin.h b/include/darwin.h index e7ff3a8b3..993e6109d 100644 --- a/include/darwin.h +++ b/include/darwin.h @@ -61,6 +61,49 @@ static __inline__ void platform_getoptreset(void) optreset = 0; } +static __inline__ int platform_uuid_compare(uuid_t *uu1, uuid_t *uu2) +{ + return uuid_compare(uu1, uu2, NULL); +} + +static __inline__ void platform_uuid_unparse(uuid_t *uu, char **buffer) +{ + uint32_t status; + char *str; + uuid_to_string(uu, &str, &status); + if (status == uuid_s_ok) + strcpy(buf, str); + else *buf = '\0'; + free(str); +} + +static __inline__ int platform_uuid_parse(char *buffer, uuid_t *uu) +{ + uint32_t status; + uuid_from_string(buffer, uu, &status); + return (status == uuid_s_ok); +} + +static __inline__ int platform_uuid_is_null(uuid_t *uu) +{ + return uuid_is_nil(uu, NULL); +} + +static __inline__ void platform_uuid_generate(uuid_t *uu) +{ + uuid_create(uu, NULL); +} + +static __inline__ void platform_uuid_clear(uuid_t *uu) +{ + uuid_create_nil(uu, NULL); +} + +static __inline__ void platform_uuid_copy(uuid_t *dst, uuid_t *src) +{ + memcpy(dst, src, sizeof(uuid_t)); +} + #define __int8_t int8_t #define __int16_t int16_t #define __int32_t int32_t diff --git a/include/freebsd.h b/include/freebsd.h index 4e7de5baf..1697f72c9 100644 --- a/include/freebsd.h +++ b/include/freebsd.h @@ -97,43 +97,47 @@ static __inline__ void platform_getoptreset(void) optind = 0; } -/* - * Implement Linux libuuid functions in terms of DEC DCE's uuid - * functions from FreeBSD libc. - */ - -static __inline__ int gnu_uuid_compare(uuid_t a, uuid_t b) +static __inline__ int platform_uuid_compare(uuid_t *uu1, uuid_t *uu2) { - return uuid_compare(&a, &b, NULL); + return uuid_compare(uu1, uu2, NULL); } -#define uuid_compare gnu_uuid_compare -static __inline__ int uuid_is_null(uuid_t uid) -{ - return uuid_is_nil(&uid, NULL); -} - -static __inline__ void uuid_unparse(uuid_t uid, char *buf) +static __inline__ void platform_uuid_unparse(uuid_t *uu, char **buffer) { uint32_t status; - char *str; - uuid_to_string(&uid, &str, &status); + char *s; + uuid_to_string(uu, &s, &status); if (status == uuid_s_ok) - strcpy(buf, str); - else *buf = '\0'; - free(str); + strcpy(*buffer, s); + else *buffer[0] = '\0'; + free(s); } -static __inline__ int gnu_uuid_parse(const char *buf, uuid_t *uid) +static __inline__ int platform_uuid_parse(char *buffer, uuid_t *uu) { uint32_t status; - uuid_from_string(buf, uid, &status); + uuid_from_string(buffer, uu, &status); return (status == uuid_s_ok); } -#define uuid_parse(s,u) gnu_uuid_parse((s), &(u)) -#define uuid_generate(uid) uuid_create(&(uid), NULL) -#define uuid_clear(uid) uuid_create_nil(&(uid), NULL) -#define uuid_copy(dst, src) memcpy(&(dst), &(src), sizeof(uuid_t)) +static __inline__ int platform_uuid_is_null(uuid_t *uu) +{ + return uuid_is_nil(uu, NULL); +} + +static __inline__ void platform_uuid_generate(uuid_t *uu) +{ + uuid_create(uu, NULL); +} + +static __inline__ void platform_uuid_clear(uuid_t *uu) +{ + uuid_create_nil(uu, NULL); +} + +static __inline__ void platform_uuid_copy(uuid_t *dst, uuid_t *src) +{ + memcpy(dst, src, sizeof(uuid_t)); +} #endif /* __XFS_FREEBSD_H__ */ diff --git a/include/irix.h b/include/irix.h index deca4bcd9..30fd0e9a4 100644 --- a/include/irix.h +++ b/include/irix.h @@ -122,12 +122,15 @@ typedef struct xfs_fsop_attrmulti_handlereq { #define __BYTE_ORDER BYTE_ORDER #define __BIG_ENDIAN BIG_ENDIAN #define __LITTLE_ENDIAN LITTLE_ENDIAN -#define __fswab16(x) (x) -#define __fswab32(x) (x) -#define __fswab64(x) (x) +#define HAVE_SWABMACROS 1 +#define INT_SWAP16(type,var) (var) +#define INT_SWAP32(type,var) (var) +#define INT_SWAP64(type,var) (var) /* Map some gcc macros for the MipsPRO compiler */ #ifndef __GNUC__ +#define __builtin_constant_p(x) (0) +#define __FUNCTION__ "XFS" #define __sgi__ __sgi #define __inline__ __inline #define inline __inline @@ -249,6 +252,53 @@ static __inline__ void platform_getoptreset(void) getoptreset(); } +static __inline__ int platform_uuid_compare(uuid_t *uu1, uuid_t *uu2) +{ + uint_t status; + return uuid_compare(uu1, uu2, &status); +} + +static __inline__ void platform_uuid_unparse(uuid_t *uu, char **buffer) +{ + uint_t status; + char *s; + uuid_to_string(uu, &s, &status); + if (status == uuid_s_ok) + strcpy(*buffer, s); + else *buffer[0] = '\0'; + free(s); +} + +static __inline__ int platform_uuid_parse(char *buffer, uuid_t *uu) +{ + uint_t status; + uuid_from_string(buffer, uu, &status); + return (status == uuid_s_ok); +} + +static __inline__ int platform_uuid_is_null(uuid_t *uu) +{ + uint status; + return uuid_is_nil(uu, &status); +} + +static __inline__ void platform_uuid_generate(uuid_t *uu) +{ + uint_t status; + uuid_create(uu, &status); +} + +static __inline__ void platform_uuid_clear(uuid_t *uu) +{ + uint_t status; + uuid_create_nil(uu, &status); +} + +static __inline__ void platform_uuid_copy(uuid_t *dst, uuid_t *src) +{ + memcpy(dst, src, sizeof(uuid_t)); +} + static __inline__ char * strsep(char **s, const char *ct) { char *sbegin = *s, *end; diff --git a/include/libxfs.h b/include/libxfs.h index 5df8b0d90..24d017302 100644 --- a/include/libxfs.h +++ b/include/libxfs.h @@ -505,6 +505,8 @@ extern void libxfs_dir2_free_log_bests (xfs_trans_t *, xfs_dabuf_t *, /* Shared utility routines */ extern unsigned int libxfs_log2_roundup(unsigned int i); +extern void cmn_err(int, char *, ...); +enum ce { CE_DEBUG, CE_CONT, CE_NOTE, CE_WARN, CE_ALERT, CE_PANIC }; #include #include diff --git a/include/libxlog.h b/include/libxlog.h index efea07053..fcdbadcd9 100644 --- a/include/libxlog.h +++ b/include/libxlog.h @@ -75,25 +75,9 @@ typedef union { #define unlikely(x) (x) #define min(a,b) ((a) < (b) ? (a) : (b)) -#if (__GNUC__ < 2) || ((__GNUC__ == 2) && (__GNUC_MINOR__ <= 95)) -# define xlog_warn(fmt,args...) \ - ( fprintf(stderr,fmt,## args), fputc('\n', stderr) ) -# define cmn_err(sev,fmt,args...) \ - xlog_warn(fmt,## args) -# define xlog_exit(fmt,args...) \ - ( xlog_warn(fmt,## args), exit(1) ) -# define xlog_panic(fmt,args...) \ - xlog_exit(fmt,## args) -#else -# define xlog_warn(...) \ - ( fprintf(stderr,__VA_ARGS__), fputc('\n', stderr) ) -# define cmn_err(sev,...) \ - xlog_warn(__VA_ARGS__) -# define xlog_exit(...) \ - ( xlog_warn(__VA_ARGS__), exit(1) ) -# define xlog_panic(...) \ - xlog_exit(__VA_ARGS__) -#endif +extern void xlog_warn(char *fmt,...); +extern void xlog_exit(char *fmt,...); +extern void xlog_panic(char *fmt,...); #define xlog_get_bp(log,bbs) libxfs_getbuf(x.logdev, 0, (bbs)) #define xlog_put_bp(bp) libxfs_putbuf(bp) diff --git a/include/linux.h b/include/linux.h index fa6005098..bc9ad4bf6 100644 --- a/include/linux.h +++ b/include/linux.h @@ -58,13 +58,20 @@ static __inline__ void platform_getoptreset(void) optind = 0; } -#ifndef O_DIRECT -# if defined (__powerpc__) -# define O_DIRECT 0400000 -# elif defined (__sparc__) -# define O_DIRECT 0x100000 -# endif -#endif +static __inline__ int platform_uuid_compare(uuid_t *uu1, uuid_t *uu2) +{ + return uuid_compare(*uu1, *uu2); +} + +static __inline__ void platform_uuid_unparse(uuid_t *uu, char **buffer) +{ + uuid_unparse(*uu, *buffer); +} + +static __inline__ int platform_uuid_is_null(uuid_t *uu) +{ + return uuid_is_null(*uu); +} #if (__GLIBC__ < 2) || ((__GLIBC__ == 2) && (__GLIBC_MINOR__ <= 1)) # define constpp const char * const * @@ -73,7 +80,7 @@ static __inline__ void platform_getoptreset(void) #endif #define ENOATTR ENODATA /* Attribute not found */ -#define EFSCORRUPTED 990 /* Filesystem is corrupted */ +#define EFSCORRUPTED EUCLEAN /* Filesystem is corrupted */ typedef loff_t xfs_off_t; typedef __uint64_t xfs_ino_t; diff --git a/libxfs/bit.c b/libxfs/bit.c index f75b6631a..f7c8d5976 100644 --- a/libxfs/bit.c +++ b/libxfs/bit.c @@ -98,44 +98,6 @@ static const char xfs_highbit[256] = { 7, 7, 7, 7, 7, 7, 7, 7, /* f8 .. ff */ }; -/* - * Count of bits set in byte, 0..8. - */ -static const char xfs_countbit[256] = { - 0, 1, 1, 2, 1, 2, 2, 3, /* 00 .. 07 */ - 1, 2, 2, 3, 2, 3, 3, 4, /* 08 .. 0f */ - 1, 2, 2, 3, 2, 3, 3, 4, /* 10 .. 17 */ - 2, 3, 3, 4, 3, 4, 4, 5, /* 18 .. 1f */ - 1, 2, 2, 3, 2, 3, 3, 4, /* 20 .. 27 */ - 2, 3, 3, 4, 3, 4, 4, 5, /* 28 .. 2f */ - 2, 3, 3, 4, 3, 4, 4, 5, /* 30 .. 37 */ - 3, 4, 4, 5, 4, 5, 5, 6, /* 38 .. 3f */ - 1, 2, 2, 3, 2, 3, 3, 4, /* 40 .. 47 */ - 2, 3, 3, 4, 3, 4, 4, 5, /* 48 .. 4f */ - 2, 3, 3, 4, 3, 4, 4, 5, /* 50 .. 57 */ - 3, 4, 4, 5, 4, 5, 5, 6, /* 58 .. 5f */ - 2, 3, 3, 4, 3, 4, 4, 5, /* 60 .. 67 */ - 3, 4, 4, 5, 4, 5, 5, 6, /* 68 .. 6f */ - 3, 4, 4, 5, 4, 5, 5, 6, /* 70 .. 77 */ - 4, 5, 5, 6, 5, 6, 6, 7, /* 78 .. 7f */ - 1, 2, 2, 3, 2, 3, 3, 4, /* 80 .. 87 */ - 2, 3, 3, 4, 3, 4, 4, 5, /* 88 .. 8f */ - 2, 3, 3, 4, 3, 4, 4, 5, /* 90 .. 97 */ - 3, 4, 4, 5, 4, 5, 5, 6, /* 98 .. 9f */ - 2, 3, 3, 4, 3, 4, 4, 5, /* a0 .. a7 */ - 3, 4, 4, 5, 4, 5, 5, 6, /* a8 .. af */ - 3, 4, 4, 5, 4, 5, 5, 6, /* b0 .. b7 */ - 4, 5, 5, 6, 5, 6, 6, 7, /* b8 .. bf */ - 2, 3, 3, 4, 3, 4, 4, 5, /* c0 .. c7 */ - 3, 4, 4, 5, 4, 5, 5, 6, /* c8 .. cf */ - 3, 4, 4, 5, 4, 5, 5, 6, /* d0 .. d7 */ - 4, 5, 5, 6, 5, 6, 6, 7, /* d8 .. df */ - 3, 4, 4, 5, 4, 5, 5, 6, /* e0 .. e7 */ - 4, 5, 5, 6, 5, 6, 6, 7, /* e8 .. ef */ - 4, 5, 5, 6, 5, 6, 6, 7, /* f0 .. f7 */ - 5, 6, 6, 7, 6, 7, 7, 8, /* f8 .. ff */ -}; - /* * xfs_lowbit32: get low bit set out of 32-bit argument, -1 if none set. */ diff --git a/libxfs/irix.c b/libxfs/irix.c index b060976a6..4371ab5d5 100644 --- a/libxfs/irix.c +++ b/libxfs/irix.c @@ -39,12 +39,6 @@ platform_set_blocksize(int fd, char *path, int blocksize) return; } -void -platform_get_blocksize(int fd, char *path) -{ - return BBSIZE; -} - void platform_flush_device(int fd, dev_t device) { diff --git a/libxfs/rdwr.c b/libxfs/rdwr.c index 06d26d2ff..2b26ccbdf 100644 --- a/libxfs/rdwr.c +++ b/libxfs/rdwr.c @@ -86,7 +86,7 @@ static void unmount_record(void *p) INT_SET(op->oh_res2, ARCH_CONVERT, 0); /* and the data for this op */ - memcpy(p + sizeof(xlog_op_header_t), &magic, sizeof(magic)); + memcpy((char *)p + sizeof(xlog_op_header_t), &magic, sizeof(magic)); } static xfs_caddr_t next(xfs_caddr_t ptr, int offset, void *private) diff --git a/libxfs/trans.c b/libxfs/trans.c index 18ec865ac..c72497877 100644 --- a/libxfs/trans.c +++ b/libxfs/trans.c @@ -391,11 +391,12 @@ libxfs_trans_get_buf( { xfs_buf_t *bp; xfs_buf_log_item_t *bip; - xfs_buftarg_t bdev = { dev }; + xfs_buftarg_t bdev; if (tp == NULL) return libxfs_getbuf(dev, d, len); + bdev.dev = dev; if (tp->t_items.lic_next == NULL) bp = xfs_trans_buf_item_match(tp, &bdev, d, len); else @@ -438,7 +439,7 @@ libxfs_trans_read_buf( xfs_buf_t *bp; xfs_buf_log_item_t *bip; int error; - xfs_buftarg_t bdev = { dev }; + xfs_buftarg_t bdev; if (tp == NULL) { bp = libxfs_getbuf(mp->m_dev, blkno, len); @@ -447,6 +448,7 @@ libxfs_trans_read_buf( return error; } + bdev.dev = dev; if (tp->t_items.lic_next == NULL) bp = xfs_trans_buf_item_match(tp, &bdev, blkno, len); else diff --git a/libxfs/util.c b/libxfs/util.c index 5f7d277cf..8d55b8799 100644 --- a/libxfs/util.c +++ b/libxfs/util.c @@ -18,6 +18,8 @@ #include #include +#include +#include /* * Change the requested timestamp in the given inode. @@ -737,7 +739,7 @@ libxfs_inode_alloc( *tp = ntp; if ((i = xfs_trans_reserve(*tp, 0, 0, 0, 0, 0))) { fprintf(stderr, _("%s: cannot reserve space: %s\n"), - progname, strerror(errno)); + progname, strerror(i)); exit(1); } xfs_trans_bjoin(*tp, ialloc_context); @@ -755,3 +757,40 @@ libxfs_inode_alloc( *ipp = ip; return error; } + +/* + * Userspace versions of common diagnostic routines (varargs fun). + */ +void +xfs_fs_repair_cmn_err(int level, xfs_mount_t *mp, char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + vfprintf(stderr, fmt, ap); + fprintf(stderr, " This is a bug.\n"); + fprintf(stderr, "Please report it to xfs@oss.sgi.com.\n"); + va_end(ap); +} + +void +xfs_fs_cmn_err(int level, xfs_mount_t *mp, char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + vfprintf(stderr, fmt, ap); + fputs("\n", stderr); + va_end(ap); +} + +void +cmn_err(int level, char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + vfprintf(stderr, fmt, ap); + fputs("\n", stderr); + va_end(ap); +} diff --git a/libxfs/xfs.h b/libxfs/xfs.h index 8b32a18be..39a363803 100644 --- a/libxfs/xfs.h +++ b/libxfs/xfs.h @@ -294,7 +294,6 @@ typedef struct { dev_t dev; } xfs_buftarg_t; #define spinlock_init(a,b) ((void) 0) #define spin_lock(a) ((void) 0) #define spin_unlock(a) ((void) 0) -#define __return_address __builtin_return_address(0) #define xfs_btree_reada_bufl(m,fsb,c) ((void) 0) #define xfs_btree_reada_bufs(m,fsb,c,x) ((void) 0) #define XFS_SB_LOCK(mp) 0 @@ -308,47 +307,32 @@ typedef struct { dev_t dev; } xfs_buftarg_t; #define XFS_TRANS_RESERVE_QUOTA_NBLKS(mp,tp,ip,nblks,ninos,fl) 0 #define XFS_TRANS_UNRESERVE_QUOTA_NBLKS(mp,tp,ip,nblks,ninos,fl) 0 -/* These are lifted from the kernel */ +#ifdef __GNUC__ +#define __return_address __builtin_return_address(0) #define get_unaligned(ptr) \ ({ __typeof__(*(ptr)) __tmp; memmove(&__tmp, (ptr), sizeof(*(ptr))); __tmp; }) - #define put_unaligned(val, ptr) \ ({ __typeof__(*(ptr)) __tmp = (val); \ memmove((ptr), &__tmp, sizeof(*(ptr))); \ (void)0; }) - -#define REPAIR_MESSAGE _(" This is a bug.\n" \ - "Please report it to linux-xfs@oss.sgi.com.\n") -#if (__GNUC__ < 2) || ((__GNUC__ == 2) && (__GNUC_MINOR__ <= 95)) -# define xfs_fs_repair_cmn_err(a,b,msg,args...) \ - ( fprintf(stderr, msg, ## args), fprintf(stderr, REPAIR_MESSAGE) ) -# define xfs_fs_cmn_err(a,b,msg,args...)( fprintf(stderr, msg, ## args) ) -# define cmn_err(a,msg,args...) ( fprintf(stderr, msg, ## args) ) -# define printk(msg,args...) ( fprintf(stderr, msg, ## args) ) #else -# define xfs_fs_repair_cmn_err(a,b,...) \ - ( fprintf(stderr, __VA_ARGS__), fprintf(stderr, REPAIR_MESSAGE) ) -# define xfs_fs_cmn_err(a,b,...) ( fprintf(stderr, __VA_ARGS__) ) -# define cmn_err(a,...) ( fprintf(stderr, __VA_ARGS__) ) -# define printk(...) ( fprintf(stderr, __VA_ARGS__) ) +#define get_unaligned(ptr) (*(ptr)) +#define put_unaligned(val, ptr) (*(ptr) = (val)) #endif -#define rol32(x,y) (((x) << (y)) | ((x) >> (32 - (y)))) -#define do_mod(a, b) ((a) % (b)) -#define do_div(n,base) ({ \ - int __res; \ - __res = ((unsigned long) n) % (unsigned) base; \ - n = ((unsigned long) n) / (unsigned) base; \ - __res; }) +extern void xfs_fs_repair_cmn_err(int, struct xfs_mount *, char *, ...); +extern void xfs_fs_cmn_err(int, struct xfs_mount *, char *, ...); -static inline int atomicIncWithWrap(int *a, int b) +static inline int __do_div(unsigned long long *n, unsigned base) { - int r = *a; - (*a)++; - if (*a == b) - *a = 0; - return r; + int __res; + __res = (int)(((unsigned long) *n) % (unsigned) base); + *n = ((unsigned long) *n) / (unsigned) base; + return __res; } +#define do_div(n,base) (__do_div(&(n), (base))) +#define do_mod(a, b) ((a) % (b)) +#define rol32(x,y) (((x) << (y)) | ((x) >> (32 - (y)))) /* diff --git a/libxlog/util.c b/libxlog/util.c index 694e954c4..e08f9f069 100644 --- a/libxlog/util.c +++ b/libxlog/util.c @@ -26,13 +26,13 @@ libxfs_init_t x; static int header_check_uuid(xfs_mount_t *mp, xlog_rec_header_t *head) { - char uu_log[64], uu_sb[64]; + char uu_log[64], uu_sb[64], *uup_log = &uu_log[0], *uup_sb = &uu_sb[0]; if (print_skip_uuid) return 0; - if (!uuid_compare(mp->m_sb.sb_uuid, head->h_fs_uuid)) return 0; + if (!platform_uuid_compare(&mp->m_sb.sb_uuid, &head->h_fs_uuid)) return 0; - uuid_unparse(mp->m_sb.sb_uuid, uu_sb); - uuid_unparse(head->h_fs_uuid, uu_log); + platform_uuid_unparse(&mp->m_sb.sb_uuid, &uup_sb); + platform_uuid_unparse(&head->h_fs_uuid, &uup_log); printf(_("* ERROR: mismatched uuid in log\n" "* SB : %s\n* log: %s\n"), @@ -82,7 +82,7 @@ xlog_header_check_recover(xfs_mount_t *mp, xlog_rec_header_t *head) int xlog_header_check_mount(xfs_mount_t *mp, xlog_rec_header_t *head) { - if (uuid_is_null(head->h_fs_uuid)) return 0; + if (platform_uuid_is_null(&head->h_fs_uuid)) return 0; if (header_check_uuid(mp, head)) { /* bail out now or just carry on regardless */ if (print_exit) @@ -90,3 +90,41 @@ xlog_header_check_mount(xfs_mount_t *mp, xlog_rec_header_t *head) } return 0; } + +/* + * Userspace versions of common diagnostic routines (varargs fun). + */ +void +xlog_warn(char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + vfprintf(stderr, fmt, ap); + fputs("\n", stderr); + va_end(ap); +} + +void +xlog_exit(char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + vfprintf(stderr, fmt, ap); + fputs("\n", stderr); + va_end(ap); + exit(1); +} + +void +xlog_panic(char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + vfprintf(stderr, fmt, ap); + fputs("\n", stderr); + va_end(ap); + abort(); +}