diff options
author | Christoph Hellwig <hch@lst.de> | 2012-11-15 17:20:37 -0500 |
---|---|---|
committer | Ben Myers <bpm@sgi.com> | 2012-11-19 21:11:24 -0500 |
commit | bc02e8693d875c2a9b0037cfd37fe0b726d26403 (patch) | |
tree | 6896726d63947779f941a4daf055da142ad07985 /fs/xfs | |
parent | 1813dd64057490e7a0678a885c4fe6d02f78bdc1 (diff) |
xfs: add CRC infrastructure
- add a mount feature bit for CRC enabled filesystems
- add some helpers for generating and verifying the CRCs
- add a copy_uuid helper
The checksumming helpers are loosely based on similar ones in sctp,
all other bits come from Dave Chinner.
Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Mark Tinguely <tinguely@sgi.com>
Signed-off-by: Ben Myers <bpm@sgi.com>
Diffstat (limited to 'fs/xfs')
-rw-r--r-- | fs/xfs/Kconfig | 1 | ||||
-rw-r--r-- | fs/xfs/uuid.h | 6 | ||||
-rw-r--r-- | fs/xfs/xfs_cksum.h | 63 | ||||
-rw-r--r-- | fs/xfs/xfs_linux.h | 1 | ||||
-rw-r--r-- | fs/xfs/xfs_sb.h | 7 |
5 files changed, 78 insertions, 0 deletions
diff --git a/fs/xfs/Kconfig b/fs/xfs/Kconfig index 6100ec0fa1d4..5a7ffe54f5d5 100644 --- a/fs/xfs/Kconfig +++ b/fs/xfs/Kconfig | |||
@@ -2,6 +2,7 @@ config XFS_FS | |||
2 | tristate "XFS filesystem support" | 2 | tristate "XFS filesystem support" |
3 | depends on BLOCK | 3 | depends on BLOCK |
4 | select EXPORTFS | 4 | select EXPORTFS |
5 | select LIBCRC32C | ||
5 | help | 6 | help |
6 | XFS is a high performance journaling filesystem which originated | 7 | XFS is a high performance journaling filesystem which originated |
7 | on the SGI IRIX platform. It is completely multi-threaded, can | 8 | on the SGI IRIX platform. It is completely multi-threaded, can |
diff --git a/fs/xfs/uuid.h b/fs/xfs/uuid.h index 4732d71262cc..104db0f3bed6 100644 --- a/fs/xfs/uuid.h +++ b/fs/xfs/uuid.h | |||
@@ -26,4 +26,10 @@ extern int uuid_is_nil(uuid_t *uuid); | |||
26 | extern int uuid_equal(uuid_t *uuid1, uuid_t *uuid2); | 26 | extern int uuid_equal(uuid_t *uuid1, uuid_t *uuid2); |
27 | extern void uuid_getnodeuniq(uuid_t *uuid, int fsid [2]); | 27 | extern void uuid_getnodeuniq(uuid_t *uuid, int fsid [2]); |
28 | 28 | ||
29 | static inline void | ||
30 | uuid_copy(uuid_t *dst, uuid_t *src) | ||
31 | { | ||
32 | memcpy(dst, src, sizeof(uuid_t)); | ||
33 | } | ||
34 | |||
29 | #endif /* __XFS_SUPPORT_UUID_H__ */ | 35 | #endif /* __XFS_SUPPORT_UUID_H__ */ |
diff --git a/fs/xfs/xfs_cksum.h b/fs/xfs/xfs_cksum.h new file mode 100644 index 000000000000..fad1676ad8cd --- /dev/null +++ b/fs/xfs/xfs_cksum.h | |||
@@ -0,0 +1,63 @@ | |||
1 | #ifndef _XFS_CKSUM_H | ||
2 | #define _XFS_CKSUM_H 1 | ||
3 | |||
4 | #define XFS_CRC_SEED (~(__uint32_t)0) | ||
5 | |||
6 | /* | ||
7 | * Calculate the intermediate checksum for a buffer that has the CRC field | ||
8 | * inside it. The offset of the 32bit crc fields is passed as the | ||
9 | * cksum_offset parameter. | ||
10 | */ | ||
11 | static inline __uint32_t | ||
12 | xfs_start_cksum(char *buffer, size_t length, unsigned long cksum_offset) | ||
13 | { | ||
14 | __uint32_t zero = 0; | ||
15 | __uint32_t crc; | ||
16 | |||
17 | /* Calculate CRC up to the checksum. */ | ||
18 | crc = crc32c(XFS_CRC_SEED, buffer, cksum_offset); | ||
19 | |||
20 | /* Skip checksum field */ | ||
21 | crc = crc32c(crc, &zero, sizeof(__u32)); | ||
22 | |||
23 | /* Calculate the rest of the CRC. */ | ||
24 | return crc32c(crc, &buffer[cksum_offset + sizeof(__be32)], | ||
25 | length - (cksum_offset + sizeof(__be32))); | ||
26 | } | ||
27 | |||
28 | /* | ||
29 | * Convert the intermediate checksum to the final ondisk format. | ||
30 | * | ||
31 | * The CRC32c calculation uses LE format even on BE machines, but returns the | ||
32 | * result in host endian format. Hence we need to byte swap it back to LE format | ||
33 | * so that it is consistent on disk. | ||
34 | */ | ||
35 | static inline __le32 | ||
36 | xfs_end_cksum(__uint32_t crc) | ||
37 | { | ||
38 | return ~cpu_to_le32(crc); | ||
39 | } | ||
40 | |||
41 | /* | ||
42 | * Helper to generate the checksum for a buffer. | ||
43 | */ | ||
44 | static inline void | ||
45 | xfs_update_cksum(char *buffer, size_t length, unsigned long cksum_offset) | ||
46 | { | ||
47 | __uint32_t crc = xfs_start_cksum(buffer, length, cksum_offset); | ||
48 | |||
49 | *(__le32 *)(buffer + cksum_offset) = xfs_end_cksum(crc); | ||
50 | } | ||
51 | |||
52 | /* | ||
53 | * Helper to verify the checksum for a buffer. | ||
54 | */ | ||
55 | static inline int | ||
56 | xfs_verify_cksum(char *buffer, size_t length, unsigned long cksum_offset) | ||
57 | { | ||
58 | __uint32_t crc = xfs_start_cksum(buffer, length, cksum_offset); | ||
59 | |||
60 | return *(__le32 *)(buffer + cksum_offset) == xfs_end_cksum(crc); | ||
61 | } | ||
62 | |||
63 | #endif /* _XFS_CKSUM_H */ | ||
diff --git a/fs/xfs/xfs_linux.h b/fs/xfs/xfs_linux.h index 0a134ca5211c..fe7e4df85a7b 100644 --- a/fs/xfs/xfs_linux.h +++ b/fs/xfs/xfs_linux.h | |||
@@ -44,6 +44,7 @@ | |||
44 | #include <linux/kernel.h> | 44 | #include <linux/kernel.h> |
45 | #include <linux/blkdev.h> | 45 | #include <linux/blkdev.h> |
46 | #include <linux/slab.h> | 46 | #include <linux/slab.h> |
47 | #include <linux/crc32c.h> | ||
47 | #include <linux/module.h> | 48 | #include <linux/module.h> |
48 | #include <linux/mutex.h> | 49 | #include <linux/mutex.h> |
49 | #include <linux/file.h> | 50 | #include <linux/file.h> |
diff --git a/fs/xfs/xfs_sb.h b/fs/xfs/xfs_sb.h index f429d9d5d325..a05b45175fb0 100644 --- a/fs/xfs/xfs_sb.h +++ b/fs/xfs/xfs_sb.h | |||
@@ -81,6 +81,7 @@ struct xfs_mount; | |||
81 | #define XFS_SB_VERSION2_ATTR2BIT 0x00000008 /* Inline attr rework */ | 81 | #define XFS_SB_VERSION2_ATTR2BIT 0x00000008 /* Inline attr rework */ |
82 | #define XFS_SB_VERSION2_PARENTBIT 0x00000010 /* parent pointers */ | 82 | #define XFS_SB_VERSION2_PARENTBIT 0x00000010 /* parent pointers */ |
83 | #define XFS_SB_VERSION2_PROJID32BIT 0x00000080 /* 32 bit project id */ | 83 | #define XFS_SB_VERSION2_PROJID32BIT 0x00000080 /* 32 bit project id */ |
84 | #define XFS_SB_VERSION2_CRCBIT 0x00000100 /* metadata CRCs */ | ||
84 | 85 | ||
85 | #define XFS_SB_VERSION2_OKREALFBITS \ | 86 | #define XFS_SB_VERSION2_OKREALFBITS \ |
86 | (XFS_SB_VERSION2_LAZYSBCOUNTBIT | \ | 87 | (XFS_SB_VERSION2_LAZYSBCOUNTBIT | \ |
@@ -503,6 +504,12 @@ static inline int xfs_sb_version_hasprojid32bit(xfs_sb_t *sbp) | |||
503 | (sbp->sb_features2 & XFS_SB_VERSION2_PROJID32BIT); | 504 | (sbp->sb_features2 & XFS_SB_VERSION2_PROJID32BIT); |
504 | } | 505 | } |
505 | 506 | ||
507 | static inline int xfs_sb_version_hascrc(xfs_sb_t *sbp) | ||
508 | { | ||
509 | return (xfs_sb_version_hasmorebits(sbp) && | ||
510 | (sbp->sb_features2 & XFS_SB_VERSION2_CRCBIT)); | ||
511 | } | ||
512 | |||
506 | /* | 513 | /* |
507 | * end of superblock version macros | 514 | * end of superblock version macros |
508 | */ | 515 | */ |