]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
qa : add case to test cephfs-meta-injection 29443/head
authorsimon gao <simon29rock@gmail.com>
Mon, 20 Jan 2020 10:38:59 +0000 (05:38 -0500)
committerSimon Gao <simon29rock@gmail.com>
Tue, 24 Mar 2020 08:39:02 +0000 (16:39 +0800)
Signed-off-by: simon gao <simon29rock@gmail.com>
qa/tasks/cephfs/filesystem.py
qa/tasks/cephfs/test_meta_injection.py [new file with mode: 0644]
qa/tasks/vstart_runner.py
src/tools/cephfs/MetaTool.cc
src/tools/cephfs/cephfs-meta-injection.cc

index 7352f12c801be6806a7636e9747e64b39a596259..f48d38f94ed5330461ac458b68a3bb052c2a0d3c 100644 (file)
@@ -1268,6 +1268,18 @@ class Filesystem(MDSCluster):
 
         return key_list_str.split("\n") if key_list_str else []
 
+    def get_meta_of_fs_file(self, dir_ino, obj_name, out):
+        """
+        get metadata from parent to verify the correctness of the data format encoded by the tool, cephfs-meta-injection.
+        warning : The splitting of directory is not considered here.
+        """
+        dirfrag_obj_name = "{0:x}.00000000".format(dir_ino)
+        try:
+            ret = self.rados(["getomapval", dirfrag_obj_name, obj_name+"_head", out])
+        except CommandFailedError as e:
+            log.error(e.__str__())
+            raise ObjectNotFound(dir_ino)
+
     def erase_metadata_objects(self, prefix):
         """
         For all objects in the metadata pool matching the prefix,
@@ -1350,6 +1362,13 @@ class Filesystem(MDSCluster):
         fs_rank = self._make_rank(rank)
         return self._run_tool("cephfs-journal-tool", args, fs_rank, quiet)
 
+    def meta_tool(self, args, rank, quiet=False):
+        """
+        Invoke cephfs-meta-injection with the passed arguments for a rank, and return its stdout
+        """
+        fs_rank = self._make_rank(rank)
+        return self._run_tool("cephfs-meta-injection", args, fs_rank, quiet)
+
     def table_tool(self, args, quiet=False):
         """
         Invoke cephfs-table-tool with the passed arguments, and return its stdout
diff --git a/qa/tasks/cephfs/test_meta_injection.py b/qa/tasks/cephfs/test_meta_injection.py
new file mode 100644 (file)
index 0000000..8f33aa8
--- /dev/null
@@ -0,0 +1,40 @@
+from tasks.cephfs.cephfs_test_case import CephFSTestCase
+import random
+import os
+
+class TestMetaInjection(CephFSTestCase):
+    def test_meta_injection(self):
+        conf_ori = self.fs.mds_asok(['config', 'show'])
+        self.fs.mds_asok(['config', 'set', 'mds_log_max_segments', '1'])
+        self.mount_a.run_shell(["mkdir", "metadir"])
+        self.mount_a.run_shell(["touch", "metadir/metafile1"])
+        self.mount_a.run_shell(["touch", "metadir/metafile2"])
+        self.fs.mds_asok(['flush', 'journal'])
+        dirino = self.mount_a.path_to_ino("metadir") 
+        ino = self.mount_a.path_to_ino("metadir/metafile1")
+        
+        # export meta of ino
+        self.fs.meta_tool(['showm', '-i', str(ino), '-o', '/tmp/meta_out'], 0, True)
+        out = self.mount_a.run_shell(['grep', str(ino),'/tmp/meta_out']).stdout.getvalue().strip()
+        
+        # check the metadata of ino
+        self.assertNotEqual(out.find(u'"ino":'+ str(ino)), -1)
+        
+        # amend info of ino
+        self.fs.get_meta_of_fs_file(dirino, "metafile1", "/tmp/meta_obj")
+        self.fs.meta_tool(['amend', '-i', str(ino), '--in', '/tmp/meta_out', '--yes-i-really-really-mean-it'], 0, True)
+        self.fs.get_meta_of_fs_file(dirino, "metafile1", "/tmp/meta_obj_chg")
+        
+        # checkout meta_out after import it
+        ori_mds5 = self.mount_a.run_shell(["md5sum", "/tmp/meta_obj"]).stdout.getvalue().strip().split()
+        chg_mds5 = self.mount_a.run_shell(["md5sum", "/tmp/meta_obj_chg"]).stdout.getvalue().strip().split()
+        print ori_mds5," ==> ", chg_mds5
+        self.assertEqual(len(ori_mds5), 2)
+        self.assertEqual(len(chg_mds5), 2)
+        self.assertEqual(ori_mds5[0], chg_mds5[0])
+
+        self.mount_a.run_shell(["rm", "metadir", "-rf"])
+        self.mount_a.run_shell(["rm", "/tmp/meta_obj"])
+        self.mount_a.run_shell(["rm", "/tmp/meta_obj_chg"])
+        # restore config of mds_log_max_segments
+        self.fs.mds_asok(['config', 'set', 'mds_log_max_segments', conf_ori["mds_log_max_segments"]])
index 7055ebb7c9d8d71fe8eb5285704932e584e9c97b..efe092159d04cc8be65dcedf63d4539b47aeb7cb 100644 (file)
@@ -1326,7 +1326,7 @@ def exec_test():
     # Help developers by stopping up-front if their tree isn't built enough for all the
     # tools that the tests might want to use (add more here if needed)
     require_binaries = ["ceph-dencoder", "cephfs-journal-tool", "cephfs-data-scan",
-                        "cephfs-table-tool", "ceph-fuse", "rados"]
+                        "cephfs-table-tool", "ceph-fuse", "rados", "cephfs-meta-injection"]
     missing_binaries = [b for b in require_binaries if not os.path.exists(os.path.join(BIN_PREFIX, b))]
     if missing_binaries and not opt_ignore_missing_binaries:
         log.error("Some ceph binaries missing, please build them: {0}".format(" ".join(missing_binaries)))
index 1b3660389abb5fac21d8764ccc46ada628b8b836..06357e527f1aad387c8df23c9b8f5bf2b5a751b0 100644 (file)
@@ -159,8 +159,8 @@ int MetaTool::main(string& mode,
         for (auto role : role_selector.get_roles()) {
             rank = role.rank;
 
-            int ret =  process(mode, ino, out, in, confirm);
-            cout << "executing for rank " << rank << " op[" <<mode<< "] ret : " << ret << std::endl;
+            r =  process(mode, ino, out, in, confirm);
+            cout << "executing for rank " << rank << " op[" <<mode<< "] ret : " << r << std::endl;
         }
         
     }else{
@@ -175,8 +175,8 @@ int MetaTool::main(string& mode,
 
 
         rank = conv_t<int>(manual_rank_num);
-        int ret = process(mode, ino, out, in, confirm);
-        cout << "op[" << mode << "] ret : " << ret << std::endl;
+        r = process(mode, ino, out, in, confirm);
+        cout << "op[" << mode << "] ret : " << r << std::endl;
     }
     return r;
 }
@@ -320,7 +320,7 @@ int MetaTool::_amend_meta(string& k, inode_meta_t& inode_meta, const string& fn,
              << "         You must confirm that all logs of mds have been flushed!!!\n"
              << "         if you want amend it, please add --yes-i-really-really-mean-it!!!"
              << std::endl;
-            
+        return -1;
     }
     bufferlist bl;
     inode_meta.encode(bl, features);
@@ -328,7 +328,7 @@ int MetaTool::_amend_meta(string& k, inode_meta_t& inode_meta, const string& fn,
     to_set[k].swap(bl);
     inode_backpointer_t bp;
     if (!op.top_op()->get_ancestor(bp))
-        return false;
+        return -1;
     frag_t frag;
     auto item = op.inodes.find(bp.dirino);
     if (item != op.inodes.end()){
index b93d921ed28136e3e56ce98353ef72c5d3bf3b2a..9ccfd0e5dcf714154b10251683a3ece4dbeaf6ab 100644 (file)
@@ -53,7 +53,7 @@ int main(int argc, const char **argv){
     all.add(modeoptions).add(general);
     po::variables_map vm;
     try{
-        po::store(po::command_line_parser(argc, argv).options(all).positional(p).run(), vm);
+        po::store(po::command_line_parser(argc, argv).options(all).positional(p).allow_unregistered().run(), vm);
     }catch(exception &e){
         cerr << "error : " << e.what() << std::endl;
         return -1;