From d77b20a851bfe84a889aae0f6678b27f5149170f 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 handle_client_fsync() defined as accepting a non-const param. --- 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 35a9d03afca..9cce1731ebc 100644 --- a/src/mds/Server.cc +++ b/src/mds/Server.cc @@ -4600,6 +4600,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) { @@ -4674,13 +4688,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; } @@ -5569,13 +5577,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; } @@ -5702,14 +5704,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; } @@ -5887,15 +5883,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; } @@ -6974,6 +6966,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 6b2f9c188f5..b175692f12f 100644 --- a/src/mds/Server.h +++ b/src/mds/Server.h @@ -236,6 +236,9 @@ public: void handle_client_removexattr(MDRequestRef& mdr); void handle_client_fsync(MDRequestRef& mdr); + + // check layout + bool is_valid_layout(file_layout_t *layout); // open void handle_client_open(MDRequestRef& mdr); -- 2.39.5