]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mon/LogMonitor: "log last" should return up to n entries 18759/head
authorKefu Chai <kchai@redhat.com>
Mon, 6 Nov 2017 08:01:23 +0000 (16:01 +0800)
committerKefu Chai <kchai@redhat.com>
Mon, 6 Nov 2017 08:03:45 +0000 (16:03 +0800)
limit the # of returned entries to "num", and backoff the start iterator
by one if it reaches the rend().

Signed-off-by: Kefu Chai <kchai@redhat.com>
src/mon/LogMonitor.cc

index 60f71e108bd2bd1b1fc23386ba84733b3a98704a..9c9541933bca972f32d31de577ebe5737cbcc225 100644 (file)
@@ -429,23 +429,24 @@ bool LogMonitor::preprocess_command(MonOpRequestRef op)
     };
 
     auto rp = summary.tail.rbegin();
-    while (num > 0 && rp != summary.tail.rend()) {
+    for (; num > 0 && rp != summary.tail.rend(); ++rp) {
       if (match(*rp)) {
         num--;
       }
-      ++rp;
+    }
+    if (rp == summary.tail.rend()) {
+      --rp;
     }
     ostringstream ss;
-    auto p = summary.tail.begin();
-    for ( ; p != summary.tail.end(); ++p) {
-      if (!match(*p)) {
+    for (; rp != summary.tail.rbegin(); --rp) {
+      if (!match(*rp)) {
         continue;
       }
 
       if (f) {
-       f->dump_object("entry", *p);
+       f->dump_object("entry", *rp);
       } else {
-       ss << *p << "\n";
+       ss << *rp << "\n";
       }
     }
     if (f) {