Skip to content

Commit 46ccffa

Browse files
committed
feat: support setting the quota_size parameter in mount point #317
1 parent 2c5ad47 commit 46ccffa

File tree

10 files changed

+266
-3
lines changed

10 files changed

+266
-3
lines changed

curvine-cli/src/cmds/mount.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ pub struct MountCommand {
6363

6464
#[arg(short, long)]
6565
storage_type: Option<String>,
66+
67+
/// Set quota size limit for the mount point (e.g., 10GB, 100MB, 1TB)
68+
#[arg(long = "quota-size")]
69+
quota_size: Option<String>,
6670
}
6771

6872
impl MountCommand {
@@ -176,6 +180,13 @@ impl MountCommand {
176180
if let Some(storage_type) = self.storage_type.as_ref() {
177181
opts = opts.storage_type(StorageType::try_from(storage_type.as_str())?);
178182
}
183+
if let Some(quota_size) = self.quota_size.as_ref() {
184+
let quota_bytes = ByteUnit::from_str(quota_size.as_str())?.as_byte();
185+
if quota_bytes > i64::MAX as u64 {
186+
return err_box!("quota size {} exceeds i64 limit", quota_size);
187+
}
188+
opts = opts.quota_size(quota_bytes as i64);
189+
}
179190

180191
Ok(opts.build())
181192
}

curvine-common/proto/mount.proto

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ message MountInfoProto {
2424
optional int64 block_size = 9;
2525
optional int32 replicas = 10;
2626
required MountTypeProto mount_type = 11;
27+
optional int64 quota_size = 12;
2728
}
2829

2930
message MountOptionsProto {
@@ -37,6 +38,7 @@ message MountOptionsProto {
3738
optional int32 replicas = 8;
3839
required MountTypeProto mount_type = 9;
3940
repeated string remove_properties = 10;
41+
optional int64 quota_size = 11;
4042
}
4143

4244
enum ConsistencyStrategyProto {

curvine-common/src/state/mount.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ pub struct MountInfo {
102102
pub block_size: Option<i64>,
103103
pub replicas: Option<i32>,
104104
pub mount_type: MountType,
105+
pub quota_size: Option<i64>,
105106
}
106107

107108
impl MountInfo {
@@ -156,6 +157,7 @@ pub struct MountOptions {
156157
pub replicas: Option<i32>,
157158
pub mount_type: MountType,
158159
pub remove_properties: Vec<String>,
160+
pub quota_size: Option<i64>,
159161
}
160162

161163
impl MountOptions {
@@ -179,6 +181,7 @@ impl MountOptions {
179181
block_size: self.block_size,
180182
replicas: self.replicas,
181183
mount_type: self.mount_type,
184+
quota_size: self.quota_size,
182185
}
183186
}
184187
}
@@ -195,6 +198,7 @@ pub struct MountOptionsBuilder {
195198
replicas: Option<i32>,
196199
mount_type: MountType,
197200
remove_properties: Vec<String>,
201+
quota_size: Option<i64>,
198202
}
199203

200204
impl MountOptionsBuilder {
@@ -266,6 +270,11 @@ impl MountOptionsBuilder {
266270
self
267271
}
268272

273+
pub fn quota_size(mut self, quota_size: i64) -> Self {
274+
self.quota_size = Some(quota_size);
275+
self
276+
}
277+
269278
pub fn build(self) -> MountOptions {
270279
MountOptions {
271280
update: self.update,
@@ -278,6 +287,7 @@ impl MountOptionsBuilder {
278287
replicas: self.replicas,
279288
mount_type: self.mount_type,
280289
remove_properties: self.remove_properties,
290+
quota_size: self.quota_size,
281291
}
282292
}
283293
}

curvine-common/src/utils/proto_utils.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,7 @@ impl ProtoUtils {
511511
block_size: info.block_size,
512512
replicas: info.replicas,
513513
mount_type: info.mount_type.into(),
514+
quota_size: info.quota_size,
514515
}
515516
}
516517

@@ -527,6 +528,7 @@ impl ProtoUtils {
527528
block_size: info.block_size,
528529
replicas: info.replicas,
529530
mount_type: info.mount_type.into(),
531+
quota_size: info.quota_size,
530532
}
531533
}
532534

@@ -542,6 +544,7 @@ impl ProtoUtils {
542544
replicas: opts.replicas,
543545
mount_type: opts.mount_type.into(),
544546
remove_properties: opts.remove_properties,
547+
quota_size: opts.quota_size,
545548
}
546549
}
547550

@@ -557,6 +560,7 @@ impl ProtoUtils {
557560
replicas: opts.replicas,
558561
mount_type: MountType::from(opts.mount_type),
559562
remove_properties: opts.remove_properties,
563+
quota_size: opts.quota_size,
560564
}
561565
}
562566

curvine-server/src/master/master_handler.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,7 @@ impl MessageHandler for MasterHandler {
444444
RpcCode::GetMountTable => self.get_mount_table(ctx),
445445
RpcCode::GetMountInfo => self.get_mount_info(ctx),
446446

447+
// Quota management
447448
RpcCode::MetricsReport => self.metrics_report(ctx),
448449

449450
// Worker related requests

curvine-server/src/master/meta/fs_dir.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,7 @@ impl FsDir {
521521
inode.as_file_ref()?,
522522
commit_block,
523523
)?;
524+
524525
Ok(true)
525526
}
526527

curvine-server/src/master/meta/fs_stats.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ impl FileSystemStats {
5353

5454
pub fn set_counts(&self, file_count: i64, dir_count: i64) {
5555
self.metrics.inode_file_num.set(file_count);
56-
self.metrics.inode_file_num.set(dir_count);
56+
self.metrics.inode_dir_num.set(dir_count);
5757
}
5858
}
5959

curvine-server/src/master/mount/mount_manager.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ impl MountManager {
8383
ufs_path: &str,
8484
mnt_opt: &MountOptions,
8585
) -> FsResult<()> {
86-
if !self.mount_table.exists(cv_path) {
87-
return err_box!("update mode: mount point {} does not exist", ufs_path);
86+
if !self.mount_table.cv_path_exists(cv_path) {
87+
return err_box!("update mode: mount point {} does not exist", cv_path);
8888
}
8989

9090
self.mount_table.umount(cv_path)?;

curvine-server/src/master/mount/mount_table.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ impl MountTable {
6868
false
6969
}
7070

71+
pub fn cv_path_exists(&self, cv_path: &str) -> bool {
72+
let inner = self.inner.read().unwrap();
73+
inner.mountpath2id.contains_key(cv_path)
74+
}
75+
7176
pub fn check_conflict(&self, cv_path: &str, _ufs_path: &str) -> FsResult<()> {
7277
let inner = self.inner.read().unwrap();
7378
for info in inner.mountid2entry.values() {

0 commit comments

Comments
 (0)