From 94b8dd46d9d4d4f8bb74430a53002af6f9b6fa1e Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Mon, 28 Jul 2008 17:02:12 -0700 Subject: [PATCH] mds: preserve snap info on import/export, clean up CInode constructor --- src/TODO | 4 +--- src/mds/CDentry.h | 4 +++- src/mds/CDir.cc | 8 +++++--- src/mds/CInode.cc | 4 ++++ src/mds/CInode.h | 5 ++--- src/mds/MDCache.cc | 7 ++----- src/mds/Migrator.cc | 16 +++++++++++----- src/mds/journal.cc | 4 +--- src/mds/mdstypes.h | 2 +- 9 files changed, 30 insertions(+), 24 deletions(-) diff --git a/src/TODO b/src/TODO index 950cc59ae7bcc..32555afce5aa8 100644 --- a/src/TODO +++ b/src/TODO @@ -26,8 +26,7 @@ snapshots - garbage collection mds -- migrator import/export of versioned dentries, inodes... drop them on export... -- dentry waiters +- dentry waiters? - resolve - rejoin - client reconnect @@ -119,7 +118,6 @@ mds - handle slow client reconnect (i.e. after mds has gone active) - fix reconnect/rejoin open file weirdness -- get rid of C*Discover objects for replicate_to .. encode to bufferlists directly? - can we get rid of the dirlock remote auth_pin weirdness on subtree roots? - anchor_destroy needs to xlock linklock.. which means it needs a Mutation wrapper? diff --git a/src/mds/CDentry.h b/src/mds/CDentry.h index 78c5be909540d..7ecd1bc69f0f7 100644 --- a/src/mds/CDentry.h +++ b/src/mds/CDentry.h @@ -227,6 +227,7 @@ public: // note: this assumes the dentry already exists. // i.e., the name is already extracted... so we just need the other state. void encode_export(bufferlist& bl) { + ::encode(first, bl); ::encode(state, bl); ::encode(version, bl); ::encode(projected_version, bl); @@ -247,7 +248,8 @@ public: put(PIN_TEMPEXPORTING); } void decode_import(bufferlist::iterator& blp, LogSegment *ls) { - int nstate; + ::decode(first, blp); + __u32 nstate; ::decode(nstate, blp); ::decode(version, blp); ::decode(projected_version, blp); diff --git a/src/mds/CDir.cc b/src/mds/CDir.cc index 5e0084671c2f4..278a01425a721 100644 --- a/src/mds/CDir.cc +++ b/src/mds/CDir.cc @@ -1184,10 +1184,8 @@ void CDir::_fetched(bufferlist &bl) assert(0); // this shouldn't happen!! } else { // inode - in = new CInode(cache); + in = new CInode(cache, true, first, last); in->inode = inode; - in->first = first; - in->last = last; // symlink? if (in->is_symlink()) @@ -1556,7 +1554,9 @@ void CDir::_committed(version_t v) void CDir::encode_export(bufferlist& bl) { assert(!is_projected()); + ::encode(first, bl); ::encode(fnode, bl); + ::encode(dirty_old_rstat, bl); ::encode(committed_version, bl); ::encode(committed_version_equivalent, bl); @@ -1582,7 +1582,9 @@ void CDir::finish_export(utime_t now) void CDir::decode_import(bufferlist::iterator& blp) { + ::decode(first, blp); ::decode(fnode, blp); + ::decode(dirty_old_rstat, blp); projected_version = fnode.version; ::decode(committed_version, blp); ::decode(committed_version_equivalent, blp); diff --git a/src/mds/CInode.cc b/src/mds/CInode.cc index 5a92ccb88489f..0ac4faf42e347 100644 --- a/src/mds/CInode.cc +++ b/src/mds/CInode.cc @@ -1283,14 +1283,17 @@ void CInode::encode_inodestat(bufferlist& bl, snapid_t snapid) void CInode::_encode_base(bufferlist& bl) { + ::encode(first, bl); ::encode(inode, bl); ::encode(symlink, bl); ::encode(dirfragtree, bl); ::encode(xattrs, bl); + ::encode(old_inodes, bl); encode_snap(bl); } void CInode::_decode_base(bufferlist::iterator& p) { + ::decode(first, p); bool was_anchored = inode.anchored; ::decode(inode, p); if (parent && was_anchored != inode.anchored) @@ -1299,6 +1302,7 @@ void CInode::_decode_base(bufferlist::iterator& p) ::decode(symlink, p); ::decode(dirfragtree, p); ::decode(xattrs, p); + ::decode(old_inodes, p); decode_snap(p); } diff --git a/src/mds/CInode.h b/src/mds/CInode.h index d676348a953f5..6266132286469 100644 --- a/src/mds/CInode.h +++ b/src/mds/CInode.h @@ -272,10 +272,10 @@ private: public: // --------------------------- - CInode(MDCache *c, bool auth=true) : + CInode(MDCache *c, bool auth=true, snapid_t f=1, snapid_t l=CEPH_NOSNAP) : mdcache(c), snaprealm(0), containing_realm(0), - first(1), last(CEPH_NOSNAP), + first(f), last(l), last_journaled(0), last_open_journaled(0), //hack_accessed(true), stickydir_ref(0), @@ -374,7 +374,6 @@ private: if (!is_replicated()) replicate_relax_locks(); - __u32 nonce = add_replica(rep); ::encode(nonce, bl); diff --git a/src/mds/MDCache.cc b/src/mds/MDCache.cc index 4a745a8efb224..ac6262dfaa5fd 100644 --- a/src/mds/MDCache.cc +++ b/src/mds/MDCache.cc @@ -981,13 +981,11 @@ CInode *MDCache::cow_inode(CInode *in, snapid_t last) { assert(last >= in->first); - CInode *oldin = new CInode(this); + CInode *oldin = new CInode(this, true, in->first, last); oldin->inode = *in->get_previous_projected_inode(); oldin->symlink = in->symlink; oldin->xattrs = in->xattrs; - oldin->first = in->first; - oldin->last = last; in->first = last+1; dout(10) << " oldin " << *oldin << dendl; @@ -6662,8 +6660,7 @@ CInode *MDCache::add_replica_inode(bufferlist::iterator& p, CDentry *dn, listlast = last; + in = new CInode(this, false, 1, last); in->decode_replica(p, true); add_inode(in); if (in->is_base()) { diff --git a/src/mds/Migrator.cc b/src/mds/Migrator.cc index 8b14cccd6ad64..417cce9b5ff71 100644 --- a/src/mds/Migrator.cc +++ b/src/mds/Migrator.cc @@ -860,6 +860,7 @@ void Migrator::encode_export_inode(CInode *in, bufferlist& enc_state, assert(!in->is_replica(mds->get_nodeid())); ::encode(in->inode.ino, enc_state); + ::encode(in->last, enc_state); in->encode_export(enc_state); // caps @@ -985,6 +986,7 @@ int Migrator::encode_export_dir(bufferlist& exportbl, // dn name ::encode(dn->name, exportbl); + ::encode(dn->last, exportbl); // state dn->encode_export(exportbl); @@ -1962,12 +1964,14 @@ void Migrator::decode_import_inode(CDentry *dn, bufferlist::iterator& blp, int o dout(15) << "decode_import_inode on " << *dn << dendl; inodeno_t ino; + snapid_t last; ::decode(ino, blp); - + ::decode(last, blp); + bool added = false; - CInode *in = cache->get_inode(ino); + CInode *in = cache->get_inode(ino, last); if (!in) { - in = new CInode(mds->mdcache); + in = new CInode(mds->mdcache, true, 1, last); added = true; } else { in->state_set(CInode::STATE_AUTH); @@ -2117,11 +2121,13 @@ int Migrator::decode_import_dir(bufferlist::iterator& blp, // dentry string dname; + snapid_t last; ::decode(dname, blp); + ::decode(last, blp); - CDentry *dn = dir->lookup(dname); + CDentry *dn = dir->lookup(dname, last); if (!dn) - dn = dir->add_null_dentry(dname); + dn = dir->add_null_dentry(dname, 1, last); dn->decode_import(blp, ls); diff --git a/src/mds/journal.cc b/src/mds/journal.cc index 1dbabe57cc730..fd37186f8405d 100644 --- a/src/mds/journal.cc +++ b/src/mds/journal.cc @@ -373,9 +373,7 @@ void EMetaBlob::replay(MDS *mds, LogSegment *logseg) CInode *in = mds->mdcache->get_inode(p->inode.ino, p->dnlast); if (!in) { - in = new CInode(mds->mdcache); - in->first = p->dnfirst; - in->last = p->dnlast; + in = new CInode(mds->mdcache, true, p->dnfirst, p->dnlast); in->inode = p->inode; in->xattrs = p->xattrs; if (in->inode.is_dir()) { diff --git a/src/mds/mdstypes.h b/src/mds/mdstypes.h index 66881338796a3..ad086dd0fd6aa 100644 --- a/src/mds/mdstypes.h +++ b/src/mds/mdstypes.h @@ -920,7 +920,7 @@ class MDSCacheObject { // -------------------------------------------- // state protected: - unsigned state; // state bits + __u32 state; // state bits public: unsigned get_state() const { return state; } -- 2.39.5