diff --git a/.ci/e2e-test/rawfile-driver.yaml b/.ci/e2e-test/rawfile-driver.yaml index 47f3fa1..e630f4e 100644 --- a/.ci/e2e-test/rawfile-driver.yaml +++ b/.ci/e2e-test/rawfile-driver.yaml @@ -4,6 +4,9 @@ SnapshotClass: FromName: true DriverInfo: Name: rawfile.hamravesh.com + SupportedFsType: + ext4: + btrfs: Capabilities: persistence: true block: false diff --git a/Dockerfile b/Dockerfile index ed3c28f..07ba35a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,6 +4,10 @@ FROM python:3.8.3-slim-buster WORKDIR /app/ +RUN apt-get update && \ + apt-get install -y e2fsprogs btrfs-progs && \ + rm -rf /var/lib/apt/lists/* + ENV PIP_NO_CACHE_DIR 1 ADD ./requirements.txt ./ RUN pip install -r ./requirements.txt diff --git a/README.md b/README.md index a7e3269..d3902f9 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ Features - [x] `Filesystem` mode - [ ] `Block` mode - [x] Volume metrics -- [ ] Supports fsTypes +- [x] Supports fsTypes: `ext4`, `btrfs` - [x] Online expansion: If fs supports it (e.g. ext4, btrfs) - [ ] Online shrinking: If fs supports it (e.g. btrfs) - [ ] Offline expansion/shrinking diff --git a/rawfile_servicer.py b/rawfile_servicer.py index 8eb1b6b..aa78cf9 100644 --- a/rawfile_servicer.py +++ b/rawfile_servicer.py @@ -108,12 +108,18 @@ class RawFileNodeServicer(csi_pb2_grpc.NodeServicer): @log_grpc_request def NodeExpandVolume(self, request, context): volume_id = request.volume_id + volume_path = request.volume_path size = request.capacity_range.required_bytes + fs_type = rawfile_util.metadata(volume_id)["fs_type"] img_file = rawfile_util.img_file(volume_id) for dev in rawfile_util.attached_loops(img_file): run(f"losetup -c {dev}") - if True: # TODO: is ext2/ext3/ext4 + if fs_type == "ext4": run(f"resize2fs {dev}") + elif fs_type == "btrfs": + run(f"btrfs filesystem resize max {volume_path}") + else: + raise Exception(f"Unsupported fsType: {fs_type}") break return csi_pb2.NodeExpandVolumeResponse(capacity_bytes=size) @@ -151,7 +157,9 @@ class RawFileControllerServicer(csi_pb2_grpc.ControllerServicer): access_type = volume_capability.WhichOneof("access_type") if access_type == "mount": - pass + fs_type = volume_capability.mount.fs_type + if fs_type == "": + fs_type = "ext4" elif access_type == "block": context.abort( grpc.StatusCode.INVALID_ARGUMENT, "Block mode not supported (yet)" @@ -179,7 +187,8 @@ class RawFileControllerServicer(csi_pb2_grpc.ControllerServicer): ) run_on_node( - init_rawfile.as_cmd(volume_id=request.name, size=size), node=node_name + init_rawfile.as_cmd(volume_id=request.name, size=size, fs_type=fs_type), + node=node_name, ) return csi_pb2.CreateVolumeResponse( diff --git a/remote.py b/remote.py index 0babe6c..90543ca 100644 --- a/remote.py +++ b/remote.py @@ -10,7 +10,7 @@ def scrub(volume_id): @remote_fn -def init_rawfile(volume_id, size): +def init_rawfile(volume_id, size, fs_type): import time import rawfile_util from volume_schema import LATEST_SCHEMA_VERSION @@ -31,10 +31,16 @@ def init_rawfile(volume_id, size): "created_at": time.time(), "img_file": img_file.as_posix(), "size": size, + "fs_type": fs_type, }, ) run(f"truncate -s {size} {img_file}") - run(f"mkfs.ext4 {img_file}") + if fs_type == "ext4": + run(f"mkfs.ext4 {img_file}") + elif fs_type == "btrfs": + run(f"mkfs.btrfs {img_file}") + else: + raise Exception(f"Unsupported fsType: {fs_type}") @remote_fn diff --git a/volume_schema.py b/volume_schema.py index 11f1b74..7765ba2 100644 --- a/volume_schema.py +++ b/volume_schema.py @@ -1,6 +1,6 @@ import sys -LATEST_SCHEMA_VERSION = 1 # type: int +LATEST_SCHEMA_VERSION = 2 # type: int def migrate_0_to_1(data: dict) -> dict: @@ -8,6 +8,12 @@ def migrate_0_to_1(data: dict) -> dict: return data +def migrate_1_to_2(data: dict) -> dict: + data["schema_version"] = 2 + data.setdefault("fs_type", "ext4") + return data + + def migrate_to(data: dict, version: int) -> dict: current = data.get("schema_version", 0) if current > version: