From cd729c80ae977b777934d7620aa35e40e5e7870e Mon Sep 17 00:00:00 2001 From: Yantao xue Date: Tue, 30 Jan 2024 17:14:43 +0800 Subject: [PATCH] mds: check file layout in mknod Fixes: https://tracker.ceph.com/issues/64061 Signed-off-by: Xue Yantao (cherry picked from commit e913e5c6ce51753724e00491fab4de64502952f3) Conflicts: src/mds/Server.h Minor conflict due to presence of helpers functions and parameter type change in handle_client_fsync(). --- src/mds/Server.cc | 57 ++++++++++++++++++++++------------------------- src/mds/Server.h | 3 +++ 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/src/mds/Server.cc b/src/mds/Server.cc index f50775665083e..6bac4e9ef6dc9 100644 --- a/src/mds/Server.cc +++ b/src/mds/Server.cc @@ -4571,6 +4571,20 @@ public: } }; +bool Server::is_valid_layout(file_layout_t *layout) +{ + if (!layout->is_valid()) { + dout(10) << " invalid initial file layout" << dendl; + return false; + } + if (!mds->mdsmap->is_data_pool(layout->pool_id)) { + dout(10) << " invalid data pool " << layout->pool_id << dendl; + return false; + } + + return true; +} + /* This function takes responsibility for the passed mdr*/ void Server::handle_client_openc(MDRequestRef& mdr) { @@ -4650,13 +4664,7 @@ void Server::handle_client_openc(MDRequestRef& mdr) access |= MAY_SET_VXATTR; } - if (!layout.is_valid()) { - dout(10) << " invalid initial file layout" << dendl; - respond_to_request(mdr, -CEPHFS_EINVAL); - return; - } - if (!mds->mdsmap->is_data_pool(layout.pool_id)) { - dout(10) << " invalid data pool " << layout.pool_id << dendl; + if (!is_valid_layout(&layout)) { respond_to_request(mdr, -CEPHFS_EINVAL); return; } @@ -5475,13 +5483,7 @@ void Server::handle_client_setlayout(MDRequestRef& mdr) access |= MAY_SET_VXATTR; } - if (!layout.is_valid()) { - dout(10) << "bad layout" << dendl; - respond_to_request(mdr, -CEPHFS_EINVAL); - return; - } - if (!mds->mdsmap->is_data_pool(layout.pool_id)) { - dout(10) << " invalid data pool " << layout.pool_id << dendl; + if (!is_valid_layout(&layout)) { respond_to_request(mdr, -CEPHFS_EINVAL); return; } @@ -5608,14 +5610,8 @@ void Server::handle_client_setdirlayout(MDRequestRef& mdr) if (layout != old_layout) { access |= MAY_SET_VXATTR; } - - if (!layout.is_valid()) { - dout(10) << "bad layout" << dendl; - respond_to_request(mdr, -CEPHFS_EINVAL); - return; - } - if (!mds->mdsmap->is_data_pool(layout.pool_id)) { - dout(10) << " invalid data pool " << layout.pool_id << dendl; + + if (!is_valid_layout(&layout)) { respond_to_request(mdr, -CEPHFS_EINVAL); return; } @@ -5793,15 +5789,11 @@ int Server::parse_layout_vxattr(string name, string value, const OSDMap& osdmap, if (r < 0) { return r; } - - if (validate && !layout->is_valid()) { - dout(10) << __func__ << ": bad layout" << dendl; - return -CEPHFS_EINVAL; - } - if (!mds->mdsmap->is_data_pool(layout->pool_id)) { - dout(10) << __func__ << ": invalid data pool " << layout->pool_id << dendl; - return -CEPHFS_EINVAL; + + if (!is_valid_layout(layout)) { + return -CEPHFS_EINVAL; } + return 0; } @@ -6944,6 +6936,11 @@ void Server::handle_client_mknod(MDRequestRef& mdr) else layout = mdcache->default_file_layout; + if (!is_valid_layout(&layout)) { + respond_to_request(mdr, -CEPHFS_EINVAL); + return; + } + CInode *newi = prepare_new_inode(mdr, dn->get_dir(), inodeno_t(req->head.ino), mode, &layout); ceph_assert(newi); diff --git a/src/mds/Server.h b/src/mds/Server.h index afd7c342d5023..d23fa72f3c4e4 100644 --- a/src/mds/Server.h +++ b/src/mds/Server.h @@ -241,6 +241,9 @@ public: bool is_reintegrate_pending(CDentry *dn); void wait_for_pending_reintegrate(CDentry *dn, MDRequestRef& mdr); + + // check layout + bool is_valid_layout(file_layout_t *layout); // open void handle_client_open(MDRequestRef& mdr); -- 2.39.5