From: Sage Weil Date: Wed, 14 Oct 2015 13:33:50 +0000 (-0400) Subject: Revert "os: drop deprecated collection_* attr methods" X-Git-Tag: v9.2.0~6^2~7 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=94467700f8de157f3a90f48e9e0c489bcefc8b3a;p=ceph.git Revert "os: drop deprecated collection_* attr methods" This reverts part of commit 893e00bc0fd793090a35d275919ca0348e9f05b0. [we leave KeyValueStore untouched] Signed-off-by: Sage Weil --- diff --git a/src/os/FileStore.cc b/src/os/FileStore.cc index 4b3cbc8037f05..b2d80fc9edf2c 100644 --- a/src/os/FileStore.cc +++ b/src/os/FileStore.cc @@ -2645,8 +2645,27 @@ unsigned FileStore::_do_transaction( break; case Transaction::OP_COLL_SETATTR: + { + coll_t cid = i.get_cid(op->cid); + string name = i.decode_string(); + bufferlist bl; + i.decode_bl(bl); + tracepoint(objectstore, coll_setattr_enter, osr_name); + if (_check_replay_guard(cid, spos) > 0) + r = _collection_setattr(cid, name.c_str(), bl.c_str(), bl.length()); + tracepoint(objectstore, coll_setattr_exit, r); + } + break; + case Transaction::OP_COLL_RMATTR: - assert(0 == "coll attributes no longer supported"); + { + coll_t cid = i.get_cid(op->cid); + string name = i.decode_string(); + tracepoint(objectstore, coll_rmattr_enter, osr_name); + if (_check_replay_guard(cid, spos) > 0) + r = _collection_rmattr(cid, name.c_str()); + tracepoint(objectstore, coll_rmattr_exit, r); + } break; case Transaction::OP_STARTSYNC: @@ -4328,6 +4347,143 @@ int FileStore::_rmattrs(coll_t cid, const ghobject_t& oid, return r; } + + +// collections + +int FileStore::collection_getattr(coll_t c, const char *name, + void *value, size_t size) +{ + char fn[PATH_MAX]; + get_cdir(c, fn, sizeof(fn)); + dout(15) << "collection_getattr " << fn << " '" << name << "' len " << size << dendl; + int r; + int fd = ::open(fn, O_RDONLY); + if (fd < 0) { + r = -errno; + goto out; + } + char n[PATH_MAX]; + get_attrname(name, n, PATH_MAX); + r = chain_fgetxattr(fd, n, value, size); + VOID_TEMP_FAILURE_RETRY(::close(fd)); + out: + dout(10) << "collection_getattr " << fn << " '" << name << "' len " << size << " = " << r << dendl; + assert(!m_filestore_fail_eio || r != -EIO); + return r; +} + +int FileStore::collection_getattr(coll_t c, const char *name, bufferlist& bl) +{ + char fn[PATH_MAX]; + get_cdir(c, fn, sizeof(fn)); + dout(15) << "collection_getattr " << fn << " '" << name << "'" << dendl; + char n[PATH_MAX]; + get_attrname(name, n, PATH_MAX); + buffer::ptr bp; + int r; + int fd = ::open(fn, O_RDONLY); + if (fd < 0) { + r = -errno; + goto out; + } + r = _fgetattr(fd, n, bp); + bl.push_back(bp); + VOID_TEMP_FAILURE_RETRY(::close(fd)); + out: + dout(10) << "collection_getattr " << fn << " '" << name << "' = " << r << dendl; + assert(!m_filestore_fail_eio || r != -EIO); + return r; +} + +int FileStore::collection_getattrs(coll_t cid, map& aset) +{ + char fn[PATH_MAX]; + get_cdir(cid, fn, sizeof(fn)); + dout(10) << "collection_getattrs " << fn << dendl; + int r = 0; + int fd = ::open(fn, O_RDONLY); + if (fd < 0) { + r = -errno; + goto out; + } + r = _fgetattrs(fd, aset); + VOID_TEMP_FAILURE_RETRY(::close(fd)); + out: + dout(10) << "collection_getattrs " << fn << " = " << r << dendl; + assert(!m_filestore_fail_eio || r != -EIO); + return r; +} + + +int FileStore::_collection_setattr(coll_t c, const char *name, + const void *value, size_t size) +{ + char fn[PATH_MAX]; + get_cdir(c, fn, sizeof(fn)); + dout(10) << "collection_setattr " << fn << " '" << name << "' len " << size << dendl; + char n[PATH_MAX]; + int r; + int fd = ::open(fn, O_RDONLY); + if (fd < 0) { + r = -errno; + goto out; + } + get_attrname(name, n, PATH_MAX); + r = chain_fsetxattr(fd, n, value, size); + VOID_TEMP_FAILURE_RETRY(::close(fd)); + out: + dout(10) << "collection_setattr " << fn << " '" << name << "' len " << size << " = " << r << dendl; + return r; +} + +int FileStore::_collection_rmattr(coll_t c, const char *name) +{ + char fn[PATH_MAX]; + get_cdir(c, fn, sizeof(fn)); + dout(15) << "collection_rmattr " << fn << dendl; + char n[PATH_MAX]; + get_attrname(name, n, PATH_MAX); + int r; + int fd = ::open(fn, O_RDONLY); + if (fd < 0) { + r = -errno; + goto out; + } + r = chain_fremovexattr(fd, n); + VOID_TEMP_FAILURE_RETRY(::close(fd)); + out: + dout(10) << "collection_rmattr " << fn << " = " << r << dendl; + return r; +} + + +int FileStore::_collection_setattrs(coll_t cid, map& aset) +{ + char fn[PATH_MAX]; + get_cdir(cid, fn, sizeof(fn)); + dout(15) << "collection_setattrs " << fn << dendl; + int r = 0; + int fd = ::open(fn, O_RDONLY); + if (fd < 0) { + r = -errno; + goto out; + } + for (map::iterator p = aset.begin(); + p != aset.end(); + ++p) { + char n[PATH_MAX]; + get_attrname(p->first.c_str(), n, PATH_MAX); + r = chain_fsetxattr(fd, n, p->second.c_str(), p->second.length()); + if (r < 0) + break; + } + VOID_TEMP_FAILURE_RETRY(::close(fd)); + out: + dout(10) << "collection_setattrs " << fn << " = " << r << dendl; + return r; +} + int FileStore::_collection_remove_recursive(const coll_t &cid, const SequencerPosition &spos) { diff --git a/src/os/FileStore.h b/src/os/FileStore.h index 2a04da2ac1aa2..6580dd4452980 100644 --- a/src/os/FileStore.h +++ b/src/os/FileStore.h @@ -610,6 +610,13 @@ public: int _rmattrs(coll_t cid, const ghobject_t& oid, const SequencerPosition &spos); + int collection_getattr(coll_t c, const char *name, void *value, size_t size); + int collection_getattr(coll_t c, const char *name, bufferlist& bl); + int collection_getattrs(coll_t cid, map &aset); + + int _collection_setattr(coll_t c, const char *name, const void *value, size_t size); + int _collection_rmattr(coll_t c, const char *name); + int _collection_setattrs(coll_t cid, map &aset); int _collection_remove_recursive(const coll_t &cid, const SequencerPosition &spos); diff --git a/src/os/ObjectStore.h b/src/os/ObjectStore.h index ec14dcd766c4d..65818ffd9a39b 100644 --- a/src/os/ObjectStore.h +++ b/src/os/ObjectStore.h @@ -358,9 +358,9 @@ public: OP_RMCOLL = 21, // cid OP_COLL_ADD = 22, // cid, oldcid, oid OP_COLL_REMOVE = 23, // cid, oid - OP_COLL_SETATTR = 24, // cid, attrname, bl **DEPRECATED** - OP_COLL_RMATTR = 25, // cid, attrname **DEPRECATED** - OP_COLL_SETATTRS = 26, // cid, attrset **DEPRECATED** + OP_COLL_SETATTR = 24, // cid, attrname, bl + OP_COLL_RMATTR = 25, // cid, attrname + OP_COLL_SETATTRS = 26, // cid, attrset OP_COLL_MOVE = 8, // newcid, oldcid, oid OP_STARTSYNC = 27, // start a sync @@ -1296,6 +1296,76 @@ public: data.ops++; } + // NOTE: Collection attr operations are all DEPRECATED. new + // backends need not implement these at all. + + /// Set an xattr on a collection + void collection_setattr(coll_t cid, const string& name, bufferlist& val) + __attribute__ ((deprecated)) { + if (use_tbl) { + __u32 op = OP_COLL_SETATTR; + ::encode(op, tbl); + ::encode(cid, tbl); + ::encode(name, tbl); + ::encode(val, tbl); + } else { + Op* _op = _get_next_op(); + _op->op = OP_COLL_SETATTR; + _op->cid = _get_coll_id(cid); + ::encode(name, data_bl); + ::encode(val, data_bl); + } + data.ops++; + } + + /// Remove an xattr from a collection + void collection_rmattr(coll_t cid, const string& name) + __attribute__ ((deprecated)) { + if (use_tbl) { + __u32 op = OP_COLL_RMATTR; + ::encode(op, tbl); + ::encode(cid, tbl); + ::encode(name, tbl); + } else { + Op* _op = _get_next_op(); + _op->op = OP_COLL_RMATTR; + _op->cid = _get_coll_id(cid); + ::encode(name, data_bl); + } + data.ops++; + } + /// Set multiple xattrs on a collection + void collection_setattrs(coll_t cid, map& aset) + __attribute__ ((deprecated)) { + if (use_tbl) { + __u32 op = OP_COLL_SETATTRS; + ::encode(op, tbl); + ::encode(cid, tbl); + ::encode(aset, tbl); + } else { + Op* _op = _get_next_op(); + _op->op = OP_COLL_SETATTRS; + _op->cid = _get_coll_id(cid); + ::encode(aset, data_bl); + } + data.ops++; + } + /// Set multiple xattrs on a collection + void collection_setattrs(coll_t cid, map& aset) + __attribute__ ((deprecated)) { + if (use_tbl) { + __u32 op = OP_COLL_SETATTRS; + ::encode(op, tbl); + ::encode(cid, tbl); + ::encode(aset, tbl); + } else { + Op* _op = _get_next_op(); + _op->op = OP_COLL_SETATTRS; + _op->cid = _get_coll_id(cid); + ::encode(aset, data_bl); + } + data.ops++; + } /// Remove omap from oid void omap_clear( coll_t cid, ///< [in] Collection containing oid @@ -1902,6 +1972,45 @@ public: * @returns true if it exists, false otherwise */ virtual bool collection_exists(coll_t c) = 0; + /** + * collection_getattr - get an xattr of a collection + * + * @param cid collection name + * @param name xattr name + * @param value pointer of buffer to receive value + * @param size size of buffer to receive value + * @returns 0 on success, negative error code on failure + */ + virtual int collection_getattr(coll_t cid, const char *name, + void *value, size_t size) + __attribute__ ((deprecated)) { + return -EOPNOTSUPP; + } + + /** + * collection_getattr - get an xattr of a collection + * + * @param cid collection name + * @param name xattr name + * @param bl buffer to receive value + * @returns 0 on success, negative error code on failure + */ + virtual int collection_getattr(coll_t cid, const char *name, bufferlist& bl) + __attribute__ ((deprecated)) { + return -EOPNOTSUPP; + } + + /** + * collection_getattrs - get all xattrs of a collection + * + * @param cid collection name + * @param aset map of keys and buffers that contain the values + * @returns 0 on success, negative error code on failure + */ + virtual int collection_getattrs(coll_t cid, map &aset) + __attribute__ ((deprecated)) { + return -EOPNOTSUPP; + } /** * is a collection empty? diff --git a/src/os/Transaction.cc b/src/os/Transaction.cc index 6b0d77d9308a9..dc8b1ab8acd4e 100644 --- a/src/os/Transaction.cc +++ b/src/os/Transaction.cc @@ -4,6 +4,10 @@ #include "ObjectStore.h" #include "common/Formatter.h" +#pragma GCC diagnostic ignored "-Wpragmas" +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" + void ObjectStore::Transaction::_build_actions_from_tbl() { //used only for tbl encode @@ -320,9 +324,41 @@ void ObjectStore::Transaction::_build_actions_from_tbl() break; case Transaction::OP_COLL_SETATTR: + { + coll_t cid; + string name; + bufferlist bl; + + ::decode(cid, p); + ::decode(name, p); + ::decode(bl, p); + + collection_setattr(cid, name, bl); + } + break; + case Transaction::OP_COLL_SETATTRS: + { + coll_t cid; + map aset; + + ::decode(cid, p); + ::decode(aset, p); + + collection_setattrs(cid, aset); + } + break; + case Transaction::OP_COLL_RMATTR: - assert(0 == "collection attrs no longer supported"); + { + coll_t cid; + string name; + + ::decode(cid, p); + ::decode(name, p); + + collection_rmattr(cid, name); + } break; case Transaction::OP_STARTSYNC: @@ -468,6 +504,9 @@ void ObjectStore::Transaction::_build_actions_from_tbl() assert(ops == data.ops); } +#pragma GCC diagnostic pop +#pragma GCC diagnostic warning "-Wpragmas" + void ObjectStore::Transaction::dump(ceph::Formatter *f) { f->open_array_section("ops"); @@ -895,6 +934,10 @@ void ObjectStore::Transaction::dump(ceph::Formatter *f) f->close_section(); } +#pragma GCC diagnostic ignored "-Wpragmas" +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" + void ObjectStore::Transaction::generate_test_instances(list& o) { o.push_back(new Transaction); @@ -934,6 +977,11 @@ void ObjectStore::Transaction::generate_test_instances(listcreate_collection(c, 12); t->collection_move_rename(c, o2, c2, o3); t->remove_collection(c); + t->collection_setattr(c, string("this"), bl); + t->collection_rmattr(c, string("foo")); + t->collection_setattrs(c, m); o.push_back(t); } +#pragma GCC diagnostic pop +#pragma GCC diagnostic warning "-Wpragmas"