--- /dev/null
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+/*
+ * Ceph - scalable distributed file system
+ *
+ * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
+ *
+ * This is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software
+ * Foundation. See file COPYING.
+ *
+ */
+#ifndef __CAPCACHE_H
+#define __CAPCACHE_H
+
+#include <iostream>
+using namespace std;
+
+#include "crypto/ExtCap.h"
+
+class CapCache {
+private:
+ map <cap_id_t, ExtCap> verified_caps;
+
+public:
+ CapCache() {
+ }
+ bool prev_verified(cap_id_t cap_id) {
+ return verified_caps.count(cap_id);
+ }
+ void insert(ExtCap *cap) {
+ verified_caps[cap->get_id()] = (*cap);
+ }
+ void remove(cap_id_t cap_id) {
+ verified_caps.erase(cap_id);
+ }
+};
+
+#endif
#include "crypto/CryptoLib.h"
using namespace CryptoLib;
+struct cap_id_t {
+ int cid;
+ int mds_id;
+};
+// comparison operators
+inline bool operator>(const cap_id_t& a, const cap_id_t& b)
+{
+ if (a.mds_id > b.mds_id)
+ return true;
+ else if (a.mds_id == b.mds_id ) {
+ if (a.cid > b.cid)
+ return true;
+ else
+ return false;
+ }
+ else
+ return false;
+}
+inline bool operator<(const cap_id_t& a, const cap_id_t& b)
+{
+ if (a.mds_id < b.mds_id)
+ return true;
+ else if (a.mds_id == b.mds_id ) {
+ if (a.cid < b.cid)
+ return true;
+ else
+ return false;
+ }
+ else
+ return false;
+}
+
+// ostream
+inline std::ostream& operator<<(std::ostream& out, const cap_id_t& c)
+{
+ out << c.mds_id << ".";
+ out.setf(std::ios::right);
+ out << c.cid;
+ out.unsetf(std::ios::right);
+ return out;
+}
class ExtCap {
private:
struct cap_data_t {
- int id; // capability id
+ cap_id_t id; // capability id
utime_t t_s; // creation time
utime_t t_e; // expiration time
int mode; // I/O mode
public:
friend class Client;
friend class OSD;
+ friend class CapCache;
// default constructor, should really not be used
ExtCap() {}
**********/
ExtCap(int m, uid_t u, inodeno_t n)
{
- data.id = 0;
+ data.id.cid = 0;
+ data.id.mds_id = 0;
data.t_s = g_clock.now();
data.t_e = data.t_s;
data.t_e += 3600;
~ExtCap() { }
- int get_id() const { return data.id; }
+ cap_id_t get_id() const { return data.id; }
utime_t get_ts() const { return data.t_s; }
utime_t get_te() const { return data.t_e; }
uid_t get_uid() const { return data.uid; }
// in case the mode needs to be changed
// FYI, you should resign the cap after this
void set_mode(int new_mode) { data.mode = new_mode; }
+ void set_id(int new_id, int new_mds_id) {
+ data.id.cid = new_id;
+ data.id.mds_id = new_mds_id;
+ }
const cap_data_t* get_data() const {
return (&data);
if (!ext_cap) {
// make new cap
ext_cap = new ExtCap(my_want, my_user, in->ino());
+ ext_cap->set_id(cap_id_count, mds->get_nodeid());
+ // increment capability count
+ cap_id_count++;
dout(3) << "Made new " << my_want << " capability for uid: "
<< ext_cap->get_uid() << " for inode: " << ext_cap->get_ino()<< endl;
private:
MDS *mds;
MDCache *mdcache;
+ // count of capability id's used
+ int cap_id_count;
public:
- Locker(MDS *m, MDCache *c) : mds(m), mdcache(c) {}
+ Locker(MDS *m, MDCache *c) : mds(m), mdcache(c), cap_id_count(0) {}
void dispatch(Message *m);
// convert public key to string
string key_str = pubToString(myPubKey);
+
+ // ready cache
+ cap_cache = new CapCache();
// i'm ready!
messenger->set_dispatcher(this);
else
cout << "OSD failed to verify capability" << endl;
}
+ else
+ cout << "Received some read with no cap from " << op->get_source().type() << endl;
+
long r = 0;
bufferlist bl;
cout << "OSD failed to verify a write capability" << endl;
}
else
- cout << "Received some write with no cap" << endl;
+ cout << "Received some write with no cap from " << op->get_source().type() << endl;
/*
// check for capability
#include"crypto/CryptoLib.h"
using namespace CryptoLib;
+#include "crypto/CapCache.h"
class Messenger;
class Message;
/** superblock
*/
OSDSuperblock superblock;
- epoch_t boot_epoch;
+ epoch_t boot_epoch;
object_t get_osdmap_object_name(epoch_t epoch) { return object_t(0,epoch << 1); }
object_t get_inc_osdmap_object_name(epoch_t epoch) { return object_t(0, (epoch << 1) + 1); }
esignPriv myPrivKey;
esignPub myPubKey;
+ // capability cache
+ CapCache *cap_cache;
+
static const int STATE_BOOTING = 1;
static const int STATE_ACTIVE = 2;
static const int STATE_STOPPING = 3;