From f219e879173a6e9b52f7901911c3cde35bcb808e Mon Sep 17 00:00:00 2001
From: "Yan, Zheng" <zheng.z.yan@intel.com>
Date: Wed, 1 Jan 2014 08:58:42 +0800
Subject: [PATCH 1/2] mds: always store backtrace xattr in the default pool

when creating file in non-default pool, we need to store a backtrace
in the default pool in addition to the specified pool. Otherwise the
'lookup-by-ino' function will consider backtrace for file is missing.

Fixes: #6914
Signed-off-by: Yan, Zheng <zheng.z.yan@intel.com>
---
 src/mds/CInode.cc  |  2 +-
 src/mds/MDCache.cc |  2 +-
 src/mds/Server.cc  | 12 ++++++++----
 3 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/src/mds/CInode.cc b/src/mds/CInode.cc
index 94a11c9..496e32c 100644
--- a/src/mds/CInode.cc
+++ b/src/mds/CInode.cc
@@ -1035,7 +1035,7 @@ void CInode::store_backtrace(Context *fin)
   object_locator_t oloc(pool);
   Context *fin2 = new C_Inode_StoredBacktrace(this, inode.backtrace_version, fin);
 
-  if (!state_test(STATE_DIRTYPOOL)) {
+  if (!state_test(STATE_DIRTYPOOL) || inode.old_pools.empty()) {
     mdcache->mds->objecter->mutate(oid, oloc, op, snapc, ceph_clock_now(g_ceph_context),
 				   0, NULL, fin2);
     return;
diff --git a/src/mds/MDCache.cc b/src/mds/MDCache.cc
index 4336fc0..e405657 100644
--- a/src/mds/MDCache.cc
+++ b/src/mds/MDCache.cc
@@ -8499,7 +8499,7 @@ void MDCache::open_ino(inodeno_t ino, int64_t pool, Context* fin,
     info.want_replica = want_replica;
     info.want_xlocked = want_xlocked;
     info.tid = ++open_ino_last_tid;
-    info.pool = pool >= 0 ? pool : mds->mdsmap->get_first_data_pool();
+    info.pool = pool >= 0 ? pool : default_file_layout.fl_pg_pool;
     info.waiters.push_back(fin);
     do_open_ino(ino, info, 0);
   }
diff --git a/src/mds/Server.cc b/src/mds/Server.cc
index dea73e2..7738a09 100644
--- a/src/mds/Server.cc
+++ b/src/mds/Server.cc
@@ -2582,7 +2582,7 @@ public:
     // dirty inode, dn, dir
     newi->inode.version--;   // a bit hacky, see C_MDS_mknod_finish
     newi->mark_dirty(newi->inode.version+1, mdr->ls);
-    newi->_mark_dirty_parent(mdr->ls);
+    newi->_mark_dirty_parent(mdr->ls, true);
 
     mdr->apply();
 
@@ -2714,6 +2714,8 @@ void Server::handle_client_openc(MDRequest *mdr)
   dn->push_projected_linkage(in);
 
   in->inode.version = dn->pre_dirty();
+  if (layout.fl_pg_pool != mdcache->default_file_layout.fl_pg_pool)
+    in->inode.add_old_pool(mdcache->default_file_layout.fl_pg_pool);
   in->inode.update_backtrace();
   if (cmode & CEPH_FILE_MODE_WR) {
     in->inode.client_ranges[client].range.first = 0;
@@ -2733,7 +2735,7 @@ void Server::handle_client_openc(MDRequest *mdr)
   le->metablob.add_client_req(req->get_reqid(), req->get_oldest_client_tid());
   journal_allocated_inos(mdr, &le->metablob);
   mdcache->predirty_journal_parents(mdr, &le->metablob, in, dn->get_dir(), PREDIRTY_PRIMARY|PREDIRTY_DIR, 1);
-  le->metablob.add_primary_dentry(dn, in, true, true);
+  le->metablob.add_primary_dentry(dn, in, true, true, true);
 
   // do the open
   mds->locker->issue_new_caps(in, cmode, mdr->session, realm, req->is_replay());
@@ -3893,7 +3895,7 @@ public:
     // a new version of hte inode since it's just been created)
     newi->inode.version--; 
     newi->mark_dirty(newi->inode.version + 1, mdr->ls);
-    newi->_mark_dirty_parent(mdr->ls);
+    newi->_mark_dirty_parent(mdr->ls, true);
 
     // mkdir?
     if (newi->inode.is_dir()) { 
@@ -3968,6 +3970,8 @@ void Server::handle_client_mknod(MDRequest *mdr)
     newi->inode.mode |= S_IFREG;
   newi->inode.version = dn->pre_dirty();
   newi->inode.rstat.rfiles = 1;
+  if (layout.fl_pg_pool != mdcache->default_file_layout.fl_pg_pool)
+    newi->inode.add_old_pool(mdcache->default_file_layout.fl_pg_pool);
   newi->inode.update_backtrace();
 
   // if the client created a _regular_ file via MKNOD, it's highly likely they'll
@@ -4009,7 +4013,7 @@ void Server::handle_client_mknod(MDRequest *mdr)
   
   mdcache->predirty_journal_parents(mdr, &le->metablob, newi, dn->get_dir(),
 				    PREDIRTY_PRIMARY|PREDIRTY_DIR, 1);
-  le->metablob.add_primary_dentry(dn, newi, true, true);
+  le->metablob.add_primary_dentry(dn, newi, true, true, true);
 
   journal_and_reply(mdr, newi, dn, le, new C_MDS_mknod_finish(mds, mdr, dn, newi, follows));
 }
-- 
1.8.4.2

