]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mds: Create struct default_file_layout and encoder/decoder functions.
authorGreg Farnum <gregf@hq.newdream.net>
Thu, 23 Sep 2010 20:32:45 +0000 (13:32 -0700)
committerGreg Farnum <gregf@hq.newdream.net>
Fri, 24 Sep 2010 18:45:02 +0000 (11:45 -0700)
Also enable the state transfer when lock state changes.

Still to do: make anything actually create these.

src/mds/CInode.cc
src/mds/CInode.h
src/mds/MDSMap.cc
src/mds/MDSMap.h

index 99e8237d2febb93eaf79afb8e464da7fcd3a2156..bb5c9d18b92710bd8705f6a4da180b543028b5ad 100644 (file)
@@ -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);
   }
index 08ff5fbd6d8bd0b355c51db98f56ca51f138f613..f775b967af927df1dde3c8ee34e363c1009a537d 100644 (file)
@@ -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);
+      }
+    }
   }
 
 
index fd1565dc820c72adff9ce6d0b8ac52027a6ca912..10d2f45736f67107dd0b0d7b5970979bb8de030c 100644 (file)
@@ -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[] = {
index 990941b07fca836c164bf3a4dc1839453e31e4d5..867d8410495db619f16e82b698ab385137f3e7a6 100644 (file)
@@ -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: