+++ /dev/null
-// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
-// vim: ts=8 sw=2 smarttab
-/*
- * 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 CEPH_FAKE_H
-#define CEPH_FAKE_H
-
-#include "include/types.h"
-
-#include <list>
-#include <set>
-#include <ext/hash_map>
-using namespace std;
-using namespace __gnu_cxx;
-
-class FakeCollections {
- private:
- Mutex faker_lock;
- ObjectStore *store;
- hash_map<coll_t, set<hobject_t> > fakecollections;
-
- public:
- FakeCollections(ObjectStore *s) : faker_lock("FakeCollections::faker_lock"), store(s) {}
-
- // faked collections
- int list_collections(vector<coll_t>& ls) {
- faker_lock.Lock();
- int r = 0;
- for (hash_map< coll_t, set<hobject_t> >::iterator p = fakecollections.begin();
- p != fakecollections.end();
- p++) {
- r++;
- ls.push_back(p->first);
- }
- faker_lock.Unlock();
- return r;
- }
-
- int create_collection(coll_t c,
- Context *onsafe=0) {
- faker_lock.Lock();
- fakecollections[c].size();
- if (onsafe) store->sync(onsafe);
- faker_lock.Unlock();
- return 0;
- }
-
- int destroy_collection(coll_t c,
- Context *onsafe=0) {
- int r = 0;
- faker_lock.Lock();
- if (fakecollections.count(c)) {
- fakecollections.erase(c);
- //fakecattr.erase(c);
- if (onsafe) store->sync(onsafe);
- } else
- r = -1;
- faker_lock.Unlock();
- return r;
- }
-
- int collection_stat(coll_t c, struct stat *st) {
- return collection_exists(c) ? 0:-1;
- }
-
- bool collection_exists(coll_t c) {
- faker_lock.Lock();
- int r = fakecollections.count(c);
- faker_lock.Unlock();
- return r;
- }
-
- int collection_add(coll_t c, hobject_t o,
- Context *onsafe=0) {
- faker_lock.Lock();
- fakecollections[c].insert(o);
- if (onsafe) store->sync(onsafe);
- faker_lock.Unlock();
- return 0;
- }
-
- int collection_remove(coll_t c, hobject_t o,
- Context *onsafe=0) {
- faker_lock.Lock();
- fakecollections[c].erase(o);
- if (onsafe) store->sync(onsafe);
- faker_lock.Unlock();
- return 0;
- }
-
- int collection_empty(coll_t c) {
- Mutex::Locker l(faker_lock);
- return fakecollections[c].empty();
- }
-
- int collection_list(coll_t c, vector<hobject_t>& o) {
- faker_lock.Lock();
- int r = 0;
- for (set<hobject_t>::iterator p = fakecollections[c].begin();
- p != fakecollections[c].end();
- p++) {
- o.push_back(*p);
- r++;
- }
- faker_lock.Unlock();
- return r;
- }
-
-};
-
-class FakeAttrs {
- private:
-
- class FakeAttrSet {
- public:
- map<string, bufferptr> attrs;
-
- int getattr(const char *name, void *value, size_t size) {
- string n = name;
- if (attrs.count(n)) {
- size_t l = MIN( attrs[n].length(), size );
- bufferlist bl;
- bl.append(attrs[n]);
- bl.copy(0, l, (char*)value);
- return l;
- }
- return -ENODATA;
- }
- int getattr(const char *name, bufferptr &bp) {
- string n = name;
- if (attrs.count(n)) {
- bp = attrs[n];
- return bp.length();
- }
- return -ENODATA;
- }
- int getattr(const char *name, bufferlist& bl) {
- string n = name;
- if (attrs.count(n)) {
- bl.append(attrs[n]);
- return bl.length();
- }
- return -1;
- }
- int getattrs(map<string,bufferptr>& aset) {
- aset = attrs;
- return 0;
- }
- int setattrs(map<string,bufferptr>& aset) {
- attrs = aset;
- return 0;
- }
-
- int setattr(const char *name, const void *value, size_t size) {
- string n = name;
- bufferptr bp = buffer::copy((char*)value, size);
- attrs[n] = bp;
- return 0;
- }
-
- int listattr(char *attrs, size_t size) {
- assert(0);
- return 0;
- }
-
- int rmattr(const char *name) {
- string n = name;
- attrs.erase(n);
- return 0;
- }
-
- bool empty() { return attrs.empty(); }
- };
-
- Mutex faker_lock;
- ObjectStore *store;
- hash_map<hobject_t, FakeAttrSet> fakeoattrs;
- hash_map<coll_t, FakeAttrSet> fakecattrs;
-
- public:
- FakeAttrs(ObjectStore *s) : faker_lock("FakeAttrs::faker_lock"), store(s) {}
-
- int setattr(coll_t cid, hobject_t oid, const char *name,
- const void *value, size_t size,
- Context *onsafe=0) {
- faker_lock.Lock();
- int r = fakeoattrs[oid].setattr(name, value, size);
- if (onsafe) store->sync(onsafe);
- faker_lock.Unlock();
- return r;
- }
- int setattrs(coll_t cid, hobject_t oid, map<string,bufferptr>& aset) {
- faker_lock.Lock();
- int r = fakeoattrs[oid].setattrs(aset);
- faker_lock.Unlock();
- return r;
- }
- int getattr(coll_t cid, hobject_t oid, const char *name,
- void *value, size_t size) {
- faker_lock.Lock();
- int r = fakeoattrs[oid].getattr(name, value, size);
- faker_lock.Unlock();
- return r;
- }
- int getattr(coll_t cid, hobject_t oid, const char *name, bufferptr& bp) {
- faker_lock.Lock();
- int r = fakeoattrs[oid].getattr(name, bp);
- faker_lock.Unlock();
- return r;
- }
- int getattrs(coll_t cid, hobject_t oid, map<string,bufferptr>& aset) {
- faker_lock.Lock();
- int r = fakeoattrs[oid].getattrs(aset);
- faker_lock.Unlock();
- return r;
- }
- int rmattr(coll_t cid, hobject_t oid, const char *name,
- Context *onsafe=0) {
- faker_lock.Lock();
- int r = fakeoattrs[oid].rmattr(name);
- if (onsafe) store->sync(onsafe);
- faker_lock.Unlock();
- return r;
- }
-
- int listattr(coll_t cid, hobject_t oid, char *attrs, size_t size) {
- faker_lock.Lock();
- int r = fakeoattrs[oid].listattr(attrs,size);
- faker_lock.Unlock();
- return r;
- }
-
- int collection_setattr(coll_t c, const char *name,
- const void *value, size_t size,
- Context *onsafe=0) {
- faker_lock.Lock();
- int r = fakecattrs[c].setattr(name, value, size);
- if (onsafe) store->sync(onsafe);
- faker_lock.Unlock();
- return r;
- }
- int collection_setattrs(coll_t cid, map<string,bufferptr>& aset) {
- faker_lock.Lock();
- int r = fakecattrs[cid].setattrs(aset);
- faker_lock.Unlock();
- return r;
- }
- int collection_getattrs(coll_t cid, map<string,bufferptr>& aset) {
- faker_lock.Lock();
- int r = fakecattrs[cid].getattrs(aset);
- faker_lock.Unlock();
- return r;
- }
- int collection_rmattr(coll_t c, const char *name,
- Context *onsafe=0) {
- faker_lock.Lock();
- int r = fakecattrs[c].rmattr(name);
- if (onsafe) store->sync(onsafe);
- faker_lock.Unlock();
- return r;
- }
- int collection_getattr(coll_t c, const char *name,
- void *value, size_t size) {
- faker_lock.Lock();
- int r = fakecattrs[c].getattr(name, value, size);
- faker_lock.Unlock();
- return r;
- }
- int collection_getattr(coll_t c, const char *name, bufferlist& bl) {
- faker_lock.Lock();
- int r = fakecattrs[c].getattr(name, bl);
- faker_lock.Unlock();
- return r;
- }
- int collection_listattr(coll_t c, char *attrs, size_t size) {
- faker_lock.Lock();
- int r = fakecattrs[c].listattr(attrs,size);
- faker_lock.Unlock();
- return r;
- }
-
-};
-
-#endif
ioctl_fiemap(false),
fsid_fd(-1), op_fd(-1),
basedir_fd(-1), current_fd(-1),
- attrs(this), fake_attrs(false),
- collections(this), fake_collections(false),
ondisk_finisher(g_ceph_context),
lock("FileStore::lock"),
force_sync(false), sync_epoch(0),
m_filestore_btrfs_clone_range(g_conf->filestore_btrfs_clone_range),
m_filestore_btrfs_snap (g_conf->filestore_btrfs_snap ),
m_filestore_btrfs_trans(g_conf->filestore_btrfs_trans),
- m_filestore_fake_attrs(g_conf->filestore_fake_attrs),
- m_filestore_fake_collections(g_conf->filestore_fake_collections),
m_filestore_commit_timeout(g_conf->filestore_commit_timeout),
m_filestore_fiemap(g_conf->filestore_fiemap),
m_filestore_flusher (g_conf->filestore_flusher ),
int FileStore::_detect_fs()
{
- // fake collections?
- if (m_filestore_fake_collections) {
- dout(0) << "faking collections (in memory)" << dendl;
- fake_collections = true;
- }
-
- // xattrs?
- if (m_filestore_fake_attrs) {
- dout(0) << "faking xattrs (in memory)" << dendl;
- fake_attrs = true;
- } else {
- char fn[PATH_MAX];
- int x = rand();
- int y = x+1;
- snprintf(fn, sizeof(fn), "%s/fsid", basedir.c_str());
- int ret = do_setxattr(fn, "user.test", &x, sizeof(x));
- if (ret >= 0)
- ret = do_getxattr(fn, "user.test", &y, sizeof(y));
- if ((ret < 0) || (x != y)) {
- derr << "Extended attributes don't appear to work. ";
- if (ret)
- *_dout << "Got error " + cpp_strerror(ret) + ". ";
- *_dout << "If you are using ext3 or ext4, be sure to mount the underlying "
- << "file system with the 'user_xattr' option." << dendl;
- return -ENOTSUP;
- }
+ char fn[PATH_MAX];
+ int x = rand();
+ int y = x+1;
+ snprintf(fn, sizeof(fn), "%s/fsid", basedir.c_str());
+ int ret = do_setxattr(fn, "user.test", &x, sizeof(x));
+ if (ret >= 0)
+ ret = do_getxattr(fn, "user.test", &y, sizeof(y));
+ if ((ret < 0) || (x != y)) {
+ derr << "Extended attributes don't appear to work. ";
+ if (ret)
+ *_dout << "Got error " + cpp_strerror(ret) + ". ";
+ *_dout << "If you are using ext3 or ext4, be sure to mount the underlying "
+ << "file system with the 'user_xattr' option." << dendl;
+ return -ENOTSUP;
}
int fd = ::open(basedir.c_str(), O_RDONLY);
int FileStore::getattr(coll_t cid, const hobject_t& oid, const char *name,
void *value, size_t size)
{
- if (fake_attrs) return attrs.getattr(cid, oid, name, value, size);
-
dout(15) << "getattr " << cid << "/" << oid << " '" << name << "' len " << size << dendl;
char n[ATTR_MAX_NAME_LEN];
get_attrname(name, n, ATTR_MAX_NAME_LEN);
int FileStore::getattr(coll_t cid, const hobject_t& oid, const char *name, bufferptr &bp)
{
- if (fake_attrs) return attrs.getattr(cid, oid, name, bp);
-
dout(15) << "getattr " << cid << "/" << oid << " '" << name << "'" << dendl;
char n[ATTR_MAX_NAME_LEN];
get_attrname(name, n, ATTR_MAX_NAME_LEN);
int FileStore::getattrs(coll_t cid, const hobject_t& oid, map<string,bufferptr>& aset, bool user_only)
{
- if (fake_attrs) return attrs.getattrs(cid, oid, aset);
-
dout(15) << "getattrs " << cid << "/" << oid << dendl;
int r = _getattrs(cid, oid, aset, user_only);
dout(10) << "getattrs " << cid << "/" << oid << " = " << r << dendl;
int FileStore::_setattr(coll_t cid, const hobject_t& oid, const char *name,
const void *value, size_t size)
{
- if (fake_attrs) return attrs.setattr(cid, oid, name, value, size);
-
dout(15) << "setattr " << cid << "/" << oid << " '" << name << "' len " << size << dendl;
char n[ATTR_MAX_NAME_LEN];
get_attrname(name, n, ATTR_MAX_NAME_LEN);
int FileStore::_setattrs(coll_t cid, const hobject_t& oid, map<string,bufferptr>& aset)
{
- if (fake_attrs) return attrs.setattrs(cid, oid, aset);
-
dout(15) << "setattrs " << cid << "/" << oid << dendl;
int r = 0;
for (map<string,bufferptr>::iterator p = aset.begin();
int FileStore::_rmattr(coll_t cid, const hobject_t& oid, const char *name)
{
- if (fake_attrs) return attrs.rmattr(cid, oid, name);
-
dout(15) << "rmattr " << cid << "/" << oid << " '" << name << "'" << dendl;
char n[ATTR_MAX_NAME_LEN];
get_attrname(name, n, ATTR_MAX_NAME_LEN);
int FileStore::_rmattrs(coll_t cid, const hobject_t& oid)
{
- //if (fake_attrs) return attrs.rmattrs(cid, oid);
-
dout(15) << "rmattrs " << cid << "/" << oid << dendl;
map<string,bufferptr> aset;
int FileStore::collection_getattr(coll_t c, const char *name,
void *value, size_t size)
{
- if (fake_attrs) return attrs.collection_getattr(c, name, value, size);
-
char fn[PATH_MAX];
get_cdir(c, fn, sizeof(fn));
dout(15) << "collection_getattr " << fn << " '" << name << "' len " << size << dendl;
int FileStore::collection_getattr(coll_t c, const char *name, bufferlist& bl)
{
- if (fake_attrs) return attrs.collection_getattr(c, name, bl);
-
char fn[PATH_MAX];
get_cdir(c, fn, sizeof(fn));
dout(15) << "collection_getattr " << fn << " '" << name << "'" << dendl;
int FileStore::collection_getattrs(coll_t cid, map<string,bufferptr>& aset)
{
- if (fake_attrs) return attrs.collection_getattrs(cid, aset);
-
char fn[PATH_MAX];
get_cdir(cid, fn, sizeof(fn));
dout(10) << "collection_getattrs " << fn << dendl;
int FileStore::_collection_setattr(coll_t c, const char *name,
const void *value, size_t size)
{
- if (fake_attrs) return attrs.collection_setattr(c, name, value, size);
-
char fn[PATH_MAX];
get_cdir(c, fn, sizeof(fn));
dout(10) << "collection_setattr " << fn << " '" << name << "' len " << size << dendl;
int FileStore::_collection_rmattr(coll_t c, const char *name)
{
- if (fake_attrs) return attrs.collection_rmattr(c, name);
-
char fn[PATH_MAX];
get_cdir(c, fn, sizeof(fn));
dout(15) << "collection_rmattr " << fn << dendl;
int FileStore::_collection_setattrs(coll_t cid, map<string,bufferptr>& aset)
{
- if (fake_attrs) return attrs.collection_setattrs(cid, aset);
-
char fn[PATH_MAX];
get_cdir(cid, fn, sizeof(fn));
dout(15) << "collection_setattrs " << fn << dendl;
int FileStore::list_collections(vector<coll_t>& ls)
{
- if (fake_collections) return collections.list_collections(ls);
-
dout(10) << "list_collections" << dendl;
char fn[PATH_MAX];
int FileStore::collection_stat(coll_t c, struct stat *st)
{
- if (fake_collections) return collections.collection_stat(c, st);
-
char fn[PATH_MAX];
get_cdir(c, fn, sizeof(fn));
dout(15) << "collection_stat " << fn << dendl;
bool FileStore::collection_exists(coll_t c)
{
- if (fake_collections) return collections.collection_exists(c);
-
struct stat st;
return collection_stat(c, &st) == 0;
}
bool FileStore::collection_empty(coll_t c)
{
- if (fake_collections) return collections.collection_empty(c);
-
dout(15) << "collection_empty " << c << dendl;
Index index;
int r = get_index(c, &index);
int min, int max, snapid_t seq,
vector<hobject_t> *ls, hobject_t *next)
{
- if (fake_collections) return -1;
Index index;
int r = get_index(c, &index);
if (r < 0)
int FileStore::collection_list(coll_t c, vector<hobject_t>& ls)
{
- if (fake_collections) return collections.collection_list(c, ls);
Index index;
int r = get_index(c, &index);
if (r < 0)
int FileStore::_create_collection(coll_t c)
{
- if (fake_collections) return collections.create_collection(c);
-
char fn[PATH_MAX];
get_cdir(c, fn, sizeof(fn));
dout(15) << "create_collection " << fn << dendl;
int FileStore::_destroy_collection(coll_t c)
{
- if (fake_collections) return collections.destroy_collection(c);
-
char fn[PATH_MAX];
get_cdir(c, fn, sizeof(fn));
dout(15) << "_destroy_collection " << fn << dendl;
int FileStore::_collection_add(coll_t c, coll_t cid, const hobject_t& o)
{
- if (fake_collections) return collections.collection_add(c, o);
-
dout(15) << "collection_add " << c << "/" << o << " " << cid << "/" << o << dendl;
int r = lfn_link(cid, c, o);
dout(10) << "collection_add " << c << "/" << o << " " << cid << "/" << o << " = " << r << dendl;
int FileStore::_collection_remove(coll_t c, const hobject_t& o)
{
- if (fake_collections) return collections.collection_remove(c, o);
-
dout(15) << "collection_remove " << c << "/" << o << dendl;
int r = lfn_unlink(c, o);
dout(10) << "collection_remove " << c << "/" << o << " = " << r << dendl;