summaryrefslogtreecommitdiffstats
path: root/src/client/MetaSession.h
blob: 301306263e66ee7093e8279f2563ed4cb588b601 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab

#ifndef CEPH_CLIENT_METASESSION_H
#define CEPH_CLIENT_METASESSION_H

#include "include/types.h"
#include "include/utime.h"
#include "include/xlist.h"
#include "mds/MDSMap.h"
#include "mds/mdstypes.h"
#include "messages/MClientCapRelease.h"

struct Cap;
struct Inode;
struct CapSnap;
struct MetaRequest;

struct MetaSession {
  mds_rank_t mds_num;
  ConnectionRef con;
  version_t seq = 0;
  uint64_t cap_gen = 0;
  utime_t cap_ttl, last_cap_renew_request;
  uint64_t cap_renew_seq = 0;
  entity_addrvec_t addrs;
  feature_bitset_t mds_features;
  feature_bitset_t mds_metric_flags;

  enum {
    STATE_NEW, // Unused
    STATE_OPENING,
    STATE_OPEN,
    STATE_CLOSING,
    STATE_CLOSED,
    STATE_STALE,
    STATE_REJECTED,
  } state = STATE_OPENING;

  enum {
    RECLAIM_NULL,
    RECLAIMING,
    RECLAIM_OK,
    RECLAIM_FAIL,
  } reclaim_state = RECLAIM_NULL;

  int mds_state = MDSMap::STATE_NULL;
  bool readonly = false;

  std::list<Context*> waiting_for_open;

  xlist<Cap*> caps;
  // dirty_list keeps all the dirty inodes before flushing in current session.
  xlist<Inode*> dirty_list;
  xlist<Inode*> flushing_caps;
  xlist<MetaRequest*> requests;
  xlist<MetaRequest*> unsafe_requests;
  std::set<ceph_tid_t> flushing_caps_tids;

  ceph::ref_t<MClientCapRelease> release;

  MetaSession(mds_rank_t mds_num, ConnectionRef con, const entity_addrvec_t& addrs)
    : mds_num(mds_num), con(con), addrs(addrs) {
  }
  ~MetaSession() {
    ceph_assert(caps.empty());
    ceph_assert(dirty_list.empty());
    ceph_assert(flushing_caps.empty());
    ceph_assert(requests.empty());
    ceph_assert(unsafe_requests.empty());
  }

  xlist<Inode*> &get_dirty_list() { return dirty_list; }

  const char *get_state_name() const;

  void dump(Formatter *f, bool cap_dump=false) const;

  void enqueue_cap_release(inodeno_t ino, uint64_t cap_id, ceph_seq_t iseq,
      ceph_seq_t mseq, epoch_t osd_barrier);
};

using MetaSessionRef = std::shared_ptr<MetaSession>;
#endif