]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mds: check file layout in mknod 55207/head
authorYantao xue <xueyantao2114@163.com>
Tue, 30 Jan 2024 09:14:43 +0000 (17:14 +0800)
committerYantao xue <xueyantao2114@163.com>
Tue, 27 Feb 2024 12:33:53 +0000 (20:33 +0800)
Fixes: https://tracker.ceph.com/issues/64061
Signed-off-by: Xue Yantao <xueyantao2114@163.com>
src/mds/Server.cc
src/mds/Server.h

index f3a9287cd053d153517b2c398801310b268647e6..ed42ac439d82a10bc4efc3760d9c286cc34cc74c 100644 (file)
@@ -4627,6 +4627,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(const MDRequestRef& mdr)
 {
@@ -4701,13 +4715,7 @@ void Server::handle_client_openc(const 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;
   }
@@ -5593,13 +5601,7 @@ void Server::handle_client_setlayout(const 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;
   }
@@ -5725,14 +5727,8 @@ void Server::handle_client_setdirlayout(const 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;
   }
@@ -5909,15 +5905,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;
 }
 
@@ -7002,6 +6994,11 @@ void Server::handle_client_mknod(const 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);
 
index 89cda03155dc80e4f13d34da387a3b1069e3e5fa..63d05ea32abbba2990102961af33e8fea2908a2d 100644 (file)
@@ -237,6 +237,9 @@ public:
   void handle_client_removexattr(const MDRequestRef& mdr);
 
   void handle_client_fsync(const MDRequestRef& mdr);
+  
+  // check layout
+  bool is_valid_layout(file_layout_t *layout);
 
   // open
   void handle_client_open(const MDRequestRef& mdr);