1    	// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2    	// vim: ts=8 sw=2 smarttab
3    	/*
4    	* Ceph - scalable distributed file system
5    	*
6    	* Copyright (C) 2013 Inktank, Inc.
7    	*
8    	* This is free software; you can redistribute it and/or
9    	* modify it under the terms of the GNU Lesser General Public
10   	* License version 2.1, as published by the Free Software
11   	* Foundation. See file COPYING.
12   	*/
13   	#ifndef CEPH_MMONSCRUB_H
14   	#define CEPH_MMONSCRUB_H
15   	
16   	#include "msg/Message.h"
17   	#include "mon/mon_types.h"
18   	
19   	class MMonScrub : public Message {
20   	private:
21   	  static constexpr int HEAD_VERSION = 2;
22   	  static constexpr int COMPAT_VERSION = 2;
23   	
24   	public:
25   	  typedef enum {
26   	    OP_SCRUB = 1,         // leader->peon: scrub (a range of) keys
27   	    OP_RESULT = 2,        // peon->leader: result of a scrub
28   	  } op_type_t;
29   	
30   	  static const char *get_opname(op_type_t op) {
31   	    switch (op) {
32   	    case OP_SCRUB: return "scrub";
33   	    case OP_RESULT: return "result";
34   	    default: ceph_abort_msg("unknown op type"); return NULL;
35   	    }
36   	  }
37   	
38   	  op_type_t op = OP_SCRUB;
39   	  version_t version = 0;
40   	  ScrubResult result;
41   	  int32_t num_keys;
42   	  pair<string,string> key;
43   	
44   	  MMonScrub()
45   	    : Message{MSG_MON_SCRUB, HEAD_VERSION, COMPAT_VERSION},
46   	      num_keys(-1)
47   	  { }
48   	
49   	  MMonScrub(op_type_t op, version_t v, int32_t num_keys)
50   	    : Message{MSG_MON_SCRUB, HEAD_VERSION, COMPAT_VERSION},
51   	      op(op), version(v), num_keys(num_keys)
52   	  { }
53   	
54   	  std::string_view get_type_name() const override { return "mon_scrub"; }
55   	
56   	  void print(ostream& out) const override {
57   	    out << "mon_scrub(" << get_opname((op_type_t)op);
58   	    out << " v " << version;
59   	    if (op == OP_RESULT)
60   	      out << " " << result;
61   	    out << " num_keys " << num_keys;
62   	    out << " key (" << key << ")";
63   	    out << ")";
64   	  }
65   	
66   	  void encode_payload(uint64_t features) override {
67   	    using ceph::encode;
(1) Event assignment: Assigning: "o" = "this->op".
Also see events: [overrun-buffer-val]
68   	    uint8_t o = op;
(2) Event overrun-buffer-val: Overrunning buffer pointed to by "o" of 1 bytes by passing it to a function which accesses it at byte offset 7. [details]
Also see events: [assignment]
69   	    encode(o, payload);
70   	    encode(version, payload);
71   	    encode(result, payload);
72   	    encode(num_keys, payload);
73   	    encode(key, payload);
74   	  }
75   	
76   	  void decode_payload() override {
77   	    auto p = payload.cbegin();
78   	    uint8_t o;
79   	    decode(o, p);
80   	    op = (op_type_t)o;
81   	    decode(version, p);
82   	    decode(result, p);
83   	    decode(num_keys, p);
84   	    decode(key, p);
85   	  }
86   	private:
87   	  template<class T, typename... Args>
88   	  friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args);
89   	};
90   	
91   	#endif /* CEPH_MMONSCRUB_H */
92