Skip to contentSkip to conversation

Preserve dir default_file_layout in encoded inode

PATCH Alexandre Oliva 2 participants 4 messages Aug 16, 2012 – Aug 17, 2012

lore
Share & tools
lore
#0 lore raw

Store dir layouts not only in the journal, but also in inode information for the directory, so that they aren't dropped on the floor when dirs are evicted from the MDS cache and dropped from the journal. Also restore dir layouts when fetching dirs back into the MDS cache.

This is supposed to fix for bug 1435, except that it doesn't look like a layout change to a directory will trigger a commit of the new layout if the directory is not otherwise modified before the change is evicted from the cache and the journal. This can be sorted out in a separate patch.

---
 src/mds/CDir.cc  |   16 +++++++++++++++-
 src/mds/CInode.h |    9 +++++++--
 2 files changed, 22 insertions(+), 3 deletions(-)
src/mds/CDir.cc +15 -1
index 6761c6f..df19252 100644
@@ -1552,8 +1552,16 @@ void CDir::_fetched(bufferlist &bl, const string& want_dn)
 	    << " already exists at " << inopath << "\n";
 	  continue;
 	} else {
+	  ceph_file_layout unset_fl = ceph_file_layout(), *fl;
+
+	  if (inode.is_dir ()
+	      && memcmp (&inode.layout, &unset_fl, sizeof (unset_fl)) != 0)
+	    fl = &inode.layout;
+	  else
+	    fl = NULL;
+
 	  // inode
-	  in = new CInode(cache, true, first, last);
+	  in = new CInode(cache, true, first, last, fl);
 	  in->inode = inode;
 	  
 	  // symlink?
@@ -1845,6 +1853,12 @@ void CDir::_encode_dentry(CDentry *dn, bufferlist& bl,
     
     dout(14) << " pos " << bl.length() << " dn '" << dn->name << "' inode " << *in << dendl;
     
+    ceph_file_layout *fl = in->get_projected_dir_layout ();
+    if (fl)
+      in->inode.layout = *fl;
+    else
+      memset (&in->inode.layout, 0, sizeof (in->inode.layout));
+
     // marker, name, inode, [symlink string]
     bl.append('I');         // inode
     ::encode(in->inode, bl);
src/mds/CInode.h +7 -2
index 57c76c4..8b42f6f 100644
@@ -71,6 +71,9 @@ struct default_file_layout {
 
   ceph_file_layout layout;
 
+  default_file_layout() {};
+  default_file_layout(ceph_file_layout l) : layout(l) {};
+
   void encode(bufferlist &bl) const {
     __u8 struct_v = 1;
     ::encode(struct_v, bl);
@@ -458,12 +461,13 @@ private:
 
  public:
   // ---------------------------
-  CInode(MDCache *c, bool auth=true, snapid_t f=2, snapid_t l=CEPH_NOSNAP) : 
+  CInode(MDCache *c, bool auth=true, snapid_t f=2, snapid_t l=CEPH_NOSNAP,
+	 ceph_file_layout *dl = NULL) : 
     mdcache(c),
     snaprealm(0), containing_realm(0),
     first(f), last(l),
     last_journaled(0), //last_open_journaled(0), 
-    default_layout(NULL),
+    default_layout(dl ? new default_file_layout (*dl) : NULL),
     //hack_accessed(true),
     stickydir_ref(0),
     parent(0),
@@ -498,6 +502,7 @@ private:
     g_num_inos++;
     close_dirfrags();
     close_snaprealm();
+    delete default_layout;
   }
   
 
Signature · 8 lines
1.7.7.6


-- 
Alexandre Oliva, freedom fighter    http://FSFLA.org/~lxoliva/
You must be the change you wish to see in the world. -- Gandhi
Be Free! -- http://FSFLA.org/   FSF Latin America board member
Free Software Evangelist      Red Hat Brazil Compiler Engineer
#1 lore raw

Hi Alexandre,

I'm glad to you picked this up again; it'll be nice to get this issue behind us. Sadly it's been a while since I've looked at this code...

Quoted 5 lines · Alexandre Oliva

Store dir layouts not only in the journal, but also in inode information for the directory, so that they aren't dropped on the floor when dirs are evicted from the MDS cache and dropped from the journal. Also restore dir layouts when fetching dirs back into the MDS cache.

That sounds like the right diagnosis. I'm not sure this fix is correct, though (see below). It looks like I had a patch from a while back that simplified a lot of this code, though, and fixed teh storage issue for free. I've dusted it off and repushed it.. can you take a look? wip-mds-layout.

Quoted 35 lines

This is supposed to fix for bug 1435, except that it doesn't look like a layout change to a directory will trigger a commit of the new layout if the directory is not otherwise modified before the change is evicted from the cache and the journal. This can be sorted out in a separate patch.

---
 src/mds/CDir.cc  |   16 +++++++++++++++-
 src/mds/CInode.h |    9 +++++++--
 2 files changed, 22 insertions(+), 3 deletions(-)
src/mds/CDir.cc +9 -1
index 6761c6f..df19252 100644
@@ -1552,8 +1552,16 @@ void CDir::_fetched(bufferlist &bl, const string& want_dn)
 	    << " already exists at " << inopath << "\n";
 	  continue;
 	} else {
+	  ceph_file_layout unset_fl = ceph_file_layout(), *fl;
+
+	  if (inode.is_dir ()
+	      && memcmp (&inode.layout, &unset_fl, sizeof (unset_fl)) != 0)
+	    fl = &inode.layout;
+	  else
+	    fl = NULL;
+
 	  // inode
-	  in = new CInode(cache, true, first, last);
+	  in = new CInode(cache, true, first, last, fl);
 	  in->inode = inode;
 
 	  // symlink?

src/mds/CDir.cc void CDir::_encode_dentry(CDentry *dn, bufferlist& bl, · line 1856

Quoted 4 lines
src/mds/CDir.cc +1 -0
@@ -1845,6 +1853,12 @@ void CDir::_encode_dentry(CDentry *dn, bufferlist& bl,
 
     dout(14) << " pos " << bl.length() << " dn '" << dn->name << "' inode " << *in << dendl;
 
+    ceph_file_layout *fl = in->get_projected_dir_layout ();

We aren't allowed to write any "projected" (i.e., unjournaled) changes to other objects until they've committed. If this were the committed/journaled layout, it'd be close, though.

In any case, can you try out wip-mds-layout? I don't have a full environment on my laptop so I haven't tested it yet; I'll try to do that later tonight.

Thanks!
sage

Quoted 61 lines
src/mds/CDir.cc +5 -0
+    if (fl)
+      in->inode.layout = *fl;
+    else
+      memset (&in->inode.layout, 0, sizeof (in->inode.layout));
+
     // marker, name, inode, [symlink string]
     bl.append('I');         // inode
     ::encode(in->inode, bl);
src/mds/CInode.h +7 -2
index 57c76c4..8b42f6f 100644
@@ -71,6 +71,9 @@ struct default_file_layout {
 
   ceph_file_layout layout;
 
+  default_file_layout() {};
+  default_file_layout(ceph_file_layout l) : layout(l) {};
+
   void encode(bufferlist &bl) const {
     __u8 struct_v = 1;
     ::encode(struct_v, bl);
@@ -458,12 +461,13 @@ private:
 
  public:
   // ---------------------------
-  CInode(MDCache *c, bool auth=true, snapid_t f=2, snapid_t l=CEPH_NOSNAP) : 
+  CInode(MDCache *c, bool auth=true, snapid_t f=2, snapid_t l=CEPH_NOSNAP,
+	 ceph_file_layout *dl = NULL) : 
     mdcache(c),
     snaprealm(0), containing_realm(0),
     first(f), last(l),
     last_journaled(0), //last_open_journaled(0), 
-    default_layout(NULL),
+    default_layout(dl ? new default_file_layout (*dl) : NULL),
     //hack_accessed(true),
     stickydir_ref(0),
     parent(0),
@@ -498,6 +502,7 @@ private:
     g_num_inos++;
     close_dirfrags();
     close_snaprealm();
+    delete default_layout;
   }
 
 
Signature · 12 lines
1.7.7.6


-- 
Alexandre Oliva, freedom fighter    http://FSFLA.org/~lxoliva/
You must be the change you wish to see in the world. -- Gandhi
Be Free! -- http://FSFLA.org/   FSF Latin America board member
Free Software Evangelist      Red Hat Brazil Compiler Engineer
--
To unsubscribe from this list: send the line "unsubscribe ceph-devel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#2 lore raw
Quoted 2 lines · Sage Weil

I've dusted it off and repushed it.. can you take a look? wip-mds-layout.

The patch looks good, but testing it is going to be a bit of a challenge because of the on-disk format change and the current unavailability of cluster snapshots. I'll figure something out, once I'm done with an ongoing cluster operation.

Quoted 2 lines

We aren't allowed to write any "projected" (i.e., unjournaled) changes to other objects until they've committed.

Aah, thanks.

Signature · 4 lines
Alexandre Oliva, freedom fighter    http://FSFLA.org/~lxoliva/
You must be the change you wish to see in the world. -- Gandhi
Be Free! -- http://FSFLA.org/   FSF Latin America board member
Free Software Evangelist      Red Hat Brazil Compiler Engineer
#3 lore raw
Quoted 8 lines · Alexandre Oliva
Quoted 2 lines · Sage Weil

I've dusted it off and repushed it.. can you take a look? wip-mds-layout.

The patch looks good, but testing it is going to be a bit of a challenge because of the on-disk format change and the current unavailability of cluster snapshots. I'll figure something out, once I'm done with an ongoing cluster operation.

I gather some of the changes would have required additional versioning changes to avoid a fully incompatible format change (as in, failure to decode properly an existing filesystem).

So I ended up applying this patch on top of yours, to keep the on-disk format unchanged, so I could roll back to the prior format. The combination of the patches is something I'd be comfortable applying in a stable branch.

I haven't yet completed testing (getting some layouts flushed from the cache and loaded back in), but it's looking good so far.

From d1bae416891d5fa0289dcad4565365892b062e42 Mon Sep 17 00:00:00 2001
From: Alexandre Oliva <[email protected]>
Date: Fri, 17 Aug 2012 16:26:05 -0300
Subject: mds: restore on-disk format for dir layouts

Revert on-disk and protocol changes introduced in 37485df86984.

---
 src/mds/CInode.cc          |   33 +++++++++++++++++++++------------
 src/mds/CInode.h           |   40 +++++++++++++++++++++++++++++++++++-----
 src/mds/MDS.h              |    2 +-
 src/mds/events/EMetaBlob.h |   23 ++++++++++++++++-------
 4 files changed, 73 insertions(+), 25 deletions(-)
src/mds/CInode.cc +21 -12
index 2b29f01..53f9e69 100644
@@ -1100,14 +1100,12 @@ void CInode::encode_lock_state(int type, bufferlist& bl)
     
   case CEPH_LOCK_IFILE:
     if (is_auth()) {
+      ::encode(inode.layout, bl);
+      ::encode(inode.size, bl);
       ::encode(inode.mtime, bl);
       ::encode(inode.atime, bl);
       ::encode(inode.time_warp_seq, bl);
-      if (!is_dir()) {
-	::encode(inode.layout, bl);
-	::encode(inode.size, bl);
-	::encode(inode.client_ranges, bl);
-      }
+      ::encode(inode.client_ranges, bl);
     } else {
       bool dirty = filelock.is_dirty();
       ::encode(dirty, bl);
@@ -1189,7 +1187,13 @@ void CInode::encode_lock_state(int type, bufferlist& bl)
 
   case CEPH_LOCK_IPOLICY:
     if (inode.is_dir()) {
-      ::encode(inode.layout, bl);
+      bool has_layout = inode.has_layout();
+      ::encode(has_layout, bl);
+      if (has_layout) {
+	__u8 lv = 1;
+	::encode(lv, bl);
+	::encode(inode.layout, bl);
+      }
     }
     break;
   
@@ -1283,14 +1287,12 @@ void CInode::decode_lock_state(int type, bufferlist& bl)
 
   case CEPH_LOCK_IFILE:
     if (!is_auth()) {
+      ::decode(inode.layout, p);
+      ::decode(inode.size, p);
       ::decode(inode.mtime, p);
       ::decode(inode.atime, p);
       ::decode(inode.time_warp_seq, p);
-      if (!is_dir()) {
-	::decode(inode.layout, p);
-	::decode(inode.size, p);
-	::decode(inode.client_ranges, p);
-      }
+      ::decode(inode.client_ranges, p);
     } else {
       bool replica_dirty;
       ::decode(replica_dirty, p);
@@ -1432,7 +1434,14 @@ void CInode::decode_lock_state(int type, bufferlist& bl)
 
   case CEPH_LOCK_IPOLICY:
     if (inode.is_dir()) {
-      ::decode(inode.layout, p);
+      bool has_layout;
+      ::decode(has_layout, p);
+      if (has_layout) {
+	__u8 lv;
+	::decode(lv, p);
+	assert(lv == 1);
+	::decode(inode.layout, p);
+      }
     }
     break;
 
src/mds/CInode.h +35 -5
index d4c0aa8..0b74b64 100644
@@ -530,7 +530,7 @@ private:
   unsigned encode_parent_mutation(ObjectOperation& m);
 
   void encode_store(bufferlist& bl) {
-    __u8 struct_v = 3;
+    __u8 struct_v = 2;
     ::encode(struct_v, bl);
     ::encode(inode, bl);
     if (is_symlink())
@@ -541,6 +541,15 @@ private:
     encode_snap_blob(snapbl);
     ::encode(snapbl, bl);
     ::encode(old_inodes, bl);
+    if (struct_v == 2 && inode.is_dir()) { // FIXME: this is redundant
+      bool has_layout = inode.has_layout();
+      ::encode(has_layout, bl);
+      if (has_layout) {
+	__u8 lv = 1;
+	::encode(lv, bl);
+	::encode(inode.layout, bl);
+      }
+    }
   }
   void decode_store(bufferlist::iterator& bl) {
     __u8 struct_v;
@@ -555,10 +564,12 @@ private:
     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) {
-	::decode(struct_v, bl);
+      bool has_layout;
+      ::decode(has_layout, bl);
+      if (has_layout) {
+	__u8 lv;
+	::decode(lv, bl);
+	assert (lv == 1);
 	::decode(inode.layout, bl);
       }
     }
@@ -576,6 +587,15 @@ private:
     
     _encode_base(bl);
     _encode_locks_state_for_replica(bl);
+    if (inode.is_dir()) { // FIXME: this is redundant
+      bool has_layout = inode.has_layout();
+      ::encode(has_layout, bl);
+      if (has_layout) {
+	__u8 lv = 1;
+	::encode(lv, bl);
+	::encode(inode.layout, bl);
+      }
+    }
   }
   void decode_replica(bufferlist::iterator& p, bool is_new) {
     __u32 nonce;
@@ -584,6 +604,16 @@ private:
     
     _decode_base(p);
     _decode_locks_state(p, is_new);
+    if (inode.is_dir()) { // FIXME: this is redundant
+      bool has_layout;
+      ::decode(has_layout, p);
+      if (has_layout) {
+	__u8 lv;
+	::decode(lv, p);
+	assert(lv == 1);
+	::decode(inode.layout, p);
+      }
+    }
   }
 
 
src/mds/MDS.h +1 -1
index 71106c3..67a5102 100644
@@ -35,7 +35,7 @@
 #include "SessionMap.h"
 
 
-#define CEPH_MDS_PROTOCOL    15 /* cluster internal */
+#define CEPH_MDS_PROTOCOL    14 /* cluster internal */
 
 
 enum {
src/mds/events/EMetaBlob.h +16 -7
index f63266e..38131d6 100644
@@ -97,6 +97,15 @@ public:
       if (i.is_dir()) {
 	::encode(dft, _enc);
 	::encode(sbl, _enc);
+	if (struct_v >= 2 && struct_v <= 3) { // FIXME: this is redundant
+	  bool has_layout = i.has_layout();
+	  ::encode(has_layout, _enc);
+	  if (has_layout) {
+	    __u8 lv = 1;
+	    ::encode(lv, _enc);
+	    ::encode(inode.layout, _enc);
+	  }
+	}
       }
       ::encode(dr, _enc);      
       ::encode(oi ? true : false, _enc);
@@ -110,8 +119,6 @@ public:
     ~fullbit() {}
 
     void encode(bufferlist& bl) const {
-      __u8 struct_v = 3;
-      ::encode(struct_v, bl);
       assert(_enc.length());
       bl.append(_enc); 
     }
@@ -129,11 +136,13 @@ public:
       if (inode.is_dir()) {
 	::decode(dirfragtree, bl);
 	::decode(snapbl, bl);
-	if (struct_v == 2) {
-	  bool dir_layout_exists;
-	  ::decode(dir_layout_exists, bl);
-	  if (dir_layout_exists) {
-	    ::decode(struct_v, bl);
+	if (struct_v >= 2 && struct_v <= 3) {
+	  bool has_layout;
+	  ::decode(has_layout, bl);
+	  if (has_layout) {
+	    __u8 lv;
+	    ::decode(lv, bl);
+	    assert(lv == 1);
 	    ::decode(inode.layout, bl);
 	  }
 	}
Signature · 9 lines
1.7.7.6



-- 
Alexandre Oliva, freedom fighter    http://FSFLA.org/~lxoliva/
You must be the change you wish to see in the world. -- Gandhi
Be Free! -- http://FSFLA.org/   FSF Latin America board member
Free Software Evangelist      Red Hat Brazil Compiler Engineer