aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/transaction.c
diff options
context:
space:
mode:
authorAlexander Block <ablock84@googlemail.com>2012-07-25 11:35:53 -0400
committerAlexander Block <ablock84@googlemail.com>2012-07-25 17:28:38 -0400
commit8ea05e3a4262b9e6871c349fa3486bcfc72ffd1a (patch)
tree893a8ff635b31caf920aaa97948e612640cbac6a /fs/btrfs/transaction.c
parent91cb916ca26feb99c78c131a1643af3d10fefd96 (diff)
Btrfs: introduce subvol uuids and times
This patch introduces uuids for subvolumes. Each subvolume has it's own uuid. In case it was snapshotted, it also contains parent_uuid. In case it was received, it also contains received_uuid. It also introduces subvolume ctime/otime/stime/rtime. The first two are comparable to the times found in inodes. otime is the origin/creation time and ctime is the change time. stime/rtime are only valid on received subvolumes. stime is the time of the subvolume when it was sent. rtime is the time of the subvolume when it was received. Additionally to the times, we have a transid for each time. They are updated at the same place as the times. btrfs receive uses stransid and rtransid to find out if a received subvolume changed in the meantime. If an older kernel mounts a filesystem with the extented fields, all fields become invalid. The next mount with a new kernel will detect this and reset the fields. Signed-off-by: Alexander Block <ablock84@googlemail.com> Reviewed-by: David Sterba <dave@jikos.cz> Reviewed-by: Arne Jansen <sensille@gmx.net> Reviewed-by: Jan Schmidt <list.btrfs@jan-o-sch.net> Reviewed-by: Alex Lyakas <alex.bolshoy.btrfs@gmail.com>
Diffstat (limited to 'fs/btrfs/transaction.c')
-rw-r--r--fs/btrfs/transaction.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c
index b72b068183ec..a21f3085a334 100644
--- a/fs/btrfs/transaction.c
+++ b/fs/btrfs/transaction.c
@@ -22,6 +22,7 @@
22#include <linux/writeback.h> 22#include <linux/writeback.h>
23#include <linux/pagemap.h> 23#include <linux/pagemap.h>
24#include <linux/blkdev.h> 24#include <linux/blkdev.h>
25#include <linux/uuid.h>
25#include "ctree.h" 26#include "ctree.h"
26#include "disk-io.h" 27#include "disk-io.h"
27#include "transaction.h" 28#include "transaction.h"
@@ -926,11 +927,13 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans,
926 struct dentry *dentry; 927 struct dentry *dentry;
927 struct extent_buffer *tmp; 928 struct extent_buffer *tmp;
928 struct extent_buffer *old; 929 struct extent_buffer *old;
930 struct timespec cur_time = CURRENT_TIME;
929 int ret; 931 int ret;
930 u64 to_reserve = 0; 932 u64 to_reserve = 0;
931 u64 index = 0; 933 u64 index = 0;
932 u64 objectid; 934 u64 objectid;
933 u64 root_flags; 935 u64 root_flags;
936 uuid_le new_uuid;
934 937
935 rsv = trans->block_rsv; 938 rsv = trans->block_rsv;
936 939
@@ -1016,6 +1019,20 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans,
1016 root_flags &= ~BTRFS_ROOT_SUBVOL_RDONLY; 1019 root_flags &= ~BTRFS_ROOT_SUBVOL_RDONLY;
1017 btrfs_set_root_flags(new_root_item, root_flags); 1020 btrfs_set_root_flags(new_root_item, root_flags);
1018 1021
1022 btrfs_set_root_generation_v2(new_root_item,
1023 trans->transid);
1024 uuid_le_gen(&new_uuid);
1025 memcpy(new_root_item->uuid, new_uuid.b, BTRFS_UUID_SIZE);
1026 memcpy(new_root_item->parent_uuid, root->root_item.uuid,
1027 BTRFS_UUID_SIZE);
1028 new_root_item->otime.sec = cpu_to_le64(cur_time.tv_sec);
1029 new_root_item->otime.nsec = cpu_to_le64(cur_time.tv_nsec);
1030 btrfs_set_root_otransid(new_root_item, trans->transid);
1031 memset(&new_root_item->stime, 0, sizeof(new_root_item->stime));
1032 memset(&new_root_item->rtime, 0, sizeof(new_root_item->rtime));
1033 btrfs_set_root_stransid(new_root_item, 0);
1034 btrfs_set_root_rtransid(new_root_item, 0);
1035
1019 old = btrfs_lock_root_node(root); 1036 old = btrfs_lock_root_node(root);
1020 ret = btrfs_cow_block(trans, root, old, NULL, 0, &old); 1037 ret = btrfs_cow_block(trans, root, old, NULL, 0, &old);
1021 if (ret) { 1038 if (ret) {