[OracleOSS] [TitleIndex] [WordIndex]



Owner: TaoMa (Completed as of r1284)


The idea behind this feature is to store a copy of the super block in a known location so that it can be used in case someone accidentally overwrites the real superblock. This is important as the superblock stores few pieces of static or "mostly static" information that can be critical in recovering data. Some examples include blocksize, clustersize, sysdir location, rootdir location, file system generation, number of slots.

But before implementating this feature we need to decide on the "known" location or locations for the backup superblock. The location needs to match the following list of conditions:

File systems which have a set of backup super blocks should be marked with a compat flag. This way the mounted file system will know whether to write out new versions of the backup super block at the end of an online resize.

Backup Superblock Location

The backup superblock's location should not clash with the group descriptor as that is one of the two file system meta data blocks that have a fixed location based upon the cluster/block sizes. The other fixed block is the superblock.

After computing the group descriptor offsets for all block/cluster size combinations, we notice that there is no clash at the 1G, 4G, 16G, 64G, 256G and 1T byte offsets. Listed below is a table that shows the closest group descriptor offsets.

Byte Offset      Cluster  Block
1071644672       c=4K     b=512
1073741824                              1G
1086324736       c=4K     b=512                                                                                                                                                                                              ...
4290772992       c=8K     b=2K
4294967296                              4G
4301258752       c=4K     b=512                                                                                                                                                                                              ...
17175674880      c=8K     b=512
17179869184                             16G
17190354944      c=4K     b=512
68717379584      c=4K     b=512
68719476736                             64G
68732059648      c=4K     b=512
274873712640     c=8K     b=1K
274877906944                            256G
274884198400     c=4K     b=512
1099507433472    c=8K     b=512
1099511627776                           1T
1099522113536    c=4K     b=512

There are much benefit for these locations:


Here is the list of tools that need modifications.

Note: It will be better if one were to add the backup superblocks after the initial superblock has been flushed to disk. That way, the code to stamp the backup superblock can be added to libocfs2 can then be shared with tunefs. For more, refer to the mkfs code that adds the journals. The true superblock with the appropriate compat flag will be flushed only after all the backups have been flushed at their location.

Some consts and function prototypes

 * backup superblock flag is used to indicate that this volume
 * has backup superblocks.
#define OCFS2_FEATURE_COMPAT_BACKUP_SB          0x0001

/* The byte offset of the first backup block will be 1G.
 * The following will be 4G, 16G, 64G, 256G and 1T.
#define OCFS2_BACKUP_SB_START                   1 << 30

/* the max backup superblock nums */

static inline uint64_t ocfs2_backup_super_blkno(int blocksize, int index)
        uint64_t offset = OCFS2_BACKUP_SB_START;

        if (index >= 0 && index < OCFS2_MAX_BACKUP_SUPERBLOCKS) {
                offset <<= (2 * index);
                offset /= blocksize;
                return offset;

        return 0;

/* write the superblock at the specific block. */
errcode_t ocfs2_write_backup_super(ocfs2_filesys *fs, uint64_t blkno);

/* Get the blkno according to the file system info.
 * The unused ones, depending on the volume size, are zeroed.
 * Return the length of the block array.
int ocfs2_get_backup_super_offset(ocfs2_filesys *fs,
                                  uint64_t *blocks, size_t len);

/* This function will get the superblock pointed to by fs and copy it to
 * the blocks. But first it will ensure all the appropriate clusters are free.
 * If not, it will error out with ENOSPC. If free, it will set bits for all
 * the clusters, zero the clusters and write the backup sb.
 * In case of updating, it will override the backup blocks with the newest
 * superblock information.
errcode_t ocfs2_set_backup_super(ocfs2_filesys *fs,
                                 uint64_t *blocks, size_t len);

/* Refresh the backup superblock inoformation. */
errcode_t ocfs2_refresh_backup_super(ocfs2_filesys *fs,
                                     uint64_t *blocks, size_t len);

errcode_t ocfs2_read_backup_super(ocfs2_filesys *fs, int backup, char *sbbuf);

2012-11-08 13:01