]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
Revert "cephfs-journal-tool: enable purge_queue journal's event commands" 23465/head
authorYan, Zheng <zyan@redhat.com>
Tue, 7 Aug 2018 09:00:02 +0000 (17:00 +0800)
committerYan, Zheng <zyan@redhat.com>
Tue, 7 Aug 2018 09:02:18 +0000 (17:02 +0800)
This reverts commit 8ebfa93982a95d6ccc66faa2a828b9386af45238. That
commit changes PurgeItem's encode/decode function, breaks backward
compatibility

Signed-off-by: "Yan, Zheng" <zyan@redhat.com>
src/mds/PurgeQueue.cc
src/mds/PurgeQueue.h
src/tools/cephfs/EventOutput.cc
src/tools/cephfs/JournalFilter.cc
src/tools/cephfs/JournalFilter.h
src/tools/cephfs/JournalScanner.cc
src/tools/cephfs/JournalScanner.h
src/tools/cephfs/JournalTool.cc

index e59b0e4bc05d7f1ab288f36e82aa2e4b161ed1a7..c71a5bc5d3360f49a5efa0fb1198c534953568aa 100644 (file)
@@ -28,22 +28,9 @@ static ostream& _prefix(std::ostream *_dout, mds_rank_t rank) {
   return *_dout << "mds." << rank << ".purge_queue ";
 }
 
-const std::map<std::string_view, PurgeItem::Action> PurgeItem::actions = {
-  {"NONE", PurgeItem::NONE},
-  {"PURGE_FILE", PurgeItem::PURGE_FILE},
-  {"TRUNCATE_FILE", PurgeItem::TRUNCATE_FILE},
-  {"PURGE_DIR", PurgeItem::PURGE_DIR}
-};
-
 void PurgeItem::encode(bufferlist &bl) const
 {
   ENCODE_START(1, 1, bl);
-  encode(stamp, bl);
-  encode(pad_size, bl);
-  uint8_t static const pad = 0xff;
-  for (unsigned int i = 0; i<pad_size; i++) {
-    encode(pad, bl);
-  }
   encode((uint8_t)action, bl);
   encode(ino, bl);
   encode(size, bl);
@@ -57,9 +44,6 @@ void PurgeItem::encode(bufferlist &bl) const
 void PurgeItem::decode(bufferlist::const_iterator &p)
 {
   DECODE_START(1, p);
-  decode(stamp, p);
-  decode(pad_size, p);
-  p.advance(pad_size);
   decode((uint8_t&)action, p);
   decode(ino, p);
   decode(size, p);
@@ -666,15 +650,3 @@ bool PurgeQueue::drain(
   return false;
 }
 
-std::string PurgeItem::get_type_str() const
-{
-  switch(action) {
-  case PurgeItem::NONE: return "NONE";
-  case PurgeItem::PURGE_FILE: return "PURGE_FILE";
-  case PurgeItem::PURGE_DIR: return "PURGE_DIR";
-  case PurgeItem::TRUNCATE_FILE: return "TRUNCATE_FILE";
-  default:
-    return "UNKNOWN";
-  }
-}
-
index 70657bbaa42fd570e53eff130805846c33a6ce44..ae2c358745d4cff61360c12bc4dba6d32a4d4c0b 100644 (file)
@@ -36,11 +36,6 @@ public:
     PURGE_DIR
   };
 
-  utime_t stamp;
-  //None PurgeItem serves as NoOp for splicing out journal entries;
-  //so there has to be a "pad_size" to specify the size of journal
-  //space to be spliced.
-  uint32_t pad_size;
   Action action;
   inodeno_t ino;
   uint64_t size;
@@ -50,35 +45,11 @@ public:
   fragtree_t fragtree;
 
   PurgeItem()
-   : stamp(ceph_clock_now()), pad_size(0), action(NONE), ino(0), size(0)
+   : action(NONE), ino(0), size(0)
   {}
 
   void encode(bufferlist &bl) const;
   void decode(bufferlist::const_iterator &p);
-
-  static Action str_to_type(std::string_view str) {
-    return PurgeItem::actions.at(str);
-  }
-
-  void dump(Formatter *f) const
-  {
-    f->dump_int("action", action);
-    f->dump_int("ino", ino);
-    f->dump_int("size", size);
-    f->open_object_section("layout");
-    layout.dump(f);
-    f->close_section();
-    f->open_object_section("SnapContext");
-    snapc.dump(f);
-    f->close_section();
-    f->open_object_section("fragtree");
-    fragtree.dump(f);
-    f->close_section();
-  }
-
-  std::string get_type_str() const;
-private:
-  static const std::map<std::string_view, PurgeItem::Action> actions;
 };
 WRITE_CLASS_ENCODER(PurgeItem)
 
index ed8403f32ab14ab73b0a5c182b2e5dce68ab62af..56ebecf86ea682939b1058e539beff9ed3ea9338 100644 (file)
@@ -37,21 +37,15 @@ int EventOutput::binary() const
   }
 
   for (JournalScanner::EventMap::const_iterator i = scan.events.begin(); i != scan.events.end(); ++i) {
-    bufferlist bin;
-    std::stringstream filename;
-    if (i->second.log_event) {
-      LogEvent *le = i->second.log_event;
-      le->encode(bin, CEPH_FEATURES_SUPPORTED_DEFAULT);
-      filename << "0x" << std::hex << i->first << std::dec << "_" << le->get_type_str() << ".bin";
-    } else if (i->second.pi) {
-      PurgeItem* pi = i->second.pi;
-      pi->encode(bin);
-      filename << "0x" << std::hex << i->first << std::dec << "_" << pi->get_type_str() << ".bin";
-    }
+    LogEvent *le = i->second.log_event;
+    bufferlist le_bin;
+    le->encode(le_bin, CEPH_FEATURES_SUPPORTED_DEFAULT);
 
+    std::stringstream filename;
+    filename << "0x" << std::hex << i->first << std::dec << "_" << le->get_type_str() << ".bin";
     std::string const file_path = path + std::string("/") + filename.str();
     std::ofstream bin_file(file_path.c_str(), std::ofstream::out | std::ofstream::binary);
-    bin.write_stream(bin_file);
+    le_bin.write_stream(bin_file);
     bin_file.close();
     if (bin_file.fail()) {
       return -EIO;
@@ -69,19 +63,12 @@ int EventOutput::json() const
   jf.open_array_section("journal");
   {
     for (JournalScanner::EventMap::const_iterator i = scan.events.begin(); i != scan.events.end(); ++i) {
-      if (i->second.log_event) {
-       LogEvent *le = i->second.log_event;
-       jf.open_object_section("log_event");
-       {
-         le->dump(&jf);
-       }
-       jf.close_section();  // log_event
-      } else if (i->second.pi) {
-       PurgeItem* pi = i->second.pi;
-       jf.open_object_section("purge_action");
-       pi->dump(&jf);
-       jf.close_section();
+      LogEvent *le = i->second.log_event;
+      jf.open_object_section("log_event");
+      {
+        le->dump(&jf);
       }
+      jf.close_section();  // log_event
     }
   }
   jf.close_section();  // journal
@@ -99,30 +86,24 @@ int EventOutput::json() const
 void EventOutput::list() const
 {
   for (JournalScanner::EventMap::const_iterator i = scan.events.begin(); i != scan.events.end(); ++i) {
-    if (i->second.log_event) {
-      std::vector<std::string> ev_paths;
-      EMetaBlob const *emb = i->second.log_event->get_metablob();
-      if (emb) {
-       emb->get_paths(ev_paths);
-      }
+    std::vector<std::string> ev_paths;
+    EMetaBlob const *emb = i->second.log_event->get_metablob();
+    if (emb) {
+      emb->get_paths(ev_paths);
+    }
 
-      std::string detail;
-      if (i->second.log_event->get_type() == EVENT_UPDATE) {
-       EUpdate *eu = reinterpret_cast<EUpdate*>(i->second.log_event);
-       detail = eu->type;
-      }
+    std::string detail;
+    if (i->second.log_event->get_type() == EVENT_UPDATE) {
+      EUpdate *eu = reinterpret_cast<EUpdate*>(i->second.log_event);
+      detail = eu->type;
+    }
 
-      std::cout <<i->second.log_event->get_stamp() << " 0x"
-       << std::hex << i->first << std::dec << " "
-       << i->second.log_event->get_type_str() << ": "
-       << " (" << detail << ")" << std::endl;
-      for (std::vector<std::string>::iterator i = ev_paths.begin(); i != ev_paths.end(); ++i) {
-       std::cout << "  " << *i << std::endl;
-      }
-    } else if (i->second.pi) {
-      std::cout << i->second.pi->stamp << " 0x"
-       << std::hex << i->first << std::dec << " "
-       << i->second.pi->get_type_str() << std::endl;
+    std::cout <<i->second.log_event->get_stamp() << " 0x"
+      << std::hex << i->first << std::dec << " "
+      << i->second.log_event->get_type_str() << ": "
+      << " (" << detail << ")" << std::endl;
+    for (std::vector<std::string>::iterator i = ev_paths.begin(); i != ev_paths.end(); ++i) {
+        std::cout << "  " << *i << std::endl;
     }
   }
 }
@@ -131,11 +112,7 @@ void EventOutput::summary() const
 {
   std::map<std::string, int> type_count;
   for (JournalScanner::EventMap::const_iterator i = scan.events.begin(); i != scan.events.end(); ++i) {
-    std::string type;
-    if (i->second.log_event)
-      type = i->second.log_event->get_type_str();
-    else if (i->second.pi)
-      type = i->second.pi->get_type_str();
+    std::string const type = i->second.log_event->get_type_str();
     if (type_count.count(type) == 0) {
       type_count[type] = 0;
     }
index 3b30ffa092f284e9e47c5da5b99c50b1481d2bea..6db9f4b0746641e7fb7a0633300c521a93e7de39 100644 (file)
 
 const string JournalFilter::range_separator("..");
 
-bool JournalFilter::apply(uint64_t pos, PurgeItem &pi) const
-{
-  /* Filtering by journal offset range */
-  if (pos < range_start || pos >= range_end) {
-    return false;
-  }
-
-  if (purge_action != PurgeItem::NONE) {
-    if (pi.action != purge_action)
-      return false;
-  }
-
-  if (inode) {
-    if (inode != pi.ino)
-      return false;
-  }
-  return true;
-}
 
 /*
  * Return whether a LogEvent is to be included or excluded.
@@ -205,10 +187,6 @@ int JournalFilter::parse_args(
         }
       }
     } else if (ceph_argparse_witharg(argv, arg, &arg_str, "--path", (char*)NULL)) {
-      if (!type.compare("purge_queue")) {
-       derr << "Invalid filter arguments: purge_queue doesn't take \"--path\"." << dendl;
-       return -EINVAL;
-      }
       dout(4) << "Filtering by path '" << arg_str << "'" << dendl;
       path_expr = arg_str;
     } else if (ceph_argparse_witharg(argv, arg, &arg_str, "--inode", (char*)NULL)) {
@@ -220,21 +198,14 @@ int JournalFilter::parse_args(
         return -EINVAL;
       }
     } else if (ceph_argparse_witharg(argv, arg, &arg_str, "--type", (char*)NULL)) {
-      try {
-       if (!type.compare("mdlog")) {
-         event_type = LogEvent::str_to_type(arg_str);
-       } else if (!type.compare("purge_queue")) {
-         purge_action = PurgeItem::str_to_type(arg_str);
-       }
-      } catch (std::out_of_range) {
-        derr << "Invalid event type '" << arg_str << "'" << dendl;
-        return -EINVAL;
+      std::string parse_err;
+      event_type = LogEvent::str_to_type(arg_str);
+      if (event_type == LogEvent::EventType(-1)) {
+        derr << "Invalid event type '" << arg_str << "': " << parse_err << dendl;
+        return -EINVAL;
       }
+
     } else if (ceph_argparse_witharg(argv, arg, &arg_str, "--frag", (char*)NULL)) {
-      if (!type.compare("purge_queue")) {
-       derr << "Invalid filter arguments: purge_queue doesn't take \"--frag\"." << dendl;
-       return -EINVAL;
-      }
       std::string const frag_sep = ".";
       size_t sep_loc = arg_str.find(frag_sep);
       std::string inode_str;
@@ -263,18 +234,9 @@ int JournalFilter::parse_args(
       frag = dirfrag_t(frag_ino, frag_t(frag_enc));
       dout(4) << "dirfrag filter: '" << frag << "'" << dendl;
     } else if (ceph_argparse_witharg(argv, arg, &arg_str, "--dname", (char*)NULL)) {
-      if (!type.compare("purge_queue")) {
-       derr << "Invalid filter arguments: purge_queue doesn't take \"--dname\"." << dendl;
-       return -EINVAL;
-      }
       frag_dentry = arg_str;
       dout(4) << "dentry filter: '" << frag_dentry << "'" << dendl;
     } else if (ceph_argparse_witharg(argv, arg, &arg_str, "--client", (char*)NULL)) {
-      if (!type.compare("purge_queue")) {
-       derr << "Invalid filter arguments: purge_queue doesn't take \"--client\"." << dendl;
-       return -EINVAL;
-      }
-
       std::string parse_err;
       int64_t client_num = strict_strtoll(arg_str.c_str(), 0, &parse_err);
       if (!parse_err.empty()) {
index f7a2db614a1356c2cf3a4444af1c8b1ee47b7a1b..4fd8ffff26880bdce69585d0b489a9596c14a8b8 100644 (file)
@@ -17,7 +17,6 @@
 
 #include "mds/mdstypes.h"
 #include "mds/LogEvent.h"
-#include "mds/PurgeQueue.h"
 
 /**
  * A set of conditions for narrowing down a search through the journal
@@ -40,11 +39,6 @@ class JournalFilter
   /* Filtering by type */
   LogEvent::EventType event_type;
 
-  std::string type;
-
-  /* Filtering by PurgeItem::Action */
-  PurgeItem::Action purge_action;
-
   /* Filtering by dirfrag */
   dirfrag_t frag;
   std::string frag_dentry;  //< optional, filter dentry name within fragment
@@ -53,17 +47,14 @@ class JournalFilter
   entity_name_t client_name;
 
   public:
-  JournalFilter(std::string t) :
+  JournalFilter() : 
     range_start(0),
     range_end(-1),
     inode(0),
-    event_type(0),
-    type(t),
-    purge_action(PurgeItem::NONE) {}
+    event_type(0) {}
 
   bool get_range(uint64_t &start, uint64_t &end) const;
   bool apply(uint64_t pos, LogEvent &le) const;
-  bool apply(uint64_t pos, PurgeItem &pi) const;
   int parse_args(
     std::vector<const char*> &argv, 
     std::vector<const char*>::iterator &arg);
index 36c018a4bf5bb52871fcad2bd947c19daf2fa2f3..a2e36f0383251fea3f6098a2727347a0c3cff732 100644 (file)
@@ -301,15 +301,10 @@ int JournalScanner::scan_events()
             valid_entry = false;
           }
         } else if (type == "purge_queue"){
-           PurgeItem* pi = new PurgeItem();
+           PurgeItem pi;
            try {
              auto q = le_bl.cbegin();
-             pi->decode(q);
-            if (filter.apply(read_offset, *pi)) {
-              events[read_offset] = EventRecord(pi, consumed);
-            } else {
-              delete pi;
-            }
+             ::decode(pi, q);
            } catch (const buffer::error &err) {
              valid_entry = false;
            }
@@ -352,10 +347,7 @@ JournalScanner::~JournalScanner()
   }
   dout(4) << events.size() << " events" << dendl;
   for (EventMap::iterator i = events.begin(); i != events.end(); ++i) {
-    if (i->second.log_event)
-      delete i->second.log_event;
-    else if (i->second.pi)
-      delete i->second.pi;
+    delete i->second.log_event;
   }
   events.clear();
 }
index 89ee2fd2803f4efae90e3a4934c0b053727fee7b..dad7dc5ac65c57a11af76969483763d913970e25 100644 (file)
@@ -65,7 +65,6 @@ class JournalScanner
     io(io_),
     rank(rank_),
     type(type_),
-    filter(type_),
     is_mdlog(false),
     pointer_present(false),
     pointer_valid(false),
@@ -90,10 +89,8 @@ class JournalScanner
   class EventRecord {
     public:
     EventRecord() : log_event(NULL), raw_size(0) {}
-    EventRecord(LogEvent *le, uint32_t rs) : log_event(le), pi(NULL), raw_size(rs) {}
-    EventRecord(PurgeItem* p, uint32_t rs) : log_event(NULL), pi(p), raw_size(rs) {}
+    EventRecord(LogEvent *le, uint32_t rs) : log_event(le), raw_size(rs) {}
     LogEvent *log_event;
-    PurgeItem *pi;
     uint32_t raw_size;  //< Size from start offset including all encoding overhead
   };
 
index a2b5395b08ce45980b7972e1f06fd074952f9e48..18f7a8183dd3782c8d2c813f9b273ff321cf8f2d 100644 (file)
@@ -168,7 +168,7 @@ int JournalTool::main(std::vector<const char*> &argv)
       r = main_journal(argv);
     } else if (mode == std::string("header")) {
       r = main_header(argv);
-    } else if (mode == std::string("event")) {
+    } else if (type == std::string("mdlog") && mode == std::string("event")) {
       r = main_event(argv);
     } else {
       cerr << "Bad command '" << mode << "'" << std::endl;
@@ -246,7 +246,7 @@ int JournalTool::main_journal(std::vector<const char*> &argv)
  */
 int JournalTool::main_header(std::vector<const char*> &argv)
 {
-  JournalFilter filter(type);
+  JournalFilter filter;
   JournalScanner js(input, rank, type, filter);
   int r = js.scan(false);
   if (r < 0) {
@@ -349,11 +349,6 @@ int JournalTool::main_event(std::vector<const char*> &argv)
     return -EINVAL;
   }
 
-  if (command == "recover_dentries" && type != "mdlog") {
-    derr << "journaler for " << type << " can't do \"recover_dentries\"." << dendl;
-    return -EINVAL;
-  }
-
   if (arg == argv.end()) {
     derr << "Incomplete command line" << dendl;
     return -EINVAL;
@@ -361,7 +356,7 @@ int JournalTool::main_event(std::vector<const char*> &argv)
 
   // Parse filter options
   // ====================
-  JournalFilter filter(type);
+  JournalFilter filter;
   r = filter.parse_args(argv, arg);
   if (r) {
     return r;
@@ -544,7 +539,7 @@ int JournalTool::journal_inspect()
 {
   int r;
 
-  JournalFilter filter(type);
+  JournalFilter filter;
   JournalScanner js(input, rank, type, filter);
   r = js.scan();
   if (r) {
@@ -1048,13 +1043,7 @@ int JournalTool::erase_region(JournalScanner const &js, uint64_t const pos, uint
   // is needed inside the ENoOp to make up the difference.
   bufferlist tmp;
   ENoOp enoop(0);
-  PurgeItem pi;
-
-  if (type == "mdlog") {
-    enoop.encode_with_header(tmp, CEPH_FEATURES_SUPPORTED_DEFAULT);
-  } else if (type == "purge_queue") {
-    pi.encode(tmp);
-  }
+  enoop.encode_with_header(tmp, CEPH_FEATURES_SUPPORTED_DEFAULT);
 
   dout(4) << "erase_region " << pos << " len=" << length << dendl;
 
@@ -1067,16 +1056,12 @@ int JournalTool::erase_region(JournalScanner const &js, uint64_t const pos, uint
     return -EINVAL;
   }
 
+  // Serialize an ENoOp with the correct amount of padding
+  enoop = ENoOp(padding);
   bufferlist entry;
-  if (type == "mdlog") {
-    // Serialize an ENoOp with the correct amount of padding
-    enoop = ENoOp(padding);
-    enoop.encode_with_header(entry, CEPH_FEATURES_SUPPORTED_DEFAULT);
-  } else if (type == "purge_queue") {
-    pi.pad_size = padding;
-    pi.encode(entry);
-  }
+  enoop.encode_with_header(entry, CEPH_FEATURES_SUPPORTED_DEFAULT);
   JournalStream stream(JOURNAL_FORMAT_RESILIENT);
+
   // Serialize region of log stream
   bufferlist log_data;
   stream.write(entry, &log_data, pos);