The SnapFS File System HOWTO

Harrison Xing harrison@mountainviewdata.com , Eric Mei ericm@mountainviewdata.com , Peter J. Braam braam@mountainviewdata.com

v0.90, Mar 3, 2001.


This document explains the configuration and operation of the SnapFS file system on Linux.

1. Disclaimer and License

Copyright (C) 2001, Mountain View Data, Inc., All rights reserved.

SnapFS is an experimental file system. It contains kernel code and user level configure tools running with root permissions and is known to have bugs. Please back up all data when using or experimenting with SnapFS.

SnapFS is covered by the GPL. The GPL describes the warranties made to you, and can be found in the file COPYING. Mountain View Data plans to provide further management and configuration tools for SnapFS as a commercial product.

SnapFS is a file system derived from Lustre and InterMezzo and builds on the Ext3 journal file system and Linux EA (extended attribute code). All recent development on SnapFS was done by Mountain View Data, Inc.

2. Introduction

2.1 What is SnapFS?

SnapFS is a file system layer that enhances existing file systems such as Ext2 or journal file system like Ext3, ReiserFS with capabilities to retain multiple versions of files. We can do 'snapshot' at any time, thus we got the frozen data the the whole file system that time, even though the current file system continues to change.

The use of versioning can take two forms. The first is to retain snapshots, or frozen images, of the file system at certain points of time, for example, just before initiating a backup. The second usage is to retain all versions of files to comply with complete history requirements common in the financial industry.

SnapFS runs on top of an existing disk file system, in practice ext2, ext3, etc. When mounting a exist partition, say ext3, as file system type SnapFS instead of ext3, the SnapFS software starts managing all access to the file system. It intercept all write accesses to the file system and do necessary backup work.

2.2 Current Limitations

Performance

Currently we focus on features and functionality, so we did not fully optimize SnapFS . You may see certain operations are a little slower than the under layer file system.

File Systems Support

Now SnapFS support Ext2 and Ext3 file system on 2.2 series kernel. We plan to support XFS and possibly other file systems .

Number of Snapshots

Current version of SnapFS support 50 snapshots of one filesystem, the future version will support up to 128 snapshots at the same time.

Number of Snap Tables

Snap table is used by SnapFS to store the snapshot information such as the time when you make a snapshot. Current version of SnapFS support up to 32 snap tables.

3. Using SnapFS

Here we describe how to install SnapFS file system.

First you need download SnapFS sources and all the necessary components from Mountain View Data Inc.'s ftp site ftp://ftp.mountainviewdata.com/pub/snapfs/ or http://sourceforge.net/projects/snapfs/.

If you go to ftp.mountainviewdata.com/pub/snapfs, you should get the following:

  1. snapfs tarball.
  2. all the necessary patches under directory "patch"
  3. perl modules necessary for snapfs utility under directory "perl".

3.1 Installing the software

  1. Adding kernel patches

    You should apply some kernel patches to make SnapFS run, all patches mentioned here can be found on Mountain View Data Inc.'s ftp site ftp://ftp.mountainviewdata.com/pub/snapfs/. Of course you can also get the patches from their official site.

    Now SnapFS support Ext2 and Ext3 filesystems. If you want to run SnapFS upon Ext3, you should patch your kernel with Stephen's Ext3 patch http://www.kernel.org/pub/linux/kernel/people/sct/ext3/. Please note that Ext3 is under development and we only test snapfs with the version 0.0.5e, which need kernel 2.2.19pre6.

    You also need to apply extended attributes(EA) patch to the kernel, which could be found at http://acl.bestbits.at/download.html. The official EA patch only support Ext2, we provide another EA patch for Ext3 which can be found from snapfs's CVS repository.

    Note: Adding SnapFS support to Ext3 is more complicated, there are more patches you should apply. We will describe this clearly below.

    Suppose you have the official 2.2.18 kernel source at /usr/src/linux, and all the necessary patches at /root/patch, and SnapFS source is located at /root/snapfs.

    Example 1. You want to run SnapFS ONLY on Ext2:

      Add official EA patch
    
      # cd /usr/src/linux
      # patch -p1 < /root/patch/linux-2.2.18ea-0.7.7.patch
    
      Add SnapFS core patch and SnapFS for Ext2 patch
    
      # patch -p1 < /root/snapfs/snapfs22/fssupport/coresnap-0.06.patch
      # patch -p1 < /root/snapfs/snapfs22/fssupport/linux-2.2.18-ext2snap.patch
    

    Example 2. You want to run SnapFS ONLY on Ext3:

      Apply 2.2.19pre6 kernel patch which ext3 0.0.5e requires
    
      # cd /usr/src/linux
      # patch -p1 < /root/patch/pre-patch-2.2.19-6
    
      Add ext3 0.0.5e patch and ext3 related patches
    
      # patch -p1 < /root/patch/linux-2.2.19pre6.kdb.diff
      # patch -p1 < /root/patch/linux-2.2.19pre6.ext3.diff
      # patch -p1 < /root/patch/linux-2.2.19pre6.ext3syms.diff
      # patch -p1 < /root/patch/linux-2.2.19pre6.rootfstype.diff
      # patch -p1 < /root/patch/linux-2.2.19pre6.loopdiscard.diff
    
      Add EA patch and EA for Ext3 patch.Please note here you need a modified
     EA patch to eliminate its conflict with Ext3.
    
      # patch -p1 < /root/patch/linux-2.2.19pre6.ea-0.7.7.diff
      # patch -p1 < /root/patch/linux-2.2.19pre6.jfsnomodule.diff
      # patch -p1 < /root/patch/linux-2.2.19pre6.ea-0.7.5-ext3.diff
    
      Add SnapFS core patch and SnapFS for Ext3 patch
    
      # patch -p1 < /root/snapfs/snapfs22/fssupport/coresnap-0.06.patch
      # patch -p1 < /root/snapfs/snapfs22/fssupport/linux-2.2.19pre6ext3-ext3snap.patch
    

    Example 3. You want to run SnapFS on both Ext2 and Ext3:

      Besides all patches in Example 2, you only need to add SnapFS for Ext2 patch finally
    
      # patch -p1 < /root/snapfs/snapfs22/fssupport/linux-2.2.18-ext2snap.patch
    

  2. Rebuild the kernel

    You need config the kernel source with "make menuconfig" or so, check the following options with 'Yes':

    Code maturity level options -> Prompt for development and/or incomplete
    code/drivers (Y)
    Filesystems -> Extended filesystem attributes (EXPERIMENTAL) (Y)
    Filesystems -> Extended user attributes (Y)
    
    If you want to run SnapFS on Ext2, check following items with 'Yes':
    Filesystems -> Extended attributes for ext2 (DANGEROUS) (Y)
    
    If you want to run SnapFS on Ext3, check the following items with 'Yes':
    Filesystems -> Second extended fs development code (Y)
    Filesystems -> Extended attributes for ext3 (DANGEROUS) (Y)
    
    Then recompile your kernel and reboot with the new kernel image.

    # cd /usr/src/linux
    # make dep; make bzImage 
    # make install
    # make modules; make modules_install
    

  3. Build SnapFS module

    First run 'Configure' script to generate config file.

    # cd /root/snapfs/snapfs22/
    # ./Configure
    

    You will be asked whether adding SnapFS support to Ext2 and Ext3, answer "y" to turn on the support and "n" to turn off it. The following is an example.

    Add Snapfs support to EXT2 filesystem? (y/n) [y]: y
    Add Snapfs support to EXT3 filesystem? (y/n) [n]: n
    

    If you enable SnapFS support to Ext3, you'll be asked if enable "EXT3 loopback device debugging support", it's for test only, answer "n" for this if unsure.

    EXT3 loopback device debugging support? (y/n) [n]: n
    

    Leave other choice as default will be ok for most of the case.

    Type "make; make install" to make and install snapfs modules.

    # make
    # make install
    

    Now you get the kernel module snapfs.o at /lib/modules/version/fs

  4. Install perl modules for snapfs control utility

    You also need to install perl modules "Term-ReadLine" and "Time-modules" for snapfs control utility -- snapctl. You can get the latest version from CPAN ( http://www.cpan.org ) or check SnapFS website http://www.snapfs.org. You can also download these modules from ftp://ftp.mountainviewdata.com/pub/snapfs/. To install the modules, you need to unpack the package you download and then install with "perl Makefile.PL; make; make install".

    # tar zxvf Term-ReadLine-Gnu-1.09.tar.gz
    # cd Term-ReadLine-Gnu-1.09
    # perl Makefile.PL; make; make install
    # cd ..
    # tar zxvf Time-modules-100.010301.tar.gz
    # cd Time-modules-100.010301
    # perl Makefile.PL; make; make install
    

3.2 Setup SnapFS

The easiest way to set up SnapFS is using the utility provided by SnapFS. Check snapfs/util/setup.sh and do some modification to reflect your system setting if necessary.

If you want to setup snapfs over ext2, use:

# cd /root/snapfs/util
# ./setup.sh start
# mount

If you want to setup snapfs over ext3, use:

# cd /root/snapfs/util
# ./setup.sh start ext3
# mount

Then you should get two filesystems mounted. One is snap_current, the other is snap_clone. snap_current represents the current(normal) file system, you can do any operations on it as usual. snap_clone is a read-only filesystem, which keep the frozen image of the snap_current filesystem when you create the snapshot.

You can do anything on the current file system now. You will see on the clone file system, all files/dirs will remain the old version when you create the snapshot.

You can also do management operations, such as snap_delete, snap_rollback, etc., on the snapshot using the tool snapctl, which will be discussed in the next section.

You can also setup SnapFS yourself step by step. The following are the instructions.

  1. First you need to insert the SnapFS module snapfs.o.

    Use 'modprobe snapfs' or 'insmod snapfs.o' to insert the SnapFS module.

  2. Create a sample partition or a file as a loop device to test SnapFS.

  3. Install the snap tables using the snapfs control utility snapctl.

    Please refer to section "Using snapctl" below for details about how to set up and install a snap table.

  4. Then you should mount the snap_current and snap_clone file system.

    There are several options for snap_current and snap_clone file system.

    snap_current options:

    table: Specify which table snap_current file system uses.

    cache_type: Specify the underlying file system type. The valid values are "ext2", "ext3" now. If this option is omitted, snapfs will use "ext2" as the underlying file system type.

    cow_type: Specify the COW type. Here COW stands for Copy On Write, please refer to section "Block Level Cow" for reference. The valid values are "file" and "block". If this option is omitted, snapfs will use block level cow.

    snap_clone options:

    dev: Specify the device name which snap_current file system uses.

    name: The snapshot name which corresponds to the snap_clone file system.

    Suppose you use a file("/tmp/fssnap") as a loop device ("/dev/loop0") and the snapshot name is "clone1".

    # mount -t snap_current -o loop,table=0 /tmp/fssnap /mnt/current
    # mount -t snap_clone -o dev=/dev/loop0,name=clone1 none /mnt/clone
    

    Now it should be ready for using SnapFS!

3.3 Using snapctl

snapctl is the management utility for SnapFS. It can install the snap table, do snap rollback/delete to restore or delete the backup data. A few important commands are listed here. To invoke snapctl, use

# cd /root/snapfs/util
# ./snapctl 

Then you can issue the following commands to do snapshot management tasks.

  1. help

    Print help information for all available commands.

  2. snapdev

    Set the device which you use SnapFS filesystem. The default one is "/dev/loop0" for test purpose. For example:

     snap control > snapdev /dev/hda3
    

  3. snaptable & snapset

    snaptable & snapset command are used to create a snap table and install snap table to memory. After invoking snapctl, type "snaptable" to set up the snap table. You need to provide the snap table file name first, eg. "table0". Then snapctl will list the snapshots in the table file if the table file is not empty. Type "a" to add a new snapshot, "d" to delete a snapshot. When adding a snapshot, you need to provide time and symbolic name for the snapshot. After setting up the snaptable, you can use snapset to install the snap table. You need to provide a table number and table file name when using snapset.

    The following is a real example:

    snap control > snaptable
    enter file name: table0
    Add, Delete or Quit [adq]: a
    enter index where you want this snapshot: 1
    enter time or 'now': now
    enter symbolic name : clone1
    Time: Fri Dec 29 15:19:21 2000 -- Index 1 -- Name: clone1
    Add, Delete or Quit [adq]: q
    OK with new table? [Yn]: y
    
    Then you can install the table to snapfs by using snapset
    snap control > snapset 0 table0
    Snapcount 2
    Finished (success)
    

  4. snapprint

    Print the snap table.

  5. snapdelete

    snapdelete is used to delete all the backup data of a snapshot.

    snap control > snapdelete clone1 table0
    

  6. snaprollback

    snaprollback is used to restore an snapshot to the current file system. Then the data in the current file system will be back to the version when you make this snapshot.

    snap control > snaprollback clone1 table0 0
    Found key 978074361 for snap name clone1
    Snaprollback finished (success)
    

  7. setfilecow

    Force SnapFS to use file level cow instead of block level cow.

  8. other commands

    For other commands, please use help command.

4. Demonstrating SnapFS

It's quite easy to run SnapFS demo. All you need is the following:

# cd /root/snapfs/snapfs22
# make demo

or 

# cd /root/snapfs/demo
# ./demo.sh start

If you want to demo SnapFS over ext3, please run:

# cd /root/snapfs/snapfs22
# make demoext3

or 

# cd /root/snapfs/demo
# ./demo.sh start ext3

Then the demo will show you the basic features of SnapFS.

5. Debugging

To help us find bugs we need logging information. The logs come in two places, from the kernel in /var/log/messages, and from user level tools such as snapctl on stdout and stderr.

6. How does SnapFS work?

SnapFS add a file system layer between VFS and actual file systems and filter any file operations it want to do snapshot functions.

6.1 Mount

After the kernel module snapfs.o was loaded, it registered two file system types: snap_current and snap_clone. When setup SnapFS, SnapFS replaced the file's or inode's operations to it's own functions, which usually act as a filter. When VFS issue a command to activate a file system operation, the control path go to the SnapFS, which usually do some check and perform backup if necessary and call the actual underlayer filesystem's correcponding functions. snapfs.o also registered a character device, we could send command to the device via ioctl to control the snap data.

6.2 Extended Attribute

SnapFS use ea (extended attributes) as its implement base. ea is the extension of Ext2 filesystem, which set aside a file system block for each inode to store extra data you want which associate with the file. Each inode's on-disk structure has one field i_file_acl to point to the extended block. SnapFS use ea to store snapfs-specific data. For details of ea, please visit http://acl.bestbits.at

6.3 Block Level COW

Here COW stands for Copy On Write, which means the data are copied when write operation happens. When users want to modify a object, say a regular file, we don't need to backup the whole file data, because user probably only modify a small section of data within the file. When this happens, we only backup the data blocks which will be changed. Thus we dramatically saved the disk space under most situations. If we further modify other sections of the file, we back the corresponding data blocks then. Users can also force SnapFS to backup all the file data by using the "setfilecow" command via snapctl.

7. Contact Information

The SnapFS web site is http://www.sourceforce.net/projects/snapfs. or http://www.snapfs.org.

General questions about SnapFS can be sent to Peter J. Braam braam@mountainviewdata.com, Harrison Xing harrisonx@mountainviewdata.com or Eric Mei ericm@mountainviewdata.com. This along with other SnapFS related mail lists are archived on the SnapFS web site, so it may be worth checking here to see if your question has already been answered.

Please include the version of SnapFS you are using and a description of your system configuration and the problem observed.

Also, please include all relevant logs: /var/log/messages, and the output of user lever administrator tools.