From 574fc5a1f31526a98c2ff347a7816c188864846a Mon Sep 17 00:00:00 2001 From: Greg Farnum Date: Thu, 23 Sep 2010 13:32:45 -0700 Subject: [PATCH] mds: Create struct default_file_layout and encoder/decoder functions. Also enable the state transfer when lock state changes. Still to do: make anything actually create these. --- src/mds/CInode.cc | 19 +++++++++++++++ src/mds/CInode.h | 60 +++++++++++++++++++++++++++++++++++++++++++++-- src/mds/MDSMap.cc | 1 + src/mds/MDSMap.h | 1 + 4 files changed, 79 insertions(+), 2 deletions(-) diff --git a/src/mds/CInode.cc b/src/mds/CInode.cc index 99e8237d2febb..bb5c9d18b9271 100644 --- a/src/mds/CInode.cc +++ b/src/mds/CInode.cc @@ -1072,6 +1072,14 @@ void CInode::encode_lock_state(int type, bufferlist& bl) ::encode(fcntl_locks, bl); ::encode(flock_locks, bl); break; + + case CEPH_LOCK_IPOLICY: + if (inode.is_dir()) { + ::encode((default_layout ? true : false), bl); + if (default_layout) + encode(*default_layout, bl); + } + break; default: assert(0); @@ -1347,6 +1355,17 @@ void CInode::decode_lock_state(int type, bufferlist& bl) ::decode(flock_locks, p); break; + case CEPH_LOCK_IPOLICY: + if (inode.is_dir()) { + bool default_layout_exists; + ::decode(default_layout_exists, p); + if (default_layout_exists) { + default_layout = new default_file_layout; + decode(*default_layout, p); + } + } + break; + default: assert(0); } diff --git a/src/mds/CInode.h b/src/mds/CInode.h index 08ff5fbd6d8bd..f775b967af927 100644 --- a/src/mds/CInode.h +++ b/src/mds/CInode.h @@ -63,6 +63,33 @@ struct cinode_lock_info_t { extern cinode_lock_info_t cinode_lock_info[]; extern int num_cinode_locks; +/** + * Default file layout stuff. This lets us set a default file layout on + * a directory inode that all files in its tree will use on creation. + */ +struct default_file_layout { + + ceph_file_layout layout; + + void encode(bufferlist &bl) const { + __u8 struct_v = 1; + ::encode(struct_v, bl); + ::encode(layout, bl); + } + + void decode(bufferlist::iterator& bl) { + __u8 struct_v; + ::decode(struct_v, bl); + if (struct_v != 1) { //uh-oh + dout(0) << "got default layout I don't understand!" << dendl; + assert(0); + } + ::decode(layout, bl); + } +}; +WRITE_CLASS_ENCODER(default_file_layout); + + // cached inode wrapper class CInode : public MDSCacheObject { private: @@ -186,6 +213,8 @@ public: //bool hack_accessed; //utime_t hack_load_stamp; + default_file_layout *default_layout; + /** * Projection methods, used to store inode changes until they have been journaled, * at which point they are popped. @@ -380,6 +409,7 @@ private: snaprealm(0), containing_realm(0), first(f), last(l), last_journaled(0), //last_open_journaled(0), + default_layout(NULL), //hack_accessed(true), stickydir_ref(0), parent(0), @@ -485,7 +515,7 @@ private: void encode_parent_mutation(ObjectOperation& m); void encode_store(bufferlist& bl) { - __u8 struct_v = 1; + __u8 struct_v = 2; ::encode(struct_v, bl); ::encode(inode, bl); if (is_symlink()) @@ -496,6 +526,11 @@ private: encode_snap_blob(snapbl); ::encode(snapbl, bl); ::encode(old_inodes, bl); + if (inode.is_dir()) { + ::encode((default_layout ? true : false), bl); + if (default_layout) + ::encode(*default_layout, bl); + } } void decode_store(bufferlist::iterator& bl) { __u8 struct_v; @@ -509,6 +544,14 @@ private: ::decode(snapbl, bl); decode_snap_blob(snapbl); ::decode(old_inodes, bl); + if (struct_v >= 2 && inode.is_dir()) { + bool default_layout_exists; + ::decode(default_layout_exists, bl); + if (default_layout_exists) { + default_layout = new default_file_layout; + ::decode(*default_layout, bl); + } + } } void encode_replica(int rep, bufferlist& bl) { @@ -523,6 +566,11 @@ private: _encode_base(bl); _encode_locks_state_for_replica(bl); + if (inode.is_dir()) { + ::encode((default_layout ? true : false), bl); + if (default_layout) + ::encode(*default_layout, bl); + } } void decode_replica(bufferlist::iterator& p, bool is_new) { __u32 nonce; @@ -530,7 +578,15 @@ private: replica_nonce = nonce; _decode_base(p); - _decode_locks_state(p, is_new); + _decode_locks_state(p, is_new); + if (inode.is_dir()) { + bool default_layout_exists; + ::decode(default_layout_exists, p); + if (default_layout_exists) { + default_layout = new default_file_layout; + ::decode(*default_layout, p); + } + } } diff --git a/src/mds/MDSMap.cc b/src/mds/MDSMap.cc index fd1565dc820c7..10d2f45736f67 100644 --- a/src/mds/MDSMap.cc +++ b/src/mds/MDSMap.cc @@ -27,6 +27,7 @@ const struct CompatSet::Feature feature_compat[] = { const struct CompatSet::Feature feature_incompat[] = { MDS_FEATURE_INCOMPAT_BASE, MDS_FEATURE_INCOMPAT_CLIENTRANGES, + MDS_FEATURE_INCOMPAT_FILELAYOUT, END_FEATURE }; const struct CompatSet::Feature feature_ro_compat[] = { diff --git a/src/mds/MDSMap.h b/src/mds/MDSMap.h index 990941b07fca8..867d8410495db 100644 --- a/src/mds/MDSMap.h +++ b/src/mds/MDSMap.h @@ -58,6 +58,7 @@ extern CompatSet mdsmap_compat_base; // pre v0.20 #define MDS_FEATURE_INCOMPAT_BASE CompatSet::Feature(1, "base v0.20") #define MDS_FEATURE_INCOMPAT_CLIENTRANGES CompatSet::Feature(2, "client writeable ranges") +#define MDS_FEATURE_INCOMPAT_FILELAYOUT CompatSet::Feature(3, "default file layouts on dirs") class MDSMap { public: -- 2.39.5