From 97993f6cb1843ebb13314dbf3157477f38c4b602 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Mon, 5 Mar 2012 21:09:05 -0800 Subject: [PATCH] filestore: remove collection, attr faking Useless functionality from the dark ages of development, when xattrs were scarce. Signed-off-by: Sage Weil --- src/Makefile.am | 1 - src/common/config_opts.h | 2 - src/os/Fake.h | 295 --------------------------------------- src/os/FileStore.cc | 88 ++---------- src/os/FileStore.h | 14 -- 5 files changed, 14 insertions(+), 386 deletions(-) delete mode 100644 src/os/Fake.h diff --git a/src/Makefile.am b/src/Makefile.am index 21ddf28ac852d..a2c674a392266 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1441,7 +1441,6 @@ noinst_HEADERS = \ os/btrfs_ioctl.h\ os/hobject.h \ os/CollectionIndex.h\ - os/Fake.h\ os/FileJournal.h\ os/FileStore.h\ os/FlatIndex.h\ diff --git a/src/common/config_opts.h b/src/common/config_opts.h index 31a118db1bfa3..2fd36569084dd 100644 --- a/src/common/config_opts.h +++ b/src/common/config_opts.h @@ -305,8 +305,6 @@ OPTION(filestore, OPT_BOOL, false) OPTION(filestore_debug_omap_check, OPT_BOOL, 0) // Expensive debugging check on sync OPTION(filestore_max_sync_interval, OPT_DOUBLE, 5) // seconds OPTION(filestore_min_sync_interval, OPT_DOUBLE, .01) // seconds -OPTION(filestore_fake_attrs, OPT_BOOL, false) -OPTION(filestore_fake_collections, OPT_BOOL, false) OPTION(filestore_dev, OPT_STR, "") OPTION(filestore_btrfs_trans, OPT_BOOL, false) OPTION(filestore_btrfs_snap, OPT_BOOL, true) diff --git a/src/os/Fake.h b/src/os/Fake.h deleted file mode 100644 index 121def89f0ad7..0000000000000 --- a/src/os/Fake.h +++ /dev/null @@ -1,295 +0,0 @@ -// -*- 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 - * - * 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 -#include -#include -using namespace std; -using namespace __gnu_cxx; - -class FakeCollections { - private: - Mutex faker_lock; - ObjectStore *store; - hash_map > fakecollections; - - public: - FakeCollections(ObjectStore *s) : faker_lock("FakeCollections::faker_lock"), store(s) {} - - // faked collections - int list_collections(vector& ls) { - faker_lock.Lock(); - int r = 0; - for (hash_map< coll_t, set >::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& o) { - faker_lock.Lock(); - int r = 0; - for (set::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 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& aset) { - aset = attrs; - return 0; - } - int setattrs(map& 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 fakeoattrs; - hash_map 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& 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& 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& aset) { - faker_lock.Lock(); - int r = fakecattrs[cid].setattrs(aset); - faker_lock.Unlock(); - return r; - } - int collection_getattrs(coll_t cid, map& 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 diff --git a/src/os/FileStore.cc b/src/os/FileStore.cc index bf856480efc5a..20f0a19d5ff8b 100644 --- a/src/os/FileStore.cc +++ b/src/os/FileStore.cc @@ -641,8 +641,6 @@ FileStore::FileStore(const std::string &base, const std::string &jdev) : 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), @@ -658,8 +656,6 @@ FileStore::FileStore(const std::string &base, const std::string &jdev) : 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 ), @@ -1169,32 +1165,20 @@ bool FileStore::test_mount_in_use() 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); @@ -3622,8 +3606,6 @@ int FileStore::_getattrs(const char *fn, map& aset, bool user_ 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); @@ -3634,8 +3616,6 @@ int FileStore::getattr(coll_t cid, const hobject_t& oid, const char *name, 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); @@ -3646,8 +3626,6 @@ int FileStore::getattr(coll_t cid, const hobject_t& oid, const char *name, buffe int FileStore::getattrs(coll_t cid, const hobject_t& oid, map& 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; @@ -3657,8 +3635,6 @@ int FileStore::getattrs(coll_t cid, const hobject_t& oid, map& 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); @@ -3669,8 +3645,6 @@ int FileStore::_setattr(coll_t cid, const hobject_t& oid, const char *name, int FileStore::_setattrs(coll_t cid, const hobject_t& oid, map& aset) { - if (fake_attrs) return attrs.setattrs(cid, oid, aset); - dout(15) << "setattrs " << cid << "/" << oid << dendl; int r = 0; for (map::iterator p = aset.begin(); @@ -3697,8 +3671,6 @@ int FileStore::_setattrs(coll_t cid, const hobject_t& oid, map 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); @@ -3709,8 +3681,6 @@ int FileStore::_rmattr(coll_t cid, const hobject_t& oid, const char *name) 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 aset; @@ -3735,8 +3705,6 @@ int FileStore::_rmattrs(coll_t cid, const hobject_t& oid) 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; @@ -3749,8 +3717,6 @@ int FileStore::collection_getattr(coll_t c, const char *name, 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; @@ -3766,8 +3732,6 @@ int FileStore::collection_getattr(coll_t c, const char *name, bufferlist& bl) int FileStore::collection_getattrs(coll_t cid, map& 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; @@ -3780,8 +3744,6 @@ int FileStore::collection_getattrs(coll_t cid, map& aset) 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; @@ -3794,8 +3756,6 @@ int FileStore::_collection_setattr(coll_t c, const char *name, 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; @@ -3809,8 +3769,6 @@ int FileStore::_collection_rmattr(coll_t c, const char *name) int FileStore::_collection_setattrs(coll_t cid, map& 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; @@ -3859,8 +3817,6 @@ int FileStore::collection_version_current(coll_t c, uint32_t *version) int FileStore::list_collections(vector& ls) { - if (fake_collections) return collections.list_collections(ls); - dout(10) << "list_collections" << dendl; char fn[PATH_MAX]; @@ -3915,8 +3871,6 @@ int FileStore::list_collections(vector& ls) 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; @@ -3928,16 +3882,12 @@ int FileStore::collection_stat(coll_t c, struct stat *st) 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); @@ -3955,7 +3905,6 @@ int FileStore::collection_list_partial(coll_t c, hobject_t start, int min, int max, snapid_t seq, vector *ls, hobject_t *next) { - if (fake_collections) return -1; Index index; int r = get_index(c, &index); if (r < 0) @@ -3970,7 +3919,6 @@ int FileStore::collection_list_partial(coll_t c, hobject_t start, int FileStore::collection_list(coll_t c, vector& ls) { - if (fake_collections) return collections.collection_list(c, ls); Index index; int r = get_index(c, &index); if (r < 0) @@ -4048,8 +3996,6 @@ ObjectMap::ObjectMapIterator FileStore::get_omap_iterator(coll_t c, 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; @@ -4063,8 +4009,6 @@ int FileStore::_create_collection(coll_t c) 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; @@ -4077,8 +4021,6 @@ int FileStore::_destroy_collection(coll_t c) 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; @@ -4087,8 +4029,6 @@ int FileStore::_collection_add(coll_t c, coll_t cid, const hobject_t& o) 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; diff --git a/src/os/FileStore.h b/src/os/FileStore.h index b92285dc5bf93..fad65ce42b391 100644 --- a/src/os/FileStore.h +++ b/src/os/FileStore.h @@ -27,8 +27,6 @@ #include "IndexManager.h" #include "ObjectMap.h" -#include "Fake.h" - #include "include/uuid.h" #include @@ -40,8 +38,6 @@ using namespace std; using namespace __gnu_cxx; -// fake attributes in memory, if we need to. - class FileStore : public JournalingObjectStore, public md_config_obs_t { @@ -67,14 +63,6 @@ class FileStore : public JournalingObjectStore, int basedir_fd, current_fd; deque snaps; - // fake attrs? - FakeAttrs attrs; - bool fake_attrs; - - // fake collections? - FakeCollections collections; - bool fake_collections; - // Indexed Collections IndexManager index_manager; int get_index(coll_t c, Index *index); @@ -410,8 +398,6 @@ private: bool m_filestore_btrfs_clone_range; bool m_filestore_btrfs_snap; bool m_filestore_btrfs_trans; - bool m_filestore_fake_attrs; - bool m_filestore_fake_collections; float m_filestore_commit_timeout; bool m_filestore_fiemap; bool m_filestore_flusher; -- 2.39.5