@@ -39,14 +39,15 @@ class VolumeStats(TypedDict):
3939
4040
4141class VolumeManager :
42- def _get_volume_path (self , volume_id : str ) -> Path :
43- return Path (f"{ consts . DATA_DIR } /{ volume_id } " )
42+ def _get_volume_path (self , storage_pool : str , volume_id : str ) -> Path :
43+ return Path (f"{ config . csi_driver . storage_pools [ storage_pool ]. path } /{ volume_id } " )
4444
4545 def create_volume (
4646 self ,
4747 volume_id : str ,
4848 size : int ,
4949 thin_provision : bool ,
50+ storage_pool : str ,
5051 freezefs : bool | None = None ,
5152 copy_on_write : bool | None = None ,
5253 source_type : VolumeSource | None = None ,
@@ -56,11 +57,16 @@ def create_volume(
5657 raise SourceTypeRequired (source_id )
5758 snapshot_name = None
5859 source_volume_id = None
59- img_data_dir = self ._get_volume_path (volume_id )
60+ img_data_dir = self ._get_volume_path (storage_pool , volume_id )
6061 img_data_dir .mkdir (mode = consts .D_PERMS , exist_ok = True )
6162 meta_dir (volume_id ).mkdir (exist_ok = True , parents = True )
6263 patch_metadata (
63- volume_id , {"ready" : False , "schema_version" : LATEST_SCHEMA_VERSION }
64+ volume_id ,
65+ {
66+ "schema_version" : LATEST_SCHEMA_VERSION ,
67+ "storage_pool" : storage_pool ,
68+ "ready" : False ,
69+ },
6470 )
6571 try :
6672 if source_type == VolumeSource .snapshot :
@@ -185,7 +191,7 @@ def rmdir(path: Path):
185191 for file in meta_dir (volume_id ).glob ("*" ):
186192 file .unlink (missing_ok = True )
187193 rmdir (meta_dir (volume_id ))
188- rmdir (self ._get_volume_path (volume_id ))
194+ rmdir (self ._get_volume_path (meta [ "storage_pool" ], volume_id ))
189195
190196 def gc_if_needed (self , volume_id , dry_run = True ):
191197 with VolLock (volume_id ):
@@ -201,7 +207,8 @@ def gc_if_needed(self, volume_id, dry_run=True):
201207 return False
202208
203209 def delete_volume (self , volume_id ):
204- img_data_dir = self ._get_volume_path (volume_id )
210+ meta = metadata_or (volume_id )
211+ img_data_dir = self ._get_volume_path (meta ["storage_pool" ], volume_id )
205212 if not img_data_dir .exists ():
206213 return 0
207214 vol_img_file = img_file (volume_id )
@@ -259,14 +266,18 @@ def migrate_metadata(self, volume_id, target_version):
259266 return update_metadata (volume_id , new_data )
260267
261268 def migrate_metadata_dir (self ):
262- for old_meta in glob (f"{ consts .DATA_DIR } /**/disk.meta" ):
269+ for old_meta in glob (
270+ f"{ config .csi_driver .storage_pools [config .csi_driver .default_pool ].path } /**/disk.meta"
271+ ):
263272 volume_id = basename (dirname (old_meta ))
264273 for f in (
265274 "disk.meta" ,
266275 "disk.meta.tmp" ,
267276 "disk.lock" ,
268277 ):
269- src = Path (f"{ consts .DATA_DIR } /{ volume_id } /{ f } " )
278+ src = Path (
279+ f"{ config .csi_driver .storage_pools [config .csi_driver .default_pool ].path } /{ volume_id } /{ f } "
280+ )
270281 if src .exists ():
271282 dst = meta_dir (volume_id ) / f
272283 dst .parent .mkdir (parents = True , exist_ok = True )
@@ -278,7 +289,8 @@ def migrate_all_volume_schemas(self):
278289 self .migrate_metadata (volume_id , target_version )
279290
280291 def is_attached (self , volume_id ):
281- vol_img_dir = self ._get_volume_path (volume_id )
292+ meta = metadata_or (volume_id )
293+ vol_img_dir = self ._get_volume_path (meta ["storage_pool" ], volume_id )
282294 if not vol_img_dir .exists ():
283295 return False
284296
0 commit comments