From 8026691d671b728571ef2dae1c954b9da7d9d2d8 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Wed, 9 Jul 2008 16:28:35 -0700 Subject: [PATCH] mds: cdir fetch/commit versioned dentries --- src/TODO | 6 ++++++ src/mds/CDentry.h | 9 +++++---- src/mds/CDir.cc | 41 +++++++++++++++++++++++++++-------------- src/mds/CDir.h | 9 ++++++--- src/mds/MDCache.h | 6 +++--- 5 files changed, 47 insertions(+), 24 deletions(-) diff --git a/src/TODO b/src/TODO index 3967b9e9e97b7..de923208ba23b 100644 --- a/src/TODO +++ b/src/TODO @@ -234,6 +234,12 @@ todo - mds metadata versioning - (dir) inode versions.. +- cdir fetch/store versioned dentries +- migrator import/export of versioned dentries, inodes... drop them on export... +- emetablob.. journaling a versioned update.. + +- path_traverse handling of .snapshot? + primary file link -> old inode primary dir link -> multiversion inode remote link -> multiversion inode diff --git a/src/mds/CDentry.h b/src/mds/CDentry.h index 8a973d4b87f0f..049945d18589c 100644 --- a/src/mds/CDentry.h +++ b/src/mds/CDentry.h @@ -121,9 +121,9 @@ public: public: // cons - CDentry(const nstring& n, CInode *in) : + CDentry(const nstring& n, CInode *in, snapid_t f=0, snapid_t l=CEPH_NOSNAP) : name(n), - first(0), last(CEPH_NOSNAP), + first(f), last(l), remote_ino(0), remote_d_type(0), inode(in), dir(0), version(0), projected_version(0), @@ -131,9 +131,10 @@ public: dir_offset(0), auth_pins(0), nested_auth_pins(0), nested_anchors(0), lock(this, CEPH_LOCK_DN, WAIT_LOCK_OFFSET) { } - CDentry(const nstring& n, inodeno_t ino, unsigned char dt, CInode *in=0) : + CDentry(const nstring& n, inodeno_t ino, unsigned char dt, CInode *in=0, + snapid_t f=0, snapid_t l=CEPH_NOSNAP) : name(n), - first(0), last(CEPH_NOSNAP), + first(f), last(l), remote_ino(ino), remote_d_type(dt), inode(in), dir(0), version(0), projected_version(0), diff --git a/src/mds/CDir.cc b/src/mds/CDir.cc index 573b14a604699..1dc2b872a6e58 100644 --- a/src/mds/CDir.cc +++ b/src/mds/CDir.cc @@ -189,13 +189,14 @@ CDir::CDir(CInode *in, frag_t fg, MDCache *mdcache, bool auth) : * linking fun */ -CDentry* CDir::add_null_dentry(const nstring& dname) +CDentry* CDir::add_null_dentry(const nstring& dname, + snapid_t first, snapid_t last) { // foreign assert(lookup(dname) == 0); // create dentry - CDentry* dn = new CDentry(dname, 0); + CDentry* dn = new CDentry(dname, NULL, first, last); if (is_auth()) dn->state_set(CDentry::STATE_AUTH); cache->lru.lru_insert_mid(dn); @@ -221,13 +222,14 @@ CDentry* CDir::add_null_dentry(const nstring& dname) } -CDentry* CDir::add_primary_dentry(const nstring& dname, CInode *in) +CDentry* CDir::add_primary_dentry(const nstring& dname, CInode *in, + snapid_t first, snapid_t last) { // primary assert(lookup(dname) == 0); // create dentry - CDentry* dn = new CDentry(dname, 0); + CDentry* dn = new CDentry(dname, NULL, first, last); if (is_auth()) dn->state_set(CDentry::STATE_AUTH); cache->lru.lru_insert_mid(dn); @@ -252,13 +254,14 @@ CDentry* CDir::add_primary_dentry(const nstring& dname, CInode *in) return dn; } -CDentry* CDir::add_remote_dentry(const nstring& dname, inodeno_t ino, unsigned char d_type) +CDentry* CDir::add_remote_dentry(const nstring& dname, inodeno_t ino, unsigned char d_type, + snapid_t first, snapid_t last) { // foreign assert(lookup(dname) == 0); // create dentry - CDentry* dn = new CDentry(dname, ino, d_type); + CDentry* dn = new CDentry(dname, ino, d_type, NULL, first, last); if (is_auth()) dn->state_set(CDentry::STATE_AUTH); cache->lru.lru_insert_mid(dn); @@ -1003,9 +1006,14 @@ void CDir::_fetched(bufferlist &bl) // dname string dname; ::decode(dname, p); - dout(24) << "_fetched parsed marker '" << type << "' dname '" << dname << dendl; + snapid_t first, last; + ::decode(first, p); + ::decode(last, p); + dout(24) << "_fetched parsed marker '" << type << "' dname '" << dname + << " [" << first << "," << last << "]" + << dendl; - CDentry *dn = lookup(dname); // existing dentry? + CDentry *dn = lookup(dname, first); // existing dentry? if (type == 'L') { // hard link @@ -1022,7 +1030,7 @@ void CDir::_fetched(bufferlist &bl) } } else { // (remote) link - dn = add_remote_dentry(dname, ino, d_type); + dn = add_remote_dentry(dname, ino, d_type, first, last); // link to inode? CInode *in = cache->get_inode(ino); // we may or may not have it. @@ -1063,8 +1071,8 @@ void CDir::_fetched(bufferlist &bl) } else { // add inode CInode *in = 0; - if (cache->have_inode(inode.ino)) { - in = cache->get_inode(inode.ino); + if (cache->have_inode(inode.ino, first)) { + in = cache->get_inode(inode.ino, first); dout(-12) << "_fetched got (but i already had) " << *in << " mode " << in->inode.mode << " mtime " << in->inode.mtime << dendl; @@ -1073,6 +1081,7 @@ void CDir::_fetched(bufferlist &bl) // inode in = new CInode(cache); in->inode = inode; + in->snapid = first; // symlink? if (in->is_symlink()) @@ -1086,7 +1095,7 @@ void CDir::_fetched(bufferlist &bl) cache->add_inode( in ); // link - dn = add_primary_dentry(dname, in); + dn = add_primary_dentry(dname, in, first, last); dout(12) << "_fetched got " << *dn << " " << *in << dendl; //in->hack_accessed = false; @@ -1277,7 +1286,9 @@ void CDir::_commit(version_t want) // marker, name, ino bl.append( "L", 1 ); // remote link - ::encode(it->first, bl); + ::encode(dn->name, bl); + ::encode(dn->first, bl); + ::encode(dn->last, bl); ::encode(ino, bl); ::encode(d_type, bl); } else { @@ -1289,7 +1300,9 @@ void CDir::_commit(version_t want) // marker, name, inode, [symlink string] bl.append( "I", 1 ); // inode - ::encode(it->first, bl); + ::encode(dn->name, bl); + ::encode(dn->first, bl); + ::encode(dn->last, bl); ::encode(in->inode, bl); if (in->is_symlink()) { diff --git a/src/mds/CDir.h b/src/mds/CDir.h index ea59183eb5f8a..c34c0827e184f 100644 --- a/src/mds/CDir.h +++ b/src/mds/CDir.h @@ -300,9 +300,12 @@ protected: return iter->second; } - CDentry* add_null_dentry(const nstring& dname); - CDentry* add_primary_dentry(const nstring& dname, CInode *in); - CDentry* add_remote_dentry(const nstring& dname, inodeno_t ino, unsigned char d_type); + CDentry* add_null_dentry(const nstring& dname, + snapid_t first=0, snapid_t last=CEPH_NOSNAP); + CDentry* add_primary_dentry(const nstring& dname, CInode *in, + snapid_t first=0, snapid_t last=CEPH_NOSNAP); + CDentry* add_remote_dentry(const nstring& dname, inodeno_t ino, unsigned char d_type, + snapid_t first=0, snapid_t last=CEPH_NOSNAP); void remove_dentry( CDentry *dn ); // delete dentry void link_remote_inode( CDentry *dn, inodeno_t ino, unsigned char d_type); void link_remote_inode( CDentry *dn, CInode *in ); diff --git a/src/mds/MDCache.h b/src/mds/MDCache.h index 655dca54c0259..82c4b30acf037 100644 --- a/src/mds/MDCache.h +++ b/src/mds/MDCache.h @@ -653,9 +653,9 @@ public: bool did_shutdown_log_cap; // inode_map - bool have_inode( inodeno_t ino ) { return have_inode(vinodeno_t(ino, 0)); } - bool have_inode( vinodeno_t vino ) { return inode_map.count(vino) ? true:false; } - CInode* get_inode( inodeno_t ino, snapid_t s=0 ) { + bool have_inode(inodeno_t ino, snapid_t snap=0) { return have_inode(vinodeno_t(ino, snap)); } + bool have_inode(vinodeno_t vino) { return inode_map.count(vino) ? true:false; } + CInode* get_inode(inodeno_t ino, snapid_t s=0) { vinodeno_t vino(ino,s); if (have_inode(vino)) return inode_map[vino]; -- 2.39.5