From 5f54671e0715781146044e2d38ba79ad03634a64 Mon Sep 17 00:00:00 2001 From: John Spray Date: Mon, 16 Nov 2015 10:57:56 +0000 Subject: [PATCH 1/2] mon: don't require OSD W for MRemoveSnaps Use ability to execute "osd pool rmsnap" command as a signal that the client should be permitted to send MRemoveSnaps too. Note that we don't also require the W ability, unlike Monitor::_allowed_command -- this is slightly more permissive handling, but anyone crafting caps that explicitly permit "osd pool rmsnap" needs to know what they are doing. Fixes: #13777 Signed-off-by: John Spray (cherry picked from commit 0b474c52abd3d528c041544f73b1d27d7d1b1320) --- src/mon/MonCap.cc | 2 ++ src/mon/OSDMonitor.cc | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/mon/MonCap.cc b/src/mon/MonCap.cc index 989893b20269a..a2540b56411c3 100644 --- a/src/mon/MonCap.cc +++ b/src/mon/MonCap.cc @@ -134,6 +134,8 @@ void MonCapGrant::expand_profile(EntityName name) const profile_grants.push_back(MonCapGrant("mds", MON_CAP_ALL)); profile_grants.push_back(MonCapGrant("mon", MON_CAP_R)); profile_grants.push_back(MonCapGrant("osd", MON_CAP_R)); + // This command grant is checked explicitly in MRemoveSnaps handling + profile_grants.push_back(MonCapGrant("osd pool rmsnap")); profile_grants.push_back(MonCapGrant("log", MON_CAP_W)); } if (profile == "osd" || profile == "mds" || profile == "mon") { diff --git a/src/mon/OSDMonitor.cc b/src/mon/OSDMonitor.cc index 9ebb34960f495..bb7f9b622180f 100644 --- a/src/mon/OSDMonitor.cc +++ b/src/mon/OSDMonitor.cc @@ -2271,7 +2271,8 @@ bool OSDMonitor::preprocess_remove_snaps(MonOpRequestRef op) MonSession *session = m->get_session(); if (!session) goto ignore; - if (!session->is_capable("osd", MON_CAP_R | MON_CAP_W)) { + if (!session->caps.is_capable(g_ceph_context, session->entity_name, + "osd", "osd pool rmsnap", {}, true, true, false)) { dout(0) << "got preprocess_remove_snaps from entity with insufficient caps " << session->caps << dendl; goto ignore; From 29d30ecd4667567a58a7f92641a8a7618e88fd44 Mon Sep 17 00:00:00 2001 From: "Yan, Zheng" Date: Thu, 12 Nov 2015 21:57:27 +0800 Subject: [PATCH 2/2] mds: properly set STATE_STRAY/STATE_ORPHAN for stray dentry/inode Fixes: #13777 Signed-off-by: Yan, Zheng (cherry picked from commit 460c74a0b872336a7279f0b40b17ed672b6e15a1) --- src/mds/MDCache.cc | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/mds/MDCache.cc b/src/mds/MDCache.cc index 3ec852a97d136..65b4ff8c4d596 100644 --- a/src/mds/MDCache.cc +++ b/src/mds/MDCache.cc @@ -6622,12 +6622,6 @@ void MDCache::trim_non_auth() if (dnl->is_remote() && dnl->get_inode() && !dnl->get_inode()->is_auth()) dn->unlink_remote(dnl); - if (dn->get_dir()->get_inode()->is_stray()) { - dn->state_set(CDentry::STATE_STRAY); - if (dnl->is_primary() && dnl->get_inode()->inode.nlink == 0) - dnl->get_inode()->state_set(CInode::STATE_ORPHAN); - } - if (!first_auth) { first_auth = dn; } else { @@ -9185,10 +9179,14 @@ void MDCache::scan_stray_dir(dirfrag_t next) } for (CDir::map_t::iterator q = dir->items.begin(); q != dir->items.end(); ++q) { CDentry *dn = q->second; + dn->state_set(CDentry::STATE_STRAY); CDentry::linkage_t *dnl = dn->get_projected_linkage(); stray_manager.notify_stray_created(); if (dnl->is_primary()) { - maybe_eval_stray(dnl->get_inode()); + CInode *in = dnl->get_inode(); + if (in->inode.nlink == 0) + in->state_set(CInode::STATE_ORPHAN); + maybe_eval_stray(in); } } }