From a37fcd85376d566e35ebbd6a294c14b21ee29847 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Sun, 20 Jul 2014 10:27:05 -0700 Subject: [PATCH] osdc/Objecter: add name-base pool_delete Avoid a lookup then delete race. Signed-off-by: Sage Weil --- src/osdc/Objecter.cc | 23 +++++++++++++++++++---- src/osdc/Objecter.h | 2 ++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/osdc/Objecter.cc b/src/osdc/Objecter.cc index 0e9cdd1a51b46..e938dd860997a 100644 --- a/src/osdc/Objecter.cc +++ b/src/osdc/Objecter.cc @@ -2686,18 +2686,33 @@ int Objecter::delete_pool(int64_t pool, Context *onfinish) if (!osdmap->have_pg_pool(pool)) return -ENOENT; + _do_delete_pool(pool, onfinish); + return 0; +} + +int Objecter::delete_pool(const string &pool_name, Context *onfinish) +{ + RWLock::WLocker wl(rwlock); + ldout(cct, 10) << "delete_pool " << pool_name << dendl; + + int64_t pool = osdmap->lookup_pg_pool_name(pool_name); + if (pool < 0) + return pool; + + _do_delete_pool(pool, onfinish); + return 0; +} + +void Objecter::_do_delete_pool(int64_t pool, Context *onfinish) +{ PoolOp *op = new PoolOp; - if (!op) return -ENOMEM; op->tid = last_tid.inc(); op->pool = pool; op->name = "delete"; op->onfinish = onfinish; op->pool_op = POOL_OP_DELETE; pool_ops[op->tid] = op; - pool_op_submit(op); - - return 0; } /** diff --git a/src/osdc/Objecter.h b/src/osdc/Objecter.h index a66830fe0fe3f..67ed9f9bc1161 100644 --- a/src/osdc/Objecter.h +++ b/src/osdc/Objecter.h @@ -2158,6 +2158,7 @@ private: void pool_op_submit(PoolOp *op); void _pool_op_submit(PoolOp *op); void _finish_pool_op(PoolOp *op); + void _do_delete_pool(int64_t pool, Context *onfinish); public: int create_pool_snap(int64_t pool, string& snapName, Context *onfinish); int allocate_selfmanaged_snap(int64_t pool, snapid_t *psnapid, Context *onfinish); @@ -2167,6 +2168,7 @@ public: int create_pool(string& name, Context *onfinish, uint64_t auid=0, int crush_rule=-1); int delete_pool(int64_t pool, Context *onfinish); + int delete_pool(const string& name, Context *onfinish); int change_pool_auid(int64_t pool, Context *onfinish, uint64_t auid); void handle_pool_op_reply(MPoolOpReply *m); -- 2.39.5